Bug Summary

File:lib/Target/X86/X86SelectionDAGInfo.cpp
Warning:line 1045, column 10
Called C++ object pointer is null

Annotated Source Code

/build/llvm-toolchain-snapshot-6.0~svn318801/lib/Target/X86/X86SelectionDAGInfo.cpp

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

/build/llvm-toolchain-snapshot-6.0~svn318801/include/llvm/CodeGen/SelectionDAG.h

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

/build/llvm-toolchain-snapshot-6.0~svn318801/include/llvm/CodeGen/SelectionDAGNodes.h

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