Bug Summary

File:include/llvm/CodeGen/SelectionDAGNodes.h
Warning:line 1116, column 10
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name X86SelectionDAGInfo.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-8/lib/clang/8.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-8~svn350071/build-llvm/lib/Target/X86 -I /build/llvm-toolchain-snapshot-8~svn350071/lib/Target/X86 -I /build/llvm-toolchain-snapshot-8~svn350071/build-llvm/include -I /build/llvm-toolchain-snapshot-8~svn350071/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/backward -internal-isystem /usr/include/clang/8.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-8/lib/clang/8.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-8~svn350071/build-llvm/lib/Target/X86 -fdebug-prefix-map=/build/llvm-toolchain-snapshot-8~svn350071=. -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -stack-protector 2 -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-12-27-042839-1215-1 -x c++ /build/llvm-toolchain-snapshot-8~svn350071/lib/Target/X86/X86SelectionDAGInfo.cpp -faddrsig

/build/llvm-toolchain-snapshot-8~svn350071/lib/Target/X86/X86SelectionDAGInfo.cpp

1//===-- X86SelectionDAGInfo.cpp - X86 SelectionDAG Info -------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the X86SelectionDAGInfo class.
11//
12//===----------------------------------------------------------------------===//
13
14#include "X86SelectionDAGInfo.h"
15#include "X86ISelLowering.h"
16#include "X86InstrInfo.h"
17#include "X86RegisterInfo.h"
18#include "X86Subtarget.h"
19#include "llvm/CodeGen/SelectionDAG.h"
20#include "llvm/CodeGen/TargetLowering.h"
21#include "llvm/IR/DerivedTypes.h"
22
23using namespace llvm;
24
25#define DEBUG_TYPE"x86-selectiondag-info" "x86-selectiondag-info"
26
27bool X86SelectionDAGInfo::isBaseRegConflictPossible(
28 SelectionDAG &DAG, ArrayRef<MCPhysReg> ClobberSet) const {
29 // We cannot use TRI->hasBasePointer() until *after* we select all basic
30 // blocks. Legalization may introduce new stack temporaries with large
31 // alignment requirements. Fall back to generic code if there are any
32 // dynamic stack adjustments (hopefully rare) and the base pointer would
33 // conflict if we had to use it.
34 MachineFrameInfo &MFI = DAG.getMachineFunction().getFrameInfo();
35 if (!MFI.hasVarSizedObjects() && !MFI.hasOpaqueSPAdjustment())
36 return false;
37
38 const X86RegisterInfo *TRI = static_cast<const X86RegisterInfo *>(
39 DAG.getSubtarget().getRegisterInfo());
40 unsigned BaseReg = TRI->getBaseRegister();
41 for (unsigned R : ClobberSet)
42 if (BaseReg == R)
43 return true;
44 return false;
45}
46
47namespace {
48
49// Represents a cover of a buffer of Size bytes with Count() blocks of type AVT
50// (of size UBytes() bytes), as well as how many bytes remain (BytesLeft() is
51// always smaller than the block size).
52struct RepMovsRepeats {
53 RepMovsRepeats(uint64_t Size) : Size(Size) {}
54
55 uint64_t Count() const { return Size / UBytes(); }
56 uint64_t BytesLeft() const { return Size % UBytes(); }
57 uint64_t UBytes() const { return AVT.getSizeInBits() / 8; }
58
59 const uint64_t Size;
60 MVT AVT = MVT::i8;
61};
62
63} // namespace
64
65SDValue X86SelectionDAGInfo::EmitTargetCodeForMemset(
66 SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Dst, SDValue Val,
67 SDValue Size, unsigned Align, bool isVolatile,
68 MachinePointerInfo DstPtrInfo) const {
69 ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size);
70 const X86Subtarget &Subtarget =
71 DAG.getMachineFunction().getSubtarget<X86Subtarget>();
72
73#ifndef NDEBUG
74 // If the base register might conflict with our physical registers, bail out.
75 const MCPhysReg ClobberSet[] = {X86::RCX, X86::RAX, X86::RDI,
76 X86::ECX, X86::EAX, X86::EDI};
77 assert(!isBaseRegConflictPossible(DAG, ClobberSet))((!isBaseRegConflictPossible(DAG, ClobberSet)) ? static_cast<
void> (0) : __assert_fail ("!isBaseRegConflictPossible(DAG, ClobberSet)"
, "/build/llvm-toolchain-snapshot-8~svn350071/lib/Target/X86/X86SelectionDAGInfo.cpp"
, 77, __PRETTY_FUNCTION__))
;
1
Assuming the condition is true
2
'?' condition is true
78#endif
79
80 // If to a segment-relative address space, use the default lowering.
81 if (DstPtrInfo.getAddrSpace() >= 256)
3
Assuming the condition is false
4
Taking false branch
82 return SDValue();
83
84 // If not DWORD aligned or size is more than the threshold, call the library.
85 // The libc version is likely to be faster for these cases. It can use the
86 // address value and run time information about the CPU.
87 if ((Align & 3) != 0 || !ConstantSize ||
5
Assuming the condition is false
7
Taking false branch
88 ConstantSize->getZExtValue() > Subtarget.getMaxInlineSizeThreshold()) {
6
Assuming the condition is false
89 // Check to see if there is a specialized entry-point for memory zeroing.
90 ConstantSDNode *ValC = dyn_cast<ConstantSDNode>(Val);
91
92 if (const char *bzeroName = (ValC && ValC->isNullValue())
93 ? DAG.getTargetLoweringInfo().getLibcallName(RTLIB::BZERO)
94 : nullptr) {
95 const TargetLowering &TLI = DAG.getTargetLoweringInfo();
96 EVT IntPtr = TLI.getPointerTy(DAG.getDataLayout());
97 Type *IntPtrTy = DAG.getDataLayout().getIntPtrType(*DAG.getContext());
98 TargetLowering::ArgListTy Args;
99 TargetLowering::ArgListEntry Entry;
100 Entry.Node = Dst;
101 Entry.Ty = IntPtrTy;
102 Args.push_back(Entry);
103 Entry.Node = Size;
104 Args.push_back(Entry);
105
106 TargetLowering::CallLoweringInfo CLI(DAG);
107 CLI.setDebugLoc(dl)
108 .setChain(Chain)
109 .setLibCallee(CallingConv::C, Type::getVoidTy(*DAG.getContext()),
110 DAG.getExternalSymbol(bzeroName, IntPtr),
111 std::move(Args))
112 .setDiscardResult();
113
114 std::pair<SDValue,SDValue> CallResult = TLI.LowerCallTo(CLI);
115 return CallResult.second;
116 }
117
118 // Otherwise have the target-independent code call memset.
119 return SDValue();
120 }
121
122 uint64_t SizeVal = ConstantSize->getZExtValue();
123 SDValue InFlag;
124 EVT AVT;
125 SDValue Count;
126 ConstantSDNode *ValC = dyn_cast<ConstantSDNode>(Val);
127 unsigned BytesLeft = 0;
128 if (ValC) {
8
Taking true branch
129 unsigned ValReg;
130 uint64_t Val = ValC->getZExtValue() & 255;
131
132 // If the value is a constant, then we can potentially use larger sets.
133 switch (Align & 3) {
9
Control jumps to 'case 0:' at line 139
134 case 2: // WORD aligned
135 AVT = MVT::i16;
136 ValReg = X86::AX;
137 Val = (Val << 8) | Val;
138 break;
139 case 0: // DWORD aligned
140 AVT = MVT::i32;
141 ValReg = X86::EAX;
142 Val = (Val << 8) | Val;
143 Val = (Val << 16) | Val;
144 if (Subtarget.is64Bit() && ((Align & 0x7) == 0)) { // QWORD aligned
10
Assuming the condition is false
145 AVT = MVT::i64;
146 ValReg = X86::RAX;
147 Val = (Val << 32) | Val;
148 }
149 break;
11
Execution continues on line 157
150 default: // Byte aligned
151 AVT = MVT::i8;
152 ValReg = X86::AL;
153 Count = DAG.getIntPtrConstant(SizeVal, dl);
154 break;
155 }
156
157 if (AVT.bitsGT(MVT::i8)) {
12
Taking false branch
158 unsigned UBytes = AVT.getSizeInBits() / 8;
159 Count = DAG.getIntPtrConstant(SizeVal / UBytes, dl);
160 BytesLeft = SizeVal % UBytes;
161 }
162
163 Chain = DAG.getCopyToReg(Chain, dl, ValReg, DAG.getConstant(Val, dl, AVT),
164 InFlag);
165 InFlag = Chain.getValue(1);
166 } else {
167 AVT = MVT::i8;
168 Count = DAG.getIntPtrConstant(SizeVal, dl);
169 Chain = DAG.getCopyToReg(Chain, dl, X86::AL, Val, InFlag);
170 InFlag = Chain.getValue(1);
171 }
172
173 bool Use64BitRegs = Subtarget.isTarget64BitLP64();
174 Chain = DAG.getCopyToReg(Chain, dl, Use64BitRegs ? X86::RCX : X86::ECX,
13
'?' condition is false
15
Calling 'SelectionDAG::getCopyToReg'
175 Count, InFlag);
14
Null pointer value stored to 'N.Node'
176 InFlag = Chain.getValue(1);
177 Chain = DAG.getCopyToReg(Chain, dl, Use64BitRegs ? X86::RDI : X86::EDI,
178 Dst, InFlag);
179 InFlag = Chain.getValue(1);
180
181 SDVTList Tys = DAG.getVTList(MVT::Other, MVT::Glue);
182 SDValue Ops[] = { Chain, DAG.getValueType(AVT), InFlag };
183 Chain = DAG.getNode(X86ISD::REP_STOS, dl, Tys, Ops);
184
185 if (BytesLeft) {
186 // Handle the last 1 - 7 bytes.
187 unsigned Offset = SizeVal - BytesLeft;
188 EVT AddrVT = Dst.getValueType();
189 EVT SizeVT = Size.getValueType();
190
191 Chain = DAG.getMemset(Chain, dl,
192 DAG.getNode(ISD::ADD, dl, AddrVT, Dst,
193 DAG.getConstant(Offset, dl, AddrVT)),
194 Val,
195 DAG.getConstant(BytesLeft, dl, SizeVT),
196 Align, isVolatile, false,
197 DstPtrInfo.getWithOffset(Offset));
198 }
199
200 // TODO: Use a Tokenfactor, as in memcpy, instead of a single chain.
201 return Chain;
202}
203
204SDValue X86SelectionDAGInfo::EmitTargetCodeForMemcpy(
205 SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Dst, SDValue Src,
206 SDValue Size, unsigned Align, bool isVolatile, bool AlwaysInline,
207 MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const {
208 // This requires the copy size to be a constant, preferably
209 // within a subtarget-specific limit.
210 ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size);
211 const X86Subtarget &Subtarget =
212 DAG.getMachineFunction().getSubtarget<X86Subtarget>();
213 if (!ConstantSize)
214 return SDValue();
215 RepMovsRepeats Repeats(ConstantSize->getZExtValue());
216 if (!AlwaysInline && Repeats.Size > Subtarget.getMaxInlineSizeThreshold())
217 return SDValue();
218
219 /// If not DWORD aligned, it is more efficient to call the library. However
220 /// if calling the library is not allowed (AlwaysInline), then soldier on as
221 /// the code generated here is better than the long load-store sequence we
222 /// would otherwise get.
223 if (!AlwaysInline && (Align & 3) != 0)
224 return SDValue();
225
226 // If to a segment-relative address space, use the default lowering.
227 if (DstPtrInfo.getAddrSpace() >= 256 ||
228 SrcPtrInfo.getAddrSpace() >= 256)
229 return SDValue();
230
231 // If the base register might conflict with our physical registers, bail out.
232 const MCPhysReg ClobberSet[] = {X86::RCX, X86::RSI, X86::RDI,
233 X86::ECX, X86::ESI, X86::EDI};
234 if (isBaseRegConflictPossible(DAG, ClobberSet))
235 return SDValue();
236
237 // If the target has enhanced REPMOVSB, then it's at least as fast to use
238 // REP MOVSB instead of REP MOVS{W,D,Q}, and it avoids having to handle
239 // BytesLeft.
240 if (!Subtarget.hasERMSB() && !(Align & 1)) {
241 if (Align & 2)
242 // WORD aligned
243 Repeats.AVT = MVT::i16;
244 else if (Align & 4)
245 // DWORD aligned
246 Repeats.AVT = MVT::i32;
247 else
248 // QWORD aligned
249 Repeats.AVT = Subtarget.is64Bit() ? MVT::i64 : MVT::i32;
250
251 if (Repeats.BytesLeft() > 0 &&
252 DAG.getMachineFunction().getFunction().optForMinSize()) {
253 // When aggressively optimizing for size, avoid generating the code to
254 // handle BytesLeft.
255 Repeats.AVT = MVT::i8;
256 }
257 }
258
259 bool Use64BitRegs = Subtarget.isTarget64BitLP64();
260 SDValue InFlag;
261 Chain = DAG.getCopyToReg(Chain, dl, Use64BitRegs ? X86::RCX : X86::ECX,
262 DAG.getIntPtrConstant(Repeats.Count(), dl), InFlag);
263 InFlag = Chain.getValue(1);
264 Chain = DAG.getCopyToReg(Chain, dl, Use64BitRegs ? X86::RDI : X86::EDI,
265 Dst, InFlag);
266 InFlag = Chain.getValue(1);
267 Chain = DAG.getCopyToReg(Chain, dl, Use64BitRegs ? X86::RSI : X86::ESI,
268 Src, InFlag);
269 InFlag = Chain.getValue(1);
270
271 SDVTList Tys = DAG.getVTList(MVT::Other, MVT::Glue);
272 SDValue Ops[] = { Chain, DAG.getValueType(Repeats.AVT), InFlag };
273 SDValue RepMovs = DAG.getNode(X86ISD::REP_MOVS, dl, Tys, Ops);
274
275 SmallVector<SDValue, 4> Results;
276 Results.push_back(RepMovs);
277 if (Repeats.BytesLeft()) {
278 // Handle the last 1 - 7 bytes.
279 unsigned Offset = Repeats.Size - Repeats.BytesLeft();
280 EVT DstVT = Dst.getValueType();
281 EVT SrcVT = Src.getValueType();
282 EVT SizeVT = Size.getValueType();
283 Results.push_back(DAG.getMemcpy(Chain, dl,
284 DAG.getNode(ISD::ADD, dl, DstVT, Dst,
285 DAG.getConstant(Offset, dl,
286 DstVT)),
287 DAG.getNode(ISD::ADD, dl, SrcVT, Src,
288 DAG.getConstant(Offset, dl,
289 SrcVT)),
290 DAG.getConstant(Repeats.BytesLeft(), dl,
291 SizeVT),
292 Align, isVolatile, AlwaysInline, false,
293 DstPtrInfo.getWithOffset(Offset),
294 SrcPtrInfo.getWithOffset(Offset)));
295 }
296
297 return DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Results);
298}

/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAG.h

