Bug Summary

File:include/llvm/CodeGen/SelectionDAGNodes.h
Warning:line 1110, 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-eagerly-assume -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 -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-7/lib/clang/7.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-7~svn338205/build-llvm/lib/Target/X86 -I /build/llvm-toolchain-snapshot-7~svn338205/lib/Target/X86 -I /build/llvm-toolchain-snapshot-7~svn338205/build-llvm/include -I /build/llvm-toolchain-snapshot-7~svn338205/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/x86_64-linux-gnu/c++/8 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/x86_64-linux-gnu/c++/8 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/backward -internal-isystem /usr/include/clang/7.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-7/lib/clang/7.0.0/include -internal-externc-isystem /usr/lib/gcc/x86_64-linux-gnu/8/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-class-memaccess -Wno-comment -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-7~svn338205/build-llvm/lib/Target/X86 -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-07-29-043837-17923-1 -x c++ /build/llvm-toolchain-snapshot-7~svn338205/lib/Target/X86/X86SelectionDAGInfo.cpp -faddrsig

/build/llvm-toolchain-snapshot-7~svn338205/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))(static_cast <bool> (!isBaseRegConflictPossible(DAG, ClobberSet
)) ? void (0) : __assert_fail ("!isBaseRegConflictPossible(DAG, ClobberSet)"
, "/build/llvm-toolchain-snapshot-7~svn338205/lib/Target/X86/X86SelectionDAGInfo.cpp"
, 77, __extension__ __PRETTY_FUNCTION__))
;
78#endif
79
80 // If to a segment-relative address space, use the default lowering.
81 if (DstPtrInfo.getAddrSpace() >= 256)
1
Assuming the condition is false
2
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 ||
3
Assuming the condition is false
4
Assuming 'ConstantSize' is non-null
6
Taking false branch
88 ConstantSize->getZExtValue() > Subtarget.getMaxInlineSizeThreshold()) {
5
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) {
7
Assuming 'ValC' is non-null
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 Chain = DAG.getCopyToReg(Chain, dl, Subtarget.is64Bit() ? X86::RCX : X86::ECX,
13
'?' condition is false
14
Null pointer value stored to 'N.Node'
15
Calling 'SelectionDAG::getCopyToReg'
174 Count, InFlag);
175 InFlag = Chain.getValue(1);
176 Chain = DAG.getCopyToReg(Chain, dl, Subtarget.is64Bit() ? X86::RDI : X86::EDI,
177 Dst, InFlag);
178 InFlag = Chain.getValue(1);
179
180 SDVTList Tys = DAG.getVTList(MVT::Other, MVT::Glue);
181 SDValue Ops[] = { Chain, DAG.getValueType(AVT), InFlag };
182 Chain = DAG.getNode(X86ISD::REP_STOS, dl, Tys, Ops);
183
184 if (BytesLeft) {
185 // Handle the last 1 - 7 bytes.
186 unsigned Offset = SizeVal - BytesLeft;
187 EVT AddrVT = Dst.getValueType();
188 EVT SizeVT = Size.getValueType();
189
190 Chain = DAG.getMemset(Chain, dl,
191 DAG.getNode(ISD::ADD, dl, AddrVT, Dst,
192 DAG.getConstant(Offset, dl, AddrVT)),
193 Val,
194 DAG.getConstant(BytesLeft, dl, SizeVT),
195 Align, isVolatile, false,
196 DstPtrInfo.getWithOffset(Offset));
197 }
198
199 // TODO: Use a Tokenfactor, as in memcpy, instead of a single chain.
200 return Chain;
201}
202
203SDValue X86SelectionDAGInfo::EmitTargetCodeForMemcpy(
204 SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Dst, SDValue Src,
205 SDValue Size, unsigned Align, bool isVolatile, bool AlwaysInline,
206 MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const {
207 // This requires the copy size to be a constant, preferably
208 // within a subtarget-specific limit.
209 ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size);
210 const X86Subtarget &Subtarget =
211 DAG.getMachineFunction().getSubtarget<X86Subtarget>();
212 if (!ConstantSize)
213 return SDValue();
214 RepMovsRepeats Repeats(ConstantSize->getZExtValue());
215 if (!AlwaysInline && Repeats.Size > Subtarget.getMaxInlineSizeThreshold())
216 return SDValue();
217
218 /// If not DWORD aligned, it is more efficient to call the library. However
219 /// if calling the library is not allowed (AlwaysInline), then soldier on as
220 /// the code generated here is better than the long load-store sequence we
221 /// would otherwise get.
222 if (!AlwaysInline && (Align & 3) != 0)
223 return SDValue();
224
225 // If to a segment-relative address space, use the default lowering.
226 if (DstPtrInfo.getAddrSpace() >= 256 ||
227 SrcPtrInfo.getAddrSpace() >= 256)
228 return SDValue();
229
230 // If the base register might conflict with our physical registers, bail out.
231 const MCPhysReg ClobberSet[] = {X86::RCX, X86::RSI, X86::RDI,
232 X86::ECX, X86::ESI, X86::EDI};
233 if (isBaseRegConflictPossible(DAG, ClobberSet))
234 return SDValue();
235
236 // If the target has enhanced REPMOVSB, then it's at least as fast to use
237 // REP MOVSB instead of REP MOVS{W,D,Q}, and it avoids having to handle
238 // BytesLeft.
239 if (!Subtarget.hasERMSB() && !(Align & 1)) {
240 if (Align & 2)
241 // WORD aligned
242 Repeats.AVT = MVT::i16;
243 else if (Align & 4)
244 // DWORD aligned
245 Repeats.AVT = MVT::i32;
246 else
247 // QWORD aligned
248 Repeats.AVT = Subtarget.is64Bit() ? MVT::i64 : MVT::i32;
249
250 if (Repeats.BytesLeft() > 0 &&
251 DAG.getMachineFunction().getFunction().optForMinSize()) {
252 // When agressively optimizing for size, avoid generating the code to
253 // handle BytesLeft.
254 Repeats.AVT = MVT::i8;
255 }
256 }
257
258 SDValue InFlag;
259 Chain = DAG.getCopyToReg(Chain, dl, Subtarget.is64Bit() ? X86::RCX : X86::ECX,
260 DAG.getIntPtrConstant(Repeats.Count(), dl), InFlag);
261 InFlag = Chain.getValue(1);
262 Chain = DAG.getCopyToReg(Chain, dl, Subtarget.is64Bit() ? X86::RDI : X86::EDI,
263 Dst, InFlag);
264 InFlag = Chain.getValue(1);
265 Chain = DAG.getCopyToReg(Chain, dl, Subtarget.is64Bit() ? X86::RSI : X86::ESI,
266 Src, InFlag);
267 InFlag = Chain.getValue(1);
268
269 SDVTList Tys = DAG.getVTList(MVT::Other, MVT::Glue);
270 SDValue Ops[] = { Chain, DAG.getValueType(Repeats.AVT), InFlag };
271 SDValue RepMovs = DAG.getNode(X86ISD::REP_MOVS, dl, Tys, Ops);
272
273 SmallVector<SDValue, 4> Results;
274 Results.push_back(RepMovs);
275 if (Repeats.BytesLeft()) {
276 // Handle the last 1 - 7 bytes.
277 unsigned Offset = Repeats.Size - Repeats.BytesLeft();
278 EVT DstVT = Dst.getValueType();
279 EVT SrcVT = Src.getValueType();
280 EVT SizeVT = Size.getValueType();
281 Results.push_back(DAG.getMemcpy(Chain, dl,
282 DAG.getNode(ISD::ADD, dl, DstVT, Dst,
283 DAG.getConstant(Offset, dl,
284 DstVT)),
285 DAG.getNode(ISD::ADD, dl, SrcVT, Src,
286 DAG.getConstant(Offset, dl,
287 SrcVT)),
288 DAG.getConstant(Repeats.BytesLeft(), dl,
289 SizeVT),
290 Align, isVolatile, AlwaysInline, false,
291 DstPtrInfo.getWithOffset(Offset),
292 SrcPtrInfo.getWithOffset(Offset)));
293 }
294
295 return DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Results);
296}

