Bug Summary

File:lib/Target/X86/X86SelectionDAGInfo.cpp
Warning:line 1072, 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~svn325118/build-llvm/lib/Target/X86 -I /build/llvm-toolchain-snapshot-7~svn325118/lib/Target/X86 -I /build/llvm-toolchain-snapshot-7~svn325118/build-llvm/include -I /build/llvm-toolchain-snapshot-7~svn325118/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0/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/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-7~svn325118/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-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-02-14-150435-17243-1 -x c++ /build/llvm-toolchain-snapshot-7~svn325118/lib/Target/X86/X86SelectionDAGInfo.cpp

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

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