1//===- llvm/CodeGen/SelectionDAG.h - InstSelection DAG ----------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file declares the SelectionDAG class, and transitively defines the
11// SDNode class and subclasses.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CODEGEN_SELECTIONDAG_H
16#define LLVM_CODEGEN_SELECTIONDAG_H
17
18#include "llvm/ADT/APFloat.h"
19#include "llvm/ADT/APInt.h"
20#include "llvm/ADT/ArrayRef.h"
21#include "llvm/ADT/DenseMap.h"
22#include "llvm/ADT/DenseSet.h"
23#include "llvm/ADT/FoldingSet.h"
24#include "llvm/ADT/SetVector.h"
25#include "llvm/ADT/SmallVector.h"
26#include "llvm/ADT/StringMap.h"
27#include "llvm/ADT/ilist.h"
28#include "llvm/ADT/iterator.h"
29#include "llvm/ADT/iterator_range.h"
30#include "llvm/Analysis/AliasAnalysis.h"
31#include "llvm/Analysis/LegacyDivergenceAnalysis.h"
32#include "llvm/CodeGen/DAGCombine.h"
33#include "llvm/CodeGen/FunctionLoweringInfo.h"
34#include "llvm/CodeGen/ISDOpcodes.h"
35#include "llvm/CodeGen/MachineFunction.h"
36#include "llvm/CodeGen/MachineMemOperand.h"
37#include "llvm/CodeGen/SelectionDAGNodes.h"
38#include "llvm/CodeGen/ValueTypes.h"
39#include "llvm/IR/DebugLoc.h"
40#include "llvm/IR/Instructions.h"
41#include "llvm/IR/Metadata.h"
42#include "llvm/Support/Allocator.h"
43#include "llvm/Support/ArrayRecycler.h"
44#include "llvm/Support/AtomicOrdering.h"
45#include "llvm/Support/Casting.h"
46#include "llvm/Support/CodeGen.h"
47#include "llvm/Support/ErrorHandling.h"
48#include "llvm/Support/MachineValueType.h"
49#include "llvm/Support/RecyclingAllocator.h"
50#include <algorithm>
51#include <cassert>
52#include <cstdint>
53#include <functional>
54#include <map>
55#include <string>
56#include <tuple>
57#include <utility>
58#include <vector>
59
60namespace llvm {
61
62class BlockAddress;
63class Constant;
64class ConstantFP;
65class ConstantInt;
66class DataLayout;
67struct fltSemantics;
68class GlobalValue;
69struct KnownBits;
70class LLVMContext;
71class MachineBasicBlock;
72class MachineConstantPoolValue;
73class MCSymbol;
74class OptimizationRemarkEmitter;
75class SDDbgValue;
76class SDDbgLabel;
77class SelectionDAG;
78class SelectionDAGTargetInfo;
79class TargetLibraryInfo;
80class TargetLowering;
81class TargetMachine;
82class TargetSubtargetInfo;
83class Value;
84
85class SDVTListNode : public FoldingSetNode {
86 friend struct FoldingSetTrait<SDVTListNode>;
87
88 /// A reference to an Interned FoldingSetNodeID for this node.
89 /// The Allocator in SelectionDAG holds the data.
90 /// SDVTList contains all types which are frequently accessed in SelectionDAG.
91 /// The size of this list is not expected to be big so it won't introduce
92 /// a memory penalty.
93 FoldingSetNodeIDRef FastID;
94 const EVT *VTs;
95 unsigned int NumVTs;
96 /// The hash value for SDVTList is fixed, so cache it to avoid
97 /// hash calculation.
98 unsigned HashValue;
99
100public:
101 SDVTListNode(const FoldingSetNodeIDRef ID, const EVT *VT, unsigned int Num) :
102 FastID(ID), VTs(VT), NumVTs(Num) {
103 HashValue = ID.ComputeHash();
104 }
105
106 SDVTList getSDVTList() {
107 SDVTList result = {VTs, NumVTs};
108 return result;
109 }
110};
111
112/// Specialize FoldingSetTrait for SDVTListNode
113/// to avoid computing temp FoldingSetNodeID and hash value.
114template<> struct FoldingSetTrait<SDVTListNode> : DefaultFoldingSetTrait<SDVTListNode> {
115 static void Profile(const SDVTListNode &X, FoldingSetNodeID& ID) {
116 ID = X.FastID;
117 }
118
119 static bool Equals(const SDVTListNode &X, const FoldingSetNodeID &ID,
120 unsigned IDHash, FoldingSetNodeID &TempID) {
121 if (X.HashValue != IDHash)
122 return false;
123 return ID == X.FastID;
124 }
125
126 static unsigned ComputeHash(const SDVTListNode &X, FoldingSetNodeID &TempID) {
127 return X.HashValue;
128 }
129};
130
131template <> struct ilist_alloc_traits<SDNode> {
132 static void deleteNode(SDNode *) {
133 llvm_unreachable("ilist_traits<SDNode> shouldn't see a deleteNode call!")::llvm::llvm_unreachable_internal("ilist_traits<SDNode> shouldn't see a deleteNode call!"
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAG.h"
, 133)
;
134 }
135};
136
137/// Keeps track of dbg_value information through SDISel. We do
138/// not build SDNodes for these so as not to perturb the generated code;
139/// instead the info is kept off to the side in this structure. Each SDNode may
140/// have one or more associated dbg_value entries. This information is kept in
141/// DbgValMap.
142/// Byval parameters are handled separately because they don't use alloca's,
143/// which busts the normal mechanism. There is good reason for handling all
144/// parameters separately: they may not have code generated for them, they
145/// should always go at the beginning of the function regardless of other code
146/// motion, and debug info for them is potentially useful even if the parameter
147/// is unused. Right now only byval parameters are handled separately.
148class SDDbgInfo {
149 BumpPtrAllocator Alloc;
150 SmallVector<SDDbgValue*, 32> DbgValues;
151 SmallVector<SDDbgValue*, 32> ByvalParmDbgValues;
152 SmallVector<SDDbgLabel*, 4> DbgLabels;
153 using DbgValMapType = DenseMap<const SDNode *, SmallVector<SDDbgValue *, 2>>;
154 DbgValMapType DbgValMap;
155
156public:
157 SDDbgInfo() = default;
158 SDDbgInfo(const SDDbgInfo &) = delete;
159 SDDbgInfo &operator=(const SDDbgInfo &) = delete;
160
161 void add(SDDbgValue *V, const SDNode *Node, bool isParameter) {
162 if (isParameter) {
163 ByvalParmDbgValues.push_back(V);
164 } else DbgValues.push_back(V);
165 if (Node)
166 DbgValMap[Node].push_back(V);
167 }
168
169 void add(SDDbgLabel *L) {
170 DbgLabels.push_back(L);
171 }
172
173 /// Invalidate all DbgValues attached to the node and remove
174 /// it from the Node-to-DbgValues map.
175 void erase(const SDNode *Node);
176
177 void clear() {
178 DbgValMap.clear();
179 DbgValues.clear();
180 ByvalParmDbgValues.clear();
181 DbgLabels.clear();
182 Alloc.Reset();
183 }
184
185 BumpPtrAllocator &getAlloc() { return Alloc; }
186
187 bool empty() const {
188 return DbgValues.empty() && ByvalParmDbgValues.empty() && DbgLabels.empty();
189 }
190
191 ArrayRef<SDDbgValue*> getSDDbgValues(const SDNode *Node) const {
192 auto I = DbgValMap.find(Node);
193 if (I != DbgValMap.end())
194 return I->second;
195 return ArrayRef<SDDbgValue*>();
196 }
197
198 using DbgIterator = SmallVectorImpl<SDDbgValue*>::iterator;
199 using DbgLabelIterator = SmallVectorImpl<SDDbgLabel*>::iterator;
200
201 DbgIterator DbgBegin() { return DbgValues.begin(); }
202 DbgIterator DbgEnd() { return DbgValues.end(); }
203 DbgIterator ByvalParmDbgBegin() { return ByvalParmDbgValues.begin(); }
204 DbgIterator ByvalParmDbgEnd() { return ByvalParmDbgValues.end(); }
205 DbgLabelIterator DbgLabelBegin() { return DbgLabels.begin(); }
206 DbgLabelIterator DbgLabelEnd() { return DbgLabels.end(); }
207};
208
209void checkForCycles(const SelectionDAG *DAG, bool force = false);
210
211/// This is used to represent a portion of an LLVM function in a low-level
212/// Data Dependence DAG representation suitable for instruction selection.
213/// This DAG is constructed as the first step of instruction selection in order
214/// to allow implementation of machine specific optimizations
215/// and code simplifications.
216///
217/// The representation used by the SelectionDAG is a target-independent
218/// representation, which has some similarities to the GCC RTL representation,
219/// but is significantly more simple, powerful, and is a graph form instead of a
220/// linear form.
221///
222class SelectionDAG {
223 const TargetMachine &TM;
224 const SelectionDAGTargetInfo *TSI = nullptr;
225 const TargetLowering *TLI = nullptr;
226 const TargetLibraryInfo *LibInfo = nullptr;
227 MachineFunction *MF;
228 Pass *SDAGISelPass = nullptr;
229 LLVMContext *Context;
230 CodeGenOpt::Level OptLevel;
231
232 LegacyDivergenceAnalysis * DA = nullptr;
233 FunctionLoweringInfo * FLI = nullptr;
234
235 /// The function-level optimization remark emitter. Used to emit remarks
236 /// whenever manipulating the DAG.
237 OptimizationRemarkEmitter *ORE;
238
239 /// The starting token.
240 SDNode EntryNode;
241
242 /// The root of the entire DAG.
243 SDValue Root;
244
245 /// A linked list of nodes in the current DAG.
246 ilist<SDNode> AllNodes;
247
248 /// The AllocatorType for allocating SDNodes. We use
249 /// pool allocation with recycling.
250 using NodeAllocatorType = RecyclingAllocator<BumpPtrAllocator, SDNode,
251 sizeof(LargestSDNode),
252 alignof(MostAlignedSDNode)>;
253
254 /// Pool allocation for nodes.
255 NodeAllocatorType NodeAllocator;
256
257 /// This structure is used to memoize nodes, automatically performing
258 /// CSE with existing nodes when a duplicate is requested.
259 FoldingSet<SDNode> CSEMap;
260
261 /// Pool allocation for machine-opcode SDNode operands.
262 BumpPtrAllocator OperandAllocator;
263 ArrayRecycler<SDUse> OperandRecycler;
264
265 /// Pool allocation for misc. objects that are created once per SelectionDAG.
266 BumpPtrAllocator Allocator;
267
268 /// Tracks dbg_value and dbg_label information through SDISel.
269 SDDbgInfo *DbgInfo;
270
271 uint16_t NextPersistentId = 0;
272
273public:
274 /// Clients of various APIs that cause global effects on
275 /// the DAG can optionally implement this interface. This allows the clients
276 /// to handle the various sorts of updates that happen.
277 ///
278 /// A DAGUpdateListener automatically registers itself with DAG when it is
279 /// constructed, and removes itself when destroyed in RAII fashion.
280 struct DAGUpdateListener {
281 DAGUpdateListener *const Next;
282 SelectionDAG &DAG;
283
284 explicit DAGUpdateListener(SelectionDAG &D)
285 : Next(D.UpdateListeners), DAG(D) {
286 DAG.UpdateListeners = this;
287 }
288
289 virtual ~DAGUpdateListener() {
290 assert(DAG.UpdateListeners == this &&((DAG.UpdateListeners == this && "DAGUpdateListeners must be destroyed in LIFO order"
) ? static_cast<void> (0) : __assert_fail ("DAG.UpdateListeners == this && \"DAGUpdateListeners must be destroyed in LIFO order\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAG.h"
, 291, __PRETTY_FUNCTION__))
291 "DAGUpdateListeners must be destroyed in LIFO order")((DAG.UpdateListeners == this && "DAGUpdateListeners must be destroyed in LIFO order"
) ? static_cast<void> (0) : __assert_fail ("DAG.UpdateListeners == this && \"DAGUpdateListeners must be destroyed in LIFO order\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAG.h"
, 291, __PRETTY_FUNCTION__))
;
292 DAG.UpdateListeners = Next;
293 }
294
295 /// The node N that was deleted and, if E is not null, an
296 /// equivalent node E that replaced it.
297 virtual void NodeDeleted(SDNode *N, SDNode *E);
298
299 /// The node N that was updated.
300 virtual void NodeUpdated(SDNode *N);
301 };
302
303 struct DAGNodeDeletedListener : public DAGUpdateListener {
304 std::function<void(SDNode *, SDNode *)> Callback;
305
306 DAGNodeDeletedListener(SelectionDAG &DAG,
307 std::function<void(SDNode *, SDNode *)> Callback)
308 : DAGUpdateListener(DAG), Callback(std::move(Callback)) {}
309
310 void NodeDeleted(SDNode *N, SDNode *E) override { Callback(N, E); }
311 };
312
313 /// When true, additional steps are taken to
314 /// ensure that getConstant() and similar functions return DAG nodes that
315 /// have legal types. This is important after type legalization since
316 /// any illegally typed nodes generated after this point will not experience
317 /// type legalization.
318 bool NewNodesMustHaveLegalTypes = false;
319
320private:
321 /// DAGUpdateListener is a friend so it can manipulate the listener stack.
322 friend struct DAGUpdateListener;
323
324 /// Linked list of registered DAGUpdateListener instances.
325 /// This stack is maintained by DAGUpdateListener RAII.
326 DAGUpdateListener *UpdateListeners = nullptr;
327
328 /// Implementation of setSubgraphColor.
329 /// Return whether we had to truncate the search.
330 bool setSubgraphColorHelper(SDNode *N, const char *Color,
331 DenseSet<SDNode *> &visited,
332 int level, bool &printed);
333
334 template <typename SDNodeT, typename... ArgTypes>
335 SDNodeT *newSDNode(ArgTypes &&... Args) {
336 return new (NodeAllocator.template Allocate<SDNodeT>())
337 SDNodeT(std::forward<ArgTypes>(Args)...);
338 }
339
340 /// Build a synthetic SDNodeT with the given args and extract its subclass
341 /// data as an integer (e.g. for use in a folding set).
342 ///
343 /// The args to this function are the same as the args to SDNodeT's
344 /// constructor, except the second arg (assumed to be a const DebugLoc&) is
345 /// omitted.
346 template <typename SDNodeT, typename... ArgTypes>
347 static uint16_t getSyntheticNodeSubclassData(unsigned IROrder,
348 ArgTypes &&... Args) {
349 // The compiler can reduce this expression to a constant iff we pass an
350 // empty DebugLoc. Thankfully, the debug location doesn't have any bearing
351 // on the subclass data.
352 return SDNodeT(IROrder, DebugLoc(), std::forward<ArgTypes>(Args)...)
353 .getRawSubclassData();
354 }
355
356 template <typename SDNodeTy>
357 static uint16_t getSyntheticNodeSubclassData(unsigned Opc, unsigned Order,
358 SDVTList VTs, EVT MemoryVT,
359 MachineMemOperand *MMO) {
360 return SDNodeTy(Opc, Order, DebugLoc(), VTs, MemoryVT, MMO)
361 .getRawSubclassData();
362 }
363
364 void createOperands(SDNode *Node, ArrayRef<SDValue> Vals);
365
366 void removeOperands(SDNode *Node) {
367 if (!Node->OperandList)
368 return;
369 OperandRecycler.deallocate(
370 ArrayRecycler<SDUse>::Capacity::get(Node->NumOperands),
371 Node->OperandList);
372 Node->NumOperands = 0;
373 Node->OperandList = nullptr;
374 }
375 void CreateTopologicalOrder(std::vector<SDNode*>& Order);
376public:
377 explicit SelectionDAG(const TargetMachine &TM, CodeGenOpt::Level);
378 SelectionDAG(const SelectionDAG &) = delete;
379 SelectionDAG &operator=(const SelectionDAG &) = delete;
380 ~SelectionDAG();
381
382 /// Prepare this SelectionDAG to process code in the given MachineFunction.
383 void init(MachineFunction &NewMF, OptimizationRemarkEmitter &NewORE,
384 Pass *PassPtr, const TargetLibraryInfo *LibraryInfo,
385 LegacyDivergenceAnalysis * Divergence);
386
387 void setFunctionLoweringInfo(FunctionLoweringInfo * FuncInfo) {
388 FLI = FuncInfo;
389 }
390
391 /// Clear state and free memory necessary to make this
392 /// SelectionDAG ready to process a new block.
393 void clear();
394
395 MachineFunction &getMachineFunction() const { return *MF; }
396 const Pass *getPass() const { return SDAGISelPass; }
397
398 const DataLayout &getDataLayout() const { return MF->getDataLayout(); }
399 const TargetMachine &getTarget() const { return TM; }
400 const TargetSubtargetInfo &getSubtarget() const { return MF->getSubtarget(); }
401 const TargetLowering &getTargetLoweringInfo() const { return *TLI; }
402 const TargetLibraryInfo &getLibInfo() const { return *LibInfo; }
403 const SelectionDAGTargetInfo &getSelectionDAGInfo() const { return *TSI; }
404 LLVMContext *getContext() const {return Context; }
405 OptimizationRemarkEmitter &getORE() const { return *ORE; }
406
407 /// Pop up a GraphViz/gv window with the DAG rendered using 'dot'.
408 void viewGraph(const std::string &Title);
409 void viewGraph();
410
411#ifndef NDEBUG
412 std::map<const SDNode *, std::string> NodeGraphAttrs;
413#endif
414
415 /// Clear all previously defined node graph attributes.
416 /// Intended to be used from a debugging tool (eg. gdb).
417 void clearGraphAttrs();
418
419 /// Set graph attributes for a node. (eg. "color=red".)
420 void setGraphAttrs(const SDNode *N, const char *Attrs);
421
422 /// Get graph attributes for a node. (eg. "color=red".)
423 /// Used from getNodeAttributes.
424 const std::string getGraphAttrs(const SDNode *N) const;
425
426 /// Convenience for setting node color attribute.
427 void setGraphColor(const SDNode *N, const char *Color);
428
429 /// Convenience for setting subgraph color attribute.
430 void setSubgraphColor(SDNode *N, const char *Color);
431
432 using allnodes_const_iterator = ilist<SDNode>::const_iterator;
433
434 allnodes_const_iterator allnodes_begin() const { return AllNodes.begin(); }
435 allnodes_const_iterator allnodes_end() const { return AllNodes.end(); }
436
437 using allnodes_iterator = ilist<SDNode>::iterator;
438
439 allnodes_iterator allnodes_begin() { return AllNodes.begin(); }
440 allnodes_iterator allnodes_end() { return AllNodes.end(); }
441
442 ilist<SDNode>::size_type allnodes_size() const {
443 return AllNodes.size();
444 }
445
446 iterator_range<allnodes_iterator> allnodes() {
447 return make_range(allnodes_begin(), allnodes_end());
448 }
449 iterator_range<allnodes_const_iterator> allnodes() const {
450 return make_range(allnodes_begin(), allnodes_end());
451 }
452
453 /// Return the root tag of the SelectionDAG.
454 const SDValue &getRoot() const { return Root; }
455
456 /// Return the token chain corresponding to the entry of the function.
457 SDValue getEntryNode() const {
458 return SDValue(const_cast<SDNode *>(&EntryNode), 0);
459 }
460
461 /// Set the current root tag of the SelectionDAG.
462 ///
463 const SDValue &setRoot(SDValue N) {
464 assert((!N.getNode() || N.getValueType() == MVT::Other) &&(((!N.getNode() || N.getValueType() == MVT::Other) &&
"DAG root value is not a chain!") ? static_cast<void> (
0) : __assert_fail ("(!N.getNode() || N.getValueType() == MVT::Other) && \"DAG root value is not a chain!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAG.h"
, 465, __PRETTY_FUNCTION__))
465 "DAG root value is not a chain!")(((!N.getNode() || N.getValueType() == MVT::Other) &&
"DAG root value is not a chain!") ? static_cast<void> (
0) : __assert_fail ("(!N.getNode() || N.getValueType() == MVT::Other) && \"DAG root value is not a chain!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAG.h"
, 465, __PRETTY_FUNCTION__))
;
466 if (N.getNode())
467 checkForCycles(N.getNode(), this);
468 Root = N;
469 if (N.getNode())
470 checkForCycles(this);
471 return Root;
472 }
473
474#ifndef NDEBUG
475 void VerifyDAGDiverence();
476#endif
477
478 /// This iterates over the nodes in the SelectionDAG, folding
479 /// certain types of nodes together, or eliminating superfluous nodes. The
480 /// Level argument controls whether Combine is allowed to produce nodes and
481 /// types that are illegal on the target.
482 void Combine(CombineLevel Level, AliasAnalysis *AA,
483 CodeGenOpt::Level OptLevel);
484
485 /// This transforms the SelectionDAG into a SelectionDAG that
486 /// only uses types natively supported by the target.
487 /// Returns "true" if it made any changes.
488 ///
489 /// Note that this is an involved process that may invalidate pointers into
490 /// the graph.
491 bool LegalizeTypes();
492
493 /// This transforms the SelectionDAG into a SelectionDAG that is
494 /// compatible with the target instruction selector, as indicated by the
495 /// TargetLowering object.
496 ///
497 /// Note that this is an involved process that may invalidate pointers into
498 /// the graph.
499 void Legalize();
500
501 /// Transforms a SelectionDAG node and any operands to it into a node
502 /// that is compatible with the target instruction selector, as indicated by
503 /// the TargetLowering object.
504 ///
505 /// \returns true if \c N is a valid, legal node after calling this.
506 ///
507 /// This essentially runs a single recursive walk of the \c Legalize process
508 /// over the given node (and its operands). This can be used to incrementally
509 /// legalize the DAG. All of the nodes which are directly replaced,
510 /// potentially including N, are added to the output parameter \c
511 /// UpdatedNodes so that the delta to the DAG can be understood by the
512 /// caller.
513 ///
514 /// When this returns false, N has been legalized in a way that make the
515 /// pointer passed in no longer valid. It may have even been deleted from the
516 /// DAG, and so it shouldn't be used further. When this returns true, the
517 /// N passed in is a legal node, and can be immediately processed as such.
518 /// This may still have done some work on the DAG, and will still populate
519 /// UpdatedNodes with any new nodes replacing those originally in the DAG.
520 bool LegalizeOp(SDNode *N, SmallSetVector<SDNode *, 16> &UpdatedNodes);
521
522 /// This transforms the SelectionDAG into a SelectionDAG
523 /// that only uses vector math operations supported by the target. This is
524 /// necessary as a separate step from Legalize because unrolling a vector
525 /// operation can introduce illegal types, which requires running
526 /// LegalizeTypes again.
527 ///
528 /// This returns true if it made any changes; in that case, LegalizeTypes
529 /// is called again before Legalize.
530 ///
531 /// Note that this is an involved process that may invalidate pointers into
532 /// the graph.
533 bool LegalizeVectors();
534
535 /// This method deletes all unreachable nodes in the SelectionDAG.
536 void RemoveDeadNodes();
537
538 /// Remove the specified node from the system. This node must
539 /// have no referrers.
540 void DeleteNode(SDNode *N);
541
542 /// Return an SDVTList that represents the list of values specified.
543 SDVTList getVTList(EVT VT);
544 SDVTList getVTList(EVT VT1, EVT VT2);
545 SDVTList getVTList(EVT VT1, EVT VT2, EVT VT3);
546 SDVTList getVTList(EVT VT1, EVT VT2, EVT VT3, EVT VT4);
547 SDVTList getVTList(ArrayRef<EVT> VTs);
548
549 //===--------------------------------------------------------------------===//
550 // Node creation methods.
551
552 /// Create a ConstantSDNode wrapping a constant value.
553 /// If VT is a vector type, the constant is splatted into a BUILD_VECTOR.
554 ///
555 /// If only legal types can be produced, this does the necessary
556 /// transformations (e.g., if the vector element type is illegal).
557 /// @{
558 SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT,
559 bool isTarget = false, bool isOpaque = false);
560 SDValue getConstant(const APInt &Val, const SDLoc &DL, EVT VT,
561 bool isTarget = false, bool isOpaque = false);
562
563 SDValue getAllOnesConstant(const SDLoc &DL, EVT VT, bool IsTarget = false,
564 bool IsOpaque = false) {
565 return getConstant(APInt::getAllOnesValue(VT.getScalarSizeInBits()), DL,
566 VT, IsTarget, IsOpaque);
567 }
568
569 SDValue getConstant(const ConstantInt &Val, const SDLoc &DL, EVT VT,
570 bool isTarget = false, bool isOpaque = false);
571 SDValue getIntPtrConstant(uint64_t Val, const SDLoc &DL,
572 bool isTarget = false);
573 SDValue getTargetConstant(uint64_t Val, const SDLoc &DL, EVT VT,
574 bool isOpaque = false) {
575 return getConstant(Val, DL, VT, true, isOpaque);
576 }
577 SDValue getTargetConstant(const APInt &Val, const SDLoc &DL, EVT VT,
578 bool isOpaque = false) {
579 return getConstant(Val, DL, VT, true, isOpaque);
580 }
581 SDValue getTargetConstant(const ConstantInt &Val, const SDLoc &DL, EVT VT,
582 bool isOpaque = false) {
583 return getConstant(Val, DL, VT, true, isOpaque);
584 }
585
586 /// Create a true or false constant of type \p VT using the target's
587 /// BooleanContent for type \p OpVT.
588 SDValue getBoolConstant(bool V, const SDLoc &DL, EVT VT, EVT OpVT);
589 /// @}
590
591 /// Create a ConstantFPSDNode wrapping a constant value.
592 /// If VT is a vector type, the constant is splatted into a BUILD_VECTOR.
593 ///
594 /// If only legal types can be produced, this does the necessary
595 /// transformations (e.g., if the vector element type is illegal).
596 /// The forms that take a double should only be used for simple constants
597 /// that can be exactly represented in VT. No checks are made.
598 /// @{
599 SDValue getConstantFP(double Val, const SDLoc &DL, EVT VT,
600 bool isTarget = false);
601 SDValue getConstantFP(const APFloat &Val, const SDLoc &DL, EVT VT,
602 bool isTarget = false);
603 SDValue getConstantFP(const ConstantFP &V, const SDLoc &DL, EVT VT,
604 bool isTarget = false);
605 SDValue getTargetConstantFP(double Val, const SDLoc &DL, EVT VT) {
606 return getConstantFP(Val, DL, VT, true);
607 }
608 SDValue getTargetConstantFP(const APFloat &Val, const SDLoc &DL, EVT VT) {
609 return getConstantFP(Val, DL, VT, true);
610 }
611 SDValue getTargetConstantFP(const ConstantFP &Val, const SDLoc &DL, EVT VT) {
612 return getConstantFP(Val, DL, VT, true);
613 }
614 /// @}
615
616 SDValue getGlobalAddress(const GlobalValue *GV, const SDLoc &DL, EVT VT,
617 int64_t offset = 0, bool isTargetGA = false,
618 unsigned char TargetFlags = 0);
619 SDValue getTargetGlobalAddress(const GlobalValue *GV, const SDLoc &DL, EVT VT,
620 int64_t offset = 0,
621 unsigned char TargetFlags = 0) {
622 return getGlobalAddress(GV, DL, VT, offset, true, TargetFlags);
623 }
624 SDValue getFrameIndex(int FI, EVT VT, bool isTarget = false);
625 SDValue getTargetFrameIndex(int FI, EVT VT) {
626 return getFrameIndex(FI, VT, true);
627 }
628 SDValue getJumpTable(int JTI, EVT VT, bool isTarget = false,
629 unsigned char TargetFlags = 0);
630 SDValue getTargetJumpTable(int JTI, EVT VT, unsigned char TargetFlags = 0) {
631 return getJumpTable(JTI, VT, true, TargetFlags);
632 }
633 SDValue getConstantPool(const Constant *C, EVT VT,
634 unsigned Align = 0, int Offs = 0, bool isT=false,
635 unsigned char TargetFlags = 0);
636 SDValue getTargetConstantPool(const Constant *C, EVT VT,
637 unsigned Align = 0, int Offset = 0,
638 unsigned char TargetFlags = 0) {
639 return getConstantPool(C, VT, Align, Offset, true, TargetFlags);
640 }
641 SDValue getConstantPool(MachineConstantPoolValue *C, EVT VT,
642 unsigned Align = 0, int Offs = 0, bool isT=false,
643 unsigned char TargetFlags = 0);
644 SDValue getTargetConstantPool(MachineConstantPoolValue *C,
645 EVT VT, unsigned Align = 0,
646 int Offset = 0, unsigned char TargetFlags=0) {
647 return getConstantPool(C, VT, Align, Offset, true, TargetFlags);
648 }
649 SDValue getTargetIndex(int Index, EVT VT, int64_t Offset = 0,
650 unsigned char TargetFlags = 0);
651 // When generating a branch to a BB, we don't in general know enough
652 // to provide debug info for the BB at that time, so keep this one around.
653 SDValue getBasicBlock(MachineBasicBlock *MBB);
654 SDValue getBasicBlock(MachineBasicBlock *MBB, SDLoc dl);
655 SDValue getExternalSymbol(const char *Sym, EVT VT);
656 SDValue getExternalSymbol(const char *Sym, const SDLoc &dl, EVT VT);
657 SDValue getTargetExternalSymbol(const char *Sym, EVT VT,
658 unsigned char TargetFlags = 0);
659 SDValue getMCSymbol(MCSymbol *Sym, EVT VT);
660
661 SDValue getValueType(EVT);
662 SDValue getRegister(unsigned Reg, EVT VT);
663 SDValue getRegisterMask(const uint32_t *RegMask);
664 SDValue getEHLabel(const SDLoc &dl, SDValue Root, MCSymbol *Label);
665 SDValue getLabelNode(unsigned Opcode, const SDLoc &dl, SDValue Root,
666 MCSymbol *Label);
667 SDValue getBlockAddress(const BlockAddress *BA, EVT VT,
668 int64_t Offset = 0, bool isTarget = false,
669 unsigned char TargetFlags = 0);
670 SDValue getTargetBlockAddress(const BlockAddress *BA, EVT VT,
671 int64_t Offset = 0,
672 unsigned char TargetFlags = 0) {
673 return getBlockAddress(BA, VT, Offset, true, TargetFlags);
674 }
675
676 SDValue getCopyToReg(SDValue Chain, const SDLoc &dl, unsigned Reg,
677 SDValue N) {
678 return getNode(ISD::CopyToReg, dl, MVT::Other, Chain,
679 getRegister(Reg, N.getValueType()), N);
680 }
681
682 // This version of the getCopyToReg method takes an extra operand, which
683 // indicates that there is potentially an incoming glue value (if Glue is not
684 // null) and that there should be a glue result.
685 SDValue getCopyToReg(SDValue Chain, const SDLoc &dl, unsigned Reg, SDValue N,
686 SDValue Glue) {
687 SDVTList VTs = getVTList(MVT::Other, MVT::Glue);
688 SDValue Ops[] = { Chain, getRegister(Reg, N.getValueType()), N, Glue };
16
Calling 'SDValue::getValueType'
689 return getNode(ISD::CopyToReg, dl, VTs,
690 makeArrayRef(Ops, Glue.getNode() ? 4 : 3));
691 }
692
693 // Similar to last getCopyToReg() except parameter Reg is a SDValue
694 SDValue getCopyToReg(SDValue Chain, const SDLoc &dl, SDValue Reg, SDValue N,
695 SDValue Glue) {
696 SDVTList VTs = getVTList(MVT::Other, MVT::Glue);
697 SDValue Ops[] = { Chain, Reg, N, Glue };
698 return getNode(ISD::CopyToReg, dl, VTs,
699 makeArrayRef(Ops, Glue.getNode() ? 4 : 3));
700 }
701
702 SDValue getCopyFromReg(SDValue Chain, const SDLoc &dl, unsigned Reg, EVT VT) {
703 SDVTList VTs = getVTList(VT, MVT::Other);
704 SDValue Ops[] = { Chain, getRegister(Reg, VT) };
705 return getNode(ISD::CopyFromReg, dl, VTs, Ops);
706 }
707
708 // This version of the getCopyFromReg method takes an extra operand, which
709 // indicates that there is potentially an incoming glue value (if Glue is not
710 // null) and that there should be a glue result.
711 SDValue getCopyFromReg(SDValue Chain, const SDLoc &dl, unsigned Reg, EVT VT,
712 SDValue Glue) {
713 SDVTList VTs = getVTList(VT, MVT::Other, MVT::Glue);
714 SDValue Ops[] = { Chain, getRegister(Reg, VT), Glue };
715 return getNode(ISD::CopyFromReg, dl, VTs,
716 makeArrayRef(Ops, Glue.getNode() ? 3 : 2));
717 }
718
719 SDValue getCondCode(ISD::CondCode Cond);
720
721 /// Return an ISD::VECTOR_SHUFFLE node. The number of elements in VT,
722 /// which must be a vector type, must match the number of mask elements
723 /// NumElts. An integer mask element equal to -1 is treated as undefined.
724 SDValue getVectorShuffle(EVT VT, const SDLoc &dl, SDValue N1, SDValue N2,
725 ArrayRef<int> Mask);
726
727 /// Return an ISD::BUILD_VECTOR node. The number of elements in VT,
728 /// which must be a vector type, must match the number of operands in Ops.
729 /// The operands must have the same type as (or, for integers, a type wider
730 /// than) VT's element type.
731 SDValue getBuildVector(EVT VT, const SDLoc &DL, ArrayRef<SDValue> Ops) {
732 // VerifySDNode (via InsertNode) checks BUILD_VECTOR later.
733 return getNode(ISD::BUILD_VECTOR, DL, VT, Ops);
734 }
735
736 /// Return an ISD::BUILD_VECTOR node. The number of elements in VT,
737 /// which must be a vector type, must match the number of operands in Ops.
738 /// The operands must have the same type as (or, for integers, a type wider
739 /// than) VT's element type.
740 SDValue getBuildVector(EVT VT, const SDLoc &DL, ArrayRef<SDUse> Ops) {
741 // VerifySDNode (via InsertNode) checks BUILD_VECTOR later.
742 return getNode(ISD::BUILD_VECTOR, DL, VT, Ops);
743 }
744
745 /// Return a splat ISD::BUILD_VECTOR node, consisting of Op splatted to all
746 /// elements. VT must be a vector type. Op's type must be the same as (or,
747 /// for integers, a type wider than) VT's element type.
748 SDValue getSplatBuildVector(EVT VT, const SDLoc &DL, SDValue Op) {
749 // VerifySDNode (via InsertNode) checks BUILD_VECTOR later.
750 if (Op.getOpcode() == ISD::UNDEF) {
751 assert((VT.getVectorElementType() == Op.getValueType() ||(((VT.getVectorElementType() == Op.getValueType() || (VT.isInteger
() && VT.getVectorElementType().bitsLE(Op.getValueType
()))) && "A splatted value must have a width equal or (for integers) "
"greater than the vector element type!") ? static_cast<void
> (0) : __assert_fail ("(VT.getVectorElementType() == Op.getValueType() || (VT.isInteger() && VT.getVectorElementType().bitsLE(Op.getValueType()))) && \"A splatted value must have a width equal or (for integers) \" \"greater than the vector element type!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAG.h"
, 755, __PRETTY_FUNCTION__))
752 (VT.isInteger() &&(((VT.getVectorElementType() == Op.getValueType() || (VT.isInteger
() && VT.getVectorElementType().bitsLE(Op.getValueType
()))) && "A splatted value must have a width equal or (for integers) "
"greater than the vector element type!") ? static_cast<void
> (0) : __assert_fail ("(VT.getVectorElementType() == Op.getValueType() || (VT.isInteger() && VT.getVectorElementType().bitsLE(Op.getValueType()))) && \"A splatted value must have a width equal or (for integers) \" \"greater than the vector element type!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAG.h"
, 755, __PRETTY_FUNCTION__))
753 VT.getVectorElementType().bitsLE(Op.getValueType()))) &&(((VT.getVectorElementType() == Op.getValueType() || (VT.isInteger
() && VT.getVectorElementType().bitsLE(Op.getValueType
()))) && "A splatted value must have a width equal or (for integers) "
"greater than the vector element type!") ? static_cast<void
> (0) : __assert_fail ("(VT.getVectorElementType() == Op.getValueType() || (VT.isInteger() && VT.getVectorElementType().bitsLE(Op.getValueType()))) && \"A splatted value must have a width equal or (for integers) \" \"greater than the vector element type!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAG.h"
, 755, __PRETTY_FUNCTION__))
754 "A splatted value must have a width equal or (for integers) "(((VT.getVectorElementType() == Op.getValueType() || (VT.isInteger
() && VT.getVectorElementType().bitsLE(Op.getValueType
()))) && "A splatted value must have a width equal or (for integers) "
"greater than the vector element type!") ? static_cast<void
> (0) : __assert_fail ("(VT.getVectorElementType() == Op.getValueType() || (VT.isInteger() && VT.getVectorElementType().bitsLE(Op.getValueType()))) && \"A splatted value must have a width equal or (for integers) \" \"greater than the vector element type!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAG.h"
, 755, __PRETTY_FUNCTION__))
755 "greater than the vector element type!")(((VT.getVectorElementType() == Op.getValueType() || (VT.isInteger
() && VT.getVectorElementType().bitsLE(Op.getValueType
()))) && "A splatted value must have a width equal or (for integers) "
"greater than the vector element type!") ? static_cast<void
> (0) : __assert_fail ("(VT.getVectorElementType() == Op.getValueType() || (VT.isInteger() && VT.getVectorElementType().bitsLE(Op.getValueType()))) && \"A splatted value must have a width equal or (for integers) \" \"greater than the vector element type!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAG.h"
, 755, __PRETTY_FUNCTION__))
;
756 return getNode(ISD::UNDEF, SDLoc(), VT);
757 }
758
759 SmallVector<SDValue, 16> Ops(VT.getVectorNumElements(), Op);
760 return getNode(ISD::BUILD_VECTOR, DL, VT, Ops);
761 }
762
763 /// Returns an ISD::VECTOR_SHUFFLE node semantically equivalent to
764 /// the shuffle node in input but with swapped operands.
765 ///
766 /// Example: shuffle A, B, <0,5,2,7> -> shuffle B, A, <4,1,6,3>
767 SDValue getCommutedVectorShuffle(const ShuffleVectorSDNode &SV);
768
769 /// Convert Op, which must be of float type, to the
770 /// float type VT, by either extending or rounding (by truncation).
771 SDValue getFPExtendOrRound(SDValue Op, const SDLoc &DL, EVT VT);
772
773 /// Convert Op, which must be of integer type, to the
774 /// integer type VT, by either any-extending or truncating it.
775 SDValue getAnyExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT);
776
777 /// Convert Op, which must be of integer type, to the
778 /// integer type VT, by either sign-extending or truncating it.
779 SDValue getSExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT);
780
781 /// Convert Op, which must be of integer type, to the
782 /// integer type VT, by either zero-extending or truncating it.
783 SDValue getZExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT);
784
785 /// Return the expression required to zero extend the Op
786 /// value assuming it was the smaller SrcTy value.
787 SDValue getZeroExtendInReg(SDValue Op, const SDLoc &DL, EVT VT);
788
789 /// Convert Op, which must be of integer type, to the integer type VT,
790 /// by using an extension appropriate for the target's
791 /// BooleanContent for type OpVT or truncating it.
792 SDValue getBoolExtOrTrunc(SDValue Op, const SDLoc &SL, EVT VT, EVT OpVT);
793
794 /// Create a bitwise NOT operation as (XOR Val, -1).
795 SDValue getNOT(const SDLoc &DL, SDValue Val, EVT VT);
796
797 /// Create a logical NOT operation as (XOR Val, BooleanOne).
798 SDValue getLogicalNOT(const SDLoc &DL, SDValue Val, EVT VT);
799
800 /// Create an add instruction with appropriate flags when used for
801 /// addressing some offset of an object. i.e. if a load is split into multiple
802 /// components, create an add nuw from the base pointer to the offset.
803 SDValue getObjectPtrOffset(const SDLoc &SL, SDValue Op, int64_t Offset) {
804 EVT VT = Op.getValueType();
805 return getObjectPtrOffset(SL, Op, getConstant(Offset, SL, VT));
806 }
807
808 SDValue getObjectPtrOffset(const SDLoc &SL, SDValue Op, SDValue Offset) {
809 EVT VT = Op.getValueType();
810
811 // The object itself can't wrap around the address space, so it shouldn't be
812 // possible for the adds of the offsets to the split parts to overflow.
813 SDNodeFlags Flags;
814 Flags.setNoUnsignedWrap(true);
815 return getNode(ISD::ADD, SL, VT, Op, Offset, Flags);
816 }
817
818 /// Return a new CALLSEQ_START node, that starts new call frame, in which
819 /// InSize bytes are set up inside CALLSEQ_START..CALLSEQ_END sequence and
820 /// OutSize specifies part of the frame set up prior to the sequence.
821 SDValue getCALLSEQ_START(SDValue Chain, uint64_t InSize, uint64_t OutSize,
822 const SDLoc &DL) {
823 SDVTList VTs = getVTList(MVT::Other, MVT::Glue);
824 SDValue Ops[] = { Chain,
825 getIntPtrConstant(InSize, DL, true),
826 getIntPtrConstant(OutSize, DL, true) };
827 return getNode(ISD::CALLSEQ_START, DL, VTs, Ops);
828 }
829
830 /// Return a new CALLSEQ_END node, which always must have a
831 /// glue result (to ensure it's not CSE'd).
832 /// CALLSEQ_END does not have a useful SDLoc.
833 SDValue getCALLSEQ_END(SDValue Chain, SDValue Op1, SDValue Op2,
834 SDValue InGlue, const SDLoc &DL) {
835 SDVTList NodeTys = getVTList(MVT::Other, MVT::Glue);
836 SmallVector<SDValue, 4> Ops;
837 Ops.push_back(Chain);
838 Ops.push_back(Op1);
839 Ops.push_back(Op2);
840 if (InGlue.getNode())
841 Ops.push_back(InGlue);
842 return getNode(ISD::CALLSEQ_END, DL, NodeTys, Ops);
843 }
844
845 /// Return true if the result of this operation is always undefined.
846 bool isUndef(unsigned Opcode, ArrayRef<SDValue> Ops);
847
848 /// Return an UNDEF node. UNDEF does not have a useful SDLoc.
849 SDValue getUNDEF(EVT VT) {
850 return getNode(ISD::UNDEF, SDLoc(), VT);
851 }
852
853 /// Return a GLOBAL_OFFSET_TABLE node. This does not have a useful SDLoc.
854 SDValue getGLOBAL_OFFSET_TABLE(EVT VT) {
855 return getNode(ISD::GLOBAL_OFFSET_TABLE, SDLoc(), VT);
856 }
857
858 /// Gets or creates the specified node.
859 ///
860 SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
861 ArrayRef<SDUse> Ops);
862 SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
863 ArrayRef<SDValue> Ops, const SDNodeFlags Flags = SDNodeFlags());
864 SDValue getNode(unsigned Opcode, const SDLoc &DL, ArrayRef<EVT> ResultTys,
865 ArrayRef<SDValue> Ops);
866 SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList,
867 ArrayRef<SDValue> Ops);
868
869 // Specialize based on number of operands.
870 SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT);
871 SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue Operand,
872 const SDNodeFlags Flags = SDNodeFlags());
873 SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1,
874 SDValue N2, const SDNodeFlags Flags = SDNodeFlags());
875 SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1,
876 SDValue N2, SDValue N3,
877 const SDNodeFlags Flags = SDNodeFlags());
878 SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1,
879 SDValue N2, SDValue N3, SDValue N4);
880 SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1,
881 SDValue N2, SDValue N3, SDValue N4, SDValue N5);
882
883 // Specialize again based on number of operands for nodes with a VTList
884 // rather than a single VT.
885 SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList);
886 SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList, SDValue N);
887 SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList, SDValue N1,
888 SDValue N2);
889 SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList, SDValue N1,
890 SDValue N2, SDValue N3);
891 SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList, SDValue N1,
892 SDValue N2, SDValue N3, SDValue N4);
893 SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList, SDValue N1,
894 SDValue N2, SDValue N3, SDValue N4, SDValue N5);
895
896 /// Compute a TokenFactor to force all the incoming stack arguments to be
897 /// loaded from the stack. This is used in tail call lowering to protect
898 /// stack arguments from being clobbered.
899 SDValue getStackArgumentTokenFactor(SDValue Chain);
900
901 SDValue getMemcpy(SDValue Chain, const SDLoc &dl, SDValue Dst, SDValue Src,
902 SDValue Size, unsigned Align, bool isVol, bool AlwaysInline,
903 bool isTailCall, MachinePointerInfo DstPtrInfo,
904 MachinePointerInfo SrcPtrInfo);
905
906 SDValue getMemmove(SDValue Chain, const SDLoc &dl, SDValue Dst, SDValue Src,
907 SDValue Size, unsigned Align, bool isVol, bool isTailCall,
908 MachinePointerInfo DstPtrInfo,
909 MachinePointerInfo SrcPtrInfo);
910
911 SDValue getMemset(SDValue Chain, const SDLoc &dl, SDValue Dst, SDValue Src,
912 SDValue Size, unsigned Align, bool isVol, bool isTailCall,
913 MachinePointerInfo DstPtrInfo);
914
915 SDValue getAtomicMemcpy(SDValue Chain, const SDLoc &dl, SDValue Dst,
916 unsigned DstAlign, SDValue Src, unsigned SrcAlign,
917 SDValue Size, Type *SizeTy, unsigned ElemSz,
918 bool isTailCall, MachinePointerInfo DstPtrInfo,
919 MachinePointerInfo SrcPtrInfo);
920
921 SDValue getAtomicMemmove(SDValue Chain, const SDLoc &dl, SDValue Dst,
922 unsigned DstAlign, SDValue Src, unsigned SrcAlign,
923 SDValue Size, Type *SizeTy, unsigned ElemSz,
924 bool isTailCall, MachinePointerInfo DstPtrInfo,
925 MachinePointerInfo SrcPtrInfo);
926
927 SDValue getAtomicMemset(SDValue Chain, const SDLoc &dl, SDValue Dst,
928 unsigned DstAlign, SDValue Value, SDValue Size,
929 Type *SizeTy, unsigned ElemSz, bool isTailCall,
930 MachinePointerInfo DstPtrInfo);
931
932 /// Helper function to make it easier to build SetCC's if you just have an
933 /// ISD::CondCode instead of an SDValue.
934 SDValue getSetCC(const SDLoc &DL, EVT VT, SDValue LHS, SDValue RHS,
935 ISD::CondCode Cond) {
936 assert(LHS.getValueType().isVector() == RHS.getValueType().isVector() &&((LHS.getValueType().isVector() == RHS.getValueType().isVector
() && "Cannot compare scalars to vectors") ? static_cast
<void> (0) : __assert_fail ("LHS.getValueType().isVector() == RHS.getValueType().isVector() && \"Cannot compare scalars to vectors\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAG.h"
, 937, __PRETTY_FUNCTION__))
937 "Cannot compare scalars to vectors")((LHS.getValueType().isVector() == RHS.getValueType().isVector
() && "Cannot compare scalars to vectors") ? static_cast
<void> (0) : __assert_fail ("LHS.getValueType().isVector() == RHS.getValueType().isVector() && \"Cannot compare scalars to vectors\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAG.h"
, 937, __PRETTY_FUNCTION__))
;
938 assert(LHS.getValueType().isVector() == VT.isVector() &&((LHS.getValueType().isVector() == VT.isVector() && "Cannot compare scalars to vectors"
) ? static_cast<void> (0) : __assert_fail ("LHS.getValueType().isVector() == VT.isVector() && \"Cannot compare scalars to vectors\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAG.h"
, 939, __PRETTY_FUNCTION__))
939 "Cannot compare scalars to vectors")((LHS.getValueType().isVector() == VT.isVector() && "Cannot compare scalars to vectors"
) ? static_cast<void> (0) : __assert_fail ("LHS.getValueType().isVector() == VT.isVector() && \"Cannot compare scalars to vectors\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAG.h"
, 939, __PRETTY_FUNCTION__))
;
940 assert(Cond != ISD::SETCC_INVALID &&((Cond != ISD::SETCC_INVALID && "Cannot create a setCC of an invalid node."
) ? static_cast<void> (0) : __assert_fail ("Cond != ISD::SETCC_INVALID && \"Cannot create a setCC of an invalid node.\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAG.h"
, 941, __PRETTY_FUNCTION__))
941 "Cannot create a setCC of an invalid node.")((Cond != ISD::SETCC_INVALID && "Cannot create a setCC of an invalid node."
) ? static_cast<void> (0) : __assert_fail ("Cond != ISD::SETCC_INVALID && \"Cannot create a setCC of an invalid node.\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAG.h"
, 941, __PRETTY_FUNCTION__))
;
942 return getNode(ISD::SETCC, DL, VT, LHS, RHS, getCondCode(Cond));
943 }
944
945 /// Helper function to make it easier to build Select's if you just have
946 /// operands and don't want to check for vector.
947 SDValue getSelect(const SDLoc &DL, EVT VT, SDValue Cond, SDValue LHS,
948 SDValue RHS) {
949 assert(LHS.getValueType() == RHS.getValueType() &&((LHS.getValueType() == RHS.getValueType() && "Cannot use select on differing types"
) ? static_cast<void> (0) : __assert_fail ("LHS.getValueType() == RHS.getValueType() && \"Cannot use select on differing types\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAG.h"
, 950, __PRETTY_FUNCTION__))
950 "Cannot use select on differing types")((LHS.getValueType() == RHS.getValueType() && "Cannot use select on differing types"
) ? static_cast<void> (0) : __assert_fail ("LHS.getValueType() == RHS.getValueType() && \"Cannot use select on differing types\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAG.h"
, 950, __PRETTY_FUNCTION__))
;
951 assert(VT.isVector() == LHS.getValueType().isVector() &&((VT.isVector() == LHS.getValueType().isVector() && "Cannot mix vectors and scalars"
) ? static_cast<void> (0) : __assert_fail ("VT.isVector() == LHS.getValueType().isVector() && \"Cannot mix vectors and scalars\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAG.h"
, 952, __PRETTY_FUNCTION__))
952 "Cannot mix vectors and scalars")((VT.isVector() == LHS.getValueType().isVector() && "Cannot mix vectors and scalars"
) ? static_cast<void> (0) : __assert_fail ("VT.isVector() == LHS.getValueType().isVector() && \"Cannot mix vectors and scalars\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAG.h"
, 952, __PRETTY_FUNCTION__))
;
953 auto Opcode = Cond.getValueType().isVector() ? ISD::VSELECT : ISD::SELECT;
954 return getNode(Opcode, DL, VT, Cond, LHS, RHS);
955 }
956
957 /// Helper function to make it easier to build SelectCC's if you just have an
958 /// ISD::CondCode instead of an SDValue.
959 SDValue getSelectCC(const SDLoc &DL, SDValue LHS, SDValue RHS, SDValue True,
960 SDValue False, ISD::CondCode Cond) {
961 return getNode(ISD::SELECT_CC, DL, True.getValueType(), LHS, RHS, True,
962 False, getCondCode(Cond));
963 }
964
965 /// Try to simplify a select/vselect into 1 of its operands or a constant.
966 SDValue simplifySelect(SDValue Cond, SDValue TVal, SDValue FVal);
967
968 /// Try to simplify a shift into 1 of its operands or a constant.
969 SDValue simplifyShift(SDValue X, SDValue Y);
970
971 /// VAArg produces a result and token chain, and takes a pointer
972 /// and a source value as input.
973 SDValue getVAArg(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr,
974 SDValue SV, unsigned Align);
975
976 /// Gets a node for an atomic cmpxchg op. There are two
977 /// valid Opcodes. ISD::ATOMIC_CMO_SWAP produces the value loaded and a
978 /// chain result. ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS produces the value loaded,
979 /// a success flag (initially i1), and a chain.
980 SDValue getAtomicCmpSwap(unsigned Opcode, const SDLoc &dl, EVT MemVT,
981 SDVTList VTs, SDValue Chain, SDValue Ptr,
982 SDValue Cmp, SDValue Swp, MachinePointerInfo PtrInfo,
983 unsigned Alignment, AtomicOrdering SuccessOrdering,
984 AtomicOrdering FailureOrdering,
985 SyncScope::ID SSID);
986 SDValue getAtomicCmpSwap(unsigned Opcode, const SDLoc &dl, EVT MemVT,
987 SDVTList VTs, SDValue Chain, SDValue Ptr,
988 SDValue Cmp, SDValue Swp, MachineMemOperand *MMO);
989
990 /// Gets a node for an atomic op, produces result (if relevant)
991 /// and chain and takes 2 operands.
992 SDValue getAtomic(unsigned Opcode, const SDLoc &dl, EVT MemVT, SDValue Chain,
993 SDValue Ptr, SDValue Val, const Value *PtrVal,
994 unsigned Alignment, AtomicOrdering Ordering,
995 SyncScope::ID SSID);
996 SDValue getAtomic(unsigned Opcode, const SDLoc &dl, EVT MemVT, SDValue Chain,
997 SDValue Ptr, SDValue Val, MachineMemOperand *MMO);
998
999 /// Gets a node for an atomic op, produces result and chain and
1000 /// takes 1 operand.
1001 SDValue getAtomic(unsigned Opcode, const SDLoc &dl, EVT MemVT, EVT VT,
1002 SDValue Chain, SDValue Ptr, MachineMemOperand *MMO);
1003
1004 /// Gets a node for an atomic op, produces result and chain and takes N
1005 /// operands.
1006 SDValue getAtomic(unsigned Opcode, const SDLoc &dl, EVT MemVT,
1007 SDVTList VTList, ArrayRef<SDValue> Ops,
1008 MachineMemOperand *MMO);
1009
1010 /// Creates a MemIntrinsicNode that may produce a
1011 /// result and takes a list of operands. Opcode may be INTRINSIC_VOID,
1012 /// INTRINSIC_W_CHAIN, or a target-specific opcode with a value not
1013 /// less than FIRST_TARGET_MEMORY_OPCODE.
1014 SDValue getMemIntrinsicNode(
1015 unsigned Opcode, const SDLoc &dl, SDVTList VTList,
1016 ArrayRef<SDValue> Ops, EVT MemVT,
1017 MachinePointerInfo PtrInfo,
1018 unsigned Align = 0,
1019 MachineMemOperand::Flags Flags
1020 = MachineMemOperand::MOLoad | MachineMemOperand::MOStore,
1021 unsigned Size = 0);
1022
1023 SDValue getMemIntrinsicNode(unsigned Opcode, const SDLoc &dl, SDVTList VTList,
1024 ArrayRef<SDValue> Ops, EVT MemVT,
1025 MachineMemOperand *MMO);
1026
1027 /// Create a MERGE_VALUES node from the given operands.
1028 SDValue getMergeValues(ArrayRef<SDValue> Ops, const SDLoc &dl);
1029
1030 /// Loads are not normal binary operators: their result type is not
1031 /// determined by their operands, and they produce a value AND a token chain.
1032 ///
1033 /// This function will set the MOLoad flag on MMOFlags, but you can set it if
1034 /// you want. The MOStore flag must not be set.
1035 SDValue getLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr,
1036 MachinePointerInfo PtrInfo, unsigned Alignment = 0,
1037 MachineMemOperand::Flags MMOFlags = MachineMemOperand::MONone,
1038 const AAMDNodes &AAInfo = AAMDNodes(),
1039 const MDNode *Ranges = nullptr);
1040 SDValue getLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr,
1041 MachineMemOperand *MMO);
1042 SDValue
1043 getExtLoad(ISD::LoadExtType ExtType, const SDLoc &dl, EVT VT, SDValue Chain,
1044 SDValue Ptr, MachinePointerInfo PtrInfo, EVT MemVT,
1045 unsigned Alignment = 0,
1046 MachineMemOperand::Flags MMOFlags = MachineMemOperand::MONone,
1047 const AAMDNodes &AAInfo = AAMDNodes());
1048 SDValue getExtLoad(ISD::LoadExtType ExtType, const SDLoc &dl, EVT VT,
1049 SDValue Chain, SDValue Ptr, EVT MemVT,
1050 MachineMemOperand *MMO);
1051 SDValue getIndexedLoad(SDValue OrigLoad, const SDLoc &dl, SDValue Base,
1052 SDValue Offset, ISD::MemIndexedMode AM);
1053 SDValue getLoad(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType, EVT VT,
1054 const SDLoc &dl, SDValue Chain, SDValue Ptr, SDValue Offset,
1055 MachinePointerInfo PtrInfo, EVT MemVT, unsigned Alignment = 0,
1056 MachineMemOperand::Flags MMOFlags = MachineMemOperand::MONone,
1057 const AAMDNodes &AAInfo = AAMDNodes(),
1058 const MDNode *Ranges = nullptr);
1059 SDValue getLoad(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType, EVT VT,
1060 const SDLoc &dl, SDValue Chain, SDValue Ptr, SDValue Offset,
1061 EVT MemVT, MachineMemOperand *MMO);
1062
1063 /// Helper function to build ISD::STORE nodes.
1064 ///
1065 /// This function will set the MOStore flag on MMOFlags, but you can set it if
1066 /// you want. The MOLoad and MOInvariant flags must not be set.
1067 SDValue
1068 getStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr,
1069 MachinePointerInfo PtrInfo, unsigned Alignment = 0,
1070 MachineMemOperand::Flags MMOFlags = MachineMemOperand::MONone,
1071 const AAMDNodes &AAInfo = AAMDNodes());
1072 SDValue getStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr,
1073 MachineMemOperand *MMO);
1074 SDValue
1075 getTruncStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr,
1076 MachinePointerInfo PtrInfo, EVT SVT, unsigned Alignment = 0,
1077 MachineMemOperand::Flags MMOFlags = MachineMemOperand::MONone,
1078 const AAMDNodes &AAInfo = AAMDNodes());
1079 SDValue getTruncStore(SDValue Chain, const SDLoc &dl, SDValue Val,
1080 SDValue Ptr, EVT SVT, MachineMemOperand *MMO);
1081 SDValue getIndexedStore(SDValue OrigStore, const SDLoc &dl, SDValue Base,
1082 SDValue Offset, ISD::MemIndexedMode AM);
1083
1084 /// Returns sum of the base pointer and offset.
1085 SDValue getMemBasePlusOffset(SDValue Base, unsigned Offset, const SDLoc &DL);
1086
1087 SDValue getMaskedLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr,
1088 SDValue Mask, SDValue Src0, EVT MemVT,
1089 MachineMemOperand *MMO, ISD::LoadExtType,
1090 bool IsExpanding = false);
1091 SDValue getMaskedStore(SDValue Chain, const SDLoc &dl, SDValue Val,
1092 SDValue Ptr, SDValue Mask, EVT MemVT,
1093 MachineMemOperand *MMO, bool IsTruncating = false,
1094 bool IsCompressing = false);
1095 SDValue getMaskedGather(SDVTList VTs, EVT VT, const SDLoc &dl,
1096 ArrayRef<SDValue> Ops, MachineMemOperand *MMO);
1097 SDValue getMaskedScatter(SDVTList VTs, EVT VT, const SDLoc &dl,
1098 ArrayRef<SDValue> Ops, MachineMemOperand *MMO);
1099
1100 /// Return (create a new or find existing) a target-specific node.
1101 /// TargetMemSDNode should be derived class from MemSDNode.
1102 template <class TargetMemSDNode>
1103 SDValue getTargetMemSDNode(SDVTList VTs, ArrayRef<SDValue> Ops,
1104 const SDLoc &dl, EVT MemVT,
1105 MachineMemOperand *MMO);
1106
1107 /// Construct a node to track a Value* through the backend.
1108 SDValue getSrcValue(const Value *v);
1109
1110 /// Return an MDNodeSDNode which holds an MDNode.
1111 SDValue getMDNode(const MDNode *MD);
1112
1113 /// Return a bitcast using the SDLoc of the value operand, and casting to the
1114 /// provided type. Use getNode to set a custom SDLoc.
1115 SDValue getBitcast(EVT VT, SDValue V);
1116
1117 /// Return an AddrSpaceCastSDNode.
1118 SDValue getAddrSpaceCast(const SDLoc &dl, EVT VT, SDValue Ptr, unsigned SrcAS,
1119 unsigned DestAS);
1120
1121 /// Return the specified value casted to
1122 /// the target's desired shift amount type.
1123 SDValue getShiftAmountOperand(EVT LHSTy, SDValue Op);
1124
1125 /// Expand the specified \c ISD::VAARG node as the Legalize pass would.
1126 SDValue expandVAArg(SDNode *Node);
1127
1128 /// Expand the specified \c ISD::VACOPY node as the Legalize pass would.
1129 SDValue expandVACopy(SDNode *Node);
1130
1131 /// Returs an GlobalAddress of the function from the current module with
1132 /// name matching the given ExternalSymbol. Additionally can provide the
1133 /// matched function.
1134 /// Panics the function doesn't exists.
1135 SDValue getSymbolFunctionGlobalAddress(SDValue Op,
1136 Function **TargetFunction = nullptr);
1137
1138 /// *Mutate* the specified node in-place to have the
1139 /// specified operands. If the resultant node already exists in the DAG,
1140 /// this does not modify the specified node, instead it returns the node that
1141 /// already exists. If the resultant node does not exist in the DAG, the
1142 /// input node is returned. As a degenerate case, if you specify the same
1143 /// input operands as the node already has, the input node is returned.
1144 SDNode *UpdateNodeOperands(SDNode *N, SDValue Op);
1145 SDNode *UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2);
1146 SDNode *UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2,
1147 SDValue Op3);
1148 SDNode *UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2,
1149 SDValue Op3, SDValue Op4);
1150 SDNode *UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2,
1151 SDValue Op3, SDValue Op4, SDValue Op5);
1152 SDNode *UpdateNodeOperands(SDNode *N, ArrayRef<SDValue> Ops);
1153
1154 /// *Mutate* the specified machine node's memory references to the provided
1155 /// list.
1156 void setNodeMemRefs(MachineSDNode *N,
1157 ArrayRef<MachineMemOperand *> NewMemRefs);
1158
1159 // Propagates the change in divergence to users
1160 void updateDivergence(SDNode * N);
1161
1162 /// These are used for target selectors to *mutate* the
1163 /// specified node to have the specified return type, Target opcode, and
1164 /// operands. Note that target opcodes are stored as
1165 /// ~TargetOpcode in the node opcode field. The resultant node is returned.
1166 SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT);
1167 SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT, SDValue Op1);
1168 SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT,
1169 SDValue Op1, SDValue Op2);
1170 SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT,
1171 SDValue Op1, SDValue Op2, SDValue Op3);
1172 SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT,
1173 ArrayRef<SDValue> Ops);
1174 SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT1, EVT VT2);
1175 SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT1,
1176 EVT VT2, ArrayRef<SDValue> Ops);
1177 SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT1,
1178 EVT VT2, EVT VT3, ArrayRef<SDValue> Ops);
1179 SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT1,
1180 EVT VT2, SDValue Op1);
1181 SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT1,
1182 EVT VT2, SDValue Op1, SDValue Op2);
1183 SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, SDVTList VTs,
1184 ArrayRef<SDValue> Ops);
1185
1186 /// This *mutates* the specified node to have the specified
1187 /// return type, opcode, and operands.
1188 SDNode *MorphNodeTo(SDNode *N, unsigned Opc, SDVTList VTs,
1189 ArrayRef<SDValue> Ops);
1190
1191 /// Mutate the specified strict FP node to its non-strict equivalent,
1192 /// unlinking the node from its chain and dropping the metadata arguments.
1193 /// The node must be a strict FP node.
1194 SDNode *mutateStrictFPToFP(SDNode *Node);
1195
1196 /// These are used for target selectors to create a new node
1197 /// with specified return type(s), MachineInstr opcode, and operands.
1198 ///
1199 /// Note that getMachineNode returns the resultant node. If there is already
1200 /// a node of the specified opcode and operands, it returns that node instead
1201 /// of the current one.
1202 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT);
1203 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT,
1204 SDValue Op1);
1205 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT,
1206 SDValue Op1, SDValue Op2);
1207 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT,
1208 SDValue Op1, SDValue Op2, SDValue Op3);
1209 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT,
1210 ArrayRef<SDValue> Ops);
1211 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT1,
1212 EVT VT2, SDValue Op1, SDValue Op2);
1213 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT1,
1214 EVT VT2, SDValue Op1, SDValue Op2, SDValue Op3);
1215 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT1,
1216 EVT VT2, ArrayRef<SDValue> Ops);
1217 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT1,
1218 EVT VT2, EVT VT3, SDValue Op1, SDValue Op2);
1219 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT1,
1220 EVT VT2, EVT VT3, SDValue Op1, SDValue Op2,
1221 SDValue Op3);
1222 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT1,
1223 EVT VT2, EVT VT3, ArrayRef<SDValue> Ops);
1224 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl,
1225 ArrayRef<EVT> ResultTys, ArrayRef<SDValue> Ops);
1226 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, SDVTList VTs,
1227 ArrayRef<SDValue> Ops);
1228
1229 /// A convenience function for creating TargetInstrInfo::EXTRACT_SUBREG nodes.
1230 SDValue getTargetExtractSubreg(int SRIdx, const SDLoc &DL, EVT VT,
1231 SDValue Operand);
1232
1233 /// A convenience function for creating TargetInstrInfo::INSERT_SUBREG nodes.
1234 SDValue getTargetInsertSubreg(int SRIdx, const SDLoc &DL, EVT VT,
1235 SDValue Operand, SDValue Subreg);
1236
1237 /// Get the specified node if it's already available, or else return NULL.
1238 SDNode *getNodeIfExists(unsigned Opcode, SDVTList VTList, ArrayRef<SDValue> Ops,
1239 const SDNodeFlags Flags = SDNodeFlags());
1240
1241 /// Creates a SDDbgValue node.
1242 SDDbgValue *getDbgValue(DIVariable *Var, DIExpression *Expr, SDNode *N,
1243 unsigned R, bool IsIndirect, const DebugLoc &DL,
1244 unsigned O);
1245
1246 /// Creates a constant SDDbgValue node.
1247 SDDbgValue *getConstantDbgValue(DIVariable *Var, DIExpression *Expr,
1248 const Value *C, const DebugLoc &DL,
1249 unsigned O);
1250
1251 /// Creates a FrameIndex SDDbgValue node.
1252 SDDbgValue *getFrameIndexDbgValue(DIVariable *Var, DIExpression *Expr,
1253 unsigned FI, bool IsIndirect,
1254 const DebugLoc &DL, unsigned O);
1255
1256 /// Creates a VReg SDDbgValue node.
1257 SDDbgValue *getVRegDbgValue(DIVariable *Var, DIExpression *Expr,
1258 unsigned VReg, bool IsIndirect,
1259 const DebugLoc &DL, unsigned O);
1260
1261 /// Creates a SDDbgLabel node.
1262 SDDbgLabel *getDbgLabel(DILabel *Label, const DebugLoc &DL, unsigned O);
1263
1264 /// Transfer debug values from one node to another, while optionally
1265 /// generating fragment expressions for split-up values. If \p InvalidateDbg
1266 /// is set, debug values are invalidated after they are transferred.
1267 void transferDbgValues(SDValue From, SDValue To, unsigned OffsetInBits = 0,
1268 unsigned SizeInBits = 0, bool InvalidateDbg = true);
1269
1270 /// Remove the specified node from the system. If any of its
1271 /// operands then becomes dead, remove them as well. Inform UpdateListener
1272 /// for each node deleted.
1273 void RemoveDeadNode(SDNode *N);
1274
1275 /// This method deletes the unreachable nodes in the
1276 /// given list, and any nodes that become unreachable as a result.
1277 void RemoveDeadNodes(SmallVectorImpl<SDNode *> &DeadNodes);
1278
1279 /// Modify anything using 'From' to use 'To' instead.
1280 /// This can cause recursive merging of nodes in the DAG. Use the first
1281 /// version if 'From' is known to have a single result, use the second
1282 /// if you have two nodes with identical results (or if 'To' has a superset
1283 /// of the results of 'From'), use the third otherwise.
1284 ///
1285 /// These methods all take an optional UpdateListener, which (if not null) is
1286 /// informed about nodes that are deleted and modified due to recursive
1287 /// changes in the dag.
1288 ///
1289 /// These functions only replace all existing uses. It's possible that as
1290 /// these replacements are being performed, CSE may cause the From node
1291 /// to be given new uses. These new uses of From are left in place, and
1292 /// not automatically transferred to To.
1293 ///
1294 void ReplaceAllUsesWith(SDValue From, SDValue To);
1295 void ReplaceAllUsesWith(SDNode *From, SDNode *To);
1296 void ReplaceAllUsesWith(SDNode *From, const SDValue *To);
1297
1298 /// Replace any uses of From with To, leaving
1299 /// uses of other values produced by From.getNode() alone.
1300 void ReplaceAllUsesOfValueWith(SDValue From, SDValue To);
1301
1302 /// Like ReplaceAllUsesOfValueWith, but for multiple values at once.
1303 /// This correctly handles the case where
1304 /// there is an overlap between the From values and the To values.
1305 void ReplaceAllUsesOfValuesWith(const SDValue *From, const SDValue *To,
1306 unsigned Num);
1307
1308 /// If an existing load has uses of its chain, create a token factor node with
1309 /// that chain and the new memory node's chain and update users of the old
1310 /// chain to the token factor. This ensures that the new memory node will have
1311 /// the same relative memory dependency position as the old load. Returns the
1312 /// new merged load chain.
1313 SDValue makeEquivalentMemoryOrdering(LoadSDNode *Old, SDValue New);
1314
1315 /// Topological-sort the AllNodes list and a
1316 /// assign a unique node id for each node in the DAG based on their
1317 /// topological order. Returns the number of nodes.
1318 unsigned AssignTopologicalOrder();
1319
1320 /// Move node N in the AllNodes list to be immediately
1321 /// before the given iterator Position. This may be used to update the
1322 /// topological ordering when the list of nodes is modified.
1323 void RepositionNode(allnodes_iterator Position, SDNode *N) {
1324 AllNodes.insert(Position, AllNodes.remove(N));
1325 }
1326
1327 /// Returns an APFloat semantics tag appropriate for the given type. If VT is
1328 /// a vector type, the element semantics are returned.
1329 static const fltSemantics &EVTToAPFloatSemantics(EVT VT) {
1330 switch (VT.getScalarType().getSimpleVT().SimpleTy) {
1331 default: llvm_unreachable("Unknown FP format")::llvm::llvm_unreachable_internal("Unknown FP format", "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAG.h"
, 1331)
;
1332 case MVT::f16: return APFloat::IEEEhalf();
1333 case MVT::f32: return APFloat::IEEEsingle();
1334 case MVT::f64: return APFloat::IEEEdouble();
1335 case MVT::f80: return APFloat::x87DoubleExtended();
1336 case MVT::f128: return APFloat::IEEEquad();
1337 case MVT::ppcf128: return APFloat::PPCDoubleDouble();
1338 }
1339 }
1340
1341 /// Add a dbg_value SDNode. If SD is non-null that means the
1342 /// value is produced by SD.
1343 void AddDbgValue(SDDbgValue *DB, SDNode *SD, bool isParameter);
1344
1345 /// Add a dbg_label SDNode.
1346 void AddDbgLabel(SDDbgLabel *DB);
1347
1348 /// Get the debug values which reference the given SDNode.
1349 ArrayRef<SDDbgValue*> GetDbgValues(const SDNode* SD) const {
1350 return DbgInfo->getSDDbgValues(SD);
1351 }
1352
1353public:
1354 /// Return true if there are any SDDbgValue nodes associated
1355 /// with this SelectionDAG.
1356 bool hasDebugValues() const { return !DbgInfo->empty(); }
1357
1358 SDDbgInfo::DbgIterator DbgBegin() { return DbgInfo->DbgBegin(); }
1359 SDDbgInfo::DbgIterator DbgEnd() { return DbgInfo->DbgEnd(); }
1360
1361 SDDbgInfo::DbgIterator ByvalParmDbgBegin() {
1362 return DbgInfo->ByvalParmDbgBegin();
1363 }
1364
1365 SDDbgInfo::DbgIterator ByvalParmDbgEnd() {
1366 return DbgInfo->ByvalParmDbgEnd();
1367 }
1368
1369 SDDbgInfo::DbgLabelIterator DbgLabelBegin() {
1370 return DbgInfo->DbgLabelBegin();
1371 }
1372 SDDbgInfo::DbgLabelIterator DbgLabelEnd() {
1373 return DbgInfo->DbgLabelEnd();
1374 }
1375
1376 /// To be invoked on an SDNode that is slated to be erased. This
1377 /// function mirrors \c llvm::salvageDebugInfo.
1378 void salvageDebugInfo(SDNode &N);
1379
1380 void dump() const;
1381
1382 /// Create a stack temporary, suitable for holding the specified value type.
1383 /// If minAlign is specified, the slot size will have at least that alignment.
1384 SDValue CreateStackTemporary(EVT VT, unsigned minAlign = 1);
1385
1386 /// Create a stack temporary suitable for holding either of the specified
1387 /// value types.
1388 SDValue CreateStackTemporary(EVT VT1, EVT VT2);
1389
1390 SDValue FoldSymbolOffset(unsigned Opcode, EVT VT,
1391 const GlobalAddressSDNode *GA,
1392 const SDNode *N2);
1393
1394 SDValue FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL, EVT VT,
1395 SDNode *Cst1, SDNode *Cst2);
1396
1397 SDValue FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL, EVT VT,
1398 const ConstantSDNode *Cst1,
1399 const ConstantSDNode *Cst2);
1400
1401 SDValue FoldConstantVectorArithmetic(unsigned Opcode, const SDLoc &DL, EVT VT,
1402 ArrayRef<SDValue> Ops,
1403 const SDNodeFlags Flags = SDNodeFlags());
1404
1405 /// Constant fold a setcc to true or false.
1406 SDValue FoldSetCC(EVT VT, SDValue N1, SDValue N2, ISD::CondCode Cond,
1407 const SDLoc &dl);
1408
1409 /// See if the specified operand can be simplified with the knowledge that only
1410 /// the bits specified by Mask are used. If so, return the simpler operand,
1411 /// otherwise return a null SDValue.
1412 ///
1413 /// (This exists alongside SimplifyDemandedBits because GetDemandedBits can
1414 /// simplify nodes with multiple uses more aggressively.)
1415 SDValue GetDemandedBits(SDValue V, const APInt &Mask);
1416
1417 /// Return true if the sign bit of Op is known to be zero.
1418 /// We use this predicate to simplify operations downstream.
1419 bool SignBitIsZero(SDValue Op, unsigned Depth = 0) const;
1420
1421 /// Return true if 'Op & Mask' is known to be zero. We
1422 /// use this predicate to simplify operations downstream. Op and Mask are
1423 /// known to be the same type.
1424 bool MaskedValueIsZero(SDValue Op, const APInt &Mask, unsigned Depth = 0)
1425 const;
1426
1427 /// Determine which bits of Op are known to be either zero or one and return
1428 /// them in Known. For vectors, the known bits are those that are shared by
1429 /// every vector element.
1430 /// Targets can implement the computeKnownBitsForTargetNode method in the
1431 /// TargetLowering class to allow target nodes to be understood.
1432 KnownBits computeKnownBits(SDValue Op, unsigned Depth = 0) const;
1433
1434 /// Determine which bits of Op are known to be either zero or one and return
1435 /// them in Known. The DemandedElts argument allows us to only collect the
1436 /// known bits that are shared by the requested vector elements.
1437 /// Targets can implement the computeKnownBitsForTargetNode method in the
1438 /// TargetLowering class to allow target nodes to be understood.
1439 KnownBits computeKnownBits(SDValue Op, const APInt &DemandedElts,
1440 unsigned Depth = 0) const;
1441
1442 /// Used to represent the possible overflow behavior of an operation.
1443 /// Never: the operation cannot overflow.
1444 /// Always: the operation will always overflow.
1445 /// Sometime: the operation may or may not overflow.
1446 enum OverflowKind {
1447 OFK_Never,
1448 OFK_Sometime,
1449 OFK_Always,
1450 };
1451
1452 /// Determine if the result of the addition of 2 node can overflow.
1453 OverflowKind computeOverflowKind(SDValue N0, SDValue N1) const;
1454
1455 /// Test if the given value is known to have exactly one bit set. This differs
1456 /// from computeKnownBits in that it doesn't necessarily determine which bit
1457 /// is set.
1458 bool isKnownToBeAPowerOfTwo(SDValue Val) const;
1459
1460 /// Return the number of times the sign bit of the register is replicated into
1461 /// the other bits. We know that at least 1 bit is always equal to the sign
1462 /// bit (itself), but other cases can give us information. For example,
1463 /// immediately after an "SRA X, 2", we know that the top 3 bits are all equal
1464 /// to each other, so we return 3. Targets can implement the
1465 /// ComputeNumSignBitsForTarget method in the TargetLowering class to allow
1466 /// target nodes to be understood.
1467 unsigned ComputeNumSignBits(SDValue Op, unsigned Depth = 0) const;
1468
1469 /// Return the number of times the sign bit of the register is replicated into
1470 /// the other bits. We know that at least 1 bit is always equal to the sign
1471 /// bit (itself), but other cases can give us information. For example,
1472 /// immediately after an "SRA X, 2", we know that the top 3 bits are all equal
1473 /// to each other, so we return 3. The DemandedElts argument allows
1474 /// us to only collect the minimum sign bits of the requested vector elements.
1475 /// Targets can implement the ComputeNumSignBitsForTarget method in the
1476 /// TargetLowering class to allow target nodes to be understood.
1477 unsigned ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
1478 unsigned Depth = 0) const;
1479
1480 /// Return true if the specified operand is an ISD::ADD with a ConstantSDNode
1481 /// on the right-hand side, or if it is an ISD::OR with a ConstantSDNode that
1482 /// is guaranteed to have the same semantics as an ADD. This handles the
1483 /// equivalence:
1484 /// X|Cst == X+Cst iff X&Cst = 0.
1485 bool isBaseWithConstantOffset(SDValue Op) const;
1486
1487 /// Test whether the given SDValue is known to never be NaN. If \p SNaN is
1488 /// true, returns if \p Op is known to never be a signaling NaN (it may still
1489 /// be a qNaN).
1490 bool isKnownNeverNaN(SDValue Op, bool SNaN = false, unsigned Depth = 0) const;
1491
1492 /// \returns true if \p Op is known to never be a signaling NaN.
1493 bool isKnownNeverSNaN(SDValue Op, unsigned Depth = 0) const {
1494 return isKnownNeverNaN(Op, true, Depth);
1495 }
1496
1497 /// Test whether the given floating point SDValue is known to never be
1498 /// positive or negative zero.
1499 bool isKnownNeverZeroFloat(SDValue Op) const;
1500
1501 /// Test whether the given SDValue is known to contain non-zero value(s).
1502 bool isKnownNeverZero(SDValue Op) const;
1503
1504 /// Test whether two SDValues are known to compare equal. This
1505 /// is true if they are the same value, or if one is negative zero and the
1506 /// other positive zero.
1507 bool isEqualTo(SDValue A, SDValue B) const;
1508
1509 /// Return true if A and B have no common bits set. As an example, this can
1510 /// allow an 'add' to be transformed into an 'or'.
1511 bool haveNoCommonBitsSet(SDValue A, SDValue B) const;
1512
1513 /// Test whether \p V has a splatted value for all the demanded elements.
1514 ///
1515 /// On success \p UndefElts will indicate the elements that have UNDEF
1516 /// values instead of the splat value, this is only guaranteed to be correct
1517 /// for \p DemandedElts.
1518 ///
1519 /// NOTE: The function will return true for a demanded splat of UNDEF values.
1520 bool isSplatValue(SDValue V, const APInt &DemandedElts, APInt &UndefElts);
1521
1522 /// Test whether \p V has a splatted value.
1523 bool isSplatValue(SDValue V, bool AllowUndefs = false);
1524
1525 /// Match a binop + shuffle pyramid that represents a horizontal reduction
1526 /// over the elements of a vector starting from the EXTRACT_VECTOR_ELT node /p
1527 /// Extract. The reduction must use one of the opcodes listed in /p
1528 /// CandidateBinOps and on success /p BinOp will contain the matching opcode.
1529 /// Returns the vector that is being reduced on, or SDValue() if a reduction
1530 /// was not matched.
1531 SDValue matchBinOpReduction(SDNode *Extract, ISD::NodeType &BinOp,
1532 ArrayRef<ISD::NodeType> CandidateBinOps);
1533
1534 /// Utility function used by legalize and lowering to
1535 /// "unroll" a vector operation by splitting out the scalars and operating
1536 /// on each element individually. If the ResNE is 0, fully unroll the vector
1537 /// op. If ResNE is less than the width of the vector op, unroll up to ResNE.
1538 /// If the ResNE is greater than the width of the vector op, unroll the
1539 /// vector op and fill the end of the resulting vector with UNDEFS.
1540 SDValue UnrollVectorOp(SDNode *N, unsigned ResNE = 0);
1541
1542 /// Return true if loads are next to each other and can be
1543 /// merged. Check that both are nonvolatile and if LD is loading
1544 /// 'Bytes' bytes from a location that is 'Dist' units away from the
1545 /// location that the 'Base' load is loading from.
1546 bool areNonVolatileConsecutiveLoads(LoadSDNode *LD, LoadSDNode *Base,
1547 unsigned Bytes, int Dist) const;
1548
1549 /// Infer alignment of a load / store address. Return 0 if
1550 /// it cannot be inferred.
1551 unsigned InferPtrAlignment(SDValue Ptr) const;
1552
1553 /// Compute the VTs needed for the low/hi parts of a type
1554 /// which is split (or expanded) into two not necessarily identical pieces.
1555 std::pair<EVT, EVT> GetSplitDestVTs(const EVT &VT) const;
1556
1557 /// Split the vector with EXTRACT_SUBVECTOR using the provides
1558 /// VTs and return the low/high part.
1559 std::pair<SDValue, SDValue> SplitVector(const SDValue &N, const SDLoc &DL,
1560 const EVT &LoVT, const EVT &HiVT);
1561
1562 /// Split the vector with EXTRACT_SUBVECTOR and return the low/high part.
1563 std::pair<SDValue, SDValue> SplitVector(const SDValue &N, const SDLoc &DL) {
1564 EVT LoVT, HiVT;
1565 std::tie(LoVT, HiVT) = GetSplitDestVTs(N.getValueType());
1566 return SplitVector(N, DL, LoVT, HiVT);
1567 }
1568
1569 /// Split the node's operand with EXTRACT_SUBVECTOR and
1570 /// return the low/high part.
1571 std::pair<SDValue, SDValue> SplitVectorOperand(const SDNode *N, unsigned OpNo)
1572 {
1573 return SplitVector(N->getOperand(OpNo), SDLoc(N));
1574 }
1575
1576 /// Append the extracted elements from Start to Count out of the vector Op
1577 /// in Args. If Count is 0, all of the elements will be extracted.
1578 void ExtractVectorElements(SDValue Op, SmallVectorImpl<SDValue> &Args,
1579 unsigned Start = 0, unsigned Count = 0);
1580
1581 /// Compute the default alignment value for the given type.
1582 unsigned getEVTAlignment(EVT MemoryVT) const;
1583
1584 /// Test whether the given value is a constant int or similar node.
1585 SDNode *isConstantIntBuildVectorOrConstantInt(SDValue N);
1586
1587 /// Test whether the given value is a constant FP or similar node.
1588 SDNode *isConstantFPBuildVectorOrConstantFP(SDValue N);
1589
1590 /// \returns true if \p N is any kind of constant or build_vector of
1591 /// constants, int or float. If a vector, it may not necessarily be a splat.
1592 inline bool isConstantValueOfAnyType(SDValue N) {
1593 return isConstantIntBuildVectorOrConstantInt(N) ||
1594 isConstantFPBuildVectorOrConstantFP(N);
1595 }
1596
1597private:
1598 void InsertNode(SDNode *N);
1599 bool RemoveNodeFromCSEMaps(SDNode *N);
1600 void AddModifiedNodeToCSEMaps(SDNode *N);
1601 SDNode *FindModifiedNodeSlot(SDNode *N, SDValue Op, void *&InsertPos);
1602 SDNode *FindModifiedNodeSlot(SDNode *N, SDValue Op1, SDValue Op2,
1603 void *&InsertPos);
1604 SDNode *FindModifiedNodeSlot(SDNode *N, ArrayRef<SDValue> Ops,
1605 void *&InsertPos);
1606 SDNode *UpdateSDLocOnMergeSDNode(SDNode *N, const SDLoc &loc);
1607
1608 void DeleteNodeNotInCSEMaps(SDNode *N);
1609 void DeallocateNode(SDNode *N);
1610
1611 void allnodes_clear();
1612
1613 /// Look up the node specified by ID in CSEMap. If it exists, return it. If
1614 /// not, return the insertion token that will make insertion faster. This
1615 /// overload is for nodes other than Constant or ConstantFP, use the other one
1616 /// for those.
1617 SDNode *FindNodeOrInsertPos(const FoldingSetNodeID &ID, void *&InsertPos);
1618
1619 /// Look up the node specified by ID in CSEMap. If it exists, return it. If
1620 /// not, return the insertion token that will make insertion faster. Performs
1621 /// additional processing for constant nodes.
1622 SDNode *FindNodeOrInsertPos(const FoldingSetNodeID &ID, const SDLoc &DL,
1623 void *&InsertPos);
1624
1625 /// List of non-single value types.
1626 FoldingSet<SDVTListNode> VTListMap;
1627
1628 /// Maps to auto-CSE operations.
1629 std::vector<CondCodeSDNode*> CondCodeNodes;
1630
1631 std::vector<SDNode*> ValueTypeNodes;
1632 std::map<EVT, SDNode*, EVT::compareRawBits> ExtendedValueTypeNodes;
1633 StringMap<SDNode*> ExternalSymbols;
1634
1635 std::map<std::pair<std::string, unsigned char>,SDNode*> TargetExternalSymbols;
1636 DenseMap<MCSymbol *, SDNode *> MCSymbols;
1637};
1638
1639template <> struct GraphTraits<SelectionDAG*> : public GraphTraits<SDNode*> {
1640 using nodes_iterator = pointer_iterator<SelectionDAG::allnodes_iterator>;
1641
1642 static nodes_iterator nodes_begin(SelectionDAG *G) {
1643 return nodes_iterator(G->allnodes_begin());
1644 }
1645
1646 static nodes_iterator nodes_end(SelectionDAG *G) {
1647 return nodes_iterator(G->allnodes_end());
1648 }
1649};
1650
1651template <class TargetMemSDNode>
1652SDValue SelectionDAG::getTargetMemSDNode(SDVTList VTs,
1653 ArrayRef<SDValue> Ops,
1654 const SDLoc &dl, EVT MemVT,
1655 MachineMemOperand *MMO) {
1656 /// Compose node ID and try to find an existing node.
1657 FoldingSetNodeID ID;
1658 unsigned Opcode =
1659 TargetMemSDNode(dl.getIROrder(), DebugLoc(), VTs, MemVT, MMO).getOpcode();
1660 ID.AddInteger(Opcode);
1661 ID.AddPointer(VTs.VTs);
1662 for (auto& Op : Ops) {
1663 ID.AddPointer(Op.getNode());
1664 ID.AddInteger(Op.getResNo());
1665 }
1666 ID.AddInteger(MemVT.getRawBits());
1667 ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
1668 ID.AddInteger(getSyntheticNodeSubclassData<TargetMemSDNode>(
1669 dl.getIROrder(), VTs, MemVT, MMO));
1670
1671 void *IP = nullptr;
1672 if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP)) {
1673 cast<TargetMemSDNode>(E)->refineAlignment(MMO);
1674 return SDValue(E, 0);
1675 }
1676
1677 /// Existing node was not found. Create a new one.
1678 auto *N = newSDNode<TargetMemSDNode>(dl.getIROrder(), dl.getDebugLoc(), VTs,
1679 MemVT, MMO);
1680 createOperands(N, Ops);
1681 CSEMap.InsertNode(N, IP);
1682 InsertNode(N);
1683 return SDValue(N, 0);
1684}
1685
1686} // end namespace llvm
1687
1688#endif // LLVM_CODEGEN_SELECTIONDAG_H

