LLVM 17.0.0git
SelectionDAG.h
Go to the documentation of this file.
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/APFloat.h"
18#include "llvm/ADT/APInt.h"
19#include "llvm/ADT/ArrayRef.h"
20#include "llvm/ADT/DenseMap.h"
21#include "llvm/ADT/DenseSet.h"
22#include "llvm/ADT/FoldingSet.h"
24#include "llvm/ADT/StringMap.h"
25#include "llvm/ADT/ilist.h"
26#include "llvm/ADT/iterator.h"
35#include "llvm/IR/DebugLoc.h"
36#include "llvm/IR/Metadata.h"
42#include <cassert>
43#include <cstdint>
44#include <functional>
45#include <map>
46#include <string>
47#include <tuple>
48#include <utility>
49#include <vector>
50
51namespace llvm {
52
53class DIExpression;
54class DILabel;
55class DIVariable;
56class Function;
57class Pass;
58class Type;
59template <class GraphType> struct GraphTraits;
60template <typename T, unsigned int N> class SmallSetVector;
61template <typename T, typename Enable> struct FoldingSetTrait;
62class AAResults;
63class BlockAddress;
64class BlockFrequencyInfo;
65class Constant;
66class ConstantFP;
67class ConstantInt;
68class DataLayout;
69struct fltSemantics;
70class FunctionLoweringInfo;
71class FunctionVarLocs;
72class GlobalValue;
73struct KnownBits;
74class LLVMContext;
75class MachineBasicBlock;
76class MachineConstantPoolValue;
77class MCSymbol;
78class OptimizationRemarkEmitter;
79class ProfileSummaryInfo;
80class SDDbgValue;
81class SDDbgOperand;
82class SDDbgLabel;
83class SelectionDAG;
84class SelectionDAGTargetInfo;
85class TargetLibraryInfo;
86class TargetLowering;
87class TargetMachine;
88class TargetSubtargetInfo;
89class Value;
90
91template <typename T> class GenericSSAContext;
92using SSAContext = GenericSSAContext<Function>;
93template <typename T> class GenericUniformityInfo;
94using UniformityInfo = GenericUniformityInfo<SSAContext>;
95
97 friend struct FoldingSetTrait<SDVTListNode>;
98
99 /// A reference to an Interned FoldingSetNodeID for this node.
100 /// The Allocator in SelectionDAG holds the data.
101 /// SDVTList contains all types which are frequently accessed in SelectionDAG.
102 /// The size of this list is not expected to be big so it won't introduce
103 /// a memory penalty.
104 FoldingSetNodeIDRef FastID;
105 const EVT *VTs;
106 unsigned int NumVTs;
107 /// The hash value for SDVTList is fixed, so cache it to avoid
108 /// hash calculation.
109 unsigned HashValue;
110
111public:
112 SDVTListNode(const FoldingSetNodeIDRef ID, const EVT *VT, unsigned int Num) :
113 FastID(ID), VTs(VT), NumVTs(Num) {
114 HashValue = ID.ComputeHash();
115 }
116
118 SDVTList result = {VTs, NumVTs};
119 return result;
120 }
121};
122
123/// Specialize FoldingSetTrait for SDVTListNode
124/// to avoid computing temp FoldingSetNodeID and hash value.
125template<> struct FoldingSetTrait<SDVTListNode> : DefaultFoldingSetTrait<SDVTListNode> {
126 static void Profile(const SDVTListNode &X, FoldingSetNodeID& ID) {
127 ID = X.FastID;
128 }
129
130 static bool Equals(const SDVTListNode &X, const FoldingSetNodeID &ID,
131 unsigned IDHash, FoldingSetNodeID &TempID) {
132 if (X.HashValue != IDHash)
133 return false;
134 return ID == X.FastID;
135 }
136
137 static unsigned ComputeHash(const SDVTListNode &X, FoldingSetNodeID &TempID) {
138 return X.HashValue;
139 }
140};
141
142template <> struct ilist_alloc_traits<SDNode> {
143 static void deleteNode(SDNode *) {
144 llvm_unreachable("ilist_traits<SDNode> shouldn't see a deleteNode call!");
145 }
146};
147
148/// Keeps track of dbg_value information through SDISel. We do
149/// not build SDNodes for these so as not to perturb the generated code;
150/// instead the info is kept off to the side in this structure. Each SDNode may
151/// have one or more associated dbg_value entries. This information is kept in
152/// DbgValMap.
153/// Byval parameters are handled separately because they don't use alloca's,
154/// which busts the normal mechanism. There is good reason for handling all
155/// parameters separately: they may not have code generated for them, they
156/// should always go at the beginning of the function regardless of other code
157/// motion, and debug info for them is potentially useful even if the parameter
158/// is unused. Right now only byval parameters are handled separately.
160 BumpPtrAllocator Alloc;
162 SmallVector<SDDbgValue*, 32> ByvalParmDbgValues;
165 DbgValMapType DbgValMap;
166
167public:
168 SDDbgInfo() = default;
169 SDDbgInfo(const SDDbgInfo &) = delete;
170 SDDbgInfo &operator=(const SDDbgInfo &) = delete;
171
172 void add(SDDbgValue *V, bool isParameter);
173
174 void add(SDDbgLabel *L) { DbgLabels.push_back(L); }
175
176 /// Invalidate all DbgValues attached to the node and remove
177 /// it from the Node-to-DbgValues map.
178 void erase(const SDNode *Node);
179
180 void clear() {
181 DbgValMap.clear();
182 DbgValues.clear();
183 ByvalParmDbgValues.clear();
184 DbgLabels.clear();
185 Alloc.Reset();
186 }
187
188 BumpPtrAllocator &getAlloc() { return Alloc; }
189
190 bool empty() const {
191 return DbgValues.empty() && ByvalParmDbgValues.empty() && DbgLabels.empty();
192 }
193
195 auto I = DbgValMap.find(Node);
196 if (I != DbgValMap.end())
197 return I->second;
198 return ArrayRef<SDDbgValue*>();
199 }
200
203
204 DbgIterator DbgBegin() { return DbgValues.begin(); }
205 DbgIterator DbgEnd() { return DbgValues.end(); }
206 DbgIterator ByvalParmDbgBegin() { return ByvalParmDbgValues.begin(); }
207 DbgIterator ByvalParmDbgEnd() { return ByvalParmDbgValues.end(); }
208 DbgLabelIterator DbgLabelBegin() { return DbgLabels.begin(); }
209 DbgLabelIterator DbgLabelEnd() { return DbgLabels.end(); }
210};
211
212void checkForCycles(const SelectionDAG *DAG, bool force = false);
213
214/// This is used to represent a portion of an LLVM function in a low-level
215/// Data Dependence DAG representation suitable for instruction selection.
216/// This DAG is constructed as the first step of instruction selection in order
217/// to allow implementation of machine specific optimizations
218/// and code simplifications.
219///
220/// The representation used by the SelectionDAG is a target-independent
221/// representation, which has some similarities to the GCC RTL representation,
222/// but is significantly more simple, powerful, and is a graph form instead of a
223/// linear form.
224///
226 const TargetMachine &TM;
227 const SelectionDAGTargetInfo *TSI = nullptr;
228 const TargetLowering *TLI = nullptr;
229 const TargetLibraryInfo *LibInfo = nullptr;
230 const FunctionVarLocs *FnVarLocs = nullptr;
231 MachineFunction *MF;
232 Pass *SDAGISelPass = nullptr;
233 LLVMContext *Context;
234 CodeGenOpt::Level OptLevel;
235
236 UniformityInfo *UA = nullptr;
237 FunctionLoweringInfo * FLI = nullptr;
238
239 /// The function-level optimization remark emitter. Used to emit remarks
240 /// whenever manipulating the DAG.
242
243 ProfileSummaryInfo *PSI = nullptr;
244 BlockFrequencyInfo *BFI = nullptr;
245
246 /// List of non-single value types.
247 FoldingSet<SDVTListNode> VTListMap;
248
249 /// Pool allocation for misc. objects that are created once per SelectionDAG.
250 BumpPtrAllocator Allocator;
251
252 /// The starting token.
253 SDNode EntryNode;
254
255 /// The root of the entire DAG.
256 SDValue Root;
257
258 /// A linked list of nodes in the current DAG.
259 ilist<SDNode> AllNodes;
260
261 /// The AllocatorType for allocating SDNodes. We use
262 /// pool allocation with recycling.
264 sizeof(LargestSDNode),
265 alignof(MostAlignedSDNode)>;
266
267 /// Pool allocation for nodes.
268 NodeAllocatorType NodeAllocator;
269
270 /// This structure is used to memoize nodes, automatically performing
271 /// CSE with existing nodes when a duplicate is requested.
272 FoldingSet<SDNode> CSEMap;
273
274 /// Pool allocation for machine-opcode SDNode operands.
275 BumpPtrAllocator OperandAllocator;
276 ArrayRecycler<SDUse> OperandRecycler;
277
278 /// Tracks dbg_value and dbg_label information through SDISel.
279 SDDbgInfo *DbgInfo;
280
283
284 struct NodeExtraInfo {
285 CallSiteInfo CSInfo;
286 MDNode *HeapAllocSite = nullptr;
287 MDNode *PCSections = nullptr;
288 bool NoMerge = false;
289 };
290 /// Out-of-line extra information for SDNodes.
292
293 /// PersistentId counter to be used when inserting the next
294 /// SDNode to this SelectionDAG. We do not place that under
295 /// `#if LLVM_ENABLE_ABI_BREAKING_CHECKS` intentionally because
296 /// it adds unneeded complexity without noticeable
297 /// benefits (see discussion with @thakis in D120714).
298 uint16_t NextPersistentId = 0;
299
300public:
301 /// Clients of various APIs that cause global effects on
302 /// the DAG can optionally implement this interface. This allows the clients
303 /// to handle the various sorts of updates that happen.
304 ///
305 /// A DAGUpdateListener automatically registers itself with DAG when it is
306 /// constructed, and removes itself when destroyed in RAII fashion.
310
312 : Next(D.UpdateListeners), DAG(D) {
313 DAG.UpdateListeners = this;
314 }
315
317 assert(DAG.UpdateListeners == this &&
318 "DAGUpdateListeners must be destroyed in LIFO order");
319 DAG.UpdateListeners = Next;
320 }
321
322 /// The node N that was deleted and, if E is not null, an
323 /// equivalent node E that replaced it.
324 virtual void NodeDeleted(SDNode *N, SDNode *E);
325
326 /// The node N that was updated.
327 virtual void NodeUpdated(SDNode *N);
328
329 /// The node N that was inserted.
330 virtual void NodeInserted(SDNode *N);
331 };
332
334 std::function<void(SDNode *, SDNode *)> Callback;
335
337 std::function<void(SDNode *, SDNode *)> Callback)
339
340 void NodeDeleted(SDNode *N, SDNode *E) override { Callback(N, E); }
341
342 private:
343 virtual void anchor();
344 };
345
347 std::function<void(SDNode *)> Callback;
348
350 std::function<void(SDNode *)> Callback)
352
353 void NodeInserted(SDNode *N) override { Callback(N); }
354
355 private:
356 virtual void anchor();
357 };
358
359 /// Help to insert SDNodeFlags automatically in transforming. Use
360 /// RAII to save and resume flags in current scope.
362 SelectionDAG &DAG;
363 SDNodeFlags Flags;
364 FlagInserter *LastInserter;
365
366 public:
368 : DAG(SDAG), Flags(Flags),
369 LastInserter(SDAG.getFlagInserter()) {
370 SDAG.setFlagInserter(this);
371 }
373 : FlagInserter(SDAG, N->getFlags()) {}
374
375 FlagInserter(const FlagInserter &) = delete;
377 ~FlagInserter() { DAG.setFlagInserter(LastInserter); }
378
379 SDNodeFlags getFlags() const { return Flags; }
380 };
381
382 /// When true, additional steps are taken to
383 /// ensure that getConstant() and similar functions return DAG nodes that
384 /// have legal types. This is important after type legalization since
385 /// any illegally typed nodes generated after this point will not experience
386 /// type legalization.
388
389private:
390 /// DAGUpdateListener is a friend so it can manipulate the listener stack.
391 friend struct DAGUpdateListener;
392
393 /// Linked list of registered DAGUpdateListener instances.
394 /// This stack is maintained by DAGUpdateListener RAII.
395 DAGUpdateListener *UpdateListeners = nullptr;
396
397 /// Implementation of setSubgraphColor.
398 /// Return whether we had to truncate the search.
399 bool setSubgraphColorHelper(SDNode *N, const char *Color,
400 DenseSet<SDNode *> &visited,
401 int level, bool &printed);
402
403 template <typename SDNodeT, typename... ArgTypes>
404 SDNodeT *newSDNode(ArgTypes &&... Args) {
405 return new (NodeAllocator.template Allocate<SDNodeT>())
406 SDNodeT(std::forward<ArgTypes>(Args)...);
407 }
408
409 /// Build a synthetic SDNodeT with the given args and extract its subclass
410 /// data as an integer (e.g. for use in a folding set).
411 ///
412 /// The args to this function are the same as the args to SDNodeT's
413 /// constructor, except the second arg (assumed to be a const DebugLoc&) is
414 /// omitted.
415 template <typename SDNodeT, typename... ArgTypes>
416 static uint16_t getSyntheticNodeSubclassData(unsigned IROrder,
417 ArgTypes &&... Args) {
418 // The compiler can reduce this expression to a constant iff we pass an
419 // empty DebugLoc. Thankfully, the debug location doesn't have any bearing
420 // on the subclass data.
421 return SDNodeT(IROrder, DebugLoc(), std::forward<ArgTypes>(Args)...)
422 .getRawSubclassData();
423 }
424
425 template <typename SDNodeTy>
426 static uint16_t getSyntheticNodeSubclassData(unsigned Opc, unsigned Order,
427 SDVTList VTs, EVT MemoryVT,
428 MachineMemOperand *MMO) {
429 return SDNodeTy(Opc, Order, DebugLoc(), VTs, MemoryVT, MMO)
430 .getRawSubclassData();
431 }
432
433 void createOperands(SDNode *Node, ArrayRef<SDValue> Vals);
434
435 void removeOperands(SDNode *Node) {
436 if (!Node->OperandList)
437 return;
438 OperandRecycler.deallocate(
440 Node->OperandList);
441 Node->NumOperands = 0;
442 Node->OperandList = nullptr;
443 }
444 void CreateTopologicalOrder(std::vector<SDNode*>& Order);
445
446public:
447 // Maximum depth for recursive analysis such as computeKnownBits, etc.
448 static constexpr unsigned MaxRecursionDepth = 6;
449
451 SelectionDAG(const SelectionDAG &) = delete;
454
455 /// Prepare this SelectionDAG to process code in the given MachineFunction.
457 Pass *PassPtr, const TargetLibraryInfo *LibraryInfo,
459 BlockFrequencyInfo *BFIin, FunctionVarLocs const *FnVarLocs);
460
462 FLI = FuncInfo;
463 }
464
465 /// Clear state and free memory necessary to make this
466 /// SelectionDAG ready to process a new block.
467 void clear();
468
469 MachineFunction &getMachineFunction() const { return *MF; }
470 const Pass *getPass() const { return SDAGISelPass; }
471
472 const DataLayout &getDataLayout() const { return MF->getDataLayout(); }
473 const TargetMachine &getTarget() const { return TM; }
474 const TargetSubtargetInfo &getSubtarget() const { return MF->getSubtarget(); }
475 template <typename STC> const STC &getSubtarget() const {
476 return MF->getSubtarget<STC>();
477 }
478 const TargetLowering &getTargetLoweringInfo() const { return *TLI; }
479 const TargetLibraryInfo &getLibInfo() const { return *LibInfo; }
480 const SelectionDAGTargetInfo &getSelectionDAGInfo() const { return *TSI; }
481 const UniformityInfo *getUniformityInfo() const { return UA; }
482 /// Returns the result of the AssignmentTrackingAnalysis pass if it's
483 /// available, otherwise return nullptr.
484 const FunctionVarLocs *getFunctionVarLocs() const { return FnVarLocs; }
485 LLVMContext *getContext() const { return Context; }
486 OptimizationRemarkEmitter &getORE() const { return *ORE; }
487 ProfileSummaryInfo *getPSI() const { return PSI; }
488 BlockFrequencyInfo *getBFI() const { return BFI; }
489
490 FlagInserter *getFlagInserter() { return Inserter; }
491 void setFlagInserter(FlagInserter *FI) { Inserter = FI; }
492
493 /// Just dump dot graph to a user-provided path and title.
494 /// This doesn't open the dot viewer program and
495 /// helps visualization when outside debugging session.
496 /// FileName expects absolute path. If provided
497 /// without any path separators then the file
498 /// will be created in the current directory.
499 /// Error will be emitted if the path is insane.
500#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
501 LLVM_DUMP_METHOD void dumpDotGraph(const Twine &FileName, const Twine &Title);
502#endif
503
504 /// Pop up a GraphViz/gv window with the DAG rendered using 'dot'.
505 void viewGraph(const std::string &Title);
506 void viewGraph();
507
508#if LLVM_ENABLE_ABI_BREAKING_CHECKS
509 std::map<const SDNode *, std::string> NodeGraphAttrs;
510#endif
511
512 /// Clear all previously defined node graph attributes.
513 /// Intended to be used from a debugging tool (eg. gdb).
514 void clearGraphAttrs();
515
516 /// Set graph attributes for a node. (eg. "color=red".)
517 void setGraphAttrs(const SDNode *N, const char *Attrs);
518
519 /// Get graph attributes for a node. (eg. "color=red".)
520 /// Used from getNodeAttributes.
521 std::string getGraphAttrs(const SDNode *N) const;
522
523 /// Convenience for setting node color attribute.
524 void setGraphColor(const SDNode *N, const char *Color);
525
526 /// Convenience for setting subgraph color attribute.
527 void setSubgraphColor(SDNode *N, const char *Color);
528
530
531 allnodes_const_iterator allnodes_begin() const { return AllNodes.begin(); }
532 allnodes_const_iterator allnodes_end() const { return AllNodes.end(); }
533
535
536 allnodes_iterator allnodes_begin() { return AllNodes.begin(); }
537 allnodes_iterator allnodes_end() { return AllNodes.end(); }
538
540 return AllNodes.size();
541 }
542
545 }
548 }
549
550 /// Return the root tag of the SelectionDAG.
551 const SDValue &getRoot() const { return Root; }
552
553 /// Return the token chain corresponding to the entry of the function.
555 return SDValue(const_cast<SDNode *>(&EntryNode), 0);
556 }
557
558 /// Set the current root tag of the SelectionDAG.
559 ///
561 assert((!N.getNode() || N.getValueType() == MVT::Other) &&
562 "DAG root value is not a chain!");
563 if (N.getNode())
564 checkForCycles(N.getNode(), this);
565 Root = N;
566 if (N.getNode())
567 checkForCycles(this);
568 return Root;
569 }
570
571#ifndef NDEBUG
572 void VerifyDAGDivergence();
573#endif
574
575 /// This iterates over the nodes in the SelectionDAG, folding
576 /// certain types of nodes together, or eliminating superfluous nodes. The
577 /// Level argument controls whether Combine is allowed to produce nodes and
578 /// types that are illegal on the target.
579 void Combine(CombineLevel Level, AAResults *AA,
580 CodeGenOpt::Level OptLevel);
581
582 /// This transforms the SelectionDAG into a SelectionDAG that
583 /// only uses types natively supported by the target.
584 /// Returns "true" if it made any changes.
585 ///
586 /// Note that this is an involved process that may invalidate pointers into
587 /// the graph.
588 bool LegalizeTypes();
589
590 /// This transforms the SelectionDAG into a SelectionDAG that is
591 /// compatible with the target instruction selector, as indicated by the
592 /// TargetLowering object.
593 ///
594 /// Note that this is an involved process that may invalidate pointers into
595 /// the graph.
596 void Legalize();
597
598 /// Transforms a SelectionDAG node and any operands to it into a node
599 /// that is compatible with the target instruction selector, as indicated by
600 /// the TargetLowering object.
601 ///
602 /// \returns true if \c N is a valid, legal node after calling this.
603 ///
604 /// This essentially runs a single recursive walk of the \c Legalize process
605 /// over the given node (and its operands). This can be used to incrementally
606 /// legalize the DAG. All of the nodes which are directly replaced,
607 /// potentially including N, are added to the output parameter \c
608 /// UpdatedNodes so that the delta to the DAG can be understood by the
609 /// caller.
610 ///
611 /// When this returns false, N has been legalized in a way that make the
612 /// pointer passed in no longer valid. It may have even been deleted from the
613 /// DAG, and so it shouldn't be used further. When this returns true, the
614 /// N passed in is a legal node, and can be immediately processed as such.
615 /// This may still have done some work on the DAG, and will still populate
616 /// UpdatedNodes with any new nodes replacing those originally in the DAG.
617 bool LegalizeOp(SDNode *N, SmallSetVector<SDNode *, 16> &UpdatedNodes);
618
619 /// This transforms the SelectionDAG into a SelectionDAG
620 /// that only uses vector math operations supported by the target. This is
621 /// necessary as a separate step from Legalize because unrolling a vector
622 /// operation can introduce illegal types, which requires running
623 /// LegalizeTypes again.
624 ///
625 /// This returns true if it made any changes; in that case, LegalizeTypes
626 /// is called again before Legalize.
627 ///
628 /// Note that this is an involved process that may invalidate pointers into
629 /// the graph.
630 bool LegalizeVectors();
631
632 /// This method deletes all unreachable nodes in the SelectionDAG.
633 void RemoveDeadNodes();
634
635 /// Remove the specified node from the system. This node must
636 /// have no referrers.
637 void DeleteNode(SDNode *N);
638
639 /// Return an SDVTList that represents the list of values specified.
641 SDVTList getVTList(EVT VT1, EVT VT2);
642 SDVTList getVTList(EVT VT1, EVT VT2, EVT VT3);
643 SDVTList getVTList(EVT VT1, EVT VT2, EVT VT3, EVT VT4);
645
646 //===--------------------------------------------------------------------===//
647 // Node creation methods.
648
649 /// Create a ConstantSDNode wrapping a constant value.
650 /// If VT is a vector type, the constant is splatted into a BUILD_VECTOR.
651 ///
652 /// If only legal types can be produced, this does the necessary
653 /// transformations (e.g., if the vector element type is illegal).
654 /// @{
655 SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT,
656 bool isTarget = false, bool isOpaque = false);
657 SDValue getConstant(const APInt &Val, const SDLoc &DL, EVT VT,
658 bool isTarget = false, bool isOpaque = false);
659
660 SDValue getAllOnesConstant(const SDLoc &DL, EVT VT, bool IsTarget = false,
661 bool IsOpaque = false) {
663 IsTarget, IsOpaque);
664 }
665
666 SDValue getConstant(const ConstantInt &Val, const SDLoc &DL, EVT VT,
667 bool isTarget = false, bool isOpaque = false);
669 bool isTarget = false);
671 bool LegalTypes = true);
673 bool isTarget = false);
674
676 bool isOpaque = false) {
677 return getConstant(Val, DL, VT, true, isOpaque);
678 }
679 SDValue getTargetConstant(const APInt &Val, const SDLoc &DL, EVT VT,
680 bool isOpaque = false) {
681 return getConstant(Val, DL, VT, true, isOpaque);
682 }
684 bool isOpaque = false) {
685 return getConstant(Val, DL, VT, true, isOpaque);
686 }
687
688 /// Create a true or false constant of type \p VT using the target's
689 /// BooleanContent for type \p OpVT.
690 SDValue getBoolConstant(bool V, const SDLoc &DL, EVT VT, EVT OpVT);
691 /// @}
692
693 /// Create a ConstantFPSDNode wrapping a constant value.
694 /// If VT is a vector type, the constant is splatted into a BUILD_VECTOR.
695 ///
696 /// If only legal types can be produced, this does the necessary
697 /// transformations (e.g., if the vector element type is illegal).
698 /// The forms that take a double should only be used for simple constants
699 /// that can be exactly represented in VT. No checks are made.
700 /// @{
701 SDValue getConstantFP(double Val, const SDLoc &DL, EVT VT,
702 bool isTarget = false);
703 SDValue getConstantFP(const APFloat &Val, const SDLoc &DL, EVT VT,
704 bool isTarget = false);
705 SDValue getConstantFP(const ConstantFP &V, const SDLoc &DL, EVT VT,
706 bool isTarget = false);
707 SDValue getTargetConstantFP(double Val, const SDLoc &DL, EVT VT) {
708 return getConstantFP(Val, DL, VT, true);
709 }
710 SDValue getTargetConstantFP(const APFloat &Val, const SDLoc &DL, EVT VT) {
711 return getConstantFP(Val, DL, VT, true);
712 }
714 return getConstantFP(Val, DL, VT, true);
715 }
716 /// @}
717
718 SDValue getGlobalAddress(const GlobalValue *GV, const SDLoc &DL, EVT VT,
719 int64_t offset = 0, bool isTargetGA = false,
720 unsigned TargetFlags = 0);
722 int64_t offset = 0, unsigned TargetFlags = 0) {
723 return getGlobalAddress(GV, DL, VT, offset, true, TargetFlags);
724 }
725 SDValue getFrameIndex(int FI, EVT VT, bool isTarget = false);
727 return getFrameIndex(FI, VT, true);
728 }
729 SDValue getJumpTable(int JTI, EVT VT, bool isTarget = false,
730 unsigned TargetFlags = 0);
731 SDValue getTargetJumpTable(int JTI, EVT VT, unsigned TargetFlags = 0) {
732 return getJumpTable(JTI, VT, true, TargetFlags);
733 }
735 MaybeAlign Align = std::nullopt, int Offs = 0,
736 bool isT = false, unsigned TargetFlags = 0);
738 MaybeAlign Align = std::nullopt, int Offset = 0,
739 unsigned TargetFlags = 0) {
740 return getConstantPool(C, VT, Align, Offset, true, TargetFlags);
741 }
743 MaybeAlign Align = std::nullopt, int Offs = 0,
744 bool isT = false, unsigned TargetFlags = 0);
746 MaybeAlign Align = std::nullopt, int Offset = 0,
747 unsigned TargetFlags = 0) {
748 return getConstantPool(C, VT, Align, Offset, true, TargetFlags);
749 }
750 SDValue getTargetIndex(int Index, EVT VT, int64_t Offset = 0,
751 unsigned TargetFlags = 0);
752 // When generating a branch to a BB, we don't in general know enough
753 // to provide debug info for the BB at that time, so keep this one around.
755 SDValue getExternalSymbol(const char *Sym, EVT VT);
756 SDValue getTargetExternalSymbol(const char *Sym, EVT VT,
757 unsigned TargetFlags = 0);
759
761 SDValue getRegister(unsigned Reg, EVT VT);
762 SDValue getRegisterMask(const uint32_t *RegMask);
763 SDValue getEHLabel(const SDLoc &dl, SDValue Root, MCSymbol *Label);
764 SDValue getLabelNode(unsigned Opcode, const SDLoc &dl, SDValue Root,
765 MCSymbol *Label);
766 SDValue getBlockAddress(const BlockAddress *BA, EVT VT, int64_t Offset = 0,
767 bool isTarget = false, unsigned TargetFlags = 0);
769 int64_t Offset = 0, unsigned TargetFlags = 0) {
770 return getBlockAddress(BA, VT, Offset, true, TargetFlags);
771 }
772
774 SDValue N) {
775 return getNode(ISD::CopyToReg, dl, MVT::Other, Chain,
776 getRegister(Reg, N.getValueType()), N);
777 }
778
779 // This version of the getCopyToReg method takes an extra operand, which
780 // indicates that there is potentially an incoming glue value (if Glue is not
781 // null) and that there should be a glue result.
783 SDValue Glue) {
784 SDVTList VTs = getVTList(MVT::Other, MVT::Glue);
785 SDValue Ops[] = { Chain, getRegister(Reg, N.getValueType()), N, Glue };
786 return getNode(ISD::CopyToReg, dl, VTs,
787 ArrayRef(Ops, Glue.getNode() ? 4 : 3));
788 }
789
790 // Similar to last getCopyToReg() except parameter Reg is a SDValue
792 SDValue Glue) {
793 SDVTList VTs = getVTList(MVT::Other, MVT::Glue);
794 SDValue Ops[] = { Chain, Reg, N, Glue };
795 return getNode(ISD::CopyToReg, dl, VTs,
796 ArrayRef(Ops, Glue.getNode() ? 4 : 3));
797 }
798
800 SDVTList VTs = getVTList(VT, MVT::Other);
801 SDValue Ops[] = { Chain, getRegister(Reg, VT) };
802 return getNode(ISD::CopyFromReg, dl, VTs, Ops);
803 }
804
805 // This version of the getCopyFromReg method takes an extra operand, which
806 // indicates that there is potentially an incoming glue value (if Glue is not
807 // null) and that there should be a glue result.
809 SDValue Glue) {
810 SDVTList VTs = getVTList(VT, MVT::Other, MVT::Glue);
811 SDValue Ops[] = { Chain, getRegister(Reg, VT), Glue };
812 return getNode(ISD::CopyFromReg, dl, VTs,
813 ArrayRef(Ops, Glue.getNode() ? 3 : 2));
814 }
815
817
818 /// Return an ISD::VECTOR_SHUFFLE node. The number of elements in VT,
819 /// which must be a vector type, must match the number of mask elements
820 /// NumElts. An integer mask element equal to -1 is treated as undefined.
822 ArrayRef<int> Mask);
823
824 /// Return an ISD::BUILD_VECTOR node. The number of elements in VT,
825 /// which must be a vector type, must match the number of operands in Ops.
826 /// The operands must have the same type as (or, for integers, a type wider
827 /// than) VT's element type.
829 // VerifySDNode (via InsertNode) checks BUILD_VECTOR later.
830 return getNode(ISD::BUILD_VECTOR, DL, VT, Ops);
831 }
832
833 /// Return an ISD::BUILD_VECTOR node. The number of elements in VT,
834 /// which must be a vector type, must match the number of operands in Ops.
835 /// The operands must have the same type as (or, for integers, a type wider
836 /// than) VT's element type.
838 // VerifySDNode (via InsertNode) checks BUILD_VECTOR later.
839 return getNode(ISD::BUILD_VECTOR, DL, VT, Ops);
840 }
841
842 /// Return a splat ISD::BUILD_VECTOR node, consisting of Op splatted to all
843 /// elements. VT must be a vector type. Op's type must be the same as (or,
844 /// for integers, a type wider than) VT's element type.
846 // VerifySDNode (via InsertNode) checks BUILD_VECTOR later.
847 if (Op.getOpcode() == ISD::UNDEF) {
848 assert((VT.getVectorElementType() == Op.getValueType() ||
849 (VT.isInteger() &&
850 VT.getVectorElementType().bitsLE(Op.getValueType()))) &&
851 "A splatted value must have a width equal or (for integers) "
852 "greater than the vector element type!");
853 return getNode(ISD::UNDEF, SDLoc(), VT);
854 }
855
857 return getNode(ISD::BUILD_VECTOR, DL, VT, Ops);
858 }
859
860 // Return a splat ISD::SPLAT_VECTOR node, consisting of Op splatted to all
861 // elements.
863 if (Op.getOpcode() == ISD::UNDEF) {
864 assert((VT.getVectorElementType() == Op.getValueType() ||
865 (VT.isInteger() &&
866 VT.getVectorElementType().bitsLE(Op.getValueType()))) &&
867 "A splatted value must have a width equal or (for integers) "
868 "greater than the vector element type!");
869 return getNode(ISD::UNDEF, SDLoc(), VT);
870 }
871 return getNode(ISD::SPLAT_VECTOR, DL, VT, Op);
872 }
873
874 /// Returns a node representing a splat of one value into all lanes
875 /// of the provided vector type. This is a utility which returns
876 /// either a BUILD_VECTOR or SPLAT_VECTOR depending on the
877 /// scalability of the desired vector type.
878 SDValue getSplat(EVT VT, const SDLoc &DL, SDValue Op) {
879 assert(VT.isVector() && "Can't splat to non-vector type");
880 return VT.isScalableVector() ?
881 getSplatVector(VT, DL, Op) : getSplatBuildVector(VT, DL, Op);
882 }
883
884 /// Returns a vector of type ResVT whose elements contain the linear sequence
885 /// <0, Step, Step * 2, Step * 3, ...>
886 SDValue getStepVector(const SDLoc &DL, EVT ResVT, APInt StepVal);
887
888 /// Returns a vector of type ResVT whose elements contain the linear sequence
889 /// <0, 1, 2, 3, ...>
890 SDValue getStepVector(const SDLoc &DL, EVT ResVT);
891
892 /// Returns an ISD::VECTOR_SHUFFLE node semantically equivalent to
893 /// the shuffle node in input but with swapped operands.
894 ///
895 /// Example: shuffle A, B, <0,5,2,7> -> shuffle B, A, <4,1,6,3>
897
898 /// Convert Op, which must be of float type, to the
899 /// float type VT, by either extending or rounding (by truncation).
901
902 /// Convert Op, which must be a STRICT operation of float type, to the
903 /// float type VT, by either extending or rounding (by truncation).
904 std::pair<SDValue, SDValue>
906
907 /// Convert *_EXTEND_VECTOR_INREG to *_EXTEND opcode.
908 static unsigned getOpcode_EXTEND(unsigned Opcode) {
909 switch (Opcode) {
910 case ISD::ANY_EXTEND:
912 return ISD::ANY_EXTEND;
913 case ISD::ZERO_EXTEND:
915 return ISD::ZERO_EXTEND;
916 case ISD::SIGN_EXTEND:
918 return ISD::SIGN_EXTEND;
919 }
920 llvm_unreachable("Unknown opcode");
921 }
922
923 /// Convert *_EXTEND to *_EXTEND_VECTOR_INREG opcode.
924 static unsigned getOpcode_EXTEND_VECTOR_INREG(unsigned Opcode) {
925 switch (Opcode) {
926 case ISD::ANY_EXTEND:
929 case ISD::ZERO_EXTEND:
932 case ISD::SIGN_EXTEND:
935 }
936 llvm_unreachable("Unknown opcode");
937 }
938
939 /// Convert Op, which must be of integer type, to the
940 /// integer type VT, by either any-extending or truncating it.
941 SDValue getAnyExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT);
942
943 /// Convert Op, which must be of integer type, to the
944 /// integer type VT, by either sign-extending or truncating it.
945 SDValue getSExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT);
946
947 /// Convert Op, which must be of integer type, to the
948 /// integer type VT, by either zero-extending or truncating it.
949 SDValue getZExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT);
950
951 /// Return the expression required to zero extend the Op
952 /// value assuming it was the smaller SrcTy value.
954
955 /// Convert Op, which must be of integer type, to the integer type VT, by
956 /// either truncating it or performing either zero or sign extension as
957 /// appropriate extension for the pointer's semantics.
958 SDValue getPtrExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT);
959
960 /// Return the expression required to extend the Op as a pointer value
961 /// assuming it was the smaller SrcTy value. This may be either a zero extend
962 /// or a sign extend.
964
965 /// Convert Op, which must be of integer type, to the integer type VT,
966 /// by using an extension appropriate for the target's
967 /// BooleanContent for type OpVT or truncating it.
968 SDValue getBoolExtOrTrunc(SDValue Op, const SDLoc &SL, EVT VT, EVT OpVT);
969
970 /// Create negative operation as (SUB 0, Val).
971 SDValue getNegative(SDValue Val, const SDLoc &DL, EVT VT);
972
973 /// Create a bitwise NOT operation as (XOR Val, -1).
974 SDValue getNOT(const SDLoc &DL, SDValue Val, EVT VT);
975
976 /// Create a logical NOT operation as (XOR Val, BooleanOne).
977 SDValue getLogicalNOT(const SDLoc &DL, SDValue Val, EVT VT);
978
979 /// Create a vector-predicated logical NOT operation as (VP_XOR Val,
980 /// BooleanOne, Mask, EVL).
981 SDValue getVPLogicalNOT(const SDLoc &DL, SDValue Val, SDValue Mask,
982 SDValue EVL, EVT VT);
983
984 /// Convert a vector-predicated Op, which must be an integer vector, to the
985 /// vector-type VT, by performing either vector-predicated zext or truncating
986 /// it. The Op will be returned as-is if Op and VT are vectors containing
987 /// integer with same width.
988 SDValue getVPZExtOrTrunc(const SDLoc &DL, EVT VT, SDValue Op, SDValue Mask,
989 SDValue EVL);
990
991 /// Convert a vector-predicated Op, which must be of integer type, to the
992 /// vector-type integer type VT, by either truncating it or performing either
993 /// vector-predicated zero or sign extension as appropriate extension for the
994 /// pointer's semantics. This function just redirects to getVPZExtOrTrunc
995 /// right now.
996 SDValue getVPPtrExtOrTrunc(const SDLoc &DL, EVT VT, SDValue Op, SDValue Mask,
997 SDValue EVL);
998
999 /// Returns sum of the base pointer and offset.
1000 /// Unlike getObjectPtrOffset this does not set NoUnsignedWrap by default.
1002 const SDNodeFlags Flags = SDNodeFlags());
1004 const SDNodeFlags Flags = SDNodeFlags());
1005
1006 /// Create an add instruction with appropriate flags when used for
1007 /// addressing some offset of an object. i.e. if a load is split into multiple
1008 /// components, create an add nuw from the base pointer to the offset.
1011 Flags.setNoUnsignedWrap(true);
1012 return getMemBasePlusOffset(Ptr, Offset, SL, Flags);
1013 }
1014
1016 // The object itself can't wrap around the address space, so it shouldn't be
1017 // possible for the adds of the offsets to the split parts to overflow.
1019 Flags.setNoUnsignedWrap(true);
1020 return getMemBasePlusOffset(Ptr, Offset, SL, Flags);
1021 }
1022
1023 /// Return a new CALLSEQ_START node, that starts new call frame, in which
1024 /// InSize bytes are set up inside CALLSEQ_START..CALLSEQ_END sequence and
1025 /// OutSize specifies part of the frame set up prior to the sequence.
1027 const SDLoc &DL) {
1028 SDVTList VTs = getVTList(MVT::Other, MVT::Glue);
1029 SDValue Ops[] = { Chain,
1030 getIntPtrConstant(InSize, DL, true),
1031 getIntPtrConstant(OutSize, DL, true) };
1032 return getNode(ISD::CALLSEQ_START, DL, VTs, Ops);
1033 }
1034
1035 /// Return a new CALLSEQ_END node, which always must have a
1036 /// glue result (to ensure it's not CSE'd).
1037 /// CALLSEQ_END does not have a useful SDLoc.
1039 SDValue InGlue, const SDLoc &DL) {
1040 SDVTList NodeTys = getVTList(MVT::Other, MVT::Glue);
1042 Ops.push_back(Chain);
1043 Ops.push_back(Op1);
1044 Ops.push_back(Op2);
1045 if (InGlue.getNode())
1046 Ops.push_back(InGlue);
1047 return getNode(ISD::CALLSEQ_END, DL, NodeTys, Ops);
1048 }
1049
1051 SDValue Glue, const SDLoc &DL) {
1052 return getCALLSEQ_END(
1053 Chain, getIntPtrConstant(Size1, DL, /*isTarget=*/true),
1054 getIntPtrConstant(Size2, DL, /*isTarget=*/true), Glue, DL);
1055 }
1056
1057 /// Return true if the result of this operation is always undefined.
1058 bool isUndef(unsigned Opcode, ArrayRef<SDValue> Ops);
1059
1060 /// Return an UNDEF node. UNDEF does not have a useful SDLoc.
1062 return getNode(ISD::UNDEF, SDLoc(), VT);
1063 }
1064
1065 /// Return a node that represents the runtime scaling 'MulImm * RuntimeVL'.
1066 SDValue getVScale(const SDLoc &DL, EVT VT, APInt MulImm,
1067 bool ConstantFold = true);
1068
1070 bool ConstantFold = true);
1071
1072 /// Return a GLOBAL_OFFSET_TABLE node. This does not have a useful SDLoc.
1074 return getNode(ISD::GLOBAL_OFFSET_TABLE, SDLoc(), VT);
1075 }
1076
1077 /// Gets or creates the specified node.
1078 ///
1079 SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
1080 ArrayRef<SDUse> Ops);
1081 SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
1083 SDValue getNode(unsigned Opcode, const SDLoc &DL, ArrayRef<EVT> ResultTys,
1084 ArrayRef<SDValue> Ops);
1085 SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList,
1087
1088 // Use flags from current flag inserter.
1089 SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
1090 ArrayRef<SDValue> Ops);
1091 SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList,
1092 ArrayRef<SDValue> Ops);
1093 SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue Operand);
1094 SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1,
1095 SDValue N2);
1096 SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1,
1097 SDValue N2, SDValue N3);
1098
1099 // Specialize based on number of operands.
1100 SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT);
1101 SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue Operand,
1102 const SDNodeFlags Flags);
1103 SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1,
1104 SDValue N2, const SDNodeFlags Flags);
1105 SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1,
1106 SDValue N2, SDValue N3, const SDNodeFlags Flags);
1107 SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1,
1108 SDValue N2, SDValue N3, SDValue N4);
1109 SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1,
1110 SDValue N2, SDValue N3, SDValue N4, SDValue N5);
1111
1112 // Specialize again based on number of operands for nodes with a VTList
1113 // rather than a single VT.
1114 SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList);
1115 SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList, SDValue N);
1116 SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList, SDValue N1,
1117 SDValue N2);
1118 SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList, SDValue N1,
1119 SDValue N2, SDValue N3);
1120 SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList, SDValue N1,
1121 SDValue N2, SDValue N3, SDValue N4);
1122 SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList, SDValue N1,
1123 SDValue N2, SDValue N3, SDValue N4, SDValue N5);
1124
1125 /// Compute a TokenFactor to force all the incoming stack arguments to be
1126 /// loaded from the stack. This is used in tail call lowering to protect
1127 /// stack arguments from being clobbered.
1129
1131 SDValue Size, Align Alignment, bool isVol,
1132 bool AlwaysInline, bool isTailCall,
1133 MachinePointerInfo DstPtrInfo,
1134 MachinePointerInfo SrcPtrInfo,
1135 const AAMDNodes &AAInfo = AAMDNodes(),
1136 AAResults *AA = nullptr);
1137
1139 SDValue Size, Align Alignment, bool isVol, bool isTailCall,
1140 MachinePointerInfo DstPtrInfo,
1141 MachinePointerInfo SrcPtrInfo,
1142 const AAMDNodes &AAInfo = AAMDNodes(),
1143 AAResults *AA = nullptr);
1144
1146 SDValue Size, Align Alignment, bool isVol,
1147 bool AlwaysInline, bool isTailCall,
1148 MachinePointerInfo DstPtrInfo,
1149 const AAMDNodes &AAInfo = AAMDNodes());
1150
1152 SDValue Src, SDValue Size, Type *SizeTy,
1153 unsigned ElemSz, bool isTailCall,
1154 MachinePointerInfo DstPtrInfo,
1155 MachinePointerInfo SrcPtrInfo);
1156
1158 SDValue Src, SDValue Size, Type *SizeTy,
1159 unsigned ElemSz, bool isTailCall,
1160 MachinePointerInfo DstPtrInfo,
1161 MachinePointerInfo SrcPtrInfo);
1162
1164 SDValue Value, SDValue Size, Type *SizeTy,
1165 unsigned ElemSz, bool isTailCall,
1166 MachinePointerInfo DstPtrInfo);
1167
1168 /// Helper function to make it easier to build SetCC's if you just have an
1169 /// ISD::CondCode instead of an SDValue.
1172 bool IsSignaling = false) {
1173 assert(LHS.getValueType().isVector() == RHS.getValueType().isVector() &&
1174 "Vector/scalar operand type mismatch for setcc");
1175 assert(LHS.getValueType().isVector() == VT.isVector() &&
1176 "Vector/scalar result type mismatch for setcc");
1178 "Cannot create a setCC of an invalid node.");
1179 if (Chain)
1180 return getNode(IsSignaling ? ISD::STRICT_FSETCCS : ISD::STRICT_FSETCC, DL,
1181 {VT, MVT::Other}, {Chain, LHS, RHS, getCondCode(Cond)});
1182 return getNode(ISD::SETCC, DL, VT, LHS, RHS, getCondCode(Cond));
1183 }
1184
1185 /// Helper function to make it easier to build VP_SETCCs if you just have an
1186 /// ISD::CondCode instead of an SDValue.
1188 ISD::CondCode Cond, SDValue Mask, SDValue EVL) {
1189 assert(LHS.getValueType().isVector() && RHS.getValueType().isVector() &&
1190 "Cannot compare scalars");
1192 "Cannot create a setCC of an invalid node.");
1193 return getNode(ISD::VP_SETCC, DL, VT, LHS, RHS, getCondCode(Cond), Mask,
1194 EVL);
1195 }
1196
1197 /// Helper function to make it easier to build Select's if you just have
1198 /// operands and don't want to check for vector.
1200 SDValue RHS) {
1201 assert(LHS.getValueType() == VT && RHS.getValueType() == VT &&
1202 "Cannot use select on differing types");
1203 auto Opcode = Cond.getValueType().isVector() ? ISD::VSELECT : ISD::SELECT;
1204 return getNode(Opcode, DL, VT, Cond, LHS, RHS);
1205 }
1206
1207 /// Helper function to make it easier to build SelectCC's if you just have an
1208 /// ISD::CondCode instead of an SDValue.
1210 SDValue False, ISD::CondCode Cond) {
1211 return getNode(ISD::SELECT_CC, DL, True.getValueType(), LHS, RHS, True,
1212 False, getCondCode(Cond));
1213 }
1214
1215 /// Try to simplify a select/vselect into 1 of its operands or a constant.
1217
1218 /// Try to simplify a shift into 1 of its operands or a constant.
1220
1221 /// Try to simplify a floating-point binary operation into 1 of its operands
1222 /// or a constant.
1223 SDValue simplifyFPBinop(unsigned Opcode, SDValue X, SDValue Y,
1225
1226 /// VAArg produces a result and token chain, and takes a pointer
1227 /// and a source value as input.
1229 SDValue SV, unsigned Align);
1230
1231 /// Gets a node for an atomic cmpxchg op. There are two
1232 /// valid Opcodes. ISD::ATOMIC_CMO_SWAP produces the value loaded and a
1233 /// chain result. ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS produces the value loaded,
1234 /// a success flag (initially i1), and a chain.
1235 SDValue getAtomicCmpSwap(unsigned Opcode, const SDLoc &dl, EVT MemVT,
1237 SDValue Cmp, SDValue Swp, MachineMemOperand *MMO);
1238
1239 /// Gets a node for an atomic op, produces result (if relevant)
1240 /// and chain and takes 2 operands.
1241 SDValue getAtomic(unsigned Opcode, const SDLoc &dl, EVT MemVT, SDValue Chain,
1243
1244 /// Gets a node for an atomic op, produces result and chain and
1245 /// takes 1 operand.
1246 SDValue getAtomic(unsigned Opcode, const SDLoc &dl, EVT MemVT, EVT VT,
1248
1249 /// Gets a node for an atomic op, produces result and chain and takes N
1250 /// operands.
1251 SDValue getAtomic(unsigned Opcode, const SDLoc &dl, EVT MemVT,
1252 SDVTList VTList, ArrayRef<SDValue> Ops,
1253 MachineMemOperand *MMO);
1254
1255 /// Creates a MemIntrinsicNode that may produce a
1256 /// result and takes a list of operands. Opcode may be INTRINSIC_VOID,
1257 /// INTRINSIC_W_CHAIN, or a target-specific opcode with a value not
1258 /// less than FIRST_TARGET_MEMORY_OPCODE.
1260 unsigned Opcode, const SDLoc &dl, SDVTList VTList, ArrayRef<SDValue> Ops,
1264 uint64_t Size = 0, const AAMDNodes &AAInfo = AAMDNodes());
1265
1267 unsigned Opcode, const SDLoc &dl, SDVTList VTList, ArrayRef<SDValue> Ops,
1269 MaybeAlign Alignment = std::nullopt,
1272 uint64_t Size = 0, const AAMDNodes &AAInfo = AAMDNodes()) {
1273 // Ensure that codegen never sees alignment 0
1274 return getMemIntrinsicNode(Opcode, dl, VTList, Ops, MemVT, PtrInfo,
1275 Alignment.value_or(getEVTAlign(MemVT)), Flags,
1276 Size, AAInfo);
1277 }
1278
1279 SDValue getMemIntrinsicNode(unsigned Opcode, const SDLoc &dl, SDVTList VTList,
1280 ArrayRef<SDValue> Ops, EVT MemVT,
1281 MachineMemOperand *MMO);
1282
1283 /// Creates a LifetimeSDNode that starts (`IsStart==true`) or ends
1284 /// (`IsStart==false`) the lifetime of the portion of `FrameIndex` between
1285 /// offsets `Offset` and `Offset + Size`.
1286 SDValue getLifetimeNode(bool IsStart, const SDLoc &dl, SDValue Chain,
1287 int FrameIndex, int64_t Size, int64_t Offset = -1);
1288
1289 /// Creates a PseudoProbeSDNode with function GUID `Guid` and
1290 /// the index of the block `Index` it is probing, as well as the attributes
1291 /// `attr` of the probe.
1293 uint64_t Index, uint32_t Attr);
1294
1295 /// Create a MERGE_VALUES node from the given operands.
1297
1298 /// Loads are not normal binary operators: their result type is not
1299 /// determined by their operands, and they produce a value AND a token chain.
1300 ///
1301 /// This function will set the MOLoad flag on MMOFlags, but you can set it if
1302 /// you want. The MOStore flag must not be set.
1307 const AAMDNodes &AAInfo = AAMDNodes(),
1308 const MDNode *Ranges = nullptr);
1309 /// FIXME: Remove once transition to Align is over.
1310 LLVM_DEPRECATED("Use the getLoad function that takes a MaybeAlign instead",
1311 "")
1317 const MDNode *Ranges = nullptr) {
1319 AAInfo, Ranges);
1320 }
1322 MachineMemOperand *MMO);
1323 SDValue
1324 getExtLoad(ISD::LoadExtType ExtType, const SDLoc &dl, EVT VT, SDValue Chain,
1328 const AAMDNodes &AAInfo = AAMDNodes());
1329 SDValue getExtLoad(ISD::LoadExtType ExtType, const SDLoc &dl, EVT VT,
1330 SDValue Chain, SDValue Ptr, EVT MemVT,
1331 MachineMemOperand *MMO);
1332 SDValue getIndexedLoad(SDValue OrigLoad, const SDLoc &dl, SDValue Base,
1338 const AAMDNodes &AAInfo = AAMDNodes(),
1339 const MDNode *Ranges = nullptr);
1341 ISD::MemIndexedMode AM, ISD::LoadExtType ExtType, EVT VT, const SDLoc &dl,
1345 const AAMDNodes &AAInfo = AAMDNodes(), const MDNode *Ranges = nullptr) {
1346 // Ensures that codegen never sees a None Alignment.
1347 return getLoad(AM, ExtType, VT, dl, Chain, Ptr, Offset, PtrInfo, MemVT,
1348 Alignment.value_or(getEVTAlign(MemVT)), MMOFlags, AAInfo,
1349 Ranges);
1350 }
1351 /// FIXME: Remove once transition to Align is over.
1352 LLVM_DEPRECATED("Use the getLoad function that takes a MaybeAlign instead",
1353 "")
1355 getLoad(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType, EVT VT,
1357 MachinePointerInfo PtrInfo, EVT MemVT, unsigned Alignment,
1360 const MDNode *Ranges = nullptr) {
1361 return getLoad(AM, ExtType, VT, dl, Chain, Ptr, Offset, PtrInfo, MemVT,
1363 }
1366 EVT MemVT, MachineMemOperand *MMO);
1367
1368 /// Helper function to build ISD::STORE nodes.
1369 ///
1370 /// This function will set the MOStore flag on MMOFlags, but you can set it if
1371 /// you want. The MOLoad and MOInvariant flags must not be set.
1372
1373 SDValue
1377 const AAMDNodes &AAInfo = AAMDNodes());
1378 inline SDValue
1382 const AAMDNodes &AAInfo = AAMDNodes()) {
1383 return getStore(Chain, dl, Val, Ptr, PtrInfo,
1384 Alignment.value_or(getEVTAlign(Val.getValueType())),
1385 MMOFlags, AAInfo);
1386 }
1387 /// FIXME: Remove once transition to Align is over.
1388 LLVM_DEPRECATED("Use the version that takes a MaybeAlign instead", "")
1394 return getStore(Chain, dl, Val, Ptr, PtrInfo, MaybeAlign(Alignment),
1395 MMOFlags, AAInfo);
1396 }
1398 MachineMemOperand *MMO);
1399 SDValue
1403 const AAMDNodes &AAInfo = AAMDNodes());
1404 inline SDValue
1409 const AAMDNodes &AAInfo = AAMDNodes()) {
1410 return getTruncStore(Chain, dl, Val, Ptr, PtrInfo, SVT,
1411 Alignment.value_or(getEVTAlign(SVT)), MMOFlags,
1412 AAInfo);
1413 }
1414 /// FIXME: Remove once transition to Align is over.
1415 LLVM_DEPRECATED("Use the version that takes a MaybeAlign instead", "")
1418 MachinePointerInfo PtrInfo, EVT SVT, unsigned Alignment,
1421 return getTruncStore(Chain, dl, Val, Ptr, PtrInfo, SVT,
1423 }
1425 SDValue Ptr, EVT SVT, MachineMemOperand *MMO);
1426 SDValue getIndexedStore(SDValue OrigStore, const SDLoc &dl, SDValue Base,
1428
1432 EVT MemVT, Align Alignment,
1434 const MDNode *Ranges = nullptr, bool IsExpanding = false);
1435 inline SDValue
1438 SDValue Mask, SDValue EVL, MachinePointerInfo PtrInfo, EVT MemVT,
1441 const AAMDNodes &AAInfo = AAMDNodes(),
1442 const MDNode *Ranges = nullptr, bool IsExpanding = false) {
1443 // Ensures that codegen never sees a None Alignment.
1444 return getLoadVP(AM, ExtType, VT, dl, Chain, Ptr, Offset, Mask, EVL,
1445 PtrInfo, MemVT, Alignment.value_or(getEVTAlign(MemVT)),
1446 MMOFlags, AAInfo, Ranges, IsExpanding);
1447 }
1450 SDValue Mask, SDValue EVL, EVT MemVT,
1451 MachineMemOperand *MMO, bool IsExpanding = false);
1455 const AAMDNodes &AAInfo, const MDNode *Ranges = nullptr,
1456 bool IsExpanding = false);
1458 SDValue Mask, SDValue EVL, MachineMemOperand *MMO,
1459 bool IsExpanding = false);
1460 SDValue getExtLoadVP(ISD::LoadExtType ExtType, const SDLoc &dl, EVT VT,
1461 SDValue Chain, SDValue Ptr, SDValue Mask, SDValue EVL,
1464 const AAMDNodes &AAInfo, bool IsExpanding = false);
1465 SDValue getExtLoadVP(ISD::LoadExtType ExtType, const SDLoc &dl, EVT VT,
1466 SDValue Chain, SDValue Ptr, SDValue Mask, SDValue EVL,
1467 EVT MemVT, MachineMemOperand *MMO,
1468 bool IsExpanding = false);
1472 SDValue Offset, SDValue Mask, SDValue EVL, EVT MemVT,
1474 bool IsTruncating = false, bool IsCompressing = false);
1476 SDValue Ptr, SDValue Mask, SDValue EVL,
1479 const AAMDNodes &AAInfo, bool IsCompressing = false);
1481 SDValue Ptr, SDValue Mask, SDValue EVL, EVT SVT,
1482 MachineMemOperand *MMO, bool IsCompressing = false);
1485
1487 EVT VT, const SDLoc &DL, SDValue Chain, SDValue Ptr,
1488 SDValue Offset, SDValue Stride, SDValue Mask,
1491 const AAMDNodes &AAInfo,
1492 const MDNode *Ranges = nullptr,
1493 bool IsExpanding = false);
1495 ISD::MemIndexedMode AM, ISD::LoadExtType ExtType, EVT VT, const SDLoc &DL,
1500 const AAMDNodes &AAInfo = AAMDNodes(), const MDNode *Ranges = nullptr,
1501 bool IsExpanding = false) {
1502 // Ensures that codegen never sees a None Alignment.
1503 return getStridedLoadVP(AM, ExtType, VT, DL, Chain, Ptr, Offset, Stride,
1504 Mask, EVL, PtrInfo, MemVT,
1505 Alignment.value_or(getEVTAlign(MemVT)), MMOFlags,
1506 AAInfo, Ranges, IsExpanding);
1507 }
1509 EVT VT, const SDLoc &DL, SDValue Chain, SDValue Ptr,
1510 SDValue Offset, SDValue Stride, SDValue Mask,
1511 SDValue EVL, EVT MemVT, MachineMemOperand *MMO,
1512 bool IsExpanding = false);
1514 SDValue Stride, SDValue Mask, SDValue EVL,
1517 const AAMDNodes &AAInfo,
1518 const MDNode *Ranges = nullptr,
1519 bool IsExpanding = false);
1521 SDValue Stride, SDValue Mask, SDValue EVL,
1522 MachineMemOperand *MMO, bool IsExpanding = false);
1523 SDValue
1524 getExtStridedLoadVP(ISD::LoadExtType ExtType, const SDLoc &DL, EVT VT,
1525 SDValue Chain, SDValue Ptr, SDValue Stride, SDValue Mask,
1528 const AAMDNodes &AAInfo, bool IsExpanding = false);
1530 SDValue Chain, SDValue Ptr, SDValue Stride,
1531 SDValue Mask, SDValue EVL, EVT MemVT,
1532 MachineMemOperand *MMO, bool IsExpanding = false);
1537 SDValue Ptr, SDValue Offset, SDValue Stride,
1538 SDValue Mask, SDValue EVL, EVT MemVT,
1540 bool IsTruncating = false,
1541 bool IsCompressing = false);
1543 SDValue Ptr, SDValue Stride, SDValue Mask,
1545 EVT SVT, Align Alignment,
1547 const AAMDNodes &AAInfo,
1548 bool IsCompressing = false);
1550 SDValue Ptr, SDValue Stride, SDValue Mask,
1551 SDValue EVL, EVT SVT, MachineMemOperand *MMO,
1552 bool IsCompressing = false);
1556
1557 SDValue getGatherVP(SDVTList VTs, EVT VT, const SDLoc &dl,
1559 ISD::MemIndexType IndexType);
1560 SDValue getScatterVP(SDVTList VTs, EVT VT, const SDLoc &dl,
1562 ISD::MemIndexType IndexType);
1563
1565 SDValue Offset, SDValue Mask, SDValue Src0, EVT MemVT,
1567 ISD::LoadExtType, bool IsExpanding = false);
1571 SDValue Base, SDValue Offset, SDValue Mask, EVT MemVT,
1573 bool IsTruncating = false, bool IsCompressing = false);
1574 SDValue getIndexedMaskedStore(SDValue OrigStore, const SDLoc &dl,
1577 SDValue getMaskedGather(SDVTList VTs, EVT MemVT, const SDLoc &dl,
1579 ISD::MemIndexType IndexType, ISD::LoadExtType ExtTy);
1580 SDValue getMaskedScatter(SDVTList VTs, EVT MemVT, const SDLoc &dl,
1582 ISD::MemIndexType IndexType,
1583 bool IsTruncating = false);
1584
1585 /// Construct a node to track a Value* through the backend.
1586 SDValue getSrcValue(const Value *v);
1587
1588 /// Return an MDNodeSDNode which holds an MDNode.
1589 SDValue getMDNode(const MDNode *MD);
1590
1591 /// Return a bitcast using the SDLoc of the value operand, and casting to the
1592 /// provided type. Use getNode to set a custom SDLoc.
1594
1595 /// Return an AddrSpaceCastSDNode.
1596 SDValue getAddrSpaceCast(const SDLoc &dl, EVT VT, SDValue Ptr, unsigned SrcAS,
1597 unsigned DestAS);
1598
1599 /// Return a freeze using the SDLoc of the value operand.
1601
1602 /// Return an AssertAlignSDNode.
1604
1605 /// Swap N1 and N2 if Opcode is a commutative binary opcode
1606 /// and the canonical form expects the opposite order.
1607 void canonicalizeCommutativeBinop(unsigned Opcode, SDValue &N1,
1608 SDValue &N2) const;
1609
1610 /// Return the specified value casted to
1611 /// the target's desired shift amount type.
1613
1614 /// Expand the specified \c ISD::VAARG node as the Legalize pass would.
1616
1617 /// Expand the specified \c ISD::VACOPY node as the Legalize pass would.
1619
1620 /// Returs an GlobalAddress of the function from the current module with
1621 /// name matching the given ExternalSymbol. Additionally can provide the
1622 /// matched function.
1623 /// Panics the function doesn't exists.
1625 Function **TargetFunction = nullptr);
1626
1627 /// *Mutate* the specified node in-place to have the
1628 /// specified operands. If the resultant node already exists in the DAG,
1629 /// this does not modify the specified node, instead it returns the node that
1630 /// already exists. If the resultant node does not exist in the DAG, the
1631 /// input node is returned. As a degenerate case, if you specify the same
1632 /// input operands as the node already has, the input node is returned.
1636 SDValue Op3);
1638 SDValue Op3, SDValue Op4);
1640 SDValue Op3, SDValue Op4, SDValue Op5);
1642
1643 /// Creates a new TokenFactor containing \p Vals. If \p Vals contains 64k
1644 /// values or more, move values into new TokenFactors in 64k-1 blocks, until
1645 /// the final TokenFactor has less than 64k operands.
1647
1648 /// *Mutate* the specified machine node's memory references to the provided
1649 /// list.
1652
1653 // Calculate divergence of node \p N based on its operands.
1655
1656 // Propagates the change in divergence to users
1657 void updateDivergence(SDNode * N);
1658
1659 /// These are used for target selectors to *mutate* the
1660 /// specified node to have the specified return type, Target opcode, and
1661 /// operands. Note that target opcodes are stored as
1662 /// ~TargetOpcode in the node opcode field. The resultant node is returned.
1663 SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT);
1664 SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT, SDValue Op1);
1665 SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT,
1666 SDValue Op1, SDValue Op2);
1667 SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT,
1668 SDValue Op1, SDValue Op2, SDValue Op3);
1669 SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT,
1670 ArrayRef<SDValue> Ops);
1671 SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT1, EVT VT2);
1672 SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT1,
1673 EVT VT2, ArrayRef<SDValue> Ops);
1674 SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT1,
1675 EVT VT2, EVT VT3, ArrayRef<SDValue> Ops);
1676 SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT1,
1677 EVT VT2, SDValue Op1, SDValue Op2);
1678 SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, SDVTList VTs,
1679 ArrayRef<SDValue> Ops);
1680
1681 /// This *mutates* the specified node to have the specified
1682 /// return type, opcode, and operands.
1683 SDNode *MorphNodeTo(SDNode *N, unsigned Opc, SDVTList VTs,
1684 ArrayRef<SDValue> Ops);
1685
1686 /// Mutate the specified strict FP node to its non-strict equivalent,
1687 /// unlinking the node from its chain and dropping the metadata arguments.
1688 /// The node must be a strict FP node.
1690
1691 /// These are used for target selectors to create a new node
1692 /// with specified return type(s), MachineInstr opcode, and operands.
1693 ///
1694 /// Note that getMachineNode returns the resultant node. If there is already
1695 /// a node of the specified opcode and operands, it returns that node instead
1696 /// of the current one.
1697 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT);
1698 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT,
1699 SDValue Op1);
1700 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT,
1701 SDValue Op1, SDValue Op2);
1702 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT,
1703 SDValue Op1, SDValue Op2, SDValue Op3);
1704 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT,
1705 ArrayRef<SDValue> Ops);
1706 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT1,
1707 EVT VT2, SDValue Op1, SDValue Op2);
1708 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT1,
1709 EVT VT2, SDValue Op1, SDValue Op2, SDValue Op3);
1710 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT1,
1711 EVT VT2, ArrayRef<SDValue> Ops);
1712 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT1,
1713 EVT VT2, EVT VT3, SDValue Op1, SDValue Op2);
1714 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT1,
1715 EVT VT2, EVT VT3, SDValue Op1, SDValue Op2,
1716 SDValue Op3);
1717 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT1,
1718 EVT VT2, EVT VT3, ArrayRef<SDValue> Ops);
1719 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl,
1720 ArrayRef<EVT> ResultTys, ArrayRef<SDValue> Ops);
1721 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, SDVTList VTs,
1722 ArrayRef<SDValue> Ops);
1723
1724 /// A convenience function for creating TargetInstrInfo::EXTRACT_SUBREG nodes.
1725 SDValue getTargetExtractSubreg(int SRIdx, const SDLoc &DL, EVT VT,
1726 SDValue Operand);
1727
1728 /// A convenience function for creating TargetInstrInfo::INSERT_SUBREG nodes.
1729 SDValue getTargetInsertSubreg(int SRIdx, const SDLoc &DL, EVT VT,
1730 SDValue Operand, SDValue Subreg);
1731
1732 /// Get the specified node if it's already available, or else return NULL.
1733 SDNode *getNodeIfExists(unsigned Opcode, SDVTList VTList,
1735 SDNode *getNodeIfExists(unsigned Opcode, SDVTList VTList,
1736 ArrayRef<SDValue> Ops);
1737
1738 /// Check if a node exists without modifying its flags.
1739 bool doesNodeExist(unsigned Opcode, SDVTList VTList, ArrayRef<SDValue> Ops);
1740
1741 /// Creates a SDDbgValue node.
1743 unsigned R, bool IsIndirect, const DebugLoc &DL,
1744 unsigned O);
1745
1746 /// Creates a constant SDDbgValue node.
1748 const Value *C, const DebugLoc &DL,
1749 unsigned O);
1750
1751 /// Creates a FrameIndex SDDbgValue node.
1753 unsigned FI, bool IsIndirect,
1754 const DebugLoc &DL, unsigned O);
1755
1756 /// Creates a FrameIndex SDDbgValue node.
1758 unsigned FI,
1759 ArrayRef<SDNode *> Dependencies,
1760 bool IsIndirect, const DebugLoc &DL,
1761 unsigned O);
1762
1763 /// Creates a VReg SDDbgValue node.
1765 unsigned VReg, bool IsIndirect,
1766 const DebugLoc &DL, unsigned O);
1767
1768 /// Creates a SDDbgValue node from a list of locations.
1771 ArrayRef<SDNode *> Dependencies, bool IsIndirect,
1772 const DebugLoc &DL, unsigned O, bool IsVariadic);
1773
1774 /// Creates a SDDbgLabel node.
1775 SDDbgLabel *getDbgLabel(DILabel *Label, const DebugLoc &DL, unsigned O);
1776
1777 /// Transfer debug values from one node to another, while optionally
1778 /// generating fragment expressions for split-up values. If \p InvalidateDbg
1779 /// is set, debug values are invalidated after they are transferred.
1780 void transferDbgValues(SDValue From, SDValue To, unsigned OffsetInBits = 0,
1781 unsigned SizeInBits = 0, bool InvalidateDbg = true);
1782
1783 /// Remove the specified node from the system. If any of its
1784 /// operands then becomes dead, remove them as well. Inform UpdateListener
1785 /// for each node deleted.
1786 void RemoveDeadNode(SDNode *N);
1787
1788 /// This method deletes the unreachable nodes in the
1789 /// given list, and any nodes that become unreachable as a result.
1791
1792 /// Modify anything using 'From' to use 'To' instead.
1793 /// This can cause recursive merging of nodes in the DAG. Use the first
1794 /// version if 'From' is known to have a single result, use the second
1795 /// if you have two nodes with identical results (or if 'To' has a superset
1796 /// of the results of 'From'), use the third otherwise.
1797 ///
1798 /// These methods all take an optional UpdateListener, which (if not null) is
1799 /// informed about nodes that are deleted and modified due to recursive
1800 /// changes in the dag.
1801 ///
1802 /// These functions only replace all existing uses. It's possible that as
1803 /// these replacements are being performed, CSE may cause the From node
1804 /// to be given new uses. These new uses of From are left in place, and
1805 /// not automatically transferred to To.
1806 ///
1809 void ReplaceAllUsesWith(SDNode *From, const SDValue *To);
1810
1811 /// Replace any uses of From with To, leaving
1812 /// uses of other values produced by From.getNode() alone.
1814
1815 /// Like ReplaceAllUsesOfValueWith, but for multiple values at once.
1816 /// This correctly handles the case where
1817 /// there is an overlap between the From values and the To values.
1818 void ReplaceAllUsesOfValuesWith(const SDValue *From, const SDValue *To,
1819 unsigned Num);
1820
1821 /// If an existing load has uses of its chain, create a token factor node with
1822 /// that chain and the new memory node's chain and update users of the old
1823 /// chain to the token factor. This ensures that the new memory node will have
1824 /// the same relative memory dependency position as the old load. Returns the
1825 /// new merged load chain.
1826 SDValue makeEquivalentMemoryOrdering(SDValue OldChain, SDValue NewMemOpChain);
1827
1828 /// If an existing load has uses of its chain, create a token factor node with
1829 /// that chain and the new memory node's chain and update users of the old
1830 /// chain to the token factor. This ensures that the new memory node will have
1831 /// the same relative memory dependency position as the old load. Returns the
1832 /// new merged load chain.
1834
1835 /// Topological-sort the AllNodes list and a
1836 /// assign a unique node id for each node in the DAG based on their
1837 /// topological order. Returns the number of nodes.
1838 unsigned AssignTopologicalOrder();
1839
1840 /// Move node N in the AllNodes list to be immediately
1841 /// before the given iterator Position. This may be used to update the
1842 /// topological ordering when the list of nodes is modified.
1844 AllNodes.insert(Position, AllNodes.remove(N));
1845 }
1846
1847 /// Returns an APFloat semantics tag appropriate for the given type. If VT is
1848 /// a vector type, the element semantics are returned.
1850 switch (VT.getScalarType().getSimpleVT().SimpleTy) {
1851 default: llvm_unreachable("Unknown FP format");
1852 case MVT::f16: return APFloat::IEEEhalf();
1853 case MVT::bf16: return APFloat::BFloat();
1854 case MVT::f32: return APFloat::IEEEsingle();
1855 case MVT::f64: return APFloat::IEEEdouble();
1856 case MVT::f80: return APFloat::x87DoubleExtended();
1857 case MVT::f128: return APFloat::IEEEquad();
1858 case MVT::ppcf128: return APFloat::PPCDoubleDouble();
1859 }
1860 }
1861
1862 /// Add a dbg_value SDNode. If SD is non-null that means the
1863 /// value is produced by SD.
1864 void AddDbgValue(SDDbgValue *DB, bool isParameter);
1865
1866 /// Add a dbg_label SDNode.
1867 void AddDbgLabel(SDDbgLabel *DB);
1868
1869 /// Get the debug values which reference the given SDNode.
1871 return DbgInfo->getSDDbgValues(SD);
1872 }
1873
1874public:
1875 /// Return true if there are any SDDbgValue nodes associated
1876 /// with this SelectionDAG.
1877 bool hasDebugValues() const { return !DbgInfo->empty(); }
1878
1879 SDDbgInfo::DbgIterator DbgBegin() const { return DbgInfo->DbgBegin(); }
1880 SDDbgInfo::DbgIterator DbgEnd() const { return DbgInfo->DbgEnd(); }
1881
1883 return DbgInfo->ByvalParmDbgBegin();
1884 }
1886 return DbgInfo->ByvalParmDbgEnd();
1887 }
1888
1890 return DbgInfo->DbgLabelBegin();
1891 }
1893 return DbgInfo->DbgLabelEnd();
1894 }
1895
1896 /// To be invoked on an SDNode that is slated to be erased. This
1897 /// function mirrors \c llvm::salvageDebugInfo.
1898 void salvageDebugInfo(SDNode &N);
1899
1900 void dump() const;
1901
1902 /// In most cases this function returns the ABI alignment for a given type,
1903 /// except for illegal vector types where the alignment exceeds that of the
1904 /// stack. In such cases we attempt to break the vector down to a legal type
1905 /// and return the ABI alignment for that instead.
1906 Align getReducedAlign(EVT VT, bool UseABI);
1907
1908 /// Create a stack temporary based on the size in bytes and the alignment
1910
1911 /// Create a stack temporary, suitable for holding the specified value type.
1912 /// If minAlign is specified, the slot size will have at least that alignment.
1913 SDValue CreateStackTemporary(EVT VT, unsigned minAlign = 1);
1914
1915 /// Create a stack temporary suitable for holding either of the specified
1916 /// value types.
1918
1919 SDValue FoldSymbolOffset(unsigned Opcode, EVT VT,
1920 const GlobalAddressSDNode *GA,
1921 const SDNode *N2);
1922
1923 SDValue FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL, EVT VT,
1924 ArrayRef<SDValue> Ops);
1925
1926 /// Fold floating-point operations with 2 operands when both operands are
1927 /// constants and/or undefined.
1928 SDValue foldConstantFPMath(unsigned Opcode, const SDLoc &DL, EVT VT,
1929 SDValue N1, SDValue N2);
1930
1931 /// Constant fold a setcc to true or false.
1933 const SDLoc &dl);
1934
1935 /// Return true if the sign bit of Op is known to be zero.
1936 /// We use this predicate to simplify operations downstream.
1937 bool SignBitIsZero(SDValue Op, unsigned Depth = 0) const;
1938
1939 /// Return true if 'Op & Mask' is known to be zero. We
1940 /// use this predicate to simplify operations downstream. Op and Mask are
1941 /// known to be the same type.
1942 bool MaskedValueIsZero(SDValue Op, const APInt &Mask,
1943 unsigned Depth = 0) const;
1944
1945 /// Return true if 'Op & Mask' is known to be zero in DemandedElts. We
1946 /// use this predicate to simplify operations downstream. Op and Mask are
1947 /// known to be the same type.
1948 bool MaskedValueIsZero(SDValue Op, const APInt &Mask,
1949 const APInt &DemandedElts, unsigned Depth = 0) const;
1950
1951 /// Return true if 'Op' is known to be zero in DemandedElts. We
1952 /// use this predicate to simplify operations downstream.
1953 bool MaskedVectorIsZero(SDValue Op, const APInt &DemandedElts,
1954 unsigned Depth = 0) const;
1955
1956 /// Return true if '(Op & Mask) == Mask'.
1957 /// Op and Mask are known to be the same type.
1958 bool MaskedValueIsAllOnes(SDValue Op, const APInt &Mask,
1959 unsigned Depth = 0) const;
1960
1961 /// For each demanded element of a vector, see if it is known to be zero.
1962 APInt computeVectorKnownZeroElements(SDValue Op, const APInt &DemandedElts,
1963 unsigned Depth = 0) const;
1964
1965 /// Determine which bits of Op are known to be either zero or one and return
1966 /// them in Known. For vectors, the known bits are those that are shared by
1967 /// every vector element.
1968 /// Targets can implement the computeKnownBitsForTargetNode method in the
1969 /// TargetLowering class to allow target nodes to be understood.
1970 KnownBits computeKnownBits(SDValue Op, unsigned Depth = 0) const;
1971
1972 /// Determine which bits of Op are known to be either zero or one and return
1973 /// them in Known. The DemandedElts argument allows us to only collect the
1974 /// known bits that are shared by the requested vector elements.
1975 /// Targets can implement the computeKnownBitsForTargetNode method in the
1976 /// TargetLowering class to allow target nodes to be understood.
1977 KnownBits computeKnownBits(SDValue Op, const APInt &DemandedElts,
1978 unsigned Depth = 0) const;
1979
1980 /// Used to represent the possible overflow behavior of an operation.
1981 /// Never: the operation cannot overflow.
1982 /// Always: the operation will always overflow.
1983 /// Sometime: the operation may or may not overflow.
1988 };
1989
1990 /// Determine if the result of the signed addition of 2 nodes can overflow.
1992
1993 /// Determine if the result of the unsigned addition of 2 nodes can overflow.
1995
1996 /// Determine if the result of the addition of 2 nodes can overflow.
1998 SDValue N1) const {
1999 return IsSigned ? computeOverflowForSignedAdd(N0, N1)
2001 }
2002
2003 /// Determine if the result of the signed sub of 2 nodes can overflow.
2005
2006 /// Determine if the result of the unsigned sub of 2 nodes can overflow.
2008
2009 /// Determine if the result of the sub of 2 nodes can overflow.
2011 SDValue N1) const {
2012 return IsSigned ? computeOverflowForSignedSub(N0, N1)
2014 }
2015
2016 /// Test if the given value is known to have exactly one bit set. This differs
2017 /// from computeKnownBits in that it doesn't necessarily determine which bit
2018 /// is set.
2019 bool isKnownToBeAPowerOfTwo(SDValue Val, unsigned Depth = 0) const;
2020
2021 /// Return the number of times the sign bit of the register is replicated into
2022 /// the other bits. We know that at least 1 bit is always equal to the sign
2023 /// bit (itself), but other cases can give us information. For example,
2024 /// immediately after an "SRA X, 2", we know that the top 3 bits are all equal
2025 /// to each other, so we return 3. Targets can implement the
2026 /// ComputeNumSignBitsForTarget method in the TargetLowering class to allow
2027 /// target nodes to be understood.
2028 unsigned ComputeNumSignBits(SDValue Op, unsigned Depth = 0) const;
2029
2030 /// Return the number of times the sign bit of the register is replicated into
2031 /// the other bits. We know that at least 1 bit is always equal to the sign
2032 /// bit (itself), but other cases can give us information. For example,
2033 /// immediately after an "SRA X, 2", we know that the top 3 bits are all equal
2034 /// to each other, so we return 3. The DemandedElts argument allows
2035 /// us to only collect the minimum sign bits of the requested vector elements.
2036 /// Targets can implement the ComputeNumSignBitsForTarget method in the
2037 /// TargetLowering class to allow target nodes to be understood.
2038 unsigned ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
2039 unsigned Depth = 0) const;
2040
2041 /// Get the upper bound on bit size for this Value \p Op as a signed integer.
2042 /// i.e. x == sext(trunc(x to MaxSignedBits) to bitwidth(x)).
2043 /// Similar to the APInt::getSignificantBits function.
2044 /// Helper wrapper to ComputeNumSignBits.
2045 unsigned ComputeMaxSignificantBits(SDValue Op, unsigned Depth = 0) const;
2046
2047 /// Get the upper bound on bit size for this Value \p Op as a signed integer.
2048 /// i.e. x == sext(trunc(x to MaxSignedBits) to bitwidth(x)).
2049 /// Similar to the APInt::getSignificantBits function.
2050 /// Helper wrapper to ComputeNumSignBits.
2051 unsigned ComputeMaxSignificantBits(SDValue Op, const APInt &DemandedElts,
2052 unsigned Depth = 0) const;
2053
2054 /// Return true if this function can prove that \p Op is never poison
2055 /// and, if \p PoisonOnly is false, does not have undef bits.
2056 bool isGuaranteedNotToBeUndefOrPoison(SDValue Op, bool PoisonOnly = false,
2057 unsigned Depth = 0) const;
2058
2059 /// Return true if this function can prove that \p Op is never poison
2060 /// and, if \p PoisonOnly is false, does not have undef bits. The DemandedElts
2061 /// argument limits the check to the requested vector elements.
2062 bool isGuaranteedNotToBeUndefOrPoison(SDValue Op, const APInt &DemandedElts,
2063 bool PoisonOnly = false,
2064 unsigned Depth = 0) const;
2065
2066 /// Return true if this function can prove that \p Op is never poison.
2067 bool isGuaranteedNotToBePoison(SDValue Op, unsigned Depth = 0) const {
2068 return isGuaranteedNotToBeUndefOrPoison(Op, /*PoisonOnly*/ true, Depth);
2069 }
2070
2071 /// Return true if this function can prove that \p Op is never poison. The
2072 /// DemandedElts argument limits the check to the requested vector elements.
2073 bool isGuaranteedNotToBePoison(SDValue Op, const APInt &DemandedElts,
2074 unsigned Depth = 0) const {
2075 return isGuaranteedNotToBeUndefOrPoison(Op, DemandedElts,
2076 /*PoisonOnly*/ true, Depth);
2077 }
2078
2079 /// Return true if Op can create undef or poison from non-undef & non-poison
2080 /// operands. The DemandedElts argument limits the check to the requested
2081 /// vector elements.
2082 ///
2083 /// \p ConsiderFlags controls whether poison producing flags on the
2084 /// instruction are considered. This can be used to see if the instruction
2085 /// could still introduce undef or poison even without poison generating flags
2086 /// which might be on the instruction. (i.e. could the result of
2087 /// Op->dropPoisonGeneratingFlags() still create poison or undef)
2088 bool canCreateUndefOrPoison(SDValue Op, const APInt &DemandedElts,
2089 bool PoisonOnly = false,
2090 bool ConsiderFlags = true,
2091 unsigned Depth = 0) const;
2092
2093 /// Return true if Op can create undef or poison from non-undef & non-poison
2094 /// operands.
2095 ///
2096 /// \p ConsiderFlags controls whether poison producing flags on the
2097 /// instruction are considered. This can be used to see if the instruction
2098 /// could still introduce undef or poison even without poison generating flags
2099 /// which might be on the instruction. (i.e. could the result of
2100 /// Op->dropPoisonGeneratingFlags() still create poison or undef)
2101 bool canCreateUndefOrPoison(SDValue Op, bool PoisonOnly = false,
2102 bool ConsiderFlags = true,
2103 unsigned Depth = 0) const;
2104
2105 /// Return true if the specified operand is an ISD::ADD with a ConstantSDNode
2106 /// on the right-hand side, or if it is an ISD::OR with a ConstantSDNode that
2107 /// is guaranteed to have the same semantics as an ADD. This handles the
2108 /// equivalence:
2109 /// X|Cst == X+Cst iff X&Cst = 0.
2110 bool isBaseWithConstantOffset(SDValue Op) const;
2111
2112 /// Test whether the given SDValue (or all elements of it, if it is a
2113 /// vector) is known to never be NaN. If \p SNaN is true, returns if \p Op is
2114 /// known to never be a signaling NaN (it may still be a qNaN).
2115 bool isKnownNeverNaN(SDValue Op, bool SNaN = false, unsigned Depth = 0) const;
2116
2117 /// \returns true if \p Op is known to never be a signaling NaN.
2118 bool isKnownNeverSNaN(SDValue Op, unsigned Depth = 0) const {
2119 return isKnownNeverNaN(Op, true, Depth);
2120 }
2121
2122 /// Test whether the given floating point SDValue is known to never be
2123 /// positive or negative zero.
2124 bool isKnownNeverZeroFloat(SDValue Op) const;
2125
2126 /// Test whether the given SDValue is known to contain non-zero value(s).
2127 bool isKnownNeverZero(SDValue Op, unsigned Depth = 0) const;
2128
2129 /// Test whether two SDValues are known to compare equal. This
2130 /// is true if they are the same value, or if one is negative zero and the
2131 /// other positive zero.
2132 bool isEqualTo(SDValue A, SDValue B) const;
2133
2134 /// Return true if A and B have no common bits set. As an example, this can
2135 /// allow an 'add' to be transformed into an 'or'.
2136 bool haveNoCommonBitsSet(SDValue A, SDValue B) const;
2137
2138 /// Test whether \p V has a splatted value for all the demanded elements.
2139 ///
2140 /// On success \p UndefElts will indicate the elements that have UNDEF
2141 /// values instead of the splat value, this is only guaranteed to be correct
2142 /// for \p DemandedElts.
2143 ///
2144 /// NOTE: The function will return true for a demanded splat of UNDEF values.
2145 bool isSplatValue(SDValue V, const APInt &DemandedElts, APInt &UndefElts,
2146 unsigned Depth = 0) const;
2147
2148 /// Test whether \p V has a splatted value.
2149 bool isSplatValue(SDValue V, bool AllowUndefs = false) const;
2150
2151 /// If V is a splatted value, return the source vector and its splat index.
2152 SDValue getSplatSourceVector(SDValue V, int &SplatIndex);
2153
2154 /// If V is a splat vector, return its scalar source operand by extracting
2155 /// that element from the source vector. If LegalTypes is true, this method
2156 /// may only return a legally-typed splat value. If it cannot legalize the
2157 /// splatted value it will return SDValue().
2158 SDValue getSplatValue(SDValue V, bool LegalTypes = false);
2159
2160 /// If a SHL/SRA/SRL node \p V has a constant or splat constant shift amount
2161 /// that is less than the element bit-width of the shift node, return it.
2163 const APInt &DemandedElts) const;
2164
2165 /// If a SHL/SRA/SRL node \p V has constant shift amounts that are all less
2166 /// than the element bit-width of the shift node, return the minimum value.
2167 const APInt *
2169 const APInt &DemandedElts) const;
2170
2171 /// If a SHL/SRA/SRL node \p V has constant shift amounts that are all less
2172 /// than the element bit-width of the shift node, return the maximum value.
2173 const APInt *
2175 const APInt &DemandedElts) const;
2176
2177 /// Match a binop + shuffle pyramid that represents a horizontal reduction
2178 /// over the elements of a vector starting from the EXTRACT_VECTOR_ELT node /p
2179 /// Extract. The reduction must use one of the opcodes listed in /p
2180 /// CandidateBinOps and on success /p BinOp will contain the matching opcode.
2181 /// Returns the vector that is being reduced on, or SDValue() if a reduction
2182 /// was not matched. If \p AllowPartials is set then in the case of a
2183 /// reduction pattern that only matches the first few stages, the extracted
2184 /// subvector of the start of the reduction is returned.
2186 ArrayRef<ISD::NodeType> CandidateBinOps,
2187 bool AllowPartials = false);
2188
2189 /// Utility function used by legalize and lowering to
2190 /// "unroll" a vector operation by splitting out the scalars and operating
2191 /// on each element individually. If the ResNE is 0, fully unroll the vector
2192 /// op. If ResNE is less than the width of the vector op, unroll up to ResNE.
2193 /// If the ResNE is greater than the width of the vector op, unroll the
2194 /// vector op and fill the end of the resulting vector with UNDEFS.
2195 SDValue UnrollVectorOp(SDNode *N, unsigned ResNE = 0);
2196
2197 /// Like UnrollVectorOp(), but for the [US](ADD|SUB|MUL)O family of opcodes.
2198 /// This is a separate function because those opcodes have two results.
2199 std::pair<SDValue, SDValue> UnrollVectorOverflowOp(SDNode *N,
2200 unsigned ResNE = 0);
2201
2202 /// Return true if loads are next to each other and can be
2203 /// merged. Check that both are nonvolatile and if LD is loading
2204 /// 'Bytes' bytes from a location that is 'Dist' units away from the
2205 /// location that the 'Base' load is loading from.
2207 unsigned Bytes, int Dist) const;
2208
2209 /// Infer alignment of a load / store address. Return std::nullopt if it
2210 /// cannot be inferred.
2212
2213 /// Split the scalar node with EXTRACT_ELEMENT using the provided VTs and
2214 /// return the low/high part.
2215 std::pair<SDValue, SDValue> SplitScalar(const SDValue &N, const SDLoc &DL,
2216 const EVT &LoVT, const EVT &HiVT);
2217
2218 /// Compute the VTs needed for the low/hi parts of a type
2219 /// which is split (or expanded) into two not necessarily identical pieces.
2220 std::pair<EVT, EVT> GetSplitDestVTs(const EVT &VT) const;
2221
2222 /// Compute the VTs needed for the low/hi parts of a type, dependent on an
2223 /// enveloping VT that has been split into two identical pieces. Sets the
2224 /// HisIsEmpty flag when hi type has zero storage size.
2225 std::pair<EVT, EVT> GetDependentSplitDestVTs(const EVT &VT, const EVT &EnvVT,
2226 bool *HiIsEmpty) const;
2227
2228 /// Split the vector with EXTRACT_SUBVECTOR using the provides
2229 /// VTs and return the low/high part.
2230 std::pair<SDValue, SDValue> SplitVector(const SDValue &N, const SDLoc &DL,
2231 const EVT &LoVT, const EVT &HiVT);
2232
2233 /// Split the vector with EXTRACT_SUBVECTOR and return the low/high part.
2234 std::pair<SDValue, SDValue> SplitVector(const SDValue &N, const SDLoc &DL) {
2235 EVT LoVT, HiVT;
2236 std::tie(LoVT, HiVT) = GetSplitDestVTs(N.getValueType());
2237 return SplitVector(N, DL, LoVT, HiVT);
2238 }
2239
2240 /// Split the explicit vector length parameter of a VP operation.
2241 std::pair<SDValue, SDValue> SplitEVL(SDValue N, EVT VecVT, const SDLoc &DL);
2242
2243 /// Split the node's operand with EXTRACT_SUBVECTOR and
2244 /// return the low/high part.
2245 std::pair<SDValue, SDValue> SplitVectorOperand(const SDNode *N, unsigned OpNo)
2246 {
2247 return SplitVector(N->getOperand(OpNo), SDLoc(N));
2248 }
2249
2250 /// Widen the vector up to the next power of two using INSERT_SUBVECTOR.
2251 SDValue WidenVector(const SDValue &N, const SDLoc &DL);
2252
2253 /// Append the extracted elements from Start to Count out of the vector Op in
2254 /// Args. If Count is 0, all of the elements will be extracted. The extracted
2255 /// elements will have type EVT if it is provided, and otherwise their type
2256 /// will be Op's element type.
2258 unsigned Start = 0, unsigned Count = 0,
2259 EVT EltVT = EVT());
2260
2261 /// Compute the default alignment value for the given type.
2262 Align getEVTAlign(EVT MemoryVT) const;
2263
2264 /// Test whether the given value is a constant int or similar node.
2266
2267 /// Test whether the given value is a constant FP or similar node.
2269
2270 /// \returns true if \p N is any kind of constant or build_vector of
2271 /// constants, int or float. If a vector, it may not necessarily be a splat.
2275 }
2276
2277 /// Set CallSiteInfo to be associated with Node.
2279 SDEI[Node].CSInfo = std::move(CallInfo);
2280 }
2281 /// Return CallSiteInfo associated with Node, or a default if none exists.
2283 auto I = SDEI.find(Node);
2284 return I != SDEI.end() ? std::move(I->second).CSInfo : CallSiteInfo();
2285 }
2286 /// Set HeapAllocSite to be associated with Node.
2288 SDEI[Node].HeapAllocSite = MD;
2289 }
2290 /// Return HeapAllocSite associated with Node, or nullptr if none exists.
2292 auto I = SDEI.find(Node);
2293 return I != SDEI.end() ? I->second.HeapAllocSite : nullptr;
2294 }
2295 /// Set PCSections to be associated with Node.
2296 void addPCSections(const SDNode *Node, MDNode *MD) {
2297 SDEI[Node].PCSections = MD;
2298 }
2299 /// Return PCSections associated with Node, or nullptr if none exists.
2301 auto It = SDEI.find(Node);
2302 return It != SDEI.end() ? It->second.PCSections : nullptr;
2303 }
2304 /// Set NoMergeSiteInfo to be associated with Node if NoMerge is true.
2305 void addNoMergeSiteInfo(const SDNode *Node, bool NoMerge) {
2306 if (NoMerge)
2307 SDEI[Node].NoMerge = NoMerge;
2308 }
2309 /// Return NoMerge info associated with Node.
2310 bool getNoMergeSiteInfo(const SDNode *Node) const {
2311 auto I = SDEI.find(Node);
2312 return I != SDEI.end() ? I->second.NoMerge : false;
2313 }
2314
2315 /// Copy extra info associated with one node to another.
2316 void copyExtraInfo(SDNode *From, SDNode *To);
2317
2318 /// Return the current function's default denormal handling kind for the given
2319 /// floating point type.
2321 return MF->getDenormalMode(EVTToAPFloatSemantics(VT));
2322 }
2323
2324 bool shouldOptForSize() const;
2325
2326 /// Get the (commutative) neutral element for the given opcode, if it exists.
2327 SDValue getNeutralElement(unsigned Opcode, const SDLoc &DL, EVT VT,
2329
2330 /// Some opcodes may create immediate undefined behavior when used with some
2331 /// values (integer division-by-zero for example). Therefore, these operations
2332 /// are not generally safe to move around or change.
2333 bool isSafeToSpeculativelyExecute(unsigned Opcode) const {
2334 switch (Opcode) {
2335 case ISD::SDIV:
2336 case ISD::SREM:
2337 case ISD::SDIVREM:
2338 case ISD::UDIV:
2339 case ISD::UREM:
2340 case ISD::UDIVREM:
2341 return false;
2342 default:
2343 return true;
2344 }
2345 }
2346
2347private:
2348 void InsertNode(SDNode *N);
2349 bool RemoveNodeFromCSEMaps(SDNode *N);
2350 void AddModifiedNodeToCSEMaps(SDNode *N);
2351 SDNode *FindModifiedNodeSlot(SDNode *N, SDValue Op, void *&InsertPos);
2352 SDNode *FindModifiedNodeSlot(SDNode *N, SDValue Op1, SDValue Op2,
2353 void *&InsertPos);
2354 SDNode *FindModifiedNodeSlot(SDNode *N, ArrayRef<SDValue> Ops,
2355 void *&InsertPos);
2356 SDNode *UpdateSDLocOnMergeSDNode(SDNode *N, const SDLoc &loc);
2357
2358 void DeleteNodeNotInCSEMaps(SDNode *N);
2359 void DeallocateNode(SDNode *N);
2360
2361 void allnodes_clear();
2362
2363 /// Look up the node specified by ID in CSEMap. If it exists, return it. If
2364 /// not, return the insertion token that will make insertion faster. This
2365 /// overload is for nodes other than Constant or ConstantFP, use the other one
2366 /// for those.
2367 SDNode *FindNodeOrInsertPos(const FoldingSetNodeID &ID, void *&InsertPos);
2368
2369 /// Look up the node specified by ID in CSEMap. If it exists, return it. If
2370 /// not, return the insertion token that will make insertion faster. Performs
2371 /// additional processing for constant nodes.
2372 SDNode *FindNodeOrInsertPos(const FoldingSetNodeID &ID, const SDLoc &DL,
2373 void *&InsertPos);
2374
2375 /// Maps to auto-CSE operations.
2376 std::vector<CondCodeSDNode*> CondCodeNodes;
2377
2378 std::vector<SDNode*> ValueTypeNodes;
2379 std::map<EVT, SDNode*, EVT::compareRawBits> ExtendedValueTypeNodes;
2380 StringMap<SDNode*> ExternalSymbols;
2381
2382 std::map<std::pair<std::string, unsigned>, SDNode *> TargetExternalSymbols;
2384
2385 FlagInserter *Inserter = nullptr;
2386};
2387
2388template <> struct GraphTraits<SelectionDAG*> : public GraphTraits<SDNode*> {
2390
2392 return nodes_iterator(G->allnodes_begin());
2393 }
2394
2396 return nodes_iterator(G->allnodes_end());
2397 }
2398};
2399
2400} // end namespace llvm
2401
2402#endif // LLVM_CODEGEN_SELECTIONDAG_H
aarch64 promote const
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file defines the StringMap class.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
This file defines the BumpPtrAllocator interface.
always inline
SmallVector< MachineOperand, 4 > Cond
BlockVerifier::State From
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
RelocType Type
Definition: COFFYAML.cpp:391
#define LLVM_DEPRECATED(MSG, FIX)
Definition: Compiler.h:145
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:492
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
uint64_t Size
Symbol * Sym
Definition: ELF_riscv.cpp:463
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
This file defines a hash set that can be used to remove duplication of nodes in a graph.
Hexagon Vector Combine
print lazy value Lazy Value Info Printer Pass
#define I(x, y, z)
Definition: MD5.cpp:58
#define G(x, y, z)
Definition: MD5.cpp:56
unsigned Reg
typename CallsiteContextGraph< DerivedCCG, FuncTy, CallTy >::FuncInfo FuncInfo
This file contains the declarations for metadata subclasses.
LLVMContext & Context
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
const char LLVMTargetMachineRef TM
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static Constant * ConstantFold(Instruction *I, const DataLayout &DL, const SmallDenseMap< Value *, Constant * > &ConstantPool)
Try to fold instruction I into a constant.
This file defines the SmallVector class.
@ Flags
Definition: TextStubV5.cpp:93
static void removeOperands(MachineInstr &MI, unsigned i)
Value * RHS
Value * LHS
Class for arbitrary precision integers.
Definition: APInt.h:75
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
Definition: APInt.h:214
static Capacity get(size_t N)
Get the capacity of an array that can hold at least N elements.
Definition: ArrayRecycler.h:79
Recycle small arrays allocated from a BumpPtrAllocator.
Definition: ArrayRecycler.h:28
void deallocate(Capacity Cap, T *Ptr)
Deallocate an array with the specified Capacity.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
The address of a basic block.
Definition: Constants.h:874
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:66
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:260
This is the shared class of boolean and integer constants.
Definition: Constants.h:78
This is an important base class in LLVM.
Definition: Constant.h:41
DWARF expression.
Base class for variables.
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:110
A debug info location.
Definition: DebugLoc.h:33
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:155
iterator end()
Definition: DenseMap.h:84
Implements a dense probed hash-table based set.
Definition: DenseSet.h:271
Node - This class is used to maintain the singly linked bucket list in a folding set.
Definition: FoldingSet.h:136
FoldingSetNodeIDRef - This class describes a reference to an interned FoldingSetNodeID,...
Definition: FoldingSet.h:288
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:318
FoldingSet - This template class is used to instantiate a specialized implementation of the folding s...
Definition: FoldingSet.h:520
FunctionLoweringInfo - This contains information that is global to a function that is used when lower...
Data structure describing the variable locations in a function.
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
This class is used to represent ISD::LOAD nodes.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
Metadata node.
Definition: Metadata.h:950
SimpleValueType SimpleTy
Abstract base class for all machine specific constantpool value subclasses.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
DenormalMode getDenormalMode(const fltSemantics &FPType) const
Returns the denormal handling type for the default rounding mode of the function.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
SmallVectorImpl< ArgRegPair > CallSiteInfoImpl
SmallVector< ArgRegPair, 1 > CallSiteInfo
Vector of call argument and its forwarding register.
A description of a memory reference used in the backend.
Flags
Flags values. These may be or'd together.
@ MOLoad
The memory access reads data.
@ MOStore
The memory access writes data.
An SDNode that represents everything that will be needed to construct a MachineInstr.
The optimization diagnostic interface.
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:94
Analysis providing profile information.
Keeps track of dbg_value information through SDISel.
Definition: SelectionDAG.h:159
BumpPtrAllocator & getAlloc()
Definition: SelectionDAG.h:188
DbgIterator ByvalParmDbgBegin()
Definition: SelectionDAG.h:206
DbgIterator DbgEnd()
Definition: SelectionDAG.h:205
SDDbgInfo & operator=(const SDDbgInfo &)=delete
SmallVectorImpl< SDDbgLabel * >::iterator DbgLabelIterator
Definition: SelectionDAG.h:202
SDDbgInfo()=default
void add(SDDbgValue *V, bool isParameter)
bool empty() const
Definition: SelectionDAG.h:190
DbgLabelIterator DbgLabelEnd()
Definition: SelectionDAG.h:209
DbgIterator ByvalParmDbgEnd()
Definition: SelectionDAG.h:207
SmallVectorImpl< SDDbgValue * >::iterator DbgIterator
Definition: SelectionDAG.h:201
SDDbgInfo(const SDDbgInfo &)=delete
DbgLabelIterator DbgLabelBegin()
Definition: SelectionDAG.h:208
void add(SDDbgLabel *L)
Definition: SelectionDAG.h:174
DbgIterator DbgBegin()
Definition: SelectionDAG.h:204
void erase(const SDNode *Node)
Invalidate all DbgValues attached to the node and remove it from the Node-to-DbgValues map.
ArrayRef< SDDbgValue * > getSDDbgValues(const SDNode *Node) const
Definition: SelectionDAG.h:194
Holds the information from a dbg_label node through SDISel.
Holds the information from a dbg_value node through SDISel.
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
SDVTListNode(const FoldingSetNodeIDRef ID, const EVT *VT, unsigned int Num)
Definition: SelectionDAG.h:112
SDVTList getSDVTList()
Definition: SelectionDAG.h:117
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
SDNode * getNode() const
get the SDNode which holds the desired result
EVT getValueType() const
Return the ValueType of the referenced return value.
Targets can subclass this to parameterize the SelectionDAG lowering and instruction selection process...
Help to insert SDNodeFlags automatically in transforming.
Definition: SelectionDAG.h:361
SDNodeFlags getFlags() const
Definition: SelectionDAG.h:379
FlagInserter(SelectionDAG &SDAG, SDNodeFlags Flags)
Definition: SelectionDAG.h:367
FlagInserter(const FlagInserter &)=delete
FlagInserter(SelectionDAG &SDAG, SDNode *N)
Definition: SelectionDAG.h:372
FlagInserter & operator=(const FlagInserter &)=delete
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Definition: SelectionDAG.h:225
static unsigned getOpcode_EXTEND_VECTOR_INREG(unsigned Opcode)
Convert *_EXTEND to *_EXTEND_VECTOR_INREG opcode.
Definition: SelectionDAG.h:924
Align getReducedAlign(EVT VT, bool UseABI)
In most cases this function returns the ABI alignment for a given type, except for illegal vector typ...
SDValue getShiftAmountOperand(EVT LHSTy, SDValue Op)
Return the specified value casted to the target's desired shift amount type.
SDValue getExtLoad(ISD::LoadExtType ExtType, const SDLoc &dl, EVT VT, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, EVT MemVT, MaybeAlign Alignment=MaybeAlign(), MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
SDValue getExtLoadVP(ISD::LoadExtType ExtType, const SDLoc &dl, EVT VT, SDValue Chain, SDValue Ptr, SDValue Mask, SDValue EVL, MachinePointerInfo PtrInfo, EVT MemVT, MaybeAlign Alignment, MachineMemOperand::Flags MMOFlags, const AAMDNodes &AAInfo, bool IsExpanding=false)
SDValue getTargetGlobalAddress(const GlobalValue *GV, const SDLoc &DL, EVT VT, int64_t offset=0, unsigned TargetFlags=0)
Definition: SelectionDAG.h:721
SDValue getSplatSourceVector(SDValue V, int &SplatIndex)
If V is a splatted value, return the source vector and its splat index.
SDValue getLabelNode(unsigned Opcode, const SDLoc &dl, SDValue Root, MCSymbol *Label)
OverflowKind computeOverflowForUnsignedSub(SDValue N0, SDValue N1) const
Determine if the result of the unsigned sub of 2 nodes can overflow.
unsigned ComputeMaxSignificantBits(SDValue Op, unsigned Depth=0) const
Get the upper bound on bit size for this Value Op as a signed integer.
const SDValue & getRoot() const
Return the root tag of the SelectionDAG.
Definition: SelectionDAG.h:551
SDValue getMemmove(SDValue Chain, const SDLoc &dl, SDValue Dst, SDValue Src, SDValue Size, Align Alignment, bool isVol, bool isTailCall, MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo, const AAMDNodes &AAInfo=AAMDNodes(), AAResults *AA=nullptr)
SDValue getMaskedGather(SDVTList VTs, EVT MemVT, const SDLoc &dl, ArrayRef< SDValue > Ops, MachineMemOperand *MMO, ISD::MemIndexType IndexType, ISD::LoadExtType ExtTy)
bool isKnownNeverSNaN(SDValue Op, unsigned Depth=0) const
SDValue getAddrSpaceCast(const SDLoc &dl, EVT VT, SDValue Ptr, unsigned SrcAS, unsigned DestAS)
Return an AddrSpaceCastSDNode.
SDValue getSelect(const SDLoc &DL, EVT VT, SDValue Cond, SDValue LHS, SDValue RHS)
Helper function to make it easier to build Select's if you just have operands and don't want to check...
SDValue getStackArgumentTokenFactor(SDValue Chain)
Compute a TokenFactor to force all the incoming stack arguments to be loaded from the stack.
const TargetSubtargetInfo & getSubtarget() const
Definition: SelectionDAG.h:474
const APInt * getValidMaximumShiftAmountConstant(SDValue V, const APInt &DemandedElts) const
If a SHL/SRA/SRL node V has constant shift amounts that are all less than the element bit-width of th...
SDValue getMemIntrinsicNode(unsigned Opcode, const SDLoc &dl, SDVTList VTList, ArrayRef< SDValue > Ops, EVT MemVT, MachinePointerInfo PtrInfo, MaybeAlign Alignment=std::nullopt, MachineMemOperand::Flags Flags=MachineMemOperand::MOLoad|MachineMemOperand::MOStore, uint64_t Size=0, const AAMDNodes &AAInfo=AAMDNodes())
const Pass * getPass() const
Definition: SelectionDAG.h:470
SDValue getMergeValues(ArrayRef< SDValue > Ops, const SDLoc &dl)
Create a MERGE_VALUES node from the given operands.
SDVTList getVTList(EVT VT)
Return an SDVTList that represents the list of values specified.
OptimizationRemarkEmitter & getORE() const
Definition: SelectionDAG.h:486
BlockFrequencyInfo * getBFI() const
Definition: SelectionDAG.h:488
void updateDivergence(SDNode *N)
SDValue getSplatValue(SDValue V, bool LegalTypes=false)
If V is a splat vector, return its scalar source operand by extracting that element from the source v...
SDValue FoldSetCC(EVT VT, SDValue N1, SDValue N2, ISD::CondCode Cond, const SDLoc &dl)
Constant fold a setcc to true or false.
MachineSDNode * getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT)
These are used for target selectors to create a new node with specified return type(s),...
void ExtractVectorElements(SDValue Op, SmallVectorImpl< SDValue > &Args, unsigned Start=0, unsigned Count=0, EVT EltVT=EVT())
Append the extracted elements from Start to Count out of the vector Op in Args.
SDValue getNeutralElement(unsigned Opcode, const SDLoc &DL, EVT VT, SDNodeFlags Flags)
Get the (commutative) neutral element for the given opcode, if it exists.
SDValue getAtomicMemset(SDValue Chain, const SDLoc &dl, SDValue Dst, SDValue Value, SDValue Size, Type *SizeTy, unsigned ElemSz, bool isTailCall, MachinePointerInfo DstPtrInfo)
bool LegalizeVectors()
This transforms the SelectionDAG into a SelectionDAG that only uses vector math operations supported ...
SDValue getTargetConstantFP(const APFloat &Val, const SDLoc &DL, EVT VT)
Definition: SelectionDAG.h:710
SDValue getVScale(const SDLoc &DL, EVT VT, APInt MulImm, bool ConstantFold=true)
Return a node that represents the runtime scaling 'MulImm * RuntimeVL'.
SDValue getPseudoProbeNode(const SDLoc &Dl, SDValue Chain, uint64_t Guid, uint64_t Index, uint32_t Attr)
Creates a PseudoProbeSDNode with function GUID Guid and the index of the block Index it is probing,...
SDValue getFreeze(SDValue V)
Return a freeze using the SDLoc of the value operand.
SDNode * SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT)
These are used for target selectors to mutate the specified node to have the specified return type,...
SDValue getConstantPool(const Constant *C, EVT VT, MaybeAlign Align=std::nullopt, int Offs=0, bool isT=false, unsigned TargetFlags=0)
SDNode * isConstantIntBuildVectorOrConstantInt(SDValue N) const
Test whether the given value is a constant int or similar node.
SDDbgInfo::DbgIterator ByvalParmDbgEnd() const
SDValue getAtomicCmpSwap(unsigned Opcode, const SDLoc &dl, EVT MemVT, SDVTList VTs, SDValue Chain, SDValue Ptr, SDValue Cmp, SDValue Swp, MachineMemOperand *MMO)
Gets a node for an atomic cmpxchg op.
SDValue makeEquivalentMemoryOrdering(SDValue OldChain, SDValue NewMemOpChain)
If an existing load has uses of its chain, create a token factor node with that chain and the new mem...
SDDbgValue * getVRegDbgValue(DIVariable *Var, DIExpression *Expr, unsigned VReg, bool IsIndirect, const DebugLoc &DL, unsigned O)
Creates a VReg SDDbgValue node.
void ReplaceAllUsesOfValuesWith(const SDValue *From, const SDValue *To, unsigned Num)
Like ReplaceAllUsesOfValueWith, but for multiple values at once.
SDValue getSetCC(const SDLoc &DL, EVT VT, SDValue LHS, SDValue RHS, ISD::CondCode Cond, SDValue Chain=SDValue(), bool IsSignaling=false)
Helper function to make it easier to build SetCC's if you just have an ISD::CondCode instead of an SD...
SDValue getSymbolFunctionGlobalAddress(SDValue Op, Function **TargetFunction=nullptr)
Returs an GlobalAddress of the function from the current module with name matching the given External...
bool isSafeToSpeculativelyExecute(unsigned Opcode) const
Some opcodes may create immediate undefined behavior when used with some values (integer division-by-...
OverflowKind computeOverflowForSub(bool IsSigned, SDValue N0, SDValue N1) const
Determine if the result of the sub of 2 nodes can overflow.
SDValue UnrollVectorOp(SDNode *N, unsigned ResNE=0)
Utility function used by legalize and lowering to "unroll" a vector operation by splitting out the sc...
SDDbgInfo::DbgIterator ByvalParmDbgBegin() const
void setFunctionLoweringInfo(FunctionLoweringInfo *FuncInfo)
Definition: SelectionDAG.h:461
SDValue getConstantFP(double Val, const SDLoc &DL, EVT VT, bool isTarget=false)
Create a ConstantFPSDNode wrapping a constant value.
OverflowKind
Used to represent the possible overflow behavior of an operation.
SDValue getCopyToReg(SDValue Chain, const SDLoc &dl, unsigned Reg, SDValue N, SDValue Glue)
Definition: SelectionDAG.h:782
bool haveNoCommonBitsSet(SDValue A, SDValue B) const
Return true if A and B have no common bits set.
const SDLoc SDValue SDValue MachinePointerInfo PtrInfo
bool calculateDivergence(SDNode *N)
SDValue getElementCount(const SDLoc &DL, EVT VT, ElementCount EC, bool ConstantFold=true)
SDValue getAssertAlign(const SDLoc &DL, SDValue V, Align A)
Return an AssertAlignSDNode.
SDNode * mutateStrictFPToFP(SDNode *Node)
Mutate the specified strict FP node to its non-strict equivalent, unlinking the node from its chain a...
SDValue getLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, MaybeAlign Alignment=MaybeAlign(), MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr)
Loads are not normal binary operators: their result type is not determined by their operands,...
SDValue getGLOBAL_OFFSET_TABLE(EVT VT)
Return a GLOBAL_OFFSET_TABLE node. This does not have a useful SDLoc.
SDValue getExtStridedLoadVP(ISD::LoadExtType ExtType, const SDLoc &DL, EVT VT, SDValue Chain, SDValue Ptr, SDValue Stride, SDValue Mask, SDValue EVL, MachinePointerInfo PtrInfo, EVT MemVT, MaybeAlign Alignment, MachineMemOperand::Flags MMOFlags, const AAMDNodes &AAInfo, bool IsExpanding=false)
SelectionDAG(const SelectionDAG &)=delete
const SDLoc SDValue Chain
SDValue getAtomic(unsigned Opcode, const SDLoc &dl, EVT MemVT, SDValue Chain, SDValue Ptr, SDValue Val, MachineMemOperand *MMO)
Gets a node for an atomic op, produces result (if relevant) and chain and takes 2 operands.
Align getEVTAlign(EVT MemoryVT) const
Compute the default alignment value for the given type.
void addNoMergeSiteInfo(const SDNode *Node, bool NoMerge)
Set NoMergeSiteInfo to be associated with Node if NoMerge is true.
bool shouldOptForSize() const
std::pair< SDValue, SDValue > SplitVectorOperand(const SDNode *N, unsigned OpNo)
Split the node's operand with EXTRACT_SUBVECTOR and return the low/high part.
SDValue getNOT(const SDLoc &DL, SDValue Val, EVT VT)
Create a bitwise NOT operation as (XOR Val, -1).
SDValue getVPZExtOrTrunc(const SDLoc &DL, EVT VT, SDValue Op, SDValue Mask, SDValue EVL)
Convert a vector-predicated Op, which must be an integer vector, to the vector-type VT,...
const STC & getSubtarget() const
Definition: SelectionDAG.h:475
SDValue getLoad(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType, EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, SDValue Offset, MachinePointerInfo PtrInfo, EVT MemVT, MaybeAlign Alignment=MaybeAlign(), MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr)
const TargetLowering & getTargetLoweringInfo() const
Definition: SelectionDAG.h:478
LLVM_DEPRECATED("Use the getLoad function that takes a MaybeAlign instead", "") inline SDValue getLoad(ISD
FIXME: Remove once transition to Align is over.
bool isEqualTo(SDValue A, SDValue B) const
Test whether two SDValues are known to compare equal.
static constexpr unsigned MaxRecursionDepth
Definition: SelectionDAG.h:448
SDValue getTruncStridedStoreVP(SDValue Chain, const SDLoc &DL, SDValue Val, SDValue Ptr, SDValue Stride, SDValue Mask, SDValue EVL, MachinePointerInfo PtrInfo, EVT SVT, Align Alignment, MachineMemOperand::Flags MMOFlags, const AAMDNodes &AAInfo, bool IsCompressing=false)
SDValue getStridedStoreVP(SDValue Chain, const SDLoc &DL, SDValue Val, SDValue Ptr, SDValue Offset, SDValue Stride, SDValue Mask, SDValue EVL, EVT MemVT, MachineMemOperand *MMO, ISD::MemIndexedMode AM, bool IsTruncating=false, bool IsCompressing=false)
bool isGuaranteedNotToBePoison(SDValue Op, unsigned Depth=0) const
Return true if this function can prove that Op is never poison.
SDValue expandVACopy(SDNode *Node)
Expand the specified ISD::VACOPY node as the Legalize pass would.
SDValue getIndexedMaskedLoad(SDValue OrigLoad, const SDLoc &dl, SDValue Base, SDValue Offset, ISD::MemIndexedMode AM)
SelectionDAG & operator=(const SelectionDAG &)=delete
const SDLoc SDValue SDValue Ptr
SDValue getTargetConstant(const APInt &Val, const SDLoc &DL, EVT VT, bool isOpaque=false)
Definition: SelectionDAG.h:679
APInt computeVectorKnownZeroElements(SDValue Op, const APInt &DemandedElts, unsigned Depth=0) const
For each demanded element of a vector, see if it is known to be zero.
void AddDbgValue(SDDbgValue *DB, bool isParameter)
Add a dbg_value SDNode.
bool NewNodesMustHaveLegalTypes
When true, additional steps are taken to ensure that getConstant() and similar functions return DAG n...
Definition: SelectionDAG.h:387
std::pair< EVT, EVT > GetSplitDestVTs(const EVT &VT) const
Compute the VTs needed for the low/hi parts of a type which is split (or expanded) into two not neces...
MDNode * getHeapAllocSite(const SDNode *Node) const
Return HeapAllocSite associated with Node, or nullptr if none exists.
void salvageDebugInfo(SDNode &N)
To be invoked on an SDNode that is slated to be erased.
SDNode * MorphNodeTo(SDNode *N, unsigned Opc, SDVTList VTs, ArrayRef< SDValue > Ops)
This mutates the specified node to have the specified return type, opcode, and operands.
LLVM_DEPRECATED("Use the getLoad function that takes a MaybeAlign instead", "") inline SDValue getLoad(EVT VT
FIXME: Remove once transition to Align is over.
SDValue getTargetJumpTable(int JTI, EVT VT, unsigned TargetFlags=0)
Definition: SelectionDAG.h:731
SDValue getLoadVP(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType, EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, SDValue Offset, SDValue Mask, SDValue EVL, MachinePointerInfo PtrInfo, EVT MemVT, MaybeAlign Alignment=MaybeAlign(), MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, bool IsExpanding=false)
std::pair< SDValue, SDValue > UnrollVectorOverflowOp(SDNode *N, unsigned ResNE=0)
Like UnrollVectorOp(), but for the [US](ADD|SUB|MUL)O family of opcodes.
allnodes_const_iterator allnodes_begin() const
Definition: SelectionDAG.h:531
SDValue getUNDEF(EVT VT)
Return an UNDEF node. UNDEF does not have a useful SDLoc.
SDValue getCALLSEQ_END(SDValue Chain, SDValue Op1, SDValue Op2, SDValue InGlue, const SDLoc &DL)
Return a new CALLSEQ_END node, which always must have a glue result (to ensure it's not CSE'd).
SDValue getGatherVP(SDVTList VTs, EVT VT, const SDLoc &dl, ArrayRef< SDValue > Ops, MachineMemOperand *MMO, ISD::MemIndexType IndexType)
SDValue getBuildVector(EVT VT, const SDLoc &DL, ArrayRef< SDValue > Ops)
Return an ISD::BUILD_VECTOR node.
Definition: SelectionDAG.h:828
SDValue getMemcpy(SDValue Chain, const SDLoc &dl, SDValue Dst, SDValue Src, SDValue Size, Align Alignment, bool isVol, bool AlwaysInline, bool isTailCall, MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo, const AAMDNodes &AAInfo=AAMDNodes(), AAResults *AA=nullptr)
allnodes_const_iterator allnodes_end() const
Definition: SelectionDAG.h:532
bool isSplatValue(SDValue V, const APInt &DemandedElts, APInt &UndefElts, unsigned Depth=0) const
Test whether V has a splatted value for all the demanded elements.
void DeleteNode(SDNode *N)
Remove the specified node from the system.
SDValue getBitcast(EVT VT, SDValue V)
Return a bitcast using the SDLoc of the value operand, and casting to the provided type.
SDDbgValue * getDbgValueList(DIVariable *Var, DIExpression *Expr, ArrayRef< SDDbgOperand > Locs, ArrayRef< SDNode * > Dependencies, bool IsIndirect, const DebugLoc &DL, unsigned O, bool IsVariadic)
Creates a SDDbgValue node from a list of locations.
SDDbgInfo::DbgIterator DbgEnd() const
SDValue getNegative(SDValue Val, const SDLoc &DL, EVT VT)
Create negative operation as (SUB 0, Val).
void setNodeMemRefs(MachineSDNode *N, ArrayRef< MachineMemOperand * > NewMemRefs)
Mutate the specified machine node's memory references to the provided list.
SDValue simplifySelect(SDValue Cond, SDValue TVal, SDValue FVal)
Try to simplify a select/vselect into 1 of its operands or a constant.
CallSiteInfo getCallSiteInfo(const SDNode *Node)
Return CallSiteInfo associated with Node, or a default if none exists.
SDValue getZeroExtendInReg(SDValue Op, const SDLoc &DL, EVT VT)
Return the expression required to zero extend the Op value assuming it was the smaller SrcTy value.
const DataLayout & getDataLayout() const
Definition: SelectionDAG.h:472
SDNode * isConstantFPBuildVectorOrConstantFP(SDValue N) const
Test whether the given value is a constant FP or similar node.
allnodes_iterator allnodes_begin()
Definition: SelectionDAG.h:536
iterator_range< allnodes_const_iterator > allnodes() const
Definition: SelectionDAG.h:546
MDNode * getPCSections(const SDNode *Node) const
Return PCSections associated with Node, or nullptr if none exists.
ProfileSummaryInfo * getPSI() const
Definition: SelectionDAG.h:487
SDValue expandVAArg(SDNode *Node)
Expand the specified ISD::VAARG node as the Legalize pass would.
SDValue getTargetFrameIndex(int FI, EVT VT)
Definition: SelectionDAG.h:726
void Legalize()
This transforms the SelectionDAG into a SelectionDAG that is compatible with the target instruction s...
SDValue getTokenFactor(const SDLoc &DL, SmallVectorImpl< SDValue > &Vals)
Creates a new TokenFactor containing Vals.
void setGraphAttrs(const SDNode *N, const char *Attrs)
Set graph attributes for a node. (eg. "color=red".)
SDValue getCopyToReg(SDValue Chain, const SDLoc &dl, SDValue Reg, SDValue N, SDValue Glue)
Definition: SelectionDAG.h:791
void addCallSiteInfo(const SDNode *Node, CallSiteInfoImpl &&CallInfo)
Set CallSiteInfo to be associated with Node.
bool LegalizeOp(SDNode *N, SmallSetVector< SDNode *, 16 > &UpdatedNodes)
Transforms a SelectionDAG node and any operands to it into a node that is compatible with the target ...
bool doesNodeExist(unsigned Opcode, SDVTList VTList, ArrayRef< SDValue > Ops)
Check if a node exists without modifying its flags.
void addHeapAllocSite(const SDNode *Node, MDNode *MD)
Set HeapAllocSite to be associated with Node.
const SelectionDAGTargetInfo & getSelectionDAGInfo() const
Definition: SelectionDAG.h:480
bool areNonVolatileConsecutiveLoads(LoadSDNode *LD, LoadSDNode *Base, unsigned Bytes, int Dist) const
Return true if loads are next to each other and can be merged.
SDDbgLabel * getDbgLabel(DILabel *Label, const DebugLoc &DL, unsigned O)
Creates a SDDbgLabel node.
SDValue getTargetConstant(const ConstantInt &Val, const SDLoc &DL, EVT VT, bool isOpaque=false)
Definition: SelectionDAG.h:683
SDValue getStoreVP(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, SDValue Offset, SDValue Mask, SDValue EVL, EVT MemVT, MachineMemOperand *MMO, ISD::MemIndexedMode AM, bool IsTruncating=false, bool IsCompressing=false)
std::pair< SDValue, SDValue > SplitVector(const SDValue &N, const SDLoc &DL)
Split the vector with EXTRACT_SUBVECTOR and return the low/high part.
void copyExtraInfo(SDNode *From, SDNode *To)
Copy extra info associated with one node to another.
SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
Create a ConstantSDNode wrapping a constant value.
void setGraphColor(const SDNode *N, const char *Color)
Convenience for setting node color attribute.
SDValue getStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, MaybeAlign Alignment=MaybeAlign(), MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
SDValue getMemBasePlusOffset(SDValue Base, TypeSize Offset, const SDLoc &DL, const SDNodeFlags Flags=SDNodeFlags())
Returns sum of the base pointer and offset.
SDValue getGlobalAddress(const GlobalValue *GV, const SDLoc &DL, EVT VT, int64_t offset=0, bool isTargetGA=false, unsigned TargetFlags=0)
SDValue getMemset(SDValue Chain, const SDLoc &dl, SDValue Dst, SDValue Src, SDValue Size, Align Alignment, bool isVol, bool AlwaysInline, bool isTailCall, MachinePointerInfo DstPtrInfo, const AAMDNodes &AAInfo=AAMDNodes())
SDValue getVAArg(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, SDValue SV, unsigned Align)
VAArg produces a result and token chain, and takes a pointer and a source value as input.
SDValue getTruncStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, EVT SVT, Align Alignment, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
SDValue getAllOnesConstant(const SDLoc &DL, EVT VT, bool IsTarget=false, bool IsOpaque=false)
Definition: SelectionDAG.h:660
SDValue getMDNode(const MDNode *MD)
Return an MDNodeSDNode which holds an MDNode.
SDValue getStridedLoadVP(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType, EVT VT, const SDLoc &DL, SDValue Chain, SDValue Ptr, SDValue Offset, SDValue Stride, SDValue Mask, SDValue EVL, MachinePointerInfo PtrInfo, EVT MemVT, MaybeAlign Alignment=MaybeAlign(), MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, bool IsExpanding=false)
void clear()
Clear state and free memory necessary to make this SelectionDAG ready to process a new block.
SDValue getCALLSEQ_END(SDValue Chain, uint64_t Size1, uint64_t Size2, SDValue Glue, const SDLoc &DL)
SDValue getIndexedStridedStoreVP(SDValue OrigStore, const SDLoc &DL, SDValue Base, SDValue Offset, ISD::MemIndexedMode AM)
void ReplaceAllUsesWith(SDValue From, SDValue To)
Modify anything using 'From' to use 'To' instead.
SDValue getCommutedVectorShuffle(const ShuffleVectorSDNode &SV)
Returns an ISD::VECTOR_SHUFFLE node semantically equivalent to the shuffle node in input but with swa...
std::pair< SDValue, SDValue > SplitVector(const SDValue &N, const SDLoc &DL, const EVT &LoVT, const EVT &HiVT)
Split the vector with EXTRACT_SUBVECTOR using the provides VTs and return the low/high part.
const APInt * getValidShiftAmountConstant(SDValue V, const APInt &DemandedElts) const
If a SHL/SRA/SRL node V has a constant or splat constant shift amount that is less than the element b...
bool isGuaranteedNotToBeUndefOrPoison(SDValue Op, bool PoisonOnly=false, unsigned Depth=0) const
Return true if this function can prove that Op is never poison and, if PoisonOnly is false,...
SDValue foldConstantFPMath(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1, SDValue N2)
Fold floating-point operations with 2 operands when both operands are constants and/or undefined.
SDValue getStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, Align Alignment, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
Helper function to build ISD::STORE nodes.
SDValue getIndexedLoadVP(SDValue OrigLoad, const SDLoc &dl, SDValue Base, SDValue Offset, ISD::MemIndexedMode AM)
SDValue getSrcValue(const Value *v)
Construct a node to track a Value* through the backend.
SDValue getSplatVector(EVT VT, const SDLoc &DL, SDValue Op)
Definition: SelectionDAG.h:862
const SDLoc SDValue SDValue MachinePointerInfo unsigned MachineMemOperand::Flags const AAMDNodes const MDNode * Ranges
SDValue getAtomicMemcpy(SDValue Chain, const SDLoc &dl, SDValue Dst, SDValue Src, SDValue Size, Type *SizeTy, unsigned ElemSz, bool isTailCall, MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo)
MaybeAlign InferPtrAlign(SDValue Ptr) const
Infer alignment of a load / store address.
FlagInserter * getFlagInserter()
Definition: SelectionDAG.h:490
bool MaskedValueIsAllOnes(SDValue Op, const APInt &Mask, unsigned Depth=0) const
Return true if '(Op & Mask) == Mask'.
const SDLoc SDValue SDValue MachinePointerInfo unsigned MachineMemOperand::Flags const AAMDNodes & AAInfo
SDValue getCALLSEQ_START(SDValue Chain, uint64_t InSize, uint64_t OutSize, const SDLoc &DL)
Return a new CALLSEQ_START node, that starts new call frame, in which InSize bytes are set up inside ...
bool hasDebugValues() const
Return true if there are any SDDbgValue nodes associated with this SelectionDAG.
bool SignBitIsZero(SDValue Op, unsigned Depth=0) const
Return true if the sign bit of Op is known to be zero.
SDValue getRegister(unsigned Reg, EVT VT)
void init(MachineFunction &NewMF, OptimizationRemarkEmitter &NewORE, Pass *PassPtr, const TargetLibraryInfo *LibraryInfo, UniformityInfo *UA, ProfileSummaryInfo *PSIin, BlockFrequencyInfo *BFIin, FunctionVarLocs const *FnVarLocs)
Prepare this SelectionDAG to process code in the given MachineFunction.
void RemoveDeadNodes()
This method deletes all unreachable nodes in the SelectionDAG.
void RemoveDeadNode(SDNode *N)
Remove the specified node from the system.
SDValue getBuildVector(EVT VT, const SDLoc &DL, ArrayRef< SDUse > Ops)
Return an ISD::BUILD_VECTOR node.
Definition: SelectionDAG.h:837
void AddDbgLabel(SDDbgLabel *DB)
Add a dbg_label SDNode.
bool isConstantValueOfAnyType(SDValue N) const
SDDbgInfo::DbgLabelIterator DbgLabelEnd() const
SDValue getTruncStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, EVT SVT, MaybeAlign Alignment=MaybeAlign(), MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
allnodes_iterator allnodes_end()
Definition: SelectionDAG.h:537
SDDbgInfo::DbgLabelIterator DbgLabelBegin() const
SDValue getTargetIndex(int Index, EVT VT, int64_t Offset=0, unsigned TargetFlags=0)
SDValue getTargetExtractSubreg(int SRIdx, const SDLoc &DL, EVT VT, SDValue Operand)
A convenience function for creating TargetInstrInfo::EXTRACT_SUBREG nodes.
SDValue getBasicBlock(MachineBasicBlock *MBB)
SDValue getSExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of integer type, to the integer type VT, by either sign-extending or trunca...
bool isKnownToBeAPowerOfTwo(SDValue Val, unsigned Depth=0) const
Test if the given value is known to have exactly one bit set.
SDValue getEHLabel(const SDLoc &dl, SDValue Root, MCSymbol *Label)
std::string getGraphAttrs(const SDNode *N) const
Get graph attributes for a node.
SDValue getIndexedStoreVP(SDValue OrigStore, const SDLoc &dl, SDValue Base, SDValue Offset, ISD::MemIndexedMode AM)
bool isKnownNeverZero(SDValue Op, unsigned Depth=0) const
Test whether the given SDValue is known to contain non-zero value(s).
SDValue getIndexedStore(SDValue OrigStore, const SDLoc &dl, SDValue Base, SDValue Offset, ISD::MemIndexedMode AM)
SDValue getBoolExtOrTrunc(SDValue Op, const SDLoc &SL, EVT VT, EVT OpVT)
Convert Op, which must be of integer type, to the integer type VT, by using an extension appropriate ...
SDValue getMaskedStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Base, SDValue Offset, SDValue Mask, EVT MemVT, MachineMemOperand *MMO, ISD::MemIndexedMode AM, bool IsTruncating=false, bool IsCompressing=false)
static const fltSemantics & EVTToAPFloatSemantics(EVT VT)
Returns an APFloat semantics tag appropriate for the given type.
SDValue getExternalSymbol(const char *Sym, EVT VT)
const TargetMachine & getTarget() const
Definition: SelectionDAG.h:473
bool getNoMergeSiteInfo(const SDNode *Node) const
Return NoMerge info associated with Node.
std::pair< SDValue, SDValue > getStrictFPExtendOrRound(SDValue Op, SDValue Chain, const SDLoc &DL, EVT VT)
Convert Op, which must be a STRICT operation of float type, to the float type VT, by either extending...
SDValue getObjectPtrOffset(const SDLoc &SL, SDValue Ptr, SDValue Offset)
std::pair< SDValue, SDValue > SplitEVL(SDValue N, EVT VecVT, const SDLoc &DL)
Split the explicit vector length parameter of a VP operation.
SDValue getPtrExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of integer type, to the integer type VT, by either truncating it or perform...
SDValue getStepVector(const SDLoc &DL, EVT ResVT, APInt StepVal)
Returns a vector of type ResVT whose elements contain the linear sequence <0, Step,...
SDValue getVPLogicalNOT(const SDLoc &DL, SDValue Val, SDValue Mask, SDValue EVL, EVT VT)
Create a vector-predicated logical NOT operation as (VP_XOR Val, BooleanOne, Mask,...
SDDbgInfo::DbgIterator DbgBegin() const
SDValue getAnyExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of integer type, to the integer type VT, by either any-extending or truncat...
SDValue getCopyToReg(SDValue Chain, const SDLoc &dl, unsigned Reg, SDValue N)
Definition: SelectionDAG.h:773
iterator_range< allnodes_iterator > allnodes()
Definition: SelectionDAG.h:543
OverflowKind computeOverflowForAdd(bool IsSigned, SDValue N0, SDValue N1) const
Determine if the result of the addition of 2 nodes can overflow.
const SDLoc & dl
SDValue getBlockAddress(const BlockAddress *BA, EVT VT, int64_t Offset=0, bool isTarget=false, unsigned TargetFlags=0)
SDValue getSelectCC(const SDLoc &DL, SDValue LHS, SDValue RHS, SDValue True, SDValue False, ISD::CondCode Cond)
Helper function to make it easier to build SelectCC's if you just have an ISD::CondCode instead of an...
bool isKnownNeverZeroFloat(SDValue Op) const
Test whether the given floating point SDValue is known to never be positive or negative zero.
SDValue getMemIntrinsicNode(unsigned Opcode, const SDLoc &dl, SDVTList VTList, ArrayRef< SDValue > Ops, EVT MemVT, MachinePointerInfo PtrInfo, Align Alignment, MachineMemOperand::Flags Flags=MachineMemOperand::MOLoad|MachineMemOperand::MOStore, uint64_t Size=0, const AAMDNodes &AAInfo=AAMDNodes())
Creates a MemIntrinsicNode that may produce a result and takes a list of operands.
SDValue getLoadVP(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType, EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, SDValue Offset, SDValue Mask, SDValue EVL, MachinePointerInfo PtrInfo, EVT MemVT, Align Alignment, MachineMemOperand::Flags MMOFlags, const AAMDNodes &AAInfo, const MDNode *Ranges=nullptr, bool IsExpanding=false)
SDValue getIntPtrConstant(uint64_t Val, const SDLoc &DL, bool isTarget=false)
SDDbgValue * getConstantDbgValue(DIVariable *Var, DIExpression *Expr, const Value *C, const DebugLoc &DL, unsigned O)
Creates a constant SDDbgValue node.
SDValue getScatterVP(SDVTList VTs, EVT VT, const SDLoc &dl, ArrayRef< SDValue > Ops, MachineMemOperand *MMO, ISD::MemIndexType IndexType)
SDValue getValueType(EVT)
SDValue getTargetConstantFP(double Val, const SDLoc &DL, EVT VT)
Definition: SelectionDAG.h:707
ArrayRef< SDDbgValue * > GetDbgValues(const SDNode *SD) const
Get the debug values which reference the given SDNode.
SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
OverflowKind computeOverflowForSignedAdd(SDValue N0, SDValue N1) const
Determine if the result of the signed addition of 2 nodes can overflow.
SDValue getFPExtendOrRound(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of float type, to the float type VT, by either extending or rounding (by tr...
unsigned AssignTopologicalOrder()
Topological-sort the AllNodes list and a assign a unique node id for each node in the DAG based on th...
ilist< SDNode >::size_type allnodes_size() const
Definition: SelectionDAG.h:539
SDValue getAtomicMemmove(SDValue Chain, const SDLoc &dl, SDValue Dst, SDValue Src, SDValue Size, Type *SizeTy, unsigned ElemSz, bool isTailCall, MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo)
bool isKnownNeverNaN(SDValue Op, bool SNaN=false, unsigned Depth=0) const
Test whether the given SDValue (or all elements of it, if it is a vector) is known to never be NaN.
SDValue getIndexedMaskedStore(SDValue OrigStore, const SDLoc &dl, SDValue Base, SDValue Offset, ISD::MemIndexedMode AM)
SDValue getTruncStoreVP(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, SDValue Mask, SDValue EVL, MachinePointerInfo PtrInfo, EVT SVT, Align Alignment, MachineMemOperand::Flags MMOFlags, const AAMDNodes &AAInfo, bool IsCompressing=false)
SDValue getTargetConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isOpaque=false)
Definition: SelectionDAG.h:675
const TargetLibraryInfo & getLibInfo() const
Definition: SelectionDAG.h:479
unsigned ComputeNumSignBits(SDValue Op, unsigned Depth=0) const
Return the number of times the sign bit of the register is replicated into the other bits.
const SDLoc SDValue SDValue MachinePointerInfo unsigned Alignment
SDValue getStridedLoadVP(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType, EVT VT, const SDLoc &DL, SDValue Chain, SDValue Ptr, SDValue Offset, SDValue Stride, SDValue Mask, SDValue EVL, MachinePointerInfo PtrInfo, EVT MemVT, Align Alignment, MachineMemOperand::Flags MMOFlags, const AAMDNodes &AAInfo, const MDNode *Ranges=nullptr, bool IsExpanding=false)
bool MaskedVectorIsZero(SDValue Op, const APInt &DemandedElts, unsigned Depth=0) const
Return true if 'Op' is known to be zero in DemandedElts.
SDValue getBoolConstant(bool V, const SDLoc &DL, EVT VT, EVT OpVT)
Create a true or false constant of type VT using the target's BooleanContent for type OpVT.
SDValue getTargetBlockAddress(const BlockAddress *BA, EVT VT, int64_t Offset=0, unsigned TargetFlags=0)
Definition: SelectionDAG.h:768
SDDbgValue * getFrameIndexDbgValue(DIVariable *Var, DIExpression *Expr, unsigned FI, bool IsIndirect, const DebugLoc &DL, unsigned O)
Creates a FrameIndex SDDbgValue node.
const UniformityInfo * getUniformityInfo() const
Definition: SelectionDAG.h:481
SDValue getJumpTable(int JTI, EVT VT, bool isTarget=false, unsigned TargetFlags=0)
bool isBaseWithConstantOffset(SDValue Op) const
Return true if the specified operand is an ISD::ADD with a ConstantSDNode on the right-hand side,...
SDValue getVPPtrExtOrTrunc(const SDLoc &DL, EVT VT, SDValue Op, SDValue Mask, SDValue EVL)
Convert a vector-predicated Op, which must be of integer type, to the vector-type integer type VT,...
SDValue getVectorIdxConstant(uint64_t Val, const SDLoc &DL, bool isTarget=false)
void ReplaceAllUsesOfValueWith(SDValue From, SDValue To)
Replace any uses of From with To, leaving uses of other values produced by From.getNode() alone.
MachineFunction & getMachineFunction() const
Definition: SelectionDAG.h:469
SDValue getCopyFromReg(SDValue Chain, const SDLoc &dl, unsigned Reg, EVT VT)
Definition: SelectionDAG.h:799
SDValue getPtrExtendInReg(SDValue Op, const SDLoc &DL, EVT VT)
Return the expression required to extend the Op as a pointer value assuming it was the smaller SrcTy ...
bool canCreateUndefOrPoison(SDValue Op, const APInt &DemandedElts, bool PoisonOnly=false, bool ConsiderFlags=true, unsigned Depth=0) const
Return true if Op can create undef or poison from non-undef & non-poison operands.
OverflowKind computeOverflowForUnsignedAdd(SDValue N0, SDValue N1) const
Determine if the result of the unsigned addition of 2 nodes can overflow.
void setFlagInserter(FlagInserter *FI)
Definition: SelectionDAG.h:491
SDValue getSplatBuildVector(EVT VT, const SDLoc &DL, SDValue Op)
Return a splat ISD::BUILD_VECTOR node, consisting of Op splatted to all elements.
Definition: SelectionDAG.h:845
SDValue FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDValue > Ops)
SDValue getFrameIndex(int FI, EVT VT, bool isTarget=false)
const FunctionVarLocs * getFunctionVarLocs() const
Returns the result of the AssignmentTrackingAnalysis pass if it's available, otherwise return nullptr...
Definition: SelectionDAG.h:484
void canonicalizeCommutativeBinop(unsigned Opcode, SDValue &N1, SDValue &N2) const
Swap N1 and N2 if Opcode is a commutative binary opcode and the canonical form expects the opposite o...
KnownBits computeKnownBits(SDValue Op, unsigned Depth=0) const
Determine which bits of Op are known to be either zero or one and return them in Known.
SDValue getRegisterMask(const uint32_t *RegMask)
SDValue getZExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of integer type, to the integer type VT, by either zero-extending or trunca...
SDValue getCondCode(ISD::CondCode Cond)
SDValue getLifetimeNode(bool IsStart, const SDLoc &dl, SDValue Chain, int FrameIndex, int64_t Size, int64_t Offset=-1)
Creates a LifetimeSDNode that starts (IsStart==true) or ends (IsStart==false) the lifetime of the por...
bool MaskedValueIsZero(SDValue Op, const APInt &Mask, unsigned Depth=0) const
Return true if 'Op & Mask' is known to be zero.
OverflowKind computeOverflowForSignedSub(SDValue N0, SDValue N1) const
Determine if the result of the signed sub of 2 nodes can overflow.
SDValue getIndexedStridedLoadVP(SDValue OrigLoad, const SDLoc &DL, SDValue Base, SDValue Offset, ISD::MemIndexedMode AM)
SDValue getObjectPtrOffset(const SDLoc &SL, SDValue Ptr, TypeSize Offset)
Create an add instruction with appropriate flags when used for addressing some offset of an object.
LLVMContext * getContext() const
Definition: SelectionDAG.h:485
SDValue simplifyFPBinop(unsigned Opcode, SDValue X, SDValue Y, SDNodeFlags Flags)
Try to simplify a floating-point binary operation into 1 of its operands or a constant.
const SDValue & setRoot(SDValue N)
Set the current root tag of the SelectionDAG.
Definition: SelectionDAG.h:560
const APInt * getValidMinimumShiftAmountConstant(SDValue V, const APInt &DemandedElts) const
If a SHL/SRA/SRL node V has constant shift amounts that are all less than the element bit-width of th...
void addPCSections(const SDNode *Node, MDNode *MD)
Set PCSections to be associated with Node.
SDValue getShiftAmountConstant(uint64_t Val, EVT VT, const SDLoc &DL, bool LegalTypes=true)
bool isGuaranteedNotToBePoison(SDValue Op, const APInt &DemandedElts, unsigned Depth=0) const
Return true if this function can prove that Op is never poison.
SDValue getTargetConstantPool(MachineConstantPoolValue *C, EVT VT, MaybeAlign Align=std::nullopt, int Offset=0, unsigned TargetFlags=0)
Definition: SelectionDAG.h:745
void clearGraphAttrs()
Clear all previously defined node graph attributes.
SDValue getTargetExternalSymbol(const char *Sym, EVT VT, unsigned TargetFlags=0)
SDValue getCopyFromReg(SDValue Chain, const SDLoc &dl, unsigned Reg, EVT VT, SDValue Glue)
Definition: SelectionDAG.h:808
SDValue getMCSymbol(MCSymbol *Sym, EVT VT)
bool isUndef(unsigned Opcode, ArrayRef< SDValue > Ops)
Return true if the result of this operation is always undefined.
SDValue getSetCCVP(const SDLoc &DL, EVT VT, SDValue LHS, SDValue RHS, ISD::CondCode Cond, SDValue Mask, SDValue EVL)
Helper function to make it easier to build VP_SETCCs if you just have an ISD::CondCode instead of an ...
SDValue CreateStackTemporary(TypeSize Bytes, Align Alignment)
Create a stack temporary based on the size in bytes and the alignment.
SDNode * UpdateNodeOperands(SDNode *N, SDValue Op)
Mutate the specified node in-place to have the specified operands.
std::pair< EVT, EVT > GetDependentSplitDestVTs(const EVT &VT, const EVT &EnvVT, bool *HiIsEmpty) const
Compute the VTs needed for the low/hi parts of a type, dependent on an enveloping VT that has been sp...
SDNode * getNodeIfExists(unsigned Opcode, SDVTList VTList, ArrayRef< SDValue > Ops, const SDNodeFlags Flags)
Get the specified node if it's already available, or else return NULL.
SDValue getTargetConstantPool(const Constant *C, EVT VT, MaybeAlign Align=std::nullopt, int Offset=0, unsigned TargetFlags=0)
Definition: SelectionDAG.h:737
SDValue FoldSymbolOffset(unsigned Opcode, EVT VT, const GlobalAddressSDNode *GA, const SDNode *N2)
void RepositionNode(allnodes_iterator Position, SDNode *N)
Move node N in the AllNodes list to be immediately before the given iterator Position.
SDValue getIndexedLoad(SDValue OrigLoad, const SDLoc &dl, SDValue Base, SDValue Offset, ISD::MemIndexedMode AM)
SDValue getTargetInsertSubreg(int SRIdx, const SDLoc &DL, EVT VT, SDValue Operand, SDValue Subreg)
A convenience function for creating TargetInstrInfo::INSERT_SUBREG nodes.
SDValue getEntryNode() const
Return the token chain corresponding to the entry of the function.
Definition: SelectionDAG.h:554
SDDbgValue * getDbgValue(DIVariable *Var, DIExpression *Expr, SDNode *N, unsigned R, bool IsIndirect, const DebugLoc &DL, unsigned O)
Creates a SDDbgValue node.
void setSubgraphColor(SDNode *N, const char *Color)
Convenience for setting subgraph color attribute.
SDValue getMaskedLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Base, SDValue Offset, SDValue Mask, SDValue Src0, EVT MemVT, MachineMemOperand *MMO, ISD::MemIndexedMode AM, ISD::LoadExtType, bool IsExpanding=false)
SDValue getTargetConstantFP(const ConstantFP &Val, const SDLoc &DL, EVT VT)
Definition: SelectionDAG.h:713
DenormalMode getDenormalMode(EVT VT) const
Return the current function's default denormal handling kind for the given floating point type.
SDValue getSplat(EVT VT, const SDLoc &DL, SDValue Op)
Returns a node representing a splat of one value into all lanes of the provided vector type.
Definition: SelectionDAG.h:878
std::pair< SDValue, SDValue > SplitScalar(const SDValue &N, const SDLoc &DL, const EVT &LoVT, const EVT &HiVT)
Split the scalar node with EXTRACT_ELEMENT using the provided VTs and return the low/high part.
static unsigned getOpcode_EXTEND(unsigned Opcode)
Convert *_EXTEND_VECTOR_INREG to *_EXTEND opcode.
Definition: SelectionDAG.h:908
SDValue matchBinOpReduction(SDNode *Extract, ISD::NodeType &BinOp, ArrayRef< ISD::NodeType > CandidateBinOps, bool AllowPartials=false)
Match a binop + shuffle pyramid that represents a horizontal reduction over the elements of a vector ...
SDValue getVectorShuffle(EVT VT, const SDLoc &dl, SDValue N1, SDValue N2, ArrayRef< int > Mask)
Return an ISD::VECTOR_SHUFFLE node.
LLVM_DUMP_METHOD void dumpDotGraph(const Twine &FileName, const Twine &Title)
Just dump dot graph to a user-provided path and title.
SDValue simplifyShift(SDValue X, SDValue Y)
Try to simplify a shift into 1 of its operands or a constant.
const SDLoc SDValue SDValue MachinePointerInfo unsigned MachineMemOperand::Flags MMOFlags
void transferDbgValues(SDValue From, SDValue To, unsigned OffsetInBits=0, unsigned SizeInBits=0, bool InvalidateDbg=true)
Transfer debug values from one node to another, while optionally generating fragment expressions for ...
SDValue getLogicalNOT(const SDLoc &DL, SDValue Val, EVT VT)
Create a logical NOT operation as (XOR Val, BooleanOne).
SDValue getMaskedScatter(SDVTList VTs, EVT MemVT, const SDLoc &dl, ArrayRef< SDValue > Ops, MachineMemOperand *MMO, ISD::MemIndexType IndexType, bool IsTruncating=false)
bool LegalizeTypes()
This transforms the SelectionDAG into a SelectionDAG that only uses types natively supported by the t...
This SDNode is used to implement the code generator support for the llvm IR shufflevector instruction...
A SetVector that performs no allocations if smaller than a certain size.
Definition: SetVector.h:312
bool empty() const
Definition: SmallVector.h:94
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:577
typename SuperClass::iterator iterator
Definition: SmallVector.h:581
void push_back(const T &Elt)
Definition: SmallVector.h:416
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:111
Provides information about what library functions are available for the current target.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:78
TargetSubtargetInfo - Generic base class for all target subtargets.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:74
Iterator for intrusive lists based on ilist_node.
pointer remove(iterator &IT)
Definition: ilist.h:188
iterator insert(iterator where, pointer New)
Definition: ilist.h:165
An intrusive list with ownership and callbacks specified/controlled by ilist_traits,...
Definition: ilist.h:328
A range adaptor for a pair of iterators.
This file defines classes to implement an intrusive doubly linked list class (i.e.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
Level
Code generation optimization level.
Definition: CodeGen.h:57
NodeType
ISD::NodeType enum - This enum defines the target-independent operators for a SelectionDAG.
Definition: ISDOpcodes.h:40
@ SETCC
SetCC operator - This evaluates to a true value iff the condition is true.
Definition: ISDOpcodes.h:749
@ STRICT_FSETCC
STRICT_FSETCC/STRICT_FSETCCS - Constrained versions of SETCC, used for floating-point operands only.
Definition: ISDOpcodes.h:475
@ ConstantFP
Definition: ISDOpcodes.h:77
@ ANY_EXTEND
ANY_EXTEND - Used for integer types. The high bits are undefined.
Definition: ISDOpcodes.h:779
@ SIGN_EXTEND_VECTOR_INREG
SIGN_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register sign-extension of the low ...
Definition: ISDOpcodes.h:816
@ SDIVREM
SDIVREM/UDIVREM - Divide two integers and produce both a quotient and remainder result.
Definition: ISDOpcodes.h:255
@ STRICT_FSETCCS
Definition: ISDOpcodes.h:476
@ SIGN_EXTEND
Conversion operators.
Definition: ISDOpcodes.h:773
@ SELECT
Select(COND, TRUEVAL, FALSEVAL).
Definition: ISDOpcodes.h:726
@ UNDEF
UNDEF - An undefined node.
Definition: ISDOpcodes.h:211
@ SPLAT_VECTOR
SPLAT_VECTOR(VAL) - Returns a vector with the scalar value VAL duplicated in all lanes.
Definition: ISDOpcodes.h:626
@ CopyFromReg
CopyFromReg - This node indicates that the input value is a virtual or physical register that is defi...
Definition: ISDOpcodes.h:208
@ CopyToReg
CopyToReg - This node has three operands: a chain, a register number to set to this value,...
Definition: ISDOpcodes.h:203
@ ZERO_EXTEND
ZERO_EXTEND - Used for integer types, zeroing the new bits.
Definition: ISDOpcodes.h:776
@ SELECT_CC
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
Definition: ISDOpcodes.h:741
@ ANY_EXTEND_VECTOR_INREG
ANY_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register any-extension of the low la...
Definition: ISDOpcodes.h:805
@ GLOBAL_OFFSET_TABLE
The address of the GOT.
Definition: ISDOpcodes.h:87
@ VSELECT
Select with a vector condition (op #0) and two vector operands (ops #1 and #2), returning a vector re...
Definition: ISDOpcodes.h:735
@ ZERO_EXTEND_VECTOR_INREG
ZERO_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register zero-extension of the low ...
Definition: ISDOpcodes.h:827
@ BlockAddress
Definition: ISDOpcodes.h:84
@ CALLSEQ_START
CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of a call sequence,...
Definition: ISDOpcodes.h:1083
@ BUILD_VECTOR
BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a fixed-width vector with the specified,...
Definition: ISDOpcodes.h:514
MemIndexType
MemIndexType enum - This enum defines how to interpret MGATHER/SCATTER's index parameter when calcula...
Definition: ISDOpcodes.h:1409
MemIndexedMode
MemIndexedMode enum - This enum defines the load / store indexed addressing modes.
Definition: ISDOpcodes.h:1396
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out,...
Definition: ISDOpcodes.h:1447
LoadExtType
LoadExtType enum - This enum defines the three variants of LOADEXT (load with extension).
Definition: ISDOpcodes.h:1427
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:440
AlignedCharArrayUnion< AtomicSDNode, TargetIndexSDNode, BlockAddressSDNode, GlobalAddressSDNode, PseudoProbeSDNode > LargestSDNode
A representation of the largest SDNode, for use in sizeof().
GenericSSAContext< Function > SSAContext
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
void checkForCycles(const SelectionDAG *DAG, bool force=false)
BumpPtrAllocatorImpl BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition: Allocator.h:375
GenericUniformityInfo< SSAContext > UniformityInfo
CombineLevel
Definition: DAGCombine.h:15
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1946
Definition: BitVector.h:858
#define N
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Definition: Metadata.h:651
static const fltSemantics & IEEEsingle() LLVM_READNONE
Definition: APFloat.cpp:244
static const fltSemantics & PPCDoubleDouble() LLVM_READNONE
Definition: APFloat.cpp:247
static const fltSemantics & x87DoubleExtended() LLVM_READNONE
Definition: APFloat.cpp:257
static const fltSemantics & IEEEquad() LLVM_READNONE
Definition: APFloat.cpp:246
static const fltSemantics & IEEEdouble() LLVM_READNONE
Definition: APFloat.cpp:245
static const fltSemantics & IEEEhalf() LLVM_READNONE
Definition: APFloat.cpp:242
static const fltSemantics & BFloat() LLVM_READNONE
Definition: APFloat.cpp:243
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
DefaultFoldingSetTrait - This class provides default implementations for FoldingSetTrait implementati...
Definition: FoldingSet.h:231
Represent subnormal handling kind for floating point instruction inputs and outputs.
Extended Value Type.
Definition: ValueTypes.h:34
uint64_t getScalarSizeInBits() const
Definition: ValueTypes.h:363
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Definition: ValueTypes.h:299
bool isVector() const
Return true if this is a vector value type.
Definition: ValueTypes.h:160
EVT getScalarType() const
If this is a vector type, return the element type, otherwise return this.
Definition: ValueTypes.h:306
bool isScalableVector() const
Return true if this is a vector type where the runtime length is machine dependent.
Definition: ValueTypes.h:166
EVT getVectorElementType() const
Given a vector type, return the type of each element.
Definition: ValueTypes.h:311
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
Definition: ValueTypes.h:319
bool bitsLE(EVT VT) const
Return true if this has no more bits than VT.
Definition: ValueTypes.h:291
bool isInteger() const
Return true if this is an integer or a vector integer type.
Definition: ValueTypes.h:144
static bool Equals(const SDVTListNode &X, const FoldingSetNodeID &ID, unsigned IDHash, FoldingSetNodeID &TempID)
Definition: SelectionDAG.h:130
static unsigned ComputeHash(const SDVTListNode &X, FoldingSetNodeID &TempID)
Definition: SelectionDAG.h:137
static void Profile(const SDVTListNode &X, FoldingSetNodeID &ID)
Definition: SelectionDAG.h:126
FoldingSetTrait - This trait class is used to define behavior of how to "profile" (in the FoldingSet ...
Definition: FoldingSet.h:261
static nodes_iterator nodes_begin(SelectionDAG *G)
static nodes_iterator nodes_end(SelectionDAG *G)
This class contains a discriminated union of information about pointers in memory operands,...
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117
These are IR-level optimization flags that may be propagated to SDNodes.
This represents a list of ValueType's that has been intern'd by a SelectionDAG.
DAGNodeDeletedListener(SelectionDAG &DAG, std::function< void(SDNode *, SDNode *)> Callback)
Definition: SelectionDAG.h:336
void NodeDeleted(SDNode *N, SDNode *E) override
The node N that was deleted and, if E is not null, an equivalent node E that replaced it.
Definition: SelectionDAG.h:340
std::function< void(SDNode *, SDNode *)> Callback
Definition: SelectionDAG.h:334
std::function< void(SDNode *)> Callback
Definition: SelectionDAG.h:347
void NodeInserted(SDNode *N) override
The node N that was inserted.
Definition: SelectionDAG.h:353
DAGNodeInsertedListener(SelectionDAG &DAG, std::function< void(SDNode *)> Callback)
Definition: SelectionDAG.h:349
Clients of various APIs that cause global effects on the DAG can optionally implement this interface.
Definition: SelectionDAG.h:307
DAGUpdateListener *const Next
Definition: SelectionDAG.h:308
virtual void NodeDeleted(SDNode *N, SDNode *E)
The node N that was deleted and, if E is not null, an equivalent node E that replaced it.
virtual void NodeInserted(SDNode *N)
The node N that was inserted.
virtual void NodeUpdated(SDNode *N)
The node N that was updated.
static void deleteNode(SDNode *)
Definition: SelectionDAG.h:143
Use delete by default for iplist and ilist.
Definition: ilist.h:41