/build/llvm-toolchain-snapshot-7~svn338205/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/DivergenceAnalysis.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-7~svn338205/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) {
192 DbgValMapType::iterator 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 DivergenceAnalysis * 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 &&(static_cast <bool> (DAG.UpdateListeners == this &&
"DAGUpdateListeners must be destroyed in LIFO order") ? void
(0) : __assert_fail ("DAG.UpdateListeners == this && \"DAGUpdateListeners must be destroyed in LIFO order\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAG.h"
, 291, __extension__ __PRETTY_FUNCTION__))
291 "DAGUpdateListeners must be destroyed in LIFO order")(static_cast <bool> (DAG.UpdateListeners == this &&
"DAGUpdateListeners must be destroyed in LIFO order") ? void
(0) : __assert_fail ("DAG.UpdateListeners == this && \"DAGUpdateListeners must be destroyed in LIFO order\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAG.h"
, 291, __extension__ __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 DivergenceAnalysis * 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) &&(static_cast <bool> ((!N.getNode() || N.getValueType() ==
MVT::Other) && "DAG root value is not a chain!") ? void
(0) : __assert_fail ("(!N.getNode() || N.getValueType() == MVT::Other) && \"DAG root value is not a chain!\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAG.h"
, 465, __extension__ __PRETTY_FUNCTION__))
465 "DAG root value is not a chain!")(static_cast <bool> ((!N.getNode() || N.getValueType() ==
MVT::Other) && "DAG root value is not a chain!") ? void
(0) : __assert_fail ("(!N.getNode() || N.getValueType() == MVT::Other) && \"DAG root value is not a chain!\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAG.h"
, 465, __extension__ __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 void VerifyDAGDiverence();
475
476 /// This iterates over the nodes in the SelectionDAG, folding
477 /// certain types of nodes together, or eliminating superfluous nodes. The
478 /// Level argument controls whether Combine is allowed to produce nodes and
479 /// types that are illegal on the target.
480 void Combine(CombineLevel Level, AliasAnalysis *AA,
481 CodeGenOpt::Level OptLevel);
482
483 /// This transforms the SelectionDAG into a SelectionDAG that
484 /// only uses types natively supported by the target.
485 /// Returns "true" if it made any changes.
486 ///
487 /// Note that this is an involved process that may invalidate pointers into
488 /// the graph.
489 bool LegalizeTypes();
490
491 /// This transforms the SelectionDAG into a SelectionDAG that is
492 /// compatible with the target instruction selector, as indicated by the
493 /// TargetLowering object.
494 ///
495 /// Note that this is an involved process that may invalidate pointers into
496 /// the graph.
497 void Legalize();
498
499 /// Transforms a SelectionDAG node and any operands to it into a node
500 /// that is compatible with the target instruction selector, as indicated by
501 /// the TargetLowering object.
502 ///
503 /// \returns true if \c N is a valid, legal node after calling this.
504 ///
505 /// This essentially runs a single recursive walk of the \c Legalize process
506 /// over the given node (and its operands). This can be used to incrementally
507 /// legalize the DAG. All of the nodes which are directly replaced,
508 /// potentially including N, are added to the output parameter \c
509 /// UpdatedNodes so that the delta to the DAG can be understood by the
510 /// caller.
511 ///
512 /// When this returns false, N has been legalized in a way that make the
513 /// pointer passed in no longer valid. It may have even been deleted from the
514 /// DAG, and so it shouldn't be used further. When this returns true, the
515 /// N passed in is a legal node, and can be immediately processed as such.
516 /// This may still have done some work on the DAG, and will still populate
517 /// UpdatedNodes with any new nodes replacing those originally in the DAG.
518 bool LegalizeOp(SDNode *N, SmallSetVector<SDNode *, 16> &UpdatedNodes);
519
520 /// This transforms the SelectionDAG into a SelectionDAG
521 /// that only uses vector math operations supported by the target. This is
522 /// necessary as a separate step from Legalize because unrolling a vector
523 /// operation can introduce illegal types, which requires running
524 /// LegalizeTypes again.
525 ///
526 /// This returns true if it made any changes; in that case, LegalizeTypes
527 /// is called again before Legalize.
528 ///
529 /// Note that this is an involved process that may invalidate pointers into
530 /// the graph.
531 bool LegalizeVectors();
532
533 /// This method deletes all unreachable nodes in the SelectionDAG.
534 void RemoveDeadNodes();
535
536 /// Remove the specified node from the system. This node must
537 /// have no referrers.
538 void DeleteNode(SDNode *N);
539
540 /// Return an SDVTList that represents the list of values specified.
541 SDVTList getVTList(EVT VT);
542 SDVTList getVTList(EVT VT1, EVT VT2);
543 SDVTList getVTList(EVT VT1, EVT VT2, EVT VT3);
544 SDVTList getVTList(EVT VT1, EVT VT2, EVT VT3, EVT VT4);
545 SDVTList getVTList(ArrayRef<EVT> VTs);
546
547 //===--------------------------------------------------------------------===//
548 // Node creation methods.
549
550 /// Create a ConstantSDNode wrapping a constant value.
551 /// If VT is a vector type, the constant is splatted into a BUILD_VECTOR.
552 ///
553 /// If only legal types can be produced, this does the necessary
554 /// transformations (e.g., if the vector element type is illegal).
555 /// @{
556 SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT,
557 bool isTarget = false, bool isOpaque = false);
558 SDValue getConstant(const APInt &Val, const SDLoc &DL, EVT VT,
559 bool isTarget = false, bool isOpaque = false);
560
561 SDValue getAllOnesConstant(const SDLoc &DL, EVT VT, bool IsTarget = false,
562 bool IsOpaque = false) {
563 return getConstant(APInt::getAllOnesValue(VT.getScalarSizeInBits()), DL,
564 VT, IsTarget, IsOpaque);
565 }
566
567 SDValue getConstant(const ConstantInt &Val, const SDLoc &DL, EVT VT,
568 bool isTarget = false, bool isOpaque = false);
569 SDValue getIntPtrConstant(uint64_t Val, const SDLoc &DL,
570 bool isTarget = false);
571 SDValue getTargetConstant(uint64_t Val, const SDLoc &DL, EVT VT,
572 bool isOpaque = false) {
573 return getConstant(Val, DL, VT, true, isOpaque);
574 }
575 SDValue getTargetConstant(const APInt &Val, const SDLoc &DL, EVT VT,
576 bool isOpaque = false) {
577 return getConstant(Val, DL, VT, true, isOpaque);
578 }
579 SDValue getTargetConstant(const ConstantInt &Val, const SDLoc &DL, EVT VT,
580 bool isOpaque = false) {
581 return getConstant(Val, DL, VT, true, isOpaque);
582 }
583
584 /// Create a true or false constant of type \p VT using the target's
585 /// BooleanContent for type \p OpVT.
586 SDValue getBoolConstant(bool V, const SDLoc &DL, EVT VT, EVT OpVT);
587 /// @}
588
589 /// Create a ConstantFPSDNode wrapping a constant value.
590 /// If VT is a vector type, the constant is splatted into a BUILD_VECTOR.
591 ///
592 /// If only legal types can be produced, this does the necessary
593 /// transformations (e.g., if the vector element type is illegal).
594 /// The forms that take a double should only be used for simple constants
595 /// that can be exactly represented in VT. No checks are made.
596 /// @{
597 SDValue getConstantFP(double Val, const SDLoc &DL, EVT VT,
598 bool isTarget = false);
599 SDValue getConstantFP(const APFloat &Val, const SDLoc &DL, EVT VT,
600 bool isTarget = false);
601 SDValue getConstantFP(const ConstantFP &V, const SDLoc &DL, EVT VT,
602 bool isTarget = false);
603 SDValue getTargetConstantFP(double Val, const SDLoc &DL, EVT VT) {
604 return getConstantFP(Val, DL, VT, true);
605 }
606 SDValue getTargetConstantFP(const APFloat &Val, const SDLoc &DL, EVT VT) {
607 return getConstantFP(Val, DL, VT, true);
608 }
609 SDValue getTargetConstantFP(const ConstantFP &Val, const SDLoc &DL, EVT VT) {
610 return getConstantFP(Val, DL, VT, true);
611 }
612 /// @}
613
614 SDValue getGlobalAddress(const GlobalValue *GV, const SDLoc &DL, EVT VT,
615 int64_t offset = 0, bool isTargetGA = false,
616 unsigned char TargetFlags = 0);
617 SDValue getTargetGlobalAddress(const GlobalValue *GV, const SDLoc &DL, EVT VT,
618 int64_t offset = 0,
619 unsigned char TargetFlags = 0) {
620 return getGlobalAddress(GV, DL, VT, offset, true, TargetFlags);
621 }
622 SDValue getFrameIndex(int FI, EVT VT, bool isTarget = false);
623 SDValue getTargetFrameIndex(int FI, EVT VT) {
624 return getFrameIndex(FI, VT, true);
625 }
626 SDValue getJumpTable(int JTI, EVT VT, bool isTarget = false,
627 unsigned char TargetFlags = 0);
628 SDValue getTargetJumpTable(int JTI, EVT VT, unsigned char TargetFlags = 0) {
629 return getJumpTable(JTI, VT, true, TargetFlags);
630 }
631 SDValue getConstantPool(const Constant *C, EVT VT,
632 unsigned Align = 0, int Offs = 0, bool isT=false,
633 unsigned char TargetFlags = 0);
634 SDValue getTargetConstantPool(const Constant *C, EVT VT,
635 unsigned Align = 0, int Offset = 0,
636 unsigned char TargetFlags = 0) {
637 return getConstantPool(C, VT, Align, Offset, true, TargetFlags);
638 }
639 SDValue getConstantPool(MachineConstantPoolValue *C, EVT VT,
640 unsigned Align = 0, int Offs = 0, bool isT=false,
641 unsigned char TargetFlags = 0);
642 SDValue getTargetConstantPool(MachineConstantPoolValue *C,
643 EVT VT, unsigned Align = 0,
644 int Offset = 0, unsigned char TargetFlags=0) {
645 return getConstantPool(C, VT, Align, Offset, true, TargetFlags);
646 }
647 SDValue getTargetIndex(int Index, EVT VT, int64_t Offset = 0,
648 unsigned char TargetFlags = 0);
649 // When generating a branch to a BB, we don't in general know enough
650 // to provide debug info for the BB at that time, so keep this one around.
651 SDValue getBasicBlock(MachineBasicBlock *MBB);
652 SDValue getBasicBlock(MachineBasicBlock *MBB, SDLoc dl);
653 SDValue getExternalSymbol(const char *Sym, EVT VT);
654 SDValue getExternalSymbol(const char *Sym, const SDLoc &dl, EVT VT);
655 SDValue getTargetExternalSymbol(const char *Sym, EVT VT,
656 unsigned char TargetFlags = 0);
657 SDValue getMCSymbol(MCSymbol *Sym, EVT VT);
658
659 SDValue getValueType(EVT);
660 SDValue getRegister(unsigned Reg, EVT VT);
661 SDValue getRegisterMask(const uint32_t *RegMask);
662 SDValue getEHLabel(const SDLoc &dl, SDValue Root, MCSymbol *Label);
663 SDValue getLabelNode(unsigned Opcode, const SDLoc &dl, SDValue Root,
664 MCSymbol *Label);
665 SDValue getBlockAddress(const BlockAddress *BA, EVT VT,
666 int64_t Offset = 0, bool isTarget = false,
667 unsigned char TargetFlags = 0);
668 SDValue getTargetBlockAddress(const BlockAddress *BA, EVT VT,
669 int64_t Offset = 0,
670 unsigned char TargetFlags = 0) {
671 return getBlockAddress(BA, VT, Offset, true, TargetFlags);
672 }
673
674 SDValue getCopyToReg(SDValue Chain, const SDLoc &dl, unsigned Reg,
675 SDValue N) {
676 return getNode(ISD::CopyToReg, dl, MVT::Other, Chain,
677 getRegister(Reg, N.getValueType()), N);
678 }
679
680 // This version of the getCopyToReg method takes an extra operand, which
681 // indicates that there is potentially an incoming glue value (if Glue is not
682 // null) and that there should be a glue result.
683 SDValue getCopyToReg(SDValue Chain, const SDLoc &dl, unsigned Reg, SDValue N,
684 SDValue Glue) {
685 SDVTList VTs = getVTList(MVT::Other, MVT::Glue);
686 SDValue Ops[] = { Chain, getRegister(Reg, N.getValueType()), N, Glue };
16
Calling 'SDValue::getValueType'
687 return getNode(ISD::CopyToReg, dl, VTs,
688 makeArrayRef(Ops, Glue.getNode() ? 4 : 3));
689 }
690
691 // Similar to last getCopyToReg() except parameter Reg is a SDValue
692 SDValue getCopyToReg(SDValue Chain, const SDLoc &dl, SDValue Reg, SDValue N,
693 SDValue Glue) {
694 SDVTList VTs = getVTList(MVT::Other, MVT::Glue);
695 SDValue Ops[] = { Chain, Reg, N, Glue };
696 return getNode(ISD::CopyToReg, dl, VTs,
697 makeArrayRef(Ops, Glue.getNode() ? 4 : 3));
698 }
699
700 SDValue getCopyFromReg(SDValue Chain, const SDLoc &dl, unsigned Reg, EVT VT) {
701 SDVTList VTs = getVTList(VT, MVT::Other);
702 SDValue Ops[] = { Chain, getRegister(Reg, VT) };
703 return getNode(ISD::CopyFromReg, dl, VTs, Ops);
704 }
705
706 // This version of the getCopyFromReg method takes an extra operand, which
707 // indicates that there is potentially an incoming glue value (if Glue is not
708 // null) and that there should be a glue result.
709 SDValue getCopyFromReg(SDValue Chain, const SDLoc &dl, unsigned Reg, EVT VT,
710 SDValue Glue) {
711 SDVTList VTs = getVTList(VT, MVT::Other, MVT::Glue);
712 SDValue Ops[] = { Chain, getRegister(Reg, VT), Glue };
713 return getNode(ISD::CopyFromReg, dl, VTs,
714 makeArrayRef(Ops, Glue.getNode() ? 3 : 2));
715 }
716
717 SDValue getCondCode(ISD::CondCode Cond);
718
719 /// Return an ISD::VECTOR_SHUFFLE node. The number of elements in VT,
720 /// which must be a vector type, must match the number of mask elements
721 /// NumElts. An integer mask element equal to -1 is treated as undefined.
722 SDValue getVectorShuffle(EVT VT, const SDLoc &dl, SDValue N1, SDValue N2,
723 ArrayRef<int> Mask);
724
725 /// Return an ISD::BUILD_VECTOR node. The number of elements in VT,
726 /// which must be a vector type, must match the number of operands in Ops.
727 /// The operands must have the same type as (or, for integers, a type wider
728 /// than) VT's element type.
729 SDValue getBuildVector(EVT VT, const SDLoc &DL, ArrayRef<SDValue> Ops) {
730 // VerifySDNode (via InsertNode) checks BUILD_VECTOR later.
731 return getNode(ISD::BUILD_VECTOR, DL, VT, Ops);
732 }
733
734 /// Return an ISD::BUILD_VECTOR node. The number of elements in VT,
735 /// which must be a vector type, must match the number of operands in Ops.
736 /// The operands must have the same type as (or, for integers, a type wider
737 /// than) VT's element type.
738 SDValue getBuildVector(EVT VT, const SDLoc &DL, ArrayRef<SDUse> Ops) {
739 // VerifySDNode (via InsertNode) checks BUILD_VECTOR later.
740 return getNode(ISD::BUILD_VECTOR, DL, VT, Ops);
741 }
742
743 /// Return a splat ISD::BUILD_VECTOR node, consisting of Op splatted to all
744 /// elements. VT must be a vector type. Op's type must be the same as (or,
745 /// for integers, a type wider than) VT's element type.
746 SDValue getSplatBuildVector(EVT VT, const SDLoc &DL, SDValue Op) {
747 // VerifySDNode (via InsertNode) checks BUILD_VECTOR later.
748 if (Op.getOpcode() == ISD::UNDEF) {
749 assert((VT.getVectorElementType() == Op.getValueType() ||(static_cast <bool> ((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!") ? 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-7~svn338205/include/llvm/CodeGen/SelectionDAG.h"
, 753, __extension__ __PRETTY_FUNCTION__))
750 (VT.isInteger() &&(static_cast <bool> ((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!") ? 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-7~svn338205/include/llvm/CodeGen/SelectionDAG.h"
, 753, __extension__ __PRETTY_FUNCTION__))
751 VT.getVectorElementType().bitsLE(Op.getValueType()))) &&(static_cast <bool> ((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!") ? 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-7~svn338205/include/llvm/CodeGen/SelectionDAG.h"
, 753, __extension__ __PRETTY_FUNCTION__))
752 "A splatted value must have a width equal or (for integers) "(static_cast <bool> ((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!") ? 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-7~svn338205/include/llvm/CodeGen/SelectionDAG.h"
, 753, __extension__ __PRETTY_FUNCTION__))
753 "greater than the vector element type!")(static_cast <bool> ((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!") ? 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-7~svn338205/include/llvm/CodeGen/SelectionDAG.h"
, 753, __extension__ __PRETTY_FUNCTION__))
;
754 return getNode(ISD::UNDEF, SDLoc(), VT);
755 }
756
757 SmallVector<SDValue, 16> Ops(VT.getVectorNumElements(), Op);
758 return getNode(ISD::BUILD_VECTOR, DL, VT, Ops);
759 }
760
761 /// Returns an ISD::VECTOR_SHUFFLE node semantically equivalent to
762 /// the shuffle node in input but with swapped operands.
763 ///
764 /// Example: shuffle A, B, <0,5,2,7> -> shuffle B, A, <4,1,6,3>
765 SDValue getCommutedVectorShuffle(const ShuffleVectorSDNode &SV);
766
767 /// Convert Op, which must be of float type, to the
768 /// float type VT, by either extending or rounding (by truncation).
769 SDValue getFPExtendOrRound(SDValue Op, const SDLoc &DL, EVT VT);
770
771 /// Convert Op, which must be of integer type, to the
772 /// integer type VT, by either any-extending or truncating it.
773 SDValue getAnyExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT);
774
775 /// Convert Op, which must be of integer type, to the
776 /// integer type VT, by either sign-extending or truncating it.
777 SDValue getSExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT);
778
779 /// Convert Op, which must be of integer type, to the
780 /// integer type VT, by either zero-extending or truncating it.
781 SDValue getZExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT);
782
783 /// Return the expression required to zero extend the Op
784 /// value assuming it was the smaller SrcTy value.
785 SDValue getZeroExtendInReg(SDValue Op, const SDLoc &DL, EVT VT);
786
787 /// Return an operation which will any-extend the low lanes of the operand
788 /// into the specified vector type. For example,
789 /// this can convert a v16i8 into a v4i32 by any-extending the low four
790 /// lanes of the operand from i8 to i32.
791 SDValue getAnyExtendVectorInReg(SDValue Op, const SDLoc &DL, EVT VT);
792
793 /// Return an operation which will sign extend the low lanes of the operand
794 /// into the specified vector type. For example,
795 /// this can convert a v16i8 into a v4i32 by sign extending the low four
796 /// lanes of the operand from i8 to i32.
797 SDValue getSignExtendVectorInReg(SDValue Op, const SDLoc &DL, EVT VT);
798
799 /// Return an operation which will zero extend the low lanes of the operand
800 /// into the specified vector type. For example,
801 /// this can convert a v16i8 into a v4i32 by zero extending the low four
802 /// lanes of the operand from i8 to i32.
803 SDValue getZeroExtendVectorInReg(SDValue Op, const SDLoc &DL, EVT VT);
804
805 /// Convert Op, which must be of integer type, to the integer type VT,
806 /// by using an extension appropriate for the target's
807 /// BooleanContent for type OpVT or truncating it.
808 SDValue getBoolExtOrTrunc(SDValue Op, const SDLoc &SL, EVT VT, EVT OpVT);
809
810 /// Create a bitwise NOT operation as (XOR Val, -1).
811 SDValue getNOT(const SDLoc &DL, SDValue Val, EVT VT);
812
813 /// Create a logical NOT operation as (XOR Val, BooleanOne).
814 SDValue getLogicalNOT(const SDLoc &DL, SDValue Val, EVT VT);
815
816 /// Create an add instruction with appropriate flags when used for
817 /// addressing some offset of an object. i.e. if a load is split into multiple
818 /// components, create an add nuw from the base pointer to the offset.
819 SDValue getObjectPtrOffset(const SDLoc &SL, SDValue Op, int64_t Offset) {
820 EVT VT = Op.getValueType();
821 return getObjectPtrOffset(SL, Op, getConstant(Offset, SL, VT));
822 }
823
824 SDValue getObjectPtrOffset(const SDLoc &SL, SDValue Op, SDValue Offset) {
825 EVT VT = Op.getValueType();
826
827 // The object itself can't wrap around the address space, so it shouldn't be
828 // possible for the adds of the offsets to the split parts to overflow.
829 SDNodeFlags Flags;
830 Flags.setNoUnsignedWrap(true);
831 return getNode(ISD::ADD, SL, VT, Op, Offset, Flags);
832 }
833
834 /// Return a new CALLSEQ_START node, that starts new call frame, in which
835 /// InSize bytes are set up inside CALLSEQ_START..CALLSEQ_END sequence and
836 /// OutSize specifies part of the frame set up prior to the sequence.
837 SDValue getCALLSEQ_START(SDValue Chain, uint64_t InSize, uint64_t OutSize,
838 const SDLoc &DL) {
839 SDVTList VTs = getVTList(MVT::Other, MVT::Glue);
840 SDValue Ops[] = { Chain,
841 getIntPtrConstant(InSize, DL, true),
842 getIntPtrConstant(OutSize, DL, true) };
843 return getNode(ISD::CALLSEQ_START, DL, VTs, Ops);
844 }
845
846 /// Return a new CALLSEQ_END node, which always must have a
847 /// glue result (to ensure it's not CSE'd).
848 /// CALLSEQ_END does not have a useful SDLoc.
849 SDValue getCALLSEQ_END(SDValue Chain, SDValue Op1, SDValue Op2,
850 SDValue InGlue, const SDLoc &DL) {
851 SDVTList NodeTys = getVTList(MVT::Other, MVT::Glue);
852 SmallVector<SDValue, 4> Ops;
853 Ops.push_back(Chain);
854 Ops.push_back(Op1);
855 Ops.push_back(Op2);
856 if (InGlue.getNode())
857 Ops.push_back(InGlue);
858 return getNode(ISD::CALLSEQ_END, DL, NodeTys, Ops);
859 }
860
861 /// Return true if the result of this operation is always undefined.
862 bool isUndef(unsigned Opcode, ArrayRef<SDValue> Ops);
863
864 /// Return an UNDEF node. UNDEF does not have a useful SDLoc.
865 SDValue getUNDEF(EVT VT) {
866 return getNode(ISD::UNDEF, SDLoc(), VT);
867 }
868
869 /// Return a GLOBAL_OFFSET_TABLE node. This does not have a useful SDLoc.
870 SDValue getGLOBAL_OFFSET_TABLE(EVT VT) {
871 return getNode(ISD::GLOBAL_OFFSET_TABLE, SDLoc(), VT);
872 }
873
874 /// Gets or creates the specified node.
875 ///
876 SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
877 ArrayRef<SDUse> Ops);
878 SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
879 ArrayRef<SDValue> Ops, const SDNodeFlags Flags = SDNodeFlags());
880 SDValue getNode(unsigned Opcode, const SDLoc &DL, ArrayRef<EVT> ResultTys,
881 ArrayRef<SDValue> Ops);
882 SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList,
883 ArrayRef<SDValue> Ops);
884
885 // Specialize based on number of operands.
886 SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT);
887 SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue Operand,
888 const SDNodeFlags Flags = SDNodeFlags());
889 SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1,
890 SDValue N2, const SDNodeFlags Flags = SDNodeFlags());
891 SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1,
892 SDValue N2, SDValue N3,
893 const SDNodeFlags Flags = SDNodeFlags());
894 SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1,
895 SDValue N2, SDValue N3, SDValue N4);
896 SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1,
897 SDValue N2, SDValue N3, SDValue N4, SDValue N5);
898
899 // Specialize again based on number of operands for nodes with a VTList
900 // rather than a single VT.
901 SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList);
902 SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList, SDValue N);
903 SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList, SDValue N1,
904 SDValue N2);
905 SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList, SDValue N1,
906 SDValue N2, SDValue N3);
907 SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList, SDValue N1,
908 SDValue N2, SDValue N3, SDValue N4);
909 SDValue getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList, SDValue N1,
910 SDValue N2, SDValue N3, SDValue N4, SDValue N5);
911
912 /// Compute a TokenFactor to force all the incoming stack arguments to be
913 /// loaded from the stack. This is used in tail call lowering to protect
914 /// stack arguments from being clobbered.
915 SDValue getStackArgumentTokenFactor(SDValue Chain);
916
917 SDValue getMemcpy(SDValue Chain, const SDLoc &dl, SDValue Dst, SDValue Src,
918 SDValue Size, unsigned Align, bool isVol, bool AlwaysInline,
919 bool isTailCall, MachinePointerInfo DstPtrInfo,
920 MachinePointerInfo SrcPtrInfo);
921
922 SDValue getMemmove(SDValue Chain, const SDLoc &dl, SDValue Dst, SDValue Src,
923 SDValue Size, unsigned Align, bool isVol, bool isTailCall,
924 MachinePointerInfo DstPtrInfo,
925 MachinePointerInfo SrcPtrInfo);
926
927 SDValue getMemset(SDValue Chain, const SDLoc &dl, SDValue Dst, SDValue Src,
928 SDValue Size, unsigned Align, bool isVol, bool isTailCall,
929 MachinePointerInfo DstPtrInfo);
930
931 SDValue getAtomicMemcpy(SDValue Chain, const SDLoc &dl, SDValue Dst,
932 unsigned DstAlign, SDValue Src, unsigned SrcAlign,
933 SDValue Size, Type *SizeTy, unsigned ElemSz,
934 bool isTailCall, MachinePointerInfo DstPtrInfo,
935 MachinePointerInfo SrcPtrInfo);
936
937 SDValue getAtomicMemmove(SDValue Chain, const SDLoc &dl, SDValue Dst,
938 unsigned DstAlign, SDValue Src, unsigned SrcAlign,
939 SDValue Size, Type *SizeTy, unsigned ElemSz,
940 bool isTailCall, MachinePointerInfo DstPtrInfo,
941 MachinePointerInfo SrcPtrInfo);
942
943 SDValue getAtomicMemset(SDValue Chain, const SDLoc &dl, SDValue Dst,
944 unsigned DstAlign, SDValue Value, SDValue Size,
945 Type *SizeTy, unsigned ElemSz, bool isTailCall,
946 MachinePointerInfo DstPtrInfo);
947
948 /// Helper function to make it easier to build SetCC's if you just
949 /// have an ISD::CondCode instead of an SDValue.
950 ///
951 SDValue getSetCC(const SDLoc &DL, EVT VT, SDValue LHS, SDValue RHS,
952 ISD::CondCode Cond) {
953 assert(LHS.getValueType().isVector() == RHS.getValueType().isVector() &&(static_cast <bool> (LHS.getValueType().isVector() == RHS
.getValueType().isVector() && "Cannot compare scalars to vectors"
) ? void (0) : __assert_fail ("LHS.getValueType().isVector() == RHS.getValueType().isVector() && \"Cannot compare scalars to vectors\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAG.h"
, 954, __extension__ __PRETTY_FUNCTION__))
954 "Cannot compare scalars to vectors")(static_cast <bool> (LHS.getValueType().isVector() == RHS
.getValueType().isVector() && "Cannot compare scalars to vectors"
) ? void (0) : __assert_fail ("LHS.getValueType().isVector() == RHS.getValueType().isVector() && \"Cannot compare scalars to vectors\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAG.h"
, 954, __extension__ __PRETTY_FUNCTION__))
;
955 assert(LHS.getValueType().isVector() == VT.isVector() &&(static_cast <bool> (LHS.getValueType().isVector() == VT
.isVector() && "Cannot compare scalars to vectors") ?
void (0) : __assert_fail ("LHS.getValueType().isVector() == VT.isVector() && \"Cannot compare scalars to vectors\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAG.h"
, 956, __extension__ __PRETTY_FUNCTION__))
956 "Cannot compare scalars to vectors")(static_cast <bool> (LHS.getValueType().isVector() == VT
.isVector() && "Cannot compare scalars to vectors") ?
void (0) : __assert_fail ("LHS.getValueType().isVector() == VT.isVector() && \"Cannot compare scalars to vectors\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAG.h"
, 956, __extension__ __PRETTY_FUNCTION__))
;
957 assert(Cond != ISD::SETCC_INVALID &&(static_cast <bool> (Cond != ISD::SETCC_INVALID &&
"Cannot create a setCC of an invalid node.") ? void (0) : __assert_fail
("Cond != ISD::SETCC_INVALID && \"Cannot create a setCC of an invalid node.\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAG.h"
, 958, __extension__ __PRETTY_FUNCTION__))
958 "Cannot create a setCC of an invalid node.")(static_cast <bool> (Cond != ISD::SETCC_INVALID &&
"Cannot create a setCC of an invalid node.") ? void (0) : __assert_fail
("Cond != ISD::SETCC_INVALID && \"Cannot create a setCC of an invalid node.\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAG.h"
, 958, __extension__ __PRETTY_FUNCTION__))
;
959 return getNode(ISD::SETCC, DL, VT, LHS, RHS, getCondCode(Cond));
960 }
961
962 /// Helper function to make it easier to build Select's if you just
963 /// have operands and don't want to check for vector.
964 SDValue getSelect(const SDLoc &DL, EVT VT, SDValue Cond, SDValue LHS,
965 SDValue RHS) {
966 assert(LHS.getValueType() == RHS.getValueType() &&(static_cast <bool> (LHS.getValueType() == RHS.getValueType
() && "Cannot use select on differing types") ? void (
0) : __assert_fail ("LHS.getValueType() == RHS.getValueType() && \"Cannot use select on differing types\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAG.h"
, 967, __extension__ __PRETTY_FUNCTION__))
967 "Cannot use select on differing types")(static_cast <bool> (LHS.getValueType() == RHS.getValueType
() && "Cannot use select on differing types") ? void (
0) : __assert_fail ("LHS.getValueType() == RHS.getValueType() && \"Cannot use select on differing types\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAG.h"
, 967, __extension__ __PRETTY_FUNCTION__))
;
968 assert(VT.isVector() == LHS.getValueType().isVector() &&(static_cast <bool> (VT.isVector() == LHS.getValueType(
).isVector() && "Cannot mix vectors and scalars") ? void
(0) : __assert_fail ("VT.isVector() == LHS.getValueType().isVector() && \"Cannot mix vectors and scalars\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAG.h"
, 969, __extension__ __PRETTY_FUNCTION__))
969 "Cannot mix vectors and scalars")(static_cast <bool> (VT.isVector() == LHS.getValueType(
).isVector() && "Cannot mix vectors and scalars") ? void
(0) : __assert_fail ("VT.isVector() == LHS.getValueType().isVector() && \"Cannot mix vectors and scalars\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAG.h"
, 969, __extension__ __PRETTY_FUNCTION__))
;
970 return getNode(Cond.getValueType().isVector() ? ISD::VSELECT : ISD::SELECT, DL, VT,
971 Cond, LHS, RHS);
972 }
973
974 /// Helper function to make it easier to build SelectCC's if you
975 /// just have an ISD::CondCode instead of an SDValue.
976 ///
977 SDValue getSelectCC(const SDLoc &DL, SDValue LHS, SDValue RHS, SDValue True,
978 SDValue False, ISD::CondCode Cond) {
979 return getNode(ISD::SELECT_CC, DL, True.getValueType(),
980 LHS, RHS, True, False, getCondCode(Cond));
981 }
982
983 /// VAArg produces a result and token chain, and takes a pointer
984 /// and a source value as input.
985 SDValue getVAArg(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr,
986 SDValue SV, unsigned Align);
987
988 /// Gets a node for an atomic cmpxchg op. There are two
989 /// valid Opcodes. ISD::ATOMIC_CMO_SWAP produces the value loaded and a
990 /// chain result. ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS produces the value loaded,
991 /// a success flag (initially i1), and a chain.
992 SDValue getAtomicCmpSwap(unsigned Opcode, const SDLoc &dl, EVT MemVT,
993 SDVTList VTs, SDValue Chain, SDValue Ptr,
994 SDValue Cmp, SDValue Swp, MachinePointerInfo PtrInfo,
995 unsigned Alignment, AtomicOrdering SuccessOrdering,
996 AtomicOrdering FailureOrdering,
997 SyncScope::ID SSID);
998 SDValue getAtomicCmpSwap(unsigned Opcode, const SDLoc &dl, EVT MemVT,
999 SDVTList VTs, SDValue Chain, SDValue Ptr,
1000 SDValue Cmp, SDValue Swp, MachineMemOperand *MMO);
1001
1002 /// Gets a node for an atomic op, produces result (if relevant)
1003 /// and chain and takes 2 operands.
1004 SDValue getAtomic(unsigned Opcode, const SDLoc &dl, EVT MemVT, SDValue Chain,
1005 SDValue Ptr, SDValue Val, const Value *PtrVal,
1006 unsigned Alignment, AtomicOrdering Ordering,
1007 SyncScope::ID SSID);
1008 SDValue getAtomic(unsigned Opcode, const SDLoc &dl, EVT MemVT, SDValue Chain,
1009 SDValue Ptr, SDValue Val, MachineMemOperand *MMO);
1010
1011 /// Gets a node for an atomic op, produces result and chain and
1012 /// takes 1 operand.
1013 SDValue getAtomic(unsigned Opcode, const SDLoc &dl, EVT MemVT, EVT VT,
1014 SDValue Chain, SDValue Ptr, MachineMemOperand *MMO);
1015
1016 /// Gets a node for an atomic op, produces result and chain and takes N
1017 /// operands.
1018 SDValue getAtomic(unsigned Opcode, const SDLoc &dl, EVT MemVT,
1019 SDVTList VTList, ArrayRef<SDValue> Ops,
1020 MachineMemOperand *MMO);
1021
1022 /// Creates a MemIntrinsicNode that may produce a
1023 /// result and takes a list of operands. Opcode may be INTRINSIC_VOID,
1024 /// INTRINSIC_W_CHAIN, or a target-specific opcode with a value not
1025 /// less than FIRST_TARGET_MEMORY_OPCODE.
1026 SDValue getMemIntrinsicNode(
1027 unsigned Opcode, const SDLoc &dl, SDVTList VTList,
1028 ArrayRef<SDValue> Ops, EVT MemVT,
1029 MachinePointerInfo PtrInfo,
1030 unsigned Align = 0,
1031 MachineMemOperand::Flags Flags
1032 = MachineMemOperand::MOLoad | MachineMemOperand::MOStore,
1033 unsigned Size = 0);
1034
1035 SDValue getMemIntrinsicNode(unsigned Opcode, const SDLoc &dl, SDVTList VTList,
1036 ArrayRef<SDValue> Ops, EVT MemVT,
1037 MachineMemOperand *MMO);
1038
1039 /// Create a MERGE_VALUES node from the given operands.
1040 SDValue getMergeValues(ArrayRef<SDValue> Ops, const SDLoc &dl);
1041
1042 /// Loads are not normal binary operators: their result type is not
1043 /// determined by their operands, and they produce a value AND a token chain.
1044 ///
1045 /// This function will set the MOLoad flag on MMOFlags, but you can set it if
1046 /// you want. The MOStore flag must not be set.
1047 SDValue getLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr,
1048 MachinePointerInfo PtrInfo, unsigned Alignment = 0,
1049 MachineMemOperand::Flags MMOFlags = MachineMemOperand::MONone,
1050 const AAMDNodes &AAInfo = AAMDNodes(),
1051 const MDNode *Ranges = nullptr);
1052 SDValue getLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr,
1053 MachineMemOperand *MMO);
1054 SDValue
1055 getExtLoad(ISD::LoadExtType ExtType, const SDLoc &dl, EVT VT, SDValue Chain,
1056 SDValue Ptr, MachinePointerInfo PtrInfo, EVT MemVT,
1057 unsigned Alignment = 0,
1058 MachineMemOperand::Flags MMOFlags = MachineMemOperand::MONone,
1059 const AAMDNodes &AAInfo = AAMDNodes());
1060 SDValue getExtLoad(ISD::LoadExtType ExtType, const SDLoc &dl, EVT VT,
1061 SDValue Chain, SDValue Ptr, EVT MemVT,
1062 MachineMemOperand *MMO);
1063 SDValue getIndexedLoad(SDValue OrigLoad, const SDLoc &dl, SDValue Base,
1064 SDValue Offset, ISD::MemIndexedMode AM);
1065 SDValue getLoad(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType, EVT VT,
1066 const SDLoc &dl, SDValue Chain, SDValue Ptr, SDValue Offset,
1067 MachinePointerInfo PtrInfo, EVT MemVT, unsigned Alignment = 0,
1068 MachineMemOperand::Flags MMOFlags = MachineMemOperand::MONone,
1069 const AAMDNodes &AAInfo = AAMDNodes(),
1070 const MDNode *Ranges = nullptr);
1071 SDValue getLoad(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType, EVT VT,
1072 const SDLoc &dl, SDValue Chain, SDValue Ptr, SDValue Offset,
1073 EVT MemVT, MachineMemOperand *MMO);
1074
1075 /// Helper function to build ISD::STORE nodes.
1076 ///
1077 /// This function will set the MOStore flag on MMOFlags, but you can set it if
1078 /// you want. The MOLoad and MOInvariant flags must not be set.
1079 SDValue
1080 getStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr,
1081 MachinePointerInfo PtrInfo, unsigned Alignment = 0,
1082 MachineMemOperand::Flags MMOFlags = MachineMemOperand::MONone,
1083 const AAMDNodes &AAInfo = AAMDNodes());
1084 SDValue getStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr,
1085 MachineMemOperand *MMO);
1086 SDValue
1087 getTruncStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr,
1088 MachinePointerInfo PtrInfo, EVT SVT, unsigned Alignment = 0,
1089 MachineMemOperand::Flags MMOFlags = MachineMemOperand::MONone,
1090 const AAMDNodes &AAInfo = AAMDNodes());
1091 SDValue getTruncStore(SDValue Chain, const SDLoc &dl, SDValue Val,
1092 SDValue Ptr, EVT SVT, MachineMemOperand *MMO);
1093 SDValue getIndexedStore(SDValue OrigStore, const SDLoc &dl, SDValue Base,
1094 SDValue Offset, ISD::MemIndexedMode AM);
1095
1096 /// Returns sum of the base pointer and offset.
1097 SDValue getMemBasePlusOffset(SDValue Base, unsigned Offset, const SDLoc &DL);
1098
1099 SDValue getMaskedLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr,
1100 SDValue Mask, SDValue Src0, EVT MemVT,
1101 MachineMemOperand *MMO, ISD::LoadExtType,
1102 bool IsExpanding = false);
1103 SDValue getMaskedStore(SDValue Chain, const SDLoc &dl, SDValue Val,
1104 SDValue Ptr, SDValue Mask, EVT MemVT,
1105 MachineMemOperand *MMO, bool IsTruncating = false,
1106 bool IsCompressing = false);
1107 SDValue getMaskedGather(SDVTList VTs, EVT VT, const SDLoc &dl,
1108 ArrayRef<SDValue> Ops, MachineMemOperand *MMO);
1109 SDValue getMaskedScatter(SDVTList VTs, EVT VT, const SDLoc &dl,
1110 ArrayRef<SDValue> Ops, MachineMemOperand *MMO);
1111
1112 /// Return (create a new or find existing) a target-specific node.
1113 /// TargetMemSDNode should be derived class from MemSDNode.
1114 template <class TargetMemSDNode>
1115 SDValue getTargetMemSDNode(SDVTList VTs, ArrayRef<SDValue> Ops,
1116 const SDLoc &dl, EVT MemVT,
1117 MachineMemOperand *MMO);
1118
1119 /// Construct a node to track a Value* through the backend.
1120 SDValue getSrcValue(const Value *v);
1121
1122 /// Return an MDNodeSDNode which holds an MDNode.
1123 SDValue getMDNode(const MDNode *MD);
1124
1125 /// Return a bitcast using the SDLoc of the value operand, and casting to the
1126 /// provided type. Use getNode to set a custom SDLoc.
1127 SDValue getBitcast(EVT VT, SDValue V);
1128
1129 /// Return an AddrSpaceCastSDNode.
1130 SDValue getAddrSpaceCast(const SDLoc &dl, EVT VT, SDValue Ptr, unsigned SrcAS,
1131 unsigned DestAS);
1132
1133 /// Return the specified value casted to
1134 /// the target's desired shift amount type.
1135 SDValue getShiftAmountOperand(EVT LHSTy, SDValue Op);
1136
1137 /// Expand the specified \c ISD::VAARG node as the Legalize pass would.
1138 SDValue expandVAArg(SDNode *Node);
1139
1140 /// Expand the specified \c ISD::VACOPY node as the Legalize pass would.
1141 SDValue expandVACopy(SDNode *Node);
1142
1143 /// *Mutate* the specified node in-place to have the
1144 /// specified operands. If the resultant node already exists in the DAG,
1145 /// this does not modify the specified node, instead it returns the node that
1146 /// already exists. If the resultant node does not exist in the DAG, the
1147 /// input node is returned. As a degenerate case, if you specify the same
1148 /// input operands as the node already has, the input node is returned.
1149 SDNode *UpdateNodeOperands(SDNode *N, SDValue Op);
1150 SDNode *UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2);
1151 SDNode *UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2,
1152 SDValue Op3);
1153 SDNode *UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2,
1154 SDValue Op3, SDValue Op4);
1155 SDNode *UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2,
1156 SDValue Op3, SDValue Op4, SDValue Op5);
1157 SDNode *UpdateNodeOperands(SDNode *N, ArrayRef<SDValue> Ops);
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-7~svn338205/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) {
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 void computeKnownBits(SDValue Op, KnownBits &Known, 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 void computeKnownBits(SDValue Op, KnownBits &Known, 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.
1488 bool isKnownNeverNaN(SDValue Op) const;
1489
1490 /// Test whether the given floating point SDValue is known to never be
1491 /// positive or negative zero.
1492 bool isKnownNeverZeroFloat(SDValue Op) const;
1493
1494 /// Test whether the given SDValue is known to contain non-zero value(s).
1495 bool isKnownNeverZero(SDValue Op) const;
1496
1497 /// Test whether two SDValues are known to compare equal. This
1498 /// is true if they are the same value, or if one is negative zero and the
1499 /// other positive zero.
1500 bool isEqualTo(SDValue A, SDValue B) const;
1501
1502 /// Return true if A and B have no common bits set. As an example, this can
1503 /// allow an 'add' to be transformed into an 'or'.
1504 bool haveNoCommonBitsSet(SDValue A, SDValue B) const;
1505
1506 /// Utility function used by legalize and lowering to
1507 /// "unroll" a vector operation by splitting out the scalars and operating
1508 /// on each element individually. If the ResNE is 0, fully unroll the vector
1509 /// op. If ResNE is less than the width of the vector op, unroll up to ResNE.
1510 /// If the ResNE is greater than the width of the vector op, unroll the
1511 /// vector op and fill the end of the resulting vector with UNDEFS.
1512 SDValue UnrollVectorOp(SDNode *N, unsigned ResNE = 0);
1513
1514 /// Return true if loads are next to each other and can be
1515 /// merged. Check that both are nonvolatile and if LD is loading
1516 /// 'Bytes' bytes from a location that is 'Dist' units away from the
1517 /// location that the 'Base' load is loading from.
1518 bool areNonVolatileConsecutiveLoads(LoadSDNode *LD, LoadSDNode *Base,
1519 unsigned Bytes, int Dist) const;
1520
1521 /// Infer alignment of a load / store address. Return 0 if
1522 /// it cannot be inferred.
1523 unsigned InferPtrAlignment(SDValue Ptr) const;
1524
1525 /// Compute the VTs needed for the low/hi parts of a type
1526 /// which is split (or expanded) into two not necessarily identical pieces.
1527 std::pair<EVT, EVT> GetSplitDestVTs(const EVT &VT) const;
1528
1529 /// Split the vector with EXTRACT_SUBVECTOR using the provides
1530 /// VTs and return the low/high part.
1531 std::pair<SDValue, SDValue> SplitVector(const SDValue &N, const SDLoc &DL,
1532 const EVT &LoVT, const EVT &HiVT);
1533
1534 /// Split the vector with EXTRACT_SUBVECTOR and return the low/high part.
1535 std::pair<SDValue, SDValue> SplitVector(const SDValue &N, const SDLoc &DL) {
1536 EVT LoVT, HiVT;
1537 std::tie(LoVT, HiVT) = GetSplitDestVTs(N.getValueType());
1538 return SplitVector(N, DL, LoVT, HiVT);
1539 }
1540
1541 /// Split the node's operand with EXTRACT_SUBVECTOR and
1542 /// return the low/high part.
1543 std::pair<SDValue, SDValue> SplitVectorOperand(const SDNode *N, unsigned OpNo)
1544 {
1545 return SplitVector(N->getOperand(OpNo), SDLoc(N));
1546 }
1547
1548 /// Append the extracted elements from Start to Count out of the vector Op
1549 /// in Args. If Count is 0, all of the elements will be extracted.
1550 void ExtractVectorElements(SDValue Op, SmallVectorImpl<SDValue> &Args,
1551 unsigned Start = 0, unsigned Count = 0);
1552
1553 /// Compute the default alignment value for the given type.
1554 unsigned getEVTAlignment(EVT MemoryVT) const;
1555
1556 /// Test whether the given value is a constant int or similar node.
1557 SDNode *isConstantIntBuildVectorOrConstantInt(SDValue N);
1558
1559 /// Test whether the given value is a constant FP or similar node.
1560 SDNode *isConstantFPBuildVectorOrConstantFP(SDValue N);
1561
1562 /// \returns true if \p N is any kind of constant or build_vector of
1563 /// constants, int or float. If a vector, it may not necessarily be a splat.
1564 inline bool isConstantValueOfAnyType(SDValue N) {
1565 return isConstantIntBuildVectorOrConstantInt(N) ||
1566 isConstantFPBuildVectorOrConstantFP(N);
1567 }
1568
1569private:
1570 void InsertNode(SDNode *N);
1571 bool RemoveNodeFromCSEMaps(SDNode *N);
1572 void AddModifiedNodeToCSEMaps(SDNode *N);
1573 SDNode *FindModifiedNodeSlot(SDNode *N, SDValue Op, void *&InsertPos);
1574 SDNode *FindModifiedNodeSlot(SDNode *N, SDValue Op1, SDValue Op2,
1575 void *&InsertPos);
1576 SDNode *FindModifiedNodeSlot(SDNode *N, ArrayRef<SDValue> Ops,
1577 void *&InsertPos);
1578 SDNode *UpdateSDLocOnMergeSDNode(SDNode *N, const SDLoc &loc);
1579
1580 void DeleteNodeNotInCSEMaps(SDNode *N);
1581 void DeallocateNode(SDNode *N);
1582
1583 void allnodes_clear();
1584
1585 /// Look up the node specified by ID in CSEMap. If it exists, return it. If
1586 /// not, return the insertion token that will make insertion faster. This
1587 /// overload is for nodes other than Constant or ConstantFP, use the other one
1588 /// for those.
1589 SDNode *FindNodeOrInsertPos(const FoldingSetNodeID &ID, void *&InsertPos);
1590
1591 /// Look up the node specified by ID in CSEMap. If it exists, return it. If
1592 /// not, return the insertion token that will make insertion faster. Performs
1593 /// additional processing for constant nodes.
1594 SDNode *FindNodeOrInsertPos(const FoldingSetNodeID &ID, const SDLoc &DL,
1595 void *&InsertPos);
1596
1597 /// List of non-single value types.
1598 FoldingSet<SDVTListNode> VTListMap;
1599
1600 /// Maps to auto-CSE operations.
1601 std::vector<CondCodeSDNode*> CondCodeNodes;
1602
1603 std::vector<SDNode*> ValueTypeNodes;
1604 std::map<EVT, SDNode*, EVT::compareRawBits> ExtendedValueTypeNodes;
1605 StringMap<SDNode*> ExternalSymbols;
1606
1607 std::map<std::pair<std::string, unsigned char>,SDNode*> TargetExternalSymbols;
1608 DenseMap<MCSymbol *, SDNode *> MCSymbols;
1609};
1610
1611template <> struct GraphTraits<SelectionDAG*> : public GraphTraits<SDNode*> {
1612 using nodes_iterator = pointer_iterator<SelectionDAG::allnodes_iterator>;
1613
1614 static nodes_iterator nodes_begin(SelectionDAG *G) {
1615 return nodes_iterator(G->allnodes_begin());
1616 }
1617
1618 static nodes_iterator nodes_end(SelectionDAG *G) {
1619 return nodes_iterator(G->allnodes_end());
1620 }
1621};
1622
1623template <class TargetMemSDNode>
1624SDValue SelectionDAG::getTargetMemSDNode(SDVTList VTs,
1625 ArrayRef<SDValue> Ops,
1626 const SDLoc &dl, EVT MemVT,
1627 MachineMemOperand *MMO) {
1628 /// Compose node ID and try to find an existing node.
1629 FoldingSetNodeID ID;
1630 unsigned Opcode =
1631 TargetMemSDNode(dl.getIROrder(), DebugLoc(), VTs, MemVT, MMO).getOpcode();
1632 ID.AddInteger(Opcode);
1633 ID.AddPointer(VTs.VTs);
1634 for (auto& Op : Ops) {
1635 ID.AddPointer(Op.getNode());
1636 ID.AddInteger(Op.getResNo());
1637 }
1638 ID.AddInteger(MemVT.getRawBits());
1639 ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
1640 ID.AddInteger(getSyntheticNodeSubclassData<TargetMemSDNode>(
1641 dl.getIROrder(), VTs, MemVT, MMO));
1642
1643 void *IP = nullptr;
1644 if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP)) {
1645 cast<TargetMemSDNode>(E)->refineAlignment(MMO);
1646 return SDValue(E, 0);
1647 }
1648
1649 /// Existing node was not found. Create a new one.
1650 auto *N = newSDNode<TargetMemSDNode>(dl.getIROrder(), dl.getDebugLoc(), VTs,
1651 MemVT, MMO);
1652 createOperands(N, Ops);
1653 CSEMap.InsertNode(N, IP);
1654 InsertNode(N);
1655 return SDValue(N, 0);
1656}
1657
1658} // end namespace llvm
1659
1660#endif // LLVM_CODEGEN_SELECTIONDAG_H