/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAGNodes.h

1//===- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ----*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file declares the SDNode class and derived classes, which are used to
11// represent the nodes and operations present in a SelectionDAG. These nodes
12// and operations are machine code level operations, with some similarities to
13// the GCC RTL representation.
14//
15// Clients should include the SelectionDAG.h file instead of this file directly.
16//
17//===----------------------------------------------------------------------===//
18
19#ifndef LLVM_CODEGEN_SELECTIONDAGNODES_H
20#define LLVM_CODEGEN_SELECTIONDAGNODES_H
21
22#include "llvm/ADT/APFloat.h"
23#include "llvm/ADT/ArrayRef.h"
24#include "llvm/ADT/BitVector.h"
25#include "llvm/ADT/FoldingSet.h"
26#include "llvm/ADT/GraphTraits.h"
27#include "llvm/ADT/SmallPtrSet.h"
28#include "llvm/ADT/SmallVector.h"
29#include "llvm/ADT/ilist_node.h"
30#include "llvm/ADT/iterator.h"
31#include "llvm/ADT/iterator_range.h"
32#include "llvm/CodeGen/ISDOpcodes.h"
33#include "llvm/CodeGen/MachineMemOperand.h"
34#include "llvm/CodeGen/ValueTypes.h"
35#include "llvm/IR/Constants.h"
36#include "llvm/IR/DebugLoc.h"
37#include "llvm/IR/Instruction.h"
38#include "llvm/IR/Instructions.h"
39#include "llvm/IR/Metadata.h"
40#include "llvm/IR/Operator.h"
41#include "llvm/Support/AlignOf.h"
42#include "llvm/Support/AtomicOrdering.h"
43#include "llvm/Support/Casting.h"
44#include "llvm/Support/ErrorHandling.h"
45#include "llvm/Support/MachineValueType.h"
46#include <algorithm>
47#include <cassert>
48#include <climits>
49#include <cstddef>
50#include <cstdint>
51#include <cstring>
52#include <iterator>
53#include <string>
54#include <tuple>
55
56namespace llvm {
57
58class APInt;
59class Constant;
60template <typename T> struct DenseMapInfo;
61class GlobalValue;
62class MachineBasicBlock;
63class MachineConstantPoolValue;
64class MCSymbol;
65class raw_ostream;
66class SDNode;
67class SelectionDAG;
68class Type;
69class Value;
70
71void checkForCycles(const SDNode *N, const SelectionDAG *DAG = nullptr,
72 bool force = false);
73
74/// This represents a list of ValueType's that has been intern'd by
75/// a SelectionDAG. Instances of this simple value class are returned by
76/// SelectionDAG::getVTList(...).
77///
78struct SDVTList {
79 const EVT *VTs;
80 unsigned int NumVTs;
81};
82
83namespace ISD {
84
85 /// Node predicates
86
87 /// If N is a BUILD_VECTOR node whose elements are all the same constant or
88 /// undefined, return true and return the constant value in \p SplatValue.
89 bool isConstantSplatVector(const SDNode *N, APInt &SplatValue);
90
91 /// Return true if the specified node is a BUILD_VECTOR where all of the
92 /// elements are ~0 or undef.
93 bool isBuildVectorAllOnes(const SDNode *N);
94
95 /// Return true if the specified node is a BUILD_VECTOR where all of the
96 /// elements are 0 or undef.
97 bool isBuildVectorAllZeros(const SDNode *N);
98
99 /// Return true if the specified node is a BUILD_VECTOR node of all
100 /// ConstantSDNode or undef.
101 bool isBuildVectorOfConstantSDNodes(const SDNode *N);
102
103 /// Return true if the specified node is a BUILD_VECTOR node of all
104 /// ConstantFPSDNode or undef.
105 bool isBuildVectorOfConstantFPSDNodes(const SDNode *N);
106
107 /// Return true if the node has at least one operand and all operands of the
108 /// specified node are ISD::UNDEF.
109 bool allOperandsUndef(const SDNode *N);
110
111} // end namespace ISD
112
113//===----------------------------------------------------------------------===//
114/// Unlike LLVM values, Selection DAG nodes may return multiple
115/// values as the result of a computation. Many nodes return multiple values,
116/// from loads (which define a token and a return value) to ADDC (which returns
117/// a result and a carry value), to calls (which may return an arbitrary number
118/// of values).
119///
120/// As such, each use of a SelectionDAG computation must indicate the node that
121/// computes it as well as which return value to use from that node. This pair
122/// of information is represented with the SDValue value type.
123///
124class SDValue {
125 friend struct DenseMapInfo<SDValue>;
126
127 SDNode *Node = nullptr; // The node defining the value we are using.
128 unsigned ResNo = 0; // Which return value of the node we are using.
129
130public:
131 SDValue() = default;
132 SDValue(SDNode *node, unsigned resno);
133
134 /// get the index which selects a specific result in the SDNode
135 unsigned getResNo() const { return ResNo; }
136
137 /// get the SDNode which holds the desired result
138 SDNode *getNode() const { return Node; }
139
140 /// set the SDNode
141 void setNode(SDNode *N) { Node = N; }
142
143 inline SDNode *operator->() const { return Node; }
144
145 bool operator==(const SDValue &O) const {
146 return Node == O.Node && ResNo == O.ResNo;
147 }
148 bool operator!=(const SDValue &O) const {
149 return !operator==(O);
150 }
151 bool operator<(const SDValue &O) const {
152 return std::tie(Node, ResNo) < std::tie(O.Node, O.ResNo);
153 }
154 explicit operator bool() const {
155 return Node != nullptr;
156 }
157
158 SDValue getValue(unsigned R) const {
159 return SDValue(Node, R);
160 }
161
162 /// Return true if this node is an operand of N.
163 bool isOperandOf(const SDNode *N) const;
164
165 /// Return the ValueType of the referenced return value.
166 inline EVT getValueType() const;
167
168 /// Return the simple ValueType of the referenced return value.
169 MVT getSimpleValueType() const {
170 return getValueType().getSimpleVT();
171 }
172
173 /// Returns the size of the value in bits.
174 unsigned getValueSizeInBits() const {
175 return getValueType().getSizeInBits();
176 }
177
178 unsigned getScalarValueSizeInBits() const {
179 return getValueType().getScalarType().getSizeInBits();
180 }
181
182 // Forwarding methods - These forward to the corresponding methods in SDNode.
183 inline unsigned getOpcode() const;
184 inline unsigned getNumOperands() const;
185 inline const SDValue &getOperand(unsigned i) const;
186 inline uint64_t getConstantOperandVal(unsigned i) const;
187 inline bool isTargetMemoryOpcode() const;
188 inline bool isTargetOpcode() const;
189 inline bool isMachineOpcode() const;
190 inline bool isUndef() const;
191 inline unsigned getMachineOpcode() const;
192 inline const DebugLoc &getDebugLoc() const;
193 inline void dump() const;
194 inline void dump(const SelectionDAG *G) const;
195 inline void dumpr() const;
196 inline void dumpr(const SelectionDAG *G) const;
197
198 /// Return true if this operand (which must be a chain) reaches the
199 /// specified operand without crossing any side-effecting instructions.
200 /// In practice, this looks through token factors and non-volatile loads.
201 /// In order to remain efficient, this only
202 /// looks a couple of nodes in, it does not do an exhaustive search.
203 bool reachesChainWithoutSideEffects(SDValue Dest,
204 unsigned Depth = 2) const;
205
206 /// Return true if there are no nodes using value ResNo of Node.
207 inline bool use_empty() const;
208
209 /// Return true if there is exactly one node using value ResNo of Node.
210 inline bool hasOneUse() const;
211};
212
213template<> struct DenseMapInfo<SDValue> {
214 static inline SDValue getEmptyKey() {
215 SDValue V;
216 V.ResNo = -1U;
217 return V;
218 }
219
220 static inline SDValue getTombstoneKey() {
221 SDValue V;
222 V.ResNo = -2U;
223 return V;
224 }
225
226 static unsigned getHashValue(const SDValue &Val) {
227 return ((unsigned)((uintptr_t)Val.getNode() >> 4) ^
228 (unsigned)((uintptr_t)Val.getNode() >> 9)) + Val.getResNo();
229 }
230
231 static bool isEqual(const SDValue &LHS, const SDValue &RHS) {
232 return LHS == RHS;
233 }
234};
235template <> struct isPodLike<SDValue> { static const bool value = true; };
236
237/// Allow casting operators to work directly on
238/// SDValues as if they were SDNode*'s.
239template<> struct simplify_type<SDValue> {
240 using SimpleType = SDNode *;
241
242 static SimpleType getSimplifiedValue(SDValue &Val) {
243 return Val.getNode();
244 }
245};
246template<> struct simplify_type<const SDValue> {
247 using SimpleType = /*const*/ SDNode *;
248
249 static SimpleType getSimplifiedValue(const SDValue &Val) {
250 return Val.getNode();
251 }
252};
253
254/// Represents a use of a SDNode. This class holds an SDValue,
255/// which records the SDNode being used and the result number, a
256/// pointer to the SDNode using the value, and Next and Prev pointers,
257/// which link together all the uses of an SDNode.
258///
259class SDUse {
260 /// Val - The value being used.
261 SDValue Val;
262 /// User - The user of this value.
263 SDNode *User = nullptr;
264 /// Prev, Next - Pointers to the uses list of the SDNode referred by
265 /// this operand.
266 SDUse **Prev = nullptr;
267 SDUse *Next = nullptr;
268
269public:
270 SDUse() = default;
271 SDUse(const SDUse &U) = delete;
272 SDUse &operator=(const SDUse &) = delete;
273
274 /// Normally SDUse will just implicitly convert to an SDValue that it holds.
275 operator const SDValue&() const { return Val; }
276
277 /// If implicit conversion to SDValue doesn't work, the get() method returns
278 /// the SDValue.
279 const SDValue &get() const { return Val; }
280
281 /// This returns the SDNode that contains this Use.
282 SDNode *getUser() { return User; }
283
284 /// Get the next SDUse in the use list.
285 SDUse *getNext() const { return Next; }
286
287 /// Convenience function for get().getNode().
288 SDNode *getNode() const { return Val.getNode(); }
289 /// Convenience function for get().getResNo().
290 unsigned getResNo() const { return Val.getResNo(); }
291 /// Convenience function for get().getValueType().
292 EVT getValueType() const { return Val.getValueType(); }
293
294 /// Convenience function for get().operator==
295 bool operator==(const SDValue &V) const {
296 return Val == V;
297 }
298
299 /// Convenience function for get().operator!=
300 bool operator!=(const SDValue &V) const {
301 return Val != V;
302 }
303
304 /// Convenience function for get().operator<
305 bool operator<(const SDValue &V) const {
306 return Val < V;
307 }
308
309private:
310 friend class SelectionDAG;
311 friend class SDNode;
312 // TODO: unfriend HandleSDNode once we fix its operand handling.
313 friend class HandleSDNode;
314
315 void setUser(SDNode *p) { User = p; }
316
317 /// Remove this use from its existing use list, assign it the
318 /// given value, and add it to the new value's node's use list.
319 inline void set(const SDValue &V);
320 /// Like set, but only supports initializing a newly-allocated
321 /// SDUse with a non-null value.
322 inline void setInitial(const SDValue &V);
323 /// Like set, but only sets the Node portion of the value,
324 /// leaving the ResNo portion unmodified.
325 inline void setNode(SDNode *N);
326
327 void addToList(SDUse **List) {
328 Next = *List;
329 if (Next) Next->Prev = &Next;
330 Prev = List;
331 *List = this;
332 }
333
334 void removeFromList() {
335 *Prev = Next;
336 if (Next) Next->Prev = Prev;
337 }
338};
339
340/// simplify_type specializations - Allow casting operators to work directly on
341/// SDValues as if they were SDNode*'s.
342template<> struct simplify_type<SDUse> {
343 using SimpleType = SDNode *;
344
345 static SimpleType getSimplifiedValue(SDUse &Val) {
346 return Val.getNode();
347 }
348};
349
350/// These are IR-level optimization flags that may be propagated to SDNodes.
351/// TODO: This data structure should be shared by the IR optimizer and the
352/// the backend.
353struct SDNodeFlags {
354private:
355 // This bit is used to determine if the flags are in a defined state.
356 // Flag bits can only be masked out during intersection if the masking flags
357 // are defined.
358 bool AnyDefined : 1;
359
360 bool NoUnsignedWrap : 1;
361 bool NoSignedWrap : 1;
362 bool Exact : 1;
363 bool NoNaNs : 1;
364 bool NoInfs : 1;
365 bool NoSignedZeros : 1;
366 bool AllowReciprocal : 1;
367 bool VectorReduction : 1;
368 bool AllowContract : 1;
369 bool ApproximateFuncs : 1;
370 bool AllowReassociation : 1;
371
372public:
373 /// Default constructor turns off all optimization flags.
374 SDNodeFlags()
375 : AnyDefined(false), NoUnsignedWrap(false), NoSignedWrap(false),
376 Exact(false), NoNaNs(false), NoInfs(false),
377 NoSignedZeros(false), AllowReciprocal(false), VectorReduction(false),
378 AllowContract(false), ApproximateFuncs(false),
379 AllowReassociation(false) {}
380
381 /// Propagate the fast-math-flags from an IR FPMathOperator.
382 void copyFMF(const FPMathOperator &FPMO) {
383 setNoNaNs(FPMO.hasNoNaNs());
384 setNoInfs(FPMO.hasNoInfs());
385 setNoSignedZeros(FPMO.hasNoSignedZeros());
386 setAllowReciprocal(FPMO.hasAllowReciprocal());
387 setAllowContract(FPMO.hasAllowContract());
388 setApproximateFuncs(FPMO.hasApproxFunc());
389 setAllowReassociation(FPMO.hasAllowReassoc());
390 }
391
392 /// Sets the state of the flags to the defined state.
393 void setDefined() { AnyDefined = true; }
394 /// Returns true if the flags are in a defined state.
395 bool isDefined() const { return AnyDefined; }
396
397 // These are mutators for each flag.
398 void setNoUnsignedWrap(bool b) {
399 setDefined();
400 NoUnsignedWrap = b;
401 }
402 void setNoSignedWrap(bool b) {
403 setDefined();
404 NoSignedWrap = b;
405 }
406 void setExact(bool b) {
407 setDefined();
408 Exact = b;
409 }
410 void setNoNaNs(bool b) {
411 setDefined();
412 NoNaNs = b;
413 }
414 void setNoInfs(bool b) {
415 setDefined();
416 NoInfs = b;
417 }
418 void setNoSignedZeros(bool b) {
419 setDefined();
420 NoSignedZeros = b;
421 }
422 void setAllowReciprocal(bool b) {
423 setDefined();
424 AllowReciprocal = b;
425 }
426 void setVectorReduction(bool b) {
427 setDefined();
428 VectorReduction = b;
429 }
430 void setAllowContract(bool b) {
431 setDefined();
432 AllowContract = b;
433 }
434 void setApproximateFuncs(bool b) {
435 setDefined();
436 ApproximateFuncs = b;
437 }
438 void setAllowReassociation(bool b) {
439 setDefined();
440 AllowReassociation = b;
441 }
442
443 // These are accessors for each flag.
444 bool hasNoUnsignedWrap() const { return NoUnsignedWrap; }
445 bool hasNoSignedWrap() const { return NoSignedWrap; }
446 bool hasExact() const { return Exact; }
447 bool hasNoNaNs() const { return NoNaNs; }
448 bool hasNoInfs() const { return NoInfs; }
449 bool hasNoSignedZeros() const { return NoSignedZeros; }
450 bool hasAllowReciprocal() const { return AllowReciprocal; }
451 bool hasVectorReduction() const { return VectorReduction; }
452 bool hasAllowContract() const { return AllowContract; }
453 bool hasApproximateFuncs() const { return ApproximateFuncs; }
454 bool hasAllowReassociation() const { return AllowReassociation; }
455
456 bool isFast() const {
457 return NoSignedZeros && AllowReciprocal && NoNaNs && NoInfs &&
458 AllowContract && ApproximateFuncs && AllowReassociation;
459 }
460
461 /// Clear any flags in this flag set that aren't also set in Flags.
462 /// If the given Flags are undefined then don't do anything.
463 void intersectWith(const SDNodeFlags Flags) {
464 if (!Flags.isDefined())
465 return;
466 NoUnsignedWrap &= Flags.NoUnsignedWrap;
467 NoSignedWrap &= Flags.NoSignedWrap;
468 Exact &= Flags.Exact;
469 NoNaNs &= Flags.NoNaNs;
470 NoInfs &= Flags.NoInfs;
471 NoSignedZeros &= Flags.NoSignedZeros;
472 AllowReciprocal &= Flags.AllowReciprocal;
473 VectorReduction &= Flags.VectorReduction;
474 AllowContract &= Flags.AllowContract;
475 ApproximateFuncs &= Flags.ApproximateFuncs;
476 AllowReassociation &= Flags.AllowReassociation;
477 }
478};
479
480/// Represents one node in the SelectionDAG.
481///
482class SDNode : public FoldingSetNode, public ilist_node<SDNode> {
483private:
484 /// The operation that this node performs.
485 int16_t NodeType;
486
487protected:
488 // We define a set of mini-helper classes to help us interpret the bits in our
489 // SubclassData. These are designed to fit within a uint16_t so they pack
490 // with NodeType.
491
492 class SDNodeBitfields {
493 friend class SDNode;
494 friend class MemIntrinsicSDNode;
495 friend class MemSDNode;
496 friend class SelectionDAG;
497
498 uint16_t HasDebugValue : 1;
499 uint16_t IsMemIntrinsic : 1;
500 uint16_t IsDivergent : 1;
501 };
502 enum { NumSDNodeBits = 3 };
503
504 class ConstantSDNodeBitfields {
505 friend class ConstantSDNode;
506
507 uint16_t : NumSDNodeBits;
508
509 uint16_t IsOpaque : 1;
510 };
511
512 class MemSDNodeBitfields {
513 friend class MemSDNode;
514 friend class MemIntrinsicSDNode;
515 friend class AtomicSDNode;
516
517 uint16_t : NumSDNodeBits;
518
519 uint16_t IsVolatile : 1;
520 uint16_t IsNonTemporal : 1;
521 uint16_t IsDereferenceable : 1;
522 uint16_t IsInvariant : 1;
523 };
524 enum { NumMemSDNodeBits = NumSDNodeBits + 4 };
525
526 class LSBaseSDNodeBitfields {
527 friend class LSBaseSDNode;
528
529 uint16_t : NumMemSDNodeBits;
530
531 uint16_t AddressingMode : 3; // enum ISD::MemIndexedMode
532 };
533 enum { NumLSBaseSDNodeBits = NumMemSDNodeBits + 3 };
534
535 class LoadSDNodeBitfields {
536 friend class LoadSDNode;
537 friend class MaskedLoadSDNode;
538
539 uint16_t : NumLSBaseSDNodeBits;
540
541 uint16_t ExtTy : 2; // enum ISD::LoadExtType
542 uint16_t IsExpanding : 1;
543 };
544
545 class StoreSDNodeBitfields {
546 friend class StoreSDNode;
547 friend class MaskedStoreSDNode;
548
549 uint16_t : NumLSBaseSDNodeBits;
550
551 uint16_t IsTruncating : 1;
552 uint16_t IsCompressing : 1;
553 };
554
555 union {
556 char RawSDNodeBits[sizeof(uint16_t)];
557 SDNodeBitfields SDNodeBits;
558 ConstantSDNodeBitfields ConstantSDNodeBits;
559 MemSDNodeBitfields MemSDNodeBits;
560 LSBaseSDNodeBitfields LSBaseSDNodeBits;
561 LoadSDNodeBitfields LoadSDNodeBits;
562 StoreSDNodeBitfields StoreSDNodeBits;
563 };
564
565 // RawSDNodeBits must cover the entirety of the union. This means that all of
566 // the union's members must have size <= RawSDNodeBits. We write the RHS as
567 // "2" instead of sizeof(RawSDNodeBits) because MSVC can't handle the latter.
568 static_assert(sizeof(SDNodeBitfields) <= 2, "field too wide");
569 static_assert(sizeof(ConstantSDNodeBitfields) <= 2, "field too wide");
570 static_assert(sizeof(MemSDNodeBitfields) <= 2, "field too wide");
571 static_assert(sizeof(LSBaseSDNodeBitfields) <= 2, "field too wide");
572 static_assert(sizeof(LoadSDNodeBitfields) <= 2, "field too wide");
573 static_assert(sizeof(StoreSDNodeBitfields) <= 2, "field too wide");
574
575private:
576 friend class SelectionDAG;
577 // TODO: unfriend HandleSDNode once we fix its operand handling.
578 friend class HandleSDNode;
579
580 /// Unique id per SDNode in the DAG.
581 int NodeId = -1;
582
583 /// The values that are used by this operation.
584 SDUse *OperandList = nullptr;
585
586 /// The types of the values this node defines. SDNode's may
587 /// define multiple values simultaneously.
588 const EVT *ValueList;
589
590 /// List of uses for this SDNode.
591 SDUse *UseList = nullptr;
592
593 /// The number of entries in the Operand/Value list.
594 unsigned short NumOperands = 0;
595 unsigned short NumValues;
596
597 // The ordering of the SDNodes. It roughly corresponds to the ordering of the
598 // original LLVM instructions.
599 // This is used for turning off scheduling, because we'll forgo
600 // the normal scheduling algorithms and output the instructions according to
601 // this ordering.
602 unsigned IROrder;
603
604 /// Source line information.
605 DebugLoc debugLoc;
606
607 /// Return a pointer to the specified value type.
608 static const EVT *getValueTypeList(EVT VT);
609
610 SDNodeFlags Flags;
611
612public:
613 /// Unique and persistent id per SDNode in the DAG.
614 /// Used for debug printing.
615 uint16_t PersistentId;
616
617 //===--------------------------------------------------------------------===//
618 // Accessors
619 //
620
621 /// Return the SelectionDAG opcode value for this node. For
622 /// pre-isel nodes (those for which isMachineOpcode returns false), these
623 /// are the opcode values in the ISD and <target>ISD namespaces. For
624 /// post-isel opcodes, see getMachineOpcode.
625 unsigned getOpcode() const { return (unsigned short)NodeType; }
626
627 /// Test if this node has a target-specific opcode (in the
628 /// \<target\>ISD namespace).
629 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
630
631 /// Test if this node has a target-specific
632 /// memory-referencing opcode (in the \<target\>ISD namespace and
633 /// greater than FIRST_TARGET_MEMORY_OPCODE).
634 bool isTargetMemoryOpcode() const {
635 return NodeType >= ISD::FIRST_TARGET_MEMORY_OPCODE;
636 }
637
638 /// Return true if the type of the node type undefined.
639 bool isUndef() const { return NodeType == ISD::UNDEF; }
640
641 /// Test if this node is a memory intrinsic (with valid pointer information).
642 /// INTRINSIC_W_CHAIN and INTRINSIC_VOID nodes are sometimes created for
643 /// non-memory intrinsics (with chains) that are not really instances of
644 /// MemSDNode. For such nodes, we need some extra state to determine the
645 /// proper classof relationship.
646 bool isMemIntrinsic() const {
647 return (NodeType == ISD::INTRINSIC_W_CHAIN ||
648 NodeType == ISD::INTRINSIC_VOID) &&
649 SDNodeBits.IsMemIntrinsic;
650 }
651
652 /// Test if this node is a strict floating point pseudo-op.
653 bool isStrictFPOpcode() {
654 switch (NodeType) {
655 default:
656 return false;
657 case ISD::STRICT_FADD:
658 case ISD::STRICT_FSUB:
659 case ISD::STRICT_FMUL:
660 case ISD::STRICT_FDIV:
661 case ISD::STRICT_FREM:
662 case ISD::STRICT_FMA:
663 case ISD::STRICT_FSQRT:
664 case ISD::STRICT_FPOW:
665 case ISD::STRICT_FPOWI:
666 case ISD::STRICT_FSIN:
667 case ISD::STRICT_FCOS:
668 case ISD::STRICT_FEXP:
669 case ISD::STRICT_FEXP2:
670 case ISD::STRICT_FLOG:
671 case ISD::STRICT_FLOG10:
672 case ISD::STRICT_FLOG2:
673 case ISD::STRICT_FRINT:
674 case ISD::STRICT_FNEARBYINT:
675 case ISD::STRICT_FMAXNUM:
676 case ISD::STRICT_FMINNUM:
677 case ISD::STRICT_FCEIL:
678 case ISD::STRICT_FFLOOR:
679 case ISD::STRICT_FROUND:
680 case ISD::STRICT_FTRUNC:
681 return true;
682 }
683 }
684
685 /// Test if this node has a post-isel opcode, directly
686 /// corresponding to a MachineInstr opcode.
687 bool isMachineOpcode() const { return NodeType < 0; }
688
689 /// This may only be called if isMachineOpcode returns
690 /// true. It returns the MachineInstr opcode value that the node's opcode
691 /// corresponds to.
692 unsigned getMachineOpcode() const {
693 assert(isMachineOpcode() && "Not a MachineInstr opcode!")((isMachineOpcode() && "Not a MachineInstr opcode!") ?
static_cast<void> (0) : __assert_fail ("isMachineOpcode() && \"Not a MachineInstr opcode!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAGNodes.h"
, 693, __PRETTY_FUNCTION__))
;
694 return ~NodeType;
695 }
696
697 bool getHasDebugValue() const { return SDNodeBits.HasDebugValue; }
698 void setHasDebugValue(bool b) { SDNodeBits.HasDebugValue = b; }
699
700 bool isDivergent() const { return SDNodeBits.IsDivergent; }
701
702 /// Return true if there are no uses of this node.
703 bool use_empty() const { return UseList == nullptr; }
704
705 /// Return true if there is exactly one use of this node.
706 bool hasOneUse() const {
707 return !use_empty() && std::next(use_begin()) == use_end();
708 }
709
710 /// Return the number of uses of this node. This method takes
711 /// time proportional to the number of uses.
712 size_t use_size() const { return std::distance(use_begin(), use_end()); }
713
714 /// Return the unique node id.
715 int getNodeId() const { return NodeId; }
716
717 /// Set unique node id.
718 void setNodeId(int Id) { NodeId = Id; }
719
720 /// Return the node ordering.
721 unsigned getIROrder() const { return IROrder; }
722
723 /// Set the node ordering.
724 void setIROrder(unsigned Order) { IROrder = Order; }
725
726 /// Return the source location info.
727 const DebugLoc &getDebugLoc() const { return debugLoc; }
728
729 /// Set source location info. Try to avoid this, putting
730 /// it in the constructor is preferable.
731 void setDebugLoc(DebugLoc dl) { debugLoc = std::move(dl); }
732
733 /// This class provides iterator support for SDUse
734 /// operands that use a specific SDNode.
735 class use_iterator
736 : public std::iterator<std::forward_iterator_tag, SDUse, ptrdiff_t> {
737 friend class SDNode;
738
739 SDUse *Op = nullptr;
740
741 explicit use_iterator(SDUse *op) : Op(op) {}
742
743 public:
744 using reference = std::iterator<std::forward_iterator_tag,
745 SDUse, ptrdiff_t>::reference;
746 using pointer = std::iterator<std::forward_iterator_tag,
747 SDUse, ptrdiff_t>::pointer;
748
749 use_iterator() = default;
750 use_iterator(const use_iterator &I) : Op(I.Op) {}
751
752 bool operator==(const use_iterator &x) const {
753 return Op == x.Op;
754 }
755 bool operator!=(const use_iterator &x) const {
756 return !operator==(x);
757 }
758
759 /// Return true if this iterator is at the end of uses list.
760 bool atEnd() const { return Op == nullptr; }
761
762 // Iterator traversal: forward iteration only.
763 use_iterator &operator++() { // Preincrement
764 assert(Op && "Cannot increment end iterator!")((Op && "Cannot increment end iterator!") ? static_cast
<void> (0) : __assert_fail ("Op && \"Cannot increment end iterator!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAGNodes.h"
, 764, __PRETTY_FUNCTION__))
;
765 Op = Op->getNext();
766 return *this;
767 }
768
769 use_iterator operator++(int) { // Postincrement
770 use_iterator tmp = *this; ++*this; return tmp;
771 }
772
773 /// Retrieve a pointer to the current user node.
774 SDNode *operator*() const {
775 assert(Op && "Cannot dereference end iterator!")((Op && "Cannot dereference end iterator!") ? static_cast
<void> (0) : __assert_fail ("Op && \"Cannot dereference end iterator!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAGNodes.h"
, 775, __PRETTY_FUNCTION__))
;
776 return Op->getUser();
777 }
778
779 SDNode *operator->() const { return operator*(); }
780
781 SDUse &getUse() const { return *Op; }
782
783 /// Retrieve the operand # of this use in its user.
784 unsigned getOperandNo() const {
785 assert(Op && "Cannot dereference end iterator!")((Op && "Cannot dereference end iterator!") ? static_cast
<void> (0) : __assert_fail ("Op && \"Cannot dereference end iterator!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAGNodes.h"
, 785, __PRETTY_FUNCTION__))
;
786 return (unsigned)(Op - Op->getUser()->OperandList);
787 }
788 };
789
790 /// Provide iteration support to walk over all uses of an SDNode.
791 use_iterator use_begin() const {
792 return use_iterator(UseList);
793 }
794
795 static use_iterator use_end() { return use_iterator(nullptr); }
796
797 inline iterator_range<use_iterator> uses() {
798 return make_range(use_begin(), use_end());
799 }
800 inline iterator_range<use_iterator> uses() const {
801 return make_range(use_begin(), use_end());
802 }
803
804 /// Return true if there are exactly NUSES uses of the indicated value.
805 /// This method ignores uses of other values defined by this operation.
806 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
807
808 /// Return true if there are any use of the indicated value.
809 /// This method ignores uses of other values defined by this operation.
810 bool hasAnyUseOfValue(unsigned Value) const;
811
812 /// Return true if this node is the only use of N.
813 bool isOnlyUserOf(const SDNode *N) const;
814
815 /// Return true if this node is an operand of N.
816 bool isOperandOf(const SDNode *N) const;
817
818 /// Return true if this node is a predecessor of N.
819 /// NOTE: Implemented on top of hasPredecessor and every bit as
820 /// expensive. Use carefully.
821 bool isPredecessorOf(const SDNode *N) const {
822 return N->hasPredecessor(this);
823 }
824
825 /// Return true if N is a predecessor of this node.
826 /// N is either an operand of this node, or can be reached by recursively
827 /// traversing up the operands.
828 /// NOTE: This is an expensive method. Use it carefully.
829 bool hasPredecessor(const SDNode *N) const;
830
831 /// Returns true if N is a predecessor of any node in Worklist. This
832 /// helper keeps Visited and Worklist sets externally to allow unions
833 /// searches to be performed in parallel, caching of results across
834 /// queries and incremental addition to Worklist. Stops early if N is
835 /// found but will resume. Remember to clear Visited and Worklists
836 /// if DAG changes. MaxSteps gives a maximum number of nodes to visit before
837 /// giving up. The TopologicalPrune flag signals that positive NodeIds are
838 /// topologically ordered (Operands have strictly smaller node id) and search
839 /// can be pruned leveraging this.
840 static bool hasPredecessorHelper(const SDNode *N,
841 SmallPtrSetImpl<const SDNode *> &Visited,
842 SmallVectorImpl<const SDNode *> &Worklist,
843 unsigned int MaxSteps = 0,
844 bool TopologicalPrune = false) {
845 SmallVector<const SDNode *, 8> DeferredNodes;
846 if (Visited.count(N))
847 return true;
848
849 // Node Id's are assigned in three places: As a topological
850 // ordering (> 0), during legalization (results in values set to
851 // 0), new nodes (set to -1). If N has a topolgical id then we
852 // know that all nodes with ids smaller than it cannot be
853 // successors and we need not check them. Filter out all node
854 // that can't be matches. We add them to the worklist before exit
855 // in case of multiple calls. Note that during selection the topological id
856 // may be violated if a node's predecessor is selected before it. We mark
857 // this at selection negating the id of unselected successors and
858 // restricting topological pruning to positive ids.
859
860 int NId = N->getNodeId();
861 // If we Invalidated the Id, reconstruct original NId.
862 if (NId < -1)
863 NId = -(NId + 1);
864
865 bool Found = false;
866 while (!Worklist.empty()) {
867 const SDNode *M = Worklist.pop_back_val();
868 int MId = M->getNodeId();
869 if (TopologicalPrune && M->getOpcode() != ISD::TokenFactor && (NId > 0) &&
870 (MId > 0) && (MId < NId)) {
871 DeferredNodes.push_back(M);
872 continue;
873 }
874 for (const SDValue &OpV : M->op_values()) {
875 SDNode *Op = OpV.getNode();
876 if (Visited.insert(Op).second)
877 Worklist.push_back(Op);
878 if (Op == N)
879 Found = true;
880 }
881 if (Found)
882 break;
883 if (MaxSteps != 0 && Visited.size() >= MaxSteps)
884 break;
885 }
886 // Push deferred nodes back on worklist.
887 Worklist.append(DeferredNodes.begin(), DeferredNodes.end());
888 // If we bailed early, conservatively return found.
889 if (MaxSteps != 0 && Visited.size() >= MaxSteps)
890 return true;
891 return Found;
892 }
893
894 /// Return true if all the users of N are contained in Nodes.
895 /// NOTE: Requires at least one match, but doesn't require them all.
896 static bool areOnlyUsersOf(ArrayRef<const SDNode *> Nodes, const SDNode *N);
897
898 /// Return the number of values used by this operation.
899 unsigned getNumOperands() const { return NumOperands; }
900
901 /// Helper method returns the integer value of a ConstantSDNode operand.
902 inline uint64_t getConstantOperandVal(unsigned Num) const;
903
904 const SDValue &getOperand(unsigned Num) const {
905 assert(Num < NumOperands && "Invalid child # of SDNode!")((Num < NumOperands && "Invalid child # of SDNode!"
) ? static_cast<void> (0) : __assert_fail ("Num < NumOperands && \"Invalid child # of SDNode!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAGNodes.h"
, 905, __PRETTY_FUNCTION__))
;
906 return OperandList[Num];
907 }
908
909 using op_iterator = SDUse *;
910
911 op_iterator op_begin() const { return OperandList; }
912 op_iterator op_end() const { return OperandList+NumOperands; }
913 ArrayRef<SDUse> ops() const { return makeArrayRef(op_begin(), op_end()); }
914
915 /// Iterator for directly iterating over the operand SDValue's.
916 struct value_op_iterator
917 : iterator_adaptor_base<value_op_iterator, op_iterator,
918 std::random_access_iterator_tag, SDValue,
919 ptrdiff_t, value_op_iterator *,
920 value_op_iterator *> {
921 explicit value_op_iterator(SDUse *U = nullptr)
922 : iterator_adaptor_base(U) {}
923
924 const SDValue &operator*() const { return I->get(); }
925 };
926
927 iterator_range<value_op_iterator> op_values() const {
928 return make_range(value_op_iterator(op_begin()),
929 value_op_iterator(op_end()));
930 }
931
932 SDVTList getVTList() const {
933 SDVTList X = { ValueList, NumValues };
934 return X;
935 }
936
937 /// If this node has a glue operand, return the node
938 /// to which the glue operand points. Otherwise return NULL.
939 SDNode *getGluedNode() const {
940 if (getNumOperands() != 0 &&
941 getOperand(getNumOperands()-1).getValueType() == MVT::Glue)
942 return getOperand(getNumOperands()-1).getNode();
943 return nullptr;
944 }
945
946 /// If this node has a glue value with a user, return
947 /// the user (there is at most one). Otherwise return NULL.
948 SDNode *getGluedUser() const {
949 for (use_iterator UI = use_begin(), UE = use_end(); UI != UE; ++UI)
950 if (UI.getUse().get().getValueType() == MVT::Glue)
951 return *UI;
952 return nullptr;
953 }
954
955 const SDNodeFlags getFlags() const { return Flags; }
956 void setFlags(SDNodeFlags NewFlags) { Flags = NewFlags; }
957 bool isFast() { return Flags.isFast(); }
958
959 /// Clear any flags in this node that aren't also set in Flags.
960 /// If Flags is not in a defined state then this has no effect.
961 void intersectFlagsWith(const SDNodeFlags Flags);
962
963 /// Return the number of values defined/returned by this operator.
964 unsigned getNumValues() const { return NumValues; }
965
966 /// Return the type of a specified result.
967 EVT getValueType(unsigned ResNo) const {
968 assert(ResNo < NumValues && "Illegal result number!")((ResNo < NumValues && "Illegal result number!") ?
static_cast<void> (0) : __assert_fail ("ResNo < NumValues && \"Illegal result number!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAGNodes.h"
, 968, __PRETTY_FUNCTION__))
;
969 return ValueList[ResNo];
970 }
971
972 /// Return the type of a specified result as a simple type.
973 MVT getSimpleValueType(unsigned ResNo) const {
974 return getValueType(ResNo).getSimpleVT();
975 }
976
977 /// Returns MVT::getSizeInBits(getValueType(ResNo)).
978 unsigned getValueSizeInBits(unsigned ResNo) const {
979 return getValueType(ResNo).getSizeInBits();
980 }
981
982 using value_iterator = const EVT *;
983
984 value_iterator value_begin() const { return ValueList; }
985 value_iterator value_end() const { return ValueList+NumValues; }
986
987 /// Return the opcode of this operation for printing.
988 std::string getOperationName(const SelectionDAG *G = nullptr) const;
989 static const char* getIndexedModeName(ISD::MemIndexedMode AM);
990 void print_types(raw_ostream &OS, const SelectionDAG *G) const;
991 void print_details(raw_ostream &OS, const SelectionDAG *G) const;
992 void print(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
993 void printr(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
994
995 /// Print a SelectionDAG node and all children down to
996 /// the leaves. The given SelectionDAG allows target-specific nodes
997 /// to be printed in human-readable form. Unlike printr, this will
998 /// print the whole DAG, including children that appear multiple
999 /// times.
1000 ///
1001 void printrFull(raw_ostream &O, const SelectionDAG *G = nullptr) const;
1002
1003 /// Print a SelectionDAG node and children up to
1004 /// depth "depth." The given SelectionDAG allows target-specific
1005 /// nodes to be printed in human-readable form. Unlike printr, this
1006 /// will print children that appear multiple times wherever they are
1007 /// used.
1008 ///
1009 void printrWithDepth(raw_ostream &O, const SelectionDAG *G = nullptr,
1010 unsigned depth = 100) const;
1011
1012 /// Dump this node, for debugging.
1013 void dump() const;
1014
1015 /// Dump (recursively) this node and its use-def subgraph.
1016 void dumpr() const;
1017
1018 /// Dump this node, for debugging.
1019 /// The given SelectionDAG allows target-specific nodes to be printed
1020 /// in human-readable form.
1021 void dump(const SelectionDAG *G) const;
1022
1023 /// Dump (recursively) this node and its use-def subgraph.
1024 /// The given SelectionDAG allows target-specific nodes to be printed
1025 /// in human-readable form.
1026 void dumpr(const SelectionDAG *G) const;
1027
1028 /// printrFull to dbgs(). The given SelectionDAG allows
1029 /// target-specific nodes to be printed in human-readable form.
1030 /// Unlike dumpr, this will print the whole DAG, including children
1031 /// that appear multiple times.
1032 void dumprFull(const SelectionDAG *G = nullptr) const;
1033
1034 /// printrWithDepth to dbgs(). The given
1035 /// SelectionDAG allows target-specific nodes to be printed in
1036 /// human-readable form. Unlike dumpr, this will print children
1037 /// that appear multiple times wherever they are used.
1038 ///
1039 void dumprWithDepth(const SelectionDAG *G = nullptr,
1040 unsigned depth = 100) const;
1041
1042 /// Gather unique data for the node.
1043 void Profile(FoldingSetNodeID &ID) const;
1044
1045 /// This method should only be used by the SDUse class.
1046 void addUse(SDUse &U) { U.addToList(&UseList); }
1047
1048protected:
1049 static SDVTList getSDVTList(EVT VT) {
1050 SDVTList Ret = { getValueTypeList(VT), 1 };
1051 return Ret;
1052 }
1053
1054 /// Create an SDNode.
1055 ///
1056 /// SDNodes are created without any operands, and never own the operand
1057 /// storage. To add operands, see SelectionDAG::createOperands.
1058 SDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs)
1059 : NodeType(Opc), ValueList(VTs.VTs), NumValues(VTs.NumVTs),
1060 IROrder(Order), debugLoc(std::move(dl)) {
1061 memset(&RawSDNodeBits, 0, sizeof(RawSDNodeBits));
1062 assert(debugLoc.hasTrivialDestructor() && "Expected trivial destructor")((debugLoc.hasTrivialDestructor() && "Expected trivial destructor"
) ? static_cast<void> (0) : __assert_fail ("debugLoc.hasTrivialDestructor() && \"Expected trivial destructor\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAGNodes.h"
, 1062, __PRETTY_FUNCTION__))
;
1063 assert(NumValues == VTs.NumVTs &&((NumValues == VTs.NumVTs && "NumValues wasn't wide enough for its operands!"
) ? static_cast<void> (0) : __assert_fail ("NumValues == VTs.NumVTs && \"NumValues wasn't wide enough for its operands!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAGNodes.h"
, 1064, __PRETTY_FUNCTION__))
1064 "NumValues wasn't wide enough for its operands!")((NumValues == VTs.NumVTs && "NumValues wasn't wide enough for its operands!"
) ? static_cast<void> (0) : __assert_fail ("NumValues == VTs.NumVTs && \"NumValues wasn't wide enough for its operands!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAGNodes.h"
, 1064, __PRETTY_FUNCTION__))
;
1065 }
1066
1067 /// Release the operands and set this node to have zero operands.
1068 void DropOperands();
1069};
1070
1071/// Wrapper class for IR location info (IR ordering and DebugLoc) to be passed
1072/// into SDNode creation functions.
1073/// When an SDNode is created from the DAGBuilder, the DebugLoc is extracted
1074/// from the original Instruction, and IROrder is the ordinal position of
1075/// the instruction.
1076/// When an SDNode is created after the DAG is being built, both DebugLoc and
1077/// the IROrder are propagated from the original SDNode.
1078/// So SDLoc class provides two constructors besides the default one, one to
1079/// be used by the DAGBuilder, the other to be used by others.
1080class SDLoc {
1081private:
1082 DebugLoc DL;
1083 int IROrder = 0;
1084
1085public:
1086 SDLoc() = default;
1087 SDLoc(const SDNode *N) : DL(N->getDebugLoc()), IROrder(N->getIROrder()) {}
1088 SDLoc(const SDValue V) : SDLoc(V.getNode()) {}
1089 SDLoc(const Instruction *I, int Order) : IROrder(Order) {
1090 assert(Order >= 0 && "bad IROrder")((Order >= 0 && "bad IROrder") ? static_cast<void
> (0) : __assert_fail ("Order >= 0 && \"bad IROrder\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAGNodes.h"
, 1090, __PRETTY_FUNCTION__))
;
1091 if (I)
1092 DL = I->getDebugLoc();
1093 }
1094
1095 unsigned getIROrder() const { return IROrder; }
1096 const DebugLoc &getDebugLoc() const { return DL; }
1097};
1098
1099// Define inline functions from the SDValue class.
1100
1101inline SDValue::SDValue(SDNode *node, unsigned resno)
1102 : Node(node), ResNo(resno) {
1103 // Explicitly check for !ResNo to avoid use-after-free, because there are
1104 // callers that use SDValue(N, 0) with a deleted N to indicate successful
1105 // combines.
1106 assert((!Node || !ResNo || ResNo < Node->getNumValues()) &&(((!Node || !ResNo || ResNo < Node->getNumValues()) &&
"Invalid result number for the given node!") ? static_cast<
void> (0) : __assert_fail ("(!Node || !ResNo || ResNo < Node->getNumValues()) && \"Invalid result number for the given node!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAGNodes.h"
, 1107, __PRETTY_FUNCTION__))
1107 "Invalid result number for the given node!")(((!Node || !ResNo || ResNo < Node->getNumValues()) &&
"Invalid result number for the given node!") ? static_cast<
void> (0) : __assert_fail ("(!Node || !ResNo || ResNo < Node->getNumValues()) && \"Invalid result number for the given node!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAGNodes.h"
, 1107, __PRETTY_FUNCTION__))
;
1108 assert(ResNo < -2U && "Cannot use result numbers reserved for DenseMaps.")((ResNo < -2U && "Cannot use result numbers reserved for DenseMaps."
) ? static_cast<void> (0) : __assert_fail ("ResNo < -2U && \"Cannot use result numbers reserved for DenseMaps.\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAGNodes.h"
, 1108, __PRETTY_FUNCTION__))
;
1109}
1110
1111inline unsigned SDValue::getOpcode() const {
1112 return Node->getOpcode();
1113}
1114
1115inline EVT SDValue::getValueType() const {
1116 return Node->getValueType(ResNo);
17
Called C++ object pointer is null
1117}
1118
1119inline unsigned SDValue::getNumOperands() const {
1120 return Node->getNumOperands();
1121}
1122
1123inline const SDValue &SDValue::getOperand(unsigned i) const {
1124 return Node->getOperand(i);
1125}
1126
1127inline uint64_t SDValue::getConstantOperandVal(unsigned i) const {
1128 return Node->getConstantOperandVal(i);
1129}
1130
1131inline bool SDValue::isTargetOpcode() const {
1132 return Node->isTargetOpcode();
1133}
1134
1135inline bool SDValue::isTargetMemoryOpcode() const {
1136 return Node->isTargetMemoryOpcode();
1137}
1138
1139inline bool SDValue::isMachineOpcode() const {
1140 return Node->isMachineOpcode();
1141}
1142
1143inline unsigned SDValue::getMachineOpcode() const {
1144 return Node->getMachineOpcode();
1145}
1146
1147inline bool SDValue::isUndef() const {
1148 return Node->isUndef();
1149}
1150
1151inline bool SDValue::use_empty() const {
1152 return !Node->hasAnyUseOfValue(ResNo);
1153}
1154
1155inline bool SDValue::hasOneUse() const {
1156 return Node->hasNUsesOfValue(1, ResNo);
1157}
1158
1159inline const DebugLoc &SDValue::getDebugLoc() const {
1160 return Node->getDebugLoc();
1161}
1162
1163inline void SDValue::dump() const {
1164 return Node->dump();
1165}
1166
1167inline void SDValue::dump(const SelectionDAG *G) const {
1168 return Node->dump(G);
1169}
1170
1171inline void SDValue::dumpr() const {
1172 return Node->dumpr();
1173}
1174
1175inline void SDValue::dumpr(const SelectionDAG *G) const {
1176 return Node->dumpr(G);
1177}
1178
1179// Define inline functions from the SDUse class.
1180
1181inline void SDUse::set(const SDValue &V) {
1182 if (Val.getNode()) removeFromList();
1183 Val = V;
1184 if (V.getNode()) V.getNode()->addUse(*this);
1185}
1186
1187inline void SDUse::setInitial(const SDValue &V) {
1188 Val = V;
1189 V.getNode()->addUse(*this);
1190}
1191
1192inline void SDUse::setNode(SDNode *N) {
1193 if (Val.getNode()) removeFromList();
1194 Val.setNode(N);
1195 if (N) N->addUse(*this);
1196}
1197
1198/// This class is used to form a handle around another node that
1199/// is persistent and is updated across invocations of replaceAllUsesWith on its
1200/// operand. This node should be directly created by end-users and not added to
1201/// the AllNodes list.
1202class HandleSDNode : public SDNode {
1203 SDUse Op;
1204
1205public:
1206 explicit HandleSDNode(SDValue X)
1207 : SDNode(ISD::HANDLENODE, 0, DebugLoc(), getSDVTList(MVT::Other)) {
1208 // HandleSDNodes are never inserted into the DAG, so they won't be
1209 // auto-numbered. Use ID 65535 as a sentinel.
1210 PersistentId = 0xffff;
1211
1212 // Manually set up the operand list. This node type is special in that it's
1213 // always stack allocated and SelectionDAG does not manage its operands.
1214 // TODO: This should either (a) not be in the SDNode hierarchy, or (b) not
1215 // be so special.
1216 Op.setUser(this);
1217 Op.setInitial(X);
1218 NumOperands = 1;
1219 OperandList = &Op;
1220 }
1221 ~HandleSDNode();
1222
1223 const SDValue &getValue() const { return Op; }
1224};
1225
1226class AddrSpaceCastSDNode : public SDNode {
1227private:
1228 unsigned SrcAddrSpace;
1229 unsigned DestAddrSpace;
1230
1231public:
1232 AddrSpaceCastSDNode(unsigned Order, const DebugLoc &dl, EVT VT,
1233 unsigned SrcAS, unsigned DestAS);
1234
1235 unsigned getSrcAddressSpace() const { return SrcAddrSpace; }
1236 unsigned getDestAddressSpace() const { return DestAddrSpace; }
1237
1238 static bool classof(const SDNode *N) {
1239 return N->getOpcode() == ISD::ADDRSPACECAST;
1240 }
1241};
1242
1243/// This is an abstract virtual class for memory operations.
1244class MemSDNode : public SDNode {
1245private:
1246 // VT of in-memory value.
1247 EVT MemoryVT;
1248
1249protected:
1250 /// Memory reference information.
1251 MachineMemOperand *MMO;
1252
1253public:
1254 MemSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl, SDVTList VTs,
1255 EVT memvt, MachineMemOperand *MMO);
1256
1257 bool readMem() const { return MMO->isLoad(); }
1258 bool writeMem() const { return MMO->isStore(); }
1259
1260 /// Returns alignment and volatility of the memory access
1261 unsigned getOriginalAlignment() const {
1262 return MMO->getBaseAlignment();
1263 }
1264 unsigned getAlignment() const {
1265 return MMO->getAlignment();
1266 }
1267
1268 /// Return the SubclassData value, without HasDebugValue. This contains an
1269 /// encoding of the volatile flag, as well as bits used by subclasses. This
1270 /// function should only be used to compute a FoldingSetNodeID value.
1271 /// The HasDebugValue bit is masked out because CSE map needs to match
1272 /// nodes with debug info with nodes without debug info. Same is about
1273 /// isDivergent bit.
1274 unsigned getRawSubclassData() const {
1275 uint16_t Data;
1276 union {
1277 char RawSDNodeBits[sizeof(uint16_t)];
1278 SDNodeBitfields SDNodeBits;
1279 };
1280 memcpy(&RawSDNodeBits, &this->RawSDNodeBits, sizeof(this->RawSDNodeBits));
1281 SDNodeBits.HasDebugValue = 0;
1282 SDNodeBits.IsDivergent = false;
1283 memcpy(&Data, &RawSDNodeBits, sizeof(RawSDNodeBits));
1284 return Data;
1285 }
1286
1287 bool isVolatile() const { return MemSDNodeBits.IsVolatile; }
1288 bool isNonTemporal() const { return MemSDNodeBits.IsNonTemporal; }
1289 bool isDereferenceable() const { return MemSDNodeBits.IsDereferenceable; }
1290 bool isInvariant() const { return MemSDNodeBits.IsInvariant; }
1291
1292 // Returns the offset from the location of the access.
1293 int64_t getSrcValueOffset() const { return MMO->getOffset(); }
1294
1295 /// Returns the AA info that describes the dereference.
1296 AAMDNodes getAAInfo() const { return MMO->getAAInfo(); }
1297
1298 /// Returns the Ranges that describes the dereference.
1299 const MDNode *getRanges() const { return MMO->getRanges(); }
1300
1301 /// Returns the synchronization scope ID for this memory operation.
1302 SyncScope::ID getSyncScopeID() const { return MMO->getSyncScopeID(); }
1303
1304 /// Return the atomic ordering requirements for this memory operation. For
1305 /// cmpxchg atomic operations, return the atomic ordering requirements when
1306 /// store occurs.
1307 AtomicOrdering getOrdering() const { return MMO->getOrdering(); }
1308
1309 /// Return the type of the in-memory value.
1310 EVT getMemoryVT() const { return MemoryVT; }
1311
1312 /// Return a MachineMemOperand object describing the memory
1313 /// reference performed by operation.
1314 MachineMemOperand *getMemOperand() const { return MMO; }
1315
1316 const MachinePointerInfo &getPointerInfo() const {
1317 return MMO->getPointerInfo();
1318 }
1319
1320 /// Return the address space for the associated pointer
1321 unsigned getAddressSpace() const {
1322 return getPointerInfo().getAddrSpace();
1323 }
1324
1325 /// Update this MemSDNode's MachineMemOperand information
1326 /// to reflect the alignment of NewMMO, if it has a greater alignment.
1327 /// This must only be used when the new alignment applies to all users of
1328 /// this MachineMemOperand.
1329 void refineAlignment(const MachineMemOperand *NewMMO) {
1330 MMO->refineAlignment(NewMMO);
1331 }
1332
1333 const SDValue &getChain() const { return getOperand(0); }
1334 const SDValue &getBasePtr() const {
1335 return getOperand(getOpcode() == ISD::STORE ? 2 : 1);
1336 }
1337
1338 // Methods to support isa and dyn_cast
1339 static bool classof(const SDNode *N) {
1340 // For some targets, we lower some target intrinsics to a MemIntrinsicNode
1341 // with either an intrinsic or a target opcode.
1342 return N->getOpcode() == ISD::LOAD ||
1343 N->getOpcode() == ISD::STORE ||
1344 N->getOpcode() == ISD::PREFETCH ||
1345 N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1346 N->getOpcode() == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS ||
1347 N->getOpcode() == ISD::ATOMIC_SWAP ||
1348 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1349 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1350 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1351 N->getOpcode() == ISD::ATOMIC_LOAD_CLR ||
1352 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1353 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1354 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1355 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1356 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1357 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1358 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
1359 N->getOpcode() == ISD::ATOMIC_LOAD ||
1360 N->getOpcode() == ISD::ATOMIC_STORE ||
1361 N->getOpcode() == ISD::MLOAD ||
1362 N->getOpcode() == ISD::MSTORE ||
1363 N->getOpcode() == ISD::MGATHER ||
1364 N->getOpcode() == ISD::MSCATTER ||
1365 N->isMemIntrinsic() ||
1366 N->isTargetMemoryOpcode();
1367 }
1368};
1369
1370/// This is an SDNode representing atomic operations.
1371class AtomicSDNode : public MemSDNode {
1372public:
1373 AtomicSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl, SDVTList VTL,
1374 EVT MemVT, MachineMemOperand *MMO)
1375 : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {}
1376
1377 const SDValue &getBasePtr() const { return getOperand(1); }
1378 const SDValue &getVal() const { return getOperand(2); }
1379
1380 /// Returns true if this SDNode represents cmpxchg atomic operation, false
1381 /// otherwise.
1382 bool isCompareAndSwap() const {
1383 unsigned Op = getOpcode();
1384 return Op == ISD::ATOMIC_CMP_SWAP ||
1385 Op == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS;
1386 }
1387
1388 /// For cmpxchg atomic operations, return the atomic ordering requirements
1389 /// when store does not occur.
1390 AtomicOrdering getFailureOrdering() const {
1391 assert(isCompareAndSwap() && "Must be cmpxchg operation")((isCompareAndSwap() && "Must be cmpxchg operation") ?
static_cast<void> (0) : __assert_fail ("isCompareAndSwap() && \"Must be cmpxchg operation\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAGNodes.h"
, 1391, __PRETTY_FUNCTION__))
;
1392 return MMO->getFailureOrdering();
1393 }
1394
1395 // Methods to support isa and dyn_cast
1396 static bool classof(const SDNode *N) {
1397 return N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1398 N->getOpcode() == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS ||
1399 N->getOpcode() == ISD::ATOMIC_SWAP ||
1400 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1401 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1402 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1403 N->getOpcode() == ISD::ATOMIC_LOAD_CLR ||
1404 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1405 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1406 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1407 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1408 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1409 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1410 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
1411 N->getOpcode() == ISD::ATOMIC_LOAD ||
1412 N->getOpcode() == ISD::ATOMIC_STORE;
1413 }
1414};
1415
1416/// This SDNode is used for target intrinsics that touch
1417/// memory and need an associated MachineMemOperand. Its opcode may be
1418/// INTRINSIC_VOID, INTRINSIC_W_CHAIN, PREFETCH, or a target-specific opcode
1419/// with a value not less than FIRST_TARGET_MEMORY_OPCODE.
1420class MemIntrinsicSDNode : public MemSDNode {
1421public:
1422 MemIntrinsicSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl,
1423 SDVTList VTs, EVT MemoryVT, MachineMemOperand *MMO)
1424 : MemSDNode(Opc, Order, dl, VTs, MemoryVT, MMO) {
1425 SDNodeBits.IsMemIntrinsic = true;
1426 }
1427
1428 // Methods to support isa and dyn_cast
1429 static bool classof(const SDNode *N) {
1430 // We lower some target intrinsics to their target opcode
1431 // early a node with a target opcode can be of this class
1432 return N->isMemIntrinsic() ||
1433 N->getOpcode() == ISD::PREFETCH ||
1434 N->isTargetMemoryOpcode();
1435 }
1436};
1437
1438/// This SDNode is used to implement the code generator
1439/// support for the llvm IR shufflevector instruction. It combines elements
1440/// from two input vectors into a new input vector, with the selection and
1441/// ordering of elements determined by an array of integers, referred to as
1442/// the shuffle mask. For input vectors of width N, mask indices of 0..N-1
1443/// refer to elements from the LHS input, and indices from N to 2N-1 the RHS.
1444/// An index of -1 is treated as undef, such that the code generator may put
1445/// any value in the corresponding element of the result.
1446class ShuffleVectorSDNode : public SDNode {
1447 // The memory for Mask is owned by the SelectionDAG's OperandAllocator, and
1448 // is freed when the SelectionDAG object is destroyed.
1449 const int *Mask;
1450
1451protected:
1452 friend class SelectionDAG;
1453
1454 ShuffleVectorSDNode(EVT VT, unsigned Order, const DebugLoc &dl, const int *M)
1455 : SDNode(ISD::VECTOR_SHUFFLE, Order, dl, getSDVTList(VT)), Mask(M) {}
1456
1457public:
1458 ArrayRef<int> getMask() const {
1459 EVT VT = getValueType(0);
1460 return makeArrayRef(Mask, VT.getVectorNumElements());
1461 }
1462
1463 int getMaskElt(unsigned Idx) const {
1464 assert(Idx < getValueType(0).getVectorNumElements() && "Idx out of range!")((Idx < getValueType(0).getVectorNumElements() && "Idx out of range!"
) ? static_cast<void> (0) : __assert_fail ("Idx < getValueType(0).getVectorNumElements() && \"Idx out of range!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAGNodes.h"
, 1464, __PRETTY_FUNCTION__))
;
1465 return Mask[Idx];
1466 }
1467
1468 bool isSplat() const { return isSplatMask(Mask, getValueType(0)); }
1469
1470 int getSplatIndex() const {
1471 assert(isSplat() && "Cannot get splat index for non-splat!")((isSplat() && "Cannot get splat index for non-splat!"
) ? static_cast<void> (0) : __assert_fail ("isSplat() && \"Cannot get splat index for non-splat!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAGNodes.h"
, 1471, __PRETTY_FUNCTION__))
;
1472 EVT VT = getValueType(0);
1473 for (unsigned i = 0, e = VT.getVectorNumElements(); i != e; ++i) {
1474 if (Mask[i] >= 0)
1475 return Mask[i];
1476 }
1477 llvm_unreachable("Splat with all undef indices?")::llvm::llvm_unreachable_internal("Splat with all undef indices?"
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAGNodes.h"
, 1477)
;
1478 }
1479
1480 static bool isSplatMask(const int *Mask, EVT VT);
1481
1482 /// Change values in a shuffle permute mask assuming
1483 /// the two vector operands have swapped position.
1484 static void commuteMask(MutableArrayRef<int> Mask) {
1485 unsigned NumElems = Mask.size();
1486 for (unsigned i = 0; i != NumElems; ++i) {
1487 int idx = Mask[i];
1488 if (idx < 0)
1489 continue;
1490 else if (idx < (int)NumElems)
1491 Mask[i] = idx + NumElems;
1492 else
1493 Mask[i] = idx - NumElems;
1494 }
1495 }
1496
1497 static bool classof(const SDNode *N) {
1498 return N->getOpcode() == ISD::VECTOR_SHUFFLE;
1499 }
1500};
1501
1502class ConstantSDNode : public SDNode {
1503 friend class SelectionDAG;
1504
1505 const ConstantInt *Value;
1506
1507 ConstantSDNode(bool isTarget, bool isOpaque, const ConstantInt *val, EVT VT)
1508 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, 0, DebugLoc(),
1509 getSDVTList(VT)),
1510 Value(val) {
1511 ConstantSDNodeBits.IsOpaque = isOpaque;
1512 }
1513
1514public:
1515 const ConstantInt *getConstantIntValue() const { return Value; }
1516 const APInt &getAPIntValue() const { return Value->getValue(); }
1517 uint64_t getZExtValue() const { return Value->getZExtValue(); }
1518 int64_t getSExtValue() const { return Value->getSExtValue(); }
1519 uint64_t getLimitedValue(uint64_t Limit = UINT64_MAX(18446744073709551615UL)) {
1520 return Value->getLimitedValue(Limit);
1521 }
1522
1523 bool isOne() const { return Value->isOne(); }
1524 bool isNullValue() const { return Value->isZero(); }
1525 bool isAllOnesValue() const { return Value->isMinusOne(); }
1526
1527 bool isOpaque() const { return ConstantSDNodeBits.IsOpaque; }
1528
1529 static bool classof(const SDNode *N) {
1530 return N->getOpcode() == ISD::Constant ||
1531 N->getOpcode() == ISD::TargetConstant;
1532 }
1533};
1534
1535uint64_t SDNode::getConstantOperandVal(unsigned Num) const {
1536 return cast<ConstantSDNode>(getOperand(Num))->getZExtValue();
1537}
1538
1539class ConstantFPSDNode : public SDNode {
1540 friend class SelectionDAG;
1541
1542 const ConstantFP *Value;
1543
1544 ConstantFPSDNode(bool isTarget, const ConstantFP *val, EVT VT)
1545 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP, 0,
1546 DebugLoc(), getSDVTList(VT)),
1547 Value(val) {}
1548
1549public:
1550 const APFloat& getValueAPF() const { return Value->getValueAPF(); }
1551 const ConstantFP *getConstantFPValue() const { return Value; }
1552
1553 /// Return true if the value is positive or negative zero.
1554 bool isZero() const { return Value->isZero(); }
1555
1556 /// Return true if the value is a NaN.
1557 bool isNaN() const { return Value->isNaN(); }
1558
1559 /// Return true if the value is an infinity
1560 bool isInfinity() const { return Value->isInfinity(); }
1561
1562 /// Return true if the value is negative.
1563 bool isNegative() const { return Value->isNegative(); }
1564
1565 /// We don't rely on operator== working on double values, as
1566 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1567 /// As such, this method can be used to do an exact bit-for-bit comparison of
1568 /// two floating point values.
1569
1570 /// We leave the version with the double argument here because it's just so
1571 /// convenient to write "2.0" and the like. Without this function we'd
1572 /// have to duplicate its logic everywhere it's called.
1573 bool isExactlyValue(double V) const {
1574 return Value->getValueAPF().isExactlyValue(V);
1575 }
1576 bool isExactlyValue(const APFloat& V) const;
1577
1578 static bool isValueValidForType(EVT VT, const APFloat& Val);
1579
1580 static bool classof(const SDNode *N) {
1581 return N->getOpcode() == ISD::ConstantFP ||
1582 N->getOpcode() == ISD::TargetConstantFP;
1583 }
1584};
1585
1586/// Returns true if \p V is a constant integer zero.
1587bool isNullConstant(SDValue V);
1588
1589/// Returns true if \p V is an FP constant with a value of positive zero.
1590bool isNullFPConstant(SDValue V);
1591
1592/// Returns true if \p V is an integer constant with all bits set.
1593bool isAllOnesConstant(SDValue V);
1594
1595/// Returns true if \p V is a constant integer one.
1596bool isOneConstant(SDValue V);
1597
1598/// Return the non-bitcasted source operand of \p V if it exists.
1599/// If \p V is not a bitcasted value, it is returned as-is.
1600SDValue peekThroughBitcasts(SDValue V);
1601
1602/// Return the non-bitcasted and one-use source operand of \p V if it exists.
1603/// If \p V is not a bitcasted one-use value, it is returned as-is.
1604SDValue peekThroughOneUseBitcasts(SDValue V);
1605
1606/// Returns true if \p V is a bitwise not operation. Assumes that an all ones
1607/// constant is canonicalized to be operand 1.
1608bool isBitwiseNot(SDValue V);
1609
1610/// Returns the SDNode if it is a constant splat BuildVector or constant int.
1611ConstantSDNode *isConstOrConstSplat(SDValue N, bool AllowUndefs = false);
1612
1613/// Returns the SDNode if it is a constant splat BuildVector or constant float.
1614ConstantFPSDNode *isConstOrConstSplatFP(SDValue N, bool AllowUndefs = false);
1615
1616/// Return true if the value is a constant 0 integer or a splatted vector of
1617/// a constant 0 integer (with no undefs).
1618/// Build vector implicit truncation is not an issue for null values.
1619bool isNullOrNullSplat(SDValue V);
1620
1621/// Return true if the value is a constant 1 integer or a splatted vector of a
1622/// constant 1 integer (with no undefs).
1623/// Does not permit build vector implicit truncation.
1624bool isOneOrOneSplat(SDValue V);
1625
1626/// Return true if the value is a constant -1 integer or a splatted vector of a
1627/// constant -1 integer (with no undefs).
1628/// Does not permit build vector implicit truncation.
1629bool isAllOnesOrAllOnesSplat(SDValue V);
1630
1631class GlobalAddressSDNode : public SDNode {
1632 friend class SelectionDAG;
1633
1634 const GlobalValue *TheGlobal;
1635 int64_t Offset;
1636 unsigned char TargetFlags;
1637
1638 GlobalAddressSDNode(unsigned Opc, unsigned Order, const DebugLoc &DL,
1639 const GlobalValue *GA, EVT VT, int64_t o,
1640 unsigned char TF);
1641
1642public:
1643 const GlobalValue *getGlobal() const { return TheGlobal; }
1644 int64_t getOffset() const { return Offset; }
1645 unsigned char getTargetFlags() const { return TargetFlags; }
1646 // Return the address space this GlobalAddress belongs to.
1647 unsigned getAddressSpace() const;
1648
1649 static bool classof(const SDNode *N) {
1650 return N->getOpcode() == ISD::GlobalAddress ||
1651 N->getOpcode() == ISD::TargetGlobalAddress ||
1652 N->getOpcode() == ISD::GlobalTLSAddress ||
1653 N->getOpcode() == ISD::TargetGlobalTLSAddress;
1654 }
1655};
1656
1657class FrameIndexSDNode : public SDNode {
1658 friend class SelectionDAG;
1659
1660 int FI;
1661
1662 FrameIndexSDNode(int fi, EVT VT, bool isTarg)
1663 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex,
1664 0, DebugLoc(), getSDVTList(VT)), FI(fi) {
1665 }
1666
1667public:
1668 int getIndex() const { return FI; }
1669
1670 static bool classof(const SDNode *N) {
1671 return N->getOpcode() == ISD::FrameIndex ||
1672 N->getOpcode() == ISD::TargetFrameIndex;
1673 }
1674};
1675
1676class JumpTableSDNode : public SDNode {
1677 friend class SelectionDAG;
1678
1679 int JTI;
1680 unsigned char TargetFlags;
1681
1682 JumpTableSDNode(int jti, EVT VT, bool isTarg, unsigned char TF)
1683 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable,
1684 0, DebugLoc(), getSDVTList(VT)), JTI(jti), TargetFlags(TF) {
1685 }
1686
1687public:
1688 int getIndex() const { return JTI; }
1689 unsigned char getTargetFlags() const { return TargetFlags; }
1690
1691 static bool classof(const SDNode *N) {
1692 return N->getOpcode() == ISD::JumpTable ||
1693 N->getOpcode() == ISD::TargetJumpTable;
1694 }
1695};
1696
1697class ConstantPoolSDNode : public SDNode {
1698 friend class SelectionDAG;
1699
1700 union {
1701 const Constant *ConstVal;
1702 MachineConstantPoolValue *MachineCPVal;
1703 } Val;
1704 int Offset; // It's a MachineConstantPoolValue if top bit is set.
1705 unsigned Alignment; // Minimum alignment requirement of CP (not log2 value).
1706 unsigned char TargetFlags;
1707
1708 ConstantPoolSDNode(bool isTarget, const Constant *c, EVT VT, int o,
1709 unsigned Align, unsigned char TF)
1710 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
1711 DebugLoc(), getSDVTList(VT)), Offset(o), Alignment(Align),
1712 TargetFlags(TF) {
1713 assert(Offset >= 0 && "Offset is too large")((Offset >= 0 && "Offset is too large") ? static_cast
<void> (0) : __assert_fail ("Offset >= 0 && \"Offset is too large\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAGNodes.h"
, 1713, __PRETTY_FUNCTION__))
;
1714 Val.ConstVal = c;
1715 }
1716
1717 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1718 EVT VT, int o, unsigned Align, unsigned char TF)
1719 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
1720 DebugLoc(), getSDVTList(VT)), Offset(o), Alignment(Align),
1721 TargetFlags(TF) {
1722 assert(Offset >= 0 && "Offset is too large")((Offset >= 0 && "Offset is too large") ? static_cast
<void> (0) : __assert_fail ("Offset >= 0 && \"Offset is too large\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAGNodes.h"
, 1722, __PRETTY_FUNCTION__))
;
1723 Val.MachineCPVal = v;
1724 Offset |= 1 << (sizeof(unsigned)*CHAR_BIT8-1);
1725 }
1726
1727public:
1728 bool isMachineConstantPoolEntry() const {
1729 return Offset < 0;
1730 }
1731
1732 const Constant *getConstVal() const {
1733 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type")((!isMachineConstantPoolEntry() && "Wrong constantpool type"
) ? static_cast<void> (0) : __assert_fail ("!isMachineConstantPoolEntry() && \"Wrong constantpool type\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAGNodes.h"
, 1733, __PRETTY_FUNCTION__))
;
1734 return Val.ConstVal;
1735 }
1736
1737 MachineConstantPoolValue *getMachineCPVal() const {
1738 assert(isMachineConstantPoolEntry() && "Wrong constantpool type")((isMachineConstantPoolEntry() && "Wrong constantpool type"
) ? static_cast<void> (0) : __assert_fail ("isMachineConstantPoolEntry() && \"Wrong constantpool type\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAGNodes.h"
, 1738, __PRETTY_FUNCTION__))
;
1739 return Val.MachineCPVal;
1740 }
1741
1742 int getOffset() const {
1743 return Offset & ~(1 << (sizeof(unsigned)*CHAR_BIT8-1));
1744 }
1745
1746 // Return the alignment of this constant pool object, which is either 0 (for
1747 // default alignment) or the desired value.
1748 unsigned getAlignment() const { return Alignment; }
1749 unsigned char getTargetFlags() const { return TargetFlags; }
1750
1751 Type *getType() const;
1752
1753 static bool classof(const SDNode *N) {
1754 return N->getOpcode() == ISD::ConstantPool ||
1755 N->getOpcode() == ISD::TargetConstantPool;
1756 }
1757};
1758
1759/// Completely target-dependent object reference.
1760class TargetIndexSDNode : public SDNode {
1761 friend class SelectionDAG;
1762
1763 unsigned char TargetFlags;
1764 int Index;
1765 int64_t Offset;
1766
1767public:
1768 TargetIndexSDNode(int Idx, EVT VT, int64_t Ofs, unsigned char TF)
1769 : SDNode(ISD::TargetIndex, 0, DebugLoc(), getSDVTList(VT)),
1770 TargetFlags(TF), Index(Idx), Offset(Ofs) {}
1771
1772 unsigned char getTargetFlags() const { return TargetFlags; }
1773 int getIndex() const { return Index; }
1774 int64_t getOffset() const { return Offset; }
1775
1776 static bool classof(const SDNode *N) {
1777 return N->getOpcode() == ISD::TargetIndex;
1778 }
1779};
1780
1781class BasicBlockSDNode : public SDNode {
1782 friend class SelectionDAG;
1783
1784 MachineBasicBlock *MBB;
1785
1786 /// Debug info is meaningful and potentially useful here, but we create
1787 /// blocks out of order when they're jumped to, which makes it a bit
1788 /// harder. Let's see if we need it first.
1789 explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1790 : SDNode(ISD::BasicBlock, 0, DebugLoc(), getSDVTList(MVT::Other)), MBB(mbb)
1791 {}
1792
1793public:
1794 MachineBasicBlock *getBasicBlock() const { return MBB; }
1795
1796 static bool classof(const SDNode *N) {
1797 return N->getOpcode() == ISD::BasicBlock;
1798 }
1799};
1800
1801/// A "pseudo-class" with methods for operating on BUILD_VECTORs.
1802class BuildVectorSDNode : public SDNode {
1803public:
1804 // These are constructed as SDNodes and then cast to BuildVectorSDNodes.
1805 explicit BuildVectorSDNode() = delete;
1806
1807 /// Check if this is a constant splat, and if so, find the
1808 /// smallest element size that splats the vector. If MinSplatBits is
1809 /// nonzero, the element size must be at least that large. Note that the
1810 /// splat element may be the entire vector (i.e., a one element vector).
1811 /// Returns the splat element value in SplatValue. Any undefined bits in
1812 /// that value are zero, and the corresponding bits in the SplatUndef mask
1813 /// are set. The SplatBitSize value is set to the splat element size in
1814 /// bits. HasAnyUndefs is set to true if any bits in the vector are
1815 /// undefined. isBigEndian describes the endianness of the target.
1816 bool isConstantSplat(APInt &SplatValue, APInt &SplatUndef,
1817 unsigned &SplatBitSize, bool &HasAnyUndefs,
1818 unsigned MinSplatBits = 0,
1819 bool isBigEndian = false) const;
1820
1821 /// Returns the splatted value or a null value if this is not a splat.
1822 ///
1823 /// If passed a non-null UndefElements bitvector, it will resize it to match
1824 /// the vector width and set the bits where elements are undef.
1825 SDValue getSplatValue(BitVector *UndefElements = nullptr) const;
1826
1827 /// Returns the splatted constant or null if this is not a constant
1828 /// splat.
1829 ///
1830 /// If passed a non-null UndefElements bitvector, it will resize it to match
1831 /// the vector width and set the bits where elements are undef.
1832 ConstantSDNode *
1833 getConstantSplatNode(BitVector *UndefElements = nullptr) const;
1834
1835 /// Returns the splatted constant FP or null if this is not a constant
1836 /// FP splat.
1837 ///
1838 /// If passed a non-null UndefElements bitvector, it will resize it to match
1839 /// the vector width and set the bits where elements are undef.
1840 ConstantFPSDNode *
1841 getConstantFPSplatNode(BitVector *UndefElements = nullptr) const;
1842
1843 /// If this is a constant FP splat and the splatted constant FP is an
1844 /// exact power or 2, return the log base 2 integer value. Otherwise,
1845 /// return -1.
1846 ///
1847 /// The BitWidth specifies the necessary bit precision.
1848 int32_t getConstantFPSplatPow2ToLog2Int(BitVector *UndefElements,
1849 uint32_t BitWidth) const;
1850
1851 bool isConstant() const;
1852
1853 static bool classof(const SDNode *N) {
1854 return N->getOpcode() == ISD::BUILD_VECTOR;
1855 }
1856};
1857
1858/// An SDNode that holds an arbitrary LLVM IR Value. This is
1859/// used when the SelectionDAG needs to make a simple reference to something
1860/// in the LLVM IR representation.
1861///
1862class SrcValueSDNode : public SDNode {
1863 friend class SelectionDAG;
1864
1865 const Value *V;
1866
1867 /// Create a SrcValue for a general value.
1868 explicit SrcValueSDNode(const Value *v)
1869 : SDNode(ISD::SRCVALUE, 0, DebugLoc(), getSDVTList(MVT::Other)), V(v) {}
1870
1871public:
1872 /// Return the contained Value.
1873 const Value *getValue() const { return V; }
1874
1875 static bool classof(const SDNode *N) {
1876 return N->getOpcode() == ISD::SRCVALUE;
1877 }
1878};
1879
1880class MDNodeSDNode : public SDNode {
1881 friend class SelectionDAG;
1882
1883 const MDNode *MD;
1884
1885 explicit MDNodeSDNode(const MDNode *md)
1886 : SDNode(ISD::MDNODE_SDNODE, 0, DebugLoc(), getSDVTList(MVT::Other)), MD(md)
1887 {}
1888
1889public:
1890 const MDNode *getMD() const { return MD; }
1891
1892 static bool classof(const SDNode *N) {
1893 return N->getOpcode() == ISD::MDNODE_SDNODE;
1894 }
1895};
1896
1897class RegisterSDNode : public SDNode {
1898 friend class SelectionDAG;
1899
1900 unsigned Reg;
1901
1902 RegisterSDNode(unsigned reg, EVT VT)
1903 : SDNode(ISD::Register, 0, DebugLoc(), getSDVTList(VT)), Reg(reg) {}
1904
1905public:
1906 unsigned getReg() const { return Reg; }
1907
1908 static bool classof(const SDNode *N) {
1909 return N->getOpcode() == ISD::Register;
1910 }
1911};
1912
1913class RegisterMaskSDNode : public SDNode {
1914 friend class SelectionDAG;
1915
1916 // The memory for RegMask is not owned by the node.
1917 const uint32_t *RegMask;
1918
1919 RegisterMaskSDNode(const uint32_t *mask)
1920 : SDNode(ISD::RegisterMask, 0, DebugLoc(), getSDVTList(MVT::Untyped)),
1921 RegMask(mask) {}
1922
1923public:
1924 const uint32_t *getRegMask() const { return RegMask; }
1925
1926 static bool classof(const SDNode *N) {
1927 return N->getOpcode() == ISD::RegisterMask;
1928 }
1929};
1930
1931class BlockAddressSDNode : public SDNode {
1932 friend class SelectionDAG;
1933
1934 const BlockAddress *BA;
1935 int64_t Offset;
1936 unsigned char TargetFlags;
1937
1938 BlockAddressSDNode(unsigned NodeTy, EVT VT, const BlockAddress *ba,
1939 int64_t o, unsigned char Flags)
1940 : SDNode(NodeTy, 0, DebugLoc(), getSDVTList(VT)),
1941 BA(ba), Offset(o), TargetFlags(Flags) {}
1942
1943public:
1944 const BlockAddress *getBlockAddress() const { return BA; }
1945 int64_t getOffset() const { return Offset; }
1946 unsigned char getTargetFlags() const { return TargetFlags; }
1947
1948 static bool classof(const SDNode *N) {
1949 return N->getOpcode() == ISD::BlockAddress ||
1950 N->getOpcode() == ISD::TargetBlockAddress;
1951 }
1952};
1953
1954class LabelSDNode : public SDNode {
1955 friend class SelectionDAG;
1956
1957 MCSymbol *Label;
1958
1959 LabelSDNode(unsigned Order, const DebugLoc &dl, MCSymbol *L)
1960 : SDNode(ISD::EH_LABEL, Order, dl, getSDVTList(MVT::Other)), Label(L) {}
1961
1962public:
1963 MCSymbol *getLabel() const { return Label; }
1964
1965 static bool classof(const SDNode *N) {
1966 return N->getOpcode() == ISD::EH_LABEL ||
1967 N->getOpcode() == ISD::ANNOTATION_LABEL;
1968 }
1969};
1970
1971class ExternalSymbolSDNode : public SDNode {
1972 friend class SelectionDAG;
1973
1974 const char *Symbol;
1975 unsigned char TargetFlags;
1976
1977 ExternalSymbolSDNode(bool isTarget, const char *Sym, unsigned char TF, EVT VT)
1978 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1979 0, DebugLoc(), getSDVTList(VT)), Symbol(Sym), TargetFlags(TF) {}
1980
1981public:
1982 const char *getSymbol() const { return Symbol; }
1983 unsigned char getTargetFlags() const { return TargetFlags; }
1984
1985 static bool classof(const SDNode *N) {
1986 return N->getOpcode() == ISD::ExternalSymbol ||
1987 N->getOpcode() == ISD::TargetExternalSymbol;
1988 }
1989};
1990
1991class MCSymbolSDNode : public SDNode {
1992 friend class SelectionDAG;
1993
1994 MCSymbol *Symbol;
1995
1996 MCSymbolSDNode(MCSymbol *Symbol, EVT VT)
1997 : SDNode(ISD::MCSymbol, 0, DebugLoc(), getSDVTList(VT)), Symbol(Symbol) {}
1998
1999public:
2000 MCSymbol *getMCSymbol() const { return Symbol; }
2001
2002 static bool classof(const SDNode *N) {
2003 return N->getOpcode() == ISD::MCSymbol;
2004 }
2005};
2006
2007class CondCodeSDNode : public SDNode {
2008 friend class SelectionDAG;
2009
2010 ISD::CondCode Condition;
2011
2012 explicit CondCodeSDNode(ISD::CondCode Cond)
2013 : SDNode(ISD::CONDCODE, 0, DebugLoc(), getSDVTList(MVT::Other)),
2014 Condition(Cond) {}
2015
2016public:
2017 ISD::CondCode get() const { return Condition; }
2018
2019 static bool classof(const SDNode *N) {
2020 return N->getOpcode() == ISD::CONDCODE;
2021 }
2022};
2023
2024/// This class is used to represent EVT's, which are used
2025/// to parameterize some operations.
2026class VTSDNode : public SDNode {
2027 friend class SelectionDAG;
2028
2029 EVT ValueType;
2030
2031 explicit VTSDNode(EVT VT)
2032 : SDNode(ISD::VALUETYPE, 0, DebugLoc(), getSDVTList(MVT::Other)),
2033 ValueType(VT) {}
2034
2035public:
2036 EVT getVT() const { return ValueType; }
2037
2038 static bool classof(const SDNode *N) {
2039 return N->getOpcode() == ISD::VALUETYPE;
2040 }
2041};
2042
2043/// Base class for LoadSDNode and StoreSDNode
2044class LSBaseSDNode : public MemSDNode {
2045public:
2046 LSBaseSDNode(ISD::NodeType NodeTy, unsigned Order, const DebugLoc &dl,
2047 SDVTList VTs, ISD::MemIndexedMode AM, EVT MemVT,
2048 MachineMemOperand *MMO)
2049 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {
2050 LSBaseSDNodeBits.AddressingMode = AM;
2051 assert(getAddressingMode() == AM && "Value truncated")((getAddressingMode() == AM && "Value truncated") ? static_cast
<void> (0) : __assert_fail ("getAddressingMode() == AM && \"Value truncated\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAGNodes.h"
, 2051, __PRETTY_FUNCTION__))
;
2052 }
2053
2054 const SDValue &getOffset() const {
2055 return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
2056 }
2057
2058 /// Return the addressing mode for this load or store:
2059 /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
2060 ISD::MemIndexedMode getAddressingMode() const {
2061 return static_cast<ISD::MemIndexedMode>(LSBaseSDNodeBits.AddressingMode);
2062 }
2063
2064 /// Return true if this is a pre/post inc/dec load/store.
2065 bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
2066
2067 /// Return true if this is NOT a pre/post inc/dec load/store.
2068 bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
2069
2070 static bool classof(const SDNode *N) {
2071 return N->getOpcode() == ISD::LOAD ||
2072 N->getOpcode() == ISD::STORE;
2073 }
2074};
2075
2076/// This class is used to represent ISD::LOAD nodes.
2077class LoadSDNode : public LSBaseSDNode {
2078 friend class SelectionDAG;
2079
2080 LoadSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2081 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, EVT MemVT,
2082 MachineMemOperand *MMO)
2083 : LSBaseSDNode(ISD::LOAD, Order, dl, VTs, AM, MemVT, MMO) {
2084 LoadSDNodeBits.ExtTy = ETy;
2085 assert(readMem() && "Load MachineMemOperand is not a load!")((readMem() && "Load MachineMemOperand is not a load!"
) ? static_cast<void> (0) : __assert_fail ("readMem() && \"Load MachineMemOperand is not a load!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAGNodes.h"
, 2085, __PRETTY_FUNCTION__))
;
2086 assert(!writeMem() && "Load MachineMemOperand is a store!")((!writeMem() && "Load MachineMemOperand is a store!"
) ? static_cast<void> (0) : __assert_fail ("!writeMem() && \"Load MachineMemOperand is a store!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAGNodes.h"
, 2086, __PRETTY_FUNCTION__))
;
2087 }
2088
2089public:
2090 /// Return whether this is a plain node,
2091 /// or one of the varieties of value-extending loads.
2092 ISD::LoadExtType getExtensionType() const {
2093 return static_cast<ISD::LoadExtType>(LoadSDNodeBits.ExtTy);
2094 }
2095
2096 const SDValue &getBasePtr() const { return getOperand(1); }
2097 const SDValue &getOffset() const { return getOperand(2); }
2098
2099 static bool classof(const SDNode *N) {
2100 return N->getOpcode() == ISD::LOAD;
2101 }
2102};
2103
2104/// This class is used to represent ISD::STORE nodes.
2105class StoreSDNode : public LSBaseSDNode {
2106 friend class SelectionDAG;
2107
2108 StoreSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2109 ISD::MemIndexedMode AM, bool isTrunc, EVT MemVT,
2110 MachineMemOperand *MMO)
2111 : LSBaseSDNode(ISD::STORE, Order, dl, VTs, AM, MemVT, MMO) {
2112 StoreSDNodeBits.IsTruncating = isTrunc;
2113 assert(!readMem() && "Store MachineMemOperand is a load!")((!readMem() && "Store MachineMemOperand is a load!")
? static_cast<void> (0) : __assert_fail ("!readMem() && \"Store MachineMemOperand is a load!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAGNodes.h"
, 2113, __PRETTY_FUNCTION__))
;
2114 assert(writeMem() && "Store MachineMemOperand is not a store!")((writeMem() && "Store MachineMemOperand is not a store!"
) ? static_cast<void> (0) : __assert_fail ("writeMem() && \"Store MachineMemOperand is not a store!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAGNodes.h"
, 2114, __PRETTY_FUNCTION__))
;
2115 }
2116
2117public:
2118 /// Return true if the op does a truncation before store.
2119 /// For integers this is the same as doing a TRUNCATE and storing the result.
2120 /// For floats, it is the same as doing an FP_ROUND and storing the result.
2121 bool isTruncatingStore() const { return StoreSDNodeBits.IsTruncating; }
2122 void setTruncatingStore(bool Truncating) {
2123 StoreSDNodeBits.IsTruncating = Truncating;
2124 }
2125
2126 const SDValue &getValue() const { return getOperand(1); }
2127 const SDValue &getBasePtr() const { return getOperand(2); }
2128 const SDValue &getOffset() const { return getOperand(3); }
2129
2130 static bool classof(const SDNode *N) {
2131 return N->getOpcode() == ISD::STORE;
2132 }
2133};
2134
2135/// This base class is used to represent MLOAD and MSTORE nodes
2136class MaskedLoadStoreSDNode : public MemSDNode {
2137public:
2138 friend class SelectionDAG;
2139
2140 MaskedLoadStoreSDNode(ISD::NodeType NodeTy, unsigned Order,
2141 const DebugLoc &dl, SDVTList VTs, EVT MemVT,
2142 MachineMemOperand *MMO)
2143 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {}
2144
2145 // MaskedLoadSDNode (Chain, ptr, mask, passthru)
2146 // MaskedStoreSDNode (Chain, data, ptr, mask)
2147 // Mask is a vector of i1 elements
2148 const SDValue &getBasePtr() const {
2149 return getOperand(getOpcode() == ISD::MLOAD ? 1 : 2);
2150 }
2151 const SDValue &getMask() const {
2152 return getOperand(getOpcode() == ISD::MLOAD ? 2 : 3);
2153 }
2154
2155 static bool classof(const SDNode *N) {
2156 return N->getOpcode() == ISD::MLOAD ||
2157 N->getOpcode() == ISD::MSTORE;
2158 }
2159};
2160
2161/// This class is used to represent an MLOAD node
2162class MaskedLoadSDNode : public MaskedLoadStoreSDNode {
2163public:
2164 friend class SelectionDAG;
2165
2166 MaskedLoadSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2167 ISD::LoadExtType ETy, bool IsExpanding, EVT MemVT,
2168 MachineMemOperand *MMO)
2169 : MaskedLoadStoreSDNode(ISD::MLOAD, Order, dl, VTs, MemVT, MMO) {
2170 LoadSDNodeBits.ExtTy = ETy;
2171 LoadSDNodeBits.IsExpanding = IsExpanding;
2172 }
2173
2174 ISD::LoadExtType getExtensionType() const {
2175 return static_cast<ISD::LoadExtType>(LoadSDNodeBits.ExtTy);
2176 }
2177
2178 const SDValue &getBasePtr() const { return getOperand(1); }
2179 const SDValue &getMask() const { return getOperand(2); }
2180 const SDValue &getPassThru() const { return getOperand(3); }
2181
2182 static bool classof(const SDNode *N) {
2183 return N->getOpcode() == ISD::MLOAD;
2184 }
2185
2186 bool isExpandingLoad() const { return LoadSDNodeBits.IsExpanding; }
2187};
2188
2189/// This class is used to represent an MSTORE node
2190class MaskedStoreSDNode : public MaskedLoadStoreSDNode {
2191public:
2192 friend class SelectionDAG;
2193
2194 MaskedStoreSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2195 bool isTrunc, bool isCompressing, EVT MemVT,
2196 MachineMemOperand *MMO)
2197 : MaskedLoadStoreSDNode(ISD::MSTORE, Order, dl, VTs, MemVT, MMO) {
2198 StoreSDNodeBits.IsTruncating = isTrunc;
2199 StoreSDNodeBits.IsCompressing = isCompressing;
2200 }
2201
2202 /// Return true if the op does a truncation before store.
2203 /// For integers this is the same as doing a TRUNCATE and storing the result.
2204 /// For floats, it is the same as doing an FP_ROUND and storing the result.
2205 bool isTruncatingStore() const { return StoreSDNodeBits.IsTruncating; }
2206
2207 /// Returns true if the op does a compression to the vector before storing.
2208 /// The node contiguously stores the active elements (integers or floats)
2209 /// in src (those with their respective bit set in writemask k) to unaligned
2210 /// memory at base_addr.
2211 bool isCompressingStore() const { return StoreSDNodeBits.IsCompressing; }
2212
2213 const SDValue &getValue() const { return getOperand(1); }
2214 const SDValue &getBasePtr() const { return getOperand(2); }
2215 const SDValue &getMask() const { return getOperand(3); }
2216
2217 static bool classof(const SDNode *N) {
2218 return N->getOpcode() == ISD::MSTORE;
2219 }
2220};
2221
2222/// This is a base class used to represent
2223/// MGATHER and MSCATTER nodes
2224///
2225class MaskedGatherScatterSDNode : public MemSDNode {
2226public:
2227 friend class SelectionDAG;
2228
2229 MaskedGatherScatterSDNode(ISD::NodeType NodeTy, unsigned Order,
2230 const DebugLoc &dl, SDVTList VTs, EVT MemVT,
2231 MachineMemOperand *MMO)
2232 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {}
2233
2234 // In the both nodes address is Op1, mask is Op2:
2235 // MaskedGatherSDNode (Chain, passthru, mask, base, index, scale)
2236 // MaskedScatterSDNode (Chain, value, mask, base, index, scale)
2237 // Mask is a vector of i1 elements
2238 const SDValue &getBasePtr() const { return getOperand(3); }
2239 const SDValue &getIndex() const { return getOperand(4); }
2240 const SDValue &getMask() const { return getOperand(2); }
2241 const SDValue &getScale() const { return getOperand(5); }
2242
2243 static bool classof(const SDNode *N) {
2244 return N->getOpcode() == ISD::MGATHER ||
2245 N->getOpcode() == ISD::MSCATTER;
2246 }
2247};
2248
2249/// This class is used to represent an MGATHER node
2250///
2251class MaskedGatherSDNode : public MaskedGatherScatterSDNode {
2252public:
2253 friend class SelectionDAG;
2254
2255 MaskedGatherSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2256 EVT MemVT, MachineMemOperand *MMO)
2257 : MaskedGatherScatterSDNode(ISD::MGATHER, Order, dl, VTs, MemVT, MMO) {}
2258
2259 const SDValue &getPassThru() const { return getOperand(1); }
2260
2261 static bool classof(const SDNode *N) {
2262 return N->getOpcode() == ISD::MGATHER;
2263 }
2264};
2265
2266/// This class is used to represent an MSCATTER node
2267///
2268class MaskedScatterSDNode : public MaskedGatherScatterSDNode {
2269public:
2270 friend class SelectionDAG;
2271
2272 MaskedScatterSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2273 EVT MemVT, MachineMemOperand *MMO)
2274 : MaskedGatherScatterSDNode(ISD::MSCATTER, Order, dl, VTs, MemVT, MMO) {}
2275
2276 const SDValue &getValue() const { return getOperand(1); }
2277
2278 static bool classof(const SDNode *N) {
2279 return N->getOpcode() == ISD::MSCATTER;
2280 }
2281};
2282
2283/// An SDNode that represents everything that will be needed
2284/// to construct a MachineInstr. These nodes are created during the
2285/// instruction selection proper phase.
2286///
2287/// Note that the only supported way to set the `memoperands` is by calling the
2288/// `SelectionDAG::setNodeMemRefs` function as the memory management happens
2289/// inside the DAG rather than in the node.
2290class MachineSDNode : public SDNode {
2291private:
2292 friend class SelectionDAG;
2293
2294 MachineSDNode(unsigned Opc, unsigned Order, const DebugLoc &DL, SDVTList VTs)
2295 : SDNode(Opc, Order, DL, VTs) {}
2296
2297 // We use a pointer union between a single `MachineMemOperand` pointer and
2298 // a pointer to an array of `MachineMemOperand` pointers. This is null when
2299 // the number of these is zero, the single pointer variant used when the
2300 // number is one, and the array is used for larger numbers.
2301 //
2302 // The array is allocated via the `SelectionDAG`'s allocator and so will
2303 // always live until the DAG is cleaned up and doesn't require ownership here.
2304 //
2305 // We can't use something simpler like `TinyPtrVector` here because `SDNode`
2306 // subclasses aren't managed in a conforming C++ manner. See the comments on
2307 // `SelectionDAG::MorphNodeTo` which details what all goes on, but the
2308 // constraint here is that these don't manage memory with their constructor or
2309 // destructor and can be initialized to a good state even if they start off
2310 // uninitialized.
2311 PointerUnion<MachineMemOperand *, MachineMemOperand **> MemRefs = {};
2312
2313 // Note that this could be folded into the above `MemRefs` member if doing so
2314 // is advantageous at some point. We don't need to store this in most cases.
2315 // However, at the moment this doesn't appear to make the allocation any
2316 // smaller and makes the code somewhat simpler to read.
2317 int NumMemRefs = 0;
2318
2319public:
2320 using mmo_iterator = ArrayRef<MachineMemOperand *>::const_iterator;
2321
2322 ArrayRef<MachineMemOperand *> memoperands() const {
2323 // Special case the common cases.
2324 if (NumMemRefs == 0)
2325 return {};
2326 if (NumMemRefs == 1)
2327 return makeArrayRef(MemRefs.getAddrOfPtr1(), 1);
2328
2329 // Otherwise we have an actual array.
2330 return makeArrayRef(MemRefs.get<MachineMemOperand **>(), NumMemRefs);
2331 }
2332 mmo_iterator memoperands_begin() const { return memoperands().begin(); }
2333 mmo_iterator memoperands_end() const { return memoperands().end(); }
2334 bool memoperands_empty() const { return memoperands().empty(); }
2335
2336 /// Clear out the memory reference descriptor list.
2337 void clearMemRefs() {
2338 MemRefs = nullptr;
2339 NumMemRefs = 0;
2340 }
2341
2342 static bool classof(const SDNode *N) {
2343 return N->isMachineOpcode();
2344 }
2345};
2346
2347class SDNodeIterator : public std::iterator<std::forward_iterator_tag,
2348 SDNode, ptrdiff_t> {
2349 const SDNode *Node;
2350 unsigned Operand;
2351
2352 SDNodeIterator(const SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
2353
2354public:
2355 bool operator==(const SDNodeIterator& x) const {
2356 return Operand == x.Operand;
2357 }
2358 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
2359
2360 pointer operator*() const {
2361 return Node->getOperand(Operand).getNode();
2362 }
2363 pointer operator->() const { return operator*(); }
2364
2365 SDNodeIterator& operator++() { // Preincrement
2366 ++Operand;
2367 return *this;
2368 }
2369 SDNodeIterator operator++(int) { // Postincrement
2370 SDNodeIterator tmp = *this; ++*this; return tmp;
2371 }
2372 size_t operator-(SDNodeIterator Other) const {
2373 assert(Node == Other.Node &&((Node == Other.Node && "Cannot compare iterators of two different nodes!"
) ? static_cast<void> (0) : __assert_fail ("Node == Other.Node && \"Cannot compare iterators of two different nodes!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAGNodes.h"
, 2374, __PRETTY_FUNCTION__))
2374 "Cannot compare iterators of two different nodes!")((Node == Other.Node && "Cannot compare iterators of two different nodes!"
) ? static_cast<void> (0) : __assert_fail ("Node == Other.Node && \"Cannot compare iterators of two different nodes!\""
, "/build/llvm-toolchain-snapshot-8~svn350071/include/llvm/CodeGen/SelectionDAGNodes.h"
, 2374, __PRETTY_FUNCTION__))
;
2375 return Operand - Other.Operand;
2376 }
2377
2378 static SDNodeIterator begin(const SDNode *N) { return SDNodeIterator(N, 0); }
2379 static SDNodeIterator end (const SDNode *N) {
2380 return SDNodeIterator(N, N->getNumOperands());
2381 }
2382
2383 unsigned getOperand() const { return Operand; }
2384 const SDNode *getNode() const { return Node; }
2385};
2386
2387template <> struct GraphTraits<SDNode*> {
2388 using NodeRef = SDNode *;
2389 using ChildIteratorType = SDNodeIterator;
2390
2391 static NodeRef getEntryNode(SDNode *N) { return N; }
2392
2393 static ChildIteratorType child_begin(NodeRef N) {
2394 return SDNodeIterator::begin(N);
2395 }
2396
2397 static ChildIteratorType child_end(NodeRef N) {
2398 return SDNodeIterator::end(N);
2399 }
2400};
2401
2402/// A representation of the largest SDNode, for use in sizeof().
2403///
2404/// This needs to be a union because the largest node differs on 32 bit systems
2405/// with 4 and 8 byte pointer alignment, respectively.
2406using LargestSDNode = AlignedCharArrayUnion<AtomicSDNode, TargetIndexSDNode,
2407 BlockAddressSDNode,
2408 GlobalAddressSDNode>;
2409
2410/// The SDNode class with the greatest alignment requirement.
2411using MostAlignedSDNode = GlobalAddressSDNode;
2412
2413namespace ISD {
2414
2415 /// Returns true if the specified node is a non-extending and unindexed load.
2416 inline bool isNormalLoad(const SDNode *N) {
2417 const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N);
2418 return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
2419 Ld->getAddressingMode() == ISD::UNINDEXED;
2420 }
2421
2422 /// Returns true if the specified node is a non-extending load.
2423 inline bool isNON_EXTLoad(const SDNode *N) {
2424 return isa<LoadSDNode>(N) &&
2425 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
2426 }
2427
2428 /// Returns true if the specified node is a EXTLOAD.
2429 inline bool isEXTLoad(const SDNode *N) {
2430 return isa<LoadSDNode>(N) &&
2431 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
2432 }
2433
2434 /// Returns true if the specified node is a SEXTLOAD.
2435 inline bool isSEXTLoad(const SDNode *N) {
2436 return isa<LoadSDNode>(N) &&
2437 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
2438 }
2439
2440 /// Returns true if the specified node is a ZEXTLOAD.
2441 inline bool isZEXTLoad(const SDNode *N) {
2442 return isa<LoadSDNode>(N) &&
2443 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
2444 }
2445
2446 /// Returns true if the specified node is an unindexed load.
2447 inline bool isUNINDEXEDLoad(const SDNode *N) {
2448 return isa<LoadSDNode>(N) &&
2449 cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2450 }
2451
2452 /// Returns true if the specified node is a non-truncating
2453 /// and unindexed store.
2454 inline bool isNormalStore(const SDNode *N) {
2455 const StoreSDNode *St = dyn_cast<StoreSDNode>(N);
2456 return St && !St->isTruncatingStore() &&
2457 St->getAddressingMode() == ISD::UNINDEXED;
2458 }
2459
2460 /// Returns true if the specified node is a non-truncating store.
2461 inline bool isNON_TRUNCStore(const SDNode *N) {
2462 return isa<StoreSDNode>(N) && !cast<StoreSDNode>(N)->isTruncatingStore();
2463 }
2464
2465 /// Returns true if the specified node is a truncating store.
2466 inline bool isTRUNCStore(const SDNode *N) {
2467 return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore();
2468 }
2469
2470 /// Returns true if the specified node is an unindexed store.
2471 inline bool isUNINDEXEDStore(const SDNode *N) {
2472 return isa<StoreSDNode>(N) &&
2473 cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2474 }
2475
2476 /// Return true if the node is a math/logic binary operator. This corresponds
2477 /// to the IR function of the same name.
2478 inline bool isBinaryOp(const SDNode *N) {
2479 auto Op = N->getOpcode();
2480 return (Op == ISD::ADD || Op == ISD::SUB || Op == ISD::MUL ||
2481 Op == ISD::AND || Op == ISD::OR || Op == ISD::XOR ||
2482 Op == ISD::SHL || Op == ISD::SRL || Op == ISD::SRA ||
2483 Op == ISD::SDIV || Op == ISD::UDIV || Op == ISD::SREM ||
2484 Op == ISD::UREM || Op == ISD::FADD || Op == ISD::FSUB ||
2485 Op == ISD::FMUL || Op == ISD::FDIV || Op == ISD::FREM);
2486 }
2487
2488 /// Attempt to match a unary predicate against a scalar/splat constant or
2489 /// every element of a constant BUILD_VECTOR.
2490 /// If AllowUndef is true, then UNDEF elements will pass nullptr to Match.
2491 bool matchUnaryPredicate(SDValue Op,
2492 std::function<bool(ConstantSDNode *)> Match,
2493 bool AllowUndefs = false);
2494
2495 /// Attempt to match a binary predicate against a pair of scalar/splat
2496 /// constants or every element of a pair of constant BUILD_VECTORs.
2497 /// If AllowUndef is true, then UNDEF elements will pass nullptr to Match.
2498 bool matchBinaryPredicate(
2499 SDValue LHS, SDValue RHS,
2500 std::function<bool(ConstantSDNode *, ConstantSDNode *)> Match,
2501 bool AllowUndefs = false);
2502} // end namespace ISD
2503
2504} // end namespace llvm
2505
2506#endif // LLVM_CODEGEN_SELECTIONDAGNODES_H