1 | //===- llvm/CodeGen/SelectionDAG.h - InstSelection DAG ----------*- C++ -*-===// |
---|---|
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | // |
9 | // This file declares the SelectionDAG class, and transitively defines the |
10 | // SDNode class and subclasses. |
11 | // |
12 | //===----------------------------------------------------------------------===// |
13 | |
14 | #ifndef LLVM_CODEGEN_SELECTIONDAG_H |
15 | #define LLVM_CODEGEN_SELECTIONDAG_H |
16 | |
17 | #include "llvm/ADT/ArrayRef.h" |
18 | #include "llvm/ADT/DenseMap.h" |
19 | #include "llvm/ADT/DenseSet.h" |
20 | #include "llvm/ADT/FoldingSet.h" |
21 | #include "llvm/ADT/SmallVector.h" |
22 | #include "llvm/ADT/StringMap.h" |
23 | #include "llvm/ADT/ilist.h" |
24 | #include "llvm/ADT/iterator.h" |
25 | #include "llvm/ADT/iterator_range.h" |
26 | #include "llvm/CodeGen/DAGCombine.h" |
27 | #include "llvm/CodeGen/ISDOpcodes.h" |
28 | #include "llvm/CodeGen/MachineFunction.h" |
29 | #include "llvm/CodeGen/MachineMemOperand.h" |
30 | #include "llvm/CodeGen/MachinePassManager.h" |
31 | #include "llvm/CodeGen/SelectionDAGNodes.h" |
32 | #include "llvm/CodeGen/ValueTypes.h" |
33 | #include "llvm/CodeGenTypes/MachineValueType.h" |
34 | #include "llvm/IR/ConstantRange.h" |
35 | #include "llvm/IR/DebugLoc.h" |
36 | #include "llvm/IR/Metadata.h" |
37 | #include "llvm/IR/RuntimeLibcalls.h" |
38 | #include "llvm/Support/Allocator.h" |
39 | #include "llvm/Support/ArrayRecycler.h" |
40 | #include "llvm/Support/CodeGen.h" |
41 | #include "llvm/Support/Compiler.h" |
42 | #include "llvm/Support/ErrorHandling.h" |
43 | #include "llvm/Support/RecyclingAllocator.h" |
44 | #include <cassert> |
45 | #include <cstdint> |
46 | #include <functional> |
47 | #include <map> |
48 | #include <set> |
49 | #include <string> |
50 | #include <tuple> |
51 | #include <utility> |
52 | #include <vector> |
53 | |
54 | namespace llvm { |
55 | |
56 | class DIExpression; |
57 | class DILabel; |
58 | class DIVariable; |
59 | class Function; |
60 | class Pass; |
61 | class Type; |
62 | template <class GraphType> struct GraphTraits; |
63 | template <typename T, unsigned int N> class SmallSetVector; |
64 | template <typename T, typename Enable> struct FoldingSetTrait; |
65 | class BatchAAResults; |
66 | class BlockAddress; |
67 | class BlockFrequencyInfo; |
68 | class Constant; |
69 | class ConstantFP; |
70 | class ConstantInt; |
71 | class DataLayout; |
72 | struct fltSemantics; |
73 | class FunctionLoweringInfo; |
74 | class FunctionVarLocs; |
75 | class GlobalValue; |
76 | struct KnownBits; |
77 | class LLVMContext; |
78 | class MachineBasicBlock; |
79 | class MachineConstantPoolValue; |
80 | class MachineModuleInfo; |
81 | class MCSymbol; |
82 | class OptimizationRemarkEmitter; |
83 | class ProfileSummaryInfo; |
84 | class SDDbgValue; |
85 | class SDDbgOperand; |
86 | class SDDbgLabel; |
87 | class SelectionDAG; |
88 | class SelectionDAGTargetInfo; |
89 | class TargetLibraryInfo; |
90 | class TargetLowering; |
91 | class TargetMachine; |
92 | class TargetSubtargetInfo; |
93 | class Value; |
94 | |
95 | template <typename T> class GenericSSAContext; |
96 | using SSAContext = GenericSSAContext<Function>; |
97 | template <typename T> class GenericUniformityInfo; |
98 | using UniformityInfo = GenericUniformityInfo<SSAContext>; |
99 | |
100 | class SDVTListNode : public FoldingSetNode { |
101 | friend struct FoldingSetTrait<SDVTListNode>; |
102 | |
103 | /// A reference to an Interned FoldingSetNodeID for this node. |
104 | /// The Allocator in SelectionDAG holds the data. |
105 | /// SDVTList contains all types which are frequently accessed in SelectionDAG. |
106 | /// The size of this list is not expected to be big so it won't introduce |
107 | /// a memory penalty. |
108 | FoldingSetNodeIDRef FastID; |
109 | const EVT *VTs; |
110 | unsigned int NumVTs; |
111 | /// The hash value for SDVTList is fixed, so cache it to avoid |
112 | /// hash calculation. |
113 | unsigned HashValue; |
114 | |
115 | public: |
116 | SDVTListNode(const FoldingSetNodeIDRef ID, const EVT *VT, unsigned int Num) : |
117 | FastID(ID), VTs(VT), NumVTs(Num) { |
118 | HashValue = ID.ComputeHash(); |
119 | } |
120 | |
121 | SDVTList getSDVTList() { |
122 | SDVTList result = {.VTs: VTs, .NumVTs: NumVTs}; |
123 | return result; |
124 | } |
125 | }; |
126 | |
127 | /// Specialize FoldingSetTrait for SDVTListNode |
128 | /// to avoid computing temp FoldingSetNodeID and hash value. |
129 | template<> struct FoldingSetTrait<SDVTListNode> : DefaultFoldingSetTrait<SDVTListNode> { |
130 | static void Profile(const SDVTListNode &X, FoldingSetNodeID& ID) { |
131 | ID = X.FastID; |
132 | } |
133 | |
134 | static bool Equals(const SDVTListNode &X, const FoldingSetNodeID &ID, |
135 | unsigned IDHash, FoldingSetNodeID &TempID) { |
136 | if (X.HashValue != IDHash) |
137 | return false; |
138 | return ID == X.FastID; |
139 | } |
140 | |
141 | static unsigned ComputeHash(const SDVTListNode &X, FoldingSetNodeID &TempID) { |
142 | return X.HashValue; |
143 | } |
144 | }; |
145 | |
146 | template <> struct ilist_alloc_traits<SDNode> { |
147 | static void deleteNode(SDNode *) { |
148 | llvm_unreachable("ilist_traits<SDNode> shouldn't see a deleteNode call!"); |
149 | } |
150 | }; |
151 | |
152 | /// Keeps track of dbg_value information through SDISel. We do |
153 | /// not build SDNodes for these so as not to perturb the generated code; |
154 | /// instead the info is kept off to the side in this structure. Each SDNode may |
155 | /// have one or more associated dbg_value entries. This information is kept in |
156 | /// DbgValMap. |
157 | /// Byval parameters are handled separately because they don't use alloca's, |
158 | /// which busts the normal mechanism. There is good reason for handling all |
159 | /// parameters separately: they may not have code generated for them, they |
160 | /// should always go at the beginning of the function regardless of other code |
161 | /// motion, and debug info for them is potentially useful even if the parameter |
162 | /// is unused. Right now only byval parameters are handled separately. |
163 | class SDDbgInfo { |
164 | BumpPtrAllocator Alloc; |
165 | SmallVector<SDDbgValue*, 32> DbgValues; |
166 | SmallVector<SDDbgValue*, 32> ByvalParmDbgValues; |
167 | SmallVector<SDDbgLabel*, 4> DbgLabels; |
168 | using DbgValMapType = DenseMap<const SDNode *, SmallVector<SDDbgValue *, 2>>; |
169 | DbgValMapType DbgValMap; |
170 | |
171 | public: |
172 | SDDbgInfo() = default; |
173 | SDDbgInfo(const SDDbgInfo &) = delete; |
174 | SDDbgInfo &operator=(const SDDbgInfo &) = delete; |
175 | |
176 | LLVM_ABI void add(SDDbgValue *V, bool isParameter); |
177 | |
178 | void add(SDDbgLabel *L) { DbgLabels.push_back(Elt: L); } |
179 | |
180 | /// Invalidate all DbgValues attached to the node and remove |
181 | /// it from the Node-to-DbgValues map. |
182 | LLVM_ABI void erase(const SDNode *Node); |
183 | |
184 | void clear() { |
185 | DbgValMap.clear(); |
186 | DbgValues.clear(); |
187 | ByvalParmDbgValues.clear(); |
188 | DbgLabels.clear(); |
189 | Alloc.Reset(); |
190 | } |
191 | |
192 | BumpPtrAllocator &getAlloc() { return Alloc; } |
193 | |
194 | bool empty() const { |
195 | return DbgValues.empty() && ByvalParmDbgValues.empty() && DbgLabels.empty(); |
196 | } |
197 | |
198 | ArrayRef<SDDbgValue*> getSDDbgValues(const SDNode *Node) const { |
199 | auto I = DbgValMap.find(Val: Node); |
200 | if (I != DbgValMap.end()) |
201 | return I->second; |
202 | return ArrayRef<SDDbgValue*>(); |
203 | } |
204 | |
205 | using DbgIterator = SmallVectorImpl<SDDbgValue*>::iterator; |
206 | using DbgLabelIterator = SmallVectorImpl<SDDbgLabel*>::iterator; |
207 | |
208 | DbgIterator DbgBegin() { return DbgValues.begin(); } |
209 | DbgIterator DbgEnd() { return DbgValues.end(); } |
210 | DbgIterator ByvalParmDbgBegin() { return ByvalParmDbgValues.begin(); } |
211 | DbgIterator ByvalParmDbgEnd() { return ByvalParmDbgValues.end(); } |
212 | DbgLabelIterator DbgLabelBegin() { return DbgLabels.begin(); } |
213 | DbgLabelIterator DbgLabelEnd() { return DbgLabels.end(); } |
214 | }; |
215 | |
216 | LLVM_ABI void checkForCycles(const SelectionDAG *DAG, bool force = false); |
217 | |
218 | /// This is used to represent a portion of an LLVM function in a low-level |
219 | /// Data Dependence DAG representation suitable for instruction selection. |
220 | /// This DAG is constructed as the first step of instruction selection in order |
221 | /// to allow implementation of machine specific optimizations |
222 | /// and code simplifications. |
223 | /// |
224 | /// The representation used by the SelectionDAG is a target-independent |
225 | /// representation, which has some similarities to the GCC RTL representation, |
226 | /// but is significantly more simple, powerful, and is a graph form instead of a |
227 | /// linear form. |
228 | /// |
229 | class SelectionDAG { |
230 | const TargetMachine &TM; |
231 | const SelectionDAGTargetInfo *TSI = nullptr; |
232 | const TargetLowering *TLI = nullptr; |
233 | const TargetLibraryInfo *LibInfo = nullptr; |
234 | const FunctionVarLocs *FnVarLocs = nullptr; |
235 | MachineFunction *MF; |
236 | MachineFunctionAnalysisManager *MFAM = nullptr; |
237 | Pass *SDAGISelPass = nullptr; |
238 | LLVMContext *Context; |
239 | CodeGenOptLevel OptLevel; |
240 | |
241 | UniformityInfo *UA = nullptr; |
242 | FunctionLoweringInfo * FLI = nullptr; |
243 | |
244 | /// The function-level optimization remark emitter. Used to emit remarks |
245 | /// whenever manipulating the DAG. |
246 | OptimizationRemarkEmitter *ORE; |
247 | |
248 | ProfileSummaryInfo *PSI = nullptr; |
249 | BlockFrequencyInfo *BFI = nullptr; |
250 | MachineModuleInfo *MMI = nullptr; |
251 | |
252 | /// Extended EVTs used for single value VTLists. |
253 | std::set<EVT, EVT::compareRawBits> EVTs; |
254 | |
255 | /// List of non-single value types. |
256 | FoldingSet<SDVTListNode> VTListMap; |
257 | |
258 | /// Pool allocation for misc. objects that are created once per SelectionDAG. |
259 | BumpPtrAllocator Allocator; |
260 | |
261 | /// The starting token. |
262 | SDNode EntryNode; |
263 | |
264 | /// The root of the entire DAG. |
265 | SDValue Root; |
266 | |
267 | /// A linked list of nodes in the current DAG. |
268 | ilist<SDNode> AllNodes; |
269 | |
270 | /// The AllocatorType for allocating SDNodes. We use |
271 | /// pool allocation with recycling. |
272 | using NodeAllocatorType = RecyclingAllocator<BumpPtrAllocator, SDNode, |
273 | sizeof(LargestSDNode), |
274 | alignof(MostAlignedSDNode)>; |
275 | |
276 | /// Pool allocation for nodes. |
277 | NodeAllocatorType NodeAllocator; |
278 | |
279 | /// This structure is used to memoize nodes, automatically performing |
280 | /// CSE with existing nodes when a duplicate is requested. |
281 | FoldingSet<SDNode> CSEMap; |
282 | |
283 | /// Pool allocation for machine-opcode SDNode operands. |
284 | BumpPtrAllocator OperandAllocator; |
285 | ArrayRecycler<SDUse> OperandRecycler; |
286 | |
287 | /// Tracks dbg_value and dbg_label information through SDISel. |
288 | SDDbgInfo *DbgInfo; |
289 | |
290 | using CallSiteInfo = MachineFunction::CallSiteInfo; |
291 | using CalledGlobalInfo = MachineFunction::CalledGlobalInfo; |
292 | |
293 | struct NodeExtraInfo { |
294 | CallSiteInfo CSInfo; |
295 | MDNode *HeapAllocSite = nullptr; |
296 | MDNode *PCSections = nullptr; |
297 | MDNode *MMRA = nullptr; |
298 | CalledGlobalInfo CalledGlobal{}; |
299 | bool NoMerge = false; |
300 | }; |
301 | /// Out-of-line extra information for SDNodes. |
302 | DenseMap<const SDNode *, NodeExtraInfo> SDEI; |
303 | |
304 | /// PersistentId counter to be used when inserting the next |
305 | /// SDNode to this SelectionDAG. We do not place that under |
306 | /// `#if LLVM_ENABLE_ABI_BREAKING_CHECKS` intentionally because |
307 | /// it adds unneeded complexity without noticeable |
308 | /// benefits (see discussion with @thakis in D120714). |
309 | uint16_t NextPersistentId = 0; |
310 | |
311 | public: |
312 | /// Clients of various APIs that cause global effects on |
313 | /// the DAG can optionally implement this interface. This allows the clients |
314 | /// to handle the various sorts of updates that happen. |
315 | /// |
316 | /// A DAGUpdateListener automatically registers itself with DAG when it is |
317 | /// constructed, and removes itself when destroyed in RAII fashion. |
318 | struct LLVM_ABI DAGUpdateListener { |
319 | DAGUpdateListener *const Next; |
320 | SelectionDAG &DAG; |
321 | |
322 | explicit DAGUpdateListener(SelectionDAG &D) |
323 | : Next(D.UpdateListeners), DAG(D) { |
324 | DAG.UpdateListeners = this; |
325 | } |
326 | |
327 | virtual ~DAGUpdateListener() { |
328 | assert(DAG.UpdateListeners == this && |
329 | "DAGUpdateListeners must be destroyed in LIFO order"); |
330 | DAG.UpdateListeners = Next; |
331 | } |
332 | |
333 | /// The node N that was deleted and, if E is not null, an |
334 | /// equivalent node E that replaced it. |
335 | virtual void NodeDeleted(SDNode *N, SDNode *E); |
336 | |
337 | /// The node N that was updated. |
338 | virtual void NodeUpdated(SDNode *N); |
339 | |
340 | /// The node N that was inserted. |
341 | virtual void NodeInserted(SDNode *N); |
342 | }; |
343 | |
344 | struct LLVM_ABI DAGNodeDeletedListener : public DAGUpdateListener { |
345 | std::function<void(SDNode *, SDNode *)> Callback; |
346 | |
347 | DAGNodeDeletedListener(SelectionDAG &DAG, |
348 | std::function<void(SDNode *, SDNode *)> Callback) |
349 | : DAGUpdateListener(DAG), Callback(std::move(Callback)) {} |
350 | |
351 | void NodeDeleted(SDNode *N, SDNode *E) override { Callback(N, E); } |
352 | |
353 | private: |
354 | virtual void anchor(); |
355 | }; |
356 | |
357 | struct LLVM_ABI DAGNodeInsertedListener : public DAGUpdateListener { |
358 | std::function<void(SDNode *)> Callback; |
359 | |
360 | DAGNodeInsertedListener(SelectionDAG &DAG, |
361 | std::function<void(SDNode *)> Callback) |
362 | : DAGUpdateListener(DAG), Callback(std::move(Callback)) {} |
363 | |
364 | void NodeInserted(SDNode *N) override { Callback(N); } |
365 | |
366 | private: |
367 | virtual void anchor(); |
368 | }; |
369 | |
370 | /// Help to insert SDNodeFlags automatically in transforming. Use |
371 | /// RAII to save and resume flags in current scope. |
372 | class FlagInserter { |
373 | SelectionDAG &DAG; |
374 | SDNodeFlags Flags; |
375 | FlagInserter *LastInserter; |
376 | |
377 | public: |
378 | FlagInserter(SelectionDAG &SDAG, SDNodeFlags Flags) |
379 | : DAG(SDAG), Flags(Flags), |
380 | LastInserter(SDAG.getFlagInserter()) { |
381 | SDAG.setFlagInserter(this); |
382 | } |
383 | FlagInserter(SelectionDAG &SDAG, SDNode *N) |
384 | : FlagInserter(SDAG, N->getFlags()) {} |
385 | |
386 | FlagInserter(const FlagInserter &) = delete; |
387 | FlagInserter &operator=(const FlagInserter &) = delete; |
388 | ~FlagInserter() { DAG.setFlagInserter(LastInserter); } |
389 | |
390 | SDNodeFlags getFlags() const { return Flags; } |
391 | }; |
392 | |
393 | /// When true, additional steps are taken to |
394 | /// ensure that getConstant() and similar functions return DAG nodes that |
395 | /// have legal types. This is important after type legalization since |
396 | /// any illegally typed nodes generated after this point will not experience |
397 | /// type legalization. |
398 | bool NewNodesMustHaveLegalTypes = false; |
399 | |
400 | private: |
401 | /// DAGUpdateListener is a friend so it can manipulate the listener stack. |
402 | friend struct DAGUpdateListener; |
403 | |
404 | /// Linked list of registered DAGUpdateListener instances. |
405 | /// This stack is maintained by DAGUpdateListener RAII. |
406 | DAGUpdateListener *UpdateListeners = nullptr; |
407 | |
408 | /// Implementation of setSubgraphColor. |
409 | /// Return whether we had to truncate the search. |
410 | bool setSubgraphColorHelper(SDNode *N, const char *Color, |
411 | DenseSet<SDNode *> &visited, |
412 | int level, bool &printed); |
413 | |
414 | template <typename SDNodeT, typename... ArgTypes> |
415 | SDNodeT *newSDNode(ArgTypes &&... Args) { |
416 | return new (NodeAllocator.template Allocate<SDNodeT>()) |
417 | SDNodeT(std::forward<ArgTypes>(Args)...); |
418 | } |
419 | |
420 | /// Build a synthetic SDNodeT with the given args and extract its subclass |
421 | /// data as an integer (e.g. for use in a folding set). |
422 | /// |
423 | /// The args to this function are the same as the args to SDNodeT's |
424 | /// constructor, except the second arg (assumed to be a const DebugLoc&) is |
425 | /// omitted. |
426 | template <typename SDNodeT, typename... ArgTypes> |
427 | static uint16_t getSyntheticNodeSubclassData(unsigned IROrder, |
428 | ArgTypes &&... Args) { |
429 | // The compiler can reduce this expression to a constant iff we pass an |
430 | // empty DebugLoc. Thankfully, the debug location doesn't have any bearing |
431 | // on the subclass data. |
432 | return SDNodeT(IROrder, DebugLoc(), std::forward<ArgTypes>(Args)...) |
433 | .getRawSubclassData(); |
434 | } |
435 | |
436 | template <typename SDNodeTy> |
437 | static uint16_t getSyntheticNodeSubclassData(unsigned Opc, unsigned Order, |
438 | SDVTList VTs, EVT MemoryVT, |
439 | MachineMemOperand *MMO) { |
440 | return SDNodeTy(Opc, Order, DebugLoc(), VTs, MemoryVT, MMO) |
441 | .getRawSubclassData(); |
442 | } |
443 | |
444 | void createOperands(SDNode *Node, ArrayRef<SDValue> Vals); |
445 | |
446 | void removeOperands(SDNode *Node) { |
447 | if (!Node->OperandList) |
448 | return; |
449 | OperandRecycler.deallocate( |
450 | Cap: ArrayRecycler<SDUse>::Capacity::get(N: Node->NumOperands), |
451 | Ptr: Node->OperandList); |
452 | Node->NumOperands = 0; |
453 | Node->OperandList = nullptr; |
454 | } |
455 | void CreateTopologicalOrder(std::vector<SDNode*>& Order); |
456 | |
457 | public: |
458 | // Maximum depth for recursive analysis such as computeKnownBits, etc. |
459 | static constexpr unsigned MaxRecursionDepth = 6; |
460 | |
461 | // Returns the maximum steps for SDNode->hasPredecessor() like searches. |
462 | LLVM_ABI static unsigned getHasPredecessorMaxSteps(); |
463 | |
464 | LLVM_ABI explicit SelectionDAG(const TargetMachine &TM, CodeGenOptLevel); |
465 | SelectionDAG(const SelectionDAG &) = delete; |
466 | SelectionDAG &operator=(const SelectionDAG &) = delete; |
467 | LLVM_ABI ~SelectionDAG(); |
468 | |
469 | /// Prepare this SelectionDAG to process code in the given MachineFunction. |
470 | LLVM_ABI void init(MachineFunction &NewMF, OptimizationRemarkEmitter &NewORE, |
471 | Pass *PassPtr, const TargetLibraryInfo *LibraryInfo, |
472 | UniformityInfo *UA, ProfileSummaryInfo *PSIin, |
473 | BlockFrequencyInfo *BFIin, MachineModuleInfo &MMI, |
474 | FunctionVarLocs const *FnVarLocs); |
475 | |
476 | void init(MachineFunction &NewMF, OptimizationRemarkEmitter &NewORE, |
477 | MachineFunctionAnalysisManager &AM, |
478 | const TargetLibraryInfo *LibraryInfo, UniformityInfo *UA, |
479 | ProfileSummaryInfo *PSIin, BlockFrequencyInfo *BFIin, |
480 | MachineModuleInfo &MMI, FunctionVarLocs const *FnVarLocs) { |
481 | init(NewMF, NewORE, PassPtr: nullptr, LibraryInfo, UA, PSIin, BFIin, MMI, FnVarLocs); |
482 | MFAM = &AM; |
483 | } |
484 | |
485 | void setFunctionLoweringInfo(FunctionLoweringInfo * FuncInfo) { |
486 | FLI = FuncInfo; |
487 | } |
488 | |
489 | /// Clear state and free memory necessary to make this |
490 | /// SelectionDAG ready to process a new block. |
491 | LLVM_ABI void clear(); |
492 | |
493 | MachineFunction &getMachineFunction() const { return *MF; } |
494 | const Pass *getPass() const { return SDAGISelPass; } |
495 | MachineFunctionAnalysisManager *getMFAM() { return MFAM; } |
496 | |
497 | CodeGenOptLevel getOptLevel() const { return OptLevel; } |
498 | const DataLayout &getDataLayout() const { return MF->getDataLayout(); } |
499 | const TargetMachine &getTarget() const { return TM; } |
500 | const TargetSubtargetInfo &getSubtarget() const { return MF->getSubtarget(); } |
501 | template <typename STC> const STC &getSubtarget() const { |
502 | return MF->getSubtarget<STC>(); |
503 | } |
504 | const TargetLowering &getTargetLoweringInfo() const { return *TLI; } |
505 | const TargetLibraryInfo &getLibInfo() const { return *LibInfo; } |
506 | const SelectionDAGTargetInfo &getSelectionDAGInfo() const { return *TSI; } |
507 | const UniformityInfo *getUniformityInfo() const { return UA; } |
508 | /// Returns the result of the AssignmentTrackingAnalysis pass if it's |
509 | /// available, otherwise return nullptr. |
510 | const FunctionVarLocs *getFunctionVarLocs() const { return FnVarLocs; } |
511 | LLVMContext *getContext() const { return Context; } |
512 | OptimizationRemarkEmitter &getORE() const { return *ORE; } |
513 | ProfileSummaryInfo *getPSI() const { return PSI; } |
514 | BlockFrequencyInfo *getBFI() const { return BFI; } |
515 | MachineModuleInfo *getMMI() const { return MMI; } |
516 | |
517 | FlagInserter *getFlagInserter() { return Inserter; } |
518 | void setFlagInserter(FlagInserter *FI) { Inserter = FI; } |
519 | |
520 | /// Just dump dot graph to a user-provided path and title. |
521 | /// This doesn't open the dot viewer program and |
522 | /// helps visualization when outside debugging session. |
523 | /// FileName expects absolute path. If provided |
524 | /// without any path separators then the file |
525 | /// will be created in the current directory. |
526 | /// Error will be emitted if the path is insane. |
527 | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
528 | LLVM_DUMP_METHOD void dumpDotGraph(const Twine &FileName, const Twine &Title); |
529 | #endif |
530 | |
531 | /// Pop up a GraphViz/gv window with the DAG rendered using 'dot'. |
532 | LLVM_ABI void viewGraph(const std::string &Title); |
533 | LLVM_ABI void viewGraph(); |
534 | |
535 | #if LLVM_ENABLE_ABI_BREAKING_CHECKS |
536 | std::map<const SDNode *, std::string> NodeGraphAttrs; |
537 | #endif |
538 | |
539 | /// Clear all previously defined node graph attributes. |
540 | /// Intended to be used from a debugging tool (eg. gdb). |
541 | LLVM_ABI void clearGraphAttrs(); |
542 | |
543 | /// Set graph attributes for a node. (eg. "color=red".) |
544 | LLVM_ABI void setGraphAttrs(const SDNode *N, const char *Attrs); |
545 | |
546 | /// Get graph attributes for a node. (eg. "color=red".) |
547 | /// Used from getNodeAttributes. |
548 | LLVM_ABI std::string getGraphAttrs(const SDNode *N) const; |
549 | |
550 | /// Convenience for setting node color attribute. |
551 | LLVM_ABI void setGraphColor(const SDNode *N, const char *Color); |
552 | |
553 | /// Convenience for setting subgraph color attribute. |
554 | LLVM_ABI void setSubgraphColor(SDNode *N, const char *Color); |
555 | |
556 | using allnodes_const_iterator = ilist<SDNode>::const_iterator; |
557 | |
558 | allnodes_const_iterator allnodes_begin() const { return AllNodes.begin(); } |
559 | allnodes_const_iterator allnodes_end() const { return AllNodes.end(); } |
560 | |
561 | using allnodes_iterator = ilist<SDNode>::iterator; |
562 | |
563 | allnodes_iterator allnodes_begin() { return AllNodes.begin(); } |
564 | allnodes_iterator allnodes_end() { return AllNodes.end(); } |
565 | |
566 | ilist<SDNode>::size_type allnodes_size() const { |
567 | return AllNodes.size(); |
568 | } |
569 | |
570 | iterator_range<allnodes_iterator> allnodes() { |
571 | return make_range(x: allnodes_begin(), y: allnodes_end()); |
572 | } |
573 | iterator_range<allnodes_const_iterator> allnodes() const { |
574 | return make_range(x: allnodes_begin(), y: allnodes_end()); |
575 | } |
576 | |
577 | /// Return the root tag of the SelectionDAG. |
578 | const SDValue &getRoot() const { return Root; } |
579 | |
580 | /// Return the token chain corresponding to the entry of the function. |
581 | SDValue getEntryNode() const { |
582 | return SDValue(const_cast<SDNode *>(&EntryNode), 0); |
583 | } |
584 | |
585 | /// Set the current root tag of the SelectionDAG. |
586 | /// |
587 | const SDValue &setRoot(SDValue N) { |
588 | assert((!N.getNode() || N.getValueType() == MVT::Other) && |
589 | "DAG root value is not a chain!"); |
590 | if (N.getNode()) |
591 | checkForCycles(N: N.getNode(), DAG: this); |
592 | Root = N; |
593 | if (N.getNode()) |
594 | checkForCycles(DAG: this); |
595 | return Root; |
596 | } |
597 | |
598 | #if !defined(NDEBUG) && LLVM_ENABLE_ABI_BREAKING_CHECKS |
599 | void VerifyDAGDivergence(); |
600 | #endif |
601 | |
602 | /// This iterates over the nodes in the SelectionDAG, folding |
603 | /// certain types of nodes together, or eliminating superfluous nodes. The |
604 | /// Level argument controls whether Combine is allowed to produce nodes and |
605 | /// types that are illegal on the target. |
606 | LLVM_ABI void Combine(CombineLevel Level, BatchAAResults *BatchAA, |
607 | CodeGenOptLevel OptLevel); |
608 | |
609 | /// This transforms the SelectionDAG into a SelectionDAG that |
610 | /// only uses types natively supported by the target. |
611 | /// Returns "true" if it made any changes. |
612 | /// |
613 | /// Note that this is an involved process that may invalidate pointers into |
614 | /// the graph. |
615 | LLVM_ABI bool LegalizeTypes(); |
616 | |
617 | /// This transforms the SelectionDAG into a SelectionDAG that is |
618 | /// compatible with the target instruction selector, as indicated by the |
619 | /// TargetLowering object. |
620 | /// |
621 | /// Note that this is an involved process that may invalidate pointers into |
622 | /// the graph. |
623 | LLVM_ABI void Legalize(); |
624 | |
625 | /// Transforms a SelectionDAG node and any operands to it into a node |
626 | /// that is compatible with the target instruction selector, as indicated by |
627 | /// the TargetLowering object. |
628 | /// |
629 | /// \returns true if \c N is a valid, legal node after calling this. |
630 | /// |
631 | /// This essentially runs a single recursive walk of the \c Legalize process |
632 | /// over the given node (and its operands). This can be used to incrementally |
633 | /// legalize the DAG. All of the nodes which are directly replaced, |
634 | /// potentially including N, are added to the output parameter \c |
635 | /// UpdatedNodes so that the delta to the DAG can be understood by the |
636 | /// caller. |
637 | /// |
638 | /// When this returns false, N has been legalized in a way that make the |
639 | /// pointer passed in no longer valid. It may have even been deleted from the |
640 | /// DAG, and so it shouldn't be used further. When this returns true, the |
641 | /// N passed in is a legal node, and can be immediately processed as such. |
642 | /// This may still have done some work on the DAG, and will still populate |
643 | /// UpdatedNodes with any new nodes replacing those originally in the DAG. |
644 | LLVM_ABI bool LegalizeOp(SDNode *N, |
645 | SmallSetVector<SDNode *, 16> &UpdatedNodes); |
646 | |
647 | /// This transforms the SelectionDAG into a SelectionDAG |
648 | /// that only uses vector math operations supported by the target. This is |
649 | /// necessary as a separate step from Legalize because unrolling a vector |
650 | /// operation can introduce illegal types, which requires running |
651 | /// LegalizeTypes again. |
652 | /// |
653 | /// This returns true if it made any changes; in that case, LegalizeTypes |
654 | /// is called again before Legalize. |
655 | /// |
656 | /// Note that this is an involved process that may invalidate pointers into |
657 | /// the graph. |
658 | LLVM_ABI bool LegalizeVectors(); |
659 | |
660 | /// This method deletes all unreachable nodes in the SelectionDAG. |
661 | LLVM_ABI void RemoveDeadNodes(); |
662 | |
663 | /// Remove the specified node from the system. This node must |
664 | /// have no referrers. |
665 | LLVM_ABI void DeleteNode(SDNode *N); |
666 | |
667 | /// Return an SDVTList that represents the list of values specified. |
668 | LLVM_ABI SDVTList getVTList(EVT VT); |
669 | LLVM_ABI SDVTList getVTList(EVT VT1, EVT VT2); |
670 | LLVM_ABI SDVTList getVTList(EVT VT1, EVT VT2, EVT VT3); |
671 | LLVM_ABI SDVTList getVTList(EVT VT1, EVT VT2, EVT VT3, EVT VT4); |
672 | LLVM_ABI SDVTList getVTList(ArrayRef<EVT> VTs); |
673 | |
674 | //===--------------------------------------------------------------------===// |
675 | // Node creation methods. |
676 | |
677 | /// Create a ConstantSDNode wrapping a constant value. |
678 | /// If VT is a vector type, the constant is splatted into a BUILD_VECTOR. |
679 | /// |
680 | /// If only legal types can be produced, this does the necessary |
681 | /// transformations (e.g., if the vector element type is illegal). |
682 | /// @{ |
683 | LLVM_ABI SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT, |
684 | bool isTarget = false, bool isOpaque = false); |
685 | LLVM_ABI SDValue getConstant(const APInt &Val, const SDLoc &DL, EVT VT, |
686 | bool isTarget = false, bool isOpaque = false); |
687 | |
688 | LLVM_ABI SDValue getSignedConstant(int64_t Val, const SDLoc &DL, EVT VT, |
689 | bool isTarget = false, |
690 | bool isOpaque = false); |
691 | |
692 | LLVM_ABI SDValue getAllOnesConstant(const SDLoc &DL, EVT VT, |
693 | bool IsTarget = false, |
694 | bool IsOpaque = false); |
695 | |
696 | LLVM_ABI SDValue getConstant(const ConstantInt &Val, const SDLoc &DL, EVT VT, |
697 | bool isTarget = false, bool isOpaque = false); |
698 | LLVM_ABI SDValue getIntPtrConstant(uint64_t Val, const SDLoc &DL, |
699 | bool isTarget = false); |
700 | LLVM_ABI SDValue getShiftAmountConstant(uint64_t Val, EVT VT, |
701 | const SDLoc &DL); |
702 | LLVM_ABI SDValue getShiftAmountConstant(const APInt &Val, EVT VT, |
703 | const SDLoc &DL); |
704 | LLVM_ABI SDValue getVectorIdxConstant(uint64_t Val, const SDLoc &DL, |
705 | bool isTarget = false); |
706 | |
707 | SDValue getTargetConstant(uint64_t Val, const SDLoc &DL, EVT VT, |
708 | bool isOpaque = false) { |
709 | return getConstant(Val, DL, VT, isTarget: true, isOpaque); |
710 | } |
711 | SDValue getTargetConstant(const APInt &Val, const SDLoc &DL, EVT VT, |
712 | bool isOpaque = false) { |
713 | return getConstant(Val, DL, VT, isTarget: true, isOpaque); |
714 | } |
715 | SDValue getTargetConstant(const ConstantInt &Val, const SDLoc &DL, EVT VT, |
716 | bool isOpaque = false) { |
717 | return getConstant(Val, DL, VT, isTarget: true, isOpaque); |
718 | } |
719 | SDValue getSignedTargetConstant(int64_t Val, const SDLoc &DL, EVT VT, |
720 | bool isOpaque = false) { |
721 | return getSignedConstant(Val, DL, VT, isTarget: true, isOpaque); |
722 | } |
723 | |
724 | /// Create a true or false constant of type \p VT using the target's |
725 | /// BooleanContent for type \p OpVT. |
726 | LLVM_ABI SDValue getBoolConstant(bool V, const SDLoc &DL, EVT VT, EVT OpVT); |
727 | /// @} |
728 | |
729 | /// Create a ConstantFPSDNode wrapping a constant value. |
730 | /// If VT is a vector type, the constant is splatted into a BUILD_VECTOR. |
731 | /// |
732 | /// If only legal types can be produced, this does the necessary |
733 | /// transformations (e.g., if the vector element type is illegal). |
734 | /// The forms that take a double should only be used for simple constants |
735 | /// that can be exactly represented in VT. No checks are made. |
736 | /// @{ |
737 | LLVM_ABI SDValue getConstantFP(double Val, const SDLoc &DL, EVT VT, |
738 | bool isTarget = false); |
739 | LLVM_ABI SDValue getConstantFP(const APFloat &Val, const SDLoc &DL, EVT VT, |
740 | bool isTarget = false); |
741 | LLVM_ABI SDValue getConstantFP(const ConstantFP &V, const SDLoc &DL, EVT VT, |
742 | bool isTarget = false); |
743 | SDValue getTargetConstantFP(double Val, const SDLoc &DL, EVT VT) { |
744 | return getConstantFP(Val, DL, VT, isTarget: true); |
745 | } |
746 | SDValue getTargetConstantFP(const APFloat &Val, const SDLoc &DL, EVT VT) { |
747 | return getConstantFP(Val, DL, VT, isTarget: true); |
748 | } |
749 | SDValue getTargetConstantFP(const ConstantFP &Val, const SDLoc &DL, EVT VT) { |
750 | return getConstantFP(V: Val, DL, VT, isTarget: true); |
751 | } |
752 | /// @} |
753 | |
754 | LLVM_ABI SDValue getGlobalAddress(const GlobalValue *GV, const SDLoc &DL, |
755 | EVT VT, int64_t offset = 0, |
756 | bool isTargetGA = false, |
757 | unsigned TargetFlags = 0); |
758 | SDValue getTargetGlobalAddress(const GlobalValue *GV, const SDLoc &DL, EVT VT, |
759 | int64_t offset = 0, unsigned TargetFlags = 0) { |
760 | return getGlobalAddress(GV, DL, VT, offset, isTargetGA: true, TargetFlags); |
761 | } |
762 | LLVM_ABI SDValue getFrameIndex(int FI, EVT VT, bool isTarget = false); |
763 | SDValue getTargetFrameIndex(int FI, EVT VT) { |
764 | return getFrameIndex(FI, VT, isTarget: true); |
765 | } |
766 | LLVM_ABI SDValue getJumpTable(int JTI, EVT VT, bool isTarget = false, |
767 | unsigned TargetFlags = 0); |
768 | SDValue getTargetJumpTable(int JTI, EVT VT, unsigned TargetFlags = 0) { |
769 | return getJumpTable(JTI, VT, isTarget: true, TargetFlags); |
770 | } |
771 | LLVM_ABI SDValue getJumpTableDebugInfo(int JTI, SDValue Chain, |
772 | const SDLoc &DL); |
773 | LLVM_ABI SDValue getConstantPool(const Constant *C, EVT VT, |
774 | MaybeAlign Align = std::nullopt, |
775 | int Offs = 0, bool isT = false, |
776 | unsigned TargetFlags = 0); |
777 | SDValue getTargetConstantPool(const Constant *C, EVT VT, |
778 | MaybeAlign Align = std::nullopt, int Offset = 0, |
779 | unsigned TargetFlags = 0) { |
780 | return getConstantPool(C, VT, Align, Offs: Offset, isT: true, TargetFlags); |
781 | } |
782 | LLVM_ABI SDValue getConstantPool(MachineConstantPoolValue *C, EVT VT, |
783 | MaybeAlign Align = std::nullopt, |
784 | int Offs = 0, bool isT = false, |
785 | unsigned TargetFlags = 0); |
786 | SDValue getTargetConstantPool(MachineConstantPoolValue *C, EVT VT, |
787 | MaybeAlign Align = std::nullopt, int Offset = 0, |
788 | unsigned TargetFlags = 0) { |
789 | return getConstantPool(C, VT, Align, Offs: Offset, isT: true, TargetFlags); |
790 | } |
791 | // When generating a branch to a BB, we don't in general know enough |
792 | // to provide debug info for the BB at that time, so keep this one around. |
793 | LLVM_ABI SDValue getBasicBlock(MachineBasicBlock *MBB); |
794 | LLVM_ABI SDValue getExternalSymbol(const char *Sym, EVT VT); |
795 | LLVM_ABI SDValue getTargetExternalSymbol(const char *Sym, EVT VT, |
796 | unsigned TargetFlags = 0); |
797 | LLVM_ABI SDValue getMCSymbol(MCSymbol *Sym, EVT VT); |
798 | |
799 | LLVM_ABI SDValue getValueType(EVT); |
800 | LLVM_ABI SDValue getRegister(Register Reg, EVT VT); |
801 | LLVM_ABI SDValue getRegisterMask(const uint32_t *RegMask); |
802 | LLVM_ABI SDValue getEHLabel(const SDLoc &dl, SDValue Root, MCSymbol *Label); |
803 | LLVM_ABI SDValue getLabelNode(unsigned Opcode, const SDLoc &dl, SDValue Root, |
804 | MCSymbol *Label); |
805 | LLVM_ABI SDValue getBlockAddress(const BlockAddress *BA, EVT VT, |
806 | int64_t Offset = 0, bool isTarget = false, |
807 | unsigned TargetFlags = 0); |
808 | SDValue getTargetBlockAddress(const BlockAddress *BA, EVT VT, |
809 | int64_t Offset = 0, unsigned TargetFlags = 0) { |
810 | return getBlockAddress(BA, VT, Offset, isTarget: true, TargetFlags); |
811 | } |
812 | |
813 | SDValue getCopyToReg(SDValue Chain, const SDLoc &dl, Register Reg, |
814 | SDValue N) { |
815 | return getNode(ISD::CopyToReg, dl, MVT::Other, Chain, |
816 | getRegister(Reg, N.getValueType()), N); |
817 | } |
818 | |
819 | // This version of the getCopyToReg method takes an extra operand, which |
820 | // indicates that there is potentially an incoming glue value (if Glue is not |
821 | // null) and that there should be a glue result. |
822 | SDValue getCopyToReg(SDValue Chain, const SDLoc &dl, Register Reg, SDValue N, |
823 | SDValue Glue) { |
824 | SDVTList VTs = getVTList(MVT::Other, MVT::Glue); |
825 | SDValue Ops[] = { Chain, getRegister(Reg, VT: N.getValueType()), N, Glue }; |
826 | return getNode(Opcode: ISD::CopyToReg, DL: dl, VTList: VTs, |
827 | Ops: ArrayRef(Ops, Glue.getNode() ? 4 : 3)); |
828 | } |
829 | |
830 | // Similar to last getCopyToReg() except parameter Reg is a SDValue |
831 | SDValue getCopyToReg(SDValue Chain, const SDLoc &dl, SDValue Reg, SDValue N, |
832 | SDValue Glue) { |
833 | SDVTList VTs = getVTList(MVT::Other, MVT::Glue); |
834 | SDValue Ops[] = { Chain, Reg, N, Glue }; |
835 | return getNode(Opcode: ISD::CopyToReg, DL: dl, VTList: VTs, |
836 | Ops: ArrayRef(Ops, Glue.getNode() ? 4 : 3)); |
837 | } |
838 | |
839 | SDValue getCopyFromReg(SDValue Chain, const SDLoc &dl, Register Reg, EVT VT) { |
840 | SDVTList VTs = getVTList(VT, MVT::Other); |
841 | SDValue Ops[] = { Chain, getRegister(Reg, VT) }; |
842 | return getNode(Opcode: ISD::CopyFromReg, DL: dl, VTList: VTs, Ops); |
843 | } |
844 | |
845 | // This version of the getCopyFromReg method takes an extra operand, which |
846 | // indicates that there is potentially an incoming glue value (if Glue is not |
847 | // null) and that there should be a glue result. |
848 | SDValue getCopyFromReg(SDValue Chain, const SDLoc &dl, Register Reg, EVT VT, |
849 | SDValue Glue) { |
850 | SDVTList VTs = getVTList(VT, MVT::Other, MVT::Glue); |
851 | SDValue Ops[] = { Chain, getRegister(Reg, VT), Glue }; |
852 | return getNode(Opcode: ISD::CopyFromReg, DL: dl, VTList: VTs, |
853 | Ops: ArrayRef(Ops, Glue.getNode() ? 3 : 2)); |
854 | } |
855 | |
856 | LLVM_ABI SDValue getCondCode(ISD::CondCode Cond); |
857 | |
858 | /// Return an ISD::VECTOR_SHUFFLE node. The number of elements in VT, |
859 | /// which must be a vector type, must match the number of mask elements |
860 | /// NumElts. An integer mask element equal to -1 is treated as undefined. |
861 | LLVM_ABI SDValue getVectorShuffle(EVT VT, const SDLoc &dl, SDValue N1, |
862 | SDValue N2, ArrayRef<int> Mask); |
863 | |
864 | /// Return an ISD::BUILD_VECTOR node. The number of elements in VT, |
865 | /// which must be a vector type, must match the number of operands in Ops. |
866 | /// The operands must have the same type as (or, for integers, a type wider |
867 | /// than) VT's element type. |
868 | SDValue getBuildVector(EVT VT, const SDLoc &DL, ArrayRef<SDValue> Ops) { |
869 | // VerifySDNode (via InsertNode) checks BUILD_VECTOR later. |
870 | return getNode(Opcode: ISD::BUILD_VECTOR, DL, VT, Ops); |
871 | } |
872 | |
873 | /// Return an ISD::BUILD_VECTOR node. The number of elements in VT, |
874 | /// which must be a vector type, must match the number of operands in Ops. |
875 | /// The operands must have the same type as (or, for integers, a type wider |
876 | /// than) VT's element type. |
877 | SDValue getBuildVector(EVT VT, const SDLoc &DL, ArrayRef<SDUse> Ops) { |
878 | // VerifySDNode (via InsertNode) checks BUILD_VECTOR later. |
879 | return getNode(Opcode: ISD::BUILD_VECTOR, DL, VT, Ops); |
880 | } |
881 | |
882 | /// Return a splat ISD::BUILD_VECTOR node, consisting of Op splatted to all |
883 | /// elements. VT must be a vector type. Op's type must be the same as (or, |
884 | /// for integers, a type wider than) VT's element type. |
885 | SDValue getSplatBuildVector(EVT VT, const SDLoc &DL, SDValue Op) { |
886 | // VerifySDNode (via InsertNode) checks BUILD_VECTOR later. |
887 | if (Op.isUndef()) { |
888 | assert((VT.getVectorElementType() == Op.getValueType() || |
889 | (VT.isInteger() && |
890 | VT.getVectorElementType().bitsLE(Op.getValueType()))) && |
891 | "A splatted value must have a width equal or (for integers) " |
892 | "greater than the vector element type!"); |
893 | return getNode(Opcode: ISD::UNDEF, DL: SDLoc(), VT); |
894 | } |
895 | |
896 | SmallVector<SDValue, 16> Ops(VT.getVectorNumElements(), Op); |
897 | return getNode(Opcode: ISD::BUILD_VECTOR, DL, VT, Ops); |
898 | } |
899 | |
900 | // Return a splat ISD::SPLAT_VECTOR node, consisting of Op splatted to all |
901 | // elements. |
902 | SDValue getSplatVector(EVT VT, const SDLoc &DL, SDValue Op) { |
903 | if (Op.isUndef()) { |
904 | assert((VT.getVectorElementType() == Op.getValueType() || |
905 | (VT.isInteger() && |
906 | VT.getVectorElementType().bitsLE(Op.getValueType()))) && |
907 | "A splatted value must have a width equal or (for integers) " |
908 | "greater than the vector element type!"); |
909 | return getNode(Opcode: ISD::UNDEF, DL: SDLoc(), VT); |
910 | } |
911 | return getNode(Opcode: ISD::SPLAT_VECTOR, DL, VT, Operand: Op); |
912 | } |
913 | |
914 | /// Returns a node representing a splat of one value into all lanes |
915 | /// of the provided vector type. This is a utility which returns |
916 | /// either a BUILD_VECTOR or SPLAT_VECTOR depending on the |
917 | /// scalability of the desired vector type. |
918 | SDValue getSplat(EVT VT, const SDLoc &DL, SDValue Op) { |
919 | assert(VT.isVector() && "Can't splat to non-vector type"); |
920 | return VT.isScalableVector() ? |
921 | getSplatVector(VT, DL, Op) : getSplatBuildVector(VT, DL, Op); |
922 | } |
923 | |
924 | /// Returns a vector of type ResVT whose elements contain the linear sequence |
925 | /// <0, Step, Step * 2, Step * 3, ...> |
926 | LLVM_ABI SDValue getStepVector(const SDLoc &DL, EVT ResVT, |
927 | const APInt &StepVal); |
928 | |
929 | /// Returns a vector of type ResVT whose elements contain the linear sequence |
930 | /// <0, 1, 2, 3, ...> |
931 | LLVM_ABI SDValue getStepVector(const SDLoc &DL, EVT ResVT); |
932 | |
933 | /// Returns an ISD::VECTOR_SHUFFLE node semantically equivalent to |
934 | /// the shuffle node in input but with swapped operands. |
935 | /// |
936 | /// Example: shuffle A, B, <0,5,2,7> -> shuffle B, A, <4,1,6,3> |
937 | LLVM_ABI SDValue getCommutedVectorShuffle(const ShuffleVectorSDNode &SV); |
938 | |
939 | /// Extract element at \p Idx from \p Vec. See EXTRACT_VECTOR_ELT |
940 | /// description for result type handling. |
941 | SDValue getExtractVectorElt(const SDLoc &DL, EVT VT, SDValue Vec, |
942 | unsigned Idx) { |
943 | return getNode(Opcode: ISD::EXTRACT_VECTOR_ELT, DL, VT, N1: Vec, |
944 | N2: getVectorIdxConstant(Val: Idx, DL)); |
945 | } |
946 | |
947 | /// Insert \p Elt into \p Vec at offset \p Idx. See INSERT_VECTOR_ELT |
948 | /// description for element type handling. |
949 | SDValue getInsertVectorElt(const SDLoc &DL, SDValue Vec, SDValue Elt, |
950 | unsigned Idx) { |
951 | return getNode(Opcode: ISD::INSERT_VECTOR_ELT, DL, VT: Vec.getValueType(), N1: Vec, N2: Elt, |
952 | N3: getVectorIdxConstant(Val: Idx, DL)); |
953 | } |
954 | |
955 | /// Insert \p SubVec at the \p Idx element of \p Vec. |
956 | SDValue getInsertSubvector(const SDLoc &DL, SDValue Vec, SDValue SubVec, |
957 | unsigned Idx) { |
958 | return getNode(Opcode: ISD::INSERT_SUBVECTOR, DL, VT: Vec.getValueType(), N1: Vec, N2: SubVec, |
959 | N3: getVectorIdxConstant(Val: Idx, DL)); |
960 | } |
961 | |
962 | /// Return the \p VT typed sub-vector of \p Vec at \p Idx |
963 | SDValue getExtractSubvector(const SDLoc &DL, EVT VT, SDValue Vec, |
964 | unsigned Idx) { |
965 | return getNode(Opcode: ISD::EXTRACT_SUBVECTOR, DL, VT, N1: Vec, |
966 | N2: getVectorIdxConstant(Val: Idx, DL)); |
967 | } |
968 | |
969 | /// Convert Op, which must be of float type, to the |
970 | /// float type VT, by either extending or rounding (by truncation). |
971 | LLVM_ABI SDValue getFPExtendOrRound(SDValue Op, const SDLoc &DL, EVT VT); |
972 | |
973 | /// Convert Op, which must be a STRICT operation of float type, to the |
974 | /// float type VT, by either extending or rounding (by truncation). |
975 | LLVM_ABI std::pair<SDValue, SDValue> |
976 | getStrictFPExtendOrRound(SDValue Op, SDValue Chain, const SDLoc &DL, EVT VT); |
977 | |
978 | /// Convert *_EXTEND_VECTOR_INREG to *_EXTEND opcode. |
979 | static unsigned getOpcode_EXTEND(unsigned Opcode) { |
980 | switch (Opcode) { |
981 | case ISD::ANY_EXTEND: |
982 | case ISD::ANY_EXTEND_VECTOR_INREG: |
983 | return ISD::ANY_EXTEND; |
984 | case ISD::ZERO_EXTEND: |
985 | case ISD::ZERO_EXTEND_VECTOR_INREG: |
986 | return ISD::ZERO_EXTEND; |
987 | case ISD::SIGN_EXTEND: |
988 | case ISD::SIGN_EXTEND_VECTOR_INREG: |
989 | return ISD::SIGN_EXTEND; |
990 | } |
991 | llvm_unreachable("Unknown opcode"); |
992 | } |
993 | |
994 | /// Convert *_EXTEND to *_EXTEND_VECTOR_INREG opcode. |
995 | static unsigned getOpcode_EXTEND_VECTOR_INREG(unsigned Opcode) { |
996 | switch (Opcode) { |
997 | case ISD::ANY_EXTEND: |
998 | case ISD::ANY_EXTEND_VECTOR_INREG: |
999 | return ISD::ANY_EXTEND_VECTOR_INREG; |
1000 | case ISD::ZERO_EXTEND: |
1001 | case ISD::ZERO_EXTEND_VECTOR_INREG: |
1002 | return ISD::ZERO_EXTEND_VECTOR_INREG; |
1003 | case ISD::SIGN_EXTEND: |
1004 | case ISD::SIGN_EXTEND_VECTOR_INREG: |
1005 | return ISD::SIGN_EXTEND_VECTOR_INREG; |
1006 | } |
1007 | llvm_unreachable("Unknown opcode"); |
1008 | } |
1009 | |
1010 | /// Convert Op, which must be of integer type, to the |
1011 | /// integer type VT, by either any-extending or truncating it. |
1012 | LLVM_ABI SDValue getAnyExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT); |
1013 | |
1014 | /// Convert Op, which must be of integer type, to the |
1015 | /// integer type VT, by either sign-extending or truncating it. |
1016 | LLVM_ABI SDValue getSExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT); |
1017 | |
1018 | /// Convert Op, which must be of integer type, to the |
1019 | /// integer type VT, by either zero-extending or truncating it. |
1020 | LLVM_ABI SDValue getZExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT); |
1021 | |
1022 | /// Convert Op, which must be of integer type, to the |
1023 | /// integer type VT, by either any/sign/zero-extending (depending on IsAny / |
1024 | /// IsSigned) or truncating it. |
1025 | SDValue getExtOrTrunc(SDValue Op, const SDLoc &DL, |
1026 | EVT VT, unsigned Opcode) { |
1027 | switch(Opcode) { |
1028 | case ISD::ANY_EXTEND: |
1029 | return getAnyExtOrTrunc(Op, DL, VT); |
1030 | case ISD::ZERO_EXTEND: |
1031 | return getZExtOrTrunc(Op, DL, VT); |
1032 | case ISD::SIGN_EXTEND: |
1033 | return getSExtOrTrunc(Op, DL, VT); |
1034 | } |
1035 | llvm_unreachable("Unsupported opcode"); |
1036 | } |
1037 | |
1038 | /// Convert Op, which must be of integer type, to the |
1039 | /// integer type VT, by either sign/zero-extending (depending on IsSigned) or |
1040 | /// truncating it. |
1041 | SDValue getExtOrTrunc(bool IsSigned, SDValue Op, const SDLoc &DL, EVT VT) { |
1042 | return IsSigned ? getSExtOrTrunc(Op, DL, VT) : getZExtOrTrunc(Op, DL, VT); |
1043 | } |
1044 | |
1045 | /// Convert Op, which must be of integer type, to the |
1046 | /// integer type VT, by first bitcasting (from potential vector) to |
1047 | /// corresponding scalar type then either any-extending or truncating it. |
1048 | LLVM_ABI SDValue getBitcastedAnyExtOrTrunc(SDValue Op, const SDLoc &DL, |
1049 | EVT VT); |
1050 | |
1051 | /// Convert Op, which must be of integer type, to the |
1052 | /// integer type VT, by first bitcasting (from potential vector) to |
1053 | /// corresponding scalar type then either sign-extending or truncating it. |
1054 | LLVM_ABI SDValue getBitcastedSExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT); |
1055 | |
1056 | /// Convert Op, which must be of integer type, to the |
1057 | /// integer type VT, by first bitcasting (from potential vector) to |
1058 | /// corresponding scalar type then either zero-extending or truncating it. |
1059 | LLVM_ABI SDValue getBitcastedZExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT); |
1060 | |
1061 | /// Return the expression required to zero extend the Op |
1062 | /// value assuming it was the smaller SrcTy value. |
1063 | LLVM_ABI SDValue getZeroExtendInReg(SDValue Op, const SDLoc &DL, EVT VT); |
1064 | |
1065 | /// Return the expression required to zero extend the Op |
1066 | /// value assuming it was the smaller SrcTy value. |
1067 | LLVM_ABI SDValue getVPZeroExtendInReg(SDValue Op, SDValue Mask, SDValue EVL, |
1068 | const SDLoc &DL, EVT VT); |
1069 | |
1070 | /// Convert Op, which must be of integer type, to the integer type VT, by |
1071 | /// either truncating it or performing either zero or sign extension as |
1072 | /// appropriate extension for the pointer's semantics. |
1073 | LLVM_ABI SDValue getPtrExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT); |
1074 | |
1075 | /// Return the expression required to extend the Op as a pointer value |
1076 | /// assuming it was the smaller SrcTy value. This may be either a zero extend |
1077 | /// or a sign extend. |
1078 | LLVM_ABI SDValue getPtrExtendInReg(SDValue Op, const SDLoc &DL, EVT VT); |
1079 | |
1080 | /// Convert Op, which must be of integer type, to the integer type VT, |
1081 | /// by using an extension appropriate for the target's |
1082 | /// BooleanContent for type OpVT or truncating it. |
1083 | LLVM_ABI SDValue getBoolExtOrTrunc(SDValue Op, const SDLoc &SL, EVT VT, |
1084 | EVT OpVT); |
1085 | |
1086 | /// Create negative operation as (SUB 0, Val). |
1087 | LLVM_ABI SDValue getNegative(SDValue Val, const SDLoc &DL, EVT VT); |
1088 | |
1089 | /// Create a bitwise NOT operation as (XOR Val, -1). |
1090 | LLVM_ABI SDValue getNOT(const SDLoc &DL, SDValue Val, EVT VT); |
1091 | |
1092 | /// Create a logical NOT operation as (XOR Val, BooleanOne). |
1093 | LLVM_ABI SDValue getLogicalNOT(const SDLoc &DL, SDValue Val, EVT VT); |
1094 | |
1095 | /// Create a vector-predicated logical NOT operation as (VP_XOR Val, |
1096 | /// BooleanOne, Mask, EVL). |
1097 | LLVM_ABI SDValue getVPLogicalNOT(const SDLoc &DL, SDValue Val, SDValue Mask, |
1098 | SDValue EVL, EVT VT); |
1099 | |
1100 | /// Convert a vector-predicated Op, which must be an integer vector, to the |
1101 | /// vector-type VT, by performing either vector-predicated zext or truncating |
1102 | /// it. The Op will be returned as-is if Op and VT are vectors containing |
1103 | /// integer with same width. |
1104 | LLVM_ABI SDValue getVPZExtOrTrunc(const SDLoc &DL, EVT VT, SDValue Op, |
1105 | SDValue Mask, SDValue EVL); |
1106 | |
1107 | /// Convert a vector-predicated Op, which must be of integer type, to the |
1108 | /// vector-type integer type VT, by either truncating it or performing either |
1109 | /// vector-predicated zero or sign extension as appropriate extension for the |
1110 | /// pointer's semantics. This function just redirects to getVPZExtOrTrunc |
1111 | /// right now. |
1112 | LLVM_ABI SDValue getVPPtrExtOrTrunc(const SDLoc &DL, EVT VT, SDValue Op, |
1113 | SDValue Mask, SDValue EVL); |
1114 | |
1115 | /// Returns sum of the base pointer and offset. |
1116 | /// Unlike getObjectPtrOffset this does not set NoUnsignedWrap by default. |
1117 | LLVM_ABI SDValue |
1118 | getMemBasePlusOffset(SDValue Base, TypeSize Offset, const SDLoc &DL, |
1119 | const SDNodeFlags Flags = SDNodeFlags()); |
1120 | LLVM_ABI SDValue |
1121 | getMemBasePlusOffset(SDValue Base, SDValue Offset, const SDLoc &DL, |
1122 | const SDNodeFlags Flags = SDNodeFlags()); |
1123 | |
1124 | /// Create an add instruction with appropriate flags when used for |
1125 | /// addressing some offset of an object. i.e. if a load is split into multiple |
1126 | /// components, create an add nuw from the base pointer to the offset. |
1127 | SDValue getObjectPtrOffset(const SDLoc &SL, SDValue Ptr, TypeSize Offset) { |
1128 | return getMemBasePlusOffset(Base: Ptr, Offset, DL: SL, Flags: SDNodeFlags::NoUnsignedWrap); |
1129 | } |
1130 | |
1131 | SDValue getObjectPtrOffset(const SDLoc &SL, SDValue Ptr, SDValue Offset) { |
1132 | // The object itself can't wrap around the address space, so it shouldn't be |
1133 | // possible for the adds of the offsets to the split parts to overflow. |
1134 | return getMemBasePlusOffset(Base: Ptr, Offset, DL: SL, Flags: SDNodeFlags::NoUnsignedWrap); |
1135 | } |
1136 | |
1137 | /// Return a new CALLSEQ_START node, that starts new call frame, in which |
1138 | /// InSize bytes are set up inside CALLSEQ_START..CALLSEQ_END sequence and |
1139 | /// OutSize specifies part of the frame set up prior to the sequence. |
1140 | SDValue getCALLSEQ_START(SDValue Chain, uint64_t InSize, uint64_t OutSize, |
1141 | const SDLoc &DL) { |
1142 | SDVTList VTs = getVTList(MVT::Other, MVT::Glue); |
1143 | SDValue Ops[] = { Chain, |
1144 | getIntPtrConstant(Val: InSize, DL, isTarget: true), |
1145 | getIntPtrConstant(Val: OutSize, DL, isTarget: true) }; |
1146 | return getNode(Opcode: ISD::CALLSEQ_START, DL, VTList: VTs, Ops); |
1147 | } |
1148 | |
1149 | /// Return a new CALLSEQ_END node, which always must have a |
1150 | /// glue result (to ensure it's not CSE'd). |
1151 | /// CALLSEQ_END does not have a useful SDLoc. |
1152 | SDValue getCALLSEQ_END(SDValue Chain, SDValue Op1, SDValue Op2, |
1153 | SDValue InGlue, const SDLoc &DL) { |
1154 | SDVTList NodeTys = getVTList(MVT::Other, MVT::Glue); |
1155 | SmallVector<SDValue, 4> Ops; |
1156 | Ops.push_back(Elt: Chain); |
1157 | Ops.push_back(Elt: Op1); |
1158 | Ops.push_back(Elt: Op2); |
1159 | if (InGlue.getNode()) |
1160 | Ops.push_back(Elt: InGlue); |
1161 | return getNode(Opcode: ISD::CALLSEQ_END, DL, VTList: NodeTys, Ops); |
1162 | } |
1163 | |
1164 | SDValue getCALLSEQ_END(SDValue Chain, uint64_t Size1, uint64_t Size2, |
1165 | SDValue Glue, const SDLoc &DL) { |
1166 | return getCALLSEQ_END( |
1167 | Chain, Op1: getIntPtrConstant(Val: Size1, DL, /*isTarget=*/isTarget: true), |
1168 | Op2: getIntPtrConstant(Val: Size2, DL, /*isTarget=*/isTarget: true), InGlue: Glue, DL); |
1169 | } |
1170 | |
1171 | /// Return true if the result of this operation is always undefined. |
1172 | LLVM_ABI bool isUndef(unsigned Opcode, ArrayRef<SDValue> Ops); |
1173 | |
1174 | /// Return an UNDEF node. UNDEF does not have a useful SDLoc. |
1175 | SDValue getUNDEF(EVT VT) { |
1176 | return getNode(Opcode: ISD::UNDEF, DL: SDLoc(), VT); |
1177 | } |
1178 | |
1179 | /// Return a POISON node. POISON does not have a useful SDLoc. |
1180 | SDValue getPOISON(EVT VT) { return getNode(Opcode: ISD::POISON, DL: SDLoc(), VT); } |
1181 | |
1182 | /// Return a node that represents the runtime scaling 'MulImm * RuntimeVL'. |
1183 | LLVM_ABI SDValue getVScale(const SDLoc &DL, EVT VT, APInt MulImm, |
1184 | bool ConstantFold = true); |
1185 | |
1186 | LLVM_ABI SDValue getElementCount(const SDLoc &DL, EVT VT, ElementCount EC, |
1187 | bool ConstantFold = true); |
1188 | |
1189 | /// Return a GLOBAL_OFFSET_TABLE node. This does not have a useful SDLoc. |
1190 | SDValue getGLOBAL_OFFSET_TABLE(EVT VT) { |
1191 | return getNode(Opcode: ISD::GLOBAL_OFFSET_TABLE, DL: SDLoc(), VT); |
1192 | } |
1193 | |
1194 | /// Gets or creates the specified node. |
1195 | /// |
1196 | LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, |
1197 | ArrayRef<SDUse> Ops); |
1198 | LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, |
1199 | ArrayRef<SDValue> Ops, const SDNodeFlags Flags); |
1200 | LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, |
1201 | ArrayRef<EVT> ResultTys, ArrayRef<SDValue> Ops); |
1202 | LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList, |
1203 | ArrayRef<SDValue> Ops, const SDNodeFlags Flags); |
1204 | |
1205 | // Use flags from current flag inserter. |
1206 | LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, |
1207 | ArrayRef<SDValue> Ops); |
1208 | LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList, |
1209 | ArrayRef<SDValue> Ops); |
1210 | LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, |
1211 | SDValue Operand); |
1212 | LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1, |
1213 | SDValue N2); |
1214 | LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1, |
1215 | SDValue N2, SDValue N3); |
1216 | |
1217 | // Specialize based on number of operands. |
1218 | LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT); |
1219 | LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, |
1220 | SDValue Operand, const SDNodeFlags Flags); |
1221 | LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1, |
1222 | SDValue N2, const SDNodeFlags Flags); |
1223 | LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1, |
1224 | SDValue N2, SDValue N3, const SDNodeFlags Flags); |
1225 | LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1, |
1226 | SDValue N2, SDValue N3, SDValue N4); |
1227 | LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1, |
1228 | SDValue N2, SDValue N3, SDValue N4, |
1229 | const SDNodeFlags Flags); |
1230 | LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1, |
1231 | SDValue N2, SDValue N3, SDValue N4, SDValue N5); |
1232 | LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1, |
1233 | SDValue N2, SDValue N3, SDValue N4, SDValue N5, |
1234 | const SDNodeFlags Flags); |
1235 | |
1236 | // Specialize again based on number of operands for nodes with a VTList |
1237 | // rather than a single VT. |
1238 | LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList); |
1239 | LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList, |
1240 | SDValue N); |
1241 | LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList, |
1242 | SDValue N1, SDValue N2); |
1243 | LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList, |
1244 | SDValue N1, SDValue N2, SDValue N3); |
1245 | LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList, |
1246 | SDValue N1, SDValue N2, SDValue N3, SDValue N4); |
1247 | LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList, |
1248 | SDValue N1, SDValue N2, SDValue N3, SDValue N4, |
1249 | SDValue N5); |
1250 | |
1251 | /// Compute a TokenFactor to force all the incoming stack arguments to be |
1252 | /// loaded from the stack. This is used in tail call lowering to protect |
1253 | /// stack arguments from being clobbered. |
1254 | LLVM_ABI SDValue getStackArgumentTokenFactor(SDValue Chain); |
1255 | |
1256 | /* \p CI if not null is the memset call being lowered. |
1257 | * \p OverrideTailCall is an optional parameter that can be used to override |
1258 | * the tail call optimization decision. */ |
1259 | LLVM_ABI SDValue getMemcpy(SDValue Chain, const SDLoc &dl, SDValue Dst, |
1260 | SDValue Src, SDValue Size, Align Alignment, |
1261 | bool isVol, bool AlwaysInline, const CallInst *CI, |
1262 | std::optional<bool> OverrideTailCall, |
1263 | MachinePointerInfo DstPtrInfo, |
1264 | MachinePointerInfo SrcPtrInfo, |
1265 | const AAMDNodes &AAInfo = AAMDNodes(), |
1266 | BatchAAResults *BatchAA = nullptr); |
1267 | |
1268 | /* \p CI if not null is the memset call being lowered. |
1269 | * \p OverrideTailCall is an optional parameter that can be used to override |
1270 | * the tail call optimization decision. */ |
1271 | LLVM_ABI SDValue getMemmove(SDValue Chain, const SDLoc &dl, SDValue Dst, |
1272 | SDValue Src, SDValue Size, Align Alignment, |
1273 | bool isVol, const CallInst *CI, |
1274 | std::optional<bool> OverrideTailCall, |
1275 | MachinePointerInfo DstPtrInfo, |
1276 | MachinePointerInfo SrcPtrInfo, |
1277 | const AAMDNodes &AAInfo = AAMDNodes(), |
1278 | BatchAAResults *BatchAA = nullptr); |
1279 | |
1280 | LLVM_ABI SDValue getMemset(SDValue Chain, const SDLoc &dl, SDValue Dst, |
1281 | SDValue Src, SDValue Size, Align Alignment, |
1282 | bool isVol, bool AlwaysInline, const CallInst *CI, |
1283 | MachinePointerInfo DstPtrInfo, |
1284 | const AAMDNodes &AAInfo = AAMDNodes()); |
1285 | |
1286 | LLVM_ABI SDValue getAtomicMemcpy(SDValue Chain, const SDLoc &dl, SDValue Dst, |
1287 | SDValue Src, SDValue Size, Type *SizeTy, |
1288 | unsigned ElemSz, bool isTailCall, |
1289 | MachinePointerInfo DstPtrInfo, |
1290 | MachinePointerInfo SrcPtrInfo); |
1291 | |
1292 | LLVM_ABI SDValue getAtomicMemmove(SDValue Chain, const SDLoc &dl, SDValue Dst, |
1293 | SDValue Src, SDValue Size, Type *SizeTy, |
1294 | unsigned ElemSz, bool isTailCall, |
1295 | MachinePointerInfo DstPtrInfo, |
1296 | MachinePointerInfo SrcPtrInfo); |
1297 | |
1298 | LLVM_ABI SDValue getAtomicMemset(SDValue Chain, const SDLoc &dl, SDValue Dst, |
1299 | SDValue Value, SDValue Size, Type *SizeTy, |
1300 | unsigned ElemSz, bool isTailCall, |
1301 | MachinePointerInfo DstPtrInfo); |
1302 | |
1303 | /// Helper function to make it easier to build SetCC's if you just have an |
1304 | /// ISD::CondCode instead of an SDValue. |
1305 | SDValue getSetCC(const SDLoc &DL, EVT VT, SDValue LHS, SDValue RHS, |
1306 | ISD::CondCode Cond, SDValue Chain = SDValue(), |
1307 | bool IsSignaling = false) { |
1308 | assert(LHS.getValueType().isVector() == RHS.getValueType().isVector() && |
1309 | "Vector/scalar operand type mismatch for setcc"); |
1310 | assert(LHS.getValueType().isVector() == VT.isVector() && |
1311 | "Vector/scalar result type mismatch for setcc"); |
1312 | assert(Cond != ISD::SETCC_INVALID && |
1313 | "Cannot create a setCC of an invalid node."); |
1314 | if (Chain) |
1315 | return getNode(IsSignaling ? ISD::STRICT_FSETCCS : ISD::STRICT_FSETCC, DL, |
1316 | {VT, MVT::Other}, {Chain, LHS, RHS, getCondCode(Cond)}); |
1317 | return getNode(Opcode: ISD::SETCC, DL, VT, N1: LHS, N2: RHS, N3: getCondCode(Cond)); |
1318 | } |
1319 | |
1320 | /// Helper function to make it easier to build VP_SETCCs if you just have an |
1321 | /// ISD::CondCode instead of an SDValue. |
1322 | SDValue getSetCCVP(const SDLoc &DL, EVT VT, SDValue LHS, SDValue RHS, |
1323 | ISD::CondCode Cond, SDValue Mask, SDValue EVL) { |
1324 | assert(LHS.getValueType().isVector() && RHS.getValueType().isVector() && |
1325 | "Cannot compare scalars"); |
1326 | assert(Cond != ISD::SETCC_INVALID && |
1327 | "Cannot create a setCC of an invalid node."); |
1328 | return getNode(Opcode: ISD::VP_SETCC, DL, VT, N1: LHS, N2: RHS, N3: getCondCode(Cond), N4: Mask, |
1329 | N5: EVL); |
1330 | } |
1331 | |
1332 | /// Helper function to make it easier to build Select's if you just have |
1333 | /// operands and don't want to check for vector. |
1334 | SDValue getSelect(const SDLoc &DL, EVT VT, SDValue Cond, SDValue LHS, |
1335 | SDValue RHS, SDNodeFlags Flags = SDNodeFlags()) { |
1336 | assert(LHS.getValueType() == VT && RHS.getValueType() == VT && |
1337 | "Cannot use select on differing types"); |
1338 | auto Opcode = Cond.getValueType().isVector() ? ISD::VSELECT : ISD::SELECT; |
1339 | return getNode(Opcode, DL, VT, N1: Cond, N2: LHS, N3: RHS, Flags); |
1340 | } |
1341 | |
1342 | /// Helper function to make it easier to build SelectCC's if you just have an |
1343 | /// ISD::CondCode instead of an SDValue. |
1344 | SDValue getSelectCC(const SDLoc &DL, SDValue LHS, SDValue RHS, SDValue True, |
1345 | SDValue False, ISD::CondCode Cond) { |
1346 | return getNode(Opcode: ISD::SELECT_CC, DL, VT: True.getValueType(), N1: LHS, N2: RHS, N3: True, |
1347 | N4: False, N5: getCondCode(Cond)); |
1348 | } |
1349 | |
1350 | /// Try to simplify a select/vselect into 1 of its operands or a constant. |
1351 | LLVM_ABI SDValue simplifySelect(SDValue Cond, SDValue TVal, SDValue FVal); |
1352 | |
1353 | /// Try to simplify a shift into 1 of its operands or a constant. |
1354 | LLVM_ABI SDValue simplifyShift(SDValue X, SDValue Y); |
1355 | |
1356 | /// Try to simplify a floating-point binary operation into 1 of its operands |
1357 | /// or a constant. |
1358 | LLVM_ABI SDValue simplifyFPBinop(unsigned Opcode, SDValue X, SDValue Y, |
1359 | SDNodeFlags Flags); |
1360 | |
1361 | /// VAArg produces a result and token chain, and takes a pointer |
1362 | /// and a source value as input. |
1363 | LLVM_ABI SDValue getVAArg(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, |
1364 | SDValue SV, unsigned Align); |
1365 | |
1366 | /// Gets a node for an atomic cmpxchg op. There are two |
1367 | /// valid Opcodes. ISD::ATOMIC_CMO_SWAP produces the value loaded and a |
1368 | /// chain result. ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS produces the value loaded, |
1369 | /// a success flag (initially i1), and a chain. |
1370 | LLVM_ABI SDValue getAtomicCmpSwap(unsigned Opcode, const SDLoc &dl, EVT MemVT, |
1371 | SDVTList VTs, SDValue Chain, SDValue Ptr, |
1372 | SDValue Cmp, SDValue Swp, |
1373 | MachineMemOperand *MMO); |
1374 | |
1375 | /// Gets a node for an atomic op, produces result (if relevant) |
1376 | /// and chain and takes 2 operands. |
1377 | LLVM_ABI SDValue getAtomic(unsigned Opcode, const SDLoc &dl, EVT MemVT, |
1378 | SDValue Chain, SDValue Ptr, SDValue Val, |
1379 | MachineMemOperand *MMO); |
1380 | |
1381 | /// Gets a node for an atomic op, produces result and chain and takes N |
1382 | /// operands. |
1383 | LLVM_ABI SDValue getAtomic(unsigned Opcode, const SDLoc &dl, EVT MemVT, |
1384 | SDVTList VTList, ArrayRef<SDValue> Ops, |
1385 | MachineMemOperand *MMO, |
1386 | ISD::LoadExtType ExtType = ISD::NON_EXTLOAD); |
1387 | |
1388 | LLVM_ABI SDValue getAtomicLoad(ISD::LoadExtType ExtType, const SDLoc &dl, |
1389 | EVT MemVT, EVT VT, SDValue Chain, SDValue Ptr, |
1390 | MachineMemOperand *MMO); |
1391 | |
1392 | /// Creates a MemIntrinsicNode that may produce a |
1393 | /// result and takes a list of operands. Opcode may be INTRINSIC_VOID, |
1394 | /// INTRINSIC_W_CHAIN, or a target-specific memory-referencing opcode |
1395 | // (see `SelectionDAGTargetInfo::isTargetMemoryOpcode`). |
1396 | LLVM_ABI SDValue getMemIntrinsicNode( |
1397 | unsigned Opcode, const SDLoc &dl, SDVTList VTList, ArrayRef<SDValue> Ops, |
1398 | EVT MemVT, MachinePointerInfo PtrInfo, Align Alignment, |
1399 | MachineMemOperand::Flags Flags = MachineMemOperand::MOLoad | |
1400 | MachineMemOperand::MOStore, |
1401 | LocationSize Size = LocationSize::precise(Value: 0), |
1402 | const AAMDNodes &AAInfo = AAMDNodes()); |
1403 | |
1404 | inline SDValue getMemIntrinsicNode( |
1405 | unsigned Opcode, const SDLoc &dl, SDVTList VTList, ArrayRef<SDValue> Ops, |
1406 | EVT MemVT, MachinePointerInfo PtrInfo, |
1407 | MaybeAlign Alignment = std::nullopt, |
1408 | MachineMemOperand::Flags Flags = MachineMemOperand::MOLoad | |
1409 | MachineMemOperand::MOStore, |
1410 | LocationSize Size = LocationSize::precise(Value: 0), |
1411 | const AAMDNodes &AAInfo = AAMDNodes()) { |
1412 | // Ensure that codegen never sees alignment 0 |
1413 | return getMemIntrinsicNode(Opcode, dl, VTList, Ops, MemVT, PtrInfo, |
1414 | Alignment: Alignment.value_or(u: getEVTAlign(MemoryVT: MemVT)), Flags, |
1415 | Size, AAInfo); |
1416 | } |
1417 | |
1418 | LLVM_ABI SDValue getMemIntrinsicNode(unsigned Opcode, const SDLoc &dl, |
1419 | SDVTList VTList, ArrayRef<SDValue> Ops, |
1420 | EVT MemVT, MachineMemOperand *MMO); |
1421 | |
1422 | /// Creates a LifetimeSDNode that starts (`IsStart==true`) or ends |
1423 | /// (`IsStart==false`) the lifetime of the portion of `FrameIndex` between |
1424 | /// offsets `Offset` and `Offset + Size`. |
1425 | LLVM_ABI SDValue getLifetimeNode(bool IsStart, const SDLoc &dl, SDValue Chain, |
1426 | int FrameIndex, int64_t Size, |
1427 | int64_t Offset = -1); |
1428 | |
1429 | /// Creates a PseudoProbeSDNode with function GUID `Guid` and |
1430 | /// the index of the block `Index` it is probing, as well as the attributes |
1431 | /// `attr` of the probe. |
1432 | LLVM_ABI SDValue getPseudoProbeNode(const SDLoc &Dl, SDValue Chain, |
1433 | uint64_t Guid, uint64_t Index, |
1434 | uint32_t Attr); |
1435 | |
1436 | /// Create a MERGE_VALUES node from the given operands. |
1437 | LLVM_ABI SDValue getMergeValues(ArrayRef<SDValue> Ops, const SDLoc &dl); |
1438 | |
1439 | /// Loads are not normal binary operators: their result type is not |
1440 | /// determined by their operands, and they produce a value AND a token chain. |
1441 | /// |
1442 | /// This function will set the MOLoad flag on MMOFlags, but you can set it if |
1443 | /// you want. The MOStore flag must not be set. |
1444 | LLVM_ABI SDValue getLoad( |
1445 | EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, |
1446 | MachinePointerInfo PtrInfo, MaybeAlign Alignment = MaybeAlign(), |
1447 | MachineMemOperand::Flags MMOFlags = MachineMemOperand::MONone, |
1448 | const AAMDNodes &AAInfo = AAMDNodes(), const MDNode *Ranges = nullptr); |
1449 | LLVM_ABI SDValue getLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, |
1450 | MachineMemOperand *MMO); |
1451 | LLVM_ABI SDValue |
1452 | getExtLoad(ISD::LoadExtType ExtType, const SDLoc &dl, EVT VT, SDValue Chain, |
1453 | SDValue Ptr, MachinePointerInfo PtrInfo, EVT MemVT, |
1454 | MaybeAlign Alignment = MaybeAlign(), |
1455 | MachineMemOperand::Flags MMOFlags = MachineMemOperand::MONone, |
1456 | const AAMDNodes &AAInfo = AAMDNodes()); |
1457 | LLVM_ABI SDValue getExtLoad(ISD::LoadExtType ExtType, const SDLoc &dl, EVT VT, |
1458 | SDValue Chain, SDValue Ptr, EVT MemVT, |
1459 | MachineMemOperand *MMO); |
1460 | LLVM_ABI SDValue getIndexedLoad(SDValue OrigLoad, const SDLoc &dl, |
1461 | SDValue Base, SDValue Offset, |
1462 | ISD::MemIndexedMode AM); |
1463 | LLVM_ABI SDValue getLoad( |
1464 | ISD::MemIndexedMode AM, ISD::LoadExtType ExtType, EVT VT, const SDLoc &dl, |
1465 | SDValue Chain, SDValue Ptr, SDValue Offset, MachinePointerInfo PtrInfo, |
1466 | EVT MemVT, Align Alignment, |
1467 | MachineMemOperand::Flags MMOFlags = MachineMemOperand::MONone, |
1468 | const AAMDNodes &AAInfo = AAMDNodes(), const MDNode *Ranges = nullptr); |
1469 | inline SDValue getLoad( |
1470 | ISD::MemIndexedMode AM, ISD::LoadExtType ExtType, EVT VT, const SDLoc &dl, |
1471 | SDValue Chain, SDValue Ptr, SDValue Offset, MachinePointerInfo PtrInfo, |
1472 | EVT MemVT, MaybeAlign Alignment = MaybeAlign(), |
1473 | MachineMemOperand::Flags MMOFlags = MachineMemOperand::MONone, |
1474 | const AAMDNodes &AAInfo = AAMDNodes(), const MDNode *Ranges = nullptr) { |
1475 | // Ensures that codegen never sees a None Alignment. |
1476 | return getLoad(AM, ExtType, VT, dl, Chain, Ptr, Offset, PtrInfo, MemVT, |
1477 | Alignment: Alignment.value_or(u: getEVTAlign(MemoryVT: MemVT)), MMOFlags, AAInfo, |
1478 | Ranges); |
1479 | } |
1480 | LLVM_ABI SDValue getLoad(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType, |
1481 | EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, |
1482 | SDValue Offset, EVT MemVT, MachineMemOperand *MMO); |
1483 | |
1484 | /// Helper function to build ISD::STORE nodes. |
1485 | /// |
1486 | /// This function will set the MOStore flag on MMOFlags, but you can set it if |
1487 | /// you want. The MOLoad and MOInvariant flags must not be set. |
1488 | |
1489 | LLVM_ABI SDValue |
1490 | getStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, |
1491 | MachinePointerInfo PtrInfo, Align Alignment, |
1492 | MachineMemOperand::Flags MMOFlags = MachineMemOperand::MONone, |
1493 | const AAMDNodes &AAInfo = AAMDNodes()); |
1494 | inline SDValue |
1495 | getStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, |
1496 | MachinePointerInfo PtrInfo, MaybeAlign Alignment = MaybeAlign(), |
1497 | MachineMemOperand::Flags MMOFlags = MachineMemOperand::MONone, |
1498 | const AAMDNodes &AAInfo = AAMDNodes()) { |
1499 | return getStore(Chain, dl, Val, Ptr, PtrInfo, |
1500 | Alignment: Alignment.value_or(u: getEVTAlign(MemoryVT: Val.getValueType())), |
1501 | MMOFlags, AAInfo); |
1502 | } |
1503 | LLVM_ABI SDValue getStore(SDValue Chain, const SDLoc &dl, SDValue Val, |
1504 | SDValue Ptr, MachineMemOperand *MMO); |
1505 | LLVM_ABI SDValue |
1506 | getTruncStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, |
1507 | MachinePointerInfo PtrInfo, EVT SVT, Align Alignment, |
1508 | MachineMemOperand::Flags MMOFlags = MachineMemOperand::MONone, |
1509 | const AAMDNodes &AAInfo = AAMDNodes()); |
1510 | inline SDValue |
1511 | getTruncStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, |
1512 | MachinePointerInfo PtrInfo, EVT SVT, |
1513 | MaybeAlign Alignment = MaybeAlign(), |
1514 | MachineMemOperand::Flags MMOFlags = MachineMemOperand::MONone, |
1515 | const AAMDNodes &AAInfo = AAMDNodes()) { |
1516 | return getTruncStore(Chain, dl, Val, Ptr, PtrInfo, SVT, |
1517 | Alignment: Alignment.value_or(u: getEVTAlign(MemoryVT: SVT)), MMOFlags, |
1518 | AAInfo); |
1519 | } |
1520 | LLVM_ABI SDValue getTruncStore(SDValue Chain, const SDLoc &dl, SDValue Val, |
1521 | SDValue Ptr, EVT SVT, MachineMemOperand *MMO); |
1522 | LLVM_ABI SDValue getIndexedStore(SDValue OrigStore, const SDLoc &dl, |
1523 | SDValue Base, SDValue Offset, |
1524 | ISD::MemIndexedMode AM); |
1525 | LLVM_ABI SDValue getStore(SDValue Chain, const SDLoc &dl, SDValue Val, |
1526 | SDValue Ptr, SDValue Offset, EVT SVT, |
1527 | MachineMemOperand *MMO, ISD::MemIndexedMode AM, |
1528 | bool IsTruncating = false); |
1529 | |
1530 | LLVM_ABI SDValue getLoadVP(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType, |
1531 | EVT VT, const SDLoc &dl, SDValue Chain, |
1532 | SDValue Ptr, SDValue Offset, SDValue Mask, |
1533 | SDValue EVL, MachinePointerInfo PtrInfo, EVT MemVT, |
1534 | Align Alignment, MachineMemOperand::Flags MMOFlags, |
1535 | const AAMDNodes &AAInfo, |
1536 | const MDNode *Ranges = nullptr, |
1537 | bool IsExpanding = false); |
1538 | inline SDValue |
1539 | getLoadVP(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType, EVT VT, |
1540 | const SDLoc &dl, SDValue Chain, SDValue Ptr, SDValue Offset, |
1541 | SDValue Mask, SDValue EVL, MachinePointerInfo PtrInfo, EVT MemVT, |
1542 | MaybeAlign Alignment = MaybeAlign(), |
1543 | MachineMemOperand::Flags MMOFlags = MachineMemOperand::MONone, |
1544 | const AAMDNodes &AAInfo = AAMDNodes(), |
1545 | const MDNode *Ranges = nullptr, bool IsExpanding = false) { |
1546 | // Ensures that codegen never sees a None Alignment. |
1547 | return getLoadVP(AM, ExtType, VT, dl, Chain, Ptr, Offset, Mask, EVL, |
1548 | PtrInfo, MemVT, Alignment: Alignment.value_or(u: getEVTAlign(MemoryVT: MemVT)), |
1549 | MMOFlags, AAInfo, Ranges, IsExpanding); |
1550 | } |
1551 | LLVM_ABI SDValue getLoadVP(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType, |
1552 | EVT VT, const SDLoc &dl, SDValue Chain, |
1553 | SDValue Ptr, SDValue Offset, SDValue Mask, |
1554 | SDValue EVL, EVT MemVT, MachineMemOperand *MMO, |
1555 | bool IsExpanding = false); |
1556 | LLVM_ABI SDValue getLoadVP(EVT VT, const SDLoc &dl, SDValue Chain, |
1557 | SDValue Ptr, SDValue Mask, SDValue EVL, |
1558 | MachinePointerInfo PtrInfo, MaybeAlign Alignment, |
1559 | MachineMemOperand::Flags MMOFlags, |
1560 | const AAMDNodes &AAInfo, |
1561 | const MDNode *Ranges = nullptr, |
1562 | bool IsExpanding = false); |
1563 | LLVM_ABI SDValue getLoadVP(EVT VT, const SDLoc &dl, SDValue Chain, |
1564 | SDValue Ptr, SDValue Mask, SDValue EVL, |
1565 | MachineMemOperand *MMO, bool IsExpanding = false); |
1566 | LLVM_ABI SDValue getExtLoadVP( |
1567 | ISD::LoadExtType ExtType, const SDLoc &dl, EVT VT, SDValue Chain, |
1568 | SDValue Ptr, SDValue Mask, SDValue EVL, MachinePointerInfo PtrInfo, |
1569 | EVT MemVT, MaybeAlign Alignment, MachineMemOperand::Flags MMOFlags, |
1570 | const AAMDNodes &AAInfo, bool IsExpanding = false); |
1571 | LLVM_ABI SDValue getExtLoadVP(ISD::LoadExtType ExtType, const SDLoc &dl, |
1572 | EVT VT, SDValue Chain, SDValue Ptr, |
1573 | SDValue Mask, SDValue EVL, EVT MemVT, |
1574 | MachineMemOperand *MMO, |
1575 | bool IsExpanding = false); |
1576 | LLVM_ABI SDValue getIndexedLoadVP(SDValue OrigLoad, const SDLoc &dl, |
1577 | SDValue Base, SDValue Offset, |
1578 | ISD::MemIndexedMode AM); |
1579 | LLVM_ABI SDValue getStoreVP(SDValue Chain, const SDLoc &dl, SDValue Val, |
1580 | SDValue Ptr, SDValue Offset, SDValue Mask, |
1581 | SDValue EVL, EVT MemVT, MachineMemOperand *MMO, |
1582 | ISD::MemIndexedMode AM, bool IsTruncating = false, |
1583 | bool IsCompressing = false); |
1584 | LLVM_ABI SDValue getTruncStoreVP(SDValue Chain, const SDLoc &dl, SDValue Val, |
1585 | SDValue Ptr, SDValue Mask, SDValue EVL, |
1586 | MachinePointerInfo PtrInfo, EVT SVT, |
1587 | Align Alignment, |
1588 | MachineMemOperand::Flags MMOFlags, |
1589 | const AAMDNodes &AAInfo, |
1590 | bool IsCompressing = false); |
1591 | LLVM_ABI SDValue getTruncStoreVP(SDValue Chain, const SDLoc &dl, SDValue Val, |
1592 | SDValue Ptr, SDValue Mask, SDValue EVL, |
1593 | EVT SVT, MachineMemOperand *MMO, |
1594 | bool IsCompressing = false); |
1595 | LLVM_ABI SDValue getIndexedStoreVP(SDValue OrigStore, const SDLoc &dl, |
1596 | SDValue Base, SDValue Offset, |
1597 | ISD::MemIndexedMode AM); |
1598 | |
1599 | LLVM_ABI SDValue getStridedLoadVP( |
1600 | ISD::MemIndexedMode AM, ISD::LoadExtType ExtType, EVT VT, const SDLoc &DL, |
1601 | SDValue Chain, SDValue Ptr, SDValue Offset, SDValue Stride, SDValue Mask, |
1602 | SDValue EVL, EVT MemVT, MachineMemOperand *MMO, bool IsExpanding = false); |
1603 | LLVM_ABI SDValue getStridedLoadVP(EVT VT, const SDLoc &DL, SDValue Chain, |
1604 | SDValue Ptr, SDValue Stride, SDValue Mask, |
1605 | SDValue EVL, MachineMemOperand *MMO, |
1606 | bool IsExpanding = false); |
1607 | LLVM_ABI SDValue getExtStridedLoadVP(ISD::LoadExtType ExtType, |
1608 | const SDLoc &DL, EVT VT, SDValue Chain, |
1609 | SDValue Ptr, SDValue Stride, |
1610 | SDValue Mask, SDValue EVL, EVT MemVT, |
1611 | MachineMemOperand *MMO, |
1612 | bool IsExpanding = false); |
1613 | LLVM_ABI SDValue getStridedStoreVP(SDValue Chain, const SDLoc &DL, |
1614 | SDValue Val, SDValue Ptr, SDValue Offset, |
1615 | SDValue Stride, SDValue Mask, SDValue EVL, |
1616 | EVT MemVT, MachineMemOperand *MMO, |
1617 | ISD::MemIndexedMode AM, |
1618 | bool IsTruncating = false, |
1619 | bool IsCompressing = false); |
1620 | LLVM_ABI SDValue getTruncStridedStoreVP(SDValue Chain, const SDLoc &DL, |
1621 | SDValue Val, SDValue Ptr, |
1622 | SDValue Stride, SDValue Mask, |
1623 | SDValue EVL, EVT SVT, |
1624 | MachineMemOperand *MMO, |
1625 | bool IsCompressing = false); |
1626 | |
1627 | LLVM_ABI SDValue getGatherVP(SDVTList VTs, EVT VT, const SDLoc &dl, |
1628 | ArrayRef<SDValue> Ops, MachineMemOperand *MMO, |
1629 | ISD::MemIndexType IndexType); |
1630 | LLVM_ABI SDValue getScatterVP(SDVTList VTs, EVT VT, const SDLoc &dl, |
1631 | ArrayRef<SDValue> Ops, MachineMemOperand *MMO, |
1632 | ISD::MemIndexType IndexType); |
1633 | |
1634 | LLVM_ABI SDValue getMaskedLoad(EVT VT, const SDLoc &dl, SDValue Chain, |
1635 | SDValue Base, SDValue Offset, SDValue Mask, |
1636 | SDValue Src0, EVT MemVT, |
1637 | MachineMemOperand *MMO, ISD::MemIndexedMode AM, |
1638 | ISD::LoadExtType, bool IsExpanding = false); |
1639 | LLVM_ABI SDValue getIndexedMaskedLoad(SDValue OrigLoad, const SDLoc &dl, |
1640 | SDValue Base, SDValue Offset, |
1641 | ISD::MemIndexedMode AM); |
1642 | LLVM_ABI SDValue getMaskedStore(SDValue Chain, const SDLoc &dl, SDValue Val, |
1643 | SDValue Base, SDValue Offset, SDValue Mask, |
1644 | EVT MemVT, MachineMemOperand *MMO, |
1645 | ISD::MemIndexedMode AM, |
1646 | bool IsTruncating = false, |
1647 | bool IsCompressing = false); |
1648 | LLVM_ABI SDValue getIndexedMaskedStore(SDValue OrigStore, const SDLoc &dl, |
1649 | SDValue Base, SDValue Offset, |
1650 | ISD::MemIndexedMode AM); |
1651 | LLVM_ABI SDValue getMaskedGather(SDVTList VTs, EVT MemVT, const SDLoc &dl, |
1652 | ArrayRef<SDValue> Ops, |
1653 | MachineMemOperand *MMO, |
1654 | ISD::MemIndexType IndexType, |
1655 | ISD::LoadExtType ExtTy); |
1656 | LLVM_ABI SDValue getMaskedScatter(SDVTList VTs, EVT MemVT, const SDLoc &dl, |
1657 | ArrayRef<SDValue> Ops, |
1658 | MachineMemOperand *MMO, |
1659 | ISD::MemIndexType IndexType, |
1660 | bool IsTruncating = false); |
1661 | LLVM_ABI SDValue getMaskedHistogram(SDVTList VTs, EVT MemVT, const SDLoc &dl, |
1662 | ArrayRef<SDValue> Ops, |
1663 | MachineMemOperand *MMO, |
1664 | ISD::MemIndexType IndexType); |
1665 | |
1666 | LLVM_ABI SDValue getGetFPEnv(SDValue Chain, const SDLoc &dl, SDValue Ptr, |
1667 | EVT MemVT, MachineMemOperand *MMO); |
1668 | LLVM_ABI SDValue getSetFPEnv(SDValue Chain, const SDLoc &dl, SDValue Ptr, |
1669 | EVT MemVT, MachineMemOperand *MMO); |
1670 | |
1671 | /// Construct a node to track a Value* through the backend. |
1672 | LLVM_ABI SDValue getSrcValue(const Value *v); |
1673 | |
1674 | /// Return an MDNodeSDNode which holds an MDNode. |
1675 | LLVM_ABI SDValue getMDNode(const MDNode *MD); |
1676 | |
1677 | /// Return a bitcast using the SDLoc of the value operand, and casting to the |
1678 | /// provided type. Use getNode to set a custom SDLoc. |
1679 | LLVM_ABI SDValue getBitcast(EVT VT, SDValue V); |
1680 | |
1681 | /// Return an AddrSpaceCastSDNode. |
1682 | LLVM_ABI SDValue getAddrSpaceCast(const SDLoc &dl, EVT VT, SDValue Ptr, |
1683 | unsigned SrcAS, unsigned DestAS); |
1684 | |
1685 | /// Return a freeze using the SDLoc of the value operand. |
1686 | LLVM_ABI SDValue getFreeze(SDValue V); |
1687 | |
1688 | /// Return an AssertAlignSDNode. |
1689 | LLVM_ABI SDValue getAssertAlign(const SDLoc &DL, SDValue V, Align A); |
1690 | |
1691 | /// Swap N1 and N2 if Opcode is a commutative binary opcode |
1692 | /// and the canonical form expects the opposite order. |
1693 | LLVM_ABI void canonicalizeCommutativeBinop(unsigned Opcode, SDValue &N1, |
1694 | SDValue &N2) const; |
1695 | |
1696 | /// Return the specified value casted to |
1697 | /// the target's desired shift amount type. |
1698 | LLVM_ABI SDValue getShiftAmountOperand(EVT LHSTy, SDValue Op); |
1699 | |
1700 | /// Expands a node with multiple results to an FP or vector libcall. The |
1701 | /// libcall is expected to take all the operands of the \p Node followed by |
1702 | /// output pointers for each of the results. \p CallRetResNo can be optionally |
1703 | /// set to indicate that one of the results comes from the libcall's return |
1704 | /// value. |
1705 | LLVM_ABI bool |
1706 | expandMultipleResultFPLibCall(RTLIB::Libcall LC, SDNode *Node, |
1707 | SmallVectorImpl<SDValue> &Results, |
1708 | std::optional<unsigned> CallRetResNo = {}); |
1709 | |
1710 | /// Expand the specified \c ISD::VAARG node as the Legalize pass would. |
1711 | LLVM_ABI SDValue expandVAArg(SDNode *Node); |
1712 | |
1713 | /// Expand the specified \c ISD::VACOPY node as the Legalize pass would. |
1714 | LLVM_ABI SDValue expandVACopy(SDNode *Node); |
1715 | |
1716 | /// Return a GlobalAddress of the function from the current module with |
1717 | /// name matching the given ExternalSymbol. Additionally can provide the |
1718 | /// matched function. |
1719 | /// Panic if the function doesn't exist. |
1720 | LLVM_ABI SDValue getSymbolFunctionGlobalAddress( |
1721 | SDValue Op, Function **TargetFunction = nullptr); |
1722 | |
1723 | /// *Mutate* the specified node in-place to have the |
1724 | /// specified operands. If the resultant node already exists in the DAG, |
1725 | /// this does not modify the specified node, instead it returns the node that |
1726 | /// already exists. If the resultant node does not exist in the DAG, the |
1727 | /// input node is returned. As a degenerate case, if you specify the same |
1728 | /// input operands as the node already has, the input node is returned. |
1729 | LLVM_ABI SDNode *UpdateNodeOperands(SDNode *N, SDValue Op); |
1730 | LLVM_ABI SDNode *UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2); |
1731 | LLVM_ABI SDNode *UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2, |
1732 | SDValue Op3); |
1733 | LLVM_ABI SDNode *UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2, |
1734 | SDValue Op3, SDValue Op4); |
1735 | LLVM_ABI SDNode *UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2, |
1736 | SDValue Op3, SDValue Op4, SDValue Op5); |
1737 | LLVM_ABI SDNode *UpdateNodeOperands(SDNode *N, ArrayRef<SDValue> Ops); |
1738 | |
1739 | /// Creates a new TokenFactor containing \p Vals. If \p Vals contains 64k |
1740 | /// values or more, move values into new TokenFactors in 64k-1 blocks, until |
1741 | /// the final TokenFactor has less than 64k operands. |
1742 | LLVM_ABI SDValue getTokenFactor(const SDLoc &DL, |
1743 | SmallVectorImpl<SDValue> &Vals); |
1744 | |
1745 | /// *Mutate* the specified machine node's memory references to the provided |
1746 | /// list. |
1747 | LLVM_ABI void setNodeMemRefs(MachineSDNode *N, |
1748 | ArrayRef<MachineMemOperand *> NewMemRefs); |
1749 | |
1750 | // Calculate divergence of node \p N based on its operands. |
1751 | LLVM_ABI bool calculateDivergence(SDNode *N); |
1752 | |
1753 | // Propagates the change in divergence to users |
1754 | LLVM_ABI void updateDivergence(SDNode *N); |
1755 | |
1756 | /// These are used for target selectors to *mutate* the |
1757 | /// specified node to have the specified return type, Target opcode, and |
1758 | /// operands. Note that target opcodes are stored as |
1759 | /// ~TargetOpcode in the node opcode field. The resultant node is returned. |
1760 | LLVM_ABI SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT); |
1761 | LLVM_ABI SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT, |
1762 | SDValue Op1); |
1763 | LLVM_ABI SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT, |
1764 | SDValue Op1, SDValue Op2); |
1765 | LLVM_ABI SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT, |
1766 | SDValue Op1, SDValue Op2, SDValue Op3); |
1767 | LLVM_ABI SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT, |
1768 | ArrayRef<SDValue> Ops); |
1769 | LLVM_ABI SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT1, |
1770 | EVT VT2); |
1771 | LLVM_ABI SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT1, |
1772 | EVT VT2, ArrayRef<SDValue> Ops); |
1773 | LLVM_ABI SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT1, |
1774 | EVT VT2, EVT VT3, ArrayRef<SDValue> Ops); |
1775 | LLVM_ABI SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT1, |
1776 | EVT VT2, SDValue Op1, SDValue Op2); |
1777 | LLVM_ABI SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, SDVTList VTs, |
1778 | ArrayRef<SDValue> Ops); |
1779 | |
1780 | /// This *mutates* the specified node to have the specified |
1781 | /// return type, opcode, and operands. |
1782 | LLVM_ABI SDNode *MorphNodeTo(SDNode *N, unsigned Opc, SDVTList VTs, |
1783 | ArrayRef<SDValue> Ops); |
1784 | |
1785 | /// Mutate the specified strict FP node to its non-strict equivalent, |
1786 | /// unlinking the node from its chain and dropping the metadata arguments. |
1787 | /// The node must be a strict FP node. |
1788 | LLVM_ABI SDNode *mutateStrictFPToFP(SDNode *Node); |
1789 | |
1790 | /// These are used for target selectors to create a new node |
1791 | /// with specified return type(s), MachineInstr opcode, and operands. |
1792 | /// |
1793 | /// Note that getMachineNode returns the resultant node. If there is already |
1794 | /// a node of the specified opcode and operands, it returns that node instead |
1795 | /// of the current one. |
1796 | LLVM_ABI MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, |
1797 | EVT VT); |
1798 | LLVM_ABI MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, |
1799 | EVT VT, SDValue Op1); |
1800 | LLVM_ABI MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, |
1801 | EVT VT, SDValue Op1, SDValue Op2); |
1802 | LLVM_ABI MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, |
1803 | EVT VT, SDValue Op1, SDValue Op2, |
1804 | SDValue Op3); |
1805 | LLVM_ABI MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, |
1806 | EVT VT, ArrayRef<SDValue> Ops); |
1807 | LLVM_ABI MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, |
1808 | EVT VT1, EVT VT2, SDValue Op1, |
1809 | SDValue Op2); |
1810 | LLVM_ABI MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, |
1811 | EVT VT1, EVT VT2, SDValue Op1, |
1812 | SDValue Op2, SDValue Op3); |
1813 | LLVM_ABI MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, |
1814 | EVT VT1, EVT VT2, |
1815 | ArrayRef<SDValue> Ops); |
1816 | LLVM_ABI MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, |
1817 | EVT VT1, EVT VT2, EVT VT3, SDValue Op1, |
1818 | SDValue Op2); |
1819 | LLVM_ABI MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, |
1820 | EVT VT1, EVT VT2, EVT VT3, SDValue Op1, |
1821 | SDValue Op2, SDValue Op3); |
1822 | LLVM_ABI MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, |
1823 | EVT VT1, EVT VT2, EVT VT3, |
1824 | ArrayRef<SDValue> Ops); |
1825 | LLVM_ABI MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, |
1826 | ArrayRef<EVT> ResultTys, |
1827 | ArrayRef<SDValue> Ops); |
1828 | LLVM_ABI MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, |
1829 | SDVTList VTs, ArrayRef<SDValue> Ops); |
1830 | |
1831 | /// A convenience function for creating TargetInstrInfo::EXTRACT_SUBREG nodes. |
1832 | LLVM_ABI SDValue getTargetExtractSubreg(int SRIdx, const SDLoc &DL, EVT VT, |
1833 | SDValue Operand); |
1834 | |
1835 | /// A convenience function for creating TargetInstrInfo::INSERT_SUBREG nodes. |
1836 | LLVM_ABI SDValue getTargetInsertSubreg(int SRIdx, const SDLoc &DL, EVT VT, |
1837 | SDValue Operand, SDValue Subreg); |
1838 | |
1839 | /// Get the specified node if it's already available, or else return NULL. |
1840 | LLVM_ABI SDNode *getNodeIfExists(unsigned Opcode, SDVTList VTList, |
1841 | ArrayRef<SDValue> Ops, |
1842 | const SDNodeFlags Flags); |
1843 | LLVM_ABI SDNode *getNodeIfExists(unsigned Opcode, SDVTList VTList, |
1844 | ArrayRef<SDValue> Ops); |
1845 | |
1846 | /// Check if a node exists without modifying its flags. |
1847 | LLVM_ABI bool doesNodeExist(unsigned Opcode, SDVTList VTList, |
1848 | ArrayRef<SDValue> Ops); |
1849 | |
1850 | /// Creates a SDDbgValue node. |
1851 | LLVM_ABI SDDbgValue *getDbgValue(DIVariable *Var, DIExpression *Expr, |
1852 | SDNode *N, unsigned R, bool IsIndirect, |
1853 | const DebugLoc &DL, unsigned O); |
1854 | |
1855 | /// Creates a constant SDDbgValue node. |
1856 | LLVM_ABI SDDbgValue *getConstantDbgValue(DIVariable *Var, DIExpression *Expr, |
1857 | const Value *C, const DebugLoc &DL, |
1858 | unsigned O); |
1859 | |
1860 | /// Creates a FrameIndex SDDbgValue node. |
1861 | LLVM_ABI SDDbgValue *getFrameIndexDbgValue(DIVariable *Var, |
1862 | DIExpression *Expr, unsigned FI, |
1863 | bool IsIndirect, |
1864 | const DebugLoc &DL, unsigned O); |
1865 | |
1866 | /// Creates a FrameIndex SDDbgValue node. |
1867 | LLVM_ABI SDDbgValue *getFrameIndexDbgValue(DIVariable *Var, |
1868 | DIExpression *Expr, unsigned FI, |
1869 | ArrayRef<SDNode *> Dependencies, |
1870 | bool IsIndirect, |
1871 | const DebugLoc &DL, unsigned O); |
1872 | |
1873 | /// Creates a VReg SDDbgValue node. |
1874 | LLVM_ABI SDDbgValue *getVRegDbgValue(DIVariable *Var, DIExpression *Expr, |
1875 | Register VReg, bool IsIndirect, |
1876 | const DebugLoc &DL, unsigned O); |
1877 | |
1878 | /// Creates a SDDbgValue node from a list of locations. |
1879 | LLVM_ABI SDDbgValue *getDbgValueList(DIVariable *Var, DIExpression *Expr, |
1880 | ArrayRef<SDDbgOperand> Locs, |
1881 | ArrayRef<SDNode *> Dependencies, |
1882 | bool IsIndirect, const DebugLoc &DL, |
1883 | unsigned O, bool IsVariadic); |
1884 | |
1885 | /// Creates a SDDbgLabel node. |
1886 | LLVM_ABI SDDbgLabel *getDbgLabel(DILabel *Label, const DebugLoc &DL, |
1887 | unsigned O); |
1888 | |
1889 | /// Transfer debug values from one node to another, while optionally |
1890 | /// generating fragment expressions for split-up values. If \p InvalidateDbg |
1891 | /// is set, debug values are invalidated after they are transferred. |
1892 | LLVM_ABI void transferDbgValues(SDValue From, SDValue To, |
1893 | unsigned OffsetInBits = 0, |
1894 | unsigned SizeInBits = 0, |
1895 | bool InvalidateDbg = true); |
1896 | |
1897 | /// Remove the specified node from the system. If any of its |
1898 | /// operands then becomes dead, remove them as well. Inform UpdateListener |
1899 | /// for each node deleted. |
1900 | LLVM_ABI void RemoveDeadNode(SDNode *N); |
1901 | |
1902 | /// This method deletes the unreachable nodes in the |
1903 | /// given list, and any nodes that become unreachable as a result. |
1904 | LLVM_ABI void RemoveDeadNodes(SmallVectorImpl<SDNode *> &DeadNodes); |
1905 | |
1906 | /// Modify anything using 'From' to use 'To' instead. |
1907 | /// This can cause recursive merging of nodes in the DAG. Use the first |
1908 | /// version if 'From' is known to have a single result, use the second |
1909 | /// if you have two nodes with identical results (or if 'To' has a superset |
1910 | /// of the results of 'From'), use the third otherwise. |
1911 | /// |
1912 | /// These methods all take an optional UpdateListener, which (if not null) is |
1913 | /// informed about nodes that are deleted and modified due to recursive |
1914 | /// changes in the dag. |
1915 | /// |
1916 | /// These functions only replace all existing uses. It's possible that as |
1917 | /// these replacements are being performed, CSE may cause the From node |
1918 | /// to be given new uses. These new uses of From are left in place, and |
1919 | /// not automatically transferred to To. |
1920 | /// |
1921 | LLVM_ABI void ReplaceAllUsesWith(SDValue From, SDValue To); |
1922 | LLVM_ABI void ReplaceAllUsesWith(SDNode *From, SDNode *To); |
1923 | LLVM_ABI void ReplaceAllUsesWith(SDNode *From, const SDValue *To); |
1924 | |
1925 | /// Replace any uses of From with To, leaving |
1926 | /// uses of other values produced by From.getNode() alone. |
1927 | LLVM_ABI void ReplaceAllUsesOfValueWith(SDValue From, SDValue To); |
1928 | |
1929 | /// Like ReplaceAllUsesOfValueWith, but for multiple values at once. |
1930 | /// This correctly handles the case where |
1931 | /// there is an overlap between the From values and the To values. |
1932 | LLVM_ABI void ReplaceAllUsesOfValuesWith(const SDValue *From, |
1933 | const SDValue *To, unsigned Num); |
1934 | |
1935 | /// If an existing load has uses of its chain, create a token factor node with |
1936 | /// that chain and the new memory node's chain and update users of the old |
1937 | /// chain to the token factor. This ensures that the new memory node will have |
1938 | /// the same relative memory dependency position as the old load. Returns the |
1939 | /// new merged load chain. |
1940 | LLVM_ABI SDValue makeEquivalentMemoryOrdering(SDValue OldChain, |
1941 | SDValue NewMemOpChain); |
1942 | |
1943 | /// If an existing load has uses of its chain, create a token factor node with |
1944 | /// that chain and the new memory node's chain and update users of the old |
1945 | /// chain to the token factor. This ensures that the new memory node will have |
1946 | /// the same relative memory dependency position as the old load. Returns the |
1947 | /// new merged load chain. |
1948 | LLVM_ABI SDValue makeEquivalentMemoryOrdering(LoadSDNode *OldLoad, |
1949 | SDValue NewMemOp); |
1950 | |
1951 | /// Topological-sort the AllNodes list and a |
1952 | /// assign a unique node id for each node in the DAG based on their |
1953 | /// topological order. Returns the number of nodes. |
1954 | LLVM_ABI unsigned AssignTopologicalOrder(); |
1955 | |
1956 | /// Move node N in the AllNodes list to be immediately |
1957 | /// before the given iterator Position. This may be used to update the |
1958 | /// topological ordering when the list of nodes is modified. |
1959 | void RepositionNode(allnodes_iterator Position, SDNode *N) { |
1960 | AllNodes.insert(where: Position, New: AllNodes.remove(IT: N)); |
1961 | } |
1962 | |
1963 | /// Add a dbg_value SDNode. If SD is non-null that means the |
1964 | /// value is produced by SD. |
1965 | LLVM_ABI void AddDbgValue(SDDbgValue *DB, bool isParameter); |
1966 | |
1967 | /// Add a dbg_label SDNode. |
1968 | LLVM_ABI void AddDbgLabel(SDDbgLabel *DB); |
1969 | |
1970 | /// Get the debug values which reference the given SDNode. |
1971 | ArrayRef<SDDbgValue*> GetDbgValues(const SDNode* SD) const { |
1972 | return DbgInfo->getSDDbgValues(Node: SD); |
1973 | } |
1974 | |
1975 | public: |
1976 | /// Return true if there are any SDDbgValue nodes associated |
1977 | /// with this SelectionDAG. |
1978 | bool hasDebugValues() const { return !DbgInfo->empty(); } |
1979 | |
1980 | SDDbgInfo::DbgIterator DbgBegin() const { return DbgInfo->DbgBegin(); } |
1981 | SDDbgInfo::DbgIterator DbgEnd() const { return DbgInfo->DbgEnd(); } |
1982 | |
1983 | SDDbgInfo::DbgIterator ByvalParmDbgBegin() const { |
1984 | return DbgInfo->ByvalParmDbgBegin(); |
1985 | } |
1986 | SDDbgInfo::DbgIterator ByvalParmDbgEnd() const { |
1987 | return DbgInfo->ByvalParmDbgEnd(); |
1988 | } |
1989 | |
1990 | SDDbgInfo::DbgLabelIterator DbgLabelBegin() const { |
1991 | return DbgInfo->DbgLabelBegin(); |
1992 | } |
1993 | SDDbgInfo::DbgLabelIterator DbgLabelEnd() const { |
1994 | return DbgInfo->DbgLabelEnd(); |
1995 | } |
1996 | |
1997 | /// To be invoked on an SDNode that is slated to be erased. This |
1998 | /// function mirrors \c llvm::salvageDebugInfo. |
1999 | LLVM_ABI void salvageDebugInfo(SDNode &N); |
2000 | |
2001 | LLVM_ABI void dump() const; |
2002 | |
2003 | /// In most cases this function returns the ABI alignment for a given type, |
2004 | /// except for illegal vector types where the alignment exceeds that of the |
2005 | /// stack. In such cases we attempt to break the vector down to a legal type |
2006 | /// and return the ABI alignment for that instead. |
2007 | LLVM_ABI Align getReducedAlign(EVT VT, bool UseABI); |
2008 | |
2009 | /// Create a stack temporary based on the size in bytes and the alignment |
2010 | LLVM_ABI SDValue CreateStackTemporary(TypeSize Bytes, Align Alignment); |
2011 | |
2012 | /// Create a stack temporary, suitable for holding the specified value type. |
2013 | /// If minAlign is specified, the slot size will have at least that alignment. |
2014 | LLVM_ABI SDValue CreateStackTemporary(EVT VT, unsigned minAlign = 1); |
2015 | |
2016 | /// Create a stack temporary suitable for holding either of the specified |
2017 | /// value types. |
2018 | LLVM_ABI SDValue CreateStackTemporary(EVT VT1, EVT VT2); |
2019 | |
2020 | LLVM_ABI SDValue FoldSymbolOffset(unsigned Opcode, EVT VT, |
2021 | const GlobalAddressSDNode *GA, |
2022 | const SDNode *N2); |
2023 | |
2024 | LLVM_ABI SDValue FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL, |
2025 | EVT VT, ArrayRef<SDValue> Ops, |
2026 | SDNodeFlags Flags = SDNodeFlags()); |
2027 | |
2028 | /// Fold floating-point operations when all operands are constants and/or |
2029 | /// undefined. |
2030 | LLVM_ABI SDValue foldConstantFPMath(unsigned Opcode, const SDLoc &DL, EVT VT, |
2031 | ArrayRef<SDValue> Ops); |
2032 | |
2033 | /// Constant fold a setcc to true or false. |
2034 | LLVM_ABI SDValue FoldSetCC(EVT VT, SDValue N1, SDValue N2, ISD::CondCode Cond, |
2035 | const SDLoc &dl); |
2036 | |
2037 | /// Return true if the sign bit of Op is known to be zero. |
2038 | /// We use this predicate to simplify operations downstream. |
2039 | LLVM_ABI bool SignBitIsZero(SDValue Op, unsigned Depth = 0) const; |
2040 | |
2041 | /// Return true if 'Op & Mask' is known to be zero. We |
2042 | /// use this predicate to simplify operations downstream. Op and Mask are |
2043 | /// known to be the same type. |
2044 | LLVM_ABI bool MaskedValueIsZero(SDValue Op, const APInt &Mask, |
2045 | unsigned Depth = 0) const; |
2046 | |
2047 | /// Return true if 'Op & Mask' is known to be zero in DemandedElts. We |
2048 | /// use this predicate to simplify operations downstream. Op and Mask are |
2049 | /// known to be the same type. |
2050 | LLVM_ABI bool MaskedValueIsZero(SDValue Op, const APInt &Mask, |
2051 | const APInt &DemandedElts, |
2052 | unsigned Depth = 0) const; |
2053 | |
2054 | /// Return true if 'Op' is known to be zero in DemandedElts. We |
2055 | /// use this predicate to simplify operations downstream. |
2056 | LLVM_ABI bool MaskedVectorIsZero(SDValue Op, const APInt &DemandedElts, |
2057 | unsigned Depth = 0) const; |
2058 | |
2059 | /// Return true if '(Op & Mask) == Mask'. |
2060 | /// Op and Mask are known to be the same type. |
2061 | LLVM_ABI bool MaskedValueIsAllOnes(SDValue Op, const APInt &Mask, |
2062 | unsigned Depth = 0) const; |
2063 | |
2064 | /// For each demanded element of a vector, see if it is known to be zero. |
2065 | LLVM_ABI APInt computeVectorKnownZeroElements(SDValue Op, |
2066 | const APInt &DemandedElts, |
2067 | unsigned Depth = 0) const; |
2068 | |
2069 | /// Determine which bits of Op are known to be either zero or one and return |
2070 | /// them in Known. For vectors, the known bits are those that are shared by |
2071 | /// every vector element. |
2072 | /// Targets can implement the computeKnownBitsForTargetNode method in the |
2073 | /// TargetLowering class to allow target nodes to be understood. |
2074 | LLVM_ABI KnownBits computeKnownBits(SDValue Op, unsigned Depth = 0) const; |
2075 | |
2076 | /// Determine which bits of Op are known to be either zero or one and return |
2077 | /// them in Known. The DemandedElts argument allows us to only collect the |
2078 | /// known bits that are shared by the requested vector elements. |
2079 | /// Targets can implement the computeKnownBitsForTargetNode method in the |
2080 | /// TargetLowering class to allow target nodes to be understood. |
2081 | LLVM_ABI KnownBits computeKnownBits(SDValue Op, const APInt &DemandedElts, |
2082 | unsigned Depth = 0) const; |
2083 | |
2084 | /// Used to represent the possible overflow behavior of an operation. |
2085 | /// Never: the operation cannot overflow. |
2086 | /// Always: the operation will always overflow. |
2087 | /// Sometime: the operation may or may not overflow. |
2088 | enum OverflowKind { |
2089 | OFK_Never, |
2090 | OFK_Sometime, |
2091 | OFK_Always, |
2092 | }; |
2093 | |
2094 | /// Determine if the result of the signed addition of 2 nodes can overflow. |
2095 | LLVM_ABI OverflowKind computeOverflowForSignedAdd(SDValue N0, |
2096 | SDValue N1) const; |
2097 | |
2098 | /// Determine if the result of the unsigned addition of 2 nodes can overflow. |
2099 | LLVM_ABI OverflowKind computeOverflowForUnsignedAdd(SDValue N0, |
2100 | SDValue N1) const; |
2101 | |
2102 | /// Determine if the result of the addition of 2 nodes can overflow. |
2103 | OverflowKind computeOverflowForAdd(bool IsSigned, SDValue N0, |
2104 | SDValue N1) const { |
2105 | return IsSigned ? computeOverflowForSignedAdd(N0, N1) |
2106 | : computeOverflowForUnsignedAdd(N0, N1); |
2107 | } |
2108 | |
2109 | /// Determine if the result of the addition of 2 nodes can never overflow. |
2110 | bool willNotOverflowAdd(bool IsSigned, SDValue N0, SDValue N1) const { |
2111 | return computeOverflowForAdd(IsSigned, N0, N1) == OFK_Never; |
2112 | } |
2113 | |
2114 | /// Determine if the result of the signed sub of 2 nodes can overflow. |
2115 | LLVM_ABI OverflowKind computeOverflowForSignedSub(SDValue N0, |
2116 | SDValue N1) const; |
2117 | |
2118 | /// Determine if the result of the unsigned sub of 2 nodes can overflow. |
2119 | LLVM_ABI OverflowKind computeOverflowForUnsignedSub(SDValue N0, |
2120 | SDValue N1) const; |
2121 | |
2122 | /// Determine if the result of the sub of 2 nodes can overflow. |
2123 | OverflowKind computeOverflowForSub(bool IsSigned, SDValue N0, |
2124 | SDValue N1) const { |
2125 | return IsSigned ? computeOverflowForSignedSub(N0, N1) |
2126 | : computeOverflowForUnsignedSub(N0, N1); |
2127 | } |
2128 | |
2129 | /// Determine if the result of the sub of 2 nodes can never overflow. |
2130 | bool willNotOverflowSub(bool IsSigned, SDValue N0, SDValue N1) const { |
2131 | return computeOverflowForSub(IsSigned, N0, N1) == OFK_Never; |
2132 | } |
2133 | |
2134 | /// Determine if the result of the signed mul of 2 nodes can overflow. |
2135 | LLVM_ABI OverflowKind computeOverflowForSignedMul(SDValue N0, |
2136 | SDValue N1) const; |
2137 | |
2138 | /// Determine if the result of the unsigned mul of 2 nodes can overflow. |
2139 | LLVM_ABI OverflowKind computeOverflowForUnsignedMul(SDValue N0, |
2140 | SDValue N1) const; |
2141 | |
2142 | /// Determine if the result of the mul of 2 nodes can overflow. |
2143 | OverflowKind computeOverflowForMul(bool IsSigned, SDValue N0, |
2144 | SDValue N1) const { |
2145 | return IsSigned ? computeOverflowForSignedMul(N0, N1) |
2146 | : computeOverflowForUnsignedMul(N0, N1); |
2147 | } |
2148 | |
2149 | /// Determine if the result of the mul of 2 nodes can never overflow. |
2150 | bool willNotOverflowMul(bool IsSigned, SDValue N0, SDValue N1) const { |
2151 | return computeOverflowForMul(IsSigned, N0, N1) == OFK_Never; |
2152 | } |
2153 | |
2154 | /// Test if the given value is known to have exactly one bit set. This differs |
2155 | /// from computeKnownBits in that it doesn't necessarily determine which bit |
2156 | /// is set. |
2157 | LLVM_ABI bool isKnownToBeAPowerOfTwo(SDValue Val, unsigned Depth = 0) const; |
2158 | |
2159 | /// Test if the given _fp_ value is known to be an integer power-of-2, either |
2160 | /// positive or negative. |
2161 | LLVM_ABI bool isKnownToBeAPowerOfTwoFP(SDValue Val, unsigned Depth = 0) const; |
2162 | |
2163 | /// Return the number of times the sign bit of the register is replicated into |
2164 | /// the other bits. We know that at least 1 bit is always equal to the sign |
2165 | /// bit (itself), but other cases can give us information. For example, |
2166 | /// immediately after an "SRA X, 2", we know that the top 3 bits are all equal |
2167 | /// to each other, so we return 3. Targets can implement the |
2168 | /// ComputeNumSignBitsForTarget method in the TargetLowering class to allow |
2169 | /// target nodes to be understood. |
2170 | LLVM_ABI unsigned ComputeNumSignBits(SDValue Op, unsigned Depth = 0) const; |
2171 | |
2172 | /// Return the number of times the sign bit of the register is replicated into |
2173 | /// the other bits. We know that at least 1 bit is always equal to the sign |
2174 | /// bit (itself), but other cases can give us information. For example, |
2175 | /// immediately after an "SRA X, 2", we know that the top 3 bits are all equal |
2176 | /// to each other, so we return 3. The DemandedElts argument allows |
2177 | /// us to only collect the minimum sign bits of the requested vector elements. |
2178 | /// Targets can implement the ComputeNumSignBitsForTarget method in the |
2179 | /// TargetLowering class to allow target nodes to be understood. |
2180 | LLVM_ABI unsigned ComputeNumSignBits(SDValue Op, const APInt &DemandedElts, |
2181 | unsigned Depth = 0) const; |
2182 | |
2183 | /// Get the upper bound on bit size for this Value \p Op as a signed integer. |
2184 | /// i.e. x == sext(trunc(x to MaxSignedBits) to bitwidth(x)). |
2185 | /// Similar to the APInt::getSignificantBits function. |
2186 | /// Helper wrapper to ComputeNumSignBits. |
2187 | LLVM_ABI unsigned ComputeMaxSignificantBits(SDValue Op, |
2188 | unsigned Depth = 0) const; |
2189 | |
2190 | /// Get the upper bound on bit size for this Value \p Op as a signed integer. |
2191 | /// i.e. x == sext(trunc(x to MaxSignedBits) to bitwidth(x)). |
2192 | /// Similar to the APInt::getSignificantBits function. |
2193 | /// Helper wrapper to ComputeNumSignBits. |
2194 | LLVM_ABI unsigned ComputeMaxSignificantBits(SDValue Op, |
2195 | const APInt &DemandedElts, |
2196 | unsigned Depth = 0) const; |
2197 | |
2198 | /// Return true if this function can prove that \p Op is never poison |
2199 | /// and, if \p PoisonOnly is false, does not have undef bits. |
2200 | LLVM_ABI bool isGuaranteedNotToBeUndefOrPoison(SDValue Op, |
2201 | bool PoisonOnly = false, |
2202 | unsigned Depth = 0) const; |
2203 | |
2204 | /// Return true if this function can prove that \p Op is never poison |
2205 | /// and, if \p PoisonOnly is false, does not have undef bits. The DemandedElts |
2206 | /// argument limits the check to the requested vector elements. |
2207 | LLVM_ABI bool isGuaranteedNotToBeUndefOrPoison(SDValue Op, |
2208 | const APInt &DemandedElts, |
2209 | bool PoisonOnly = false, |
2210 | unsigned Depth = 0) const; |
2211 | |
2212 | /// Return true if this function can prove that \p Op is never poison. |
2213 | bool isGuaranteedNotToBePoison(SDValue Op, unsigned Depth = 0) const { |
2214 | return isGuaranteedNotToBeUndefOrPoison(Op, /*PoisonOnly*/ PoisonOnly: true, Depth); |
2215 | } |
2216 | |
2217 | /// Return true if this function can prove that \p Op is never poison. The |
2218 | /// DemandedElts argument limits the check to the requested vector elements. |
2219 | bool isGuaranteedNotToBePoison(SDValue Op, const APInt &DemandedElts, |
2220 | unsigned Depth = 0) const { |
2221 | return isGuaranteedNotToBeUndefOrPoison(Op, DemandedElts, |
2222 | /*PoisonOnly*/ PoisonOnly: true, Depth); |
2223 | } |
2224 | |
2225 | /// Return true if Op can create undef or poison from non-undef & non-poison |
2226 | /// operands. The DemandedElts argument limits the check to the requested |
2227 | /// vector elements. |
2228 | /// |
2229 | /// \p ConsiderFlags controls whether poison producing flags on the |
2230 | /// instruction are considered. This can be used to see if the instruction |
2231 | /// could still introduce undef or poison even without poison generating flags |
2232 | /// which might be on the instruction. (i.e. could the result of |
2233 | /// Op->dropPoisonGeneratingFlags() still create poison or undef) |
2234 | LLVM_ABI bool canCreateUndefOrPoison(SDValue Op, const APInt &DemandedElts, |
2235 | bool PoisonOnly = false, |
2236 | bool ConsiderFlags = true, |
2237 | unsigned Depth = 0) const; |
2238 | |
2239 | /// Return true if Op can create undef or poison from non-undef & non-poison |
2240 | /// operands. |
2241 | /// |
2242 | /// \p ConsiderFlags controls whether poison producing flags on the |
2243 | /// instruction are considered. This can be used to see if the instruction |
2244 | /// could still introduce undef or poison even without poison generating flags |
2245 | /// which might be on the instruction. (i.e. could the result of |
2246 | /// Op->dropPoisonGeneratingFlags() still create poison or undef) |
2247 | LLVM_ABI bool canCreateUndefOrPoison(SDValue Op, bool PoisonOnly = false, |
2248 | bool ConsiderFlags = true, |
2249 | unsigned Depth = 0) const; |
2250 | |
2251 | /// Return true if the specified operand is an ISD::OR or ISD::XOR node |
2252 | /// that can be treated as an ISD::ADD node. |
2253 | /// or(x,y) == add(x,y) iff haveNoCommonBitsSet(x,y) |
2254 | /// xor(x,y) == add(x,y) iff isMinSignedConstant(y) && !NoWrap |
2255 | /// If \p NoWrap is true, this will not match ISD::XOR. |
2256 | LLVM_ABI bool isADDLike(SDValue Op, bool NoWrap = false) const; |
2257 | |
2258 | /// Return true if the specified operand is an ISD::ADD with a ConstantSDNode |
2259 | /// on the right-hand side, or if it is an ISD::OR with a ConstantSDNode that |
2260 | /// is guaranteed to have the same semantics as an ADD. This handles the |
2261 | /// equivalence: |
2262 | /// X|Cst == X+Cst iff X&Cst = 0. |
2263 | LLVM_ABI bool isBaseWithConstantOffset(SDValue Op) const; |
2264 | |
2265 | /// Test whether the given SDValue (or all elements of it, if it is a |
2266 | /// vector) is known to never be NaN in \p DemandedElts. If \p SNaN is true, |
2267 | /// returns if \p Op is known to never be a signaling NaN (it may still be a |
2268 | /// qNaN). |
2269 | LLVM_ABI bool isKnownNeverNaN(SDValue Op, const APInt &DemandedElts, |
2270 | bool SNaN = false, unsigned Depth = 0) const; |
2271 | |
2272 | /// Test whether the given SDValue (or all elements of it, if it is a |
2273 | /// vector) is known to never be NaN. If \p SNaN is true, returns if \p Op is |
2274 | /// known to never be a signaling NaN (it may still be a qNaN). |
2275 | LLVM_ABI bool isKnownNeverNaN(SDValue Op, bool SNaN = false, |
2276 | unsigned Depth = 0) const; |
2277 | |
2278 | /// \returns true if \p Op is known to never be a signaling NaN in \p |
2279 | /// DemandedElts. |
2280 | bool isKnownNeverSNaN(SDValue Op, const APInt &DemandedElts, |
2281 | unsigned Depth = 0) const { |
2282 | return isKnownNeverNaN(Op, DemandedElts, SNaN: true, Depth); |
2283 | } |
2284 | |
2285 | /// \returns true if \p Op is known to never be a signaling NaN. |
2286 | bool isKnownNeverSNaN(SDValue Op, unsigned Depth = 0) const { |
2287 | return isKnownNeverNaN(Op, SNaN: true, Depth); |
2288 | } |
2289 | |
2290 | /// Test whether the given floating point SDValue is known to never be |
2291 | /// positive or negative zero. |
2292 | LLVM_ABI bool isKnownNeverZeroFloat(SDValue Op) const; |
2293 | |
2294 | /// Test whether the given SDValue is known to contain non-zero value(s). |
2295 | LLVM_ABI bool isKnownNeverZero(SDValue Op, unsigned Depth = 0) const; |
2296 | |
2297 | /// Test whether the given float value is known to be positive. +0.0, +inf and |
2298 | /// +nan are considered positive, -0.0, -inf and -nan are not. |
2299 | LLVM_ABI bool cannotBeOrderedNegativeFP(SDValue Op) const; |
2300 | |
2301 | /// Test whether two SDValues are known to compare equal. This |
2302 | /// is true if they are the same value, or if one is negative zero and the |
2303 | /// other positive zero. |
2304 | LLVM_ABI bool isEqualTo(SDValue A, SDValue B) const; |
2305 | |
2306 | /// Return true if A and B have no common bits set. As an example, this can |
2307 | /// allow an 'add' to be transformed into an 'or'. |
2308 | LLVM_ABI bool haveNoCommonBitsSet(SDValue A, SDValue B) const; |
2309 | |
2310 | /// Test whether \p V has a splatted value for all the demanded elements. |
2311 | /// |
2312 | /// On success \p UndefElts will indicate the elements that have UNDEF |
2313 | /// values instead of the splat value, this is only guaranteed to be correct |
2314 | /// for \p DemandedElts. |
2315 | /// |
2316 | /// NOTE: The function will return true for a demanded splat of UNDEF values. |
2317 | LLVM_ABI bool isSplatValue(SDValue V, const APInt &DemandedElts, |
2318 | APInt &UndefElts, unsigned Depth = 0) const; |
2319 | |
2320 | /// Test whether \p V has a splatted value. |
2321 | LLVM_ABI bool isSplatValue(SDValue V, bool AllowUndefs = false) const; |
2322 | |
2323 | /// If V is a splatted value, return the source vector and its splat index. |
2324 | LLVM_ABI SDValue getSplatSourceVector(SDValue V, int &SplatIndex); |
2325 | |
2326 | /// If V is a splat vector, return its scalar source operand by extracting |
2327 | /// that element from the source vector. If LegalTypes is true, this method |
2328 | /// may only return a legally-typed splat value. If it cannot legalize the |
2329 | /// splatted value it will return SDValue(). |
2330 | LLVM_ABI SDValue getSplatValue(SDValue V, bool LegalTypes = false); |
2331 | |
2332 | /// If a SHL/SRA/SRL node \p V has shift amounts that are all less than the |
2333 | /// element bit-width of the shift node, return the valid constant range. |
2334 | LLVM_ABI std::optional<ConstantRange> |
2335 | getValidShiftAmountRange(SDValue V, const APInt &DemandedElts, |
2336 | unsigned Depth) const; |
2337 | |
2338 | /// If a SHL/SRA/SRL node \p V has a uniform shift amount |
2339 | /// that is less than the element bit-width of the shift node, return it. |
2340 | LLVM_ABI std::optional<uint64_t> |
2341 | getValidShiftAmount(SDValue V, const APInt &DemandedElts, |
2342 | unsigned Depth = 0) const; |
2343 | |
2344 | /// If a SHL/SRA/SRL node \p V has a uniform shift amount |
2345 | /// that is less than the element bit-width of the shift node, return it. |
2346 | LLVM_ABI std::optional<uint64_t> |
2347 | getValidShiftAmount(SDValue V, unsigned Depth = 0) const; |
2348 | |
2349 | /// If a SHL/SRA/SRL node \p V has shift amounts that are all less than the |
2350 | /// element bit-width of the shift node, return the minimum possible value. |
2351 | LLVM_ABI std::optional<uint64_t> |
2352 | getValidMinimumShiftAmount(SDValue V, const APInt &DemandedElts, |
2353 | unsigned Depth = 0) const; |
2354 | |
2355 | /// If a SHL/SRA/SRL node \p V has shift amounts that are all less than the |
2356 | /// element bit-width of the shift node, return the minimum possible value. |
2357 | LLVM_ABI std::optional<uint64_t> |
2358 | getValidMinimumShiftAmount(SDValue V, unsigned Depth = 0) const; |
2359 | |
2360 | /// If a SHL/SRA/SRL node \p V has shift amounts that are all less than the |
2361 | /// element bit-width of the shift node, return the maximum possible value. |
2362 | LLVM_ABI std::optional<uint64_t> |
2363 | getValidMaximumShiftAmount(SDValue V, const APInt &DemandedElts, |
2364 | unsigned Depth = 0) const; |
2365 | |
2366 | /// If a SHL/SRA/SRL node \p V has shift amounts that are all less than the |
2367 | /// element bit-width of the shift node, return the maximum possible value. |
2368 | LLVM_ABI std::optional<uint64_t> |
2369 | getValidMaximumShiftAmount(SDValue V, unsigned Depth = 0) const; |
2370 | |
2371 | /// Match a binop + shuffle pyramid that represents a horizontal reduction |
2372 | /// over the elements of a vector starting from the EXTRACT_VECTOR_ELT node /p |
2373 | /// Extract. The reduction must use one of the opcodes listed in /p |
2374 | /// CandidateBinOps and on success /p BinOp will contain the matching opcode. |
2375 | /// Returns the vector that is being reduced on, or SDValue() if a reduction |
2376 | /// was not matched. If \p AllowPartials is set then in the case of a |
2377 | /// reduction pattern that only matches the first few stages, the extracted |
2378 | /// subvector of the start of the reduction is returned. |
2379 | LLVM_ABI SDValue matchBinOpReduction(SDNode *Extract, ISD::NodeType &BinOp, |
2380 | ArrayRef<ISD::NodeType> CandidateBinOps, |
2381 | bool AllowPartials = false); |
2382 | |
2383 | /// Utility function used by legalize and lowering to |
2384 | /// "unroll" a vector operation by splitting out the scalars and operating |
2385 | /// on each element individually. If the ResNE is 0, fully unroll the vector |
2386 | /// op. If ResNE is less than the width of the vector op, unroll up to ResNE. |
2387 | /// If the ResNE is greater than the width of the vector op, unroll the |
2388 | /// vector op and fill the end of the resulting vector with UNDEFS. |
2389 | LLVM_ABI SDValue UnrollVectorOp(SDNode *N, unsigned ResNE = 0); |
2390 | |
2391 | /// Like UnrollVectorOp(), but for the [US](ADD|SUB|MUL)O family of opcodes. |
2392 | /// This is a separate function because those opcodes have two results. |
2393 | LLVM_ABI std::pair<SDValue, SDValue> |
2394 | UnrollVectorOverflowOp(SDNode *N, unsigned ResNE = 0); |
2395 | |
2396 | /// Return true if loads are next to each other and can be |
2397 | /// merged. Check that both are nonvolatile and if LD is loading |
2398 | /// 'Bytes' bytes from a location that is 'Dist' units away from the |
2399 | /// location that the 'Base' load is loading from. |
2400 | LLVM_ABI bool areNonVolatileConsecutiveLoads(LoadSDNode *LD, LoadSDNode *Base, |
2401 | unsigned Bytes, int Dist) const; |
2402 | |
2403 | /// Infer alignment of a load / store address. Return std::nullopt if it |
2404 | /// cannot be inferred. |
2405 | LLVM_ABI MaybeAlign InferPtrAlign(SDValue Ptr) const; |
2406 | |
2407 | /// Split the scalar node with EXTRACT_ELEMENT using the provided VTs and |
2408 | /// return the low/high part. |
2409 | LLVM_ABI std::pair<SDValue, SDValue> SplitScalar(const SDValue &N, |
2410 | const SDLoc &DL, |
2411 | const EVT &LoVT, |
2412 | const EVT &HiVT); |
2413 | |
2414 | /// Compute the VTs needed for the low/hi parts of a type |
2415 | /// which is split (or expanded) into two not necessarily identical pieces. |
2416 | LLVM_ABI std::pair<EVT, EVT> GetSplitDestVTs(const EVT &VT) const; |
2417 | |
2418 | /// Compute the VTs needed for the low/hi parts of a type, dependent on an |
2419 | /// enveloping VT that has been split into two identical pieces. Sets the |
2420 | /// HisIsEmpty flag when hi type has zero storage size. |
2421 | LLVM_ABI std::pair<EVT, EVT> GetDependentSplitDestVTs(const EVT &VT, |
2422 | const EVT &EnvVT, |
2423 | bool *HiIsEmpty) const; |
2424 | |
2425 | /// Split the vector with EXTRACT_SUBVECTOR using the provided |
2426 | /// VTs and return the low/high part. |
2427 | LLVM_ABI std::pair<SDValue, SDValue> SplitVector(const SDValue &N, |
2428 | const SDLoc &DL, |
2429 | const EVT &LoVT, |
2430 | const EVT &HiVT); |
2431 | |
2432 | /// Split the vector with EXTRACT_SUBVECTOR and return the low/high part. |
2433 | std::pair<SDValue, SDValue> SplitVector(const SDValue &N, const SDLoc &DL) { |
2434 | EVT LoVT, HiVT; |
2435 | std::tie(args&: LoVT, args&: HiVT) = GetSplitDestVTs(VT: N.getValueType()); |
2436 | return SplitVector(N, DL, LoVT, HiVT); |
2437 | } |
2438 | |
2439 | /// Split the explicit vector length parameter of a VP operation. |
2440 | LLVM_ABI std::pair<SDValue, SDValue> SplitEVL(SDValue N, EVT VecVT, |
2441 | const SDLoc &DL); |
2442 | |
2443 | /// Split the node's operand with EXTRACT_SUBVECTOR and |
2444 | /// return the low/high part. |
2445 | std::pair<SDValue, SDValue> SplitVectorOperand(const SDNode *N, unsigned OpNo) |
2446 | { |
2447 | return SplitVector(N: N->getOperand(Num: OpNo), DL: SDLoc(N)); |
2448 | } |
2449 | |
2450 | /// Widen the vector up to the next power of two using INSERT_SUBVECTOR. |
2451 | LLVM_ABI SDValue WidenVector(const SDValue &N, const SDLoc &DL); |
2452 | |
2453 | /// Append the extracted elements from Start to Count out of the vector Op in |
2454 | /// Args. If Count is 0, all of the elements will be extracted. The extracted |
2455 | /// elements will have type EVT if it is provided, and otherwise their type |
2456 | /// will be Op's element type. |
2457 | LLVM_ABI void ExtractVectorElements(SDValue Op, |
2458 | SmallVectorImpl<SDValue> &Args, |
2459 | unsigned Start = 0, unsigned Count = 0, |
2460 | EVT EltVT = EVT()); |
2461 | |
2462 | /// Compute the default alignment value for the given type. |
2463 | LLVM_ABI Align getEVTAlign(EVT MemoryVT) const; |
2464 | |
2465 | /// Test whether the given value is a constant int or similar node. |
2466 | LLVM_ABI bool |
2467 | isConstantIntBuildVectorOrConstantInt(SDValue N, |
2468 | bool AllowOpaques = true) const; |
2469 | |
2470 | /// Test whether the given value is a constant FP or similar node. |
2471 | LLVM_ABI bool isConstantFPBuildVectorOrConstantFP(SDValue N) const; |
2472 | |
2473 | /// \returns true if \p N is any kind of constant or build_vector of |
2474 | /// constants, int or float. If a vector, it may not necessarily be a splat. |
2475 | inline bool isConstantValueOfAnyType(SDValue N) const { |
2476 | return isConstantIntBuildVectorOrConstantInt(N) || |
2477 | isConstantFPBuildVectorOrConstantFP(N); |
2478 | } |
2479 | |
2480 | /// Check if a value \op N is a constant using the target's BooleanContent for |
2481 | /// its type. |
2482 | LLVM_ABI std::optional<bool> |
2483 | isBoolConstant(SDValue N, bool AllowTruncation = false) const; |
2484 | |
2485 | /// Set CallSiteInfo to be associated with Node. |
2486 | void addCallSiteInfo(const SDNode *Node, CallSiteInfo &&CallInfo) { |
2487 | SDEI[Node].CSInfo = std::move(CallInfo); |
2488 | } |
2489 | /// Return CallSiteInfo associated with Node, or a default if none exists. |
2490 | CallSiteInfo getCallSiteInfo(const SDNode *Node) { |
2491 | auto I = SDEI.find(Val: Node); |
2492 | return I != SDEI.end() ? std::move(I->second).CSInfo : CallSiteInfo(); |
2493 | } |
2494 | /// Set HeapAllocSite to be associated with Node. |
2495 | void addHeapAllocSite(const SDNode *Node, MDNode *MD) { |
2496 | SDEI[Node].HeapAllocSite = MD; |
2497 | } |
2498 | /// Return HeapAllocSite associated with Node, or nullptr if none exists. |
2499 | MDNode *getHeapAllocSite(const SDNode *Node) const { |
2500 | auto I = SDEI.find(Val: Node); |
2501 | return I != SDEI.end() ? I->second.HeapAllocSite : nullptr; |
2502 | } |
2503 | /// Set PCSections to be associated with Node. |
2504 | void addPCSections(const SDNode *Node, MDNode *MD) { |
2505 | SDEI[Node].PCSections = MD; |
2506 | } |
2507 | /// Set MMRAMetadata to be associated with Node. |
2508 | void addMMRAMetadata(const SDNode *Node, MDNode *MMRA) { |
2509 | SDEI[Node].MMRA = MMRA; |
2510 | } |
2511 | /// Return PCSections associated with Node, or nullptr if none exists. |
2512 | MDNode *getPCSections(const SDNode *Node) const { |
2513 | auto It = SDEI.find(Val: Node); |
2514 | return It != SDEI.end() ? It->second.PCSections : nullptr; |
2515 | } |
2516 | /// Return the MMRA MDNode associated with Node, or nullptr if none |
2517 | /// exists. |
2518 | MDNode *getMMRAMetadata(const SDNode *Node) const { |
2519 | auto It = SDEI.find(Val: Node); |
2520 | return It != SDEI.end() ? It->second.MMRA : nullptr; |
2521 | } |
2522 | /// Set CalledGlobal to be associated with Node. |
2523 | void addCalledGlobal(const SDNode *Node, const GlobalValue *GV, |
2524 | unsigned OpFlags) { |
2525 | SDEI[Node].CalledGlobal = {.Callee: GV, .TargetFlags: OpFlags}; |
2526 | } |
2527 | /// Return CalledGlobal associated with Node, or a nullopt if none exists. |
2528 | std::optional<CalledGlobalInfo> getCalledGlobal(const SDNode *Node) { |
2529 | auto I = SDEI.find(Val: Node); |
2530 | return I != SDEI.end() |
2531 | ? std::make_optional(t: std::move(I->second).CalledGlobal) |
2532 | : std::nullopt; |
2533 | } |
2534 | /// Set NoMergeSiteInfo to be associated with Node if NoMerge is true. |
2535 | void addNoMergeSiteInfo(const SDNode *Node, bool NoMerge) { |
2536 | if (NoMerge) |
2537 | SDEI[Node].NoMerge = NoMerge; |
2538 | } |
2539 | /// Return NoMerge info associated with Node. |
2540 | bool getNoMergeSiteInfo(const SDNode *Node) const { |
2541 | auto I = SDEI.find(Val: Node); |
2542 | return I != SDEI.end() ? I->second.NoMerge : false; |
2543 | } |
2544 | |
2545 | /// Copy extra info associated with one node to another. |
2546 | LLVM_ABI void copyExtraInfo(SDNode *From, SDNode *To); |
2547 | |
2548 | /// Return the current function's default denormal handling kind for the given |
2549 | /// floating point type. |
2550 | DenormalMode getDenormalMode(EVT VT) const { |
2551 | return MF->getDenormalMode(FPType: VT.getFltSemantics()); |
2552 | } |
2553 | |
2554 | LLVM_ABI bool shouldOptForSize() const; |
2555 | |
2556 | /// Get the (commutative) neutral element for the given opcode, if it exists. |
2557 | LLVM_ABI SDValue getNeutralElement(unsigned Opcode, const SDLoc &DL, EVT VT, |
2558 | SDNodeFlags Flags); |
2559 | |
2560 | /// Some opcodes may create immediate undefined behavior when used with some |
2561 | /// values (integer division-by-zero for example). Therefore, these operations |
2562 | /// are not generally safe to move around or change. |
2563 | bool isSafeToSpeculativelyExecute(unsigned Opcode) const { |
2564 | switch (Opcode) { |
2565 | case ISD::SDIV: |
2566 | case ISD::SREM: |
2567 | case ISD::SDIVREM: |
2568 | case ISD::UDIV: |
2569 | case ISD::UREM: |
2570 | case ISD::UDIVREM: |
2571 | return false; |
2572 | default: |
2573 | return true; |
2574 | } |
2575 | } |
2576 | |
2577 | /// Check if the provided node is save to speculatively executed given its |
2578 | /// current arguments. So, while `udiv` the opcode is not safe to |
2579 | /// speculatively execute, a given `udiv` node may be if the denominator is |
2580 | /// known nonzero. |
2581 | bool isSafeToSpeculativelyExecuteNode(const SDNode *N) const { |
2582 | switch (N->getOpcode()) { |
2583 | case ISD::UDIV: |
2584 | return isKnownNeverZero(Op: N->getOperand(Num: 1)); |
2585 | default: |
2586 | return isSafeToSpeculativelyExecute(Opcode: N->getOpcode()); |
2587 | } |
2588 | } |
2589 | |
2590 | LLVM_ABI SDValue makeStateFunctionCall(unsigned LibFunc, SDValue Ptr, |
2591 | SDValue InChain, const SDLoc &DLoc); |
2592 | |
2593 | private: |
2594 | #ifndef NDEBUG |
2595 | void verifyNode(SDNode *N) const; |
2596 | #endif |
2597 | void InsertNode(SDNode *N); |
2598 | bool RemoveNodeFromCSEMaps(SDNode *N); |
2599 | void AddModifiedNodeToCSEMaps(SDNode *N); |
2600 | SDNode *FindModifiedNodeSlot(SDNode *N, SDValue Op, void *&InsertPos); |
2601 | SDNode *FindModifiedNodeSlot(SDNode *N, SDValue Op1, SDValue Op2, |
2602 | void *&InsertPos); |
2603 | SDNode *FindModifiedNodeSlot(SDNode *N, ArrayRef<SDValue> Ops, |
2604 | void *&InsertPos); |
2605 | SDNode *UpdateSDLocOnMergeSDNode(SDNode *N, const SDLoc &loc); |
2606 | |
2607 | void DeleteNodeNotInCSEMaps(SDNode *N); |
2608 | void DeallocateNode(SDNode *N); |
2609 | |
2610 | void allnodes_clear(); |
2611 | |
2612 | /// Look up the node specified by ID in CSEMap. If it exists, return it. If |
2613 | /// not, return the insertion token that will make insertion faster. This |
2614 | /// overload is for nodes other than Constant or ConstantFP, use the other one |
2615 | /// for those. |
2616 | SDNode *FindNodeOrInsertPos(const FoldingSetNodeID &ID, void *&InsertPos); |
2617 | |
2618 | /// Look up the node specified by ID in CSEMap. If it exists, return it. If |
2619 | /// not, return the insertion token that will make insertion faster. Performs |
2620 | /// additional processing for constant nodes. |
2621 | SDNode *FindNodeOrInsertPos(const FoldingSetNodeID &ID, const SDLoc &DL, |
2622 | void *&InsertPos); |
2623 | |
2624 | /// Maps to auto-CSE operations. |
2625 | std::vector<CondCodeSDNode*> CondCodeNodes; |
2626 | |
2627 | std::vector<SDNode*> ValueTypeNodes; |
2628 | std::map<EVT, SDNode*, EVT::compareRawBits> ExtendedValueTypeNodes; |
2629 | StringMap<SDNode*> ExternalSymbols; |
2630 | |
2631 | std::map<std::pair<std::string, unsigned>, SDNode *> TargetExternalSymbols; |
2632 | DenseMap<MCSymbol *, SDNode *> MCSymbols; |
2633 | |
2634 | FlagInserter *Inserter = nullptr; |
2635 | }; |
2636 | |
2637 | template <> struct GraphTraits<SelectionDAG*> : public GraphTraits<SDNode*> { |
2638 | using nodes_iterator = pointer_iterator<SelectionDAG::allnodes_iterator>; |
2639 | |
2640 | static nodes_iterator nodes_begin(SelectionDAG *G) { |
2641 | return nodes_iterator(G->allnodes_begin()); |
2642 | } |
2643 | |
2644 | static nodes_iterator nodes_end(SelectionDAG *G) { |
2645 | return nodes_iterator(G->allnodes_end()); |
2646 | } |
2647 | }; |
2648 | |
2649 | } // end namespace llvm |
2650 | |
2651 | #endif // LLVM_CODEGEN_SELECTIONDAG_H |
2652 |
Definitions
- SDVTListNode
- SDVTListNode
- getSDVTList
- FoldingSetTrait
- Profile
- Equals
- ComputeHash
- ilist_alloc_traits
- deleteNode
- SDDbgInfo
- SDDbgInfo
- SDDbgInfo
- operator=
- add
- clear
- getAlloc
- empty
- getSDDbgValues
- DbgBegin
- DbgEnd
- ByvalParmDbgBegin
- ByvalParmDbgEnd
- DbgLabelBegin
- DbgLabelEnd
- SelectionDAG
- NodeExtraInfo
- DAGUpdateListener
- DAGUpdateListener
- ~DAGUpdateListener
- DAGNodeDeletedListener
- DAGNodeDeletedListener
- NodeDeleted
- DAGNodeInsertedListener
- DAGNodeInsertedListener
- NodeInserted
- FlagInserter
- FlagInserter
- FlagInserter
- FlagInserter
- operator=
- ~FlagInserter
- getFlags
- newSDNode
- getSyntheticNodeSubclassData
- getSyntheticNodeSubclassData
- removeOperands
- MaxRecursionDepth
- SelectionDAG
- operator=
- init
- setFunctionLoweringInfo
- getMachineFunction
- getPass
- getMFAM
- getOptLevel
- getDataLayout
- getTarget
- getSubtarget
- getSubtarget
- getTargetLoweringInfo
- getLibInfo
- getSelectionDAGInfo
- getUniformityInfo
- getFunctionVarLocs
- getContext
- getORE
- getPSI
- getBFI
- getMMI
- getFlagInserter
- setFlagInserter
- allnodes_begin
- allnodes_end
- allnodes_begin
- allnodes_end
- allnodes_size
- allnodes
- allnodes
- getRoot
- getEntryNode
- setRoot
- getTargetConstant
- getTargetConstant
- getTargetConstant
- getSignedTargetConstant
- getTargetConstantFP
- getTargetConstantFP
- getTargetConstantFP
- getTargetGlobalAddress
- getTargetFrameIndex
- getTargetJumpTable
- getTargetConstantPool
- getTargetConstantPool
- getTargetBlockAddress
- getCopyToReg
- getCopyToReg
- getCopyToReg
- getCopyFromReg
- getCopyFromReg
- getBuildVector
- getBuildVector
- getSplatBuildVector
- getSplatVector
- getSplat
- getExtractVectorElt
- getInsertVectorElt
- getInsertSubvector
- getExtractSubvector
- getOpcode_EXTEND
- getOpcode_EXTEND_VECTOR_INREG
- getExtOrTrunc
- getExtOrTrunc
- getObjectPtrOffset
- getObjectPtrOffset
- getCALLSEQ_START
- getCALLSEQ_END
- getCALLSEQ_END
- getUNDEF
- getPOISON
- getGLOBAL_OFFSET_TABLE
- getSetCC
- getSetCCVP
- getSelect
- getSelectCC
- getMemIntrinsicNode
- getLoad
- getStore
- getTruncStore
- getLoadVP
- RepositionNode
- GetDbgValues
- hasDebugValues
- DbgBegin
- DbgEnd
- ByvalParmDbgBegin
- ByvalParmDbgEnd
- DbgLabelBegin
- DbgLabelEnd
- OverflowKind
- computeOverflowForAdd
- willNotOverflowAdd
- computeOverflowForSub
- willNotOverflowSub
- computeOverflowForMul
- willNotOverflowMul
- isGuaranteedNotToBePoison
- isGuaranteedNotToBePoison
- isKnownNeverSNaN
- isKnownNeverSNaN
- SplitVector
- SplitVectorOperand
- isConstantValueOfAnyType
- addCallSiteInfo
- getCallSiteInfo
- addHeapAllocSite
- getHeapAllocSite
- addPCSections
- addMMRAMetadata
- getPCSections
- getMMRAMetadata
- addCalledGlobal
- getCalledGlobal
- addNoMergeSiteInfo
- getNoMergeSiteInfo
- getDenormalMode
- isSafeToSpeculativelyExecute
- isSafeToSpeculativelyExecuteNode
- GraphTraits
- nodes_begin
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more