/build/llvm-toolchain-snapshot-7~svn338205/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 return true;
676 }
677 }
678
679 /// Test if this node has a post-isel opcode, directly
680 /// corresponding to a MachineInstr opcode.
681 bool isMachineOpcode() const { return NodeType < 0; }
682
683 /// This may only be called if isMachineOpcode returns
684 /// true. It returns the MachineInstr opcode value that the node's opcode
685 /// corresponds to.
686 unsigned getMachineOpcode() const {
687 assert(isMachineOpcode() && "Not a MachineInstr opcode!")(static_cast <bool> (isMachineOpcode() && "Not a MachineInstr opcode!"
) ? void (0) : __assert_fail ("isMachineOpcode() && \"Not a MachineInstr opcode!\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAGNodes.h"
, 687, __extension__ __PRETTY_FUNCTION__))
;
688 return ~NodeType;
689 }
690
691 bool getHasDebugValue() const { return SDNodeBits.HasDebugValue; }
692 void setHasDebugValue(bool b) { SDNodeBits.HasDebugValue = b; }
693
694 bool isDivergent() const { return SDNodeBits.IsDivergent; }
695
696 /// Return true if there are no uses of this node.
697 bool use_empty() const { return UseList == nullptr; }
698
699 /// Return true if there is exactly one use of this node.
700 bool hasOneUse() const {
701 return !use_empty() && std::next(use_begin()) == use_end();
702 }
703
704 /// Return the number of uses of this node. This method takes
705 /// time proportional to the number of uses.
706 size_t use_size() const { return std::distance(use_begin(), use_end()); }
707
708 /// Return the unique node id.
709 int getNodeId() const { return NodeId; }
710
711 /// Set unique node id.
712 void setNodeId(int Id) { NodeId = Id; }
713
714 /// Return the node ordering.
715 unsigned getIROrder() const { return IROrder; }
716
717 /// Set the node ordering.
718 void setIROrder(unsigned Order) { IROrder = Order; }
719
720 /// Return the source location info.
721 const DebugLoc &getDebugLoc() const { return debugLoc; }
722
723 /// Set source location info. Try to avoid this, putting
724 /// it in the constructor is preferable.
725 void setDebugLoc(DebugLoc dl) { debugLoc = std::move(dl); }
726
727 /// This class provides iterator support for SDUse
728 /// operands that use a specific SDNode.
729 class use_iterator
730 : public std::iterator<std::forward_iterator_tag, SDUse, ptrdiff_t> {
731 friend class SDNode;
732
733 SDUse *Op = nullptr;
734
735 explicit use_iterator(SDUse *op) : Op(op) {}
736
737 public:
738 using reference = std::iterator<std::forward_iterator_tag,
739 SDUse, ptrdiff_t>::reference;
740 using pointer = std::iterator<std::forward_iterator_tag,
741 SDUse, ptrdiff_t>::pointer;
742
743 use_iterator() = default;
744 use_iterator(const use_iterator &I) : Op(I.Op) {}
745
746 bool operator==(const use_iterator &x) const {
747 return Op == x.Op;
748 }
749 bool operator!=(const use_iterator &x) const {
750 return !operator==(x);
751 }
752
753 /// Return true if this iterator is at the end of uses list.
754 bool atEnd() const { return Op == nullptr; }
755
756 // Iterator traversal: forward iteration only.
757 use_iterator &operator++() { // Preincrement
758 assert(Op && "Cannot increment end iterator!")(static_cast <bool> (Op && "Cannot increment end iterator!"
) ? void (0) : __assert_fail ("Op && \"Cannot increment end iterator!\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAGNodes.h"
, 758, __extension__ __PRETTY_FUNCTION__))
;
759 Op = Op->getNext();
760 return *this;
761 }
762
763 use_iterator operator++(int) { // Postincrement
764 use_iterator tmp = *this; ++*this; return tmp;
765 }
766
767 /// Retrieve a pointer to the current user node.
768 SDNode *operator*() const {
769 assert(Op && "Cannot dereference end iterator!")(static_cast <bool> (Op && "Cannot dereference end iterator!"
) ? void (0) : __assert_fail ("Op && \"Cannot dereference end iterator!\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAGNodes.h"
, 769, __extension__ __PRETTY_FUNCTION__))
;
770 return Op->getUser();
771 }
772
773 SDNode *operator->() const { return operator*(); }
774
775 SDUse &getUse() const { return *Op; }
776
777 /// Retrieve the operand # of this use in its user.
778 unsigned getOperandNo() const {
779 assert(Op && "Cannot dereference end iterator!")(static_cast <bool> (Op && "Cannot dereference end iterator!"
) ? void (0) : __assert_fail ("Op && \"Cannot dereference end iterator!\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAGNodes.h"
, 779, __extension__ __PRETTY_FUNCTION__))
;
780 return (unsigned)(Op - Op->getUser()->OperandList);
781 }
782 };
783
784 /// Provide iteration support to walk over all uses of an SDNode.
785 use_iterator use_begin() const {
786 return use_iterator(UseList);
787 }
788
789 static use_iterator use_end() { return use_iterator(nullptr); }
790
791 inline iterator_range<use_iterator> uses() {
792 return make_range(use_begin(), use_end());
793 }
794 inline iterator_range<use_iterator> uses() const {
795 return make_range(use_begin(), use_end());
796 }
797
798 /// Return true if there are exactly NUSES uses of the indicated value.
799 /// This method ignores uses of other values defined by this operation.
800 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
801
802 /// Return true if there are any use of the indicated value.
803 /// This method ignores uses of other values defined by this operation.
804 bool hasAnyUseOfValue(unsigned Value) const;
805
806 /// Return true if this node is the only use of N.
807 bool isOnlyUserOf(const SDNode *N) const;
808
809 /// Return true if this node is an operand of N.
810 bool isOperandOf(const SDNode *N) const;
811
812 /// Return true if this node is a predecessor of N.
813 /// NOTE: Implemented on top of hasPredecessor and every bit as
814 /// expensive. Use carefully.
815 bool isPredecessorOf(const SDNode *N) const {
816 return N->hasPredecessor(this);
817 }
818
819 /// Return true if N is a predecessor of this node.
820 /// N is either an operand of this node, or can be reached by recursively
821 /// traversing up the operands.
822 /// NOTE: This is an expensive method. Use it carefully.
823 bool hasPredecessor(const SDNode *N) const;
824
825 /// Returns true if N is a predecessor of any node in Worklist. This
826 /// helper keeps Visited and Worklist sets externally to allow unions
827 /// searches to be performed in parallel, caching of results across
828 /// queries and incremental addition to Worklist. Stops early if N is
829 /// found but will resume. Remember to clear Visited and Worklists
830 /// if DAG changes. MaxSteps gives a maximum number of nodes to visit before
831 /// giving up. The TopologicalPrune flag signals that positive NodeIds are
832 /// topologically ordered (Operands have strictly smaller node id) and search
833 /// can be pruned leveraging this.
834 static bool hasPredecessorHelper(const SDNode *N,
835 SmallPtrSetImpl<const SDNode *> &Visited,
836 SmallVectorImpl<const SDNode *> &Worklist,
837 unsigned int MaxSteps = 0,
838 bool TopologicalPrune = false) {
839 SmallVector<const SDNode *, 8> DeferredNodes;
840 if (Visited.count(N))
841 return true;
842
843 // Node Id's are assigned in three places: As a topological
844 // ordering (> 0), during legalization (results in values set to
845 // 0), new nodes (set to -1). If N has a topolgical id then we
846 // know that all nodes with ids smaller than it cannot be
847 // successors and we need not check them. Filter out all node
848 // that can't be matches. We add them to the worklist before exit
849 // in case of multiple calls. Note that during selection the topological id
850 // may be violated if a node's predecessor is selected before it. We mark
851 // this at selection negating the id of unselected successors and
852 // restricting topological pruning to positive ids.
853
854 int NId = N->getNodeId();
855 // If we Invalidated the Id, reconstruct original NId.
856 if (NId < -1)
857 NId = -(NId + 1);
858
859 bool Found = false;
860 while (!Worklist.empty()) {
861 const SDNode *M = Worklist.pop_back_val();
862 int MId = M->getNodeId();
863 if (TopologicalPrune && M->getOpcode() != ISD::TokenFactor && (NId > 0) &&
864 (MId > 0) && (MId < NId)) {
865 DeferredNodes.push_back(M);
866 continue;
867 }
868 for (const SDValue &OpV : M->op_values()) {
869 SDNode *Op = OpV.getNode();
870 if (Visited.insert(Op).second)
871 Worklist.push_back(Op);
872 if (Op == N)
873 Found = true;
874 }
875 if (Found)
876 break;
877 if (MaxSteps != 0 && Visited.size() >= MaxSteps)
878 break;
879 }
880 // Push deferred nodes back on worklist.
881 Worklist.append(DeferredNodes.begin(), DeferredNodes.end());
882 // If we bailed early, conservatively return found.
883 if (MaxSteps != 0 && Visited.size() >= MaxSteps)
884 return true;
885 return Found;
886 }
887
888 /// Return true if all the users of N are contained in Nodes.
889 /// NOTE: Requires at least one match, but doesn't require them all.
890 static bool areOnlyUsersOf(ArrayRef<const SDNode *> Nodes, const SDNode *N);
891
892 /// Return the number of values used by this operation.
893 unsigned getNumOperands() const { return NumOperands; }
894
895 /// Helper method returns the integer value of a ConstantSDNode operand.
896 inline uint64_t getConstantOperandVal(unsigned Num) const;
897
898 const SDValue &getOperand(unsigned Num) const {
899 assert(Num < NumOperands && "Invalid child # of SDNode!")(static_cast <bool> (Num < NumOperands && "Invalid child # of SDNode!"
) ? void (0) : __assert_fail ("Num < NumOperands && \"Invalid child # of SDNode!\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAGNodes.h"
, 899, __extension__ __PRETTY_FUNCTION__))
;
900 return OperandList[Num];
901 }
902
903 using op_iterator = SDUse *;
904
905 op_iterator op_begin() const { return OperandList; }
906 op_iterator op_end() const { return OperandList+NumOperands; }
907 ArrayRef<SDUse> ops() const { return makeArrayRef(op_begin(), op_end()); }
908
909 /// Iterator for directly iterating over the operand SDValue's.
910 struct value_op_iterator
911 : iterator_adaptor_base<value_op_iterator, op_iterator,
912 std::random_access_iterator_tag, SDValue,
913 ptrdiff_t, value_op_iterator *,
914 value_op_iterator *> {
915 explicit value_op_iterator(SDUse *U = nullptr)
916 : iterator_adaptor_base(U) {}
917
918 const SDValue &operator*() const { return I->get(); }
919 };
920
921 iterator_range<value_op_iterator> op_values() const {
922 return make_range(value_op_iterator(op_begin()),
923 value_op_iterator(op_end()));
924 }
925
926 SDVTList getVTList() const {
927 SDVTList X = { ValueList, NumValues };
928 return X;
929 }
930
931 /// If this node has a glue operand, return the node
932 /// to which the glue operand points. Otherwise return NULL.
933 SDNode *getGluedNode() const {
934 if (getNumOperands() != 0 &&
935 getOperand(getNumOperands()-1).getValueType() == MVT::Glue)
936 return getOperand(getNumOperands()-1).getNode();
937 return nullptr;
938 }
939
940 /// If this node has a glue value with a user, return
941 /// the user (there is at most one). Otherwise return NULL.
942 SDNode *getGluedUser() const {
943 for (use_iterator UI = use_begin(), UE = use_end(); UI != UE; ++UI)
944 if (UI.getUse().get().getValueType() == MVT::Glue)
945 return *UI;
946 return nullptr;
947 }
948
949 const SDNodeFlags getFlags() const { return Flags; }
950 void setFlags(SDNodeFlags NewFlags) { Flags = NewFlags; }
951 bool isFast() { return Flags.isFast(); }
952
953 /// Clear any flags in this node that aren't also set in Flags.
954 /// If Flags is not in a defined state then this has no effect.
955 void intersectFlagsWith(const SDNodeFlags Flags);
956
957 /// Return the number of values defined/returned by this operator.
958 unsigned getNumValues() const { return NumValues; }
959
960 /// Return the type of a specified result.
961 EVT getValueType(unsigned ResNo) const {
962 assert(ResNo < NumValues && "Illegal result number!")(static_cast <bool> (ResNo < NumValues && "Illegal result number!"
) ? void (0) : __assert_fail ("ResNo < NumValues && \"Illegal result number!\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAGNodes.h"
, 962, __extension__ __PRETTY_FUNCTION__))
;
963 return ValueList[ResNo];
964 }
965
966 /// Return the type of a specified result as a simple type.
967 MVT getSimpleValueType(unsigned ResNo) const {
968 return getValueType(ResNo).getSimpleVT();
969 }
970
971 /// Returns MVT::getSizeInBits(getValueType(ResNo)).
972 unsigned getValueSizeInBits(unsigned ResNo) const {
973 return getValueType(ResNo).getSizeInBits();
974 }
975
976 using value_iterator = const EVT *;
977
978 value_iterator value_begin() const { return ValueList; }
979 value_iterator value_end() const { return ValueList+NumValues; }
980
981 /// Return the opcode of this operation for printing.
982 std::string getOperationName(const SelectionDAG *G = nullptr) const;
983 static const char* getIndexedModeName(ISD::MemIndexedMode AM);
984 void print_types(raw_ostream &OS, const SelectionDAG *G) const;
985 void print_details(raw_ostream &OS, const SelectionDAG *G) const;
986 void print(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
987 void printr(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
988
989 /// Print a SelectionDAG node and all children down to
990 /// the leaves. The given SelectionDAG allows target-specific nodes
991 /// to be printed in human-readable form. Unlike printr, this will
992 /// print the whole DAG, including children that appear multiple
993 /// times.
994 ///
995 void printrFull(raw_ostream &O, const SelectionDAG *G = nullptr) const;
996
997 /// Print a SelectionDAG node and children up to
998 /// depth "depth." The given SelectionDAG allows target-specific
999 /// nodes to be printed in human-readable form. Unlike printr, this
1000 /// will print children that appear multiple times wherever they are
1001 /// used.
1002 ///
1003 void printrWithDepth(raw_ostream &O, const SelectionDAG *G = nullptr,
1004 unsigned depth = 100) const;
1005
1006 /// Dump this node, for debugging.
1007 void dump() const;
1008
1009 /// Dump (recursively) this node and its use-def subgraph.
1010 void dumpr() const;
1011
1012 /// Dump this node, for debugging.
1013 /// The given SelectionDAG allows target-specific nodes to be printed
1014 /// in human-readable form.
1015 void dump(const SelectionDAG *G) const;
1016
1017 /// Dump (recursively) this node and its use-def subgraph.
1018 /// The given SelectionDAG allows target-specific nodes to be printed
1019 /// in human-readable form.
1020 void dumpr(const SelectionDAG *G) const;
1021
1022 /// printrFull to dbgs(). The given SelectionDAG allows
1023 /// target-specific nodes to be printed in human-readable form.
1024 /// Unlike dumpr, this will print the whole DAG, including children
1025 /// that appear multiple times.
1026 void dumprFull(const SelectionDAG *G = nullptr) const;
1027
1028 /// printrWithDepth to dbgs(). The given
1029 /// SelectionDAG allows target-specific nodes to be printed in
1030 /// human-readable form. Unlike dumpr, this will print children
1031 /// that appear multiple times wherever they are used.
1032 ///
1033 void dumprWithDepth(const SelectionDAG *G = nullptr,
1034 unsigned depth = 100) const;
1035
1036 /// Gather unique data for the node.
1037 void Profile(FoldingSetNodeID &ID) const;
1038
1039 /// This method should only be used by the SDUse class.
1040 void addUse(SDUse &U) { U.addToList(&UseList); }
1041
1042protected:
1043 static SDVTList getSDVTList(EVT VT) {
1044 SDVTList Ret = { getValueTypeList(VT), 1 };
1045 return Ret;
1046 }
1047
1048 /// Create an SDNode.
1049 ///
1050 /// SDNodes are created without any operands, and never own the operand
1051 /// storage. To add operands, see SelectionDAG::createOperands.
1052 SDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs)
1053 : NodeType(Opc), ValueList(VTs.VTs), NumValues(VTs.NumVTs),
1054 IROrder(Order), debugLoc(std::move(dl)) {
1055 memset(&RawSDNodeBits, 0, sizeof(RawSDNodeBits));
1056 assert(debugLoc.hasTrivialDestructor() && "Expected trivial destructor")(static_cast <bool> (debugLoc.hasTrivialDestructor() &&
"Expected trivial destructor") ? void (0) : __assert_fail ("debugLoc.hasTrivialDestructor() && \"Expected trivial destructor\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAGNodes.h"
, 1056, __extension__ __PRETTY_FUNCTION__))
;
1057 assert(NumValues == VTs.NumVTs &&(static_cast <bool> (NumValues == VTs.NumVTs &&
"NumValues wasn't wide enough for its operands!") ? void (0)
: __assert_fail ("NumValues == VTs.NumVTs && \"NumValues wasn't wide enough for its operands!\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAGNodes.h"
, 1058, __extension__ __PRETTY_FUNCTION__))
1058 "NumValues wasn't wide enough for its operands!")(static_cast <bool> (NumValues == VTs.NumVTs &&
"NumValues wasn't wide enough for its operands!") ? void (0)
: __assert_fail ("NumValues == VTs.NumVTs && \"NumValues wasn't wide enough for its operands!\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAGNodes.h"
, 1058, __extension__ __PRETTY_FUNCTION__))
;
1059 }
1060
1061 /// Release the operands and set this node to have zero operands.
1062 void DropOperands();
1063};
1064
1065/// Wrapper class for IR location info (IR ordering and DebugLoc) to be passed
1066/// into SDNode creation functions.
1067/// When an SDNode is created from the DAGBuilder, the DebugLoc is extracted
1068/// from the original Instruction, and IROrder is the ordinal position of
1069/// the instruction.
1070/// When an SDNode is created after the DAG is being built, both DebugLoc and
1071/// the IROrder are propagated from the original SDNode.
1072/// So SDLoc class provides two constructors besides the default one, one to
1073/// be used by the DAGBuilder, the other to be used by others.
1074class SDLoc {
1075private:
1076 DebugLoc DL;
1077 int IROrder = 0;
1078
1079public:
1080 SDLoc() = default;
1081 SDLoc(const SDNode *N) : DL(N->getDebugLoc()), IROrder(N->getIROrder()) {}
1082 SDLoc(const SDValue V) : SDLoc(V.getNode()) {}
1083 SDLoc(const Instruction *I, int Order) : IROrder(Order) {
1084 assert(Order >= 0 && "bad IROrder")(static_cast <bool> (Order >= 0 && "bad IROrder"
) ? void (0) : __assert_fail ("Order >= 0 && \"bad IROrder\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAGNodes.h"
, 1084, __extension__ __PRETTY_FUNCTION__))
;
1085 if (I)
1086 DL = I->getDebugLoc();
1087 }
1088
1089 unsigned getIROrder() const { return IROrder; }
1090 const DebugLoc &getDebugLoc() const { return DL; }
1091};
1092
1093// Define inline functions from the SDValue class.
1094
1095inline SDValue::SDValue(SDNode *node, unsigned resno)
1096 : Node(node), ResNo(resno) {
1097 // Explicitly check for !ResNo to avoid use-after-free, because there are
1098 // callers that use SDValue(N, 0) with a deleted N to indicate successful
1099 // combines.
1100 assert((!Node || !ResNo || ResNo < Node->getNumValues()) &&(static_cast <bool> ((!Node || !ResNo || ResNo < Node
->getNumValues()) && "Invalid result number for the given node!"
) ? void (0) : __assert_fail ("(!Node || !ResNo || ResNo < Node->getNumValues()) && \"Invalid result number for the given node!\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAGNodes.h"
, 1101, __extension__ __PRETTY_FUNCTION__))
1101 "Invalid result number for the given node!")(static_cast <bool> ((!Node || !ResNo || ResNo < Node
->getNumValues()) && "Invalid result number for the given node!"
) ? void (0) : __assert_fail ("(!Node || !ResNo || ResNo < Node->getNumValues()) && \"Invalid result number for the given node!\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAGNodes.h"
, 1101, __extension__ __PRETTY_FUNCTION__))
;
1102 assert(ResNo < -2U && "Cannot use result numbers reserved for DenseMaps.")(static_cast <bool> (ResNo < -2U && "Cannot use result numbers reserved for DenseMaps."
) ? void (0) : __assert_fail ("ResNo < -2U && \"Cannot use result numbers reserved for DenseMaps.\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAGNodes.h"
, 1102, __extension__ __PRETTY_FUNCTION__))
;
1103}
1104
1105inline unsigned SDValue::getOpcode() const {
1106 return Node->getOpcode();
1107}
1108
1109inline EVT SDValue::getValueType() const {
1110 return Node->getValueType(ResNo);
17
Called C++ object pointer is null
1111}
1112
1113inline unsigned SDValue::getNumOperands() const {
1114 return Node->getNumOperands();
1115}
1116
1117inline const SDValue &SDValue::getOperand(unsigned i) const {
1118 return Node->getOperand(i);
1119}
1120
1121inline uint64_t SDValue::getConstantOperandVal(unsigned i) const {
1122 return Node->getConstantOperandVal(i);
1123}
1124
1125inline bool SDValue::isTargetOpcode() const {
1126 return Node->isTargetOpcode();
1127}
1128
1129inline bool SDValue::isTargetMemoryOpcode() const {
1130 return Node->isTargetMemoryOpcode();
1131}
1132
1133inline bool SDValue::isMachineOpcode() const {
1134 return Node->isMachineOpcode();
1135}
1136
1137inline unsigned SDValue::getMachineOpcode() const {
1138 return Node->getMachineOpcode();
1139}
1140
1141inline bool SDValue::isUndef() const {
1142 return Node->isUndef();
1143}
1144
1145inline bool SDValue::use_empty() const {
1146 return !Node->hasAnyUseOfValue(ResNo);
1147}
1148
1149inline bool SDValue::hasOneUse() const {
1150 return Node->hasNUsesOfValue(1, ResNo);
1151}
1152
1153inline const DebugLoc &SDValue::getDebugLoc() const {
1154 return Node->getDebugLoc();
1155}
1156
1157inline void SDValue::dump() const {
1158 return Node->dump();
1159}
1160
1161inline void SDValue::dump(const SelectionDAG *G) const {
1162 return Node->dump(G);
1163}
1164
1165inline void SDValue::dumpr() const {
1166 return Node->dumpr();
1167}
1168
1169inline void SDValue::dumpr(const SelectionDAG *G) const {
1170 return Node->dumpr(G);
1171}
1172
1173// Define inline functions from the SDUse class.
1174
1175inline void SDUse::set(const SDValue &V) {
1176 if (Val.getNode()) removeFromList();
1177 Val = V;
1178 if (V.getNode()) V.getNode()->addUse(*this);
1179}
1180
1181inline void SDUse::setInitial(const SDValue &V) {
1182 Val = V;
1183 V.getNode()->addUse(*this);
1184}
1185
1186inline void SDUse::setNode(SDNode *N) {
1187 if (Val.getNode()) removeFromList();
1188 Val.setNode(N);
1189 if (N) N->addUse(*this);
1190}
1191
1192/// This class is used to form a handle around another node that
1193/// is persistent and is updated across invocations of replaceAllUsesWith on its
1194/// operand. This node should be directly created by end-users and not added to
1195/// the AllNodes list.
1196class HandleSDNode : public SDNode {
1197 SDUse Op;
1198
1199public:
1200 explicit HandleSDNode(SDValue X)
1201 : SDNode(ISD::HANDLENODE, 0, DebugLoc(), getSDVTList(MVT::Other)) {
1202 // HandleSDNodes are never inserted into the DAG, so they won't be
1203 // auto-numbered. Use ID 65535 as a sentinel.
1204 PersistentId = 0xffff;
1205
1206 // Manually set up the operand list. This node type is special in that it's
1207 // always stack allocated and SelectionDAG does not manage its operands.
1208 // TODO: This should either (a) not be in the SDNode hierarchy, or (b) not
1209 // be so special.
1210 Op.setUser(this);
1211 Op.setInitial(X);
1212 NumOperands = 1;
1213 OperandList = &Op;
1214 }
1215 ~HandleSDNode();
1216
1217 const SDValue &getValue() const { return Op; }
1218};
1219
1220class AddrSpaceCastSDNode : public SDNode {
1221private:
1222 unsigned SrcAddrSpace;
1223 unsigned DestAddrSpace;
1224
1225public:
1226 AddrSpaceCastSDNode(unsigned Order, const DebugLoc &dl, EVT VT,
1227 unsigned SrcAS, unsigned DestAS);
1228
1229 unsigned getSrcAddressSpace() const { return SrcAddrSpace; }
1230 unsigned getDestAddressSpace() const { return DestAddrSpace; }
1231
1232 static bool classof(const SDNode *N) {
1233 return N->getOpcode() == ISD::ADDRSPACECAST;
1234 }
1235};
1236
1237/// This is an abstract virtual class for memory operations.
1238class MemSDNode : public SDNode {
1239private:
1240 // VT of in-memory value.
1241 EVT MemoryVT;
1242
1243protected:
1244 /// Memory reference information.
1245 MachineMemOperand *MMO;
1246
1247public:
1248 MemSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl, SDVTList VTs,
1249 EVT memvt, MachineMemOperand *MMO);
1250
1251 bool readMem() const { return MMO->isLoad(); }
1252 bool writeMem() const { return MMO->isStore(); }
1253
1254 /// Returns alignment and volatility of the memory access
1255 unsigned getOriginalAlignment() const {
1256 return MMO->getBaseAlignment();
1257 }
1258 unsigned getAlignment() const {
1259 return MMO->getAlignment();
1260 }
1261
1262 /// Return the SubclassData value, without HasDebugValue. This contains an
1263 /// encoding of the volatile flag, as well as bits used by subclasses. This
1264 /// function should only be used to compute a FoldingSetNodeID value.
1265 /// The HasDebugValue bit is masked out because CSE map needs to match
1266 /// nodes with debug info with nodes without debug info. Same is about
1267 /// isDivergent bit.
1268 unsigned getRawSubclassData() const {
1269 uint16_t Data;
1270 union {
1271 char RawSDNodeBits[sizeof(uint16_t)];
1272 SDNodeBitfields SDNodeBits;
1273 };
1274 memcpy(&RawSDNodeBits, &this->RawSDNodeBits, sizeof(this->RawSDNodeBits));
1275 SDNodeBits.HasDebugValue = 0;
1276 SDNodeBits.IsDivergent = false;
1277 memcpy(&Data, &RawSDNodeBits, sizeof(RawSDNodeBits));
1278 return Data;
1279 }
1280
1281 bool isVolatile() const { return MemSDNodeBits.IsVolatile; }
1282 bool isNonTemporal() const { return MemSDNodeBits.IsNonTemporal; }
1283 bool isDereferenceable() const { return MemSDNodeBits.IsDereferenceable; }
1284 bool isInvariant() const { return MemSDNodeBits.IsInvariant; }
1285
1286 // Returns the offset from the location of the access.
1287 int64_t getSrcValueOffset() const { return MMO->getOffset(); }
1288
1289 /// Returns the AA info that describes the dereference.
1290 AAMDNodes getAAInfo() const { return MMO->getAAInfo(); }
1291
1292 /// Returns the Ranges that describes the dereference.
1293 const MDNode *getRanges() const { return MMO->getRanges(); }
1294
1295 /// Returns the synchronization scope ID for this memory operation.
1296 SyncScope::ID getSyncScopeID() const { return MMO->getSyncScopeID(); }
1297
1298 /// Return the atomic ordering requirements for this memory operation. For
1299 /// cmpxchg atomic operations, return the atomic ordering requirements when
1300 /// store occurs.
1301 AtomicOrdering getOrdering() const { return MMO->getOrdering(); }
1302
1303 /// Return the type of the in-memory value.
1304 EVT getMemoryVT() const { return MemoryVT; }
1305
1306 /// Return a MachineMemOperand object describing the memory
1307 /// reference performed by operation.
1308 MachineMemOperand *getMemOperand() const { return MMO; }
1309
1310 const MachinePointerInfo &getPointerInfo() const {
1311 return MMO->getPointerInfo();
1312 }
1313
1314 /// Return the address space for the associated pointer
1315 unsigned getAddressSpace() const {
1316 return getPointerInfo().getAddrSpace();
1317 }
1318
1319 /// Update this MemSDNode's MachineMemOperand information
1320 /// to reflect the alignment of NewMMO, if it has a greater alignment.
1321 /// This must only be used when the new alignment applies to all users of
1322 /// this MachineMemOperand.
1323 void refineAlignment(const MachineMemOperand *NewMMO) {
1324 MMO->refineAlignment(NewMMO);
1325 }
1326
1327 const SDValue &getChain() const { return getOperand(0); }
1328 const SDValue &getBasePtr() const {
1329 return getOperand(getOpcode() == ISD::STORE ? 2 : 1);
1330 }
1331
1332 // Methods to support isa and dyn_cast
1333 static bool classof(const SDNode *N) {
1334 // For some targets, we lower some target intrinsics to a MemIntrinsicNode
1335 // with either an intrinsic or a target opcode.
1336 return N->getOpcode() == ISD::LOAD ||
1337 N->getOpcode() == ISD::STORE ||
1338 N->getOpcode() == ISD::PREFETCH ||
1339 N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1340 N->getOpcode() == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS ||
1341 N->getOpcode() == ISD::ATOMIC_SWAP ||
1342 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1343 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1344 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1345 N->getOpcode() == ISD::ATOMIC_LOAD_CLR ||
1346 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1347 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1348 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1349 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1350 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1351 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1352 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
1353 N->getOpcode() == ISD::ATOMIC_LOAD ||
1354 N->getOpcode() == ISD::ATOMIC_STORE ||
1355 N->getOpcode() == ISD::MLOAD ||
1356 N->getOpcode() == ISD::MSTORE ||
1357 N->getOpcode() == ISD::MGATHER ||
1358 N->getOpcode() == ISD::MSCATTER ||
1359 N->isMemIntrinsic() ||
1360 N->isTargetMemoryOpcode();
1361 }
1362};
1363
1364/// This is an SDNode representing atomic operations.
1365class AtomicSDNode : public MemSDNode {
1366public:
1367 AtomicSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl, SDVTList VTL,
1368 EVT MemVT, MachineMemOperand *MMO)
1369 : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {}
1370
1371 const SDValue &getBasePtr() const { return getOperand(1); }
1372 const SDValue &getVal() const { return getOperand(2); }
1373
1374 /// Returns true if this SDNode represents cmpxchg atomic operation, false
1375 /// otherwise.
1376 bool isCompareAndSwap() const {
1377 unsigned Op = getOpcode();
1378 return Op == ISD::ATOMIC_CMP_SWAP ||
1379 Op == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS;
1380 }
1381
1382 /// For cmpxchg atomic operations, return the atomic ordering requirements
1383 /// when store does not occur.
1384 AtomicOrdering getFailureOrdering() const {
1385 assert(isCompareAndSwap() && "Must be cmpxchg operation")(static_cast <bool> (isCompareAndSwap() && "Must be cmpxchg operation"
) ? void (0) : __assert_fail ("isCompareAndSwap() && \"Must be cmpxchg operation\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAGNodes.h"
, 1385, __extension__ __PRETTY_FUNCTION__))
;
1386 return MMO->getFailureOrdering();
1387 }
1388
1389 // Methods to support isa and dyn_cast
1390 static bool classof(const SDNode *N) {
1391 return N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1392 N->getOpcode() == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS ||
1393 N->getOpcode() == ISD::ATOMIC_SWAP ||
1394 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1395 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1396 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1397 N->getOpcode() == ISD::ATOMIC_LOAD_CLR ||
1398 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1399 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1400 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1401 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1402 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1403 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1404 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
1405 N->getOpcode() == ISD::ATOMIC_LOAD ||
1406 N->getOpcode() == ISD::ATOMIC_STORE;
1407 }
1408};
1409
1410/// This SDNode is used for target intrinsics that touch
1411/// memory and need an associated MachineMemOperand. Its opcode may be
1412/// INTRINSIC_VOID, INTRINSIC_W_CHAIN, PREFETCH, or a target-specific opcode
1413/// with a value not less than FIRST_TARGET_MEMORY_OPCODE.
1414class MemIntrinsicSDNode : public MemSDNode {
1415public:
1416 MemIntrinsicSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl,
1417 SDVTList VTs, EVT MemoryVT, MachineMemOperand *MMO)
1418 : MemSDNode(Opc, Order, dl, VTs, MemoryVT, MMO) {
1419 SDNodeBits.IsMemIntrinsic = true;
1420 }
1421
1422 // Methods to support isa and dyn_cast
1423 static bool classof(const SDNode *N) {
1424 // We lower some target intrinsics to their target opcode
1425 // early a node with a target opcode can be of this class
1426 return N->isMemIntrinsic() ||
1427 N->getOpcode() == ISD::PREFETCH ||
1428 N->isTargetMemoryOpcode();
1429 }
1430};
1431
1432/// This SDNode is used to implement the code generator
1433/// support for the llvm IR shufflevector instruction. It combines elements
1434/// from two input vectors into a new input vector, with the selection and
1435/// ordering of elements determined by an array of integers, referred to as
1436/// the shuffle mask. For input vectors of width N, mask indices of 0..N-1
1437/// refer to elements from the LHS input, and indices from N to 2N-1 the RHS.
1438/// An index of -1 is treated as undef, such that the code generator may put
1439/// any value in the corresponding element of the result.
1440class ShuffleVectorSDNode : public SDNode {
1441 // The memory for Mask is owned by the SelectionDAG's OperandAllocator, and
1442 // is freed when the SelectionDAG object is destroyed.
1443 const int *Mask;
1444
1445protected:
1446 friend class SelectionDAG;
1447
1448 ShuffleVectorSDNode(EVT VT, unsigned Order, const DebugLoc &dl, const int *M)
1449 : SDNode(ISD::VECTOR_SHUFFLE, Order, dl, getSDVTList(VT)), Mask(M) {}
1450
1451public:
1452 ArrayRef<int> getMask() const {
1453 EVT VT = getValueType(0);
1454 return makeArrayRef(Mask, VT.getVectorNumElements());
1455 }
1456
1457 int getMaskElt(unsigned Idx) const {
1458 assert(Idx < getValueType(0).getVectorNumElements() && "Idx out of range!")(static_cast <bool> (Idx < getValueType(0).getVectorNumElements
() && "Idx out of range!") ? void (0) : __assert_fail
("Idx < getValueType(0).getVectorNumElements() && \"Idx out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAGNodes.h"
, 1458, __extension__ __PRETTY_FUNCTION__))
;
1459 return Mask[Idx];
1460 }
1461
1462 bool isSplat() const { return isSplatMask(Mask, getValueType(0)); }
1463
1464 int getSplatIndex() const {
1465 assert(isSplat() && "Cannot get splat index for non-splat!")(static_cast <bool> (isSplat() && "Cannot get splat index for non-splat!"
) ? void (0) : __assert_fail ("isSplat() && \"Cannot get splat index for non-splat!\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAGNodes.h"
, 1465, __extension__ __PRETTY_FUNCTION__))
;
1466 EVT VT = getValueType(0);
1467 for (unsigned i = 0, e = VT.getVectorNumElements(); i != e; ++i) {
1468 if (Mask[i] >= 0)
1469 return Mask[i];
1470 }
1471 llvm_unreachable("Splat with all undef indices?")::llvm::llvm_unreachable_internal("Splat with all undef indices?"
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAGNodes.h"
, 1471)
;
1472 }
1473
1474 static bool isSplatMask(const int *Mask, EVT VT);
1475
1476 /// Change values in a shuffle permute mask assuming
1477 /// the two vector operands have swapped position.
1478 static void commuteMask(MutableArrayRef<int> Mask) {
1479 unsigned NumElems = Mask.size();
1480 for (unsigned i = 0; i != NumElems; ++i) {
1481 int idx = Mask[i];
1482 if (idx < 0)
1483 continue;
1484 else if (idx < (int)NumElems)
1485 Mask[i] = idx + NumElems;
1486 else
1487 Mask[i] = idx - NumElems;
1488 }
1489 }
1490
1491 static bool classof(const SDNode *N) {
1492 return N->getOpcode() == ISD::VECTOR_SHUFFLE;
1493 }
1494};
1495
1496class ConstantSDNode : public SDNode {
1497 friend class SelectionDAG;
1498
1499 const ConstantInt *Value;
1500
1501 ConstantSDNode(bool isTarget, bool isOpaque, const ConstantInt *val, EVT VT)
1502 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, 0, DebugLoc(),
1503 getSDVTList(VT)),
1504 Value(val) {
1505 ConstantSDNodeBits.IsOpaque = isOpaque;
1506 }
1507
1508public:
1509 const ConstantInt *getConstantIntValue() const { return Value; }
1510 const APInt &getAPIntValue() const { return Value->getValue(); }
1511 uint64_t getZExtValue() const { return Value->getZExtValue(); }
1512 int64_t getSExtValue() const { return Value->getSExtValue(); }
1513 uint64_t getLimitedValue(uint64_t Limit = UINT64_MAX(18446744073709551615UL)) {
1514 return Value->getLimitedValue(Limit);
1515 }
1516
1517 bool isOne() const { return Value->isOne(); }
1518 bool isNullValue() const { return Value->isZero(); }
1519 bool isAllOnesValue() const { return Value->isMinusOne(); }
1520
1521 bool isOpaque() const { return ConstantSDNodeBits.IsOpaque; }
1522
1523 static bool classof(const SDNode *N) {
1524 return N->getOpcode() == ISD::Constant ||
1525 N->getOpcode() == ISD::TargetConstant;
1526 }
1527};
1528
1529uint64_t SDNode::getConstantOperandVal(unsigned Num) const {
1530 return cast<ConstantSDNode>(getOperand(Num))->getZExtValue();
1531}
1532
1533class ConstantFPSDNode : public SDNode {
1534 friend class SelectionDAG;
1535
1536 const ConstantFP *Value;
1537
1538 ConstantFPSDNode(bool isTarget, const ConstantFP *val, EVT VT)
1539 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP, 0,
1540 DebugLoc(), getSDVTList(VT)),
1541 Value(val) {}
1542
1543public:
1544 const APFloat& getValueAPF() const { return Value->getValueAPF(); }
1545 const ConstantFP *getConstantFPValue() const { return Value; }
1546
1547 /// Return true if the value is positive or negative zero.
1548 bool isZero() const { return Value->isZero(); }
1549
1550 /// Return true if the value is a NaN.
1551 bool isNaN() const { return Value->isNaN(); }
1552
1553 /// Return true if the value is an infinity
1554 bool isInfinity() const { return Value->isInfinity(); }
1555
1556 /// Return true if the value is negative.
1557 bool isNegative() const { return Value->isNegative(); }
1558
1559 /// We don't rely on operator== working on double values, as
1560 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1561 /// As such, this method can be used to do an exact bit-for-bit comparison of
1562 /// two floating point values.
1563
1564 /// We leave the version with the double argument here because it's just so
1565 /// convenient to write "2.0" and the like. Without this function we'd
1566 /// have to duplicate its logic everywhere it's called.
1567 bool isExactlyValue(double V) const {
1568 return Value->getValueAPF().isExactlyValue(V);
1569 }
1570 bool isExactlyValue(const APFloat& V) const;
1571
1572 static bool isValueValidForType(EVT VT, const APFloat& Val);
1573
1574 static bool classof(const SDNode *N) {
1575 return N->getOpcode() == ISD::ConstantFP ||
1576 N->getOpcode() == ISD::TargetConstantFP;
1577 }
1578};
1579
1580/// Returns true if \p V is a constant integer zero.
1581bool isNullConstant(SDValue V);
1582
1583/// Returns true if \p V is an FP constant with a value of positive zero.
1584bool isNullFPConstant(SDValue V);
1585
1586/// Returns true if \p V is an integer constant with all bits set.
1587bool isAllOnesConstant(SDValue V);
1588
1589/// Returns true if \p V is a constant integer one.
1590bool isOneConstant(SDValue V);
1591
1592/// Returns true if \p V is a bitwise not operation. Assumes that an all ones
1593/// constant is canonicalized to be operand 1.
1594bool isBitwiseNot(SDValue V);
1595
1596/// Returns the SDNode if it is a constant splat BuildVector or constant int.
1597ConstantSDNode *isConstOrConstSplat(SDValue N);
1598
1599/// Returns the SDNode if it is a constant splat BuildVector or constant float.
1600ConstantFPSDNode *isConstOrConstSplatFP(SDValue N);
1601
1602class GlobalAddressSDNode : public SDNode {
1603 friend class SelectionDAG;
1604
1605 const GlobalValue *TheGlobal;
1606 int64_t Offset;
1607 unsigned char TargetFlags;
1608
1609 GlobalAddressSDNode(unsigned Opc, unsigned Order, const DebugLoc &DL,
1610 const GlobalValue *GA, EVT VT, int64_t o,
1611 unsigned char TF);
1612
1613public:
1614 const GlobalValue *getGlobal() const { return TheGlobal; }
1615 int64_t getOffset() const { return Offset; }
1616 unsigned char getTargetFlags() const { return TargetFlags; }
1617 // Return the address space this GlobalAddress belongs to.
1618 unsigned getAddressSpace() const;
1619
1620 static bool classof(const SDNode *N) {
1621 return N->getOpcode() == ISD::GlobalAddress ||
1622 N->getOpcode() == ISD::TargetGlobalAddress ||
1623 N->getOpcode() == ISD::GlobalTLSAddress ||
1624 N->getOpcode() == ISD::TargetGlobalTLSAddress;
1625 }
1626};
1627
1628class FrameIndexSDNode : public SDNode {
1629 friend class SelectionDAG;
1630
1631 int FI;
1632
1633 FrameIndexSDNode(int fi, EVT VT, bool isTarg)
1634 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex,
1635 0, DebugLoc(), getSDVTList(VT)), FI(fi) {
1636 }
1637
1638public:
1639 int getIndex() const { return FI; }
1640
1641 static bool classof(const SDNode *N) {
1642 return N->getOpcode() == ISD::FrameIndex ||
1643 N->getOpcode() == ISD::TargetFrameIndex;
1644 }
1645};
1646
1647class JumpTableSDNode : public SDNode {
1648 friend class SelectionDAG;
1649
1650 int JTI;
1651 unsigned char TargetFlags;
1652
1653 JumpTableSDNode(int jti, EVT VT, bool isTarg, unsigned char TF)
1654 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable,
1655 0, DebugLoc(), getSDVTList(VT)), JTI(jti), TargetFlags(TF) {
1656 }
1657
1658public:
1659 int getIndex() const { return JTI; }
1660 unsigned char getTargetFlags() const { return TargetFlags; }
1661
1662 static bool classof(const SDNode *N) {
1663 return N->getOpcode() == ISD::JumpTable ||
1664 N->getOpcode() == ISD::TargetJumpTable;
1665 }
1666};
1667
1668class ConstantPoolSDNode : public SDNode {
1669 friend class SelectionDAG;
1670
1671 union {
1672 const Constant *ConstVal;
1673 MachineConstantPoolValue *MachineCPVal;
1674 } Val;
1675 int Offset; // It's a MachineConstantPoolValue if top bit is set.
1676 unsigned Alignment; // Minimum alignment requirement of CP (not log2 value).
1677 unsigned char TargetFlags;
1678
1679 ConstantPoolSDNode(bool isTarget, const Constant *c, EVT VT, int o,
1680 unsigned Align, unsigned char TF)
1681 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
1682 DebugLoc(), getSDVTList(VT)), Offset(o), Alignment(Align),
1683 TargetFlags(TF) {
1684 assert(Offset >= 0 && "Offset is too large")(static_cast <bool> (Offset >= 0 && "Offset is too large"
) ? void (0) : __assert_fail ("Offset >= 0 && \"Offset is too large\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAGNodes.h"
, 1684, __extension__ __PRETTY_FUNCTION__))
;
1685 Val.ConstVal = c;
1686 }
1687
1688 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1689 EVT VT, int o, unsigned Align, unsigned char TF)
1690 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
1691 DebugLoc(), getSDVTList(VT)), Offset(o), Alignment(Align),
1692 TargetFlags(TF) {
1693 assert(Offset >= 0 && "Offset is too large")(static_cast <bool> (Offset >= 0 && "Offset is too large"
) ? void (0) : __assert_fail ("Offset >= 0 && \"Offset is too large\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAGNodes.h"
, 1693, __extension__ __PRETTY_FUNCTION__))
;
1694 Val.MachineCPVal = v;
1695 Offset |= 1 << (sizeof(unsigned)*CHAR_BIT8-1);
1696 }
1697
1698public:
1699 bool isMachineConstantPoolEntry() const {
1700 return Offset < 0;
1701 }
1702
1703 const Constant *getConstVal() const {
1704 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type")(static_cast <bool> (!isMachineConstantPoolEntry() &&
"Wrong constantpool type") ? void (0) : __assert_fail ("!isMachineConstantPoolEntry() && \"Wrong constantpool type\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAGNodes.h"
, 1704, __extension__ __PRETTY_FUNCTION__))
;
1705 return Val.ConstVal;
1706 }
1707
1708 MachineConstantPoolValue *getMachineCPVal() const {
1709 assert(isMachineConstantPoolEntry() && "Wrong constantpool type")(static_cast <bool> (isMachineConstantPoolEntry() &&
"Wrong constantpool type") ? void (0) : __assert_fail ("isMachineConstantPoolEntry() && \"Wrong constantpool type\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAGNodes.h"
, 1709, __extension__ __PRETTY_FUNCTION__))
;
1710 return Val.MachineCPVal;
1711 }
1712
1713 int getOffset() const {
1714 return Offset & ~(1 << (sizeof(unsigned)*CHAR_BIT8-1));
1715 }
1716
1717 // Return the alignment of this constant pool object, which is either 0 (for
1718 // default alignment) or the desired value.
1719 unsigned getAlignment() const { return Alignment; }
1720 unsigned char getTargetFlags() const { return TargetFlags; }
1721
1722 Type *getType() const;
1723
1724 static bool classof(const SDNode *N) {
1725 return N->getOpcode() == ISD::ConstantPool ||
1726 N->getOpcode() == ISD::TargetConstantPool;
1727 }
1728};
1729
1730/// Completely target-dependent object reference.
1731class TargetIndexSDNode : public SDNode {
1732 friend class SelectionDAG;
1733
1734 unsigned char TargetFlags;
1735 int Index;
1736 int64_t Offset;
1737
1738public:
1739 TargetIndexSDNode(int Idx, EVT VT, int64_t Ofs, unsigned char TF)
1740 : SDNode(ISD::TargetIndex, 0, DebugLoc(), getSDVTList(VT)),
1741 TargetFlags(TF), Index(Idx), Offset(Ofs) {}
1742
1743 unsigned char getTargetFlags() const { return TargetFlags; }
1744 int getIndex() const { return Index; }
1745 int64_t getOffset() const { return Offset; }
1746
1747 static bool classof(const SDNode *N) {
1748 return N->getOpcode() == ISD::TargetIndex;
1749 }
1750};
1751
1752class BasicBlockSDNode : public SDNode {
1753 friend class SelectionDAG;
1754
1755 MachineBasicBlock *MBB;
1756
1757 /// Debug info is meaningful and potentially useful here, but we create
1758 /// blocks out of order when they're jumped to, which makes it a bit
1759 /// harder. Let's see if we need it first.
1760 explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1761 : SDNode(ISD::BasicBlock, 0, DebugLoc(), getSDVTList(MVT::Other)), MBB(mbb)
1762 {}
1763
1764public:
1765 MachineBasicBlock *getBasicBlock() const { return MBB; }
1766
1767 static bool classof(const SDNode *N) {
1768 return N->getOpcode() == ISD::BasicBlock;
1769 }
1770};
1771
1772/// A "pseudo-class" with methods for operating on BUILD_VECTORs.
1773class BuildVectorSDNode : public SDNode {
1774public:
1775 // These are constructed as SDNodes and then cast to BuildVectorSDNodes.
1776 explicit BuildVectorSDNode() = delete;
1777
1778 /// Check if this is a constant splat, and if so, find the
1779 /// smallest element size that splats the vector. If MinSplatBits is
1780 /// nonzero, the element size must be at least that large. Note that the
1781 /// splat element may be the entire vector (i.e., a one element vector).
1782 /// Returns the splat element value in SplatValue. Any undefined bits in
1783 /// that value are zero, and the corresponding bits in the SplatUndef mask
1784 /// are set. The SplatBitSize value is set to the splat element size in
1785 /// bits. HasAnyUndefs is set to true if any bits in the vector are
1786 /// undefined. isBigEndian describes the endianness of the target.
1787 bool isConstantSplat(APInt &SplatValue, APInt &SplatUndef,
1788 unsigned &SplatBitSize, bool &HasAnyUndefs,
1789 unsigned MinSplatBits = 0,
1790 bool isBigEndian = false) const;
1791
1792 /// Returns the splatted value or a null value if this is not a splat.
1793 ///
1794 /// If passed a non-null UndefElements bitvector, it will resize it to match
1795 /// the vector width and set the bits where elements are undef.
1796 SDValue getSplatValue(BitVector *UndefElements = nullptr) const;
1797
1798 /// Returns the splatted constant or null if this is not a constant
1799 /// splat.
1800 ///
1801 /// If passed a non-null UndefElements bitvector, it will resize it to match
1802 /// the vector width and set the bits where elements are undef.
1803 ConstantSDNode *
1804 getConstantSplatNode(BitVector *UndefElements = nullptr) const;
1805
1806 /// Returns the splatted constant FP or null if this is not a constant
1807 /// FP splat.
1808 ///
1809 /// If passed a non-null UndefElements bitvector, it will resize it to match
1810 /// the vector width and set the bits where elements are undef.
1811 ConstantFPSDNode *
1812 getConstantFPSplatNode(BitVector *UndefElements = nullptr) const;
1813
1814 /// If this is a constant FP splat and the splatted constant FP is an
1815 /// exact power or 2, return the log base 2 integer value. Otherwise,
1816 /// return -1.
1817 ///
1818 /// The BitWidth specifies the necessary bit precision.
1819 int32_t getConstantFPSplatPow2ToLog2Int(BitVector *UndefElements,
1820 uint32_t BitWidth) const;
1821
1822 bool isConstant() const;
1823
1824 static bool classof(const SDNode *N) {
1825 return N->getOpcode() == ISD::BUILD_VECTOR;
1826 }
1827};
1828
1829/// An SDNode that holds an arbitrary LLVM IR Value. This is
1830/// used when the SelectionDAG needs to make a simple reference to something
1831/// in the LLVM IR representation.
1832///
1833class SrcValueSDNode : public SDNode {
1834 friend class SelectionDAG;
1835
1836 const Value *V;
1837
1838 /// Create a SrcValue for a general value.
1839 explicit SrcValueSDNode(const Value *v)
1840 : SDNode(ISD::SRCVALUE, 0, DebugLoc(), getSDVTList(MVT::Other)), V(v) {}
1841
1842public:
1843 /// Return the contained Value.
1844 const Value *getValue() const { return V; }
1845
1846 static bool classof(const SDNode *N) {
1847 return N->getOpcode() == ISD::SRCVALUE;
1848 }
1849};
1850
1851class MDNodeSDNode : public SDNode {
1852 friend class SelectionDAG;
1853
1854 const MDNode *MD;
1855
1856 explicit MDNodeSDNode(const MDNode *md)
1857 : SDNode(ISD::MDNODE_SDNODE, 0, DebugLoc(), getSDVTList(MVT::Other)), MD(md)
1858 {}
1859
1860public:
1861 const MDNode *getMD() const { return MD; }
1862
1863 static bool classof(const SDNode *N) {
1864 return N->getOpcode() == ISD::MDNODE_SDNODE;
1865 }
1866};
1867
1868class RegisterSDNode : public SDNode {
1869 friend class SelectionDAG;
1870
1871 unsigned Reg;
1872
1873 RegisterSDNode(unsigned reg, EVT VT)
1874 : SDNode(ISD::Register, 0, DebugLoc(), getSDVTList(VT)), Reg(reg) {}
1875
1876public:
1877 unsigned getReg() const { return Reg; }
1878
1879 static bool classof(const SDNode *N) {
1880 return N->getOpcode() == ISD::Register;
1881 }
1882};
1883
1884class RegisterMaskSDNode : public SDNode {
1885 friend class SelectionDAG;
1886
1887 // The memory for RegMask is not owned by the node.
1888 const uint32_t *RegMask;
1889
1890 RegisterMaskSDNode(const uint32_t *mask)
1891 : SDNode(ISD::RegisterMask, 0, DebugLoc(), getSDVTList(MVT::Untyped)),
1892 RegMask(mask) {}
1893
1894public:
1895 const uint32_t *getRegMask() const { return RegMask; }
1896
1897 static bool classof(const SDNode *N) {
1898 return N->getOpcode() == ISD::RegisterMask;
1899 }
1900};
1901
1902class BlockAddressSDNode : public SDNode {
1903 friend class SelectionDAG;
1904
1905 const BlockAddress *BA;
1906 int64_t Offset;
1907 unsigned char TargetFlags;
1908
1909 BlockAddressSDNode(unsigned NodeTy, EVT VT, const BlockAddress *ba,
1910 int64_t o, unsigned char Flags)
1911 : SDNode(NodeTy, 0, DebugLoc(), getSDVTList(VT)),
1912 BA(ba), Offset(o), TargetFlags(Flags) {}
1913
1914public:
1915 const BlockAddress *getBlockAddress() const { return BA; }
1916 int64_t getOffset() const { return Offset; }
1917 unsigned char getTargetFlags() const { return TargetFlags; }
1918
1919 static bool classof(const SDNode *N) {
1920 return N->getOpcode() == ISD::BlockAddress ||
1921 N->getOpcode() == ISD::TargetBlockAddress;
1922 }
1923};
1924
1925class LabelSDNode : public SDNode {
1926 friend class SelectionDAG;
1927
1928 MCSymbol *Label;
1929
1930 LabelSDNode(unsigned Order, const DebugLoc &dl, MCSymbol *L)
1931 : SDNode(ISD::EH_LABEL, Order, dl, getSDVTList(MVT::Other)), Label(L) {}
1932
1933public:
1934 MCSymbol *getLabel() const { return Label; }
1935
1936 static bool classof(const SDNode *N) {
1937 return N->getOpcode() == ISD::EH_LABEL ||
1938 N->getOpcode() == ISD::ANNOTATION_LABEL;
1939 }
1940};
1941
1942class ExternalSymbolSDNode : public SDNode {
1943 friend class SelectionDAG;
1944
1945 const char *Symbol;
1946 unsigned char TargetFlags;
1947
1948 ExternalSymbolSDNode(bool isTarget, const char *Sym, unsigned char TF, EVT VT)
1949 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1950 0, DebugLoc(), getSDVTList(VT)), Symbol(Sym), TargetFlags(TF) {}
1951
1952public:
1953 const char *getSymbol() const { return Symbol; }
1954 unsigned char getTargetFlags() const { return TargetFlags; }
1955
1956 static bool classof(const SDNode *N) {
1957 return N->getOpcode() == ISD::ExternalSymbol ||
1958 N->getOpcode() == ISD::TargetExternalSymbol;
1959 }
1960};
1961
1962class MCSymbolSDNode : public SDNode {
1963 friend class SelectionDAG;
1964
1965 MCSymbol *Symbol;
1966
1967 MCSymbolSDNode(MCSymbol *Symbol, EVT VT)
1968 : SDNode(ISD::MCSymbol, 0, DebugLoc(), getSDVTList(VT)), Symbol(Symbol) {}
1969
1970public:
1971 MCSymbol *getMCSymbol() const { return Symbol; }
1972
1973 static bool classof(const SDNode *N) {
1974 return N->getOpcode() == ISD::MCSymbol;
1975 }
1976};
1977
1978class CondCodeSDNode : public SDNode {
1979 friend class SelectionDAG;
1980
1981 ISD::CondCode Condition;
1982
1983 explicit CondCodeSDNode(ISD::CondCode Cond)
1984 : SDNode(ISD::CONDCODE, 0, DebugLoc(), getSDVTList(MVT::Other)),
1985 Condition(Cond) {}
1986
1987public:
1988 ISD::CondCode get() const { return Condition; }
1989
1990 static bool classof(const SDNode *N) {
1991 return N->getOpcode() == ISD::CONDCODE;
1992 }
1993};
1994
1995/// This class is used to represent EVT's, which are used
1996/// to parameterize some operations.
1997class VTSDNode : public SDNode {
1998 friend class SelectionDAG;
1999
2000 EVT ValueType;
2001
2002 explicit VTSDNode(EVT VT)
2003 : SDNode(ISD::VALUETYPE, 0, DebugLoc(), getSDVTList(MVT::Other)),
2004 ValueType(VT) {}
2005
2006public:
2007 EVT getVT() const { return ValueType; }
2008
2009 static bool classof(const SDNode *N) {
2010 return N->getOpcode() == ISD::VALUETYPE;
2011 }
2012};
2013
2014/// Base class for LoadSDNode and StoreSDNode
2015class LSBaseSDNode : public MemSDNode {
2016public:
2017 LSBaseSDNode(ISD::NodeType NodeTy, unsigned Order, const DebugLoc &dl,
2018 SDVTList VTs, ISD::MemIndexedMode AM, EVT MemVT,
2019 MachineMemOperand *MMO)
2020 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {
2021 LSBaseSDNodeBits.AddressingMode = AM;
2022 assert(getAddressingMode() == AM && "Value truncated")(static_cast <bool> (getAddressingMode() == AM &&
"Value truncated") ? void (0) : __assert_fail ("getAddressingMode() == AM && \"Value truncated\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAGNodes.h"
, 2022, __extension__ __PRETTY_FUNCTION__))
;
2023 }
2024
2025 const SDValue &getOffset() const {
2026 return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
2027 }
2028
2029 /// Return the addressing mode for this load or store:
2030 /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
2031 ISD::MemIndexedMode getAddressingMode() const {
2032 return static_cast<ISD::MemIndexedMode>(LSBaseSDNodeBits.AddressingMode);
2033 }
2034
2035 /// Return true if this is a pre/post inc/dec load/store.
2036 bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
2037
2038 /// Return true if this is NOT a pre/post inc/dec load/store.
2039 bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
2040
2041 static bool classof(const SDNode *N) {
2042 return N->getOpcode() == ISD::LOAD ||
2043 N->getOpcode() == ISD::STORE;
2044 }
2045};
2046
2047/// This class is used to represent ISD::LOAD nodes.
2048class LoadSDNode : public LSBaseSDNode {
2049 friend class SelectionDAG;
2050
2051 LoadSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2052 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, EVT MemVT,
2053 MachineMemOperand *MMO)
2054 : LSBaseSDNode(ISD::LOAD, Order, dl, VTs, AM, MemVT, MMO) {
2055 LoadSDNodeBits.ExtTy = ETy;
2056 assert(readMem() && "Load MachineMemOperand is not a load!")(static_cast <bool> (readMem() && "Load MachineMemOperand is not a load!"
) ? void (0) : __assert_fail ("readMem() && \"Load MachineMemOperand is not a load!\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAGNodes.h"
, 2056, __extension__ __PRETTY_FUNCTION__))
;
2057 assert(!writeMem() && "Load MachineMemOperand is a store!")(static_cast <bool> (!writeMem() && "Load MachineMemOperand is a store!"
) ? void (0) : __assert_fail ("!writeMem() && \"Load MachineMemOperand is a store!\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAGNodes.h"
, 2057, __extension__ __PRETTY_FUNCTION__))
;
2058 }
2059
2060public:
2061 /// Return whether this is a plain node,
2062 /// or one of the varieties of value-extending loads.
2063 ISD::LoadExtType getExtensionType() const {
2064 return static_cast<ISD::LoadExtType>(LoadSDNodeBits.ExtTy);
2065 }
2066
2067 const SDValue &getBasePtr() const { return getOperand(1); }
2068 const SDValue &getOffset() const { return getOperand(2); }
2069
2070 static bool classof(const SDNode *N) {
2071 return N->getOpcode() == ISD::LOAD;
2072 }
2073};
2074
2075/// This class is used to represent ISD::STORE nodes.
2076class StoreSDNode : public LSBaseSDNode {
2077 friend class SelectionDAG;
2078
2079 StoreSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2080 ISD::MemIndexedMode AM, bool isTrunc, EVT MemVT,
2081 MachineMemOperand *MMO)
2082 : LSBaseSDNode(ISD::STORE, Order, dl, VTs, AM, MemVT, MMO) {
2083 StoreSDNodeBits.IsTruncating = isTrunc;
2084 assert(!readMem() && "Store MachineMemOperand is a load!")(static_cast <bool> (!readMem() && "Store MachineMemOperand is a load!"
) ? void (0) : __assert_fail ("!readMem() && \"Store MachineMemOperand is a load!\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAGNodes.h"
, 2084, __extension__ __PRETTY_FUNCTION__))
;
2085 assert(writeMem() && "Store MachineMemOperand is not a store!")(static_cast <bool> (writeMem() && "Store MachineMemOperand is not a store!"
) ? void (0) : __assert_fail ("writeMem() && \"Store MachineMemOperand is not a store!\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAGNodes.h"
, 2085, __extension__ __PRETTY_FUNCTION__))
;
2086 }
2087
2088public:
2089 /// Return true if the op does a truncation before store.
2090 /// For integers this is the same as doing a TRUNCATE and storing the result.
2091 /// For floats, it is the same as doing an FP_ROUND and storing the result.
2092 bool isTruncatingStore() const { return StoreSDNodeBits.IsTruncating; }
2093 void setTruncatingStore(bool Truncating) {
2094 StoreSDNodeBits.IsTruncating = Truncating;
2095 }
2096
2097 const SDValue &getValue() const { return getOperand(1); }
2098 const SDValue &getBasePtr() const { return getOperand(2); }
2099 const SDValue &getOffset() const { return getOperand(3); }
2100
2101 static bool classof(const SDNode *N) {
2102 return N->getOpcode() == ISD::STORE;
2103 }
2104};
2105
2106/// This base class is used to represent MLOAD and MSTORE nodes
2107class MaskedLoadStoreSDNode : public MemSDNode {
2108public:
2109 friend class SelectionDAG;
2110
2111 MaskedLoadStoreSDNode(ISD::NodeType NodeTy, unsigned Order,
2112 const DebugLoc &dl, SDVTList VTs, EVT MemVT,
2113 MachineMemOperand *MMO)
2114 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {}
2115
2116 // In the both nodes address is Op1, mask is Op2:
2117 // MaskedLoadSDNode (Chain, ptr, mask, src0), src0 is a passthru value
2118 // MaskedStoreSDNode (Chain, ptr, mask, data)
2119 // Mask is a vector of i1 elements
2120 const SDValue &getBasePtr() const { return getOperand(1); }
2121 const SDValue &getMask() const { return getOperand(2); }
2122
2123 static bool classof(const SDNode *N) {
2124 return N->getOpcode() == ISD::MLOAD ||
2125 N->getOpcode() == ISD::MSTORE;
2126 }
2127};
2128
2129/// This class is used to represent an MLOAD node
2130class MaskedLoadSDNode : public MaskedLoadStoreSDNode {
2131public:
2132 friend class SelectionDAG;
2133
2134 MaskedLoadSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2135 ISD::LoadExtType ETy, bool IsExpanding, EVT MemVT,
2136 MachineMemOperand *MMO)
2137 : MaskedLoadStoreSDNode(ISD::MLOAD, Order, dl, VTs, MemVT, MMO) {
2138 LoadSDNodeBits.ExtTy = ETy;
2139 LoadSDNodeBits.IsExpanding = IsExpanding;
2140 }
2141
2142 ISD::LoadExtType getExtensionType() const {
2143 return static_cast<ISD::LoadExtType>(LoadSDNodeBits.ExtTy);
2144 }
2145
2146 const SDValue &getSrc0() const { return getOperand(3); }
2147 static bool classof(const SDNode *N) {
2148 return N->getOpcode() == ISD::MLOAD;
2149 }
2150
2151 bool isExpandingLoad() const { return LoadSDNodeBits.IsExpanding; }
2152};
2153
2154/// This class is used to represent an MSTORE node
2155class MaskedStoreSDNode : public MaskedLoadStoreSDNode {
2156public:
2157 friend class SelectionDAG;
2158
2159 MaskedStoreSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2160 bool isTrunc, bool isCompressing, EVT MemVT,
2161 MachineMemOperand *MMO)
2162 : MaskedLoadStoreSDNode(ISD::MSTORE, Order, dl, VTs, MemVT, MMO) {
2163 StoreSDNodeBits.IsTruncating = isTrunc;
2164 StoreSDNodeBits.IsCompressing = isCompressing;
2165 }
2166
2167 /// Return true if the op does a truncation before store.
2168 /// For integers this is the same as doing a TRUNCATE and storing the result.
2169 /// For floats, it is the same as doing an FP_ROUND and storing the result.
2170 bool isTruncatingStore() const { return StoreSDNodeBits.IsTruncating; }
2171
2172 /// Returns true if the op does a compression to the vector before storing.
2173 /// The node contiguously stores the active elements (integers or floats)
2174 /// in src (those with their respective bit set in writemask k) to unaligned
2175 /// memory at base_addr.
2176 bool isCompressingStore() const { return StoreSDNodeBits.IsCompressing; }
2177
2178 const SDValue &getValue() const { return getOperand(3); }
2179
2180 static bool classof(const SDNode *N) {
2181 return N->getOpcode() == ISD::MSTORE;
2182 }
2183};
2184
2185/// This is a base class used to represent
2186/// MGATHER and MSCATTER nodes
2187///
2188class MaskedGatherScatterSDNode : public MemSDNode {
2189public:
2190 friend class SelectionDAG;
2191
2192 MaskedGatherScatterSDNode(ISD::NodeType NodeTy, unsigned Order,
2193 const DebugLoc &dl, SDVTList VTs, EVT MemVT,
2194 MachineMemOperand *MMO)
2195 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {}
2196
2197 // In the both nodes address is Op1, mask is Op2:
2198 // MaskedGatherSDNode (Chain, passthru, mask, base, index, scale)
2199 // MaskedScatterSDNode (Chain, value, mask, base, index, scale)
2200 // Mask is a vector of i1 elements
2201 const SDValue &getBasePtr() const { return getOperand(3); }
2202 const SDValue &getIndex() const { return getOperand(4); }
2203 const SDValue &getMask() const { return getOperand(2); }
2204 const SDValue &getValue() const { return getOperand(1); }
2205 const SDValue &getScale() const { return getOperand(5); }
2206
2207 static bool classof(const SDNode *N) {
2208 return N->getOpcode() == ISD::MGATHER ||
2209 N->getOpcode() == ISD::MSCATTER;
2210 }
2211};
2212
2213/// This class is used to represent an MGATHER node
2214///
2215class MaskedGatherSDNode : public MaskedGatherScatterSDNode {
2216public:
2217 friend class SelectionDAG;
2218
2219 MaskedGatherSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2220 EVT MemVT, MachineMemOperand *MMO)
2221 : MaskedGatherScatterSDNode(ISD::MGATHER, Order, dl, VTs, MemVT, MMO) {}
2222
2223 static bool classof(const SDNode *N) {
2224 return N->getOpcode() == ISD::MGATHER;
2225 }
2226};
2227
2228/// This class is used to represent an MSCATTER node
2229///
2230class MaskedScatterSDNode : public MaskedGatherScatterSDNode {
2231public:
2232 friend class SelectionDAG;
2233
2234 MaskedScatterSDNode(unsigned Order, const DebugLoc &dl, SDVTList VTs,
2235 EVT MemVT, MachineMemOperand *MMO)
2236 : MaskedGatherScatterSDNode(ISD::MSCATTER, Order, dl, VTs, MemVT, MMO) {}
2237
2238 static bool classof(const SDNode *N) {
2239 return N->getOpcode() == ISD::MSCATTER;
2240 }
2241};
2242
2243/// An SDNode that represents everything that will be needed
2244/// to construct a MachineInstr. These nodes are created during the
2245/// instruction selection proper phase.
2246class MachineSDNode : public SDNode {
2247public:
2248 using mmo_iterator = MachineMemOperand **;
2249
2250private:
2251 friend class SelectionDAG;
2252
2253 MachineSDNode(unsigned Opc, unsigned Order, const DebugLoc &DL, SDVTList VTs)
2254 : SDNode(Opc, Order, DL, VTs) {}
2255
2256 /// Memory reference descriptions for this instruction.
2257 mmo_iterator MemRefs = nullptr;
2258 mmo_iterator MemRefsEnd = nullptr;
2259
2260public:
2261 mmo_iterator memoperands_begin() const { return MemRefs; }
2262 mmo_iterator memoperands_end() const { return MemRefsEnd; }
2263 bool memoperands_empty() const { return MemRefsEnd == MemRefs; }
2264
2265 /// Assign this MachineSDNodes's memory reference descriptor
2266 /// list. This does not transfer ownership.
2267 void setMemRefs(mmo_iterator NewMemRefs, mmo_iterator NewMemRefsEnd) {
2268 for (mmo_iterator MMI = NewMemRefs, MME = NewMemRefsEnd; MMI != MME; ++MMI)
2269 assert(*MMI && "Null mem ref detected!")(static_cast <bool> (*MMI && "Null mem ref detected!"
) ? void (0) : __assert_fail ("*MMI && \"Null mem ref detected!\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAGNodes.h"
, 2269, __extension__ __PRETTY_FUNCTION__))
;
2270 MemRefs = NewMemRefs;
2271 MemRefsEnd = NewMemRefsEnd;
2272 }
2273
2274 static bool classof(const SDNode *N) {
2275 return N->isMachineOpcode();
2276 }
2277};
2278
2279class SDNodeIterator : public std::iterator<std::forward_iterator_tag,
2280 SDNode, ptrdiff_t> {
2281 const SDNode *Node;
2282 unsigned Operand;
2283
2284 SDNodeIterator(const SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
2285
2286public:
2287 bool operator==(const SDNodeIterator& x) const {
2288 return Operand == x.Operand;
2289 }
2290 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
2291
2292 pointer operator*() const {
2293 return Node->getOperand(Operand).getNode();
2294 }
2295 pointer operator->() const { return operator*(); }
2296
2297 SDNodeIterator& operator++() { // Preincrement
2298 ++Operand;
2299 return *this;
2300 }
2301 SDNodeIterator operator++(int) { // Postincrement
2302 SDNodeIterator tmp = *this; ++*this; return tmp;
2303 }
2304 size_t operator-(SDNodeIterator Other) const {
2305 assert(Node == Other.Node &&(static_cast <bool> (Node == Other.Node && "Cannot compare iterators of two different nodes!"
) ? void (0) : __assert_fail ("Node == Other.Node && \"Cannot compare iterators of two different nodes!\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAGNodes.h"
, 2306, __extension__ __PRETTY_FUNCTION__))
2306 "Cannot compare iterators of two different nodes!")(static_cast <bool> (Node == Other.Node && "Cannot compare iterators of two different nodes!"
) ? void (0) : __assert_fail ("Node == Other.Node && \"Cannot compare iterators of two different nodes!\""
, "/build/llvm-toolchain-snapshot-7~svn338205/include/llvm/CodeGen/SelectionDAGNodes.h"
, 2306, __extension__ __PRETTY_FUNCTION__))
;
2307 return Operand - Other.Operand;
2308 }
2309
2310 static SDNodeIterator begin(const SDNode *N) { return SDNodeIterator(N, 0); }
2311 static SDNodeIterator end (const SDNode *N) {
2312 return SDNodeIterator(N, N->getNumOperands());
2313 }
2314
2315 unsigned getOperand() const { return Operand; }
2316 const SDNode *getNode() const { return Node; }
2317};
2318
2319template <> struct GraphTraits<SDNode*> {
2320 using NodeRef = SDNode *;
2321 using ChildIteratorType = SDNodeIterator;
2322
2323 static NodeRef getEntryNode(SDNode *N) { return N; }
2324
2325 static ChildIteratorType child_begin(NodeRef N) {
2326 return SDNodeIterator::begin(N);
2327 }
2328
2329 static ChildIteratorType child_end(NodeRef N) {
2330 return SDNodeIterator::end(N);
2331 }
2332};
2333
2334/// A representation of the largest SDNode, for use in sizeof().
2335///
2336/// This needs to be a union because the largest node differs on 32 bit systems
2337/// with 4 and 8 byte pointer alignment, respectively.
2338using LargestSDNode = AlignedCharArrayUnion<AtomicSDNode, TargetIndexSDNode,
2339 BlockAddressSDNode,
2340 GlobalAddressSDNode>;
2341
2342/// The SDNode class with the greatest alignment requirement.
2343using MostAlignedSDNode = GlobalAddressSDNode;
2344
2345namespace ISD {
2346
2347 /// Returns true if the specified node is a non-extending and unindexed load.
2348 inline bool isNormalLoad(const SDNode *N) {
2349 const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N);
2350 return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
2351 Ld->getAddressingMode() == ISD::UNINDEXED;
2352 }
2353
2354 /// Returns true if the specified node is a non-extending load.
2355 inline bool isNON_EXTLoad(const SDNode *N) {
2356 return isa<LoadSDNode>(N) &&
2357 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
2358 }
2359
2360 /// Returns true if the specified node is a EXTLOAD.
2361 inline bool isEXTLoad(const SDNode *N) {
2362 return isa<LoadSDNode>(N) &&
2363 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
2364 }
2365
2366 /// Returns true if the specified node is a SEXTLOAD.
2367 inline bool isSEXTLoad(const SDNode *N) {
2368 return isa<LoadSDNode>(N) &&
2369 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
2370 }
2371
2372 /// Returns true if the specified node is a ZEXTLOAD.
2373 inline bool isZEXTLoad(const SDNode *N) {
2374 return isa<LoadSDNode>(N) &&
2375 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
2376 }
2377
2378 /// Returns true if the specified node is an unindexed load.
2379 inline bool isUNINDEXEDLoad(const SDNode *N) {
2380 return isa<LoadSDNode>(N) &&
2381 cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2382 }
2383
2384 /// Returns true if the specified node is a non-truncating
2385 /// and unindexed store.
2386 inline bool isNormalStore(const SDNode *N) {
2387 const StoreSDNode *St = dyn_cast<StoreSDNode>(N);
2388 return St && !St->isTruncatingStore() &&
2389 St->getAddressingMode() == ISD::UNINDEXED;
2390 }
2391
2392 /// Returns true if the specified node is a non-truncating store.
2393 inline bool isNON_TRUNCStore(const SDNode *N) {
2394 return isa<StoreSDNode>(N) && !cast<StoreSDNode>(N)->isTruncatingStore();
2395 }
2396
2397 /// Returns true if the specified node is a truncating store.
2398 inline bool isTRUNCStore(const SDNode *N) {
2399 return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore();
2400 }
2401
2402 /// Returns true if the specified node is an unindexed store.
2403 inline bool isUNINDEXEDStore(const SDNode *N) {
2404 return isa<StoreSDNode>(N) &&
2405 cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2406 }
2407
2408 /// Attempt to match a unary predicate against a scalar/splat constant or
2409 /// every element of a constant BUILD_VECTOR.
2410 bool matchUnaryPredicate(SDValue Op,
2411 std::function<bool(ConstantSDNode *)> Match);
2412
2413 /// Attempt to match a binary predicate against a pair of scalar/splat
2414 /// constants or every element of a pair of constant BUILD_VECTORs.
2415 bool matchBinaryPredicate(
2416 SDValue LHS, SDValue RHS,
2417 std::function<bool(ConstantSDNode *, ConstantSDNode *)> Match);
2418
2419} // end namespace ISD
2420
2421} // end namespace llvm
2422
2423#endif // LLVM_CODEGEN_SELECTIONDAGNODES_H