Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
SelectionDAG.cpp
Go to the documentation of this file.
1//===- SelectionDAG.cpp - Implement the SelectionDAG data structures ------===//
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 implements the SelectionDAG class.
10//
11//===----------------------------------------------------------------------===//
12
13#include "llvm/CodeGen/SelectionDAG.h"
14#include "SDNodeDbgValue.h"
15#include "llvm/ADT/APFloat.h"
16#include "llvm/ADT/APInt.h"
17#include "llvm/ADT/APSInt.h"
18#include "llvm/ADT/ArrayRef.h"
19#include "llvm/ADT/BitVector.h"
20#include "llvm/ADT/DenseSet.h"
21#include "llvm/ADT/FoldingSet.h"
22#include "llvm/ADT/STLExtras.h"
23#include "llvm/ADT/SmallPtrSet.h"
24#include "llvm/ADT/SmallVector.h"
25#include "llvm/ADT/Twine.h"
26#include "llvm/Analysis/AliasAnalysis.h"
27#include "llvm/Analysis/MemoryLocation.h"
28#include "llvm/Analysis/TargetLibraryInfo.h"
29#include "llvm/Analysis/ValueTracking.h"
30#include "llvm/Analysis/VectorUtils.h"
31#include "llvm/BinaryFormat/Dwarf.h"
32#include "llvm/CodeGen/Analysis.h"
33#include "llvm/CodeGen/FunctionLoweringInfo.h"
34#include "llvm/CodeGen/ISDOpcodes.h"
35#include "llvm/CodeGen/MachineBasicBlock.h"
36#include "llvm/CodeGen/MachineConstantPool.h"
37#include "llvm/CodeGen/MachineFrameInfo.h"
38#include "llvm/CodeGen/MachineFunction.h"
39#include "llvm/CodeGen/MachineMemOperand.h"
40#include "llvm/CodeGen/RuntimeLibcallUtil.h"
41#include "llvm/CodeGen/SDPatternMatch.h"
42#include "llvm/CodeGen/SelectionDAGAddressAnalysis.h"
43#include "llvm/CodeGen/SelectionDAGNodes.h"
44#include "llvm/CodeGen/SelectionDAGTargetInfo.h"
45#include "llvm/CodeGen/TargetFrameLowering.h"
46#include "llvm/CodeGen/TargetLowering.h"
47#include "llvm/CodeGen/TargetRegisterInfo.h"
48#include "llvm/CodeGen/TargetSubtargetInfo.h"
49#include "llvm/CodeGen/ValueTypes.h"
50#include "llvm/CodeGenTypes/MachineValueType.h"
51#include "llvm/IR/Constant.h"
52#include "llvm/IR/Constants.h"
53#include "llvm/IR/DataLayout.h"
54#include "llvm/IR/DebugInfoMetadata.h"
55#include "llvm/IR/DebugLoc.h"
56#include "llvm/IR/DerivedTypes.h"
57#include "llvm/IR/Function.h"
58#include "llvm/IR/GlobalValue.h"
59#include "llvm/IR/Metadata.h"
60#include "llvm/IR/Type.h"
61#include "llvm/Support/Casting.h"
62#include "llvm/Support/CodeGen.h"
63#include "llvm/Support/Compiler.h"
64#include "llvm/Support/Debug.h"
65#include "llvm/Support/ErrorHandling.h"
66#include "llvm/Support/KnownBits.h"
67#include "llvm/Support/MathExtras.h"
68#include "llvm/Support/Mutex.h"
69#include "llvm/Support/raw_ostream.h"
70#include "llvm/Target/TargetMachine.h"
71#include "llvm/Target/TargetOptions.h"
72#include "llvm/TargetParser/Triple.h"
73#include "llvm/Transforms/Utils/SizeOpts.h"
74#include <algorithm>
75#include <cassert>
76#include <cstdint>
77#include <cstdlib>
78#include <deque>
79#include <limits>
80#include <optional>
81#include <set>
82#include <string>
83#include <utility>
84#include <vector>
85
86using namespacellvm;
87using namespacellvm::SDPatternMatch;
88
89/// makeVTList - Return an instance of the SDVTList struct initialized with the
90/// specified members.
91staticSDVTListmakeVTList(constEVT *VTs,unsigned NumVTs) {
92SDVTList Res = {VTs, NumVTs};
93return Res;
94}
95
96// Default null implementations of the callbacks.
97voidSelectionDAG::DAGUpdateListener::NodeDeleted(SDNode*,SDNode*) {}
98voidSelectionDAG::DAGUpdateListener::NodeUpdated(SDNode*) {}
99voidSelectionDAG::DAGUpdateListener::NodeInserted(SDNode *) {}
100
101void SelectionDAG::DAGNodeDeletedListener::anchor() {}
102void SelectionDAG::DAGNodeInsertedListener::anchor() {}
103
104#define DEBUG_TYPE "selectiondag"
105
106staticcl::opt<bool>EnableMemCpyDAGOpt("enable-memcpy-dag-opt",
107cl::Hidden,cl::init(true),
108cl::desc("Gang up loads and stores generated by inlining of memcpy"));
109
110staticcl::opt<int>MaxLdStGlue("ldstmemcpy-glue-max",
111cl::desc("Number limit for gluing ld/st of memcpy."),
112cl::Hidden,cl::init(0));
113
114staticcl::opt<unsigned>
115MaxSteps("has-predecessor-max-steps",cl::Hidden,cl::init(8192),
116cl::desc("DAG combiner limit number of steps when searching DAG "
117"for predecessor nodes"));
118
119staticvoidNewSDValueDbgMsg(SDValue V,StringRef Msg,SelectionDAG *G) {
120LLVM_DEBUG(dbgs() << Msg; V.getNode()->dump(G););
121}
122
123unsignedSelectionDAG::getHasPredecessorMaxSteps() {returnMaxSteps; }
124
125//===----------------------------------------------------------------------===//
126// ConstantFPSDNode Class
127//===----------------------------------------------------------------------===//
128
129/// isExactlyValue - We don't rely on operator== working on double values, as
130/// it returns true for things that are clearly not equal, like -0.0 and 0.0.
131/// As such, this method can be used to do an exact bit-for-bit comparison of
132/// two floating point values.
133boolConstantFPSDNode::isExactlyValue(constAPFloat& V) const{
134return getValueAPF().bitwiseIsEqual(V);
135}
136
137boolConstantFPSDNode::isValueValidForType(EVT VT,
138constAPFloat& Val) {
139assert(VT.isFloatingPoint() &&"Can only convert between FP types");
140
141// convert modifies in place, so make a copy.
142APFloat Val2 =APFloat(Val);
143bool losesInfo;
144 (void)Val2.convert(VT.getFltSemantics(),APFloat::rmNearestTiesToEven,
145 &losesInfo);
146return !losesInfo;
147}
148
149//===----------------------------------------------------------------------===//
150// ISD Namespace
151//===----------------------------------------------------------------------===//
152
153boolISD::isConstantSplatVector(constSDNode *N,APInt &SplatVal) {
154if (N->getOpcode() ==ISD::SPLAT_VECTOR) {
155unsigned EltSize =
156N->getValueType(0).getVectorElementType().getSizeInBits();
157if (auto *Op0 = dyn_cast<ConstantSDNode>(N->getOperand(0))) {
158 SplatVal = Op0->getAPIntValue().trunc(EltSize);
159returntrue;
160 }
161if (auto *Op0 = dyn_cast<ConstantFPSDNode>(N->getOperand(0))) {
162 SplatVal = Op0->getValueAPF().bitcastToAPInt().trunc(EltSize);
163returntrue;
164 }
165 }
166
167auto *BV = dyn_cast<BuildVectorSDNode>(N);
168if (!BV)
169returnfalse;
170
171APInt SplatUndef;
172unsigned SplatBitSize;
173bool HasUndefs;
174unsigned EltSize =N->getValueType(0).getVectorElementType().getSizeInBits();
175// Endianness does not matter here. We are checking for a splat given the
176// element size of the vector, and if we find such a splat for little endian
177// layout, then that should be valid also for big endian (as the full vector
178// size is known to be a multiple of the element size).
179constbool IsBigEndian =false;
180return BV->isConstantSplat(SplatVal, SplatUndef, SplatBitSize, HasUndefs,
181 EltSize, IsBigEndian) &&
182 EltSize == SplatBitSize;
183}
184
185// FIXME: AllOnes and AllZeros duplicate a lot of code. Could these be
186// specializations of the more general isConstantSplatVector()?
187
188boolISD::isConstantSplatVectorAllOnes(constSDNode *N,bool BuildVectorOnly) {
189// Look through a bit convert.
190while (N->getOpcode() ==ISD::BITCAST)
191N =N->getOperand(0).getNode();
192
193if (!BuildVectorOnly &&N->getOpcode() ==ISD::SPLAT_VECTOR) {
194APInt SplatVal;
195returnisConstantSplatVector(N, SplatVal) && SplatVal.isAllOnes();
196 }
197
198if (N->getOpcode() !=ISD::BUILD_VECTOR)returnfalse;
199
200unsigned i = 0, e =N->getNumOperands();
201
202// Skip over all of the undef values.
203while (i != e &&N->getOperand(i).isUndef())
204 ++i;
205
206// Do not accept an all-undef vector.
207if (i == e)returnfalse;
208
209// Do not accept build_vectors that aren't all constants or which have non-~0
210// elements. We have to be a bit careful here, as the type of the constant
211// may not be the same as the type of the vector elements due to type
212// legalization (the elements are promoted to a legal type for the target and
213// a vector of a type may be legal when the base element type is not).
214// We only want to check enough bits to cover the vector elements, because
215// we care if the resultant vector is all ones, not whether the individual
216// constants are.
217SDValue NotZero =N->getOperand(i);
218unsigned EltSize =N->getValueType(0).getScalarSizeInBits();
219if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(NotZero)) {
220if (CN->getAPIntValue().countr_one() < EltSize)
221returnfalse;
222 }elseif (ConstantFPSDNode *CFPN = dyn_cast<ConstantFPSDNode>(NotZero)) {
223if (CFPN->getValueAPF().bitcastToAPInt().countr_one() < EltSize)
224returnfalse;
225 }else
226returnfalse;
227
228// Okay, we have at least one ~0 value, check to see if the rest match or are
229// undefs. Even with the above element type twiddling, this should be OK, as
230// the same type legalization should have applied to all the elements.
231for (++i; i != e; ++i)
232if (N->getOperand(i) != NotZero && !N->getOperand(i).isUndef())
233returnfalse;
234returntrue;
235}
236
237boolISD::isConstantSplatVectorAllZeros(constSDNode *N,bool BuildVectorOnly) {
238// Look through a bit convert.
239while (N->getOpcode() ==ISD::BITCAST)
240N =N->getOperand(0).getNode();
241
242if (!BuildVectorOnly &&N->getOpcode() ==ISD::SPLAT_VECTOR) {
243APInt SplatVal;
244returnisConstantSplatVector(N, SplatVal) && SplatVal.isZero();
245 }
246
247if (N->getOpcode() !=ISD::BUILD_VECTOR)returnfalse;
248
249bool IsAllUndef =true;
250for (constSDValue &Op :N->op_values()) {
251if (Op.isUndef())
252continue;
253 IsAllUndef =false;
254// Do not accept build_vectors that aren't all constants or which have non-0
255// elements. We have to be a bit careful here, as the type of the constant
256// may not be the same as the type of the vector elements due to type
257// legalization (the elements are promoted to a legal type for the target
258// and a vector of a type may be legal when the base element type is not).
259// We only want to check enough bits to cover the vector elements, because
260// we care if the resultant vector is all zeros, not whether the individual
261// constants are.
262unsigned EltSize =N->getValueType(0).getScalarSizeInBits();
263if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Op)) {
264if (CN->getAPIntValue().countr_zero() < EltSize)
265returnfalse;
266 }elseif (ConstantFPSDNode *CFPN = dyn_cast<ConstantFPSDNode>(Op)) {
267if (CFPN->getValueAPF().bitcastToAPInt().countr_zero() < EltSize)
268returnfalse;
269 }else
270returnfalse;
271 }
272
273// Do not accept an all-undef vector.
274if (IsAllUndef)
275returnfalse;
276returntrue;
277}
278
279boolISD::isBuildVectorAllOnes(constSDNode *N) {
280returnisConstantSplatVectorAllOnes(N,/*BuildVectorOnly*/true);
281}
282
283boolISD::isBuildVectorAllZeros(constSDNode *N) {
284returnisConstantSplatVectorAllZeros(N,/*BuildVectorOnly*/true);
285}
286
287boolISD::isBuildVectorOfConstantSDNodes(constSDNode *N) {
288if (N->getOpcode() !=ISD::BUILD_VECTOR)
289returnfalse;
290
291for (constSDValue &Op :N->op_values()) {
292if (Op.isUndef())
293continue;
294if (!isa<ConstantSDNode>(Op))
295returnfalse;
296 }
297returntrue;
298}
299
300boolISD::isBuildVectorOfConstantFPSDNodes(constSDNode *N) {
301if (N->getOpcode() !=ISD::BUILD_VECTOR)
302returnfalse;
303
304for (constSDValue &Op :N->op_values()) {
305if (Op.isUndef())
306continue;
307if (!isa<ConstantFPSDNode>(Op))
308returnfalse;
309 }
310returntrue;
311}
312
313boolISD::isVectorShrinkable(constSDNode *N,unsigned NewEltSize,
314boolSigned) {
315assert(N->getValueType(0).isVector() &&"Expected a vector!");
316
317unsigned EltSize =N->getValueType(0).getScalarSizeInBits();
318if (EltSize <= NewEltSize)
319returnfalse;
320
321if (N->getOpcode() ==ISD::ZERO_EXTEND) {
322return (N->getOperand(0).getValueType().getScalarSizeInBits() <=
323 NewEltSize) &&
324 !Signed;
325 }
326if (N->getOpcode() ==ISD::SIGN_EXTEND) {
327return (N->getOperand(0).getValueType().getScalarSizeInBits() <=
328 NewEltSize) &&
329Signed;
330 }
331if (N->getOpcode() !=ISD::BUILD_VECTOR)
332returnfalse;
333
334for (constSDValue &Op :N->op_values()) {
335if (Op.isUndef())
336continue;
337if (!isa<ConstantSDNode>(Op))
338returnfalse;
339
340APIntC =Op->getAsAPIntVal().trunc(EltSize);
341if (Signed &&C.trunc(NewEltSize).sext(EltSize) !=C)
342returnfalse;
343if (!Signed &&C.trunc(NewEltSize).zext(EltSize) !=C)
344returnfalse;
345 }
346
347returntrue;
348}
349
350boolISD::allOperandsUndef(constSDNode *N) {
351// Return false if the node has no operands.
352// This is "logically inconsistent" with the definition of "all" but
353// is probably the desired behavior.
354if (N->getNumOperands() == 0)
355returnfalse;
356returnall_of(N->op_values(), [](SDValueOp) { return Op.isUndef(); });
357}
358
359boolISD::isFreezeUndef(constSDNode *N) {
360returnN->getOpcode() ==ISD::FREEZE &&N->getOperand(0).isUndef();
361}
362
363template <typename ConstNodeType>
364boolISD::matchUnaryPredicateImpl(SDValueOp,
365 std::function<bool(ConstNodeType *)>Match,
366bool AllowUndefs) {
367// FIXME: Add support for scalar UNDEF cases?
368if (auto *C = dyn_cast<ConstNodeType>(Op))
369returnMatch(C);
370
371// FIXME: Add support for vector UNDEF cases?
372if (ISD::BUILD_VECTOR !=Op.getOpcode() &&
373ISD::SPLAT_VECTOR !=Op.getOpcode())
374returnfalse;
375
376EVT SVT =Op.getValueType().getScalarType();
377for (unsigned i = 0, e =Op.getNumOperands(); i != e; ++i) {
378if (AllowUndefs &&Op.getOperand(i).isUndef()) {
379if (!Match(nullptr))
380returnfalse;
381continue;
382 }
383
384auto *Cst = dyn_cast<ConstNodeType>(Op.getOperand(i));
385if (!Cst || Cst->getValueType(0) != SVT || !Match(Cst))
386returnfalse;
387 }
388returntrue;
389}
390// Build used template types.
391templatebool ISD::matchUnaryPredicateImpl<ConstantSDNode>(
392SDValue, std::function<bool(ConstantSDNode *)>,bool);
393templatebool ISD::matchUnaryPredicateImpl<ConstantFPSDNode>(
394SDValue, std::function<bool(ConstantFPSDNode *)>,bool);
395
396boolISD::matchBinaryPredicate(
397SDValue LHS,SDValue RHS,
398 std::function<bool(ConstantSDNode *,ConstantSDNode *)>Match,
399bool AllowUndefs,bool AllowTypeMismatch) {
400if (!AllowTypeMismatch &&LHS.getValueType() !=RHS.getValueType())
401returnfalse;
402
403// TODO: Add support for scalar UNDEF cases?
404if (auto *LHSCst = dyn_cast<ConstantSDNode>(LHS))
405if (auto *RHSCst = dyn_cast<ConstantSDNode>(RHS))
406returnMatch(LHSCst, RHSCst);
407
408// TODO: Add support for vector UNDEF cases?
409if (LHS.getOpcode() !=RHS.getOpcode() ||
410 (LHS.getOpcode() !=ISD::BUILD_VECTOR &&
411LHS.getOpcode() !=ISD::SPLAT_VECTOR))
412returnfalse;
413
414EVT SVT =LHS.getValueType().getScalarType();
415for (unsigned i = 0, e =LHS.getNumOperands(); i != e; ++i) {
416SDValue LHSOp =LHS.getOperand(i);
417SDValue RHSOp =RHS.getOperand(i);
418bool LHSUndef = AllowUndefs && LHSOp.isUndef();
419bool RHSUndef = AllowUndefs && RHSOp.isUndef();
420auto *LHSCst = dyn_cast<ConstantSDNode>(LHSOp);
421auto *RHSCst = dyn_cast<ConstantSDNode>(RHSOp);
422if ((!LHSCst && !LHSUndef) || (!RHSCst && !RHSUndef))
423returnfalse;
424if (!AllowTypeMismatch && (LHSOp.getValueType() != SVT ||
425 LHSOp.getValueType() != RHSOp.getValueType()))
426returnfalse;
427if (!Match(LHSCst, RHSCst))
428returnfalse;
429 }
430returntrue;
431}
432
433ISD::NodeTypeISD::getInverseMinMaxOpcode(unsigned MinMaxOpc) {
434switch (MinMaxOpc) {
435default:
436llvm_unreachable("unrecognized opcode");
437caseISD::UMIN:
438returnISD::UMAX;
439caseISD::UMAX:
440returnISD::UMIN;
441caseISD::SMIN:
442returnISD::SMAX;
443caseISD::SMAX:
444returnISD::SMIN;
445 }
446}
447
448ISD::NodeTypeISD::getVecReduceBaseOpcode(unsigned VecReduceOpcode) {
449switch (VecReduceOpcode) {
450default:
451llvm_unreachable("Expected VECREDUCE opcode");
452caseISD::VECREDUCE_FADD:
453caseISD::VECREDUCE_SEQ_FADD:
454case ISD::VP_REDUCE_FADD:
455case ISD::VP_REDUCE_SEQ_FADD:
456returnISD::FADD;
457caseISD::VECREDUCE_FMUL:
458caseISD::VECREDUCE_SEQ_FMUL:
459case ISD::VP_REDUCE_FMUL:
460case ISD::VP_REDUCE_SEQ_FMUL:
461returnISD::FMUL;
462caseISD::VECREDUCE_ADD:
463case ISD::VP_REDUCE_ADD:
464returnISD::ADD;
465caseISD::VECREDUCE_MUL:
466case ISD::VP_REDUCE_MUL:
467returnISD::MUL;
468caseISD::VECREDUCE_AND:
469case ISD::VP_REDUCE_AND:
470returnISD::AND;
471caseISD::VECREDUCE_OR:
472case ISD::VP_REDUCE_OR:
473returnISD::OR;
474caseISD::VECREDUCE_XOR:
475case ISD::VP_REDUCE_XOR:
476returnISD::XOR;
477caseISD::VECREDUCE_SMAX:
478case ISD::VP_REDUCE_SMAX:
479returnISD::SMAX;
480caseISD::VECREDUCE_SMIN:
481case ISD::VP_REDUCE_SMIN:
482returnISD::SMIN;
483caseISD::VECREDUCE_UMAX:
484case ISD::VP_REDUCE_UMAX:
485returnISD::UMAX;
486caseISD::VECREDUCE_UMIN:
487case ISD::VP_REDUCE_UMIN:
488returnISD::UMIN;
489caseISD::VECREDUCE_FMAX:
490case ISD::VP_REDUCE_FMAX:
491returnISD::FMAXNUM;
492caseISD::VECREDUCE_FMIN:
493case ISD::VP_REDUCE_FMIN:
494returnISD::FMINNUM;
495caseISD::VECREDUCE_FMAXIMUM:
496case ISD::VP_REDUCE_FMAXIMUM:
497returnISD::FMAXIMUM;
498caseISD::VECREDUCE_FMINIMUM:
499case ISD::VP_REDUCE_FMINIMUM:
500returnISD::FMINIMUM;
501 }
502}
503
504boolISD::isVPOpcode(unsigned Opcode) {
505switch (Opcode) {
506default:
507returnfalse;
508#define BEGIN_REGISTER_VP_SDNODE(VPSD, ...) \
509 case ISD::VPSD: \
510 return true;
511#include "llvm/IR/VPIntrinsics.def"
512 }
513}
514
515boolISD::isVPBinaryOp(unsigned Opcode) {
516switch (Opcode) {
517default:
518break;
519#define BEGIN_REGISTER_VP_SDNODE(VPSD, ...) case ISD::VPSD:
520#define VP_PROPERTY_BINARYOP return true;
521#define END_REGISTER_VP_SDNODE(VPSD) break;
522#include "llvm/IR/VPIntrinsics.def"
523 }
524returnfalse;
525}
526
527boolISD::isVPReduction(unsigned Opcode) {
528switch (Opcode) {
529default:
530returnfalse;
531case ISD::VP_REDUCE_ADD:
532case ISD::VP_REDUCE_MUL:
533case ISD::VP_REDUCE_AND:
534case ISD::VP_REDUCE_OR:
535case ISD::VP_REDUCE_XOR:
536case ISD::VP_REDUCE_SMAX:
537case ISD::VP_REDUCE_SMIN:
538case ISD::VP_REDUCE_UMAX:
539case ISD::VP_REDUCE_UMIN:
540case ISD::VP_REDUCE_FMAX:
541case ISD::VP_REDUCE_FMIN:
542case ISD::VP_REDUCE_FMAXIMUM:
543case ISD::VP_REDUCE_FMINIMUM:
544case ISD::VP_REDUCE_FADD:
545case ISD::VP_REDUCE_FMUL:
546case ISD::VP_REDUCE_SEQ_FADD:
547case ISD::VP_REDUCE_SEQ_FMUL:
548returntrue;
549 }
550}
551
552/// The operand position of the vector mask.
553std::optional<unsigned>ISD::getVPMaskIdx(unsigned Opcode) {
554switch (Opcode) {
555default:
556return std::nullopt;
557#define BEGIN_REGISTER_VP_SDNODE(VPSD, LEGALPOS, TDNAME, MASKPOS, ...) \
558 case ISD::VPSD: \
559 return MASKPOS;
560#include "llvm/IR/VPIntrinsics.def"
561 }
562}
563
564/// The operand position of the explicit vector length parameter.
565std::optional<unsigned>ISD::getVPExplicitVectorLengthIdx(unsigned Opcode) {
566switch (Opcode) {
567default:
568return std::nullopt;
569#define BEGIN_REGISTER_VP_SDNODE(VPSD, LEGALPOS, TDNAME, MASKPOS, EVLPOS) \
570 case ISD::VPSD: \
571 return EVLPOS;
572#include "llvm/IR/VPIntrinsics.def"
573 }
574}
575
576std::optional<unsigned>ISD::getBaseOpcodeForVP(unsigned VPOpcode,
577bool hasFPExcept) {
578// FIXME: Return strict opcodes in case of fp exceptions.
579switch (VPOpcode) {
580default:
581return std::nullopt;
582#define BEGIN_REGISTER_VP_SDNODE(VPOPC, ...) case ISD::VPOPC:
583#define VP_PROPERTY_FUNCTIONAL_SDOPC(SDOPC) return ISD::SDOPC;
584#define END_REGISTER_VP_SDNODE(VPOPC) break;
585#include "llvm/IR/VPIntrinsics.def"
586 }
587return std::nullopt;
588}
589
590std::optional<unsigned>ISD::getVPForBaseOpcode(unsigned Opcode) {
591switch (Opcode) {
592default:
593return std::nullopt;
594#define BEGIN_REGISTER_VP_SDNODE(VPOPC, ...) break;
595#define VP_PROPERTY_FUNCTIONAL_SDOPC(SDOPC) case ISD::SDOPC:
596#define END_REGISTER_VP_SDNODE(VPOPC) return ISD::VPOPC;
597#include "llvm/IR/VPIntrinsics.def"
598 }
599}
600
601ISD::NodeTypeISD::getExtForLoadExtType(bool IsFP,ISD::LoadExtType ExtType) {
602switch (ExtType) {
603caseISD::EXTLOAD:
604return IsFP ?ISD::FP_EXTEND :ISD::ANY_EXTEND;
605caseISD::SEXTLOAD:
606returnISD::SIGN_EXTEND;
607caseISD::ZEXTLOAD:
608returnISD::ZERO_EXTEND;
609default:
610break;
611 }
612
613llvm_unreachable("Invalid LoadExtType");
614}
615
616ISD::CondCodeISD::getSetCCSwappedOperands(ISD::CondCodeOperation) {
617// To perform this operation, we just need to swap the L and G bits of the
618// operation.
619unsigned OldL = (Operation >> 2) & 1;
620unsigned OldG = (Operation >> 1) & 1;
621returnISD::CondCode((Operation & ~6) |// Keep the N, U, E bits
622 (OldL << 1) |// New G bit
623 (OldG << 2));// New L bit.
624}
625
626staticISD::CondCodegetSetCCInverseImpl(ISD::CondCodeOp,bool isIntegerLike) {
627unsignedOperation =Op;
628if (isIntegerLike)
629Operation ^= 7;// Flip L, G, E bits, but not U.
630else
631Operation ^= 15;// Flip all of the condition bits.
632
633if (Operation >ISD::SETTRUE2)
634Operation &= ~8;// Don't let N and U bits get set.
635
636returnISD::CondCode(Operation);
637}
638
639ISD::CondCodeISD::getSetCCInverse(ISD::CondCodeOp,EVTType) {
640returngetSetCCInverseImpl(Op,Type.isInteger());
641}
642
643ISD::CondCodeISD::GlobalISel::getSetCCInverse(ISD::CondCodeOp,
644bool isIntegerLike) {
645returngetSetCCInverseImpl(Op, isIntegerLike);
646}
647
648/// For an integer comparison, return 1 if the comparison is a signed operation
649/// and 2 if the result is an unsigned comparison. Return zero if the operation
650/// does not depend on the sign of the input (setne and seteq).
651staticintisSignedOp(ISD::CondCode Opcode) {
652switch (Opcode) {
653default:llvm_unreachable("Illegal integer setcc operation!");
654caseISD::SETEQ:
655caseISD::SETNE:return 0;
656caseISD::SETLT:
657caseISD::SETLE:
658caseISD::SETGT:
659caseISD::SETGE:return 1;
660caseISD::SETULT:
661caseISD::SETULE:
662caseISD::SETUGT:
663caseISD::SETUGE:return 2;
664 }
665}
666
667ISD::CondCodeISD::getSetCCOrOperation(ISD::CondCode Op1,ISD::CondCode Op2,
668EVTType) {
669bool IsInteger =Type.isInteger();
670if (IsInteger && (isSignedOp(Op1) |isSignedOp(Op2)) == 3)
671// Cannot fold a signed integer setcc with an unsigned integer setcc.
672returnISD::SETCC_INVALID;
673
674unsignedOp = Op1 | Op2;// Combine all of the condition bits.
675
676// If the N and U bits get set, then the resultant comparison DOES suddenly
677// care about orderedness, and it is true when ordered.
678if (Op >ISD::SETTRUE2)
679Op &= ~16;// Clear the U bit if the N bit is set.
680
681// Canonicalize illegal integer setcc's.
682if (IsInteger &&Op ==ISD::SETUNE)// e.g. SETUGT | SETULT
683Op =ISD::SETNE;
684
685returnISD::CondCode(Op);
686}
687
688ISD::CondCodeISD::getSetCCAndOperation(ISD::CondCode Op1,ISD::CondCode Op2,
689EVTType) {
690bool IsInteger =Type.isInteger();
691if (IsInteger && (isSignedOp(Op1) |isSignedOp(Op2)) == 3)
692// Cannot fold a signed setcc with an unsigned setcc.
693returnISD::SETCC_INVALID;
694
695// Combine all of the condition bits.
696ISD::CondCode Result =ISD::CondCode(Op1 & Op2);
697
698// Canonicalize illegal integer setcc's.
699if (IsInteger) {
700switch (Result) {
701default:break;
702caseISD::SETUO : Result =ISD::SETFALSE;break;// SETUGT & SETULT
703caseISD::SETOEQ:// SETEQ & SETU[LG]E
704caseISD::SETUEQ: Result =ISD::SETEQ ;break;// SETUGE & SETULE
705caseISD::SETOLT: Result =ISD::SETULT ;break;// SETULT & SETNE
706caseISD::SETOGT: Result =ISD::SETUGT ;break;// SETUGT & SETNE
707 }
708 }
709
710return Result;
711}
712
713//===----------------------------------------------------------------------===//
714// SDNode Profile Support
715//===----------------------------------------------------------------------===//
716
717/// AddNodeIDOpcode - Add the node opcode to the NodeID data.
718staticvoidAddNodeIDOpcode(FoldingSetNodeID &ID,unsigned OpC) {
719ID.AddInteger(OpC);
720}
721
722/// AddNodeIDValueTypes - Value type lists are intern'd so we can represent them
723/// solely with their pointer.
724staticvoidAddNodeIDValueTypes(FoldingSetNodeID &ID,SDVTList VTList) {
725ID.AddPointer(VTList.VTs);
726}
727
728/// AddNodeIDOperands - Various routines for adding operands to the NodeID data.
729staticvoidAddNodeIDOperands(FoldingSetNodeID &ID,
730ArrayRef<SDValue> Ops) {
731for (constauto &Op : Ops) {
732ID.AddPointer(Op.getNode());
733ID.AddInteger(Op.getResNo());
734 }
735}
736
737/// AddNodeIDOperands - Various routines for adding operands to the NodeID data.
738staticvoidAddNodeIDOperands(FoldingSetNodeID &ID,
739ArrayRef<SDUse> Ops) {
740for (constauto &Op : Ops) {
741ID.AddPointer(Op.getNode());
742ID.AddInteger(Op.getResNo());
743 }
744}
745
746staticvoidAddNodeIDNode(FoldingSetNodeID &ID,unsigned OpC,
747SDVTList VTList,ArrayRef<SDValue> OpList) {
748AddNodeIDOpcode(ID, OpC);
749AddNodeIDValueTypes(ID, VTList);
750AddNodeIDOperands(ID, OpList);
751}
752
753/// If this is an SDNode with special info, add this info to the NodeID data.
754staticvoidAddNodeIDCustom(FoldingSetNodeID &ID,constSDNode *N) {
755switch (N->getOpcode()) {
756caseISD::TargetExternalSymbol:
757caseISD::ExternalSymbol:
758caseISD::MCSymbol:
759llvm_unreachable("Should only be used on nodes with operands");
760default:break;// Normal nodes don't need extra info.
761caseISD::TargetConstant:
762caseISD::Constant: {
763constConstantSDNode *C = cast<ConstantSDNode>(N);
764ID.AddPointer(C->getConstantIntValue());
765ID.AddBoolean(C->isOpaque());
766break;
767 }
768caseISD::TargetConstantFP:
769caseISD::ConstantFP:
770ID.AddPointer(cast<ConstantFPSDNode>(N)->getConstantFPValue());
771break;
772caseISD::TargetGlobalAddress:
773caseISD::GlobalAddress:
774caseISD::TargetGlobalTLSAddress:
775caseISD::GlobalTLSAddress: {
776constGlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(N);
777ID.AddPointer(GA->getGlobal());
778ID.AddInteger(GA->getOffset());
779ID.AddInteger(GA->getTargetFlags());
780break;
781 }
782caseISD::BasicBlock:
783ID.AddPointer(cast<BasicBlockSDNode>(N)->getBasicBlock());
784break;
785caseISD::Register:
786ID.AddInteger(cast<RegisterSDNode>(N)->getReg().id());
787break;
788caseISD::RegisterMask:
789ID.AddPointer(cast<RegisterMaskSDNode>(N)->getRegMask());
790break;
791caseISD::SRCVALUE:
792ID.AddPointer(cast<SrcValueSDNode>(N)->getValue());
793break;
794caseISD::FrameIndex:
795caseISD::TargetFrameIndex:
796ID.AddInteger(cast<FrameIndexSDNode>(N)->getIndex());
797break;
798caseISD::LIFETIME_START:
799caseISD::LIFETIME_END:
800if (cast<LifetimeSDNode>(N)->hasOffset()) {
801ID.AddInteger(cast<LifetimeSDNode>(N)->getSize());
802ID.AddInteger(cast<LifetimeSDNode>(N)->getOffset());
803 }
804break;
805caseISD::PSEUDO_PROBE:
806ID.AddInteger(cast<PseudoProbeSDNode>(N)->getGuid());
807ID.AddInteger(cast<PseudoProbeSDNode>(N)->getIndex());
808ID.AddInteger(cast<PseudoProbeSDNode>(N)->getAttributes());
809break;
810caseISD::JumpTable:
811caseISD::TargetJumpTable:
812ID.AddInteger(cast<JumpTableSDNode>(N)->getIndex());
813ID.AddInteger(cast<JumpTableSDNode>(N)->getTargetFlags());
814break;
815caseISD::ConstantPool:
816caseISD::TargetConstantPool: {
817constConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(N);
818ID.AddInteger(CP->getAlign().value());
819ID.AddInteger(CP->getOffset());
820if (CP->isMachineConstantPoolEntry())
821 CP->getMachineCPVal()->addSelectionDAGCSEId(ID);
822else
823ID.AddPointer(CP->getConstVal());
824ID.AddInteger(CP->getTargetFlags());
825break;
826 }
827caseISD::TargetIndex: {
828constTargetIndexSDNode *TI = cast<TargetIndexSDNode>(N);
829ID.AddInteger(TI->getIndex());
830ID.AddInteger(TI->getOffset());
831ID.AddInteger(TI->getTargetFlags());
832break;
833 }
834caseISD::LOAD: {
835constLoadSDNode *LD = cast<LoadSDNode>(N);
836ID.AddInteger(LD->getMemoryVT().getRawBits());
837ID.AddInteger(LD->getRawSubclassData());
838ID.AddInteger(LD->getPointerInfo().getAddrSpace());
839ID.AddInteger(LD->getMemOperand()->getFlags());
840break;
841 }
842caseISD::STORE: {
843constStoreSDNode *ST = cast<StoreSDNode>(N);
844ID.AddInteger(ST->getMemoryVT().getRawBits());
845ID.AddInteger(ST->getRawSubclassData());
846ID.AddInteger(ST->getPointerInfo().getAddrSpace());
847ID.AddInteger(ST->getMemOperand()->getFlags());
848break;
849 }
850case ISD::VP_LOAD: {
851constVPLoadSDNode *ELD = cast<VPLoadSDNode>(N);
852ID.AddInteger(ELD->getMemoryVT().getRawBits());
853ID.AddInteger(ELD->getRawSubclassData());
854ID.AddInteger(ELD->getPointerInfo().getAddrSpace());
855ID.AddInteger(ELD->getMemOperand()->getFlags());
856break;
857 }
858case ISD::VP_STORE: {
859constVPStoreSDNode *EST = cast<VPStoreSDNode>(N);
860ID.AddInteger(EST->getMemoryVT().getRawBits());
861ID.AddInteger(EST->getRawSubclassData());
862ID.AddInteger(EST->getPointerInfo().getAddrSpace());
863ID.AddInteger(EST->getMemOperand()->getFlags());
864break;
865 }
866case ISD::EXPERIMENTAL_VP_STRIDED_LOAD: {
867constVPStridedLoadSDNode *SLD = cast<VPStridedLoadSDNode>(N);
868ID.AddInteger(SLD->getMemoryVT().getRawBits());
869ID.AddInteger(SLD->getRawSubclassData());
870ID.AddInteger(SLD->getPointerInfo().getAddrSpace());
871break;
872 }
873case ISD::EXPERIMENTAL_VP_STRIDED_STORE: {
874constVPStridedStoreSDNode *SST = cast<VPStridedStoreSDNode>(N);
875ID.AddInteger(SST->getMemoryVT().getRawBits());
876ID.AddInteger(SST->getRawSubclassData());
877ID.AddInteger(SST->getPointerInfo().getAddrSpace());
878break;
879 }
880case ISD::VP_GATHER: {
881constVPGatherSDNode *EG = cast<VPGatherSDNode>(N);
882ID.AddInteger(EG->getMemoryVT().getRawBits());
883ID.AddInteger(EG->getRawSubclassData());
884ID.AddInteger(EG->getPointerInfo().getAddrSpace());
885ID.AddInteger(EG->getMemOperand()->getFlags());
886break;
887 }
888case ISD::VP_SCATTER: {
889constVPScatterSDNode *ES = cast<VPScatterSDNode>(N);
890ID.AddInteger(ES->getMemoryVT().getRawBits());
891ID.AddInteger(ES->getRawSubclassData());
892ID.AddInteger(ES->getPointerInfo().getAddrSpace());
893ID.AddInteger(ES->getMemOperand()->getFlags());
894break;
895 }
896caseISD::MLOAD: {
897constMaskedLoadSDNode *MLD = cast<MaskedLoadSDNode>(N);
898ID.AddInteger(MLD->getMemoryVT().getRawBits());
899ID.AddInteger(MLD->getRawSubclassData());
900ID.AddInteger(MLD->getPointerInfo().getAddrSpace());
901ID.AddInteger(MLD->getMemOperand()->getFlags());
902break;
903 }
904caseISD::MSTORE: {
905constMaskedStoreSDNode *MST = cast<MaskedStoreSDNode>(N);
906ID.AddInteger(MST->getMemoryVT().getRawBits());
907ID.AddInteger(MST->getRawSubclassData());
908ID.AddInteger(MST->getPointerInfo().getAddrSpace());
909ID.AddInteger(MST->getMemOperand()->getFlags());
910break;
911 }
912caseISD::MGATHER: {
913constMaskedGatherSDNode *MG = cast<MaskedGatherSDNode>(N);
914ID.AddInteger(MG->getMemoryVT().getRawBits());
915ID.AddInteger(MG->getRawSubclassData());
916ID.AddInteger(MG->getPointerInfo().getAddrSpace());
917ID.AddInteger(MG->getMemOperand()->getFlags());
918break;
919 }
920caseISD::MSCATTER: {
921constMaskedScatterSDNode *MS = cast<MaskedScatterSDNode>(N);
922ID.AddInteger(MS->getMemoryVT().getRawBits());
923ID.AddInteger(MS->getRawSubclassData());
924ID.AddInteger(MS->getPointerInfo().getAddrSpace());
925ID.AddInteger(MS->getMemOperand()->getFlags());
926break;
927 }
928caseISD::ATOMIC_CMP_SWAP:
929caseISD::ATOMIC_CMP_SWAP_WITH_SUCCESS:
930caseISD::ATOMIC_SWAP:
931caseISD::ATOMIC_LOAD_ADD:
932caseISD::ATOMIC_LOAD_SUB:
933caseISD::ATOMIC_LOAD_AND:
934caseISD::ATOMIC_LOAD_CLR:
935caseISD::ATOMIC_LOAD_OR:
936caseISD::ATOMIC_LOAD_XOR:
937caseISD::ATOMIC_LOAD_NAND:
938caseISD::ATOMIC_LOAD_MIN:
939caseISD::ATOMIC_LOAD_MAX:
940caseISD::ATOMIC_LOAD_UMIN:
941caseISD::ATOMIC_LOAD_UMAX:
942caseISD::ATOMIC_LOAD:
943caseISD::ATOMIC_STORE: {
944constAtomicSDNode *AT = cast<AtomicSDNode>(N);
945ID.AddInteger(AT->getMemoryVT().getRawBits());
946ID.AddInteger(AT->getRawSubclassData());
947ID.AddInteger(AT->getPointerInfo().getAddrSpace());
948ID.AddInteger(AT->getMemOperand()->getFlags());
949break;
950 }
951caseISD::VECTOR_SHUFFLE: {
952ArrayRef<int> Mask = cast<ShuffleVectorSDNode>(N)->getMask();
953for (int M : Mask)
954ID.AddInteger(M);
955break;
956 }
957caseISD::ADDRSPACECAST: {
958constAddrSpaceCastSDNode *ASC = cast<AddrSpaceCastSDNode>(N);
959ID.AddInteger(ASC->getSrcAddressSpace());
960ID.AddInteger(ASC->getDestAddressSpace());
961break;
962 }
963caseISD::TargetBlockAddress:
964caseISD::BlockAddress: {
965constBlockAddressSDNode *BA = cast<BlockAddressSDNode>(N);
966ID.AddPointer(BA->getBlockAddress());
967ID.AddInteger(BA->getOffset());
968ID.AddInteger(BA->getTargetFlags());
969break;
970 }
971caseISD::AssertAlign:
972ID.AddInteger(cast<AssertAlignSDNode>(N)->getAlign().value());
973break;
974caseISD::PREFETCH:
975caseISD::INTRINSIC_VOID:
976caseISD::INTRINSIC_W_CHAIN:
977// Handled by MemIntrinsicSDNode check after the switch.
978break;
979 }// end switch (N->getOpcode())
980
981// MemIntrinsic nodes could also have subclass data, address spaces, and flags
982// to check.
983if (auto *MN = dyn_cast<MemIntrinsicSDNode>(N)) {
984ID.AddInteger(MN->getRawSubclassData());
985ID.AddInteger(MN->getPointerInfo().getAddrSpace());
986ID.AddInteger(MN->getMemOperand()->getFlags());
987ID.AddInteger(MN->getMemoryVT().getRawBits());
988 }
989}
990
991/// AddNodeIDNode - Generic routine for adding a nodes info to the NodeID
992/// data.
993staticvoidAddNodeIDNode(FoldingSetNodeID &ID,constSDNode *N) {
994AddNodeIDOpcode(ID,N->getOpcode());
995// Add the return value info.
996AddNodeIDValueTypes(ID,N->getVTList());
997// Add the operand info.
998AddNodeIDOperands(ID,N->ops());
999
1000// Handle SDNode leafs with special info.
1001AddNodeIDCustom(ID,N);
1002}
1003
1004//===----------------------------------------------------------------------===//
1005// SelectionDAG Class
1006//===----------------------------------------------------------------------===//
1007
1008/// doNotCSE - Return true if CSE should not be performed for this node.
1009staticbooldoNotCSE(SDNode *N) {
1010if (N->getValueType(0) == MVT::Glue)
1011returntrue;// Never CSE anything that produces a glue result.
1012
1013switch (N->getOpcode()) {
1014default:break;
1015caseISD::HANDLENODE:
1016caseISD::EH_LABEL:
1017returntrue;// Never CSE these nodes.
1018 }
1019
1020// Check that remaining values produced are not flags.
1021for (unsigned i = 1, e =N->getNumValues(); i != e; ++i)
1022if (N->getValueType(i) == MVT::Glue)
1023returntrue;// Never CSE anything that produces a glue result.
1024
1025returnfalse;
1026}
1027
1028/// RemoveDeadNodes - This method deletes all unreachable nodes in the
1029/// SelectionDAG.
1030voidSelectionDAG::RemoveDeadNodes() {
1031// Create a dummy node (which is not added to allnodes), that adds a reference
1032// to the root node, preventing it from being deleted.
1033HandleSDNode Dummy(getRoot());
1034
1035SmallVector<SDNode*, 128> DeadNodes;
1036
1037// Add all obviously-dead nodes to the DeadNodes worklist.
1038for (SDNode &Node :allnodes())
1039if (Node.use_empty())
1040 DeadNodes.push_back(&Node);
1041
1042RemoveDeadNodes(DeadNodes);
1043
1044// If the root changed (e.g. it was a dead load, update the root).
1045setRoot(Dummy.getValue());
1046}
1047
1048/// RemoveDeadNodes - This method deletes the unreachable nodes in the
1049/// given list, and any nodes that become unreachable as a result.
1050voidSelectionDAG::RemoveDeadNodes(SmallVectorImpl<SDNode *> &DeadNodes) {
1051
1052// Process the worklist, deleting the nodes and adding their uses to the
1053// worklist.
1054while (!DeadNodes.empty()) {
1055SDNode *N = DeadNodes.pop_back_val();
1056// Skip to next node if we've already managed to delete the node. This could
1057// happen if replacing a node causes a node previously added to the node to
1058// be deleted.
1059if (N->getOpcode() ==ISD::DELETED_NODE)
1060continue;
1061
1062for (DAGUpdateListener *DUL = UpdateListeners; DUL; DUL = DUL->Next)
1063 DUL->NodeDeleted(N,nullptr);
1064
1065// Take the node out of the appropriate CSE map.
1066 RemoveNodeFromCSEMaps(N);
1067
1068// Next, brutally remove the operand list. This is safe to do, as there are
1069// no cycles in the graph.
1070for (SDNode::op_iteratorI =N->op_begin(), E =N->op_end();I != E; ) {
1071SDUse &Use = *I++;
1072SDNode *Operand =Use.getNode();
1073Use.set(SDValue());
1074
1075// Now that we removed this operand, see if there are no uses of it left.
1076if (Operand->use_empty())
1077 DeadNodes.push_back(Operand);
1078 }
1079
1080 DeallocateNode(N);
1081 }
1082}
1083
1084voidSelectionDAG::RemoveDeadNode(SDNode *N){
1085SmallVector<SDNode*, 16> DeadNodes(1,N);
1086
1087// Create a dummy node that adds a reference to the root node, preventing
1088// it from being deleted. (This matters if the root is an operand of the
1089// dead node.)
1090HandleSDNode Dummy(getRoot());
1091
1092RemoveDeadNodes(DeadNodes);
1093}
1094
1095voidSelectionDAG::DeleteNode(SDNode *N) {
1096// First take this out of the appropriate CSE map.
1097 RemoveNodeFromCSEMaps(N);
1098
1099// Finally, remove uses due to operands of this node, remove from the
1100// AllNodes list, and delete the node.
1101 DeleteNodeNotInCSEMaps(N);
1102}
1103
1104void SelectionDAG::DeleteNodeNotInCSEMaps(SDNode *N) {
1105assert(N->getIterator() != AllNodes.begin() &&
1106"Cannot delete the entry node!");
1107assert(N->use_empty() &&"Cannot delete a node that is not dead!");
1108
1109// Drop all of the operands and decrement used node's use counts.
1110N->DropOperands();
1111
1112 DeallocateNode(N);
1113}
1114
1115voidSDDbgInfo::add(SDDbgValue *V,bool isParameter) {
1116assert(!(V->isVariadic() && isParameter));
1117if (isParameter)
1118 ByvalParmDbgValues.push_back(V);
1119else
1120 DbgValues.push_back(V);
1121for (constSDNode *Node : V->getSDNodes())
1122if (Node)
1123 DbgValMap[Node].push_back(V);
1124}
1125
1126voidSDDbgInfo::erase(constSDNode *Node) {
1127DbgValMapType::iteratorI = DbgValMap.find(Node);
1128if (I == DbgValMap.end())
1129return;
1130for (auto &Val:I->second)
1131 Val->setIsInvalidated();
1132 DbgValMap.erase(I);
1133}
1134
1135void SelectionDAG::DeallocateNode(SDNode *N) {
1136// If we have operands, deallocate them.
1137 removeOperands(N);
1138
1139 NodeAllocator.Deallocate(AllNodes.remove(N));
1140
1141// Set the opcode to DELETED_NODE to help catch bugs when node
1142// memory is reallocated.
1143// FIXME: There are places in SDag that have grown a dependency on the opcode
1144// value in the released node.
1145__asan_unpoison_memory_region(&N->NodeType,sizeof(N->NodeType));
1146N->NodeType =ISD::DELETED_NODE;
1147
1148// If any of the SDDbgValue nodes refer to this SDNode, invalidate
1149// them and forget about that node.
1150 DbgInfo->erase(N);
1151
1152// Invalidate extra info.
1153 SDEI.erase(N);
1154}
1155
1156#ifndef NDEBUG
1157/// VerifySDNode - Check the given SDNode. Aborts if it is invalid.
1158staticvoidVerifySDNode(SDNode *N,constTargetLowering *TLI) {
1159switch (N->getOpcode()) {
1160default:
1161if (N->getOpcode() >ISD::BUILTIN_OP_END)
1162 TLI->verifyTargetSDNode(N);
1163break;
1164caseISD::BUILD_PAIR: {
1165EVT VT =N->getValueType(0);
1166assert(N->getNumValues() == 1 &&"Too many results!");
1167assert(!VT.isVector() && (VT.isInteger() || VT.isFloatingPoint()) &&
1168"Wrong return type!");
1169assert(N->getNumOperands() == 2 &&"Wrong number of operands!");
1170assert(N->getOperand(0).getValueType() ==N->getOperand(1).getValueType() &&
1171"Mismatched operand types!");
1172assert(N->getOperand(0).getValueType().isInteger() == VT.isInteger() &&
1173"Wrong operand type!");
1174assert(VT.getSizeInBits() == 2 *N->getOperand(0).getValueSizeInBits() &&
1175"Wrong return type size");
1176break;
1177 }
1178caseISD::BUILD_VECTOR: {
1179assert(N->getNumValues() == 1 &&"Too many results!");
1180assert(N->getValueType(0).isVector() &&"Wrong return type!");
1181assert(N->getNumOperands() ==N->getValueType(0).getVectorNumElements() &&
1182"Wrong number of operands!");
1183EVT EltVT =N->getValueType(0).getVectorElementType();
1184for (constSDUse &Op :N->ops()) {
1185assert((Op.getValueType() == EltVT ||
1186 (EltVT.isInteger() &&Op.getValueType().isInteger() &&
1187 EltVT.bitsLE(Op.getValueType()))) &&
1188"Wrong operand type!");
1189assert(Op.getValueType() ==N->getOperand(0).getValueType() &&
1190"Operands must all have the same type");
1191 }
1192break;
1193 }
1194 }
1195}
1196#endif// NDEBUG
1197
1198/// Insert a newly allocated node into the DAG.
1199///
1200/// Handles insertion into the all nodes list and CSE map, as well as
1201/// verification and other common operations when a new node is allocated.
1202void SelectionDAG::InsertNode(SDNode *N) {
1203 AllNodes.push_back(N);
1204#ifndef NDEBUG
1205N->PersistentId = NextPersistentId++;
1206VerifySDNode(N, TLI);
1207#endif
1208for (DAGUpdateListener *DUL = UpdateListeners; DUL; DUL = DUL->Next)
1209 DUL->NodeInserted(N);
1210}
1211
1212/// RemoveNodeFromCSEMaps - Take the specified node out of the CSE map that
1213/// correspond to it. This is useful when we're about to delete or repurpose
1214/// the node. We don't want future request for structurally identical nodes
1215/// to return N anymore.
1216bool SelectionDAG::RemoveNodeFromCSEMaps(SDNode *N) {
1217bool Erased =false;
1218switch (N->getOpcode()) {
1219caseISD::HANDLENODE:returnfalse;// noop.
1220caseISD::CONDCODE:
1221assert(CondCodeNodes[cast<CondCodeSDNode>(N)->get()] &&
1222"Cond code doesn't exist!");
1223 Erased = CondCodeNodes[cast<CondCodeSDNode>(N)->get()] !=nullptr;
1224 CondCodeNodes[cast<CondCodeSDNode>(N)->get()] =nullptr;
1225break;
1226caseISD::ExternalSymbol:
1227 Erased = ExternalSymbols.erase(cast<ExternalSymbolSDNode>(N)->getSymbol());
1228break;
1229caseISD::TargetExternalSymbol: {
1230ExternalSymbolSDNode *ESN = cast<ExternalSymbolSDNode>(N);
1231 Erased = TargetExternalSymbols.erase(std::pair<std::string, unsigned>(
1232 ESN->getSymbol(), ESN->getTargetFlags()));
1233break;
1234 }
1235caseISD::MCSymbol: {
1236auto *MCSN = cast<MCSymbolSDNode>(N);
1237 Erased = MCSymbols.erase(MCSN->getMCSymbol());
1238break;
1239 }
1240caseISD::VALUETYPE: {
1241EVT VT = cast<VTSDNode>(N)->getVT();
1242if (VT.isExtended()) {
1243 Erased = ExtendedValueTypeNodes.erase(VT);
1244 }else {
1245 Erased = ValueTypeNodes[VT.getSimpleVT().SimpleTy] !=nullptr;
1246 ValueTypeNodes[VT.getSimpleVT().SimpleTy] =nullptr;
1247 }
1248break;
1249 }
1250default:
1251// Remove it from the CSE Map.
1252assert(N->getOpcode() !=ISD::DELETED_NODE &&"DELETED_NODE in CSEMap!");
1253assert(N->getOpcode() !=ISD::EntryToken &&"EntryToken in CSEMap!");
1254 Erased = CSEMap.RemoveNode(N);
1255break;
1256 }
1257#ifndef NDEBUG
1258// Verify that the node was actually in one of the CSE maps, unless it has a
1259// glue result (which cannot be CSE'd) or is one of the special cases that are
1260// not subject to CSE.
1261if (!Erased &&N->getValueType(N->getNumValues()-1) != MVT::Glue &&
1262 !N->isMachineOpcode() && !doNotCSE(N)) {
1263N->dump(this);
1264dbgs() <<"\n";
1265llvm_unreachable("Node is not in map!");
1266 }
1267#endif
1268return Erased;
1269}
1270
1271/// AddModifiedNodeToCSEMaps - The specified node has been removed from the CSE
1272/// maps and modified in place. Add it back to the CSE maps, unless an identical
1273/// node already exists, in which case transfer all its users to the existing
1274/// node. This transfer can potentially trigger recursive merging.
1275void
1276SelectionDAG::AddModifiedNodeToCSEMaps(SDNode *N) {
1277// For node types that aren't CSE'd, just act as if no identical node
1278// already exists.
1279if (!doNotCSE(N)) {
1280SDNode *Existing = CSEMap.GetOrInsertNode(N);
1281if (Existing !=N) {
1282// If there was already an existing matching node, use ReplaceAllUsesWith
1283// to replace the dead one with the existing one. This can cause
1284// recursive merging of other unrelated nodes down the line.
1285 Existing->intersectFlagsWith(N->getFlags());
1286ReplaceAllUsesWith(N, Existing);
1287
1288// N is now dead. Inform the listeners and delete it.
1289for (DAGUpdateListener *DUL = UpdateListeners; DUL; DUL = DUL->Next)
1290 DUL->NodeDeleted(N, Existing);
1291 DeleteNodeNotInCSEMaps(N);
1292return;
1293 }
1294 }
1295
1296// If the node doesn't already exist, we updated it. Inform listeners.
1297for (DAGUpdateListener *DUL = UpdateListeners; DUL; DUL = DUL->Next)
1298 DUL->NodeUpdated(N);
1299}
1300
1301/// FindModifiedNodeSlot - Find a slot for the specified node if its operands
1302/// were replaced with those specified. If this node is never memoized,
1303/// return null, otherwise return a pointer to the slot it would take. If a
1304/// node already exists with these operands, the slot will be non-null.
1305SDNode *SelectionDAG::FindModifiedNodeSlot(SDNode *N,SDValueOp,
1306void *&InsertPos) {
1307if (doNotCSE(N))
1308returnnullptr;
1309
1310SDValue Ops[] = {Op };
1311FoldingSetNodeIDID;
1312AddNodeIDNode(ID,N->getOpcode(),N->getVTList(), Ops);
1313AddNodeIDCustom(ID,N);
1314SDNode *Node = FindNodeOrInsertPos(ID,SDLoc(N), InsertPos);
1315if (Node)
1316Node->intersectFlagsWith(N->getFlags());
1317returnNode;
1318}
1319
1320/// FindModifiedNodeSlot - Find a slot for the specified node if its operands
1321/// were replaced with those specified. If this node is never memoized,
1322/// return null, otherwise return a pointer to the slot it would take. If a
1323/// node already exists with these operands, the slot will be non-null.
1324SDNode *SelectionDAG::FindModifiedNodeSlot(SDNode *N,
1325SDValue Op1,SDValue Op2,
1326void *&InsertPos) {
1327if (doNotCSE(N))
1328returnnullptr;
1329
1330SDValue Ops[] = { Op1, Op2 };
1331FoldingSetNodeIDID;
1332AddNodeIDNode(ID,N->getOpcode(),N->getVTList(), Ops);
1333AddNodeIDCustom(ID,N);
1334SDNode *Node = FindNodeOrInsertPos(ID,SDLoc(N), InsertPos);
1335if (Node)
1336Node->intersectFlagsWith(N->getFlags());
1337returnNode;
1338}
1339
1340/// FindModifiedNodeSlot - Find a slot for the specified node if its operands
1341/// were replaced with those specified. If this node is never memoized,
1342/// return null, otherwise return a pointer to the slot it would take. If a
1343/// node already exists with these operands, the slot will be non-null.
1344SDNode *SelectionDAG::FindModifiedNodeSlot(SDNode *N,ArrayRef<SDValue> Ops,
1345void *&InsertPos) {
1346if (doNotCSE(N))
1347returnnullptr;
1348
1349FoldingSetNodeIDID;
1350AddNodeIDNode(ID,N->getOpcode(),N->getVTList(), Ops);
1351AddNodeIDCustom(ID,N);
1352SDNode *Node = FindNodeOrInsertPos(ID,SDLoc(N), InsertPos);
1353if (Node)
1354Node->intersectFlagsWith(N->getFlags());
1355returnNode;
1356}
1357
1358AlignSelectionDAG::getEVTAlign(EVT VT) const{
1359Type *Ty = VT == MVT::iPTR ?PointerType::get(*getContext(), 0)
1360 : VT.getTypeForEVT(*getContext());
1361
1362returngetDataLayout().getABITypeAlign(Ty);
1363}
1364
1365// EntryNode could meaningfully have debug info if we can find it...
1366SelectionDAG::SelectionDAG(constTargetMachine &tm,CodeGenOptLevel OL)
1367 : TM(tm), OptLevel(OL), EntryNode(ISD::EntryToken, 0,DebugLoc(),
1368getVTList(MVT::Other,MVT::Glue)),
1369 Root(getEntryNode()) {
1370 InsertNode(&EntryNode);
1371 DbgInfo =newSDDbgInfo();
1372}
1373
1374voidSelectionDAG::init(MachineFunction &NewMF,
1375OptimizationRemarkEmitter &NewORE,Pass *PassPtr,
1376constTargetLibraryInfo *LibraryInfo,
1377UniformityInfo *NewUA,ProfileSummaryInfo *PSIin,
1378BlockFrequencyInfo *BFIin,MachineModuleInfo &MMIin,
1379FunctionVarLocsconst *VarLocs) {
1380 MF = &NewMF;
1381 SDAGISelPass = PassPtr;
1382 ORE = &NewORE;
1383 TLI =getSubtarget().getTargetLowering();
1384 TSI =getSubtarget().getSelectionDAGInfo();
1385 LibInfo = LibraryInfo;
1386 Context = &MF->getFunction().getContext();
1387 UA = NewUA;
1388 PSI = PSIin;
1389 BFI = BFIin;
1390 MMI = &MMIin;
1391 FnVarLocs = VarLocs;
1392}
1393
1394SelectionDAG::~SelectionDAG() {
1395assert(!UpdateListeners &&"Dangling registered DAGUpdateListeners");
1396 allnodes_clear();
1397 OperandRecycler.clear(OperandAllocator);
1398delete DbgInfo;
1399}
1400
1401boolSelectionDAG::shouldOptForSize() const{
1402returnllvm::shouldOptimizeForSize(FLI->MBB->getBasicBlock(), PSI, BFI);
1403}
1404
1405void SelectionDAG::allnodes_clear() {
1406assert(&*AllNodes.begin() == &EntryNode);
1407 AllNodes.remove(AllNodes.begin());
1408while (!AllNodes.empty())
1409 DeallocateNode(&AllNodes.front());
1410#ifndef NDEBUG
1411 NextPersistentId = 0;
1412#endif
1413}
1414
1415SDNode *SelectionDAG::FindNodeOrInsertPos(constFoldingSetNodeID &ID,
1416void *&InsertPos) {
1417SDNode *N = CSEMap.FindNodeOrInsertPos(ID, InsertPos);
1418if (N) {
1419switch (N->getOpcode()) {
1420default:break;
1421caseISD::Constant:
1422caseISD::ConstantFP:
1423llvm_unreachable("Querying for Constant and ConstantFP nodes requires "
1424"debug location. Use another overload.");
1425 }
1426 }
1427returnN;
1428}
1429
1430SDNode *SelectionDAG::FindNodeOrInsertPos(constFoldingSetNodeID &ID,
1431constSDLoc &DL,void *&InsertPos) {
1432SDNode *N = CSEMap.FindNodeOrInsertPos(ID, InsertPos);
1433if (N) {
1434switch (N->getOpcode()) {
1435caseISD::Constant:
1436caseISD::ConstantFP:
1437// Erase debug location from the node if the node is used at several
1438// different places. Do not propagate one location to all uses as it
1439// will cause a worse single stepping debugging experience.
1440if (N->getDebugLoc() !=DL.getDebugLoc())
1441N->setDebugLoc(DebugLoc());
1442break;
1443default:
1444// When the node's point of use is located earlier in the instruction
1445// sequence than its prior point of use, update its debug info to the
1446// earlier location.
1447if (DL.getIROrder() &&DL.getIROrder() <N->getIROrder())
1448N->setDebugLoc(DL.getDebugLoc());
1449break;
1450 }
1451 }
1452returnN;
1453}
1454
1455voidSelectionDAG::clear() {
1456 allnodes_clear();
1457 OperandRecycler.clear(OperandAllocator);
1458 OperandAllocator.Reset();
1459 CSEMap.clear();
1460
1461 ExtendedValueTypeNodes.clear();
1462 ExternalSymbols.clear();
1463 TargetExternalSymbols.clear();
1464 MCSymbols.clear();
1465 SDEI.clear();
1466 std::fill(CondCodeNodes.begin(), CondCodeNodes.end(),nullptr);
1467 std::fill(ValueTypeNodes.begin(), ValueTypeNodes.end(),nullptr);
1468
1469 EntryNode.UseList =nullptr;
1470 InsertNode(&EntryNode);
1471 Root =getEntryNode();
1472 DbgInfo->clear();
1473}
1474
1475SDValueSelectionDAG::getFPExtendOrRound(SDValueOp,constSDLoc &DL,EVT VT) {
1476return VT.bitsGT(Op.getValueType())
1477 ?getNode(ISD::FP_EXTEND,DL, VT,Op)
1478 :getNode(ISD::FP_ROUND,DL, VT,Op,
1479getIntPtrConstant(0,DL,/*isTarget=*/true));
1480}
1481
1482std::pair<SDValue, SDValue>
1483SelectionDAG::getStrictFPExtendOrRound(SDValueOp,SDValue Chain,
1484constSDLoc &DL,EVT VT) {
1485assert(!VT.bitsEq(Op.getValueType()) &&
1486"Strict no-op FP extend/round not allowed.");
1487SDValue Res =
1488 VT.bitsGT(Op.getValueType())
1489 ?getNode(ISD::STRICT_FP_EXTEND,DL, {VT, MVT::Other}, {Chain,Op})
1490 :getNode(ISD::STRICT_FP_ROUND,DL, {VT, MVT::Other},
1491 {Chain,Op,getIntPtrConstant(0,DL,/*isTarget=*/true)});
1492
1493return std::pair<SDValue, SDValue>(Res,SDValue(Res.getNode(), 1));
1494}
1495
1496SDValueSelectionDAG::getAnyExtOrTrunc(SDValueOp,constSDLoc &DL,EVT VT) {
1497return VT.bitsGT(Op.getValueType()) ?
1498getNode(ISD::ANY_EXTEND,DL, VT,Op) :
1499getNode(ISD::TRUNCATE,DL, VT,Op);
1500}
1501
1502SDValueSelectionDAG::getSExtOrTrunc(SDValueOp,constSDLoc &DL,EVT VT) {
1503return VT.bitsGT(Op.getValueType()) ?
1504getNode(ISD::SIGN_EXTEND,DL, VT,Op) :
1505getNode(ISD::TRUNCATE,DL, VT,Op);
1506}
1507
1508SDValueSelectionDAG::getZExtOrTrunc(SDValueOp,constSDLoc &DL,EVT VT) {
1509return VT.bitsGT(Op.getValueType()) ?
1510getNode(ISD::ZERO_EXTEND,DL, VT,Op) :
1511getNode(ISD::TRUNCATE,DL, VT,Op);
1512}
1513
1514SDValueSelectionDAG::getBitcastedAnyExtOrTrunc(SDValueOp,constSDLoc &DL,
1515EVT VT) {
1516assert(!VT.isVector());
1517autoType =Op.getValueType();
1518SDValue DestOp;
1519if (Type == VT)
1520returnOp;
1521autoSize =Op.getValueSizeInBits();
1522 DestOp =getBitcast(EVT::getIntegerVT(*Context,Size),Op);
1523if (DestOp.getValueType() == VT)
1524return DestOp;
1525
1526returngetAnyExtOrTrunc(DestOp,DL, VT);
1527}
1528
1529SDValueSelectionDAG::getBitcastedSExtOrTrunc(SDValueOp,constSDLoc &DL,
1530EVT VT) {
1531assert(!VT.isVector());
1532autoType =Op.getValueType();
1533SDValue DestOp;
1534if (Type == VT)
1535returnOp;
1536autoSize =Op.getValueSizeInBits();
1537 DestOp =getBitcast(MVT::getIntegerVT(Size),Op);
1538if (DestOp.getValueType() == VT)
1539return DestOp;
1540
1541returngetSExtOrTrunc(DestOp,DL, VT);
1542}
1543
1544SDValueSelectionDAG::getBitcastedZExtOrTrunc(SDValueOp,constSDLoc &DL,
1545EVT VT) {
1546assert(!VT.isVector());
1547autoType =Op.getValueType();
1548SDValue DestOp;
1549if (Type == VT)
1550returnOp;
1551autoSize =Op.getValueSizeInBits();
1552 DestOp =getBitcast(MVT::getIntegerVT(Size),Op);
1553if (DestOp.getValueType() == VT)
1554return DestOp;
1555
1556returngetZExtOrTrunc(DestOp,DL, VT);
1557}
1558
1559SDValueSelectionDAG::getBoolExtOrTrunc(SDValueOp,constSDLoc &SL,EVT VT,
1560EVT OpVT) {
1561if (VT.bitsLE(Op.getValueType()))
1562returngetNode(ISD::TRUNCATE, SL, VT,Op);
1563
1564TargetLowering::BooleanContent BType = TLI->getBooleanContents(OpVT);
1565returngetNode(TLI->getExtendForContent(BType), SL, VT,Op);
1566}
1567
1568SDValueSelectionDAG::getZeroExtendInReg(SDValueOp,constSDLoc &DL,EVT VT) {
1569EVT OpVT =Op.getValueType();
1570assert(VT.isInteger() && OpVT.isInteger() &&
1571"Cannot getZeroExtendInReg FP types");
1572assert(VT.isVector() == OpVT.isVector() &&
1573"getZeroExtendInReg type should be vector iff the operand "
1574"type is vector!");
1575assert((!VT.isVector() ||
1576 VT.getVectorElementCount() == OpVT.getVectorElementCount()) &&
1577"Vector element counts must match in getZeroExtendInReg");
1578assert(VT.bitsLE(OpVT) &&"Not extending!");
1579if (OpVT == VT)
1580returnOp;
1581APInt Imm =APInt::getLowBitsSet(OpVT.getScalarSizeInBits(),
1582 VT.getScalarSizeInBits());
1583returngetNode(ISD::AND,DL, OpVT,Op,getConstant(Imm,DL, OpVT));
1584}
1585
1586SDValueSelectionDAG::getVPZeroExtendInReg(SDValueOp,SDValue Mask,
1587SDValue EVL,constSDLoc &DL,
1588EVT VT) {
1589EVT OpVT =Op.getValueType();
1590assert(VT.isInteger() && OpVT.isInteger() &&
1591"Cannot getVPZeroExtendInReg FP types");
1592assert(VT.isVector() && OpVT.isVector() &&
1593"getVPZeroExtendInReg type and operand type should be vector!");
1594assert(VT.getVectorElementCount() == OpVT.getVectorElementCount() &&
1595"Vector element counts must match in getZeroExtendInReg");
1596assert(VT.bitsLE(OpVT) &&"Not extending!");
1597if (OpVT == VT)
1598returnOp;
1599APInt Imm =APInt::getLowBitsSet(OpVT.getScalarSizeInBits(),
1600 VT.getScalarSizeInBits());
1601returngetNode(ISD::VP_AND,DL, OpVT,Op,getConstant(Imm,DL, OpVT), Mask,
1602 EVL);
1603}
1604
1605SDValueSelectionDAG::getPtrExtOrTrunc(SDValueOp,constSDLoc &DL,EVT VT) {
1606// Only unsigned pointer semantics are supported right now. In the future this
1607// might delegate to TLI to check pointer signedness.
1608returngetZExtOrTrunc(Op,DL, VT);
1609}
1610
1611SDValueSelectionDAG::getPtrExtendInReg(SDValueOp,constSDLoc &DL,EVT VT) {
1612// Only unsigned pointer semantics are supported right now. In the future this
1613// might delegate to TLI to check pointer signedness.
1614returngetZeroExtendInReg(Op,DL, VT);
1615}
1616
1617SDValueSelectionDAG::getNegative(SDValue Val,constSDLoc &DL,EVT VT) {
1618returngetNode(ISD::SUB,DL, VT,getConstant(0,DL, VT), Val);
1619}
1620
1621/// getNOT - Create a bitwise NOT operation as (XOR Val, -1).
1622SDValueSelectionDAG::getNOT(constSDLoc &DL,SDValue Val,EVT VT) {
1623returngetNode(ISD::XOR,DL, VT, Val,getAllOnesConstant(DL, VT));
1624}
1625
1626SDValueSelectionDAG::getLogicalNOT(constSDLoc &DL,SDValue Val,EVT VT) {
1627SDValue TrueValue =getBoolConstant(true,DL, VT, VT);
1628returngetNode(ISD::XOR,DL, VT, Val, TrueValue);
1629}
1630
1631SDValueSelectionDAG::getVPLogicalNOT(constSDLoc &DL,SDValue Val,
1632SDValue Mask,SDValue EVL,EVT VT) {
1633SDValue TrueValue =getBoolConstant(true,DL, VT, VT);
1634returngetNode(ISD::VP_XOR,DL, VT, Val, TrueValue, Mask, EVL);
1635}
1636
1637SDValueSelectionDAG::getVPPtrExtOrTrunc(constSDLoc &DL,EVT VT,SDValueOp,
1638SDValue Mask,SDValue EVL) {
1639returngetVPZExtOrTrunc(DL, VT,Op, Mask, EVL);
1640}
1641
1642SDValueSelectionDAG::getVPZExtOrTrunc(constSDLoc &DL,EVT VT,SDValueOp,
1643SDValue Mask,SDValue EVL) {
1644if (VT.bitsGT(Op.getValueType()))
1645returngetNode(ISD::VP_ZERO_EXTEND,DL, VT,Op, Mask, EVL);
1646if (VT.bitsLT(Op.getValueType()))
1647returngetNode(ISD::VP_TRUNCATE,DL, VT,Op, Mask, EVL);
1648returnOp;
1649}
1650
1651SDValueSelectionDAG::getBoolConstant(bool V,constSDLoc &DL,EVT VT,
1652EVT OpVT) {
1653if (!V)
1654returngetConstant(0,DL, VT);
1655
1656switch (TLI->getBooleanContents(OpVT)) {
1657caseTargetLowering::ZeroOrOneBooleanContent:
1658caseTargetLowering::UndefinedBooleanContent:
1659returngetConstant(1,DL, VT);
1660caseTargetLowering::ZeroOrNegativeOneBooleanContent:
1661returngetAllOnesConstant(DL, VT);
1662 }
1663llvm_unreachable("Unexpected boolean content enum!");
1664}
1665
1666SDValueSelectionDAG::getConstant(uint64_t Val,constSDLoc &DL,EVT VT,
1667bool isT,bool isO) {
1668returngetConstant(APInt(VT.getScalarSizeInBits(), Val,/*isSigned=*/false),
1669DL, VT, isT, isO);
1670}
1671
1672SDValueSelectionDAG::getConstant(constAPInt &Val,constSDLoc &DL,EVT VT,
1673bool isT,bool isO) {
1674returngetConstant(*ConstantInt::get(*Context, Val),DL, VT, isT, isO);
1675}
1676
1677SDValueSelectionDAG::getConstant(constConstantInt &Val,constSDLoc &DL,
1678EVT VT,bool isT,bool isO) {
1679assert(VT.isInteger() &&"Cannot create FP integer constant!");
1680
1681EVT EltVT = VT.getScalarType();
1682constConstantInt *Elt = &Val;
1683
1684// Vector splats are explicit within the DAG, with ConstantSDNode holding the
1685// to-be-splatted scalar ConstantInt.
1686if (isa<VectorType>(Elt->getType()))
1687 Elt = ConstantInt::get(*getContext(), Elt->getValue());
1688
1689// In some cases the vector type is legal but the element type is illegal and
1690// needs to be promoted, for example v8i8 on ARM. In this case, promote the
1691// inserted value (the type does not need to match the vector element type).
1692// Any extra bits introduced will be truncated away.
1693if (VT.isVector() && TLI->getTypeAction(*getContext(), EltVT) ==
1694TargetLowering::TypePromoteInteger) {
1695 EltVT = TLI->getTypeToTransformTo(*getContext(), EltVT);
1696APInt NewVal;
1697if (TLI->isSExtCheaperThanZExt(VT.getScalarType(), EltVT))
1698 NewVal = Elt->getValue().sextOrTrunc(EltVT.getSizeInBits());
1699else
1700 NewVal = Elt->getValue().zextOrTrunc(EltVT.getSizeInBits());
1701 Elt = ConstantInt::get(*getContext(), NewVal);
1702 }
1703// In other cases the element type is illegal and needs to be expanded, for
1704// example v2i64 on MIPS32. In this case, find the nearest legal type, split
1705// the value into n parts and use a vector type with n-times the elements.
1706// Then bitcast to the type requested.
1707// Legalizing constants too early makes the DAGCombiner's job harder so we
1708// only legalize if the DAG tells us we must produce legal types.
1709elseif (NewNodesMustHaveLegalTypes && VT.isVector() &&
1710 TLI->getTypeAction(*getContext(), EltVT) ==
1711TargetLowering::TypeExpandInteger) {
1712constAPInt &NewVal = Elt->getValue();
1713EVT ViaEltVT = TLI->getTypeToTransformTo(*getContext(), EltVT);
1714unsigned ViaEltSizeInBits = ViaEltVT.getSizeInBits();
1715
1716// For scalable vectors, try to use a SPLAT_VECTOR_PARTS node.
1717if (VT.isScalableVector() ||
1718 TLI->isOperationLegal(ISD::SPLAT_VECTOR, VT)) {
1719assert(EltVT.getSizeInBits() % ViaEltSizeInBits == 0 &&
1720"Can only handle an even split!");
1721unsigned Parts = EltVT.getSizeInBits() / ViaEltSizeInBits;
1722
1723SmallVector<SDValue, 2> ScalarParts;
1724for (unsigned i = 0; i != Parts; ++i)
1725 ScalarParts.push_back(getConstant(
1726 NewVal.extractBits(ViaEltSizeInBits, i * ViaEltSizeInBits),DL,
1727 ViaEltVT, isT, isO));
1728
1729returngetNode(ISD::SPLAT_VECTOR_PARTS,DL, VT, ScalarParts);
1730 }
1731
1732unsigned ViaVecNumElts = VT.getSizeInBits() / ViaEltSizeInBits;
1733EVT ViaVecVT =EVT::getVectorVT(*getContext(), ViaEltVT, ViaVecNumElts);
1734
1735// Check the temporary vector is the correct size. If this fails then
1736// getTypeToTransformTo() probably returned a type whose size (in bits)
1737// isn't a power-of-2 factor of the requested type size.
1738assert(ViaVecVT.getSizeInBits() == VT.getSizeInBits());
1739
1740SmallVector<SDValue, 2> EltParts;
1741for (unsigned i = 0; i < ViaVecNumElts / VT.getVectorNumElements(); ++i)
1742 EltParts.push_back(getConstant(
1743 NewVal.extractBits(ViaEltSizeInBits, i * ViaEltSizeInBits),DL,
1744 ViaEltVT, isT, isO));
1745
1746// EltParts is currently in little endian order. If we actually want
1747// big-endian order then reverse it now.
1748if (getDataLayout().isBigEndian())
1749 std::reverse(EltParts.begin(), EltParts.end());
1750
1751// The elements must be reversed when the element order is different
1752// to the endianness of the elements (because the BITCAST is itself a
1753// vector shuffle in this situation). However, we do not need any code to
1754// perform this reversal because getConstant() is producing a vector
1755// splat.
1756// This situation occurs in MIPS MSA.
1757
1758SmallVector<SDValue, 8> Ops;
1759for (unsigned i = 0, e = VT.getVectorNumElements(); i != e; ++i)
1760llvm::append_range(Ops, EltParts);
1761
1762SDValue V =
1763getNode(ISD::BITCAST,DL, VT,getBuildVector(ViaVecVT,DL, Ops));
1764return V;
1765 }
1766
1767assert(Elt->getBitWidth() == EltVT.getSizeInBits() &&
1768"APInt size does not match type size!");
1769unsigned Opc = isT ?ISD::TargetConstant :ISD::Constant;
1770SDVTList VTs =getVTList(EltVT);
1771FoldingSetNodeIDID;
1772AddNodeIDNode(ID, Opc, VTs, {});
1773ID.AddPointer(Elt);
1774ID.AddBoolean(isO);
1775void *IP =nullptr;
1776SDNode *N =nullptr;
1777if ((N = FindNodeOrInsertPos(ID,DL, IP)))
1778if (!VT.isVector())
1779returnSDValue(N, 0);
1780
1781if (!N) {
1782N = newSDNode<ConstantSDNode>(isT, isO, Elt, VTs);
1783 CSEMap.InsertNode(N, IP);
1784 InsertNode(N);
1785NewSDValueDbgMsg(SDValue(N, 0),"Creating constant: ",this);
1786 }
1787
1788SDValue Result(N, 0);
1789if (VT.isVector())
1790 Result =getSplat(VT,DL, Result);
1791return Result;
1792}
1793
1794SDValueSelectionDAG::getSignedConstant(int64_t Val,constSDLoc &DL,EVT VT,
1795bool isT,bool isO) {
1796unsignedSize = VT.getScalarSizeInBits();
1797returngetConstant(APInt(Size, Val,/*isSigned=*/true),DL, VT, isT, isO);
1798}
1799
1800SDValueSelectionDAG::getAllOnesConstant(constSDLoc &DL,EVT VT,bool IsTarget,
1801bool IsOpaque) {
1802returngetConstant(APInt::getAllOnes(VT.getScalarSizeInBits()),DL, VT,
1803 IsTarget, IsOpaque);
1804}
1805
1806SDValueSelectionDAG::getIntPtrConstant(uint64_t Val,constSDLoc &DL,
1807bool isTarget) {
1808returngetConstant(Val,DL, TLI->getPointerTy(getDataLayout()), isTarget);
1809}
1810
1811SDValueSelectionDAG::getShiftAmountConstant(uint64_t Val,EVT VT,
1812constSDLoc &DL) {
1813assert(VT.isInteger() &&"Shift amount is not an integer type!");
1814EVT ShiftVT = TLI->getShiftAmountTy(VT,getDataLayout());
1815returngetConstant(Val,DL, ShiftVT);
1816}
1817
1818SDValueSelectionDAG::getShiftAmountConstant(constAPInt &Val,EVT VT,
1819constSDLoc &DL) {
1820assert(Val.ult(VT.getScalarSizeInBits()) &&"Out of range shift");
1821returngetShiftAmountConstant(Val.getZExtValue(), VT,DL);
1822}
1823
1824SDValueSelectionDAG::getVectorIdxConstant(uint64_t Val,constSDLoc &DL,
1825bool isTarget) {
1826returngetConstant(Val,DL, TLI->getVectorIdxTy(getDataLayout()), isTarget);
1827}
1828
1829SDValueSelectionDAG::getConstantFP(constAPFloat &V,constSDLoc &DL,EVT VT,
1830bool isTarget) {
1831returngetConstantFP(*ConstantFP::get(*getContext(), V),DL, VT, isTarget);
1832}
1833
1834SDValueSelectionDAG::getConstantFP(constConstantFP &V,constSDLoc &DL,
1835EVT VT,bool isTarget) {
1836assert(VT.isFloatingPoint() &&"Cannot create integer FP constant!");
1837
1838EVT EltVT = VT.getScalarType();
1839constConstantFP *Elt = &V;
1840
1841// Vector splats are explicit within the DAG, with ConstantFPSDNode holding
1842// the to-be-splatted scalar ConstantFP.
1843if (isa<VectorType>(Elt->getType()))
1844 Elt = ConstantFP::get(*getContext(), Elt->getValue());
1845
1846// Do the map lookup using the actual bit pattern for the floating point
1847// value, so that we don't have problems with 0.0 comparing equal to -0.0, and
1848// we don't have issues with SNANs.
1849unsigned Opc = isTarget ?ISD::TargetConstantFP :ISD::ConstantFP;
1850SDVTList VTs =getVTList(EltVT);
1851FoldingSetNodeIDID;
1852AddNodeIDNode(ID, Opc, VTs, {});
1853ID.AddPointer(Elt);
1854void *IP =nullptr;
1855SDNode *N =nullptr;
1856if ((N = FindNodeOrInsertPos(ID,DL, IP)))
1857if (!VT.isVector())
1858returnSDValue(N, 0);
1859
1860if (!N) {
1861N = newSDNode<ConstantFPSDNode>(isTarget, Elt, VTs);
1862 CSEMap.InsertNode(N, IP);
1863 InsertNode(N);
1864 }
1865
1866SDValue Result(N, 0);
1867if (VT.isVector())
1868 Result =getSplat(VT,DL, Result);
1869NewSDValueDbgMsg(Result,"Creating fp constant: ",this);
1870return Result;
1871}
1872
1873SDValueSelectionDAG::getConstantFP(double Val,constSDLoc &DL,EVT VT,
1874bool isTarget) {
1875EVT EltVT = VT.getScalarType();
1876if (EltVT == MVT::f32)
1877returngetConstantFP(APFloat((float)Val),DL, VT, isTarget);
1878if (EltVT == MVT::f64)
1879returngetConstantFP(APFloat(Val),DL, VT, isTarget);
1880if (EltVT == MVT::f80 || EltVT == MVT::f128 || EltVT == MVT::ppcf128 ||
1881 EltVT == MVT::f16 || EltVT == MVT::bf16) {
1882bool Ignored;
1883APFloat APF =APFloat(Val);
1884 APF.convert(EltVT.getFltSemantics(),APFloat::rmNearestTiesToEven,
1885 &Ignored);
1886returngetConstantFP(APF,DL, VT, isTarget);
1887 }
1888llvm_unreachable("Unsupported type in getConstantFP");
1889}
1890
1891SDValueSelectionDAG::getGlobalAddress(constGlobalValue *GV,constSDLoc &DL,
1892EVT VT, int64_tOffset,bool isTargetGA,
1893unsigned TargetFlags) {
1894assert((TargetFlags == 0 || isTargetGA) &&
1895"Cannot set target flags on target-independent globals");
1896
1897// Truncate (with sign-extension) the offset value to the pointer size.
1898unsignedBitWidth =getDataLayout().getPointerTypeSizeInBits(GV->getType());
1899if (BitWidth < 64)
1900Offset =SignExtend64(Offset,BitWidth);
1901
1902unsigned Opc;
1903if (GV->isThreadLocal())
1904 Opc = isTargetGA ?ISD::TargetGlobalTLSAddress :ISD::GlobalTLSAddress;
1905else
1906 Opc = isTargetGA ?ISD::TargetGlobalAddress :ISD::GlobalAddress;
1907
1908SDVTList VTs =getVTList(VT);
1909FoldingSetNodeIDID;
1910AddNodeIDNode(ID, Opc, VTs, {});
1911ID.AddPointer(GV);
1912ID.AddInteger(Offset);
1913ID.AddInteger(TargetFlags);
1914void *IP =nullptr;
1915if (SDNode *E = FindNodeOrInsertPos(ID,DL, IP))
1916returnSDValue(E, 0);
1917
1918auto *N = newSDNode<GlobalAddressSDNode>(
1919 Opc,DL.getIROrder(),DL.getDebugLoc(), GV, VTs,Offset, TargetFlags);
1920 CSEMap.InsertNode(N, IP);
1921 InsertNode(N);
1922returnSDValue(N, 0);
1923}
1924
1925SDValueSelectionDAG::getFrameIndex(int FI,EVT VT,bool isTarget) {
1926unsigned Opc = isTarget ?ISD::TargetFrameIndex :ISD::FrameIndex;
1927SDVTList VTs =getVTList(VT);
1928FoldingSetNodeIDID;
1929AddNodeIDNode(ID, Opc, VTs, {});
1930ID.AddInteger(FI);
1931void *IP =nullptr;
1932if (SDNode *E = FindNodeOrInsertPos(ID, IP))
1933returnSDValue(E, 0);
1934
1935auto *N = newSDNode<FrameIndexSDNode>(FI, VTs, isTarget);
1936 CSEMap.InsertNode(N, IP);
1937 InsertNode(N);
1938returnSDValue(N, 0);
1939}
1940
1941SDValueSelectionDAG::getJumpTable(int JTI,EVT VT,bool isTarget,
1942unsigned TargetFlags) {
1943assert((TargetFlags == 0 || isTarget) &&
1944"Cannot set target flags on target-independent jump tables");
1945unsigned Opc = isTarget ?ISD::TargetJumpTable :ISD::JumpTable;
1946SDVTList VTs =getVTList(VT);
1947FoldingSetNodeIDID;
1948AddNodeIDNode(ID, Opc, VTs, {});
1949ID.AddInteger(JTI);
1950ID.AddInteger(TargetFlags);
1951void *IP =nullptr;
1952if (SDNode *E = FindNodeOrInsertPos(ID, IP))
1953returnSDValue(E, 0);
1954
1955auto *N = newSDNode<JumpTableSDNode>(JTI, VTs, isTarget, TargetFlags);
1956 CSEMap.InsertNode(N, IP);
1957 InsertNode(N);
1958returnSDValue(N, 0);
1959}
1960
1961SDValueSelectionDAG::getJumpTableDebugInfo(int JTI,SDValue Chain,
1962constSDLoc &DL) {
1963EVT PTy =getTargetLoweringInfo().getPointerTy(getDataLayout());
1964returngetNode(ISD::JUMP_TABLE_DEBUG_INFO,DL, MVT::Glue, Chain,
1965getTargetConstant(static_cast<uint64_t>(JTI),DL, PTy,true));
1966}
1967
1968SDValueSelectionDAG::getConstantPool(constConstant *C,EVT VT,
1969MaybeAlign Alignment,intOffset,
1970bool isTarget,unsigned TargetFlags) {
1971assert((TargetFlags == 0 || isTarget) &&
1972"Cannot set target flags on target-independent globals");
1973if (!Alignment)
1974 Alignment =shouldOptForSize()
1975 ?getDataLayout().getABITypeAlign(C->getType())
1976 :getDataLayout().getPrefTypeAlign(C->getType());
1977unsigned Opc = isTarget ?ISD::TargetConstantPool :ISD::ConstantPool;
1978SDVTList VTs =getVTList(VT);
1979FoldingSetNodeIDID;
1980AddNodeIDNode(ID, Opc, VTs, {});
1981ID.AddInteger(Alignment->value());
1982ID.AddInteger(Offset);
1983ID.AddPointer(C);
1984ID.AddInteger(TargetFlags);
1985void *IP =nullptr;
1986if (SDNode *E = FindNodeOrInsertPos(ID, IP))
1987returnSDValue(E, 0);
1988
1989auto *N = newSDNode<ConstantPoolSDNode>(isTarget,C, VTs,Offset, *Alignment,
1990 TargetFlags);
1991 CSEMap.InsertNode(N, IP);
1992 InsertNode(N);
1993SDValue V =SDValue(N, 0);
1994NewSDValueDbgMsg(V,"Creating new constant pool: ",this);
1995return V;
1996}
1997
1998SDValueSelectionDAG::getConstantPool(MachineConstantPoolValue *C,EVT VT,
1999MaybeAlign Alignment,intOffset,
2000bool isTarget,unsigned TargetFlags) {
2001assert((TargetFlags == 0 || isTarget) &&
2002"Cannot set target flags on target-independent globals");
2003if (!Alignment)
2004 Alignment =getDataLayout().getPrefTypeAlign(C->getType());
2005unsigned Opc = isTarget ?ISD::TargetConstantPool :ISD::ConstantPool;
2006SDVTList VTs =getVTList(VT);
2007FoldingSetNodeIDID;
2008AddNodeIDNode(ID, Opc, VTs, {});
2009ID.AddInteger(Alignment->value());
2010ID.AddInteger(Offset);
2011C->addSelectionDAGCSEId(ID);
2012ID.AddInteger(TargetFlags);
2013void *IP =nullptr;
2014if (SDNode *E = FindNodeOrInsertPos(ID, IP))
2015returnSDValue(E, 0);
2016
2017auto *N = newSDNode<ConstantPoolSDNode>(isTarget,C, VTs,Offset, *Alignment,
2018 TargetFlags);
2019 CSEMap.InsertNode(N, IP);
2020 InsertNode(N);
2021returnSDValue(N, 0);
2022}
2023
2024SDValueSelectionDAG::getBasicBlock(MachineBasicBlock *MBB) {
2025FoldingSetNodeIDID;
2026AddNodeIDNode(ID,ISD::BasicBlock,getVTList(MVT::Other), {});
2027ID.AddPointer(MBB);
2028void *IP =nullptr;
2029if (SDNode *E = FindNodeOrInsertPos(ID, IP))
2030returnSDValue(E, 0);
2031
2032auto *N = newSDNode<BasicBlockSDNode>(MBB);
2033 CSEMap.InsertNode(N, IP);
2034 InsertNode(N);
2035returnSDValue(N, 0);
2036}
2037
2038SDValueSelectionDAG::getValueType(EVT VT) {
2039if (VT.isSimple() && (unsigned)VT.getSimpleVT().SimpleTy >=
2040 ValueTypeNodes.size())
2041 ValueTypeNodes.resize(VT.getSimpleVT().SimpleTy+1);
2042
2043SDNode *&N = VT.isExtended() ?
2044 ExtendedValueTypeNodes[VT] : ValueTypeNodes[VT.getSimpleVT().SimpleTy];
2045
2046if (N)returnSDValue(N, 0);
2047N = newSDNode<VTSDNode>(VT);
2048 InsertNode(N);
2049returnSDValue(N, 0);
2050}
2051
2052SDValueSelectionDAG::getExternalSymbol(constchar *Sym,EVT VT) {
2053SDNode *&N = ExternalSymbols[Sym];
2054if (N)returnSDValue(N, 0);
2055N = newSDNode<ExternalSymbolSDNode>(false,Sym, 0,getVTList(VT));
2056 InsertNode(N);
2057returnSDValue(N, 0);
2058}
2059
2060SDValueSelectionDAG::getMCSymbol(MCSymbol *Sym,EVT VT) {
2061SDNode *&N = MCSymbols[Sym];
2062if (N)
2063returnSDValue(N, 0);
2064N = newSDNode<MCSymbolSDNode>(Sym,getVTList(VT));
2065 InsertNode(N);
2066returnSDValue(N, 0);
2067}
2068
2069SDValueSelectionDAG::getTargetExternalSymbol(constchar *Sym,EVT VT,
2070unsigned TargetFlags) {
2071SDNode *&N =
2072 TargetExternalSymbols[std::pair<std::string, unsigned>(Sym, TargetFlags)];
2073if (N)returnSDValue(N, 0);
2074N = newSDNode<ExternalSymbolSDNode>(true,Sym, TargetFlags,getVTList(VT));
2075 InsertNode(N);
2076returnSDValue(N, 0);
2077}
2078
2079SDValueSelectionDAG::getCondCode(ISD::CondCodeCond) {
2080if ((unsigned)Cond >= CondCodeNodes.size())
2081 CondCodeNodes.resize(Cond+1);
2082
2083if (!CondCodeNodes[Cond]) {
2084auto *N = newSDNode<CondCodeSDNode>(Cond);
2085 CondCodeNodes[Cond] =N;
2086 InsertNode(N);
2087 }
2088
2089returnSDValue(CondCodeNodes[Cond], 0);
2090}
2091
2092SDValueSelectionDAG::getVScale(constSDLoc &DL,EVT VT,APInt MulImm,
2093bool ConstantFold) {
2094assert(MulImm.getBitWidth() == VT.getSizeInBits() &&
2095"APInt size does not match type size!");
2096
2097if (MulImm == 0)
2098returngetConstant(0,DL, VT);
2099
2100if (ConstantFold) {
2101constMachineFunction &MF =getMachineFunction();
2102constFunction &F = MF.getFunction();
2103ConstantRange CR =getVScaleRange(&F, 64);
2104if (constAPInt *C = CR.getSingleElement())
2105returngetConstant(MulImm *C->getZExtValue(),DL, VT);
2106 }
2107
2108returngetNode(ISD::VSCALE,DL, VT,getConstant(MulImm,DL, VT));
2109}
2110
2111SDValueSelectionDAG::getElementCount(constSDLoc &DL,EVT VT,ElementCount EC,
2112bool ConstantFold) {
2113if (EC.isScalable())
2114returngetVScale(DL, VT,
2115APInt(VT.getSizeInBits(), EC.getKnownMinValue()));
2116
2117returngetConstant(EC.getKnownMinValue(),DL, VT);
2118}
2119
2120SDValueSelectionDAG::getStepVector(constSDLoc &DL,EVT ResVT) {
2121APInt One(ResVT.getScalarSizeInBits(), 1);
2122returngetStepVector(DL, ResVT, One);
2123}
2124
2125SDValueSelectionDAG::getStepVector(constSDLoc &DL,EVT ResVT,
2126constAPInt &StepVal) {
2127assert(ResVT.getScalarSizeInBits() == StepVal.getBitWidth());
2128if (ResVT.isScalableVector())
2129returngetNode(
2130ISD::STEP_VECTOR,DL, ResVT,
2131getTargetConstant(StepVal,DL, ResVT.getVectorElementType()));
2132
2133SmallVector<SDValue, 16> OpsStepConstants;
2134for (uint64_t i = 0; i < ResVT.getVectorNumElements(); i++)
2135 OpsStepConstants.push_back(
2136getConstant(StepVal * i,DL, ResVT.getVectorElementType()));
2137returngetBuildVector(ResVT,DL, OpsStepConstants);
2138}
2139
2140/// Swaps the values of N1 and N2. Swaps all indices in the shuffle mask M that
2141/// point at N1 to point at N2 and indices that point at N2 to point at N1.
2142staticvoidcommuteShuffle(SDValue &N1,SDValue &N2,MutableArrayRef<int> M) {
2143std::swap(N1, N2);
2144ShuffleVectorSDNode::commuteMask(M);
2145}
2146
2147SDValueSelectionDAG::getVectorShuffle(EVT VT,constSDLoc &dl,SDValue N1,
2148SDValue N2,ArrayRef<int> Mask) {
2149assert(VT.getVectorNumElements() == Mask.size() &&
2150"Must have the same number of vector elements as mask elements!");
2151assert(VT == N1.getValueType() && VT == N2.getValueType() &&
2152"Invalid VECTOR_SHUFFLE");
2153
2154// Canonicalize shuffle undef, undef -> undef
2155if (N1.isUndef() && N2.isUndef())
2156returngetUNDEF(VT);
2157
2158// Validate that all indices in Mask are within the range of the elements
2159// input to the shuffle.
2160int NElts = Mask.size();
2161assert(llvm::all_of(Mask,
2162 [&](int M) {return M < (NElts * 2) && M >= -1; }) &&
2163"Index out of range");
2164
2165// Copy the mask so we can do any needed cleanup.
2166SmallVector<int, 8> MaskVec(Mask);
2167
2168// Canonicalize shuffle v, v -> v, undef
2169if (N1 == N2) {
2170 N2 =getUNDEF(VT);
2171for (int i = 0; i != NElts; ++i)
2172if (MaskVec[i] >= NElts) MaskVec[i] -= NElts;
2173 }
2174
2175// Canonicalize shuffle undef, v -> v, undef. Commute the shuffle mask.
2176if (N1.isUndef())
2177commuteShuffle(N1, N2, MaskVec);
2178
2179if (TLI->hasVectorBlend()) {
2180// If shuffling a splat, try to blend the splat instead. We do this here so
2181// that even when this arises during lowering we don't have to re-handle it.
2182auto BlendSplat = [&](BuildVectorSDNode *BV,intOffset) {
2183BitVector UndefElements;
2184SDValueSplat = BV->getSplatValue(&UndefElements);
2185if (!Splat)
2186return;
2187
2188for (int i = 0; i < NElts; ++i) {
2189if (MaskVec[i] <Offset || MaskVec[i] >= (Offset + NElts))
2190continue;
2191
2192// If this input comes from undef, mark it as such.
2193if (UndefElements[MaskVec[i] -Offset]) {
2194 MaskVec[i] = -1;
2195continue;
2196 }
2197
2198// If we can blend a non-undef lane, use that instead.
2199if (!UndefElements[i])
2200 MaskVec[i] = i +Offset;
2201 }
2202 };
2203if (auto *N1BV = dyn_cast<BuildVectorSDNode>(N1))
2204 BlendSplat(N1BV, 0);
2205if (auto *N2BV = dyn_cast<BuildVectorSDNode>(N2))
2206 BlendSplat(N2BV, NElts);
2207 }
2208
2209// Canonicalize all index into lhs, -> shuffle lhs, undef
2210// Canonicalize all index into rhs, -> shuffle rhs, undef
2211bool AllLHS =true, AllRHS =true;
2212bool N2Undef = N2.isUndef();
2213for (int i = 0; i != NElts; ++i) {
2214if (MaskVec[i] >= NElts) {
2215if (N2Undef)
2216 MaskVec[i] = -1;
2217else
2218 AllLHS =false;
2219 }elseif (MaskVec[i] >= 0) {
2220 AllRHS =false;
2221 }
2222 }
2223if (AllLHS && AllRHS)
2224returngetUNDEF(VT);
2225if (AllLHS && !N2Undef)
2226 N2 =getUNDEF(VT);
2227if (AllRHS) {
2228 N1 =getUNDEF(VT);
2229commuteShuffle(N1, N2, MaskVec);
2230 }
2231// Reset our undef status after accounting for the mask.
2232 N2Undef = N2.isUndef();
2233// Re-check whether both sides ended up undef.
2234if (N1.isUndef() && N2Undef)
2235returngetUNDEF(VT);
2236
2237// If Identity shuffle return that node.
2238bool Identity =true, AllSame =true;
2239for (int i = 0; i != NElts; ++i) {
2240if (MaskVec[i] >= 0 && MaskVec[i] != i) Identity =false;
2241if (MaskVec[i] != MaskVec[0]) AllSame =false;
2242 }
2243if (Identity && NElts)
2244return N1;
2245
2246// Shuffling a constant splat doesn't change the result.
2247if (N2Undef) {
2248SDValue V = N1;
2249
2250// Look through any bitcasts. We check that these don't change the number
2251// (and size) of elements and just changes their types.
2252while (V.getOpcode() ==ISD::BITCAST)
2253 V = V->getOperand(0);
2254
2255// A splat should always show up as a build vector node.
2256if (auto *BV = dyn_cast<BuildVectorSDNode>(V)) {
2257BitVector UndefElements;
2258SDValueSplat = BV->getSplatValue(&UndefElements);
2259// If this is a splat of an undef, shuffling it is also undef.
2260if (Splat &&Splat.isUndef())
2261returngetUNDEF(VT);
2262
2263bool SameNumElts =
2264 V.getValueType().getVectorNumElements() == VT.getVectorNumElements();
2265
2266// We only have a splat which can skip shuffles if there is a splatted
2267// value and no undef lanes rearranged by the shuffle.
2268if (Splat && UndefElements.none()) {
2269// Splat of <x, x, ..., x>, return <x, x, ..., x>, provided that the
2270// number of elements match or the value splatted is a zero constant.
2271if (SameNumElts ||isNullConstant(Splat))
2272return N1;
2273 }
2274
2275// If the shuffle itself creates a splat, build the vector directly.
2276if (AllSame && SameNumElts) {
2277EVT BuildVT = BV->getValueType(0);
2278constSDValue &Splatted = BV->getOperand(MaskVec[0]);
2279SDValue NewBV =getSplatBuildVector(BuildVT, dl, Splatted);
2280
2281// We may have jumped through bitcasts, so the type of the
2282// BUILD_VECTOR may not match the type of the shuffle.
2283if (BuildVT != VT)
2284 NewBV =getNode(ISD::BITCAST, dl, VT, NewBV);
2285return NewBV;
2286 }
2287 }
2288 }
2289
2290SDVTList VTs =getVTList(VT);
2291FoldingSetNodeIDID;
2292SDValue Ops[2] = { N1, N2 };
2293AddNodeIDNode(ID,ISD::VECTOR_SHUFFLE, VTs, Ops);
2294for (int i = 0; i != NElts; ++i)
2295ID.AddInteger(MaskVec[i]);
2296
2297void* IP =nullptr;
2298if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP))
2299returnSDValue(E, 0);
2300
2301// Allocate the mask array for the node out of the BumpPtrAllocator, since
2302// SDNode doesn't have access to it. This memory will be "leaked" when
2303// the node is deallocated, but recovered when the NodeAllocator is released.
2304int *MaskAlloc = OperandAllocator.Allocate<int>(NElts);
2305llvm::copy(MaskVec, MaskAlloc);
2306
2307auto *N = newSDNode<ShuffleVectorSDNode>(VTs, dl.getIROrder(),
2308 dl.getDebugLoc(), MaskAlloc);
2309 createOperands(N, Ops);
2310
2311 CSEMap.InsertNode(N, IP);
2312 InsertNode(N);
2313SDValue V =SDValue(N, 0);
2314NewSDValueDbgMsg(V,"Creating new node: ",this);
2315return V;
2316}
2317
2318SDValueSelectionDAG::getCommutedVectorShuffle(constShuffleVectorSDNode &SV) {
2319EVT VT = SV.getValueType(0);
2320SmallVector<int, 8> MaskVec(SV.getMask());
2321ShuffleVectorSDNode::commuteMask(MaskVec);
2322
2323SDValue Op0 = SV.getOperand(0);
2324SDValue Op1 = SV.getOperand(1);
2325returngetVectorShuffle(VT,SDLoc(&SV), Op1, Op0, MaskVec);
2326}
2327
2328SDValueSelectionDAG::getRegister(Register Reg,EVT VT) {
2329SDVTList VTs =getVTList(VT);
2330FoldingSetNodeIDID;
2331AddNodeIDNode(ID,ISD::Register, VTs, {});
2332ID.AddInteger(Reg.id());
2333void *IP =nullptr;
2334if (SDNode *E = FindNodeOrInsertPos(ID, IP))
2335returnSDValue(E, 0);
2336
2337auto *N = newSDNode<RegisterSDNode>(Reg, VTs);
2338N->SDNodeBits.IsDivergent = TLI->isSDNodeSourceOfDivergence(N, FLI, UA);
2339 CSEMap.InsertNode(N, IP);
2340 InsertNode(N);
2341returnSDValue(N, 0);
2342}
2343
2344SDValueSelectionDAG::getRegisterMask(constuint32_t *RegMask) {
2345FoldingSetNodeIDID;
2346AddNodeIDNode(ID,ISD::RegisterMask,getVTList(MVT::Untyped), {});
2347ID.AddPointer(RegMask);
2348void *IP =nullptr;
2349if (SDNode *E = FindNodeOrInsertPos(ID, IP))
2350returnSDValue(E, 0);
2351
2352auto *N = newSDNode<RegisterMaskSDNode>(RegMask);
2353 CSEMap.InsertNode(N, IP);
2354 InsertNode(N);
2355returnSDValue(N, 0);
2356}
2357
2358SDValueSelectionDAG::getEHLabel(constSDLoc &dl,SDValue Root,
2359MCSymbol *Label) {
2360returngetLabelNode(ISD::EH_LABEL, dl, Root, Label);
2361}
2362
2363SDValueSelectionDAG::getLabelNode(unsigned Opcode,constSDLoc &dl,
2364SDValue Root,MCSymbol *Label) {
2365FoldingSetNodeIDID;
2366SDValue Ops[] = { Root };
2367AddNodeIDNode(ID, Opcode,getVTList(MVT::Other), Ops);
2368ID.AddPointer(Label);
2369void *IP =nullptr;
2370if (SDNode *E = FindNodeOrInsertPos(ID, IP))
2371returnSDValue(E, 0);
2372
2373auto *N =
2374 newSDNode<LabelSDNode>(Opcode, dl.getIROrder(), dl.getDebugLoc(), Label);
2375 createOperands(N, Ops);
2376
2377 CSEMap.InsertNode(N, IP);
2378 InsertNode(N);
2379returnSDValue(N, 0);
2380}
2381
2382SDValueSelectionDAG::getBlockAddress(constBlockAddress *BA,EVT VT,
2383 int64_tOffset,bool isTarget,
2384unsigned TargetFlags) {
2385unsigned Opc = isTarget ?ISD::TargetBlockAddress :ISD::BlockAddress;
2386SDVTList VTs =getVTList(VT);
2387
2388FoldingSetNodeIDID;
2389AddNodeIDNode(ID, Opc, VTs, {});
2390ID.AddPointer(BA);
2391ID.AddInteger(Offset);
2392ID.AddInteger(TargetFlags);
2393void *IP =nullptr;
2394if (SDNode *E = FindNodeOrInsertPos(ID, IP))
2395returnSDValue(E, 0);
2396
2397auto *N = newSDNode<BlockAddressSDNode>(Opc, VTs, BA,Offset, TargetFlags);
2398 CSEMap.InsertNode(N, IP);
2399 InsertNode(N);
2400returnSDValue(N, 0);
2401}
2402
2403SDValueSelectionDAG::getSrcValue(constValue *V) {
2404FoldingSetNodeIDID;
2405AddNodeIDNode(ID,ISD::SRCVALUE,getVTList(MVT::Other), {});
2406ID.AddPointer(V);
2407
2408void *IP =nullptr;
2409if (SDNode *E = FindNodeOrInsertPos(ID, IP))
2410returnSDValue(E, 0);
2411
2412auto *N = newSDNode<SrcValueSDNode>(V);
2413 CSEMap.InsertNode(N, IP);
2414 InsertNode(N);
2415returnSDValue(N, 0);
2416}
2417
2418SDValueSelectionDAG::getMDNode(constMDNode *MD) {
2419FoldingSetNodeIDID;
2420AddNodeIDNode(ID,ISD::MDNODE_SDNODE,getVTList(MVT::Other), {});
2421ID.AddPointer(MD);
2422
2423void *IP =nullptr;
2424if (SDNode *E = FindNodeOrInsertPos(ID, IP))
2425returnSDValue(E, 0);
2426
2427auto *N = newSDNode<MDNodeSDNode>(MD);
2428 CSEMap.InsertNode(N, IP);
2429 InsertNode(N);
2430returnSDValue(N, 0);
2431}
2432
2433SDValueSelectionDAG::getBitcast(EVT VT,SDValue V) {
2434if (VT == V.getValueType())
2435return V;
2436
2437returngetNode(ISD::BITCAST,SDLoc(V), VT, V);
2438}
2439
2440SDValueSelectionDAG::getAddrSpaceCast(constSDLoc &dl,EVT VT,SDValuePtr,
2441unsigned SrcAS,unsigned DestAS) {
2442SDVTList VTs =getVTList(VT);
2443SDValue Ops[] = {Ptr};
2444FoldingSetNodeIDID;
2445AddNodeIDNode(ID,ISD::ADDRSPACECAST, VTs, Ops);
2446ID.AddInteger(SrcAS);
2447ID.AddInteger(DestAS);
2448
2449void *IP =nullptr;
2450if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP))
2451returnSDValue(E, 0);
2452
2453auto *N = newSDNode<AddrSpaceCastSDNode>(dl.getIROrder(), dl.getDebugLoc(),
2454 VTs, SrcAS, DestAS);
2455 createOperands(N, Ops);
2456
2457 CSEMap.InsertNode(N, IP);
2458 InsertNode(N);
2459returnSDValue(N, 0);
2460}
2461
2462SDValueSelectionDAG::getFreeze(SDValue V) {
2463returngetNode(ISD::FREEZE,SDLoc(V), V.getValueType(), V);
2464}
2465
2466/// getShiftAmountOperand - Return the specified value casted to
2467/// the target's desired shift amount type.
2468SDValueSelectionDAG::getShiftAmountOperand(EVT LHSTy,SDValueOp) {
2469EVT OpTy =Op.getValueType();
2470EVT ShTy = TLI->getShiftAmountTy(LHSTy,getDataLayout());
2471if (OpTy == ShTy || OpTy.isVector())returnOp;
2472
2473returngetZExtOrTrunc(Op,SDLoc(Op), ShTy);
2474}
2475
2476SDValueSelectionDAG::getPartialReduceAdd(SDLocDL,EVT ReducedTy,SDValue Op1,
2477SDValue Op2) {
2478EVT FullTy = Op2.getValueType();
2479
2480unsigned Stride = ReducedTy.getVectorMinNumElements();
2481unsigned ScaleFactor = FullTy.getVectorMinNumElements() / Stride;
2482
2483// Collect all of the subvectors
2484 std::deque<SDValue> Subvectors = {Op1};
2485for (unsignedI = 0;I < ScaleFactor;I++) {
2486auto SourceIndex =getVectorIdxConstant(I * Stride,DL);
2487 Subvectors.push_back(
2488getNode(ISD::EXTRACT_SUBVECTOR,DL, ReducedTy, {Op2, SourceIndex}));
2489 }
2490
2491// Flatten the subvector tree
2492while (Subvectors.size() > 1) {
2493 Subvectors.push_back(
2494getNode(ISD::ADD,DL, ReducedTy, {Subvectors[0], Subvectors[1]}));
2495 Subvectors.pop_front();
2496 Subvectors.pop_front();
2497 }
2498
2499assert(Subvectors.size() == 1 &&
2500"There should only be one subvector after tree flattening");
2501
2502return Subvectors[0];
2503}
2504
2505/// Given a store node \p StoreNode, return true if it is safe to fold that node
2506/// into \p FPNode, which expands to a library call with output pointers.
2507staticboolcanFoldStoreIntoLibCallOutputPointers(StoreSDNode *StoreNode,
2508SDNode *FPNode) {
2509SmallVector<const SDNode *, 8> Worklist;
2510SmallVector<const SDNode *, 8> DeferredNodes;
2511SmallPtrSet<const SDNode *, 16> Visited;
2512
2513// Skip FPNode use by StoreNode (that's the use we want to fold into FPNode).
2514for (SDValueOp : StoreNode->ops())
2515if (Op.getNode() != FPNode)
2516 Worklist.push_back(Op.getNode());
2517
2518unsignedMaxSteps =SelectionDAG::getHasPredecessorMaxSteps();
2519while (!Worklist.empty()) {
2520constSDNode *Node = Worklist.pop_back_val();
2521auto [_, Inserted] = Visited.insert(Node);
2522if (!Inserted)
2523continue;
2524
2525if (MaxSteps > 0 && Visited.size() >=MaxSteps)
2526returnfalse;
2527
2528// Reached the FPNode (would result in a cycle).
2529// OR Reached CALLSEQ_START (would result in nested call sequences).
2530if (Node == FPNode ||Node->getOpcode() ==ISD::CALLSEQ_START)
2531returnfalse;
2532
2533if (Node->getOpcode() ==ISD::CALLSEQ_END) {
2534// Defer looking into call sequences (so we can check we're outside one).
2535// We still need to look through these for the predecessor check.
2536 DeferredNodes.push_back(Node);
2537continue;
2538 }
2539
2540for (SDValueOp :Node->ops())
2541 Worklist.push_back(Op.getNode());
2542 }
2543
2544// True if we're outside a call sequence and don't have the FPNode as a
2545// predecessor. No cycles or nested call sequences possible.
2546return !SDNode::hasPredecessorHelper(FPNode, Visited, DeferredNodes,
2547MaxSteps);
2548}
2549
2550boolSelectionDAG::expandMultipleResultFPLibCall(
2551RTLIB::Libcall LC,SDNode *Node,SmallVectorImpl<SDValue> &Results,
2552 std::optional<unsigned> CallRetResNo) {
2553LLVMContext &Ctx = *getContext();
2554EVT VT = Node->getValueType(0);
2555unsigned NumResults = Node->getNumValues();
2556
2557constchar *LCName = TLI->getLibcallName(LC);
2558if (!LC || !LCName)
2559returnfalse;
2560
2561auto getVecDesc = [&]() ->VecDescconst * {
2562for (boolMasked : {false,true}) {
2563if (VecDescconst *VD =getLibInfo().getVectorMappingInfo(
2564 LCName, VT.getVectorElementCount(),Masked)) {
2565return VD;
2566 }
2567 }
2568returnnullptr;
2569 };
2570
2571// For vector types, we must find a vector mapping for the libcall.
2572VecDescconst *VD =nullptr;
2573if (VT.isVector() && !(VD = getVecDesc()))
2574returnfalse;
2575
2576// Find users of the node that store the results (and share input chains). The
2577// destination pointers can be used instead of creating stack allocations.
2578SDValue StoresInChain;
2579SmallVector<StoreSDNode *, 2> ResultStores(NumResults);
2580for (SDNode *User : Node->users()) {
2581if (!ISD::isNormalStore(User))
2582continue;
2583auto *ST = cast<StoreSDNode>(User);
2584SDValue StoreValue = ST->getValue();
2585unsigned ResNo = StoreValue.getResNo();
2586// Ensure the store corresponds to an output pointer.
2587if (CallRetResNo == ResNo)
2588continue;
2589// Ensure the store to the default address space and not atomic or volatile.
2590if (!ST->isSimple() || ST->getAddressSpace() != 0)
2591continue;
2592// Ensure all store chains are the same (so they don't alias).
2593if (StoresInChain && ST->getChain() != StoresInChain)
2594continue;
2595// Ensure the store is properly aligned.
2596Type *StoreType = StoreValue.getValueType().getTypeForEVT(Ctx);
2597if (ST->getAlign() <
2598getDataLayout().getABITypeAlign(StoreType->getScalarType()))
2599continue;
2600// Avoid:
2601// 1. Creating cyclic dependencies.
2602// 2. Expanding the node to a call within a call sequence.
2603if (!canFoldStoreIntoLibCallOutputPointers(ST, Node))
2604continue;
2605 ResultStores[ResNo] = ST;
2606 StoresInChain = ST->getChain();
2607 }
2608
2609TargetLowering::ArgListTy Args;
2610auto AddArgListEntry = [&](SDValue Node,Type *Ty) {
2611TargetLowering::ArgListEntry Entry{};
2612 Entry.Ty = Ty;
2613 Entry.Node = Node;
2614 Args.push_back(Entry);
2615 };
2616
2617// Pass the arguments.
2618for (constSDValue &Op : Node->op_values()) {
2619EVT ArgVT =Op.getValueType();
2620Type *ArgTy = ArgVT.getTypeForEVT(Ctx);
2621 AddArgListEntry(Op, ArgTy);
2622 }
2623
2624// Pass the output pointers.
2625SmallVector<SDValue, 2> ResultPtrs(NumResults);
2626Type *PointerTy =PointerType::getUnqual(Ctx);
2627for (auto [ResNo, ST] :llvm::enumerate(ResultStores)) {
2628if (ResNo == CallRetResNo)
2629continue;
2630EVT ResVT = Node->getValueType(ResNo);
2631SDValue ResultPtr = ST ? ST->getBasePtr() :CreateStackTemporary(ResVT);
2632 ResultPtrs[ResNo] = ResultPtr;
2633 AddArgListEntry(ResultPtr,PointerTy);
2634 }
2635
2636SDLocDL(Node);
2637
2638// Pass the vector mask (if required).
2639if (VD && VD->isMasked()) {
2640EVT MaskVT = TLI->getSetCCResultType(getDataLayout(), Ctx, VT);
2641SDValue Mask =getBoolConstant(true,DL, MaskVT, VT);
2642 AddArgListEntry(Mask, MaskVT.getTypeForEVT(Ctx));
2643 }
2644
2645Type *RetType = CallRetResNo.has_value()
2646 ? Node->getValueType(*CallRetResNo).getTypeForEVT(Ctx)
2647 :Type::getVoidTy(Ctx);
2648SDValue InChain = StoresInChain ? StoresInChain :getEntryNode();
2649SDValue Callee =getExternalSymbol(VD ? VD->getVectorFnName().data() : LCName,
2650 TLI->getPointerTy(getDataLayout()));
2651TargetLowering::CallLoweringInfo CLI(*this);
2652 CLI.setDebugLoc(DL).setChain(InChain).setLibCallee(
2653 TLI->getLibcallCallingConv(LC), RetType, Callee, std::move(Args));
2654
2655auto [Call, CallChain] = TLI->LowerCallTo(CLI);
2656
2657for (auto [ResNo, ResultPtr] :llvm::enumerate(ResultPtrs)) {
2658if (ResNo == CallRetResNo) {
2659Results.push_back(Call);
2660continue;
2661 }
2662MachinePointerInfo PtrInfo;
2663if (StoreSDNode *ST = ResultStores[ResNo]) {
2664// Replace store with the library call.
2665ReplaceAllUsesOfValueWith(SDValue(ST, 0), CallChain);
2666 PtrInfo = ST->getPointerInfo();
2667 }else {
2668 PtrInfo =MachinePointerInfo::getFixedStack(
2669getMachineFunction(), cast<FrameIndexSDNode>(ResultPtr)->getIndex());
2670 }
2671SDValue LoadResult =
2672getLoad(Node->getValueType(ResNo),DL, CallChain, ResultPtr, PtrInfo);
2673Results.push_back(LoadResult);
2674 }
2675
2676if (CallRetResNo && !Node->hasAnyUseOfValue(*CallRetResNo)) {
2677// FIXME: Find a way to avoid updating the root. This is needed for x86,
2678// which uses a floating-point stack. If (for example) the node to be
2679// expanded has two results one floating-point which is returned by the
2680// call, and one integer result, returned via an output pointer. If only the
2681// integer result is used then the `CopyFromReg` for the FP result may be
2682// optimized out. This prevents an FP stack pop from being emitted for it.
2683// Setting the root like this ensures there will be a use of the
2684// `CopyFromReg` chain, and ensures the FP pop will be emitted.
2685SDValue NewRoot =
2686getNode(ISD::TokenFactor,DL, MVT::Other,getRoot(), CallChain);
2687setRoot(NewRoot);
2688// Ensure the new root is reachable from the results.
2689Results[0] =getMergeValues({Results[0], NewRoot},DL);
2690 }
2691
2692returntrue;
2693}
2694
2695SDValueSelectionDAG::expandVAArg(SDNode *Node) {
2696SDLoc dl(Node);
2697constTargetLowering &TLI =getTargetLoweringInfo();
2698constValue *V = cast<SrcValueSDNode>(Node->getOperand(2))->getValue();
2699EVT VT = Node->getValueType(0);
2700SDValue Tmp1 = Node->getOperand(0);
2701SDValue Tmp2 = Node->getOperand(1);
2702constMaybeAlign MA(Node->getConstantOperandVal(3));
2703
2704SDValue VAListLoad =getLoad(TLI.getPointerTy(getDataLayout()), dl, Tmp1,
2705 Tmp2,MachinePointerInfo(V));
2706SDValue VAList = VAListLoad;
2707
2708if (MA && *MA > TLI.getMinStackArgumentAlignment()) {
2709 VAList =getNode(ISD::ADD, dl, VAList.getValueType(), VAList,
2710getConstant(MA->value() - 1, dl, VAList.getValueType()));
2711
2712 VAList =getNode(
2713ISD::AND, dl, VAList.getValueType(), VAList,
2714getSignedConstant(-(int64_t)MA->value(), dl, VAList.getValueType()));
2715 }
2716
2717// Increment the pointer, VAList, to the next vaarg
2718 Tmp1 =getNode(ISD::ADD, dl, VAList.getValueType(), VAList,
2719getConstant(getDataLayout().getTypeAllocSize(
2720 VT.getTypeForEVT(*getContext())),
2721 dl, VAList.getValueType()));
2722// Store the incremented VAList to the legalized pointer
2723 Tmp1 =
2724getStore(VAListLoad.getValue(1), dl, Tmp1, Tmp2,MachinePointerInfo(V));
2725// Load the actual argument out of the pointer VAList
2726returngetLoad(VT, dl, Tmp1, VAList,MachinePointerInfo());
2727}
2728
2729SDValueSelectionDAG::expandVACopy(SDNode *Node) {
2730SDLoc dl(Node);
2731constTargetLowering &TLI =getTargetLoweringInfo();
2732// This defaults to loading a pointer from the input and storing it to the
2733// output, returning the chain.
2734constValue *VD = cast<SrcValueSDNode>(Node->getOperand(3))->getValue();
2735constValue *VS = cast<SrcValueSDNode>(Node->getOperand(4))->getValue();
2736SDValue Tmp1 =
2737getLoad(TLI.getPointerTy(getDataLayout()), dl, Node->getOperand(0),
2738 Node->getOperand(2),MachinePointerInfo(VS));
2739returngetStore(Tmp1.getValue(1), dl, Tmp1, Node->getOperand(1),
2740MachinePointerInfo(VD));
2741}
2742
2743AlignSelectionDAG::getReducedAlign(EVT VT,bool UseABI) {
2744constDataLayout &DL =getDataLayout();
2745Type *Ty = VT.getTypeForEVT(*getContext());
2746Align RedAlign = UseABI ?DL.getABITypeAlign(Ty) :DL.getPrefTypeAlign(Ty);
2747
2748if (TLI->isTypeLegal(VT) || !VT.isVector())
2749return RedAlign;
2750
2751constTargetFrameLowering *TFI = MF->getSubtarget().getFrameLowering();
2752constAlign StackAlign = TFI->getStackAlign();
2753
2754// See if we can choose a smaller ABI alignment in cases where it's an
2755// illegal vector type that will get broken down.
2756if (RedAlign > StackAlign) {
2757EVT IntermediateVT;
2758MVT RegisterVT;
2759unsigned NumIntermediates;
2760 TLI->getVectorTypeBreakdown(*getContext(), VT, IntermediateVT,
2761 NumIntermediates, RegisterVT);
2762 Ty = IntermediateVT.getTypeForEVT(*getContext());
2763Align RedAlign2 = UseABI ?DL.getABITypeAlign(Ty) :DL.getPrefTypeAlign(Ty);
2764if (RedAlign2 < RedAlign)
2765 RedAlign = RedAlign2;
2766
2767if (!getMachineFunction().getFrameInfo().isStackRealignable())
2768// If the stack is not realignable, the alignment should be limited to the
2769// StackAlignment
2770 RedAlign = std::min(RedAlign, StackAlign);
2771 }
2772
2773return RedAlign;
2774}
2775
2776SDValueSelectionDAG::CreateStackTemporary(TypeSize Bytes,Align Alignment) {
2777MachineFrameInfo &MFI = MF->getFrameInfo();
2778constTargetFrameLowering *TFI = MF->getSubtarget().getFrameLowering();
2779int StackID = 0;
2780if (Bytes.isScalable())
2781 StackID = TFI->getStackIDForScalableVectors();
2782// The stack id gives an indication of whether the object is scalable or
2783// not, so it's safe to pass in the minimum size here.
2784int FrameIdx = MFI.CreateStackObject(Bytes.getKnownMinValue(), Alignment,
2785false,nullptr, StackID);
2786returngetFrameIndex(FrameIdx, TLI->getFrameIndexTy(getDataLayout()));
2787}
2788
2789SDValueSelectionDAG::CreateStackTemporary(EVT VT,unsigned minAlign) {
2790Type *Ty = VT.getTypeForEVT(*getContext());
2791Align StackAlign =
2792 std::max(getDataLayout().getPrefTypeAlign(Ty),Align(minAlign));
2793returnCreateStackTemporary(VT.getStoreSize(), StackAlign);
2794}
2795
2796SDValueSelectionDAG::CreateStackTemporary(EVT VT1,EVT VT2) {
2797TypeSize VT1Size = VT1.getStoreSize();
2798TypeSize VT2Size = VT2.getStoreSize();
2799assert(VT1Size.isScalable() == VT2Size.isScalable() &&
2800"Don't know how to choose the maximum size when creating a stack "
2801"temporary");
2802TypeSize Bytes = VT1Size.getKnownMinValue() > VT2Size.getKnownMinValue()
2803 ? VT1Size
2804 : VT2Size;
2805
2806Type *Ty1 = VT1.getTypeForEVT(*getContext());
2807Type *Ty2 = VT2.getTypeForEVT(*getContext());
2808constDataLayout &DL =getDataLayout();
2809AlignAlign = std::max(DL.getPrefTypeAlign(Ty1),DL.getPrefTypeAlign(Ty2));
2810returnCreateStackTemporary(Bytes,Align);
2811}
2812
2813SDValueSelectionDAG::FoldSetCC(EVT VT,SDValue N1,SDValue N2,
2814ISD::CondCodeCond,constSDLoc &dl) {
2815EVT OpVT = N1.getValueType();
2816
2817auto GetUndefBooleanConstant = [&]() {
2818if (VT.getScalarType() == MVT::i1 ||
2819 TLI->getBooleanContents(OpVT) ==
2820TargetLowering::UndefinedBooleanContent)
2821returngetUNDEF(VT);
2822// ZeroOrOne / ZeroOrNegative require specific values for the high bits,
2823// so we cannot use getUNDEF(). Return zero instead.
2824returngetConstant(0, dl, VT);
2825 };
2826
2827// These setcc operations always fold.
2828switch (Cond) {
2829default:break;
2830caseISD::SETFALSE:
2831caseISD::SETFALSE2:returngetBoolConstant(false, dl, VT, OpVT);
2832caseISD::SETTRUE:
2833caseISD::SETTRUE2:returngetBoolConstant(true, dl, VT, OpVT);
2834
2835caseISD::SETOEQ:
2836caseISD::SETOGT:
2837caseISD::SETOGE:
2838caseISD::SETOLT:
2839caseISD::SETOLE:
2840caseISD::SETONE:
2841caseISD::SETO:
2842caseISD::SETUO:
2843caseISD::SETUEQ:
2844caseISD::SETUNE:
2845assert(!OpVT.isInteger() &&"Illegal setcc for integer!");
2846break;
2847 }
2848
2849if (OpVT.isInteger()) {
2850// For EQ and NE, we can always pick a value for the undef to make the
2851// predicate pass or fail, so we can return undef.
2852// Matches behavior in llvm::ConstantFoldCompareInstruction.
2853// icmp eq/ne X, undef -> undef.
2854if ((N1.isUndef() || N2.isUndef()) &&
2855 (Cond ==ISD::SETEQ ||Cond ==ISD::SETNE))
2856return GetUndefBooleanConstant();
2857
2858// If both operands are undef, we can return undef for int comparison.
2859// icmp undef, undef -> undef.
2860if (N1.isUndef() && N2.isUndef())
2861return GetUndefBooleanConstant();
2862
2863// icmp X, X -> true/false
2864// icmp X, undef -> true/false because undef could be X.
2865if (N1.isUndef() || N2.isUndef() || N1 == N2)
2866returngetBoolConstant(ISD::isTrueWhenEqual(Cond), dl, VT, OpVT);
2867 }
2868
2869if (ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2)) {
2870constAPInt &C2 = N2C->getAPIntValue();
2871if (ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1)) {
2872constAPInt &C1 = N1C->getAPIntValue();
2873
2874returngetBoolConstant(ICmpInst::compare(C1, C2,getICmpCondCode(Cond)),
2875 dl, VT, OpVT);
2876 }
2877 }
2878
2879auto *N1CFP = dyn_cast<ConstantFPSDNode>(N1);
2880auto *N2CFP = dyn_cast<ConstantFPSDNode>(N2);
2881
2882if (N1CFP && N2CFP) {
2883APFloat::cmpResult R = N1CFP->getValueAPF().compare(N2CFP->getValueAPF());
2884switch (Cond) {
2885default:break;
2886caseISD::SETEQ:if (R==APFloat::cmpUnordered)
2887return GetUndefBooleanConstant();
2888 [[fallthrough]];
2889caseISD::SETOEQ:returngetBoolConstant(R==APFloat::cmpEqual, dl, VT,
2890 OpVT);
2891caseISD::SETNE:if (R==APFloat::cmpUnordered)
2892return GetUndefBooleanConstant();
2893 [[fallthrough]];
2894caseISD::SETONE:returngetBoolConstant(R==APFloat::cmpGreaterThan ||
2895 R==APFloat::cmpLessThan, dl, VT,
2896 OpVT);
2897caseISD::SETLT:if (R==APFloat::cmpUnordered)
2898return GetUndefBooleanConstant();
2899 [[fallthrough]];
2900caseISD::SETOLT:returngetBoolConstant(R==APFloat::cmpLessThan, dl, VT,
2901 OpVT);
2902caseISD::SETGT:if (R==APFloat::cmpUnordered)
2903return GetUndefBooleanConstant();
2904 [[fallthrough]];
2905caseISD::SETOGT:returngetBoolConstant(R==APFloat::cmpGreaterThan, dl,
2906 VT, OpVT);
2907caseISD::SETLE:if (R==APFloat::cmpUnordered)
2908return GetUndefBooleanConstant();
2909 [[fallthrough]];
2910caseISD::SETOLE:returngetBoolConstant(R==APFloat::cmpLessThan ||
2911 R==APFloat::cmpEqual, dl, VT,
2912 OpVT);
2913caseISD::SETGE:if (R==APFloat::cmpUnordered)
2914return GetUndefBooleanConstant();
2915 [[fallthrough]];
2916caseISD::SETOGE:returngetBoolConstant(R==APFloat::cmpGreaterThan ||
2917 R==APFloat::cmpEqual, dl, VT, OpVT);
2918caseISD::SETO:returngetBoolConstant(R!=APFloat::cmpUnordered, dl, VT,
2919 OpVT);
2920caseISD::SETUO:returngetBoolConstant(R==APFloat::cmpUnordered, dl, VT,
2921 OpVT);
2922caseISD::SETUEQ:returngetBoolConstant(R==APFloat::cmpUnordered ||
2923 R==APFloat::cmpEqual, dl, VT,
2924 OpVT);
2925caseISD::SETUNE:returngetBoolConstant(R!=APFloat::cmpEqual, dl, VT,
2926 OpVT);
2927caseISD::SETULT:returngetBoolConstant(R==APFloat::cmpUnordered ||
2928 R==APFloat::cmpLessThan, dl, VT,
2929 OpVT);
2930caseISD::SETUGT:returngetBoolConstant(R==APFloat::cmpGreaterThan ||
2931 R==APFloat::cmpUnordered, dl, VT,
2932 OpVT);
2933caseISD::SETULE:returngetBoolConstant(R!=APFloat::cmpGreaterThan, dl,
2934 VT, OpVT);
2935caseISD::SETUGE:returngetBoolConstant(R!=APFloat::cmpLessThan, dl, VT,
2936 OpVT);
2937 }
2938 }elseif (N1CFP && OpVT.isSimple() && !N2.isUndef()) {
2939// Ensure that the constant occurs on the RHS.
2940ISD::CondCode SwappedCond =ISD::getSetCCSwappedOperands(Cond);
2941if (!TLI->isCondCodeLegal(SwappedCond, OpVT.getSimpleVT()))
2942returnSDValue();
2943returngetSetCC(dl, VT, N2, N1, SwappedCond);
2944 }elseif ((N2CFP && N2CFP->getValueAPF().isNaN()) ||
2945 (OpVT.isFloatingPoint() && (N1.isUndef() || N2.isUndef()))) {
2946// If an operand is known to be a nan (or undef that could be a nan), we can
2947// fold it.
2948// Choosing NaN for the undef will always make unordered comparison succeed
2949// and ordered comparison fails.
2950// Matches behavior in llvm::ConstantFoldCompareInstruction.
2951switch (ISD::getUnorderedFlavor(Cond)) {
2952default:
2953llvm_unreachable("Unknown flavor!");
2954case 0:// Known false.
2955returngetBoolConstant(false, dl, VT, OpVT);
2956case 1:// Known true.
2957returngetBoolConstant(true, dl, VT, OpVT);
2958case 2:// Undefined.
2959return GetUndefBooleanConstant();
2960 }
2961 }
2962
2963// Could not fold it.
2964returnSDValue();
2965}
2966
2967/// SignBitIsZero - Return true if the sign bit of Op is known to be zero. We
2968/// use this predicate to simplify operations downstream.
2969boolSelectionDAG::SignBitIsZero(SDValueOp,unsignedDepth) const{
2970unsignedBitWidth =Op.getScalarValueSizeInBits();
2971returnMaskedValueIsZero(Op,APInt::getSignMask(BitWidth),Depth);
2972}
2973
2974/// MaskedValueIsZero - Return true if 'V & Mask' is known to be zero. We use
2975/// this predicate to simplify operations downstream. Mask is known to be zero
2976/// for bits that V cannot have.
2977boolSelectionDAG::MaskedValueIsZero(SDValue V,constAPInt &Mask,
2978unsignedDepth) const{
2979return Mask.isSubsetOf(computeKnownBits(V,Depth).Zero);
2980}
2981
2982/// MaskedValueIsZero - Return true if 'V & Mask' is known to be zero in
2983/// DemandedElts. We use this predicate to simplify operations downstream.
2984/// Mask is known to be zero for bits that V cannot have.
2985boolSelectionDAG::MaskedValueIsZero(SDValue V,constAPInt &Mask,
2986constAPInt &DemandedElts,
2987unsignedDepth) const{
2988return Mask.isSubsetOf(computeKnownBits(V, DemandedElts,Depth).Zero);
2989}
2990
2991/// MaskedVectorIsZero - Return true if 'Op' is known to be zero in
2992/// DemandedElts. We use this predicate to simplify operations downstream.
2993boolSelectionDAG::MaskedVectorIsZero(SDValue V,constAPInt &DemandedElts,
2994unsignedDepth/* = 0 */) const{
2995returncomputeKnownBits(V, DemandedElts,Depth).isZero();
2996}
2997
2998/// MaskedValueIsAllOnes - Return true if '(Op & Mask) == Mask'.
2999boolSelectionDAG::MaskedValueIsAllOnes(SDValue V,constAPInt &Mask,
3000unsignedDepth) const{
3001return Mask.isSubsetOf(computeKnownBits(V,Depth).One);
3002}
3003
3004APIntSelectionDAG::computeVectorKnownZeroElements(SDValueOp,
3005constAPInt &DemandedElts,
3006unsignedDepth) const{
3007EVT VT =Op.getValueType();
3008assert(VT.isVector() && !VT.isScalableVector() &&"Only for fixed vectors!");
3009
3010unsigned NumElts = VT.getVectorNumElements();
3011assert(DemandedElts.getBitWidth() == NumElts &&"Unexpected demanded mask.");
3012
3013APInt KnownZeroElements =APInt::getZero(NumElts);
3014for (unsigned EltIdx = 0; EltIdx != NumElts; ++EltIdx) {
3015if (!DemandedElts[EltIdx])
3016continue;// Don't query elements that are not demanded.
3017APInt Mask =APInt::getOneBitSet(NumElts, EltIdx);
3018if (MaskedVectorIsZero(Op, Mask,Depth))
3019 KnownZeroElements.setBit(EltIdx);
3020 }
3021return KnownZeroElements;
3022}
3023
3024/// isSplatValue - Return true if the vector V has the same value
3025/// across all DemandedElts. For scalable vectors, we don't know the
3026/// number of lanes at compile time. Instead, we use a 1 bit APInt
3027/// to represent a conservative value for all lanes; that is, that
3028/// one bit value is implicitly splatted across all lanes.
3029boolSelectionDAG::isSplatValue(SDValue V,constAPInt &DemandedElts,
3030APInt &UndefElts,unsignedDepth) const{
3031unsigned Opcode = V.getOpcode();
3032EVT VT = V.getValueType();
3033assert(VT.isVector() &&"Vector type expected");
3034assert((!VT.isScalableVector() || DemandedElts.getBitWidth() == 1) &&
3035"scalable demanded bits are ignored");
3036
3037if (!DemandedElts)
3038returnfalse;// No demanded elts, better to assume we don't know anything.
3039
3040if (Depth >=MaxRecursionDepth)
3041returnfalse;// Limit search depth.
3042
3043// Deal with some common cases here that work for both fixed and scalable
3044// vector types.
3045switch (Opcode) {
3046caseISD::SPLAT_VECTOR:
3047 UndefElts = V.getOperand(0).isUndef()
3048 ?APInt::getAllOnes(DemandedElts.getBitWidth())
3049 :APInt(DemandedElts.getBitWidth(), 0);
3050returntrue;
3051caseISD::ADD:
3052caseISD::SUB:
3053caseISD::AND:
3054caseISD::XOR:
3055caseISD::OR: {
3056APInt UndefLHS, UndefRHS;
3057SDValueLHS = V.getOperand(0);
3058SDValueRHS = V.getOperand(1);
3059if (isSplatValue(LHS, DemandedElts, UndefLHS,Depth + 1) &&
3060isSplatValue(RHS, DemandedElts, UndefRHS,Depth + 1)) {
3061 UndefElts = UndefLHS | UndefRHS;
3062returntrue;
3063 }
3064returnfalse;
3065 }
3066caseISD::ABS:
3067caseISD::TRUNCATE:
3068caseISD::SIGN_EXTEND:
3069caseISD::ZERO_EXTEND:
3070returnisSplatValue(V.getOperand(0), DemandedElts, UndefElts,Depth + 1);
3071default:
3072if (Opcode >=ISD::BUILTIN_OP_END || Opcode ==ISD::INTRINSIC_WO_CHAIN ||
3073 Opcode ==ISD::INTRINSIC_W_CHAIN || Opcode ==ISD::INTRINSIC_VOID)
3074return TLI->isSplatValueForTargetNode(V, DemandedElts, UndefElts, *this,
3075Depth);
3076break;
3077}
3078
3079// We don't support other cases than those above for scalable vectors at
3080// the moment.
3081if (VT.isScalableVector())
3082returnfalse;
3083
3084unsigned NumElts = VT.getVectorNumElements();
3085assert(NumElts == DemandedElts.getBitWidth() &&"Vector size mismatch");
3086 UndefElts =APInt::getZero(NumElts);
3087
3088switch (Opcode) {
3089caseISD::BUILD_VECTOR: {
3090SDValue Scl;
3091for (unsigned i = 0; i != NumElts; ++i) {
3092SDValueOp = V.getOperand(i);
3093if (Op.isUndef()) {
3094 UndefElts.setBit(i);
3095continue;
3096 }
3097if (!DemandedElts[i])
3098continue;
3099if (Scl && Scl !=Op)
3100returnfalse;
3101 Scl =Op;
3102 }
3103returntrue;
3104 }
3105caseISD::VECTOR_SHUFFLE: {
3106// Check if this is a shuffle node doing a splat or a shuffle of a splat.
3107APInt DemandedLHS =APInt::getZero(NumElts);
3108APInt DemandedRHS =APInt::getZero(NumElts);
3109ArrayRef<int> Mask = cast<ShuffleVectorSDNode>(V)->getMask();
3110for (int i = 0; i != (int)NumElts; ++i) {
3111int M = Mask[i];
3112if (M < 0) {
3113 UndefElts.setBit(i);
3114continue;
3115 }
3116if (!DemandedElts[i])
3117continue;
3118if (M < (int)NumElts)
3119 DemandedLHS.setBit(M);
3120else
3121 DemandedRHS.setBit(M - NumElts);
3122 }
3123
3124// If we aren't demanding either op, assume there's no splat.
3125// If we are demanding both ops, assume there's no splat.
3126if ((DemandedLHS.isZero() && DemandedRHS.isZero()) ||
3127 (!DemandedLHS.isZero() && !DemandedRHS.isZero()))
3128returnfalse;
3129
3130// See if the demanded elts of the source op is a splat or we only demand
3131// one element, which should always be a splat.
3132// TODO: Handle source ops splats with undefs.
3133auto CheckSplatSrc = [&](SDValue Src,constAPInt &SrcElts) {
3134APInt SrcUndefs;
3135return (SrcElts.popcount() == 1) ||
3136 (isSplatValue(Src, SrcElts, SrcUndefs,Depth + 1) &&
3137 (SrcElts & SrcUndefs).isZero());
3138 };
3139if (!DemandedLHS.isZero())
3140return CheckSplatSrc(V.getOperand(0), DemandedLHS);
3141return CheckSplatSrc(V.getOperand(1), DemandedRHS);
3142 }
3143caseISD::EXTRACT_SUBVECTOR: {
3144// Offset the demanded elts by the subvector index.
3145SDValue Src = V.getOperand(0);
3146// We don't support scalable vectors at the moment.
3147if (Src.getValueType().isScalableVector())
3148returnfalse;
3149uint64_tIdx = V.getConstantOperandVal(1);
3150unsigned NumSrcElts = Src.getValueType().getVectorNumElements();
3151APInt UndefSrcElts;
3152APInt DemandedSrcElts = DemandedElts.zext(NumSrcElts).shl(Idx);
3153if (isSplatValue(Src, DemandedSrcElts, UndefSrcElts,Depth + 1)) {
3154 UndefElts = UndefSrcElts.extractBits(NumElts,Idx);
3155returntrue;
3156 }
3157break;
3158 }
3159caseISD::ANY_EXTEND_VECTOR_INREG:
3160caseISD::SIGN_EXTEND_VECTOR_INREG:
3161caseISD::ZERO_EXTEND_VECTOR_INREG: {
3162// Widen the demanded elts by the src element count.
3163SDValue Src = V.getOperand(0);
3164// We don't support scalable vectors at the moment.
3165if (Src.getValueType().isScalableVector())
3166returnfalse;
3167unsigned NumSrcElts = Src.getValueType().getVectorNumElements();
3168APInt UndefSrcElts;
3169APInt DemandedSrcElts = DemandedElts.zext(NumSrcElts);
3170if (isSplatValue(Src, DemandedSrcElts, UndefSrcElts,Depth + 1)) {
3171 UndefElts = UndefSrcElts.trunc(NumElts);
3172returntrue;
3173 }
3174break;
3175 }
3176caseISD::BITCAST: {
3177SDValue Src = V.getOperand(0);
3178EVT SrcVT = Src.getValueType();
3179unsigned SrcBitWidth = SrcVT.getScalarSizeInBits();
3180unsignedBitWidth = VT.getScalarSizeInBits();
3181
3182// Ignore bitcasts from unsupported types.
3183// TODO: Add fp support?
3184if (!SrcVT.isVector() || !SrcVT.isInteger() || !VT.isInteger())
3185break;
3186
3187// Bitcast 'small element' vector to 'large element' vector.
3188if ((BitWidth % SrcBitWidth) == 0) {
3189// See if each sub element is a splat.
3190unsigned Scale =BitWidth / SrcBitWidth;
3191unsigned NumSrcElts = SrcVT.getVectorNumElements();
3192APInt ScaledDemandedElts =
3193APIntOps::ScaleBitMask(DemandedElts, NumSrcElts);
3194for (unsignedI = 0;I != Scale; ++I) {
3195APInt SubUndefElts;
3196APInt SubDemandedElt =APInt::getOneBitSet(Scale,I);
3197APInt SubDemandedElts =APInt::getSplat(NumSrcElts, SubDemandedElt);
3198 SubDemandedElts &= ScaledDemandedElts;
3199if (!isSplatValue(Src, SubDemandedElts, SubUndefElts,Depth + 1))
3200returnfalse;
3201// TODO: Add support for merging sub undef elements.
3202if (!SubUndefElts.isZero())
3203returnfalse;
3204 }
3205returntrue;
3206 }
3207break;
3208 }
3209 }
3210
3211returnfalse;
3212}
3213
3214/// Helper wrapper to main isSplatValue function.
3215boolSelectionDAG::isSplatValue(SDValue V,bool AllowUndefs) const{
3216EVT VT = V.getValueType();
3217assert(VT.isVector() &&"Vector type expected");
3218
3219APInt UndefElts;
3220// Since the number of lanes in a scalable vector is unknown at compile time,
3221// we track one bit which is implicitly broadcast to all lanes. This means
3222// that all lanes in a scalable vector are considered demanded.
3223APInt DemandedElts
3224 =APInt::getAllOnes(VT.isScalableVector() ? 1 : VT.getVectorNumElements());
3225returnisSplatValue(V, DemandedElts, UndefElts) &&
3226 (AllowUndefs || !UndefElts);
3227}
3228
3229SDValueSelectionDAG::getSplatSourceVector(SDValue V,int &SplatIdx) {
3230 V =peekThroughExtractSubvectors(V);
3231
3232EVT VT = V.getValueType();
3233unsigned Opcode = V.getOpcode();
3234switch (Opcode) {
3235default: {
3236APInt UndefElts;
3237// Since the number of lanes in a scalable vector is unknown at compile time,
3238// we track one bit which is implicitly broadcast to all lanes. This means
3239// that all lanes in a scalable vector are considered demanded.
3240APInt DemandedElts
3241 =APInt::getAllOnes(VT.isScalableVector() ? 1 : VT.getVectorNumElements());
3242
3243if (isSplatValue(V, DemandedElts, UndefElts)) {
3244if (VT.isScalableVector()) {
3245// DemandedElts and UndefElts are ignored for scalable vectors, since
3246// the only supported cases are SPLAT_VECTOR nodes.
3247 SplatIdx = 0;
3248 }else {
3249// Handle case where all demanded elements are UNDEF.
3250if (DemandedElts.isSubsetOf(UndefElts)) {
3251 SplatIdx = 0;
3252returngetUNDEF(VT);
3253 }
3254 SplatIdx = (UndefElts & DemandedElts).countr_one();
3255 }
3256return V;
3257 }
3258break;
3259 }
3260caseISD::SPLAT_VECTOR:
3261 SplatIdx = 0;
3262return V;
3263caseISD::VECTOR_SHUFFLE: {
3264assert(!VT.isScalableVector());
3265// Check if this is a shuffle node doing a splat.
3266// TODO - remove this and rely purely on SelectionDAG::isSplatValue,
3267// getTargetVShiftNode currently struggles without the splat source.
3268auto *SVN = cast<ShuffleVectorSDNode>(V);
3269if (!SVN->isSplat())
3270break;
3271intIdx = SVN->getSplatIndex();
3272int NumElts = V.getValueType().getVectorNumElements();
3273 SplatIdx =Idx % NumElts;
3274return V.getOperand(Idx / NumElts);
3275 }
3276 }
3277
3278returnSDValue();
3279}
3280
3281SDValueSelectionDAG::getSplatValue(SDValue V,bool LegalTypes) {
3282int SplatIdx;
3283if (SDValue SrcVector =getSplatSourceVector(V, SplatIdx)) {
3284EVT SVT = SrcVector.getValueType().getScalarType();
3285EVT LegalSVT = SVT;
3286if (LegalTypes && !TLI->isTypeLegal(SVT)) {
3287if (!SVT.isInteger())
3288returnSDValue();
3289 LegalSVT = TLI->getTypeToTransformTo(*getContext(), LegalSVT);
3290if (LegalSVT.bitsLT(SVT))
3291returnSDValue();
3292 }
3293returngetNode(ISD::EXTRACT_VECTOR_ELT,SDLoc(V), LegalSVT, SrcVector,
3294getVectorIdxConstant(SplatIdx,SDLoc(V)));
3295 }
3296returnSDValue();
3297}
3298
3299std::optional<ConstantRange>
3300SelectionDAG::getValidShiftAmountRange(SDValue V,constAPInt &DemandedElts,
3301unsignedDepth) const{
3302assert((V.getOpcode() ==ISD::SHL || V.getOpcode() ==ISD::SRL ||
3303 V.getOpcode() ==ISD::SRA) &&
3304"Unknown shift node");
3305// Shifting more than the bitwidth is not valid.
3306unsignedBitWidth = V.getScalarValueSizeInBits();
3307
3308if (auto *Cst = dyn_cast<ConstantSDNode>(V.getOperand(1))) {
3309constAPInt &ShAmt = Cst->getAPIntValue();
3310if (ShAmt.uge(BitWidth))
3311return std::nullopt;
3312returnConstantRange(ShAmt);
3313 }
3314
3315if (auto *BV = dyn_cast<BuildVectorSDNode>(V.getOperand(1))) {
3316constAPInt *MinAmt =nullptr, *MaxAmt =nullptr;
3317for (unsigned i = 0, e = BV->getNumOperands(); i != e; ++i) {
3318if (!DemandedElts[i])
3319continue;
3320auto *SA = dyn_cast<ConstantSDNode>(BV->getOperand(i));
3321if (!SA) {
3322 MinAmt = MaxAmt =nullptr;
3323break;
3324 }
3325constAPInt &ShAmt = SA->getAPIntValue();
3326if (ShAmt.uge(BitWidth))
3327return std::nullopt;
3328if (!MinAmt || MinAmt->ugt(ShAmt))
3329 MinAmt = &ShAmt;
3330if (!MaxAmt || MaxAmt->ult(ShAmt))
3331 MaxAmt = &ShAmt;
3332 }
3333assert(((!MinAmt && !MaxAmt) || (MinAmt && MaxAmt)) &&
3334"Failed to find matching min/max shift amounts");
3335if (MinAmt && MaxAmt)
3336returnConstantRange(*MinAmt, *MaxAmt + 1);
3337 }
3338
3339// Use computeKnownBits to find a hidden constant/knownbits (usually type
3340// legalized). e.g. Hidden behind multiple bitcasts/build_vector/casts etc.
3341KnownBits KnownAmt =computeKnownBits(V.getOperand(1), DemandedElts,Depth);
3342if (KnownAmt.getMaxValue().ult(BitWidth))
3343returnConstantRange::fromKnownBits(KnownAmt,/*IsSigned=*/false);
3344
3345return std::nullopt;
3346}
3347
3348std::optional<uint64_t>
3349SelectionDAG::getValidShiftAmount(SDValue V,constAPInt &DemandedElts,
3350unsignedDepth) const{
3351assert((V.getOpcode() ==ISD::SHL || V.getOpcode() ==ISD::SRL ||
3352 V.getOpcode() ==ISD::SRA) &&
3353"Unknown shift node");
3354if (std::optional<ConstantRange> AmtRange =
3355getValidShiftAmountRange(V, DemandedElts,Depth))
3356if (constAPInt *ShAmt = AmtRange->getSingleElement())
3357return ShAmt->getZExtValue();
3358return std::nullopt;
3359}
3360
3361std::optional<uint64_t>
3362SelectionDAG::getValidShiftAmount(SDValue V,unsignedDepth) const{
3363EVT VT = V.getValueType();
3364APInt DemandedElts = VT.isFixedLengthVector()
3365 ?APInt::getAllOnes(VT.getVectorNumElements())
3366 :APInt(1, 1);
3367returngetValidShiftAmount(V, DemandedElts,Depth);
3368}
3369
3370std::optional<uint64_t>
3371SelectionDAG::getValidMinimumShiftAmount(SDValue V,constAPInt &DemandedElts,
3372unsignedDepth) const{
3373assert((V.getOpcode() ==ISD::SHL || V.getOpcode() ==ISD::SRL ||
3374 V.getOpcode() ==ISD::SRA) &&
3375"Unknown shift node");
3376if (std::optional<ConstantRange> AmtRange =
3377getValidShiftAmountRange(V, DemandedElts,Depth))
3378return AmtRange->getUnsignedMin().getZExtValue();
3379return std::nullopt;
3380}
3381
3382std::optional<uint64_t>
3383SelectionDAG::getValidMinimumShiftAmount(SDValue V,unsignedDepth) const{
3384EVT VT = V.getValueType();
3385APInt DemandedElts = VT.isFixedLengthVector()
3386 ?APInt::getAllOnes(VT.getVectorNumElements())
3387 :APInt(1, 1);
3388returngetValidMinimumShiftAmount(V, DemandedElts,Depth);
3389}
3390
3391std::optional<uint64_t>
3392SelectionDAG::getValidMaximumShiftAmount(SDValue V,constAPInt &DemandedElts,
3393unsignedDepth) const{
3394assert((V.getOpcode() ==ISD::SHL || V.getOpcode() ==ISD::SRL ||
3395 V.getOpcode() ==ISD::SRA) &&
3396"Unknown shift node");
3397if (std::optional<ConstantRange> AmtRange =
3398getValidShiftAmountRange(V, DemandedElts,Depth))
3399return AmtRange->getUnsignedMax().getZExtValue();
3400return std::nullopt;
3401}
3402
3403std::optional<uint64_t>
3404SelectionDAG::getValidMaximumShiftAmount(SDValue V,unsignedDepth) const{
3405EVT VT = V.getValueType();
3406APInt DemandedElts = VT.isFixedLengthVector()
3407 ?APInt::getAllOnes(VT.getVectorNumElements())
3408 :APInt(1, 1);
3409returngetValidMaximumShiftAmount(V, DemandedElts,Depth);
3410}
3411
3412/// Determine which bits of Op are known to be either zero or one and return
3413/// them in Known. For vectors, the known bits are those that are shared by
3414/// every vector element.
3415KnownBitsSelectionDAG::computeKnownBits(SDValueOp,unsignedDepth) const{
3416EVT VT =Op.getValueType();
3417
3418// Since the number of lanes in a scalable vector is unknown at compile time,
3419// we track one bit which is implicitly broadcast to all lanes. This means
3420// that all lanes in a scalable vector are considered demanded.
3421APInt DemandedElts = VT.isFixedLengthVector()
3422 ?APInt::getAllOnes(VT.getVectorNumElements())
3423 :APInt(1, 1);
3424returncomputeKnownBits(Op, DemandedElts,Depth);
3425}
3426
3427/// Determine which bits of Op are known to be either zero or one and return
3428/// them in Known. The DemandedElts argument allows us to only collect the known
3429/// bits that are shared by the requested vector elements.
3430KnownBitsSelectionDAG::computeKnownBits(SDValueOp,constAPInt &DemandedElts,
3431unsignedDepth) const{
3432unsignedBitWidth =Op.getScalarValueSizeInBits();
3433
3434KnownBits Known(BitWidth);// Don't know anything.
3435
3436if (auto *C = dyn_cast<ConstantSDNode>(Op)) {
3437// We know all of the bits for a constant!
3438returnKnownBits::makeConstant(C->getAPIntValue());
3439 }
3440if (auto *C = dyn_cast<ConstantFPSDNode>(Op)) {
3441// We know all of the bits for a constant fp!
3442returnKnownBits::makeConstant(C->getValueAPF().bitcastToAPInt());
3443 }
3444
3445if (Depth >=MaxRecursionDepth)
3446return Known;// Limit search depth.
3447
3448KnownBits Known2;
3449unsigned NumElts = DemandedElts.getBitWidth();
3450assert((!Op.getValueType().isFixedLengthVector() ||
3451 NumElts ==Op.getValueType().getVectorNumElements()) &&
3452"Unexpected vector size");
3453
3454if (!DemandedElts)
3455return Known;// No demanded elts, better to assume we don't know anything.
3456
3457unsigned Opcode =Op.getOpcode();
3458switch (Opcode) {
3459caseISD::MERGE_VALUES:
3460returncomputeKnownBits(Op.getOperand(Op.getResNo()), DemandedElts,
3461Depth + 1);
3462caseISD::SPLAT_VECTOR: {
3463SDValueSrcOp =Op.getOperand(0);
3464assert(SrcOp.getValueSizeInBits() >=BitWidth &&
3465"Expected SPLAT_VECTOR implicit truncation");
3466// Implicitly truncate the bits to match the official semantics of
3467// SPLAT_VECTOR.
3468 Known =computeKnownBits(SrcOp,Depth + 1).trunc(BitWidth);
3469break;
3470 }
3471caseISD::SPLAT_VECTOR_PARTS: {
3472unsigned ScalarSize =Op.getOperand(0).getScalarValueSizeInBits();
3473assert(ScalarSize *Op.getNumOperands() ==BitWidth &&
3474"Expected SPLAT_VECTOR_PARTS scalars to cover element width");
3475for (auto [I,SrcOp] :enumerate(Op->ops())) {
3476 Known.insertBits(computeKnownBits(SrcOp,Depth + 1), ScalarSize *I);
3477 }
3478break;
3479 }
3480caseISD::STEP_VECTOR: {
3481constAPInt &Step =Op.getConstantOperandAPInt(0);
3482
3483if (Step.isPowerOf2())
3484 Known.Zero.setLowBits(Step.logBase2());
3485
3486constFunction &F =getMachineFunction().getFunction();
3487
3488if (!isUIntN(BitWidth,Op.getValueType().getVectorMinNumElements()))
3489break;
3490constAPInt MinNumElts =
3491APInt(BitWidth,Op.getValueType().getVectorMinNumElements());
3492
3493bool Overflow;
3494constAPInt MaxNumElts =getVScaleRange(&F,BitWidth)
3495 .getUnsignedMax()
3496 .umul_ov(MinNumElts, Overflow);
3497if (Overflow)
3498break;
3499
3500constAPInt MaxValue = (MaxNumElts - 1).umul_ov(Step, Overflow);
3501if (Overflow)
3502break;
3503
3504 Known.Zero.setHighBits(MaxValue.countl_zero());
3505break;
3506 }
3507caseISD::BUILD_VECTOR:
3508assert(!Op.getValueType().isScalableVector());
3509// Collect the known bits that are shared by every demanded vector element.
3510 Known.Zero.setAllBits(); Known.One.setAllBits();
3511for (unsigned i = 0, e =Op.getNumOperands(); i != e; ++i) {
3512if (!DemandedElts[i])
3513continue;
3514
3515SDValueSrcOp =Op.getOperand(i);
3516 Known2 =computeKnownBits(SrcOp,Depth + 1);
3517
3518// BUILD_VECTOR can implicitly truncate sources, we must handle this.
3519if (SrcOp.getValueSizeInBits() !=BitWidth) {
3520assert(SrcOp.getValueSizeInBits() >BitWidth &&
3521"Expected BUILD_VECTOR implicit truncation");
3522 Known2 = Known2.trunc(BitWidth);
3523 }
3524
3525// Known bits are the values that are shared by every demanded element.
3526 Known = Known.intersectWith(Known2);
3527
3528// If we don't know any bits, early out.
3529if (Known.isUnknown())
3530break;
3531 }
3532break;
3533caseISD::VECTOR_SHUFFLE: {
3534assert(!Op.getValueType().isScalableVector());
3535// Collect the known bits that are shared by every vector element referenced
3536// by the shuffle.
3537APInt DemandedLHS, DemandedRHS;
3538constShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(Op);
3539assert(NumElts == SVN->getMask().size() &&"Unexpected vector size");
3540if (!getShuffleDemandedElts(NumElts, SVN->getMask(), DemandedElts,
3541 DemandedLHS, DemandedRHS))
3542break;
3543
3544// Known bits are the values that are shared by every demanded element.
3545 Known.Zero.setAllBits(); Known.One.setAllBits();
3546if (!!DemandedLHS) {
3547SDValueLHS =Op.getOperand(0);
3548 Known2 =computeKnownBits(LHS, DemandedLHS,Depth + 1);
3549 Known = Known.intersectWith(Known2);
3550 }
3551// If we don't know any bits, early out.
3552if (Known.isUnknown())
3553break;
3554if (!!DemandedRHS) {
3555SDValueRHS =Op.getOperand(1);
3556 Known2 =computeKnownBits(RHS, DemandedRHS,Depth + 1);
3557 Known = Known.intersectWith(Known2);
3558 }
3559break;
3560 }
3561caseISD::VSCALE: {
3562constFunction &F =getMachineFunction().getFunction();
3563constAPInt &Multiplier =Op.getConstantOperandAPInt(0);
3564 Known =getVScaleRange(&F,BitWidth).multiply(Multiplier).toKnownBits();
3565break;
3566 }
3567caseISD::CONCAT_VECTORS: {
3568if (Op.getValueType().isScalableVector())
3569break;
3570// Split DemandedElts and test each of the demanded subvectors.
3571 Known.Zero.setAllBits(); Known.One.setAllBits();
3572EVT SubVectorVT =Op.getOperand(0).getValueType();
3573unsigned NumSubVectorElts = SubVectorVT.getVectorNumElements();
3574unsigned NumSubVectors =Op.getNumOperands();
3575for (unsigned i = 0; i != NumSubVectors; ++i) {
3576APInt DemandedSub =
3577 DemandedElts.extractBits(NumSubVectorElts, i * NumSubVectorElts);
3578if (!!DemandedSub) {
3579SDValue Sub =Op.getOperand(i);
3580 Known2 =computeKnownBits(Sub, DemandedSub,Depth + 1);
3581 Known = Known.intersectWith(Known2);
3582 }
3583// If we don't know any bits, early out.
3584if (Known.isUnknown())
3585break;
3586 }
3587break;
3588 }
3589caseISD::INSERT_SUBVECTOR: {
3590if (Op.getValueType().isScalableVector())
3591break;
3592// Demand any elements from the subvector and the remainder from the src its
3593// inserted into.
3594SDValue Src =Op.getOperand(0);
3595SDValue Sub =Op.getOperand(1);
3596uint64_tIdx =Op.getConstantOperandVal(2);
3597unsigned NumSubElts = Sub.getValueType().getVectorNumElements();
3598APInt DemandedSubElts = DemandedElts.extractBits(NumSubElts,Idx);
3599APInt DemandedSrcElts = DemandedElts;
3600 DemandedSrcElts.insertBits(APInt::getZero(NumSubElts),Idx);
3601
3602 Known.One.setAllBits();
3603 Known.Zero.setAllBits();
3604if (!!DemandedSubElts) {
3605 Known =computeKnownBits(Sub, DemandedSubElts,Depth + 1);
3606if (Known.isUnknown())
3607break;// early-out.
3608 }
3609if (!!DemandedSrcElts) {
3610 Known2 =computeKnownBits(Src, DemandedSrcElts,Depth + 1);
3611 Known = Known.intersectWith(Known2);
3612 }
3613break;
3614 }
3615caseISD::EXTRACT_SUBVECTOR: {
3616// Offset the demanded elts by the subvector index.
3617SDValue Src =Op.getOperand(0);
3618// Bail until we can represent demanded elements for scalable vectors.
3619if (Op.getValueType().isScalableVector() || Src.getValueType().isScalableVector())
3620break;
3621uint64_tIdx =Op.getConstantOperandVal(1);
3622unsigned NumSrcElts = Src.getValueType().getVectorNumElements();
3623APInt DemandedSrcElts = DemandedElts.zext(NumSrcElts).shl(Idx);
3624 Known =computeKnownBits(Src, DemandedSrcElts,Depth + 1);
3625break;
3626 }
3627caseISD::SCALAR_TO_VECTOR: {
3628if (Op.getValueType().isScalableVector())
3629break;
3630// We know about scalar_to_vector as much as we know about it source,
3631// which becomes the first element of otherwise unknown vector.
3632if (DemandedElts != 1)
3633break;
3634
3635SDValue N0 =Op.getOperand(0);
3636 Known =computeKnownBits(N0,Depth + 1);
3637if (N0.getValueSizeInBits() !=BitWidth)
3638 Known = Known.trunc(BitWidth);
3639
3640break;
3641 }
3642caseISD::BITCAST: {
3643if (Op.getValueType().isScalableVector())
3644break;
3645
3646SDValue N0 =Op.getOperand(0);
3647EVT SubVT = N0.getValueType();
3648unsigned SubBitWidth = SubVT.getScalarSizeInBits();
3649
3650// Ignore bitcasts from unsupported types.
3651if (!(SubVT.isInteger() || SubVT.isFloatingPoint()))
3652break;
3653
3654// Fast handling of 'identity' bitcasts.
3655if (BitWidth == SubBitWidth) {
3656 Known =computeKnownBits(N0, DemandedElts,Depth + 1);
3657break;
3658 }
3659
3660bool IsLE =getDataLayout().isLittleEndian();
3661
3662// Bitcast 'small element' vector to 'large element' scalar/vector.
3663if ((BitWidth % SubBitWidth) == 0) {
3664assert(N0.getValueType().isVector() &&"Expected bitcast from vector");
3665
3666// Collect known bits for the (larger) output by collecting the known
3667// bits from each set of sub elements and shift these into place.
3668// We need to separately call computeKnownBits for each set of
3669// sub elements as the knownbits for each is likely to be different.
3670unsigned SubScale =BitWidth / SubBitWidth;
3671APInt SubDemandedElts(NumElts * SubScale, 0);
3672for (unsigned i = 0; i != NumElts; ++i)
3673if (DemandedElts[i])
3674 SubDemandedElts.setBit(i * SubScale);
3675
3676for (unsigned i = 0; i != SubScale; ++i) {
3677 Known2 =computeKnownBits(N0, SubDemandedElts.shl(i),
3678Depth + 1);
3679unsigned Shifts = IsLE ? i : SubScale - 1 - i;
3680 Known.insertBits(Known2, SubBitWidth * Shifts);
3681 }
3682 }
3683
3684// Bitcast 'large element' scalar/vector to 'small element' vector.
3685if ((SubBitWidth %BitWidth) == 0) {
3686assert(Op.getValueType().isVector() &&"Expected bitcast to vector");
3687
3688// Collect known bits for the (smaller) output by collecting the known
3689// bits from the overlapping larger input elements and extracting the
3690// sub sections we actually care about.
3691unsigned SubScale = SubBitWidth /BitWidth;
3692APInt SubDemandedElts =
3693APIntOps::ScaleBitMask(DemandedElts, NumElts / SubScale);
3694 Known2 =computeKnownBits(N0, SubDemandedElts,Depth + 1);
3695
3696 Known.Zero.setAllBits(); Known.One.setAllBits();
3697for (unsigned i = 0; i != NumElts; ++i)
3698if (DemandedElts[i]) {
3699unsigned Shifts = IsLE ? i : NumElts - 1 - i;
3700unsignedOffset = (Shifts % SubScale) *BitWidth;
3701 Known = Known.intersectWith(Known2.extractBits(BitWidth,Offset));
3702// If we don't know any bits, early out.
3703if (Known.isUnknown())
3704break;
3705 }
3706 }
3707break;
3708 }
3709caseISD::AND:
3710 Known =computeKnownBits(Op.getOperand(1), DemandedElts,Depth + 1);
3711 Known2 =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
3712
3713 Known &= Known2;
3714break;
3715caseISD::OR:
3716 Known =computeKnownBits(Op.getOperand(1), DemandedElts,Depth + 1);
3717 Known2 =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
3718
3719 Known |= Known2;
3720break;
3721caseISD::XOR:
3722 Known =computeKnownBits(Op.getOperand(1), DemandedElts,Depth + 1);
3723 Known2 =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
3724
3725 Known ^= Known2;
3726break;
3727caseISD::MUL: {
3728 Known =computeKnownBits(Op.getOperand(1), DemandedElts,Depth + 1);
3729 Known2 =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
3730bool SelfMultiply =Op.getOperand(0) ==Op.getOperand(1);
3731// TODO: SelfMultiply can be poison, but not undef.
3732if (SelfMultiply)
3733 SelfMultiply &=isGuaranteedNotToBeUndefOrPoison(
3734Op.getOperand(0), DemandedElts,false,Depth + 1);
3735 Known =KnownBits::mul(Known, Known2, SelfMultiply);
3736
3737// If the multiplication is known not to overflow, the product of a number
3738// with itself is non-negative. Only do this if we didn't already computed
3739// the opposite value for the sign bit.
3740if (Op->getFlags().hasNoSignedWrap() &&
3741Op.getOperand(0) ==Op.getOperand(1) &&
3742 !Known.isNegative())
3743 Known.makeNonNegative();
3744break;
3745 }
3746caseISD::MULHU: {
3747 Known =computeKnownBits(Op.getOperand(1), DemandedElts,Depth + 1);
3748 Known2 =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
3749 Known =KnownBits::mulhu(Known, Known2);
3750break;
3751 }
3752caseISD::MULHS: {
3753 Known =computeKnownBits(Op.getOperand(1), DemandedElts,Depth + 1);
3754 Known2 =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
3755 Known =KnownBits::mulhs(Known, Known2);
3756break;
3757 }
3758caseISD::ABDU: {
3759 Known =computeKnownBits(Op.getOperand(1), DemandedElts,Depth + 1);
3760 Known2 =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
3761 Known =KnownBits::abdu(Known, Known2);
3762break;
3763 }
3764caseISD::ABDS: {
3765 Known =computeKnownBits(Op.getOperand(1), DemandedElts,Depth + 1);
3766 Known2 =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
3767 Known =KnownBits::abds(Known, Known2);
3768unsigned SignBits1 =
3769ComputeNumSignBits(Op.getOperand(1), DemandedElts,Depth + 1);
3770if (SignBits1 == 1)
3771break;
3772unsigned SignBits0 =
3773ComputeNumSignBits(Op.getOperand(0), DemandedElts,Depth + 1);
3774 Known.Zero.setHighBits(std::min(SignBits0, SignBits1) - 1);
3775break;
3776 }
3777caseISD::UMUL_LOHI: {
3778assert((Op.getResNo() == 0 ||Op.getResNo() == 1) &&"Unknown result");
3779 Known =computeKnownBits(Op.getOperand(1), DemandedElts,Depth + 1);
3780 Known2 =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
3781bool SelfMultiply =Op.getOperand(0) ==Op.getOperand(1);
3782if (Op.getResNo() == 0)
3783 Known =KnownBits::mul(Known, Known2, SelfMultiply);
3784else
3785 Known =KnownBits::mulhu(Known, Known2);
3786break;
3787 }
3788caseISD::SMUL_LOHI: {
3789assert((Op.getResNo() == 0 ||Op.getResNo() == 1) &&"Unknown result");
3790 Known =computeKnownBits(Op.getOperand(1), DemandedElts,Depth + 1);
3791 Known2 =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
3792bool SelfMultiply =Op.getOperand(0) ==Op.getOperand(1);
3793if (Op.getResNo() == 0)
3794 Known =KnownBits::mul(Known, Known2, SelfMultiply);
3795else
3796 Known =KnownBits::mulhs(Known, Known2);
3797break;
3798 }
3799caseISD::AVGFLOORU: {
3800 Known =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
3801 Known2 =computeKnownBits(Op.getOperand(1), DemandedElts,Depth + 1);
3802 Known =KnownBits::avgFloorU(Known, Known2);
3803break;
3804 }
3805caseISD::AVGCEILU: {
3806 Known =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
3807 Known2 =computeKnownBits(Op.getOperand(1), DemandedElts,Depth + 1);
3808 Known =KnownBits::avgCeilU(Known, Known2);
3809break;
3810 }
3811caseISD::AVGFLOORS: {
3812 Known =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
3813 Known2 =computeKnownBits(Op.getOperand(1), DemandedElts,Depth + 1);
3814 Known =KnownBits::avgFloorS(Known, Known2);
3815break;
3816 }
3817caseISD::AVGCEILS: {
3818 Known =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
3819 Known2 =computeKnownBits(Op.getOperand(1), DemandedElts,Depth + 1);
3820 Known =KnownBits::avgCeilS(Known, Known2);
3821break;
3822 }
3823caseISD::SELECT:
3824caseISD::VSELECT:
3825 Known =computeKnownBits(Op.getOperand(2), DemandedElts,Depth+1);
3826// If we don't know any bits, early out.
3827if (Known.isUnknown())
3828break;
3829 Known2 =computeKnownBits(Op.getOperand(1), DemandedElts,Depth+1);
3830
3831// Only known if known in both the LHS and RHS.
3832 Known = Known.intersectWith(Known2);
3833break;
3834caseISD::SELECT_CC:
3835 Known =computeKnownBits(Op.getOperand(3), DemandedElts,Depth+1);
3836// If we don't know any bits, early out.
3837if (Known.isUnknown())
3838break;
3839 Known2 =computeKnownBits(Op.getOperand(2), DemandedElts,Depth+1);
3840
3841// Only known if known in both the LHS and RHS.
3842 Known = Known.intersectWith(Known2);
3843break;
3844caseISD::SMULO:
3845caseISD::UMULO:
3846if (Op.getResNo() != 1)
3847break;
3848// The boolean result conforms to getBooleanContents.
3849// If we know the result of a setcc has the top bits zero, use this info.
3850// We know that we have an integer-based boolean since these operations
3851// are only available for integer.
3852if (TLI->getBooleanContents(Op.getValueType().isVector(),false) ==
3853TargetLowering::ZeroOrOneBooleanContent &&
3854BitWidth > 1)
3855 Known.Zero.setBitsFrom(1);
3856break;
3857caseISD::SETCC:
3858caseISD::SETCCCARRY:
3859caseISD::STRICT_FSETCC:
3860caseISD::STRICT_FSETCCS: {
3861unsigned OpNo =Op->isStrictFPOpcode() ? 1 : 0;
3862// If we know the result of a setcc has the top bits zero, use this info.
3863if (TLI->getBooleanContents(Op.getOperand(OpNo).getValueType()) ==
3864TargetLowering::ZeroOrOneBooleanContent &&
3865BitWidth > 1)
3866 Known.Zero.setBitsFrom(1);
3867break;
3868 }
3869caseISD::SHL: {
3870 Known =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
3871 Known2 =computeKnownBits(Op.getOperand(1), DemandedElts,Depth + 1);
3872
3873bool NUW =Op->getFlags().hasNoUnsignedWrap();
3874bool NSW =Op->getFlags().hasNoSignedWrap();
3875
3876bool ShAmtNonZero = Known2.isNonZero();
3877
3878 Known =KnownBits::shl(Known, Known2, NUW, NSW, ShAmtNonZero);
3879
3880// Minimum shift low bits are known zero.
3881if (std::optional<uint64_t> ShMinAmt =
3882getValidMinimumShiftAmount(Op, DemandedElts,Depth + 1))
3883 Known.Zero.setLowBits(*ShMinAmt);
3884break;
3885 }
3886caseISD::SRL:
3887 Known =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
3888 Known2 =computeKnownBits(Op.getOperand(1), DemandedElts,Depth + 1);
3889 Known =KnownBits::lshr(Known, Known2,/*ShAmtNonZero=*/false,
3890Op->getFlags().hasExact());
3891
3892// Minimum shift high bits are known zero.
3893if (std::optional<uint64_t> ShMinAmt =
3894getValidMinimumShiftAmount(Op, DemandedElts,Depth + 1))
3895 Known.Zero.setHighBits(*ShMinAmt);
3896break;
3897caseISD::SRA:
3898 Known =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
3899 Known2 =computeKnownBits(Op.getOperand(1), DemandedElts,Depth + 1);
3900 Known =KnownBits::ashr(Known, Known2,/*ShAmtNonZero=*/false,
3901Op->getFlags().hasExact());
3902break;
3903caseISD::FSHL:
3904caseISD::FSHR:
3905if (ConstantSDNode *C =isConstOrConstSplat(Op.getOperand(2), DemandedElts)) {
3906unsigned Amt =C->getAPIntValue().urem(BitWidth);
3907
3908// For fshl, 0-shift returns the 1st arg.
3909// For fshr, 0-shift returns the 2nd arg.
3910if (Amt == 0) {
3911 Known =computeKnownBits(Op.getOperand(Opcode ==ISD::FSHL ? 0 : 1),
3912 DemandedElts,Depth + 1);
3913break;
3914 }
3915
3916// fshl: (X << (Z % BW)) | (Y >> (BW - (Z % BW)))
3917// fshr: (X << (BW - (Z % BW))) | (Y >> (Z % BW))
3918 Known =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
3919 Known2 =computeKnownBits(Op.getOperand(1), DemandedElts,Depth + 1);
3920if (Opcode ==ISD::FSHL) {
3921 Known.One <<= Amt;
3922 Known.Zero <<= Amt;
3923 Known2.One.lshrInPlace(BitWidth - Amt);
3924 Known2.Zero.lshrInPlace(BitWidth - Amt);
3925 }else {
3926 Known.One <<=BitWidth - Amt;
3927 Known.Zero <<=BitWidth - Amt;
3928 Known2.One.lshrInPlace(Amt);
3929 Known2.Zero.lshrInPlace(Amt);
3930 }
3931 Known = Known.unionWith(Known2);
3932 }
3933break;
3934caseISD::SHL_PARTS:
3935caseISD::SRA_PARTS:
3936caseISD::SRL_PARTS: {
3937assert((Op.getResNo() == 0 ||Op.getResNo() == 1) &&"Unknown result");
3938
3939// Collect lo/hi source values and concatenate.
3940unsigned LoBits =Op.getOperand(0).getScalarValueSizeInBits();
3941unsigned HiBits =Op.getOperand(1).getScalarValueSizeInBits();
3942 Known =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
3943 Known2 =computeKnownBits(Op.getOperand(1), DemandedElts,Depth + 1);
3944 Known = Known2.concat(Known);
3945
3946// Collect shift amount.
3947 Known2 =computeKnownBits(Op.getOperand(2), DemandedElts,Depth + 1);
3948
3949if (Opcode ==ISD::SHL_PARTS)
3950 Known =KnownBits::shl(Known, Known2);
3951elseif (Opcode ==ISD::SRA_PARTS)
3952 Known =KnownBits::ashr(Known, Known2);
3953else// if (Opcode == ISD::SRL_PARTS)
3954 Known =KnownBits::lshr(Known, Known2);
3955
3956// TODO: Minimum shift low/high bits are known zero.
3957
3958if (Op.getResNo() == 0)
3959 Known = Known.extractBits(LoBits, 0);
3960else
3961 Known = Known.extractBits(HiBits, LoBits);
3962break;
3963 }
3964caseISD::SIGN_EXTEND_INREG: {
3965 Known =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
3966EVTEVT = cast<VTSDNode>(Op.getOperand(1))->getVT();
3967 Known = Known.sextInReg(EVT.getScalarSizeInBits());
3968break;
3969 }
3970caseISD::CTTZ:
3971caseISD::CTTZ_ZERO_UNDEF: {
3972 Known2 =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
3973// If we have a known 1, its position is our upper bound.
3974unsigned PossibleTZ = Known2.countMaxTrailingZeros();
3975unsigned LowBits =llvm::bit_width(PossibleTZ);
3976 Known.Zero.setBitsFrom(LowBits);
3977break;
3978 }
3979caseISD::CTLZ:
3980caseISD::CTLZ_ZERO_UNDEF: {
3981 Known2 =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
3982// If we have a known 1, its position is our upper bound.
3983unsigned PossibleLZ = Known2.countMaxLeadingZeros();
3984unsigned LowBits =llvm::bit_width(PossibleLZ);
3985 Known.Zero.setBitsFrom(LowBits);
3986break;
3987 }
3988caseISD::CTPOP: {
3989 Known2 =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
3990// If we know some of the bits are zero, they can't be one.
3991unsigned PossibleOnes = Known2.countMaxPopulation();
3992 Known.Zero.setBitsFrom(llvm::bit_width(PossibleOnes));
3993break;
3994 }
3995caseISD::PARITY: {
3996// Parity returns 0 everywhere but the LSB.
3997 Known.Zero.setBitsFrom(1);
3998break;
3999 }
4000caseISD::MGATHER:
4001caseISD::MLOAD: {
4002ISD::LoadExtType ETy =
4003 (Opcode ==ISD::MGATHER)
4004 ? cast<MaskedGatherSDNode>(Op)->getExtensionType()
4005 : cast<MaskedLoadSDNode>(Op)->getExtensionType();
4006if (ETy ==ISD::ZEXTLOAD) {
4007EVT MemVT = cast<MemSDNode>(Op)->getMemoryVT();
4008KnownBits Known0(MemVT.getScalarSizeInBits());
4009return Known0.zext(BitWidth);
4010 }
4011break;
4012 }
4013caseISD::LOAD: {
4014LoadSDNode *LD = cast<LoadSDNode>(Op);
4015constConstant *Cst = TLI->getTargetConstantFromLoad(LD);
4016if (ISD::isNON_EXTLoad(LD) && Cst) {
4017// Determine any common known bits from the loaded constant pool value.
4018Type *CstTy = Cst->getType();
4019if ((NumElts *BitWidth) == CstTy->getPrimitiveSizeInBits() &&
4020 !Op.getValueType().isScalableVector()) {
4021// If its a vector splat, then we can (quickly) reuse the scalar path.
4022// NOTE: We assume all elements match and none are UNDEF.
4023if (CstTy->isVectorTy()) {
4024if (constConstant *Splat = Cst->getSplatValue()) {
4025 Cst =Splat;
4026 CstTy = Cst->getType();
4027 }
4028 }
4029// TODO - do we need to handle different bitwidths?
4030if (CstTy->isVectorTy() &&BitWidth == CstTy->getScalarSizeInBits()) {
4031// Iterate across all vector elements finding common known bits.
4032 Known.One.setAllBits();
4033 Known.Zero.setAllBits();
4034for (unsigned i = 0; i != NumElts; ++i) {
4035if (!DemandedElts[i])
4036continue;
4037if (Constant *Elt = Cst->getAggregateElement(i)) {
4038if (auto *CInt = dyn_cast<ConstantInt>(Elt)) {
4039constAPInt &Value = CInt->getValue();
4040 Known.One &=Value;
4041 Known.Zero &=~Value;
4042continue;
4043 }
4044if (auto *CFP = dyn_cast<ConstantFP>(Elt)) {
4045APIntValue = CFP->getValueAPF().bitcastToAPInt();
4046 Known.One &=Value;
4047 Known.Zero &=~Value;
4048continue;
4049 }
4050 }
4051 Known.One.clearAllBits();
4052 Known.Zero.clearAllBits();
4053break;
4054 }
4055 }elseif (BitWidth == CstTy->getPrimitiveSizeInBits()) {
4056if (auto *CInt = dyn_cast<ConstantInt>(Cst)) {
4057 Known =KnownBits::makeConstant(CInt->getValue());
4058 }elseif (auto *CFP = dyn_cast<ConstantFP>(Cst)) {
4059 Known =
4060KnownBits::makeConstant(CFP->getValueAPF().bitcastToAPInt());
4061 }
4062 }
4063 }
4064 }elseif (Op.getResNo() == 0) {
4065KnownBits Known0(!LD->getMemoryVT().isScalableVT()
4066 ? LD->getMemoryVT().getFixedSizeInBits()
4067 :BitWidth);
4068EVT VT =Op.getValueType();
4069// Fill in any known bits from range information. There are 3 types being
4070// used. The results VT (same vector elt size as BitWidth), the loaded
4071// MemoryVT (which may or may not be vector) and the range VTs original
4072// type. The range matadata needs the full range (i.e
4073// MemoryVT().getSizeInBits()), which is truncated to the correct elt size
4074// if it is know. These are then extended to the original VT sizes below.
4075if (constMDNode *MD = LD->getRanges()) {
4076computeKnownBitsFromRangeMetadata(*MD, Known0);
4077if (VT.isVector()) {
4078// Handle truncation to the first demanded element.
4079// TODO: Figure out which demanded elements are covered
4080if (DemandedElts != 1 || !getDataLayout().isLittleEndian())
4081break;
4082 Known0 = Known0.trunc(BitWidth);
4083 }
4084 }
4085
4086if (LD->getMemoryVT().isVector())
4087 Known0 = Known0.trunc(LD->getMemoryVT().getScalarSizeInBits());
4088
4089// Extend the Known bits from memory to the size of the result.
4090if (ISD::isZEXTLoad(Op.getNode()))
4091 Known = Known0.zext(BitWidth);
4092elseif (ISD::isSEXTLoad(Op.getNode()))
4093 Known = Known0.sext(BitWidth);
4094elseif (ISD::isEXTLoad(Op.getNode()))
4095 Known = Known0.anyext(BitWidth);
4096else
4097 Known = Known0;
4098assert(Known.getBitWidth() ==BitWidth);
4099return Known;
4100 }
4101break;
4102 }
4103caseISD::ZERO_EXTEND_VECTOR_INREG: {
4104if (Op.getValueType().isScalableVector())
4105break;
4106EVT InVT =Op.getOperand(0).getValueType();
4107APInt InDemandedElts = DemandedElts.zext(InVT.getVectorNumElements());
4108 Known =computeKnownBits(Op.getOperand(0), InDemandedElts,Depth + 1);
4109 Known = Known.zext(BitWidth);
4110break;
4111 }
4112caseISD::ZERO_EXTEND: {
4113 Known =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
4114 Known = Known.zext(BitWidth);
4115break;
4116 }
4117caseISD::SIGN_EXTEND_VECTOR_INREG: {
4118if (Op.getValueType().isScalableVector())
4119break;
4120EVT InVT =Op.getOperand(0).getValueType();
4121APInt InDemandedElts = DemandedElts.zext(InVT.getVectorNumElements());
4122 Known =computeKnownBits(Op.getOperand(0), InDemandedElts,Depth + 1);
4123// If the sign bit is known to be zero or one, then sext will extend
4124// it to the top bits, else it will just zext.
4125 Known = Known.sext(BitWidth);
4126break;
4127 }
4128caseISD::SIGN_EXTEND: {
4129 Known =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
4130// If the sign bit is known to be zero or one, then sext will extend
4131// it to the top bits, else it will just zext.
4132 Known = Known.sext(BitWidth);
4133break;
4134 }
4135caseISD::ANY_EXTEND_VECTOR_INREG: {
4136if (Op.getValueType().isScalableVector())
4137break;
4138EVT InVT =Op.getOperand(0).getValueType();
4139APInt InDemandedElts = DemandedElts.zext(InVT.getVectorNumElements());
4140 Known =computeKnownBits(Op.getOperand(0), InDemandedElts,Depth + 1);
4141 Known = Known.anyext(BitWidth);
4142break;
4143 }
4144caseISD::ANY_EXTEND: {
4145 Known =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
4146 Known = Known.anyext(BitWidth);
4147break;
4148 }
4149caseISD::TRUNCATE: {
4150 Known =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
4151 Known = Known.trunc(BitWidth);
4152break;
4153 }
4154caseISD::AssertZext: {
4155EVT VT = cast<VTSDNode>(Op.getOperand(1))->getVT();
4156APInt InMask =APInt::getLowBitsSet(BitWidth, VT.getSizeInBits());
4157 Known =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
4158 Known.Zero |= (~InMask);
4159 Known.One &= (~Known.Zero);
4160break;
4161 }
4162caseISD::AssertAlign: {
4163unsigned LogOfAlign =Log2(cast<AssertAlignSDNode>(Op)->getAlign());
4164assert(LogOfAlign != 0);
4165
4166// TODO: Should use maximum with source
4167// If a node is guaranteed to be aligned, set low zero bits accordingly as
4168// well as clearing one bits.
4169 Known.Zero.setLowBits(LogOfAlign);
4170 Known.One.clearLowBits(LogOfAlign);
4171break;
4172 }
4173caseISD::FGETSIGN:
4174// All bits are zero except the low bit.
4175 Known.Zero.setBitsFrom(1);
4176break;
4177caseISD::ADD:
4178caseISD::SUB: {
4179SDNodeFlags Flags =Op.getNode()->getFlags();
4180 Known =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
4181 Known2 =computeKnownBits(Op.getOperand(1), DemandedElts,Depth + 1);
4182 Known =KnownBits::computeForAddSub(
4183Op.getOpcode() ==ISD::ADD, Flags.hasNoSignedWrap(),
4184 Flags.hasNoUnsignedWrap(), Known, Known2);
4185break;
4186 }
4187caseISD::USUBO:
4188caseISD::SSUBO:
4189caseISD::USUBO_CARRY:
4190caseISD::SSUBO_CARRY:
4191if (Op.getResNo() == 1) {
4192// If we know the result of a setcc has the top bits zero, use this info.
4193if (TLI->getBooleanContents(Op.getOperand(0).getValueType()) ==
4194TargetLowering::ZeroOrOneBooleanContent &&
4195BitWidth > 1)
4196 Known.Zero.setBitsFrom(1);
4197break;
4198 }
4199 [[fallthrough]];
4200caseISD::SUBC: {
4201assert(Op.getResNo() == 0 &&
4202"We only compute knownbits for the difference here.");
4203
4204// With USUBO_CARRY and SSUBO_CARRY a borrow bit may be added in.
4205KnownBits Borrow(1);
4206if (Opcode ==ISD::USUBO_CARRY || Opcode ==ISD::SSUBO_CARRY) {
4207 Borrow =computeKnownBits(Op.getOperand(2), DemandedElts,Depth + 1);
4208// Borrow has bit width 1
4209 Borrow = Borrow.trunc(1);
4210 }else {
4211 Borrow.setAllZero();
4212 }
4213
4214 Known =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
4215 Known2 =computeKnownBits(Op.getOperand(1), DemandedElts,Depth + 1);
4216 Known =KnownBits::computeForSubBorrow(Known, Known2, Borrow);
4217break;
4218 }
4219caseISD::UADDO:
4220caseISD::SADDO:
4221caseISD::UADDO_CARRY:
4222caseISD::SADDO_CARRY:
4223if (Op.getResNo() == 1) {
4224// If we know the result of a setcc has the top bits zero, use this info.
4225if (TLI->getBooleanContents(Op.getOperand(0).getValueType()) ==
4226TargetLowering::ZeroOrOneBooleanContent &&
4227BitWidth > 1)
4228 Known.Zero.setBitsFrom(1);
4229break;
4230 }
4231 [[fallthrough]];
4232caseISD::ADDC:
4233caseISD::ADDE: {
4234assert(Op.getResNo() == 0 &&"We only compute knownbits for the sum here.");
4235
4236// With ADDE and UADDO_CARRY, a carry bit may be added in.
4237KnownBits Carry(1);
4238if (Opcode ==ISD::ADDE)
4239// Can't track carry from glue, set carry to unknown.
4240 Carry.resetAll();
4241elseif (Opcode ==ISD::UADDO_CARRY || Opcode ==ISD::SADDO_CARRY) {
4242 Carry =computeKnownBits(Op.getOperand(2), DemandedElts,Depth + 1);
4243// Carry has bit width 1
4244 Carry = Carry.trunc(1);
4245 }else {
4246 Carry.setAllZero();
4247 }
4248
4249 Known =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
4250 Known2 =computeKnownBits(Op.getOperand(1), DemandedElts,Depth + 1);
4251 Known =KnownBits::computeForAddCarry(Known, Known2, Carry);
4252break;
4253 }
4254caseISD::UDIV: {
4255 Known =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
4256 Known2 =computeKnownBits(Op.getOperand(1), DemandedElts,Depth + 1);
4257 Known =KnownBits::udiv(Known, Known2,Op->getFlags().hasExact());
4258break;
4259 }
4260caseISD::SDIV: {
4261 Known =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
4262 Known2 =computeKnownBits(Op.getOperand(1), DemandedElts,Depth + 1);
4263 Known =KnownBits::sdiv(Known, Known2,Op->getFlags().hasExact());
4264break;
4265 }
4266caseISD::SREM: {
4267 Known =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
4268 Known2 =computeKnownBits(Op.getOperand(1), DemandedElts,Depth + 1);
4269 Known =KnownBits::srem(Known, Known2);
4270break;
4271 }
4272caseISD::UREM: {
4273 Known =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
4274 Known2 =computeKnownBits(Op.getOperand(1), DemandedElts,Depth + 1);
4275 Known =KnownBits::urem(Known, Known2);
4276break;
4277 }
4278caseISD::EXTRACT_ELEMENT: {
4279 Known =computeKnownBits(Op.getOperand(0),Depth+1);
4280constunsigned Index =Op.getConstantOperandVal(1);
4281constunsigned EltBitWidth =Op.getValueSizeInBits();
4282
4283// Remove low part of known bits mask
4284 Known.Zero = Known.Zero.getHiBits(Known.getBitWidth() - Index * EltBitWidth);
4285 Known.One = Known.One.getHiBits(Known.getBitWidth() - Index * EltBitWidth);
4286
4287// Remove high part of known bit mask
4288 Known = Known.trunc(EltBitWidth);
4289break;
4290 }
4291caseISD::EXTRACT_VECTOR_ELT: {
4292SDValue InVec =Op.getOperand(0);
4293SDValue EltNo =Op.getOperand(1);
4294EVT VecVT = InVec.getValueType();
4295// computeKnownBits not yet implemented for scalable vectors.
4296if (VecVT.isScalableVector())
4297break;
4298constunsigned EltBitWidth = VecVT.getScalarSizeInBits();
4299constunsigned NumSrcElts = VecVT.getVectorNumElements();
4300
4301// If BitWidth > EltBitWidth the value is anyext:ed. So we do not know
4302// anything about the extended bits.
4303if (BitWidth > EltBitWidth)
4304 Known = Known.trunc(EltBitWidth);
4305
4306// If we know the element index, just demand that vector element, else for
4307// an unknown element index, ignore DemandedElts and demand them all.
4308APInt DemandedSrcElts =APInt::getAllOnes(NumSrcElts);
4309auto *ConstEltNo = dyn_cast<ConstantSDNode>(EltNo);
4310if (ConstEltNo && ConstEltNo->getAPIntValue().ult(NumSrcElts))
4311 DemandedSrcElts =
4312APInt::getOneBitSet(NumSrcElts, ConstEltNo->getZExtValue());
4313
4314 Known =computeKnownBits(InVec, DemandedSrcElts,Depth + 1);
4315if (BitWidth > EltBitWidth)
4316 Known = Known.anyext(BitWidth);
4317break;
4318 }
4319caseISD::INSERT_VECTOR_ELT: {
4320if (Op.getValueType().isScalableVector())
4321break;
4322
4323// If we know the element index, split the demand between the
4324// source vector and the inserted element, otherwise assume we need
4325// the original demanded vector elements and the value.
4326SDValue InVec =Op.getOperand(0);
4327SDValue InVal =Op.getOperand(1);
4328SDValue EltNo =Op.getOperand(2);
4329bool DemandedVal =true;
4330APInt DemandedVecElts = DemandedElts;
4331auto *CEltNo = dyn_cast<ConstantSDNode>(EltNo);
4332if (CEltNo && CEltNo->getAPIntValue().ult(NumElts)) {
4333unsigned EltIdx = CEltNo->getZExtValue();
4334 DemandedVal = !!DemandedElts[EltIdx];
4335 DemandedVecElts.clearBit(EltIdx);
4336 }
4337 Known.One.setAllBits();
4338 Known.Zero.setAllBits();
4339if (DemandedVal) {
4340 Known2 =computeKnownBits(InVal,Depth + 1);
4341 Known = Known.intersectWith(Known2.zextOrTrunc(BitWidth));
4342 }
4343if (!!DemandedVecElts) {
4344 Known2 =computeKnownBits(InVec, DemandedVecElts,Depth + 1);
4345 Known = Known.intersectWith(Known2);
4346 }
4347break;
4348 }
4349caseISD::BITREVERSE: {
4350 Known2 =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
4351 Known = Known2.reverseBits();
4352break;
4353 }
4354caseISD::BSWAP: {
4355 Known2 =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
4356 Known = Known2.byteSwap();
4357break;
4358 }
4359caseISD::ABS: {
4360 Known2 =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
4361 Known = Known2.abs();
4362 Known.Zero.setHighBits(
4363ComputeNumSignBits(Op.getOperand(0), DemandedElts,Depth + 1) - 1);
4364break;
4365 }
4366caseISD::USUBSAT: {
4367 Known =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
4368 Known2 =computeKnownBits(Op.getOperand(1), DemandedElts,Depth + 1);
4369 Known =KnownBits::usub_sat(Known, Known2);
4370break;
4371 }
4372caseISD::UMIN: {
4373 Known =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
4374 Known2 =computeKnownBits(Op.getOperand(1), DemandedElts,Depth + 1);
4375 Known =KnownBits::umin(Known, Known2);
4376break;
4377 }
4378caseISD::UMAX: {
4379 Known =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
4380 Known2 =computeKnownBits(Op.getOperand(1), DemandedElts,Depth + 1);
4381 Known =KnownBits::umax(Known, Known2);
4382break;
4383 }
4384caseISD::SMIN:
4385caseISD::SMAX: {
4386// If we have a clamp pattern, we know that the number of sign bits will be
4387// the minimum of the clamp min/max range.
4388bool IsMax = (Opcode ==ISD::SMAX);
4389ConstantSDNode *CstLow =nullptr, *CstHigh =nullptr;
4390if ((CstLow =isConstOrConstSplat(Op.getOperand(1), DemandedElts)))
4391if (Op.getOperand(0).getOpcode() == (IsMax ?ISD::SMIN :ISD::SMAX))
4392 CstHigh =
4393isConstOrConstSplat(Op.getOperand(0).getOperand(1), DemandedElts);
4394if (CstLow && CstHigh) {
4395if (!IsMax)
4396std::swap(CstLow, CstHigh);
4397
4398constAPInt &ValueLow = CstLow->getAPIntValue();
4399constAPInt &ValueHigh = CstHigh->getAPIntValue();
4400if (ValueLow.sle(ValueHigh)) {
4401unsigned LowSignBits = ValueLow.getNumSignBits();
4402unsigned HighSignBits = ValueHigh.getNumSignBits();
4403unsigned MinSignBits = std::min(LowSignBits, HighSignBits);
4404if (ValueLow.isNegative() && ValueHigh.isNegative()) {
4405 Known.One.setHighBits(MinSignBits);
4406break;
4407 }
4408if (ValueLow.isNonNegative() && ValueHigh.isNonNegative()) {
4409 Known.Zero.setHighBits(MinSignBits);
4410break;
4411 }
4412 }
4413 }
4414
4415 Known =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
4416 Known2 =computeKnownBits(Op.getOperand(1), DemandedElts,Depth + 1);
4417if (IsMax)
4418 Known =KnownBits::smax(Known, Known2);
4419else
4420 Known =KnownBits::smin(Known, Known2);
4421
4422// For SMAX, if CstLow is non-negative we know the result will be
4423// non-negative and thus all sign bits are 0.
4424// TODO: There's an equivalent of this for smin with negative constant for
4425// known ones.
4426if (IsMax && CstLow) {
4427constAPInt &ValueLow = CstLow->getAPIntValue();
4428if (ValueLow.isNonNegative()) {
4429unsigned SignBits =ComputeNumSignBits(Op.getOperand(0),Depth + 1);
4430 Known.Zero.setHighBits(std::min(SignBits, ValueLow.getNumSignBits()));
4431 }
4432 }
4433
4434break;
4435 }
4436caseISD::UINT_TO_FP: {
4437 Known.makeNonNegative();
4438break;
4439 }
4440caseISD::SINT_TO_FP: {
4441 Known2 =computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
4442if (Known2.isNonNegative())
4443 Known.makeNonNegative();
4444elseif (Known2.isNegative())
4445 Known.makeNegative();
4446break;
4447 }
4448caseISD::FP_TO_UINT_SAT: {
4449// FP_TO_UINT_SAT produces an unsigned value that fits in the saturating VT.
4450EVT VT = cast<VTSDNode>(Op.getOperand(1))->getVT();
4451 Known.Zero |=APInt::getBitsSetFrom(BitWidth, VT.getScalarSizeInBits());
4452break;
4453 }
4454caseISD::ATOMIC_CMP_SWAP_WITH_SUCCESS:
4455if (Op.getResNo() == 1) {
4456// The boolean result conforms to getBooleanContents.
4457// If we know the result of a setcc has the top bits zero, use this info.
4458// We know that we have an integer-based boolean since these operations
4459// are only available for integer.
4460if (TLI->getBooleanContents(Op.getValueType().isVector(),false) ==
4461TargetLowering::ZeroOrOneBooleanContent &&
4462BitWidth > 1)
4463 Known.Zero.setBitsFrom(1);
4464break;
4465 }
4466 [[fallthrough]];
4467caseISD::ATOMIC_CMP_SWAP:
4468caseISD::ATOMIC_SWAP:
4469caseISD::ATOMIC_LOAD_ADD:
4470caseISD::ATOMIC_LOAD_SUB:
4471caseISD::ATOMIC_LOAD_AND:
4472caseISD::ATOMIC_LOAD_CLR:
4473caseISD::ATOMIC_LOAD_OR:
4474caseISD::ATOMIC_LOAD_XOR:
4475caseISD::ATOMIC_LOAD_NAND:
4476caseISD::ATOMIC_LOAD_MIN:
4477caseISD::ATOMIC_LOAD_MAX:
4478caseISD::ATOMIC_LOAD_UMIN:
4479caseISD::ATOMIC_LOAD_UMAX:
4480caseISD::ATOMIC_LOAD: {
4481unsigned MemBits =
4482 cast<AtomicSDNode>(Op)->getMemoryVT().getScalarSizeInBits();
4483// If we are looking at the loaded value.
4484if (Op.getResNo() == 0) {
4485if (TLI->getExtendForAtomicOps() ==ISD::ZERO_EXTEND)
4486 Known.Zero.setBitsFrom(MemBits);
4487elseif (Op->getOpcode() ==ISD::ATOMIC_LOAD &&
4488 cast<AtomicSDNode>(Op)->getExtensionType() ==ISD::ZEXTLOAD)
4489 Known.Zero.setBitsFrom(MemBits);
4490 }
4491break;
4492 }
4493caseISD::FrameIndex:
4494caseISD::TargetFrameIndex:
4495 TLI->computeKnownBitsForFrameIndex(cast<FrameIndexSDNode>(Op)->getIndex(),
4496 Known,getMachineFunction());
4497break;
4498
4499default:
4500if (Opcode <ISD::BUILTIN_OP_END)
4501break;
4502 [[fallthrough]];
4503caseISD::INTRINSIC_WO_CHAIN:
4504caseISD::INTRINSIC_W_CHAIN:
4505caseISD::INTRINSIC_VOID:
4506// TODO: Probably okay to remove after audit; here to reduce change size
4507// in initial enablement patch for scalable vectors
4508if (Op.getValueType().isScalableVector())
4509break;
4510
4511// Allow the target to implement this method for its nodes.
4512 TLI->computeKnownBitsForTargetNode(Op, Known, DemandedElts, *this,Depth);
4513break;
4514 }
4515
4516return Known;
4517}
4518
4519/// Convert ConstantRange OverflowResult into SelectionDAG::OverflowKind.
4520staticSelectionDAG::OverflowKindmapOverflowResult(ConstantRange::OverflowResult OR) {
4521switch (OR) {
4522caseConstantRange::OverflowResult::MayOverflow:
4523returnSelectionDAG::OFK_Sometime;
4524caseConstantRange::OverflowResult::AlwaysOverflowsLow:
4525caseConstantRange::OverflowResult::AlwaysOverflowsHigh:
4526returnSelectionDAG::OFK_Always;
4527caseConstantRange::OverflowResult::NeverOverflows:
4528returnSelectionDAG::OFK_Never;
4529 }
4530llvm_unreachable("Unknown OverflowResult");
4531}
4532
4533SelectionDAG::OverflowKind
4534SelectionDAG::computeOverflowForSignedAdd(SDValue N0,SDValue N1) const{
4535// X + 0 never overflow
4536if (isNullConstant(N1))
4537returnOFK_Never;
4538
4539// If both operands each have at least two sign bits, the addition
4540// cannot overflow.
4541if (ComputeNumSignBits(N0) > 1 &&ComputeNumSignBits(N1) > 1)
4542returnOFK_Never;
4543
4544// TODO: Add ConstantRange::signedAddMayOverflow handling.
4545returnOFK_Sometime;
4546}
4547
4548SelectionDAG::OverflowKind
4549SelectionDAG::computeOverflowForUnsignedAdd(SDValue N0,SDValue N1) const{
4550// X + 0 never overflow
4551if (isNullConstant(N1))
4552returnOFK_Never;
4553
4554// mulhi + 1 never overflow
4555KnownBits N1Known =computeKnownBits(N1);
4556if (N0.getOpcode() ==ISD::UMUL_LOHI && N0.getResNo() == 1 &&
4557 N1Known.getMaxValue().ult(2))
4558returnOFK_Never;
4559
4560KnownBits N0Known =computeKnownBits(N0);
4561if (N1.getOpcode() ==ISD::UMUL_LOHI && N1.getResNo() == 1 &&
4562 N0Known.getMaxValue().ult(2))
4563returnOFK_Never;
4564
4565// Fallback to ConstantRange::unsignedAddMayOverflow handling.
4566ConstantRange N0Range =ConstantRange::fromKnownBits(N0Known,false);
4567ConstantRange N1Range =ConstantRange::fromKnownBits(N1Known,false);
4568returnmapOverflowResult(N0Range.unsignedAddMayOverflow(N1Range));
4569}
4570
4571SelectionDAG::OverflowKind
4572SelectionDAG::computeOverflowForSignedSub(SDValue N0,SDValue N1) const{
4573// X - 0 never overflow
4574if (isNullConstant(N1))
4575returnOFK_Never;
4576
4577// If both operands each have at least two sign bits, the subtraction
4578// cannot overflow.
4579if (ComputeNumSignBits(N0) > 1 &&ComputeNumSignBits(N1) > 1)
4580returnOFK_Never;
4581
4582KnownBits N0Known =computeKnownBits(N0);
4583KnownBits N1Known =computeKnownBits(N1);
4584ConstantRange N0Range =ConstantRange::fromKnownBits(N0Known,true);
4585ConstantRange N1Range =ConstantRange::fromKnownBits(N1Known,true);
4586returnmapOverflowResult(N0Range.signedSubMayOverflow(N1Range));
4587}
4588
4589SelectionDAG::OverflowKind
4590SelectionDAG::computeOverflowForUnsignedSub(SDValue N0,SDValue N1) const{
4591// X - 0 never overflow
4592if (isNullConstant(N1))
4593returnOFK_Never;
4594
4595KnownBits N0Known =computeKnownBits(N0);
4596KnownBits N1Known =computeKnownBits(N1);
4597ConstantRange N0Range =ConstantRange::fromKnownBits(N0Known,false);
4598ConstantRange N1Range =ConstantRange::fromKnownBits(N1Known,false);
4599returnmapOverflowResult(N0Range.unsignedSubMayOverflow(N1Range));
4600}
4601
4602SelectionDAG::OverflowKind
4603SelectionDAG::computeOverflowForUnsignedMul(SDValue N0,SDValue N1) const{
4604// X * 0 and X * 1 never overflow.
4605if (isNullConstant(N1) ||isOneConstant(N1))
4606returnOFK_Never;
4607
4608KnownBits N0Known =computeKnownBits(N0);
4609KnownBits N1Known =computeKnownBits(N1);
4610ConstantRange N0Range =ConstantRange::fromKnownBits(N0Known,false);
4611ConstantRange N1Range =ConstantRange::fromKnownBits(N1Known,false);
4612returnmapOverflowResult(N0Range.unsignedMulMayOverflow(N1Range));
4613}
4614
4615SelectionDAG::OverflowKind
4616SelectionDAG::computeOverflowForSignedMul(SDValue N0,SDValue N1) const{
4617// X * 0 and X * 1 never overflow.
4618if (isNullConstant(N1) ||isOneConstant(N1))
4619returnOFK_Never;
4620
4621// Get the size of the result.
4622unsignedBitWidth = N0.getScalarValueSizeInBits();
4623
4624// Sum of the sign bits.
4625unsigned SignBits =ComputeNumSignBits(N0) +ComputeNumSignBits(N1);
4626
4627// If we have enough sign bits, then there's no overflow.
4628if (SignBits >BitWidth + 1)
4629returnOFK_Never;
4630
4631if (SignBits ==BitWidth + 1) {
4632// The overflow occurs when the true multiplication of the
4633// the operands is the minimum negative number.
4634KnownBits N0Known =computeKnownBits(N0);
4635KnownBits N1Known =computeKnownBits(N1);
4636// If one of the operands is non-negative, then there's no
4637// overflow.
4638if (N0Known.isNonNegative() || N1Known.isNonNegative())
4639returnOFK_Never;
4640 }
4641
4642returnOFK_Sometime;
4643}
4644
4645boolSelectionDAG::isKnownToBeAPowerOfTwo(SDValue Val,unsignedDepth) const{
4646if (Depth >=MaxRecursionDepth)
4647returnfalse;// Limit search depth.
4648
4649EVT OpVT = Val.getValueType();
4650unsignedBitWidth = OpVT.getScalarSizeInBits();
4651
4652// Is the constant a known power of 2?
4653if (ISD::matchUnaryPredicate(Val, [BitWidth](ConstantSDNode *C) {
4654returnC->getAPIntValue().zextOrTrunc(BitWidth).isPowerOf2();
4655 }))
4656returntrue;
4657
4658// A left-shift of a constant one will have exactly one bit set because
4659// shifting the bit off the end is undefined.
4660if (Val.getOpcode() ==ISD::SHL) {
4661auto *C =isConstOrConstSplat(Val.getOperand(0));
4662if (C &&C->getAPIntValue() == 1)
4663returntrue;
4664returnisKnownToBeAPowerOfTwo(Val.getOperand(0),Depth + 1) &&
4665isKnownNeverZero(Val,Depth);
4666 }
4667
4668// Similarly, a logical right-shift of a constant sign-bit will have exactly
4669// one bit set.
4670if (Val.getOpcode() ==ISD::SRL) {
4671auto *C =isConstOrConstSplat(Val.getOperand(0));
4672if (C &&C->getAPIntValue().isSignMask())
4673returntrue;
4674returnisKnownToBeAPowerOfTwo(Val.getOperand(0),Depth + 1) &&
4675isKnownNeverZero(Val,Depth);
4676 }
4677
4678if (Val.getOpcode() ==ISD::ROTL || Val.getOpcode() ==ISD::ROTR)
4679returnisKnownToBeAPowerOfTwo(Val.getOperand(0),Depth + 1);
4680
4681// Are all operands of a build vector constant powers of two?
4682if (Val.getOpcode() ==ISD::BUILD_VECTOR)
4683if (llvm::all_of(Val->ops(), [BitWidth](SDValue E) {
4684 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(E))
4685 return C->getAPIntValue().zextOrTrunc(BitWidth).isPowerOf2();
4686 return false;
4687 }))
4688returntrue;
4689
4690// Is the operand of a splat vector a constant power of two?
4691if (Val.getOpcode() ==ISD::SPLAT_VECTOR)
4692if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Val->getOperand(0)))
4693if (C->getAPIntValue().zextOrTrunc(BitWidth).isPowerOf2())
4694returntrue;
4695
4696// vscale(power-of-two) is a power-of-two for some targets
4697if (Val.getOpcode() ==ISD::VSCALE &&
4698getTargetLoweringInfo().isVScaleKnownToBeAPowerOfTwo() &&
4699isKnownToBeAPowerOfTwo(Val.getOperand(0),Depth + 1))
4700returntrue;
4701
4702if (Val.getOpcode() ==ISD::SMIN || Val.getOpcode() ==ISD::SMAX ||
4703 Val.getOpcode() ==ISD::UMIN || Val.getOpcode() ==ISD::UMAX)
4704returnisKnownToBeAPowerOfTwo(Val.getOperand(1),Depth + 1) &&
4705isKnownToBeAPowerOfTwo(Val.getOperand(0),Depth + 1);
4706
4707if (Val.getOpcode() ==ISD::SELECT || Val.getOpcode() ==ISD::VSELECT)
4708returnisKnownToBeAPowerOfTwo(Val.getOperand(2),Depth + 1) &&
4709isKnownToBeAPowerOfTwo(Val.getOperand(1),Depth + 1);
4710
4711// Looking for `x & -x` pattern:
4712// If x == 0:
4713// x & -x -> 0
4714// If x != 0:
4715// x & -x -> non-zero pow2
4716// so if we find the pattern return whether we know `x` is non-zero.
4717SDValueX;
4718if (sd_match(Val,m_And(m_Value(X),m_Neg(m_Deferred(X)))))
4719returnisKnownNeverZero(X,Depth);
4720
4721if (Val.getOpcode() ==ISD::ZERO_EXTEND)
4722returnisKnownToBeAPowerOfTwo(Val.getOperand(0),Depth + 1);
4723
4724// More could be done here, though the above checks are enough
4725// to handle some common cases.
4726returnfalse;
4727}
4728
4729boolSelectionDAG::isKnownToBeAPowerOfTwoFP(SDValue Val,unsignedDepth) const{
4730if (ConstantFPSDNode *C1 =isConstOrConstSplatFP(Val,true))
4731return C1->getValueAPF().getExactLog2Abs() >= 0;
4732
4733if (Val.getOpcode() ==ISD::UINT_TO_FP || Val.getOpcode() ==ISD::SINT_TO_FP)
4734returnisKnownToBeAPowerOfTwo(Val.getOperand(0),Depth + 1);
4735
4736returnfalse;
4737}
4738
4739unsignedSelectionDAG::ComputeNumSignBits(SDValueOp,unsignedDepth) const{
4740EVT VT =Op.getValueType();
4741
4742// Since the number of lanes in a scalable vector is unknown at compile time,
4743// we track one bit which is implicitly broadcast to all lanes. This means
4744// that all lanes in a scalable vector are considered demanded.
4745APInt DemandedElts = VT.isFixedLengthVector()
4746 ?APInt::getAllOnes(VT.getVectorNumElements())
4747 :APInt(1, 1);
4748returnComputeNumSignBits(Op, DemandedElts,Depth);
4749}
4750
4751unsignedSelectionDAG::ComputeNumSignBits(SDValueOp,constAPInt &DemandedElts,
4752unsignedDepth) const{
4753EVT VT =Op.getValueType();
4754assert((VT.isInteger() || VT.isFloatingPoint()) &&"Invalid VT!");
4755unsigned VTBits = VT.getScalarSizeInBits();
4756unsigned NumElts = DemandedElts.getBitWidth();
4757unsigned Tmp, Tmp2;
4758unsigned FirstAnswer = 1;
4759
4760if (auto *C = dyn_cast<ConstantSDNode>(Op)) {
4761constAPInt &Val =C->getAPIntValue();
4762return Val.getNumSignBits();
4763 }
4764
4765if (Depth >=MaxRecursionDepth)
4766return 1;// Limit search depth.
4767
4768if (!DemandedElts)
4769return 1;// No demanded elts, better to assume we don't know anything.
4770
4771unsigned Opcode =Op.getOpcode();
4772switch (Opcode) {
4773default:break;
4774caseISD::AssertSext:
4775 Tmp = cast<VTSDNode>(Op.getOperand(1))->getVT().getSizeInBits();
4776return VTBits-Tmp+1;
4777caseISD::AssertZext:
4778 Tmp = cast<VTSDNode>(Op.getOperand(1))->getVT().getSizeInBits();
4779return VTBits-Tmp;
4780caseISD::MERGE_VALUES:
4781returnComputeNumSignBits(Op.getOperand(Op.getResNo()), DemandedElts,
4782Depth + 1);
4783caseISD::SPLAT_VECTOR: {
4784// Check if the sign bits of source go down as far as the truncated value.
4785unsigned NumSrcBits =Op.getOperand(0).getValueSizeInBits();
4786unsigned NumSrcSignBits =ComputeNumSignBits(Op.getOperand(0),Depth + 1);
4787if (NumSrcSignBits > (NumSrcBits - VTBits))
4788return NumSrcSignBits - (NumSrcBits - VTBits);
4789break;
4790 }
4791caseISD::BUILD_VECTOR:
4792assert(!VT.isScalableVector());
4793 Tmp = VTBits;
4794for (unsigned i = 0, e =Op.getNumOperands(); (i < e) && (Tmp > 1); ++i) {
4795if (!DemandedElts[i])
4796continue;
4797
4798SDValueSrcOp =Op.getOperand(i);
4799// BUILD_VECTOR can implicitly truncate sources, we handle this specially
4800// for constant nodes to ensure we only look at the sign bits.
4801if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(SrcOp)) {
4802APIntT =C->getAPIntValue().trunc(VTBits);
4803 Tmp2 =T.getNumSignBits();
4804 }else {
4805 Tmp2 =ComputeNumSignBits(SrcOp,Depth + 1);
4806
4807if (SrcOp.getValueSizeInBits() != VTBits) {
4808assert(SrcOp.getValueSizeInBits() > VTBits &&
4809"Expected BUILD_VECTOR implicit truncation");
4810unsigned ExtraBits =SrcOp.getValueSizeInBits() - VTBits;
4811 Tmp2 = (Tmp2 > ExtraBits ? Tmp2 - ExtraBits : 1);
4812 }
4813 }
4814 Tmp = std::min(Tmp, Tmp2);
4815 }
4816return Tmp;
4817
4818caseISD::VECTOR_SHUFFLE: {
4819// Collect the minimum number of sign bits that are shared by every vector
4820// element referenced by the shuffle.
4821APInt DemandedLHS, DemandedRHS;
4822constShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(Op);
4823assert(NumElts == SVN->getMask().size() &&"Unexpected vector size");
4824if (!getShuffleDemandedElts(NumElts, SVN->getMask(), DemandedElts,
4825 DemandedLHS, DemandedRHS))
4826return 1;
4827
4828 Tmp = std::numeric_limits<unsigned>::max();
4829if (!!DemandedLHS)
4830 Tmp =ComputeNumSignBits(Op.getOperand(0), DemandedLHS,Depth + 1);
4831if (!!DemandedRHS) {
4832 Tmp2 =ComputeNumSignBits(Op.getOperand(1), DemandedRHS,Depth + 1);
4833 Tmp = std::min(Tmp, Tmp2);
4834 }
4835// If we don't know anything, early out and try computeKnownBits fall-back.
4836if (Tmp == 1)
4837break;
4838assert(Tmp <= VTBits &&"Failed to determine minimum sign bits");
4839return Tmp;
4840 }
4841
4842caseISD::BITCAST: {
4843if (VT.isScalableVector())
4844break;
4845SDValue N0 =Op.getOperand(0);
4846EVT SrcVT = N0.getValueType();
4847unsigned SrcBits = SrcVT.getScalarSizeInBits();
4848
4849// Ignore bitcasts from unsupported types..
4850if (!(SrcVT.isInteger() || SrcVT.isFloatingPoint()))
4851break;
4852
4853// Fast handling of 'identity' bitcasts.
4854if (VTBits == SrcBits)
4855returnComputeNumSignBits(N0, DemandedElts,Depth + 1);
4856
4857bool IsLE =getDataLayout().isLittleEndian();
4858
4859// Bitcast 'large element' scalar/vector to 'small element' vector.
4860if ((SrcBits % VTBits) == 0) {
4861assert(VT.isVector() &&"Expected bitcast to vector");
4862
4863unsigned Scale = SrcBits / VTBits;
4864APInt SrcDemandedElts =
4865APIntOps::ScaleBitMask(DemandedElts, NumElts / Scale);
4866
4867// Fast case - sign splat can be simply split across the small elements.
4868 Tmp =ComputeNumSignBits(N0, SrcDemandedElts,Depth + 1);
4869if (Tmp == SrcBits)
4870return VTBits;
4871
4872// Slow case - determine how far the sign extends into each sub-element.
4873 Tmp2 = VTBits;
4874for (unsigned i = 0; i != NumElts; ++i)
4875if (DemandedElts[i]) {
4876unsigned SubOffset = i % Scale;
4877 SubOffset = (IsLE ? ((Scale - 1) - SubOffset) : SubOffset);
4878 SubOffset = SubOffset * VTBits;
4879if (Tmp <= SubOffset)
4880return 1;
4881 Tmp2 = std::min(Tmp2, Tmp - SubOffset);
4882 }
4883return Tmp2;
4884 }
4885break;
4886 }
4887
4888caseISD::FP_TO_SINT_SAT:
4889// FP_TO_SINT_SAT produces a signed value that fits in the saturating VT.
4890 Tmp = cast<VTSDNode>(Op.getOperand(1))->getVT().getScalarSizeInBits();
4891return VTBits - Tmp + 1;
4892caseISD::SIGN_EXTEND:
4893 Tmp = VTBits -Op.getOperand(0).getScalarValueSizeInBits();
4894returnComputeNumSignBits(Op.getOperand(0), DemandedElts,Depth+1) + Tmp;
4895caseISD::SIGN_EXTEND_INREG:
4896// Max of the input and what this extends.
4897 Tmp = cast<VTSDNode>(Op.getOperand(1))->getVT().getScalarSizeInBits();
4898 Tmp = VTBits-Tmp+1;
4899 Tmp2 =ComputeNumSignBits(Op.getOperand(0), DemandedElts,Depth+1);
4900return std::max(Tmp, Tmp2);
4901caseISD::SIGN_EXTEND_VECTOR_INREG: {
4902if (VT.isScalableVector())
4903break;
4904SDValue Src =Op.getOperand(0);
4905EVT SrcVT = Src.getValueType();
4906APInt DemandedSrcElts = DemandedElts.zext(SrcVT.getVectorNumElements());
4907 Tmp = VTBits - SrcVT.getScalarSizeInBits();
4908returnComputeNumSignBits(Src, DemandedSrcElts,Depth+1) + Tmp;
4909 }
4910caseISD::SRA:
4911 Tmp =ComputeNumSignBits(Op.getOperand(0), DemandedElts,Depth + 1);
4912// SRA X, C -> adds C sign bits.
4913if (std::optional<uint64_t> ShAmt =
4914getValidMinimumShiftAmount(Op, DemandedElts,Depth + 1))
4915 Tmp = std::min<uint64_t>(Tmp + *ShAmt, VTBits);
4916return Tmp;
4917caseISD::SHL:
4918if (std::optional<ConstantRange> ShAmtRange =
4919getValidShiftAmountRange(Op, DemandedElts,Depth + 1)) {
4920uint64_t MaxShAmt = ShAmtRange->getUnsignedMax().getZExtValue();
4921uint64_t MinShAmt = ShAmtRange->getUnsignedMin().getZExtValue();
4922// Try to look through ZERO/SIGN/ANY_EXTEND. If all extended bits are
4923// shifted out, then we can compute the number of sign bits for the
4924// operand being extended. A future improvement could be to pass along the
4925// "shifted left by" information in the recursive calls to
4926// ComputeKnownSignBits. Allowing us to handle this more generically.
4927if (ISD::isExtOpcode(Op.getOperand(0).getOpcode())) {
4928SDValue Ext =Op.getOperand(0);
4929EVT ExtVT = Ext.getValueType();
4930SDValue Extendee = Ext.getOperand(0);
4931EVT ExtendeeVT = Extendee.getValueType();
4932uint64_t SizeDifference =
4933 ExtVT.getScalarSizeInBits() - ExtendeeVT.getScalarSizeInBits();
4934if (SizeDifference <= MinShAmt) {
4935 Tmp = SizeDifference +
4936ComputeNumSignBits(Extendee, DemandedElts,Depth + 1);
4937if (MaxShAmt < Tmp)
4938return Tmp - MaxShAmt;
4939 }
4940 }
4941// shl destroys sign bits, ensure it doesn't shift out all sign bits.
4942 Tmp =ComputeNumSignBits(Op.getOperand(0), DemandedElts,Depth + 1);
4943if (MaxShAmt < Tmp)
4944return Tmp - MaxShAmt;
4945 }
4946break;
4947caseISD::AND:
4948caseISD::OR:
4949caseISD::XOR:// NOT is handled here.
4950// Logical binary ops preserve the number of sign bits at the worst.
4951 Tmp =ComputeNumSignBits(Op.getOperand(0), DemandedElts,Depth+1);
4952if (Tmp != 1) {
4953 Tmp2 =ComputeNumSignBits(Op.getOperand(1), DemandedElts,Depth+1);
4954 FirstAnswer = std::min(Tmp, Tmp2);
4955// We computed what we know about the sign bits as our first
4956// answer. Now proceed to the generic code that uses
4957// computeKnownBits, and pick whichever answer is better.
4958 }
4959break;
4960
4961caseISD::SELECT:
4962caseISD::VSELECT:
4963 Tmp =ComputeNumSignBits(Op.getOperand(1), DemandedElts,Depth+1);
4964if (Tmp == 1)return 1;// Early out.
4965 Tmp2 =ComputeNumSignBits(Op.getOperand(2), DemandedElts,Depth+1);
4966return std::min(Tmp, Tmp2);
4967caseISD::SELECT_CC:
4968 Tmp =ComputeNumSignBits(Op.getOperand(2), DemandedElts,Depth+1);
4969if (Tmp == 1)return 1;// Early out.
4970 Tmp2 =ComputeNumSignBits(Op.getOperand(3), DemandedElts,Depth+1);
4971return std::min(Tmp, Tmp2);
4972
4973caseISD::SMIN:
4974caseISD::SMAX: {
4975// If we have a clamp pattern, we know that the number of sign bits will be
4976// the minimum of the clamp min/max range.
4977bool IsMax = (Opcode ==ISD::SMAX);
4978ConstantSDNode *CstLow =nullptr, *CstHigh =nullptr;
4979if ((CstLow =isConstOrConstSplat(Op.getOperand(1), DemandedElts)))
4980if (Op.getOperand(0).getOpcode() == (IsMax ?ISD::SMIN :ISD::SMAX))
4981 CstHigh =
4982isConstOrConstSplat(Op.getOperand(0).getOperand(1), DemandedElts);
4983if (CstLow && CstHigh) {
4984if (!IsMax)
4985std::swap(CstLow, CstHigh);
4986if (CstLow->getAPIntValue().sle(CstHigh->getAPIntValue())) {
4987 Tmp = CstLow->getAPIntValue().getNumSignBits();
4988 Tmp2 = CstHigh->getAPIntValue().getNumSignBits();
4989return std::min(Tmp, Tmp2);
4990 }
4991 }
4992
4993// Fallback - just get the minimum number of sign bits of the operands.
4994 Tmp =ComputeNumSignBits(Op.getOperand(0), DemandedElts,Depth + 1);
4995if (Tmp == 1)
4996return 1;// Early out.
4997 Tmp2 =ComputeNumSignBits(Op.getOperand(1), DemandedElts,Depth + 1);
4998return std::min(Tmp, Tmp2);
4999 }
5000caseISD::UMIN:
5001caseISD::UMAX:
5002 Tmp =ComputeNumSignBits(Op.getOperand(0), DemandedElts,Depth + 1);
5003if (Tmp == 1)
5004return 1;// Early out.
5005 Tmp2 =ComputeNumSignBits(Op.getOperand(1), DemandedElts,Depth + 1);
5006return std::min(Tmp, Tmp2);
5007caseISD::SSUBO_CARRY:
5008caseISD::USUBO_CARRY:
5009// sub_carry(x,x,c) -> 0/-1 (sext carry)
5010if (Op.getResNo() == 0 &&Op.getOperand(0) ==Op.getOperand(1))
5011return VTBits;
5012 [[fallthrough]];
5013caseISD::SADDO:
5014caseISD::UADDO:
5015caseISD::SADDO_CARRY:
5016caseISD::UADDO_CARRY:
5017caseISD::SSUBO:
5018caseISD::USUBO:
5019caseISD::SMULO:
5020caseISD::UMULO:
5021if (Op.getResNo() != 1)
5022break;
5023// The boolean result conforms to getBooleanContents. Fall through.
5024// If setcc returns 0/-1, all bits are sign bits.
5025// We know that we have an integer-based boolean since these operations
5026// are only available for integer.
5027if (TLI->getBooleanContents(VT.isVector(),false) ==
5028TargetLowering::ZeroOrNegativeOneBooleanContent)
5029return VTBits;
5030break;
5031caseISD::SETCC:
5032caseISD::SETCCCARRY:
5033caseISD::STRICT_FSETCC:
5034caseISD::STRICT_FSETCCS: {
5035unsigned OpNo =Op->isStrictFPOpcode() ? 1 : 0;
5036// If setcc returns 0/-1, all bits are sign bits.
5037if (TLI->getBooleanContents(Op.getOperand(OpNo).getValueType()) ==
5038TargetLowering::ZeroOrNegativeOneBooleanContent)
5039return VTBits;
5040break;
5041 }
5042caseISD::ROTL:
5043caseISD::ROTR:
5044 Tmp =ComputeNumSignBits(Op.getOperand(0), DemandedElts,Depth + 1);
5045
5046// If we're rotating an 0/-1 value, then it stays an 0/-1 value.
5047if (Tmp == VTBits)
5048return VTBits;
5049
5050if (ConstantSDNode *C =
5051isConstOrConstSplat(Op.getOperand(1), DemandedElts)) {
5052unsigned RotAmt =C->getAPIntValue().urem(VTBits);
5053
5054// Handle rotate right by N like a rotate left by 32-N.
5055if (Opcode ==ISD::ROTR)
5056 RotAmt = (VTBits - RotAmt) % VTBits;
5057
5058// If we aren't rotating out all of the known-in sign bits, return the
5059// number that are left. This handles rotl(sext(x), 1) for example.
5060if (Tmp > (RotAmt + 1))return (Tmp - RotAmt);
5061 }
5062break;
5063caseISD::ADD:
5064caseISD::ADDC:
5065// Add can have at most one carry bit. Thus we know that the output
5066// is, at worst, one more bit than the inputs.
5067 Tmp =ComputeNumSignBits(Op.getOperand(0), DemandedElts,Depth + 1);
5068if (Tmp == 1)return 1;// Early out.
5069
5070// Special case decrementing a value (ADD X, -1):
5071if (ConstantSDNode *CRHS =
5072isConstOrConstSplat(Op.getOperand(1), DemandedElts))
5073if (CRHS->isAllOnes()) {
5074KnownBits Known =
5075computeKnownBits(Op.getOperand(0), DemandedElts,Depth + 1);
5076
5077// If the input is known to be 0 or 1, the output is 0/-1, which is all
5078// sign bits set.
5079if ((Known.Zero | 1).isAllOnes())
5080return VTBits;
5081
5082// If we are subtracting one from a positive number, there is no carry
5083// out of the result.
5084if (Known.isNonNegative())
5085return Tmp;
5086 }
5087
5088 Tmp2 =ComputeNumSignBits(Op.getOperand(1), DemandedElts,Depth + 1);
5089if (Tmp2 == 1)return 1;// Early out.
5090return std::min(Tmp, Tmp2) - 1;
5091caseISD::SUB:
5092 Tmp2 =ComputeNumSignBits(Op.getOperand(1), DemandedElts,Depth + 1);
5093if (Tmp2 == 1)return 1;// Early out.
5094
5095// Handle NEG.
5096if (ConstantSDNode *CLHS =
5097isConstOrConstSplat(Op.getOperand(0), DemandedElts))
5098if (CLHS->isZero()) {
5099KnownBits Known =
5100computeKnownBits(Op.getOperand(1), DemandedElts,Depth + 1);
5101// If the input is known to be 0 or 1, the output is 0/-1, which is all
5102// sign bits set.
5103if ((Known.Zero | 1).isAllOnes())
5104return VTBits;
5105
5106// If the input is known to be positive (the sign bit is known clear),
5107// the output of the NEG has the same number of sign bits as the input.
5108if (Known.isNonNegative())
5109return Tmp2;
5110
5111// Otherwise, we treat this like a SUB.
5112 }
5113
5114// Sub can have at most one carry bit. Thus we know that the output
5115// is, at worst, one more bit than the inputs.
5116 Tmp =ComputeNumSignBits(Op.getOperand(0), DemandedElts,Depth + 1);
5117if (Tmp == 1)return 1;// Early out.
5118return std::min(Tmp, Tmp2) - 1;
5119caseISD::MUL: {
5120// The output of the Mul can be at most twice the valid bits in the inputs.
5121unsigned SignBitsOp0 =ComputeNumSignBits(Op.getOperand(0),Depth + 1);
5122if (SignBitsOp0 == 1)
5123break;
5124unsigned SignBitsOp1 =ComputeNumSignBits(Op.getOperand(1),Depth + 1);
5125if (SignBitsOp1 == 1)
5126break;
5127unsigned OutValidBits =
5128 (VTBits - SignBitsOp0 + 1) + (VTBits - SignBitsOp1 + 1);
5129return OutValidBits > VTBits ? 1 : VTBits - OutValidBits + 1;
5130 }
5131caseISD::AVGCEILS:
5132caseISD::AVGFLOORS:
5133 Tmp =ComputeNumSignBits(Op.getOperand(0), DemandedElts,Depth + 1);
5134if (Tmp == 1)
5135return 1;// Early out.
5136 Tmp2 =ComputeNumSignBits(Op.getOperand(1), DemandedElts,Depth + 1);
5137return std::min(Tmp, Tmp2);
5138caseISD::SREM:
5139// The sign bit is the LHS's sign bit, except when the result of the
5140// remainder is zero. The magnitude of the result should be less than or
5141// equal to the magnitude of the LHS. Therefore, the result should have
5142// at least as many sign bits as the left hand side.
5143returnComputeNumSignBits(Op.getOperand(0), DemandedElts,Depth + 1);
5144caseISD::TRUNCATE: {
5145// Check if the sign bits of source go down as far as the truncated value.
5146unsigned NumSrcBits =Op.getOperand(0).getScalarValueSizeInBits();
5147unsigned NumSrcSignBits =ComputeNumSignBits(Op.getOperand(0),Depth + 1);
5148if (NumSrcSignBits > (NumSrcBits - VTBits))
5149return NumSrcSignBits - (NumSrcBits - VTBits);
5150break;
5151 }
5152caseISD::EXTRACT_ELEMENT: {
5153if (VT.isScalableVector())
5154break;
5155constint KnownSign =ComputeNumSignBits(Op.getOperand(0),Depth+1);
5156constintBitWidth =Op.getValueSizeInBits();
5157constint Items =Op.getOperand(0).getValueSizeInBits() /BitWidth;
5158
5159// Get reverse index (starting from 1), Op1 value indexes elements from
5160// little end. Sign starts at big end.
5161constint rIndex = Items - 1 -Op.getConstantOperandVal(1);
5162
5163// If the sign portion ends in our element the subtraction gives correct
5164// result. Otherwise it gives either negative or > bitwidth result
5165return std::clamp(KnownSign - rIndex *BitWidth, 0,BitWidth);
5166 }
5167caseISD::INSERT_VECTOR_ELT: {
5168if (VT.isScalableVector())
5169break;
5170// If we know the element index, split the demand between the
5171// source vector and the inserted element, otherwise assume we need
5172// the original demanded vector elements and the value.
5173SDValue InVec =Op.getOperand(0);
5174SDValue InVal =Op.getOperand(1);
5175SDValue EltNo =Op.getOperand(2);
5176bool DemandedVal =true;
5177APInt DemandedVecElts = DemandedElts;
5178auto *CEltNo = dyn_cast<ConstantSDNode>(EltNo);
5179if (CEltNo && CEltNo->getAPIntValue().ult(NumElts)) {
5180unsigned EltIdx = CEltNo->getZExtValue();
5181 DemandedVal = !!DemandedElts[EltIdx];
5182 DemandedVecElts.clearBit(EltIdx);
5183 }
5184 Tmp = std::numeric_limits<unsigned>::max();
5185if (DemandedVal) {
5186// TODO - handle implicit truncation of inserted elements.
5187if (InVal.getScalarValueSizeInBits() != VTBits)
5188break;
5189 Tmp2 =ComputeNumSignBits(InVal,Depth + 1);
5190 Tmp = std::min(Tmp, Tmp2);
5191 }
5192if (!!DemandedVecElts) {
5193 Tmp2 =ComputeNumSignBits(InVec, DemandedVecElts,Depth + 1);
5194 Tmp = std::min(Tmp, Tmp2);
5195 }
5196assert(Tmp <= VTBits &&"Failed to determine minimum sign bits");
5197return Tmp;
5198 }
5199caseISD::EXTRACT_VECTOR_ELT: {
5200assert(!VT.isScalableVector());
5201SDValue InVec =Op.getOperand(0);
5202SDValue EltNo =Op.getOperand(1);
5203EVT VecVT = InVec.getValueType();
5204// ComputeNumSignBits not yet implemented for scalable vectors.
5205if (VecVT.isScalableVector())
5206break;
5207constunsignedBitWidth =Op.getValueSizeInBits();
5208constunsigned EltBitWidth =Op.getOperand(0).getScalarValueSizeInBits();
5209constunsigned NumSrcElts = VecVT.getVectorNumElements();
5210
5211// If BitWidth > EltBitWidth the value is anyext:ed, and we do not know
5212// anything about sign bits. But if the sizes match we can derive knowledge
5213// about sign bits from the vector operand.
5214if (BitWidth != EltBitWidth)
5215break;
5216
5217// If we know the element index, just demand that vector element, else for
5218// an unknown element index, ignore DemandedElts and demand them all.
5219APInt DemandedSrcElts =APInt::getAllOnes(NumSrcElts);
5220auto *ConstEltNo = dyn_cast<ConstantSDNode>(EltNo);
5221if (ConstEltNo && ConstEltNo->getAPIntValue().ult(NumSrcElts))
5222 DemandedSrcElts =
5223APInt::getOneBitSet(NumSrcElts, ConstEltNo->getZExtValue());
5224
5225returnComputeNumSignBits(InVec, DemandedSrcElts,Depth + 1);
5226 }
5227caseISD::EXTRACT_SUBVECTOR: {
5228// Offset the demanded elts by the subvector index.
5229SDValue Src =Op.getOperand(0);
5230// Bail until we can represent demanded elements for scalable vectors.
5231if (Src.getValueType().isScalableVector())
5232break;
5233uint64_tIdx =Op.getConstantOperandVal(1);
5234unsigned NumSrcElts = Src.getValueType().getVectorNumElements();
5235APInt DemandedSrcElts = DemandedElts.zext(NumSrcElts).shl(Idx);
5236returnComputeNumSignBits(Src, DemandedSrcElts,Depth + 1);
5237 }
5238caseISD::CONCAT_VECTORS: {
5239if (VT.isScalableVector())
5240break;
5241// Determine the minimum number of sign bits across all demanded
5242// elts of the input vectors. Early out if the result is already 1.
5243 Tmp = std::numeric_limits<unsigned>::max();
5244EVT SubVectorVT =Op.getOperand(0).getValueType();
5245unsigned NumSubVectorElts = SubVectorVT.getVectorNumElements();
5246unsigned NumSubVectors =Op.getNumOperands();
5247for (unsigned i = 0; (i < NumSubVectors) && (Tmp > 1); ++i) {
5248APInt DemandedSub =
5249 DemandedElts.extractBits(NumSubVectorElts, i * NumSubVectorElts);
5250if (!DemandedSub)
5251continue;
5252 Tmp2 =ComputeNumSignBits(Op.getOperand(i), DemandedSub,Depth + 1);
5253 Tmp = std::min(Tmp, Tmp2);
5254 }
5255assert(Tmp <= VTBits &&"Failed to determine minimum sign bits");
5256return Tmp;
5257 }
5258caseISD::INSERT_SUBVECTOR: {
5259if (VT.isScalableVector())
5260break;
5261// Demand any elements from the subvector and the remainder from the src its
5262// inserted into.
5263SDValue Src =Op.getOperand(0);
5264SDValue Sub =Op.getOperand(1);
5265uint64_tIdx =Op.getConstantOperandVal(2);
5266unsigned NumSubElts = Sub.getValueType().getVectorNumElements();
5267APInt DemandedSubElts = DemandedElts.extractBits(NumSubElts,Idx);
5268APInt DemandedSrcElts = DemandedElts;
5269 DemandedSrcElts.insertBits(APInt::getZero(NumSubElts),Idx);
5270
5271 Tmp = std::numeric_limits<unsigned>::max();
5272if (!!DemandedSubElts) {
5273 Tmp =ComputeNumSignBits(Sub, DemandedSubElts,Depth + 1);
5274if (Tmp == 1)
5275return 1;// early-out
5276 }
5277if (!!DemandedSrcElts) {
5278 Tmp2 =ComputeNumSignBits(Src, DemandedSrcElts,Depth + 1);
5279 Tmp = std::min(Tmp, Tmp2);
5280 }
5281assert(Tmp <= VTBits &&"Failed to determine minimum sign bits");
5282return Tmp;
5283 }
5284caseISD::LOAD: {
5285LoadSDNode *LD = cast<LoadSDNode>(Op);
5286if (constMDNode *Ranges = LD->getRanges()) {
5287if (DemandedElts != 1)
5288break;
5289
5290ConstantRange CR =getConstantRangeFromMetadata(*Ranges);
5291if (VTBits > CR.getBitWidth()) {
5292switch (LD->getExtensionType()) {
5293caseISD::SEXTLOAD:
5294 CR = CR.signExtend(VTBits);
5295break;
5296caseISD::ZEXTLOAD:
5297 CR = CR.zeroExtend(VTBits);
5298break;
5299default:
5300break;
5301 }
5302 }
5303
5304if (VTBits != CR.getBitWidth())
5305break;
5306return std::min(CR.getSignedMin().getNumSignBits(),
5307 CR.getSignedMax().getNumSignBits());
5308 }
5309
5310break;
5311 }
5312caseISD::ATOMIC_CMP_SWAP:
5313caseISD::ATOMIC_CMP_SWAP_WITH_SUCCESS:
5314caseISD::ATOMIC_SWAP:
5315caseISD::ATOMIC_LOAD_ADD:
5316caseISD::ATOMIC_LOAD_SUB:
5317caseISD::ATOMIC_LOAD_AND:
5318caseISD::ATOMIC_LOAD_CLR:
5319caseISD::ATOMIC_LOAD_OR:
5320caseISD::ATOMIC_LOAD_XOR:
5321caseISD::ATOMIC_LOAD_NAND:
5322caseISD::ATOMIC_LOAD_MIN:
5323caseISD::ATOMIC_LOAD_MAX:
5324caseISD::ATOMIC_LOAD_UMIN:
5325caseISD::ATOMIC_LOAD_UMAX:
5326caseISD::ATOMIC_LOAD: {
5327 Tmp = cast<AtomicSDNode>(Op)->getMemoryVT().getScalarSizeInBits();
5328// If we are looking at the loaded value.
5329if (Op.getResNo() == 0) {
5330if (Tmp == VTBits)
5331return 1;// early-out
5332if (TLI->getExtendForAtomicOps() ==ISD::SIGN_EXTEND)
5333return VTBits - Tmp + 1;
5334if (TLI->getExtendForAtomicOps() ==ISD::ZERO_EXTEND)
5335return VTBits - Tmp;
5336if (Op->getOpcode() ==ISD::ATOMIC_LOAD) {
5337ISD::LoadExtType ETy = cast<AtomicSDNode>(Op)->getExtensionType();
5338if (ETy ==ISD::SEXTLOAD)
5339return VTBits - Tmp + 1;
5340if (ETy ==ISD::ZEXTLOAD)
5341return VTBits - Tmp;
5342 }
5343 }
5344break;
5345 }
5346 }
5347
5348// If we are looking at the loaded value of the SDNode.
5349if (Op.getResNo() == 0) {
5350// Handle LOADX separately here. EXTLOAD case will fallthrough.
5351if (LoadSDNode *LD = dyn_cast<LoadSDNode>(Op)) {
5352unsigned ExtType = LD->getExtensionType();
5353switch (ExtType) {
5354default:break;
5355caseISD::SEXTLOAD:// e.g. i16->i32 = '17' bits known.
5356 Tmp = LD->getMemoryVT().getScalarSizeInBits();
5357return VTBits - Tmp + 1;
5358caseISD::ZEXTLOAD:// e.g. i16->i32 = '16' bits known.
5359 Tmp = LD->getMemoryVT().getScalarSizeInBits();
5360return VTBits - Tmp;
5361caseISD::NON_EXTLOAD:
5362if (constConstant *Cst = TLI->getTargetConstantFromLoad(LD)) {
5363// We only need to handle vectors - computeKnownBits should handle
5364// scalar cases.
5365Type *CstTy = Cst->getType();
5366if (CstTy->isVectorTy() && !VT.isScalableVector() &&
5367 (NumElts * VTBits) == CstTy->getPrimitiveSizeInBits() &&
5368 VTBits == CstTy->getScalarSizeInBits()) {
5369 Tmp = VTBits;
5370for (unsigned i = 0; i != NumElts; ++i) {
5371if (!DemandedElts[i])
5372continue;
5373if (Constant *Elt = Cst->getAggregateElement(i)) {
5374if (auto *CInt = dyn_cast<ConstantInt>(Elt)) {
5375constAPInt &Value = CInt->getValue();
5376 Tmp = std::min(Tmp,Value.getNumSignBits());
5377continue;
5378 }
5379if (auto *CFP = dyn_cast<ConstantFP>(Elt)) {
5380APIntValue = CFP->getValueAPF().bitcastToAPInt();
5381 Tmp = std::min(Tmp,Value.getNumSignBits());
5382continue;
5383 }
5384 }
5385// Unknown type. Conservatively assume no bits match sign bit.
5386return 1;
5387 }
5388return Tmp;
5389 }
5390 }
5391break;
5392 }
5393 }
5394 }
5395
5396// Allow the target to implement this method for its nodes.
5397if (Opcode >=ISD::BUILTIN_OP_END ||
5398 Opcode ==ISD::INTRINSIC_WO_CHAIN ||
5399 Opcode ==ISD::INTRINSIC_W_CHAIN ||
5400 Opcode ==ISD::INTRINSIC_VOID) {
5401// TODO: This can probably be removed once target code is audited. This
5402// is here purely to reduce patch size and review complexity.
5403if (!VT.isScalableVector()) {
5404unsigned NumBits =
5405 TLI->ComputeNumSignBitsForTargetNode(Op, DemandedElts, *this,Depth);
5406if (NumBits > 1)
5407 FirstAnswer = std::max(FirstAnswer, NumBits);
5408 }
5409 }
5410
5411// Finally, if we can prove that the top bits of the result are 0's or 1's,
5412// use this information.
5413KnownBits Known =computeKnownBits(Op, DemandedElts,Depth);
5414return std::max(FirstAnswer, Known.countMinSignBits());
5415}
5416
5417unsignedSelectionDAG::ComputeMaxSignificantBits(SDValueOp,
5418unsignedDepth) const{
5419unsigned SignBits =ComputeNumSignBits(Op,Depth);
5420returnOp.getScalarValueSizeInBits() - SignBits + 1;
5421}
5422
5423unsignedSelectionDAG::ComputeMaxSignificantBits(SDValueOp,
5424constAPInt &DemandedElts,
5425unsignedDepth) const{
5426unsigned SignBits =ComputeNumSignBits(Op, DemandedElts,Depth);
5427returnOp.getScalarValueSizeInBits() - SignBits + 1;
5428}
5429
5430boolSelectionDAG::isGuaranteedNotToBeUndefOrPoison(SDValueOp,boolPoisonOnly,
5431unsignedDepth) const{
5432// Early out for FREEZE.
5433if (Op.getOpcode() ==ISD::FREEZE)
5434returntrue;
5435
5436EVT VT =Op.getValueType();
5437APInt DemandedElts = VT.isFixedLengthVector()
5438 ?APInt::getAllOnes(VT.getVectorNumElements())
5439 :APInt(1, 1);
5440returnisGuaranteedNotToBeUndefOrPoison(Op, DemandedElts,PoisonOnly,Depth);
5441}
5442
5443boolSelectionDAG::isGuaranteedNotToBeUndefOrPoison(SDValueOp,
5444constAPInt &DemandedElts,
5445boolPoisonOnly,
5446unsignedDepth) const{
5447unsigned Opcode =Op.getOpcode();
5448
5449// Early out for FREEZE.
5450if (Opcode ==ISD::FREEZE)
5451returntrue;
5452
5453if (Depth >=MaxRecursionDepth)
5454returnfalse;// Limit search depth.
5455
5456if (isIntOrFPConstant(Op))
5457returntrue;
5458
5459switch (Opcode) {
5460caseISD::CONDCODE:
5461caseISD::VALUETYPE:
5462caseISD::FrameIndex:
5463caseISD::TargetFrameIndex:
5464caseISD::CopyFromReg:
5465returntrue;
5466
5467caseISD::UNDEF:
5468returnPoisonOnly;
5469
5470caseISD::BUILD_VECTOR:
5471// NOTE: BUILD_VECTOR has implicit truncation of wider scalar elements -
5472// this shouldn't affect the result.
5473for (unsigned i = 0, e =Op.getNumOperands(); i < e; ++i) {
5474if (!DemandedElts[i])
5475continue;
5476if (!isGuaranteedNotToBeUndefOrPoison(Op.getOperand(i),PoisonOnly,
5477Depth + 1))
5478returnfalse;
5479 }
5480returntrue;
5481
5482caseISD::SPLAT_VECTOR:
5483returnisGuaranteedNotToBeUndefOrPoison(Op.getOperand(0),PoisonOnly,
5484Depth + 1);
5485
5486caseISD::VECTOR_SHUFFLE: {
5487APInt DemandedLHS, DemandedRHS;
5488auto *SVN = cast<ShuffleVectorSDNode>(Op);
5489if (!getShuffleDemandedElts(DemandedElts.getBitWidth(), SVN->getMask(),
5490 DemandedElts, DemandedLHS, DemandedRHS,
5491/*AllowUndefElts=*/false))
5492returnfalse;
5493if (!DemandedLHS.isZero() &&
5494 !isGuaranteedNotToBeUndefOrPoison(Op.getOperand(0), DemandedLHS,
5495PoisonOnly,Depth + 1))
5496returnfalse;
5497if (!DemandedRHS.isZero() &&
5498 !isGuaranteedNotToBeUndefOrPoison(Op.getOperand(1), DemandedRHS,
5499PoisonOnly,Depth + 1))
5500returnfalse;
5501returntrue;
5502 }
5503
5504// TODO: Search for noundef attributes from library functions.
5505
5506// TODO: Pointers dereferenced by ISD::LOAD/STORE ops are noundef.
5507
5508default:
5509// Allow the target to implement this method for its nodes.
5510if (Opcode >=ISD::BUILTIN_OP_END || Opcode ==ISD::INTRINSIC_WO_CHAIN ||
5511 Opcode ==ISD::INTRINSIC_W_CHAIN || Opcode ==ISD::INTRINSIC_VOID)
5512return TLI->isGuaranteedNotToBeUndefOrPoisonForTargetNode(
5513Op, DemandedElts, *this,PoisonOnly,Depth);
5514break;
5515 }
5516
5517// If Op can't create undef/poison and none of its operands are undef/poison
5518// then Op is never undef/poison.
5519// NOTE: TargetNodes can handle this in themselves in
5520// isGuaranteedNotToBeUndefOrPoisonForTargetNode or let
5521// TargetLowering::isGuaranteedNotToBeUndefOrPoisonForTargetNode handle it.
5522return !canCreateUndefOrPoison(Op,PoisonOnly,/*ConsiderFlags*/true,
5523Depth) &&
5524all_of(Op->ops(), [&](SDValue V) {
5525 return isGuaranteedNotToBeUndefOrPoison(V, PoisonOnly, Depth + 1);
5526 });
5527}
5528
5529boolSelectionDAG::canCreateUndefOrPoison(SDValueOp,boolPoisonOnly,
5530bool ConsiderFlags,
5531unsignedDepth) const{
5532EVT VT =Op.getValueType();
5533APInt DemandedElts = VT.isFixedLengthVector()
5534 ?APInt::getAllOnes(VT.getVectorNumElements())
5535 :APInt(1, 1);
5536returncanCreateUndefOrPoison(Op, DemandedElts,PoisonOnly, ConsiderFlags,
5537Depth);
5538}
5539
5540boolSelectionDAG::canCreateUndefOrPoison(SDValueOp,constAPInt &DemandedElts,
5541boolPoisonOnly,bool ConsiderFlags,
5542unsignedDepth) const{
5543if (ConsiderFlags &&Op->hasPoisonGeneratingFlags())
5544returntrue;
5545
5546unsigned Opcode =Op.getOpcode();
5547switch (Opcode) {
5548caseISD::FREEZE:
5549caseISD::CONCAT_VECTORS:
5550caseISD::INSERT_SUBVECTOR:
5551caseISD::SADDSAT:
5552caseISD::UADDSAT:
5553caseISD::SSUBSAT:
5554caseISD::USUBSAT:
5555caseISD::MULHU:
5556caseISD::MULHS:
5557caseISD::SMIN:
5558caseISD::SMAX:
5559caseISD::UMIN:
5560caseISD::UMAX:
5561caseISD::AND:
5562caseISD::XOR:
5563caseISD::ROTL:
5564caseISD::ROTR:
5565caseISD::FSHL:
5566caseISD::FSHR:
5567caseISD::BSWAP:
5568caseISD::CTPOP:
5569caseISD::BITREVERSE:
5570caseISD::PARITY:
5571caseISD::SIGN_EXTEND:
5572caseISD::TRUNCATE:
5573caseISD::SIGN_EXTEND_INREG:
5574caseISD::SIGN_EXTEND_VECTOR_INREG:
5575caseISD::ZERO_EXTEND_VECTOR_INREG:
5576caseISD::BITCAST:
5577caseISD::BUILD_VECTOR:
5578caseISD::BUILD_PAIR:
5579caseISD::SPLAT_VECTOR:
5580returnfalse;
5581
5582caseISD::SELECT_CC:
5583caseISD::SETCC: {
5584// Integer setcc cannot create undef or poison.
5585if (Op.getOperand(0).getValueType().isInteger())
5586returnfalse;
5587
5588// FP compares are more complicated. They can create poison for nan/infinity
5589// based on options and flags. The options and flags also cause special
5590// nonan condition codes to be used. Those condition codes may be preserved
5591// even if the nonan flag is dropped somewhere.
5592unsigned CCOp = Opcode ==ISD::SETCC ? 2 : 4;
5593ISD::CondCode CCCode = cast<CondCodeSDNode>(Op.getOperand(CCOp))->get();
5594if (((unsigned)CCCode & 0x10U))
5595returntrue;
5596
5597constTargetOptions &Options =getTarget().Options;
5598returnOptions.NoNaNsFPMath ||Options.NoInfsFPMath;
5599 }
5600
5601caseISD::OR:
5602caseISD::ZERO_EXTEND:
5603caseISD::ADD:
5604caseISD::SUB:
5605caseISD::MUL:
5606// No poison except from flags (which is handled above)
5607returnfalse;
5608
5609caseISD::SHL:
5610caseISD::SRL:
5611caseISD::SRA:
5612// If the max shift amount isn't in range, then the shift can
5613// create poison.
5614return !isGuaranteedNotToBeUndefOrPoison(Op.getOperand(1), DemandedElts,
5615PoisonOnly,Depth + 1) ||
5616 !getValidMaximumShiftAmount(Op, DemandedElts,Depth + 1);
5617
5618caseISD::SCALAR_TO_VECTOR:
5619// Check if we demand any upper (undef) elements.
5620return !PoisonOnly && DemandedElts.ugt(1);
5621
5622caseISD::INSERT_VECTOR_ELT:
5623caseISD::EXTRACT_VECTOR_ELT: {
5624// Ensure that the element index is in bounds.
5625EVT VecVT =Op.getOperand(0).getValueType();
5626SDValueIdx =Op.getOperand(Opcode ==ISD::INSERT_VECTOR_ELT ? 2 : 1);
5627if (isGuaranteedNotToBeUndefOrPoison(Idx, DemandedElts,PoisonOnly,
5628Depth + 1)) {
5629KnownBits KnownIdx =computeKnownBits(Idx,Depth + 1);
5630return KnownIdx.getMaxValue().uge(VecVT.getVectorMinNumElements());
5631 }
5632returntrue;
5633 }
5634
5635caseISD::VECTOR_SHUFFLE: {
5636// Check for any demanded shuffle element that is undef.
5637auto *SVN = cast<ShuffleVectorSDNode>(Op);
5638for (auto [Idx, Elt] :enumerate(SVN->getMask()))
5639if (Elt < 0 && DemandedElts[Idx])
5640returntrue;
5641returnfalse;
5642 }
5643
5644default:
5645// Allow the target to implement this method for its nodes.
5646if (Opcode >=ISD::BUILTIN_OP_END || Opcode ==ISD::INTRINSIC_WO_CHAIN ||
5647 Opcode ==ISD::INTRINSIC_W_CHAIN || Opcode ==ISD::INTRINSIC_VOID)
5648return TLI->canCreateUndefOrPoisonForTargetNode(
5649Op, DemandedElts, *this,PoisonOnly, ConsiderFlags,Depth);
5650break;
5651 }
5652
5653// Be conservative and return true.
5654returntrue;
5655}
5656
5657boolSelectionDAG::isADDLike(SDValueOp,bool NoWrap) const{
5658unsigned Opcode =Op.getOpcode();
5659if (Opcode ==ISD::OR)
5660returnOp->getFlags().hasDisjoint() ||
5661haveNoCommonBitsSet(Op.getOperand(0),Op.getOperand(1));
5662if (Opcode ==ISD::XOR)
5663return !NoWrap &&isMinSignedConstant(Op.getOperand(1));
5664returnfalse;
5665}
5666
5667boolSelectionDAG::isBaseWithConstantOffset(SDValueOp) const{
5668returnOp.getNumOperands() == 2 && isa<ConstantSDNode>(Op.getOperand(1)) &&
5669 (Op.getOpcode() ==ISD::ADD ||isADDLike(Op));
5670}
5671
5672boolSelectionDAG::isKnownNeverNaN(SDValueOp,bool SNaN,unsignedDepth) const{
5673// If we're told that NaNs won't happen, assume they won't.
5674if (getTarget().Options.NoNaNsFPMath ||Op->getFlags().hasNoNaNs())
5675returntrue;
5676
5677if (Depth >=MaxRecursionDepth)
5678returnfalse;// Limit search depth.
5679
5680// If the value is a constant, we can obviously see if it is a NaN or not.
5681if (constConstantFPSDNode *C = dyn_cast<ConstantFPSDNode>(Op)) {
5682return !C->getValueAPF().isNaN() ||
5683 (SNaN && !C->getValueAPF().isSignaling());
5684 }
5685
5686unsigned Opcode =Op.getOpcode();
5687switch (Opcode) {
5688caseISD::FADD:
5689caseISD::FSUB:
5690caseISD::FMUL:
5691caseISD::FDIV:
5692caseISD::FREM:
5693caseISD::FSIN:
5694caseISD::FCOS:
5695caseISD::FTAN:
5696caseISD::FASIN:
5697caseISD::FACOS:
5698caseISD::FATAN:
5699caseISD::FATAN2:
5700caseISD::FSINH:
5701caseISD::FCOSH:
5702caseISD::FTANH:
5703caseISD::FMA:
5704caseISD::FMAD: {
5705if (SNaN)
5706returntrue;
5707// TODO: Need isKnownNeverInfinity
5708returnfalse;
5709 }
5710caseISD::FCANONICALIZE:
5711caseISD::FEXP:
5712caseISD::FEXP2:
5713caseISD::FEXP10:
5714caseISD::FTRUNC:
5715caseISD::FFLOOR:
5716caseISD::FCEIL:
5717caseISD::FROUND:
5718caseISD::FROUNDEVEN:
5719caseISD::LROUND:
5720caseISD::LLROUND:
5721caseISD::FRINT:
5722caseISD::LRINT:
5723caseISD::LLRINT:
5724caseISD::FNEARBYINT:
5725caseISD::FLDEXP: {
5726if (SNaN)
5727returntrue;
5728returnisKnownNeverNaN(Op.getOperand(0), SNaN,Depth + 1);
5729 }
5730caseISD::FABS:
5731caseISD::FNEG:
5732caseISD::FCOPYSIGN: {
5733returnisKnownNeverNaN(Op.getOperand(0), SNaN,Depth + 1);
5734 }
5735caseISD::SELECT:
5736returnisKnownNeverNaN(Op.getOperand(1), SNaN,Depth + 1) &&
5737isKnownNeverNaN(Op.getOperand(2), SNaN,Depth + 1);
5738caseISD::FP_EXTEND:
5739caseISD::FP_ROUND: {
5740if (SNaN)
5741returntrue;
5742returnisKnownNeverNaN(Op.getOperand(0), SNaN,Depth + 1);
5743 }
5744caseISD::SINT_TO_FP:
5745caseISD::UINT_TO_FP:
5746returntrue;
5747caseISD::FSQRT:// Need is known positive
5748caseISD::FLOG:
5749caseISD::FLOG2:
5750caseISD::FLOG10:
5751caseISD::FPOWI:
5752caseISD::FPOW: {
5753if (SNaN)
5754returntrue;
5755// TODO: Refine on operand
5756returnfalse;
5757 }
5758caseISD::FMINNUM:
5759caseISD::FMAXNUM:
5760caseISD::FMINIMUMNUM:
5761caseISD::FMAXIMUMNUM: {
5762// Only one needs to be known not-nan, since it will be returned if the
5763// other ends up being one.
5764returnisKnownNeverNaN(Op.getOperand(0), SNaN,Depth + 1) ||
5765isKnownNeverNaN(Op.getOperand(1), SNaN,Depth + 1);
5766 }
5767caseISD::FMINNUM_IEEE:
5768caseISD::FMAXNUM_IEEE: {
5769if (SNaN)
5770returntrue;
5771// This can return a NaN if either operand is an sNaN, or if both operands
5772// are NaN.
5773return (isKnownNeverNaN(Op.getOperand(0),false,Depth + 1) &&
5774isKnownNeverSNaN(Op.getOperand(1),Depth + 1)) ||
5775 (isKnownNeverNaN(Op.getOperand(1),false,Depth + 1) &&
5776isKnownNeverSNaN(Op.getOperand(0),Depth + 1));
5777 }
5778caseISD::FMINIMUM:
5779caseISD::FMAXIMUM: {
5780// TODO: Does this quiet or return the origina NaN as-is?
5781returnisKnownNeverNaN(Op.getOperand(0), SNaN,Depth + 1) &&
5782isKnownNeverNaN(Op.getOperand(1), SNaN,Depth + 1);
5783 }
5784caseISD::EXTRACT_VECTOR_ELT: {
5785returnisKnownNeverNaN(Op.getOperand(0), SNaN,Depth + 1);
5786 }
5787caseISD::BUILD_VECTOR: {
5788for (constSDValue &Opnd :Op->ops())
5789if (!isKnownNeverNaN(Opnd, SNaN,Depth + 1))
5790returnfalse;
5791returntrue;
5792 }
5793default:
5794if (Opcode >=ISD::BUILTIN_OP_END ||
5795 Opcode ==ISD::INTRINSIC_WO_CHAIN ||
5796 Opcode ==ISD::INTRINSIC_W_CHAIN ||
5797 Opcode ==ISD::INTRINSIC_VOID) {
5798return TLI->isKnownNeverNaNForTargetNode(Op, *this, SNaN,Depth);
5799 }
5800
5801returnfalse;
5802 }
5803}
5804
5805boolSelectionDAG::isKnownNeverZeroFloat(SDValueOp) const{
5806assert(Op.getValueType().isFloatingPoint() &&
5807"Floating point type expected");
5808
5809// If the value is a constant, we can obviously see if it is a zero or not.
5810returnISD::matchUnaryFpPredicate(
5811Op, [](ConstantFPSDNode *C) {return !C->isZero(); });
5812}
5813
5814boolSelectionDAG::isKnownNeverZero(SDValueOp,unsignedDepth) const{
5815if (Depth >=MaxRecursionDepth)
5816returnfalse;// Limit search depth.
5817
5818assert(!Op.getValueType().isFloatingPoint() &&
5819"Floating point types unsupported - use isKnownNeverZeroFloat");
5820
5821// If the value is a constant, we can obviously see if it is a zero or not.
5822if (ISD::matchUnaryPredicate(Op,
5823 [](ConstantSDNode *C) {return !C->isZero(); }))
5824returntrue;
5825
5826// TODO: Recognize more cases here. Most of the cases are also incomplete to
5827// some degree.
5828switch (Op.getOpcode()) {
5829default:
5830break;
5831
5832caseISD::OR:
5833returnisKnownNeverZero(Op.getOperand(1),Depth + 1) ||
5834isKnownNeverZero(Op.getOperand(0),Depth + 1);
5835
5836caseISD::VSELECT:
5837caseISD::SELECT:
5838returnisKnownNeverZero(Op.getOperand(1),Depth + 1) &&
5839isKnownNeverZero(Op.getOperand(2),Depth + 1);
5840
5841caseISD::SHL: {
5842if (Op->getFlags().hasNoSignedWrap() ||Op->getFlags().hasNoUnsignedWrap())
5843returnisKnownNeverZero(Op.getOperand(0),Depth + 1);
5844KnownBits ValKnown =computeKnownBits(Op.getOperand(0),Depth + 1);
5845// 1 << X is never zero.
5846if (ValKnown.One[0])
5847returntrue;
5848// If max shift cnt of known ones is non-zero, result is non-zero.
5849APInt MaxCnt =computeKnownBits(Op.getOperand(1),Depth + 1).getMaxValue();
5850if (MaxCnt.ult(ValKnown.getBitWidth()) &&
5851 !ValKnown.One.shl(MaxCnt).isZero())
5852returntrue;
5853break;
5854 }
5855caseISD::UADDSAT:
5856caseISD::UMAX:
5857returnisKnownNeverZero(Op.getOperand(1),Depth + 1) ||
5858isKnownNeverZero(Op.getOperand(0),Depth + 1);
5859
5860// For smin/smax: If either operand is known negative/positive
5861// respectively we don't need the other to be known at all.
5862caseISD::SMAX: {
5863KnownBits Op1 =computeKnownBits(Op.getOperand(1),Depth + 1);
5864if (Op1.isStrictlyPositive())
5865returntrue;
5866
5867KnownBits Op0 =computeKnownBits(Op.getOperand(0),Depth + 1);
5868if (Op0.isStrictlyPositive())
5869returntrue;
5870
5871if (Op1.isNonZero() && Op0.isNonZero())
5872returntrue;
5873
5874returnisKnownNeverZero(Op.getOperand(1),Depth + 1) &&
5875isKnownNeverZero(Op.getOperand(0),Depth + 1);
5876 }
5877caseISD::SMIN: {
5878KnownBits Op1 =computeKnownBits(Op.getOperand(1),Depth + 1);
5879if (Op1.isNegative())
5880returntrue;
5881
5882KnownBits Op0 =computeKnownBits(Op.getOperand(0),Depth + 1);
5883if (Op0.isNegative())
5884returntrue;
5885
5886if (Op1.isNonZero() && Op0.isNonZero())
5887returntrue;
5888
5889returnisKnownNeverZero(Op.getOperand(1),Depth + 1) &&
5890isKnownNeverZero(Op.getOperand(0),Depth + 1);
5891 }
5892caseISD::UMIN:
5893returnisKnownNeverZero(Op.getOperand(1),Depth + 1) &&
5894isKnownNeverZero(Op.getOperand(0),Depth + 1);
5895
5896caseISD::ROTL:
5897caseISD::ROTR:
5898caseISD::BITREVERSE:
5899caseISD::BSWAP:
5900caseISD::CTPOP:
5901caseISD::ABS:
5902returnisKnownNeverZero(Op.getOperand(0),Depth + 1);
5903
5904caseISD::SRA:
5905caseISD::SRL: {
5906if (Op->getFlags().hasExact())
5907returnisKnownNeverZero(Op.getOperand(0),Depth + 1);
5908KnownBits ValKnown =computeKnownBits(Op.getOperand(0),Depth + 1);
5909if (ValKnown.isNegative())
5910returntrue;
5911// If max shift cnt of known ones is non-zero, result is non-zero.
5912APInt MaxCnt =computeKnownBits(Op.getOperand(1),Depth + 1).getMaxValue();
5913if (MaxCnt.ult(ValKnown.getBitWidth()) &&
5914 !ValKnown.One.lshr(MaxCnt).isZero())
5915returntrue;
5916break;
5917 }
5918caseISD::UDIV:
5919caseISD::SDIV:
5920// div exact can only produce a zero if the dividend is zero.
5921// TODO: For udiv this is also true if Op1 u<= Op0
5922if (Op->getFlags().hasExact())
5923returnisKnownNeverZero(Op.getOperand(0),Depth + 1);
5924break;
5925
5926caseISD::ADD:
5927if (Op->getFlags().hasNoUnsignedWrap())
5928if (isKnownNeverZero(Op.getOperand(1),Depth + 1) ||
5929isKnownNeverZero(Op.getOperand(0),Depth + 1))
5930returntrue;
5931// TODO: There are a lot more cases we can prove for add.
5932break;
5933
5934caseISD::SUB: {
5935if (isNullConstant(Op.getOperand(0)))
5936returnisKnownNeverZero(Op.getOperand(1),Depth + 1);
5937
5938 std::optional<bool> ne =
5939KnownBits::ne(computeKnownBits(Op.getOperand(0),Depth + 1),
5940computeKnownBits(Op.getOperand(1),Depth + 1));
5941return ne && *ne;
5942 }
5943
5944caseISD::MUL:
5945if (Op->getFlags().hasNoSignedWrap() ||Op->getFlags().hasNoUnsignedWrap())
5946if (isKnownNeverZero(Op.getOperand(1),Depth + 1) &&
5947isKnownNeverZero(Op.getOperand(0),Depth + 1))
5948returntrue;
5949break;
5950
5951caseISD::ZERO_EXTEND:
5952caseISD::SIGN_EXTEND:
5953returnisKnownNeverZero(Op.getOperand(0),Depth + 1);
5954caseISD::VSCALE: {
5955constFunction &F =getMachineFunction().getFunction();
5956constAPInt &Multiplier =Op.getConstantOperandAPInt(0);
5957ConstantRange CR =
5958getVScaleRange(&F,Op.getScalarValueSizeInBits()).multiply(Multiplier);
5959if (!CR.contains(APInt(CR.getBitWidth(), 0)))
5960returntrue;
5961break;
5962 }
5963 }
5964
5965returncomputeKnownBits(Op,Depth).isNonZero();
5966}
5967
5968boolSelectionDAG::cannotBeOrderedNegativeFP(SDValueOp) const{
5969if (ConstantFPSDNode *C1 =isConstOrConstSplatFP(Op,true))
5970return !C1->isNegative();
5971
5972returnOp.getOpcode() ==ISD::FABS;
5973}
5974
5975boolSelectionDAG::isEqualTo(SDValueA,SDValueB) const{
5976// Check the obvious case.
5977if (A ==B)returntrue;
5978
5979// For negative and positive zero.
5980if (constConstantFPSDNode *CA = dyn_cast<ConstantFPSDNode>(A))
5981if (constConstantFPSDNode *CB = dyn_cast<ConstantFPSDNode>(B))
5982if (CA->isZero() && CB->isZero())returntrue;
5983
5984// Otherwise they may not be equal.
5985returnfalse;
5986}
5987
5988// Only bits set in Mask must be negated, other bits may be arbitrary.
5989SDValuellvm::getBitwiseNotOperand(SDValue V,SDValue Mask,bool AllowUndefs) {
5990if (isBitwiseNot(V, AllowUndefs))
5991return V.getOperand(0);
5992
5993// Handle any_extend (not (truncate X)) pattern, where Mask only sets
5994// bits in the non-extended part.
5995ConstantSDNode *MaskC =isConstOrConstSplat(Mask);
5996if (!MaskC || V.getOpcode() !=ISD::ANY_EXTEND)
5997returnSDValue();
5998SDValue ExtArg = V.getOperand(0);
5999if (ExtArg.getScalarValueSizeInBits() >=
6000 MaskC->getAPIntValue().getActiveBits() &&
6001isBitwiseNot(ExtArg, AllowUndefs) &&
6002 ExtArg.getOperand(0).getOpcode() ==ISD::TRUNCATE &&
6003 ExtArg.getOperand(0).getOperand(0).getValueType() == V.getValueType())
6004return ExtArg.getOperand(0).getOperand(0);
6005returnSDValue();
6006}
6007
6008staticboolhaveNoCommonBitsSetCommutative(SDValueA,SDValueB) {
6009// Match masked merge pattern (X & ~M) op (Y & M)
6010// Including degenerate case (X & ~M) op M
6011auto MatchNoCommonBitsPattern = [&](SDValueNot,SDValue Mask,
6012SDValueOther) {
6013if (SDValue NotOperand =
6014getBitwiseNotOperand(Not, Mask,/* AllowUndefs */true)) {
6015if (NotOperand->getOpcode() ==ISD::ZERO_EXTEND ||
6016 NotOperand->getOpcode() ==ISD::TRUNCATE)
6017 NotOperand = NotOperand->getOperand(0);
6018
6019if (Other == NotOperand)
6020returntrue;
6021if (Other->getOpcode() ==ISD::AND)
6022return NotOperand ==Other->getOperand(0) ||
6023 NotOperand ==Other->getOperand(1);
6024 }
6025returnfalse;
6026 };
6027
6028if (A->getOpcode() ==ISD::ZERO_EXTEND ||A->getOpcode() ==ISD::TRUNCATE)
6029A =A->getOperand(0);
6030
6031if (B->getOpcode() ==ISD::ZERO_EXTEND ||B->getOpcode() ==ISD::TRUNCATE)
6032B =B->getOperand(0);
6033
6034if (A->getOpcode() ==ISD::AND)
6035return MatchNoCommonBitsPattern(A->getOperand(0),A->getOperand(1),B) ||
6036 MatchNoCommonBitsPattern(A->getOperand(1),A->getOperand(0),B);
6037returnfalse;
6038}
6039
6040// FIXME: unify with llvm::haveNoCommonBitsSet.
6041boolSelectionDAG::haveNoCommonBitsSet(SDValueA,SDValueB) const{
6042assert(A.getValueType() ==B.getValueType() &&
6043"Values must have the same type");
6044if (haveNoCommonBitsSetCommutative(A,B) ||
6045haveNoCommonBitsSetCommutative(B,A))
6046returntrue;
6047returnKnownBits::haveNoCommonBitsSet(computeKnownBits(A),
6048computeKnownBits(B));
6049}
6050
6051staticSDValueFoldSTEP_VECTOR(constSDLoc &DL,EVT VT,SDValue Step,
6052SelectionDAG &DAG) {
6053if (cast<ConstantSDNode>(Step)->isZero())
6054return DAG.getConstant(0,DL, VT);
6055
6056returnSDValue();
6057}
6058
6059staticSDValueFoldBUILD_VECTOR(constSDLoc &DL,EVT VT,
6060ArrayRef<SDValue> Ops,
6061SelectionDAG &DAG) {
6062int NumOps = Ops.size();
6063assert(NumOps != 0 &&"Can't build an empty vector!");
6064assert(!VT.isScalableVector() &&
6065"BUILD_VECTOR cannot be used with scalable types");
6066assert(VT.getVectorNumElements() == (unsigned)NumOps &&
6067"Incorrect element count in BUILD_VECTOR!");
6068
6069// BUILD_VECTOR of UNDEFs is UNDEF.
6070if (llvm::all_of(Ops, [](SDValueOp) {returnOp.isUndef(); }))
6071return DAG.getUNDEF(VT);
6072
6073// BUILD_VECTOR of seq extract/insert from the same vector + type is Identity.
6074SDValue IdentitySrc;
6075bool IsIdentity =true;
6076for (int i = 0; i != NumOps; ++i) {
6077if (Ops[i].getOpcode() !=ISD::EXTRACT_VECTOR_ELT ||
6078 Ops[i].getOperand(0).getValueType() != VT ||
6079 (IdentitySrc && Ops[i].getOperand(0) != IdentitySrc) ||
6080 !isa<ConstantSDNode>(Ops[i].getOperand(1)) ||
6081 Ops[i].getConstantOperandAPInt(1) != i) {
6082 IsIdentity =false;
6083break;
6084 }
6085 IdentitySrc = Ops[i].getOperand(0);
6086 }
6087if (IsIdentity)
6088return IdentitySrc;
6089
6090returnSDValue();
6091}
6092
6093/// Try to simplify vector concatenation to an input value, undef, or build
6094/// vector.
6095staticSDValuefoldCONCAT_VECTORS(constSDLoc &DL,EVT VT,
6096ArrayRef<SDValue> Ops,
6097SelectionDAG &DAG) {
6098assert(!Ops.empty() &&"Can't concatenate an empty list of vectors!");
6099assert(llvm::all_of(Ops,
6100 [Ops](SDValueOp) {
6101return Ops[0].getValueType() ==Op.getValueType();
6102 }) &&
6103"Concatenation of vectors with inconsistent value types!");
6104assert((Ops[0].getValueType().getVectorElementCount() * Ops.size()) ==
6105 VT.getVectorElementCount() &&
6106"Incorrect element count in vector concatenation!");
6107
6108if (Ops.size() == 1)
6109return Ops[0];
6110
6111// Concat of UNDEFs is UNDEF.
6112if (llvm::all_of(Ops, [](SDValueOp) {returnOp.isUndef(); }))
6113return DAG.getUNDEF(VT);
6114
6115// Scan the operands and look for extract operations from a single source
6116// that correspond to insertion at the same location via this concatenation:
6117// concat (extract X, 0*subvec_elts), (extract X, 1*subvec_elts), ...
6118SDValue IdentitySrc;
6119bool IsIdentity =true;
6120for (unsigned i = 0, e = Ops.size(); i != e; ++i) {
6121SDValueOp = Ops[i];
6122unsigned IdentityIndex = i *Op.getValueType().getVectorMinNumElements();
6123if (Op.getOpcode() !=ISD::EXTRACT_SUBVECTOR ||
6124Op.getOperand(0).getValueType() != VT ||
6125 (IdentitySrc &&Op.getOperand(0) != IdentitySrc) ||
6126Op.getConstantOperandVal(1) != IdentityIndex) {
6127 IsIdentity =false;
6128break;
6129 }
6130assert((!IdentitySrc || IdentitySrc ==Op.getOperand(0)) &&
6131"Unexpected identity source vector for concat of extracts");
6132 IdentitySrc =Op.getOperand(0);
6133 }
6134if (IsIdentity) {
6135assert(IdentitySrc &&"Failed to set source vector of extracts");
6136return IdentitySrc;
6137 }
6138
6139// The code below this point is only designed to work for fixed width
6140// vectors, so we bail out for now.
6141if (VT.isScalableVector())
6142returnSDValue();
6143
6144// A CONCAT_VECTOR with all UNDEF/BUILD_VECTOR operands can be
6145// simplified to one big BUILD_VECTOR.
6146// FIXME: Add support for SCALAR_TO_VECTOR as well.
6147EVT SVT = VT.getScalarType();
6148SmallVector<SDValue, 16> Elts;
6149for (SDValueOp : Ops) {
6150EVT OpVT =Op.getValueType();
6151if (Op.isUndef())
6152 Elts.append(OpVT.getVectorNumElements(), DAG.getUNDEF(SVT));
6153elseif (Op.getOpcode() ==ISD::BUILD_VECTOR)
6154 Elts.append(Op->op_begin(),Op->op_end());
6155else
6156returnSDValue();
6157 }
6158
6159// BUILD_VECTOR requires all inputs to be of the same type, find the
6160// maximum type and extend them all.
6161for (SDValueOp : Elts)
6162 SVT = (SVT.bitsLT(Op.getValueType()) ?Op.getValueType() : SVT);
6163
6164if (SVT.bitsGT(VT.getScalarType())) {
6165for (SDValue &Op : Elts) {
6166if (Op.isUndef())
6167Op = DAG.getUNDEF(SVT);
6168else
6169Op = DAG.getTargetLoweringInfo().isZExtFree(Op.getValueType(), SVT)
6170 ? DAG.getZExtOrTrunc(Op,DL, SVT)
6171 : DAG.getSExtOrTrunc(Op,DL, SVT);
6172 }
6173 }
6174
6175SDValue V = DAG.getBuildVector(VT,DL, Elts);
6176NewSDValueDbgMsg(V,"New node fold concat vectors: ", &DAG);
6177return V;
6178}
6179
6180/// Gets or creates the specified node.
6181SDValueSelectionDAG::getNode(unsigned Opcode,constSDLoc &DL,EVT VT) {
6182SDVTList VTs =getVTList(VT);
6183FoldingSetNodeIDID;
6184AddNodeIDNode(ID, Opcode, VTs, {});
6185void *IP =nullptr;
6186if (SDNode *E = FindNodeOrInsertPos(ID,DL, IP))
6187returnSDValue(E, 0);
6188
6189auto *N = newSDNode<SDNode>(Opcode,DL.getIROrder(),DL.getDebugLoc(), VTs);
6190 CSEMap.InsertNode(N, IP);
6191
6192 InsertNode(N);
6193SDValue V =SDValue(N, 0);
6194NewSDValueDbgMsg(V,"Creating new node: ",this);
6195return V;
6196}
6197
6198SDValueSelectionDAG::getNode(unsigned Opcode,constSDLoc &DL,EVT VT,
6199SDValue N1) {
6200SDNodeFlags Flags;
6201if (Inserter)
6202 Flags = Inserter->getFlags();
6203returngetNode(Opcode,DL, VT, N1, Flags);
6204}
6205
6206SDValueSelectionDAG::getNode(unsigned Opcode,constSDLoc &DL,EVT VT,
6207SDValue N1,constSDNodeFlags Flags) {
6208assert(N1.getOpcode() !=ISD::DELETED_NODE &&"Operand is DELETED_NODE!");
6209
6210// Constant fold unary operations with a vector integer or float operand.
6211switch (Opcode) {
6212default:
6213// FIXME: Entirely reasonable to perform folding of other unary
6214// operations here as the need arises.
6215break;
6216caseISD::FNEG:
6217caseISD::FABS:
6218caseISD::FCEIL:
6219caseISD::FTRUNC:
6220caseISD::FFLOOR:
6221caseISD::FP_EXTEND:
6222caseISD::FP_TO_SINT:
6223caseISD::FP_TO_UINT:
6224caseISD::FP_TO_FP16:
6225caseISD::FP_TO_BF16:
6226caseISD::TRUNCATE:
6227caseISD::ANY_EXTEND:
6228caseISD::ZERO_EXTEND:
6229caseISD::SIGN_EXTEND:
6230caseISD::UINT_TO_FP:
6231caseISD::SINT_TO_FP:
6232caseISD::FP16_TO_FP:
6233caseISD::BF16_TO_FP:
6234caseISD::BITCAST:
6235caseISD::ABS:
6236caseISD::BITREVERSE:
6237caseISD::BSWAP:
6238caseISD::CTLZ:
6239caseISD::CTLZ_ZERO_UNDEF:
6240caseISD::CTTZ:
6241caseISD::CTTZ_ZERO_UNDEF:
6242caseISD::CTPOP:
6243caseISD::STEP_VECTOR: {
6244SDValue Ops = {N1};
6245if (SDValue Fold =FoldConstantArithmetic(Opcode,DL, VT, Ops))
6246return Fold;
6247 }
6248 }
6249
6250unsigned OpOpcode = N1.getNode()->getOpcode();
6251switch (Opcode) {
6252caseISD::STEP_VECTOR:
6253assert(VT.isScalableVector() &&
6254"STEP_VECTOR can only be used with scalable types");
6255assert(OpOpcode ==ISD::TargetConstant &&
6256 VT.getVectorElementType() == N1.getValueType() &&
6257"Unexpected step operand");
6258break;
6259caseISD::FREEZE:
6260assert(VT == N1.getValueType() &&"Unexpected VT!");
6261if (isGuaranteedNotToBeUndefOrPoison(N1,/*PoisonOnly*/false,
6262/*Depth*/ 1))
6263return N1;
6264break;
6265caseISD::TokenFactor:
6266caseISD::MERGE_VALUES:
6267caseISD::CONCAT_VECTORS:
6268return N1;// Factor, merge or concat of one node? No need.
6269caseISD::BUILD_VECTOR: {
6270// Attempt to simplify BUILD_VECTOR.
6271SDValue Ops[] = {N1};
6272if (SDValue V =FoldBUILD_VECTOR(DL, VT, Ops, *this))
6273return V;
6274break;
6275 }
6276caseISD::FP_ROUND:llvm_unreachable("Invalid method to make FP_ROUND node");
6277caseISD::FP_EXTEND:
6278assert(VT.isFloatingPoint() && N1.getValueType().isFloatingPoint() &&
6279"Invalid FP cast!");
6280if (N1.getValueType() == VT)return N1;// noop conversion.
6281assert((!VT.isVector() || VT.getVectorElementCount() ==
6282 N1.getValueType().getVectorElementCount()) &&
6283"Vector element count mismatch!");
6284assert(N1.getValueType().bitsLT(VT) &&"Invalid fpext node, dst < src!");
6285if (N1.isUndef())
6286returngetUNDEF(VT);
6287break;
6288caseISD::FP_TO_SINT:
6289caseISD::FP_TO_UINT:
6290if (N1.isUndef())
6291returngetUNDEF(VT);
6292break;
6293caseISD::SINT_TO_FP:
6294caseISD::UINT_TO_FP:
6295// [us]itofp(undef) = 0, because the result value is bounded.
6296if (N1.isUndef())
6297returngetConstantFP(0.0,DL, VT);
6298break;
6299caseISD::SIGN_EXTEND:
6300assert(VT.isInteger() && N1.getValueType().isInteger() &&
6301"Invalid SIGN_EXTEND!");
6302assert(VT.isVector() == N1.getValueType().isVector() &&
6303"SIGN_EXTEND result type type should be vector iff the operand "
6304"type is vector!");
6305if (N1.getValueType() == VT)return N1;// noop extension
6306assert((!VT.isVector() || VT.getVectorElementCount() ==
6307 N1.getValueType().getVectorElementCount()) &&
6308"Vector element count mismatch!");
6309assert(N1.getValueType().bitsLT(VT) &&"Invalid sext node, dst < src!");
6310if (OpOpcode ==ISD::SIGN_EXTEND || OpOpcode ==ISD::ZERO_EXTEND) {
6311SDNodeFlags Flags;
6312if (OpOpcode ==ISD::ZERO_EXTEND)
6313 Flags.setNonNeg(N1->getFlags().hasNonNeg());
6314returngetNode(OpOpcode,DL, VT, N1.getOperand(0), Flags);
6315 }
6316if (OpOpcode ==ISD::UNDEF)
6317// sext(undef) = 0, because the top bits will all be the same.
6318returngetConstant(0,DL, VT);
6319break;
6320caseISD::ZERO_EXTEND:
6321assert(VT.isInteger() && N1.getValueType().isInteger() &&
6322"Invalid ZERO_EXTEND!");
6323assert(VT.isVector() == N1.getValueType().isVector() &&
6324"ZERO_EXTEND result type type should be vector iff the operand "
6325"type is vector!");
6326if (N1.getValueType() == VT)return N1;// noop extension
6327assert((!VT.isVector() || VT.getVectorElementCount() ==
6328 N1.getValueType().getVectorElementCount()) &&
6329"Vector element count mismatch!");
6330assert(N1.getValueType().bitsLT(VT) &&"Invalid zext node, dst < src!");
6331if (OpOpcode ==ISD::ZERO_EXTEND) {// (zext (zext x)) -> (zext x)
6332SDNodeFlags Flags;
6333 Flags.setNonNeg(N1->getFlags().hasNonNeg());
6334returngetNode(ISD::ZERO_EXTEND,DL, VT, N1.getOperand(0), Flags);
6335 }
6336if (OpOpcode ==ISD::UNDEF)
6337// zext(undef) = 0, because the top bits will be zero.
6338returngetConstant(0,DL, VT);
6339
6340// Skip unnecessary zext_inreg pattern:
6341// (zext (trunc x)) -> x iff the upper bits are known zero.
6342// TODO: Remove (zext (trunc (and x, c))) exception which some targets
6343// use to recognise zext_inreg patterns.
6344if (OpOpcode ==ISD::TRUNCATE) {
6345SDValue OpOp = N1.getOperand(0);
6346if (OpOp.getValueType() == VT) {
6347if (OpOp.getOpcode() !=ISD::AND) {
6348APInt HiBits =APInt::getBitsSetFrom(VT.getScalarSizeInBits(),
6349 N1.getScalarValueSizeInBits());
6350if (MaskedValueIsZero(OpOp, HiBits)) {
6351transferDbgValues(N1, OpOp);
6352return OpOp;
6353 }
6354 }
6355 }
6356 }
6357break;
6358caseISD::ANY_EXTEND:
6359assert(VT.isInteger() && N1.getValueType().isInteger() &&
6360"Invalid ANY_EXTEND!");
6361assert(VT.isVector() == N1.getValueType().isVector() &&
6362"ANY_EXTEND result type type should be vector iff the operand "
6363"type is vector!");
6364if (N1.getValueType() == VT)return N1;// noop extension
6365assert((!VT.isVector() || VT.getVectorElementCount() ==
6366 N1.getValueType().getVectorElementCount()) &&
6367"Vector element count mismatch!");
6368assert(N1.getValueType().bitsLT(VT) &&"Invalid anyext node, dst < src!");
6369
6370if (OpOpcode ==ISD::ZERO_EXTEND || OpOpcode ==ISD::SIGN_EXTEND ||
6371 OpOpcode ==ISD::ANY_EXTEND) {
6372SDNodeFlags Flags;
6373if (OpOpcode ==ISD::ZERO_EXTEND)
6374 Flags.setNonNeg(N1->getFlags().hasNonNeg());
6375// (ext (zext x)) -> (zext x) and (ext (sext x)) -> (sext x)
6376returngetNode(OpOpcode,DL, VT, N1.getOperand(0), Flags);
6377 }
6378if (OpOpcode ==ISD::UNDEF)
6379returngetUNDEF(VT);
6380
6381// (ext (trunc x)) -> x
6382if (OpOpcode ==ISD::TRUNCATE) {
6383SDValue OpOp = N1.getOperand(0);
6384if (OpOp.getValueType() == VT) {
6385transferDbgValues(N1, OpOp);
6386return OpOp;
6387 }
6388 }
6389break;
6390caseISD::TRUNCATE:
6391assert(VT.isInteger() && N1.getValueType().isInteger() &&
6392"Invalid TRUNCATE!");
6393assert(VT.isVector() == N1.getValueType().isVector() &&
6394"TRUNCATE result type type should be vector iff the operand "
6395"type is vector!");
6396if (N1.getValueType() == VT)return N1;// noop truncate
6397assert((!VT.isVector() || VT.getVectorElementCount() ==
6398 N1.getValueType().getVectorElementCount()) &&
6399"Vector element count mismatch!");
6400assert(N1.getValueType().bitsGT(VT) &&"Invalid truncate node, src < dst!");
6401if (OpOpcode ==ISD::TRUNCATE)
6402returngetNode(ISD::TRUNCATE,DL, VT, N1.getOperand(0));
6403if (OpOpcode ==ISD::ZERO_EXTEND || OpOpcode ==ISD::SIGN_EXTEND ||
6404 OpOpcode ==ISD::ANY_EXTEND) {
6405// If the source is smaller than the dest, we still need an extend.
6406if (N1.getOperand(0).getValueType().getScalarType().bitsLT(
6407 VT.getScalarType()))
6408returngetNode(OpOpcode,DL, VT, N1.getOperand(0));
6409if (N1.getOperand(0).getValueType().bitsGT(VT))
6410returngetNode(ISD::TRUNCATE,DL, VT, N1.getOperand(0));
6411return N1.getOperand(0);
6412 }
6413if (OpOpcode ==ISD::UNDEF)
6414returngetUNDEF(VT);
6415if (OpOpcode ==ISD::VSCALE && !NewNodesMustHaveLegalTypes)
6416returngetVScale(DL, VT,
6417 N1.getConstantOperandAPInt(0).trunc(VT.getSizeInBits()));
6418break;
6419caseISD::ANY_EXTEND_VECTOR_INREG:
6420caseISD::ZERO_EXTEND_VECTOR_INREG:
6421caseISD::SIGN_EXTEND_VECTOR_INREG:
6422assert(VT.isVector() &&"This DAG node is restricted to vector types.");
6423assert(N1.getValueType().bitsLE(VT) &&
6424"The input must be the same size or smaller than the result.");
6425assert(VT.getVectorMinNumElements() <
6426 N1.getValueType().getVectorMinNumElements() &&
6427"The destination vector type must have fewer lanes than the input.");
6428break;
6429caseISD::ABS:
6430assert(VT.isInteger() && VT == N1.getValueType() &&"Invalid ABS!");
6431if (OpOpcode ==ISD::UNDEF)
6432returngetConstant(0,DL, VT);
6433break;
6434caseISD::BSWAP:
6435assert(VT.isInteger() && VT == N1.getValueType() &&"Invalid BSWAP!");
6436assert((VT.getScalarSizeInBits() % 16 == 0) &&
6437"BSWAP types must be a multiple of 16 bits!");
6438if (OpOpcode ==ISD::UNDEF)
6439returngetUNDEF(VT);
6440// bswap(bswap(X)) -> X.
6441if (OpOpcode ==ISD::BSWAP)
6442return N1.getOperand(0);
6443break;
6444caseISD::BITREVERSE:
6445assert(VT.isInteger() && VT == N1.getValueType() &&"Invalid BITREVERSE!");
6446if (OpOpcode ==ISD::UNDEF)
6447returngetUNDEF(VT);
6448break;
6449caseISD::BITCAST:
6450assert(VT.getSizeInBits() == N1.getValueSizeInBits() &&
6451"Cannot BITCAST between types of different sizes!");
6452if (VT == N1.getValueType())return N1;// noop conversion.
6453if (OpOpcode ==ISD::BITCAST)// bitconv(bitconv(x)) -> bitconv(x)
6454returngetNode(ISD::BITCAST,DL, VT, N1.getOperand(0));
6455if (OpOpcode ==ISD::UNDEF)
6456returngetUNDEF(VT);
6457break;
6458caseISD::SCALAR_TO_VECTOR:
6459assert(VT.isVector() && !N1.getValueType().isVector() &&
6460 (VT.getVectorElementType() == N1.getValueType() ||
6461 (VT.getVectorElementType().isInteger() &&
6462 N1.getValueType().isInteger() &&
6463 VT.getVectorElementType().bitsLE(N1.getValueType()))) &&
6464"Illegal SCALAR_TO_VECTOR node!");
6465if (OpOpcode ==ISD::UNDEF)
6466returngetUNDEF(VT);
6467// scalar_to_vector(extract_vector_elt V, 0) -> V, top bits are undefined.
6468if (OpOpcode ==ISD::EXTRACT_VECTOR_ELT &&
6469 isa<ConstantSDNode>(N1.getOperand(1)) &&
6470 N1.getConstantOperandVal(1) == 0 &&
6471 N1.getOperand(0).getValueType() == VT)
6472return N1.getOperand(0);
6473break;
6474caseISD::FNEG:
6475// Negation of an unknown bag of bits is still completely undefined.
6476if (OpOpcode ==ISD::UNDEF)
6477returngetUNDEF(VT);
6478
6479if (OpOpcode ==ISD::FNEG)// --X -> X
6480return N1.getOperand(0);
6481break;
6482caseISD::FABS:
6483if (OpOpcode ==ISD::FNEG)// abs(-X) -> abs(X)
6484returngetNode(ISD::FABS,DL, VT, N1.getOperand(0));
6485break;
6486caseISD::VSCALE:
6487assert(VT == N1.getValueType() &&"Unexpected VT!");
6488break;
6489caseISD::CTPOP:
6490if (N1.getValueType().getScalarType() == MVT::i1)
6491return N1;
6492break;
6493caseISD::CTLZ:
6494caseISD::CTTZ:
6495if (N1.getValueType().getScalarType() == MVT::i1)
6496returngetNOT(DL, N1, N1.getValueType());
6497break;
6498caseISD::VECREDUCE_ADD:
6499if (N1.getValueType().getScalarType() == MVT::i1)
6500returngetNode(ISD::VECREDUCE_XOR,DL, VT, N1);
6501break;
6502caseISD::VECREDUCE_SMIN:
6503caseISD::VECREDUCE_UMAX:
6504if (N1.getValueType().getScalarType() == MVT::i1)
6505returngetNode(ISD::VECREDUCE_OR,DL, VT, N1);
6506break;
6507caseISD::VECREDUCE_SMAX:
6508caseISD::VECREDUCE_UMIN:
6509if (N1.getValueType().getScalarType() == MVT::i1)
6510returngetNode(ISD::VECREDUCE_AND,DL, VT, N1);
6511break;
6512caseISD::SPLAT_VECTOR:
6513assert(VT.isVector() &&"Wrong return type!");
6514// FIXME: Hexagon uses i32 scalar for a floating point zero vector so allow
6515// that for now.
6516assert((VT.getVectorElementType() == N1.getValueType() ||
6517 (VT.isFloatingPoint() && N1.getValueType() == MVT::i32) ||
6518 (VT.getVectorElementType().isInteger() &&
6519 N1.getValueType().isInteger() &&
6520 VT.getVectorElementType().bitsLE(N1.getValueType()))) &&
6521"Wrong operand type!");
6522break;
6523 }
6524
6525SDNode *N;
6526SDVTList VTs =getVTList(VT);
6527SDValue Ops[] = {N1};
6528if (VT != MVT::Glue) {// Don't CSE glue producing nodes
6529FoldingSetNodeIDID;
6530AddNodeIDNode(ID, Opcode, VTs, Ops);
6531void *IP =nullptr;
6532if (SDNode *E = FindNodeOrInsertPos(ID,DL, IP)) {
6533 E->intersectFlagsWith(Flags);
6534returnSDValue(E, 0);
6535 }
6536
6537N = newSDNode<SDNode>(Opcode,DL.getIROrder(),DL.getDebugLoc(), VTs);
6538N->setFlags(Flags);
6539 createOperands(N, Ops);
6540 CSEMap.InsertNode(N, IP);
6541 }else {
6542N = newSDNode<SDNode>(Opcode,DL.getIROrder(),DL.getDebugLoc(), VTs);
6543 createOperands(N, Ops);
6544 }
6545
6546 InsertNode(N);
6547SDValue V =SDValue(N, 0);
6548NewSDValueDbgMsg(V,"Creating new node: ",this);
6549return V;
6550}
6551
6552static std::optional<APInt>FoldValue(unsigned Opcode,constAPInt &C1,
6553constAPInt &C2) {
6554switch (Opcode) {
6555caseISD::ADD:return C1 + C2;
6556caseISD::SUB:return C1 - C2;
6557caseISD::MUL:return C1 * C2;
6558caseISD::AND:return C1 & C2;
6559caseISD::OR:return C1 | C2;
6560caseISD::XOR:return C1 ^ C2;
6561caseISD::SHL:return C1 << C2;
6562caseISD::SRL:return C1.lshr(C2);
6563caseISD::SRA:return C1.ashr(C2);
6564caseISD::ROTL:return C1.rotl(C2);
6565caseISD::ROTR:return C1.rotr(C2);
6566caseISD::SMIN:return C1.sle(C2) ? C1 : C2;
6567caseISD::SMAX:return C1.sge(C2) ? C1 : C2;
6568caseISD::UMIN:return C1.ule(C2) ? C1 : C2;
6569caseISD::UMAX:return C1.uge(C2) ? C1 : C2;
6570caseISD::SADDSAT:return C1.sadd_sat(C2);
6571caseISD::UADDSAT:return C1.uadd_sat(C2);
6572caseISD::SSUBSAT:return C1.ssub_sat(C2);
6573caseISD::USUBSAT:return C1.usub_sat(C2);
6574caseISD::SSHLSAT:return C1.sshl_sat(C2);
6575caseISD::USHLSAT:return C1.ushl_sat(C2);
6576caseISD::UDIV:
6577if (!C2.getBoolValue())
6578break;
6579return C1.udiv(C2);
6580caseISD::UREM:
6581if (!C2.getBoolValue())
6582break;
6583return C1.urem(C2);
6584caseISD::SDIV:
6585if (!C2.getBoolValue())
6586break;
6587return C1.sdiv(C2);
6588caseISD::SREM:
6589if (!C2.getBoolValue())
6590break;
6591return C1.srem(C2);
6592caseISD::AVGFLOORS:
6593returnAPIntOps::avgFloorS(C1, C2);
6594caseISD::AVGFLOORU:
6595returnAPIntOps::avgFloorU(C1, C2);
6596caseISD::AVGCEILS:
6597returnAPIntOps::avgCeilS(C1, C2);
6598caseISD::AVGCEILU:
6599returnAPIntOps::avgCeilU(C1, C2);
6600caseISD::ABDS:
6601returnAPIntOps::abds(C1, C2);
6602caseISD::ABDU:
6603returnAPIntOps::abdu(C1, C2);
6604caseISD::MULHS:
6605returnAPIntOps::mulhs(C1, C2);
6606caseISD::MULHU:
6607returnAPIntOps::mulhu(C1, C2);
6608 }
6609return std::nullopt;
6610}
6611// Handle constant folding with UNDEF.
6612// TODO: Handle more cases.
6613static std::optional<APInt>FoldValueWithUndef(unsigned Opcode,constAPInt &C1,
6614bool IsUndef1,constAPInt &C2,
6615bool IsUndef2) {
6616if (!(IsUndef1 || IsUndef2))
6617returnFoldValue(Opcode, C1, C2);
6618
6619// Fold and(x, undef) -> 0
6620// Fold mul(x, undef) -> 0
6621if (Opcode ==ISD::AND || Opcode ==ISD::MUL)
6622returnAPInt::getZero(C1.getBitWidth());
6623
6624return std::nullopt;
6625}
6626
6627SDValueSelectionDAG::FoldSymbolOffset(unsigned Opcode,EVT VT,
6628constGlobalAddressSDNode *GA,
6629constSDNode *N2) {
6630if (GA->getOpcode() !=ISD::GlobalAddress)
6631returnSDValue();
6632if (!TLI->isOffsetFoldingLegal(GA))
6633returnSDValue();
6634auto *C2 = dyn_cast<ConstantSDNode>(N2);
6635if (!C2)
6636returnSDValue();
6637 int64_tOffset = C2->getSExtValue();
6638switch (Opcode) {
6639caseISD::ADD:break;
6640caseISD::SUB:Offset = -uint64_t(Offset);break;
6641default:returnSDValue();
6642 }
6643returngetGlobalAddress(GA->getGlobal(),SDLoc(C2), VT,
6644 GA->getOffset() +uint64_t(Offset));
6645}
6646
6647boolSelectionDAG::isUndef(unsigned Opcode,ArrayRef<SDValue> Ops) {
6648switch (Opcode) {
6649caseISD::SDIV:
6650caseISD::UDIV:
6651caseISD::SREM:
6652caseISD::UREM: {
6653// If a divisor is zero/undef or any element of a divisor vector is
6654// zero/undef, the whole op is undef.
6655assert(Ops.size() == 2 &&"Div/rem should have 2 operands");
6656SDValue Divisor = Ops[1];
6657if (Divisor.isUndef() ||isNullConstant(Divisor))
6658returntrue;
6659
6660returnISD::isBuildVectorOfConstantSDNodes(Divisor.getNode()) &&
6661llvm::any_of(Divisor->op_values(),
6662 [](SDValue V) { return V.isUndef() ||
6663 isNullConstant(V); });
6664// TODO: Handle signed overflow.
6665 }
6666// TODO: Handle oversized shifts.
6667default:
6668returnfalse;
6669 }
6670}
6671
6672SDValueSelectionDAG::FoldConstantArithmetic(unsigned Opcode,constSDLoc &DL,
6673EVT VT,ArrayRef<SDValue> Ops,
6674SDNodeFlags Flags) {
6675// If the opcode is a target-specific ISD node, there's nothing we can
6676// do here and the operand rules may not line up with the below, so
6677// bail early.
6678// We can't create a scalar CONCAT_VECTORS so skip it. It will break
6679// for concats involving SPLAT_VECTOR. Concats of BUILD_VECTORS are handled by
6680// foldCONCAT_VECTORS in getNode before this is called.
6681if (Opcode >=ISD::BUILTIN_OP_END || Opcode ==ISD::CONCAT_VECTORS)
6682returnSDValue();
6683
6684unsigned NumOps = Ops.size();
6685if (NumOps == 0)
6686returnSDValue();
6687
6688if (isUndef(Opcode, Ops))
6689returngetUNDEF(VT);
6690
6691// Handle unary special cases.
6692if (NumOps == 1) {
6693SDValue N1 = Ops[0];
6694
6695// Constant fold unary operations with an integer constant operand. Even
6696// opaque constant will be folded, because the folding of unary operations
6697// doesn't create new constants with different values. Nevertheless, the
6698// opaque flag is preserved during folding to prevent future folding with
6699// other constants.
6700if (auto *C = dyn_cast<ConstantSDNode>(N1)) {
6701constAPInt &Val =C->getAPIntValue();
6702switch (Opcode) {
6703caseISD::SIGN_EXTEND:
6704returngetConstant(Val.sextOrTrunc(VT.getSizeInBits()),DL, VT,
6705C->isTargetOpcode(),C->isOpaque());
6706caseISD::TRUNCATE:
6707if (C->isOpaque())
6708break;
6709 [[fallthrough]];
6710caseISD::ZERO_EXTEND:
6711returngetConstant(Val.zextOrTrunc(VT.getSizeInBits()),DL, VT,
6712C->isTargetOpcode(),C->isOpaque());
6713caseISD::ANY_EXTEND:
6714// Some targets like RISCV prefer to sign extend some types.
6715if (TLI->isSExtCheaperThanZExt(N1.getValueType(), VT))
6716returngetConstant(Val.sextOrTrunc(VT.getSizeInBits()),DL, VT,
6717C->isTargetOpcode(),C->isOpaque());
6718returngetConstant(Val.zextOrTrunc(VT.getSizeInBits()),DL, VT,
6719C->isTargetOpcode(),C->isOpaque());
6720caseISD::ABS:
6721returngetConstant(Val.abs(),DL, VT,C->isTargetOpcode(),
6722C->isOpaque());
6723caseISD::BITREVERSE:
6724returngetConstant(Val.reverseBits(),DL, VT,C->isTargetOpcode(),
6725C->isOpaque());
6726caseISD::BSWAP:
6727returngetConstant(Val.byteSwap(),DL, VT,C->isTargetOpcode(),
6728C->isOpaque());
6729caseISD::CTPOP:
6730returngetConstant(Val.popcount(),DL, VT,C->isTargetOpcode(),
6731C->isOpaque());
6732caseISD::CTLZ:
6733caseISD::CTLZ_ZERO_UNDEF:
6734returngetConstant(Val.countl_zero(),DL, VT,C->isTargetOpcode(),
6735C->isOpaque());
6736caseISD::CTTZ:
6737caseISD::CTTZ_ZERO_UNDEF:
6738returngetConstant(Val.countr_zero(),DL, VT,C->isTargetOpcode(),
6739C->isOpaque());
6740caseISD::UINT_TO_FP:
6741caseISD::SINT_TO_FP: {
6742APFloat FPV(VT.getFltSemantics(),APInt::getZero(VT.getSizeInBits()));
6743 (void)FPV.convertFromAPInt(Val, Opcode ==ISD::SINT_TO_FP,
6744APFloat::rmNearestTiesToEven);
6745returngetConstantFP(FPV,DL, VT);
6746 }
6747caseISD::FP16_TO_FP:
6748caseISD::BF16_TO_FP: {
6749bool Ignored;
6750APFloat FPV(Opcode ==ISD::FP16_TO_FP ?APFloat::IEEEhalf()
6751 :APFloat::BFloat(),
6752 (Val.getBitWidth() == 16) ? Val : Val.trunc(16));
6753
6754// This can return overflow, underflow, or inexact; we don't care.
6755// FIXME need to be more flexible about rounding mode.
6756 (void)FPV.convert(VT.getFltSemantics(),APFloat::rmNearestTiesToEven,
6757 &Ignored);
6758returngetConstantFP(FPV,DL, VT);
6759 }
6760caseISD::STEP_VECTOR:
6761if (SDValue V =FoldSTEP_VECTOR(DL, VT, N1, *this))
6762return V;
6763break;
6764caseISD::BITCAST:
6765if (VT == MVT::f16 &&C->getValueType(0) == MVT::i16)
6766returngetConstantFP(APFloat(APFloat::IEEEhalf(), Val),DL, VT);
6767if (VT == MVT::f32 &&C->getValueType(0) == MVT::i32)
6768returngetConstantFP(APFloat(APFloat::IEEEsingle(), Val),DL, VT);
6769if (VT == MVT::f64 &&C->getValueType(0) == MVT::i64)
6770returngetConstantFP(APFloat(APFloat::IEEEdouble(), Val),DL, VT);
6771if (VT == MVT::f128 &&C->getValueType(0) == MVT::i128)
6772returngetConstantFP(APFloat(APFloat::IEEEquad(), Val),DL, VT);
6773break;
6774 }
6775 }
6776
6777// Constant fold unary operations with a floating point constant operand.
6778if (auto *C = dyn_cast<ConstantFPSDNode>(N1)) {
6779APFloat V =C->getValueAPF();// make copy
6780switch (Opcode) {
6781caseISD::FNEG:
6782 V.changeSign();
6783returngetConstantFP(V,DL, VT);
6784caseISD::FABS:
6785 V.clearSign();
6786returngetConstantFP(V,DL, VT);
6787caseISD::FCEIL: {
6788APFloat::opStatus fs = V.roundToIntegral(APFloat::rmTowardPositive);
6789if (fs ==APFloat::opOK || fs ==APFloat::opInexact)
6790returngetConstantFP(V,DL, VT);
6791returnSDValue();
6792 }
6793caseISD::FTRUNC: {
6794APFloat::opStatus fs = V.roundToIntegral(APFloat::rmTowardZero);
6795if (fs ==APFloat::opOK || fs ==APFloat::opInexact)
6796returngetConstantFP(V,DL, VT);
6797returnSDValue();
6798 }
6799caseISD::FFLOOR: {
6800APFloat::opStatus fs = V.roundToIntegral(APFloat::rmTowardNegative);
6801if (fs ==APFloat::opOK || fs ==APFloat::opInexact)
6802returngetConstantFP(V,DL, VT);
6803returnSDValue();
6804 }
6805caseISD::FP_EXTEND: {
6806boolignored;
6807// This can return overflow, underflow, or inexact; we don't care.
6808// FIXME need to be more flexible about rounding mode.
6809 (void)V.convert(VT.getFltSemantics(),APFloat::rmNearestTiesToEven,
6810 &ignored);
6811returngetConstantFP(V,DL, VT);
6812 }
6813caseISD::FP_TO_SINT:
6814caseISD::FP_TO_UINT: {
6815boolignored;
6816APSInt IntVal(VT.getSizeInBits(), Opcode ==ISD::FP_TO_UINT);
6817// FIXME need to be more flexible about rounding mode.
6818APFloat::opStatus s =
6819 V.convertToInteger(IntVal,APFloat::rmTowardZero, &ignored);
6820if (s ==APFloat::opInvalidOp)// inexact is OK, in fact usual
6821break;
6822returngetConstant(IntVal,DL, VT);
6823 }
6824caseISD::FP_TO_FP16:
6825caseISD::FP_TO_BF16: {
6826bool Ignored;
6827// This can return overflow, underflow, or inexact; we don't care.
6828// FIXME need to be more flexible about rounding mode.
6829 (void)V.convert(Opcode ==ISD::FP_TO_FP16 ?APFloat::IEEEhalf()
6830 :APFloat::BFloat(),
6831APFloat::rmNearestTiesToEven, &Ignored);
6832returngetConstant(V.bitcastToAPInt().getZExtValue(),DL, VT);
6833 }
6834caseISD::BITCAST:
6835if (VT == MVT::i16 &&C->getValueType(0) == MVT::f16)
6836returngetConstant((uint16_t)V.bitcastToAPInt().getZExtValue(),DL,
6837 VT);
6838if (VT == MVT::i16 &&C->getValueType(0) == MVT::bf16)
6839returngetConstant((uint16_t)V.bitcastToAPInt().getZExtValue(),DL,
6840 VT);
6841if (VT == MVT::i32 &&C->getValueType(0) == MVT::f32)
6842returngetConstant((uint32_t)V.bitcastToAPInt().getZExtValue(),DL,
6843 VT);
6844if (VT == MVT::i64 &&C->getValueType(0) == MVT::f64)
6845returngetConstant(V.bitcastToAPInt().getZExtValue(),DL, VT);
6846break;
6847 }
6848 }
6849
6850// Early-out if we failed to constant fold a bitcast.
6851if (Opcode ==ISD::BITCAST)
6852returnSDValue();
6853 }
6854
6855// Handle binops special cases.
6856if (NumOps == 2) {
6857if (SDValue CFP =foldConstantFPMath(Opcode,DL, VT, Ops))
6858return CFP;
6859
6860if (auto *C1 = dyn_cast<ConstantSDNode>(Ops[0])) {
6861if (auto *C2 = dyn_cast<ConstantSDNode>(Ops[1])) {
6862if (C1->isOpaque() || C2->isOpaque())
6863returnSDValue();
6864
6865 std::optional<APInt> FoldAttempt =
6866FoldValue(Opcode, C1->getAPIntValue(), C2->getAPIntValue());
6867if (!FoldAttempt)
6868returnSDValue();
6869
6870SDValue Folded =getConstant(*FoldAttempt,DL, VT);
6871assert((!Folded || !VT.isVector()) &&
6872"Can't fold vectors ops with scalar operands");
6873return Folded;
6874 }
6875 }
6876
6877// fold (add Sym, c) -> Sym+c
6878if (GlobalAddressSDNode *GA = dyn_cast<GlobalAddressSDNode>(Ops[0]))
6879returnFoldSymbolOffset(Opcode, VT, GA, Ops[1].getNode());
6880if (TLI->isCommutativeBinOp(Opcode))
6881if (GlobalAddressSDNode *GA = dyn_cast<GlobalAddressSDNode>(Ops[1]))
6882returnFoldSymbolOffset(Opcode, VT, GA, Ops[0].getNode());
6883
6884// fold (sext_in_reg c1) -> c2
6885if (Opcode ==ISD::SIGN_EXTEND_INREG) {
6886EVTEVT = cast<VTSDNode>(Ops[1])->getVT();
6887
6888auto SignExtendInReg = [&](APInt Val,llvm::EVT ConstantVT) {
6889unsigned FromBits =EVT.getScalarSizeInBits();
6890 Val <<= Val.getBitWidth() - FromBits;
6891 Val.ashrInPlace(Val.getBitWidth() - FromBits);
6892returngetConstant(Val,DL, ConstantVT);
6893 };
6894
6895if (auto *C1 = dyn_cast<ConstantSDNode>(Ops[0])) {
6896constAPInt &Val = C1->getAPIntValue();
6897return SignExtendInReg(Val, VT);
6898 }
6899
6900if (ISD::isBuildVectorOfConstantSDNodes(Ops[0].getNode())) {
6901SmallVector<SDValue, 8> ScalarOps;
6902llvm::EVT OpVT = Ops[0].getOperand(0).getValueType();
6903for (intI = 0, E = VT.getVectorNumElements();I != E; ++I) {
6904SDValueOp = Ops[0].getOperand(I);
6905if (Op.isUndef()) {
6906 ScalarOps.push_back(getUNDEF(OpVT));
6907continue;
6908 }
6909constAPInt &Val = cast<ConstantSDNode>(Op)->getAPIntValue();
6910 ScalarOps.push_back(SignExtendInReg(Val, OpVT));
6911 }
6912returngetBuildVector(VT,DL, ScalarOps);
6913 }
6914
6915if (Ops[0].getOpcode() ==ISD::SPLAT_VECTOR &&
6916 isa<ConstantSDNode>(Ops[0].getOperand(0)))
6917returngetNode(ISD::SPLAT_VECTOR,DL, VT,
6918 SignExtendInReg(Ops[0].getConstantOperandAPInt(0),
6919 Ops[0].getOperand(0).getValueType()));
6920 }
6921 }
6922
6923// This is for vector folding only from here on.
6924if (!VT.isVector())
6925returnSDValue();
6926
6927ElementCount NumElts = VT.getVectorElementCount();
6928
6929// See if we can fold through any bitcasted integer ops.
6930if (NumOps == 2 && VT.isFixedLengthVector() && VT.isInteger() &&
6931 Ops[0].getValueType() == VT && Ops[1].getValueType() == VT &&
6932 (Ops[0].getOpcode() ==ISD::BITCAST ||
6933 Ops[1].getOpcode() ==ISD::BITCAST)) {
6934SDValue N1 =peekThroughBitcasts(Ops[0]);
6935SDValue N2 =peekThroughBitcasts(Ops[1]);
6936auto *BV1 = dyn_cast<BuildVectorSDNode>(N1);
6937auto *BV2 = dyn_cast<BuildVectorSDNode>(N2);
6938if (BV1 && BV2 && N1.getValueType().isInteger() &&
6939 N2.getValueType().isInteger()) {
6940bool IsLE =getDataLayout().isLittleEndian();
6941unsigned EltBits = VT.getScalarSizeInBits();
6942SmallVector<APInt> RawBits1, RawBits2;
6943BitVector UndefElts1, UndefElts2;
6944if (BV1->getConstantRawBits(IsLE, EltBits, RawBits1, UndefElts1) &&
6945 BV2->getConstantRawBits(IsLE, EltBits, RawBits2, UndefElts2)) {
6946SmallVector<APInt> RawBits;
6947for (unsignedI = 0, E = NumElts.getFixedValue();I != E; ++I) {
6948 std::optional<APInt> Fold =FoldValueWithUndef(
6949 Opcode, RawBits1[I], UndefElts1[I], RawBits2[I], UndefElts2[I]);
6950if (!Fold)
6951break;
6952 RawBits.push_back(*Fold);
6953 }
6954if (RawBits.size() == NumElts.getFixedValue()) {
6955// We have constant folded, but we might need to cast this again back
6956// to the original (possibly legalized) type.
6957EVT BVVT, BVEltVT;
6958if (N1.getValueType() == VT) {
6959 BVVT = N1.getValueType();
6960 BVEltVT = BV1->getOperand(0).getValueType();
6961 }else {
6962 BVVT = N2.getValueType();
6963 BVEltVT = BV2->getOperand(0).getValueType();
6964 }
6965unsigned BVEltBits = BVEltVT.getSizeInBits();
6966SmallVector<APInt> DstBits;
6967BitVector DstUndefs;
6968BuildVectorSDNode::recastRawBits(IsLE, BVVT.getScalarSizeInBits(),
6969 DstBits, RawBits, DstUndefs,
6970BitVector(RawBits.size(),false));
6971SmallVector<SDValue> Ops(DstBits.size(),getUNDEF(BVEltVT));
6972for (unsignedI = 0, E = DstBits.size();I != E; ++I) {
6973if (DstUndefs[I])
6974continue;
6975 Ops[I] =getConstant(DstBits[I].sext(BVEltBits),DL, BVEltVT);
6976 }
6977returngetBitcast(VT,getBuildVector(BVVT,DL, Ops));
6978 }
6979 }
6980 }
6981 }
6982
6983// Fold (mul step_vector(C0), C1) to (step_vector(C0 * C1)).
6984// (shl step_vector(C0), C1) -> (step_vector(C0 << C1))
6985if ((Opcode ==ISD::MUL || Opcode ==ISD::SHL) &&
6986 Ops[0].getOpcode() ==ISD::STEP_VECTOR) {
6987APInt RHSVal;
6988if (ISD::isConstantSplatVector(Ops[1].getNode(), RHSVal)) {
6989APInt NewStep = Opcode ==ISD::MUL
6990 ? Ops[0].getConstantOperandAPInt(0) * RHSVal
6991 : Ops[0].getConstantOperandAPInt(0) << RHSVal;
6992returngetStepVector(DL, VT, NewStep);
6993 }
6994 }
6995
6996auto IsScalarOrSameVectorSize = [NumElts](constSDValue &Op) {
6997return !Op.getValueType().isVector() ||
6998Op.getValueType().getVectorElementCount() == NumElts;
6999 };
7000
7001auto IsBuildVectorSplatVectorOrUndef = [](constSDValue &Op) {
7002returnOp.isUndef() ||Op.getOpcode() ==ISD::CONDCODE ||
7003Op.getOpcode() ==ISD::BUILD_VECTOR ||
7004Op.getOpcode() ==ISD::SPLAT_VECTOR;
7005 };
7006
7007// All operands must be vector types with the same number of elements as
7008// the result type and must be either UNDEF or a build/splat vector
7009// or UNDEF scalars.
7010if (!llvm::all_of(Ops, IsBuildVectorSplatVectorOrUndef) ||
7011 !llvm::all_of(Ops, IsScalarOrSameVectorSize))
7012returnSDValue();
7013
7014// If we are comparing vectors, then the result needs to be a i1 boolean that
7015// is then extended back to the legal result type depending on how booleans
7016// are represented.
7017EVT SVT = (Opcode ==ISD::SETCC ? MVT::i1 : VT.getScalarType());
7018ISD::NodeType ExtendCode =
7019 (Opcode ==ISD::SETCC && SVT != VT.getScalarType())
7020 ?TargetLowering::getExtendForContent(TLI->getBooleanContents(VT))
7021 :ISD::SIGN_EXTEND;
7022
7023// Find legal integer scalar type for constant promotion and
7024// ensure that its scalar size is at least as large as source.
7025EVT LegalSVT = VT.getScalarType();
7026if (NewNodesMustHaveLegalTypes && LegalSVT.isInteger()) {
7027 LegalSVT = TLI->getTypeToTransformTo(*getContext(), LegalSVT);
7028if (LegalSVT.bitsLT(VT.getScalarType()))
7029returnSDValue();
7030 }
7031
7032// For scalable vector types we know we're dealing with SPLAT_VECTORs. We
7033// only have one operand to check. For fixed-length vector types we may have
7034// a combination of BUILD_VECTOR and SPLAT_VECTOR.
7035unsigned NumVectorElts = NumElts.isScalable() ? 1 : NumElts.getFixedValue();
7036
7037// Constant fold each scalar lane separately.
7038SmallVector<SDValue, 4> ScalarResults;
7039for (unsignedI = 0;I != NumVectorElts;I++) {
7040SmallVector<SDValue, 4> ScalarOps;
7041for (SDValueOp : Ops) {
7042EVT InSVT =Op.getValueType().getScalarType();
7043if (Op.getOpcode() !=ISD::BUILD_VECTOR &&
7044Op.getOpcode() !=ISD::SPLAT_VECTOR) {
7045if (Op.isUndef())
7046 ScalarOps.push_back(getUNDEF(InSVT));
7047else
7048 ScalarOps.push_back(Op);
7049continue;
7050 }
7051
7052SDValue ScalarOp =
7053Op.getOperand(Op.getOpcode() ==ISD::SPLAT_VECTOR ? 0 :I);
7054EVT ScalarVT = ScalarOp.getValueType();
7055
7056// Build vector (integer) scalar operands may need implicit
7057// truncation - do this before constant folding.
7058if (ScalarVT.isInteger() && ScalarVT.bitsGT(InSVT)) {
7059// Don't create illegally-typed nodes unless they're constants or undef
7060// - if we fail to constant fold we can't guarantee the (dead) nodes
7061// we're creating will be cleaned up before being visited for
7062// legalization.
7063if (NewNodesMustHaveLegalTypes && !ScalarOp.isUndef() &&
7064 !isa<ConstantSDNode>(ScalarOp) &&
7065 TLI->getTypeAction(*getContext(), InSVT) !=
7066TargetLowering::TypeLegal)
7067returnSDValue();
7068 ScalarOp =getNode(ISD::TRUNCATE,DL, InSVT, ScalarOp);
7069 }
7070
7071 ScalarOps.push_back(ScalarOp);
7072 }
7073
7074// Constant fold the scalar operands.
7075SDValue ScalarResult =getNode(Opcode,DL, SVT, ScalarOps, Flags);
7076
7077// Scalar folding only succeeded if the result is a constant or UNDEF.
7078if (!ScalarResult.isUndef() && ScalarResult.getOpcode() !=ISD::Constant &&
7079 ScalarResult.getOpcode() !=ISD::ConstantFP)
7080returnSDValue();
7081
7082// Legalize the (integer) scalar constant if necessary. We only do
7083// this once we know the folding succeeded, since otherwise we would
7084// get a node with illegal type which has a user.
7085if (LegalSVT != SVT)
7086 ScalarResult =getNode(ExtendCode,DL, LegalSVT, ScalarResult);
7087
7088 ScalarResults.push_back(ScalarResult);
7089 }
7090
7091SDValue V = NumElts.isScalable() ?getSplatVector(VT,DL, ScalarResults[0])
7092 :getBuildVector(VT,DL, ScalarResults);
7093NewSDValueDbgMsg(V,"New node fold constant vector: ",this);
7094return V;
7095}
7096
7097SDValueSelectionDAG::foldConstantFPMath(unsigned Opcode,constSDLoc &DL,
7098EVT VT,ArrayRef<SDValue> Ops) {
7099// TODO: Add support for unary/ternary fp opcodes.
7100if (Ops.size() != 2)
7101returnSDValue();
7102
7103// TODO: We don't do any constant folding for strict FP opcodes here, but we
7104// should. That will require dealing with a potentially non-default
7105// rounding mode, checking the "opStatus" return value from the APFloat
7106// math calculations, and possibly other variations.
7107SDValue N1 = Ops[0];
7108SDValue N2 = Ops[1];
7109ConstantFPSDNode *N1CFP =isConstOrConstSplatFP(N1,/*AllowUndefs*/false);
7110ConstantFPSDNode *N2CFP =isConstOrConstSplatFP(N2,/*AllowUndefs*/false);
7111if (N1CFP && N2CFP) {
7112APFloat C1 = N1CFP->getValueAPF();// make copy
7113constAPFloat &C2 = N2CFP->getValueAPF();
7114switch (Opcode) {
7115caseISD::FADD:
7116 C1.add(C2,APFloat::rmNearestTiesToEven);
7117returngetConstantFP(C1,DL, VT);
7118caseISD::FSUB:
7119 C1.subtract(C2,APFloat::rmNearestTiesToEven);
7120returngetConstantFP(C1,DL, VT);
7121caseISD::FMUL:
7122 C1.multiply(C2,APFloat::rmNearestTiesToEven);
7123returngetConstantFP(C1,DL, VT);
7124caseISD::FDIV:
7125 C1.divide(C2,APFloat::rmNearestTiesToEven);
7126returngetConstantFP(C1,DL, VT);
7127caseISD::FREM:
7128 C1.mod(C2);
7129returngetConstantFP(C1,DL, VT);
7130caseISD::FCOPYSIGN:
7131 C1.copySign(C2);
7132returngetConstantFP(C1,DL, VT);
7133caseISD::FMINNUM:
7134returngetConstantFP(minnum(C1, C2),DL, VT);
7135caseISD::FMAXNUM:
7136returngetConstantFP(maxnum(C1, C2),DL, VT);
7137caseISD::FMINIMUM:
7138returngetConstantFP(minimum(C1, C2),DL, VT);
7139caseISD::FMAXIMUM:
7140returngetConstantFP(maximum(C1, C2),DL, VT);
7141caseISD::FMINIMUMNUM:
7142returngetConstantFP(minimumnum(C1, C2),DL, VT);
7143caseISD::FMAXIMUMNUM:
7144returngetConstantFP(maximumnum(C1, C2),DL, VT);
7145default:break;
7146 }
7147 }
7148if (N1CFP && Opcode ==ISD::FP_ROUND) {
7149APFloat C1 = N1CFP->getValueAPF();// make copy
7150bool Unused;
7151// This can return overflow, underflow, or inexact; we don't care.
7152// FIXME need to be more flexible about rounding mode.
7153 (void)C1.convert(VT.getFltSemantics(),APFloat::rmNearestTiesToEven,
7154 &Unused);
7155returngetConstantFP(C1,DL, VT);
7156 }
7157
7158switch (Opcode) {
7159caseISD::FSUB:
7160// -0.0 - undef --> undef (consistent with "fneg undef")
7161if (ConstantFPSDNode *N1C =isConstOrConstSplatFP(N1,/*AllowUndefs*/true))
7162if (N1C && N1C->getValueAPF().isNegZero() && N2.isUndef())
7163returngetUNDEF(VT);
7164 [[fallthrough]];
7165
7166caseISD::FADD:
7167caseISD::FMUL:
7168caseISD::FDIV:
7169caseISD::FREM:
7170// If both operands are undef, the result is undef. If 1 operand is undef,
7171// the result is NaN. This should match the behavior of the IR optimizer.
7172if (N1.isUndef() && N2.isUndef())
7173returngetUNDEF(VT);
7174if (N1.isUndef() || N2.isUndef())
7175returngetConstantFP(APFloat::getNaN(VT.getFltSemantics()),DL, VT);
7176 }
7177returnSDValue();
7178}
7179
7180SDValueSelectionDAG::getAssertAlign(constSDLoc &DL,SDValue Val,AlignA) {
7181assert(Val.getValueType().isInteger() &&"Invalid AssertAlign!");
7182
7183// There's no need to assert on a byte-aligned pointer. All pointers are at
7184// least byte aligned.
7185if (A ==Align(1))
7186return Val;
7187
7188SDVTList VTs =getVTList(Val.getValueType());
7189FoldingSetNodeIDID;
7190AddNodeIDNode(ID,ISD::AssertAlign, VTs, {Val});
7191ID.AddInteger(A.value());
7192
7193void *IP =nullptr;
7194if (SDNode *E = FindNodeOrInsertPos(ID,DL, IP))
7195returnSDValue(E, 0);
7196
7197auto *N =
7198 newSDNode<AssertAlignSDNode>(DL.getIROrder(),DL.getDebugLoc(), VTs,A);
7199 createOperands(N, {Val});
7200
7201 CSEMap.InsertNode(N, IP);
7202 InsertNode(N);
7203
7204SDValue V(N, 0);
7205NewSDValueDbgMsg(V,"Creating new node: ",this);
7206return V;
7207}
7208
7209SDValueSelectionDAG::getNode(unsigned Opcode,constSDLoc &DL,EVT VT,
7210SDValue N1,SDValue N2) {
7211SDNodeFlags Flags;
7212if (Inserter)
7213 Flags = Inserter->getFlags();
7214returngetNode(Opcode,DL, VT, N1, N2, Flags);
7215}
7216
7217voidSelectionDAG::canonicalizeCommutativeBinop(unsigned Opcode,SDValue &N1,
7218SDValue &N2) const{
7219if (!TLI->isCommutativeBinOp(Opcode))
7220return;
7221
7222// Canonicalize:
7223// binop(const, nonconst) -> binop(nonconst, const)
7224bool N1C =isConstantIntBuildVectorOrConstantInt(N1);
7225bool N2C =isConstantIntBuildVectorOrConstantInt(N2);
7226bool N1CFP =isConstantFPBuildVectorOrConstantFP(N1);
7227bool N2CFP =isConstantFPBuildVectorOrConstantFP(N2);
7228if ((N1C && !N2C) || (N1CFP && !N2CFP))
7229std::swap(N1, N2);
7230
7231// Canonicalize:
7232// binop(splat(x), step_vector) -> binop(step_vector, splat(x))
7233elseif (N1.getOpcode() ==ISD::SPLAT_VECTOR &&
7234 N2.getOpcode() ==ISD::STEP_VECTOR)
7235std::swap(N1, N2);
7236}
7237
7238SDValueSelectionDAG::getNode(unsigned Opcode,constSDLoc &DL,EVT VT,
7239SDValue N1,SDValue N2,constSDNodeFlags Flags) {
7240assert(N1.getOpcode() !=ISD::DELETED_NODE &&
7241 N2.getOpcode() !=ISD::DELETED_NODE &&
7242"Operand is DELETED_NODE!");
7243
7244canonicalizeCommutativeBinop(Opcode, N1, N2);
7245
7246auto *N1C = dyn_cast<ConstantSDNode>(N1);
7247auto *N2C = dyn_cast<ConstantSDNode>(N2);
7248
7249// Don't allow undefs in vector splats - we might be returning N2 when folding
7250// to zero etc.
7251ConstantSDNode *N2CV =
7252isConstOrConstSplat(N2,/*AllowUndefs*/false,/*AllowTruncation*/true);
7253
7254switch (Opcode) {
7255default:break;
7256caseISD::TokenFactor:
7257assert(VT == MVT::Other && N1.getValueType() == MVT::Other &&
7258 N2.getValueType() == MVT::Other &&"Invalid token factor!");
7259// Fold trivial token factors.
7260if (N1.getOpcode() ==ISD::EntryToken)return N2;
7261if (N2.getOpcode() ==ISD::EntryToken)return N1;
7262if (N1 == N2)return N1;
7263break;
7264caseISD::BUILD_VECTOR: {
7265// Attempt to simplify BUILD_VECTOR.
7266SDValue Ops[] = {N1, N2};
7267if (SDValue V =FoldBUILD_VECTOR(DL, VT, Ops, *this))
7268return V;
7269break;
7270 }
7271caseISD::CONCAT_VECTORS: {
7272SDValue Ops[] = {N1, N2};
7273if (SDValue V =foldCONCAT_VECTORS(DL, VT, Ops, *this))
7274return V;
7275break;
7276 }
7277caseISD::AND:
7278assert(VT.isInteger() &&"This operator does not apply to FP types!");
7279assert(N1.getValueType() == N2.getValueType() &&
7280 N1.getValueType() == VT &&"Binary operator types must match!");
7281// (X & 0) -> 0. This commonly occurs when legalizing i64 values, so it's
7282// worth handling here.
7283if (N2CV && N2CV->isZero())
7284return N2;
7285if (N2CV && N2CV->isAllOnes())// X & -1 -> X
7286return N1;
7287break;
7288caseISD::OR:
7289caseISD::XOR:
7290caseISD::ADD:
7291caseISD::SUB:
7292assert(VT.isInteger() &&"This operator does not apply to FP types!");
7293assert(N1.getValueType() == N2.getValueType() &&
7294 N1.getValueType() == VT &&"Binary operator types must match!");
7295// (X ^|+- 0) -> X. This commonly occurs when legalizing i64 values, so
7296// it's worth handling here.
7297if (N2CV && N2CV->isZero())
7298return N1;
7299if ((Opcode ==ISD::ADD || Opcode ==ISD::SUB) && VT.isVector() &&
7300 VT.getVectorElementType() == MVT::i1)
7301returngetNode(ISD::XOR,DL, VT, N1, N2);
7302break;
7303caseISD::MUL:
7304assert(VT.isInteger() &&"This operator does not apply to FP types!");
7305assert(N1.getValueType() == N2.getValueType() &&
7306 N1.getValueType() == VT &&"Binary operator types must match!");
7307if (VT.isVector() && VT.getVectorElementType() == MVT::i1)
7308returngetNode(ISD::AND,DL, VT, N1, N2);
7309if (N2C && (N1.getOpcode() ==ISD::VSCALE) && Flags.hasNoSignedWrap()) {
7310constAPInt &MulImm = N1->getConstantOperandAPInt(0);
7311constAPInt &N2CImm = N2C->getAPIntValue();
7312returngetVScale(DL, VT, MulImm * N2CImm);
7313 }
7314break;
7315caseISD::UDIV:
7316caseISD::UREM:
7317caseISD::MULHU:
7318caseISD::MULHS:
7319caseISD::SDIV:
7320caseISD::SREM:
7321caseISD::SADDSAT:
7322caseISD::SSUBSAT:
7323caseISD::UADDSAT:
7324caseISD::USUBSAT:
7325assert(VT.isInteger() &&"This operator does not apply to FP types!");
7326assert(N1.getValueType() == N2.getValueType() &&
7327 N1.getValueType() == VT &&"Binary operator types must match!");
7328if (VT.isVector() && VT.getVectorElementType() == MVT::i1) {
7329// fold (add_sat x, y) -> (or x, y) for bool types.
7330if (Opcode ==ISD::SADDSAT || Opcode ==ISD::UADDSAT)
7331returngetNode(ISD::OR,DL, VT, N1, N2);
7332// fold (sub_sat x, y) -> (and x, ~y) for bool types.
7333if (Opcode ==ISD::SSUBSAT || Opcode ==ISD::USUBSAT)
7334returngetNode(ISD::AND,DL, VT, N1,getNOT(DL, N2, VT));
7335 }
7336break;
7337caseISD::SCMP:
7338caseISD::UCMP:
7339assert(N1.getValueType() == N2.getValueType() &&
7340"Types of operands of UCMP/SCMP must match");
7341assert(N1.getValueType().isVector() == VT.isVector() &&
7342"Operands and return type of must both be scalars or vectors");
7343if (VT.isVector())
7344assert(VT.getVectorElementCount() ==
7345 N1.getValueType().getVectorElementCount() &&
7346"Result and operands must have the same number of elements");
7347break;
7348caseISD::AVGFLOORS:
7349caseISD::AVGFLOORU:
7350caseISD::AVGCEILS:
7351caseISD::AVGCEILU:
7352assert(VT.isInteger() &&"This operator does not apply to FP types!");
7353assert(N1.getValueType() == N2.getValueType() &&
7354 N1.getValueType() == VT &&"Binary operator types must match!");
7355break;
7356caseISD::ABDS:
7357caseISD::ABDU:
7358assert(VT.isInteger() &&"This operator does not apply to FP types!");
7359assert(N1.getValueType() == N2.getValueType() &&
7360 N1.getValueType() == VT &&"Binary operator types must match!");
7361if (VT.isVector() && VT.getVectorElementType() == MVT::i1)
7362returngetNode(ISD::XOR,DL, VT, N1, N2);
7363break;
7364caseISD::SMIN:
7365caseISD::UMAX:
7366assert(VT.isInteger() &&"This operator does not apply to FP types!");
7367assert(N1.getValueType() == N2.getValueType() &&
7368 N1.getValueType() == VT &&"Binary operator types must match!");
7369if (VT.isVector() && VT.getVectorElementType() == MVT::i1)
7370returngetNode(ISD::OR,DL, VT, N1, N2);
7371break;
7372caseISD::SMAX:
7373caseISD::UMIN:
7374assert(VT.isInteger() &&"This operator does not apply to FP types!");
7375assert(N1.getValueType() == N2.getValueType() &&
7376 N1.getValueType() == VT &&"Binary operator types must match!");
7377if (VT.isVector() && VT.getVectorElementType() == MVT::i1)
7378returngetNode(ISD::AND,DL, VT, N1, N2);
7379break;
7380caseISD::FADD:
7381caseISD::FSUB:
7382caseISD::FMUL:
7383caseISD::FDIV:
7384caseISD::FREM:
7385assert(VT.isFloatingPoint() &&"This operator only applies to FP types!");
7386assert(N1.getValueType() == N2.getValueType() &&
7387 N1.getValueType() == VT &&"Binary operator types must match!");
7388if (SDValue V =simplifyFPBinop(Opcode, N1, N2, Flags))
7389return V;
7390break;
7391caseISD::FCOPYSIGN:// N1 and result must match. N1/N2 need not match.
7392assert(N1.getValueType() == VT &&
7393 N1.getValueType().isFloatingPoint() &&
7394 N2.getValueType().isFloatingPoint() &&
7395"Invalid FCOPYSIGN!");
7396break;
7397caseISD::SHL:
7398if (N2C && (N1.getOpcode() ==ISD::VSCALE) && Flags.hasNoSignedWrap()) {
7399constAPInt &MulImm = N1->getConstantOperandAPInt(0);
7400constAPInt &ShiftImm = N2C->getAPIntValue();
7401returngetVScale(DL, VT, MulImm << ShiftImm);
7402 }
7403 [[fallthrough]];
7404caseISD::SRA:
7405caseISD::SRL:
7406if (SDValue V =simplifyShift(N1, N2))
7407return V;
7408 [[fallthrough]];
7409caseISD::ROTL:
7410caseISD::ROTR:
7411assert(VT == N1.getValueType() &&
7412"Shift operators return type must be the same as their first arg");
7413assert(VT.isInteger() && N2.getValueType().isInteger() &&
7414"Shifts only work on integers");
7415assert((!VT.isVector() || VT == N2.getValueType()) &&
7416"Vector shift amounts must be in the same as their first arg");
7417// Verify that the shift amount VT is big enough to hold valid shift
7418// amounts. This catches things like trying to shift an i1024 value by an
7419// i8, which is easy to fall into in generic code that uses
7420// TLI.getShiftAmount().
7421assert(N2.getValueType().getScalarSizeInBits() >=
7422Log2_32_Ceil(VT.getScalarSizeInBits()) &&
7423"Invalid use of small shift amount with oversized value!");
7424
7425// Always fold shifts of i1 values so the code generator doesn't need to
7426// handle them. Since we know the size of the shift has to be less than the
7427// size of the value, the shift/rotate count is guaranteed to be zero.
7428if (VT == MVT::i1)
7429return N1;
7430if (N2CV && N2CV->isZero())
7431return N1;
7432break;
7433caseISD::FP_ROUND:
7434assert(VT.isFloatingPoint() && N1.getValueType().isFloatingPoint() &&
7435 VT.bitsLE(N1.getValueType()) && N2C &&
7436 (N2C->getZExtValue() == 0 || N2C->getZExtValue() == 1) &&
7437 N2.getOpcode() ==ISD::TargetConstant &&"Invalid FP_ROUND!");
7438if (N1.getValueType() == VT)return N1;// noop conversion.
7439break;
7440caseISD::AssertSext:
7441caseISD::AssertZext: {
7442EVTEVT = cast<VTSDNode>(N2)->getVT();
7443assert(VT == N1.getValueType() &&"Not an inreg extend!");
7444assert(VT.isInteger() &&EVT.isInteger() &&
7445"Cannot *_EXTEND_INREG FP types");
7446assert(!EVT.isVector() &&
7447"AssertSExt/AssertZExt type should be the vector element type "
7448"rather than the vector type!");
7449assert(EVT.bitsLE(VT.getScalarType()) &&"Not extending!");
7450if (VT.getScalarType() ==EVT)return N1;// noop assertion.
7451break;
7452 }
7453caseISD::SIGN_EXTEND_INREG: {
7454EVTEVT = cast<VTSDNode>(N2)->getVT();
7455assert(VT == N1.getValueType() &&"Not an inreg extend!");
7456assert(VT.isInteger() &&EVT.isInteger() &&
7457"Cannot *_EXTEND_INREG FP types");
7458assert(EVT.isVector() == VT.isVector() &&
7459"SIGN_EXTEND_INREG type should be vector iff the operand "
7460"type is vector!");
7461assert((!EVT.isVector() ||
7462EVT.getVectorElementCount() == VT.getVectorElementCount()) &&
7463"Vector element counts must match in SIGN_EXTEND_INREG");
7464assert(EVT.bitsLE(VT) &&"Not extending!");
7465if (EVT == VT)return N1;// Not actually extending
7466break;
7467 }
7468caseISD::FP_TO_SINT_SAT:
7469caseISD::FP_TO_UINT_SAT: {
7470assert(VT.isInteger() && cast<VTSDNode>(N2)->getVT().isInteger() &&
7471 N1.getValueType().isFloatingPoint() &&"Invalid FP_TO_*INT_SAT");
7472assert(N1.getValueType().isVector() == VT.isVector() &&
7473"FP_TO_*INT_SAT type should be vector iff the operand type is "
7474"vector!");
7475assert((!VT.isVector() || VT.getVectorElementCount() ==
7476 N1.getValueType().getVectorElementCount()) &&
7477"Vector element counts must match in FP_TO_*INT_SAT");
7478assert(!cast<VTSDNode>(N2)->getVT().isVector() &&
7479"Type to saturate to must be a scalar.");
7480assert(cast<VTSDNode>(N2)->getVT().bitsLE(VT.getScalarType()) &&
7481"Not extending!");
7482break;
7483 }
7484caseISD::EXTRACT_VECTOR_ELT:
7485assert(VT.getSizeInBits() >= N1.getValueType().getScalarSizeInBits() &&
7486"The result of EXTRACT_VECTOR_ELT must be at least as wide as the \
7487 element type of the vector.");
7488
7489// Extract from an undefined value or using an undefined index is undefined.
7490if (N1.isUndef() || N2.isUndef())
7491returngetUNDEF(VT);
7492
7493// EXTRACT_VECTOR_ELT of out-of-bounds element is an UNDEF for fixed length
7494// vectors. For scalable vectors we will provide appropriate support for
7495// dealing with arbitrary indices.
7496if (N2C && N1.getValueType().isFixedLengthVector() &&
7497 N2C->getAPIntValue().uge(N1.getValueType().getVectorNumElements()))
7498returngetUNDEF(VT);
7499
7500// EXTRACT_VECTOR_ELT of CONCAT_VECTORS is often formed while lowering is
7501// expanding copies of large vectors from registers. This only works for
7502// fixed length vectors, since we need to know the exact number of
7503// elements.
7504if (N2C && N1.getOpcode() ==ISD::CONCAT_VECTORS &&
7505 N1.getOperand(0).getValueType().isFixedLengthVector()) {
7506unsigned Factor =
7507 N1.getOperand(0).getValueType().getVectorNumElements();
7508returngetNode(ISD::EXTRACT_VECTOR_ELT,DL, VT,
7509 N1.getOperand(N2C->getZExtValue() / Factor),
7510getVectorIdxConstant(N2C->getZExtValue() % Factor,DL));
7511 }
7512
7513// EXTRACT_VECTOR_ELT of BUILD_VECTOR or SPLAT_VECTOR is often formed while
7514// lowering is expanding large vector constants.
7515if (N2C && (N1.getOpcode() ==ISD::BUILD_VECTOR ||
7516 N1.getOpcode() ==ISD::SPLAT_VECTOR)) {
7517assert((N1.getOpcode() !=ISD::BUILD_VECTOR ||
7518 N1.getValueType().isFixedLengthVector()) &&
7519"BUILD_VECTOR used for scalable vectors");
7520unsigned Index =
7521 N1.getOpcode() ==ISD::BUILD_VECTOR ? N2C->getZExtValue() : 0;
7522SDValue Elt = N1.getOperand(Index);
7523
7524if (VT != Elt.getValueType())
7525// If the vector element type is not legal, the BUILD_VECTOR operands
7526// are promoted and implicitly truncated, and the result implicitly
7527// extended. Make that explicit here.
7528 Elt =getAnyExtOrTrunc(Elt,DL, VT);
7529
7530return Elt;
7531 }
7532
7533// EXTRACT_VECTOR_ELT of INSERT_VECTOR_ELT is often formed when vector
7534// operations are lowered to scalars.
7535if (N1.getOpcode() ==ISD::INSERT_VECTOR_ELT) {
7536// If the indices are the same, return the inserted element else
7537// if the indices are known different, extract the element from
7538// the original vector.
7539SDValue N1Op2 = N1.getOperand(2);
7540ConstantSDNode *N1Op2C = dyn_cast<ConstantSDNode>(N1Op2);
7541
7542if (N1Op2C && N2C) {
7543if (N1Op2C->getZExtValue() == N2C->getZExtValue()) {
7544if (VT == N1.getOperand(1).getValueType())
7545return N1.getOperand(1);
7546if (VT.isFloatingPoint()) {
7547assert(VT.getSizeInBits() > N1.getOperand(1).getValueType().getSizeInBits());
7548returngetFPExtendOrRound(N1.getOperand(1),DL, VT);
7549 }
7550returngetSExtOrTrunc(N1.getOperand(1),DL, VT);
7551 }
7552returngetNode(ISD::EXTRACT_VECTOR_ELT,DL, VT, N1.getOperand(0), N2);
7553 }
7554 }
7555
7556// EXTRACT_VECTOR_ELT of v1iX EXTRACT_SUBVECTOR could be formed
7557// when vector types are scalarized and v1iX is legal.
7558// vextract (v1iX extract_subvector(vNiX, Idx)) -> vextract(vNiX,Idx).
7559// Here we are completely ignoring the extract element index (N2),
7560// which is fine for fixed width vectors, since any index other than 0
7561// is undefined anyway. However, this cannot be ignored for scalable
7562// vectors - in theory we could support this, but we don't want to do this
7563// without a profitability check.
7564if (N1.getOpcode() ==ISD::EXTRACT_SUBVECTOR &&
7565 N1.getValueType().isFixedLengthVector() &&
7566 N1.getValueType().getVectorNumElements() == 1) {
7567returngetNode(ISD::EXTRACT_VECTOR_ELT,DL, VT, N1.getOperand(0),
7568 N1.getOperand(1));
7569 }
7570break;
7571caseISD::EXTRACT_ELEMENT:
7572assert(N2C && (unsigned)N2C->getZExtValue() < 2 &&"Bad EXTRACT_ELEMENT!");
7573assert(!N1.getValueType().isVector() && !VT.isVector() &&
7574 (N1.getValueType().isInteger() == VT.isInteger()) &&
7575 N1.getValueType() != VT &&
7576"Wrong types for EXTRACT_ELEMENT!");
7577
7578// EXTRACT_ELEMENT of BUILD_PAIR is often formed while legalize is expanding
7579// 64-bit integers into 32-bit parts. Instead of building the extract of
7580// the BUILD_PAIR, only to have legalize rip it apart, just do it now.
7581if (N1.getOpcode() ==ISD::BUILD_PAIR)
7582return N1.getOperand(N2C->getZExtValue());
7583
7584// EXTRACT_ELEMENT of a constant int is also very common.
7585if (N1C) {
7586unsigned ElementSize = VT.getSizeInBits();
7587unsigned Shift = ElementSize * N2C->getZExtValue();
7588constAPInt &Val = N1C->getAPIntValue();
7589returngetConstant(Val.extractBits(ElementSize, Shift),DL, VT);
7590 }
7591break;
7592caseISD::EXTRACT_SUBVECTOR: {
7593EVT N1VT = N1.getValueType();
7594assert(VT.isVector() && N1VT.isVector() &&
7595"Extract subvector VTs must be vectors!");
7596assert(VT.getVectorElementType() == N1VT.getVectorElementType() &&
7597"Extract subvector VTs must have the same element type!");
7598assert((VT.isFixedLengthVector() || N1VT.isScalableVector()) &&
7599"Cannot extract a scalable vector from a fixed length vector!");
7600assert((VT.isScalableVector() != N1VT.isScalableVector() ||
7601 VT.getVectorMinNumElements() <= N1VT.getVectorMinNumElements()) &&
7602"Extract subvector must be from larger vector to smaller vector!");
7603assert(N2C &&"Extract subvector index must be a constant");
7604assert((VT.isScalableVector() != N1VT.isScalableVector() ||
7605 (VT.getVectorMinNumElements() + N2C->getZExtValue()) <=
7606 N1VT.getVectorMinNumElements()) &&
7607"Extract subvector overflow!");
7608assert(N2C->getAPIntValue().getBitWidth() ==
7609 TLI->getVectorIdxTy(getDataLayout()).getFixedSizeInBits() &&
7610"Constant index for EXTRACT_SUBVECTOR has an invalid size");
7611
7612// Trivial extraction.
7613if (VT == N1VT)
7614return N1;
7615
7616// EXTRACT_SUBVECTOR of an UNDEF is an UNDEF.
7617if (N1.isUndef())
7618returngetUNDEF(VT);
7619
7620// EXTRACT_SUBVECTOR of CONCAT_VECTOR can be simplified if the pieces of
7621// the concat have the same type as the extract.
7622if (N1.getOpcode() ==ISD::CONCAT_VECTORS &&
7623 VT == N1.getOperand(0).getValueType()) {
7624unsigned Factor = VT.getVectorMinNumElements();
7625return N1.getOperand(N2C->getZExtValue() / Factor);
7626 }
7627
7628// EXTRACT_SUBVECTOR of INSERT_SUBVECTOR is often created
7629// during shuffle legalization.
7630if (N1.getOpcode() ==ISD::INSERT_SUBVECTOR && N2 == N1.getOperand(2) &&
7631 VT == N1.getOperand(1).getValueType())
7632return N1.getOperand(1);
7633break;
7634 }
7635 }
7636
7637// Perform trivial constant folding.
7638if (SDValue SV =FoldConstantArithmetic(Opcode,DL, VT, {N1, N2}, Flags))
7639return SV;
7640
7641// Canonicalize an UNDEF to the RHS, even over a constant.
7642if (N1.isUndef()) {
7643if (TLI->isCommutativeBinOp(Opcode)) {
7644std::swap(N1, N2);
7645 }else {
7646switch (Opcode) {
7647caseISD::SUB:
7648returngetUNDEF(VT);// fold op(undef, arg2) -> undef
7649caseISD::SIGN_EXTEND_INREG:
7650caseISD::UDIV:
7651caseISD::SDIV:
7652caseISD::UREM:
7653caseISD::SREM:
7654caseISD::SSUBSAT:
7655caseISD::USUBSAT:
7656returngetConstant(0,DL, VT);// fold op(undef, arg2) -> 0
7657 }
7658 }
7659 }
7660
7661// Fold a bunch of operators when the RHS is undef.
7662if (N2.isUndef()) {
7663switch (Opcode) {
7664caseISD::XOR:
7665if (N1.isUndef())
7666// Handle undef ^ undef -> 0 special case. This is a common
7667// idiom (misuse).
7668returngetConstant(0,DL, VT);
7669 [[fallthrough]];
7670caseISD::ADD:
7671caseISD::SUB:
7672caseISD::UDIV:
7673caseISD::SDIV:
7674caseISD::UREM:
7675caseISD::SREM:
7676returngetUNDEF(VT);// fold op(arg1, undef) -> undef
7677caseISD::MUL:
7678caseISD::AND:
7679caseISD::SSUBSAT:
7680caseISD::USUBSAT:
7681returngetConstant(0,DL, VT);// fold op(arg1, undef) -> 0
7682caseISD::OR:
7683caseISD::SADDSAT:
7684caseISD::UADDSAT:
7685returngetAllOnesConstant(DL, VT);
7686 }
7687 }
7688
7689// Memoize this node if possible.
7690SDNode *N;
7691SDVTList VTs =getVTList(VT);
7692SDValue Ops[] = {N1, N2};
7693if (VT != MVT::Glue) {
7694FoldingSetNodeIDID;
7695AddNodeIDNode(ID, Opcode, VTs, Ops);
7696void *IP =nullptr;
7697if (SDNode *E = FindNodeOrInsertPos(ID,DL, IP)) {
7698 E->intersectFlagsWith(Flags);
7699returnSDValue(E, 0);
7700 }
7701
7702N = newSDNode<SDNode>(Opcode,DL.getIROrder(),DL.getDebugLoc(), VTs);
7703N->setFlags(Flags);
7704 createOperands(N, Ops);
7705 CSEMap.InsertNode(N, IP);
7706 }else {
7707N = newSDNode<SDNode>(Opcode,DL.getIROrder(),DL.getDebugLoc(), VTs);
7708 createOperands(N, Ops);
7709 }
7710
7711 InsertNode(N);
7712SDValue V =SDValue(N, 0);
7713NewSDValueDbgMsg(V,"Creating new node: ",this);
7714return V;
7715}
7716
7717SDValueSelectionDAG::getNode(unsigned Opcode,constSDLoc &DL,EVT VT,
7718SDValue N1,SDValue N2,SDValue N3) {
7719SDNodeFlags Flags;
7720if (Inserter)
7721 Flags = Inserter->getFlags();
7722returngetNode(Opcode,DL, VT, N1, N2, N3, Flags);
7723}
7724
7725SDValueSelectionDAG::getNode(unsigned Opcode,constSDLoc &DL,EVT VT,
7726SDValue N1,SDValue N2,SDValue N3,
7727constSDNodeFlags Flags) {
7728assert(N1.getOpcode() !=ISD::DELETED_NODE &&
7729 N2.getOpcode() !=ISD::DELETED_NODE &&
7730 N3.getOpcode() !=ISD::DELETED_NODE &&
7731"Operand is DELETED_NODE!");
7732// Perform various simplifications.
7733switch (Opcode) {
7734caseISD::FMA:
7735caseISD::FMAD: {
7736assert(VT.isFloatingPoint() &&"This operator only applies to FP types!");
7737assert(N1.getValueType() == VT && N2.getValueType() == VT &&
7738 N3.getValueType() == VT &&"FMA types must match!");
7739ConstantFPSDNode *N1CFP = dyn_cast<ConstantFPSDNode>(N1);
7740ConstantFPSDNode *N2CFP = dyn_cast<ConstantFPSDNode>(N2);
7741ConstantFPSDNode *N3CFP = dyn_cast<ConstantFPSDNode>(N3);
7742if (N1CFP && N2CFP && N3CFP) {
7743APFloat V1 = N1CFP->getValueAPF();
7744constAPFloat &V2 = N2CFP->getValueAPF();
7745constAPFloat &V3 = N3CFP->getValueAPF();
7746if (Opcode ==ISD::FMAD) {
7747 V1.multiply(V2,APFloat::rmNearestTiesToEven);
7748 V1.add(V3,APFloat::rmNearestTiesToEven);
7749 }else
7750 V1.fusedMultiplyAdd(V2, V3,APFloat::rmNearestTiesToEven);
7751returngetConstantFP(V1,DL, VT);
7752 }
7753break;
7754 }
7755caseISD::BUILD_VECTOR: {
7756// Attempt to simplify BUILD_VECTOR.
7757SDValue Ops[] = {N1, N2, N3};
7758if (SDValue V =FoldBUILD_VECTOR(DL, VT, Ops, *this))
7759return V;
7760break;
7761 }
7762caseISD::CONCAT_VECTORS: {
7763SDValue Ops[] = {N1, N2, N3};
7764if (SDValue V =foldCONCAT_VECTORS(DL, VT, Ops, *this))
7765return V;
7766break;
7767 }
7768caseISD::SETCC: {
7769assert(VT.isInteger() &&"SETCC result type must be an integer!");
7770assert(N1.getValueType() == N2.getValueType() &&
7771"SETCC operands must have the same type!");
7772assert(VT.isVector() == N1.getValueType().isVector() &&
7773"SETCC type should be vector iff the operand type is vector!");
7774assert((!VT.isVector() || VT.getVectorElementCount() ==
7775 N1.getValueType().getVectorElementCount()) &&
7776"SETCC vector element counts must match!");
7777// Use FoldSetCC to simplify SETCC's.
7778if (SDValue V =FoldSetCC(VT, N1, N2, cast<CondCodeSDNode>(N3)->get(),DL))
7779return V;
7780// Vector constant folding.
7781SDValue Ops[] = {N1, N2, N3};
7782if (SDValue V =FoldConstantArithmetic(Opcode,DL, VT, Ops)) {
7783NewSDValueDbgMsg(V,"New node vector constant folding: ",this);
7784return V;
7785 }
7786break;
7787 }
7788caseISD::SELECT:
7789caseISD::VSELECT:
7790if (SDValue V =simplifySelect(N1, N2, N3))
7791return V;
7792break;
7793caseISD::VECTOR_SHUFFLE:
7794llvm_unreachable("should use getVectorShuffle constructor!");
7795caseISD::VECTOR_SPLICE: {
7796if (cast<ConstantSDNode>(N3)->isZero())
7797return N1;
7798break;
7799 }
7800caseISD::INSERT_VECTOR_ELT: {
7801ConstantSDNode *N3C = dyn_cast<ConstantSDNode>(N3);
7802// INSERT_VECTOR_ELT into out-of-bounds element is an UNDEF, except
7803// for scalable vectors where we will generate appropriate code to
7804// deal with out-of-bounds cases correctly.
7805if (N3C && N1.getValueType().isFixedLengthVector() &&
7806 N3C->getZExtValue() >= N1.getValueType().getVectorNumElements())
7807returngetUNDEF(VT);
7808
7809// Undefined index can be assumed out-of-bounds, so that's UNDEF too.
7810if (N3.isUndef())
7811returngetUNDEF(VT);
7812
7813// If the inserted element is an UNDEF, just use the input vector.
7814if (N2.isUndef())
7815return N1;
7816
7817break;
7818 }
7819caseISD::INSERT_SUBVECTOR: {
7820// Inserting undef into undef is still undef.
7821if (N1.isUndef() && N2.isUndef())
7822returngetUNDEF(VT);
7823
7824EVT N2VT = N2.getValueType();
7825assert(VT == N1.getValueType() &&
7826"Dest and insert subvector source types must match!");
7827assert(VT.isVector() && N2VT.isVector() &&
7828"Insert subvector VTs must be vectors!");
7829assert(VT.getVectorElementType() == N2VT.getVectorElementType() &&
7830"Insert subvector VTs must have the same element type!");
7831assert((VT.isScalableVector() || N2VT.isFixedLengthVector()) &&
7832"Cannot insert a scalable vector into a fixed length vector!");
7833assert((VT.isScalableVector() != N2VT.isScalableVector() ||
7834 VT.getVectorMinNumElements() >= N2VT.getVectorMinNumElements()) &&
7835"Insert subvector must be from smaller vector to larger vector!");
7836assert(isa<ConstantSDNode>(N3) &&
7837"Insert subvector index must be constant");
7838assert((VT.isScalableVector() != N2VT.isScalableVector() ||
7839 (N2VT.getVectorMinNumElements() + N3->getAsZExtVal()) <=
7840 VT.getVectorMinNumElements()) &&
7841"Insert subvector overflow!");
7842assert(N3->getAsAPIntVal().getBitWidth() ==
7843 TLI->getVectorIdxTy(getDataLayout()).getFixedSizeInBits() &&
7844"Constant index for INSERT_SUBVECTOR has an invalid size");
7845
7846// Trivial insertion.
7847if (VT == N2VT)
7848return N2;
7849
7850// If this is an insert of an extracted vector into an undef vector, we
7851// can just use the input to the extract.
7852if (N1.isUndef() && N2.getOpcode() ==ISD::EXTRACT_SUBVECTOR &&
7853 N2.getOperand(1) == N3 && N2.getOperand(0).getValueType() == VT)
7854return N2.getOperand(0);
7855break;
7856 }
7857caseISD::BITCAST:
7858// Fold bit_convert nodes from a type to themselves.
7859if (N1.getValueType() == VT)
7860return N1;
7861break;
7862case ISD::VP_TRUNCATE:
7863case ISD::VP_SIGN_EXTEND:
7864case ISD::VP_ZERO_EXTEND:
7865// Don't create noop casts.
7866if (N1.getValueType() == VT)
7867return N1;
7868break;
7869caseISD::VECTOR_COMPRESS: {
7870 [[maybe_unused]]EVT VecVT = N1.getValueType();
7871 [[maybe_unused]]EVT MaskVT = N2.getValueType();
7872 [[maybe_unused]]EVT PassthruVT = N3.getValueType();
7873assert(VT == VecVT &&"Vector and result type don't match.");
7874assert(VecVT.isVector() && MaskVT.isVector() && PassthruVT.isVector() &&
7875"All inputs must be vectors.");
7876assert(VecVT == PassthruVT &&"Vector and passthru types don't match.");
7877assert(VecVT.getVectorElementCount() == MaskVT.getVectorElementCount() &&
7878"Vector and mask must have same number of elements.");
7879
7880if (N1.isUndef() || N2.isUndef())
7881return N3;
7882
7883break;
7884 }
7885 }
7886
7887// Memoize node if it doesn't produce a glue result.
7888SDNode *N;
7889SDVTList VTs =getVTList(VT);
7890SDValue Ops[] = {N1, N2, N3};
7891if (VT != MVT::Glue) {
7892FoldingSetNodeIDID;
7893AddNodeIDNode(ID, Opcode, VTs, Ops);
7894void *IP =nullptr;
7895if (SDNode *E = FindNodeOrInsertPos(ID,DL, IP)) {
7896 E->intersectFlagsWith(Flags);
7897returnSDValue(E, 0);
7898 }
7899
7900N = newSDNode<SDNode>(Opcode,DL.getIROrder(),DL.getDebugLoc(), VTs);
7901N->setFlags(Flags);
7902 createOperands(N, Ops);
7903 CSEMap.InsertNode(N, IP);
7904 }else {
7905N = newSDNode<SDNode>(Opcode,DL.getIROrder(),DL.getDebugLoc(), VTs);
7906 createOperands(N, Ops);
7907 }
7908
7909 InsertNode(N);
7910SDValue V =SDValue(N, 0);
7911NewSDValueDbgMsg(V,"Creating new node: ",this);
7912return V;
7913}
7914
7915SDValueSelectionDAG::getNode(unsigned Opcode,constSDLoc &DL,EVT VT,
7916SDValue N1,SDValue N2,SDValue N3,SDValue N4,
7917constSDNodeFlags Flags) {
7918SDValue Ops[] = { N1, N2, N3, N4 };
7919returngetNode(Opcode,DL, VT, Ops, Flags);
7920}
7921
7922SDValueSelectionDAG::getNode(unsigned Opcode,constSDLoc &DL,EVT VT,
7923SDValue N1,SDValue N2,SDValue N3,SDValue N4) {
7924SDNodeFlags Flags;
7925if (Inserter)
7926 Flags = Inserter->getFlags();
7927returngetNode(Opcode,DL, VT, N1, N2, N3, N4, Flags);
7928}
7929
7930SDValueSelectionDAG::getNode(unsigned Opcode,constSDLoc &DL,EVT VT,
7931SDValue N1,SDValue N2,SDValue N3,SDValue N4,
7932SDValue N5,constSDNodeFlags Flags) {
7933SDValue Ops[] = { N1, N2, N3, N4, N5 };
7934returngetNode(Opcode,DL, VT, Ops, Flags);
7935}
7936
7937SDValueSelectionDAG::getNode(unsigned Opcode,constSDLoc &DL,EVT VT,
7938SDValue N1,SDValue N2,SDValue N3,SDValue N4,
7939SDValue N5) {
7940SDNodeFlags Flags;
7941if (Inserter)
7942 Flags = Inserter->getFlags();
7943returngetNode(Opcode,DL, VT, N1, N2, N3, N4, N5, Flags);
7944}
7945
7946/// getStackArgumentTokenFactor - Compute a TokenFactor to force all
7947/// the incoming stack arguments to be loaded from the stack.
7948SDValueSelectionDAG::getStackArgumentTokenFactor(SDValue Chain) {
7949SmallVector<SDValue, 8> ArgChains;
7950
7951// Include the original chain at the beginning of the list. When this is
7952// used by target LowerCall hooks, this helps legalize find the
7953// CALLSEQ_BEGIN node.
7954 ArgChains.push_back(Chain);
7955
7956// Add a chain value for each stack argument.
7957for (SDNode *U :getEntryNode().getNode()->users())
7958if (LoadSDNode *L = dyn_cast<LoadSDNode>(U))
7959if (FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(L->getBasePtr()))
7960if (FI->getIndex() < 0)
7961 ArgChains.push_back(SDValue(L, 1));
7962
7963// Build a tokenfactor for all the chains.
7964returngetNode(ISD::TokenFactor,SDLoc(Chain), MVT::Other, ArgChains);
7965}
7966
7967/// getMemsetValue - Vectorized representation of the memset value
7968/// operand.
7969staticSDValuegetMemsetValue(SDValueValue,EVT VT,SelectionDAG &DAG,
7970constSDLoc &dl) {
7971assert(!Value.isUndef());
7972
7973unsigned NumBits = VT.getScalarSizeInBits();
7974if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Value)) {
7975assert(C->getAPIntValue().getBitWidth() == 8);
7976APInt Val =APInt::getSplat(NumBits,C->getAPIntValue());
7977if (VT.isInteger()) {
7978bool IsOpaque = VT.getSizeInBits() > 64 ||
7979 !DAG.getTargetLoweringInfo().isLegalStoreImmediate(C->getSExtValue());
7980return DAG.getConstant(Val, dl, VT,false, IsOpaque);
7981 }
7982return DAG.getConstantFP(APFloat(VT.getFltSemantics(), Val), dl, VT);
7983 }
7984
7985assert(Value.getValueType() == MVT::i8 &&"memset with non-byte fill value?");
7986EVT IntVT = VT.getScalarType();
7987if (!IntVT.isInteger())
7988 IntVT =EVT::getIntegerVT(*DAG.getContext(), IntVT.getSizeInBits());
7989
7990Value = DAG.getNode(ISD::ZERO_EXTEND, dl, IntVT,Value);
7991if (NumBits > 8) {
7992// Use a multiplication with 0x010101... to extend the input to the
7993// required length.
7994APInt Magic =APInt::getSplat(NumBits,APInt(8, 0x01));
7995Value = DAG.getNode(ISD::MUL, dl, IntVT,Value,
7996 DAG.getConstant(Magic, dl, IntVT));
7997 }
7998
7999if (VT !=Value.getValueType() && !VT.isInteger())
8000Value = DAG.getBitcast(VT.getScalarType(),Value);
8001if (VT !=Value.getValueType())
8002Value = DAG.getSplatBuildVector(VT, dl,Value);
8003
8004returnValue;
8005}
8006
8007/// getMemsetStringVal - Similar to getMemsetValue. Except this is only
8008/// used when a memcpy is turned into a memset when the source is a constant
8009/// string ptr.
8010staticSDValuegetMemsetStringVal(EVT VT,constSDLoc &dl,SelectionDAG &DAG,
8011constTargetLowering &TLI,
8012constConstantDataArraySlice &Slice) {
8013// Handle vector with all elements zero.
8014if (Slice.Array ==nullptr) {
8015if (VT.isInteger())
8016return DAG.getConstant(0, dl, VT);
8017if (VT == MVT::f32 || VT == MVT::f64 || VT == MVT::f128)
8018return DAG.getConstantFP(0.0, dl, VT);
8019if (VT.isVector()) {
8020unsigned NumElts = VT.getVectorNumElements();
8021MVT EltVT = (VT.getVectorElementType() == MVT::f32) ? MVT::i32 : MVT::i64;
8022return DAG.getNode(ISD::BITCAST, dl, VT,
8023 DAG.getConstant(0, dl,
8024EVT::getVectorVT(*DAG.getContext(),
8025 EltVT, NumElts)));
8026 }
8027llvm_unreachable("Expected type!");
8028 }
8029
8030assert(!VT.isVector() &&"Can't handle vector type here!");
8031unsigned NumVTBits = VT.getSizeInBits();
8032unsigned NumVTBytes = NumVTBits / 8;
8033unsigned NumBytes = std::min(NumVTBytes,unsigned(Slice.Length));
8034
8035APInt Val(NumVTBits, 0);
8036if (DAG.getDataLayout().isLittleEndian()) {
8037for (unsigned i = 0; i != NumBytes; ++i)
8038 Val |= (uint64_t)(unsignedchar)Slice[i] << i*8;
8039 }else {
8040for (unsigned i = 0; i != NumBytes; ++i)
8041 Val |= (uint64_t)(unsignedchar)Slice[i] << (NumVTBytes-i-1)*8;
8042 }
8043
8044// If the "cost" of materializing the integer immediate is less than the cost
8045// of a load, then it is cost effective to turn the load into the immediate.
8046Type *Ty = VT.getTypeForEVT(*DAG.getContext());
8047if (TLI.shouldConvertConstantLoadToIntImm(Val, Ty))
8048return DAG.getConstant(Val, dl, VT);
8049returnSDValue();
8050}
8051
8052SDValueSelectionDAG::getMemBasePlusOffset(SDValueBase,TypeSizeOffset,
8053constSDLoc &DL,
8054constSDNodeFlags Flags) {
8055EVT VT =Base.getValueType();
8056SDValue Index;
8057
8058if (Offset.isScalable())
8059 Index =getVScale(DL,Base.getValueType(),
8060APInt(Base.getValueSizeInBits().getFixedValue(),
8061Offset.getKnownMinValue()));
8062else
8063 Index =getConstant(Offset.getFixedValue(),DL, VT);
8064
8065returngetMemBasePlusOffset(Base, Index,DL, Flags);
8066}
8067
8068SDValueSelectionDAG::getMemBasePlusOffset(SDValuePtr,SDValueOffset,
8069constSDLoc &DL,
8070constSDNodeFlags Flags) {
8071assert(Offset.getValueType().isInteger());
8072EVT BasePtrVT =Ptr.getValueType();
8073returngetNode(ISD::ADD,DL, BasePtrVT,Ptr,Offset, Flags);
8074}
8075
8076/// Returns true if memcpy source is constant data.
8077staticboolisMemSrcFromConstant(SDValue Src,ConstantDataArraySlice &Slice) {
8078uint64_t SrcDelta = 0;
8079GlobalAddressSDNode *G =nullptr;
8080if (Src.getOpcode() ==ISD::GlobalAddress)
8081G = cast<GlobalAddressSDNode>(Src);
8082elseif (Src.getOpcode() ==ISD::ADD &&
8083 Src.getOperand(0).getOpcode() ==ISD::GlobalAddress &&
8084 Src.getOperand(1).getOpcode() ==ISD::Constant) {
8085G = cast<GlobalAddressSDNode>(Src.getOperand(0));
8086 SrcDelta = Src.getConstantOperandVal(1);
8087 }
8088if (!G)
8089returnfalse;
8090
8091returngetConstantDataArrayInfo(G->getGlobal(), Slice, 8,
8092 SrcDelta +G->getOffset());
8093}
8094
8095staticboolshouldLowerMemFuncForSize(constMachineFunction &MF,
8096SelectionDAG &DAG) {
8097// On Darwin, -Os means optimize for size without hurting performance, so
8098// only really optimize for size when -Oz (MinSize) is used.
8099if (MF.getTarget().getTargetTriple().isOSDarwin())
8100return MF.getFunction().hasMinSize();
8101return DAG.shouldOptForSize();
8102}
8103
8104staticvoidchainLoadsAndStoresForMemcpy(SelectionDAG &DAG,constSDLoc &dl,
8105SmallVector<SDValue, 32> &OutChains,unsignedFrom,
8106unsigned To,SmallVector<SDValue, 16> &OutLoadChains,
8107SmallVector<SDValue, 16> &OutStoreChains) {
8108assert(OutLoadChains.size() &&"Missing loads in memcpy inlining");
8109assert(OutStoreChains.size() &&"Missing stores in memcpy inlining");
8110SmallVector<SDValue, 16> GluedLoadChains;
8111for (unsigned i =From; i < To; ++i) {
8112 OutChains.push_back(OutLoadChains[i]);
8113 GluedLoadChains.push_back(OutLoadChains[i]);
8114 }
8115
8116// Chain for all loads.
8117SDValue LoadToken = DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
8118 GluedLoadChains);
8119
8120for (unsigned i =From; i < To; ++i) {
8121StoreSDNode *ST = dyn_cast<StoreSDNode>(OutStoreChains[i]);
8122SDValue NewStore = DAG.getTruncStore(LoadToken, dl, ST->getValue(),
8123 ST->getBasePtr(), ST->getMemoryVT(),
8124 ST->getMemOperand());
8125 OutChains.push_back(NewStore);
8126 }
8127}
8128
8129staticSDValuegetMemcpyLoadsAndStores(
8130SelectionDAG &DAG,constSDLoc &dl,SDValue Chain,SDValue Dst,SDValue Src,
8131uint64_tSize,Align Alignment,bool isVol,bool AlwaysInline,
8132MachinePointerInfo DstPtrInfo,MachinePointerInfo SrcPtrInfo,
8133constAAMDNodes &AAInfo,BatchAAResults *BatchAA) {
8134// Turn a memcpy of undef to nop.
8135// FIXME: We need to honor volatile even is Src is undef.
8136if (Src.isUndef())
8137return Chain;
8138
8139// Expand memcpy to a series of load and store ops if the size operand falls
8140// below a certain threshold.
8141// TODO: In the AlwaysInline case, if the size is big then generate a loop
8142// rather than maybe a humongous number of loads and stores.
8143constTargetLowering &TLI = DAG.getTargetLoweringInfo();
8144constDataLayout &DL = DAG.getDataLayout();
8145LLVMContext &C = *DAG.getContext();
8146 std::vector<EVT> MemOps;
8147bool DstAlignCanChange =false;
8148MachineFunction &MF = DAG.getMachineFunction();
8149MachineFrameInfo &MFI = MF.getFrameInfo();
8150bool OptSize =shouldLowerMemFuncForSize(MF, DAG);
8151FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(Dst);
8152if (FI && !MFI.isFixedObjectIndex(FI->getIndex()))
8153 DstAlignCanChange =true;
8154MaybeAlign SrcAlign = DAG.InferPtrAlign(Src);
8155if (!SrcAlign || Alignment > *SrcAlign)
8156 SrcAlign = Alignment;
8157assert(SrcAlign &&"SrcAlign must be set");
8158ConstantDataArraySlice Slice;
8159// If marked as volatile, perform a copy even when marked as constant.
8160bool CopyFromConstant = !isVol &&isMemSrcFromConstant(Src, Slice);
8161bool isZeroConstant = CopyFromConstant && Slice.Array ==nullptr;
8162unsigned Limit = AlwaysInline ? ~0U : TLI.getMaxStoresPerMemcpy(OptSize);
8163constMemOpOp = isZeroConstant
8164 ?MemOp::Set(Size, DstAlignCanChange, Alignment,
8165/*IsZeroMemset*/true, isVol)
8166 :MemOp::Copy(Size, DstAlignCanChange, Alignment,
8167 *SrcAlign, isVol, CopyFromConstant);
8168if (!TLI.findOptimalMemOpLowering(
8169 MemOps, Limit,Op, DstPtrInfo.getAddrSpace(),
8170 SrcPtrInfo.getAddrSpace(), MF.getFunction().getAttributes()))
8171returnSDValue();
8172
8173if (DstAlignCanChange) {
8174Type *Ty = MemOps[0].getTypeForEVT(C);
8175Align NewAlign =DL.getABITypeAlign(Ty);
8176
8177// Don't promote to an alignment that would require dynamic stack
8178// realignment which may conflict with optimizations such as tail call
8179// optimization.
8180constTargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
8181if (!TRI->hasStackRealignment(MF))
8182if (MaybeAlign StackAlign =DL.getStackAlignment())
8183 NewAlign = std::min(NewAlign, *StackAlign);
8184
8185if (NewAlign > Alignment) {
8186// Give the stack frame object a larger alignment if needed.
8187if (MFI.getObjectAlign(FI->getIndex()) < NewAlign)
8188 MFI.setObjectAlignment(FI->getIndex(), NewAlign);
8189 Alignment = NewAlign;
8190 }
8191 }
8192
8193// Prepare AAInfo for loads/stores after lowering this memcpy.
8194AAMDNodes NewAAInfo = AAInfo;
8195 NewAAInfo.TBAA = NewAAInfo.TBAAStruct =nullptr;
8196
8197constValue *SrcVal = dyn_cast_if_present<const Value *>(SrcPtrInfo.V);
8198boolisConstant =
8199 BatchAA && SrcVal &&
8200 BatchAA->pointsToConstantMemory(MemoryLocation(SrcVal,Size, AAInfo));
8201
8202MachineMemOperand::Flags MMOFlags =
8203 isVol ?MachineMemOperand::MOVolatile :MachineMemOperand::MONone;
8204SmallVector<SDValue, 16> OutLoadChains;
8205SmallVector<SDValue, 16> OutStoreChains;
8206SmallVector<SDValue, 32> OutChains;
8207unsigned NumMemOps = MemOps.size();
8208uint64_t SrcOff = 0, DstOff = 0;
8209for (unsigned i = 0; i != NumMemOps; ++i) {
8210EVT VT = MemOps[i];
8211unsigned VTSize = VT.getSizeInBits() / 8;
8212SDValueValue, Store;
8213
8214if (VTSize >Size) {
8215// Issuing an unaligned load / store pair that overlaps with the previous
8216// pair. Adjust the offset accordingly.
8217assert(i == NumMemOps-1 && i != 0);
8218 SrcOff -= VTSize -Size;
8219 DstOff -= VTSize -Size;
8220 }
8221
8222if (CopyFromConstant &&
8223 (isZeroConstant || (VT.isInteger() && !VT.isVector()))) {
8224// It's unlikely a store of a vector immediate can be done in a single
8225// instruction. It would require a load from a constantpool first.
8226// We only handle zero vectors here.
8227// FIXME: Handle other cases where store of vector immediate is done in
8228// a single instruction.
8229ConstantDataArraySlice SubSlice;
8230if (SrcOff < Slice.Length) {
8231 SubSlice = Slice;
8232 SubSlice.move(SrcOff);
8233 }else {
8234// This is an out-of-bounds access and hence UB. Pretend we read zero.
8235 SubSlice.Array =nullptr;
8236 SubSlice.Offset = 0;
8237 SubSlice.Length = VTSize;
8238 }
8239Value =getMemsetStringVal(VT, dl, DAG, TLI, SubSlice);
8240if (Value.getNode()) {
8241 Store = DAG.getStore(
8242 Chain, dl,Value,
8243 DAG.getMemBasePlusOffset(Dst,TypeSize::getFixed(DstOff), dl),
8244 DstPtrInfo.getWithOffset(DstOff), Alignment, MMOFlags, NewAAInfo);
8245 OutChains.push_back(Store);
8246 }
8247 }
8248
8249if (!Store.getNode()) {
8250// The type might not be legal for the target. This should only happen
8251// if the type is smaller than a legal type, as on PPC, so the right
8252// thing to do is generate a LoadExt/StoreTrunc pair. These simplify
8253// to Load/Store if NVT==VT.
8254// FIXME does the case above also need this?
8255EVT NVT = TLI.getTypeToTransformTo(C, VT);
8256assert(NVT.bitsGE(VT));
8257
8258bool isDereferenceable =
8259 SrcPtrInfo.getWithOffset(SrcOff).isDereferenceable(VTSize,C,DL);
8260MachineMemOperand::Flags SrcMMOFlags = MMOFlags;
8261if (isDereferenceable)
8262 SrcMMOFlags |=MachineMemOperand::MODereferenceable;
8263if (isConstant)
8264 SrcMMOFlags |=MachineMemOperand::MOInvariant;
8265
8266Value = DAG.getExtLoad(
8267ISD::EXTLOAD, dl, NVT, Chain,
8268 DAG.getMemBasePlusOffset(Src,TypeSize::getFixed(SrcOff), dl),
8269 SrcPtrInfo.getWithOffset(SrcOff), VT,
8270commonAlignment(*SrcAlign, SrcOff), SrcMMOFlags, NewAAInfo);
8271 OutLoadChains.push_back(Value.getValue(1));
8272
8273 Store = DAG.getTruncStore(
8274 Chain, dl,Value,
8275 DAG.getMemBasePlusOffset(Dst,TypeSize::getFixed(DstOff), dl),
8276 DstPtrInfo.getWithOffset(DstOff), VT, Alignment, MMOFlags, NewAAInfo);
8277 OutStoreChains.push_back(Store);
8278 }
8279 SrcOff += VTSize;
8280 DstOff += VTSize;
8281Size -= VTSize;
8282 }
8283
8284unsigned GluedLdStLimit =MaxLdStGlue == 0 ?
8285 TLI.getMaxGluedStoresPerMemcpy() :MaxLdStGlue;
8286unsigned NumLdStInMemcpy = OutStoreChains.size();
8287
8288if (NumLdStInMemcpy) {
8289// It may be that memcpy might be converted to memset if it's memcpy
8290// of constants. In such a case, we won't have loads and stores, but
8291// just stores. In the absence of loads, there is nothing to gang up.
8292if ((GluedLdStLimit <= 1) || !EnableMemCpyDAGOpt) {
8293// If target does not care, just leave as it.
8294for (unsigned i = 0; i < NumLdStInMemcpy; ++i) {
8295 OutChains.push_back(OutLoadChains[i]);
8296 OutChains.push_back(OutStoreChains[i]);
8297 }
8298 }else {
8299// Ld/St less than/equal limit set by target.
8300if (NumLdStInMemcpy <= GluedLdStLimit) {
8301chainLoadsAndStoresForMemcpy(DAG, dl, OutChains, 0,
8302 NumLdStInMemcpy, OutLoadChains,
8303 OutStoreChains);
8304 }else {
8305unsigned NumberLdChain = NumLdStInMemcpy / GluedLdStLimit;
8306unsigned RemainingLdStInMemcpy = NumLdStInMemcpy % GluedLdStLimit;
8307unsigned GlueIter = 0;
8308
8309for (unsigned cnt = 0; cnt < NumberLdChain; ++cnt) {
8310unsigned IndexFrom = NumLdStInMemcpy - GlueIter - GluedLdStLimit;
8311unsigned IndexTo = NumLdStInMemcpy - GlueIter;
8312
8313chainLoadsAndStoresForMemcpy(DAG, dl, OutChains, IndexFrom, IndexTo,
8314 OutLoadChains, OutStoreChains);
8315 GlueIter += GluedLdStLimit;
8316 }
8317
8318// Residual ld/st.
8319if (RemainingLdStInMemcpy) {
8320chainLoadsAndStoresForMemcpy(DAG, dl, OutChains, 0,
8321 RemainingLdStInMemcpy, OutLoadChains,
8322 OutStoreChains);
8323 }
8324 }
8325 }
8326 }
8327return DAG.getNode(ISD::TokenFactor, dl, MVT::Other, OutChains);
8328}
8329
8330staticSDValuegetMemmoveLoadsAndStores(SelectionDAG &DAG,constSDLoc &dl,
8331SDValue Chain,SDValue Dst,SDValue Src,
8332uint64_tSize,Align Alignment,
8333bool isVol,bool AlwaysInline,
8334MachinePointerInfo DstPtrInfo,
8335MachinePointerInfo SrcPtrInfo,
8336constAAMDNodes &AAInfo) {
8337// Turn a memmove of undef to nop.
8338// FIXME: We need to honor volatile even is Src is undef.
8339if (Src.isUndef())
8340return Chain;
8341
8342// Expand memmove to a series of load and store ops if the size operand falls
8343// below a certain threshold.
8344constTargetLowering &TLI = DAG.getTargetLoweringInfo();
8345constDataLayout &DL = DAG.getDataLayout();
8346LLVMContext &C = *DAG.getContext();
8347 std::vector<EVT> MemOps;
8348bool DstAlignCanChange =false;
8349MachineFunction &MF = DAG.getMachineFunction();
8350MachineFrameInfo &MFI = MF.getFrameInfo();
8351bool OptSize =shouldLowerMemFuncForSize(MF, DAG);
8352FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(Dst);
8353if (FI && !MFI.isFixedObjectIndex(FI->getIndex()))
8354 DstAlignCanChange =true;
8355MaybeAlign SrcAlign = DAG.InferPtrAlign(Src);
8356if (!SrcAlign || Alignment > *SrcAlign)
8357 SrcAlign = Alignment;
8358assert(SrcAlign &&"SrcAlign must be set");
8359unsigned Limit = AlwaysInline ? ~0U : TLI.getMaxStoresPerMemmove(OptSize);
8360if (!TLI.findOptimalMemOpLowering(
8361 MemOps, Limit,
8362MemOp::Copy(Size, DstAlignCanChange, Alignment, *SrcAlign,
8363/*IsVolatile*/true),
8364 DstPtrInfo.getAddrSpace(), SrcPtrInfo.getAddrSpace(),
8365 MF.getFunction().getAttributes()))
8366returnSDValue();
8367
8368if (DstAlignCanChange) {
8369Type *Ty = MemOps[0].getTypeForEVT(C);
8370Align NewAlign =DL.getABITypeAlign(Ty);
8371
8372// Don't promote to an alignment that would require dynamic stack
8373// realignment which may conflict with optimizations such as tail call
8374// optimization.
8375constTargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
8376if (!TRI->hasStackRealignment(MF))
8377if (MaybeAlign StackAlign =DL.getStackAlignment())
8378 NewAlign = std::min(NewAlign, *StackAlign);
8379
8380if (NewAlign > Alignment) {
8381// Give the stack frame object a larger alignment if needed.
8382if (MFI.getObjectAlign(FI->getIndex()) < NewAlign)
8383 MFI.setObjectAlignment(FI->getIndex(), NewAlign);
8384 Alignment = NewAlign;
8385 }
8386 }
8387
8388// Prepare AAInfo for loads/stores after lowering this memmove.
8389AAMDNodes NewAAInfo = AAInfo;
8390 NewAAInfo.TBAA = NewAAInfo.TBAAStruct =nullptr;
8391
8392MachineMemOperand::Flags MMOFlags =
8393 isVol ?MachineMemOperand::MOVolatile :MachineMemOperand::MONone;
8394uint64_t SrcOff = 0, DstOff = 0;
8395SmallVector<SDValue, 8> LoadValues;
8396SmallVector<SDValue, 8> LoadChains;
8397SmallVector<SDValue, 8> OutChains;
8398unsigned NumMemOps = MemOps.size();
8399for (unsigned i = 0; i < NumMemOps; i++) {
8400EVT VT = MemOps[i];
8401unsigned VTSize = VT.getSizeInBits() / 8;
8402SDValueValue;
8403
8404bool isDereferenceable =
8405 SrcPtrInfo.getWithOffset(SrcOff).isDereferenceable(VTSize,C,DL);
8406MachineMemOperand::Flags SrcMMOFlags = MMOFlags;
8407if (isDereferenceable)
8408 SrcMMOFlags |=MachineMemOperand::MODereferenceable;
8409
8410Value = DAG.getLoad(
8411 VT, dl, Chain,
8412 DAG.getMemBasePlusOffset(Src,TypeSize::getFixed(SrcOff), dl),
8413 SrcPtrInfo.getWithOffset(SrcOff), *SrcAlign, SrcMMOFlags, NewAAInfo);
8414 LoadValues.push_back(Value);
8415 LoadChains.push_back(Value.getValue(1));
8416 SrcOff += VTSize;
8417 }
8418 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, LoadChains);
8419 OutChains.clear();
8420for (unsigned i = 0; i < NumMemOps; i++) {
8421EVT VT = MemOps[i];
8422unsigned VTSize = VT.getSizeInBits() / 8;
8423SDValue Store;
8424
8425 Store = DAG.getStore(
8426 Chain, dl, LoadValues[i],
8427 DAG.getMemBasePlusOffset(Dst,TypeSize::getFixed(DstOff), dl),
8428 DstPtrInfo.getWithOffset(DstOff), Alignment, MMOFlags, NewAAInfo);
8429 OutChains.push_back(Store);
8430 DstOff += VTSize;
8431 }
8432
8433return DAG.getNode(ISD::TokenFactor, dl, MVT::Other, OutChains);
8434}
8435
8436/// Lower the call to 'memset' intrinsic function into a series of store
8437/// operations.
8438///
8439/// \param DAG Selection DAG where lowered code is placed.
8440/// \param dl Link to corresponding IR location.
8441/// \param Chain Control flow dependency.
8442/// \param Dst Pointer to destination memory location.
8443/// \param Src Value of byte to write into the memory.
8444/// \param Size Number of bytes to write.
8445/// \param Alignment Alignment of the destination in bytes.
8446/// \param isVol True if destination is volatile.
8447/// \param AlwaysInline Makes sure no function call is generated.
8448/// \param DstPtrInfo IR information on the memory pointer.
8449/// \returns New head in the control flow, if lowering was successful, empty
8450/// SDValue otherwise.
8451///
8452/// The function tries to replace 'llvm.memset' intrinsic with several store
8453/// operations and value calculation code. This is usually profitable for small
8454/// memory size or when the semantic requires inlining.
8455staticSDValuegetMemsetStores(SelectionDAG &DAG,constSDLoc &dl,
8456SDValue Chain,SDValue Dst,SDValue Src,
8457uint64_tSize,Align Alignment,bool isVol,
8458bool AlwaysInline,MachinePointerInfo DstPtrInfo,
8459constAAMDNodes &AAInfo) {
8460// Turn a memset of undef to nop.
8461// FIXME: We need to honor volatile even is Src is undef.
8462if (Src.isUndef())
8463return Chain;
8464
8465// Expand memset to a series of load/store ops if the size operand
8466// falls below a certain threshold.
8467constTargetLowering &TLI = DAG.getTargetLoweringInfo();
8468 std::vector<EVT> MemOps;
8469bool DstAlignCanChange =false;
8470MachineFunction &MF = DAG.getMachineFunction();
8471MachineFrameInfo &MFI = MF.getFrameInfo();
8472bool OptSize =shouldLowerMemFuncForSize(MF, DAG);
8473FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(Dst);
8474if (FI && !MFI.isFixedObjectIndex(FI->getIndex()))
8475 DstAlignCanChange =true;
8476bool IsZeroVal =isNullConstant(Src);
8477unsigned Limit = AlwaysInline ? ~0 : TLI.getMaxStoresPerMemset(OptSize);
8478
8479if (!TLI.findOptimalMemOpLowering(
8480 MemOps, Limit,
8481MemOp::Set(Size, DstAlignCanChange, Alignment, IsZeroVal, isVol),
8482 DstPtrInfo.getAddrSpace(), ~0u, MF.getFunction().getAttributes()))
8483returnSDValue();
8484
8485if (DstAlignCanChange) {
8486Type *Ty = MemOps[0].getTypeForEVT(*DAG.getContext());
8487constDataLayout &DL = DAG.getDataLayout();
8488Align NewAlign =DL.getABITypeAlign(Ty);
8489
8490// Don't promote to an alignment that would require dynamic stack
8491// realignment which may conflict with optimizations such as tail call
8492// optimization.
8493constTargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
8494if (!TRI->hasStackRealignment(MF))
8495if (MaybeAlign StackAlign =DL.getStackAlignment())
8496 NewAlign = std::min(NewAlign, *StackAlign);
8497
8498if (NewAlign > Alignment) {
8499// Give the stack frame object a larger alignment if needed.
8500if (MFI.getObjectAlign(FI->getIndex()) < NewAlign)
8501 MFI.setObjectAlignment(FI->getIndex(), NewAlign);
8502 Alignment = NewAlign;
8503 }
8504 }
8505
8506SmallVector<SDValue, 8> OutChains;
8507uint64_t DstOff = 0;
8508unsigned NumMemOps = MemOps.size();
8509
8510// Find the largest store and generate the bit pattern for it.
8511EVT LargestVT = MemOps[0];
8512for (unsigned i = 1; i < NumMemOps; i++)
8513if (MemOps[i].bitsGT(LargestVT))
8514 LargestVT = MemOps[i];
8515SDValue MemSetValue =getMemsetValue(Src, LargestVT, DAG, dl);
8516
8517// Prepare AAInfo for loads/stores after lowering this memset.
8518AAMDNodes NewAAInfo = AAInfo;
8519 NewAAInfo.TBAA = NewAAInfo.TBAAStruct =nullptr;
8520
8521for (unsigned i = 0; i < NumMemOps; i++) {
8522EVT VT = MemOps[i];
8523unsigned VTSize = VT.getSizeInBits() / 8;
8524if (VTSize >Size) {
8525// Issuing an unaligned load / store pair that overlaps with the previous
8526// pair. Adjust the offset accordingly.
8527assert(i == NumMemOps-1 && i != 0);
8528 DstOff -= VTSize -Size;
8529 }
8530
8531// If this store is smaller than the largest store see whether we can get
8532// the smaller value for free with a truncate or extract vector element and
8533// then store.
8534SDValueValue = MemSetValue;
8535if (VT.bitsLT(LargestVT)) {
8536unsigned Index;
8537unsigned NElts = LargestVT.getSizeInBits() / VT.getSizeInBits();
8538EVT SVT =EVT::getVectorVT(*DAG.getContext(), VT.getScalarType(), NElts);
8539if (!LargestVT.isVector() && !VT.isVector() &&
8540 TLI.isTruncateFree(LargestVT, VT))
8541Value = DAG.getNode(ISD::TRUNCATE, dl, VT, MemSetValue);
8542elseif (LargestVT.isVector() && !VT.isVector() &&
8543 TLI.shallExtractConstSplatVectorElementToStore(
8544 LargestVT.getTypeForEVT(*DAG.getContext()),
8545 VT.getSizeInBits(), Index) &&
8546 TLI.isTypeLegal(SVT) &&
8547 LargestVT.getSizeInBits() == SVT.getSizeInBits()) {
8548// Target which can combine store(extractelement VectorTy, Idx) can get
8549// the smaller value for free.
8550SDValue TailValue = DAG.getNode(ISD::BITCAST, dl, SVT, MemSetValue);
8551Value = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, VT, TailValue,
8552 DAG.getVectorIdxConstant(Index, dl));
8553 }else
8554Value =getMemsetValue(Src, VT, DAG, dl);
8555 }
8556assert(Value.getValueType() == VT &&"Value with wrong type.");
8557SDValue Store = DAG.getStore(
8558 Chain, dl,Value,
8559 DAG.getMemBasePlusOffset(Dst,TypeSize::getFixed(DstOff), dl),
8560 DstPtrInfo.getWithOffset(DstOff), Alignment,
8561 isVol ?MachineMemOperand::MOVolatile :MachineMemOperand::MONone,
8562 NewAAInfo);
8563 OutChains.push_back(Store);
8564 DstOff += VT.getSizeInBits() / 8;
8565Size -= VTSize;
8566 }
8567
8568return DAG.getNode(ISD::TokenFactor, dl, MVT::Other, OutChains);
8569}
8570
8571staticvoidcheckAddrSpaceIsValidForLibcall(constTargetLowering *TLI,
8572unsigned AS) {
8573// Lowering memcpy / memset / memmove intrinsics to calls is only valid if all
8574// pointer operands can be losslessly bitcasted to pointers of address space 0
8575if (AS != 0 && !TLI->getTargetMachine().isNoopAddrSpaceCast(AS, 0)) {
8576report_fatal_error("cannot lower memory intrinsic in address space " +
8577Twine(AS));
8578 }
8579}
8580
8581SDValueSelectionDAG::getMemcpy(
8582SDValue Chain,constSDLoc &dl,SDValue Dst,SDValue Src,SDValueSize,
8583Align Alignment,bool isVol,bool AlwaysInline,constCallInst *CI,
8584 std::optional<bool> OverrideTailCall,MachinePointerInfo DstPtrInfo,
8585MachinePointerInfo SrcPtrInfo,constAAMDNodes &AAInfo,
8586BatchAAResults *BatchAA) {
8587// Check to see if we should lower the memcpy to loads and stores first.
8588// For cases within the target-specified limits, this is the best choice.
8589ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size);
8590if (ConstantSize) {
8591// Memcpy with size zero? Just return the original chain.
8592if (ConstantSize->isZero())
8593return Chain;
8594
8595SDValue Result =getMemcpyLoadsAndStores(
8596 *this, dl, Chain, Dst, Src, ConstantSize->getZExtValue(), Alignment,
8597 isVol,false, DstPtrInfo, SrcPtrInfo, AAInfo, BatchAA);
8598if (Result.getNode())
8599return Result;
8600 }
8601
8602// Then check to see if we should lower the memcpy with target-specific
8603// code. If the target chooses to do this, this is the next best.
8604if (TSI) {
8605SDValue Result = TSI->EmitTargetCodeForMemcpy(
8606 *this, dl, Chain, Dst, Src,Size, Alignment, isVol, AlwaysInline,
8607 DstPtrInfo, SrcPtrInfo);
8608if (Result.getNode())
8609return Result;
8610 }
8611
8612// If we really need inline code and the target declined to provide it,
8613// use a (potentially long) sequence of loads and stores.
8614if (AlwaysInline) {
8615assert(ConstantSize &&"AlwaysInline requires a constant size!");
8616returngetMemcpyLoadsAndStores(
8617 *this, dl, Chain, Dst, Src, ConstantSize->getZExtValue(), Alignment,
8618 isVol,true, DstPtrInfo, SrcPtrInfo, AAInfo, BatchAA);
8619 }
8620
8621checkAddrSpaceIsValidForLibcall(TLI, DstPtrInfo.getAddrSpace());
8622checkAddrSpaceIsValidForLibcall(TLI, SrcPtrInfo.getAddrSpace());
8623
8624// FIXME: If the memcpy is volatile (isVol), lowering it to a plain libc
8625// memcpy is not guaranteed to be safe. libc memcpys aren't required to
8626// respect volatile, so they may do things like read or write memory
8627// beyond the given memory regions. But fixing this isn't easy, and most
8628// people don't care.
8629
8630// Emit a library call.
8631TargetLowering::ArgListTy Args;
8632TargetLowering::ArgListEntry Entry;
8633 Entry.Ty =PointerType::getUnqual(*getContext());
8634 Entry.Node = Dst; Args.push_back(Entry);
8635 Entry.Node = Src; Args.push_back(Entry);
8636
8637 Entry.Ty =getDataLayout().getIntPtrType(*getContext());
8638 Entry.Node =Size; Args.push_back(Entry);
8639// FIXME: pass in SDLoc
8640TargetLowering::CallLoweringInfo CLI(*this);
8641bool IsTailCall =false;
8642if (OverrideTailCall.has_value()) {
8643 IsTailCall = *OverrideTailCall;
8644 }else {
8645bool LowersToMemcpy =
8646 TLI->getLibcallName(RTLIB::MEMCPY) ==StringRef("memcpy");
8647bool ReturnsFirstArg = CI &&funcReturnsFirstArgOfCall(*CI);
8648 IsTailCall = CI && CI->isTailCall() &&
8649isInTailCallPosition(*CI,getTarget(),
8650 ReturnsFirstArg && LowersToMemcpy);
8651 }
8652
8653 CLI.setDebugLoc(dl)
8654 .setChain(Chain)
8655 .setLibCallee(TLI->getLibcallCallingConv(RTLIB::MEMCPY),
8656 Dst.getValueType().getTypeForEVT(*getContext()),
8657getExternalSymbol(TLI->getLibcallName(RTLIB::MEMCPY),
8658 TLI->getPointerTy(getDataLayout())),
8659 std::move(Args))
8660 .setDiscardResult()
8661 .setTailCall(IsTailCall);
8662
8663 std::pair<SDValue,SDValue> CallResult = TLI->LowerCallTo(CLI);
8664return CallResult.second;
8665}
8666
8667SDValueSelectionDAG::getAtomicMemcpy(SDValue Chain,constSDLoc &dl,
8668SDValue Dst,SDValue Src,SDValueSize,
8669Type *SizeTy,unsigned ElemSz,
8670bool isTailCall,
8671MachinePointerInfo DstPtrInfo,
8672MachinePointerInfo SrcPtrInfo) {
8673// Emit a library call.
8674TargetLowering::ArgListTy Args;
8675TargetLowering::ArgListEntry Entry;
8676 Entry.Ty =getDataLayout().getIntPtrType(*getContext());
8677 Entry.Node = Dst;
8678 Args.push_back(Entry);
8679
8680 Entry.Node = Src;
8681 Args.push_back(Entry);
8682
8683 Entry.Ty = SizeTy;
8684 Entry.Node =Size;
8685 Args.push_back(Entry);
8686
8687RTLIB::Libcall LibraryCall =
8688RTLIB::getMEMCPY_ELEMENT_UNORDERED_ATOMIC(ElemSz);
8689if (LibraryCall == RTLIB::UNKNOWN_LIBCALL)
8690report_fatal_error("Unsupported element size");
8691
8692TargetLowering::CallLoweringInfo CLI(*this);
8693 CLI.setDebugLoc(dl)
8694 .setChain(Chain)
8695 .setLibCallee(TLI->getLibcallCallingConv(LibraryCall),
8696Type::getVoidTy(*getContext()),
8697getExternalSymbol(TLI->getLibcallName(LibraryCall),
8698 TLI->getPointerTy(getDataLayout())),
8699 std::move(Args))
8700 .setDiscardResult()
8701 .setTailCall(isTailCall);
8702
8703 std::pair<SDValue, SDValue> CallResult = TLI->LowerCallTo(CLI);
8704return CallResult.second;
8705}
8706
8707SDValueSelectionDAG::getMemmove(SDValue Chain,constSDLoc &dl,SDValue Dst,
8708SDValue Src,SDValueSize,Align Alignment,
8709bool isVol,constCallInst *CI,
8710 std::optional<bool> OverrideTailCall,
8711MachinePointerInfo DstPtrInfo,
8712MachinePointerInfo SrcPtrInfo,
8713constAAMDNodes &AAInfo,
8714BatchAAResults *BatchAA) {
8715// Check to see if we should lower the memmove to loads and stores first.
8716// For cases within the target-specified limits, this is the best choice.
8717ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size);
8718if (ConstantSize) {
8719// Memmove with size zero? Just return the original chain.
8720if (ConstantSize->isZero())
8721return Chain;
8722
8723SDValue Result =getMemmoveLoadsAndStores(
8724 *this, dl, Chain, Dst, Src, ConstantSize->getZExtValue(), Alignment,
8725 isVol,false, DstPtrInfo, SrcPtrInfo, AAInfo);
8726if (Result.getNode())
8727return Result;
8728 }
8729
8730// Then check to see if we should lower the memmove with target-specific
8731// code. If the target chooses to do this, this is the next best.
8732if (TSI) {
8733SDValue Result =
8734 TSI->EmitTargetCodeForMemmove(*this, dl, Chain, Dst, Src,Size,
8735 Alignment, isVol, DstPtrInfo, SrcPtrInfo);
8736if (Result.getNode())
8737return Result;
8738 }
8739
8740checkAddrSpaceIsValidForLibcall(TLI, DstPtrInfo.getAddrSpace());
8741checkAddrSpaceIsValidForLibcall(TLI, SrcPtrInfo.getAddrSpace());
8742
8743// FIXME: If the memmove is volatile, lowering it to plain libc memmove may
8744// not be safe. See memcpy above for more details.
8745
8746// Emit a library call.
8747TargetLowering::ArgListTy Args;
8748TargetLowering::ArgListEntry Entry;
8749 Entry.Ty =PointerType::getUnqual(*getContext());
8750 Entry.Node = Dst; Args.push_back(Entry);
8751 Entry.Node = Src; Args.push_back(Entry);
8752
8753 Entry.Ty =getDataLayout().getIntPtrType(*getContext());
8754 Entry.Node =Size; Args.push_back(Entry);
8755// FIXME: pass in SDLoc
8756TargetLowering::CallLoweringInfo CLI(*this);
8757
8758bool IsTailCall =false;
8759if (OverrideTailCall.has_value()) {
8760 IsTailCall = *OverrideTailCall;
8761 }else {
8762bool LowersToMemmove =
8763 TLI->getLibcallName(RTLIB::MEMMOVE) ==StringRef("memmove");
8764bool ReturnsFirstArg = CI &&funcReturnsFirstArgOfCall(*CI);
8765 IsTailCall = CI && CI->isTailCall() &&
8766isInTailCallPosition(*CI,getTarget(),
8767 ReturnsFirstArg && LowersToMemmove);
8768 }
8769
8770 CLI.setDebugLoc(dl)
8771 .setChain(Chain)
8772 .setLibCallee(TLI->getLibcallCallingConv(RTLIB::MEMMOVE),
8773 Dst.getValueType().getTypeForEVT(*getContext()),
8774getExternalSymbol(TLI->getLibcallName(RTLIB::MEMMOVE),
8775 TLI->getPointerTy(getDataLayout())),
8776 std::move(Args))
8777 .setDiscardResult()
8778 .setTailCall(IsTailCall);
8779
8780 std::pair<SDValue,SDValue> CallResult = TLI->LowerCallTo(CLI);
8781return CallResult.second;
8782}
8783
8784SDValueSelectionDAG::getAtomicMemmove(SDValue Chain,constSDLoc &dl,
8785SDValue Dst,SDValue Src,SDValueSize,
8786Type *SizeTy,unsigned ElemSz,
8787bool isTailCall,
8788MachinePointerInfo DstPtrInfo,
8789MachinePointerInfo SrcPtrInfo) {
8790// Emit a library call.
8791TargetLowering::ArgListTy Args;
8792TargetLowering::ArgListEntry Entry;
8793 Entry.Ty =getDataLayout().getIntPtrType(*getContext());
8794 Entry.Node = Dst;
8795 Args.push_back(Entry);
8796
8797 Entry.Node = Src;
8798 Args.push_back(Entry);
8799
8800 Entry.Ty = SizeTy;
8801 Entry.Node =Size;
8802 Args.push_back(Entry);
8803
8804RTLIB::Libcall LibraryCall =
8805RTLIB::getMEMMOVE_ELEMENT_UNORDERED_ATOMIC(ElemSz);
8806if (LibraryCall == RTLIB::UNKNOWN_LIBCALL)
8807report_fatal_error("Unsupported element size");
8808
8809TargetLowering::CallLoweringInfo CLI(*this);
8810 CLI.setDebugLoc(dl)
8811 .setChain(Chain)
8812 .setLibCallee(TLI->getLibcallCallingConv(LibraryCall),
8813Type::getVoidTy(*getContext()),
8814getExternalSymbol(TLI->getLibcallName(LibraryCall),
8815 TLI->getPointerTy(getDataLayout())),
8816 std::move(Args))
8817 .setDiscardResult()
8818 .setTailCall(isTailCall);
8819
8820 std::pair<SDValue, SDValue> CallResult = TLI->LowerCallTo(CLI);
8821return CallResult.second;
8822}
8823
8824SDValueSelectionDAG::getMemset(SDValue Chain,constSDLoc &dl,SDValue Dst,
8825SDValue Src,SDValueSize,Align Alignment,
8826bool isVol,bool AlwaysInline,
8827constCallInst *CI,
8828MachinePointerInfo DstPtrInfo,
8829constAAMDNodes &AAInfo) {
8830// Check to see if we should lower the memset to stores first.
8831// For cases within the target-specified limits, this is the best choice.
8832ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size);
8833if (ConstantSize) {
8834// Memset with size zero? Just return the original chain.
8835if (ConstantSize->isZero())
8836return Chain;
8837
8838SDValue Result =getMemsetStores(*this, dl, Chain, Dst, Src,
8839 ConstantSize->getZExtValue(), Alignment,
8840 isVol,false, DstPtrInfo, AAInfo);
8841
8842if (Result.getNode())
8843return Result;
8844 }
8845
8846// Then check to see if we should lower the memset with target-specific
8847// code. If the target chooses to do this, this is the next best.
8848if (TSI) {
8849SDValue Result = TSI->EmitTargetCodeForMemset(
8850 *this, dl, Chain, Dst, Src,Size, Alignment, isVol, AlwaysInline, DstPtrInfo);
8851if (Result.getNode())
8852return Result;
8853 }
8854
8855// If we really need inline code and the target declined to provide it,
8856// use a (potentially long) sequence of loads and stores.
8857if (AlwaysInline) {
8858assert(ConstantSize &&"AlwaysInline requires a constant size!");
8859SDValue Result =getMemsetStores(*this, dl, Chain, Dst, Src,
8860 ConstantSize->getZExtValue(), Alignment,
8861 isVol,true, DstPtrInfo, AAInfo);
8862assert(Result &&
8863"getMemsetStores must return a valid sequence when AlwaysInline");
8864return Result;
8865 }
8866
8867checkAddrSpaceIsValidForLibcall(TLI, DstPtrInfo.getAddrSpace());
8868
8869// Emit a library call.
8870auto &Ctx = *getContext();
8871constauto&DL =getDataLayout();
8872
8873TargetLowering::CallLoweringInfo CLI(*this);
8874// FIXME: pass in SDLoc
8875 CLI.setDebugLoc(dl).setChain(Chain);
8876
8877constchar *BzeroName =getTargetLoweringInfo().getLibcallName(RTLIB::BZERO);
8878
8879// Helper function to create an Entry from Node and Type.
8880constauto CreateEntry = [](SDValue Node,Type *Ty) {
8881TargetLowering::ArgListEntry Entry;
8882 Entry.Node = Node;
8883 Entry.Ty = Ty;
8884return Entry;
8885 };
8886
8887bool UseBZero =isNullConstant(Src) && BzeroName;
8888// If zeroing out and bzero is present, use it.
8889if (UseBZero) {
8890TargetLowering::ArgListTy Args;
8891 Args.push_back(CreateEntry(Dst,PointerType::getUnqual(Ctx)));
8892 Args.push_back(CreateEntry(Size,DL.getIntPtrType(Ctx)));
8893 CLI.setLibCallee(
8894 TLI->getLibcallCallingConv(RTLIB::BZERO),Type::getVoidTy(Ctx),
8895getExternalSymbol(BzeroName, TLI->getPointerTy(DL)), std::move(Args));
8896 }else {
8897TargetLowering::ArgListTy Args;
8898 Args.push_back(CreateEntry(Dst,PointerType::getUnqual(Ctx)));
8899 Args.push_back(CreateEntry(Src, Src.getValueType().getTypeForEVT(Ctx)));
8900 Args.push_back(CreateEntry(Size,DL.getIntPtrType(Ctx)));
8901 CLI.setLibCallee(TLI->getLibcallCallingConv(RTLIB::MEMSET),
8902 Dst.getValueType().getTypeForEVT(Ctx),
8903getExternalSymbol(TLI->getLibcallName(RTLIB::MEMSET),
8904 TLI->getPointerTy(DL)),
8905 std::move(Args));
8906 }
8907bool LowersToMemset =
8908 TLI->getLibcallName(RTLIB::MEMSET) ==StringRef("memset");
8909// If we're going to use bzero, make sure not to tail call unless the
8910// subsequent return doesn't need a value, as bzero doesn't return the first
8911// arg unlike memset.
8912bool ReturnsFirstArg = CI &&funcReturnsFirstArgOfCall(*CI) && !UseBZero;
8913bool IsTailCall =
8914 CI && CI->isTailCall() &&
8915isInTailCallPosition(*CI,getTarget(), ReturnsFirstArg && LowersToMemset);
8916 CLI.setDiscardResult().setTailCall(IsTailCall);
8917
8918 std::pair<SDValue, SDValue> CallResult = TLI->LowerCallTo(CLI);
8919return CallResult.second;
8920}
8921
8922SDValueSelectionDAG::getAtomicMemset(SDValue Chain,constSDLoc &dl,
8923SDValue Dst,SDValueValue,SDValueSize,
8924Type *SizeTy,unsigned ElemSz,
8925bool isTailCall,
8926MachinePointerInfo DstPtrInfo) {
8927// Emit a library call.
8928TargetLowering::ArgListTy Args;
8929TargetLowering::ArgListEntry Entry;
8930 Entry.Ty =getDataLayout().getIntPtrType(*getContext());
8931 Entry.Node = Dst;
8932 Args.push_back(Entry);
8933
8934 Entry.Ty =Type::getInt8Ty(*getContext());
8935 Entry.Node =Value;
8936 Args.push_back(Entry);
8937
8938 Entry.Ty = SizeTy;
8939 Entry.Node =Size;
8940 Args.push_back(Entry);
8941
8942RTLIB::Libcall LibraryCall =
8943RTLIB::getMEMSET_ELEMENT_UNORDERED_ATOMIC(ElemSz);
8944if (LibraryCall == RTLIB::UNKNOWN_LIBCALL)
8945report_fatal_error("Unsupported element size");
8946
8947TargetLowering::CallLoweringInfo CLI(*this);
8948 CLI.setDebugLoc(dl)
8949 .setChain(Chain)
8950 .setLibCallee(TLI->getLibcallCallingConv(LibraryCall),
8951Type::getVoidTy(*getContext()),
8952getExternalSymbol(TLI->getLibcallName(LibraryCall),
8953 TLI->getPointerTy(getDataLayout())),
8954 std::move(Args))
8955 .setDiscardResult()
8956 .setTailCall(isTailCall);
8957
8958 std::pair<SDValue, SDValue> CallResult = TLI->LowerCallTo(CLI);
8959return CallResult.second;
8960}
8961
8962SDValueSelectionDAG::getAtomic(unsigned Opcode,constSDLoc &dl,EVT MemVT,
8963SDVTList VTList,ArrayRef<SDValue> Ops,
8964MachineMemOperand *MMO) {
8965FoldingSetNodeIDID;
8966ID.AddInteger(MemVT.getRawBits());
8967AddNodeIDNode(ID, Opcode, VTList, Ops);
8968ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
8969ID.AddInteger(MMO->getFlags());
8970void* IP =nullptr;
8971if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP)) {
8972 cast<AtomicSDNode>(E)->refineAlignment(MMO);
8973returnSDValue(E, 0);
8974 }
8975
8976auto *N = newSDNode<AtomicSDNode>(Opcode, dl.getIROrder(), dl.getDebugLoc(),
8977 VTList, MemVT, MMO);
8978 createOperands(N, Ops);
8979
8980 CSEMap.InsertNode(N, IP);
8981 InsertNode(N);
8982returnSDValue(N, 0);
8983}
8984
8985SDValueSelectionDAG::getAtomicCmpSwap(unsigned Opcode,constSDLoc &dl,
8986EVT MemVT,SDVTList VTs,SDValue Chain,
8987SDValuePtr,SDValue Cmp,SDValue Swp,
8988MachineMemOperand *MMO) {
8989assert(Opcode ==ISD::ATOMIC_CMP_SWAP ||
8990 Opcode ==ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS);
8991assert(Cmp.getValueType() == Swp.getValueType() &&"Invalid Atomic Op Types");
8992
8993SDValue Ops[] = {Chain,Ptr, Cmp, Swp};
8994returngetAtomic(Opcode, dl, MemVT, VTs, Ops, MMO);
8995}
8996
8997SDValueSelectionDAG::getAtomic(unsigned Opcode,constSDLoc &dl,EVT MemVT,
8998SDValue Chain,SDValuePtr,SDValue Val,
8999MachineMemOperand *MMO) {
9000assert((Opcode ==ISD::ATOMIC_LOAD_ADD || Opcode ==ISD::ATOMIC_LOAD_SUB ||
9001 Opcode ==ISD::ATOMIC_LOAD_AND || Opcode ==ISD::ATOMIC_LOAD_CLR ||
9002 Opcode ==ISD::ATOMIC_LOAD_OR || Opcode ==ISD::ATOMIC_LOAD_XOR ||
9003 Opcode ==ISD::ATOMIC_LOAD_NAND || Opcode ==ISD::ATOMIC_LOAD_MIN ||
9004 Opcode ==ISD::ATOMIC_LOAD_MAX || Opcode ==ISD::ATOMIC_LOAD_UMIN ||
9005 Opcode ==ISD::ATOMIC_LOAD_UMAX || Opcode ==ISD::ATOMIC_LOAD_FADD ||
9006 Opcode ==ISD::ATOMIC_LOAD_FSUB || Opcode ==ISD::ATOMIC_LOAD_FMAX ||
9007 Opcode ==ISD::ATOMIC_LOAD_FMIN ||
9008 Opcode ==ISD::ATOMIC_LOAD_UINC_WRAP ||
9009 Opcode ==ISD::ATOMIC_LOAD_UDEC_WRAP ||
9010 Opcode ==ISD::ATOMIC_LOAD_USUB_COND ||
9011 Opcode ==ISD::ATOMIC_LOAD_USUB_SAT || Opcode ==ISD::ATOMIC_SWAP ||
9012 Opcode ==ISD::ATOMIC_STORE) &&
9013"Invalid Atomic Op");
9014
9015EVT VT = Val.getValueType();
9016
9017SDVTList VTs = Opcode ==ISD::ATOMIC_STORE ?getVTList(MVT::Other) :
9018getVTList(VT, MVT::Other);
9019SDValue Ops[] = {Chain,Ptr, Val};
9020returngetAtomic(Opcode, dl, MemVT, VTs, Ops, MMO);
9021}
9022
9023SDValueSelectionDAG::getAtomic(unsigned Opcode,constSDLoc &dl,EVT MemVT,
9024EVT VT,SDValue Chain,SDValuePtr,
9025MachineMemOperand *MMO) {
9026assert(Opcode ==ISD::ATOMIC_LOAD &&"Invalid Atomic Op");
9027
9028SDVTList VTs =getVTList(VT, MVT::Other);
9029SDValue Ops[] = {Chain,Ptr};
9030returngetAtomic(Opcode, dl, MemVT, VTs, Ops, MMO);
9031}
9032
9033/// getMergeValues - Create a MERGE_VALUES node from the given operands.
9034SDValueSelectionDAG::getMergeValues(ArrayRef<SDValue> Ops,constSDLoc &dl) {
9035if (Ops.size() == 1)
9036return Ops[0];
9037
9038SmallVector<EVT, 4> VTs;
9039 VTs.reserve(Ops.size());
9040for (constSDValue &Op : Ops)
9041 VTs.push_back(Op.getValueType());
9042returngetNode(ISD::MERGE_VALUES, dl,getVTList(VTs), Ops);
9043}
9044
9045SDValueSelectionDAG::getMemIntrinsicNode(
9046unsigned Opcode,constSDLoc &dl,SDVTList VTList,ArrayRef<SDValue> Ops,
9047EVT MemVT,MachinePointerInfo PtrInfo,Align Alignment,
9048MachineMemOperand::Flags Flags,LocationSizeSize,
9049constAAMDNodes &AAInfo) {
9050if (Size.hasValue() && !Size.getValue())
9051Size =LocationSize::precise(MemVT.getStoreSize());
9052
9053MachineFunction &MF =getMachineFunction();
9054MachineMemOperand *MMO =
9055 MF.getMachineMemOperand(PtrInfo, Flags,Size, Alignment, AAInfo);
9056
9057returngetMemIntrinsicNode(Opcode, dl, VTList, Ops, MemVT, MMO);
9058}
9059
9060SDValueSelectionDAG::getMemIntrinsicNode(unsigned Opcode,constSDLoc &dl,
9061SDVTList VTList,
9062ArrayRef<SDValue> Ops,EVT MemVT,
9063MachineMemOperand *MMO) {
9064assert(
9065 (Opcode ==ISD::INTRINSIC_VOID || Opcode ==ISD::INTRINSIC_W_CHAIN ||
9066 Opcode ==ISD::PREFETCH ||
9067 (Opcode <= (unsigned)std::numeric_limits<int>::max() &&
9068 Opcode >=ISD::BUILTIN_OP_END && TSI->isTargetMemoryOpcode(Opcode))) &&
9069"Opcode is not a memory-accessing opcode!");
9070
9071// Memoize the node unless it returns a glue result.
9072MemIntrinsicSDNode *N;
9073if (VTList.VTs[VTList.NumVTs-1] != MVT::Glue) {
9074FoldingSetNodeIDID;
9075AddNodeIDNode(ID, Opcode, VTList, Ops);
9076ID.AddInteger(getSyntheticNodeSubclassData<MemIntrinsicSDNode>(
9077 Opcode, dl.getIROrder(), VTList, MemVT, MMO));
9078ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
9079ID.AddInteger(MMO->getFlags());
9080ID.AddInteger(MemVT.getRawBits());
9081void *IP =nullptr;
9082if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP)) {
9083 cast<MemIntrinsicSDNode>(E)->refineAlignment(MMO);
9084returnSDValue(E, 0);
9085 }
9086
9087N = newSDNode<MemIntrinsicSDNode>(Opcode, dl.getIROrder(), dl.getDebugLoc(),
9088 VTList, MemVT, MMO);
9089 createOperands(N, Ops);
9090
9091 CSEMap.InsertNode(N, IP);
9092 }else {
9093N = newSDNode<MemIntrinsicSDNode>(Opcode, dl.getIROrder(), dl.getDebugLoc(),
9094 VTList, MemVT, MMO);
9095 createOperands(N, Ops);
9096 }
9097 InsertNode(N);
9098SDValue V(N, 0);
9099NewSDValueDbgMsg(V,"Creating new node: ",this);
9100return V;
9101}
9102
9103SDValueSelectionDAG::getLifetimeNode(bool IsStart,constSDLoc &dl,
9104SDValue Chain,int FrameIndex,
9105 int64_tSize, int64_tOffset) {
9106constunsigned Opcode = IsStart ?ISD::LIFETIME_START :ISD::LIFETIME_END;
9107constauto VTs =getVTList(MVT::Other);
9108SDValue Ops[2] = {
9109 Chain,
9110getFrameIndex(FrameIndex,
9111getTargetLoweringInfo().getFrameIndexTy(getDataLayout()),
9112true)};
9113
9114FoldingSetNodeIDID;
9115AddNodeIDNode(ID, Opcode, VTs, Ops);
9116ID.AddInteger(FrameIndex);
9117ID.AddInteger(Size);
9118ID.AddInteger(Offset);
9119void *IP =nullptr;
9120if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP))
9121returnSDValue(E, 0);
9122
9123LifetimeSDNode *N = newSDNode<LifetimeSDNode>(
9124 Opcode, dl.getIROrder(), dl.getDebugLoc(), VTs,Size,Offset);
9125 createOperands(N, Ops);
9126 CSEMap.InsertNode(N, IP);
9127 InsertNode(N);
9128SDValue V(N, 0);
9129NewSDValueDbgMsg(V,"Creating new node: ",this);
9130return V;
9131}
9132
9133SDValueSelectionDAG::getPseudoProbeNode(constSDLoc &Dl,SDValue Chain,
9134uint64_tGuid,uint64_t Index,
9135uint32_t Attr) {
9136constunsigned Opcode =ISD::PSEUDO_PROBE;
9137constauto VTs =getVTList(MVT::Other);
9138SDValue Ops[] = {Chain};
9139FoldingSetNodeIDID;
9140AddNodeIDNode(ID, Opcode, VTs, Ops);
9141ID.AddInteger(Guid);
9142ID.AddInteger(Index);
9143void *IP =nullptr;
9144if (SDNode *E = FindNodeOrInsertPos(ID, Dl, IP))
9145returnSDValue(E, 0);
9146
9147auto *N = newSDNode<PseudoProbeSDNode>(
9148 Opcode, Dl.getIROrder(), Dl.getDebugLoc(), VTs,Guid, Index, Attr);
9149 createOperands(N, Ops);
9150 CSEMap.InsertNode(N, IP);
9151 InsertNode(N);
9152SDValue V(N, 0);
9153NewSDValueDbgMsg(V,"Creating new node: ",this);
9154return V;
9155}
9156
9157/// InferPointerInfo - If the specified ptr/offset is a frame index, infer a
9158/// MachinePointerInfo record from it. This is particularly useful because the
9159/// code generator has many cases where it doesn't bother passing in a
9160/// MachinePointerInfo to getLoad or getStore when it has "FI+Cst".
9161staticMachinePointerInfoInferPointerInfo(constMachinePointerInfo &Info,
9162SelectionDAG &DAG,SDValuePtr,
9163 int64_tOffset = 0) {
9164// If this is FI+Offset, we can model it.
9165if (constFrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(Ptr))
9166returnMachinePointerInfo::getFixedStack(DAG.getMachineFunction(),
9167 FI->getIndex(),Offset);
9168
9169// If this is (FI+Offset1)+Offset2, we can model it.
9170if (Ptr.getOpcode() !=ISD::ADD ||
9171 !isa<ConstantSDNode>(Ptr.getOperand(1)) ||
9172 !isa<FrameIndexSDNode>(Ptr.getOperand(0)))
9173returnInfo;
9174
9175int FI = cast<FrameIndexSDNode>(Ptr.getOperand(0))->getIndex();
9176returnMachinePointerInfo::getFixedStack(
9177 DAG.getMachineFunction(), FI,
9178Offset + cast<ConstantSDNode>(Ptr.getOperand(1))->getSExtValue());
9179}
9180
9181/// InferPointerInfo - If the specified ptr/offset is a frame index, infer a
9182/// MachinePointerInfo record from it. This is particularly useful because the
9183/// code generator has many cases where it doesn't bother passing in a
9184/// MachinePointerInfo to getLoad or getStore when it has "FI+Cst".
9185staticMachinePointerInfoInferPointerInfo(constMachinePointerInfo &Info,
9186SelectionDAG &DAG,SDValuePtr,
9187SDValue OffsetOp) {
9188// If the 'Offset' value isn't a constant, we can't handle this.
9189if (ConstantSDNode *OffsetNode = dyn_cast<ConstantSDNode>(OffsetOp))
9190returnInferPointerInfo(Info, DAG,Ptr, OffsetNode->getSExtValue());
9191if (OffsetOp.isUndef())
9192returnInferPointerInfo(Info, DAG,Ptr);
9193returnInfo;
9194}
9195
9196SDValueSelectionDAG::getLoad(ISD::MemIndexedMode AM,ISD::LoadExtType ExtType,
9197EVT VT,constSDLoc &dl,SDValue Chain,
9198SDValuePtr,SDValueOffset,
9199MachinePointerInfo PtrInfo,EVT MemVT,
9200Align Alignment,
9201MachineMemOperand::Flags MMOFlags,
9202constAAMDNodes &AAInfo,constMDNode *Ranges) {
9203assert(Chain.getValueType() == MVT::Other &&
9204"Invalid chain type");
9205
9206 MMOFlags |=MachineMemOperand::MOLoad;
9207assert((MMOFlags &MachineMemOperand::MOStore) == 0);
9208// If we don't have a PtrInfo, infer the trivial frame index case to simplify
9209// clients.
9210if (PtrInfo.V.isNull())
9211 PtrInfo =InferPointerInfo(PtrInfo, *this,Ptr,Offset);
9212
9213LocationSizeSize =LocationSize::precise(MemVT.getStoreSize());
9214MachineFunction &MF =getMachineFunction();
9215MachineMemOperand *MMO = MF.getMachineMemOperand(PtrInfo, MMOFlags,Size,
9216 Alignment, AAInfo, Ranges);
9217returngetLoad(AM, ExtType, VT, dl, Chain,Ptr,Offset, MemVT, MMO);
9218}
9219
9220SDValueSelectionDAG::getLoad(ISD::MemIndexedMode AM,ISD::LoadExtType ExtType,
9221EVT VT,constSDLoc &dl,SDValue Chain,
9222SDValuePtr,SDValueOffset,EVT MemVT,
9223MachineMemOperand *MMO) {
9224if (VT == MemVT) {
9225 ExtType =ISD::NON_EXTLOAD;
9226 }elseif (ExtType ==ISD::NON_EXTLOAD) {
9227assert(VT == MemVT &&"Non-extending load from different memory type!");
9228 }else {
9229// Extending load.
9230assert(MemVT.getScalarType().bitsLT(VT.getScalarType()) &&
9231"Should only be an extending load, not truncating!");
9232assert(VT.isInteger() == MemVT.isInteger() &&
9233"Cannot convert from FP to Int or Int -> FP!");
9234assert(VT.isVector() == MemVT.isVector() &&
9235"Cannot use an ext load to convert to or from a vector!");
9236assert((!VT.isVector() ||
9237 VT.getVectorElementCount() == MemVT.getVectorElementCount()) &&
9238"Cannot use an ext load to change the number of vector elements!");
9239 }
9240
9241boolIndexed = AM !=ISD::UNINDEXED;
9242assert((Indexed ||Offset.isUndef()) &&"Unindexed load with an offset!");
9243
9244SDVTList VTs =Indexed ?
9245getVTList(VT,Ptr.getValueType(), MVT::Other) :getVTList(VT, MVT::Other);
9246SDValue Ops[] = { Chain,Ptr,Offset };
9247FoldingSetNodeIDID;
9248AddNodeIDNode(ID,ISD::LOAD, VTs, Ops);
9249ID.AddInteger(MemVT.getRawBits());
9250ID.AddInteger(getSyntheticNodeSubclassData<LoadSDNode>(
9251 dl.getIROrder(), VTs, AM, ExtType, MemVT, MMO));
9252ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
9253ID.AddInteger(MMO->getFlags());
9254void *IP =nullptr;
9255if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP)) {
9256 cast<LoadSDNode>(E)->refineAlignment(MMO);
9257returnSDValue(E, 0);
9258 }
9259auto *N = newSDNode<LoadSDNode>(dl.getIROrder(), dl.getDebugLoc(), VTs, AM,
9260 ExtType, MemVT, MMO);
9261 createOperands(N, Ops);
9262
9263 CSEMap.InsertNode(N, IP);
9264 InsertNode(N);
9265SDValue V(N, 0);
9266NewSDValueDbgMsg(V,"Creating new node: ",this);
9267return V;
9268}
9269
9270SDValueSelectionDAG::getLoad(EVT VT,constSDLoc &dl,SDValue Chain,
9271SDValuePtr,MachinePointerInfo PtrInfo,
9272MaybeAlign Alignment,
9273MachineMemOperand::Flags MMOFlags,
9274constAAMDNodes &AAInfo,constMDNode *Ranges) {
9275SDValue Undef =getUNDEF(Ptr.getValueType());
9276returngetLoad(ISD::UNINDEXED,ISD::NON_EXTLOAD, VT, dl, Chain,Ptr, Undef,
9277 PtrInfo, VT, Alignment, MMOFlags, AAInfo, Ranges);
9278}
9279
9280SDValueSelectionDAG::getLoad(EVT VT,constSDLoc &dl,SDValue Chain,
9281SDValuePtr,MachineMemOperand *MMO) {
9282SDValue Undef =getUNDEF(Ptr.getValueType());
9283returngetLoad(ISD::UNINDEXED,ISD::NON_EXTLOAD, VT, dl, Chain,Ptr, Undef,
9284 VT, MMO);
9285}
9286
9287SDValueSelectionDAG::getExtLoad(ISD::LoadExtType ExtType,constSDLoc &dl,
9288EVT VT,SDValue Chain,SDValuePtr,
9289MachinePointerInfo PtrInfo,EVT MemVT,
9290MaybeAlign Alignment,
9291MachineMemOperand::Flags MMOFlags,
9292constAAMDNodes &AAInfo) {
9293SDValue Undef =getUNDEF(Ptr.getValueType());
9294returngetLoad(ISD::UNINDEXED, ExtType, VT, dl, Chain,Ptr, Undef, PtrInfo,
9295 MemVT, Alignment, MMOFlags, AAInfo);
9296}
9297
9298SDValueSelectionDAG::getExtLoad(ISD::LoadExtType ExtType,constSDLoc &dl,
9299EVT VT,SDValue Chain,SDValuePtr,EVT MemVT,
9300MachineMemOperand *MMO) {
9301SDValue Undef =getUNDEF(Ptr.getValueType());
9302returngetLoad(ISD::UNINDEXED, ExtType, VT, dl, Chain,Ptr, Undef,
9303 MemVT, MMO);
9304}
9305
9306SDValueSelectionDAG::getIndexedLoad(SDValue OrigLoad,constSDLoc &dl,
9307SDValueBase,SDValueOffset,
9308ISD::MemIndexedMode AM) {
9309LoadSDNode *LD = cast<LoadSDNode>(OrigLoad);
9310assert(LD->getOffset().isUndef() &&"Load is already a indexed load!");
9311// Don't propagate the invariant or dereferenceable flags.
9312auto MMOFlags =
9313 LD->getMemOperand()->getFlags() &
9314 ~(MachineMemOperand::MOInvariant |MachineMemOperand::MODereferenceable);
9315returngetLoad(AM, LD->getExtensionType(), OrigLoad.getValueType(), dl,
9316 LD->getChain(),Base,Offset, LD->getPointerInfo(),
9317 LD->getMemoryVT(), LD->getAlign(), MMOFlags, LD->getAAInfo());
9318}
9319
9320SDValueSelectionDAG::getStore(SDValue Chain,constSDLoc &dl,SDValue Val,
9321SDValuePtr,MachinePointerInfo PtrInfo,
9322Align Alignment,
9323MachineMemOperand::Flags MMOFlags,
9324constAAMDNodes &AAInfo) {
9325assert(Chain.getValueType() == MVT::Other &&"Invalid chain type");
9326
9327 MMOFlags |=MachineMemOperand::MOStore;
9328assert((MMOFlags &MachineMemOperand::MOLoad) == 0);
9329
9330if (PtrInfo.V.isNull())
9331 PtrInfo =InferPointerInfo(PtrInfo, *this,Ptr);
9332
9333MachineFunction &MF =getMachineFunction();
9334LocationSizeSize =LocationSize::precise(Val.getValueType().getStoreSize());
9335MachineMemOperand *MMO =
9336 MF.getMachineMemOperand(PtrInfo, MMOFlags,Size, Alignment, AAInfo);
9337returngetStore(Chain, dl, Val,Ptr, MMO);
9338}
9339
9340SDValueSelectionDAG::getStore(SDValue Chain,constSDLoc &dl,SDValue Val,
9341SDValuePtr,MachineMemOperand *MMO) {
9342assert(Chain.getValueType() == MVT::Other &&
9343"Invalid chain type");
9344EVT VT = Val.getValueType();
9345SDVTList VTs =getVTList(MVT::Other);
9346SDValue Undef =getUNDEF(Ptr.getValueType());
9347SDValue Ops[] = { Chain, Val,Ptr, Undef };
9348FoldingSetNodeIDID;
9349AddNodeIDNode(ID,ISD::STORE, VTs, Ops);
9350ID.AddInteger(VT.getRawBits());
9351ID.AddInteger(getSyntheticNodeSubclassData<StoreSDNode>(
9352 dl.getIROrder(), VTs,ISD::UNINDEXED,false, VT, MMO));
9353ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
9354ID.AddInteger(MMO->getFlags());
9355void *IP =nullptr;
9356if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP)) {
9357 cast<StoreSDNode>(E)->refineAlignment(MMO);
9358returnSDValue(E, 0);
9359 }
9360auto *N = newSDNode<StoreSDNode>(dl.getIROrder(), dl.getDebugLoc(), VTs,
9361ISD::UNINDEXED,false, VT, MMO);
9362 createOperands(N, Ops);
9363
9364 CSEMap.InsertNode(N, IP);
9365 InsertNode(N);
9366SDValue V(N, 0);
9367NewSDValueDbgMsg(V,"Creating new node: ",this);
9368return V;
9369}
9370
9371SDValueSelectionDAG::getTruncStore(SDValue Chain,constSDLoc &dl,SDValue Val,
9372SDValuePtr,MachinePointerInfo PtrInfo,
9373EVT SVT,Align Alignment,
9374MachineMemOperand::Flags MMOFlags,
9375constAAMDNodes &AAInfo) {
9376assert(Chain.getValueType() == MVT::Other &&
9377"Invalid chain type");
9378
9379 MMOFlags |=MachineMemOperand::MOStore;
9380assert((MMOFlags &MachineMemOperand::MOLoad) == 0);
9381
9382if (PtrInfo.V.isNull())
9383 PtrInfo =InferPointerInfo(PtrInfo, *this,Ptr);
9384
9385MachineFunction &MF =getMachineFunction();
9386MachineMemOperand *MMO = MF.getMachineMemOperand(
9387 PtrInfo, MMOFlags,LocationSize::precise(SVT.getStoreSize()), Alignment,
9388 AAInfo);
9389returngetTruncStore(Chain, dl, Val,Ptr, SVT, MMO);
9390}
9391
9392SDValueSelectionDAG::getTruncStore(SDValue Chain,constSDLoc &dl,SDValue Val,
9393SDValuePtr,EVT SVT,
9394MachineMemOperand *MMO) {
9395EVT VT = Val.getValueType();
9396
9397assert(Chain.getValueType() == MVT::Other &&
9398"Invalid chain type");
9399if (VT == SVT)
9400returngetStore(Chain, dl, Val,Ptr, MMO);
9401
9402assert(SVT.getScalarType().bitsLT(VT.getScalarType()) &&
9403"Should only be a truncating store, not extending!");
9404assert(VT.isInteger() == SVT.isInteger() &&
9405"Can't do FP-INT conversion!");
9406assert(VT.isVector() == SVT.isVector() &&
9407"Cannot use trunc store to convert to or from a vector!");
9408assert((!VT.isVector() ||
9409 VT.getVectorElementCount() == SVT.getVectorElementCount()) &&
9410"Cannot use trunc store to change the number of vector elements!");
9411
9412SDVTList VTs =getVTList(MVT::Other);
9413SDValue Undef =getUNDEF(Ptr.getValueType());
9414SDValue Ops[] = { Chain, Val,Ptr, Undef };
9415FoldingSetNodeIDID;
9416AddNodeIDNode(ID,ISD::STORE, VTs, Ops);
9417ID.AddInteger(SVT.getRawBits());
9418ID.AddInteger(getSyntheticNodeSubclassData<StoreSDNode>(
9419 dl.getIROrder(), VTs,ISD::UNINDEXED,true, SVT, MMO));
9420ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
9421ID.AddInteger(MMO->getFlags());
9422void *IP =nullptr;
9423if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP)) {
9424 cast<StoreSDNode>(E)->refineAlignment(MMO);
9425returnSDValue(E, 0);
9426 }
9427auto *N = newSDNode<StoreSDNode>(dl.getIROrder(), dl.getDebugLoc(), VTs,
9428ISD::UNINDEXED,true, SVT, MMO);
9429 createOperands(N, Ops);
9430
9431 CSEMap.InsertNode(N, IP);
9432 InsertNode(N);
9433SDValue V(N, 0);
9434NewSDValueDbgMsg(V,"Creating new node: ",this);
9435return V;
9436}
9437
9438SDValueSelectionDAG::getIndexedStore(SDValue OrigStore,constSDLoc &dl,
9439SDValueBase,SDValueOffset,
9440ISD::MemIndexedMode AM) {
9441StoreSDNode *ST = cast<StoreSDNode>(OrigStore);
9442assert(ST->getOffset().isUndef() &&"Store is already a indexed store!");
9443SDVTList VTs =getVTList(Base.getValueType(), MVT::Other);
9444SDValue Ops[] = { ST->getChain(), ST->getValue(),Base,Offset };
9445FoldingSetNodeIDID;
9446AddNodeIDNode(ID,ISD::STORE, VTs, Ops);
9447ID.AddInteger(ST->getMemoryVT().getRawBits());
9448ID.AddInteger(ST->getRawSubclassData());
9449ID.AddInteger(ST->getPointerInfo().getAddrSpace());
9450ID.AddInteger(ST->getMemOperand()->getFlags());
9451void *IP =nullptr;
9452if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP))
9453returnSDValue(E, 0);
9454
9455auto *N = newSDNode<StoreSDNode>(dl.getIROrder(), dl.getDebugLoc(), VTs, AM,
9456 ST->isTruncatingStore(), ST->getMemoryVT(),
9457 ST->getMemOperand());
9458 createOperands(N, Ops);
9459
9460 CSEMap.InsertNode(N, IP);
9461 InsertNode(N);
9462SDValue V(N, 0);
9463NewSDValueDbgMsg(V,"Creating new node: ",this);
9464return V;
9465}
9466
9467SDValueSelectionDAG::getLoadVP(
9468ISD::MemIndexedMode AM,ISD::LoadExtType ExtType,EVT VT,constSDLoc &dl,
9469SDValue Chain,SDValuePtr,SDValueOffset,SDValue Mask,SDValue EVL,
9470MachinePointerInfo PtrInfo,EVT MemVT,Align Alignment,
9471MachineMemOperand::Flags MMOFlags,constAAMDNodes &AAInfo,
9472constMDNode *Ranges,bool IsExpanding) {
9473assert(Chain.getValueType() == MVT::Other &&"Invalid chain type");
9474
9475 MMOFlags |=MachineMemOperand::MOLoad;
9476assert((MMOFlags &MachineMemOperand::MOStore) == 0);
9477// If we don't have a PtrInfo, infer the trivial frame index case to simplify
9478// clients.
9479if (PtrInfo.V.isNull())
9480 PtrInfo =InferPointerInfo(PtrInfo, *this,Ptr,Offset);
9481
9482LocationSizeSize =LocationSize::precise(MemVT.getStoreSize());
9483MachineFunction &MF =getMachineFunction();
9484MachineMemOperand *MMO = MF.getMachineMemOperand(PtrInfo, MMOFlags,Size,
9485 Alignment, AAInfo, Ranges);
9486returngetLoadVP(AM, ExtType, VT, dl, Chain,Ptr,Offset, Mask, EVL, MemVT,
9487 MMO, IsExpanding);
9488}
9489
9490SDValueSelectionDAG::getLoadVP(ISD::MemIndexedMode AM,
9491ISD::LoadExtType ExtType,EVT VT,
9492constSDLoc &dl,SDValue Chain,SDValuePtr,
9493SDValueOffset,SDValue Mask,SDValue EVL,
9494EVT MemVT,MachineMemOperand *MMO,
9495bool IsExpanding) {
9496boolIndexed = AM !=ISD::UNINDEXED;
9497assert((Indexed ||Offset.isUndef()) &&"Unindexed load with an offset!");
9498
9499SDVTList VTs =Indexed ?getVTList(VT,Ptr.getValueType(), MVT::Other)
9500 :getVTList(VT, MVT::Other);
9501SDValue Ops[] = {Chain,Ptr,Offset, Mask, EVL};
9502FoldingSetNodeIDID;
9503AddNodeIDNode(ID, ISD::VP_LOAD, VTs, Ops);
9504ID.AddInteger(MemVT.getRawBits());
9505ID.AddInteger(getSyntheticNodeSubclassData<VPLoadSDNode>(
9506 dl.getIROrder(), VTs, AM, ExtType, IsExpanding, MemVT, MMO));
9507ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
9508ID.AddInteger(MMO->getFlags());
9509void *IP =nullptr;
9510if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP)) {
9511 cast<VPLoadSDNode>(E)->refineAlignment(MMO);
9512returnSDValue(E, 0);
9513 }
9514auto *N = newSDNode<VPLoadSDNode>(dl.getIROrder(), dl.getDebugLoc(), VTs, AM,
9515 ExtType, IsExpanding, MemVT, MMO);
9516 createOperands(N, Ops);
9517
9518 CSEMap.InsertNode(N, IP);
9519 InsertNode(N);
9520SDValue V(N, 0);
9521NewSDValueDbgMsg(V,"Creating new node: ",this);
9522return V;
9523}
9524
9525SDValueSelectionDAG::getLoadVP(EVT VT,constSDLoc &dl,SDValue Chain,
9526SDValuePtr,SDValue Mask,SDValue EVL,
9527MachinePointerInfo PtrInfo,
9528MaybeAlign Alignment,
9529MachineMemOperand::Flags MMOFlags,
9530constAAMDNodes &AAInfo,constMDNode *Ranges,
9531bool IsExpanding) {
9532SDValue Undef =getUNDEF(Ptr.getValueType());
9533returngetLoadVP(ISD::UNINDEXED,ISD::NON_EXTLOAD, VT, dl, Chain,Ptr, Undef,
9534 Mask, EVL, PtrInfo, VT, Alignment, MMOFlags, AAInfo, Ranges,
9535 IsExpanding);
9536}
9537
9538SDValueSelectionDAG::getLoadVP(EVT VT,constSDLoc &dl,SDValue Chain,
9539SDValuePtr,SDValue Mask,SDValue EVL,
9540MachineMemOperand *MMO,bool IsExpanding) {
9541SDValue Undef =getUNDEF(Ptr.getValueType());
9542returngetLoadVP(ISD::UNINDEXED,ISD::NON_EXTLOAD, VT, dl, Chain,Ptr, Undef,
9543 Mask, EVL, VT, MMO, IsExpanding);
9544}
9545
9546SDValueSelectionDAG::getExtLoadVP(ISD::LoadExtType ExtType,constSDLoc &dl,
9547EVT VT,SDValue Chain,SDValuePtr,
9548SDValue Mask,SDValue EVL,
9549MachinePointerInfo PtrInfo,EVT MemVT,
9550MaybeAlign Alignment,
9551MachineMemOperand::Flags MMOFlags,
9552constAAMDNodes &AAInfo,bool IsExpanding) {
9553SDValue Undef =getUNDEF(Ptr.getValueType());
9554returngetLoadVP(ISD::UNINDEXED, ExtType, VT, dl, Chain,Ptr, Undef, Mask,
9555 EVL, PtrInfo, MemVT, Alignment, MMOFlags, AAInfo,nullptr,
9556 IsExpanding);
9557}
9558
9559SDValueSelectionDAG::getExtLoadVP(ISD::LoadExtType ExtType,constSDLoc &dl,
9560EVT VT,SDValue Chain,SDValuePtr,
9561SDValue Mask,SDValue EVL,EVT MemVT,
9562MachineMemOperand *MMO,bool IsExpanding) {
9563SDValue Undef =getUNDEF(Ptr.getValueType());
9564returngetLoadVP(ISD::UNINDEXED, ExtType, VT, dl, Chain,Ptr, Undef, Mask,
9565 EVL, MemVT, MMO, IsExpanding);
9566}
9567
9568SDValueSelectionDAG::getIndexedLoadVP(SDValue OrigLoad,constSDLoc &dl,
9569SDValueBase,SDValueOffset,
9570ISD::MemIndexedMode AM) {
9571auto *LD = cast<VPLoadSDNode>(OrigLoad);
9572assert(LD->getOffset().isUndef() &&"Load is already a indexed load!");
9573// Don't propagate the invariant or dereferenceable flags.
9574auto MMOFlags =
9575 LD->getMemOperand()->getFlags() &
9576 ~(MachineMemOperand::MOInvariant |MachineMemOperand::MODereferenceable);
9577returngetLoadVP(AM, LD->getExtensionType(), OrigLoad.getValueType(), dl,
9578 LD->getChain(),Base,Offset, LD->getMask(),
9579 LD->getVectorLength(), LD->getPointerInfo(),
9580 LD->getMemoryVT(), LD->getAlign(), MMOFlags, LD->getAAInfo(),
9581nullptr, LD->isExpandingLoad());
9582}
9583
9584SDValueSelectionDAG::getStoreVP(SDValue Chain,constSDLoc &dl,SDValue Val,
9585SDValuePtr,SDValueOffset,SDValue Mask,
9586SDValue EVL,EVT MemVT,MachineMemOperand *MMO,
9587ISD::MemIndexedMode AM,bool IsTruncating,
9588bool IsCompressing) {
9589assert(Chain.getValueType() == MVT::Other &&"Invalid chain type");
9590boolIndexed = AM !=ISD::UNINDEXED;
9591assert((Indexed ||Offset.isUndef()) &&"Unindexed vp_store with an offset!");
9592SDVTList VTs =Indexed ?getVTList(Ptr.getValueType(), MVT::Other)
9593 :getVTList(MVT::Other);
9594SDValue Ops[] = {Chain, Val,Ptr,Offset, Mask, EVL};
9595FoldingSetNodeIDID;
9596AddNodeIDNode(ID, ISD::VP_STORE, VTs, Ops);
9597ID.AddInteger(MemVT.getRawBits());
9598ID.AddInteger(getSyntheticNodeSubclassData<VPStoreSDNode>(
9599 dl.getIROrder(), VTs, AM, IsTruncating, IsCompressing, MemVT, MMO));
9600ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
9601ID.AddInteger(MMO->getFlags());
9602void *IP =nullptr;
9603if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP)) {
9604 cast<VPStoreSDNode>(E)->refineAlignment(MMO);
9605returnSDValue(E, 0);
9606 }
9607auto *N = newSDNode<VPStoreSDNode>(dl.getIROrder(), dl.getDebugLoc(), VTs, AM,
9608 IsTruncating, IsCompressing, MemVT, MMO);
9609 createOperands(N, Ops);
9610
9611 CSEMap.InsertNode(N, IP);
9612 InsertNode(N);
9613SDValue V(N, 0);
9614NewSDValueDbgMsg(V,"Creating new node: ",this);
9615return V;
9616}
9617
9618SDValueSelectionDAG::getTruncStoreVP(SDValue Chain,constSDLoc &dl,
9619SDValue Val,SDValuePtr,SDValue Mask,
9620SDValue EVL,MachinePointerInfo PtrInfo,
9621EVT SVT,Align Alignment,
9622MachineMemOperand::Flags MMOFlags,
9623constAAMDNodes &AAInfo,
9624bool IsCompressing) {
9625assert(Chain.getValueType() == MVT::Other &&"Invalid chain type");
9626
9627 MMOFlags |=MachineMemOperand::MOStore;
9628assert((MMOFlags &MachineMemOperand::MOLoad) == 0);
9629
9630if (PtrInfo.V.isNull())
9631 PtrInfo =InferPointerInfo(PtrInfo, *this,Ptr);
9632
9633MachineFunction &MF =getMachineFunction();
9634MachineMemOperand *MMO = MF.getMachineMemOperand(
9635 PtrInfo, MMOFlags,LocationSize::precise(SVT.getStoreSize()), Alignment,
9636 AAInfo);
9637returngetTruncStoreVP(Chain, dl, Val,Ptr, Mask, EVL, SVT, MMO,
9638 IsCompressing);
9639}
9640
9641SDValueSelectionDAG::getTruncStoreVP(SDValue Chain,constSDLoc &dl,
9642SDValue Val,SDValuePtr,SDValue Mask,
9643SDValue EVL,EVT SVT,
9644MachineMemOperand *MMO,
9645bool IsCompressing) {
9646EVT VT = Val.getValueType();
9647
9648assert(Chain.getValueType() == MVT::Other &&"Invalid chain type");
9649if (VT == SVT)
9650returngetStoreVP(Chain, dl, Val,Ptr,getUNDEF(Ptr.getValueType()), Mask,
9651 EVL, VT, MMO,ISD::UNINDEXED,
9652/*IsTruncating*/false, IsCompressing);
9653
9654assert(SVT.getScalarType().bitsLT(VT.getScalarType()) &&
9655"Should only be a truncating store, not extending!");
9656assert(VT.isInteger() == SVT.isInteger() &&"Can't do FP-INT conversion!");
9657assert(VT.isVector() == SVT.isVector() &&
9658"Cannot use trunc store to convert to or from a vector!");
9659assert((!VT.isVector() ||
9660 VT.getVectorElementCount() == SVT.getVectorElementCount()) &&
9661"Cannot use trunc store to change the number of vector elements!");
9662
9663SDVTList VTs =getVTList(MVT::Other);
9664SDValue Undef =getUNDEF(Ptr.getValueType());
9665SDValue Ops[] = {Chain, Val,Ptr, Undef, Mask, EVL};
9666FoldingSetNodeIDID;
9667AddNodeIDNode(ID, ISD::VP_STORE, VTs, Ops);
9668ID.AddInteger(SVT.getRawBits());
9669ID.AddInteger(getSyntheticNodeSubclassData<VPStoreSDNode>(
9670 dl.getIROrder(), VTs,ISD::UNINDEXED,true, IsCompressing, SVT, MMO));
9671ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
9672ID.AddInteger(MMO->getFlags());
9673void *IP =nullptr;
9674if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP)) {
9675 cast<VPStoreSDNode>(E)->refineAlignment(MMO);
9676returnSDValue(E, 0);
9677 }
9678auto *N =
9679 newSDNode<VPStoreSDNode>(dl.getIROrder(), dl.getDebugLoc(), VTs,
9680ISD::UNINDEXED,true, IsCompressing, SVT, MMO);
9681 createOperands(N, Ops);
9682
9683 CSEMap.InsertNode(N, IP);
9684 InsertNode(N);
9685SDValue V(N, 0);
9686NewSDValueDbgMsg(V,"Creating new node: ",this);
9687return V;
9688}
9689
9690SDValueSelectionDAG::getIndexedStoreVP(SDValue OrigStore,constSDLoc &dl,
9691SDValueBase,SDValueOffset,
9692ISD::MemIndexedMode AM) {
9693auto *ST = cast<VPStoreSDNode>(OrigStore);
9694assert(ST->getOffset().isUndef() &&"Store is already an indexed store!");
9695SDVTList VTs =getVTList(Base.getValueType(), MVT::Other);
9696SDValue Ops[] = {ST->getChain(), ST->getValue(),Base,
9697Offset, ST->getMask(), ST->getVectorLength()};
9698FoldingSetNodeIDID;
9699AddNodeIDNode(ID, ISD::VP_STORE, VTs, Ops);
9700ID.AddInteger(ST->getMemoryVT().getRawBits());
9701ID.AddInteger(ST->getRawSubclassData());
9702ID.AddInteger(ST->getPointerInfo().getAddrSpace());
9703ID.AddInteger(ST->getMemOperand()->getFlags());
9704void *IP =nullptr;
9705if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP))
9706returnSDValue(E, 0);
9707
9708auto *N = newSDNode<VPStoreSDNode>(
9709 dl.getIROrder(), dl.getDebugLoc(), VTs, AM, ST->isTruncatingStore(),
9710 ST->isCompressingStore(), ST->getMemoryVT(), ST->getMemOperand());
9711 createOperands(N, Ops);
9712
9713 CSEMap.InsertNode(N, IP);
9714 InsertNode(N);
9715SDValue V(N, 0);
9716NewSDValueDbgMsg(V,"Creating new node: ",this);
9717return V;
9718}
9719
9720SDValueSelectionDAG::getStridedLoadVP(
9721ISD::MemIndexedMode AM,ISD::LoadExtType ExtType,EVT VT,constSDLoc &DL,
9722SDValue Chain,SDValuePtr,SDValueOffset,SDValue Stride,SDValue Mask,
9723SDValue EVL,EVT MemVT,MachineMemOperand *MMO,bool IsExpanding) {
9724boolIndexed = AM !=ISD::UNINDEXED;
9725assert((Indexed ||Offset.isUndef()) &&"Unindexed load with an offset!");
9726
9727SDValue Ops[] = {Chain,Ptr,Offset, Stride, Mask, EVL};
9728SDVTList VTs =Indexed ?getVTList(VT,Ptr.getValueType(), MVT::Other)
9729 :getVTList(VT, MVT::Other);
9730FoldingSetNodeIDID;
9731AddNodeIDNode(ID, ISD::EXPERIMENTAL_VP_STRIDED_LOAD, VTs, Ops);
9732ID.AddInteger(VT.getRawBits());
9733ID.AddInteger(getSyntheticNodeSubclassData<VPStridedLoadSDNode>(
9734DL.getIROrder(), VTs, AM, ExtType, IsExpanding, MemVT, MMO));
9735ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
9736
9737void *IP =nullptr;
9738if (SDNode *E = FindNodeOrInsertPos(ID,DL, IP)) {
9739 cast<VPStridedLoadSDNode>(E)->refineAlignment(MMO);
9740returnSDValue(E, 0);
9741 }
9742
9743auto *N =
9744 newSDNode<VPStridedLoadSDNode>(DL.getIROrder(),DL.getDebugLoc(), VTs, AM,
9745 ExtType, IsExpanding, MemVT, MMO);
9746 createOperands(N, Ops);
9747 CSEMap.InsertNode(N, IP);
9748 InsertNode(N);
9749SDValue V(N, 0);
9750NewSDValueDbgMsg(V,"Creating new node: ",this);
9751return V;
9752}
9753
9754SDValueSelectionDAG::getStridedLoadVP(EVT VT,constSDLoc &DL,SDValue Chain,
9755SDValuePtr,SDValue Stride,
9756SDValue Mask,SDValue EVL,
9757MachineMemOperand *MMO,
9758bool IsExpanding) {
9759SDValue Undef =getUNDEF(Ptr.getValueType());
9760returngetStridedLoadVP(ISD::UNINDEXED,ISD::NON_EXTLOAD, VT,DL, Chain,Ptr,
9761 Undef, Stride, Mask, EVL, VT, MMO, IsExpanding);
9762}
9763
9764SDValueSelectionDAG::getExtStridedLoadVP(
9765ISD::LoadExtType ExtType,constSDLoc &DL,EVT VT,SDValue Chain,
9766SDValuePtr,SDValue Stride,SDValue Mask,SDValue EVL,EVT MemVT,
9767MachineMemOperand *MMO,bool IsExpanding) {
9768SDValue Undef =getUNDEF(Ptr.getValueType());
9769returngetStridedLoadVP(ISD::UNINDEXED, ExtType, VT,DL, Chain,Ptr, Undef,
9770 Stride, Mask, EVL, MemVT, MMO, IsExpanding);
9771}
9772
9773SDValueSelectionDAG::getStridedStoreVP(SDValue Chain,constSDLoc &DL,
9774SDValue Val,SDValuePtr,
9775SDValueOffset,SDValue Stride,
9776SDValue Mask,SDValue EVL,EVT MemVT,
9777MachineMemOperand *MMO,
9778ISD::MemIndexedMode AM,
9779bool IsTruncating,bool IsCompressing) {
9780assert(Chain.getValueType() == MVT::Other &&"Invalid chain type");
9781boolIndexed = AM !=ISD::UNINDEXED;
9782assert((Indexed ||Offset.isUndef()) &&"Unindexed vp_store with an offset!");
9783SDVTList VTs =Indexed ?getVTList(Ptr.getValueType(), MVT::Other)
9784 :getVTList(MVT::Other);
9785SDValue Ops[] = {Chain, Val,Ptr,Offset, Stride, Mask, EVL};
9786FoldingSetNodeIDID;
9787AddNodeIDNode(ID, ISD::EXPERIMENTAL_VP_STRIDED_STORE, VTs, Ops);
9788ID.AddInteger(MemVT.getRawBits());
9789ID.AddInteger(getSyntheticNodeSubclassData<VPStridedStoreSDNode>(
9790DL.getIROrder(), VTs, AM, IsTruncating, IsCompressing, MemVT, MMO));
9791ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
9792void *IP =nullptr;
9793if (SDNode *E = FindNodeOrInsertPos(ID,DL, IP)) {
9794 cast<VPStridedStoreSDNode>(E)->refineAlignment(MMO);
9795returnSDValue(E, 0);
9796 }
9797auto *N = newSDNode<VPStridedStoreSDNode>(DL.getIROrder(),DL.getDebugLoc(),
9798 VTs, AM, IsTruncating,
9799 IsCompressing, MemVT, MMO);
9800 createOperands(N, Ops);
9801
9802 CSEMap.InsertNode(N, IP);
9803 InsertNode(N);
9804SDValue V(N, 0);
9805NewSDValueDbgMsg(V,"Creating new node: ",this);
9806return V;
9807}
9808
9809SDValueSelectionDAG::getTruncStridedStoreVP(SDValue Chain,constSDLoc &DL,
9810SDValue Val,SDValuePtr,
9811SDValue Stride,SDValue Mask,
9812SDValue EVL,EVT SVT,
9813MachineMemOperand *MMO,
9814bool IsCompressing) {
9815EVT VT = Val.getValueType();
9816
9817assert(Chain.getValueType() == MVT::Other &&"Invalid chain type");
9818if (VT == SVT)
9819returngetStridedStoreVP(Chain,DL, Val,Ptr,getUNDEF(Ptr.getValueType()),
9820 Stride, Mask, EVL, VT, MMO,ISD::UNINDEXED,
9821/*IsTruncating*/false, IsCompressing);
9822
9823assert(SVT.getScalarType().bitsLT(VT.getScalarType()) &&
9824"Should only be a truncating store, not extending!");
9825assert(VT.isInteger() == SVT.isInteger() &&"Can't do FP-INT conversion!");
9826assert(VT.isVector() == SVT.isVector() &&
9827"Cannot use trunc store to convert to or from a vector!");
9828assert((!VT.isVector() ||
9829 VT.getVectorElementCount() == SVT.getVectorElementCount()) &&
9830"Cannot use trunc store to change the number of vector elements!");
9831
9832SDVTList VTs =getVTList(MVT::Other);
9833SDValue Undef =getUNDEF(Ptr.getValueType());
9834SDValue Ops[] = {Chain, Val,Ptr, Undef, Stride, Mask, EVL};
9835FoldingSetNodeIDID;
9836AddNodeIDNode(ID, ISD::EXPERIMENTAL_VP_STRIDED_STORE, VTs, Ops);
9837ID.AddInteger(SVT.getRawBits());
9838ID.AddInteger(getSyntheticNodeSubclassData<VPStridedStoreSDNode>(
9839DL.getIROrder(), VTs,ISD::UNINDEXED,true, IsCompressing, SVT, MMO));
9840ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
9841void *IP =nullptr;
9842if (SDNode *E = FindNodeOrInsertPos(ID,DL, IP)) {
9843 cast<VPStridedStoreSDNode>(E)->refineAlignment(MMO);
9844returnSDValue(E, 0);
9845 }
9846auto *N = newSDNode<VPStridedStoreSDNode>(DL.getIROrder(),DL.getDebugLoc(),
9847 VTs,ISD::UNINDEXED,true,
9848 IsCompressing, SVT, MMO);
9849 createOperands(N, Ops);
9850
9851 CSEMap.InsertNode(N, IP);
9852 InsertNode(N);
9853SDValue V(N, 0);
9854NewSDValueDbgMsg(V,"Creating new node: ",this);
9855return V;
9856}
9857
9858SDValueSelectionDAG::getGatherVP(SDVTList VTs,EVT VT,constSDLoc &dl,
9859ArrayRef<SDValue> Ops,MachineMemOperand *MMO,
9860ISD::MemIndexType IndexType) {
9861assert(Ops.size() == 6 &&"Incompatible number of operands");
9862
9863FoldingSetNodeIDID;
9864AddNodeIDNode(ID, ISD::VP_GATHER, VTs, Ops);
9865ID.AddInteger(VT.getRawBits());
9866ID.AddInteger(getSyntheticNodeSubclassData<VPGatherSDNode>(
9867 dl.getIROrder(), VTs, VT, MMO, IndexType));
9868ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
9869ID.AddInteger(MMO->getFlags());
9870void *IP =nullptr;
9871if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP)) {
9872 cast<VPGatherSDNode>(E)->refineAlignment(MMO);
9873returnSDValue(E, 0);
9874 }
9875
9876auto *N = newSDNode<VPGatherSDNode>(dl.getIROrder(), dl.getDebugLoc(), VTs,
9877 VT, MMO, IndexType);
9878 createOperands(N, Ops);
9879
9880assert(N->getMask().getValueType().getVectorElementCount() ==
9881N->getValueType(0).getVectorElementCount() &&
9882"Vector width mismatch between mask and data");
9883assert(N->getIndex().getValueType().getVectorElementCount().isScalable() ==
9884N->getValueType(0).getVectorElementCount().isScalable() &&
9885"Scalable flags of index and data do not match");
9886assert(ElementCount::isKnownGE(
9887N->getIndex().getValueType().getVectorElementCount(),
9888N->getValueType(0).getVectorElementCount()) &&
9889"Vector width mismatch between index and data");
9890assert(isa<ConstantSDNode>(N->getScale()) &&
9891N->getScale()->getAsAPIntVal().isPowerOf2() &&
9892"Scale should be a constant power of 2");
9893
9894 CSEMap.InsertNode(N, IP);
9895 InsertNode(N);
9896SDValue V(N, 0);
9897NewSDValueDbgMsg(V,"Creating new node: ",this);
9898return V;
9899}
9900
9901SDValueSelectionDAG::getScatterVP(SDVTList VTs,EVT VT,constSDLoc &dl,
9902ArrayRef<SDValue> Ops,
9903MachineMemOperand *MMO,
9904ISD::MemIndexType IndexType) {
9905assert(Ops.size() == 7 &&"Incompatible number of operands");
9906
9907FoldingSetNodeIDID;
9908AddNodeIDNode(ID, ISD::VP_SCATTER, VTs, Ops);
9909ID.AddInteger(VT.getRawBits());
9910ID.AddInteger(getSyntheticNodeSubclassData<VPScatterSDNode>(
9911 dl.getIROrder(), VTs, VT, MMO, IndexType));
9912ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
9913ID.AddInteger(MMO->getFlags());
9914void *IP =nullptr;
9915if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP)) {
9916 cast<VPScatterSDNode>(E)->refineAlignment(MMO);
9917returnSDValue(E, 0);
9918 }
9919auto *N = newSDNode<VPScatterSDNode>(dl.getIROrder(), dl.getDebugLoc(), VTs,
9920 VT, MMO, IndexType);
9921 createOperands(N, Ops);
9922
9923assert(N->getMask().getValueType().getVectorElementCount() ==
9924N->getValue().getValueType().getVectorElementCount() &&
9925"Vector width mismatch between mask and data");
9926assert(
9927N->getIndex().getValueType().getVectorElementCount().isScalable() ==
9928N->getValue().getValueType().getVectorElementCount().isScalable() &&
9929"Scalable flags of index and data do not match");
9930assert(ElementCount::isKnownGE(
9931N->getIndex().getValueType().getVectorElementCount(),
9932N->getValue().getValueType().getVectorElementCount()) &&
9933"Vector width mismatch between index and data");
9934assert(isa<ConstantSDNode>(N->getScale()) &&
9935N->getScale()->getAsAPIntVal().isPowerOf2() &&
9936"Scale should be a constant power of 2");
9937
9938 CSEMap.InsertNode(N, IP);
9939 InsertNode(N);
9940SDValue V(N, 0);
9941NewSDValueDbgMsg(V,"Creating new node: ",this);
9942return V;
9943}
9944
9945SDValueSelectionDAG::getMaskedLoad(EVT VT,constSDLoc &dl,SDValue Chain,
9946SDValueBase,SDValueOffset,SDValue Mask,
9947SDValue PassThru,EVT MemVT,
9948MachineMemOperand *MMO,
9949ISD::MemIndexedMode AM,
9950ISD::LoadExtType ExtTy,bool isExpanding) {
9951boolIndexed = AM !=ISD::UNINDEXED;
9952assert((Indexed ||Offset.isUndef()) &&
9953"Unindexed masked load with an offset!");
9954SDVTList VTs =Indexed ?getVTList(VT,Base.getValueType(), MVT::Other)
9955 :getVTList(VT, MVT::Other);
9956SDValue Ops[] = {Chain,Base,Offset, Mask, PassThru};
9957FoldingSetNodeIDID;
9958AddNodeIDNode(ID,ISD::MLOAD, VTs, Ops);
9959ID.AddInteger(MemVT.getRawBits());
9960ID.AddInteger(getSyntheticNodeSubclassData<MaskedLoadSDNode>(
9961 dl.getIROrder(), VTs, AM, ExtTy, isExpanding, MemVT, MMO));
9962ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
9963ID.AddInteger(MMO->getFlags());
9964void *IP =nullptr;
9965if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP)) {
9966 cast<MaskedLoadSDNode>(E)->refineAlignment(MMO);
9967returnSDValue(E, 0);
9968 }
9969auto *N = newSDNode<MaskedLoadSDNode>(dl.getIROrder(), dl.getDebugLoc(), VTs,
9970 AM, ExtTy, isExpanding, MemVT, MMO);
9971 createOperands(N, Ops);
9972
9973 CSEMap.InsertNode(N, IP);
9974 InsertNode(N);
9975SDValue V(N, 0);
9976NewSDValueDbgMsg(V,"Creating new node: ",this);
9977return V;
9978}
9979
9980SDValueSelectionDAG::getIndexedMaskedLoad(SDValue OrigLoad,constSDLoc &dl,
9981SDValueBase,SDValueOffset,
9982ISD::MemIndexedMode AM) {
9983MaskedLoadSDNode *LD = cast<MaskedLoadSDNode>(OrigLoad);
9984assert(LD->getOffset().isUndef() &&"Masked load is already a indexed load!");
9985returngetMaskedLoad(OrigLoad.getValueType(), dl, LD->getChain(),Base,
9986Offset, LD->getMask(), LD->getPassThru(),
9987 LD->getMemoryVT(), LD->getMemOperand(), AM,
9988 LD->getExtensionType(), LD->isExpandingLoad());
9989}
9990
9991SDValueSelectionDAG::getMaskedStore(SDValue Chain,constSDLoc &dl,
9992SDValue Val,SDValueBase,SDValueOffset,
9993SDValue Mask,EVT MemVT,
9994MachineMemOperand *MMO,
9995ISD::MemIndexedMode AM,bool IsTruncating,
9996bool IsCompressing) {
9997assert(Chain.getValueType() == MVT::Other &&
9998"Invalid chain type");
9999boolIndexed = AM !=ISD::UNINDEXED;
10000assert((Indexed ||Offset.isUndef()) &&
10001"Unindexed masked store with an offset!");
10002SDVTList VTs =Indexed ?getVTList(Base.getValueType(), MVT::Other)
10003 :getVTList(MVT::Other);
10004SDValue Ops[] = {Chain, Val,Base,Offset, Mask};
10005FoldingSetNodeIDID;
10006AddNodeIDNode(ID,ISD::MSTORE, VTs, Ops);
10007ID.AddInteger(MemVT.getRawBits());
10008ID.AddInteger(getSyntheticNodeSubclassData<MaskedStoreSDNode>(
10009 dl.getIROrder(), VTs, AM, IsTruncating, IsCompressing, MemVT, MMO));
10010ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
10011ID.AddInteger(MMO->getFlags());
10012void *IP =nullptr;
10013if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP)) {
10014 cast<MaskedStoreSDNode>(E)->refineAlignment(MMO);
10015returnSDValue(E, 0);
10016 }
10017auto *N =
10018 newSDNode<MaskedStoreSDNode>(dl.getIROrder(), dl.getDebugLoc(), VTs, AM,
10019 IsTruncating, IsCompressing, MemVT, MMO);
10020 createOperands(N, Ops);
10021
10022 CSEMap.InsertNode(N, IP);
10023 InsertNode(N);
10024SDValue V(N, 0);
10025NewSDValueDbgMsg(V,"Creating new node: ",this);
10026return V;
10027}
10028
10029SDValueSelectionDAG::getIndexedMaskedStore(SDValue OrigStore,constSDLoc &dl,
10030SDValueBase,SDValueOffset,
10031ISD::MemIndexedMode AM) {
10032MaskedStoreSDNode *ST = cast<MaskedStoreSDNode>(OrigStore);
10033assert(ST->getOffset().isUndef() &&
10034"Masked store is already a indexed store!");
10035returngetMaskedStore(ST->getChain(), dl, ST->getValue(),Base,Offset,
10036 ST->getMask(), ST->getMemoryVT(), ST->getMemOperand(),
10037 AM, ST->isTruncatingStore(), ST->isCompressingStore());
10038}
10039
10040SDValueSelectionDAG::getMaskedGather(SDVTList VTs,EVT MemVT,constSDLoc &dl,
10041ArrayRef<SDValue> Ops,
10042MachineMemOperand *MMO,
10043ISD::MemIndexType IndexType,
10044ISD::LoadExtType ExtTy) {
10045assert(Ops.size() == 6 &&"Incompatible number of operands");
10046
10047FoldingSetNodeIDID;
10048AddNodeIDNode(ID,ISD::MGATHER, VTs, Ops);
10049ID.AddInteger(MemVT.getRawBits());
10050ID.AddInteger(getSyntheticNodeSubclassData<MaskedGatherSDNode>(
10051 dl.getIROrder(), VTs, MemVT, MMO, IndexType, ExtTy));
10052ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
10053ID.AddInteger(MMO->getFlags());
10054void *IP =nullptr;
10055if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP)) {
10056 cast<MaskedGatherSDNode>(E)->refineAlignment(MMO);
10057returnSDValue(E, 0);
10058 }
10059
10060auto *N = newSDNode<MaskedGatherSDNode>(dl.getIROrder(), dl.getDebugLoc(),
10061 VTs, MemVT, MMO, IndexType, ExtTy);
10062 createOperands(N, Ops);
10063
10064assert(N->getPassThru().getValueType() ==N->getValueType(0) &&
10065"Incompatible type of the PassThru value in MaskedGatherSDNode");
10066assert(N->getMask().getValueType().getVectorElementCount() ==
10067N->getValueType(0).getVectorElementCount() &&
10068"Vector width mismatch between mask and data");
10069assert(N->getIndex().getValueType().getVectorElementCount().isScalable() ==
10070N->getValueType(0).getVectorElementCount().isScalable() &&
10071"Scalable flags of index and data do not match");
10072assert(ElementCount::isKnownGE(
10073N->getIndex().getValueType().getVectorElementCount(),
10074N->getValueType(0).getVectorElementCount()) &&
10075"Vector width mismatch between index and data");
10076assert(isa<ConstantSDNode>(N->getScale()) &&
10077N->getScale()->getAsAPIntVal().isPowerOf2() &&
10078"Scale should be a constant power of 2");
10079
10080 CSEMap.InsertNode(N, IP);
10081 InsertNode(N);
10082SDValue V(N, 0);
10083NewSDValueDbgMsg(V,"Creating new node: ",this);
10084return V;
10085}
10086
10087SDValueSelectionDAG::getMaskedScatter(SDVTList VTs,EVT MemVT,constSDLoc &dl,
10088ArrayRef<SDValue> Ops,
10089MachineMemOperand *MMO,
10090ISD::MemIndexType IndexType,
10091bool IsTrunc) {
10092assert(Ops.size() == 6 &&"Incompatible number of operands");
10093
10094FoldingSetNodeIDID;
10095AddNodeIDNode(ID,ISD::MSCATTER, VTs, Ops);
10096ID.AddInteger(MemVT.getRawBits());
10097ID.AddInteger(getSyntheticNodeSubclassData<MaskedScatterSDNode>(
10098 dl.getIROrder(), VTs, MemVT, MMO, IndexType, IsTrunc));
10099ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
10100ID.AddInteger(MMO->getFlags());
10101void *IP =nullptr;
10102if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP)) {
10103 cast<MaskedScatterSDNode>(E)->refineAlignment(MMO);
10104returnSDValue(E, 0);
10105 }
10106
10107auto *N = newSDNode<MaskedScatterSDNode>(dl.getIROrder(), dl.getDebugLoc(),
10108 VTs, MemVT, MMO, IndexType, IsTrunc);
10109 createOperands(N, Ops);
10110
10111assert(N->getMask().getValueType().getVectorElementCount() ==
10112N->getValue().getValueType().getVectorElementCount() &&
10113"Vector width mismatch between mask and data");
10114assert(
10115N->getIndex().getValueType().getVectorElementCount().isScalable() ==
10116N->getValue().getValueType().getVectorElementCount().isScalable() &&
10117"Scalable flags of index and data do not match");
10118assert(ElementCount::isKnownGE(
10119N->getIndex().getValueType().getVectorElementCount(),
10120N->getValue().getValueType().getVectorElementCount()) &&
10121"Vector width mismatch between index and data");
10122assert(isa<ConstantSDNode>(N->getScale()) &&
10123N->getScale()->getAsAPIntVal().isPowerOf2() &&
10124"Scale should be a constant power of 2");
10125
10126 CSEMap.InsertNode(N, IP);
10127 InsertNode(N);
10128SDValue V(N, 0);
10129NewSDValueDbgMsg(V,"Creating new node: ",this);
10130return V;
10131}
10132
10133SDValueSelectionDAG::getMaskedHistogram(SDVTList VTs,EVT MemVT,
10134constSDLoc &dl,ArrayRef<SDValue> Ops,
10135MachineMemOperand *MMO,
10136ISD::MemIndexType IndexType) {
10137assert(Ops.size() == 7 &&"Incompatible number of operands");
10138
10139FoldingSetNodeIDID;
10140AddNodeIDNode(ID,ISD::EXPERIMENTAL_VECTOR_HISTOGRAM, VTs, Ops);
10141ID.AddInteger(MemVT.getRawBits());
10142ID.AddInteger(getSyntheticNodeSubclassData<MaskedHistogramSDNode>(
10143 dl.getIROrder(), VTs, MemVT, MMO, IndexType));
10144ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
10145ID.AddInteger(MMO->getFlags());
10146void *IP =nullptr;
10147if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP)) {
10148 cast<MaskedGatherSDNode>(E)->refineAlignment(MMO);
10149returnSDValue(E, 0);
10150 }
10151
10152auto *N = newSDNode<MaskedHistogramSDNode>(dl.getIROrder(), dl.getDebugLoc(),
10153 VTs, MemVT, MMO, IndexType);
10154 createOperands(N, Ops);
10155
10156assert(N->getMask().getValueType().getVectorElementCount() ==
10157N->getIndex().getValueType().getVectorElementCount() &&
10158"Vector width mismatch between mask and data");
10159assert(isa<ConstantSDNode>(N->getScale()) &&
10160N->getScale()->getAsAPIntVal().isPowerOf2() &&
10161"Scale should be a constant power of 2");
10162assert(N->getInc().getValueType().isInteger() &&"Non integer update value");
10163
10164 CSEMap.InsertNode(N, IP);
10165 InsertNode(N);
10166SDValue V(N, 0);
10167NewSDValueDbgMsg(V,"Creating new node: ",this);
10168return V;
10169}
10170
10171SDValueSelectionDAG::getGetFPEnv(SDValue Chain,constSDLoc &dl,SDValuePtr,
10172EVT MemVT,MachineMemOperand *MMO) {
10173assert(Chain.getValueType() == MVT::Other &&"Invalid chain type");
10174SDVTList VTs =getVTList(MVT::Other);
10175SDValue Ops[] = {Chain,Ptr};
10176FoldingSetNodeIDID;
10177AddNodeIDNode(ID,ISD::GET_FPENV_MEM, VTs, Ops);
10178ID.AddInteger(MemVT.getRawBits());
10179ID.AddInteger(getSyntheticNodeSubclassData<FPStateAccessSDNode>(
10180ISD::GET_FPENV_MEM, dl.getIROrder(), VTs, MemVT, MMO));
10181ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
10182ID.AddInteger(MMO->getFlags());
10183void *IP =nullptr;
10184if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP))
10185returnSDValue(E, 0);
10186
10187auto *N = newSDNode<FPStateAccessSDNode>(ISD::GET_FPENV_MEM, dl.getIROrder(),
10188 dl.getDebugLoc(), VTs, MemVT, MMO);
10189 createOperands(N, Ops);
10190
10191 CSEMap.InsertNode(N, IP);
10192 InsertNode(N);
10193SDValue V(N, 0);
10194NewSDValueDbgMsg(V,"Creating new node: ",this);
10195return V;
10196}
10197
10198SDValueSelectionDAG::getSetFPEnv(SDValue Chain,constSDLoc &dl,SDValuePtr,
10199EVT MemVT,MachineMemOperand *MMO) {
10200assert(Chain.getValueType() == MVT::Other &&"Invalid chain type");
10201SDVTList VTs =getVTList(MVT::Other);
10202SDValue Ops[] = {Chain,Ptr};
10203FoldingSetNodeIDID;
10204AddNodeIDNode(ID,ISD::SET_FPENV_MEM, VTs, Ops);
10205ID.AddInteger(MemVT.getRawBits());
10206ID.AddInteger(getSyntheticNodeSubclassData<FPStateAccessSDNode>(
10207ISD::SET_FPENV_MEM, dl.getIROrder(), VTs, MemVT, MMO));
10208ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
10209ID.AddInteger(MMO->getFlags());
10210void *IP =nullptr;
10211if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP))
10212returnSDValue(E, 0);
10213
10214auto *N = newSDNode<FPStateAccessSDNode>(ISD::SET_FPENV_MEM, dl.getIROrder(),
10215 dl.getDebugLoc(), VTs, MemVT, MMO);
10216 createOperands(N, Ops);
10217
10218 CSEMap.InsertNode(N, IP);
10219 InsertNode(N);
10220SDValue V(N, 0);
10221NewSDValueDbgMsg(V,"Creating new node: ",this);
10222return V;
10223}
10224
10225SDValueSelectionDAG::simplifySelect(SDValueCond,SDValueT,SDValueF) {
10226// select undef, T, F --> T (if T is a constant), otherwise F
10227// select, ?, undef, F --> F
10228// select, ?, T, undef --> T
10229if (Cond.isUndef())
10230returnisConstantValueOfAnyType(T) ?T :F;
10231if (T.isUndef())
10232returnF;
10233if (F.isUndef())
10234returnT;
10235
10236// select true, T, F --> T
10237// select false, T, F --> F
10238if (autoC =isBoolConstant(Cond,/*AllowTruncation=*/true))
10239return *C ?T :F;
10240
10241// select ?, T, T --> T
10242if (T ==F)
10243returnT;
10244
10245returnSDValue();
10246}
10247
10248SDValueSelectionDAG::simplifyShift(SDValueX,SDValueY) {
10249// shift undef, Y --> 0 (can always assume that the undef value is 0)
10250if (X.isUndef())
10251returngetConstant(0,SDLoc(X.getNode()),X.getValueType());
10252// shift X, undef --> undef (because it may shift by the bitwidth)
10253if (Y.isUndef())
10254returngetUNDEF(X.getValueType());
10255
10256// shift 0, Y --> 0
10257// shift X, 0 --> X
10258if (isNullOrNullSplat(X) ||isNullOrNullSplat(Y))
10259returnX;
10260
10261// shift X, C >= bitwidth(X) --> undef
10262// All vector elements must be too big (or undef) to avoid partial undefs.
10263auto isShiftTooBig = [X](ConstantSDNode *Val) {
10264return !Val || Val->getAPIntValue().uge(X.getScalarValueSizeInBits());
10265 };
10266if (ISD::matchUnaryPredicate(Y, isShiftTooBig,true))
10267returngetUNDEF(X.getValueType());
10268
10269// shift i1/vXi1 X, Y --> X (any non-zero shift amount is undefined).
10270if (X.getValueType().getScalarType() == MVT::i1)
10271returnX;
10272
10273returnSDValue();
10274}
10275
10276SDValueSelectionDAG::simplifyFPBinop(unsigned Opcode,SDValueX,SDValueY,
10277SDNodeFlags Flags) {
10278// If this operation has 'nnan' or 'ninf' and at least 1 disallowed operand
10279// (an undef operand can be chosen to be Nan/Inf), then the result of this
10280// operation is poison. That result can be relaxed to undef.
10281ConstantFPSDNode *XC =isConstOrConstSplatFP(X,/* AllowUndefs */true);
10282ConstantFPSDNode *YC =isConstOrConstSplatFP(Y,/* AllowUndefs */true);
10283bool HasNan = (XC && XC->getValueAPF().isNaN()) ||
10284 (YC && YC->getValueAPF().isNaN());
10285bool HasInf = (XC && XC->getValueAPF().isInfinity()) ||
10286 (YC && YC->getValueAPF().isInfinity());
10287
10288if (Flags.hasNoNaNs() && (HasNan ||X.isUndef() ||Y.isUndef()))
10289returngetUNDEF(X.getValueType());
10290
10291if (Flags.hasNoInfs() && (HasInf ||X.isUndef() ||Y.isUndef()))
10292returngetUNDEF(X.getValueType());
10293
10294if (!YC)
10295returnSDValue();
10296
10297// X + -0.0 --> X
10298if (Opcode ==ISD::FADD)
10299if (YC->getValueAPF().isNegZero())
10300returnX;
10301
10302// X - +0.0 --> X
10303if (Opcode ==ISD::FSUB)
10304if (YC->getValueAPF().isPosZero())
10305returnX;
10306
10307// X * 1.0 --> X
10308// X / 1.0 --> X
10309if (Opcode ==ISD::FMUL || Opcode ==ISD::FDIV)
10310if (YC->getValueAPF().isExactlyValue(1.0))
10311returnX;
10312
10313// X * 0.0 --> 0.0
10314if (Opcode ==ISD::FMUL && Flags.hasNoNaNs() && Flags.hasNoSignedZeros())
10315if (YC->getValueAPF().isZero())
10316returngetConstantFP(0.0,SDLoc(Y),Y.getValueType());
10317
10318returnSDValue();
10319}
10320
10321SDValueSelectionDAG::getVAArg(EVT VT,constSDLoc &dl,SDValue Chain,
10322SDValuePtr,SDValue SV,unsignedAlign) {
10323SDValue Ops[] = { Chain,Ptr, SV,getTargetConstant(Align, dl, MVT::i32) };
10324returngetNode(ISD::VAARG, dl,getVTList(VT, MVT::Other), Ops);
10325}
10326
10327SDValueSelectionDAG::getNode(unsigned Opcode,constSDLoc &DL,EVT VT,
10328ArrayRef<SDUse> Ops) {
10329switch (Ops.size()) {
10330case 0:returngetNode(Opcode,DL, VT);
10331case 1:returngetNode(Opcode,DL, VT,static_cast<constSDValue>(Ops[0]));
10332case 2:returngetNode(Opcode,DL, VT, Ops[0], Ops[1]);
10333case 3:returngetNode(Opcode,DL, VT, Ops[0], Ops[1], Ops[2]);
10334default:break;
10335 }
10336
10337// Copy from an SDUse array into an SDValue array for use with
10338// the regular getNode logic.
10339SmallVector<SDValue, 8> NewOps(Ops);
10340returngetNode(Opcode,DL, VT, NewOps);
10341}
10342
10343SDValueSelectionDAG::getNode(unsigned Opcode,constSDLoc &DL,EVT VT,
10344ArrayRef<SDValue> Ops) {
10345SDNodeFlags Flags;
10346if (Inserter)
10347 Flags = Inserter->getFlags();
10348returngetNode(Opcode,DL, VT, Ops, Flags);
10349}
10350
10351SDValueSelectionDAG::getNode(unsigned Opcode,constSDLoc &DL,EVT VT,
10352ArrayRef<SDValue> Ops,constSDNodeFlags Flags) {
10353unsigned NumOps = Ops.size();
10354switch (NumOps) {
10355case 0:returngetNode(Opcode,DL, VT);
10356case 1:returngetNode(Opcode,DL, VT, Ops[0], Flags);
10357case 2:returngetNode(Opcode,DL, VT, Ops[0], Ops[1], Flags);
10358case 3:returngetNode(Opcode,DL, VT, Ops[0], Ops[1], Ops[2], Flags);
10359default:break;
10360 }
10361
10362#ifndef NDEBUG
10363for (constauto &Op : Ops)
10364assert(Op.getOpcode() !=ISD::DELETED_NODE &&
10365"Operand is DELETED_NODE!");
10366#endif
10367
10368switch (Opcode) {
10369default:break;
10370caseISD::BUILD_VECTOR:
10371// Attempt to simplify BUILD_VECTOR.
10372if (SDValue V =FoldBUILD_VECTOR(DL, VT, Ops, *this))
10373return V;
10374break;
10375caseISD::CONCAT_VECTORS:
10376if (SDValue V =foldCONCAT_VECTORS(DL, VT, Ops, *this))
10377return V;
10378break;
10379caseISD::SELECT_CC:
10380assert(NumOps == 5 &&"SELECT_CC takes 5 operands!");
10381assert(Ops[0].getValueType() == Ops[1].getValueType() &&
10382"LHS and RHS of condition must have same type!");
10383assert(Ops[2].getValueType() == Ops[3].getValueType() &&
10384"True and False arms of SelectCC must have same type!");
10385assert(Ops[2].getValueType() == VT &&
10386"select_cc node must be of same type as true and false value!");
10387assert((!Ops[0].getValueType().isVector() ||
10388 Ops[0].getValueType().getVectorElementCount() ==
10389 VT.getVectorElementCount()) &&
10390"Expected select_cc with vector result to have the same sized "
10391"comparison type!");
10392break;
10393caseISD::BR_CC:
10394assert(NumOps == 5 &&"BR_CC takes 5 operands!");
10395assert(Ops[2].getValueType() == Ops[3].getValueType() &&
10396"LHS/RHS of comparison should match types!");
10397break;
10398case ISD::VP_ADD:
10399case ISD::VP_SUB:
10400// If it is VP_ADD/VP_SUB mask operation then turn it to VP_XOR
10401if (VT.isVector() && VT.getVectorElementType() == MVT::i1)
10402 Opcode = ISD::VP_XOR;
10403break;
10404case ISD::VP_MUL:
10405// If it is VP_MUL mask operation then turn it to VP_AND
10406if (VT.isVector() && VT.getVectorElementType() == MVT::i1)
10407 Opcode = ISD::VP_AND;
10408break;
10409case ISD::VP_REDUCE_MUL:
10410// If it is VP_REDUCE_MUL mask operation then turn it to VP_REDUCE_AND
10411if (VT == MVT::i1)
10412 Opcode = ISD::VP_REDUCE_AND;
10413break;
10414case ISD::VP_REDUCE_ADD:
10415// If it is VP_REDUCE_ADD mask operation then turn it to VP_REDUCE_XOR
10416if (VT == MVT::i1)
10417 Opcode = ISD::VP_REDUCE_XOR;
10418break;
10419case ISD::VP_REDUCE_SMAX:
10420case ISD::VP_REDUCE_UMIN:
10421// If it is VP_REDUCE_SMAX/VP_REDUCE_UMIN mask operation then turn it to
10422// VP_REDUCE_AND.
10423if (VT == MVT::i1)
10424 Opcode = ISD::VP_REDUCE_AND;
10425break;
10426case ISD::VP_REDUCE_SMIN:
10427case ISD::VP_REDUCE_UMAX:
10428// If it is VP_REDUCE_SMIN/VP_REDUCE_UMAX mask operation then turn it to
10429// VP_REDUCE_OR.
10430if (VT == MVT::i1)
10431 Opcode = ISD::VP_REDUCE_OR;
10432break;
10433 }
10434
10435// Memoize nodes.
10436SDNode *N;
10437SDVTList VTs =getVTList(VT);
10438
10439if (VT != MVT::Glue) {
10440FoldingSetNodeIDID;
10441AddNodeIDNode(ID, Opcode, VTs, Ops);
10442void *IP =nullptr;
10443
10444if (SDNode *E = FindNodeOrInsertPos(ID,DL, IP)) {
10445 E->intersectFlagsWith(Flags);
10446returnSDValue(E, 0);
10447 }
10448
10449N = newSDNode<SDNode>(Opcode,DL.getIROrder(),DL.getDebugLoc(), VTs);
10450 createOperands(N, Ops);
10451
10452 CSEMap.InsertNode(N, IP);
10453 }else {
10454N = newSDNode<SDNode>(Opcode,DL.getIROrder(),DL.getDebugLoc(), VTs);
10455 createOperands(N, Ops);
10456 }
10457
10458N->setFlags(Flags);
10459 InsertNode(N);
10460SDValue V(N, 0);
10461NewSDValueDbgMsg(V,"Creating new node: ",this);
10462return V;
10463}
10464
10465SDValueSelectionDAG::getNode(unsigned Opcode,constSDLoc &DL,
10466ArrayRef<EVT> ResultTys,ArrayRef<SDValue> Ops) {
10467returngetNode(Opcode,DL,getVTList(ResultTys), Ops);
10468}
10469
10470SDValueSelectionDAG::getNode(unsigned Opcode,constSDLoc &DL,SDVTList VTList,
10471ArrayRef<SDValue> Ops) {
10472SDNodeFlags Flags;
10473if (Inserter)
10474 Flags = Inserter->getFlags();
10475returngetNode(Opcode,DL, VTList, Ops, Flags);
10476}
10477
10478SDValueSelectionDAG::getNode(unsigned Opcode,constSDLoc &DL,SDVTList VTList,
10479ArrayRef<SDValue> Ops,constSDNodeFlags Flags) {
10480if (VTList.NumVTs == 1)
10481returngetNode(Opcode,DL, VTList.VTs[0], Ops, Flags);
10482
10483#ifndef NDEBUG
10484for (constauto &Op : Ops)
10485assert(Op.getOpcode() !=ISD::DELETED_NODE &&
10486"Operand is DELETED_NODE!");
10487#endif
10488
10489switch (Opcode) {
10490caseISD::SADDO:
10491caseISD::UADDO:
10492caseISD::SSUBO:
10493caseISD::USUBO: {
10494assert(VTList.NumVTs == 2 && Ops.size() == 2 &&
10495"Invalid add/sub overflow op!");
10496assert(VTList.VTs[0].isInteger() && VTList.VTs[1].isInteger() &&
10497 Ops[0].getValueType() == Ops[1].getValueType() &&
10498 Ops[0].getValueType() == VTList.VTs[0] &&
10499"Binary operator types must match!");
10500SDValue N1 = Ops[0], N2 = Ops[1];
10501canonicalizeCommutativeBinop(Opcode, N1, N2);
10502
10503// (X +- 0) -> X with zero-overflow.
10504ConstantSDNode *N2CV =isConstOrConstSplat(N2,/*AllowUndefs*/false,
10505/*AllowTruncation*/true);
10506if (N2CV && N2CV->isZero()) {
10507SDValue ZeroOverFlow =getConstant(0,DL, VTList.VTs[1]);
10508returngetNode(ISD::MERGE_VALUES,DL, VTList, {N1, ZeroOverFlow}, Flags);
10509 }
10510
10511if (VTList.VTs[0].isVector() &&
10512 VTList.VTs[0].getVectorElementType() == MVT::i1 &&
10513 VTList.VTs[1].getVectorElementType() == MVT::i1) {
10514SDValue F1 =getFreeze(N1);
10515SDValue F2 =getFreeze(N2);
10516// {vXi1,vXi1} (u/s)addo(vXi1 x, vXi1y) -> {xor(x,y),and(x,y)}
10517if (Opcode ==ISD::UADDO || Opcode ==ISD::SADDO)
10518returngetNode(ISD::MERGE_VALUES,DL, VTList,
10519 {getNode(ISD::XOR,DL, VTList.VTs[0], F1, F2),
10520getNode(ISD::AND,DL, VTList.VTs[1], F1, F2)},
10521 Flags);
10522// {vXi1,vXi1} (u/s)subo(vXi1 x, vXi1y) -> {xor(x,y),and(~x,y)}
10523if (Opcode ==ISD::USUBO || Opcode ==ISD::SSUBO) {
10524SDValue NotF1 =getNOT(DL, F1, VTList.VTs[0]);
10525returngetNode(ISD::MERGE_VALUES,DL, VTList,
10526 {getNode(ISD::XOR,DL, VTList.VTs[0], F1, F2),
10527getNode(ISD::AND,DL, VTList.VTs[1], NotF1, F2)},
10528 Flags);
10529 }
10530 }
10531break;
10532 }
10533caseISD::SADDO_CARRY:
10534caseISD::UADDO_CARRY:
10535caseISD::SSUBO_CARRY:
10536caseISD::USUBO_CARRY:
10537assert(VTList.NumVTs == 2 && Ops.size() == 3 &&
10538"Invalid add/sub overflow op!");
10539assert(VTList.VTs[0].isInteger() && VTList.VTs[1].isInteger() &&
10540 Ops[0].getValueType() == Ops[1].getValueType() &&
10541 Ops[0].getValueType() == VTList.VTs[0] &&
10542 Ops[2].getValueType() == VTList.VTs[1] &&
10543"Binary operator types must match!");
10544break;
10545caseISD::SMUL_LOHI:
10546caseISD::UMUL_LOHI: {
10547assert(VTList.NumVTs == 2 && Ops.size() == 2 &&"Invalid mul lo/hi op!");
10548assert(VTList.VTs[0].isInteger() && VTList.VTs[0] == VTList.VTs[1] &&
10549 VTList.VTs[0] == Ops[0].getValueType() &&
10550 VTList.VTs[0] == Ops[1].getValueType() &&
10551"Binary operator types must match!");
10552// Constant fold.
10553ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(Ops[0]);
10554ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ops[1]);
10555if (LHS &&RHS) {
10556unsigned Width = VTList.VTs[0].getScalarSizeInBits();
10557unsigned OutWidth = Width * 2;
10558APInt Val =LHS->getAPIntValue();
10559APIntMul =RHS->getAPIntValue();
10560if (Opcode ==ISD::SMUL_LOHI) {
10561 Val = Val.sext(OutWidth);
10562Mul =Mul.sext(OutWidth);
10563 }else {
10564 Val = Val.zext(OutWidth);
10565Mul =Mul.zext(OutWidth);
10566 }
10567 Val *=Mul;
10568
10569SDValueHi =
10570getConstant(Val.extractBits(Width, Width),DL, VTList.VTs[0]);
10571SDValueLo =getConstant(Val.trunc(Width),DL, VTList.VTs[0]);
10572returngetNode(ISD::MERGE_VALUES,DL, VTList, {Lo,Hi}, Flags);
10573 }
10574break;
10575 }
10576caseISD::FFREXP: {
10577assert(VTList.NumVTs == 2 && Ops.size() == 1 &&"Invalid ffrexp op!");
10578assert(VTList.VTs[0].isFloatingPoint() && VTList.VTs[1].isInteger() &&
10579 VTList.VTs[0] == Ops[0].getValueType() &&"frexp type mismatch");
10580
10581if (constConstantFPSDNode *C = dyn_cast<ConstantFPSDNode>(Ops[0])) {
10582int FrexpExp;
10583APFloat FrexpMant =
10584frexp(C->getValueAPF(), FrexpExp,APFloat::rmNearestTiesToEven);
10585SDValue Result0 =getConstantFP(FrexpMant,DL, VTList.VTs[0]);
10586SDValue Result1 =
10587getConstant(FrexpMant.isFinite() ? FrexpExp : 0,DL, VTList.VTs[1]);
10588returngetNode(ISD::MERGE_VALUES,DL, VTList, {Result0, Result1}, Flags);
10589 }
10590
10591break;
10592 }
10593caseISD::STRICT_FP_EXTEND:
10594assert(VTList.NumVTs == 2 && Ops.size() == 2 &&
10595"Invalid STRICT_FP_EXTEND!");
10596assert(VTList.VTs[0].isFloatingPoint() &&
10597 Ops[1].getValueType().isFloatingPoint() &&"Invalid FP cast!");
10598assert(VTList.VTs[0].isVector() == Ops[1].getValueType().isVector() &&
10599"STRICT_FP_EXTEND result type should be vector iff the operand "
10600"type is vector!");
10601assert((!VTList.VTs[0].isVector() ||
10602 VTList.VTs[0].getVectorElementCount() ==
10603 Ops[1].getValueType().getVectorElementCount()) &&
10604"Vector element count mismatch!");
10605assert(Ops[1].getValueType().bitsLT(VTList.VTs[0]) &&
10606"Invalid fpext node, dst <= src!");
10607break;
10608caseISD::STRICT_FP_ROUND:
10609assert(VTList.NumVTs == 2 && Ops.size() == 3 &&"Invalid STRICT_FP_ROUND!");
10610assert(VTList.VTs[0].isVector() == Ops[1].getValueType().isVector() &&
10611"STRICT_FP_ROUND result type should be vector iff the operand "
10612"type is vector!");
10613assert((!VTList.VTs[0].isVector() ||
10614 VTList.VTs[0].getVectorElementCount() ==
10615 Ops[1].getValueType().getVectorElementCount()) &&
10616"Vector element count mismatch!");
10617assert(VTList.VTs[0].isFloatingPoint() &&
10618 Ops[1].getValueType().isFloatingPoint() &&
10619 VTList.VTs[0].bitsLT(Ops[1].getValueType()) &&
10620 Ops[2].getOpcode() ==ISD::TargetConstant &&
10621 (Ops[2]->getAsZExtVal() == 0 || Ops[2]->getAsZExtVal() == 1) &&
10622"Invalid STRICT_FP_ROUND!");
10623break;
10624#if 0
10625// FIXME: figure out how to safely handle things like
10626// int foo(int x) { return 1 << (x & 255); }
10627// int bar() { return foo(256); }
10628caseISD::SRA_PARTS:
10629caseISD::SRL_PARTS:
10630caseISD::SHL_PARTS:
10631if (N3.getOpcode() ==ISD::SIGN_EXTEND_INREG &&
10632 cast<VTSDNode>(N3.getOperand(1))->getVT() != MVT::i1)
10633returngetNode(Opcode,DL, VT, N1, N2, N3.getOperand(0));
10634elseif (N3.getOpcode() ==ISD::AND)
10635if (ConstantSDNode *AndRHS = dyn_cast<ConstantSDNode>(N3.getOperand(1))) {
10636// If the and is only masking out bits that cannot effect the shift,
10637// eliminate the and.
10638unsigned NumBits = VT.getScalarSizeInBits()*2;
10639if ((AndRHS->getValue() & (NumBits-1)) == NumBits-1)
10640returngetNode(Opcode,DL, VT, N1, N2, N3.getOperand(0));
10641 }
10642break;
10643#endif
10644 }
10645
10646// Memoize the node unless it returns a glue result.
10647SDNode *N;
10648if (VTList.VTs[VTList.NumVTs-1] != MVT::Glue) {
10649FoldingSetNodeIDID;
10650AddNodeIDNode(ID, Opcode, VTList, Ops);
10651void *IP =nullptr;
10652if (SDNode *E = FindNodeOrInsertPos(ID,DL, IP)) {
10653 E->intersectFlagsWith(Flags);
10654returnSDValue(E, 0);
10655 }
10656
10657N = newSDNode<SDNode>(Opcode,DL.getIROrder(),DL.getDebugLoc(), VTList);
10658 createOperands(N, Ops);
10659 CSEMap.InsertNode(N, IP);
10660 }else {
10661N = newSDNode<SDNode>(Opcode,DL.getIROrder(),DL.getDebugLoc(), VTList);
10662 createOperands(N, Ops);
10663 }
10664
10665N->setFlags(Flags);
10666 InsertNode(N);
10667SDValue V(N, 0);
10668NewSDValueDbgMsg(V,"Creating new node: ",this);
10669return V;
10670}
10671
10672SDValueSelectionDAG::getNode(unsigned Opcode,constSDLoc &DL,
10673SDVTList VTList) {
10674returngetNode(Opcode,DL, VTList,ArrayRef<SDValue>());
10675}
10676
10677SDValueSelectionDAG::getNode(unsigned Opcode,constSDLoc &DL,SDVTList VTList,
10678SDValue N1) {
10679SDValue Ops[] = { N1 };
10680returngetNode(Opcode,DL, VTList, Ops);
10681}
10682
10683SDValueSelectionDAG::getNode(unsigned Opcode,constSDLoc &DL,SDVTList VTList,
10684SDValue N1,SDValue N2) {
10685SDValue Ops[] = { N1, N2 };
10686returngetNode(Opcode,DL, VTList, Ops);
10687}
10688
10689SDValueSelectionDAG::getNode(unsigned Opcode,constSDLoc &DL,SDVTList VTList,
10690SDValue N1,SDValue N2,SDValue N3) {
10691SDValue Ops[] = { N1, N2, N3 };
10692returngetNode(Opcode,DL, VTList, Ops);
10693}
10694
10695SDValueSelectionDAG::getNode(unsigned Opcode,constSDLoc &DL,SDVTList VTList,
10696SDValue N1,SDValue N2,SDValue N3,SDValue N4) {
10697SDValue Ops[] = { N1, N2, N3, N4 };
10698returngetNode(Opcode,DL, VTList, Ops);
10699}
10700
10701SDValueSelectionDAG::getNode(unsigned Opcode,constSDLoc &DL,SDVTList VTList,
10702SDValue N1,SDValue N2,SDValue N3,SDValue N4,
10703SDValue N5) {
10704SDValue Ops[] = { N1, N2, N3, N4, N5 };
10705returngetNode(Opcode,DL, VTList, Ops);
10706}
10707
10708SDVTListSelectionDAG::getVTList(EVT VT) {
10709if (!VT.isExtended())
10710returnmakeVTList(SDNode::getValueTypeList(VT.getSimpleVT()), 1);
10711
10712returnmakeVTList(&(*EVTs.insert(VT).first), 1);
10713}
10714
10715SDVTListSelectionDAG::getVTList(EVT VT1,EVT VT2) {
10716FoldingSetNodeIDID;
10717ID.AddInteger(2U);
10718ID.AddInteger(VT1.getRawBits());
10719ID.AddInteger(VT2.getRawBits());
10720
10721void *IP =nullptr;
10722SDVTListNode *Result = VTListMap.FindNodeOrInsertPos(ID, IP);
10723if (!Result) {
10724EVT *Array = Allocator.Allocate<EVT>(2);
10725 Array[0] = VT1;
10726 Array[1] = VT2;
10727 Result =new (Allocator)SDVTListNode(ID.Intern(Allocator), Array, 2);
10728 VTListMap.InsertNode(Result, IP);
10729 }
10730return Result->getSDVTList();
10731}
10732
10733SDVTListSelectionDAG::getVTList(EVT VT1,EVT VT2,EVT VT3) {
10734FoldingSetNodeIDID;
10735ID.AddInteger(3U);
10736ID.AddInteger(VT1.getRawBits());
10737ID.AddInteger(VT2.getRawBits());
10738ID.AddInteger(VT3.getRawBits());
10739
10740void *IP =nullptr;
10741SDVTListNode *Result = VTListMap.FindNodeOrInsertPos(ID, IP);
10742if (!Result) {
10743EVT *Array = Allocator.Allocate<EVT>(3);
10744 Array[0] = VT1;
10745 Array[1] = VT2;
10746 Array[2] = VT3;
10747 Result =new (Allocator)SDVTListNode(ID.Intern(Allocator), Array, 3);
10748 VTListMap.InsertNode(Result, IP);
10749 }
10750return Result->getSDVTList();
10751}
10752
10753SDVTListSelectionDAG::getVTList(EVT VT1,EVT VT2,EVT VT3,EVT VT4) {
10754FoldingSetNodeIDID;
10755ID.AddInteger(4U);
10756ID.AddInteger(VT1.getRawBits());
10757ID.AddInteger(VT2.getRawBits());
10758ID.AddInteger(VT3.getRawBits());
10759ID.AddInteger(VT4.getRawBits());
10760
10761void *IP =nullptr;
10762SDVTListNode *Result = VTListMap.FindNodeOrInsertPos(ID, IP);
10763if (!Result) {
10764EVT *Array = Allocator.Allocate<EVT>(4);
10765 Array[0] = VT1;
10766 Array[1] = VT2;
10767 Array[2] = VT3;
10768 Array[3] = VT4;
10769 Result =new (Allocator)SDVTListNode(ID.Intern(Allocator), Array, 4);
10770 VTListMap.InsertNode(Result, IP);
10771 }
10772return Result->getSDVTList();
10773}
10774
10775SDVTListSelectionDAG::getVTList(ArrayRef<EVT> VTs) {
10776unsigned NumVTs = VTs.size();
10777FoldingSetNodeIDID;
10778ID.AddInteger(NumVTs);
10779for (unsigned index = 0; index < NumVTs; index++) {
10780ID.AddInteger(VTs[index].getRawBits());
10781 }
10782
10783void *IP =nullptr;
10784SDVTListNode *Result = VTListMap.FindNodeOrInsertPos(ID, IP);
10785if (!Result) {
10786EVT *Array = Allocator.Allocate<EVT>(NumVTs);
10787llvm::copy(VTs, Array);
10788 Result =new (Allocator)SDVTListNode(ID.Intern(Allocator), Array, NumVTs);
10789 VTListMap.InsertNode(Result, IP);
10790 }
10791return Result->getSDVTList();
10792}
10793
10794
10795/// UpdateNodeOperands - *Mutate* the specified node in-place to have the
10796/// specified operands. If the resultant node already exists in the DAG,
10797/// this does not modify the specified node, instead it returns the node that
10798/// already exists. If the resultant node does not exist in the DAG, the
10799/// input node is returned. As a degenerate case, if you specify the same
10800/// input operands as the node already has, the input node is returned.
10801SDNode *SelectionDAG::UpdateNodeOperands(SDNode *N,SDValueOp) {
10802assert(N->getNumOperands() == 1 &&"Update with wrong number of operands");
10803
10804// Check to see if there is no change.
10805if (Op ==N->getOperand(0))returnN;
10806
10807// See if the modified node already exists.
10808void *InsertPos =nullptr;
10809if (SDNode *Existing = FindModifiedNodeSlot(N,Op, InsertPos))
10810return Existing;
10811
10812// Nope it doesn't. Remove the node from its current place in the maps.
10813if (InsertPos)
10814if (!RemoveNodeFromCSEMaps(N))
10815 InsertPos =nullptr;
10816
10817// Now we update the operands.
10818N->OperandList[0].set(Op);
10819
10820updateDivergence(N);
10821// If this gets put into a CSE map, add it.
10822if (InsertPos) CSEMap.InsertNode(N, InsertPos);
10823returnN;
10824}
10825
10826SDNode *SelectionDAG::UpdateNodeOperands(SDNode *N,SDValue Op1,SDValue Op2) {
10827assert(N->getNumOperands() == 2 &&"Update with wrong number of operands");
10828
10829// Check to see if there is no change.
10830if (Op1 ==N->getOperand(0) && Op2 ==N->getOperand(1))
10831returnN;// No operands changed, just return the input node.
10832
10833// See if the modified node already exists.
10834void *InsertPos =nullptr;
10835if (SDNode *Existing = FindModifiedNodeSlot(N, Op1, Op2, InsertPos))
10836return Existing;
10837
10838// Nope it doesn't. Remove the node from its current place in the maps.
10839if (InsertPos)
10840if (!RemoveNodeFromCSEMaps(N))
10841 InsertPos =nullptr;
10842
10843// Now we update the operands.
10844if (N->OperandList[0] != Op1)
10845N->OperandList[0].set(Op1);
10846if (N->OperandList[1] != Op2)
10847N->OperandList[1].set(Op2);
10848
10849updateDivergence(N);
10850// If this gets put into a CSE map, add it.
10851if (InsertPos) CSEMap.InsertNode(N, InsertPos);
10852returnN;
10853}
10854
10855SDNode *SelectionDAG::
10856UpdateNodeOperands(SDNode *N,SDValue Op1,SDValue Op2,SDValue Op3) {
10857SDValue Ops[] = { Op1, Op2, Op3 };
10858returnUpdateNodeOperands(N, Ops);
10859}
10860
10861SDNode *SelectionDAG::
10862UpdateNodeOperands(SDNode *N,SDValue Op1,SDValue Op2,
10863SDValue Op3,SDValue Op4) {
10864SDValue Ops[] = { Op1, Op2, Op3, Op4 };
10865returnUpdateNodeOperands(N, Ops);
10866}
10867
10868SDNode *SelectionDAG::
10869UpdateNodeOperands(SDNode *N,SDValue Op1,SDValue Op2,
10870SDValue Op3,SDValue Op4,SDValue Op5) {
10871SDValue Ops[] = { Op1, Op2, Op3, Op4, Op5 };
10872returnUpdateNodeOperands(N, Ops);
10873}
10874
10875SDNode *SelectionDAG::
10876UpdateNodeOperands(SDNode *N,ArrayRef<SDValue> Ops) {
10877unsigned NumOps = Ops.size();
10878assert(N->getNumOperands() == NumOps &&
10879"Update with wrong number of operands");
10880
10881// If no operands changed just return the input node.
10882if (std::equal(Ops.begin(), Ops.end(),N->op_begin()))
10883returnN;
10884
10885// See if the modified node already exists.
10886void *InsertPos =nullptr;
10887if (SDNode *Existing = FindModifiedNodeSlot(N, Ops, InsertPos))
10888return Existing;
10889
10890// Nope it doesn't. Remove the node from its current place in the maps.
10891if (InsertPos)
10892if (!RemoveNodeFromCSEMaps(N))
10893 InsertPos =nullptr;
10894
10895// Now we update the operands.
10896for (unsigned i = 0; i != NumOps; ++i)
10897if (N->OperandList[i] != Ops[i])
10898N->OperandList[i].set(Ops[i]);
10899
10900updateDivergence(N);
10901// If this gets put into a CSE map, add it.
10902if (InsertPos) CSEMap.InsertNode(N, InsertPos);
10903returnN;
10904}
10905
10906/// DropOperands - Release the operands and set this node to have
10907/// zero operands.
10908voidSDNode::DropOperands() {
10909// Unlike the code in MorphNodeTo that does this, we don't need to
10910// watch for dead nodes here.
10911for (op_iteratorI =op_begin(), E =op_end();I != E; ) {
10912SDUse &Use = *I++;
10913Use.set(SDValue());
10914 }
10915}
10916
10917voidSelectionDAG::setNodeMemRefs(MachineSDNode *N,
10918ArrayRef<MachineMemOperand *> NewMemRefs) {
10919if (NewMemRefs.empty()) {
10920N->clearMemRefs();
10921return;
10922 }
10923
10924// Check if we can avoid allocating by storing a single reference directly.
10925if (NewMemRefs.size() == 1) {
10926N->MemRefs = NewMemRefs[0];
10927N->NumMemRefs = 1;
10928return;
10929 }
10930
10931MachineMemOperand **MemRefsBuffer =
10932 Allocator.template Allocate<MachineMemOperand *>(NewMemRefs.size());
10933llvm::copy(NewMemRefs, MemRefsBuffer);
10934N->MemRefs = MemRefsBuffer;
10935N->NumMemRefs =static_cast<int>(NewMemRefs.size());
10936}
10937
10938/// SelectNodeTo - These are wrappers around MorphNodeTo that accept a
10939/// machine opcode.
10940///
10941SDNode *SelectionDAG::SelectNodeTo(SDNode *N,unsigned MachineOpc,
10942EVT VT) {
10943SDVTList VTs =getVTList(VT);
10944returnSelectNodeTo(N, MachineOpc, VTs, {});
10945}
10946
10947SDNode *SelectionDAG::SelectNodeTo(SDNode *N,unsigned MachineOpc,
10948EVT VT,SDValue Op1) {
10949SDVTList VTs =getVTList(VT);
10950SDValue Ops[] = { Op1 };
10951returnSelectNodeTo(N, MachineOpc, VTs, Ops);
10952}
10953
10954SDNode *SelectionDAG::SelectNodeTo(SDNode *N,unsigned MachineOpc,
10955EVT VT,SDValue Op1,
10956SDValue Op2) {
10957SDVTList VTs =getVTList(VT);
10958SDValue Ops[] = { Op1, Op2 };
10959returnSelectNodeTo(N, MachineOpc, VTs, Ops);
10960}
10961
10962SDNode *SelectionDAG::SelectNodeTo(SDNode *N,unsigned MachineOpc,
10963EVT VT,SDValue Op1,
10964SDValue Op2,SDValue Op3) {
10965SDVTList VTs =getVTList(VT);
10966SDValue Ops[] = { Op1, Op2, Op3 };
10967returnSelectNodeTo(N, MachineOpc, VTs, Ops);
10968}
10969
10970SDNode *SelectionDAG::SelectNodeTo(SDNode *N,unsigned MachineOpc,
10971EVT VT,ArrayRef<SDValue> Ops) {
10972SDVTList VTs =getVTList(VT);
10973returnSelectNodeTo(N, MachineOpc, VTs, Ops);
10974}
10975
10976SDNode *SelectionDAG::SelectNodeTo(SDNode *N,unsigned MachineOpc,
10977EVT VT1,EVT VT2,ArrayRef<SDValue> Ops) {
10978SDVTList VTs =getVTList(VT1, VT2);
10979returnSelectNodeTo(N, MachineOpc, VTs, Ops);
10980}
10981
10982SDNode *SelectionDAG::SelectNodeTo(SDNode *N,unsigned MachineOpc,
10983EVT VT1,EVT VT2) {
10984SDVTList VTs =getVTList(VT1, VT2);
10985returnSelectNodeTo(N, MachineOpc, VTs, {});
10986}
10987
10988SDNode *SelectionDAG::SelectNodeTo(SDNode *N,unsigned MachineOpc,
10989EVT VT1,EVT VT2,EVT VT3,
10990ArrayRef<SDValue> Ops) {
10991SDVTList VTs =getVTList(VT1, VT2, VT3);
10992returnSelectNodeTo(N, MachineOpc, VTs, Ops);
10993}
10994
10995SDNode *SelectionDAG::SelectNodeTo(SDNode *N,unsigned MachineOpc,
10996EVT VT1,EVT VT2,
10997SDValue Op1,SDValue Op2) {
10998SDVTList VTs =getVTList(VT1, VT2);
10999SDValue Ops[] = { Op1, Op2 };
11000returnSelectNodeTo(N, MachineOpc, VTs, Ops);
11001}
11002
11003SDNode *SelectionDAG::SelectNodeTo(SDNode *N,unsigned MachineOpc,
11004SDVTList VTs,ArrayRef<SDValue> Ops) {
11005SDNode *New =MorphNodeTo(N, ~MachineOpc, VTs, Ops);
11006// Reset the NodeID to -1.
11007 New->setNodeId(-1);
11008if (New !=N) {
11009ReplaceAllUsesWith(N, New);
11010RemoveDeadNode(N);
11011 }
11012return New;
11013}
11014
11015/// UpdateSDLocOnMergeSDNode - If the opt level is -O0 then it throws away
11016/// the line number information on the merged node since it is not possible to
11017/// preserve the information that operation is associated with multiple lines.
11018/// This will make the debugger working better at -O0, were there is a higher
11019/// probability having other instructions associated with that line.
11020///
11021/// For IROrder, we keep the smaller of the two
11022SDNode *SelectionDAG::UpdateSDLocOnMergeSDNode(SDNode *N,constSDLoc &OLoc) {
11023DebugLoc NLoc =N->getDebugLoc();
11024if (NLoc && OptLevel ==CodeGenOptLevel::None && OLoc.getDebugLoc() != NLoc) {
11025N->setDebugLoc(DebugLoc());
11026 }
11027unsigned Order = std::min(N->getIROrder(), OLoc.getIROrder());
11028N->setIROrder(Order);
11029returnN;
11030}
11031
11032/// MorphNodeTo - This *mutates* the specified node to have the specified
11033/// return type, opcode, and operands.
11034///
11035/// Note that MorphNodeTo returns the resultant node. If there is already a
11036/// node of the specified opcode and operands, it returns that node instead of
11037/// the current one. Note that the SDLoc need not be the same.
11038///
11039/// Using MorphNodeTo is faster than creating a new node and swapping it in
11040/// with ReplaceAllUsesWith both because it often avoids allocating a new
11041/// node, and because it doesn't require CSE recalculation for any of
11042/// the node's users.
11043///
11044/// However, note that MorphNodeTo recursively deletes dead nodes from the DAG.
11045/// As a consequence it isn't appropriate to use from within the DAG combiner or
11046/// the legalizer which maintain worklists that would need to be updated when
11047/// deleting things.
11048SDNode *SelectionDAG::MorphNodeTo(SDNode *N,unsigned Opc,
11049SDVTList VTs,ArrayRef<SDValue> Ops) {
11050// If an identical node already exists, use it.
11051void *IP =nullptr;
11052if (VTs.VTs[VTs.NumVTs-1] != MVT::Glue) {
11053FoldingSetNodeIDID;
11054AddNodeIDNode(ID, Opc, VTs, Ops);
11055if (SDNode *ON = FindNodeOrInsertPos(ID,SDLoc(N), IP))
11056return UpdateSDLocOnMergeSDNode(ON,SDLoc(N));
11057 }
11058
11059if (!RemoveNodeFromCSEMaps(N))
11060 IP =nullptr;
11061
11062// Start the morphing.
11063N->NodeType = Opc;
11064N->ValueList = VTs.VTs;
11065N->NumValues = VTs.NumVTs;
11066
11067// Clear the operands list, updating used nodes to remove this from their
11068// use list. Keep track of any operands that become dead as a result.
11069SmallPtrSet<SDNode*, 16> DeadNodeSet;
11070for (SDNode::op_iteratorI =N->op_begin(), E =N->op_end();I != E; ) {
11071SDUse &Use = *I++;
11072SDNode *Used =Use.getNode();
11073Use.set(SDValue());
11074if (Used->use_empty())
11075 DeadNodeSet.insert(Used);
11076 }
11077
11078// For MachineNode, initialize the memory references information.
11079if (MachineSDNode *MN = dyn_cast<MachineSDNode>(N))
11080 MN->clearMemRefs();
11081
11082// Swap for an appropriately sized array from the recycler.
11083 removeOperands(N);
11084 createOperands(N, Ops);
11085
11086// Delete any nodes that are still dead after adding the uses for the
11087// new operands.
11088if (!DeadNodeSet.empty()) {
11089SmallVector<SDNode *, 16> DeadNodes;
11090for (SDNode *N : DeadNodeSet)
11091if (N->use_empty())
11092 DeadNodes.push_back(N);
11093RemoveDeadNodes(DeadNodes);
11094 }
11095
11096if (IP)
11097 CSEMap.InsertNode(N, IP);// Memoize the new node.
11098returnN;
11099}
11100
11101SDNode*SelectionDAG::mutateStrictFPToFP(SDNode *Node) {
11102unsigned OrigOpc = Node->getOpcode();
11103unsigned NewOpc;
11104switch (OrigOpc) {
11105default:
11106llvm_unreachable("mutateStrictFPToFP called with unexpected opcode!");
11107#define DAG_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN) \
11108 case ISD::STRICT_##DAGN: NewOpc = ISD::DAGN; break;
11109#define CMP_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN) \
11110 case ISD::STRICT_##DAGN: NewOpc = ISD::SETCC; break;
11111#include "llvm/IR/ConstrainedOps.def"
11112 }
11113
11114assert(Node->getNumValues() == 2 &&"Unexpected number of results!");
11115
11116// We're taking this node out of the chain, so we need to re-link things.
11117SDValue InputChain = Node->getOperand(0);
11118SDValue OutputChain =SDValue(Node, 1);
11119ReplaceAllUsesOfValueWith(OutputChain, InputChain);
11120
11121SmallVector<SDValue, 3> Ops;
11122for (unsigned i = 1, e = Node->getNumOperands(); i != e; ++i)
11123 Ops.push_back(Node->getOperand(i));
11124
11125SDVTList VTs =getVTList(Node->getValueType(0));
11126SDNode *Res =MorphNodeTo(Node, NewOpc, VTs, Ops);
11127
11128// MorphNodeTo can operate in two ways: if an existing node with the
11129// specified operands exists, it can just return it. Otherwise, it
11130// updates the node in place to have the requested operands.
11131if (Res == Node) {
11132// If we updated the node in place, reset the node ID. To the isel,
11133// this should be just like a newly allocated machine node.
11134 Res->setNodeId(-1);
11135 }else {
11136ReplaceAllUsesWith(Node, Res);
11137RemoveDeadNode(Node);
11138 }
11139
11140return Res;
11141}
11142
11143/// getMachineNode - These are used for target selectors to create a new node
11144/// with specified return type(s), MachineInstr opcode, and operands.
11145///
11146/// Note that getMachineNode returns the resultant node. If there is already a
11147/// node of the specified opcode and operands, it returns that node instead of
11148/// the current one.
11149MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode,constSDLoc &dl,
11150EVT VT) {
11151SDVTList VTs =getVTList(VT);
11152returngetMachineNode(Opcode, dl, VTs, {});
11153}
11154
11155MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode,constSDLoc &dl,
11156EVT VT,SDValue Op1) {
11157SDVTList VTs =getVTList(VT);
11158SDValue Ops[] = { Op1 };
11159returngetMachineNode(Opcode, dl, VTs, Ops);
11160}
11161
11162MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode,constSDLoc &dl,
11163EVT VT,SDValue Op1,SDValue Op2) {
11164SDVTList VTs =getVTList(VT);
11165SDValue Ops[] = { Op1, Op2 };
11166returngetMachineNode(Opcode, dl, VTs, Ops);
11167}
11168
11169MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode,constSDLoc &dl,
11170EVT VT,SDValue Op1,SDValue Op2,
11171SDValue Op3) {
11172SDVTList VTs =getVTList(VT);
11173SDValue Ops[] = { Op1, Op2, Op3 };
11174returngetMachineNode(Opcode, dl, VTs, Ops);
11175}
11176
11177MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode,constSDLoc &dl,
11178EVT VT,ArrayRef<SDValue> Ops) {
11179SDVTList VTs =getVTList(VT);
11180returngetMachineNode(Opcode, dl, VTs, Ops);
11181}
11182
11183MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode,constSDLoc &dl,
11184EVT VT1,EVT VT2,SDValue Op1,
11185SDValue Op2) {
11186SDVTList VTs =getVTList(VT1, VT2);
11187SDValue Ops[] = { Op1, Op2 };
11188returngetMachineNode(Opcode, dl, VTs, Ops);
11189}
11190
11191MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode,constSDLoc &dl,
11192EVT VT1,EVT VT2,SDValue Op1,
11193SDValue Op2,SDValue Op3) {
11194SDVTList VTs =getVTList(VT1, VT2);
11195SDValue Ops[] = { Op1, Op2, Op3 };
11196returngetMachineNode(Opcode, dl, VTs, Ops);
11197}
11198
11199MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode,constSDLoc &dl,
11200EVT VT1,EVT VT2,
11201ArrayRef<SDValue> Ops) {
11202SDVTList VTs =getVTList(VT1, VT2);
11203returngetMachineNode(Opcode, dl, VTs, Ops);
11204}
11205
11206MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode,constSDLoc &dl,
11207EVT VT1,EVT VT2,EVT VT3,
11208SDValue Op1,SDValue Op2) {
11209SDVTList VTs =getVTList(VT1, VT2, VT3);
11210SDValue Ops[] = { Op1, Op2 };
11211returngetMachineNode(Opcode, dl, VTs, Ops);
11212}
11213
11214MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode,constSDLoc &dl,
11215EVT VT1,EVT VT2,EVT VT3,
11216SDValue Op1,SDValue Op2,
11217SDValue Op3) {
11218SDVTList VTs =getVTList(VT1, VT2, VT3);
11219SDValue Ops[] = { Op1, Op2, Op3 };
11220returngetMachineNode(Opcode, dl, VTs, Ops);
11221}
11222
11223MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode,constSDLoc &dl,
11224EVT VT1,EVT VT2,EVT VT3,
11225ArrayRef<SDValue> Ops) {
11226SDVTList VTs =getVTList(VT1, VT2, VT3);
11227returngetMachineNode(Opcode, dl, VTs, Ops);
11228}
11229
11230MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode,constSDLoc &dl,
11231ArrayRef<EVT> ResultTys,
11232ArrayRef<SDValue> Ops) {
11233SDVTList VTs =getVTList(ResultTys);
11234returngetMachineNode(Opcode, dl, VTs, Ops);
11235}
11236
11237MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode,constSDLoc &DL,
11238SDVTList VTs,
11239ArrayRef<SDValue> Ops) {
11240bool DoCSE = VTs.VTs[VTs.NumVTs-1] != MVT::Glue;
11241MachineSDNode *N;
11242void *IP =nullptr;
11243
11244if (DoCSE) {
11245FoldingSetNodeIDID;
11246AddNodeIDNode(ID, ~Opcode, VTs, Ops);
11247 IP =nullptr;
11248if (SDNode *E = FindNodeOrInsertPos(ID,DL, IP)) {
11249return cast<MachineSDNode>(UpdateSDLocOnMergeSDNode(E,DL));
11250 }
11251 }
11252
11253// Allocate a new MachineSDNode.
11254N = newSDNode<MachineSDNode>(~Opcode,DL.getIROrder(),DL.getDebugLoc(), VTs);
11255 createOperands(N, Ops);
11256
11257if (DoCSE)
11258 CSEMap.InsertNode(N, IP);
11259
11260 InsertNode(N);
11261NewSDValueDbgMsg(SDValue(N, 0),"Creating new machine node: ",this);
11262returnN;
11263}
11264
11265/// getTargetExtractSubreg - A convenience function for creating
11266/// TargetOpcode::EXTRACT_SUBREG nodes.
11267SDValueSelectionDAG::getTargetExtractSubreg(int SRIdx,constSDLoc &DL,EVT VT,
11268SDValue Operand) {
11269SDValue SRIdxVal =getTargetConstant(SRIdx,DL, MVT::i32);
11270SDNode *Subreg =getMachineNode(TargetOpcode::EXTRACT_SUBREG,DL,
11271 VT, Operand, SRIdxVal);
11272returnSDValue(Subreg, 0);
11273}
11274
11275/// getTargetInsertSubreg - A convenience function for creating
11276/// TargetOpcode::INSERT_SUBREG nodes.
11277SDValueSelectionDAG::getTargetInsertSubreg(int SRIdx,constSDLoc &DL,EVT VT,
11278SDValue Operand,SDValue Subreg) {
11279SDValue SRIdxVal =getTargetConstant(SRIdx,DL, MVT::i32);
11280SDNode *Result =getMachineNode(TargetOpcode::INSERT_SUBREG,DL,
11281 VT, Operand, Subreg, SRIdxVal);
11282returnSDValue(Result, 0);
11283}
11284
11285/// getNodeIfExists - Get the specified node if it's already available, or
11286/// else return NULL.
11287SDNode *SelectionDAG::getNodeIfExists(unsigned Opcode,SDVTList VTList,
11288ArrayRef<SDValue> Ops) {
11289SDNodeFlags Flags;
11290if (Inserter)
11291 Flags = Inserter->getFlags();
11292returngetNodeIfExists(Opcode, VTList, Ops, Flags);
11293}
11294
11295SDNode *SelectionDAG::getNodeIfExists(unsigned Opcode,SDVTList VTList,
11296ArrayRef<SDValue> Ops,
11297constSDNodeFlags Flags) {
11298if (VTList.VTs[VTList.NumVTs - 1] != MVT::Glue) {
11299FoldingSetNodeIDID;
11300AddNodeIDNode(ID, Opcode, VTList, Ops);
11301void *IP =nullptr;
11302if (SDNode *E = FindNodeOrInsertPos(ID,SDLoc(), IP)) {
11303 E->intersectFlagsWith(Flags);
11304return E;
11305 }
11306 }
11307returnnullptr;
11308}
11309
11310/// doesNodeExist - Check if a node exists without modifying its flags.
11311boolSelectionDAG::doesNodeExist(unsigned Opcode,SDVTList VTList,
11312ArrayRef<SDValue> Ops) {
11313if (VTList.VTs[VTList.NumVTs - 1] != MVT::Glue) {
11314FoldingSetNodeIDID;
11315AddNodeIDNode(ID, Opcode, VTList, Ops);
11316void *IP =nullptr;
11317if (FindNodeOrInsertPos(ID,SDLoc(), IP))
11318returntrue;
11319 }
11320returnfalse;
11321}
11322
11323/// getDbgValue - Creates a SDDbgValue node.
11324///
11325/// SDNode
11326SDDbgValue *SelectionDAG::getDbgValue(DIVariable *Var,DIExpression *Expr,
11327SDNode *N,unsigned R,bool IsIndirect,
11328constDebugLoc &DL,unsigned O) {
11329assert(cast<DILocalVariable>(Var)->isValidLocationForIntrinsic(DL) &&
11330"Expected inlined-at fields to agree");
11331returnnew (DbgInfo->getAlloc())
11332SDDbgValue(DbgInfo->getAlloc(), Var, Expr,SDDbgOperand::fromNode(N, R),
11333 {}, IsIndirect,DL, O,
11334/*IsVariadic=*/false);
11335}
11336
11337/// Constant
11338SDDbgValue *SelectionDAG::getConstantDbgValue(DIVariable *Var,
11339DIExpression *Expr,
11340constValue *C,
11341constDebugLoc &DL,unsigned O) {
11342assert(cast<DILocalVariable>(Var)->isValidLocationForIntrinsic(DL) &&
11343"Expected inlined-at fields to agree");
11344returnnew (DbgInfo->getAlloc())
11345SDDbgValue(DbgInfo->getAlloc(), Var, Expr,SDDbgOperand::fromConst(C), {},
11346/*IsIndirect=*/false,DL, O,
11347/*IsVariadic=*/false);
11348}
11349
11350/// FrameIndex
11351SDDbgValue *SelectionDAG::getFrameIndexDbgValue(DIVariable *Var,
11352DIExpression *Expr,unsigned FI,
11353bool IsIndirect,
11354constDebugLoc &DL,
11355unsigned O) {
11356assert(cast<DILocalVariable>(Var)->isValidLocationForIntrinsic(DL) &&
11357"Expected inlined-at fields to agree");
11358returngetFrameIndexDbgValue(Var, Expr, FI, {}, IsIndirect,DL, O);
11359}
11360
11361/// FrameIndex with dependencies
11362SDDbgValue *SelectionDAG::getFrameIndexDbgValue(DIVariable *Var,
11363DIExpression *Expr,unsigned FI,
11364ArrayRef<SDNode *> Dependencies,
11365bool IsIndirect,
11366constDebugLoc &DL,
11367unsigned O) {
11368assert(cast<DILocalVariable>(Var)->isValidLocationForIntrinsic(DL) &&
11369"Expected inlined-at fields to agree");
11370returnnew (DbgInfo->getAlloc())
11371SDDbgValue(DbgInfo->getAlloc(), Var, Expr,SDDbgOperand::fromFrameIdx(FI),
11372 Dependencies, IsIndirect,DL, O,
11373/*IsVariadic=*/false);
11374}
11375
11376/// VReg
11377SDDbgValue *SelectionDAG::getVRegDbgValue(DIVariable *Var,DIExpression *Expr,
11378unsigned VReg,bool IsIndirect,
11379constDebugLoc &DL,unsigned O) {
11380assert(cast<DILocalVariable>(Var)->isValidLocationForIntrinsic(DL) &&
11381"Expected inlined-at fields to agree");
11382returnnew (DbgInfo->getAlloc())
11383SDDbgValue(DbgInfo->getAlloc(), Var, Expr,SDDbgOperand::fromVReg(VReg),
11384 {}, IsIndirect,DL, O,
11385/*IsVariadic=*/false);
11386}
11387
11388SDDbgValue *SelectionDAG::getDbgValueList(DIVariable *Var,DIExpression *Expr,
11389ArrayRef<SDDbgOperand> Locs,
11390ArrayRef<SDNode *> Dependencies,
11391bool IsIndirect,constDebugLoc &DL,
11392unsigned O,bool IsVariadic) {
11393assert(cast<DILocalVariable>(Var)->isValidLocationForIntrinsic(DL) &&
11394"Expected inlined-at fields to agree");
11395returnnew (DbgInfo->getAlloc())
11396SDDbgValue(DbgInfo->getAlloc(), Var, Expr, Locs, Dependencies, IsIndirect,
11397DL, O, IsVariadic);
11398}
11399
11400voidSelectionDAG::transferDbgValues(SDValueFrom,SDValue To,
11401unsigned OffsetInBits,unsigned SizeInBits,
11402bool InvalidateDbg) {
11403SDNode *FromNode =From.getNode();
11404SDNode *ToNode = To.getNode();
11405assert(FromNode && ToNode &&"Can't modify dbg values");
11406
11407// PR35338
11408// TODO: assert(From != To && "Redundant dbg value transfer");
11409// TODO: assert(FromNode != ToNode && "Intranode dbg value transfer");
11410if (From == To || FromNode == ToNode)
11411return;
11412
11413if (!FromNode->getHasDebugValue())
11414return;
11415
11416SDDbgOperand FromLocOp =
11417SDDbgOperand::fromNode(From.getNode(),From.getResNo());
11418SDDbgOperand ToLocOp =SDDbgOperand::fromNode(To.getNode(), To.getResNo());
11419
11420SmallVector<SDDbgValue *, 2> ClonedDVs;
11421for (SDDbgValue *Dbg :GetDbgValues(FromNode)) {
11422if (Dbg->isInvalidated())
11423continue;
11424
11425// TODO: assert(!Dbg->isInvalidated() && "Transfer of invalid dbg value");
11426
11427// Create a new location ops vector that is equal to the old vector, but
11428// with each instance of FromLocOp replaced with ToLocOp.
11429bool Changed =false;
11430auto NewLocOps = Dbg->copyLocationOps();
11431 std::replace_if(
11432 NewLocOps.begin(), NewLocOps.end(),
11433 [&Changed, FromLocOp](constSDDbgOperand &Op) {
11434 bool Match = Op == FromLocOp;
11435 Changed |= Match;
11436 return Match;
11437 },
11438 ToLocOp);
11439// Ignore this SDDbgValue if we didn't find a matching location.
11440if (!Changed)
11441continue;
11442
11443DIVariable *Var = Dbg->getVariable();
11444auto *Expr = Dbg->getExpression();
11445// If a fragment is requested, update the expression.
11446if (SizeInBits) {
11447// When splitting a larger (e.g., sign-extended) value whose
11448// lower bits are described with an SDDbgValue, do not attempt
11449// to transfer the SDDbgValue to the upper bits.
11450if (auto FI = Expr->getFragmentInfo())
11451if (OffsetInBits + SizeInBits > FI->SizeInBits)
11452continue;
11453auto Fragment =DIExpression::createFragmentExpression(Expr, OffsetInBits,
11454 SizeInBits);
11455if (!Fragment)
11456continue;
11457 Expr = *Fragment;
11458 }
11459
11460auto AdditionalDependencies = Dbg->getAdditionalDependencies();
11461// Clone the SDDbgValue and move it to To.
11462SDDbgValue *Clone =getDbgValueList(
11463 Var, Expr, NewLocOps, AdditionalDependencies, Dbg->isIndirect(),
11464 Dbg->getDebugLoc(), std::max(ToNode->getIROrder(), Dbg->getOrder()),
11465 Dbg->isVariadic());
11466 ClonedDVs.push_back(Clone);
11467
11468if (InvalidateDbg) {
11469// Invalidate value and indicate the SDDbgValue should not be emitted.
11470 Dbg->setIsInvalidated();
11471 Dbg->setIsEmitted();
11472 }
11473 }
11474
11475for (SDDbgValue *Dbg : ClonedDVs) {
11476assert(is_contained(Dbg->getSDNodes(), ToNode) &&
11477"Transferred DbgValues should depend on the new SDNode");
11478AddDbgValue(Dbg,false);
11479 }
11480}
11481
11482voidSelectionDAG::salvageDebugInfo(SDNode &N) {
11483if (!N.getHasDebugValue())
11484return;
11485
11486auto GetLocationOperand = [](SDNode *Node,unsigned ResNo) {
11487if (auto *FISDN = dyn_cast<FrameIndexSDNode>(Node))
11488returnSDDbgOperand::fromFrameIdx(FISDN->getIndex());
11489returnSDDbgOperand::fromNode(Node, ResNo);
11490 };
11491
11492SmallVector<SDDbgValue *, 2> ClonedDVs;
11493for (auto *DV :GetDbgValues(&N)) {
11494if (DV->isInvalidated())
11495continue;
11496switch (N.getOpcode()) {
11497default:
11498break;
11499caseISD::ADD: {
11500SDValue N0 =N.getOperand(0);
11501SDValue N1 =N.getOperand(1);
11502if (!isa<ConstantSDNode>(N0)) {
11503bool RHSConstant = isa<ConstantSDNode>(N1);
11504uint64_tOffset;
11505if (RHSConstant)
11506Offset =N.getConstantOperandVal(1);
11507// We are not allowed to turn indirect debug values variadic, so
11508// don't salvage those.
11509if (!RHSConstant && DV->isIndirect())
11510continue;
11511
11512// Rewrite an ADD constant node into a DIExpression. Since we are
11513// performing arithmetic to compute the variable's *value* in the
11514// DIExpression, we need to mark the expression with a
11515// DW_OP_stack_value.
11516auto *DIExpr = DV->getExpression();
11517auto NewLocOps = DV->copyLocationOps();
11518bool Changed =false;
11519size_t OrigLocOpsSize = NewLocOps.size();
11520for (size_t i = 0; i < OrigLocOpsSize; ++i) {
11521// We're not given a ResNo to compare against because the whole
11522// node is going away. We know that any ISD::ADD only has one
11523// result, so we can assume any node match is using the result.
11524if (NewLocOps[i].getKind() !=SDDbgOperand::SDNODE ||
11525 NewLocOps[i].getSDNode() != &N)
11526continue;
11527 NewLocOps[i] = GetLocationOperand(N0.getNode(), N0.getResNo());
11528if (RHSConstant) {
11529SmallVector<uint64_t, 3> ExprOps;
11530DIExpression::appendOffset(ExprOps,Offset);
11531 DIExpr =DIExpression::appendOpsToArg(DIExpr, ExprOps, i,true);
11532 }else {
11533// Convert to a variadic expression (if not already).
11534// convertToVariadicExpression() returns a const pointer, so we use
11535// a temporary const variable here.
11536constauto *TmpDIExpr =
11537DIExpression::convertToVariadicExpression(DIExpr);
11538SmallVector<uint64_t, 3> ExprOps;
11539 ExprOps.push_back(dwarf::DW_OP_LLVM_arg);
11540 ExprOps.push_back(NewLocOps.size());
11541 ExprOps.push_back(dwarf::DW_OP_plus);
11542SDDbgOperandRHS =
11543SDDbgOperand::fromNode(N1.getNode(), N1.getResNo());
11544 NewLocOps.push_back(RHS);
11545 DIExpr =DIExpression::appendOpsToArg(TmpDIExpr, ExprOps, i,true);
11546 }
11547 Changed =true;
11548 }
11549 (void)Changed;
11550assert(Changed &&"Salvage target doesn't use N");
11551
11552bool IsVariadic =
11553 DV->isVariadic() || OrigLocOpsSize != NewLocOps.size();
11554
11555auto AdditionalDependencies = DV->getAdditionalDependencies();
11556SDDbgValue *Clone =getDbgValueList(
11557 DV->getVariable(), DIExpr, NewLocOps, AdditionalDependencies,
11558 DV->isIndirect(), DV->getDebugLoc(), DV->getOrder(), IsVariadic);
11559 ClonedDVs.push_back(Clone);
11560 DV->setIsInvalidated();
11561 DV->setIsEmitted();
11562LLVM_DEBUG(dbgs() <<"SALVAGE: Rewriting";
11563 N0.getNode()->dumprFull(this);
11564dbgs() <<" into " << *DIExpr <<'\n');
11565 }
11566break;
11567 }
11568caseISD::TRUNCATE: {
11569SDValue N0 =N.getOperand(0);
11570TypeSize FromSize = N0.getValueSizeInBits();
11571TypeSize ToSize =N.getValueSizeInBits(0);
11572
11573DIExpression *DbgExpression = DV->getExpression();
11574auto ExtOps =DIExpression::getExtOps(FromSize, ToSize,false);
11575auto NewLocOps = DV->copyLocationOps();
11576bool Changed =false;
11577for (size_t i = 0; i < NewLocOps.size(); ++i) {
11578if (NewLocOps[i].getKind() !=SDDbgOperand::SDNODE ||
11579 NewLocOps[i].getSDNode() != &N)
11580continue;
11581
11582 NewLocOps[i] = GetLocationOperand(N0.getNode(), N0.getResNo());
11583 DbgExpression =DIExpression::appendOpsToArg(DbgExpression, ExtOps, i);
11584 Changed =true;
11585 }
11586assert(Changed &&"Salvage target doesn't use N");
11587 (void)Changed;
11588
11589SDDbgValue *Clone =
11590getDbgValueList(DV->getVariable(), DbgExpression, NewLocOps,
11591 DV->getAdditionalDependencies(), DV->isIndirect(),
11592 DV->getDebugLoc(), DV->getOrder(), DV->isVariadic());
11593
11594 ClonedDVs.push_back(Clone);
11595 DV->setIsInvalidated();
11596 DV->setIsEmitted();
11597LLVM_DEBUG(dbgs() <<"SALVAGE: Rewriting"; N0.getNode()->dumprFull(this);
11598dbgs() <<" into " << *DbgExpression <<'\n');
11599break;
11600 }
11601 }
11602 }
11603
11604for (SDDbgValue *Dbg : ClonedDVs) {
11605assert((!Dbg->getSDNodes().empty() ||
11606llvm::any_of(Dbg->getLocationOps(),
11607 [&](constSDDbgOperand &Op) {
11608 return Op.getKind() == SDDbgOperand::FRAMEIX;
11609 })) &&
11610"Salvaged DbgValue should depend on a new SDNode");
11611AddDbgValue(Dbg,false);
11612 }
11613}
11614
11615/// Creates a SDDbgLabel node.
11616SDDbgLabel *SelectionDAG::getDbgLabel(DILabel *Label,
11617constDebugLoc &DL,unsigned O) {
11618assert(cast<DILabel>(Label)->isValidLocationForIntrinsic(DL) &&
11619"Expected inlined-at fields to agree");
11620returnnew (DbgInfo->getAlloc())SDDbgLabel(Label,DL, O);
11621}
11622
11623namespace{
11624
11625/// RAUWUpdateListener - Helper for ReplaceAllUsesWith - When the node
11626/// pointed to by a use iterator is deleted, increment the use iterator
11627/// so that it doesn't dangle.
11628///
11629classRAUWUpdateListener :publicSelectionDAG::DAGUpdateListener {
11630SDNode::use_iterator &UI;
11631SDNode::use_iterator &UE;
11632
11633void NodeDeleted(SDNode *N,SDNode *E) override{
11634// Increment the iterator as needed.
11635while (UI != UE &&N == UI->getUser())
11636 ++UI;
11637 }
11638
11639public:
11640 RAUWUpdateListener(SelectionDAG &d,
11641SDNode::use_iterator &ui,
11642SDNode::use_iterator &ue)
11643 :SelectionDAG::DAGUpdateListener(d), UI(ui), UE(ue) {}
11644};
11645
11646}// end anonymous namespace
11647
11648/// ReplaceAllUsesWith - Modify anything using 'From' to use 'To' instead.
11649/// This can cause recursive merging of nodes in the DAG.
11650///
11651/// This version assumes From has a single result value.
11652///
11653voidSelectionDAG::ReplaceAllUsesWith(SDValue FromN,SDValue To) {
11654SDNode *From = FromN.getNode();
11655assert(From->getNumValues() == 1 && FromN.getResNo() == 0 &&
11656"Cannot replace with this method!");
11657assert(From != To.getNode() &&"Cannot replace uses of with self");
11658
11659// Preserve Debug Values
11660transferDbgValues(FromN, To);
11661// Preserve extra info.
11662copyExtraInfo(From, To.getNode());
11663
11664// Iterate over all the existing uses of From. New uses will be added
11665// to the beginning of the use list, which we avoid visiting.
11666// This specifically avoids visiting uses of From that arise while the
11667// replacement is happening, because any such uses would be the result
11668// of CSE: If an existing node looks like From after one of its operands
11669// is replaced by To, we don't want to replace of all its users with To
11670// too. See PR3018 for more info.
11671SDNode::use_iterator UI =From->use_begin(), UE =From->use_end();
11672 RAUWUpdateListener Listener(*this, UI, UE);
11673while (UI != UE) {
11674SDNode *User = UI->getUser();
11675
11676// This node is about to morph, remove its old self from the CSE maps.
11677 RemoveNodeFromCSEMaps(User);
11678
11679// A user can appear in a use list multiple times, and when this
11680// happens the uses are usually next to each other in the list.
11681// To help reduce the number of CSE recomputations, process all
11682// the uses of this user that we can find this way.
11683do {
11684SDUse &Use = *UI;
11685 ++UI;
11686Use.set(To);
11687if (To->isDivergent() !=From->isDivergent())
11688updateDivergence(User);
11689 }while (UI != UE && UI->getUser() ==User);
11690// Now that we have modified User, add it back to the CSE maps. If it
11691// already exists there, recursively merge the results together.
11692 AddModifiedNodeToCSEMaps(User);
11693 }
11694
11695// If we just RAUW'd the root, take note.
11696if (FromN ==getRoot())
11697setRoot(To);
11698}
11699
11700/// ReplaceAllUsesWith - Modify anything using 'From' to use 'To' instead.
11701/// This can cause recursive merging of nodes in the DAG.
11702///
11703/// This version assumes that for each value of From, there is a
11704/// corresponding value in To in the same position with the same type.
11705///
11706voidSelectionDAG::ReplaceAllUsesWith(SDNode *From,SDNode *To) {
11707#ifndef NDEBUG
11708for (unsigned i = 0, e =From->getNumValues(); i != e; ++i)
11709assert((!From->hasAnyUseOfValue(i) ||
11710From->getValueType(i) == To->getValueType(i)) &&
11711"Cannot use this version of ReplaceAllUsesWith!");
11712#endif
11713
11714// Handle the trivial case.
11715if (From == To)
11716return;
11717
11718// Preserve Debug Info. Only do this if there's a use.
11719for (unsigned i = 0, e =From->getNumValues(); i != e; ++i)
11720if (From->hasAnyUseOfValue(i)) {
11721assert((i < To->getNumValues()) &&"Invalid To location");
11722transferDbgValues(SDValue(From, i),SDValue(To, i));
11723 }
11724// Preserve extra info.
11725copyExtraInfo(From, To);
11726
11727// Iterate over just the existing users of From. See the comments in
11728// the ReplaceAllUsesWith above.
11729SDNode::use_iterator UI =From->use_begin(), UE =From->use_end();
11730 RAUWUpdateListener Listener(*this, UI, UE);
11731while (UI != UE) {
11732SDNode *User = UI->getUser();
11733
11734// This node is about to morph, remove its old self from the CSE maps.
11735 RemoveNodeFromCSEMaps(User);
11736
11737// A user can appear in a use list multiple times, and when this
11738// happens the uses are usually next to each other in the list.
11739// To help reduce the number of CSE recomputations, process all
11740// the uses of this user that we can find this way.
11741do {
11742SDUse &Use = *UI;
11743 ++UI;
11744Use.setNode(To);
11745if (To->isDivergent() !=From->isDivergent())
11746updateDivergence(User);
11747 }while (UI != UE && UI->getUser() ==User);
11748
11749// Now that we have modified User, add it back to the CSE maps. If it
11750// already exists there, recursively merge the results together.
11751 AddModifiedNodeToCSEMaps(User);
11752 }
11753
11754// If we just RAUW'd the root, take note.
11755if (From ==getRoot().getNode())
11756setRoot(SDValue(To,getRoot().getResNo()));
11757}
11758
11759/// ReplaceAllUsesWith - Modify anything using 'From' to use 'To' instead.
11760/// This can cause recursive merging of nodes in the DAG.
11761///
11762/// This version can replace From with any result values. To must match the
11763/// number and types of values returned by From.
11764voidSelectionDAG::ReplaceAllUsesWith(SDNode *From,constSDValue *To) {
11765if (From->getNumValues() == 1)// Handle the simple case efficiently.
11766returnReplaceAllUsesWith(SDValue(From, 0), To[0]);
11767
11768for (unsigned i = 0, e =From->getNumValues(); i != e; ++i) {
11769// Preserve Debug Info.
11770transferDbgValues(SDValue(From, i), To[i]);
11771// Preserve extra info.
11772copyExtraInfo(From, To[i].getNode());
11773 }
11774
11775// Iterate over just the existing users of From. See the comments in
11776// the ReplaceAllUsesWith above.
11777SDNode::use_iterator UI =From->use_begin(), UE =From->use_end();
11778 RAUWUpdateListener Listener(*this, UI, UE);
11779while (UI != UE) {
11780SDNode *User = UI->getUser();
11781
11782// This node is about to morph, remove its old self from the CSE maps.
11783 RemoveNodeFromCSEMaps(User);
11784
11785// A user can appear in a use list multiple times, and when this happens the
11786// uses are usually next to each other in the list. To help reduce the
11787// number of CSE and divergence recomputations, process all the uses of this
11788// user that we can find this way.
11789bool To_IsDivergent =false;
11790do {
11791SDUse &Use = *UI;
11792constSDValue &ToOp = To[Use.getResNo()];
11793 ++UI;
11794Use.set(ToOp);
11795 To_IsDivergent |= ToOp->isDivergent();
11796 }while (UI != UE && UI->getUser() ==User);
11797
11798if (To_IsDivergent !=From->isDivergent())
11799updateDivergence(User);
11800
11801// Now that we have modified User, add it back to the CSE maps. If it
11802// already exists there, recursively merge the results together.
11803 AddModifiedNodeToCSEMaps(User);
11804 }
11805
11806// If we just RAUW'd the root, take note.
11807if (From ==getRoot().getNode())
11808setRoot(SDValue(To[getRoot().getResNo()]));
11809}
11810
11811/// ReplaceAllUsesOfValueWith - Replace any uses of From with To, leaving
11812/// uses of other values produced by From.getNode() alone. The Deleted
11813/// vector is handled the same way as for ReplaceAllUsesWith.
11814voidSelectionDAG::ReplaceAllUsesOfValueWith(SDValueFrom,SDValue To){
11815// Handle the really simple, really trivial case efficiently.
11816if (From == To)return;
11817
11818// Handle the simple, trivial, case efficiently.
11819if (From.getNode()->getNumValues() == 1) {
11820ReplaceAllUsesWith(From, To);
11821return;
11822 }
11823
11824// Preserve Debug Info.
11825transferDbgValues(From, To);
11826copyExtraInfo(From.getNode(), To.getNode());
11827
11828// Iterate over just the existing users of From. See the comments in
11829// the ReplaceAllUsesWith above.
11830SDNode::use_iterator UI =From.getNode()->use_begin(),
11831 UE =From.getNode()->use_end();
11832 RAUWUpdateListener Listener(*this, UI, UE);
11833while (UI != UE) {
11834SDNode *User = UI->getUser();
11835bool UserRemovedFromCSEMaps =false;
11836
11837// A user can appear in a use list multiple times, and when this
11838// happens the uses are usually next to each other in the list.
11839// To help reduce the number of CSE recomputations, process all
11840// the uses of this user that we can find this way.
11841do {
11842SDUse &Use = *UI;
11843
11844// Skip uses of different values from the same node.
11845if (Use.getResNo() !=From.getResNo()) {
11846 ++UI;
11847continue;
11848 }
11849
11850// If this node hasn't been modified yet, it's still in the CSE maps,
11851// so remove its old self from the CSE maps.
11852if (!UserRemovedFromCSEMaps) {
11853 RemoveNodeFromCSEMaps(User);
11854 UserRemovedFromCSEMaps =true;
11855 }
11856
11857 ++UI;
11858Use.set(To);
11859if (To->isDivergent() !=From->isDivergent())
11860updateDivergence(User);
11861 }while (UI != UE && UI->getUser() ==User);
11862// We are iterating over all uses of the From node, so if a use
11863// doesn't use the specific value, no changes are made.
11864if (!UserRemovedFromCSEMaps)
11865continue;
11866
11867// Now that we have modified User, add it back to the CSE maps. If it
11868// already exists there, recursively merge the results together.
11869 AddModifiedNodeToCSEMaps(User);
11870 }
11871
11872// If we just RAUW'd the root, take note.
11873if (From ==getRoot())
11874setRoot(To);
11875}
11876
11877namespace{
11878
11879/// UseMemo - This class is used by SelectionDAG::ReplaceAllUsesOfValuesWith
11880/// to record information about a use.
11881structUseMemo {
11882SDNode *User;
11883unsignedIndex;
11884SDUse *Use;
11885};
11886
11887/// operator< - Sort Memos by User.
11888booloperator<(const UseMemo &L,const UseMemo &R) {
11889return (intptr_t)L.User < (intptr_t)R.User;
11890}
11891
11892/// RAUOVWUpdateListener - Helper for ReplaceAllUsesOfValuesWith - When the node
11893/// pointed to by a UseMemo is deleted, set the User to nullptr to indicate that
11894/// the node already has been taken care of recursively.
11895classRAUOVWUpdateListener :publicSelectionDAG::DAGUpdateListener {
11896SmallVectorImpl<UseMemo> &Uses;
11897
11898void NodeDeleted(SDNode *N,SDNode *E) override{
11899for (UseMemo &Memo :Uses)
11900if (Memo.User ==N)
11901 Memo.User =nullptr;
11902 }
11903
11904public:
11905 RAUOVWUpdateListener(SelectionDAG &d,SmallVectorImpl<UseMemo> &uses)
11906 :SelectionDAG::DAGUpdateListener(d),Uses(uses) {}
11907};
11908
11909}// end anonymous namespace
11910
11911/// Return true if a glue output should propagate divergence information.
11912staticboolgluePropagatesDivergence(constSDNode *Node) {
11913switch (Node->getOpcode()) {
11914caseISD::CopyFromReg:
11915caseISD::CopyToReg:
11916returnfalse;
11917default:
11918returntrue;
11919 }
11920
11921llvm_unreachable("covered opcode switch");
11922}
11923
11924boolSelectionDAG::calculateDivergence(SDNode *N) {
11925if (TLI->isSDNodeAlwaysUniform(N)) {
11926assert(!TLI->isSDNodeSourceOfDivergence(N, FLI, UA) &&
11927"Conflicting divergence information!");
11928returnfalse;
11929 }
11930if (TLI->isSDNodeSourceOfDivergence(N, FLI, UA))
11931returntrue;
11932for (constauto &Op :N->ops()) {
11933EVT VT =Op.getValueType();
11934
11935// Skip Chain. It does not carry divergence.
11936if (VT != MVT::Other &&Op.getNode()->isDivergent() &&
11937 (VT != MVT::Glue ||gluePropagatesDivergence(Op.getNode())))
11938returntrue;
11939 }
11940returnfalse;
11941}
11942
11943voidSelectionDAG::updateDivergence(SDNode *N) {
11944SmallVector<SDNode *, 16> Worklist(1,N);
11945do {
11946N = Worklist.pop_back_val();
11947bool IsDivergent =calculateDivergence(N);
11948if (N->SDNodeBits.IsDivergent != IsDivergent) {
11949N->SDNodeBits.IsDivergent = IsDivergent;
11950llvm::append_range(Worklist,N->users());
11951 }
11952 }while (!Worklist.empty());
11953}
11954
11955void SelectionDAG::CreateTopologicalOrder(std::vector<SDNode *> &Order) {
11956DenseMap<SDNode *, unsigned> Degree;
11957 Order.reserve(AllNodes.size());
11958for (auto &N :allnodes()) {
11959unsigned NOps =N.getNumOperands();
11960 Degree[&N] = NOps;
11961if (0 == NOps)
11962 Order.push_back(&N);
11963 }
11964for (size_tI = 0;I != Order.size(); ++I) {
11965SDNode *N = Order[I];
11966for (auto *U :N->users()) {
11967unsigned &UnsortedOps = Degree[U];
11968if (0 == --UnsortedOps)
11969 Order.push_back(U);
11970 }
11971 }
11972}
11973
11974#if !defined(NDEBUG) && LLVM_ENABLE_ABI_BREAKING_CHECKS
11975void SelectionDAG::VerifyDAGDivergence() {
11976 std::vector<SDNode *> TopoOrder;
11977 CreateTopologicalOrder(TopoOrder);
11978for (auto *N : TopoOrder) {
11979assert(calculateDivergence(N) ==N->isDivergent() &&
11980"Divergence bit inconsistency detected");
11981 }
11982}
11983#endif
11984
11985/// ReplaceAllUsesOfValuesWith - Replace any uses of From with To, leaving
11986/// uses of other values produced by From.getNode() alone. The same value
11987/// may appear in both the From and To list. The Deleted vector is
11988/// handled the same way as for ReplaceAllUsesWith.
11989voidSelectionDAG::ReplaceAllUsesOfValuesWith(constSDValue *From,
11990constSDValue *To,
11991unsigned Num){
11992// Handle the simple, trivial case efficiently.
11993if (Num == 1)
11994returnReplaceAllUsesOfValueWith(*From, *To);
11995
11996transferDbgValues(*From, *To);
11997copyExtraInfo(From->getNode(), To->getNode());
11998
11999// Read up all the uses and make records of them. This helps
12000// processing new uses that are introduced during the
12001// replacement process.
12002SmallVector<UseMemo, 4>Uses;
12003for (unsigned i = 0; i != Num; ++i) {
12004unsigned FromResNo =From[i].getResNo();
12005SDNode *FromNode =From[i].getNode();
12006for (SDUse &Use : FromNode->uses()) {
12007if (Use.getResNo() == FromResNo) {
12008 UseMemo Memo = {Use.getUser(), i, &Use};
12009Uses.push_back(Memo);
12010 }
12011 }
12012 }
12013
12014// Sort the uses, so that all the uses from a given User are together.
12015llvm::sort(Uses);
12016 RAUOVWUpdateListener Listener(*this,Uses);
12017
12018for (unsigned UseIndex = 0, UseIndexEnd =Uses.size();
12019 UseIndex != UseIndexEnd; ) {
12020// We know that this user uses some value of From. If it is the right
12021// value, update it.
12022SDNode *User =Uses[UseIndex].User;
12023// If the node has been deleted by recursive CSE updates when updating
12024// another node, then just skip this entry.
12025if (User ==nullptr) {
12026 ++UseIndex;
12027continue;
12028 }
12029
12030// This node is about to morph, remove its old self from the CSE maps.
12031 RemoveNodeFromCSEMaps(User);
12032
12033// The Uses array is sorted, so all the uses for a given User
12034// are next to each other in the list.
12035// To help reduce the number of CSE recomputations, process all
12036// the uses of this user that we can find this way.
12037do {
12038unsigned i =Uses[UseIndex].Index;
12039SDUse &Use = *Uses[UseIndex].Use;
12040 ++UseIndex;
12041
12042Use.set(To[i]);
12043 }while (UseIndex != UseIndexEnd &&Uses[UseIndex].User ==User);
12044
12045// Now that we have modified User, add it back to the CSE maps. If it
12046// already exists there, recursively merge the results together.
12047 AddModifiedNodeToCSEMaps(User);
12048 }
12049}
12050
12051/// AssignTopologicalOrder - Assign a unique node id for each node in the DAG
12052/// based on their topological order. It returns the maximum id and a vector
12053/// of the SDNodes* in assigned order by reference.
12054unsignedSelectionDAG::AssignTopologicalOrder() {
12055unsigned DAGSize = 0;
12056
12057// SortedPos tracks the progress of the algorithm. Nodes before it are
12058// sorted, nodes after it are unsorted. When the algorithm completes
12059// it is at the end of the list.
12060allnodes_iterator SortedPos =allnodes_begin();
12061
12062// Visit all the nodes. Move nodes with no operands to the front of
12063// the list immediately. Annotate nodes that do have operands with their
12064// operand count. Before we do this, the Node Id fields of the nodes
12065// may contain arbitrary values. After, the Node Id fields for nodes
12066// before SortedPos will contain the topological sort index, and the
12067// Node Id fields for nodes At SortedPos and after will contain the
12068// count of outstanding operands.
12069for (SDNode &N :llvm::make_early_inc_range(allnodes())) {
12070checkForCycles(&N,this);
12071unsigned Degree =N.getNumOperands();
12072if (Degree == 0) {
12073// A node with no uses, add it to the result array immediately.
12074N.setNodeId(DAGSize++);
12075allnodes_iterator Q(&N);
12076if (Q != SortedPos)
12077 SortedPos = AllNodes.insert(SortedPos, AllNodes.remove(Q));
12078assert(SortedPos != AllNodes.end() &&"Overran node list");
12079 ++SortedPos;
12080 }else {
12081// Temporarily use the Node Id as scratch space for the degree count.
12082N.setNodeId(Degree);
12083 }
12084 }
12085
12086// Visit all the nodes. As we iterate, move nodes into sorted order,
12087// such that by the time the end is reached all nodes will be sorted.
12088for (SDNode &Node :allnodes()) {
12089SDNode *N = &Node;
12090checkForCycles(N,this);
12091// N is in sorted position, so all its uses have one less operand
12092// that needs to be sorted.
12093for (SDNode *P :N->users()) {
12094unsigned Degree =P->getNodeId();
12095assert(Degree != 0 &&"Invalid node degree");
12096 --Degree;
12097if (Degree == 0) {
12098// All of P's operands are sorted, so P may sorted now.
12099P->setNodeId(DAGSize++);
12100if (P->getIterator() != SortedPos)
12101 SortedPos = AllNodes.insert(SortedPos, AllNodes.remove(P));
12102assert(SortedPos != AllNodes.end() &&"Overran node list");
12103 ++SortedPos;
12104 }else {
12105// Update P's outstanding operand count.
12106P->setNodeId(Degree);
12107 }
12108 }
12109if (Node.getIterator() == SortedPos) {
12110#ifndef NDEBUG
12111allnodes_iteratorI(N);
12112SDNode *S = &*++I;
12113dbgs() <<"Overran sorted position:\n";
12114 S->dumprFull(this);dbgs() <<"\n";
12115dbgs() <<"Checking if this is due to cycles\n";
12116checkForCycles(this,true);
12117#endif
12118llvm_unreachable(nullptr);
12119 }
12120 }
12121
12122assert(SortedPos == AllNodes.end() &&
12123"Topological sort incomplete!");
12124assert(AllNodes.front().getOpcode() ==ISD::EntryToken &&
12125"First node in topological sort is not the entry token!");
12126assert(AllNodes.front().getNodeId() == 0 &&
12127"First node in topological sort has non-zero id!");
12128assert(AllNodes.front().getNumOperands() == 0 &&
12129"First node in topological sort has operands!");
12130assert(AllNodes.back().getNodeId() == (int)DAGSize-1 &&
12131"Last node in topologic sort has unexpected id!");
12132assert(AllNodes.back().use_empty() &&
12133"Last node in topologic sort has users!");
12134assert(DAGSize ==allnodes_size() &&"Node count mismatch!");
12135return DAGSize;
12136}
12137
12138/// AddDbgValue - Add a dbg_value SDNode. If SD is non-null that means the
12139/// value is produced by SD.
12140voidSelectionDAG::AddDbgValue(SDDbgValue *DB,bool isParameter) {
12141for (SDNode *SD : DB->getSDNodes()) {
12142if (!SD)
12143continue;
12144assert(DbgInfo->getSDDbgValues(SD).empty() || SD->getHasDebugValue());
12145 SD->setHasDebugValue(true);
12146 }
12147 DbgInfo->add(DB, isParameter);
12148}
12149
12150voidSelectionDAG::AddDbgLabel(SDDbgLabel *DB) { DbgInfo->add(DB); }
12151
12152SDValueSelectionDAG::makeEquivalentMemoryOrdering(SDValue OldChain,
12153SDValue NewMemOpChain) {
12154assert(isa<MemSDNode>(NewMemOpChain) &&"Expected a memop node");
12155assert(NewMemOpChain.getValueType() == MVT::Other &&"Expected a token VT");
12156// The new memory operation must have the same position as the old load in
12157// terms of memory dependency. Create a TokenFactor for the old load and new
12158// memory operation and update uses of the old load's output chain to use that
12159// TokenFactor.
12160if (OldChain == NewMemOpChain || OldChain.use_empty())
12161return NewMemOpChain;
12162
12163SDValue TokenFactor =getNode(ISD::TokenFactor,SDLoc(OldChain), MVT::Other,
12164 OldChain, NewMemOpChain);
12165ReplaceAllUsesOfValueWith(OldChain, TokenFactor);
12166UpdateNodeOperands(TokenFactor.getNode(), OldChain, NewMemOpChain);
12167return TokenFactor;
12168}
12169
12170SDValueSelectionDAG::makeEquivalentMemoryOrdering(LoadSDNode *OldLoad,
12171SDValue NewMemOp) {
12172assert(isa<MemSDNode>(NewMemOp.getNode()) &&"Expected a memop node");
12173SDValue OldChain =SDValue(OldLoad, 1);
12174SDValue NewMemOpChain = NewMemOp.getValue(1);
12175returnmakeEquivalentMemoryOrdering(OldChain, NewMemOpChain);
12176}
12177
12178SDValueSelectionDAG::getSymbolFunctionGlobalAddress(SDValueOp,
12179Function **OutFunction) {
12180assert(isa<ExternalSymbolSDNode>(Op) &&"Node should be an ExternalSymbol");
12181
12182auto *Symbol = cast<ExternalSymbolSDNode>(Op)->getSymbol();
12183auto *Module = MF->getFunction().getParent();
12184auto *Function =Module->getFunction(Symbol);
12185
12186if (OutFunction !=nullptr)
12187 *OutFunction =Function;
12188
12189if (Function !=nullptr) {
12190auto PtrTy = TLI->getPointerTy(getDataLayout(),Function->getAddressSpace());
12191returngetGlobalAddress(Function,SDLoc(Op), PtrTy);
12192 }
12193
12194 std::string ErrorStr;
12195raw_string_ostream ErrorFormatter(ErrorStr);
12196 ErrorFormatter <<"Undefined external symbol ";
12197 ErrorFormatter <<'"' << Symbol <<'"';
12198report_fatal_error(Twine(ErrorStr));
12199}
12200
12201//===----------------------------------------------------------------------===//
12202// SDNode Class
12203//===----------------------------------------------------------------------===//
12204
12205boolllvm::isNullConstant(SDValue V) {
12206ConstantSDNode *Const = dyn_cast<ConstantSDNode>(V);
12207return Const !=nullptr && Const->isZero();
12208}
12209
12210boolllvm::isNullConstantOrUndef(SDValue V) {
12211return V.isUndef() ||isNullConstant(V);
12212}
12213
12214boolllvm::isNullFPConstant(SDValue V) {
12215ConstantFPSDNode *Const = dyn_cast<ConstantFPSDNode>(V);
12216return Const !=nullptr && Const->isZero() && !Const->isNegative();
12217}
12218
12219boolllvm::isAllOnesConstant(SDValue V) {
12220ConstantSDNode *Const = dyn_cast<ConstantSDNode>(V);
12221return Const !=nullptr && Const->isAllOnes();
12222}
12223
12224boolllvm::isOneConstant(SDValue V) {
12225ConstantSDNode *Const = dyn_cast<ConstantSDNode>(V);
12226return Const !=nullptr && Const->isOne();
12227}
12228
12229boolllvm::isMinSignedConstant(SDValue V) {
12230ConstantSDNode *Const = dyn_cast<ConstantSDNode>(V);
12231return Const !=nullptr && Const->isMinSignedValue();
12232}
12233
12234boolllvm::isNeutralConstant(unsigned Opcode,SDNodeFlags Flags,SDValue V,
12235unsigned OperandNo) {
12236// NOTE: The cases should match with IR's ConstantExpr::getBinOpIdentity().
12237// TODO: Target-specific opcodes could be added.
12238if (auto *ConstV =isConstOrConstSplat(V,/*AllowUndefs*/false,
12239/*AllowTruncation*/true)) {
12240APInt Const = ConstV->getAPIntValue().trunc(V.getScalarValueSizeInBits());
12241switch (Opcode) {
12242caseISD::ADD:
12243caseISD::OR:
12244caseISD::XOR:
12245caseISD::UMAX:
12246return Const.isZero();
12247caseISD::MUL:
12248return Const.isOne();
12249caseISD::AND:
12250caseISD::UMIN:
12251return Const.isAllOnes();
12252caseISD::SMAX:
12253return Const.isMinSignedValue();
12254caseISD::SMIN:
12255return Const.isMaxSignedValue();
12256caseISD::SUB:
12257caseISD::SHL:
12258caseISD::SRA:
12259caseISD::SRL:
12260return OperandNo == 1 && Const.isZero();
12261caseISD::UDIV:
12262caseISD::SDIV:
12263return OperandNo == 1 && Const.isOne();
12264 }
12265 }elseif (auto *ConstFP =isConstOrConstSplatFP(V)) {
12266switch (Opcode) {
12267caseISD::FADD:
12268return ConstFP->isZero() &&
12269 (Flags.hasNoSignedZeros() || ConstFP->isNegative());
12270caseISD::FSUB:
12271return OperandNo == 1 && ConstFP->isZero() &&
12272 (Flags.hasNoSignedZeros() || !ConstFP->isNegative());
12273caseISD::FMUL:
12274return ConstFP->isExactlyValue(1.0);
12275caseISD::FDIV:
12276return OperandNo == 1 && ConstFP->isExactlyValue(1.0);
12277caseISD::FMINNUM:
12278caseISD::FMAXNUM: {
12279// Neutral element for fminnum is NaN, Inf or FLT_MAX, depending on FMF.
12280EVT VT = V.getValueType();
12281constfltSemantics &Semantics = VT.getFltSemantics();
12282APFloat NeutralAF = !Flags.hasNoNaNs()
12283 ?APFloat::getQNaN(Semantics)
12284 : !Flags.hasNoInfs()
12285 ?APFloat::getInf(Semantics)
12286 :APFloat::getLargest(Semantics);
12287if (Opcode ==ISD::FMAXNUM)
12288 NeutralAF.changeSign();
12289
12290return ConstFP->isExactlyValue(NeutralAF);
12291 }
12292 }
12293 }
12294returnfalse;
12295}
12296
12297SDValuellvm::peekThroughBitcasts(SDValue V) {
12298while (V.getOpcode() ==ISD::BITCAST)
12299 V = V.getOperand(0);
12300return V;
12301}
12302
12303SDValuellvm::peekThroughOneUseBitcasts(SDValue V) {
12304while (V.getOpcode() ==ISD::BITCAST && V.getOperand(0).hasOneUse())
12305 V = V.getOperand(0);
12306return V;
12307}
12308
12309SDValuellvm::peekThroughExtractSubvectors(SDValue V) {
12310while (V.getOpcode() ==ISD::EXTRACT_SUBVECTOR)
12311 V = V.getOperand(0);
12312return V;
12313}
12314
12315SDValuellvm::peekThroughTruncates(SDValue V) {
12316while (V.getOpcode() ==ISD::TRUNCATE)
12317 V = V.getOperand(0);
12318return V;
12319}
12320
12321boolllvm::isBitwiseNot(SDValue V,bool AllowUndefs) {
12322if (V.getOpcode() !=ISD::XOR)
12323returnfalse;
12324 V =peekThroughBitcasts(V.getOperand(1));
12325unsigned NumBits = V.getScalarValueSizeInBits();
12326ConstantSDNode *C =
12327isConstOrConstSplat(V, AllowUndefs,/*AllowTruncation*/true);
12328returnC && (C->getAPIntValue().countr_one() >= NumBits);
12329}
12330
12331ConstantSDNode *llvm::isConstOrConstSplat(SDValueN,bool AllowUndefs,
12332bool AllowTruncation) {
12333EVT VT =N.getValueType();
12334APInt DemandedElts = VT.isFixedLengthVector()
12335 ?APInt::getAllOnes(VT.getVectorMinNumElements())
12336 :APInt(1, 1);
12337returnisConstOrConstSplat(N, DemandedElts, AllowUndefs, AllowTruncation);
12338}
12339
12340ConstantSDNode *llvm::isConstOrConstSplat(SDValueN,constAPInt &DemandedElts,
12341bool AllowUndefs,
12342bool AllowTruncation) {
12343if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N))
12344return CN;
12345
12346// SplatVectors can truncate their operands. Ignore that case here unless
12347// AllowTruncation is set.
12348if (N->getOpcode() ==ISD::SPLAT_VECTOR) {
12349EVT VecEltVT =N->getValueType(0).getVectorElementType();
12350if (auto *CN = dyn_cast<ConstantSDNode>(N->getOperand(0))) {
12351EVT CVT = CN->getValueType(0);
12352assert(CVT.bitsGE(VecEltVT) &&"Illegal splat_vector element extension");
12353if (AllowTruncation || CVT == VecEltVT)
12354return CN;
12355 }
12356 }
12357
12358if (BuildVectorSDNode *BV = dyn_cast<BuildVectorSDNode>(N)) {
12359BitVector UndefElements;
12360ConstantSDNode *CN = BV->getConstantSplatNode(DemandedElts, &UndefElements);
12361
12362// BuildVectors can truncate their operands. Ignore that case here unless
12363// AllowTruncation is set.
12364// TODO: Look into whether we should allow UndefElements in non-DemandedElts
12365if (CN && (UndefElements.none() || AllowUndefs)) {
12366EVT CVT = CN->getValueType(0);
12367EVT NSVT =N.getValueType().getScalarType();
12368assert(CVT.bitsGE(NSVT) &&"Illegal build vector element extension");
12369if (AllowTruncation || (CVT == NSVT))
12370return CN;
12371 }
12372 }
12373
12374returnnullptr;
12375}
12376
12377ConstantFPSDNode *llvm::isConstOrConstSplatFP(SDValueN,bool AllowUndefs) {
12378EVT VT =N.getValueType();
12379APInt DemandedElts = VT.isFixedLengthVector()
12380 ?APInt::getAllOnes(VT.getVectorMinNumElements())
12381 :APInt(1, 1);
12382returnisConstOrConstSplatFP(N, DemandedElts, AllowUndefs);
12383}
12384
12385ConstantFPSDNode *llvm::isConstOrConstSplatFP(SDValueN,
12386constAPInt &DemandedElts,
12387bool AllowUndefs) {
12388if (ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N))
12389return CN;
12390
12391if (BuildVectorSDNode *BV = dyn_cast<BuildVectorSDNode>(N)) {
12392BitVector UndefElements;
12393ConstantFPSDNode *CN =
12394 BV->getConstantFPSplatNode(DemandedElts, &UndefElements);
12395// TODO: Look into whether we should allow UndefElements in non-DemandedElts
12396if (CN && (UndefElements.none() || AllowUndefs))
12397return CN;
12398 }
12399
12400if (N.getOpcode() ==ISD::SPLAT_VECTOR)
12401if (ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N.getOperand(0)))
12402return CN;
12403
12404returnnullptr;
12405}
12406
12407boolllvm::isNullOrNullSplat(SDValueN,bool AllowUndefs) {
12408// TODO: may want to use peekThroughBitcast() here.
12409ConstantSDNode *C =
12410isConstOrConstSplat(N, AllowUndefs,/*AllowTruncation=*/true);
12411returnC &&C->isZero();
12412}
12413
12414boolllvm::isOneOrOneSplat(SDValueN,bool AllowUndefs) {
12415ConstantSDNode *C =
12416isConstOrConstSplat(N, AllowUndefs,/*AllowTruncation*/true);
12417returnC &&C->isOne();
12418}
12419
12420boolllvm::isAllOnesOrAllOnesSplat(SDValueN,bool AllowUndefs) {
12421N =peekThroughBitcasts(N);
12422unsignedBitWidth =N.getScalarValueSizeInBits();
12423ConstantSDNode *C =isConstOrConstSplat(N, AllowUndefs);
12424returnC &&C->isAllOnes() &&C->getValueSizeInBits(0) ==BitWidth;
12425}
12426
12427HandleSDNode::~HandleSDNode() {
12428DropOperands();
12429}
12430
12431MemSDNode::MemSDNode(unsigned Opc,unsigned Order,constDebugLoc &dl,
12432SDVTList VTs,EVT memvt,MachineMemOperand *mmo)
12433 :SDNode(Opc, Order, dl, VTs), MemoryVT(memvt), MMO(mmo) {
12434MemSDNodeBits.IsVolatile =MMO->isVolatile();
12435MemSDNodeBits.IsNonTemporal =MMO->isNonTemporal();
12436MemSDNodeBits.IsDereferenceable =MMO->isDereferenceable();
12437MemSDNodeBits.IsInvariant =MMO->isInvariant();
12438
12439// We check here that the size of the memory operand fits within the size of
12440// the MMO. This is because the MMO might indicate only a possible address
12441// range instead of specifying the affected memory addresses precisely.
12442assert(
12443 (!MMO->getType().isValid() ||
12444TypeSize::isKnownLE(memvt.getStoreSize(),MMO->getSize().getValue())) &&
12445"Size mismatch!");
12446}
12447
12448/// Profile - Gather unique data for the node.
12449///
12450voidSDNode::Profile(FoldingSetNodeID &ID) const{
12451AddNodeIDNode(ID,this);
12452}
12453
12454namespace{
12455
12456structEVTArray {
12457 std::vector<EVT> VTs;
12458
12459 EVTArray() {
12460 VTs.reserve(MVT::VALUETYPE_SIZE);
12461for (unsigned i = 0; i <MVT::VALUETYPE_SIZE; ++i)
12462 VTs.push_back(MVT((MVT::SimpleValueType)i));
12463 }
12464 };
12465
12466}// end anonymous namespace
12467
12468/// getValueTypeList - Return a pointer to the specified value type.
12469///
12470constEVT *SDNode::getValueTypeList(MVT VT) {
12471static EVTArray SimpleVTArray;
12472
12473assert(VT <MVT::VALUETYPE_SIZE &&"Value type out of range!");
12474return &SimpleVTArray.VTs[VT.SimpleTy];
12475}
12476
12477/// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
12478/// indicated value. This method ignores uses of other values defined by this
12479/// operation.
12480boolSDNode::hasNUsesOfValue(unsigned NUses,unsignedValue) const{
12481assert(Value <getNumValues() &&"Bad value!");
12482
12483// TODO: Only iterate over uses of a given value of the node
12484for (SDUse &U :uses()) {
12485if (U.getResNo() ==Value) {
12486if (NUses == 0)
12487returnfalse;
12488 --NUses;
12489 }
12490 }
12491
12492// Found exactly the right number of uses?
12493return NUses == 0;
12494}
12495
12496/// hasAnyUseOfValue - Return true if there are any use of the indicated
12497/// value. This method ignores uses of other values defined by this operation.
12498boolSDNode::hasAnyUseOfValue(unsignedValue) const{
12499assert(Value <getNumValues() &&"Bad value!");
12500
12501for (SDUse &U :uses())
12502if (U.getResNo() ==Value)
12503returntrue;
12504
12505returnfalse;
12506}
12507
12508/// isOnlyUserOf - Return true if this node is the only use of N.
12509boolSDNode::isOnlyUserOf(constSDNode *N) const{
12510bool Seen =false;
12511for (constSDNode *User :N->users()) {
12512if (User ==this)
12513 Seen =true;
12514else
12515returnfalse;
12516 }
12517
12518return Seen;
12519}
12520
12521/// Return true if the only users of N are contained in Nodes.
12522boolSDNode::areOnlyUsersOf(ArrayRef<const SDNode *> Nodes,constSDNode *N) {
12523bool Seen =false;
12524for (constSDNode *User :N->users()) {
12525if (llvm::is_contained(Nodes,User))
12526 Seen =true;
12527else
12528returnfalse;
12529 }
12530
12531return Seen;
12532}
12533
12534/// isOperand - Return true if this node is an operand of N.
12535boolSDValue::isOperandOf(constSDNode *N) const{
12536returnis_contained(N->op_values(), *this);
12537}
12538
12539boolSDNode::isOperandOf(constSDNode *N) const{
12540returnany_of(N->op_values(),
12541 [this](SDValueOp) { return this == Op.getNode(); });
12542}
12543
12544/// reachesChainWithoutSideEffects - Return true if this operand (which must
12545/// be a chain) reaches the specified operand without crossing any
12546/// side-effecting instructions on any chain path. In practice, this looks
12547/// through token factors and non-volatile loads. In order to remain efficient,
12548/// this only looks a couple of nodes in, it does not do an exhaustive search.
12549///
12550/// Note that we only need to examine chains when we're searching for
12551/// side-effects; SelectionDAG requires that all side-effects are represented
12552/// by chains, even if another operand would force a specific ordering. This
12553/// constraint is necessary to allow transformations like splitting loads.
12554boolSDValue::reachesChainWithoutSideEffects(SDValue Dest,
12555unsignedDepth) const{
12556if (*this == Dest)returntrue;
12557
12558// Don't search too deeply, we just want to be able to see through
12559// TokenFactor's etc.
12560if (Depth == 0)returnfalse;
12561
12562// If this is a token factor, all inputs to the TF happen in parallel.
12563if (getOpcode() ==ISD::TokenFactor) {
12564// First, try a shallow search.
12565if (is_contained((*this)->ops(), Dest)) {
12566// We found the chain we want as an operand of this TokenFactor.
12567// Essentially, we reach the chain without side-effects if we could
12568// serialize the TokenFactor into a simple chain of operations with
12569// Dest as the last operation. This is automatically true if the
12570// chain has one use: there are no other ordering constraints.
12571// If the chain has more than one use, we give up: some other
12572// use of Dest might force a side-effect between Dest and the current
12573// node.
12574if (Dest.hasOneUse())
12575returntrue;
12576 }
12577// Next, try a deep search: check whether every operand of the TokenFactor
12578// reaches Dest.
12579returnllvm::all_of((*this)->ops(), [=](SDValueOp) {
12580 return Op.reachesChainWithoutSideEffects(Dest, Depth - 1);
12581 });
12582 }
12583
12584// Loads don't have side effects, look through them.
12585if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(*this)) {
12586if (Ld->isUnordered())
12587return Ld->getChain().reachesChainWithoutSideEffects(Dest,Depth-1);
12588 }
12589returnfalse;
12590}
12591
12592boolSDNode::hasPredecessor(constSDNode *N) const{
12593SmallPtrSet<const SDNode *, 32> Visited;
12594SmallVector<const SDNode *, 16> Worklist;
12595 Worklist.push_back(this);
12596returnhasPredecessorHelper(N, Visited, Worklist);
12597}
12598
12599voidSDNode::intersectFlagsWith(constSDNodeFlags Flags) {
12600 this->Flags &= Flags;
12601}
12602
12603SDValue
12604SelectionDAG::matchBinOpReduction(SDNode *Extract,ISD::NodeType &BinOp,
12605ArrayRef<ISD::NodeType> CandidateBinOps,
12606bool AllowPartials) {
12607// The pattern must end in an extract from index 0.
12608if (Extract->getOpcode() !=ISD::EXTRACT_VECTOR_ELT ||
12609 !isNullConstant(Extract->getOperand(1)))
12610returnSDValue();
12611
12612// Match against one of the candidate binary ops.
12613SDValueOp = Extract->getOperand(0);
12614if (llvm::none_of(CandidateBinOps, [Op](ISD::NodeType BinOp) {
12615returnOp.getOpcode() ==unsigned(BinOp);
12616 }))
12617returnSDValue();
12618
12619// Floating-point reductions may require relaxed constraints on the final step
12620// of the reduction because they may reorder intermediate operations.
12621unsigned CandidateBinOp =Op.getOpcode();
12622if (Op.getValueType().isFloatingPoint()) {
12623SDNodeFlags Flags =Op->getFlags();
12624switch (CandidateBinOp) {
12625caseISD::FADD:
12626if (!Flags.hasNoSignedZeros() || !Flags.hasAllowReassociation())
12627returnSDValue();
12628break;
12629default:
12630llvm_unreachable("Unhandled FP opcode for binop reduction");
12631 }
12632 }
12633
12634// Matching failed - attempt to see if we did enough stages that a partial
12635// reduction from a subvector is possible.
12636auto PartialReduction = [&](SDValueOp,unsigned NumSubElts) {
12637if (!AllowPartials || !Op)
12638returnSDValue();
12639EVT OpVT =Op.getValueType();
12640EVT OpSVT = OpVT.getScalarType();
12641EVT SubVT =EVT::getVectorVT(*getContext(), OpSVT, NumSubElts);
12642if (!TLI->isExtractSubvectorCheap(SubVT, OpVT, 0))
12643returnSDValue();
12644 BinOp = (ISD::NodeType)CandidateBinOp;
12645returngetNode(ISD::EXTRACT_SUBVECTOR,SDLoc(Op), SubVT,Op,
12646getVectorIdxConstant(0,SDLoc(Op)));
12647 };
12648
12649// At each stage, we're looking for something that looks like:
12650// %s = shufflevector <8 x i32> %op, <8 x i32> undef,
12651// <8 x i32> <i32 2, i32 3, i32 undef, i32 undef,
12652// i32 undef, i32 undef, i32 undef, i32 undef>
12653// %a = binop <8 x i32> %op, %s
12654// Where the mask changes according to the stage. E.g. for a 3-stage pyramid,
12655// we expect something like:
12656// <4,5,6,7,u,u,u,u>
12657// <2,3,u,u,u,u,u,u>
12658// <1,u,u,u,u,u,u,u>
12659// While a partial reduction match would be:
12660// <2,3,u,u,u,u,u,u>
12661// <1,u,u,u,u,u,u,u>
12662unsigned Stages =Log2_32(Op.getValueType().getVectorNumElements());
12663SDValue PrevOp;
12664for (unsigned i = 0; i < Stages; ++i) {
12665unsigned MaskEnd = (1 << i);
12666
12667if (Op.getOpcode() != CandidateBinOp)
12668return PartialReduction(PrevOp, MaskEnd);
12669
12670SDValue Op0 =Op.getOperand(0);
12671SDValue Op1 =Op.getOperand(1);
12672
12673ShuffleVectorSDNode *Shuffle = dyn_cast<ShuffleVectorSDNode>(Op0);
12674if (Shuffle) {
12675Op = Op1;
12676 }else {
12677 Shuffle = dyn_cast<ShuffleVectorSDNode>(Op1);
12678Op = Op0;
12679 }
12680
12681// The first operand of the shuffle should be the same as the other operand
12682// of the binop.
12683if (!Shuffle || Shuffle->getOperand(0) !=Op)
12684return PartialReduction(PrevOp, MaskEnd);
12685
12686// Verify the shuffle has the expected (at this stage of the pyramid) mask.
12687for (int Index = 0; Index < (int)MaskEnd; ++Index)
12688if (Shuffle->getMaskElt(Index) != (int)(MaskEnd + Index))
12689return PartialReduction(PrevOp, MaskEnd);
12690
12691 PrevOp =Op;
12692 }
12693
12694// Handle subvector reductions, which tend to appear after the shuffle
12695// reduction stages.
12696while (Op.getOpcode() == CandidateBinOp) {
12697unsigned NumElts =Op.getValueType().getVectorNumElements();
12698SDValue Op0 =Op.getOperand(0);
12699SDValue Op1 =Op.getOperand(1);
12700if (Op0.getOpcode() !=ISD::EXTRACT_SUBVECTOR ||
12701 Op1.getOpcode() !=ISD::EXTRACT_SUBVECTOR ||
12702 Op0.getOperand(0) != Op1.getOperand(0))
12703break;
12704SDValue Src = Op0.getOperand(0);
12705unsigned NumSrcElts = Src.getValueType().getVectorNumElements();
12706if (NumSrcElts != (2 * NumElts))
12707break;
12708if (!(Op0.getConstantOperandAPInt(1) == 0 &&
12709 Op1.getConstantOperandAPInt(1) == NumElts) &&
12710 !(Op1.getConstantOperandAPInt(1) == 0 &&
12711 Op0.getConstantOperandAPInt(1) == NumElts))
12712break;
12713Op = Src;
12714 }
12715
12716 BinOp = (ISD::NodeType)CandidateBinOp;
12717returnOp;
12718}
12719
12720SDValueSelectionDAG::UnrollVectorOp(SDNode *N,unsigned ResNE) {
12721EVT VT =N->getValueType(0);
12722EVT EltVT = VT.getVectorElementType();
12723unsigned NE = VT.getVectorNumElements();
12724
12725SDLoc dl(N);
12726
12727// If ResNE is 0, fully unroll the vector op.
12728if (ResNE == 0)
12729 ResNE = NE;
12730elseif (NE > ResNE)
12731 NE = ResNE;
12732
12733if (N->getNumValues() == 2) {
12734SmallVector<SDValue, 8> Scalars0, Scalars1;
12735SmallVector<SDValue, 4>Operands(N->getNumOperands());
12736EVT VT1 =N->getValueType(1);
12737EVT EltVT1 = VT1.getVectorElementType();
12738
12739unsigned i;
12740for (i = 0; i != NE; ++i) {
12741for (unsigned j = 0, e =N->getNumOperands(); j != e; ++j) {
12742SDValue Operand =N->getOperand(j);
12743EVT OperandVT = Operand.getValueType();
12744
12745// A vector operand; extract a single element.
12746EVT OperandEltVT = OperandVT.getVectorElementType();
12747Operands[j] =getNode(ISD::EXTRACT_VECTOR_ELT, dl, OperandEltVT,
12748 Operand,getVectorIdxConstant(i, dl));
12749 }
12750
12751SDValue EltOp =getNode(N->getOpcode(), dl, {EltVT, EltVT1},Operands);
12752 Scalars0.push_back(EltOp);
12753 Scalars1.push_back(EltOp.getValue(1));
12754 }
12755
12756for (; i < ResNE; ++i) {
12757 Scalars0.push_back(getUNDEF(EltVT));
12758 Scalars1.push_back(getUNDEF(EltVT1));
12759 }
12760
12761EVT VecVT =EVT::getVectorVT(*getContext(), EltVT, ResNE);
12762EVT VecVT1 =EVT::getVectorVT(*getContext(), EltVT1, ResNE);
12763SDValue Vec0 =getBuildVector(VecVT, dl, Scalars0);
12764SDValue Vec1 =getBuildVector(VecVT1, dl, Scalars1);
12765returngetMergeValues({Vec0, Vec1}, dl);
12766 }
12767
12768assert(N->getNumValues() == 1 &&
12769"Can't unroll a vector with multiple results!");
12770
12771SmallVector<SDValue, 8> Scalars;
12772SmallVector<SDValue, 4>Operands(N->getNumOperands());
12773
12774unsigned i;
12775for (i= 0; i != NE; ++i) {
12776for (unsigned j = 0, e =N->getNumOperands(); j != e; ++j) {
12777SDValue Operand =N->getOperand(j);
12778EVT OperandVT = Operand.getValueType();
12779if (OperandVT.isVector()) {
12780// A vector operand; extract a single element.
12781EVT OperandEltVT = OperandVT.getVectorElementType();
12782Operands[j] =getNode(ISD::EXTRACT_VECTOR_ELT, dl, OperandEltVT,
12783 Operand,getVectorIdxConstant(i, dl));
12784 }else {
12785// A scalar operand; just use it as is.
12786Operands[j] = Operand;
12787 }
12788 }
12789
12790switch (N->getOpcode()) {
12791default: {
12792 Scalars.push_back(getNode(N->getOpcode(), dl, EltVT,Operands,
12793N->getFlags()));
12794break;
12795 }
12796caseISD::VSELECT:
12797 Scalars.push_back(getNode(ISD::SELECT, dl, EltVT,Operands));
12798break;
12799caseISD::SHL:
12800caseISD::SRA:
12801caseISD::SRL:
12802caseISD::ROTL:
12803caseISD::ROTR:
12804 Scalars.push_back(getNode(N->getOpcode(), dl, EltVT,Operands[0],
12805getShiftAmountOperand(Operands[0].getValueType(),
12806Operands[1])));
12807break;
12808caseISD::SIGN_EXTEND_INREG: {
12809EVT ExtVT = cast<VTSDNode>(Operands[1])->getVT().getVectorElementType();
12810 Scalars.push_back(getNode(N->getOpcode(), dl, EltVT,
12811Operands[0],
12812getValueType(ExtVT)));
12813break;
12814 }
12815caseISD::ADDRSPACECAST: {
12816constauto *ASC = cast<AddrSpaceCastSDNode>(N);
12817 Scalars.push_back(getAddrSpaceCast(dl, EltVT,Operands[0],
12818 ASC->getSrcAddressSpace(),
12819 ASC->getDestAddressSpace()));
12820break;
12821 }
12822 }
12823 }
12824
12825for (; i < ResNE; ++i)
12826 Scalars.push_back(getUNDEF(EltVT));
12827
12828EVT VecVT =EVT::getVectorVT(*getContext(), EltVT, ResNE);
12829returngetBuildVector(VecVT, dl, Scalars);
12830}
12831
12832std::pair<SDValue, SDValue>SelectionDAG::UnrollVectorOverflowOp(
12833SDNode *N,unsigned ResNE) {
12834unsigned Opcode =N->getOpcode();
12835assert((Opcode ==ISD::UADDO || Opcode ==ISD::SADDO ||
12836 Opcode ==ISD::USUBO || Opcode ==ISD::SSUBO ||
12837 Opcode ==ISD::UMULO || Opcode ==ISD::SMULO) &&
12838"Expected an overflow opcode");
12839
12840EVT ResVT =N->getValueType(0);
12841EVT OvVT =N->getValueType(1);
12842EVT ResEltVT = ResVT.getVectorElementType();
12843EVT OvEltVT = OvVT.getVectorElementType();
12844SDLoc dl(N);
12845
12846// If ResNE is 0, fully unroll the vector op.
12847unsigned NE = ResVT.getVectorNumElements();
12848if (ResNE == 0)
12849 ResNE = NE;
12850elseif (NE > ResNE)
12851 NE = ResNE;
12852
12853SmallVector<SDValue, 8> LHSScalars;
12854SmallVector<SDValue, 8> RHSScalars;
12855ExtractVectorElements(N->getOperand(0), LHSScalars, 0, NE);
12856ExtractVectorElements(N->getOperand(1), RHSScalars, 0, NE);
12857
12858EVT SVT = TLI->getSetCCResultType(getDataLayout(), *getContext(), ResEltVT);
12859SDVTList VTs =getVTList(ResEltVT, SVT);
12860SmallVector<SDValue, 8> ResScalars;
12861SmallVector<SDValue, 8> OvScalars;
12862for (unsigned i = 0; i < NE; ++i) {
12863SDValue Res =getNode(Opcode, dl, VTs, LHSScalars[i], RHSScalars[i]);
12864SDValue Ov =
12865getSelect(dl, OvEltVT, Res.getValue(1),
12866getBoolConstant(true, dl, OvEltVT, ResVT),
12867getConstant(0, dl, OvEltVT));
12868
12869 ResScalars.push_back(Res);
12870 OvScalars.push_back(Ov);
12871 }
12872
12873 ResScalars.append(ResNE - NE,getUNDEF(ResEltVT));
12874 OvScalars.append(ResNE - NE,getUNDEF(OvEltVT));
12875
12876EVT NewResVT =EVT::getVectorVT(*getContext(), ResEltVT, ResNE);
12877EVT NewOvVT =EVT::getVectorVT(*getContext(), OvEltVT, ResNE);
12878return std::make_pair(getBuildVector(NewResVT, dl, ResScalars),
12879getBuildVector(NewOvVT, dl, OvScalars));
12880}
12881
12882boolSelectionDAG::areNonVolatileConsecutiveLoads(LoadSDNode *LD,
12883LoadSDNode *Base,
12884unsigned Bytes,
12885int Dist) const{
12886if (LD->isVolatile() ||Base->isVolatile())
12887returnfalse;
12888// TODO: probably too restrictive for atomics, revisit
12889if (!LD->isSimple())
12890returnfalse;
12891if (LD->isIndexed() ||Base->isIndexed())
12892returnfalse;
12893if (LD->getChain() !=Base->getChain())
12894returnfalse;
12895EVT VT = LD->getMemoryVT();
12896if (VT.getSizeInBits() / 8 != Bytes)
12897returnfalse;
12898
12899auto BaseLocDecomp =BaseIndexOffset::match(Base, *this);
12900auto LocDecomp =BaseIndexOffset::match(LD, *this);
12901
12902 int64_tOffset = 0;
12903if (BaseLocDecomp.equalBaseIndex(LocDecomp, *this,Offset))
12904return (Dist * (int64_t)Bytes ==Offset);
12905returnfalse;
12906}
12907
12908/// InferPtrAlignment - Infer alignment of a load / store address. Return
12909/// std::nullopt if it cannot be inferred.
12910MaybeAlignSelectionDAG::InferPtrAlign(SDValuePtr) const{
12911// If this is a GlobalAddress + cst, return the alignment.
12912constGlobalValue *GV =nullptr;
12913 int64_t GVOffset = 0;
12914if (TLI->isGAPlusOffset(Ptr.getNode(), GV, GVOffset)) {
12915unsigned PtrWidth =getDataLayout().getPointerTypeSizeInBits(GV->getType());
12916KnownBits Known(PtrWidth);
12917llvm::computeKnownBits(GV, Known,getDataLayout());
12918unsigned AlignBits = Known.countMinTrailingZeros();
12919if (AlignBits)
12920returncommonAlignment(Align(1ull << std::min(31U, AlignBits)), GVOffset);
12921 }
12922
12923// If this is a direct reference to a stack slot, use information about the
12924// stack slot's alignment.
12925int FrameIdx = INT_MIN;
12926 int64_t FrameOffset = 0;
12927if (FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(Ptr)) {
12928 FrameIdx = FI->getIndex();
12929 }elseif (isBaseWithConstantOffset(Ptr) &&
12930 isa<FrameIndexSDNode>(Ptr.getOperand(0))) {
12931// Handle FI+Cst
12932 FrameIdx = cast<FrameIndexSDNode>(Ptr.getOperand(0))->getIndex();
12933 FrameOffset =Ptr.getConstantOperandVal(1);
12934 }
12935
12936if (FrameIdx != INT_MIN) {
12937constMachineFrameInfo &MFI =getMachineFunction().getFrameInfo();
12938returncommonAlignment(MFI.getObjectAlign(FrameIdx), FrameOffset);
12939 }
12940
12941return std::nullopt;
12942}
12943
12944/// Split the scalar node with EXTRACT_ELEMENT using the provided
12945/// VTs and return the low/high part.
12946std::pair<SDValue, SDValue>SelectionDAG::SplitScalar(constSDValue &N,
12947constSDLoc &DL,
12948constEVT &LoVT,
12949constEVT &HiVT) {
12950assert(!LoVT.isVector() && !HiVT.isVector() && !N.getValueType().isVector() &&
12951"Split node must be a scalar type");
12952SDValueLo =
12953getNode(ISD::EXTRACT_ELEMENT,DL, LoVT,N,getIntPtrConstant(0,DL));
12954SDValueHi =
12955getNode(ISD::EXTRACT_ELEMENT,DL, HiVT,N,getIntPtrConstant(1,DL));
12956return std::make_pair(Lo,Hi);
12957}
12958
12959/// GetSplitDestVTs - Compute the VTs needed for the low/hi parts of a type
12960/// which is split (or expanded) into two not necessarily identical pieces.
12961std::pair<EVT, EVT>SelectionDAG::GetSplitDestVTs(constEVT &VT) const{
12962// Currently all types are split in half.
12963EVT LoVT, HiVT;
12964if (!VT.isVector())
12965 LoVT = HiVT = TLI->getTypeToTransformTo(*getContext(), VT);
12966else
12967 LoVT = HiVT = VT.getHalfNumVectorElementsVT(*getContext());
12968
12969return std::make_pair(LoVT, HiVT);
12970}
12971
12972/// GetDependentSplitDestVTs - Compute the VTs needed for the low/hi parts of a
12973/// type, dependent on an enveloping VT that has been split into two identical
12974/// pieces. Sets the HiIsEmpty flag when hi type has zero storage size.
12975std::pair<EVT, EVT>
12976SelectionDAG::GetDependentSplitDestVTs(constEVT &VT,constEVT &EnvVT,
12977bool *HiIsEmpty) const{
12978EVT EltTp = VT.getVectorElementType();
12979// Examples:
12980// custom VL=8 with enveloping VL=8/8 yields 8/0 (hi empty)
12981// custom VL=9 with enveloping VL=8/8 yields 8/1
12982// custom VL=10 with enveloping VL=8/8 yields 8/2
12983// etc.
12984ElementCount VTNumElts = VT.getVectorElementCount();
12985ElementCount EnvNumElts = EnvVT.getVectorElementCount();
12986assert(VTNumElts.isScalable() == EnvNumElts.isScalable() &&
12987"Mixing fixed width and scalable vectors when enveloping a type");
12988EVT LoVT, HiVT;
12989if (VTNumElts.getKnownMinValue() > EnvNumElts.getKnownMinValue()) {
12990 LoVT =EVT::getVectorVT(*getContext(), EltTp, EnvNumElts);
12991 HiVT =EVT::getVectorVT(*getContext(), EltTp, VTNumElts - EnvNumElts);
12992 *HiIsEmpty =false;
12993 }else {
12994// Flag that hi type has zero storage size, but return split envelop type
12995// (this would be easier if vector types with zero elements were allowed).
12996 LoVT =EVT::getVectorVT(*getContext(), EltTp, VTNumElts);
12997 HiVT =EVT::getVectorVT(*getContext(), EltTp, EnvNumElts);
12998 *HiIsEmpty =true;
12999 }
13000return std::make_pair(LoVT, HiVT);
13001}
13002
13003/// SplitVector - Split the vector with EXTRACT_SUBVECTOR and return the
13004/// low/high part.
13005std::pair<SDValue, SDValue>
13006SelectionDAG::SplitVector(constSDValue &N,constSDLoc &DL,constEVT &LoVT,
13007constEVT &HiVT) {
13008assert(LoVT.isScalableVector() == HiVT.isScalableVector() &&
13009 LoVT.isScalableVector() ==N.getValueType().isScalableVector() &&
13010"Splitting vector with an invalid mixture of fixed and scalable "
13011"vector types");
13012assert(LoVT.getVectorMinNumElements() + HiVT.getVectorMinNumElements() <=
13013N.getValueType().getVectorMinNumElements() &&
13014"More vector elements requested than available!");
13015SDValueLo,Hi;
13016Lo =
13017getNode(ISD::EXTRACT_SUBVECTOR,DL, LoVT,N,getVectorIdxConstant(0,DL));
13018// For scalable vectors it is safe to use LoVT.getVectorMinNumElements()
13019// (rather than having to use ElementCount), because EXTRACT_SUBVECTOR scales
13020// IDX with the runtime scaling factor of the result vector type. For
13021// fixed-width result vectors, that runtime scaling factor is 1.
13022Hi =getNode(ISD::EXTRACT_SUBVECTOR,DL, HiVT,N,
13023getVectorIdxConstant(LoVT.getVectorMinNumElements(),DL));
13024return std::make_pair(Lo,Hi);
13025}
13026
13027std::pair<SDValue, SDValue>SelectionDAG::SplitEVL(SDValueN,EVT VecVT,
13028constSDLoc &DL) {
13029// Split the vector length parameter.
13030// %evl -> umin(%evl, %halfnumelts) and usubsat(%evl - %halfnumelts).
13031EVT VT =N.getValueType();
13032assert(VecVT.getVectorElementCount().isKnownEven() &&
13033"Expecting the mask to be an evenly-sized vector");
13034unsigned HalfMinNumElts = VecVT.getVectorMinNumElements() / 2;
13035SDValue HalfNumElts =
13036 VecVT.isFixedLengthVector()
13037 ?getConstant(HalfMinNumElts,DL, VT)
13038 :getVScale(DL, VT,APInt(VT.getScalarSizeInBits(), HalfMinNumElts));
13039SDValueLo =getNode(ISD::UMIN,DL, VT,N, HalfNumElts);
13040SDValueHi =getNode(ISD::USUBSAT,DL, VT,N, HalfNumElts);
13041return std::make_pair(Lo,Hi);
13042}
13043
13044/// Widen the vector up to the next power of two using INSERT_SUBVECTOR.
13045SDValueSelectionDAG::WidenVector(constSDValue &N,constSDLoc &DL) {
13046EVT VT =N.getValueType();
13047EVT WideVT =EVT::getVectorVT(*getContext(), VT.getVectorElementType(),
13048NextPowerOf2(VT.getVectorNumElements()));
13049returngetNode(ISD::INSERT_SUBVECTOR,DL, WideVT,getUNDEF(WideVT),N,
13050getVectorIdxConstant(0,DL));
13051}
13052
13053voidSelectionDAG::ExtractVectorElements(SDValueOp,
13054SmallVectorImpl<SDValue> &Args,
13055unsigned Start,unsigned Count,
13056EVT EltVT) {
13057EVT VT =Op.getValueType();
13058if (Count == 0)
13059 Count = VT.getVectorNumElements();
13060if (EltVT ==EVT())
13061 EltVT = VT.getVectorElementType();
13062SDLoc SL(Op);
13063for (unsigned i = Start, e = Start + Count; i != e; ++i) {
13064 Args.push_back(getNode(ISD::EXTRACT_VECTOR_ELT, SL, EltVT,Op,
13065getVectorIdxConstant(i, SL)));
13066 }
13067}
13068
13069// getAddressSpace - Return the address space this GlobalAddress belongs to.
13070unsignedGlobalAddressSDNode::getAddressSpace() const{
13071returngetGlobal()->getType()->getAddressSpace();
13072}
13073
13074Type *ConstantPoolSDNode::getType() const{
13075if (isMachineConstantPoolEntry())
13076return Val.MachineCPVal->getType();
13077return Val.ConstVal->getType();
13078}
13079
13080boolBuildVectorSDNode::isConstantSplat(APInt &SplatValue,APInt &SplatUndef,
13081unsigned &SplatBitSize,
13082bool &HasAnyUndefs,
13083unsigned MinSplatBits,
13084bool IsBigEndian) const{
13085EVT VT =getValueType(0);
13086assert(VT.isVector() &&"Expected a vector type");
13087unsigned VecWidth = VT.getSizeInBits();
13088if (MinSplatBits > VecWidth)
13089returnfalse;
13090
13091// FIXME: The widths are based on this node's type, but build vectors can
13092// truncate their operands.
13093 SplatValue =APInt(VecWidth, 0);
13094 SplatUndef =APInt(VecWidth, 0);
13095
13096// Get the bits. Bits with undefined values (when the corresponding element
13097// of the vector is an ISD::UNDEF value) are set in SplatUndef and cleared
13098// in SplatValue. If any of the values are not constant, give up and return
13099// false.
13100unsignedint NumOps =getNumOperands();
13101assert(NumOps > 0 &&"isConstantSplat has 0-size build vector");
13102unsigned EltWidth = VT.getScalarSizeInBits();
13103
13104for (unsigned j = 0; j < NumOps; ++j) {
13105unsigned i = IsBigEndian ? NumOps - 1 - j : j;
13106SDValue OpVal =getOperand(i);
13107unsigned BitPos = j * EltWidth;
13108
13109if (OpVal.isUndef())
13110 SplatUndef.setBits(BitPos, BitPos + EltWidth);
13111elseif (auto *CN = dyn_cast<ConstantSDNode>(OpVal))
13112 SplatValue.insertBits(CN->getAPIntValue().zextOrTrunc(EltWidth), BitPos);
13113elseif (auto *CN = dyn_cast<ConstantFPSDNode>(OpVal))
13114 SplatValue.insertBits(CN->getValueAPF().bitcastToAPInt(), BitPos);
13115else
13116returnfalse;
13117 }
13118
13119// The build_vector is all constants or undefs. Find the smallest element
13120// size that splats the vector.
13121 HasAnyUndefs = (SplatUndef != 0);
13122
13123// FIXME: This does not work for vectors with elements less than 8 bits.
13124while (VecWidth > 8) {
13125// If we can't split in half, stop here.
13126if (VecWidth & 1)
13127break;
13128
13129unsigned HalfSize = VecWidth / 2;
13130APInt HighValue = SplatValue.extractBits(HalfSize, HalfSize);
13131APInt LowValue = SplatValue.extractBits(HalfSize, 0);
13132APInt HighUndef = SplatUndef.extractBits(HalfSize, HalfSize);
13133APInt LowUndef = SplatUndef.extractBits(HalfSize, 0);
13134
13135// If the two halves do not match (ignoring undef bits), stop here.
13136if ((HighValue & ~LowUndef) != (LowValue & ~HighUndef) ||
13137 MinSplatBits > HalfSize)
13138break;
13139
13140 SplatValue = HighValue | LowValue;
13141 SplatUndef = HighUndef & LowUndef;
13142
13143 VecWidth = HalfSize;
13144 }
13145
13146// FIXME: The loop above only tries to split in halves. But if the input
13147// vector for example is <3 x i16> it wouldn't be able to detect a
13148// SplatBitSize of 16. No idea if that is a design flaw currently limiting
13149// optimizations. I guess that back in the days when this helper was created
13150// vectors normally was power-of-2 sized.
13151
13152 SplatBitSize = VecWidth;
13153returntrue;
13154}
13155
13156SDValueBuildVectorSDNode::getSplatValue(constAPInt &DemandedElts,
13157BitVector *UndefElements) const{
13158unsigned NumOps =getNumOperands();
13159if (UndefElements) {
13160 UndefElements->clear();
13161 UndefElements->resize(NumOps);
13162 }
13163assert(NumOps == DemandedElts.getBitWidth() &&"Unexpected vector size");
13164if (!DemandedElts)
13165returnSDValue();
13166SDValue Splatted;
13167for (unsigned i = 0; i != NumOps; ++i) {
13168if (!DemandedElts[i])
13169continue;
13170SDValueOp =getOperand(i);
13171if (Op.isUndef()) {
13172if (UndefElements)
13173 (*UndefElements)[i] =true;
13174 }elseif (!Splatted) {
13175 Splatted =Op;
13176 }elseif (Splatted !=Op) {
13177returnSDValue();
13178 }
13179 }
13180
13181if (!Splatted) {
13182unsigned FirstDemandedIdx = DemandedElts.countr_zero();
13183assert(getOperand(FirstDemandedIdx).isUndef() &&
13184"Can only have a splat without a constant for all undefs.");
13185returngetOperand(FirstDemandedIdx);
13186 }
13187
13188return Splatted;
13189}
13190
13191SDValueBuildVectorSDNode::getSplatValue(BitVector *UndefElements) const{
13192APInt DemandedElts =APInt::getAllOnes(getNumOperands());
13193returngetSplatValue(DemandedElts, UndefElements);
13194}
13195
13196boolBuildVectorSDNode::getRepeatedSequence(constAPInt &DemandedElts,
13197SmallVectorImpl<SDValue> &Sequence,
13198BitVector *UndefElements) const{
13199unsigned NumOps =getNumOperands();
13200 Sequence.clear();
13201if (UndefElements) {
13202 UndefElements->clear();
13203 UndefElements->resize(NumOps);
13204 }
13205assert(NumOps == DemandedElts.getBitWidth() &&"Unexpected vector size");
13206if (!DemandedElts || NumOps < 2 || !isPowerOf2_32(NumOps))
13207returnfalse;
13208
13209// Set the undefs even if we don't find a sequence (like getSplatValue).
13210if (UndefElements)
13211for (unsignedI = 0;I != NumOps; ++I)
13212if (DemandedElts[I] &&getOperand(I).isUndef())
13213 (*UndefElements)[I] =true;
13214
13215// Iteratively widen the sequence length looking for repetitions.
13216for (unsigned SeqLen = 1; SeqLen < NumOps; SeqLen *= 2) {
13217 Sequence.append(SeqLen,SDValue());
13218for (unsignedI = 0;I != NumOps; ++I) {
13219if (!DemandedElts[I])
13220continue;
13221SDValue &SeqOp = Sequence[I % SeqLen];
13222SDValueOp =getOperand(I);
13223if (Op.isUndef()) {
13224if (!SeqOp)
13225 SeqOp =Op;
13226continue;
13227 }
13228if (SeqOp && !SeqOp.isUndef() && SeqOp !=Op) {
13229 Sequence.clear();
13230break;
13231 }
13232 SeqOp =Op;
13233 }
13234if (!Sequence.empty())
13235returntrue;
13236 }
13237
13238assert(Sequence.empty() &&"Failed to empty non-repeating sequence pattern");
13239returnfalse;
13240}
13241
13242boolBuildVectorSDNode::getRepeatedSequence(SmallVectorImpl<SDValue> &Sequence,
13243BitVector *UndefElements) const{
13244APInt DemandedElts =APInt::getAllOnes(getNumOperands());
13245returngetRepeatedSequence(DemandedElts, Sequence, UndefElements);
13246}
13247
13248ConstantSDNode *
13249BuildVectorSDNode::getConstantSplatNode(constAPInt &DemandedElts,
13250BitVector *UndefElements) const{
13251return dyn_cast_or_null<ConstantSDNode>(
13252getSplatValue(DemandedElts, UndefElements));
13253}
13254
13255ConstantSDNode *
13256BuildVectorSDNode::getConstantSplatNode(BitVector *UndefElements) const{
13257return dyn_cast_or_null<ConstantSDNode>(getSplatValue(UndefElements));
13258}
13259
13260ConstantFPSDNode *
13261BuildVectorSDNode::getConstantFPSplatNode(constAPInt &DemandedElts,
13262BitVector *UndefElements) const{
13263return dyn_cast_or_null<ConstantFPSDNode>(
13264getSplatValue(DemandedElts, UndefElements));
13265}
13266
13267ConstantFPSDNode *
13268BuildVectorSDNode::getConstantFPSplatNode(BitVector *UndefElements) const{
13269return dyn_cast_or_null<ConstantFPSDNode>(getSplatValue(UndefElements));
13270}
13271
13272int32_t
13273BuildVectorSDNode::getConstantFPSplatPow2ToLog2Int(BitVector *UndefElements,
13274uint32_tBitWidth) const{
13275if (ConstantFPSDNode *CN =
13276 dyn_cast_or_null<ConstantFPSDNode>(getSplatValue(UndefElements))) {
13277bool IsExact;
13278APSInt IntVal(BitWidth);
13279constAPFloat &APF = CN->getValueAPF();
13280if (APF.convertToInteger(IntVal,APFloat::rmTowardZero, &IsExact) !=
13281APFloat::opOK ||
13282 !IsExact)
13283return -1;
13284
13285return IntVal.exactLogBase2();
13286 }
13287return -1;
13288}
13289
13290boolBuildVectorSDNode::getConstantRawBits(
13291bool IsLittleEndian,unsigned DstEltSizeInBits,
13292SmallVectorImpl<APInt> &RawBitElements,BitVector &UndefElements) const{
13293// Early-out if this contains anything but Undef/Constant/ConstantFP.
13294if (!isConstant())
13295returnfalse;
13296
13297unsigned NumSrcOps =getNumOperands();
13298unsigned SrcEltSizeInBits =getValueType(0).getScalarSizeInBits();
13299assert(((NumSrcOps * SrcEltSizeInBits) % DstEltSizeInBits) == 0 &&
13300"Invalid bitcast scale");
13301
13302// Extract raw src bits.
13303SmallVector<APInt> SrcBitElements(NumSrcOps,
13304APInt::getZero(SrcEltSizeInBits));
13305BitVector SrcUndeElements(NumSrcOps,false);
13306
13307for (unsignedI = 0;I != NumSrcOps; ++I) {
13308SDValueOp =getOperand(I);
13309if (Op.isUndef()) {
13310 SrcUndeElements.set(I);
13311continue;
13312 }
13313auto *CInt = dyn_cast<ConstantSDNode>(Op);
13314auto *CFP = dyn_cast<ConstantFPSDNode>(Op);
13315assert((CInt || CFP) &&"Unknown constant");
13316 SrcBitElements[I] = CInt ? CInt->getAPIntValue().trunc(SrcEltSizeInBits)
13317 : CFP->getValueAPF().bitcastToAPInt();
13318 }
13319
13320// Recast to dst width.
13321recastRawBits(IsLittleEndian, DstEltSizeInBits, RawBitElements,
13322 SrcBitElements, UndefElements, SrcUndeElements);
13323returntrue;
13324}
13325
13326voidBuildVectorSDNode::recastRawBits(bool IsLittleEndian,
13327unsigned DstEltSizeInBits,
13328SmallVectorImpl<APInt> &DstBitElements,
13329ArrayRef<APInt> SrcBitElements,
13330BitVector &DstUndefElements,
13331constBitVector &SrcUndefElements) {
13332unsigned NumSrcOps = SrcBitElements.size();
13333unsigned SrcEltSizeInBits = SrcBitElements[0].getBitWidth();
13334assert(((NumSrcOps * SrcEltSizeInBits) % DstEltSizeInBits) == 0 &&
13335"Invalid bitcast scale");
13336assert(NumSrcOps == SrcUndefElements.size() &&
13337"Vector size mismatch");
13338
13339unsigned NumDstOps = (NumSrcOps * SrcEltSizeInBits) / DstEltSizeInBits;
13340 DstUndefElements.clear();
13341 DstUndefElements.resize(NumDstOps,false);
13342 DstBitElements.assign(NumDstOps,APInt::getZero(DstEltSizeInBits));
13343
13344// Concatenate src elements constant bits together into dst element.
13345if (SrcEltSizeInBits <= DstEltSizeInBits) {
13346unsigned Scale = DstEltSizeInBits / SrcEltSizeInBits;
13347for (unsignedI = 0;I != NumDstOps; ++I) {
13348 DstUndefElements.set(I);
13349APInt &DstBits = DstBitElements[I];
13350for (unsigned J = 0; J != Scale; ++J) {
13351unsignedIdx = (I * Scale) + (IsLittleEndian ? J : (Scale - J - 1));
13352if (SrcUndefElements[Idx])
13353continue;
13354 DstUndefElements.reset(I);
13355constAPInt &SrcBits = SrcBitElements[Idx];
13356assert(SrcBits.getBitWidth() == SrcEltSizeInBits &&
13357"Illegal constant bitwidths");
13358 DstBits.insertBits(SrcBits, J * SrcEltSizeInBits);
13359 }
13360 }
13361return;
13362 }
13363
13364// Split src element constant bits into dst elements.
13365unsigned Scale = SrcEltSizeInBits / DstEltSizeInBits;
13366for (unsignedI = 0;I != NumSrcOps; ++I) {
13367if (SrcUndefElements[I]) {
13368 DstUndefElements.set(I * Scale, (I + 1) * Scale);
13369continue;
13370 }
13371constAPInt &SrcBits = SrcBitElements[I];
13372for (unsigned J = 0; J != Scale; ++J) {
13373unsignedIdx = (I * Scale) + (IsLittleEndian ? J : (Scale - J - 1));
13374APInt &DstBits = DstBitElements[Idx];
13375 DstBits = SrcBits.extractBits(DstEltSizeInBits, J * DstEltSizeInBits);
13376 }
13377 }
13378}
13379
13380boolBuildVectorSDNode::isConstant() const{
13381for (constSDValue &Op :op_values()) {
13382unsigned Opc =Op.getOpcode();
13383if (Opc !=ISD::UNDEF && Opc !=ISD::Constant && Opc !=ISD::ConstantFP)
13384returnfalse;
13385 }
13386returntrue;
13387}
13388
13389std::optional<std::pair<APInt, APInt>>
13390BuildVectorSDNode::isConstantSequence() const{
13391unsigned NumOps =getNumOperands();
13392if (NumOps < 2)
13393return std::nullopt;
13394
13395if (!isa<ConstantSDNode>(getOperand(0)) ||
13396 !isa<ConstantSDNode>(getOperand(1)))
13397return std::nullopt;
13398
13399unsigned EltSize =getValueType(0).getScalarSizeInBits();
13400APInt Start =getConstantOperandAPInt(0).trunc(EltSize);
13401APInt Stride =getConstantOperandAPInt(1).trunc(EltSize) - Start;
13402
13403if (Stride.isZero())
13404return std::nullopt;
13405
13406for (unsigned i = 2; i < NumOps; ++i) {
13407if (!isa<ConstantSDNode>(getOperand(i)))
13408return std::nullopt;
13409
13410APInt Val =getConstantOperandAPInt(i).trunc(EltSize);
13411if (Val != (Start + (Stride * i)))
13412return std::nullopt;
13413 }
13414
13415return std::make_pair(Start, Stride);
13416}
13417
13418boolShuffleVectorSDNode::isSplatMask(constint *Mask,EVT VT) {
13419// Find the first non-undef value in the shuffle mask.
13420unsigned i, e;
13421for (i = 0, e = VT.getVectorNumElements(); i != e && Mask[i] < 0; ++i)
13422/* search */;
13423
13424// If all elements are undefined, this shuffle can be considered a splat
13425// (although it should eventually get simplified away completely).
13426if (i == e)
13427returntrue;
13428
13429// Make sure all remaining elements are either undef or the same as the first
13430// non-undef value.
13431for (intIdx = Mask[i]; i != e; ++i)
13432if (Mask[i] >= 0 && Mask[i] !=Idx)
13433returnfalse;
13434returntrue;
13435}
13436
13437// Returns true if it is a constant integer BuildVector or constant integer,
13438// possibly hidden by a bitcast.
13439boolSelectionDAG::isConstantIntBuildVectorOrConstantInt(
13440SDValueN,bool AllowOpaques) const{
13441N =peekThroughBitcasts(N);
13442
13443if (auto *C = dyn_cast<ConstantSDNode>(N))
13444return AllowOpaques || !C->isOpaque();
13445
13446if (ISD::isBuildVectorOfConstantSDNodes(N.getNode()))
13447returntrue;
13448
13449// Treat a GlobalAddress supporting constant offset folding as a
13450// constant integer.
13451if (auto *GA = dyn_cast<GlobalAddressSDNode>(N))
13452if (GA->getOpcode() ==ISD::GlobalAddress &&
13453 TLI->isOffsetFoldingLegal(GA))
13454returntrue;
13455
13456if ((N.getOpcode() ==ISD::SPLAT_VECTOR) &&
13457 isa<ConstantSDNode>(N.getOperand(0)))
13458returntrue;
13459returnfalse;
13460}
13461
13462// Returns true if it is a constant float BuildVector or constant float.
13463boolSelectionDAG::isConstantFPBuildVectorOrConstantFP(SDValueN) const{
13464if (isa<ConstantFPSDNode>(N))
13465returntrue;
13466
13467if (ISD::isBuildVectorOfConstantFPSDNodes(N.getNode()))
13468returntrue;
13469
13470if ((N.getOpcode() ==ISD::SPLAT_VECTOR) &&
13471 isa<ConstantFPSDNode>(N.getOperand(0)))
13472returntrue;
13473
13474returnfalse;
13475}
13476
13477std::optional<bool>SelectionDAG::isBoolConstant(SDValueN,
13478bool AllowTruncation) const{
13479ConstantSDNode *Const =isConstOrConstSplat(N,false, AllowTruncation);
13480if (!Const)
13481return std::nullopt;
13482
13483constAPInt &CVal = Const->getAPIntValue();
13484switch (TLI->getBooleanContents(N.getValueType())) {
13485caseTargetLowering::ZeroOrOneBooleanContent:
13486if (CVal.isOne())
13487returntrue;
13488if (CVal.isZero())
13489returnfalse;
13490return std::nullopt;
13491caseTargetLowering::ZeroOrNegativeOneBooleanContent:
13492if (CVal.isAllOnes())
13493returntrue;
13494if (CVal.isZero())
13495returnfalse;
13496return std::nullopt;
13497caseTargetLowering::UndefinedBooleanContent:
13498return CVal[0];
13499 }
13500llvm_unreachable("Unknown BooleanContent enum");
13501}
13502
13503void SelectionDAG::createOperands(SDNode *Node,ArrayRef<SDValue> Vals) {
13504assert(!Node->OperandList &&"Node already has operands");
13505assert(SDNode::getMaxNumOperands() >= Vals.size() &&
13506"too many operands to fit into SDNode");
13507SDUse *Ops = OperandRecycler.allocate(
13508ArrayRecycler<SDUse>::Capacity::get(Vals.size()), OperandAllocator);
13509
13510bool IsDivergent =false;
13511for (unsignedI = 0;I != Vals.size(); ++I) {
13512 Ops[I].setUser(Node);
13513 Ops[I].setInitial(Vals[I]);
13514EVT VT = Ops[I].getValueType();
13515
13516// Skip Chain. It does not carry divergence.
13517if (VT != MVT::Other &&
13518 (VT != MVT::Glue ||gluePropagatesDivergence(Ops[I].getNode())) &&
13519 Ops[I].getNode()->isDivergent()) {
13520 IsDivergent =true;
13521 }
13522 }
13523Node->NumOperands = Vals.size();
13524Node->OperandList = Ops;
13525if (!TLI->isSDNodeAlwaysUniform(Node)) {
13526 IsDivergent |= TLI->isSDNodeSourceOfDivergence(Node, FLI, UA);
13527Node->SDNodeBits.IsDivergent = IsDivergent;
13528 }
13529checkForCycles(Node);
13530}
13531
13532SDValueSelectionDAG::getTokenFactor(constSDLoc &DL,
13533SmallVectorImpl<SDValue> &Vals) {
13534size_t Limit =SDNode::getMaxNumOperands();
13535while (Vals.size() > Limit) {
13536unsigned SliceIdx = Vals.size() - Limit;
13537auto ExtractedTFs =ArrayRef<SDValue>(Vals).slice(SliceIdx, Limit);
13538SDValue NewTF =getNode(ISD::TokenFactor,DL, MVT::Other, ExtractedTFs);
13539 Vals.erase(Vals.begin() + SliceIdx, Vals.end());
13540 Vals.emplace_back(NewTF);
13541 }
13542returngetNode(ISD::TokenFactor,DL, MVT::Other, Vals);
13543}
13544
13545SDValueSelectionDAG::getNeutralElement(unsigned Opcode,constSDLoc &DL,
13546EVT VT,SDNodeFlags Flags) {
13547switch (Opcode) {
13548default:
13549returnSDValue();
13550caseISD::ADD:
13551caseISD::OR:
13552caseISD::XOR:
13553caseISD::UMAX:
13554returngetConstant(0,DL, VT);
13555caseISD::MUL:
13556returngetConstant(1,DL, VT);
13557caseISD::AND:
13558caseISD::UMIN:
13559returngetAllOnesConstant(DL, VT);
13560caseISD::SMAX:
13561returngetConstant(APInt::getSignedMinValue(VT.getSizeInBits()),DL, VT);
13562caseISD::SMIN:
13563returngetConstant(APInt::getSignedMaxValue(VT.getSizeInBits()),DL, VT);
13564caseISD::FADD:
13565// If flags allow, prefer positive zero since it's generally cheaper
13566// to materialize on most targets.
13567returngetConstantFP(Flags.hasNoSignedZeros() ? 0.0 : -0.0,DL, VT);
13568caseISD::FMUL:
13569returngetConstantFP(1.0,DL, VT);
13570caseISD::FMINNUM:
13571caseISD::FMAXNUM: {
13572// Neutral element for fminnum is NaN, Inf or FLT_MAX, depending on FMF.
13573constfltSemantics &Semantics = VT.getFltSemantics();
13574APFloat NeutralAF = !Flags.hasNoNaNs() ?APFloat::getQNaN(Semantics) :
13575 !Flags.hasNoInfs() ?APFloat::getInf(Semantics) :
13576APFloat::getLargest(Semantics);
13577if (Opcode ==ISD::FMAXNUM)
13578 NeutralAF.changeSign();
13579
13580returngetConstantFP(NeutralAF,DL, VT);
13581 }
13582caseISD::FMINIMUM:
13583caseISD::FMAXIMUM: {
13584// Neutral element for fminimum is Inf or FLT_MAX, depending on FMF.
13585constfltSemantics &Semantics = VT.getFltSemantics();
13586APFloat NeutralAF = !Flags.hasNoInfs() ?APFloat::getInf(Semantics)
13587 :APFloat::getLargest(Semantics);
13588if (Opcode ==ISD::FMAXIMUM)
13589 NeutralAF.changeSign();
13590
13591returngetConstantFP(NeutralAF,DL, VT);
13592 }
13593
13594 }
13595}
13596
13597/// Helper used to make a call to a library function that has one argument of
13598/// pointer type.
13599///
13600/// Such functions include 'fegetmode', 'fesetenv' and some others, which are
13601/// used to get or set floating-point state. They have one argument of pointer
13602/// type, which points to the memory region containing bits of the
13603/// floating-point state. The value returned by such function is ignored in the
13604/// created call.
13605///
13606/// \param LibFunc Reference to library function (value of RTLIB::Libcall).
13607/// \param Ptr Pointer used to save/load state.
13608/// \param InChain Ingoing token chain.
13609/// \returns Outgoing chain token.
13610SDValueSelectionDAG::makeStateFunctionCall(unsignedLibFunc,SDValuePtr,
13611SDValue InChain,
13612constSDLoc &DLoc) {
13613assert(InChain.getValueType() == MVT::Other &&"Expected token chain");
13614TargetLowering::ArgListTy Args;
13615TargetLowering::ArgListEntry Entry;
13616 Entry.Node =Ptr;
13617 Entry.Ty =Ptr.getValueType().getTypeForEVT(*getContext());
13618 Args.push_back(Entry);
13619RTLIB::Libcall LC =static_cast<RTLIB::Libcall>(LibFunc);
13620SDValue Callee =getExternalSymbol(TLI->getLibcallName(LC),
13621 TLI->getPointerTy(getDataLayout()));
13622TargetLowering::CallLoweringInfo CLI(*this);
13623 CLI.setDebugLoc(DLoc).setChain(InChain).setLibCallee(
13624 TLI->getLibcallCallingConv(LC),Type::getVoidTy(*getContext()), Callee,
13625 std::move(Args));
13626return TLI->LowerCallTo(CLI).second;
13627}
13628
13629voidSelectionDAG::copyExtraInfo(SDNode *From,SDNode *To) {
13630assert(From && To &&"Invalid SDNode; empty source SDValue?");
13631autoI = SDEI.find(From);
13632if (I == SDEI.end())
13633return;
13634
13635// Use of operator[] on the DenseMap may cause an insertion, which invalidates
13636// the iterator, hence the need to make a copy to prevent a use-after-free.
13637 NodeExtraInfo NEI =I->second;
13638if (LLVM_LIKELY(!NEI.PCSections)) {
13639// No deep copy required for the types of extra info set.
13640//
13641// FIXME: Investigate if other types of extra info also need deep copy. This
13642// depends on the types of nodes they can be attached to: if some extra info
13643// is only ever attached to nodes where a replacement To node is always the
13644// node where later use and propagation of the extra info has the intended
13645// semantics, no deep copy is required.
13646 SDEI[To] = std::move(NEI);
13647return;
13648 }
13649
13650// We need to copy NodeExtraInfo to all _new_ nodes that are being introduced
13651// through the replacement of From with To. Otherwise, replacements of a node
13652// (From) with more complex nodes (To and its operands) may result in lost
13653// extra info where the root node (To) is insignificant in further propagating
13654// and using extra info when further lowering to MIR.
13655//
13656// In the first step pre-populate the visited set with the nodes reachable
13657// from the old From node. This avoids copying NodeExtraInfo to parts of the
13658// DAG that is not new and should be left untouched.
13659SmallVector<const SDNode *> Leafs{From};// Leafs reachable with VisitFrom.
13660DenseSet<const SDNode *> FromReach;// The set of nodes reachable from From.
13661auto VisitFrom = [&](auto &&Self,constSDNode *N,int MaxDepth) {
13662if (MaxDepth == 0) {
13663// Remember this node in case we need to increase MaxDepth and continue
13664// populating FromReach from this node.
13665 Leafs.emplace_back(N);
13666return;
13667 }
13668if (!FromReach.insert(N).second)
13669return;
13670for (constSDValue &Op :N->op_values())
13671 Self(Self,Op.getNode(), MaxDepth - 1);
13672 };
13673
13674// Copy extra info to To and all its transitive operands (that are new).
13675SmallPtrSet<const SDNode *, 8> Visited;
13676auto DeepCopyTo = [&](auto &&Self,constSDNode *N) {
13677if (FromReach.contains(N))
13678returntrue;
13679if (!Visited.insert(N).second)
13680returntrue;
13681if (getEntryNode().getNode() ==N)
13682returnfalse;
13683for (constSDValue &Op :N->op_values()) {
13684if (!Self(Self,Op.getNode()))
13685returnfalse;
13686 }
13687// Copy only if entry node was not reached.
13688 SDEI[N] = NEI;
13689returntrue;
13690 };
13691
13692// We first try with a lower MaxDepth, assuming that the path to common
13693// operands between From and To is relatively short. This significantly
13694// improves performance in the common case. The initial MaxDepth is big
13695// enough to avoid retry in the common case; the last MaxDepth is large
13696// enough to avoid having to use the fallback below (and protects from
13697// potential stack exhaustion from recursion).
13698for (int PrevDepth = 0, MaxDepth = 16; MaxDepth <= 1024;
13699 PrevDepth = MaxDepth, MaxDepth *= 2, Visited.clear()) {
13700// StartFrom is the previous (or initial) set of leafs reachable at the
13701// previous maximum depth.
13702SmallVector<const SDNode *> StartFrom;
13703std::swap(StartFrom, Leafs);
13704for (constSDNode *N : StartFrom)
13705 VisitFrom(VisitFrom,N, MaxDepth - PrevDepth);
13706if (LLVM_LIKELY(DeepCopyTo(DeepCopyTo, To)))
13707return;
13708// This should happen very rarely (reached the entry node).
13709LLVM_DEBUG(dbgs() << __func__ <<": MaxDepth=" << MaxDepth <<" too low\n");
13710assert(!Leafs.empty());
13711 }
13712
13713// This should not happen - but if it did, that means the subgraph reachable
13714// from From has depth greater or equal to maximum MaxDepth, and VisitFrom()
13715// could not visit all reachable common operands. Consequently, we were able
13716// to reach the entry node.
13717errs() <<"warning: incomplete propagation of SelectionDAG::NodeExtraInfo\n";
13718assert(false &&"From subgraph too complex - increase max. MaxDepth?");
13719// Best-effort fallback if assertions disabled.
13720 SDEI[To] = std::move(NEI);
13721}
13722
13723#ifndef NDEBUG
13724staticvoidcheckForCyclesHelper(constSDNode *N,
13725SmallPtrSetImpl<const SDNode*> &Visited,
13726SmallPtrSetImpl<const SDNode*> &Checked,
13727constllvm::SelectionDAG *DAG) {
13728// If this node has already been checked, don't check it again.
13729if (Checked.count(N))
13730return;
13731
13732// If a node has already been visited on this depth-first walk, reject it as
13733// a cycle.
13734if (!Visited.insert(N).second) {
13735errs() <<"Detected cycle in SelectionDAG\n";
13736dbgs() <<"Offending node:\n";
13737N->dumprFull(DAG);dbgs() <<"\n";
13738 abort();
13739 }
13740
13741for (constSDValue &Op :N->op_values())
13742checkForCyclesHelper(Op.getNode(), Visited, Checked, DAG);
13743
13744 Checked.insert(N);
13745 Visited.erase(N);
13746}
13747#endif
13748
13749voidllvm::checkForCycles(constllvm::SDNode *N,
13750constllvm::SelectionDAG *DAG,
13751bool force) {
13752#ifndef NDEBUG
13753bool check = force;
13754#ifdef EXPENSIVE_CHECKS
13755 check =true;
13756#endif// EXPENSIVE_CHECKS
13757if (check) {
13758assert(N &&"Checking nonexistent SDNode");
13759SmallPtrSet<const SDNode*, 32> visited;
13760SmallPtrSet<const SDNode*, 32> checked;
13761checkForCyclesHelper(N, visited, checked, DAG);
13762 }
13763#endif// !NDEBUG
13764}
13765
13766voidllvm::checkForCycles(constllvm::SelectionDAG *DAG,bool force) {
13767checkForCycles(DAG->getRoot().getNode(), DAG, force);
13768}
FMAInstKind::Indexed
@ Indexed
isConstant
static bool isConstant(const MachineInstr &MI)
Definition:AMDGPUInstructionSelector.cpp:2862
APFloat.h
This file declares a class to represent arbitrary precision floating point values and provide a varie...
APInt.h
This file implements a class to represent arbitrary precision integral constant values and operations...
APSInt.h
This file implements the APSInt class, which is a simple class that represents an arbitrary sized int...
MBB
MachineBasicBlock & MBB
Definition:ARMSLSHardening.cpp:71
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition:ARMSLSHardening.cpp:73
Results
Function Alias Analysis Results
Definition:AliasAnalysis.cpp:731
AliasAnalysis.h
ArrayRef.h
BitVector.h
This file implements the BitVector class.
From
BlockVerifier::State From
Definition:BlockVerifier.cpp:57
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
A
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Info
Analysis containing CSE Info
Definition:CSEInfo.cpp:27
Casting.h
CodeGen.h
isBigEndian
static std::optional< bool > isBigEndian(const SmallDenseMap< int64_t, int64_t, 8 > &MemOffset2Idx, int64_t LowestIdx)
Given a map from byte offsets in memory to indices in a load/store, determine if that map corresponds...
Definition:CombinerHelper.cpp:127
Compiler.h
__asan_unpoison_memory_region
#define __asan_unpoison_memory_region(p, size)
Definition:Compiler.h:553
LLVM_LIKELY
#define LLVM_LIKELY(EXPR)
Definition:Compiler.h:319
Constants.h
This file contains the declarations for the subclasses of Constant, which represent the different fla...
DataLayout.h
Idx
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
Definition:DeadArgumentElimination.cpp:353
ignored
Looks at all the uses of the given value Returns the Liveness deduced from the uses of this value Adds all uses that cause the result to be MaybeLive to MaybeLiveRetUses If the result is MaybeLiveUses might be modified but its content should be ignored(since it might not be complete). DeadArgumentEliminationPass
Definition:DeadArgumentElimination.cpp:473
uses
Given that RA is a live propagate it s liveness to any other values it uses(according to Uses). void DeadArgumentEliminationPass
Definition:DeadArgumentElimination.cpp:717
value
Given that RA is a live value
Definition:DeadArgumentElimination.cpp:716
DebugInfoMetadata.h
DebugLoc.h
Debug.h
LLVM_DEBUG
#define LLVM_DEBUG(...)
Definition:Debug.h:106
DenseSet.h
This file defines the DenseSet and SmallDenseSet classes.
DerivedTypes.h
Dwarf.h
This file contains constants used for implementing Dwarf debug support.
Index
uint32_t Index
Definition:ELFObjHandler.cpp:83
Size
uint64_t Size
Definition:ELFObjHandler.cpp:81
Sym
Symbol * Sym
Definition:ELF_riscv.cpp:479
X
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
FoldingSet.h
This file defines a hash set that can be used to remove duplication of nodes in a graph.
FunctionLoweringInfo.h
GlobalValue.h
_
#define _
Definition:HexagonMCCodeEmitter.cpp:46
Constant.h
Function.h
Type.h
ISDOpcodes.h
users
iv users
Definition:IVUsers.cpp:48
KnownBits.h
Options
static LVOptions Options
Definition:LVOptions.cpp:25
getMemsetValue
static Register getMemsetValue(Register Val, LLT Ty, MachineIRBuilder &MIB)
Definition:LegalizerHelper.cpp:9523
shouldLowerMemFuncForSize
static bool shouldLowerMemFuncForSize(const MachineFunction &MF)
Definition:LegalizerHelper.cpp:9447
isZero
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
Definition:Lint.cpp:557
getPrefTypeAlign
static Align getPrefTypeAlign(EVT VT, SelectionDAG &DAG)
Definition:LoongArchISelLowering.cpp:5483
F
#define F(x, y, z)
Definition:MD5.cpp:55
I
#define I(x, y, z)
Definition:MD5.cpp:58
G
#define G(x, y, z)
Definition:MD5.cpp:56
Operands
mir Rename Register Operands
Definition:MIRNamerPass.cpp:74
MachineBasicBlock.h
MachineConstantPool.h
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
MachineFrameInfo.h
MachineFunction.h
MachineMemOperand.h
TRI
unsigned const TargetRegisterInfo * TRI
Definition:MachineSink.cpp:2029
MachineValueType.h
MathExtras.h
MemoryLocation.h
This file provides utility analysis objects describing memory locations.
Metadata.h
This file contains the declarations for metadata subclasses.
getReg
static unsigned getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
Definition:MipsDisassembler.cpp:520
Mutex.h
Signed
@ Signed
Definition:NVPTXISelLowering.cpp:4789
Y
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
P
#define P(N)
Operation
PowerPC Reduce CR logical Operation
Definition:PPCReduceCRLogicals.cpp:735
Cond
const SmallVectorImpl< MachineOperand > & Cond
Definition:RISCVRedundantCopyElimination.cpp:75
Uses
Remove Loads Into Fake Uses
Definition:RemoveLoadsIntoFakeUses.cpp:74
RuntimeLibcallUtil.h
SDNodeDbgValue.h
SDPatternMatch.h
Contains matchers for matching SelectionDAG nodes and values.
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
getValueType
static Type * getValueType(Value *V)
Returns the type of the given value/instruction V.
Definition:SLPVectorizer.cpp:243
STLExtras.h
This file contains some templates that are useful if you are working with the STL at all.
umul_ov
static uint64_t umul_ov(uint64_t i, uint64_t j, bool &Overflow)
Definition:ScalarEvolution.cpp:3051
SelectionDAGAddressAnalysis.h
SelectionDAGNodes.h
SelectionDAGTargetInfo.h
getMemcpyLoadsAndStores
static SDValue getMemcpyLoadsAndStores(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Dst, SDValue Src, uint64_t Size, Align Alignment, bool isVol, bool AlwaysInline, MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo, const AAMDNodes &AAInfo, BatchAAResults *BatchAA)
Definition:SelectionDAG.cpp:8129
getMemsetStores
static SDValue getMemsetStores(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Dst, SDValue Src, uint64_t Size, Align Alignment, bool isVol, bool AlwaysInline, MachinePointerInfo DstPtrInfo, const AAMDNodes &AAInfo)
Lower the call to 'memset' intrinsic function into a series of store operations.
Definition:SelectionDAG.cpp:8455
FoldValueWithUndef
static std::optional< APInt > FoldValueWithUndef(unsigned Opcode, const APInt &C1, bool IsUndef1, const APInt &C2, bool IsUndef2)
Definition:SelectionDAG.cpp:6613
FoldSTEP_VECTOR
static SDValue FoldSTEP_VECTOR(const SDLoc &DL, EVT VT, SDValue Step, SelectionDAG &DAG)
Definition:SelectionDAG.cpp:6051
AddNodeIDNode
static void AddNodeIDNode(FoldingSetNodeID &ID, unsigned OpC, SDVTList VTList, ArrayRef< SDValue > OpList)
Definition:SelectionDAG.cpp:746
getMemsetStringVal
static SDValue getMemsetStringVal(EVT VT, const SDLoc &dl, SelectionDAG &DAG, const TargetLowering &TLI, const ConstantDataArraySlice &Slice)
getMemsetStringVal - Similar to getMemsetValue.
Definition:SelectionDAG.cpp:8010
EnableMemCpyDAGOpt
static cl::opt< bool > EnableMemCpyDAGOpt("enable-memcpy-dag-opt", cl::Hidden, cl::init(true), cl::desc("Gang up loads and stores generated by inlining of memcpy"))
haveNoCommonBitsSetCommutative
static bool haveNoCommonBitsSetCommutative(SDValue A, SDValue B)
Definition:SelectionDAG.cpp:6008
AddNodeIDValueTypes
static void AddNodeIDValueTypes(FoldingSetNodeID &ID, SDVTList VTList)
AddNodeIDValueTypes - Value type lists are intern'd so we can represent them solely with their pointe...
Definition:SelectionDAG.cpp:724
commuteShuffle
static void commuteShuffle(SDValue &N1, SDValue &N2, MutableArrayRef< int > M)
Swaps the values of N1 and N2.
Definition:SelectionDAG.cpp:2142
isMemSrcFromConstant
static bool isMemSrcFromConstant(SDValue Src, ConstantDataArraySlice &Slice)
Returns true if memcpy source is constant data.
Definition:SelectionDAG.cpp:8077
getMemmoveLoadsAndStores
static SDValue getMemmoveLoadsAndStores(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Dst, SDValue Src, uint64_t Size, Align Alignment, bool isVol, bool AlwaysInline, MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo, const AAMDNodes &AAInfo)
Definition:SelectionDAG.cpp:8330
AddNodeIDOpcode
static void AddNodeIDOpcode(FoldingSetNodeID &ID, unsigned OpC)
AddNodeIDOpcode - Add the node opcode to the NodeID data.
Definition:SelectionDAG.cpp:718
getSetCCInverseImpl
static ISD::CondCode getSetCCInverseImpl(ISD::CondCode Op, bool isIntegerLike)
Definition:SelectionDAG.cpp:626
doNotCSE
static bool doNotCSE(SDNode *N)
doNotCSE - Return true if CSE should not be performed for this node.
Definition:SelectionDAG.cpp:1009
MaxLdStGlue
static cl::opt< int > MaxLdStGlue("ldstmemcpy-glue-max", cl::desc("Number limit for gluing ld/st of memcpy."), cl::Hidden, cl::init(0))
AddNodeIDOperands
static void AddNodeIDOperands(FoldingSetNodeID &ID, ArrayRef< SDValue > Ops)
AddNodeIDOperands - Various routines for adding operands to the NodeID data.
Definition:SelectionDAG.cpp:729
canFoldStoreIntoLibCallOutputPointers
static bool canFoldStoreIntoLibCallOutputPointers(StoreSDNode *StoreNode, SDNode *FPNode)
Given a store node StoreNode, return true if it is safe to fold that node into FPNode,...
Definition:SelectionDAG.cpp:2507
foldCONCAT_VECTORS
static SDValue foldCONCAT_VECTORS(const SDLoc &DL, EVT VT, ArrayRef< SDValue > Ops, SelectionDAG &DAG)
Try to simplify vector concatenation to an input value, undef, or build vector.
Definition:SelectionDAG.cpp:6095
InferPointerInfo
static MachinePointerInfo InferPointerInfo(const MachinePointerInfo &Info, SelectionDAG &DAG, SDValue Ptr, int64_t Offset=0)
InferPointerInfo - If the specified ptr/offset is a frame index, infer a MachinePointerInfo record fr...
Definition:SelectionDAG.cpp:9161
AddNodeIDCustom
static void AddNodeIDCustom(FoldingSetNodeID &ID, const SDNode *N)
If this is an SDNode with special info, add this info to the NodeID data.
Definition:SelectionDAG.cpp:754
gluePropagatesDivergence
static bool gluePropagatesDivergence(const SDNode *Node)
Return true if a glue output should propagate divergence information.
Definition:SelectionDAG.cpp:11912
NewSDValueDbgMsg
static void NewSDValueDbgMsg(SDValue V, StringRef Msg, SelectionDAG *G)
Definition:SelectionDAG.cpp:119
makeVTList
static SDVTList makeVTList(const EVT *VTs, unsigned NumVTs)
makeVTList - Return an instance of the SDVTList struct initialized with the specified members.
Definition:SelectionDAG.cpp:91
VerifySDNode
static void VerifySDNode(SDNode *N, const TargetLowering *TLI)
VerifySDNode - Check the given SDNode. Aborts if it is invalid.
Definition:SelectionDAG.cpp:1158
checkForCyclesHelper
static void checkForCyclesHelper(const SDNode *N, SmallPtrSetImpl< const SDNode * > &Visited, SmallPtrSetImpl< const SDNode * > &Checked, const llvm::SelectionDAG *DAG)
Definition:SelectionDAG.cpp:13724
chainLoadsAndStoresForMemcpy
static void chainLoadsAndStoresForMemcpy(SelectionDAG &DAG, const SDLoc &dl, SmallVector< SDValue, 32 > &OutChains, unsigned From, unsigned To, SmallVector< SDValue, 16 > &OutLoadChains, SmallVector< SDValue, 16 > &OutStoreChains)
Definition:SelectionDAG.cpp:8104
isSignedOp
static int isSignedOp(ISD::CondCode Opcode)
For an integer comparison, return 1 if the comparison is a signed operation and 2 if the result is an...
Definition:SelectionDAG.cpp:651
FoldValue
static std::optional< APInt > FoldValue(unsigned Opcode, const APInt &C1, const APInt &C2)
Definition:SelectionDAG.cpp:6552
FoldBUILD_VECTOR
static SDValue FoldBUILD_VECTOR(const SDLoc &DL, EVT VT, ArrayRef< SDValue > Ops, SelectionDAG &DAG)
Definition:SelectionDAG.cpp:6059
checkAddrSpaceIsValidForLibcall
static void checkAddrSpaceIsValidForLibcall(const TargetLowering *TLI, unsigned AS)
Definition:SelectionDAG.cpp:8571
MaxSteps
static cl::opt< unsigned > MaxSteps("has-predecessor-max-steps", cl::Hidden, cl::init(8192), cl::desc("DAG combiner limit number of steps when searching DAG " "for predecessor nodes"))
SelectionDAG.h
SizeOpts.h
SmallPtrSet.h
This file defines the SmallPtrSet class.
SmallVector.h
This file defines the SmallVector class.
TargetFrameLowering.h
Ptr
@ Ptr
Definition:TargetLibraryInfo.cpp:77
TargetLibraryInfo.h
TargetLowering.h
This file describes how to lower LLVM code to machine code.
TargetOptions.h
TargetRegisterInfo.h
TargetSubtargetInfo.h
Triple.h
Twine.h
getOpcode
static std::optional< unsigned > getOpcode(ArrayRef< VPValue * > Values)
Returns the opcode of Values or ~0 if they do not all agree.
Definition:VPlanSLP.cpp:191
mapOverflowResult
static OverflowResult mapOverflowResult(ConstantRange::OverflowResult OR)
Convert ConstantRange OverflowResult into ValueTracking OverflowResult.
Definition:ValueTracking.cpp:7173
UndefPoisonKind::PoisonOnly
@ PoisonOnly
ValueTracking.h
ValueTypes.h
VectorUtils.h
RHS
Value * RHS
Definition:X86PartialReduction.cpp:74
LHS
Value * LHS
Definition:X86PartialReduction.cpp:73
getSize
static unsigned getSize(unsigned Kind)
Definition:XtensaAsmBackend.cpp:134
Node
Definition:ItaniumDemangle.h:163
T
char
llvm::APFloat
Definition:APFloat.h:904
llvm::APFloat::getQNaN
static APFloat getQNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for QNaN values.
Definition:APFloat.h:1122
llvm::APFloat::divide
opStatus divide(const APFloat &RHS, roundingMode RM)
Definition:APFloat.h:1210
llvm::APFloat::copySign
void copySign(const APFloat &RHS)
Definition:APFloat.h:1304
llvm::APFloat::convert
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
Definition:APFloat.cpp:5463
llvm::APFloat::subtract
opStatus subtract(const APFloat &RHS, roundingMode RM)
Definition:APFloat.h:1192
llvm::APFloat::isExactlyValue
bool isExactlyValue(double V) const
We don't rely on operator== working on double values, as it returns true for things that are clearly ...
Definition:APFloat.h:1428
llvm::APFloat::add
opStatus add(const APFloat &RHS, roundingMode RM)
Definition:APFloat.h:1183
llvm::APFloat::isFinite
bool isFinite() const
Definition:APFloat.h:1450
llvm::APFloat::isNaN
bool isNaN() const
Definition:APFloat.h:1443
llvm::APFloat::convertFromAPInt
opStatus convertFromAPInt(const APInt &Input, bool IsSigned, roundingMode RM)
Definition:APFloat.h:1334
llvm::APFloat::multiply
opStatus multiply(const APFloat &RHS, roundingMode RM)
Definition:APFloat.h:1201
llvm::APFloat::fusedMultiplyAdd
opStatus fusedMultiplyAdd(const APFloat &Multiplicand, const APFloat &Addend, roundingMode RM)
Definition:APFloat.h:1237
llvm::APFloat::isZero
bool isZero() const
Definition:APFloat.h:1441
llvm::APFloat::getLargest
static APFloat getLargest(const fltSemantics &Sem, bool Negative=false)
Returns the largest finite number in the given semantics.
Definition:APFloat.h:1140
llvm::APFloat::convertToInteger
opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
Definition:APFloat.h:1326
llvm::APFloat::getInf
static APFloat getInf(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Infinity.
Definition:APFloat.h:1100
llvm::APFloat::mod
opStatus mod(const APFloat &RHS)
Definition:APFloat.h:1228
llvm::APFloat::isPosZero
bool isPosZero() const
Definition:APFloat.h:1456
llvm::APFloat::isNegZero
bool isNegZero() const
Definition:APFloat.h:1457
llvm::APFloat::changeSign
void changeSign()
Definition:APFloat.h:1299
llvm::APFloat::getNaN
static APFloat getNaN(const fltSemantics &Sem, bool Negative=false, uint64_t payload=0)
Factory for NaN values.
Definition:APFloat.h:1111
llvm::APFloat::isInfinity
bool isInfinity() const
Definition:APFloat.h:1442
llvm::APInt
Class for arbitrary precision integers.
Definition:APInt.h:78
llvm::APInt::umul_ov
APInt umul_ov(const APInt &RHS, bool &Overflow) const
Definition:APInt.cpp:1945
llvm::APInt::usub_sat
APInt usub_sat(const APInt &RHS) const
Definition:APInt.cpp:2029
llvm::APInt::udiv
APInt udiv(const APInt &RHS) const
Unsigned division operation.
Definition:APInt.cpp:1547
llvm::APInt::getAllOnes
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
Definition:APInt.h:234
llvm::APInt::clearBit
void clearBit(unsigned BitPosition)
Set a given bit to 0.
Definition:APInt.h:1407
llvm::APInt::zext
APInt zext(unsigned width) const
Zero extend to a new width.
Definition:APInt.cpp:986
llvm::APInt::getSignMask
static APInt getSignMask(unsigned BitWidth)
Get the SignMask for a specific bit width.
Definition:APInt.h:229
llvm::APInt::getZExtValue
uint64_t getZExtValue() const
Get zero extended value.
Definition:APInt.h:1520
llvm::APInt::setHighBits
void setHighBits(unsigned hiBits)
Set the top hiBits bits.
Definition:APInt.h:1392
llvm::APInt::popcount
unsigned popcount() const
Count the number of bits set.
Definition:APInt.h:1649
llvm::APInt::setBitsFrom
void setBitsFrom(unsigned loBit)
Set the top bits starting from loBit.
Definition:APInt.h:1386
llvm::APInt::getHiBits
APInt getHiBits(unsigned numBits) const
Compute an APInt containing numBits highbits from this APInt.
Definition:APInt.cpp:612
llvm::APInt::zextOrTrunc
APInt zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
Definition:APInt.cpp:1007
llvm::APInt::getActiveBits
unsigned getActiveBits() const
Compute the number of active bits in the value.
Definition:APInt.h:1492
llvm::APInt::trunc
APInt trunc(unsigned width) const
Truncate to new width.
Definition:APInt.cpp:910
llvm::APInt::setBit
void setBit(unsigned BitPosition)
Set the given bit to 1 whose position is given as "bitPosition".
Definition:APInt.h:1330
llvm::APInt::abs
APInt abs() const
Get the absolute value.
Definition:APInt.h:1773
llvm::APInt::sadd_sat
APInt sadd_sat(const APInt &RHS) const
Definition:APInt.cpp:2000
llvm::APInt::isAllOnes
bool isAllOnes() const
Determine if all bits are set. This is true for zero-width values.
Definition:APInt.h:371
llvm::APInt::ugt
bool ugt(const APInt &RHS) const
Unsigned greater than comparison.
Definition:APInt.h:1182
llvm::APInt::isZero
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
Definition:APInt.h:380
llvm::APInt::urem
APInt urem(const APInt &RHS) const
Unsigned remainder operation.
Definition:APInt.cpp:1640
llvm::APInt::getBitWidth
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition:APInt.h:1468
llvm::APInt::ult
bool ult(const APInt &RHS) const
Unsigned less than comparison.
Definition:APInt.h:1111
llvm::APInt::getSignedMaxValue
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
Definition:APInt.h:209
llvm::APInt::isNegative
bool isNegative() const
Determine sign of this APInt.
Definition:APInt.h:329
llvm::APInt::sdiv
APInt sdiv(const APInt &RHS) const
Signed division function for APInt.
Definition:APInt.cpp:1618
llvm::APInt::clearAllBits
void clearAllBits()
Set every bit to 0.
Definition:APInt.h:1397
llvm::APInt::rotr
APInt rotr(unsigned rotateAmt) const
Rotate right by rotateAmt.
Definition:APInt.cpp:1128
llvm::APInt::reverseBits
APInt reverseBits() const
Definition:APInt.cpp:741
llvm::APInt::ashrInPlace
void ashrInPlace(unsigned ShiftAmt)
Arithmetic right-shift this APInt by ShiftAmt in place.
Definition:APInt.h:834
llvm::APInt::sle
bool sle(const APInt &RHS) const
Signed less or equal comparison.
Definition:APInt.h:1166
llvm::APInt::countr_zero
unsigned countr_zero() const
Count the number of trailing zero bits.
Definition:APInt.h:1618
llvm::APInt::getNumSignBits
unsigned getNumSignBits() const
Computes the number of leading bits of this APInt that are equal to its sign bit.
Definition:APInt.h:1607
llvm::APInt::countl_zero
unsigned countl_zero() const
The APInt version of std::countl_zero.
Definition:APInt.h:1577
llvm::APInt::getSplat
static APInt getSplat(unsigned NewLen, const APInt &V)
Return a value containing V broadcasted over NewLen bits.
Definition:APInt.cpp:624
llvm::APInt::getSignedMinValue
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
Definition:APInt.h:219
llvm::APInt::sshl_sat
APInt sshl_sat(const APInt &RHS) const
Definition:APInt.cpp:2060
llvm::APInt::ushl_sat
APInt ushl_sat(const APInt &RHS) const
Definition:APInt.cpp:2074
llvm::APInt::sextOrTrunc
APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
Definition:APInt.cpp:1015
llvm::APInt::rotl
APInt rotl(unsigned rotateAmt) const
Rotate left by rotateAmt.
Definition:APInt.cpp:1115
llvm::APInt::insertBits
void insertBits(const APInt &SubBits, unsigned bitPosition)
Insert the bits from a smaller APInt starting at bitPosition.
Definition:APInt.cpp:370
llvm::APInt::clearLowBits
void clearLowBits(unsigned loBits)
Set bottom loBits bits to 0.
Definition:APInt.h:1417
llvm::APInt::logBase2
unsigned logBase2() const
Definition:APInt.h:1739
llvm::APInt::uadd_sat
APInt uadd_sat(const APInt &RHS) const
Definition:APInt.cpp:2010
llvm::APInt::ashr
APInt ashr(unsigned ShiftAmt) const
Arithmetic right-shift function.
Definition:APInt.h:827
llvm::APInt::setAllBits
void setAllBits()
Set every bit to 1.
Definition:APInt.h:1319
llvm::APInt::srem
APInt srem(const APInt &RHS) const
Function for signed remainder operation.
Definition:APInt.cpp:1710
llvm::APInt::isNonNegative
bool isNonNegative() const
Determine if this APInt Value is non-negative (>= 0)
Definition:APInt.h:334
llvm::APInt::ule
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
Definition:APInt.h:1150
llvm::APInt::sext
APInt sext(unsigned width) const
Sign extend to a new width.
Definition:APInt.cpp:959
llvm::APInt::setBits
void setBits(unsigned loBit, unsigned hiBit)
Set the bits from loBit (inclusive) to hiBit (exclusive) to 1.
Definition:APInt.h:1367
llvm::APInt::shl
APInt shl(unsigned shiftAmt) const
Left-shift function.
Definition:APInt.h:873
llvm::APInt::byteSwap
APInt byteSwap() const
Definition:APInt.cpp:719
llvm::APInt::isSubsetOf
bool isSubsetOf(const APInt &RHS) const
This operation checks that all bits set in this APInt are also set in RHS.
Definition:APInt.h:1257
llvm::APInt::isPowerOf2
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
Definition:APInt.h:440
llvm::APInt::getLowBitsSet
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Constructs an APInt value that has the bottom loBitsSet bits set.
Definition:APInt.h:306
llvm::APInt::getZero
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
Definition:APInt.h:200
llvm::APInt::setLowBits
void setLowBits(unsigned loBits)
Set the bottom loBits bits.
Definition:APInt.h:1389
llvm::APInt::extractBits
APInt extractBits(unsigned numBits, unsigned bitPosition) const
Return an APInt with the extracted bits [bitPosition,bitPosition+numBits).
Definition:APInt.cpp:455
llvm::APInt::sge
bool sge(const APInt &RHS) const
Signed greater or equal comparison.
Definition:APInt.h:1237
llvm::APInt::isOne
bool isOne() const
Determine if this is a value of 1.
Definition:APInt.h:389
llvm::APInt::getBitsSetFrom
static APInt getBitsSetFrom(unsigned numBits, unsigned loBit)
Constructs an APInt value that has a contiguous range of bits set.
Definition:APInt.h:286
llvm::APInt::getOneBitSet
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
Definition:APInt.h:239
llvm::APInt::lshrInPlace
void lshrInPlace(unsigned ShiftAmt)
Logical right-shift this APInt by ShiftAmt in place.
Definition:APInt.h:858
llvm::APInt::lshr
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
Definition:APInt.h:851
llvm::APInt::uge
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
Definition:APInt.h:1221
llvm::APInt::ssub_sat
APInt ssub_sat(const APInt &RHS) const
Definition:APInt.cpp:2019
llvm::APSInt
An arbitrary precision integer that knows its signedness.
Definition:APSInt.h:23
llvm::AddrSpaceCastSDNode
Definition:SelectionDAGNodes.h:1332
llvm::AddrSpaceCastSDNode::getSrcAddressSpace
unsigned getSrcAddressSpace() const
Definition:SelectionDAGNodes.h:1343
llvm::AddrSpaceCastSDNode::getDestAddressSpace
unsigned getDestAddressSpace() const
Definition:SelectionDAGNodes.h:1344
llvm::ArrayRecycler
Recycle small arrays allocated from a BumpPtrAllocator.
Definition:ArrayRecycler.h:28
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition:ArrayRef.h:41
llvm::ArrayRef::end
iterator end() const
Definition:ArrayRef.h:157
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition:ArrayRef.h:168
llvm::ArrayRef::begin
iterator begin() const
Definition:ArrayRef.h:156
llvm::ArrayRef::empty
bool empty() const
empty - Check if the array is empty.
Definition:ArrayRef.h:163
llvm::ArrayRef::slice
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
Definition:ArrayRef.h:198
llvm::AtomicSDNode
This is an SDNode representing atomic operations.
Definition:SelectionDAGNodes.h:1527
llvm::BaseIndexOffset::match
static BaseIndexOffset match(const SDNode *N, const SelectionDAG &DAG)
Parses tree in N for base, index, offset addresses.
Definition:SelectionDAGAddressAnalysis.cpp:301
llvm::BatchAAResults
This class is a wrapper over an AAResults, and it is intended to be used only when there are no IR ch...
Definition:AliasAnalysis.h:630
llvm::BatchAAResults::pointsToConstantMemory
bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal=false)
Definition:AliasAnalysis.h:643
llvm::BitVector
Definition:BitVector.h:82
llvm::BitVector::reset
BitVector & reset()
Definition:BitVector.h:392
llvm::BitVector::resize
void resize(unsigned N, bool t=false)
resize - Grow or shrink the bitvector.
Definition:BitVector.h:341
llvm::BitVector::clear
void clear()
clear - Removes all bits from the bitvector.
Definition:BitVector.h:335
llvm::BitVector::set
BitVector & set()
Definition:BitVector.h:351
llvm::BitVector::none
bool none() const
none - Returns true if none of the bits are set.
Definition:BitVector.h:188
llvm::BitVector::size
size_type size() const
size - Returns the number of bits in this bitvector.
Definition:BitVector.h:159
llvm::BlockAddressSDNode
Definition:SelectionDAGNodes.h:2314
llvm::BlockAddressSDNode::getOffset
int64_t getOffset() const
Definition:SelectionDAGNodes.h:2328
llvm::BlockAddressSDNode::getTargetFlags
unsigned getTargetFlags() const
Definition:SelectionDAGNodes.h:2329
llvm::BlockAddressSDNode::getBlockAddress
const BlockAddress * getBlockAddress() const
Definition:SelectionDAGNodes.h:2327
llvm::BlockAddress
The address of a basic block.
Definition:Constants.h:893
llvm::BlockFrequencyInfo
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Definition:BlockFrequencyInfo.h:37
llvm::BuildVectorSDNode
A "pseudo-class" with methods for operating on BUILD_VECTORs.
Definition:SelectionDAGNodes.h:2107
llvm::BuildVectorSDNode::getConstantRawBits
bool getConstantRawBits(bool IsLittleEndian, unsigned DstEltSizeInBits, SmallVectorImpl< APInt > &RawBitElements, BitVector &UndefElements) const
Extract the raw bit data from a build vector of Undef, Constant or ConstantFP node elements.
Definition:SelectionDAG.cpp:13290
llvm::BuildVectorSDNode::recastRawBits
static void recastRawBits(bool IsLittleEndian, unsigned DstEltSizeInBits, SmallVectorImpl< APInt > &DstBitElements, ArrayRef< APInt > SrcBitElements, BitVector &DstUndefElements, const BitVector &SrcUndefElements)
Recast bit data SrcBitElements to DstEltSizeInBits wide elements.
Definition:SelectionDAG.cpp:13326
llvm::BuildVectorSDNode::getRepeatedSequence
bool getRepeatedSequence(const APInt &DemandedElts, SmallVectorImpl< SDValue > &Sequence, BitVector *UndefElements=nullptr) const
Find the shortest repeating sequence of values in the build vector.
Definition:SelectionDAG.cpp:13196
llvm::BuildVectorSDNode::getConstantFPSplatNode
ConstantFPSDNode * getConstantFPSplatNode(const APInt &DemandedElts, BitVector *UndefElements=nullptr) const
Returns the demanded splatted constant FP or null if this is not a constant FP splat.
Definition:SelectionDAG.cpp:13261
llvm::BuildVectorSDNode::isConstantSequence
std::optional< std::pair< APInt, APInt > > isConstantSequence() const
If this BuildVector is constant and represents the numerical series "<a, a+n, a+2n,...
Definition:SelectionDAG.cpp:13390
llvm::BuildVectorSDNode::getSplatValue
SDValue getSplatValue(const APInt &DemandedElts, BitVector *UndefElements=nullptr) const
Returns the demanded splatted value or a null value if this is not a splat.
Definition:SelectionDAG.cpp:13156
llvm::BuildVectorSDNode::isConstantSplat
bool isConstantSplat(APInt &SplatValue, APInt &SplatUndef, unsigned &SplatBitSize, bool &HasAnyUndefs, unsigned MinSplatBits=0, bool isBigEndian=false) const
Check if this is a constant splat, and if so, find the smallest element size that splats the vector.
Definition:SelectionDAG.cpp:13080
llvm::BuildVectorSDNode::getConstantSplatNode
ConstantSDNode * getConstantSplatNode(const APInt &DemandedElts, BitVector *UndefElements=nullptr) const
Returns the demanded splatted constant or null if this is not a constant splat.
Definition:SelectionDAG.cpp:13249
llvm::BuildVectorSDNode::getConstantFPSplatPow2ToLog2Int
int32_t getConstantFPSplatPow2ToLog2Int(BitVector *UndefElements, uint32_t BitWidth) const
If this is a constant FP splat and the splatted constant FP is an exact power or 2,...
Definition:SelectionDAG.cpp:13273
llvm::BuildVectorSDNode::isConstant
bool isConstant() const
Definition:SelectionDAG.cpp:13380
llvm::BumpPtrAllocatorImpl::Allocate
LLVM_ATTRIBUTE_RETURNS_NONNULL void * Allocate(size_t Size, Align Alignment)
Allocate space at the specified alignment.
Definition:Allocator.h:148
llvm::BumpPtrAllocatorImpl::Reset
void Reset()
Deallocate all but the current slab and reset the current pointer to the beginning of it,...
Definition:Allocator.h:123
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition:Instructions.h:1479
llvm::CallInst::isTailCall
bool isTailCall() const
Definition:Instructions.h:1589
llvm::ConstantFPSDNode
Definition:SelectionDAGNodes.h:1739
llvm::ConstantFPSDNode::isValueValidForType
static bool isValueValidForType(EVT VT, const APFloat &Val)
Definition:SelectionDAG.cpp:137
llvm::ConstantFPSDNode::getValueAPF
const APFloat & getValueAPF() const
Definition:SelectionDAGNodes.h:1752
llvm::ConstantFPSDNode::isExactlyValue
bool isExactlyValue(double V) const
We don't rely on operator== working on double values, as it returns true for things that are clearly ...
Definition:SelectionDAGNodes.h:1775
llvm::ConstantFP
ConstantFP - Floating Point Values [float, double].
Definition:Constants.h:271
llvm::ConstantFP::getValue
const APFloat & getValue() const
Definition:Constants.h:315
llvm::ConstantInt
This is the shared class of boolean and integer constants.
Definition:Constants.h:83
llvm::ConstantInt::getBitWidth
unsigned getBitWidth() const
getBitWidth - Return the scalar bitwidth of this constant.
Definition:Constants.h:151
llvm::ConstantInt::getValue
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition:Constants.h:148
llvm::ConstantPoolSDNode
Definition:SelectionDAGNodes.h:2002
llvm::ConstantPoolSDNode::isMachineConstantPoolEntry
bool isMachineConstantPoolEntry() const
Definition:SelectionDAGNodes.h:2033
llvm::ConstantPoolSDNode::getType
Type * getType() const
Definition:SelectionDAG.cpp:13074
llvm::ConstantRange
This class represents a range of values.
Definition:ConstantRange.h:47
llvm::ConstantRange::multiply
ConstantRange multiply(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a multiplication of a value in thi...
Definition:ConstantRange.cpp:1164
llvm::ConstantRange::getSingleElement
const APInt * getSingleElement() const
If this set contains a single element, return it, otherwise return null.
Definition:ConstantRange.h:251
llvm::ConstantRange::fromKnownBits
static ConstantRange fromKnownBits(const KnownBits &Known, bool IsSigned)
Initialize a range based on a known bits constraint.
Definition:ConstantRange.cpp:60
llvm::ConstantRange::unsignedSubMayOverflow
OverflowResult unsignedSubMayOverflow(const ConstantRange &Other) const
Return whether unsigned sub of the two ranges always/never overflows.
Definition:ConstantRange.cpp:2183
llvm::ConstantRange::unsignedAddMayOverflow
OverflowResult unsignedAddMayOverflow(const ConstantRange &Other) const
Return whether unsigned add of the two ranges always/never overflows.
Definition:ConstantRange.cpp:2137
llvm::ConstantRange::toKnownBits
KnownBits toKnownBits() const
Return known bits for values in this range.
Definition:ConstantRange.cpp:80
llvm::ConstantRange::zeroExtend
ConstantRange zeroExtend(uint32_t BitWidth) const
Return a new range in the specified integer type, which must be strictly larger than the current type...
Definition:ConstantRange.cpp:829
llvm::ConstantRange::getSignedMin
APInt getSignedMin() const
Return the smallest signed value contained in the ConstantRange.
Definition:ConstantRange.cpp:501
llvm::ConstantRange::unsignedMulMayOverflow
OverflowResult unsignedMulMayOverflow(const ConstantRange &Other) const
Return whether unsigned mul of the two ranges always/never overflows.
Definition:ConstantRange.cpp:2229
llvm::ConstantRange::signExtend
ConstantRange signExtend(uint32_t BitWidth) const
Return a new range in the specified integer type, which must be strictly larger than the current type...
Definition:ConstantRange.cpp:846
llvm::ConstantRange::contains
bool contains(const APInt &Val) const
Return true if the specified value is in the set.
Definition:ConstantRange.cpp:507
llvm::ConstantRange::getUnsignedMax
APInt getUnsignedMax() const
Return the largest unsigned value contained in the ConstantRange.
Definition:ConstantRange.cpp:483
llvm::ConstantRange::getSignedMax
APInt getSignedMax() const
Return the largest signed value contained in the ConstantRange.
Definition:ConstantRange.cpp:495
llvm::ConstantRange::OverflowResult
OverflowResult
Represents whether an operation on the given constant range is known to always or never overflow.
Definition:ConstantRange.h:567
llvm::ConstantRange::OverflowResult::NeverOverflows
@ NeverOverflows
Never overflows.
llvm::ConstantRange::OverflowResult::AlwaysOverflowsHigh
@ AlwaysOverflowsHigh
Always overflows in the direction of signed/unsigned max value.
llvm::ConstantRange::OverflowResult::AlwaysOverflowsLow
@ AlwaysOverflowsLow
Always overflows in the direction of signed/unsigned min value.
llvm::ConstantRange::OverflowResult::MayOverflow
@ MayOverflow
May or may not overflow.
llvm::ConstantRange::getBitWidth
uint32_t getBitWidth() const
Get the bit width of this ConstantRange.
Definition:ConstantRange.h:209
llvm::ConstantRange::signedSubMayOverflow
OverflowResult signedSubMayOverflow(const ConstantRange &Other) const
Return whether signed sub of the two ranges always/never overflows.
Definition:ConstantRange.cpp:2199
llvm::ConstantSDNode
Definition:SelectionDAGNodes.h:1684
llvm::ConstantSDNode::getZExtValue
uint64_t getZExtValue() const
Definition:SelectionDAGNodes.h:1701
llvm::ConstantSDNode::getAPIntValue
const APInt & getAPIntValue() const
Definition:SelectionDAGNodes.h:1700
llvm::ConstantSDNode::isZero
bool isZero() const
Definition:SelectionDAGNodes.h:1710
llvm::ConstantSDNode::isAllOnes
bool isAllOnes() const
Definition:SelectionDAGNodes.h:1711
llvm::Constant
This is an important base class in LLVM.
Definition:Constant.h:42
llvm::Constant::getSplatValue
Constant * getSplatValue(bool AllowPoison=false) const
If all elements of the vector constant have the same value, return that value.
Definition:Constants.cpp:1708
llvm::Constant::getAggregateElement
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
Definition:Constants.cpp:435
llvm::DIExpression
DWARF expression.
Definition:DebugInfoMetadata.h:2763
llvm::DIExpression::getExtOps
static ExtOps getExtOps(unsigned FromSize, unsigned ToSize, bool Signed)
Returns the ops for a zero- or sign-extension in a DIExpression.
Definition:DebugInfoMetadata.cpp:2243
llvm::DIExpression::appendOffset
static void appendOffset(SmallVectorImpl< uint64_t > &Ops, int64_t Offset)
Append Ops with operations to apply the Offset.
Definition:DebugInfoMetadata.cpp:1721
llvm::DIExpression::appendOpsToArg
static DIExpression * appendOpsToArg(const DIExpression *Expr, ArrayRef< uint64_t > Ops, unsigned ArgNo, bool StackValue=false)
Create a copy of Expr by appending the given list of Ops to each instance of the operand DW_OP_LLVM_a...
Definition:DebugInfoMetadata.cpp:1858
llvm::DIExpression::convertToVariadicExpression
static const DIExpression * convertToVariadicExpression(const DIExpression *Expr)
If Expr is a non-variadic expression (i.e.
Definition:DebugInfoMetadata.cpp:1611
llvm::DIExpression::createFragmentExpression
static std::optional< DIExpression * > createFragmentExpression(const DIExpression *Expr, unsigned OffsetInBits, unsigned SizeInBits)
Create a DIExpression to describe one part of an aggregate variable that is fragmented across multipl...
Definition:DebugInfoMetadata.cpp:2006
llvm::DILabel
Label.
Definition:DebugInfoMetadata.h:3551
llvm::DIVariable
Base class for variables.
Definition:DebugInfoMetadata.h:2698
llvm::DWARFExpression::Operation
This class represents an Operation in the Expression.
Definition:DWARFExpression.h:32
llvm::DWARFExpression::Operation::getNumOperands
uint64_t getNumOperands() const
Definition:DWARFExpression.h:90
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition:DataLayout.h:63
llvm::DataLayout::isLittleEndian
bool isLittleEndian() const
Layout endianness...
Definition:DataLayout.h:197
llvm::DataLayout::getIntPtrType
IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
Returns an integer type with size at least as big as that of a pointer in the given address space.
Definition:DataLayout.cpp:851
llvm::DataLayout::getABITypeAlign
Align getABITypeAlign(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
Definition:DataLayout.cpp:843
llvm::DataLayout::getPointerTypeSizeInBits
unsigned getPointerTypeSizeInBits(Type *) const
Layout pointer size, in bits, based on the type.
Definition:DataLayout.cpp:743
llvm::DataLayout::getPrefTypeAlign
Align getPrefTypeAlign(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
Definition:DataLayout.cpp:847
llvm::DebugLoc
A debug info location.
Definition:DebugLoc.h:33
llvm::DenseMapBase::reserve
void reserve(size_type NumEntries)
Grow the densemap so that it can contain at least NumEntries items before resizing again.
Definition:DenseMap.h:103
llvm::DenseMapIterator
Definition:DenseMap.h:1189
llvm::DenseMap
Definition:DenseMap.h:727
llvm::DenseSet
Implements a dense probed hash-table based set.
Definition:DenseSet.h:278
llvm::ElementCount
Definition:TypeSize.h:300
llvm::ExternalSymbolSDNode
Definition:SelectionDAGNodes.h:2356
llvm::ExternalSymbolSDNode::getSymbol
const char * getSymbol() const
Definition:SelectionDAGNodes.h:2369
llvm::ExternalSymbolSDNode::getTargetFlags
unsigned getTargetFlags() const
Definition:SelectionDAGNodes.h:2370
llvm::FoldingSetNodeID
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition:FoldingSet.h:327
llvm::FrameIndexSDNode
Definition:SelectionDAGNodes.h:1904
llvm::FrameIndexSDNode::getIndex
int getIndex() const
Definition:SelectionDAGNodes.h:1915
llvm::FunctionLoweringInfo::MBB
MachineBasicBlock * MBB
MBB - The current block.
Definition:FunctionLoweringInfo.h:158
llvm::FunctionVarLocs
Data structure describing the variable locations in a function.
Definition:AssignmentTrackingAnalysis.h:38
llvm::Function
Definition:Function.h:63
llvm::Function::hasMinSize
bool hasMinSize() const
Optimize this function for minimum size (-Oz).
Definition:Function.h:704
llvm::Function::getAttributes
AttributeList getAttributes() const
Return the attribute list for this Function.
Definition:Function.h:353
llvm::Function::getContext
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
Definition:Function.cpp:369
llvm::GenericUniformityInfo< SSAContext >
llvm::GlobalAddressSDNode
Definition:SelectionDAGNodes.h:1876
llvm::GlobalAddressSDNode::getOffset
int64_t getOffset() const
Definition:SelectionDAGNodes.h:1891
llvm::GlobalAddressSDNode::getAddressSpace
unsigned getAddressSpace() const
Definition:SelectionDAG.cpp:13070
llvm::GlobalAddressSDNode::getTargetFlags
unsigned getTargetFlags() const
Definition:SelectionDAGNodes.h:1892
llvm::GlobalAddressSDNode::getGlobal
const GlobalValue * getGlobal() const
Definition:SelectionDAGNodes.h:1890
llvm::GlobalValue
Definition:GlobalValue.h:48
llvm::GlobalValue::isThreadLocal
bool isThreadLocal() const
If the value is "Thread Local", its value isn't shared by the threads.
Definition:GlobalValue.h:264
llvm::GlobalValue::getAddressSpace
unsigned getAddressSpace() const
Definition:GlobalValue.h:206
llvm::GlobalValue::getParent
Module * getParent()
Get the module that this global value is contained inside of...
Definition:GlobalValue.h:657
llvm::GlobalValue::getType
PointerType * getType() const
Global values are always pointers.
Definition:GlobalValue.h:295
llvm::HandleSDNode
This class is used to form a handle around another node that is persistent and is updated across invo...
Definition:SelectionDAGNodes.h:1308
llvm::HandleSDNode::~HandleSDNode
~HandleSDNode()
Definition:SelectionDAG.cpp:12427
llvm::ICmpInst::compare
static bool compare(const APInt &LHS, const APInt &RHS, ICmpInst::Predicate Pred)
Return result of LHS Pred RHS comparison.
Definition:Instructions.cpp:3745
llvm::LLT::isValid
constexpr bool isValid() const
Definition:LowLevelType.h:145
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition:LLVMContext.h:67
llvm::LifetimeSDNode
This SDNode is used for LIFETIME_START/LIFETIME_END values, which indicate the offet and size that ar...
Definition:SelectionDAGNodes.h:1925
llvm::LoadSDNode
This class is used to represent ISD::LOAD nodes.
Definition:SelectionDAGNodes.h:2464
llvm::LocationSize
Definition:MemoryLocation.h:68
llvm::LocationSize::precise
static LocationSize precise(uint64_t Value)
Definition:MemoryLocation.h:108
llvm::LocationSize::getValue
TypeSize getValue() const
Definition:MemoryLocation.h:170
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition:MCSymbol.h:41
llvm::MDNode
Metadata node.
Definition:Metadata.h:1073
llvm::MVT
Machine Value Type.
Definition:MachineValueType.h:35
llvm::MVT::SimpleValueType
SimpleValueType
Definition:MachineValueType.h:37
llvm::MVT::VALUETYPE_SIZE
@ VALUETYPE_SIZE
Definition:MachineValueType.h:49
llvm::MVT::SimpleTy
SimpleValueType SimpleTy
Definition:MachineValueType.h:55
llvm::MVT::getIntegerVT
static MVT getIntegerVT(unsigned BitWidth)
Definition:MachineValueType.h:441
llvm::MachineBasicBlock
Definition:MachineBasicBlock.h:125
llvm::MachineBasicBlock::getBasicBlock
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
Definition:MachineBasicBlock.h:256
llvm::MachineConstantPoolValue
Abstract base class for all machine specific constantpool value subclasses.
Definition:MachineConstantPool.h:35
llvm::MachineFrameInfo
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
Definition:MachineFrameInfo.h:106
llvm::MachineFrameInfo::CreateStackObject
int CreateStackObject(uint64_t Size, Align Alignment, bool isSpillSlot, const AllocaInst *Alloca=nullptr, uint8_t ID=0)
Create a new statically sized stack object, returning a nonnegative identifier to represent it.
Definition:MachineFrameInfo.cpp:51
llvm::MachineFrameInfo::getObjectAlign
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
Definition:MachineFrameInfo.h:486
llvm::MachineFrameInfo::isFixedObjectIndex
bool isFixedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a fixed stack object.
Definition:MachineFrameInfo.h:700
llvm::MachineFrameInfo::setObjectAlignment
void setObjectAlignment(int ObjectIdx, Align Alignment)
setObjectAlignment - Change the alignment of the specified stack object.
Definition:MachineFrameInfo.h:499
llvm::MachineFunction
Definition:MachineFunction.h:267
llvm::MachineFunction::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Definition:MachineFunction.h:733
llvm::MachineFunction::getMachineMemOperand
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, LLT MemTy, Align base_alignment, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
Definition:MachineFunction.cpp:536
llvm::MachineFunction::getFrameInfo
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
Definition:MachineFunction.h:749
llvm::MachineFunction::getFunction
Function & getFunction()
Return the LLVM function that this machine code represents.
Definition:MachineFunction.h:704
llvm::MachineFunction::getTarget
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Definition:MachineFunction.h:729
llvm::MachineMemOperand
A description of a memory reference used in the backend.
Definition:MachineMemOperand.h:129
llvm::MachineMemOperand::getType
LLT getType() const
Definition:MachineMemOperand.h:253
llvm::MachineMemOperand::getSize
LocationSize getSize() const
Return the size in bytes of the memory reference.
Definition:MachineMemOperand.h:240
llvm::MachineMemOperand::isVolatile
bool isVolatile() const
Definition:MachineMemOperand.h:298
llvm::MachineMemOperand::isNonTemporal
bool isNonTemporal() const
Definition:MachineMemOperand.h:299
llvm::MachineMemOperand::isInvariant
bool isInvariant() const
Definition:MachineMemOperand.h:301
llvm::MachineMemOperand::Flags
Flags
Flags values. These may be or'd together.
Definition:MachineMemOperand.h:132
llvm::MachineMemOperand::MOVolatile
@ MOVolatile
The memory access is volatile.
Definition:MachineMemOperand.h:140
llvm::MachineMemOperand::MODereferenceable
@ MODereferenceable
The memory access is dereferenceable (i.e., doesn't trap).
Definition:MachineMemOperand.h:144
llvm::MachineMemOperand::MOLoad
@ MOLoad
The memory access reads data.
Definition:MachineMemOperand.h:136
llvm::MachineMemOperand::MONone
@ MONone
Definition:MachineMemOperand.h:134
llvm::MachineMemOperand::MOInvariant
@ MOInvariant
The memory access always returns the same value (or traps).
Definition:MachineMemOperand.h:146
llvm::MachineMemOperand::MOStore
@ MOStore
The memory access writes data.
Definition:MachineMemOperand.h:138
llvm::MachineMemOperand::getPointerInfo
const MachinePointerInfo & getPointerInfo() const
Definition:MachineMemOperand.h:204
llvm::MachineMemOperand::getFlags
Flags getFlags() const
Return the raw flags of the source value,.
Definition:MachineMemOperand.h:224
llvm::MachineMemOperand::isDereferenceable
bool isDereferenceable() const
Definition:MachineMemOperand.h:300
llvm::MachineModuleInfo
This class contains meta information specific to a module.
Definition:MachineModuleInfo.h:82
llvm::MachineSDNode
An SDNode that represents everything that will be needed to construct a MachineInstr.
Definition:SelectionDAGNodes.h:3060
llvm::MaskedGatherSDNode
This class is used to represent an MGATHER node.
Definition:SelectionDAGNodes.h:2961
llvm::MaskedLoadSDNode
This class is used to represent an MLOAD node.
Definition:SelectionDAGNodes.h:2774
llvm::MaskedScatterSDNode
This class is used to represent an MSCATTER node.
Definition:SelectionDAGNodes.h:2986
llvm::MaskedStoreSDNode
This class is used to represent an MSTORE node.
Definition:SelectionDAGNodes.h:2803
llvm::MemIntrinsicSDNode
This SDNode is used for target intrinsics that touch memory and need an associated MachineMemOperand.
Definition:SelectionDAGNodes.h:1601
llvm::MemSDNode::MemSDNode
MemSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl, SDVTList VTs, EVT memvt, MachineMemOperand *MMO)
Definition:SelectionDAG.cpp:12431
llvm::MemSDNode::MMO
MachineMemOperand * MMO
Memory reference information.
Definition:SelectionDAGNodes.h:1359
llvm::MemSDNode::getMemOperand
MachineMemOperand * getMemOperand() const
Return a MachineMemOperand object describing the memory reference performed by operation.
Definition:SelectionDAGNodes.h:1436
llvm::MemSDNode::getPointerInfo
const MachinePointerInfo & getPointerInfo() const
Definition:SelectionDAGNodes.h:1438
llvm::MemSDNode::getRawSubclassData
unsigned getRawSubclassData() const
Return the SubclassData value, without HasDebugValue.
Definition:SelectionDAGNodes.h:1378
llvm::MemSDNode::getMemoryVT
EVT getMemoryVT() const
Return the type of the in-memory value.
Definition:SelectionDAGNodes.h:1432
llvm::MemoryLocation
Representation for a specific memory location.
Definition:MemoryLocation.h:227
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition:Module.h:65
llvm::Module::getFunction
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
Definition:Module.cpp:228
llvm::MutableArrayRef
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition:ArrayRef.h:310
llvm::OptimizationRemarkEmitter
The optimization diagnostic interface.
Definition:OptimizationRemarkEmitter.h:32
llvm::Pass
Pass interface - Implemented by all 'passes'.
Definition:Pass.h:94
llvm::PointerType::get
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
llvm::PointerType::getUnqual
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
Definition:DerivedTypes.h:686
llvm::PointerType::getAddressSpace
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Definition:DerivedTypes.h:703
llvm::PointerUnion::isNull
bool isNull() const
Test if the pointer held in the union is null, regardless of which type it is.
Definition:PointerUnion.h:142
llvm::ProfileSummaryInfo
Analysis providing profile information.
Definition:ProfileSummaryInfo.h:41
llvm::RecyclingAllocator::Deallocate
void Deallocate(SubClass *E)
Deallocate - Release storage for the pointed-to object.
Definition:RecyclingAllocator.h:51
llvm::Register
Wrapper class representing virtual and physical registers.
Definition:Register.h:19
llvm::SDDbgInfo
Keeps track of dbg_value information through SDISel.
Definition:SelectionDAG.h:162
llvm::SDDbgInfo::getAlloc
BumpPtrAllocator & getAlloc()
Definition:SelectionDAG.h:191
llvm::SDDbgInfo::add
void add(SDDbgValue *V, bool isParameter)
Definition:SelectionDAG.cpp:1115
llvm::SDDbgInfo::clear
void clear()
Definition:SelectionDAG.h:183
llvm::SDDbgInfo::erase
void erase(const SDNode *Node)
Invalidate all DbgValues attached to the node and remove it from the Node-to-DbgValues map.
Definition:SelectionDAG.cpp:1126
llvm::SDDbgInfo::getSDDbgValues
ArrayRef< SDDbgValue * > getSDDbgValues(const SDNode *Node) const
Definition:SelectionDAG.h:197
llvm::SDDbgLabel
Holds the information from a dbg_label node through SDISel.
Definition:SDNodeDbgValue.h:242
llvm::SDDbgOperand
Holds the information for a single machine location through SDISel; either an SDNode,...
Definition:SDNodeDbgValue.h:31
llvm::SDDbgOperand::fromNode
static SDDbgOperand fromNode(SDNode *Node, unsigned ResNo)
Definition:SDNodeDbgValue.h:71
llvm::SDDbgOperand::fromFrameIdx
static SDDbgOperand fromFrameIdx(unsigned FrameIdx)
Definition:SDNodeDbgValue.h:74
llvm::SDDbgOperand::fromVReg
static SDDbgOperand fromVReg(unsigned VReg)
Definition:SDNodeDbgValue.h:77
llvm::SDDbgOperand::fromConst
static SDDbgOperand fromConst(const Value *Const)
Definition:SDNodeDbgValue.h:80
llvm::SDDbgOperand::SDNODE
@ SDNODE
Value is the result of an expression.
Definition:SDNodeDbgValue.h:34
llvm::SDDbgValue
Holds the information from a dbg_value node through SDISel.
Definition:SDNodeDbgValue.h:133
llvm::SDLoc
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Definition:SelectionDAGNodes.h:1182
llvm::SDLoc::getDebugLoc
const DebugLoc & getDebugLoc() const
Definition:SelectionDAGNodes.h:1198
llvm::SDLoc::getIROrder
unsigned getIROrder() const
Definition:SelectionDAGNodes.h:1197
llvm::SDNode::use_iterator
This class provides iterator support for SDUse operands that use a specific SDNode.
Definition:SelectionDAGNodes.h:772
llvm::SDNode
Represents one node in the SelectionDAG.
Definition:SelectionDAGNodes.h:496
llvm::SDNode::ops
ArrayRef< SDUse > ops() const
Definition:SelectionDAGNodes.h:1001
llvm::SDNode::getAsAPIntVal
const APInt & getAsAPIntVal() const
Helper method returns the APInt value of a ConstantSDNode.
Definition:SelectionDAGNodes.h:1735
llvm::SDNode::dumprFull
void dumprFull(const SelectionDAG *G=nullptr) const
printrFull to dbgs().
Definition:SelectionDAGDumper.cpp:1167
llvm::SDNode::getOpcode
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
Definition:SelectionDAGNodes.h:687
llvm::SDNode::isDivergent
bool isDivergent() const
Definition:SelectionDAGNodes.h:733
llvm::SDNode::isOnlyUserOf
bool isOnlyUserOf(const SDNode *N) const
Return true if this node is the only use of N.
Definition:SelectionDAG.cpp:12509
llvm::SDNode::op_values
iterator_range< value_op_iterator > op_values() const
Definition:SelectionDAGNodes.h:1015
llvm::SDNode::getIROrder
unsigned getIROrder() const
Return the node ordering.
Definition:SelectionDAGNodes.h:758
llvm::SDNode::getMaxNumOperands
static constexpr size_t getMaxNumOperands()
Return the maximum number of operands that a SDNode can hold.
Definition:SelectionDAGNodes.h:976
llvm::SDNode::uses
iterator_range< use_iterator > uses()
Definition:SelectionDAGNodes.h:859
llvm::SDNode::MemSDNodeBits
MemSDNodeBitfields MemSDNodeBits
Definition:SelectionDAGNodes.h:609
llvm::SDNode::Profile
void Profile(FoldingSetNodeID &ID) const
Gather unique data for the node.
Definition:SelectionDAG.cpp:12450
llvm::SDNode::getHasDebugValue
bool getHasDebugValue() const
Definition:SelectionDAGNodes.h:730
llvm::SDNode::getFlags
SDNodeFlags getFlags() const
Definition:SelectionDAGNodes.h:1043
llvm::SDNode::setNodeId
void setNodeId(int Id)
Set unique node id.
Definition:SelectionDAGNodes.h:749
llvm::SDNode::intersectFlagsWith
void intersectFlagsWith(const SDNodeFlags Flags)
Clear any flags in this node that aren't also set in Flags.
Definition:SelectionDAG.cpp:12599
llvm::SDNode::hasPredecessorHelper
static bool hasPredecessorHelper(const SDNode *N, SmallPtrSetImpl< const SDNode * > &Visited, SmallVectorImpl< const SDNode * > &Worklist, unsigned int MaxSteps=0, bool TopologicalPrune=false)
Returns true if N is a predecessor of any node in Worklist.
Definition:SelectionDAGNodes.h:914
llvm::SDNode::getAsZExtVal
uint64_t getAsZExtVal() const
Helper method returns the zero-extended integer value of a ConstantSDNode.
Definition:SelectionDAGNodes.h:1727
llvm::SDNode::use_empty
bool use_empty() const
Return true if there are no uses of this node.
Definition:SelectionDAGNodes.h:736
llvm::SDNode::getNumValues
unsigned getNumValues() const
Return the number of values defined/returned by this operator.
Definition:SelectionDAGNodes.h:1059
llvm::SDNode::getNumOperands
unsigned getNumOperands() const
Return the number of values used by this operation.
Definition:SelectionDAGNodes.h:973
llvm::SDNode::getOperand
const SDValue & getOperand(unsigned Num) const
Definition:SelectionDAGNodes.h:992
llvm::SDNode::areOnlyUsersOf
static bool areOnlyUsersOf(ArrayRef< const SDNode * > Nodes, const SDNode *N)
Return true if all the users of N are contained in Nodes.
Definition:SelectionDAG.cpp:12522
llvm::SDNode::isOperandOf
bool isOperandOf(const SDNode *N) const
Return true if this node is an operand of N.
Definition:SelectionDAG.cpp:12539
llvm::SDNode::getConstantOperandAPInt
const APInt & getConstantOperandAPInt(unsigned Num) const
Helper method returns the APInt of a ConstantSDNode operand.
Definition:SelectionDAGNodes.h:1731
llvm::SDNode::hasPredecessor
bool hasPredecessor(const SDNode *N) const
Return true if N is a predecessor of this node.
Definition:SelectionDAG.cpp:12592
llvm::SDNode::hasAnyUseOfValue
bool hasAnyUseOfValue(unsigned Value) const
Return true if there are any use of the indicated value.
Definition:SelectionDAG.cpp:12498
llvm::SDNode::getValueType
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
Definition:SelectionDAGNodes.h:1062
llvm::SDNode::isUndef
bool isUndef() const
Return true if the type of the node type undefined.
Definition:SelectionDAGNodes.h:694
llvm::SDNode::hasNUsesOfValue
bool hasNUsesOfValue(unsigned NUses, unsigned Value) const
Return true if there are exactly NUSES uses of the indicated value.
Definition:SelectionDAG.cpp:12480
llvm::SDNode::op_end
op_iterator op_end() const
Definition:SelectionDAGNodes.h:1000
llvm::SDNode::op_begin
op_iterator op_begin() const
Definition:SelectionDAGNodes.h:999
llvm::SDNode::DropOperands
void DropOperands()
Release the operands and set this node to have zero operands.
Definition:SelectionDAG.cpp:10908
llvm::SDUse
Represents a use of a SDNode.
Definition:SelectionDAGNodes.h:283
llvm::SDUse::getValueType
EVT getValueType() const
Convenience function for get().getValueType().
Definition:SelectionDAGNodes.h:320
llvm::SDUse::getUser
SDNode * getUser()
This returns the SDNode that contains this Use.
Definition:SelectionDAGNodes.h:306
llvm::SDVTListNode
Definition:SelectionDAG.h:99
llvm::SDValue
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
Definition:SelectionDAGNodes.h:145
llvm::SDValue::isUndef
bool isUndef() const
Definition:SelectionDAGNodes.h:1249
llvm::SDValue::getNode
SDNode * getNode() const
get the SDNode which holds the desired result
Definition:SelectionDAGNodes.h:159
llvm::SDValue::hasOneUse
bool hasOneUse() const
Return true if there is exactly one node using value ResNo of Node.
Definition:SelectionDAGNodes.h:1257
llvm::SDValue::isOperandOf
bool isOperandOf(const SDNode *N) const
Return true if this node is an operand of N.
Definition:SelectionDAG.cpp:12535
llvm::SDValue::reachesChainWithoutSideEffects
bool reachesChainWithoutSideEffects(SDValue Dest, unsigned Depth=2) const
Return true if this operand (which must be a chain) reaches the specified operand without crossing an...
Definition:SelectionDAG.cpp:12554
llvm::SDValue::getValue
SDValue getValue(unsigned R) const
Definition:SelectionDAGNodes.h:179
llvm::SDValue::getValueType
EVT getValueType() const
Return the ValueType of the referenced return value.
Definition:SelectionDAGNodes.h:1217
llvm::SDValue::getValueSizeInBits
TypeSize getValueSizeInBits() const
Returns the size of the value in bits.
Definition:SelectionDAGNodes.h:199
llvm::SDValue::getOperand
const SDValue & getOperand(unsigned i) const
Definition:SelectionDAGNodes.h:1225
llvm::SDValue::use_empty
bool use_empty() const
Return true if there are no nodes using value ResNo of Node.
Definition:SelectionDAGNodes.h:1253
llvm::SDValue::getConstantOperandAPInt
const APInt & getConstantOperandAPInt(unsigned i) const
Definition:SelectionDAGNodes.h:1233
llvm::SDValue::getScalarValueSizeInBits
uint64_t getScalarValueSizeInBits() const
Definition:SelectionDAGNodes.h:203
llvm::SDValue::getResNo
unsigned getResNo() const
get the index which selects a specific result in the SDNode
Definition:SelectionDAGNodes.h:156
llvm::SDValue::getConstantOperandVal
uint64_t getConstantOperandVal(unsigned i) const
Definition:SelectionDAGNodes.h:1229
llvm::SDValue::getOpcode
unsigned getOpcode() const
Definition:SelectionDAGNodes.h:1213
llvm::SelectionDAGTargetInfo::isTargetMemoryOpcode
virtual bool isTargetMemoryOpcode(unsigned Opcode) const
Returns true if a node with the given target-specific opcode has a memory operand.
Definition:SelectionDAGTargetInfo.h:41
llvm::SelectionDAGTargetInfo::EmitTargetCodeForMemset
virtual SDValue EmitTargetCodeForMemset(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Op1, SDValue Op2, SDValue Op3, Align Alignment, bool isVolatile, bool AlwaysInline, MachinePointerInfo DstPtrInfo) const
Emit target-specific code that performs a memset.
Definition:SelectionDAGTargetInfo.h:94
llvm::SelectionDAGTargetInfo::EmitTargetCodeForMemmove
virtual SDValue EmitTargetCodeForMemmove(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Op1, SDValue Op2, SDValue Op3, Align Alignment, bool isVolatile, MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const
Emit target-specific code that performs a memmove.
Definition:SelectionDAGTargetInfo.h:80
llvm::SelectionDAGTargetInfo::EmitTargetCodeForMemcpy
virtual SDValue EmitTargetCodeForMemcpy(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Op1, SDValue Op2, SDValue Op3, Align Alignment, bool isVolatile, bool AlwaysInline, MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const
Emit target-specific code that performs a memcpy.
Definition:SelectionDAGTargetInfo.h:64
llvm::SelectionDAG::FlagInserter::getFlags
SDNodeFlags getFlags() const
Definition:SelectionDAG.h:389
llvm::SelectionDAG
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Definition:SelectionDAG.h:228
llvm::SelectionDAG::getReducedAlign
Align getReducedAlign(EVT VT, bool UseABI)
In most cases this function returns the ABI alignment for a given type, except for illegal vector typ...
Definition:SelectionDAG.cpp:2743
llvm::SelectionDAG::getVPZeroExtendInReg
SDValue getVPZeroExtendInReg(SDValue Op, SDValue Mask, SDValue EVL, const SDLoc &DL, EVT VT)
Return the expression required to zero extend the Op value assuming it was the smaller SrcTy value.
Definition:SelectionDAG.cpp:1586
llvm::SelectionDAG::getShiftAmountOperand
SDValue getShiftAmountOperand(EVT LHSTy, SDValue Op)
Return the specified value casted to the target's desired shift amount type.
Definition:SelectionDAG.cpp:2468
llvm::SelectionDAG::getExtLoad
SDValue getExtLoad(ISD::LoadExtType ExtType, const SDLoc &dl, EVT VT, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, EVT MemVT, MaybeAlign Alignment=MaybeAlign(), MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
Definition:SelectionDAG.cpp:9287
llvm::SelectionDAG::getExtLoadVP
SDValue getExtLoadVP(ISD::LoadExtType ExtType, const SDLoc &dl, EVT VT, SDValue Chain, SDValue Ptr, SDValue Mask, SDValue EVL, MachinePointerInfo PtrInfo, EVT MemVT, MaybeAlign Alignment, MachineMemOperand::Flags MMOFlags, const AAMDNodes &AAInfo, bool IsExpanding=false)
Definition:SelectionDAG.cpp:9546
llvm::SelectionDAG::getSplatSourceVector
SDValue getSplatSourceVector(SDValue V, int &SplatIndex)
If V is a splatted value, return the source vector and its splat index.
Definition:SelectionDAG.cpp:3229
llvm::SelectionDAG::getLabelNode
SDValue getLabelNode(unsigned Opcode, const SDLoc &dl, SDValue Root, MCSymbol *Label)
Definition:SelectionDAG.cpp:2363
llvm::SelectionDAG::computeOverflowForUnsignedSub
OverflowKind computeOverflowForUnsignedSub(SDValue N0, SDValue N1) const
Determine if the result of the unsigned sub of 2 nodes can overflow.
Definition:SelectionDAG.cpp:4590
llvm::SelectionDAG::ComputeMaxSignificantBits
unsigned ComputeMaxSignificantBits(SDValue Op, unsigned Depth=0) const
Get the upper bound on bit size for this Value Op as a signed integer.
Definition:SelectionDAG.cpp:5417
llvm::SelectionDAG::getRoot
const SDValue & getRoot() const
Return the root tag of the SelectionDAG.
Definition:SelectionDAG.h:577
llvm::SelectionDAG::getMaskedGather
SDValue getMaskedGather(SDVTList VTs, EVT MemVT, const SDLoc &dl, ArrayRef< SDValue > Ops, MachineMemOperand *MMO, ISD::MemIndexType IndexType, ISD::LoadExtType ExtTy)
Definition:SelectionDAG.cpp:10040
llvm::SelectionDAG::isKnownNeverSNaN
bool isKnownNeverSNaN(SDValue Op, unsigned Depth=0) const
Definition:SelectionDAG.h:2153
llvm::SelectionDAG::getAddrSpaceCast
SDValue getAddrSpaceCast(const SDLoc &dl, EVT VT, SDValue Ptr, unsigned SrcAS, unsigned DestAS)
Return an AddrSpaceCastSDNode.
Definition:SelectionDAG.cpp:2440
llvm::SelectionDAG::getStackArgumentTokenFactor
SDValue getStackArgumentTokenFactor(SDValue Chain)
Compute a TokenFactor to force all the incoming stack arguments to be loaded from the stack.
Definition:SelectionDAG.cpp:7948
llvm::SelectionDAG::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
Definition:SelectionDAG.h:499
llvm::SelectionDAG::getMergeValues
SDValue getMergeValues(ArrayRef< SDValue > Ops, const SDLoc &dl)
Create a MERGE_VALUES node from the given operands.
Definition:SelectionDAG.cpp:9034
llvm::SelectionDAG::getVTList
SDVTList getVTList(EVT VT)
Return an SDVTList that represents the list of values specified.
Definition:SelectionDAG.cpp:10708
llvm::SelectionDAG::getShiftAmountConstant
SDValue getShiftAmountConstant(uint64_t Val, EVT VT, const SDLoc &DL)
Definition:SelectionDAG.cpp:1811
llvm::SelectionDAG::updateDivergence
void updateDivergence(SDNode *N)
Definition:SelectionDAG.cpp:11943
llvm::SelectionDAG::getSplatValue
SDValue getSplatValue(SDValue V, bool LegalTypes=false)
If V is a splat vector, return its scalar source operand by extracting that element from the source v...
Definition:SelectionDAG.cpp:3281
llvm::SelectionDAG::FoldSetCC
SDValue FoldSetCC(EVT VT, SDValue N1, SDValue N2, ISD::CondCode Cond, const SDLoc &dl)
Constant fold a setcc to true or false.
Definition:SelectionDAG.cpp:2813
llvm::SelectionDAG::getAllOnesConstant
SDValue getAllOnesConstant(const SDLoc &DL, EVT VT, bool IsTarget=false, bool IsOpaque=false)
Definition:SelectionDAG.cpp:1800
llvm::SelectionDAG::getMachineNode
MachineSDNode * getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT)
These are used for target selectors to create a new node with specified return type(s),...
Definition:SelectionDAG.cpp:11149
llvm::SelectionDAG::ExtractVectorElements
void ExtractVectorElements(SDValue Op, SmallVectorImpl< SDValue > &Args, unsigned Start=0, unsigned Count=0, EVT EltVT=EVT())
Append the extracted elements from Start to Count out of the vector Op in Args.
Definition:SelectionDAG.cpp:13053
llvm::SelectionDAG::getNeutralElement
SDValue getNeutralElement(unsigned Opcode, const SDLoc &DL, EVT VT, SDNodeFlags Flags)
Get the (commutative) neutral element for the given opcode, if it exists.
Definition:SelectionDAG.cpp:13545
llvm::SelectionDAG::getAtomicMemset
SDValue getAtomicMemset(SDValue Chain, const SDLoc &dl, SDValue Dst, SDValue Value, SDValue Size, Type *SizeTy, unsigned ElemSz, bool isTailCall, MachinePointerInfo DstPtrInfo)
Definition:SelectionDAG.cpp:8922
llvm::SelectionDAG::getVScale
SDValue getVScale(const SDLoc &DL, EVT VT, APInt MulImm, bool ConstantFold=true)
Return a node that represents the runtime scaling 'MulImm * RuntimeVL'.
Definition:SelectionDAG.cpp:2092
llvm::SelectionDAG::getPseudoProbeNode
SDValue getPseudoProbeNode(const SDLoc &Dl, SDValue Chain, uint64_t Guid, uint64_t Index, uint32_t Attr)
Creates a PseudoProbeSDNode with function GUID Guid and the index of the block Index it is probing,...
Definition:SelectionDAG.cpp:9133
llvm::SelectionDAG::getFreeze
SDValue getFreeze(SDValue V)
Return a freeze using the SDLoc of the value operand.
Definition:SelectionDAG.cpp:2462
llvm::SelectionDAG::SelectNodeTo
SDNode * SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT)
These are used for target selectors to mutate the specified node to have the specified return type,...
Definition:SelectionDAG.cpp:10941
llvm::SelectionDAG::SelectionDAG
SelectionDAG(const TargetMachine &TM, CodeGenOptLevel)
Definition:SelectionDAG.cpp:1366
llvm::SelectionDAG::getMemset
SDValue getMemset(SDValue Chain, const SDLoc &dl, SDValue Dst, SDValue Src, SDValue Size, Align Alignment, bool isVol, bool AlwaysInline, const CallInst *CI, MachinePointerInfo DstPtrInfo, const AAMDNodes &AAInfo=AAMDNodes())
Definition:SelectionDAG.cpp:8824
llvm::SelectionDAG::getBitcastedSExtOrTrunc
SDValue getBitcastedSExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of integer type, to the integer type VT, by first bitcasting (from potentia...
Definition:SelectionDAG.cpp:1529
llvm::SelectionDAG::getConstantPool
SDValue getConstantPool(const Constant *C, EVT VT, MaybeAlign Align=std::nullopt, int Offs=0, bool isT=false, unsigned TargetFlags=0)
Definition:SelectionDAG.cpp:1968
llvm::SelectionDAG::getStridedLoadVP
SDValue getStridedLoadVP(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType, EVT VT, const SDLoc &DL, SDValue Chain, SDValue Ptr, SDValue Offset, SDValue Stride, SDValue Mask, SDValue EVL, EVT MemVT, MachineMemOperand *MMO, bool IsExpanding=false)
Definition:SelectionDAG.cpp:9720
llvm::SelectionDAG::getAtomicCmpSwap
SDValue getAtomicCmpSwap(unsigned Opcode, const SDLoc &dl, EVT MemVT, SDVTList VTs, SDValue Chain, SDValue Ptr, SDValue Cmp, SDValue Swp, MachineMemOperand *MMO)
Gets a node for an atomic cmpxchg op.
Definition:SelectionDAG.cpp:8985
llvm::SelectionDAG::makeEquivalentMemoryOrdering
SDValue makeEquivalentMemoryOrdering(SDValue OldChain, SDValue NewMemOpChain)
If an existing load has uses of its chain, create a token factor node with that chain and the new mem...
Definition:SelectionDAG.cpp:12152
llvm::SelectionDAG::isConstantIntBuildVectorOrConstantInt
bool isConstantIntBuildVectorOrConstantInt(SDValue N, bool AllowOpaques=true) const
Test whether the given value is a constant int or similar node.
Definition:SelectionDAG.cpp:13439
llvm::SelectionDAG::getVRegDbgValue
SDDbgValue * getVRegDbgValue(DIVariable *Var, DIExpression *Expr, unsigned VReg, bool IsIndirect, const DebugLoc &DL, unsigned O)
Creates a VReg SDDbgValue node.
Definition:SelectionDAG.cpp:11377
llvm::SelectionDAG::ReplaceAllUsesOfValuesWith
void ReplaceAllUsesOfValuesWith(const SDValue *From, const SDValue *To, unsigned Num)
Like ReplaceAllUsesOfValueWith, but for multiple values at once.
Definition:SelectionDAG.cpp:11989
llvm::SelectionDAG::getJumpTableDebugInfo
SDValue getJumpTableDebugInfo(int JTI, SDValue Chain, const SDLoc &DL)
Definition:SelectionDAG.cpp:1961
llvm::SelectionDAG::getSetCC
SDValue getSetCC(const SDLoc &DL, EVT VT, SDValue LHS, SDValue RHS, ISD::CondCode Cond, SDValue Chain=SDValue(), bool IsSignaling=false)
Helper function to make it easier to build SetCC's if you just have an ISD::CondCode instead of an SD...
Definition:SelectionDAG.h:1251
llvm::SelectionDAG::getSymbolFunctionGlobalAddress
SDValue getSymbolFunctionGlobalAddress(SDValue Op, Function **TargetFunction=nullptr)
Return a GlobalAddress of the function from the current module with name matching the given ExternalS...
Definition:SelectionDAG.cpp:12178
llvm::SelectionDAG::UnrollVectorOp
SDValue UnrollVectorOp(SDNode *N, unsigned ResNE=0)
Utility function used by legalize and lowering to "unroll" a vector operation by splitting out the sc...
Definition:SelectionDAG.cpp:12720
llvm::SelectionDAG::getConstantFP
SDValue getConstantFP(double Val, const SDLoc &DL, EVT VT, bool isTarget=false)
Create a ConstantFPSDNode wrapping a constant value.
Definition:SelectionDAG.cpp:1873
llvm::SelectionDAG::OverflowKind
OverflowKind
Used to represent the possible overflow behavior of an operation.
Definition:SelectionDAG.h:1980
llvm::SelectionDAG::OFK_Never
@ OFK_Never
Definition:SelectionDAG.h:1981
llvm::SelectionDAG::OFK_Sometime
@ OFK_Sometime
Definition:SelectionDAG.h:1982
llvm::SelectionDAG::OFK_Always
@ OFK_Always
Definition:SelectionDAG.h:1983
llvm::SelectionDAG::getHasPredecessorMaxSteps
static unsigned getHasPredecessorMaxSteps()
Definition:SelectionDAG.cpp:123
llvm::SelectionDAG::haveNoCommonBitsSet
bool haveNoCommonBitsSet(SDValue A, SDValue B) const
Return true if A and B have no common bits set.
Definition:SelectionDAG.cpp:6041
llvm::SelectionDAG::cannotBeOrderedNegativeFP
bool cannotBeOrderedNegativeFP(SDValue Op) const
Test whether the given float value is known to be positive.
Definition:SelectionDAG.cpp:5968
llvm::SelectionDAG::getRegister
SDValue getRegister(Register Reg, EVT VT)
Definition:SelectionDAG.cpp:2328
llvm::SelectionDAG::calculateDivergence
bool calculateDivergence(SDNode *N)
Definition:SelectionDAG.cpp:11924
llvm::SelectionDAG::getElementCount
SDValue getElementCount(const SDLoc &DL, EVT VT, ElementCount EC, bool ConstantFold=true)
Definition:SelectionDAG.cpp:2111
llvm::SelectionDAG::getGetFPEnv
SDValue getGetFPEnv(SDValue Chain, const SDLoc &dl, SDValue Ptr, EVT MemVT, MachineMemOperand *MMO)
Definition:SelectionDAG.cpp:10171
llvm::SelectionDAG::getAssertAlign
SDValue getAssertAlign(const SDLoc &DL, SDValue V, Align A)
Return an AssertAlignSDNode.
Definition:SelectionDAG.cpp:7180
llvm::SelectionDAG::mutateStrictFPToFP
SDNode * mutateStrictFPToFP(SDNode *Node)
Mutate the specified strict FP node to its non-strict equivalent, unlinking the node from its chain a...
Definition:SelectionDAG.cpp:11101
llvm::SelectionDAG::getLoad
SDValue getLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, MaybeAlign Alignment=MaybeAlign(), MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr)
Loads are not normal binary operators: their result type is not determined by their operands,...
Definition:SelectionDAG.cpp:9270
llvm::SelectionDAG::getBitcastedZExtOrTrunc
SDValue getBitcastedZExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of integer type, to the integer type VT, by first bitcasting (from potentia...
Definition:SelectionDAG.cpp:1544
llvm::SelectionDAG::getStepVector
SDValue getStepVector(const SDLoc &DL, EVT ResVT, const APInt &StepVal)
Returns a vector of type ResVT whose elements contain the linear sequence <0, Step,...
Definition:SelectionDAG.cpp:2125
llvm::SelectionDAG::getAtomic
SDValue getAtomic(unsigned Opcode, const SDLoc &dl, EVT MemVT, SDValue Chain, SDValue Ptr, SDValue Val, MachineMemOperand *MMO)
Gets a node for an atomic op, produces result (if relevant) and chain and takes 2 operands.
Definition:SelectionDAG.cpp:8997
llvm::SelectionDAG::getMemcpy
SDValue getMemcpy(SDValue Chain, const SDLoc &dl, SDValue Dst, SDValue Src, SDValue Size, Align Alignment, bool isVol, bool AlwaysInline, const CallInst *CI, std::optional< bool > OverrideTailCall, MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo, const AAMDNodes &AAInfo=AAMDNodes(), BatchAAResults *BatchAA=nullptr)
Definition:SelectionDAG.cpp:8581
llvm::SelectionDAG::getValidMinimumShiftAmount
std::optional< uint64_t > getValidMinimumShiftAmount(SDValue V, const APInt &DemandedElts, unsigned Depth=0) const
If a SHL/SRA/SRL node V has shift amounts that are all less than the element bit-width of the shift n...
Definition:SelectionDAG.cpp:3371
llvm::SelectionDAG::getEVTAlign
Align getEVTAlign(EVT MemoryVT) const
Compute the default alignment value for the given type.
Definition:SelectionDAG.cpp:1358
llvm::SelectionDAG::shouldOptForSize
bool shouldOptForSize() const
Definition:SelectionDAG.cpp:1401
llvm::SelectionDAG::getNOT
SDValue getNOT(const SDLoc &DL, SDValue Val, EVT VT)
Create a bitwise NOT operation as (XOR Val, -1).
Definition:SelectionDAG.cpp:1622
llvm::SelectionDAG::getVPZExtOrTrunc
SDValue getVPZExtOrTrunc(const SDLoc &DL, EVT VT, SDValue Op, SDValue Mask, SDValue EVL)
Convert a vector-predicated Op, which must be an integer vector, to the vector-type VT,...
Definition:SelectionDAG.cpp:1642
llvm::SelectionDAG::getTargetLoweringInfo
const TargetLowering & getTargetLoweringInfo() const
Definition:SelectionDAG.h:503
llvm::SelectionDAG::isEqualTo
bool isEqualTo(SDValue A, SDValue B) const
Test whether two SDValues are known to compare equal.
Definition:SelectionDAG.cpp:5975
llvm::SelectionDAG::MaxRecursionDepth
static constexpr unsigned MaxRecursionDepth
Definition:SelectionDAG.h:458
llvm::SelectionDAG::getStridedStoreVP
SDValue getStridedStoreVP(SDValue Chain, const SDLoc &DL, SDValue Val, SDValue Ptr, SDValue Offset, SDValue Stride, SDValue Mask, SDValue EVL, EVT MemVT, MachineMemOperand *MMO, ISD::MemIndexedMode AM, bool IsTruncating=false, bool IsCompressing=false)
Definition:SelectionDAG.cpp:9773
llvm::SelectionDAG::expandVACopy
SDValue expandVACopy(SDNode *Node)
Expand the specified ISD::VACOPY node as the Legalize pass would.
Definition:SelectionDAG.cpp:2729
llvm::SelectionDAG::getIndexedMaskedLoad
SDValue getIndexedMaskedLoad(SDValue OrigLoad, const SDLoc &dl, SDValue Base, SDValue Offset, ISD::MemIndexedMode AM)
Definition:SelectionDAG.cpp:9980
llvm::SelectionDAG::computeVectorKnownZeroElements
APInt computeVectorKnownZeroElements(SDValue Op, const APInt &DemandedElts, unsigned Depth=0) const
For each demanded element of a vector, see if it is known to be zero.
Definition:SelectionDAG.cpp:3004
llvm::SelectionDAG::AddDbgValue
void AddDbgValue(SDDbgValue *DB, bool isParameter)
Add a dbg_value SDNode.
Definition:SelectionDAG.cpp:12140
llvm::SelectionDAG::NewNodesMustHaveLegalTypes
bool NewNodesMustHaveLegalTypes
When true, additional steps are taken to ensure that getConstant() and similar functions return DAG n...
Definition:SelectionDAG.h:397
llvm::SelectionDAG::GetSplitDestVTs
std::pair< EVT, EVT > GetSplitDestVTs(const EVT &VT) const
Compute the VTs needed for the low/hi parts of a type which is split (or expanded) into two not neces...
Definition:SelectionDAG.cpp:12961
llvm::SelectionDAG::salvageDebugInfo
void salvageDebugInfo(SDNode &N)
To be invoked on an SDNode that is slated to be erased.
Definition:SelectionDAG.cpp:11482
llvm::SelectionDAG::MorphNodeTo
SDNode * MorphNodeTo(SDNode *N, unsigned Opc, SDVTList VTs, ArrayRef< SDValue > Ops)
This mutates the specified node to have the specified return type, opcode, and operands.
Definition:SelectionDAG.cpp:11048
llvm::SelectionDAG::UnrollVectorOverflowOp
std::pair< SDValue, SDValue > UnrollVectorOverflowOp(SDNode *N, unsigned ResNE=0)
Like UnrollVectorOp(), but for the [US](ADD|SUB|MUL)O family of opcodes.
Definition:SelectionDAG.cpp:12832
llvm::SelectionDAG::allnodes_begin
allnodes_const_iterator allnodes_begin() const
Definition:SelectionDAG.h:557
llvm::SelectionDAG::getUNDEF
SDValue getUNDEF(EVT VT)
Return an UNDEF node. UNDEF does not have a useful SDLoc.
Definition:SelectionDAG.h:1129
llvm::SelectionDAG::getGatherVP
SDValue getGatherVP(SDVTList VTs, EVT VT, const SDLoc &dl, ArrayRef< SDValue > Ops, MachineMemOperand *MMO, ISD::MemIndexType IndexType)
Definition:SelectionDAG.cpp:9858
llvm::SelectionDAG::getBuildVector
SDValue getBuildVector(EVT VT, const SDLoc &DL, ArrayRef< SDValue > Ops)
Return an ISD::BUILD_VECTOR node.
Definition:SelectionDAG.h:857
llvm::SelectionDAG::getBitcastedAnyExtOrTrunc
SDValue getBitcastedAnyExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of integer type, to the integer type VT, by first bitcasting (from potentia...
Definition:SelectionDAG.cpp:1514
llvm::SelectionDAG::isSplatValue
bool isSplatValue(SDValue V, const APInt &DemandedElts, APInt &UndefElts, unsigned Depth=0) const
Test whether V has a splatted value for all the demanded elements.
Definition:SelectionDAG.cpp:3029
llvm::SelectionDAG::DeleteNode
void DeleteNode(SDNode *N)
Remove the specified node from the system.
Definition:SelectionDAG.cpp:1095
llvm::SelectionDAG::getBitcast
SDValue getBitcast(EVT VT, SDValue V)
Return a bitcast using the SDLoc of the value operand, and casting to the provided type.
Definition:SelectionDAG.cpp:2433
llvm::SelectionDAG::getDbgValueList
SDDbgValue * getDbgValueList(DIVariable *Var, DIExpression *Expr, ArrayRef< SDDbgOperand > Locs, ArrayRef< SDNode * > Dependencies, bool IsIndirect, const DebugLoc &DL, unsigned O, bool IsVariadic)
Creates a SDDbgValue node from a list of locations.
Definition:SelectionDAG.cpp:11388
llvm::SelectionDAG::getSelect
SDValue getSelect(const SDLoc &DL, EVT VT, SDValue Cond, SDValue LHS, SDValue RHS, SDNodeFlags Flags=SDNodeFlags())
Helper function to make it easier to build Select's if you just have operands and don't want to check...
Definition:SelectionDAG.h:1280
llvm::SelectionDAG::getNegative
SDValue getNegative(SDValue Val, const SDLoc &DL, EVT VT)
Create negative operation as (SUB 0, Val).
Definition:SelectionDAG.cpp:1617
llvm::SelectionDAG::setNodeMemRefs
void setNodeMemRefs(MachineSDNode *N, ArrayRef< MachineMemOperand * > NewMemRefs)
Mutate the specified machine node's memory references to the provided list.
Definition:SelectionDAG.cpp:10917
llvm::SelectionDAG::simplifySelect
SDValue simplifySelect(SDValue Cond, SDValue TVal, SDValue FVal)
Try to simplify a select/vselect into 1 of its operands or a constant.
Definition:SelectionDAG.cpp:10225
llvm::SelectionDAG::getZeroExtendInReg
SDValue getZeroExtendInReg(SDValue Op, const SDLoc &DL, EVT VT)
Return the expression required to zero extend the Op value assuming it was the smaller SrcTy value.
Definition:SelectionDAG.cpp:1568
llvm::SelectionDAG::isConstantFPBuildVectorOrConstantFP
bool isConstantFPBuildVectorOrConstantFP(SDValue N) const
Test whether the given value is a constant FP or similar node.
Definition:SelectionDAG.cpp:13463
llvm::SelectionDAG::getDataLayout
const DataLayout & getDataLayout() const
Definition:SelectionDAG.h:497
llvm::SelectionDAG::expandVAArg
SDValue expandVAArg(SDNode *Node)
Expand the specified ISD::VAARG node as the Legalize pass would.
Definition:SelectionDAG.cpp:2695
llvm::SelectionDAG::getTokenFactor
SDValue getTokenFactor(const SDLoc &DL, SmallVectorImpl< SDValue > &Vals)
Creates a new TokenFactor containing Vals.
Definition:SelectionDAG.cpp:13532
llvm::SelectionDAG::doesNodeExist
bool doesNodeExist(unsigned Opcode, SDVTList VTList, ArrayRef< SDValue > Ops)
Check if a node exists without modifying its flags.
Definition:SelectionDAG.cpp:11311
llvm::SelectionDAG::areNonVolatileConsecutiveLoads
bool areNonVolatileConsecutiveLoads(LoadSDNode *LD, LoadSDNode *Base, unsigned Bytes, int Dist) const
Return true if loads are next to each other and can be merged.
Definition:SelectionDAG.cpp:12882
llvm::SelectionDAG::getMaskedHistogram
SDValue getMaskedHistogram(SDVTList VTs, EVT MemVT, const SDLoc &dl, ArrayRef< SDValue > Ops, MachineMemOperand *MMO, ISD::MemIndexType IndexType)
Definition:SelectionDAG.cpp:10133
llvm::SelectionDAG::getDbgLabel
SDDbgLabel * getDbgLabel(DILabel *Label, const DebugLoc &DL, unsigned O)
Creates a SDDbgLabel node.
Definition:SelectionDAG.cpp:11616
llvm::SelectionDAG::getStoreVP
SDValue getStoreVP(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, SDValue Offset, SDValue Mask, SDValue EVL, EVT MemVT, MachineMemOperand *MMO, ISD::MemIndexedMode AM, bool IsTruncating=false, bool IsCompressing=false)
Definition:SelectionDAG.cpp:9584
llvm::SelectionDAG::computeOverflowForUnsignedMul
OverflowKind computeOverflowForUnsignedMul(SDValue N0, SDValue N1) const
Determine if the result of the unsigned mul of 2 nodes can overflow.
Definition:SelectionDAG.cpp:4603
llvm::SelectionDAG::copyExtraInfo
void copyExtraInfo(SDNode *From, SDNode *To)
Copy extra info associated with one node to another.
Definition:SelectionDAG.cpp:13629
llvm::SelectionDAG::getConstant
SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
Create a ConstantSDNode wrapping a constant value.
Definition:SelectionDAG.cpp:1666
llvm::SelectionDAG::getMemBasePlusOffset
SDValue getMemBasePlusOffset(SDValue Base, TypeSize Offset, const SDLoc &DL, const SDNodeFlags Flags=SDNodeFlags())
Returns sum of the base pointer and offset.
Definition:SelectionDAG.cpp:8052
llvm::SelectionDAG::getGlobalAddress
SDValue getGlobalAddress(const GlobalValue *GV, const SDLoc &DL, EVT VT, int64_t offset=0, bool isTargetGA=false, unsigned TargetFlags=0)
Definition:SelectionDAG.cpp:1891
llvm::SelectionDAG::getVAArg
SDValue getVAArg(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, SDValue SV, unsigned Align)
VAArg produces a result and token chain, and takes a pointer and a source value as input.
Definition:SelectionDAG.cpp:10321
llvm::SelectionDAG::getTruncStore
SDValue getTruncStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, EVT SVT, Align Alignment, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
Definition:SelectionDAG.cpp:9371
llvm::SelectionDAG::getMDNode
SDValue getMDNode(const MDNode *MD)
Return an MDNodeSDNode which holds an MDNode.
Definition:SelectionDAG.cpp:2418
llvm::SelectionDAG::clear
void clear()
Clear state and free memory necessary to make this SelectionDAG ready to process a new block.
Definition:SelectionDAG.cpp:1455
llvm::SelectionDAG::ReplaceAllUsesWith
void ReplaceAllUsesWith(SDValue From, SDValue To)
Modify anything using 'From' to use 'To' instead.
Definition:SelectionDAG.cpp:11653
llvm::SelectionDAG::getCommutedVectorShuffle
SDValue getCommutedVectorShuffle(const ShuffleVectorSDNode &SV)
Returns an ISD::VECTOR_SHUFFLE node semantically equivalent to the shuffle node in input but with swa...
Definition:SelectionDAG.cpp:2318
llvm::SelectionDAG::SplitVector
std::pair< SDValue, SDValue > SplitVector(const SDValue &N, const SDLoc &DL, const EVT &LoVT, const EVT &HiVT)
Split the vector with EXTRACT_SUBVECTOR using the provided VTs and return the low/high part.
Definition:SelectionDAG.cpp:13006
llvm::SelectionDAG::makeStateFunctionCall
SDValue makeStateFunctionCall(unsigned LibFunc, SDValue Ptr, SDValue InChain, const SDLoc &DLoc)
Helper used to make a call to a library function that has one argument of pointer type.
Definition:SelectionDAG.cpp:13610
llvm::SelectionDAG::isGuaranteedNotToBeUndefOrPoison
bool isGuaranteedNotToBeUndefOrPoison(SDValue Op, bool PoisonOnly=false, unsigned Depth=0) const
Return true if this function can prove that Op is never poison and, if PoisonOnly is false,...
Definition:SelectionDAG.cpp:5430
llvm::SelectionDAG::getStore
SDValue getStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, Align Alignment, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
Helper function to build ISD::STORE nodes.
Definition:SelectionDAG.cpp:9320
llvm::SelectionDAG::getSignedConstant
SDValue getSignedConstant(int64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
Definition:SelectionDAG.cpp:1794
llvm::SelectionDAG::getIndexedLoadVP
SDValue getIndexedLoadVP(SDValue OrigLoad, const SDLoc &dl, SDValue Base, SDValue Offset, ISD::MemIndexedMode AM)
Definition:SelectionDAG.cpp:9568
llvm::SelectionDAG::getSrcValue
SDValue getSrcValue(const Value *v)
Construct a node to track a Value* through the backend.
Definition:SelectionDAG.cpp:2403
llvm::SelectionDAG::getSplatVector
SDValue getSplatVector(EVT VT, const SDLoc &DL, SDValue Op)
Definition:SelectionDAG.h:891
llvm::SelectionDAG::getAtomicMemcpy
SDValue getAtomicMemcpy(SDValue Chain, const SDLoc &dl, SDValue Dst, SDValue Src, SDValue Size, Type *SizeTy, unsigned ElemSz, bool isTailCall, MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo)
Definition:SelectionDAG.cpp:8667
llvm::SelectionDAG::computeOverflowForSignedMul
OverflowKind computeOverflowForSignedMul(SDValue N0, SDValue N1) const
Determine if the result of the signed mul of 2 nodes can overflow.
Definition:SelectionDAG.cpp:4616
llvm::SelectionDAG::InferPtrAlign
MaybeAlign InferPtrAlign(SDValue Ptr) const
Infer alignment of a load / store address.
Definition:SelectionDAG.cpp:12910
llvm::SelectionDAG::dump
void dump() const
Definition:SelectionDAGDumper.cpp:1038
llvm::SelectionDAG::MaskedValueIsAllOnes
bool MaskedValueIsAllOnes(SDValue Op, const APInt &Mask, unsigned Depth=0) const
Return true if '(Op & Mask) == Mask'.
Definition:SelectionDAG.cpp:2999
llvm::SelectionDAG::SignBitIsZero
bool SignBitIsZero(SDValue Op, unsigned Depth=0) const
Return true if the sign bit of Op is known to be zero.
Definition:SelectionDAG.cpp:2969
llvm::SelectionDAG::RemoveDeadNodes
void RemoveDeadNodes()
This method deletes all unreachable nodes in the SelectionDAG.
Definition:SelectionDAG.cpp:1030
llvm::SelectionDAG::RemoveDeadNode
void RemoveDeadNode(SDNode *N)
Remove the specified node from the system.
Definition:SelectionDAG.cpp:1084
llvm::SelectionDAG::AddDbgLabel
void AddDbgLabel(SDDbgLabel *DB)
Add a dbg_label SDNode.
Definition:SelectionDAG.cpp:12150
llvm::SelectionDAG::isConstantValueOfAnyType
bool isConstantValueOfAnyType(SDValue N) const
Definition:SelectionDAG.h:2334
llvm::SelectionDAG::getTargetExtractSubreg
SDValue getTargetExtractSubreg(int SRIdx, const SDLoc &DL, EVT VT, SDValue Operand)
A convenience function for creating TargetInstrInfo::EXTRACT_SUBREG nodes.
Definition:SelectionDAG.cpp:11267
llvm::SelectionDAG::getBasicBlock
SDValue getBasicBlock(MachineBasicBlock *MBB)
Definition:SelectionDAG.cpp:2024
llvm::SelectionDAG::getSExtOrTrunc
SDValue getSExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of integer type, to the integer type VT, by either sign-extending or trunca...
Definition:SelectionDAG.cpp:1502
llvm::SelectionDAG::isKnownToBeAPowerOfTwo
bool isKnownToBeAPowerOfTwo(SDValue Val, unsigned Depth=0) const
Test if the given value is known to have exactly one bit set.
Definition:SelectionDAG.cpp:4645
llvm::SelectionDAG::getPartialReduceAdd
SDValue getPartialReduceAdd(SDLoc DL, EVT ReducedTy, SDValue Op1, SDValue Op2)
Create the DAG equivalent of vector_partial_reduce where Op1 and Op2 are its operands and ReducedTY i...
Definition:SelectionDAG.cpp:2476
llvm::SelectionDAG::getEHLabel
SDValue getEHLabel(const SDLoc &dl, SDValue Root, MCSymbol *Label)
Definition:SelectionDAG.cpp:2358
llvm::SelectionDAG::getIndexedStoreVP
SDValue getIndexedStoreVP(SDValue OrigStore, const SDLoc &dl, SDValue Base, SDValue Offset, ISD::MemIndexedMode AM)
Definition:SelectionDAG.cpp:9690
llvm::SelectionDAG::isKnownNeverZero
bool isKnownNeverZero(SDValue Op, unsigned Depth=0) const
Test whether the given SDValue is known to contain non-zero value(s).
Definition:SelectionDAG.cpp:5814
llvm::SelectionDAG::getIndexedStore
SDValue getIndexedStore(SDValue OrigStore, const SDLoc &dl, SDValue Base, SDValue Offset, ISD::MemIndexedMode AM)
Definition:SelectionDAG.cpp:9438
llvm::SelectionDAG::FoldConstantArithmetic
SDValue FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDValue > Ops, SDNodeFlags Flags=SDNodeFlags())
Definition:SelectionDAG.cpp:6672
llvm::SelectionDAG::getSetFPEnv
SDValue getSetFPEnv(SDValue Chain, const SDLoc &dl, SDValue Ptr, EVT MemVT, MachineMemOperand *MMO)
Definition:SelectionDAG.cpp:10198
llvm::SelectionDAG::getBoolExtOrTrunc
SDValue getBoolExtOrTrunc(SDValue Op, const SDLoc &SL, EVT VT, EVT OpVT)
Convert Op, which must be of integer type, to the integer type VT, by using an extension appropriate ...
Definition:SelectionDAG.cpp:1559
llvm::SelectionDAG::getMaskedStore
SDValue getMaskedStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Base, SDValue Offset, SDValue Mask, EVT MemVT, MachineMemOperand *MMO, ISD::MemIndexedMode AM, bool IsTruncating=false, bool IsCompressing=false)
Definition:SelectionDAG.cpp:9991
llvm::SelectionDAG::getExternalSymbol
SDValue getExternalSymbol(const char *Sym, EVT VT)
Definition:SelectionDAG.cpp:2052
llvm::SelectionDAG::getTarget
const TargetMachine & getTarget() const
Definition:SelectionDAG.h:498
llvm::SelectionDAG::getStrictFPExtendOrRound
std::pair< SDValue, SDValue > getStrictFPExtendOrRound(SDValue Op, SDValue Chain, const SDLoc &DL, EVT VT)
Convert Op, which must be a STRICT operation of float type, to the float type VT, by either extending...
Definition:SelectionDAG.cpp:1483
llvm::SelectionDAG::SplitEVL
std::pair< SDValue, SDValue > SplitEVL(SDValue N, EVT VecVT, const SDLoc &DL)
Split the explicit vector length parameter of a VP operation.
Definition:SelectionDAG.cpp:13027
llvm::SelectionDAG::getPtrExtOrTrunc
SDValue getPtrExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of integer type, to the integer type VT, by either truncating it or perform...
Definition:SelectionDAG.cpp:1605
llvm::SelectionDAG::getVPLogicalNOT
SDValue getVPLogicalNOT(const SDLoc &DL, SDValue Val, SDValue Mask, SDValue EVL, EVT VT)
Create a vector-predicated logical NOT operation as (VP_XOR Val, BooleanOne, Mask,...
Definition:SelectionDAG.cpp:1631
llvm::SelectionDAG::getAnyExtOrTrunc
SDValue getAnyExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of integer type, to the integer type VT, by either any-extending or truncat...
Definition:SelectionDAG.cpp:1496
llvm::SelectionDAG::allnodes
iterator_range< allnodes_iterator > allnodes()
Definition:SelectionDAG.h:569
llvm::SelectionDAG::getBlockAddress
SDValue getBlockAddress(const BlockAddress *BA, EVT VT, int64_t Offset=0, bool isTarget=false, unsigned TargetFlags=0)
Definition:SelectionDAG.cpp:2382
llvm::SelectionDAG::WidenVector
SDValue WidenVector(const SDValue &N, const SDLoc &DL)
Widen the vector up to the next power of two using INSERT_SUBVECTOR.
Definition:SelectionDAG.cpp:13045
llvm::SelectionDAG::isKnownNeverZeroFloat
bool isKnownNeverZeroFloat(SDValue Op) const
Test whether the given floating point SDValue is known to never be positive or negative zero.
Definition:SelectionDAG.cpp:5805
llvm::SelectionDAG::getLoadVP
SDValue getLoadVP(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType, EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, SDValue Offset, SDValue Mask, SDValue EVL, MachinePointerInfo PtrInfo, EVT MemVT, Align Alignment, MachineMemOperand::Flags MMOFlags, const AAMDNodes &AAInfo, const MDNode *Ranges=nullptr, bool IsExpanding=false)
Definition:SelectionDAG.cpp:9467
llvm::SelectionDAG::getIntPtrConstant
SDValue getIntPtrConstant(uint64_t Val, const SDLoc &DL, bool isTarget=false)
Definition:SelectionDAG.cpp:1806
llvm::SelectionDAG::getConstantDbgValue
SDDbgValue * getConstantDbgValue(DIVariable *Var, DIExpression *Expr, const Value *C, const DebugLoc &DL, unsigned O)
Creates a constant SDDbgValue node.
Definition:SelectionDAG.cpp:11338
llvm::SelectionDAG::getScatterVP
SDValue getScatterVP(SDVTList VTs, EVT VT, const SDLoc &dl, ArrayRef< SDValue > Ops, MachineMemOperand *MMO, ISD::MemIndexType IndexType)
Definition:SelectionDAG.cpp:9901
llvm::SelectionDAG::getValueType
SDValue getValueType(EVT)
Definition:SelectionDAG.cpp:2038
llvm::SelectionDAG::GetDbgValues
ArrayRef< SDDbgValue * > GetDbgValues(const SDNode *SD) const
Get the debug values which reference the given SDNode.
Definition:SelectionDAG.h:1865
llvm::SelectionDAG::getNode
SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
Definition:SelectionDAG.cpp:10327
llvm::SelectionDAG::computeOverflowForSignedAdd
OverflowKind computeOverflowForSignedAdd(SDValue N0, SDValue N1) const
Determine if the result of the signed addition of 2 nodes can overflow.
Definition:SelectionDAG.cpp:4534
llvm::SelectionDAG::getFPExtendOrRound
SDValue getFPExtendOrRound(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of float type, to the float type VT, by either extending or rounding (by tr...
Definition:SelectionDAG.cpp:1475
llvm::SelectionDAG::AssignTopologicalOrder
unsigned AssignTopologicalOrder()
Topological-sort the AllNodes list and a assign a unique node id for each node in the DAG based on th...
Definition:SelectionDAG.cpp:12054
llvm::SelectionDAG::allnodes_size
ilist< SDNode >::size_type allnodes_size() const
Definition:SelectionDAG.h:565
llvm::SelectionDAG::getAtomicMemmove
SDValue getAtomicMemmove(SDValue Chain, const SDLoc &dl, SDValue Dst, SDValue Src, SDValue Size, Type *SizeTy, unsigned ElemSz, bool isTailCall, MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo)
Definition:SelectionDAG.cpp:8784
llvm::SelectionDAG::isKnownNeverNaN
bool isKnownNeverNaN(SDValue Op, bool SNaN=false, unsigned Depth=0) const
Test whether the given SDValue (or all elements of it, if it is a vector) is known to never be NaN.
Definition:SelectionDAG.cpp:5672
llvm::SelectionDAG::getIndexedMaskedStore
SDValue getIndexedMaskedStore(SDValue OrigStore, const SDLoc &dl, SDValue Base, SDValue Offset, ISD::MemIndexedMode AM)
Definition:SelectionDAG.cpp:10029
llvm::SelectionDAG::getTruncStoreVP
SDValue getTruncStoreVP(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, SDValue Mask, SDValue EVL, MachinePointerInfo PtrInfo, EVT SVT, Align Alignment, MachineMemOperand::Flags MMOFlags, const AAMDNodes &AAInfo, bool IsCompressing=false)
Definition:SelectionDAG.cpp:9618
llvm::SelectionDAG::getTargetConstant
SDValue getTargetConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isOpaque=false)
Definition:SelectionDAG.h:701
llvm::SelectionDAG::getLibInfo
const TargetLibraryInfo & getLibInfo() const
Definition:SelectionDAG.h:504
llvm::SelectionDAG::ComputeNumSignBits
unsigned ComputeNumSignBits(SDValue Op, unsigned Depth=0) const
Return the number of times the sign bit of the register is replicated into the other bits.
Definition:SelectionDAG.cpp:4739
llvm::SelectionDAG::MaskedVectorIsZero
bool MaskedVectorIsZero(SDValue Op, const APInt &DemandedElts, unsigned Depth=0) const
Return true if 'Op' is known to be zero in DemandedElts.
Definition:SelectionDAG.cpp:2993
llvm::SelectionDAG::getBoolConstant
SDValue getBoolConstant(bool V, const SDLoc &DL, EVT VT, EVT OpVT)
Create a true or false constant of type VT using the target's BooleanContent for type OpVT.
Definition:SelectionDAG.cpp:1651
llvm::SelectionDAG::getFrameIndexDbgValue
SDDbgValue * getFrameIndexDbgValue(DIVariable *Var, DIExpression *Expr, unsigned FI, bool IsIndirect, const DebugLoc &DL, unsigned O)
Creates a FrameIndex SDDbgValue node.
Definition:SelectionDAG.cpp:11351
llvm::SelectionDAG::getExtStridedLoadVP
SDValue getExtStridedLoadVP(ISD::LoadExtType ExtType, const SDLoc &DL, EVT VT, SDValue Chain, SDValue Ptr, SDValue Stride, SDValue Mask, SDValue EVL, EVT MemVT, MachineMemOperand *MMO, bool IsExpanding=false)
Definition:SelectionDAG.cpp:9764
llvm::SelectionDAG::getMemmove
SDValue getMemmove(SDValue Chain, const SDLoc &dl, SDValue Dst, SDValue Src, SDValue Size, Align Alignment, bool isVol, const CallInst *CI, std::optional< bool > OverrideTailCall, MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo, const AAMDNodes &AAInfo=AAMDNodes(), BatchAAResults *BatchAA=nullptr)
Definition:SelectionDAG.cpp:8707
llvm::SelectionDAG::getJumpTable
SDValue getJumpTable(int JTI, EVT VT, bool isTarget=false, unsigned TargetFlags=0)
Definition:SelectionDAG.cpp:1941
llvm::SelectionDAG::isBaseWithConstantOffset
bool isBaseWithConstantOffset(SDValue Op) const
Return true if the specified operand is an ISD::ADD with a ConstantSDNode on the right-hand side,...
Definition:SelectionDAG.cpp:5667
llvm::SelectionDAG::getVPPtrExtOrTrunc
SDValue getVPPtrExtOrTrunc(const SDLoc &DL, EVT VT, SDValue Op, SDValue Mask, SDValue EVL)
Convert a vector-predicated Op, which must be of integer type, to the vector-type integer type VT,...
Definition:SelectionDAG.cpp:1637
llvm::SelectionDAG::getVectorIdxConstant
SDValue getVectorIdxConstant(uint64_t Val, const SDLoc &DL, bool isTarget=false)
Definition:SelectionDAG.cpp:1824
llvm::SelectionDAG::ReplaceAllUsesOfValueWith
void ReplaceAllUsesOfValueWith(SDValue From, SDValue To)
Replace any uses of From with To, leaving uses of other values produced by From.getNode() alone.
Definition:SelectionDAG.cpp:11814
llvm::SelectionDAG::getMachineFunction
MachineFunction & getMachineFunction() const
Definition:SelectionDAG.h:492
llvm::SelectionDAG::getPtrExtendInReg
SDValue getPtrExtendInReg(SDValue Op, const SDLoc &DL, EVT VT)
Return the expression required to extend the Op as a pointer value assuming it was the smaller SrcTy ...
Definition:SelectionDAG.cpp:1611
llvm::SelectionDAG::canCreateUndefOrPoison
bool canCreateUndefOrPoison(SDValue Op, const APInt &DemandedElts, bool PoisonOnly=false, bool ConsiderFlags=true, unsigned Depth=0) const
Return true if Op can create undef or poison from non-undef & non-poison operands.
Definition:SelectionDAG.cpp:5540
llvm::SelectionDAG::computeOverflowForUnsignedAdd
OverflowKind computeOverflowForUnsignedAdd(SDValue N0, SDValue N1) const
Determine if the result of the unsigned addition of 2 nodes can overflow.
Definition:SelectionDAG.cpp:4549
llvm::SelectionDAG::getValidMaximumShiftAmount
std::optional< uint64_t > getValidMaximumShiftAmount(SDValue V, const APInt &DemandedElts, unsigned Depth=0) const
If a SHL/SRA/SRL node V has shift amounts that are all less than the element bit-width of the shift n...
Definition:SelectionDAG.cpp:3392
llvm::SelectionDAG::getSplatBuildVector
SDValue getSplatBuildVector(EVT VT, const SDLoc &DL, SDValue Op)
Return a splat ISD::BUILD_VECTOR node, consisting of Op splatted to all elements.
Definition:SelectionDAG.h:874
llvm::SelectionDAG::getFrameIndex
SDValue getFrameIndex(int FI, EVT VT, bool isTarget=false)
Definition:SelectionDAG.cpp:1925
llvm::SelectionDAG::getTruncStridedStoreVP
SDValue getTruncStridedStoreVP(SDValue Chain, const SDLoc &DL, SDValue Val, SDValue Ptr, SDValue Stride, SDValue Mask, SDValue EVL, EVT SVT, MachineMemOperand *MMO, bool IsCompressing=false)
Definition:SelectionDAG.cpp:9809
llvm::SelectionDAG::canonicalizeCommutativeBinop
void canonicalizeCommutativeBinop(unsigned Opcode, SDValue &N1, SDValue &N2) const
Swap N1 and N2 if Opcode is a commutative binary opcode and the canonical form expects the opposite o...
Definition:SelectionDAG.cpp:7217
llvm::SelectionDAG::computeKnownBits
KnownBits computeKnownBits(SDValue Op, unsigned Depth=0) const
Determine which bits of Op are known to be either zero or one and return them in Known.
Definition:SelectionDAG.cpp:3415
llvm::SelectionDAG::getRegisterMask
SDValue getRegisterMask(const uint32_t *RegMask)
Definition:SelectionDAG.cpp:2344
llvm::SelectionDAG::getZExtOrTrunc
SDValue getZExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of integer type, to the integer type VT, by either zero-extending or trunca...
Definition:SelectionDAG.cpp:1508
llvm::SelectionDAG::getCondCode
SDValue getCondCode(ISD::CondCode Cond)
Definition:SelectionDAG.cpp:2079
llvm::SelectionDAG::getLifetimeNode
SDValue getLifetimeNode(bool IsStart, const SDLoc &dl, SDValue Chain, int FrameIndex, int64_t Size, int64_t Offset=-1)
Creates a LifetimeSDNode that starts (IsStart==true) or ends (IsStart==false) the lifetime of the por...
Definition:SelectionDAG.cpp:9103
llvm::SelectionDAG::MaskedValueIsZero
bool MaskedValueIsZero(SDValue Op, const APInt &Mask, unsigned Depth=0) const
Return true if 'Op & Mask' is known to be zero.
Definition:SelectionDAG.cpp:2977
llvm::SelectionDAG::isKnownToBeAPowerOfTwoFP
bool isKnownToBeAPowerOfTwoFP(SDValue Val, unsigned Depth=0) const
Test if the given fp value is known to be an integer power-of-2, either positive or negative.
Definition:SelectionDAG.cpp:4729
llvm::SelectionDAG::computeOverflowForSignedSub
OverflowKind computeOverflowForSignedSub(SDValue N0, SDValue N1) const
Determine if the result of the signed sub of 2 nodes can overflow.
Definition:SelectionDAG.cpp:4572
llvm::SelectionDAG::expandMultipleResultFPLibCall
bool expandMultipleResultFPLibCall(RTLIB::Libcall LC, SDNode *Node, SmallVectorImpl< SDValue > &Results, std::optional< unsigned > CallRetResNo={})
Expands a node with multiple results to an FP or vector libcall.
Definition:SelectionDAG.cpp:2550
llvm::SelectionDAG::getValidShiftAmount
std::optional< uint64_t > getValidShiftAmount(SDValue V, const APInt &DemandedElts, unsigned Depth=0) const
If a SHL/SRA/SRL node V has a uniform shift amount that is less than the element bit-width of the shi...
Definition:SelectionDAG.cpp:3349
llvm::SelectionDAG::~SelectionDAG
~SelectionDAG()
Definition:SelectionDAG.cpp:1394
llvm::SelectionDAG::getContext
LLVMContext * getContext() const
Definition:SelectionDAG.h:510
llvm::SelectionDAG::simplifyFPBinop
SDValue simplifyFPBinop(unsigned Opcode, SDValue X, SDValue Y, SDNodeFlags Flags)
Try to simplify a floating-point binary operation into 1 of its operands or a constant.
Definition:SelectionDAG.cpp:10276
llvm::SelectionDAG::setRoot
const SDValue & setRoot(SDValue N)
Set the current root tag of the SelectionDAG.
Definition:SelectionDAG.h:586
llvm::SelectionDAG::getMemIntrinsicNode
SDValue getMemIntrinsicNode(unsigned Opcode, const SDLoc &dl, SDVTList VTList, ArrayRef< SDValue > Ops, EVT MemVT, MachinePointerInfo PtrInfo, Align Alignment, MachineMemOperand::Flags Flags=MachineMemOperand::MOLoad|MachineMemOperand::MOStore, LocationSize Size=0, const AAMDNodes &AAInfo=AAMDNodes())
Creates a MemIntrinsicNode that may produce a result and takes a list of operands.
Definition:SelectionDAG.cpp:9045
llvm::SelectionDAG::getTargetExternalSymbol
SDValue getTargetExternalSymbol(const char *Sym, EVT VT, unsigned TargetFlags=0)
Definition:SelectionDAG.cpp:2069
llvm::SelectionDAG::getMCSymbol
SDValue getMCSymbol(MCSymbol *Sym, EVT VT)
Definition:SelectionDAG.cpp:2060
llvm::SelectionDAG::isUndef
bool isUndef(unsigned Opcode, ArrayRef< SDValue > Ops)
Return true if the result of this operation is always undefined.
Definition:SelectionDAG.cpp:6647
llvm::SelectionDAG::CreateStackTemporary
SDValue CreateStackTemporary(TypeSize Bytes, Align Alignment)
Create a stack temporary based on the size in bytes and the alignment.
Definition:SelectionDAG.cpp:2776
llvm::SelectionDAG::UpdateNodeOperands
SDNode * UpdateNodeOperands(SDNode *N, SDValue Op)
Mutate the specified node in-place to have the specified operands.
Definition:SelectionDAG.cpp:10801
llvm::SelectionDAG::GetDependentSplitDestVTs
std::pair< EVT, EVT > GetDependentSplitDestVTs(const EVT &VT, const EVT &EnvVT, bool *HiIsEmpty) const
Compute the VTs needed for the low/hi parts of a type, dependent on an enveloping VT that has been sp...
Definition:SelectionDAG.cpp:12976
llvm::SelectionDAG::foldConstantFPMath
SDValue foldConstantFPMath(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDValue > Ops)
Fold floating-point operations when all operands are constants and/or undefined.
Definition:SelectionDAG.cpp:7097
llvm::SelectionDAG::getNodeIfExists
SDNode * getNodeIfExists(unsigned Opcode, SDVTList VTList, ArrayRef< SDValue > Ops, const SDNodeFlags Flags)
Get the specified node if it's already available, or else return NULL.
Definition:SelectionDAG.cpp:11295
llvm::SelectionDAG::init
void init(MachineFunction &NewMF, OptimizationRemarkEmitter &NewORE, Pass *PassPtr, const TargetLibraryInfo *LibraryInfo, UniformityInfo *UA, ProfileSummaryInfo *PSIin, BlockFrequencyInfo *BFIin, MachineModuleInfo &MMI, FunctionVarLocs const *FnVarLocs)
Prepare this SelectionDAG to process code in the given MachineFunction.
Definition:SelectionDAG.cpp:1374
llvm::SelectionDAG::getValidShiftAmountRange
std::optional< ConstantRange > getValidShiftAmountRange(SDValue V, const APInt &DemandedElts, unsigned Depth) const
If a SHL/SRA/SRL node V has shift amounts that are all less than the element bit-width of the shift n...
Definition:SelectionDAG.cpp:3300
llvm::SelectionDAG::FoldSymbolOffset
SDValue FoldSymbolOffset(unsigned Opcode, EVT VT, const GlobalAddressSDNode *GA, const SDNode *N2)
Definition:SelectionDAG.cpp:6627
llvm::SelectionDAG::isBoolConstant
std::optional< bool > isBoolConstant(SDValue N, bool AllowTruncation=false) const
Check if a value \op N is a constant using the target's BooleanContent for its type.
Definition:SelectionDAG.cpp:13477
llvm::SelectionDAG::getIndexedLoad
SDValue getIndexedLoad(SDValue OrigLoad, const SDLoc &dl, SDValue Base, SDValue Offset, ISD::MemIndexedMode AM)
Definition:SelectionDAG.cpp:9306
llvm::SelectionDAG::getTargetInsertSubreg
SDValue getTargetInsertSubreg(int SRIdx, const SDLoc &DL, EVT VT, SDValue Operand, SDValue Subreg)
A convenience function for creating TargetInstrInfo::INSERT_SUBREG nodes.
Definition:SelectionDAG.cpp:11277
llvm::SelectionDAG::getEntryNode
SDValue getEntryNode() const
Return the token chain corresponding to the entry of the function.
Definition:SelectionDAG.h:580
llvm::SelectionDAG::getDbgValue
SDDbgValue * getDbgValue(DIVariable *Var, DIExpression *Expr, SDNode *N, unsigned R, bool IsIndirect, const DebugLoc &DL, unsigned O)
Creates a SDDbgValue node.
Definition:SelectionDAG.cpp:11326
llvm::SelectionDAG::getMaskedLoad
SDValue getMaskedLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Base, SDValue Offset, SDValue Mask, SDValue Src0, EVT MemVT, MachineMemOperand *MMO, ISD::MemIndexedMode AM, ISD::LoadExtType, bool IsExpanding=false)
Definition:SelectionDAG.cpp:9945
llvm::SelectionDAG::getSplat
SDValue getSplat(EVT VT, const SDLoc &DL, SDValue Op)
Returns a node representing a splat of one value into all lanes of the provided vector type.
Definition:SelectionDAG.h:907
llvm::SelectionDAG::SplitScalar
std::pair< SDValue, SDValue > SplitScalar(const SDValue &N, const SDLoc &DL, const EVT &LoVT, const EVT &HiVT)
Split the scalar node with EXTRACT_ELEMENT using the provided VTs and return the low/high part.
Definition:SelectionDAG.cpp:12946
llvm::SelectionDAG::matchBinOpReduction
SDValue matchBinOpReduction(SDNode *Extract, ISD::NodeType &BinOp, ArrayRef< ISD::NodeType > CandidateBinOps, bool AllowPartials=false)
Match a binop + shuffle pyramid that represents a horizontal reduction over the elements of a vector ...
Definition:SelectionDAG.cpp:12604
llvm::SelectionDAG::isADDLike
bool isADDLike(SDValue Op, bool NoWrap=false) const
Return true if the specified operand is an ISD::OR or ISD::XOR node that can be treated as an ISD::AD...
Definition:SelectionDAG.cpp:5657
llvm::SelectionDAG::getVectorShuffle
SDValue getVectorShuffle(EVT VT, const SDLoc &dl, SDValue N1, SDValue N2, ArrayRef< int > Mask)
Return an ISD::VECTOR_SHUFFLE node.
Definition:SelectionDAG.cpp:2147
llvm::SelectionDAG::simplifyShift
SDValue simplifyShift(SDValue X, SDValue Y)
Try to simplify a shift into 1 of its operands or a constant.
Definition:SelectionDAG.cpp:10248
llvm::SelectionDAG::transferDbgValues
void transferDbgValues(SDValue From, SDValue To, unsigned OffsetInBits=0, unsigned SizeInBits=0, bool InvalidateDbg=true)
Transfer debug values from one node to another, while optionally generating fragment expressions for ...
Definition:SelectionDAG.cpp:11400
llvm::SelectionDAG::getLogicalNOT
SDValue getLogicalNOT(const SDLoc &DL, SDValue Val, EVT VT)
Create a logical NOT operation as (XOR Val, BooleanOne).
Definition:SelectionDAG.cpp:1626
llvm::SelectionDAG::getMaskedScatter
SDValue getMaskedScatter(SDVTList VTs, EVT MemVT, const SDLoc &dl, ArrayRef< SDValue > Ops, MachineMemOperand *MMO, ISD::MemIndexType IndexType, bool IsTruncating=false)
Definition:SelectionDAG.cpp:10087
llvm::SelectionDAG::allnodes_iterator
ilist< SDNode >::iterator allnodes_iterator
Definition:SelectionDAG.h:560
llvm::ShuffleVectorSDNode
This SDNode is used to implement the code generator support for the llvm IR shufflevector instruction...
Definition:SelectionDAGNodes.h:1625
llvm::ShuffleVectorSDNode::isSplatMask
static bool isSplatMask(const int *Mask, EVT VT)
Definition:SelectionDAG.cpp:13418
llvm::ShuffleVectorSDNode::getMaskElt
int getMaskElt(unsigned Idx) const
Definition:SelectionDAGNodes.h:1643
llvm::ShuffleVectorSDNode::getMask
ArrayRef< int > getMask() const
Definition:SelectionDAGNodes.h:1638
llvm::ShuffleVectorSDNode::commuteMask
static void commuteMask(MutableArrayRef< int > Mask)
Change values in a shuffle permute mask assuming the two vector operands have swapped position.
Definition:SelectionDAGNodes.h:1666
llvm::SmallPtrSetImplBase::size
size_type size() const
Definition:SmallPtrSet.h:94
llvm::SmallPtrSetImplBase::clear
void clear()
Definition:SmallPtrSet.h:97
llvm::SmallPtrSetImplBase::empty
bool empty() const
Definition:SmallPtrSet.h:93
llvm::SmallPtrSetImpl
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition:SmallPtrSet.h:363
llvm::SmallPtrSetImpl::erase
bool erase(PtrType Ptr)
Remove pointer from the set.
Definition:SmallPtrSet.h:401
llvm::SmallPtrSetImpl::count
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Definition:SmallPtrSet.h:452
llvm::SmallPtrSetImpl::insert
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition:SmallPtrSet.h:384
llvm::SmallPtrSet
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition:SmallPtrSet.h:519
llvm::SmallVectorBase::empty
bool empty() const
Definition:SmallVector.h:81
llvm::SmallVectorBase::size
size_t size() const
Definition:SmallVector.h:78
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition:SmallVector.h:573
llvm::SmallVectorImpl::pop_back_val
T pop_back_val()
Definition:SmallVector.h:673
llvm::SmallVectorImpl::assign
void assign(size_type NumElts, ValueParamT Elt)
Definition:SmallVector.h:704
llvm::SmallVectorImpl::emplace_back
reference emplace_back(ArgTypes &&... Args)
Definition:SmallVector.h:937
llvm::SmallVectorImpl::reserve
void reserve(size_type N)
Definition:SmallVector.h:663
llvm::SmallVectorImpl::erase
iterator erase(const_iterator CI)
Definition:SmallVector.h:737
llvm::SmallVectorImpl::append
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
Definition:SmallVector.h:683
llvm::SmallVectorImpl::clear
void clear()
Definition:SmallVector.h:610
llvm::SmallVectorTemplateBase::push_back
void push_back(const T &Elt)
Definition:SmallVector.h:413
llvm::SmallVectorTemplateCommon::end
iterator end()
Definition:SmallVector.h:269
llvm::SmallVectorTemplateCommon::begin
iterator begin()
Definition:SmallVector.h:267
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition:SmallVector.h:1196
llvm::SrcOp
Definition:MachineIRBuilder.h:142
llvm::StoreSDNode
This class is used to represent ISD::STORE nodes.
Definition:SelectionDAGNodes.h:2492
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition:StringRef.h:51
llvm::StringRef::data
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition:StringRef.h:144
llvm::TargetFrameLowering
Information about stack frame layout on the target.
Definition:TargetFrameLowering.h:45
llvm::TargetFrameLowering::getStackIDForScalableVectors
virtual TargetStackID::Value getStackIDForScalableVectors() const
Returns the StackID that scalable vectors should be associated with.
Definition:TargetFrameLowering.h:441
llvm::TargetFrameLowering::getStackAlign
Align getStackAlign() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
Definition:TargetFrameLowering.h:105
llvm::TargetIndexSDNode
Completely target-dependent object reference.
Definition:SelectionDAGNodes.h:2065
llvm::TargetIndexSDNode::getIndex
int getIndex() const
Definition:SelectionDAGNodes.h:2078
llvm::TargetIndexSDNode::getOffset
int64_t getOffset() const
Definition:SelectionDAGNodes.h:2079
llvm::TargetIndexSDNode::getTargetFlags
unsigned getTargetFlags() const
Definition:SelectionDAGNodes.h:2077
llvm::TargetLibraryInfo
Provides information about what library functions are available for the current target.
Definition:TargetLibraryInfo.h:280
llvm::TargetLibraryInfo::getVectorMappingInfo
const VecDesc * getVectorMappingInfo(StringRef F, const ElementCount &VF, bool Masked) const
Definition:TargetLibraryInfo.h:400
llvm::TargetLoweringBase::ArgListEntry
Definition:TargetLowering.h:297
llvm::TargetLoweringBase::getLibcallCallingConv
CallingConv::ID getLibcallCallingConv(RTLIB::Libcall Call) const
Get the CallingConv that should be used for the specified libcall.
Definition:TargetLowering.h:3466
llvm::TargetLoweringBase::shouldConvertConstantLoadToIntImm
virtual bool shouldConvertConstantLoadToIntImm(const APInt &Imm, Type *Ty) const
Return true if it is beneficial to convert a load of a constant to just the constant itself.
Definition:TargetLowering.h:3322
llvm::TargetLoweringBase::isSExtCheaperThanZExt
virtual bool isSExtCheaperThanZExt(EVT FromTy, EVT ToTy) const
Return true if sign-extension from FromTy to ToTy is cheaper than zero-extension.
Definition:TargetLowering.h:3085
llvm::TargetLoweringBase::getVectorIdxTy
virtual MVT getVectorIdxTy(const DataLayout &DL) const
Returns the type to be used for the index operand of: ISD::INSERT_VECTOR_ELT, ISD::EXTRACT_VECTOR_ELT...
Definition:TargetLowering.h:421
llvm::TargetLoweringBase::getTargetMachine
const TargetMachine & getTargetMachine() const
Definition:TargetLowering.h:364
llvm::TargetLoweringBase::isZExtFree
virtual bool isZExtFree(Type *FromTy, Type *ToTy) const
Return true if any actual instruction that defines a value of type FromTy implicitly zero-extends the...
Definition:TargetLowering.h:3066
llvm::TargetLoweringBase::TypePromoteInteger
@ TypePromoteInteger
Definition:TargetLowering.h:211
llvm::TargetLoweringBase::TypeExpandInteger
@ TypeExpandInteger
Definition:TargetLowering.h:212
llvm::TargetLoweringBase::TypeLegal
@ TypeLegal
Definition:TargetLowering.h:210
llvm::TargetLoweringBase::getMaxStoresPerMemcpy
unsigned getMaxStoresPerMemcpy(bool OptSize) const
Get maximum # of store operations permitted for llvm.memcpy.
Definition:TargetLowering.h:1875
llvm::TargetLoweringBase::isCommutativeBinOp
virtual bool isCommutativeBinOp(unsigned Opcode) const
Returns true if the opcode is a commutative binary operation.
Definition:TargetLowering.h:2897
llvm::TargetLoweringBase::getExtendForAtomicOps
virtual ISD::NodeType getExtendForAtomicOps() const
Returns how the platform's atomic operations are extended (ZERO_EXTEND, SIGN_EXTEND,...
Definition:TargetLowering.h:2381
llvm::TargetLoweringBase::getShiftAmountTy
EVT getShiftAmountTy(EVT LHSTy, const DataLayout &DL) const
Returns the type for the shift amount of a shift opcode.
Definition:TargetLoweringBase.cpp:890
llvm::TargetLoweringBase::isExtractSubvectorCheap
virtual bool isExtractSubvectorCheap(EVT ResVT, EVT SrcVT, unsigned Index) const
Return true if EXTRACT_SUBVECTOR is cheap for extracting this result type from this source type with ...
Definition:TargetLowering.h:3331
llvm::TargetLoweringBase::shallExtractConstSplatVectorElementToStore
virtual bool shallExtractConstSplatVectorElementToStore(Type *VectorTy, unsigned ElemSizeInBits, unsigned &Index) const
Return true if the target shall perform extract vector element and store given that the vector is kno...
Definition:TargetLowering.h:960
llvm::TargetLoweringBase::isTruncateFree
virtual bool isTruncateFree(Type *FromTy, Type *ToTy) const
Return true if it's free to truncate a value of type FromTy to type ToTy.
Definition:TargetLowering.h:2972
llvm::TargetLoweringBase::getSetCCResultType
virtual EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context, EVT VT) const
Return the ValueType of the result of SETCC operations.
Definition:TargetLoweringBase.cpp:1523
llvm::TargetLoweringBase::getTypeToTransformTo
virtual EVT getTypeToTransformTo(LLVMContext &Context, EVT VT) const
For types supported by the target, this is an identity function.
Definition:TargetLowering.h:1156
llvm::TargetLoweringBase::getBooleanContents
BooleanContent getBooleanContents(bool isVec, bool isFloat) const
For targets without i1 registers, this gives the nature of the high-bits of boolean values held in ty...
Definition:TargetLowering.h:1004
llvm::TargetLoweringBase::isCondCodeLegal
bool isCondCodeLegal(ISD::CondCode CC, MVT VT) const
Return true if the specified condition code is legal for a comparison of the specified types on this ...
Definition:TargetLowering.h:1630
llvm::TargetLoweringBase::isTypeLegal
bool isTypeLegal(EVT VT) const
Return true if the target has native support for the specified value type.
Definition:TargetLowering.h:1093
llvm::TargetLoweringBase::getPointerTy
virtual MVT getPointerTy(const DataLayout &DL, uint32_t AS=0) const
Return the pointer type for the given address space, defaults to the pointer type from the data layou...
Definition:TargetLowering.h:371
llvm::TargetLoweringBase::isOperationLegal
bool isOperationLegal(unsigned Op, EVT VT) const
Return true if the specified operation is legal on this target.
Definition:TargetLowering.h:1447
llvm::TargetLoweringBase::BooleanContent
BooleanContent
Enum that describes how the target represents true/false values.
Definition:TargetLowering.h:234
llvm::TargetLoweringBase::ZeroOrOneBooleanContent
@ ZeroOrOneBooleanContent
Definition:TargetLowering.h:236
llvm::TargetLoweringBase::UndefinedBooleanContent
@ UndefinedBooleanContent
Definition:TargetLowering.h:235
llvm::TargetLoweringBase::ZeroOrNegativeOneBooleanContent
@ ZeroOrNegativeOneBooleanContent
Definition:TargetLowering.h:237
llvm::TargetLoweringBase::getMaxStoresPerMemmove
unsigned getMaxStoresPerMemmove(bool OptSize) const
Get maximum # of store operations permitted for llvm.memmove.
Definition:TargetLowering.h:1904
llvm::TargetLoweringBase::getMaxGluedStoresPerMemcpy
virtual unsigned getMaxGluedStoresPerMemcpy() const
Get maximum # of store operations to be glued together.
Definition:TargetLowering.h:1884
llvm::TargetLoweringBase::getMinStackArgumentAlignment
Align getMinStackArgumentAlignment() const
Return the minimum stack alignment of an argument.
Definition:TargetLowering.h:2038
llvm::TargetLoweringBase::getTypeAction
LegalizeTypeAction getTypeAction(LLVMContext &Context, EVT VT) const
Return how we should legalize values of this type, either it is already legal (return 'Legal') or we ...
Definition:TargetLowering.h:1143
llvm::TargetLoweringBase::getLibcallName
const char * getLibcallName(RTLIB::Libcall Call) const
Get the libcall routine name for the specified libcall.
Definition:TargetLowering.h:3440
llvm::TargetLoweringBase::ArgListTy
std::vector< ArgListEntry > ArgListTy
Definition:TargetLowering.h:329
llvm::TargetLoweringBase::hasVectorBlend
virtual bool hasVectorBlend() const
Return true if the target has a vector blend instruction.
Definition:TargetLowering.h:3128
llvm::TargetLoweringBase::getMaxStoresPerMemset
unsigned getMaxStoresPerMemset(bool OptSize) const
Get maximum # of store operations permitted for llvm.memset.
Definition:TargetLowering.h:1865
llvm::TargetLoweringBase::getFrameIndexTy
MVT getFrameIndexTy(const DataLayout &DL) const
Return the type for frame index, which is determined by the alloca address space specified through th...
Definition:TargetLowering.h:384
llvm::TargetLoweringBase::isLegalStoreImmediate
virtual bool isLegalStoreImmediate(int64_t Value) const
Return true if the specified immediate is legal for the value input of a store instruction.
Definition:TargetLowering.h:2873
llvm::TargetLoweringBase::getVectorTypeBreakdown
unsigned getVectorTypeBreakdown(LLVMContext &Context, EVT VT, EVT &IntermediateVT, unsigned &NumIntermediates, MVT &RegisterVT) const
Vector types are broken down into some number of legal first class types.
Definition:TargetLoweringBase.cpp:1541
llvm::TargetLoweringBase::getExtendForContent
static ISD::NodeType getExtendForContent(BooleanContent Content)
Definition:TargetLowering.h:334
llvm::TargetLowering
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
Definition:TargetLowering.h:3780
llvm::TargetLowering::computeKnownBitsForFrameIndex
virtual void computeKnownBitsForFrameIndex(int FIOp, KnownBits &Known, const MachineFunction &MF) const
Determine which of the bits of FrameIndex FIOp are known to be 0.
Definition:TargetLowering.cpp:3795
llvm::TargetLowering::ComputeNumSignBitsForTargetNode
virtual unsigned ComputeNumSignBitsForTargetNode(SDValue Op, const APInt &DemandedElts, const SelectionDAG &DAG, unsigned Depth=0) const
This method can be implemented by targets that want to expose additional information about sign bits ...
Definition:TargetLowering.cpp:3809
llvm::TargetLowering::verifyTargetSDNode
virtual void verifyTargetSDNode(const SDNode *N) const
Check the given SDNode. Aborts if it is invalid.
Definition:TargetLowering.h:4935
llvm::TargetLowering::findOptimalMemOpLowering
virtual bool findOptimalMemOpLowering(std::vector< EVT > &MemOps, unsigned Limit, const MemOp &Op, unsigned DstAS, unsigned SrcAS, const AttributeList &FuncAttributes) const
Determines the optimal series of memory ops to replace the memset / memcpy.
Definition:TargetLowering.cpp:200
llvm::TargetLowering::LowerCallTo
std::pair< SDValue, SDValue > LowerCallTo(CallLoweringInfo &CLI) const
This function lowers an abstract call to a function into an actual call.
Definition:SelectionDAGBuilder.cpp:10958
llvm::TargetLowering::isKnownNeverNaNForTargetNode
virtual bool isKnownNeverNaNForTargetNode(SDValue Op, const SelectionDAG &DAG, bool SNaN=false, unsigned Depth=0) const
If SNaN is false,.
Definition:TargetLowering.cpp:3921
llvm::TargetLowering::computeKnownBitsForTargetNode
virtual void computeKnownBitsForTargetNode(const SDValue Op, KnownBits &Known, const APInt &DemandedElts, const SelectionDAG &DAG, unsigned Depth=0) const
Determine which of the bits specified in Mask are known to be either zero or one and return them in t...
Definition:TargetLowering.cpp:3774
llvm::TargetLowering::isSDNodeSourceOfDivergence
virtual bool isSDNodeSourceOfDivergence(const SDNode *N, FunctionLoweringInfo *FLI, UniformityInfo *UA) const
Definition:TargetLowering.h:3792
llvm::TargetLowering::isSDNodeAlwaysUniform
virtual bool isSDNodeAlwaysUniform(const SDNode *N) const
Definition:TargetLowering.h:3820
llvm::TargetLowering::isSplatValueForTargetNode
virtual bool isSplatValueForTargetNode(SDValue Op, const APInt &DemandedElts, APInt &UndefElts, const SelectionDAG &DAG, unsigned Depth=0) const
Return true if vector Op has the same value across all DemandedElts, indicating any elements which ma...
Definition:TargetLowering.cpp:3934
llvm::TargetLowering::isOffsetFoldingLegal
virtual bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const
Return true if folding a constant offset with the given GlobalAddress is legal.
Definition:TargetLowering.cpp:490
llvm::TargetLowering::getTargetConstantFromLoad
virtual const Constant * getTargetConstantFromLoad(LoadSDNode *LD) const
This method returns the constant pool value that will be loaded by LD.
Definition:TargetLowering.cpp:3883
llvm::TargetLowering::isGAPlusOffset
virtual bool isGAPlusOffset(SDNode *N, const GlobalValue *&GA, int64_t &Offset) const
Returns true (and the GlobalValue and the offset) if the node is a GlobalAddress + offset.
Definition:TargetLowering.cpp:5484
llvm::TargetLowering::isGuaranteedNotToBeUndefOrPoisonForTargetNode
virtual bool isGuaranteedNotToBeUndefOrPoisonForTargetNode(SDValue Op, const APInt &DemandedElts, const SelectionDAG &DAG, bool PoisonOnly, unsigned Depth) const
Return true if this function can prove that Op is never poison and, if PoisonOnly is false,...
Definition:TargetLowering.cpp:3887
llvm::TargetLowering::canCreateUndefOrPoisonForTargetNode
virtual bool canCreateUndefOrPoisonForTargetNode(SDValue Op, const APInt &DemandedElts, const SelectionDAG &DAG, bool PoisonOnly, bool ConsiderFlags, unsigned Depth) const
Return true if Op can create undef or poison from non-undef & non-poison operands.
Definition:TargetLowering.cpp:3908
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition:TargetMachine.h:77
llvm::TargetMachine::isNoopAddrSpaceCast
virtual bool isNoopAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const
Returns true if a cast between SrcAS and DestAS is a noop.
Definition:TargetMachine.h:330
llvm::TargetMachine::getTargetTriple
const Triple & getTargetTriple() const
Definition:TargetMachine.h:126
llvm::TargetMachine::Options
TargetOptions Options
Definition:TargetMachine.h:118
llvm::TargetOptions
Definition:TargetOptions.h:132
llvm::TargetRegisterInfo
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Definition:TargetRegisterInfo.h:235
llvm::TargetSubtargetInfo::getSelectionDAGInfo
virtual const SelectionDAGTargetInfo * getSelectionDAGInfo() const
Definition:TargetSubtargetInfo.h:102
llvm::TargetSubtargetInfo::getRegisterInfo
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
Definition:TargetSubtargetInfo.h:129
llvm::TargetSubtargetInfo::getFrameLowering
virtual const TargetFrameLowering * getFrameLowering() const
Definition:TargetSubtargetInfo.h:98
llvm::TargetSubtargetInfo::getTargetLowering
virtual const TargetLowering * getTargetLowering() const
Definition:TargetSubtargetInfo.h:101
llvm::Triple::isOSDarwin
bool isOSDarwin() const
Is this a "Darwin" OS (macOS, iOS, tvOS, watchOS, XROS, or DriverKit).
Definition:Triple.h:588
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition:Twine.h:81
llvm::TypeSize
Definition:TypeSize.h:334
llvm::TypeSize::getFixed
static constexpr TypeSize getFixed(ScalarTy ExactSize)
Definition:TypeSize.h:345
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition:Type.h:45
llvm::Type::isVectorTy
bool isVectorTy() const
True if this is an instance of VectorType.
Definition:Type.h:270
llvm::Type::getScalarSizeInBits
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
llvm::Type::getVoidTy
static Type * getVoidTy(LLVMContext &C)
llvm::Type::getInt8Ty
static IntegerType * getInt8Ty(LLVMContext &C)
llvm::Type::getPrimitiveSizeInBits
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
llvm::Type::getScalarType
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition:Type.h:355
llvm::Use
A Use represents the edge between a Value definition and its users.
Definition:Use.h:43
llvm::Use::set
void set(Value *Val)
Definition:Value.h:886
llvm::Use::getUser
User * getUser() const
Returns the User that contains this Use.
Definition:Use.h:72
llvm::User
Definition:User.h:44
llvm::VPGatherSDNode
This class is used to represent an VP_GATHER node.
Definition:SelectionDAGNodes.h:2888
llvm::VPLoadSDNode
This class is used to represent a VP_LOAD node.
Definition:SelectionDAGNodes.h:2602
llvm::VPScatterSDNode
This class is used to represent an VP_SCATTER node.
Definition:SelectionDAGNodes.h:2904
llvm::VPStoreSDNode
This class is used to represent a VP_STORE node.
Definition:SelectionDAGNodes.h:2660
llvm::VPStridedLoadSDNode
This class is used to represent an EXPERIMENTAL_VP_STRIDED_LOAD node.
Definition:SelectionDAGNodes.h:2630
llvm::VPStridedStoreSDNode
This class is used to represent an EXPERIMENTAL_VP_STRIDED_STORE node.
Definition:SelectionDAGNodes.h:2695
llvm::Value
LLVM Value Representation.
Definition:Value.h:74
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition:Value.h:255
llvm::VecDesc
Provides info so a possible vectorization of a function can be computed.
Definition:TargetLibraryInfo.h:42
llvm::VecDesc::isMasked
bool isMasked() const
Definition:TargetLibraryInfo.h:60
llvm::VecDesc::getVectorFnName
StringRef getVectorFnName() const
Definition:TargetLibraryInfo.h:58
llvm::cl::opt
Definition:CommandLine.h:1423
llvm::detail::DenseSetImpl::insert
std::pair< iterator, bool > insert(const ValueT &V)
Definition:DenseSet.h:213
llvm::detail::DenseSetImpl::contains
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
Definition:DenseSet.h:193
llvm::details::FixedOrScalableQuantity::getFixedValue
constexpr ScalarTy getFixedValue() const
Definition:TypeSize.h:202
llvm::details::FixedOrScalableQuantity< TypeSize, uint64_t >::isKnownLE
static constexpr bool isKnownLE(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
Definition:TypeSize.h:232
llvm::details::FixedOrScalableQuantity::isScalable
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
Definition:TypeSize.h:171
llvm::details::FixedOrScalableQuantity::isKnownEven
constexpr bool isKnownEven() const
A return value of true indicates we know at compile time that the number of elements (vscale * Min) i...
Definition:TypeSize.h:179
llvm::details::FixedOrScalableQuantity::getKnownMinValue
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
Definition:TypeSize.h:168
llvm::details::FixedOrScalableQuantity< ElementCount, unsigned >::isKnownGE
static constexpr bool isKnownGE(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
Definition:TypeSize.h:239
llvm::raw_string_ostream
A raw_ostream that writes to an std::string.
Definition:raw_ostream.h:661
uint16_t
uint32_t
uint64_t
unsigned
Analysis.h
ErrorHandling.h
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition:ErrorHandling.h:143
TargetMachine.h
llvm::APIntOps::mulhu
APInt mulhu(const APInt &C1, const APInt &C2)
Performs (2*N)-bit multiplication on zero-extended operands.
Definition:APInt.cpp:3104
llvm::APIntOps::abdu
const APInt abdu(const APInt &A, const APInt &B)
Determine the absolute difference of two APInts considered to be unsigned.
Definition:APInt.h:2242
llvm::APIntOps::avgCeilU
APInt avgCeilU(const APInt &C1, const APInt &C2)
Compute the ceil of the unsigned average of C1 and C2.
Definition:APInt.cpp:3091
llvm::APIntOps::avgFloorU
APInt avgFloorU(const APInt &C1, const APInt &C2)
Compute the floor of the unsigned average of C1 and C2.
Definition:APInt.cpp:3081
llvm::APIntOps::abds
const APInt abds(const APInt &A, const APInt &B)
Determine the absolute difference of two APInts considered to be signed.
Definition:APInt.h:2237
llvm::APIntOps::mulhs
APInt mulhs(const APInt &C1, const APInt &C2)
Performs (2*N)-bit multiplication on sign-extended operands.
Definition:APInt.cpp:3096
llvm::APIntOps::ScaleBitMask
APInt ScaleBitMask(const APInt &A, unsigned NewBitWidth, bool MatchAllBits=false)
Splat/Merge neighboring bits to widen/narrow the bitmask represented by.
Definition:APInt.cpp:2982
llvm::APIntOps::avgFloorS
APInt avgFloorS(const APInt &C1, const APInt &C2)
Compute the floor of the signed average of C1 and C2.
Definition:APInt.cpp:3076
llvm::APIntOps::avgCeilS
APInt avgCeilS(const APInt &C1, const APInt &C2)
Compute the ceil of the signed average of C1 and C2.
Definition:APInt.cpp:3086
llvm::CallingConv::C
@ C
The default llvm calling convention, compatible with C.
Definition:CallingConv.h:34
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition:CallingConv.h:24
llvm::ISD::GlobalISel::getSetCCInverse
CondCode getSetCCInverse(CondCode Operation, bool isIntegerLike)
Return the operation corresponding to !(X op Y), where 'op' is a valid SetCC operation.
Definition:SelectionDAG.cpp:643
llvm::ISD::getSetCCAndOperation
CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, EVT Type)
Return the result of a logical AND between different comparisons of identical values: ((X op1 Y) & (X...
Definition:SelectionDAG.cpp:688
llvm::ISD::isConstantSplatVectorAllOnes
bool isConstantSplatVectorAllOnes(const SDNode *N, bool BuildVectorOnly=false)
Return true if the specified node is a BUILD_VECTOR or SPLAT_VECTOR where all of the elements are ~0 ...
Definition:SelectionDAG.cpp:188
llvm::ISD::isNON_EXTLoad
bool isNON_EXTLoad(const SDNode *N)
Returns true if the specified node is a non-extending load.
Definition:SelectionDAGNodes.h:3215
llvm::ISD::NodeType
NodeType
ISD::NodeType enum - This enum defines the target-independent operators for a SelectionDAG.
Definition:ISDOpcodes.h:40
llvm::ISD::SETCC
@ SETCC
SetCC operator - This evaluates to a true value iff the condition is true.
Definition:ISDOpcodes.h:780
llvm::ISD::MERGE_VALUES
@ MERGE_VALUES
MERGE_VALUES - This node takes multiple discrete operands and returns them all as its individual resu...
Definition:ISDOpcodes.h:243
llvm::ISD::CTLZ_ZERO_UNDEF
@ CTLZ_ZERO_UNDEF
Definition:ISDOpcodes.h:753
llvm::ISD::TargetConstantPool
@ TargetConstantPool
Definition:ISDOpcodes.h:174
llvm::ISD::MDNODE_SDNODE
@ MDNODE_SDNODE
MDNODE_SDNODE - This is a node that holdes an MDNode*, which is used to reference metadata in the IR.
Definition:ISDOpcodes.h:1242
llvm::ISD::STRICT_FSETCC
@ STRICT_FSETCC
STRICT_FSETCC/STRICT_FSETCCS - Constrained versions of SETCC, used for floating-point operands only.
Definition:ISDOpcodes.h:491
llvm::ISD::STORE
@ STORE
Definition:ISDOpcodes.h:1103
llvm::ISD::ATOMIC_LOAD_FMAX
@ ATOMIC_LOAD_FMAX
Definition:ISDOpcodes.h:1347
llvm::ISD::LRINT
@ LRINT
Definition:ISDOpcodes.h:1021
llvm::ISD::DELETED_NODE
@ DELETED_NODE
DELETED_NODE - This is an illegal value that is used to catch errors.
Definition:ISDOpcodes.h:44
llvm::ISD::VECREDUCE_SEQ_FADD
@ VECREDUCE_SEQ_FADD
Generic reduction nodes.
Definition:ISDOpcodes.h:1417
llvm::ISD::FP_TO_BF16
@ FP_TO_BF16
Definition:ISDOpcodes.h:974
llvm::ISD::JumpTable
@ JumpTable
Definition:ISDOpcodes.h:81
llvm::ISD::FLOG10
@ FLOG10
Definition:ISDOpcodes.h:1008
llvm::ISD::MLOAD
@ MLOAD
Masked load and store - consecutive vector load and store operations with additional mask operand tha...
Definition:ISDOpcodes.h:1360
llvm::ISD::VECREDUCE_SMIN
@ VECREDUCE_SMIN
Definition:ISDOpcodes.h:1450
llvm::ISD::SREM
@ SREM
Definition:ISDOpcodes.h:251
llvm::ISD::FGETSIGN
@ FGETSIGN
INT = FGETSIGN(FP) - Return the sign bit of the specified floating point value as an integer 0/1 valu...
Definition:ISDOpcodes.h:512
llvm::ISD::SMUL_LOHI
@ SMUL_LOHI
SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing a signed/unsigned value of type i[2...
Definition:ISDOpcodes.h:257
llvm::ISD::SSUBO_CARRY
@ SSUBO_CARRY
Definition:ISDOpcodes.h:321
llvm::ISD::ATOMIC_LOAD_NAND
@ ATOMIC_LOAD_NAND
Definition:ISDOpcodes.h:1340
llvm::ISD::UDIV
@ UDIV
Definition:ISDOpcodes.h:250
llvm::ISD::INSERT_SUBVECTOR
@ INSERT_SUBVECTOR
INSERT_SUBVECTOR(VECTOR1, VECTOR2, IDX) - Returns a vector with VECTOR2 inserted into VECTOR1.
Definition:ISDOpcodes.h:574
llvm::ISD::UINT_TO_FP
@ UINT_TO_FP
Definition:ISDOpcodes.h:842
llvm::ISD::UMIN
@ UMIN
Definition:ISDOpcodes.h:699
llvm::ISD::JUMP_TABLE_DEBUG_INFO
@ JUMP_TABLE_DEBUG_INFO
JUMP_TABLE_DEBUG_INFO - Jumptable debug info.
Definition:ISDOpcodes.h:1131
llvm::ISD::BSWAP
@ BSWAP
Byte Swap and Counting operators.
Definition:ISDOpcodes.h:744
llvm::ISD::ROTR
@ ROTR
Definition:ISDOpcodes.h:739
llvm::ISD::FPOW
@ FPOW
Definition:ISDOpcodes.h:994
llvm::ISD::TargetBlockAddress
@ TargetBlockAddress
Definition:ISDOpcodes.h:176
llvm::ISD::ConstantFP
@ ConstantFP
Definition:ISDOpcodes.h:77
llvm::ISD::ATOMIC_LOAD_MAX
@ ATOMIC_LOAD_MAX
Definition:ISDOpcodes.h:1342
llvm::ISD::ATOMIC_STORE
@ ATOMIC_STORE
OUTCHAIN = ATOMIC_STORE(INCHAIN, val, ptr) This corresponds to "store atomic" instruction.
Definition:ISDOpcodes.h:1312
llvm::ISD::UADDO
@ UADDO
Definition:ISDOpcodes.h:331
llvm::ISD::FTRUNC
@ FTRUNC
Definition:ISDOpcodes.h:1013
llvm::ISD::SDIV
@ SDIV
Definition:ISDOpcodes.h:249
llvm::ISD::ATOMIC_LOAD_UMIN
@ ATOMIC_LOAD_UMIN
Definition:ISDOpcodes.h:1343
llvm::ISD::ADDC
@ ADDC
Carry-setting nodes for multiple precision addition and subtraction.
Definition:ISDOpcodes.h:276
llvm::ISD::FMAD
@ FMAD
FMAD - Perform a * b + c, while getting the same result as the separately rounded operations.
Definition:ISDOpcodes.h:502
llvm::ISD::FMAXNUM_IEEE
@ FMAXNUM_IEEE
Definition:ISDOpcodes.h:1045
llvm::ISD::LLRINT
@ LLRINT
Definition:ISDOpcodes.h:1022
llvm::ISD::ADD
@ ADD
Simple integer binary arithmetic operators.
Definition:ISDOpcodes.h:246
llvm::ISD::LOAD
@ LOAD
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
Definition:ISDOpcodes.h:1102
llvm::ISD::ANY_EXTEND
@ ANY_EXTEND
ANY_EXTEND - Used for integer types. The high bits are undefined.
Definition:ISDOpcodes.h:814
llvm::ISD::FSUB
@ FSUB
Definition:ISDOpcodes.h:398
llvm::ISD::ATOMIC_LOAD_USUB_COND
@ ATOMIC_LOAD_USUB_COND
Definition:ISDOpcodes.h:1351
llvm::ISD::FMA
@ FMA
FMA - Perform a * b + c with no intermediate rounding step.
Definition:ISDOpcodes.h:498
llvm::ISD::FATAN2
@ FATAN2
FATAN2 - atan2, inspired by libm.
Definition:ISDOpcodes.h:999
llvm::ISD::SUBC
@ SUBC
Definition:ISDOpcodes.h:277
llvm::ISD::FABS
@ FABS
Definition:ISDOpcodes.h:982
llvm::ISD::FNEARBYINT
@ FNEARBYINT
Definition:ISDOpcodes.h:1015
llvm::ISD::INTRINSIC_VOID
@ INTRINSIC_VOID
OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...) This node represents a target intrin...
Definition:ISDOpcodes.h:205
llvm::ISD::GlobalAddress
@ GlobalAddress
Definition:ISDOpcodes.h:78
llvm::ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS
@ ATOMIC_CMP_SWAP_WITH_SUCCESS
Val, Success, OUTCHAIN = ATOMIC_CMP_SWAP_WITH_SUCCESS(INCHAIN, ptr, cmp, swap) N.b.
Definition:ISDOpcodes.h:1325
llvm::ISD::FCOSH
@ FCOSH
Definition:ISDOpcodes.h:992
llvm::ISD::SINT_TO_FP
@ SINT_TO_FP
[SU]INT_TO_FP - These operators convert integers (whose interpreted sign depends on the first letter)...
Definition:ISDOpcodes.h:841
llvm::ISD::CONCAT_VECTORS
@ CONCAT_VECTORS
CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of vector type with the same length ...
Definition:ISDOpcodes.h:558
llvm::ISD::VECREDUCE_FMAX
@ VECREDUCE_FMAX
FMIN/FMAX nodes can have flags, for NaN/NoNaN variants.
Definition:ISDOpcodes.h:1435
llvm::ISD::FADD
@ FADD
Simple binary floating point operators.
Definition:ISDOpcodes.h:397
llvm::ISD::VECREDUCE_FMAXIMUM
@ VECREDUCE_FMAXIMUM
FMINIMUM/FMAXIMUM nodes propatate NaNs and signed zeroes using the llvm.minimum and llvm....
Definition:ISDOpcodes.h:1439
llvm::ISD::ABS
@ ABS
ABS - Determine the unsigned absolute value of a signed integer value of the same bitwidth.
Definition:ISDOpcodes.h:717
llvm::ISD::FEXP10
@ FEXP10
Definition:ISDOpcodes.h:1011
llvm::ISD::SIGN_EXTEND_VECTOR_INREG
@ SIGN_EXTEND_VECTOR_INREG
SIGN_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register sign-extension of the low ...
Definition:ISDOpcodes.h:871
llvm::ISD::FP_TO_FP16
@ FP_TO_FP16
Definition:ISDOpcodes.h:965
llvm::ISD::FACOS
@ FACOS
Definition:ISDOpcodes.h:989
llvm::ISD::VECREDUCE_SMAX
@ VECREDUCE_SMAX
Definition:ISDOpcodes.h:1449
llvm::ISD::SRL
@ SRL
Definition:ISDOpcodes.h:737
llvm::ISD::STRICT_FSETCCS
@ STRICT_FSETCCS
Definition:ISDOpcodes.h:492
llvm::ISD::FMAXIMUM
@ FMAXIMUM
Definition:ISDOpcodes.h:1051
llvm::ISD::FP16_TO_FP
@ FP16_TO_FP
FP16_TO_FP, FP_TO_FP16 - These operators are used to perform promotions and truncation for half-preci...
Definition:ISDOpcodes.h:964
llvm::ISD::FATAN
@ FATAN
Definition:ISDOpcodes.h:990
llvm::ISD::VALUETYPE
@ VALUETYPE
Definition:ISDOpcodes.h:72
llvm::ISD::ATOMIC_LOAD_OR
@ ATOMIC_LOAD_OR
Definition:ISDOpcodes.h:1338
llvm::ISD::BITCAST
@ BITCAST
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
Definition:ISDOpcodes.h:954
llvm::ISD::Register
@ Register
Definition:ISDOpcodes.h:74
llvm::ISD::BUILD_PAIR
@ BUILD_PAIR
BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.
Definition:ISDOpcodes.h:236
llvm::ISD::ATOMIC_LOAD_XOR
@ ATOMIC_LOAD_XOR
Definition:ISDOpcodes.h:1339
llvm::ISD::FFLOOR
@ FFLOOR
Definition:ISDOpcodes.h:1018
llvm::ISD::FLDEXP
@ FLDEXP
FLDEXP - ldexp, inspired by libm (op0 * 2**op1).
Definition:ISDOpcodes.h:997
llvm::ISD::BUILTIN_OP_END
@ BUILTIN_OP_END
BUILTIN_OP_END - This must be the last enum value in this list.
Definition:ISDOpcodes.h:1494
llvm::ISD::ATOMIC_LOAD_FADD
@ ATOMIC_LOAD_FADD
Definition:ISDOpcodes.h:1345
llvm::ISD::UCMP
@ UCMP
Definition:ISDOpcodes.h:706
llvm::ISD::GlobalTLSAddress
@ GlobalTLSAddress
Definition:ISDOpcodes.h:79
llvm::ISD::SRA
@ SRA
Definition:ISDOpcodes.h:736
llvm::ISD::SRCVALUE
@ SRCVALUE
SRCVALUE - This is a node type that holds a Value* that is used to make reference to a value in the L...
Definition:ISDOpcodes.h:1238
llvm::ISD::FrameIndex
@ FrameIndex
Definition:ISDOpcodes.h:80
llvm::ISD::EH_LABEL
@ EH_LABEL
EH_LABEL - Represents a label in mid basic block used to track locations needed for debug and excepti...
Definition:ISDOpcodes.h:1173
llvm::ISD::ATOMIC_LOAD_USUB_SAT
@ ATOMIC_LOAD_USUB_SAT
Definition:ISDOpcodes.h:1352
llvm::ISD::LLROUND
@ LLROUND
Definition:ISDOpcodes.h:1020
llvm::ISD::USUBO
@ USUBO
Definition:ISDOpcodes.h:335
llvm::ISD::AVGFLOORU
@ AVGFLOORU
Definition:ISDOpcodes.h:681
llvm::ISD::SIGN_EXTEND
@ SIGN_EXTEND
Conversion operators.
Definition:ISDOpcodes.h:805
llvm::ISD::FLOG2
@ FLOG2
Definition:ISDOpcodes.h:1007
llvm::ISD::AVGCEILS
@ AVGCEILS
AVGCEILS/AVGCEILU - Rounding averaging add - Add two integers using an integer of type i[N+2],...
Definition:ISDOpcodes.h:685
llvm::ISD::SCALAR_TO_VECTOR
@ SCALAR_TO_VECTOR
SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a scalar value into element 0 of the...
Definition:ISDOpcodes.h:635
llvm::ISD::TargetExternalSymbol
@ TargetExternalSymbol
Definition:ISDOpcodes.h:175
llvm::ISD::USHLSAT
@ USHLSAT
Definition:ISDOpcodes.h:367
llvm::ISD::VECREDUCE_FADD
@ VECREDUCE_FADD
These reductions have relaxed evaluation order semantics, and have a single vector operand.
Definition:ISDOpcodes.h:1432
llvm::ISD::UADDSAT
@ UADDSAT
Definition:ISDOpcodes.h:348
llvm::ISD::CTTZ_ZERO_UNDEF
@ CTTZ_ZERO_UNDEF
Bit counting operators with an undefined result for zero inputs.
Definition:ISDOpcodes.h:752
llvm::ISD::TargetJumpTable
@ TargetJumpTable
Definition:ISDOpcodes.h:173
llvm::ISD::TargetIndex
@ TargetIndex
TargetIndex - Like a constant pool entry, but with completely target-dependent semantics.
Definition:ISDOpcodes.h:183
llvm::ISD::FASIN
@ FASIN
Definition:ISDOpcodes.h:988
llvm::ISD::FMAXNUM
@ FMAXNUM
Definition:ISDOpcodes.h:1032
llvm::ISD::FPOWI
@ FPOWI
Definition:ISDOpcodes.h:995
llvm::ISD::FRINT
@ FRINT
Definition:ISDOpcodes.h:1014
llvm::ISD::PREFETCH
@ PREFETCH
PREFETCH - This corresponds to a prefetch intrinsic.
Definition:ISDOpcodes.h:1292
llvm::ISD::VECREDUCE_FMIN
@ VECREDUCE_FMIN
Definition:ISDOpcodes.h:1436
llvm::ISD::SETCCCARRY
@ SETCCCARRY
Like SetCC, ops #0 and #1 are the LHS and RHS operands to compare, but op #2 is a boolean indicating ...
Definition:ISDOpcodes.h:788
llvm::ISD::FNEG
@ FNEG
Perform various unary floating-point operations inspired by libm.
Definition:ISDOpcodes.h:981
llvm::ISD::ATOMIC_LOAD_FSUB
@ ATOMIC_LOAD_FSUB
Definition:ISDOpcodes.h:1346
llvm::ISD::BR_CC
@ BR_CC
BR_CC - Conditional branch.
Definition:ISDOpcodes.h:1148
llvm::ISD::CTTZ
@ CTTZ
Definition:ISDOpcodes.h:745
llvm::ISD::SSUBO
@ SSUBO
Same for subtraction.
Definition:ISDOpcodes.h:334
llvm::ISD::CALLSEQ_END
@ CALLSEQ_END
Definition:ISDOpcodes.h:1212
llvm::ISD::ATOMIC_LOAD_MIN
@ ATOMIC_LOAD_MIN
Definition:ISDOpcodes.h:1341
llvm::ISD::FP_TO_UINT
@ FP_TO_UINT
Definition:ISDOpcodes.h:888
llvm::ISD::STEP_VECTOR
@ STEP_VECTOR
STEP_VECTOR(IMM) - Returns a scalable vector whose lanes are comprised of a linear sequence of unsign...
Definition:ISDOpcodes.h:661
llvm::ISD::OR
@ OR
Definition:ISDOpcodes.h:710
llvm::ISD::FCANONICALIZE
@ FCANONICALIZE
Returns platform specific canonical encoding of a floating point number.
Definition:ISDOpcodes.h:515
llvm::ISD::SSUBSAT
@ SSUBSAT
RESULT = [US]SUBSAT(LHS, RHS) - Perform saturation subtraction on 2 integers with the same bit width ...
Definition:ISDOpcodes.h:356
llvm::ISD::UMULO
@ UMULO
Definition:ISDOpcodes.h:339
llvm::ISD::SRA_PARTS
@ SRA_PARTS
Definition:ISDOpcodes.h:795
llvm::ISD::SELECT
@ SELECT
Select(COND, TRUEVAL, FALSEVAL).
Definition:ISDOpcodes.h:757
llvm::ISD::UMUL_LOHI
@ UMUL_LOHI
Definition:ISDOpcodes.h:258
llvm::ISD::ATOMIC_LOAD
@ ATOMIC_LOAD
Val, OUTCHAIN = ATOMIC_LOAD(INCHAIN, ptr) This corresponds to "load atomic" instruction.
Definition:ISDOpcodes.h:1308
llvm::ISD::UNDEF
@ UNDEF
UNDEF - An undefined node.
Definition:ISDOpcodes.h:218
llvm::ISD::VECREDUCE_UMAX
@ VECREDUCE_UMAX
Definition:ISDOpcodes.h:1451
llvm::ISD::FTANH
@ FTANH
Definition:ISDOpcodes.h:993
llvm::ISD::RegisterMask
@ RegisterMask
Definition:ISDOpcodes.h:75
llvm::ISD::EXTRACT_ELEMENT
@ EXTRACT_ELEMENT
EXTRACT_ELEMENT - This is used to get the lower or upper (determined by a Constant,...
Definition:ISDOpcodes.h:229
llvm::ISD::SPLAT_VECTOR
@ SPLAT_VECTOR
SPLAT_VECTOR(VAL) - Returns a vector with the scalar value VAL duplicated in all lanes.
Definition:ISDOpcodes.h:642
llvm::ISD::AssertAlign
@ AssertAlign
AssertAlign - These nodes record if a register contains a value that has a known alignment and the tr...
Definition:ISDOpcodes.h:68
llvm::ISD::FSHL
@ FSHL
Definition:ISDOpcodes.h:740
llvm::ISD::ATOMIC_LOAD_FMIN
@ ATOMIC_LOAD_FMIN
Definition:ISDOpcodes.h:1348
llvm::ISD::BasicBlock
@ BasicBlock
Various leaf nodes.
Definition:ISDOpcodes.h:71
llvm::ISD::AVGCEILU
@ AVGCEILU
Definition:ISDOpcodes.h:686
llvm::ISD::CopyFromReg
@ CopyFromReg
CopyFromReg - This node indicates that the input value is a virtual or physical register that is defi...
Definition:ISDOpcodes.h:215
llvm::ISD::SADDO
@ SADDO
RESULT, BOOL = [SU]ADDO(LHS, RHS) - Overflow-aware nodes for addition.
Definition:ISDOpcodes.h:330
llvm::ISD::FSHR
@ FSHR
Definition:ISDOpcodes.h:741
llvm::ISD::FROUND
@ FROUND
Definition:ISDOpcodes.h:1016
llvm::ISD::TargetGlobalAddress
@ TargetGlobalAddress
TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or anything else with this node...
Definition:ISDOpcodes.h:170
llvm::ISD::USUBSAT
@ USUBSAT
Definition:ISDOpcodes.h:357
llvm::ISD::VECREDUCE_ADD
@ VECREDUCE_ADD
Integer reductions may have a result type larger than the vector element type.
Definition:ISDOpcodes.h:1444
llvm::ISD::MULHU
@ MULHU
MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing an unsigned/signed value of...
Definition:ISDOpcodes.h:674
llvm::ISD::SHL
@ SHL
Shift and rotation operations.
Definition:ISDOpcodes.h:735
llvm::ISD::ATOMIC_LOAD_CLR
@ ATOMIC_LOAD_CLR
Definition:ISDOpcodes.h:1337
llvm::ISD::VECTOR_SHUFFLE
@ VECTOR_SHUFFLE
VECTOR_SHUFFLE(VEC1, VEC2) - Returns a vector, of the same type as VEC1/VEC2.
Definition:ISDOpcodes.h:615
llvm::ISD::ATOMIC_LOAD_AND
@ ATOMIC_LOAD_AND
Definition:ISDOpcodes.h:1336
llvm::ISD::EXTRACT_SUBVECTOR
@ EXTRACT_SUBVECTOR
EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR.
Definition:ISDOpcodes.h:588
llvm::ISD::FMINNUM_IEEE
@ FMINNUM_IEEE
FMINNUM_IEEE/FMAXNUM_IEEE - Perform floating-point minimumNumber or maximumNumber on two values,...
Definition:ISDOpcodes.h:1044
llvm::ISD::FCOS
@ FCOS
Definition:ISDOpcodes.h:986
llvm::ISD::EntryToken
@ EntryToken
EntryToken - This is the marker used to indicate the start of a region.
Definition:ISDOpcodes.h:47
llvm::ISD::XOR
@ XOR
Definition:ISDOpcodes.h:711
llvm::ISD::EXTRACT_VECTOR_ELT
@ EXTRACT_VECTOR_ELT
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
Definition:ISDOpcodes.h:550
llvm::ISD::CopyToReg
@ CopyToReg
CopyToReg - This node has three operands: a chain, a register number to set to this value,...
Definition:ISDOpcodes.h:209
llvm::ISD::ZERO_EXTEND
@ ZERO_EXTEND
ZERO_EXTEND - Used for integer types, zeroing the new bits.
Definition:ISDOpcodes.h:811
llvm::ISD::TargetConstantFP
@ TargetConstantFP
Definition:ISDOpcodes.h:165
llvm::ISD::FP_TO_UINT_SAT
@ FP_TO_UINT_SAT
Definition:ISDOpcodes.h:907
llvm::ISD::CTPOP
@ CTPOP
Definition:ISDOpcodes.h:747
llvm::ISD::SELECT_CC
@ SELECT_CC
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
Definition:ISDOpcodes.h:772
llvm::ISD::FMUL
@ FMUL
Definition:ISDOpcodes.h:399
llvm::ISD::MSTORE
@ MSTORE
Definition:ISDOpcodes.h:1361
llvm::ISD::VSCALE
@ VSCALE
VSCALE(IMM) - Returns the runtime scaling factor used to calculate the number of elements within a sc...
Definition:ISDOpcodes.h:1407
llvm::ISD::VECREDUCE_XOR
@ VECREDUCE_XOR
Definition:ISDOpcodes.h:1448
llvm::ISD::ATOMIC_CMP_SWAP
@ ATOMIC_CMP_SWAP
Val, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap) For double-word atomic operations: ValLo,...
Definition:ISDOpcodes.h:1319
llvm::ISD::ATOMIC_LOAD_UMAX
@ ATOMIC_LOAD_UMAX
Definition:ISDOpcodes.h:1344
llvm::ISD::SRL_PARTS
@ SRL_PARTS
Definition:ISDOpcodes.h:796
llvm::ISD::FTAN
@ FTAN
Definition:ISDOpcodes.h:987
llvm::ISD::FMINNUM
@ FMINNUM
FMINNUM/FMAXNUM - Perform floating-point minimum or maximum on two values.
Definition:ISDOpcodes.h:1031
llvm::ISD::SUB
@ SUB
Definition:ISDOpcodes.h:247
llvm::ISD::MULHS
@ MULHS
Definition:ISDOpcodes.h:675
llvm::ISD::SSHLSAT
@ SSHLSAT
RESULT = [US]SHLSAT(LHS, RHS) - Perform saturation left shift.
Definition:ISDOpcodes.h:366
llvm::ISD::SMULO
@ SMULO
Same for multiplication.
Definition:ISDOpcodes.h:338
llvm::ISD::CONDCODE
@ CONDCODE
Definition:ISDOpcodes.h:73
llvm::ISD::PARITY
@ PARITY
Definition:ISDOpcodes.h:749
llvm::ISD::VECREDUCE_AND
@ VECREDUCE_AND
Definition:ISDOpcodes.h:1446
llvm::ISD::TargetFrameIndex
@ TargetFrameIndex
Definition:ISDOpcodes.h:172
llvm::ISD::ConstantPool
@ ConstantPool
Definition:ISDOpcodes.h:82
llvm::ISD::ANY_EXTEND_VECTOR_INREG
@ ANY_EXTEND_VECTOR_INREG
ANY_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register any-extension of the low la...
Definition:ISDOpcodes.h:860
llvm::ISD::SIGN_EXTEND_INREG
@ SIGN_EXTEND_INREG
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
Definition:ISDOpcodes.h:849
llvm::ISD::SMIN
@ SMIN
[US]{MIN/MAX} - Binary minimum or maximum of signed or unsigned integers.
Definition:ISDOpcodes.h:697
llvm::ISD::MCSymbol
@ MCSymbol
Definition:ISDOpcodes.h:178
llvm::ISD::Constant
@ Constant
Definition:ISDOpcodes.h:76
llvm::ISD::LIFETIME_START
@ LIFETIME_START
This corresponds to the llvm.lifetime.
Definition:ISDOpcodes.h:1377
llvm::ISD::FP_EXTEND
@ FP_EXTEND
X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
Definition:ISDOpcodes.h:939
llvm::ISD::VECREDUCE_OR
@ VECREDUCE_OR
Definition:ISDOpcodes.h:1447
llvm::ISD::VSELECT
@ VSELECT
Select with a vector condition (op #0) and two vector operands (ops #1 and #2), returning a vector re...
Definition:ISDOpcodes.h:766
llvm::ISD::UADDO_CARRY
@ UADDO_CARRY
Carry-using nodes for multiple precision addition and subtraction.
Definition:ISDOpcodes.h:310
llvm::ISD::MSCATTER
@ MSCATTER
Definition:ISDOpcodes.h:1373
llvm::ISD::FROUNDEVEN
@ FROUNDEVEN
Definition:ISDOpcodes.h:1017
llvm::ISD::VECREDUCE_MUL
@ VECREDUCE_MUL
Definition:ISDOpcodes.h:1445
llvm::ISD::MGATHER
@ MGATHER
Masked gather and scatter - load and store operations for a vector of random addresses with additiona...
Definition:ISDOpcodes.h:1372
llvm::ISD::LIFETIME_END
@ LIFETIME_END
Definition:ISDOpcodes.h:1378
llvm::ISD::HANDLENODE
@ HANDLENODE
HANDLENODE node - Used as a handle for various purposes.
Definition:ISDOpcodes.h:1262
llvm::ISD::VECREDUCE_UMIN
@ VECREDUCE_UMIN
Definition:ISDOpcodes.h:1452
llvm::ISD::FDIV
@ FDIV
Definition:ISDOpcodes.h:400
llvm::ISD::BF16_TO_FP
@ BF16_TO_FP
BF16_TO_FP, FP_TO_BF16 - These operators are used to perform promotions and truncation for bfloat16.
Definition:ISDOpcodes.h:973
llvm::ISD::FREM
@ FREM
Definition:ISDOpcodes.h:401
llvm::ISD::ATOMIC_LOAD_UDEC_WRAP
@ ATOMIC_LOAD_UDEC_WRAP
Definition:ISDOpcodes.h:1350
llvm::ISD::ATOMIC_LOAD_ADD
@ ATOMIC_LOAD_ADD
Definition:ISDOpcodes.h:1334
llvm::ISD::STRICT_FP_ROUND
@ STRICT_FP_ROUND
X = STRICT_FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision ...
Definition:ISDOpcodes.h:480
llvm::ISD::FMINIMUM
@ FMINIMUM
FMINIMUM/FMAXIMUM - NaN-propagating minimum/maximum that also treat -0.0 as less than 0....
Definition:ISDOpcodes.h:1050
llvm::ISD::ATOMIC_LOAD_SUB
@ ATOMIC_LOAD_SUB
Definition:ISDOpcodes.h:1335
llvm::ISD::FP_TO_SINT
@ FP_TO_SINT
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
Definition:ISDOpcodes.h:887
llvm::ISD::TargetConstant
@ TargetConstant
TargetConstant* - Like Constant*, but the DAG does not do any folding, simplification,...
Definition:ISDOpcodes.h:164
llvm::ISD::STRICT_FP_EXTEND
@ STRICT_FP_EXTEND
X = STRICT_FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
Definition:ISDOpcodes.h:485
llvm::ISD::AND
@ AND
Bitwise operators - logical and, logical or, logical xor.
Definition:ISDOpcodes.h:709
llvm::ISD::INTRINSIC_WO_CHAIN
@ INTRINSIC_WO_CHAIN
RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...) This node represents a target intrinsic fun...
Definition:ISDOpcodes.h:190
llvm::ISD::GET_FPENV_MEM
@ GET_FPENV_MEM
Gets the current floating-point environment.
Definition:ISDOpcodes.h:1078
llvm::ISD::USUBO_CARRY
@ USUBO_CARRY
Definition:ISDOpcodes.h:311
llvm::ISD::FLOG
@ FLOG
Definition:ISDOpcodes.h:1006
llvm::ISD::PSEUDO_PROBE
@ PSEUDO_PROBE
Pseudo probe for AutoFDO, as a place holder in a basic block to improve the sample counts quality.
Definition:ISDOpcodes.h:1402
llvm::ISD::SCMP
@ SCMP
[US]CMP - 3-way comparison of signed or unsigned integers.
Definition:ISDOpcodes.h:705
llvm::ISD::AVGFLOORS
@ AVGFLOORS
AVGFLOORS/AVGFLOORU - Averaging add - Add two integers using an integer of type i[N+1],...
Definition:ISDOpcodes.h:680
llvm::ISD::VECREDUCE_FMUL
@ VECREDUCE_FMUL
Definition:ISDOpcodes.h:1433
llvm::ISD::ADDE
@ ADDE
Carry-using nodes for multiple precision addition and subtraction.
Definition:ISDOpcodes.h:286
llvm::ISD::UREM
@ UREM
Definition:ISDOpcodes.h:252
llvm::ISD::SPLAT_VECTOR_PARTS
@ SPLAT_VECTOR_PARTS
SPLAT_VECTOR_PARTS(SCALAR1, SCALAR2, ...) - Returns a vector with the scalar values joined together a...
Definition:ISDOpcodes.h:651
llvm::ISD::FREEZE
@ FREEZE
FREEZE - FREEZE(VAL) returns an arbitrary value if VAL is UNDEF (or is evaluated to UNDEF),...
Definition:ISDOpcodes.h:223
llvm::ISD::INSERT_VECTOR_ELT
@ INSERT_VECTOR_ELT
INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element at IDX replaced with VAL.
Definition:ISDOpcodes.h:539
llvm::ISD::TokenFactor
@ TokenFactor
TokenFactor - This node takes multiple tokens as input and produces a single token result.
Definition:ISDOpcodes.h:52
llvm::ISD::FSIN
@ FSIN
Definition:ISDOpcodes.h:985
llvm::ISD::FEXP
@ FEXP
Definition:ISDOpcodes.h:1009
llvm::ISD::VECTOR_SPLICE
@ VECTOR_SPLICE
VECTOR_SPLICE(VEC1, VEC2, IMM) - Returns a subvector of the same type as VEC1/VEC2 from CONCAT_VECTOR...
Definition:ISDOpcodes.h:627
llvm::ISD::FCEIL
@ FCEIL
Definition:ISDOpcodes.h:1012
llvm::ISD::ATOMIC_SWAP
@ ATOMIC_SWAP
Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt) Val, OUTCHAIN = ATOMIC_LOAD_[OpName](INCHAIN,...
Definition:ISDOpcodes.h:1333
llvm::ISD::ExternalSymbol
@ ExternalSymbol
Definition:ISDOpcodes.h:83
llvm::ISD::MUL
@ MUL
Definition:ISDOpcodes.h:248
llvm::ISD::FSINH
@ FSINH
Definition:ISDOpcodes.h:991
llvm::ISD::FFREXP
@ FFREXP
FFREXP - frexp, extract fractional and exponent component of a floating-point value.
Definition:ISDOpcodes.h:1004
llvm::ISD::FP_ROUND
@ FP_ROUND
X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision of the ...
Definition:ISDOpcodes.h:920
llvm::ISD::VECTOR_COMPRESS
@ VECTOR_COMPRESS
VECTOR_COMPRESS(Vec, Mask, Passthru) consecutively place vector elements based on mask e....
Definition:ISDOpcodes.h:669
llvm::ISD::LROUND
@ LROUND
Definition:ISDOpcodes.h:1019
llvm::ISD::CTLZ
@ CTLZ
Definition:ISDOpcodes.h:746
llvm::ISD::FMAXIMUMNUM
@ FMAXIMUMNUM
Definition:ISDOpcodes.h:1056
llvm::ISD::ZERO_EXTEND_VECTOR_INREG
@ ZERO_EXTEND_VECTOR_INREG
ZERO_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register zero-extension of the low ...
Definition:ISDOpcodes.h:882
llvm::ISD::FSQRT
@ FSQRT
Definition:ISDOpcodes.h:983
llvm::ISD::ADDRSPACECAST
@ ADDRSPACECAST
ADDRSPACECAST - This operator converts between pointers of different address spaces.
Definition:ISDOpcodes.h:958
llvm::ISD::EXPERIMENTAL_VECTOR_HISTOGRAM
@ EXPERIMENTAL_VECTOR_HISTOGRAM
Definition:ISDOpcodes.h:1481
llvm::ISD::FP_TO_SINT_SAT
@ FP_TO_SINT_SAT
FP_TO_[US]INT_SAT - Convert floating point value in operand 0 to a signed or unsigned scalar integer ...
Definition:ISDOpcodes.h:906
llvm::ISD::VECREDUCE_FMINIMUM
@ VECREDUCE_FMINIMUM
Definition:ISDOpcodes.h:1440
llvm::ISD::TRUNCATE
@ TRUNCATE
TRUNCATE - Completely drop the high bits.
Definition:ISDOpcodes.h:817
llvm::ISD::VAARG
@ VAARG
VAARG - VAARG has four operands: an input chain, a pointer, a SRCVALUE, and the alignment.
Definition:ISDOpcodes.h:1217
llvm::ISD::ROTL
@ ROTL
Definition:ISDOpcodes.h:738
llvm::ISD::BlockAddress
@ BlockAddress
Definition:ISDOpcodes.h:84
llvm::ISD::VECREDUCE_SEQ_FMUL
@ VECREDUCE_SEQ_FMUL
Definition:ISDOpcodes.h:1418
llvm::ISD::SHL_PARTS
@ SHL_PARTS
SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded integer shift operations.
Definition:ISDOpcodes.h:794
llvm::ISD::AssertSext
@ AssertSext
AssertSext, AssertZext - These nodes record if a register contains a value that has already been zero...
Definition:ISDOpcodes.h:61
llvm::ISD::BITREVERSE
@ BITREVERSE
Definition:ISDOpcodes.h:748
llvm::ISD::ATOMIC_LOAD_UINC_WRAP
@ ATOMIC_LOAD_UINC_WRAP
Definition:ISDOpcodes.h:1349
llvm::ISD::FCOPYSIGN
@ FCOPYSIGN
FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.
Definition:ISDOpcodes.h:508
llvm::ISD::SADDSAT
@ SADDSAT
RESULT = [US]ADDSAT(LHS, RHS) - Perform saturation addition on 2 integers with the same bit width (W)...
Definition:ISDOpcodes.h:347
llvm::ISD::AssertZext
@ AssertZext
Definition:ISDOpcodes.h:62
llvm::ISD::FEXP2
@ FEXP2
Definition:ISDOpcodes.h:1010
llvm::ISD::SMAX
@ SMAX
Definition:ISDOpcodes.h:698
llvm::ISD::CALLSEQ_START
@ CALLSEQ_START
CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of a call sequence,...
Definition:ISDOpcodes.h:1211
llvm::ISD::UMAX
@ UMAX
Definition:ISDOpcodes.h:700
llvm::ISD::SET_FPENV_MEM
@ SET_FPENV_MEM
Sets the current floating point environment.
Definition:ISDOpcodes.h:1083
llvm::ISD::FMINIMUMNUM
@ FMINIMUMNUM
FMINIMUMNUM/FMAXIMUMNUM - minimumnum/maximumnum that is same with FMINNUM_IEEE and FMAXNUM_IEEE besid...
Definition:ISDOpcodes.h:1055
llvm::ISD::ABDS
@ ABDS
ABDS/ABDU - Absolute difference - Return the absolute difference between two numbers interpreted as s...
Definition:ISDOpcodes.h:692
llvm::ISD::SADDO_CARRY
@ SADDO_CARRY
Carry-using overflow-aware nodes for multiple precision addition and subtraction.
Definition:ISDOpcodes.h:320
llvm::ISD::INTRINSIC_W_CHAIN
@ INTRINSIC_W_CHAIN
RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...) This node represents a target in...
Definition:ISDOpcodes.h:198
llvm::ISD::TargetGlobalTLSAddress
@ TargetGlobalTLSAddress
Definition:ISDOpcodes.h:171
llvm::ISD::ABDU
@ ABDU
Definition:ISDOpcodes.h:693
llvm::ISD::BUILD_VECTOR
@ BUILD_VECTOR
BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a fixed-width vector with the specified,...
Definition:ISDOpcodes.h:530
llvm::ISD::isBuildVectorOfConstantSDNodes
bool isBuildVectorOfConstantSDNodes(const SDNode *N)
Return true if the specified node is a BUILD_VECTOR node of all ConstantSDNode or undef.
Definition:SelectionDAG.cpp:287
llvm::ISD::getExtForLoadExtType
NodeType getExtForLoadExtType(bool IsFP, LoadExtType)
Definition:SelectionDAG.cpp:601
llvm::ISD::isNormalStore
bool isNormalStore(const SDNode *N)
Returns true if the specified node is a non-truncating and unindexed store.
Definition:SelectionDAGNodes.h:3246
llvm::ISD::matchUnaryPredicate
bool matchUnaryPredicate(SDValue Op, std::function< bool(ConstantSDNode *)> Match, bool AllowUndefs=false)
Hook for matching ConstantSDNode predicate.
Definition:SelectionDAGNodes.h:3267
llvm::ISD::isZEXTLoad
bool isZEXTLoad(const SDNode *N)
Returns true if the specified node is a ZEXTLOAD.
Definition:SelectionDAGNodes.h:3233
llvm::ISD::matchUnaryFpPredicate
bool matchUnaryFpPredicate(SDValue Op, std::function< bool(ConstantFPSDNode *)> Match, bool AllowUndefs=false)
Hook for matching ConstantFPSDNode predicate.
Definition:SelectionDAGNodes.h:3275
llvm::ISD::isExtOpcode
bool isExtOpcode(unsigned Opcode)
Definition:ISDOpcodes.h:1681
llvm::ISD::isConstantSplatVectorAllZeros
bool isConstantSplatVectorAllZeros(const SDNode *N, bool BuildVectorOnly=false)
Return true if the specified node is a BUILD_VECTOR or SPLAT_VECTOR where all of the elements are 0 o...
Definition:SelectionDAG.cpp:237
llvm::ISD::isVectorShrinkable
bool isVectorShrinkable(const SDNode *N, unsigned NewEltSize, bool Signed)
Returns true if the specified node is a vector where all elements can be truncated to the specified e...
Definition:SelectionDAG.cpp:313
llvm::ISD::matchUnaryPredicateImpl
bool matchUnaryPredicateImpl(SDValue Op, std::function< bool(ConstNodeType *)> Match, bool AllowUndefs=false)
Attempt to match a unary predicate against a scalar/splat constant or every element of a constant BUI...
Definition:SelectionDAG.cpp:364
llvm::ISD::isVPBinaryOp
bool isVPBinaryOp(unsigned Opcode)
Whether this is a vector-predicated binary operation opcode.
Definition:SelectionDAG.cpp:515
llvm::ISD::getSetCCInverse
CondCode getSetCCInverse(CondCode Operation, EVT Type)
Return the operation corresponding to !(X op Y), where 'op' is a valid SetCC operation.
Definition:SelectionDAG.cpp:639
llvm::ISD::getBaseOpcodeForVP
std::optional< unsigned > getBaseOpcodeForVP(unsigned Opcode, bool hasFPExcept)
Translate this VP Opcode to its corresponding non-VP Opcode.
Definition:SelectionDAG.cpp:576
llvm::ISD::isTrueWhenEqual
bool isTrueWhenEqual(CondCode Cond)
Return true if the specified condition returns true if the two operands to the condition are equal.
Definition:ISDOpcodes.h:1668
llvm::ISD::getVPMaskIdx
std::optional< unsigned > getVPMaskIdx(unsigned Opcode)
The operand position of the vector mask.
Definition:SelectionDAG.cpp:553
llvm::ISD::getUnorderedFlavor
unsigned getUnorderedFlavor(CondCode Cond)
This function returns 0 if the condition is always false if an operand is a NaN, 1 if the condition i...
Definition:ISDOpcodes.h:1673
llvm::ISD::getVPExplicitVectorLengthIdx
std::optional< unsigned > getVPExplicitVectorLengthIdx(unsigned Opcode)
The operand position of the explicit vector length parameter.
Definition:SelectionDAG.cpp:565
llvm::ISD::isEXTLoad
bool isEXTLoad(const SDNode *N)
Returns true if the specified node is a EXTLOAD.
Definition:SelectionDAGNodes.h:3221
llvm::ISD::allOperandsUndef
bool allOperandsUndef(const SDNode *N)
Return true if the node has at least one operand and all operands of the specified node are ISD::UNDE...
Definition:SelectionDAG.cpp:350
llvm::ISD::isFreezeUndef
bool isFreezeUndef(const SDNode *N)
Return true if the specified node is FREEZE(UNDEF).
Definition:SelectionDAG.cpp:359
llvm::ISD::getSetCCSwappedOperands
CondCode getSetCCSwappedOperands(CondCode Operation)
Return the operation corresponding to (Y op X) when given the operation for (X op Y).
Definition:SelectionDAG.cpp:616
llvm::ISD::getVPForBaseOpcode
std::optional< unsigned > getVPForBaseOpcode(unsigned Opcode)
Translate this non-VP Opcode to its corresponding VP Opcode.
Definition:SelectionDAG.cpp:590
llvm::ISD::MemIndexType
MemIndexType
MemIndexType enum - This enum defines how to interpret MGATHER/SCATTER's index parameter when calcula...
Definition:ISDOpcodes.h:1572
llvm::ISD::isBuildVectorAllZeros
bool isBuildVectorAllZeros(const SDNode *N)
Return true if the specified node is a BUILD_VECTOR where all of the elements are 0 or undef.
Definition:SelectionDAG.cpp:283
llvm::ISD::isConstantSplatVector
bool isConstantSplatVector(const SDNode *N, APInt &SplatValue)
Node predicates.
Definition:SelectionDAG.cpp:153
llvm::ISD::getInverseMinMaxOpcode
NodeType getInverseMinMaxOpcode(unsigned MinMaxOpc)
Given a MinMaxOpc of ISD::(U|S)MIN or ISD::(U|S)MAX, returns ISD::(U|S)MAX and ISD::(U|S)MIN,...
Definition:SelectionDAG.cpp:433
llvm::ISD::matchBinaryPredicate
bool matchBinaryPredicate(SDValue LHS, SDValue RHS, std::function< bool(ConstantSDNode *, ConstantSDNode *)> Match, bool AllowUndefs=false, bool AllowTypeMismatch=false)
Attempt to match a binary predicate against a pair of scalar/splat constants or every element of a pa...
Definition:SelectionDAG.cpp:396
llvm::ISD::isVPReduction
bool isVPReduction(unsigned Opcode)
Whether this is a vector-predicated reduction opcode.
Definition:SelectionDAG.cpp:527
llvm::ISD::MemIndexedMode
MemIndexedMode
MemIndexedMode enum - This enum defines the load / store indexed addressing modes.
Definition:ISDOpcodes.h:1559
llvm::ISD::UNINDEXED
@ UNINDEXED
Definition:ISDOpcodes.h:1559
llvm::ISD::isBuildVectorOfConstantFPSDNodes
bool isBuildVectorOfConstantFPSDNodes(const SDNode *N)
Return true if the specified node is a BUILD_VECTOR node of all ConstantFPSDNode or undef.
Definition:SelectionDAG.cpp:300
llvm::ISD::isSEXTLoad
bool isSEXTLoad(const SDNode *N)
Returns true if the specified node is a SEXTLOAD.
Definition:SelectionDAGNodes.h:3227
llvm::ISD::CondCode
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out,...
Definition:ISDOpcodes.h:1610
llvm::ISD::SETOEQ
@ SETOEQ
Definition:ISDOpcodes.h:1613
llvm::ISD::SETUNE
@ SETUNE
Definition:ISDOpcodes.h:1626
llvm::ISD::SETUEQ
@ SETUEQ
Definition:ISDOpcodes.h:1621
llvm::ISD::SETTRUE2
@ SETTRUE2
Definition:ISDOpcodes.h:1636
llvm::ISD::SETOLE
@ SETOLE
Definition:ISDOpcodes.h:1617
llvm::ISD::SETOLT
@ SETOLT
Definition:ISDOpcodes.h:1616
llvm::ISD::SETNE
@ SETNE
Definition:ISDOpcodes.h:1635
llvm::ISD::SETUGT
@ SETUGT
Definition:ISDOpcodes.h:1622
llvm::ISD::SETOGT
@ SETOGT
Definition:ISDOpcodes.h:1614
llvm::ISD::SETULT
@ SETULT
Definition:ISDOpcodes.h:1624
llvm::ISD::SETUO
@ SETUO
Definition:ISDOpcodes.h:1620
llvm::ISD::SETONE
@ SETONE
Definition:ISDOpcodes.h:1618
llvm::ISD::SETGT
@ SETGT
Definition:ISDOpcodes.h:1631
llvm::ISD::SETFALSE2
@ SETFALSE2
Definition:ISDOpcodes.h:1629
llvm::ISD::SETLT
@ SETLT
Definition:ISDOpcodes.h:1633
llvm::ISD::SETO
@ SETO
Definition:ISDOpcodes.h:1619
llvm::ISD::SETGE
@ SETGE
Definition:ISDOpcodes.h:1632
llvm::ISD::SETTRUE
@ SETTRUE
Definition:ISDOpcodes.h:1627
llvm::ISD::SETUGE
@ SETUGE
Definition:ISDOpcodes.h:1623
llvm::ISD::SETLE
@ SETLE
Definition:ISDOpcodes.h:1634
llvm::ISD::SETULE
@ SETULE
Definition:ISDOpcodes.h:1625
llvm::ISD::SETOGE
@ SETOGE
Definition:ISDOpcodes.h:1615
llvm::ISD::SETFALSE
@ SETFALSE
Definition:ISDOpcodes.h:1612
llvm::ISD::SETEQ
@ SETEQ
Definition:ISDOpcodes.h:1630
llvm::ISD::SETCC_INVALID
@ SETCC_INVALID
Definition:ISDOpcodes.h:1638
llvm::ISD::isBuildVectorAllOnes
bool isBuildVectorAllOnes(const SDNode *N)
Return true if the specified node is a BUILD_VECTOR where all of the elements are ~0 or undef.
Definition:SelectionDAG.cpp:279
llvm::ISD::getVecReduceBaseOpcode
NodeType getVecReduceBaseOpcode(unsigned VecReduceOpcode)
Get underlying scalar opcode for VECREDUCE opcode.
Definition:SelectionDAG.cpp:448
llvm::ISD::LoadExtType
LoadExtType
LoadExtType enum - This enum defines the three variants of LOADEXT (load with extension).
Definition:ISDOpcodes.h:1590
llvm::ISD::NON_EXTLOAD
@ NON_EXTLOAD
Definition:ISDOpcodes.h:1590
llvm::ISD::SEXTLOAD
@ SEXTLOAD
Definition:ISDOpcodes.h:1590
llvm::ISD::ZEXTLOAD
@ ZEXTLOAD
Definition:ISDOpcodes.h:1590
llvm::ISD::EXTLOAD
@ EXTLOAD
Definition:ISDOpcodes.h:1590
llvm::ISD::isVPOpcode
bool isVPOpcode(unsigned Opcode)
Whether this is a vector-predicated Opcode.
Definition:SelectionDAG.cpp:504
llvm::ISD::getSetCCOrOperation
CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, EVT Type)
Return the result of a logical OR between different comparisons of identical values: ((X op1 Y) | (X ...
Definition:SelectionDAG.cpp:667
llvm::PatternMatch::m_And
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
Definition:PatternMatch.h:1216
llvm::PatternMatch::m_Deferred
deferredval_ty< Value > m_Deferred(Value *const &V)
Like m_Specific(), but works if the specific value to match is determined as part of the same match()...
Definition:PatternMatch.h:903
llvm::PatternMatch::m_Neg
BinaryOp_match< cst_pred_ty< is_zero_int >, ValTy, Instruction::Sub > m_Neg(const ValTy &V)
Matches a 'Neg' as 'sub 0, V'.
Definition:PatternMatch.h:2820
llvm::PatternMatch::m_Value
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
Definition:PatternMatch.h:92
llvm::RTLIB::Libcall
Libcall
RTLIB::Libcall enum - This enum defines all of the runtime library calls the backend can emit.
Definition:RuntimeLibcalls.h:33
llvm::RTLIB::getMEMCPY_ELEMENT_UNORDERED_ATOMIC
Libcall getMEMCPY_ELEMENT_UNORDERED_ATOMIC(uint64_t ElementSize)
getMEMCPY_ELEMENT_UNORDERED_ATOMIC - Return MEMCPY_ELEMENT_UNORDERED_ATOMIC_* value for the given ele...
Definition:TargetLoweringBase.cpp:535
llvm::RTLIB::getMEMSET_ELEMENT_UNORDERED_ATOMIC
Libcall getMEMSET_ELEMENT_UNORDERED_ATOMIC(uint64_t ElementSize)
getMEMSET_ELEMENT_UNORDERED_ATOMIC - Return MEMSET_ELEMENT_UNORDERED_ATOMIC_* value for the given ele...
Definition:TargetLoweringBase.cpp:569
llvm::RTLIB::getMEMMOVE_ELEMENT_UNORDERED_ATOMIC
Libcall getMEMMOVE_ELEMENT_UNORDERED_ATOMIC(uint64_t ElementSize)
getMEMMOVE_ELEMENT_UNORDERED_ATOMIC - Return MEMMOVE_ELEMENT_UNORDERED_ATOMIC_* value for the given e...
Definition:TargetLoweringBase.cpp:552
llvm::SDPatternMatch
Definition:SDPatternMatch.h:23
llvm::SDPatternMatch::sd_match
bool sd_match(SDNode *N, const SelectionDAG *DAG, Pattern &&P)
Definition:SDPatternMatch.h:67
llvm::cl::Hidden
@ Hidden
Definition:CommandLine.h:137
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition:CommandLine.h:443
llvm::dwarf::DW_OP_LLVM_arg
@ DW_OP_LLVM_arg
Only used in LLVM metadata.
Definition:Dwarf.h:147
llvm::sampleprof::Base
@ Base
Definition:Discriminator.h:58
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::Log2_32_Ceil
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
Definition:MathExtras.h:354
llvm::Offset
@ Offset
Definition:DWP.cpp:480
llvm::operator<
bool operator<(int64_t V1, const APSInt &V2)
Definition:APSInt.h:361
llvm::getICmpCondCode
ISD::CondCode getICmpCondCode(ICmpInst::Predicate Pred)
getICmpCondCode - Return the ISD condition code corresponding to the given LLVM IR integer condition ...
Definition:Analysis.cpp:233
llvm::peekThroughExtractSubvectors
SDValue peekThroughExtractSubvectors(SDValue V)
Return the non-extracted vector source operand of V if it exists.
Definition:SelectionDAG.cpp:12309
llvm::all_of
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition:STLExtras.h:1739
llvm::isNullConstant
bool isNullConstant(SDValue V)
Returns true if V is a constant integer zero.
Definition:SelectionDAG.cpp:12205
llvm::isUIntN
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
Definition:MathExtras.h:256
llvm::isAllOnesOrAllOnesSplat
bool isAllOnesOrAllOnesSplat(const MachineInstr &MI, const MachineRegisterInfo &MRI, bool AllowUndefs=false)
Return true if the value is a constant -1 integer or a splatted vector of a constant -1 integer (with...
Definition:Utils.cpp:1565
llvm::getBitwiseNotOperand
SDValue getBitwiseNotOperand(SDValue V, SDValue Mask, bool AllowUndefs)
If V is a bitwise not, returns the inverted operand.
Definition:SelectionDAG.cpp:5989
llvm::Depth
@ Depth
Definition:SIMachineScheduler.h:36
llvm::peekThroughBitcasts
SDValue peekThroughBitcasts(SDValue V)
Return the non-bitcasted source operand of V if it exists.
Definition:SelectionDAG.cpp:12297
llvm::LoopIdiomVectorizeStyle::Masked
@ Masked
llvm::enumerate
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
Definition:STLExtras.h:2448
llvm::countr_one
int countr_one(T Value)
Count the number of ones from the least significant bit to the first zero bit.
Definition:bit.h:307
llvm::LibFunc
LibFunc
Definition:TargetLibraryInfo.h:68
llvm::PointerTy
void * PointerTy
Definition:GenericValue.h:21
llvm::isIntOrFPConstant
bool isIntOrFPConstant(SDValue V)
Return true if V is either a integer or FP constant.
Definition:SelectionDAGNodes.h:1872
llvm::DiagnosticPredicateTy::Match
@ Match
llvm::getConstantDataArrayInfo
bool getConstantDataArrayInfo(const Value *V, ConstantDataArraySlice &Slice, unsigned ElementSize, uint64_t Offset=0)
Returns true if the value V is a pointer into a ConstantDataArray.
Definition:ValueTracking.cpp:6481
llvm::bit_width
int bit_width(T Value)
Returns the number of bits needed to represent Value if Value is nonzero.
Definition:bit.h:317
llvm::maximum
LLVM_READONLY APFloat maximum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2019 maximum semantics.
Definition:APFloat.h:1604
llvm::append_range
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition:STLExtras.h:2115
llvm::shouldOptimizeForSize
bool shouldOptimizeForSize(const MachineFunction *MF, ProfileSummaryInfo *PSI, const MachineBlockFrequencyInfo *BFI, PGSOQueryType QueryType=PGSOQueryType::Other)
Returns true if machine function MF is suggested to be size-optimized based on the profile.
Definition:MachineSizeOpts.cpp:27
llvm::make_early_inc_range
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
Definition:STLExtras.h:657
llvm::getAlign
MaybeAlign getAlign(const Function &F, unsigned Index)
Definition:NVPTXUtilities.cpp:323
llvm::isNullOrNullSplat
bool isNullOrNullSplat(const MachineInstr &MI, const MachineRegisterInfo &MRI, bool AllowUndefs=false)
Return true if the value is a constant 0 integer or a splatted vector of a constant 0 integer (with n...
Definition:Utils.cpp:1547
llvm::isMinSignedConstant
bool isMinSignedConstant(SDValue V)
Returns true if V is a constant min signed integer value.
Definition:SelectionDAG.cpp:12229
llvm::isConstOrConstSplatFP
ConstantFPSDNode * isConstOrConstSplatFP(SDValue N, bool AllowUndefs=false)
Returns the SDNode if it is a constant splat BuildVector or constant float.
Definition:SelectionDAG.cpp:12377
llvm::getConstantRangeFromMetadata
ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD)
Parse out a conservative ConstantRange from !range metadata.
Definition:ConstantRange.cpp:2264
llvm::frexp
APFloat frexp(const APFloat &X, int &Exp, APFloat::roundingMode RM)
Equivalent of C standard library function.
Definition:APFloat.h:1526
llvm::getOffset
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
Definition:RuntimeDyld.cpp:172
llvm::any_of
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition:STLExtras.h:1746
llvm::getShuffleDemandedElts
bool getShuffleDemandedElts(int SrcWidth, ArrayRef< int > Mask, const APInt &DemandedElts, APInt &DemandedLHS, APInt &DemandedRHS, bool AllowUndefElts=false)
Transform a shuffle mask's output demanded element mask into demanded element masks for the 2 operand...
Definition:VectorUtils.cpp:373
llvm::maxnum
LLVM_READONLY APFloat maxnum(const APFloat &A, const APFloat &B)
Implements IEEE-754 2019 maximumNumber semantics.
Definition:APFloat.h:1563
llvm::Log2_32
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
Definition:MathExtras.h:341
llvm::isBitwiseNot
bool isBitwiseNot(SDValue V, bool AllowUndefs=false)
Returns true if V is a bitwise not operation.
Definition:SelectionDAG.cpp:12321
llvm::isPowerOf2_32
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition:MathExtras.h:292
llvm::get
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
Definition:PointerIntPair.h:270
llvm::checkForCycles
void checkForCycles(const SelectionDAG *DAG, bool force=false)
Definition:SelectionDAG.cpp:13766
llvm::sort
void sort(IteratorTy Start, IteratorTy End)
Definition:STLExtras.h:1664
llvm::minimumnum
LLVM_READONLY APFloat minimumnum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2019 minimumNumber semantics.
Definition:APFloat.h:1590
llvm::ComplexDeinterleavingOperation::Splat
@ Splat
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition:Debug.cpp:163
llvm::peekThroughTruncates
SDValue peekThroughTruncates(SDValue V)
Return the non-truncated source operand of V if it exists.
Definition:SelectionDAG.cpp:12315
llvm::none_of
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
Definition:STLExtras.h:1753
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition:Error.cpp:167
llvm::getVScaleRange
ConstantRange getVScaleRange(const Function *F, unsigned BitWidth)
Determine the possible constant range of vscale with the given bit width, based on the vscale_range f...
Definition:ValueTracking.cpp:1058
llvm::peekThroughOneUseBitcasts
SDValue peekThroughOneUseBitcasts(SDValue V)
Return the non-bitcasted and one-use source operand of V if it exists.
Definition:SelectionDAG.cpp:12303
llvm::CodeGenOptLevel
CodeGenOptLevel
Code generation optimization level.
Definition:CodeGen.h:54
llvm::CodeGenOptLevel::None
@ None
-O0
llvm::isOneOrOneSplat
bool isOneOrOneSplat(SDValue V, bool AllowUndefs=false)
Return true if the value is a constant 1 integer or a splatted vector of a constant 1 integer (with n...
Definition:SelectionDAG.cpp:12414
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition:raw_ostream.cpp:907
llvm::PackElem::Hi
@ Hi
llvm::PackElem::Lo
@ Lo
llvm::IRMemLocation::Other
@ Other
Any other memory.
llvm::minnum
LLVM_READONLY APFloat minnum(const APFloat &A, const APFloat &B)
Implements IEEE-754 2019 minimumNumber semantics.
Definition:APFloat.h:1549
llvm::RecurKind::Mul
@ Mul
Product of integers.
llvm::isNullConstantOrUndef
bool isNullConstantOrUndef(SDValue V)
Returns true if V is a constant integer zero or an UNDEF node.
Definition:SelectionDAG.cpp:12210
llvm::computeKnownBits
void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
Definition:ValueTracking.cpp:164
llvm::isInTailCallPosition
bool isInTailCallPosition(const CallBase &Call, const TargetMachine &TM, bool ReturnsFirstArg=false)
Test if the given instruction is in a position to be optimized with a tail-call.
Definition:Analysis.cpp:535
llvm::Op
DWARFExpression::Operation Op
Definition:DWARFExpression.cpp:22
llvm::isConstOrConstSplat
ConstantSDNode * isConstOrConstSplat(SDValue N, bool AllowUndefs=false, bool AllowTruncation=false)
Returns the SDNode if it is a constant splat BuildVector or constant int.
Definition:SelectionDAG.cpp:12331
llvm::copy
OutputIt copy(R &&Range, OutputIt Out)
Definition:STLExtras.h:1841
llvm::BitWidth
constexpr unsigned BitWidth
Definition:BitmaskEnum.h:217
llvm::funcReturnsFirstArgOfCall
bool funcReturnsFirstArgOfCall(const CallInst &CI)
Returns true if the parent of CI returns CI's first argument after calling CI.
Definition:Analysis.cpp:715
llvm::isOneConstant
bool isOneConstant(SDValue V)
Returns true if V is a constant integer one.
Definition:SelectionDAG.cpp:12224
llvm::is_contained
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition:STLExtras.h:1903
llvm::commonAlignment
Align commonAlignment(Align A, uint64_t Offset)
Returns the alignment that satisfies both alignments.
Definition:Alignment.h:212
llvm::isNullFPConstant
bool isNullFPConstant(SDValue V)
Returns true if V is an FP constant with a value of positive zero.
Definition:SelectionDAG.cpp:12214
llvm::SignExtend64
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
Definition:MathExtras.h:582
llvm::Log2
unsigned Log2(Align A)
Returns the log2 of the alignment.
Definition:Alignment.h:208
llvm::computeKnownBitsFromRangeMetadata
void computeKnownBitsFromRangeMetadata(const MDNode &Ranges, KnownBits &Known)
Compute known bits from the range metadata.
Definition:ValueTracking.cpp:439
llvm::minimum
LLVM_READONLY APFloat minimum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2019 minimum semantics.
Definition:APFloat.h:1577
llvm::maximumnum
LLVM_READONLY APFloat maximumnum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2019 maximumNumber semantics.
Definition:APFloat.h:1617
llvm::isNeutralConstant
bool isNeutralConstant(unsigned Opc, SDNodeFlags Flags, SDValue V, unsigned OperandNo)
Returns true if V is a neutral element of Opc with Flags.
Definition:SelectionDAG.cpp:12234
llvm::Guid
@ Guid
Definition:PGOCtxProfWriter.h:22
llvm::isAllOnesConstant
bool isAllOnesConstant(SDValue V)
Returns true if V is an integer constant with all bits set.
Definition:SelectionDAG.cpp:12219
llvm::NextPowerOf2
constexpr uint64_t NextPowerOf2(uint64_t A)
Returns the next power of two (in 64-bits) that is strictly greater than A.
Definition:MathExtras.h:383
std::swap
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition:BitVector.h:860
raw_ostream.h
N
#define N
llvm::AAMDNodes
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Definition:Metadata.h:764
llvm::AAMDNodes::TBAAStruct
MDNode * TBAAStruct
The tag for type-based alias analysis (tbaa struct).
Definition:Metadata.h:784
llvm::AAMDNodes::TBAA
MDNode * TBAA
The tag for type-based alias analysis.
Definition:Metadata.h:781
llvm::APFloatBase::IEEEsingle
static const fltSemantics & IEEEsingle() LLVM_READNONE
Definition:APFloat.cpp:257
llvm::APFloatBase::cmpResult
cmpResult
IEEE-754R 5.11: Floating Point Comparison Relations.
Definition:APFloat.h:292
llvm::APFloatBase::cmpUnordered
@ cmpUnordered
Definition:APFloat.h:296
llvm::APFloatBase::cmpLessThan
@ cmpLessThan
Definition:APFloat.h:293
llvm::APFloatBase::cmpEqual
@ cmpEqual
Definition:APFloat.h:294
llvm::APFloatBase::cmpGreaterThan
@ cmpGreaterThan
Definition:APFloat.h:295
llvm::APFloatBase::rmTowardNegative
static constexpr roundingMode rmTowardNegative
Definition:APFloat.h:305
llvm::APFloatBase::rmNearestTiesToEven
static constexpr roundingMode rmNearestTiesToEven
Definition:APFloat.h:302
llvm::APFloatBase::rmTowardZero
static constexpr roundingMode rmTowardZero
Definition:APFloat.h:306
llvm::APFloatBase::IEEEquad
static const fltSemantics & IEEEquad() LLVM_READNONE
Definition:APFloat.cpp:259
llvm::APFloatBase::IEEEdouble
static const fltSemantics & IEEEdouble() LLVM_READNONE
Definition:APFloat.cpp:258
llvm::APFloatBase::IEEEhalf
static const fltSemantics & IEEEhalf() LLVM_READNONE
Definition:APFloat.cpp:255
llvm::APFloatBase::rmTowardPositive
static constexpr roundingMode rmTowardPositive
Definition:APFloat.h:304
llvm::APFloatBase::BFloat
static const fltSemantics & BFloat() LLVM_READNONE
Definition:APFloat.cpp:256
llvm::APFloatBase::opStatus
opStatus
IEEE-754R 7: Default exception handling.
Definition:APFloat.h:318
llvm::APFloatBase::opOK
@ opOK
Definition:APFloat.h:319
llvm::APFloatBase::opInexact
@ opInexact
Definition:APFloat.h:324
llvm::APFloatBase::opInvalidOp
@ opInvalidOp
Definition:APFloat.h:320
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition:Alignment.h:39
llvm::ConstantDataArraySlice
Represents offset+length into a ConstantDataArray.
Definition:ValueTracking.h:662
llvm::ConstantDataArraySlice::Length
uint64_t Length
Length of the slice.
Definition:ValueTracking.h:671
llvm::ConstantDataArraySlice::Offset
uint64_t Offset
Slice starts at this Offset.
Definition:ValueTracking.h:668
llvm::ConstantDataArraySlice::move
void move(uint64_t Delta)
Moves the Offset and adjusts Length accordingly.
Definition:ValueTracking.h:674
llvm::ConstantDataArraySlice::Array
const ConstantDataArray * Array
ConstantDataArray pointer.
Definition:ValueTracking.h:665
llvm::EVT
Extended Value Type.
Definition:ValueTypes.h:35
llvm::EVT::getStoreSize
TypeSize getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
Definition:ValueTypes.h:390
llvm::EVT::isSimple
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
Definition:ValueTypes.h:137
llvm::EVT::getRawBits
intptr_t getRawBits() const
Definition:ValueTypes.h:507
llvm::EVT::getVectorVT
static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements, bool IsScalable=false)
Returns the EVT that represents a vector NumElements in length, where each element is of type VT.
Definition:ValueTypes.h:74
llvm::EVT::bitsGT
bool bitsGT(EVT VT) const
Return true if this has more bits than VT.
Definition:ValueTypes.h:279
llvm::EVT::bitsLT
bool bitsLT(EVT VT) const
Return true if this has less bits than VT.
Definition:ValueTypes.h:295
llvm::EVT::isFloatingPoint
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
Definition:ValueTypes.h:147
llvm::EVT::getVectorElementCount
ElementCount getVectorElementCount() const
Definition:ValueTypes.h:345
llvm::EVT::getSizeInBits
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition:ValueTypes.h:368
llvm::EVT::getVectorMinNumElements
unsigned getVectorMinNumElements() const
Given a vector type, return the minimum number of elements it contains.
Definition:ValueTypes.h:354
llvm::EVT::getScalarSizeInBits
uint64_t getScalarSizeInBits() const
Definition:ValueTypes.h:380
llvm::EVT::getSimpleVT
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Definition:ValueTypes.h:311
llvm::EVT::getIntegerVT
static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth)
Returns the EVT that represents an integer with the given number of bits.
Definition:ValueTypes.h:65
llvm::EVT::isFixedLengthVector
bool isFixedLengthVector() const
Definition:ValueTypes.h:181
llvm::EVT::isVector
bool isVector() const
Return true if this is a vector value type.
Definition:ValueTypes.h:168
llvm::EVT::getScalarType
EVT getScalarType() const
If this is a vector type, return the element type, otherwise return this.
Definition:ValueTypes.h:318
llvm::EVT::bitsGE
bool bitsGE(EVT VT) const
Return true if this has no less bits than VT.
Definition:ValueTypes.h:287
llvm::EVT::bitsEq
bool bitsEq(EVT VT) const
Return true if this has the same number of bits as VT.
Definition:ValueTypes.h:251
llvm::EVT::getTypeForEVT
Type * getTypeForEVT(LLVMContext &Context) const
This method returns an LLVM type corresponding to the specified EVT.
Definition:ValueTypes.cpp:210
llvm::EVT::isScalableVector
bool isScalableVector() const
Return true if this is a vector type where the runtime length is machine dependent.
Definition:ValueTypes.h:174
llvm::EVT::getVectorElementType
EVT getVectorElementType() const
Given a vector type, return the type of each element.
Definition:ValueTypes.h:323
llvm::EVT::isExtended
bool isExtended() const
Test if the given EVT is extended (as opposed to being simple).
Definition:ValueTypes.h:142
llvm::EVT::getFltSemantics
const fltSemantics & getFltSemantics() const
Returns an APFloat semantics tag appropriate for the value type.
Definition:ValueTypes.cpp:320
llvm::EVT::getVectorNumElements
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
Definition:ValueTypes.h:331
llvm::EVT::bitsLE
bool bitsLE(EVT VT) const
Return true if this has no more bits than VT.
Definition:ValueTypes.h:303
llvm::EVT::getHalfNumVectorElementsVT
EVT getHalfNumVectorElementsVT(LLVMContext &Context) const
Definition:ValueTypes.h:448
llvm::EVT::isInteger
bool isInteger() const
Return true if this is an integer or a vector integer type.
Definition:ValueTypes.h:152
llvm::KnownBits
Definition:KnownBits.h:23
llvm::KnownBits::makeConstant
static KnownBits makeConstant(const APInt &C)
Create known bits from a known constant.
Definition:KnownBits.h:293
llvm::KnownBits::sextInReg
KnownBits sextInReg(unsigned SrcBitWidth) const
Return known bits for a in-register sign extension of the value we're tracking.
Definition:KnownBits.cpp:158
llvm::KnownBits::mulhu
static KnownBits mulhu(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits from zero-extended multiply-hi.
Definition:KnownBits.cpp:909
llvm::KnownBits::countMinSignBits
unsigned countMinSignBits() const
Returns the number of times the sign bit is replicated into the other bits.
Definition:KnownBits.h:247
llvm::KnownBits::smax
static KnownBits smax(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for smax(LHS, RHS).
Definition:KnownBits.cpp:211
llvm::KnownBits::isNonNegative
bool isNonNegative() const
Returns true if this value is known to be non-negative.
Definition:KnownBits.h:100
llvm::KnownBits::isZero
bool isZero() const
Returns true if value is all zero.
Definition:KnownBits.h:79
llvm::KnownBits::makeNonNegative
void makeNonNegative()
Make this value non-negative.
Definition:KnownBits.h:116
llvm::KnownBits::usub_sat
static KnownBits usub_sat(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from llvm.usub.sat(LHS, RHS)
Definition:KnownBits.cpp:774
llvm::KnownBits::countMinTrailingZeros
unsigned countMinTrailingZeros() const
Returns the minimum number of trailing zero bits.
Definition:KnownBits.h:234
llvm::KnownBits::ashr
static KnownBits ashr(const KnownBits &LHS, const KnownBits &RHS, bool ShAmtNonZero=false, bool Exact=false)
Compute known bits for ashr(LHS, RHS).
Definition:KnownBits.cpp:428
llvm::KnownBits::urem
static KnownBits urem(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for urem(LHS, RHS).
Definition:KnownBits.cpp:1049
llvm::KnownBits::isUnknown
bool isUnknown() const
Returns true if we don't know any bits.
Definition:KnownBits.h:65
llvm::KnownBits::countMaxTrailingZeros
unsigned countMaxTrailingZeros() const
Returns the maximum number of trailing zero bits possible.
Definition:KnownBits.h:266
llvm::KnownBits::ne
static std::optional< bool > ne(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_NE result.
Definition:KnownBits.cpp:496
llvm::KnownBits::makeNegative
void makeNegative()
Make this value negative.
Definition:KnownBits.h:111
llvm::KnownBits::trunc
KnownBits trunc(unsigned BitWidth) const
Return known bits for a truncation of the value we're tracking.
Definition:KnownBits.h:153
llvm::KnownBits::byteSwap
KnownBits byteSwap() const
Definition:KnownBits.h:471
llvm::KnownBits::countMaxPopulation
unsigned countMaxPopulation() const
Returns the maximum number of bits that could be one.
Definition:KnownBits.h:281
llvm::KnownBits::setAllZero
void setAllZero()
Make all bits known to be zero and discard any previous information.
Definition:KnownBits.h:85
llvm::KnownBits::reverseBits
KnownBits reverseBits() const
Definition:KnownBits.h:475
llvm::KnownBits::concat
KnownBits concat(const KnownBits &Lo) const
Concatenate the bits from Lo onto the bottom of *this.
Definition:KnownBits.h:225
llvm::KnownBits::getBitWidth
unsigned getBitWidth() const
Get the bit width of this value.
Definition:KnownBits.h:43
llvm::KnownBits::umax
static KnownBits umax(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for umax(LHS, RHS).
Definition:KnownBits.cpp:187
llvm::KnownBits::zext
KnownBits zext(unsigned BitWidth) const
Return known bits for a zero extension of the value we're tracking.
Definition:KnownBits.h:164
llvm::KnownBits::resetAll
void resetAll()
Resets the known state of all bits.
Definition:KnownBits.h:73
llvm::KnownBits::unionWith
KnownBits unionWith(const KnownBits &RHS) const
Returns KnownBits information that is known to be true for either this or RHS or both.
Definition:KnownBits.h:313
llvm::KnownBits::lshr
static KnownBits lshr(const KnownBits &LHS, const KnownBits &RHS, bool ShAmtNonZero=false, bool Exact=false)
Compute known bits for lshr(LHS, RHS).
Definition:KnownBits.cpp:370
llvm::KnownBits::isNonZero
bool isNonZero() const
Returns true if this value is known to be non-zero.
Definition:KnownBits.h:103
llvm::KnownBits::abdu
static KnownBits abdu(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for abdu(LHS, RHS).
Definition:KnownBits.cpp:228
llvm::KnownBits::extractBits
KnownBits extractBits(unsigned NumBits, unsigned BitPosition) const
Return a subset of the known bits from [bitPosition,bitPosition+numBits).
Definition:KnownBits.h:217
llvm::KnownBits::avgFloorU
static KnownBits avgFloorU(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from APIntOps::avgFloorU.
Definition:KnownBits.cpp:792
llvm::KnownBits::intersectWith
KnownBits intersectWith(const KnownBits &RHS) const
Returns KnownBits information that is known to be true for both this and RHS.
Definition:KnownBits.h:303
llvm::KnownBits::sext
KnownBits sext(unsigned BitWidth) const
Return known bits for a sign extension of the value we're tracking.
Definition:KnownBits.h:172
llvm::KnownBits::computeForSubBorrow
static KnownBits computeForSubBorrow(const KnownBits &LHS, KnownBits RHS, const KnownBits &Borrow)
Compute known bits results from subtracting RHS from LHS with 1-bit Borrow.
Definition:KnownBits.cpp:146
llvm::KnownBits::zextOrTrunc
KnownBits zextOrTrunc(unsigned BitWidth) const
Return known bits for a zero extension or truncation of the value we're tracking.
Definition:KnownBits.h:188
llvm::KnownBits::getMaxValue
APInt getMaxValue() const
Return the maximal unsigned value possible given these KnownBits.
Definition:KnownBits.h:137
llvm::KnownBits::abds
static KnownBits abds(KnownBits LHS, KnownBits RHS)
Compute known bits for abds(LHS, RHS).
Definition:KnownBits.cpp:247
llvm::KnownBits::smin
static KnownBits smin(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for smin(LHS, RHS).
Definition:KnownBits.cpp:215
llvm::KnownBits::mulhs
static KnownBits mulhs(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits from sign-extended multiply-hi.
Definition:KnownBits.cpp:901
llvm::KnownBits::srem
static KnownBits srem(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for srem(LHS, RHS).
Definition:KnownBits.cpp:1066
llvm::KnownBits::udiv
static KnownBits udiv(const KnownBits &LHS, const KnownBits &RHS, bool Exact=false)
Compute known bits for udiv(LHS, RHS).
Definition:KnownBits.cpp:1009
llvm::KnownBits::computeForAddSub
static KnownBits computeForAddSub(bool Add, bool NSW, bool NUW, const KnownBits &LHS, const KnownBits &RHS)
Compute known bits resulting from adding LHS and RHS.
Definition:KnownBits.cpp:60
llvm::KnownBits::isStrictlyPositive
bool isStrictlyPositive() const
Returns true if this value is known to be positive.
Definition:KnownBits.h:106
llvm::KnownBits::sdiv
static KnownBits sdiv(const KnownBits &LHS, const KnownBits &RHS, bool Exact=false)
Compute known bits for sdiv(LHS, RHS).
Definition:KnownBits.cpp:953
llvm::KnownBits::avgFloorS
static KnownBits avgFloorS(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from APIntOps::avgFloorS.
Definition:KnownBits.cpp:788
llvm::KnownBits::haveNoCommonBitsSet
static bool haveNoCommonBitsSet(const KnownBits &LHS, const KnownBits &RHS)
Return true if LHS and RHS have no common bits set.
Definition:KnownBits.h:318
llvm::KnownBits::isNegative
bool isNegative() const
Returns true if this value is known to be negative.
Definition:KnownBits.h:97
llvm::KnownBits::computeForAddCarry
static KnownBits computeForAddCarry(const KnownBits &LHS, const KnownBits &RHS, const KnownBits &Carry)
Compute known bits resulting from adding LHS, RHS and a 1-bit Carry.
Definition:KnownBits.cpp:53
llvm::KnownBits::countMaxLeadingZeros
unsigned countMaxLeadingZeros() const
Returns the maximum number of leading zero bits possible.
Definition:KnownBits.h:272
llvm::KnownBits::insertBits
void insertBits(const KnownBits &SubBits, unsigned BitPosition)
Insert the bits from a smaller known bits starting at bitPosition.
Definition:KnownBits.h:211
llvm::KnownBits::avgCeilU
static KnownBits avgCeilU(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from APIntOps::avgCeilU.
Definition:KnownBits.cpp:800
llvm::KnownBits::One
APInt One
Definition:KnownBits.h:25
llvm::KnownBits::mul
static KnownBits mul(const KnownBits &LHS, const KnownBits &RHS, bool NoUndefSelfMultiply=false)
Compute known bits resulting from multiplying LHS and RHS.
Definition:KnownBits.cpp:804
llvm::KnownBits::anyext
KnownBits anyext(unsigned BitWidth) const
Return known bits for an "any" extension of the value we're tracking, where we don't know anything ab...
Definition:KnownBits.h:159
llvm::KnownBits::Zero
APInt Zero
Definition:KnownBits.h:24
llvm::KnownBits::abs
KnownBits abs(bool IntMinIsPoison=false) const
Compute known bits for the absolute value.
Definition:KnownBits.cpp:550
llvm::KnownBits::shl
static KnownBits shl(const KnownBits &LHS, const KnownBits &RHS, bool NUW=false, bool NSW=false, bool ShAmtNonZero=false)
Compute known bits for shl(LHS, RHS).
Definition:KnownBits.cpp:285
llvm::KnownBits::umin
static KnownBits umin(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for umin(LHS, RHS).
Definition:KnownBits.cpp:205
llvm::KnownBits::avgCeilS
static KnownBits avgCeilS(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from APIntOps::avgCeilS.
Definition:KnownBits.cpp:796
llvm::MachinePointerInfo
This class contains a discriminated union of information about pointers in memory operands,...
Definition:MachineMemOperand.h:41
llvm::MachinePointerInfo::isDereferenceable
bool isDereferenceable(unsigned Size, LLVMContext &C, const DataLayout &DL) const
Return true if memory region [V, V+Offset+Size) is known to be dereferenceable.
Definition:MachineOperand.cpp:1050
llvm::MachinePointerInfo::getAddrSpace
unsigned getAddrSpace() const
Return the LLVM IR address space number that this pointer points into.
Definition:MachineOperand.cpp:1046
llvm::MachinePointerInfo::V
PointerUnion< const Value *, const PseudoSourceValue * > V
This is the IR pointer value for the access, or it is null if unknown.
Definition:MachineMemOperand.h:43
llvm::MachinePointerInfo::getWithOffset
MachinePointerInfo getWithOffset(int64_t O) const
Definition:MachineMemOperand.h:81
llvm::MachinePointerInfo::getFixedStack
static MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
Definition:MachineOperand.cpp:1072
llvm::MaybeAlign
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition:Alignment.h:117
llvm::MemOp
Definition:TargetLowering.h:115
llvm::MemOp::Set
static MemOp Set(uint64_t Size, bool DstAlignCanChange, Align DstAlign, bool IsZeroMemset, bool IsVolatile)
Definition:TargetLowering.h:148
llvm::MemOp::Copy
static MemOp Copy(uint64_t Size, bool DstAlignCanChange, Align DstAlign, Align SrcAlign, bool IsVolatile, bool MemcpyStrSrc=false)
Definition:TargetLowering.h:133
llvm::SDNodeFlags
These are IR-level optimization flags that may be propagated to SDNodes.
Definition:SelectionDAGNodes.h:381
llvm::SDNodeFlags::hasNonNeg
bool hasNonNeg() const
Definition:SelectionDAGNodes.h:463
llvm::SDPatternMatch::Not
Definition:SDPatternMatch.h:362
llvm::SDVTList
This represents a list of ValueType's that has been intern'd by a SelectionDAG.
Definition:SelectionDAGNodes.h:79
llvm::SDVTList::VTs
const EVT * VTs
Definition:SelectionDAGNodes.h:80
llvm::SDVTList::NumVTs
unsigned int NumVTs
Definition:SelectionDAGNodes.h:81
llvm::SelectionDAG::DAGUpdateListener
Clients of various APIs that cause global effects on the DAG can optionally implement this interface.
Definition:SelectionDAG.h:317
llvm::SelectionDAG::DAGUpdateListener::Next
DAGUpdateListener *const Next
Definition:SelectionDAG.h:318
llvm::SelectionDAG::DAGUpdateListener::NodeDeleted
virtual void NodeDeleted(SDNode *N, SDNode *E)
The node N that was deleted and, if E is not null, an equivalent node E that replaced it.
Definition:SelectionDAG.cpp:97
llvm::SelectionDAG::DAGUpdateListener::NodeInserted
virtual void NodeInserted(SDNode *N)
The node N that was inserted.
Definition:SelectionDAG.cpp:99
llvm::SelectionDAG::DAGUpdateListener::NodeUpdated
virtual void NodeUpdated(SDNode *N)
The node N that was updated.
Definition:SelectionDAG.cpp:98
llvm::TargetLowering::CallLoweringInfo
This structure contains all information that is necessary for lowering calls.
Definition:TargetLowering.h:4529
llvm::TargetLowering::CallLoweringInfo::setLibCallee
CallLoweringInfo & setLibCallee(CallingConv::ID CC, Type *ResultType, SDValue Target, ArgListTy &&ArgsList)
Definition:TargetLowering.h:4583
llvm::TargetLowering::CallLoweringInfo::setDiscardResult
CallLoweringInfo & setDiscardResult(bool Value=true)
Definition:TargetLowering.h:4658
llvm::TargetLowering::CallLoweringInfo::setDebugLoc
CallLoweringInfo & setDebugLoc(const SDLoc &dl)
Definition:TargetLowering.h:4572
llvm::TargetLowering::CallLoweringInfo::setTailCall
CallLoweringInfo & setTailCall(bool Value=true)
Definition:TargetLowering.h:4653
llvm::TargetLowering::CallLoweringInfo::setChain
CallLoweringInfo & setChain(SDValue InChain)
Definition:TargetLowering.h:4577
llvm::cl::desc
Definition:CommandLine.h:409
llvm::fltSemantics
Definition:APFloat.cpp:103

Generated on Thu Jul 17 2025 11:43:22 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp