Bug Summary

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

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name LanaiISelDAGToDAG.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=none -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining -debugger-tuning=gdb -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-11/lib/clang/11.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/build-llvm/lib/Target/Lanai -I /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/Target/Lanai -I /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/build-llvm/include -I /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-11/lib/clang/11.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -std=c++14 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/build-llvm/lib/Target/Lanai -fdebug-prefix-map=/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347=. -ferror-limit 19 -fmessage-length 0 -fvisibility hidden -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -o /tmp/scan-build-2020-03-09-184146-41876-1 -x c++ /build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/Target/Lanai/LanaiISelDAGToDAG.cpp

/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/lib/Target/Lanai/LanaiISelDAGToDAG.cpp

1//===-- LanaiISelDAGToDAG.cpp - A dag to dag inst selector for Lanai ------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines an instruction selector for the Lanai target.
10//
11//===----------------------------------------------------------------------===//
12
13#include "LanaiAluCode.h"
14#include "LanaiMachineFunctionInfo.h"
15#include "LanaiRegisterInfo.h"
16#include "LanaiSubtarget.h"
17#include "LanaiTargetMachine.h"
18#include "llvm/CodeGen/MachineConstantPool.h"
19#include "llvm/CodeGen/MachineFrameInfo.h"
20#include "llvm/CodeGen/MachineFunction.h"
21#include "llvm/CodeGen/MachineInstrBuilder.h"
22#include "llvm/CodeGen/MachineRegisterInfo.h"
23#include "llvm/CodeGen/SelectionDAGISel.h"
24#include "llvm/IR/CFG.h"
25#include "llvm/IR/GlobalValue.h"
26#include "llvm/IR/Instructions.h"
27#include "llvm/IR/Intrinsics.h"
28#include "llvm/IR/Type.h"
29#include "llvm/Support/Debug.h"
30#include "llvm/Support/ErrorHandling.h"
31#include "llvm/Support/raw_ostream.h"
32#include "llvm/Target/TargetMachine.h"
33
34using namespace llvm;
35
36#define DEBUG_TYPE"lanai-isel" "lanai-isel"
37
38//===----------------------------------------------------------------------===//
39// Instruction Selector Implementation
40//===----------------------------------------------------------------------===//
41
42//===----------------------------------------------------------------------===//
43// LanaiDAGToDAGISel - Lanai specific code to select Lanai machine
44// instructions for SelectionDAG operations.
45//===----------------------------------------------------------------------===//
46namespace {
47
48class LanaiDAGToDAGISel : public SelectionDAGISel {
49public:
50 explicit LanaiDAGToDAGISel(LanaiTargetMachine &TargetMachine)
51 : SelectionDAGISel(TargetMachine) {}
52
53 bool runOnMachineFunction(MachineFunction &MF) override {
54 return SelectionDAGISel::runOnMachineFunction(MF);
55 }
56
57 // Pass Name
58 StringRef getPassName() const override {
59 return "Lanai DAG->DAG Pattern Instruction Selection";
60 }
61
62 bool SelectInlineAsmMemoryOperand(const SDValue &Op, unsigned ConstraintCode,
63 std::vector<SDValue> &OutOps) override;
64
65private:
66// Include the pieces autogenerated from the target description.
67#include "LanaiGenDAGISel.inc"
68
69 // Instruction Selection not handled by the auto-generated tablgen
70 void Select(SDNode *N) override;
71
72 // Support functions for the opcodes of Instruction Selection
73 // not handled by the auto-generated tablgen
74 void selectFrameIndex(SDNode *N);
75
76 // Complex Pattern for address selection.
77 bool selectAddrRi(SDValue Addr, SDValue &Base, SDValue &Offset,
78 SDValue &AluOp);
79 bool selectAddrRr(SDValue Addr, SDValue &R1, SDValue &R2, SDValue &AluOp);
80 bool selectAddrSls(SDValue Addr, SDValue &Offset);
81 bool selectAddrSpls(SDValue Addr, SDValue &Base, SDValue &Offset,
82 SDValue &AluOp);
83
84 // getI32Imm - Return a target constant with the specified value, of type i32.
85 inline SDValue getI32Imm(unsigned Imm, const SDLoc &DL) {
86 return CurDAG->getTargetConstant(Imm, DL, MVT::i32);
87 }
88
89private:
90 bool selectAddrRiSpls(SDValue Addr, SDValue &Base, SDValue &Offset,
91 SDValue &AluOp, bool RiMode);
92};
93
94bool canBeRepresentedAsSls(const ConstantSDNode &CN) {
95 // Fits in 21-bit signed immediate and two low-order bits are zero.
96 return isInt<21>(CN.getSExtValue()) && ((CN.getSExtValue() & 0x3) == 0);
97}
98
99} // namespace
100
101// Helper functions for ComplexPattern used on LanaiInstrInfo
102// Used on Lanai Load/Store instructions.
103bool LanaiDAGToDAGISel::selectAddrSls(SDValue Addr, SDValue &Offset) {
104 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Addr)) {
1
Calling 'dyn_cast<llvm::ConstantSDNode, llvm::SDValue>'
16
Returning from 'dyn_cast<llvm::ConstantSDNode, llvm::SDValue>'
17
Assuming 'CN' is null
18
Taking false branch
105 SDLoc DL(Addr);
106 // Loading from a constant address.
107 if (canBeRepresentedAsSls(*CN)) {
108 int32_t Imm = CN->getSExtValue();
109 Offset = CurDAG->getTargetConstant(Imm, DL, CN->getValueType(0));
110 return true;
111 }
112 }
113 if (Addr.getOpcode() == ISD::OR &&
19
Calling 'SDValue::getOpcode'
114 Addr.getOperand(1).getOpcode() == LanaiISD::SMALL) {
115 Offset = Addr.getOperand(1).getOperand(0);
116 return true;
117 }
118 return false;
119}
120
121bool LanaiDAGToDAGISel::selectAddrRiSpls(SDValue Addr, SDValue &Base,
122 SDValue &Offset, SDValue &AluOp,
123 bool RiMode) {
124 SDLoc DL(Addr);
125
126 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Addr)) {
127 if (RiMode) {
128 // Fits in 16-bit signed immediate.
129 if (isInt<16>(CN->getSExtValue())) {
130 int16_t Imm = CN->getSExtValue();
131 Offset = CurDAG->getTargetConstant(Imm, DL, CN->getValueType(0));
132 Base = CurDAG->getRegister(Lanai::R0, CN->getValueType(0));
133 AluOp = CurDAG->getTargetConstant(LPAC::ADD, DL, MVT::i32);
134 return true;
135 }
136 // Allow SLS to match if the constant doesn't fit in 16 bits but can be
137 // represented as an SLS.
138 if (canBeRepresentedAsSls(*CN))
139 return false;
140 } else {
141 // Fits in 10-bit signed immediate.
142 if (isInt<10>(CN->getSExtValue())) {
143 int16_t Imm = CN->getSExtValue();
144 Offset = CurDAG->getTargetConstant(Imm, DL, CN->getValueType(0));
145 Base = CurDAG->getRegister(Lanai::R0, CN->getValueType(0));
146 AluOp = CurDAG->getTargetConstant(LPAC::ADD, DL, MVT::i32);
147 return true;
148 }
149 }
150 }
151
152 // if Address is FI, get the TargetFrameIndex.
153 if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(Addr)) {
154 Base = CurDAG->getTargetFrameIndex(
155 FIN->getIndex(),
156 getTargetLowering()->getPointerTy(CurDAG->getDataLayout()));
157 Offset = CurDAG->getTargetConstant(0, DL, MVT::i32);
158 AluOp = CurDAG->getTargetConstant(LPAC::ADD, DL, MVT::i32);
159 return true;
160 }
161
162 // Skip direct calls
163 if ((Addr.getOpcode() == ISD::TargetExternalSymbol ||
164 Addr.getOpcode() == ISD::TargetGlobalAddress))
165 return false;
166
167 // Address of the form imm + reg
168 ISD::NodeType AluOperator = static_cast<ISD::NodeType>(Addr.getOpcode());
169 if (AluOperator == ISD::ADD) {
170 AluOp = CurDAG->getTargetConstant(LPAC::ADD, DL, MVT::i32);
171 // Addresses of the form FI+const
172 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Addr.getOperand(1)))
173 if ((RiMode && isInt<16>(CN->getSExtValue())) ||
174 (!RiMode && isInt<10>(CN->getSExtValue()))) {
175 // If the first operand is a FI, get the TargetFI Node
176 if (FrameIndexSDNode *FIN =
177 dyn_cast<FrameIndexSDNode>(Addr.getOperand(0))) {
178 Base = CurDAG->getTargetFrameIndex(
179 FIN->getIndex(),
180 getTargetLowering()->getPointerTy(CurDAG->getDataLayout()));
181 } else {
182 Base = Addr.getOperand(0);
183 }
184
185 Offset = CurDAG->getTargetConstant(CN->getSExtValue(), DL, MVT::i32);
186 return true;
187 }
188 }
189
190 // Let SLS match SMALL instead of RI.
191 if (AluOperator == ISD::OR && RiMode &&
192 Addr.getOperand(1).getOpcode() == LanaiISD::SMALL)
193 return false;
194
195 Base = Addr;
196 Offset = CurDAG->getTargetConstant(0, DL, MVT::i32);
197 AluOp = CurDAG->getTargetConstant(LPAC::ADD, DL, MVT::i32);
198 return true;
199}
200
201bool LanaiDAGToDAGISel::selectAddrRi(SDValue Addr, SDValue &Base,
202 SDValue &Offset, SDValue &AluOp) {
203 return selectAddrRiSpls(Addr, Base, Offset, AluOp, /*RiMode=*/true);
204}
205
206bool LanaiDAGToDAGISel::selectAddrSpls(SDValue Addr, SDValue &Base,
207 SDValue &Offset, SDValue &AluOp) {
208 return selectAddrRiSpls(Addr, Base, Offset, AluOp, /*RiMode=*/false);
209}
210
211bool LanaiDAGToDAGISel::selectAddrRr(SDValue Addr, SDValue &R1, SDValue &R2,
212 SDValue &AluOp) {
213 // if Address is FI, get the TargetFrameIndex.
214 if (Addr.getOpcode() == ISD::FrameIndex)
215 return false;
216
217 // Skip direct calls
218 if ((Addr.getOpcode() == ISD::TargetExternalSymbol ||
219 Addr.getOpcode() == ISD::TargetGlobalAddress))
220 return false;
221
222 // Address of the form OP + OP
223 ISD::NodeType AluOperator = static_cast<ISD::NodeType>(Addr.getOpcode());
224 LPAC::AluCode AluCode = LPAC::isdToLanaiAluCode(AluOperator);
225 if (AluCode != LPAC::UNKNOWN) {
226 // Skip addresses of the form FI OP const
227 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Addr.getOperand(1)))
228 if (isInt<16>(CN->getSExtValue()))
229 return false;
230
231 // Skip addresses with hi/lo operands
232 if (Addr.getOperand(0).getOpcode() == LanaiISD::HI ||
233 Addr.getOperand(0).getOpcode() == LanaiISD::LO ||
234 Addr.getOperand(0).getOpcode() == LanaiISD::SMALL ||
235 Addr.getOperand(1).getOpcode() == LanaiISD::HI ||
236 Addr.getOperand(1).getOpcode() == LanaiISD::LO ||
237 Addr.getOperand(1).getOpcode() == LanaiISD::SMALL)
238 return false;
239
240 // Addresses of the form register OP register
241 R1 = Addr.getOperand(0);
242 R2 = Addr.getOperand(1);
243 AluOp = CurDAG->getTargetConstant(AluCode, SDLoc(Addr), MVT::i32);
244 return true;
245 }
246
247 // Skip addresses with zero offset
248 return false;
249}
250
251bool LanaiDAGToDAGISel::SelectInlineAsmMemoryOperand(
252 const SDValue &Op, unsigned ConstraintCode, std::vector<SDValue> &OutOps) {
253 SDValue Op0, Op1, AluOp;
254 switch (ConstraintCode) {
255 default:
256 return true;
257 case InlineAsm::Constraint_m: // memory
258 if (!selectAddrRr(Op, Op0, Op1, AluOp) &&
259 !selectAddrRi(Op, Op0, Op1, AluOp))
260 return true;
261 break;
262 }
263
264 OutOps.push_back(Op0);
265 OutOps.push_back(Op1);
266 OutOps.push_back(AluOp);
267 return false;
268}
269
270// Select instructions not customized! Used for
271// expanded, promoted and normal instructions
272void LanaiDAGToDAGISel::Select(SDNode *Node) {
273 unsigned Opcode = Node->getOpcode();
274
275 // If we have a custom node, we already have selected!
276 if (Node->isMachineOpcode()) {
277 LLVM_DEBUG(errs() << "== "; Node->dump(CurDAG); errs() << "\n")do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("lanai-isel")) { errs() << "== "; Node->dump(CurDAG
); errs() << "\n"; } } while (false)
;
278 return;
279 }
280
281 // Instruction Selection not handled by the auto-generated tablegen selection
282 // should be handled here.
283 EVT VT = Node->getValueType(0);
284 switch (Opcode) {
285 case ISD::Constant:
286 if (VT == MVT::i32) {
287 ConstantSDNode *ConstNode = cast<ConstantSDNode>(Node);
288 // Materialize zero constants as copies from R0. This allows the coalescer
289 // to propagate these into other instructions.
290 if (ConstNode->isNullValue()) {
291 SDValue New = CurDAG->getCopyFromReg(CurDAG->getEntryNode(),
292 SDLoc(Node), Lanai::R0, MVT::i32);
293 return ReplaceNode(Node, New.getNode());
294 }
295 // Materialize all ones constants as copies from R1. This allows the
296 // coalescer to propagate these into other instructions.
297 if (ConstNode->isAllOnesValue()) {
298 SDValue New = CurDAG->getCopyFromReg(CurDAG->getEntryNode(),
299 SDLoc(Node), Lanai::R1, MVT::i32);
300 return ReplaceNode(Node, New.getNode());
301 }
302 }
303 break;
304 case ISD::FrameIndex:
305 selectFrameIndex(Node);
306 return;
307 default:
308 break;
309 }
310
311 // Select the default instruction
312 SelectCode(Node);
313}
314
315void LanaiDAGToDAGISel::selectFrameIndex(SDNode *Node) {
316 SDLoc DL(Node);
317 SDValue Imm = CurDAG->getTargetConstant(0, DL, MVT::i32);
318 int FI = cast<FrameIndexSDNode>(Node)->getIndex();
319 EVT VT = Node->getValueType(0);
320 SDValue TFI = CurDAG->getTargetFrameIndex(FI, VT);
321 unsigned Opc = Lanai::ADD_I_LO;
322 if (Node->hasOneUse()) {
323 CurDAG->SelectNodeTo(Node, Opc, VT, TFI, Imm);
324 return;
325 }
326 ReplaceNode(Node, CurDAG->getMachineNode(Opc, DL, VT, TFI, Imm));
327}
328
329// createLanaiISelDag - This pass converts a legalized DAG into a
330// Lanai-specific DAG, ready for instruction scheduling.
331FunctionPass *llvm::createLanaiISelDag(LanaiTargetMachine &TM) {
332 return new LanaiDAGToDAGISel(TM);
333}

/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/include/llvm/Support/Casting.h

1//===- llvm/Support/Casting.h - Allow flexible, checked, casts --*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the isa<X>(), cast<X>(), dyn_cast<X>(), cast_or_null<X>(),
10// and dyn_cast_or_null<X>() templates.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_SUPPORT_CASTING_H
15#define LLVM_SUPPORT_CASTING_H
16
17#include "llvm/Support/Compiler.h"
18#include "llvm/Support/type_traits.h"
19#include <cassert>
20#include <memory>
21#include <type_traits>
22
23namespace llvm {
24
25//===----------------------------------------------------------------------===//
26// isa<x> Support Templates
27//===----------------------------------------------------------------------===//
28
29// Define a template that can be specialized by smart pointers to reflect the
30// fact that they are automatically dereferenced, and are not involved with the
31// template selection process... the default implementation is a noop.
32//
33template<typename From> struct simplify_type {
34 using SimpleType = From; // The real type this represents...
35
36 // An accessor to get the real value...
37 static SimpleType &getSimplifiedValue(From &Val) { return Val; }
38};
39
40template<typename From> struct simplify_type<const From> {
41 using NonConstSimpleType = typename simplify_type<From>::SimpleType;
42 using SimpleType =
43 typename add_const_past_pointer<NonConstSimpleType>::type;
44 using RetType =
45 typename add_lvalue_reference_if_not_pointer<SimpleType>::type;
46
47 static RetType getSimplifiedValue(const From& Val) {
48 return simplify_type<From>::getSimplifiedValue(const_cast<From&>(Val));
49 }
50};
51
52// The core of the implementation of isa<X> is here; To and From should be
53// the names of classes. This template can be specialized to customize the
54// implementation of isa<> without rewriting it from scratch.
55template <typename To, typename From, typename Enabler = void>
56struct isa_impl {
57 static inline bool doit(const From &Val) {
58 return To::classof(&Val);
59 }
60};
61
62/// Always allow upcasts, and perform no dynamic check for them.
63template <typename To, typename From>
64struct isa_impl<To, From, std::enable_if_t<std::is_base_of<To, From>::value>> {
65 static inline bool doit(const From &) { return true; }
66};
67
68template <typename To, typename From> struct isa_impl_cl {
69 static inline bool doit(const From &Val) {
70 return isa_impl<To, From>::doit(Val);
71 }
72};
73
74template <typename To, typename From> struct isa_impl_cl<To, const From> {
75 static inline bool doit(const From &Val) {
76 return isa_impl<To, From>::doit(Val);
77 }
78};
79
80template <typename To, typename From>
81struct isa_impl_cl<To, const std::unique_ptr<From>> {
82 static inline bool doit(const std::unique_ptr<From> &Val) {
83 assert(Val && "isa<> used on a null pointer")((Val && "isa<> used on a null pointer") ? static_cast
<void> (0) : __assert_fail ("Val && \"isa<> used on a null pointer\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/include/llvm/Support/Casting.h"
, 83, __PRETTY_FUNCTION__))
;
84 return isa_impl_cl<To, From>::doit(*Val);
85 }
86};
87
88template <typename To, typename From> struct isa_impl_cl<To, From*> {
89 static inline bool doit(const From *Val) {
90 assert(Val && "isa<> used on a null pointer")((Val && "isa<> used on a null pointer") ? static_cast
<void> (0) : __assert_fail ("Val && \"isa<> used on a null pointer\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/include/llvm/Support/Casting.h"
, 90, __PRETTY_FUNCTION__))
;
91 return isa_impl<To, From>::doit(*Val);
92 }
93};
94
95template <typename To, typename From> struct isa_impl_cl<To, From*const> {
96 static inline bool doit(const From *Val) {
97 assert(Val && "isa<> used on a null pointer")((Val && "isa<> used on a null pointer") ? static_cast
<void> (0) : __assert_fail ("Val && \"isa<> used on a null pointer\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/include/llvm/Support/Casting.h"
, 97, __PRETTY_FUNCTION__))
;
98 return isa_impl<To, From>::doit(*Val);
99 }
100};
101
102template <typename To, typename From> struct isa_impl_cl<To, const From*> {
103 static inline bool doit(const From *Val) {
104 assert(Val && "isa<> used on a null pointer")((Val && "isa<> used on a null pointer") ? static_cast
<void> (0) : __assert_fail ("Val && \"isa<> used on a null pointer\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/include/llvm/Support/Casting.h"
, 104, __PRETTY_FUNCTION__))
;
105 return isa_impl<To, From>::doit(*Val);
106 }
107};
108
109template <typename To, typename From> struct isa_impl_cl<To, const From*const> {
110 static inline bool doit(const From *Val) {
111 assert(Val && "isa<> used on a null pointer")((Val && "isa<> used on a null pointer") ? static_cast
<void> (0) : __assert_fail ("Val && \"isa<> used on a null pointer\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/include/llvm/Support/Casting.h"
, 111, __PRETTY_FUNCTION__))
;
112 return isa_impl<To, From>::doit(*Val);
113 }
114};
115
116template<typename To, typename From, typename SimpleFrom>
117struct isa_impl_wrap {
118 // When From != SimplifiedType, we can simplify the type some more by using
119 // the simplify_type template.
120 static bool doit(const From &Val) {
121 return isa_impl_wrap<To, SimpleFrom,
122 typename simplify_type<SimpleFrom>::SimpleType>::doit(
123 simplify_type<const From>::getSimplifiedValue(Val));
124 }
125};
126
127template<typename To, typename FromTy>
128struct isa_impl_wrap<To, FromTy, FromTy> {
129 // When From == SimpleType, we are as simple as we are going to get.
130 static bool doit(const FromTy &Val) {
131 return isa_impl_cl<To,FromTy>::doit(Val);
132 }
133};
134
135// isa<X> - Return true if the parameter to the template is an instance of the
136// template type argument. Used like this:
137//
138// if (isa<Type>(myVal)) { ... }
139//
140template <class X, class Y> LLVM_NODISCARD[[clang::warn_unused_result]] inline bool isa(const Y &Val) {
141 return isa_impl_wrap<X, const Y,
142 typename simplify_type<const Y>::SimpleType>::doit(Val);
143}
144
145// isa_and_nonnull<X> - Functionally identical to isa, except that a null value
146// is accepted.
147//
148template <class X, class Y>
149LLVM_NODISCARD[[clang::warn_unused_result]] inline bool isa_and_nonnull(const Y &Val) {
150 if (!Val)
151 return false;
152 return isa<X>(Val);
153}
154
155//===----------------------------------------------------------------------===//
156// cast<x> Support Templates
157//===----------------------------------------------------------------------===//
158
159template<class To, class From> struct cast_retty;
160
161// Calculate what type the 'cast' function should return, based on a requested
162// type of To and a source type of From.
163template<class To, class From> struct cast_retty_impl {
164 using ret_type = To &; // Normal case, return Ty&
165};
166template<class To, class From> struct cast_retty_impl<To, const From> {
167 using ret_type = const To &; // Normal case, return Ty&
168};
169
170template<class To, class From> struct cast_retty_impl<To, From*> {
171 using ret_type = To *; // Pointer arg case, return Ty*
172};
173
174template<class To, class From> struct cast_retty_impl<To, const From*> {
175 using ret_type = const To *; // Constant pointer arg case, return const Ty*
176};
177
178template<class To, class From> struct cast_retty_impl<To, const From*const> {
179 using ret_type = const To *; // Constant pointer arg case, return const Ty*
180};
181
182template <class To, class From>
183struct cast_retty_impl<To, std::unique_ptr<From>> {
184private:
185 using PointerType = typename cast_retty_impl<To, From *>::ret_type;
186 using ResultType = std::remove_pointer_t<PointerType>;
187
188public:
189 using ret_type = std::unique_ptr<ResultType>;
190};
191
192template<class To, class From, class SimpleFrom>
193struct cast_retty_wrap {
194 // When the simplified type and the from type are not the same, use the type
195 // simplifier to reduce the type, then reuse cast_retty_impl to get the
196 // resultant type.
197 using ret_type = typename cast_retty<To, SimpleFrom>::ret_type;
198};
199
200template<class To, class FromTy>
201struct cast_retty_wrap<To, FromTy, FromTy> {
202 // When the simplified type is equal to the from type, use it directly.
203 using ret_type = typename cast_retty_impl<To,FromTy>::ret_type;
204};
205
206template<class To, class From>
207struct cast_retty {
208 using ret_type = typename cast_retty_wrap<
209 To, From, typename simplify_type<From>::SimpleType>::ret_type;
210};
211
212// Ensure the non-simple values are converted using the simplify_type template
213// that may be specialized by smart pointers...
214//
215template<class To, class From, class SimpleFrom> struct cast_convert_val {
216 // This is not a simple type, use the template to simplify it...
217 static typename cast_retty<To, From>::ret_type doit(From &Val) {
218 return cast_convert_val<To, SimpleFrom,
11
Returning without writing to 'Val.Node'
219 typename simplify_type<SimpleFrom>::SimpleType>::doit(
220 simplify_type<From>::getSimplifiedValue(Val));
8
Calling 'simplify_type::getSimplifiedValue'
10
Returning from 'simplify_type::getSimplifiedValue'
221 }
222};
223
224template<class To, class FromTy> struct cast_convert_val<To,FromTy,FromTy> {
225 // This _is_ a simple type, just cast it.
226 static typename cast_retty<To, FromTy>::ret_type doit(const FromTy &Val) {
227 typename cast_retty<To, FromTy>::ret_type Res2
228 = (typename cast_retty<To, FromTy>::ret_type)const_cast<FromTy&>(Val);
229 return Res2;
230 }
231};
232
233template <class X> struct is_simple_type {
234 static const bool value =
235 std::is_same<X, typename simplify_type<X>::SimpleType>::value;
236};
237
238// cast<X> - Return the argument parameter cast to the specified type. This
239// casting operator asserts that the type is correct, so it does not return null
240// on failure. It does not allow a null argument (use cast_or_null for that).
241// It is typically used like this:
242//
243// cast<Instruction>(myVal)->getParent()
244//
245template <class X, class Y>
246inline std::enable_if_t<!is_simple_type<Y>::value,
247 typename cast_retty<X, const Y>::ret_type>
248cast(const Y &Val) {
249 assert(isa<X>(Val) && "cast<Ty>() argument of incompatible type!")((isa<X>(Val) && "cast<Ty>() argument of incompatible type!"
) ? static_cast<void> (0) : __assert_fail ("isa<X>(Val) && \"cast<Ty>() argument of incompatible type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/include/llvm/Support/Casting.h"
, 249, __PRETTY_FUNCTION__))
;
250 return cast_convert_val<
251 X, const Y, typename simplify_type<const Y>::SimpleType>::doit(Val);
252}
253
254template <class X, class Y>
255inline typename cast_retty<X, Y>::ret_type cast(Y &Val) {
256 assert(isa<X>(Val) && "cast<Ty>() argument of incompatible type!")((isa<X>(Val) && "cast<Ty>() argument of incompatible type!"
) ? static_cast<void> (0) : __assert_fail ("isa<X>(Val) && \"cast<Ty>() argument of incompatible type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/include/llvm/Support/Casting.h"
, 256, __PRETTY_FUNCTION__))
;
5
'Val' is a 'ConstantSDNode'
6
'?' condition is true
257 return cast_convert_val<X, Y,
7
Calling 'cast_convert_val::doit'
12
Returning from 'cast_convert_val::doit'
13
Returning without writing to 'Val.Node'
258 typename simplify_type<Y>::SimpleType>::doit(Val);
259}
260
261template <class X, class Y>
262inline typename cast_retty<X, Y *>::ret_type cast(Y *Val) {
263 assert(isa<X>(Val) && "cast<Ty>() argument of incompatible type!")((isa<X>(Val) && "cast<Ty>() argument of incompatible type!"
) ? static_cast<void> (0) : __assert_fail ("isa<X>(Val) && \"cast<Ty>() argument of incompatible type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/include/llvm/Support/Casting.h"
, 263, __PRETTY_FUNCTION__))
;
264 return cast_convert_val<X, Y*,
265 typename simplify_type<Y*>::SimpleType>::doit(Val);
266}
267
268template <class X, class Y>
269inline typename cast_retty<X, std::unique_ptr<Y>>::ret_type
270cast(std::unique_ptr<Y> &&Val) {
271 assert(isa<X>(Val.get()) && "cast<Ty>() argument of incompatible type!")((isa<X>(Val.get()) && "cast<Ty>() argument of incompatible type!"
) ? static_cast<void> (0) : __assert_fail ("isa<X>(Val.get()) && \"cast<Ty>() argument of incompatible type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/include/llvm/Support/Casting.h"
, 271, __PRETTY_FUNCTION__))
;
272 using ret_type = typename cast_retty<X, std::unique_ptr<Y>>::ret_type;
273 return ret_type(
274 cast_convert_val<X, Y *, typename simplify_type<Y *>::SimpleType>::doit(
275 Val.release()));
276}
277
278// cast_or_null<X> - Functionally identical to cast, except that a null value is
279// accepted.
280//
281template <class X, class Y>
282LLVM_NODISCARD[[clang::warn_unused_result]] inline std::enable_if_t<
283 !is_simple_type<Y>::value, typename cast_retty<X, const Y>::ret_type>
284cast_or_null(const Y &Val) {
285 if (!Val)
286 return nullptr;
287 assert(isa<X>(Val) && "cast_or_null<Ty>() argument of incompatible type!")((isa<X>(Val) && "cast_or_null<Ty>() argument of incompatible type!"
) ? static_cast<void> (0) : __assert_fail ("isa<X>(Val) && \"cast_or_null<Ty>() argument of incompatible type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/include/llvm/Support/Casting.h"
, 287, __PRETTY_FUNCTION__))
;
288 return cast<X>(Val);
289}
290
291template <class X, class Y>
292LLVM_NODISCARD[[clang::warn_unused_result]] inline std::enable_if_t<!is_simple_type<Y>::value,
293 typename cast_retty<X, Y>::ret_type>
294cast_or_null(Y &Val) {
295 if (!Val)
296 return nullptr;
297 assert(isa<X>(Val) && "cast_or_null<Ty>() argument of incompatible type!")((isa<X>(Val) && "cast_or_null<Ty>() argument of incompatible type!"
) ? static_cast<void> (0) : __assert_fail ("isa<X>(Val) && \"cast_or_null<Ty>() argument of incompatible type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/include/llvm/Support/Casting.h"
, 297, __PRETTY_FUNCTION__))
;
298 return cast<X>(Val);
299}
300
301template <class X, class Y>
302LLVM_NODISCARD[[clang::warn_unused_result]] inline typename cast_retty<X, Y *>::ret_type
303cast_or_null(Y *Val) {
304 if (!Val) return nullptr;
305 assert(isa<X>(Val) && "cast_or_null<Ty>() argument of incompatible type!")((isa<X>(Val) && "cast_or_null<Ty>() argument of incompatible type!"
) ? static_cast<void> (0) : __assert_fail ("isa<X>(Val) && \"cast_or_null<Ty>() argument of incompatible type!\""
, "/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/include/llvm/Support/Casting.h"
, 305, __PRETTY_FUNCTION__))
;
306 return cast<X>(Val);
307}
308
309template <class X, class Y>
310inline typename cast_retty<X, std::unique_ptr<Y>>::ret_type
311cast_or_null(std::unique_ptr<Y> &&Val) {
312 if (!Val)
313 return nullptr;
314 return cast<X>(std::move(Val));
315}
316
317// dyn_cast<X> - Return the argument parameter cast to the specified type. This
318// casting operator returns null if the argument is of the wrong type, so it can
319// be used to test for a type as well as cast if successful. This should be
320// used in the context of an if statement like this:
321//
322// if (const Instruction *I = dyn_cast<Instruction>(myVal)) { ... }
323//
324
325template <class X, class Y>
326LLVM_NODISCARD[[clang::warn_unused_result]] inline std::enable_if_t<
327 !is_simple_type<Y>::value, typename cast_retty<X, const Y>::ret_type>
328dyn_cast(const Y &Val) {
329 return isa<X>(Val) ? cast<X>(Val) : nullptr;
330}
331
332template <class X, class Y>
333LLVM_NODISCARD[[clang::warn_unused_result]] inline typename cast_retty<X, Y>::ret_type dyn_cast(Y &Val) {
334 return isa<X>(Val) ? cast<X>(Val) : nullptr;
2
Assuming 'Val' is a 'ConstantSDNode'
3
'?' condition is true
4
Calling 'cast<llvm::ConstantSDNode, llvm::SDValue>'
14
Returning from 'cast<llvm::ConstantSDNode, llvm::SDValue>'
15
Returning without writing to 'Val.Node'
335}
336
337template <class X, class Y>
338LLVM_NODISCARD[[clang::warn_unused_result]] inline typename cast_retty<X, Y *>::ret_type dyn_cast(Y *Val) {
339 return isa<X>(Val) ? cast<X>(Val) : nullptr;
340}
341
342// dyn_cast_or_null<X> - Functionally identical to dyn_cast, except that a null
343// value is accepted.
344//
345template <class X, class Y>
346LLVM_NODISCARD[[clang::warn_unused_result]] inline std::enable_if_t<
347 !is_simple_type<Y>::value, typename cast_retty<X, const Y>::ret_type>
348dyn_cast_or_null(const Y &Val) {
349 return (Val && isa<X>(Val)) ? cast<X>(Val) : nullptr;
350}
351
352template <class X, class Y>
353LLVM_NODISCARD[[clang::warn_unused_result]] inline std::enable_if_t<!is_simple_type<Y>::value,
354 typename cast_retty<X, Y>::ret_type>
355dyn_cast_or_null(Y &Val) {
356 return (Val && isa<X>(Val)) ? cast<X>(Val) : nullptr;
357}
358
359template <class X, class Y>
360LLVM_NODISCARD[[clang::warn_unused_result]] inline typename cast_retty<X, Y *>::ret_type
361dyn_cast_or_null(Y *Val) {
362 return (Val && isa<X>(Val)) ? cast<X>(Val) : nullptr;
363}
364
365// unique_dyn_cast<X> - Given a unique_ptr<Y>, try to return a unique_ptr<X>,
366// taking ownership of the input pointer iff isa<X>(Val) is true. If the
367// cast is successful, From refers to nullptr on exit and the casted value
368// is returned. If the cast is unsuccessful, the function returns nullptr
369// and From is unchanged.
370template <class X, class Y>
371LLVM_NODISCARD[[clang::warn_unused_result]] inline auto unique_dyn_cast(std::unique_ptr<Y> &Val)
372 -> decltype(cast<X>(Val)) {
373 if (!isa<X>(Val))
374 return nullptr;
375 return cast<X>(std::move(Val));
376}
377
378template <class X, class Y>
379LLVM_NODISCARD[[clang::warn_unused_result]] inline auto unique_dyn_cast(std::unique_ptr<Y> &&Val) {
380 return unique_dyn_cast<X, Y>(Val);
381}
382
383// dyn_cast_or_null<X> - Functionally identical to unique_dyn_cast, except that
384// a null value is accepted.
385template <class X, class Y>
386LLVM_NODISCARD[[clang::warn_unused_result]] inline auto unique_dyn_cast_or_null(std::unique_ptr<Y> &Val)
387 -> decltype(cast<X>(Val)) {
388 if (!Val)
389 return nullptr;
390 return unique_dyn_cast<X, Y>(Val);
391}
392
393template <class X, class Y>
394LLVM_NODISCARD[[clang::warn_unused_result]] inline auto unique_dyn_cast_or_null(std::unique_ptr<Y> &&Val) {
395 return unique_dyn_cast_or_null<X, Y>(Val);
396}
397
398} // end namespace llvm
399
400#endif // LLVM_SUPPORT_CASTING_H

/build/llvm-toolchain-snapshot-11~++20200309111110+2c36c23f347/llvm/include/llvm/CodeGen/SelectionDAGNodes.h

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