Bug Summary

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

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name X86SelectionDAGInfo.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-9/lib/clang/9.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-9~svn362543/build-llvm/lib/Target/X86 -I /build/llvm-toolchain-snapshot-9~svn362543/lib/Target/X86 -I /build/llvm-toolchain-snapshot-9~svn362543/build-llvm/include -I /build/llvm-toolchain-snapshot-9~svn362543/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/backward -internal-isystem /usr/include/clang/9.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-9/lib/clang/9.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-9~svn362543/build-llvm/lib/Target/X86 -fdebug-prefix-map=/build/llvm-toolchain-snapshot-9~svn362543=. -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -stack-protector 2 -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2019-06-05-060531-1271-1 -x c++ /build/llvm-toolchain-snapshot-9~svn362543/lib/Target/X86/X86SelectionDAGInfo.cpp -faddrsig

/build/llvm-toolchain-snapshot-9~svn362543/lib/Target/X86/X86SelectionDAGInfo.cpp

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

/build/llvm-toolchain-snapshot-9~svn362543/include/llvm/CodeGen/SelectionDAG.h

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

/build/llvm-toolchain-snapshot-9~svn362543/include/llvm/CodeGen/SelectionDAGNodes.h

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