Bug Summary

File:lib/Target/X86/X86SelectionDAGInfo.cpp
Warning:line 1084, 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~svn329677/build-llvm/lib/Target/X86 -I /build/llvm-toolchain-snapshot-7~svn329677/lib/Target/X86 -I /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/include -I /build/llvm-toolchain-snapshot-7~svn329677/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~svn329677/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-04-11-031539-24776-1 -x c++ /build/llvm-toolchain-snapshot-7~svn329677/lib/Target/X86/X86SelectionDAGInfo.cpp

/build/llvm-toolchain-snapshot-7~svn329677/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~svn329677/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~svn329677/include/llvm/CodeGen/SelectionDAG.h

1//===- llvm/CodeGen/SelectionDAG.h - InstSelection DAG ----------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file declares the SelectionDAG class, and transitively defines the
11// SDNode class and subclasses.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CODEGEN_SELECTIONDAG_H
16#define LLVM_CODEGEN_SELECTIONDAG_H
17
18#include "llvm/ADT/APFloat.h"
19#include "llvm/ADT/APInt.h"
20#include "llvm/ADT/ArrayRef.h"
21#include "llvm/ADT/DenseMap.h"
22#include "llvm/ADT/DenseSet.h"
23#include "llvm/ADT/FoldingSet.h"
24#include "llvm/ADT/SetVector.h"
25#include "llvm/ADT/SmallVector.h"
26#include "llvm/ADT/StringMap.h"
27#include "llvm/ADT/ilist.h"
28#include "llvm/ADT/iterator.h"
29#include "llvm/ADT/iterator_range.h"
30#include "llvm/Analysis/AliasAnalysis.h"
31#include "llvm/Analysis/DivergenceAnalysis.h"
32#include "llvm/CodeGen/DAGCombine.h"
33#include "llvm/CodeGen/FunctionLoweringInfo.h"
34#include "llvm/CodeGen/ISDOpcodes.h"
35#include "llvm/CodeGen/MachineFunction.h"
36#include "llvm/CodeGen/MachineMemOperand.h"
37#include "llvm/CodeGen/SelectionDAGNodes.h"
38#include "llvm/CodeGen/ValueTypes.h"
39#include "llvm/IR/DebugLoc.h"
40#include "llvm/IR/Instructions.h"
41#include "llvm/IR/Metadata.h"
42#include "llvm/Support/Allocator.h"
43#include "llvm/Support/ArrayRecycler.h"
44#include "llvm/Support/AtomicOrdering.h"
45#include "llvm/Support/Casting.h"
46#include "llvm/Support/CodeGen.h"
47#include "llvm/Support/ErrorHandling.h"
48#include "llvm/Support/MachineValueType.h"
49#include "llvm/Support/RecyclingAllocator.h"
50#include <algorithm>
51#include <cassert>
52#include <cstdint>
53#include <functional>
54#include <map>
55#include <string>
56#include <tuple>
57#include <utility>
58#include <vector>
59
60namespace llvm {
61
62class BlockAddress;
63class Constant;
64class ConstantFP;
65class ConstantInt;
66class DataLayout;
67struct fltSemantics;
68class GlobalValue;
69struct KnownBits;
70class LLVMContext;
71class MachineBasicBlock;
72class MachineConstantPoolValue;
73class MCSymbol;
74class OptimizationRemarkEmitter;
75class SDDbgValue;
76class SelectionDAG;
77class SelectionDAGTargetInfo;
78class TargetLibraryInfo;
79class TargetLowering;
80class TargetMachine;
81class TargetSubtargetInfo;
82class Value;
83
84class SDVTListNode : public FoldingSetNode {
85 friend struct FoldingSetTrait<SDVTListNode>;
86
87 /// A reference to an Interned FoldingSetNodeID for this node.
88 /// The Allocator in SelectionDAG holds the data.
89 /// SDVTList contains all types which are frequently accessed in SelectionDAG.
90 /// The size of this list is not expected to be big so it won't introduce
91 /// a memory penalty.
92 FoldingSetNodeIDRef FastID;
93 const EVT *VTs;
94 unsigned int NumVTs;
95 /// The hash value for SDVTList is fixed, so cache it to avoid
96 /// hash calculation.
97 unsigned HashValue;
98
99public:
100 SDVTListNode(const FoldingSetNodeIDRef ID, const EVT *VT, unsigned int Num) :
101 FastID(ID), VTs(VT), NumVTs(Num) {
102 HashValue = ID.ComputeHash();
103 }
104
105 SDVTList getSDVTList() {
106 SDVTList result = {VTs, NumVTs};
107 return result;
108 }
109};
110
111/// Specialize FoldingSetTrait for SDVTListNode
112/// to avoid computing temp FoldingSetNodeID and hash value.
113template<> struct FoldingSetTrait<SDVTListNode> : DefaultFoldingSetTrait<SDVTListNode> {
114 static void Profile(const SDVTListNode &X, FoldingSetNodeID& ID) {
115 ID = X.FastID;
116 }
117
118 static bool Equals(const SDVTListNode &X, const FoldingSetNodeID &ID,
119 unsigned IDHash, FoldingSetNodeID &TempID) {
120 if (X.HashValue != IDHash)
121 return false;
122 return ID == X.FastID;
123 }
124
125 static unsigned ComputeHash(const SDVTListNode &X, FoldingSetNodeID &TempID) {
126 return X.HashValue;
127 }
128};
129
130template <> struct ilist_alloc_traits<SDNode> {
131 static void deleteNode(SDNode *) {
132 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~svn329677/include/llvm/CodeGen/SelectionDAG.h"
, 132)
;
133 }
134};
135
136/// Keeps track of dbg_value information through SDISel. We do
137/// not build SDNodes for these so as not to perturb the generated code;
138/// instead the info is kept off to the side in this structure. Each SDNode may
139/// have one or more associated dbg_value entries. This information is kept in
140/// DbgValMap.
141/// Byval parameters are handled separately because they don't use alloca's,
142/// which busts the normal mechanism. There is good reason for handling all
143/// parameters separately: they may not have code generated for them, they
144/// should always go at the beginning of the function regardless of other code
145/// motion, and debug info for them is potentially useful even if the parameter
146/// is unused. Right now only byval parameters are handled separately.
147class SDDbgInfo {
148 BumpPtrAllocator Alloc;
149 SmallVector<SDDbgValue*, 32> DbgValues;
150 SmallVector<SDDbgValue*, 32> ByvalParmDbgValues;
151 using DbgValMapType = DenseMap<const SDNode *, SmallVector<SDDbgValue *, 2>>;
152 DbgValMapType DbgValMap;
153
154public:
155 SDDbgInfo() = default;
156 SDDbgInfo(const SDDbgInfo &) = delete;
157 SDDbgInfo &operator=(const SDDbgInfo &) = delete;
158
159 void add(SDDbgValue *V, const SDNode *Node, bool isParameter) {
160 if (isParameter) {
161 ByvalParmDbgValues.push_back(V);
162 } else DbgValues.push_back(V);
163 if (Node)
164 DbgValMap[Node].push_back(V);
165 }
166
167 /// \brief Invalidate all DbgValues attached to the node and remove
168 /// it from the Node-to-DbgValues map.
169 void erase(const SDNode *Node);
170
171 void clear() {
172 DbgValMap.clear();
173 DbgValues.clear();
174 ByvalParmDbgValues.clear();
175 Alloc.Reset();
176 }
177
178 BumpPtrAllocator &getAlloc() { return Alloc; }
179
180 bool empty() const {
181 return DbgValues.empty() && ByvalParmDbgValues.empty();
182 }
183
184 ArrayRef<SDDbgValue*> getSDDbgValues(const SDNode *Node) {
185 DbgValMapType::iterator I = DbgValMap.find(Node);
186 if (I != DbgValMap.end())
187 return I->second;
188 return ArrayRef<SDDbgValue*>();
189 }
190
191 using DbgIterator = SmallVectorImpl<SDDbgValue*>::iterator;
192
193 DbgIterator DbgBegin() { return DbgValues.begin(); }
194 DbgIterator DbgEnd() { return DbgValues.end(); }
195 DbgIterator ByvalParmDbgBegin() { return ByvalParmDbgValues.begin(); }
196 DbgIterator ByvalParmDbgEnd() { return ByvalParmDbgValues.end(); }
197};
198
199void checkForCycles(const SelectionDAG *DAG, bool force = false);
200
201/// This is used to represent a portion of an LLVM function in a low-level
202/// Data Dependence DAG representation suitable for instruction selection.
203/// This DAG is constructed as the first step of instruction selection in order
204/// to allow implementation of machine specific optimizations
205/// and code simplifications.
206///
207/// The representation used by the SelectionDAG is a target-independent
208/// representation, which has some similarities to the GCC RTL representation,
209/// but is significantly more simple, powerful, and is a graph form instead of a
210/// linear form.
211///
212class SelectionDAG {
213 const TargetMachine &TM;
214 const SelectionDAGTargetInfo *TSI = nullptr;
215 const TargetLowering *TLI = nullptr;
216 const TargetLibraryInfo *LibInfo = nullptr;
217 MachineFunction *MF;
218 Pass *SDAGISelPass = nullptr;
219 LLVMContext *Context;
220 CodeGenOpt::Level OptLevel;
221
222 DivergenceAnalysis * DA = nullptr;
223 FunctionLoweringInfo * FLI = nullptr;
224
225 /// The function-level optimization remark emitter. Used to emit remarks
226 /// whenever manipulating the DAG.
227 OptimizationRemarkEmitter *ORE;
228
229 /// The starting token.
230 SDNode EntryNode;
231
232 /// The root of the entire DAG.
233 SDValue Root;
234
235 /// A linked list of nodes in the current DAG.
236 ilist<SDNode> AllNodes;
237
238 /// The AllocatorType for allocating SDNodes. We use
239 /// pool allocation with recycling.
240 using NodeAllocatorType = RecyclingAllocator<BumpPtrAllocator, SDNode,
241 sizeof(LargestSDNode),
242 alignof(MostAlignedSDNode)>;
243
244 /// Pool allocation for nodes.
245 NodeAllocatorType NodeAllocator;
246
247 /// This structure is used to memoize nodes, automatically performing
248 /// CSE with existing nodes when a duplicate is requested.
249 FoldingSet<SDNode> CSEMap;
250
251 /// Pool allocation for machine-opcode SDNode operands.
252 BumpPtrAllocator OperandAllocator;
253 ArrayRecycler<SDUse> OperandRecycler;
254
255 /// Pool allocation for misc. objects that are created once per SelectionDAG.
256 BumpPtrAllocator Allocator;
257
258 /// Tracks dbg_value information through SDISel.
259 SDDbgInfo *DbgInfo;
260
261 uint16_t NextPersistentId = 0;
262
263public:
264 /// Clients of various APIs that cause global effects on
265 /// the DAG can optionally implement this interface. This allows the clients
266 /// to handle the various sorts of updates that happen.
267 ///
268 /// A DAGUpdateListener automatically registers itself with DAG when it is
269 /// constructed, and removes itself when destroyed in RAII fashion.
270 struct DAGUpdateListener {
271 DAGUpdateListener *const Next;
272 SelectionDAG &DAG;
273
274 explicit DAGUpdateListener(SelectionDAG &D)
275 : Next(D.UpdateListeners), DAG(D) {
276 DAG.UpdateListeners = this;
277 }
278
279 virtual ~DAGUpdateListener() {
280 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~svn329677/include/llvm/CodeGen/SelectionDAG.h"
, 281, __extension__ __PRETTY_FUNCTION__))
281 "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~svn329677/include/llvm/CodeGen/SelectionDAG.h"
, 281, __extension__ __PRETTY_FUNCTION__))
;
282 DAG.UpdateListeners = Next;
283 }
284
285 /// The node N that was deleted and, if E is not null, an
286 /// equivalent node E that replaced it.
287 virtual void NodeDeleted(SDNode *N, SDNode *E);
288
289 /// The node N that was updated.
290 virtual void NodeUpdated(SDNode *N);
291 };
292
293 struct DAGNodeDeletedListener : public DAGUpdateListener {
294 std::function<void(SDNode *, SDNode *)> Callback;
295
296 DAGNodeDeletedListener(SelectionDAG &DAG,
297 std::function<void(SDNode *, SDNode *)> Callback)
298 : DAGUpdateListener(DAG), Callback(std::move(Callback)) {}
299
300 void NodeDeleted(SDNode *N, SDNode *E) override { Callback(N, E); }
301 };
302
303 /// When true, additional steps are taken to
304 /// ensure that getConstant() and similar functions return DAG nodes that
305 /// have legal types. This is important after type legalization since
306 /// any illegally typed nodes generated after this point will not experience
307 /// type legalization.
308 bool NewNodesMustHaveLegalTypes = false;
309
310private:
311 /// DAGUpdateListener is a friend so it can manipulate the listener stack.
312 friend struct DAGUpdateListener;
313
314 /// Linked list of registered DAGUpdateListener instances.
315 /// This stack is maintained by DAGUpdateListener RAII.
316 DAGUpdateListener *UpdateListeners = nullptr;
317
318 /// Implementation of setSubgraphColor.
319 /// Return whether we had to truncate the search.
320 bool setSubgraphColorHelper(SDNode *N, const char *Color,
321 DenseSet<SDNode *> &visited,
322 int level, bool &printed);
323
324 template <typename SDNodeT, typename... ArgTypes>
325 SDNodeT *newSDNode(ArgTypes &&... Args) {
326 return new (NodeAllocator.template Allocate<SDNodeT>())
327 SDNodeT(std::forward<ArgTypes>(Args)...);
328 }
329
330 /// Build a synthetic SDNodeT with the given args and extract its subclass
331 /// data as an integer (e.g. for use in a folding set).
332 ///
333 /// The args to this function are the same as the args to SDNodeT's
334 /// constructor, except the second arg (assumed to be a const DebugLoc&) is
335 /// omitted.
336 template <typename SDNodeT, typename... ArgTypes>
337 static uint16_t getSyntheticNodeSubclassData(unsigned IROrder,
338 ArgTypes &&... Args) {
339 // The compiler can reduce this expression to a constant iff we pass an
340 // empty DebugLoc. Thankfully, the debug location doesn't have any bearing
341 // on the subclass data.
342 return SDNodeT(IROrder, DebugLoc(), std::forward<ArgTypes>(Args)...)
343 .getRawSubclassData();
344 }
345
346 template <typename SDNodeTy>
347 static uint16_t getSyntheticNodeSubclassData(unsigned Opc, unsigned Order,
348 SDVTList VTs, EVT MemoryVT,
349 MachineMemOperand *MMO) {
350 return SDNodeTy(Opc, Order, DebugLoc(), VTs, MemoryVT, MMO)
351 .getRawSubclassData();
352 }
353
354 void createOperands(SDNode *Node, ArrayRef<SDValue> Vals);
355
356 void removeOperands(SDNode *Node) {
357 if (!Node->OperandList)
358 return;
359 OperandRecycler.deallocate(
360 ArrayRecycler<SDUse>::Capacity::get(Node->NumOperands),
361 Node->OperandList);
362 Node->NumOperands = 0;
363 Node->OperandList = nullptr;
364 }
365 void CreateTopologicalOrder(std::vector<SDNode*>& Order);
366public:
367 explicit SelectionDAG(const TargetMachine &TM, CodeGenOpt::Level);
368 SelectionDAG(const SelectionDAG &) = delete;
369 SelectionDAG &operator=(const SelectionDAG &) = delete;
370 ~SelectionDAG();
371
372 /// Prepare this SelectionDAG to process code in the given MachineFunction.
373 void init(MachineFunction &NewMF, OptimizationRemarkEmitter &NewORE,
374 Pass *PassPtr, const TargetLibraryInfo *LibraryInfo,
375 DivergenceAnalysis * DA);
376
377 void setFunctionLoweringInfo(FunctionLoweringInfo * FuncInfo) {
378 FLI = FuncInfo;
379 }
380
381 /// Clear state and free memory necessary to make this
382 /// SelectionDAG ready to process a new block.
383 void clear();
384
385 MachineFunction &getMachineFunction() const { return *MF; }
386 const Pass *getPass() const { return SDAGISelPass; }
387
388 const DataLayout &getDataLayout() const { return MF->getDataLayout(); }
389 const TargetMachine &getTarget() const { return TM; }
390 const TargetSubtargetInfo &getSubtarget() const { return MF->getSubtarget(); }
391 const TargetLowering &getTargetLoweringInfo() const { return *TLI; }
392 const TargetLibraryInfo &getLibInfo() const { return *LibInfo; }
393 const SelectionDAGTargetInfo &getSelectionDAGInfo() const { return *TSI; }
394 LLVMContext *getContext() const {return Context; }
395 OptimizationRemarkEmitter &getORE() const { return *ORE; }
396
397 /// Pop up a GraphViz/gv window with the DAG rendered using 'dot'.
398 void viewGraph(const std::string &Title);
399 void viewGraph();
400
401#ifndef NDEBUG
402 std::map<const SDNode *, std::string> NodeGraphAttrs;
403#endif
404
405 /// Clear all previously defined node graph attributes.
406 /// Intended to be used from a debugging tool (eg. gdb).
407 void clearGraphAttrs();
408
409 /// Set graph attributes for a node. (eg. "color=red".)
410 void setGraphAttrs(const SDNode *N, const char *Attrs);
411
412 /// Get graph attributes for a node. (eg. "color=red".)
413 /// Used from getNodeAttributes.
414 const std::string getGraphAttrs(const SDNode *N) const;
415
416 /// Convenience for setting node color attribute.
417 void setGraphColor(const SDNode *N, const char *Color);
418
419 /// Convenience for setting subgraph color attribute.
420 void setSubgraphColor(SDNode *N, const char *Color);
421
422 using allnodes_const_iterator = ilist<SDNode>::const_iterator;
423
424 allnodes_const_iterator allnodes_begin() const { return AllNodes.begin(); }
425 allnodes_const_iterator allnodes_end() const { return AllNodes.end(); }
426
427 using allnodes_iterator = ilist<SDNode>::iterator;
428
429 allnodes_iterator allnodes_begin() { return AllNodes.begin(); }
430 allnodes_iterator allnodes_end() { return AllNodes.end(); }
431
432 ilist<SDNode>::size_type allnodes_size() const {
433 return AllNodes.size();
434 }
435
436 iterator_range<allnodes_iterator> allnodes() {
437 return make_range(allnodes_begin(), allnodes_end());
438 }
439 iterator_range<allnodes_const_iterator> allnodes() const {
440 return make_range(allnodes_begin(), allnodes_end());
441 }
442
443 /// Return the root tag of the SelectionDAG.
444 const SDValue &getRoot() const { return Root; }
445
446 /// Return the token chain corresponding to the entry of the function.
447 SDValue getEntryNode() const {
448 return SDValue(const_cast<SDNode *>(&EntryNode), 0);
449 }
450
451 /// Set the current root tag of the SelectionDAG.
452 ///
453 const SDValue &setRoot(SDValue N) {
454 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~svn329677/include/llvm/CodeGen/SelectionDAG.h"
, 455, __extension__ __PRETTY_FUNCTION__))
455 "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~svn329677/include/llvm/CodeGen/SelectionDAG.h"
, 455, __extension__ __PRETTY_FUNCTION__))
;
456 if (N.getNode())
457 checkForCycles(N.getNode(), this);
458 Root = N;
459 if (N.getNode())
460 checkForCycles(this);
461 return Root;
462 }
463
464 void VerifyDAGDiverence();
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~svn329677/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~svn329677/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~svn329677/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~svn329677/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~svn329677/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~svn329677/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~svn329677/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~svn329677/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~svn329677/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~svn329677/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~svn329677/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~svn329677/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~svn329677/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~svn329677/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~svn329677/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 // Propagates the change in divergence to users
1132 void updateDivergence(SDNode * N);
1133
1134 /// These are used for target selectors to *mutate* the
1135 /// specified node to have the specified return type, Target opcode, and
1136 /// operands. Note that target opcodes are stored as
1137 /// ~TargetOpcode in the node opcode field. The resultant node is returned.
1138 SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT);
1139 SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT, SDValue Op1);
1140 SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT,
1141 SDValue Op1, SDValue Op2);
1142 SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT,
1143 SDValue Op1, SDValue Op2, SDValue Op3);
1144 SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT,
1145 ArrayRef<SDValue> Ops);
1146 SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT1, EVT VT2);
1147 SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT1,
1148 EVT VT2, ArrayRef<SDValue> Ops);
1149 SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT1,
1150 EVT VT2, EVT VT3, ArrayRef<SDValue> Ops);
1151 SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT1,
1152 EVT VT2, SDValue Op1);
1153 SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT1,
1154 EVT VT2, SDValue Op1, SDValue Op2);
1155 SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, SDVTList VTs,
1156 ArrayRef<SDValue> Ops);
1157
1158 /// This *mutates* the specified node to have the specified
1159 /// return type, opcode, and operands.
1160 SDNode *MorphNodeTo(SDNode *N, unsigned Opc, SDVTList VTs,
1161 ArrayRef<SDValue> Ops);
1162
1163 /// Mutate the specified strict FP node to its non-strict equivalent,
1164 /// unlinking the node from its chain and dropping the metadata arguments.
1165 /// The node must be a strict FP node.
1166 SDNode *mutateStrictFPToFP(SDNode *Node);
1167
1168 /// These are used for target selectors to create a new node
1169 /// with specified return type(s), MachineInstr opcode, and operands.
1170 ///
1171 /// Note that getMachineNode returns the resultant node. If there is already
1172 /// a node of the specified opcode and operands, it returns that node instead
1173 /// of the current one.
1174 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT);
1175 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT,
1176 SDValue Op1);
1177 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT,
1178 SDValue Op1, SDValue Op2);
1179 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT,
1180 SDValue Op1, SDValue Op2, SDValue Op3);
1181 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT,
1182 ArrayRef<SDValue> Ops);
1183 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT1,
1184 EVT VT2, SDValue Op1, SDValue Op2);
1185 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT1,
1186 EVT VT2, SDValue Op1, SDValue Op2, SDValue Op3);
1187 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT1,
1188 EVT VT2, ArrayRef<SDValue> Ops);
1189 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT1,
1190 EVT VT2, EVT VT3, SDValue Op1, SDValue Op2);
1191 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT1,
1192 EVT VT2, EVT VT3, SDValue Op1, SDValue Op2,
1193 SDValue Op3);
1194 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT1,
1195 EVT VT2, EVT VT3, ArrayRef<SDValue> Ops);
1196 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl,
1197 ArrayRef<EVT> ResultTys, ArrayRef<SDValue> Ops);
1198 MachineSDNode *getMachineNode(unsigned Opcode, const SDLoc &dl, SDVTList VTs,
1199 ArrayRef<SDValue> Ops);
1200
1201 /// A convenience function for creating TargetInstrInfo::EXTRACT_SUBREG nodes.
1202 SDValue getTargetExtractSubreg(int SRIdx, const SDLoc &DL, EVT VT,
1203 SDValue Operand);
1204
1205 /// A convenience function for creating TargetInstrInfo::INSERT_SUBREG nodes.
1206 SDValue getTargetInsertSubreg(int SRIdx, const SDLoc &DL, EVT VT,
1207 SDValue Operand, SDValue Subreg);
1208
1209 /// Get the specified node if it's already available, or else return NULL.
1210 SDNode *getNodeIfExists(unsigned Opcode, SDVTList VTs, ArrayRef<SDValue> Ops,
1211 const SDNodeFlags Flags = SDNodeFlags());
1212
1213 /// Creates a SDDbgValue node.
1214 SDDbgValue *getDbgValue(DIVariable *Var, DIExpression *Expr, SDNode *N,
1215 unsigned R, bool IsIndirect, const DebugLoc &DL,
1216 unsigned O);
1217
1218 /// Creates a constant SDDbgValue node.
1219 SDDbgValue *getConstantDbgValue(DIVariable *Var, DIExpression *Expr,
1220 const Value *C, const DebugLoc &DL,
1221 unsigned O);
1222
1223 /// Creates a FrameIndex SDDbgValue node.
1224 SDDbgValue *getFrameIndexDbgValue(DIVariable *Var, DIExpression *Expr,
1225 unsigned FI, const DebugLoc &DL,
1226 unsigned O);
1227
1228 /// Transfer debug values from one node to another, while optionally
1229 /// generating fragment expressions for split-up values. If \p InvalidateDbg
1230 /// is set, debug values are invalidated after they are transferred.
1231 void transferDbgValues(SDValue From, SDValue To, unsigned OffsetInBits = 0,
1232 unsigned SizeInBits = 0, bool InvalidateDbg = true);
1233
1234 /// Remove the specified node from the system. If any of its
1235 /// operands then becomes dead, remove them as well. Inform UpdateListener
1236 /// for each node deleted.
1237 void RemoveDeadNode(SDNode *N);
1238
1239 /// This method deletes the unreachable nodes in the
1240 /// given list, and any nodes that become unreachable as a result.
1241 void RemoveDeadNodes(SmallVectorImpl<SDNode *> &DeadNodes);
1242
1243 /// Modify anything using 'From' to use 'To' instead.
1244 /// This can cause recursive merging of nodes in the DAG. Use the first
1245 /// version if 'From' is known to have a single result, use the second
1246 /// if you have two nodes with identical results (or if 'To' has a superset
1247 /// of the results of 'From'), use the third otherwise.
1248 ///
1249 /// These methods all take an optional UpdateListener, which (if not null) is
1250 /// informed about nodes that are deleted and modified due to recursive
1251 /// changes in the dag.
1252 ///
1253 /// These functions only replace all existing uses. It's possible that as
1254 /// these replacements are being performed, CSE may cause the From node
1255 /// to be given new uses. These new uses of From are left in place, and
1256 /// not automatically transferred to To.
1257 ///
1258 void ReplaceAllUsesWith(SDValue From, SDValue Op);
1259 void ReplaceAllUsesWith(SDNode *From, SDNode *To);
1260 void ReplaceAllUsesWith(SDNode *From, const SDValue *To);
1261
1262 /// Replace any uses of From with To, leaving
1263 /// uses of other values produced by From.getNode() alone.
1264 void ReplaceAllUsesOfValueWith(SDValue From, SDValue To);
1265
1266 /// Like ReplaceAllUsesOfValueWith, but for multiple values at once.
1267 /// This correctly handles the case where
1268 /// there is an overlap between the From values and the To values.
1269 void ReplaceAllUsesOfValuesWith(const SDValue *From, const SDValue *To,
1270 unsigned Num);
1271
1272 /// If an existing load has uses of its chain, create a token factor node with
1273 /// that chain and the new memory node's chain and update users of the old
1274 /// chain to the token factor. This ensures that the new memory node will have
1275 /// the same relative memory dependency position as the old load. Returns the
1276 /// new merged load chain.
1277 SDValue makeEquivalentMemoryOrdering(LoadSDNode *Old, SDValue New);
1278
1279 /// Topological-sort the AllNodes list and a
1280 /// assign a unique node id for each node in the DAG based on their
1281 /// topological order. Returns the number of nodes.
1282 unsigned AssignTopologicalOrder();
1283
1284 /// Move node N in the AllNodes list to be immediately
1285 /// before the given iterator Position. This may be used to update the
1286 /// topological ordering when the list of nodes is modified.
1287 void RepositionNode(allnodes_iterator Position, SDNode *N) {
1288 AllNodes.insert(Position, AllNodes.remove(N));
1289 }
1290
1291 /// Returns an APFloat semantics tag appropriate for the given type. If VT is
1292 /// a vector type, the element semantics are returned.
1293 static const fltSemantics &EVTToAPFloatSemantics(EVT VT) {
1294 switch (VT.getScalarType().getSimpleVT().SimpleTy) {
1295 default: llvm_unreachable("Unknown FP format")::llvm::llvm_unreachable_internal("Unknown FP format", "/build/llvm-toolchain-snapshot-7~svn329677/include/llvm/CodeGen/SelectionDAG.h"
, 1295)
;
1296 case MVT::f16: return APFloat::IEEEhalf();
1297 case MVT::f32: return APFloat::IEEEsingle();
1298 case MVT::f64: return APFloat::IEEEdouble();
1299 case MVT::f80: return APFloat::x87DoubleExtended();
1300 case MVT::f128: return APFloat::IEEEquad();
1301 case MVT::ppcf128: return APFloat::PPCDoubleDouble();
1302 }
1303 }
1304
1305 /// Add a dbg_value SDNode. If SD is non-null that means the
1306 /// value is produced by SD.
1307 void AddDbgValue(SDDbgValue *DB, SDNode *SD, bool isParameter);
1308
1309 /// Get the debug values which reference the given SDNode.
1310 ArrayRef<SDDbgValue*> GetDbgValues(const SDNode* SD) {
1311 return DbgInfo->getSDDbgValues(SD);
1312 }
1313
1314public:
1315 /// Return true if there are any SDDbgValue nodes associated
1316 /// with this SelectionDAG.
1317 bool hasDebugValues() const { return !DbgInfo->empty(); }
1318
1319 SDDbgInfo::DbgIterator DbgBegin() { return DbgInfo->DbgBegin(); }
1320 SDDbgInfo::DbgIterator DbgEnd() { return DbgInfo->DbgEnd(); }
1321
1322 SDDbgInfo::DbgIterator ByvalParmDbgBegin() {
1323 return DbgInfo->ByvalParmDbgBegin();
1324 }
1325
1326 SDDbgInfo::DbgIterator ByvalParmDbgEnd() {
1327 return DbgInfo->ByvalParmDbgEnd();
1328 }
1329
1330 /// To be invoked on an SDNode that is slated to be erased. This
1331 /// function mirrors \c llvm::salvageDebugInfo.
1332 void salvageDebugInfo(SDNode &N);
1333
1334 void dump() const;
1335
1336 /// Create a stack temporary, suitable for holding the specified value type.
1337 /// If minAlign is specified, the slot size will have at least that alignment.
1338 SDValue CreateStackTemporary(EVT VT, unsigned minAlign = 1);
1339
1340 /// Create a stack temporary suitable for holding either of the specified
1341 /// value types.
1342 SDValue CreateStackTemporary(EVT VT1, EVT VT2);
1343
1344 SDValue FoldSymbolOffset(unsigned Opcode, EVT VT,
1345 const GlobalAddressSDNode *GA,
1346 const SDNode *N2);
1347
1348 SDValue FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL, EVT VT,
1349 SDNode *Cst1, SDNode *Cst2);
1350
1351 SDValue FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL, EVT VT,
1352 const ConstantSDNode *Cst1,
1353 const ConstantSDNode *Cst2);
1354
1355 SDValue FoldConstantVectorArithmetic(unsigned Opcode, const SDLoc &DL, EVT VT,
1356 ArrayRef<SDValue> Ops,
1357 const SDNodeFlags Flags = SDNodeFlags());
1358
1359 /// Constant fold a setcc to true or false.
1360 SDValue FoldSetCC(EVT VT, SDValue N1, SDValue N2, ISD::CondCode Cond,
1361 const SDLoc &dl);
1362
1363 /// See if the specified operand can be simplified with the knowledge that only
1364 /// the bits specified by Mask are used. If so, return the simpler operand,
1365 /// otherwise return a null SDValue.
1366 ///
1367 /// (This exists alongside SimplifyDemandedBits because GetDemandedBits can
1368 /// simplify nodes with multiple uses more aggressively.)
1369 SDValue GetDemandedBits(SDValue V, const APInt &Mask);
1370
1371 /// Return true if the sign bit of Op is known to be zero.
1372 /// We use this predicate to simplify operations downstream.
1373 bool SignBitIsZero(SDValue Op, unsigned Depth = 0) const;
1374
1375 /// Return true if 'Op & Mask' is known to be zero. We
1376 /// use this predicate to simplify operations downstream. Op and Mask are
1377 /// known to be the same type.
1378 bool MaskedValueIsZero(SDValue Op, const APInt &Mask, unsigned Depth = 0)
1379 const;
1380
1381 /// Determine which bits of Op are known to be either zero or one and return
1382 /// them in Known. For vectors, the known bits are those that are shared by
1383 /// every vector element.
1384 /// Targets can implement the computeKnownBitsForTargetNode method in the
1385 /// TargetLowering class to allow target nodes to be understood.
1386 void computeKnownBits(SDValue Op, KnownBits &Known, unsigned Depth = 0) const;
1387
1388 /// Determine which bits of Op are known to be either zero or one and return
1389 /// them in Known. The DemandedElts argument allows us to only collect the
1390 /// known bits that are shared by the requested vector elements.
1391 /// Targets can implement the computeKnownBitsForTargetNode method in the
1392 /// TargetLowering class to allow target nodes to be understood.
1393 void computeKnownBits(SDValue Op, KnownBits &Known, const APInt &DemandedElts,
1394 unsigned Depth = 0) const;
1395
1396 /// Used to represent the possible overflow behavior of an operation.
1397 /// Never: the operation cannot overflow.
1398 /// Always: the operation will always overflow.
1399 /// Sometime: the operation may or may not overflow.
1400 enum OverflowKind {
1401 OFK_Never,
1402 OFK_Sometime,
1403 OFK_Always,
1404 };
1405
1406 /// Determine if the result of the addition of 2 node can overflow.
1407 OverflowKind computeOverflowKind(SDValue N0, SDValue N1) const;
1408
1409 /// Test if the given value is known to have exactly one bit set. This differs
1410 /// from computeKnownBits in that it doesn't necessarily determine which bit
1411 /// is set.
1412 bool isKnownToBeAPowerOfTwo(SDValue Val) const;
1413
1414 /// Return the number of times the sign bit of the register is replicated into
1415 /// the other bits. We know that at least 1 bit is always equal to the sign
1416 /// bit (itself), but other cases can give us information. For example,
1417 /// immediately after an "SRA X, 2", we know that the top 3 bits are all equal
1418 /// to each other, so we return 3. Targets can implement the
1419 /// ComputeNumSignBitsForTarget method in the TargetLowering class to allow
1420 /// target nodes to be understood.
1421 unsigned ComputeNumSignBits(SDValue Op, unsigned Depth = 0) const;
1422
1423 /// Return the number of times the sign bit of the register is replicated into
1424 /// the other bits. We know that at least 1 bit is always equal to the sign
1425 /// bit (itself), but other cases can give us information. For example,
1426 /// immediately after an "SRA X, 2", we know that the top 3 bits are all equal
1427 /// to each other, so we return 3. The DemandedElts argument allows
1428 /// us to only collect the minimum sign bits of the requested vector elements.
1429 /// Targets can implement the ComputeNumSignBitsForTarget method in the
1430 /// TargetLowering class to allow target nodes to be understood.
1431 unsigned ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
1432 unsigned Depth = 0) const;
1433
1434 /// Return true if the specified operand is an ISD::ADD with a ConstantSDNode
1435 /// on the right-hand side, or if it is an ISD::OR with a ConstantSDNode that
1436 /// is guaranteed to have the same semantics as an ADD. This handles the
1437 /// equivalence:
1438 /// X|Cst == X+Cst iff X&Cst = 0.
1439 bool isBaseWithConstantOffset(SDValue Op) const;
1440
1441 /// Test whether the given SDValue is known to never be NaN.
1442 bool isKnownNeverNaN(SDValue Op) const;
1443
1444 /// Test whether the given SDValue is known to never be positive or negative
1445 /// zero.
1446 bool isKnownNeverZero(SDValue Op) const;
1447
1448 /// Test whether two SDValues are known to compare equal. This
1449 /// is true if they are the same value, or if one is negative zero and the
1450 /// other positive zero.
1451 bool isEqualTo(SDValue A, SDValue B) const;
1452
1453 /// Return true if A and B have no common bits set. As an example, this can
1454 /// allow an 'add' to be transformed into an 'or'.
1455 bool haveNoCommonBitsSet(SDValue A, SDValue B) const;
1456
1457 /// Utility function used by legalize and lowering to
1458 /// "unroll" a vector operation by splitting out the scalars and operating
1459 /// on each element individually. If the ResNE is 0, fully unroll the vector
1460 /// op. If ResNE is less than the width of the vector op, unroll up to ResNE.
1461 /// If the ResNE is greater than the width of the vector op, unroll the
1462 /// vector op and fill the end of the resulting vector with UNDEFS.
1463 SDValue UnrollVectorOp(SDNode *N, unsigned ResNE = 0);
1464
1465 /// Return true if loads are next to each other and can be
1466 /// merged. Check that both are nonvolatile and if LD is loading
1467 /// 'Bytes' bytes from a location that is 'Dist' units away from the
1468 /// location that the 'Base' load is loading from.
1469 bool areNonVolatileConsecutiveLoads(LoadSDNode *LD, LoadSDNode *Base,
1470 unsigned Bytes, int Dist) const;
1471
1472 /// Infer alignment of a load / store address. Return 0 if
1473 /// it cannot be inferred.
1474 unsigned InferPtrAlignment(SDValue Ptr) const;
1475
1476 /// Compute the VTs needed for the low/hi parts of a type
1477 /// which is split (or expanded) into two not necessarily identical pieces.
1478 std::pair<EVT, EVT> GetSplitDestVTs(const EVT &VT) const;
1479
1480 /// Split the vector with EXTRACT_SUBVECTOR using the provides
1481 /// VTs and return the low/high part.
1482 std::pair<SDValue, SDValue> SplitVector(const SDValue &N, const SDLoc &DL,
1483 const EVT &LoVT, const EVT &HiVT);
1484
1485 /// Split the vector with EXTRACT_SUBVECTOR and return the low/high part.
1486 std::pair<SDValue, SDValue> SplitVector(const SDValue &N, const SDLoc &DL) {
1487 EVT LoVT, HiVT;
1488 std::tie(LoVT, HiVT) = GetSplitDestVTs(N.getValueType());
1489 return SplitVector(N, DL, LoVT, HiVT);
1490 }
1491
1492 /// Split the node's operand with EXTRACT_SUBVECTOR and
1493 /// return the low/high part.
1494 std::pair<SDValue, SDValue> SplitVectorOperand(const SDNode *N, unsigned OpNo)
1495 {
1496 return SplitVector(N->getOperand(OpNo), SDLoc(N));
1497 }
1498
1499 /// Append the extracted elements from Start to Count out of the vector Op
1500 /// in Args. If Count is 0, all of the elements will be extracted.
1501 void ExtractVectorElements(SDValue Op, SmallVectorImpl<SDValue> &Args,
1502 unsigned Start = 0, unsigned Count = 0);
1503
1504 /// Compute the default alignment value for the given type.
1505 unsigned getEVTAlignment(EVT MemoryVT) const;
1506
1507 /// Test whether the given value is a constant int or similar node.
1508 SDNode *isConstantIntBuildVectorOrConstantInt(SDValue N);
1509
1510 /// Test whether the given value is a constant FP or similar node.
1511 SDNode *isConstantFPBuildVectorOrConstantFP(SDValue N);
1512
1513 /// \returns true if \p N is any kind of constant or build_vector of
1514 /// constants, int or float. If a vector, it may not necessarily be a splat.
1515 inline bool isConstantValueOfAnyType(SDValue N) {
1516 return isConstantIntBuildVectorOrConstantInt(N) ||
1517 isConstantFPBuildVectorOrConstantFP(N);
1518 }
1519
1520private:
1521 void InsertNode(SDNode *N);
1522 bool RemoveNodeFromCSEMaps(SDNode *N);
1523 void AddModifiedNodeToCSEMaps(SDNode *N);
1524 SDNode *FindModifiedNodeSlot(SDNode *N, SDValue Op, void *&InsertPos);
1525 SDNode *FindModifiedNodeSlot(SDNode *N, SDValue Op1, SDValue Op2,
1526 void *&InsertPos);
1527 SDNode *FindModifiedNodeSlot(SDNode *N, ArrayRef<SDValue> Ops,
1528 void *&InsertPos);
1529 SDNode *UpdateSDLocOnMergeSDNode(SDNode *N, const SDLoc &loc);
1530
1531 void DeleteNodeNotInCSEMaps(SDNode *N);
1532 void DeallocateNode(SDNode *N);
1533
1534 void allnodes_clear();
1535
1536 /// Look up the node specified by ID in CSEMap. If it exists, return it. If
1537 /// not, return the insertion token that will make insertion faster. This
1538 /// overload is for nodes other than Constant or ConstantFP, use the other one
1539 /// for those.
1540 SDNode *FindNodeOrInsertPos(const FoldingSetNodeID &ID, void *&InsertPos);
1541
1542 /// Look up the node specified by ID in CSEMap. If it exists, return it. If
1543 /// not, return the insertion token that will make insertion faster. Performs
1544 /// additional processing for constant nodes.
1545 SDNode *FindNodeOrInsertPos(const FoldingSetNodeID &ID, const SDLoc &DL,
1546 void *&InsertPos);
1547
1548 /// List of non-single value types.
1549 FoldingSet<SDVTListNode> VTListMap;
1550
1551 /// Maps to auto-CSE operations.
1552 std::vector<CondCodeSDNode*> CondCodeNodes;
1553
1554 std::vector<SDNode*> ValueTypeNodes;
1555 std::map<EVT, SDNode*, EVT::compareRawBits> ExtendedValueTypeNodes;
1556 StringMap<SDNode*> ExternalSymbols;
1557
1558 std::map<std::pair<std::string, unsigned char>,SDNode*> TargetExternalSymbols;
1559 DenseMap<MCSymbol *, SDNode *> MCSymbols;
1560};
1561
1562template <> struct GraphTraits<SelectionDAG*> : public GraphTraits<SDNode*> {
1563 using nodes_iterator = pointer_iterator<SelectionDAG::allnodes_iterator>;
1564
1565 static nodes_iterator nodes_begin(SelectionDAG *G) {
1566 return nodes_iterator(G->allnodes_begin());
1567 }
1568
1569 static nodes_iterator nodes_end(SelectionDAG *G) {
1570 return nodes_iterator(G->allnodes_end());
1571 }
1572};
1573
1574template <class TargetMemSDNode>
1575SDValue SelectionDAG::getTargetMemSDNode(SDVTList VTs,
1576 ArrayRef<SDValue> Ops,
1577 const SDLoc &dl, EVT MemVT,
1578 MachineMemOperand *MMO) {
1579 /// Compose node ID and try to find an existing node.
1580 FoldingSetNodeID ID;
1581 unsigned Opcode =
1582 TargetMemSDNode(dl.getIROrder(), DebugLoc(), VTs, MemVT, MMO).getOpcode();
1583 ID.AddInteger(Opcode);
1584 ID.AddPointer(VTs.VTs);
1585 for (auto& Op : Ops) {
1586 ID.AddPointer(Op.getNode());
1587 ID.AddInteger(Op.getResNo());
1588 }
1589 ID.AddInteger(MemVT.getRawBits());
1590 ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
1591 ID.AddInteger(getSyntheticNodeSubclassData<TargetMemSDNode>(
1592 dl.getIROrder(), VTs, MemVT, MMO));
1593
1594 void *IP = nullptr;
1595 if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP)) {
1596 cast<TargetMemSDNode>(E)->refineAlignment(MMO);
1597 return SDValue(E, 0);
1598 }
1599
1600 /// Existing node was not found. Create a new one.
1601 auto *N = newSDNode<TargetMemSDNode>(dl.getIROrder(), dl.getDebugLoc(), VTs,
1602 MemVT, MMO);
1603 createOperands(N, Ops);
1604 CSEMap.InsertNode(N, IP);
1605 InsertNode(N);
1606 return SDValue(N, 0);
1607}
1608
1609} // end namespace llvm
1610
1611#endif // LLVM_CODEGEN_SELECTIONDAG_H

/build/llvm-toolchain-snapshot-7~svn329677/include/llvm/CodeGen/SelectionDAGNodes.h

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