Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
SelectionDAGBuilder.cpp
Go to the documentation of this file.
1//===- SelectionDAGBuilder.cpp - Selection-DAG building -------------------===//
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 routines for translating from LLVM IR into SelectionDAG IR.
10//
11//===----------------------------------------------------------------------===//
12
13#include "SelectionDAGBuilder.h"
14#include "SDNodeDbgValue.h"
15#include "llvm/ADT/APFloat.h"
16#include "llvm/ADT/APInt.h"
17#include "llvm/ADT/BitVector.h"
18#include "llvm/ADT/STLExtras.h"
19#include "llvm/ADT/SmallPtrSet.h"
20#include "llvm/ADT/SmallSet.h"
21#include "llvm/ADT/StringRef.h"
22#include "llvm/ADT/Twine.h"
23#include "llvm/Analysis/AliasAnalysis.h"
24#include "llvm/Analysis/BranchProbabilityInfo.h"
25#include "llvm/Analysis/ConstantFolding.h"
26#include "llvm/Analysis/Loads.h"
27#include "llvm/Analysis/MemoryLocation.h"
28#include "llvm/Analysis/TargetLibraryInfo.h"
29#include "llvm/Analysis/TargetTransformInfo.h"
30#include "llvm/Analysis/ValueTracking.h"
31#include "llvm/Analysis/VectorUtils.h"
32#include "llvm/CodeGen/Analysis.h"
33#include "llvm/CodeGen/AssignmentTrackingAnalysis.h"
34#include "llvm/CodeGen/CodeGenCommonISel.h"
35#include "llvm/CodeGen/FunctionLoweringInfo.h"
36#include "llvm/CodeGen/GCMetadata.h"
37#include "llvm/CodeGen/ISDOpcodes.h"
38#include "llvm/CodeGen/MachineBasicBlock.h"
39#include "llvm/CodeGen/MachineFrameInfo.h"
40#include "llvm/CodeGen/MachineFunction.h"
41#include "llvm/CodeGen/MachineInstrBuilder.h"
42#include "llvm/CodeGen/MachineInstrBundleIterator.h"
43#include "llvm/CodeGen/MachineMemOperand.h"
44#include "llvm/CodeGen/MachineModuleInfo.h"
45#include "llvm/CodeGen/MachineOperand.h"
46#include "llvm/CodeGen/MachineRegisterInfo.h"
47#include "llvm/CodeGen/SelectionDAG.h"
48#include "llvm/CodeGen/SelectionDAGTargetInfo.h"
49#include "llvm/CodeGen/StackMaps.h"
50#include "llvm/CodeGen/SwiftErrorValueTracking.h"
51#include "llvm/CodeGen/TargetFrameLowering.h"
52#include "llvm/CodeGen/TargetInstrInfo.h"
53#include "llvm/CodeGen/TargetOpcodes.h"
54#include "llvm/CodeGen/TargetRegisterInfo.h"
55#include "llvm/CodeGen/TargetSubtargetInfo.h"
56#include "llvm/CodeGen/WinEHFuncInfo.h"
57#include "llvm/IR/Argument.h"
58#include "llvm/IR/Attributes.h"
59#include "llvm/IR/BasicBlock.h"
60#include "llvm/IR/CFG.h"
61#include "llvm/IR/CallingConv.h"
62#include "llvm/IR/Constant.h"
63#include "llvm/IR/ConstantRange.h"
64#include "llvm/IR/Constants.h"
65#include "llvm/IR/DataLayout.h"
66#include "llvm/IR/DebugInfo.h"
67#include "llvm/IR/DebugInfoMetadata.h"
68#include "llvm/IR/DerivedTypes.h"
69#include "llvm/IR/DiagnosticInfo.h"
70#include "llvm/IR/EHPersonalities.h"
71#include "llvm/IR/Function.h"
72#include "llvm/IR/GetElementPtrTypeIterator.h"
73#include "llvm/IR/InlineAsm.h"
74#include "llvm/IR/InstrTypes.h"
75#include "llvm/IR/Instructions.h"
76#include "llvm/IR/IntrinsicInst.h"
77#include "llvm/IR/Intrinsics.h"
78#include "llvm/IR/IntrinsicsAArch64.h"
79#include "llvm/IR/IntrinsicsAMDGPU.h"
80#include "llvm/IR/IntrinsicsWebAssembly.h"
81#include "llvm/IR/LLVMContext.h"
82#include "llvm/IR/MemoryModelRelaxationAnnotations.h"
83#include "llvm/IR/Metadata.h"
84#include "llvm/IR/Module.h"
85#include "llvm/IR/Operator.h"
86#include "llvm/IR/PatternMatch.h"
87#include "llvm/IR/Statepoint.h"
88#include "llvm/IR/Type.h"
89#include "llvm/IR/User.h"
90#include "llvm/IR/Value.h"
91#include "llvm/MC/MCContext.h"
92#include "llvm/Support/AtomicOrdering.h"
93#include "llvm/Support/Casting.h"
94#include "llvm/Support/CommandLine.h"
95#include "llvm/Support/Compiler.h"
96#include "llvm/Support/Debug.h"
97#include "llvm/Support/InstructionCost.h"
98#include "llvm/Support/MathExtras.h"
99#include "llvm/Support/raw_ostream.h"
100#include "llvm/Target/TargetIntrinsicInfo.h"
101#include "llvm/Target/TargetMachine.h"
102#include "llvm/Target/TargetOptions.h"
103#include "llvm/TargetParser/Triple.h"
104#include "llvm/Transforms/Utils/Local.h"
105#include <cstddef>
106#include <limits>
107#include <optional>
108#include <tuple>
109
110using namespacellvm;
111using namespacePatternMatch;
112using namespaceSwitchCG;
113
114#define DEBUG_TYPE "isel"
115
116/// LimitFloatPrecision - Generate low-precision inline sequences for
117/// some float libcalls (6, 8 or 12 bits).
118staticunsignedLimitFloatPrecision;
119
120staticcl::opt<bool>
121InsertAssertAlign("insert-assert-align",cl::init(true),
122cl::desc("Insert the experimental `assertalign` node."),
123cl::ReallyHidden);
124
125staticcl::opt<unsigned, true>
126LimitFPPrecision("limit-float-precision",
127cl::desc("Generate low-precision inline sequences "
128"for some float libcalls"),
129cl::location(LimitFloatPrecision),cl::Hidden,
130cl::init(0));
131
132staticcl::opt<unsigned>SwitchPeelThreshold(
133"switch-peel-threshold",cl::Hidden,cl::init(66),
134cl::desc("Set the case probability threshold for peeling the case from a "
135"switch statement. A value greater than 100 will void this "
136"optimization"));
137
138// Limit the width of DAG chains. This is important in general to prevent
139// DAG-based analysis from blowing up. For example, alias analysis and
140// load clustering may not complete in reasonable time. It is difficult to
141// recognize and avoid this situation within each individual analysis, and
142// future analyses are likely to have the same behavior. Limiting DAG width is
143// the safe approach and will be especially important with global DAGs.
144//
145// MaxParallelChains default is arbitrarily high to avoid affecting
146// optimization, but could be lowered to improve compile time. Any ld-ld-st-st
147// sequence over this should have been converted to llvm.memcpy by the
148// frontend. It is easy to induce this behavior with .ll code such as:
149// %buffer = alloca [4096 x i8]
150// %data = load [4096 x i8]* %argPtr
151// store [4096 x i8] %data, [4096 x i8]* %buffer
152staticconstunsignedMaxParallelChains = 64;
153
154staticSDValuegetCopyFromPartsVector(SelectionDAG &DAG,constSDLoc &DL,
155constSDValue *Parts,unsigned NumParts,
156MVT PartVT,EVT ValueVT,constValue *V,
157SDValue InChain,
158 std::optional<CallingConv::ID>CC);
159
160/// getCopyFromParts - Create a value that contains the specified legal parts
161/// combined into the value they represent. If the parts combine to a type
162/// larger than ValueVT then AssertOp can be used to specify whether the extra
163/// bits are known to be zero (ISD::AssertZext) or sign extended from ValueVT
164/// (ISD::AssertSext).
165staticSDValue
166getCopyFromParts(SelectionDAG &DAG,constSDLoc &DL,constSDValue *Parts,
167unsigned NumParts,MVT PartVT,EVT ValueVT,constValue *V,
168SDValue InChain,
169 std::optional<CallingConv::ID>CC = std::nullopt,
170 std::optional<ISD::NodeType> AssertOp = std::nullopt) {
171// Let the target assemble the parts if it wants to
172constTargetLowering &TLI = DAG.getTargetLoweringInfo();
173if (SDValue Val = TLI.joinRegisterPartsIntoValue(DAG,DL, Parts, NumParts,
174 PartVT, ValueVT,CC))
175return Val;
176
177if (ValueVT.isVector())
178returngetCopyFromPartsVector(DAG,DL, Parts, NumParts, PartVT, ValueVT, V,
179 InChain,CC);
180
181assert(NumParts > 0 &&"No parts to assemble!");
182SDValue Val = Parts[0];
183
184if (NumParts > 1) {
185// Assemble the value from multiple parts.
186if (ValueVT.isInteger()) {
187unsigned PartBits = PartVT.getSizeInBits();
188unsigned ValueBits = ValueVT.getSizeInBits();
189
190// Assemble the power of 2 part.
191unsigned RoundParts =llvm::bit_floor(NumParts);
192unsigned RoundBits = PartBits * RoundParts;
193EVT RoundVT = RoundBits == ValueBits ?
194 ValueVT :EVT::getIntegerVT(*DAG.getContext(), RoundBits);
195SDValueLo,Hi;
196
197EVT HalfVT =EVT::getIntegerVT(*DAG.getContext(), RoundBits/2);
198
199if (RoundParts > 2) {
200Lo =getCopyFromParts(DAG,DL, Parts, RoundParts / 2, PartVT, HalfVT, V,
201 InChain);
202Hi =getCopyFromParts(DAG,DL, Parts + RoundParts / 2, RoundParts / 2,
203 PartVT, HalfVT, V, InChain);
204 }else {
205Lo = DAG.getNode(ISD::BITCAST,DL, HalfVT, Parts[0]);
206Hi = DAG.getNode(ISD::BITCAST,DL, HalfVT, Parts[1]);
207 }
208
209if (DAG.getDataLayout().isBigEndian())
210std::swap(Lo,Hi);
211
212 Val = DAG.getNode(ISD::BUILD_PAIR,DL, RoundVT,Lo,Hi);
213
214if (RoundParts < NumParts) {
215// Assemble the trailing non-power-of-2 part.
216unsigned OddParts = NumParts - RoundParts;
217EVT OddVT =EVT::getIntegerVT(*DAG.getContext(), OddParts * PartBits);
218Hi =getCopyFromParts(DAG,DL, Parts + RoundParts, OddParts, PartVT,
219 OddVT, V, InChain,CC);
220
221// Combine the round and odd parts.
222Lo = Val;
223if (DAG.getDataLayout().isBigEndian())
224std::swap(Lo,Hi);
225EVT TotalVT =EVT::getIntegerVT(*DAG.getContext(), NumParts * PartBits);
226Hi = DAG.getNode(ISD::ANY_EXTEND,DL, TotalVT,Hi);
227Hi = DAG.getNode(ISD::SHL,DL, TotalVT,Hi,
228 DAG.getConstant(Lo.getValueSizeInBits(),DL,
229 TLI.getShiftAmountTy(
230 TotalVT, DAG.getDataLayout())));
231Lo = DAG.getNode(ISD::ZERO_EXTEND,DL, TotalVT,Lo);
232 Val = DAG.getNode(ISD::OR,DL, TotalVT,Lo,Hi);
233 }
234 }elseif (PartVT.isFloatingPoint()) {
235// FP split into multiple FP parts (for ppcf128)
236assert(ValueVT ==EVT(MVT::ppcf128) && PartVT == MVT::f64 &&
237"Unexpected split");
238SDValueLo,Hi;
239Lo = DAG.getNode(ISD::BITCAST,DL,EVT(MVT::f64), Parts[0]);
240Hi = DAG.getNode(ISD::BITCAST,DL,EVT(MVT::f64), Parts[1]);
241if (TLI.hasBigEndianPartOrdering(ValueVT, DAG.getDataLayout()))
242std::swap(Lo,Hi);
243 Val = DAG.getNode(ISD::BUILD_PAIR,DL, ValueVT,Lo,Hi);
244 }else {
245// FP split into integer parts (soft fp)
246assert(ValueVT.isFloatingPoint() && PartVT.isInteger() &&
247 !PartVT.isVector() &&"Unexpected split");
248EVT IntVT =EVT::getIntegerVT(*DAG.getContext(), ValueVT.getSizeInBits());
249 Val =getCopyFromParts(DAG,DL, Parts, NumParts, PartVT, IntVT, V,
250 InChain,CC);
251 }
252 }
253
254// There is now one part, held in Val. Correct it to match ValueVT.
255// PartEVT is the type of the register class that holds the value.
256// ValueVT is the type of the inline asm operation.
257EVT PartEVT = Val.getValueType();
258
259if (PartEVT == ValueVT)
260return Val;
261
262if (PartEVT.isInteger() && ValueVT.isFloatingPoint() &&
263 ValueVT.bitsLT(PartEVT)) {
264// For an FP value in an integer part, we need to truncate to the right
265// width first.
266 PartEVT =EVT::getIntegerVT(*DAG.getContext(), ValueVT.getSizeInBits());
267 Val = DAG.getNode(ISD::TRUNCATE,DL, PartEVT, Val);
268 }
269
270// Handle types that have the same size.
271if (PartEVT.getSizeInBits() == ValueVT.getSizeInBits())
272return DAG.getNode(ISD::BITCAST,DL, ValueVT, Val);
273
274// Handle types with different sizes.
275if (PartEVT.isInteger() && ValueVT.isInteger()) {
276if (ValueVT.bitsLT(PartEVT)) {
277// For a truncate, see if we have any information to
278// indicate whether the truncated bits will always be
279// zero or sign-extension.
280if (AssertOp)
281 Val = DAG.getNode(*AssertOp,DL, PartEVT, Val,
282 DAG.getValueType(ValueVT));
283return DAG.getNode(ISD::TRUNCATE,DL, ValueVT, Val);
284 }
285return DAG.getNode(ISD::ANY_EXTEND,DL, ValueVT, Val);
286 }
287
288if (PartEVT.isFloatingPoint() && ValueVT.isFloatingPoint()) {
289// FP_ROUND's are always exact here.
290if (ValueVT.bitsLT(Val.getValueType())) {
291
292SDValue NoChange =
293 DAG.getTargetConstant(1,DL, TLI.getPointerTy(DAG.getDataLayout()));
294
295if (DAG.getMachineFunction().getFunction().getAttributes().hasFnAttr(
296 llvm::Attribute::StrictFP)) {
297return DAG.getNode(ISD::STRICT_FP_ROUND,DL,
298 DAG.getVTList(ValueVT, MVT::Other), InChain, Val,
299 NoChange);
300 }
301
302return DAG.getNode(ISD::FP_ROUND,DL, ValueVT, Val, NoChange);
303 }
304
305return DAG.getNode(ISD::FP_EXTEND,DL, ValueVT, Val);
306 }
307
308// Handle MMX to a narrower integer type by bitcasting MMX to integer and
309// then truncating.
310if (PartEVT == MVT::x86mmx && ValueVT.isInteger() &&
311 ValueVT.bitsLT(PartEVT)) {
312 Val = DAG.getNode(ISD::BITCAST,DL, MVT::i64, Val);
313return DAG.getNode(ISD::TRUNCATE,DL, ValueVT, Val);
314 }
315
316report_fatal_error("Unknown mismatch in getCopyFromParts!");
317}
318
319staticvoiddiagnosePossiblyInvalidConstraint(LLVMContext &Ctx,constValue *V,
320constTwine &ErrMsg) {
321constInstruction *I = dyn_cast_or_null<Instruction>(V);
322if (!I)
323return Ctx.emitError(ErrMsg);
324
325if (constCallInst *CI = dyn_cast<CallInst>(I))
326if (CI->isInlineAsm()) {
327return Ctx.diagnose(DiagnosticInfoInlineAsm(
328 *CI, ErrMsg +", possible invalid constraint for vector type"));
329 }
330
331return Ctx.emitError(I, ErrMsg);
332}
333
334/// getCopyFromPartsVector - Create a value that contains the specified legal
335/// parts combined into the value they represent. If the parts combine to a
336/// type larger than ValueVT then AssertOp can be used to specify whether the
337/// extra bits are known to be zero (ISD::AssertZext) or sign extended from
338/// ValueVT (ISD::AssertSext).
339staticSDValuegetCopyFromPartsVector(SelectionDAG &DAG,constSDLoc &DL,
340constSDValue *Parts,unsigned NumParts,
341MVT PartVT,EVT ValueVT,constValue *V,
342SDValue InChain,
343 std::optional<CallingConv::ID> CallConv) {
344assert(ValueVT.isVector() &&"Not a vector value");
345assert(NumParts > 0 &&"No parts to assemble!");
346constbool IsABIRegCopy = CallConv.has_value();
347
348constTargetLowering &TLI = DAG.getTargetLoweringInfo();
349SDValue Val = Parts[0];
350
351// Handle a multi-element vector.
352if (NumParts > 1) {
353EVT IntermediateVT;
354MVT RegisterVT;
355unsigned NumIntermediates;
356unsigned NumRegs;
357
358if (IsABIRegCopy) {
359 NumRegs = TLI.getVectorTypeBreakdownForCallingConv(
360 *DAG.getContext(), *CallConv, ValueVT, IntermediateVT,
361 NumIntermediates, RegisterVT);
362 }else {
363 NumRegs =
364 TLI.getVectorTypeBreakdown(*DAG.getContext(), ValueVT, IntermediateVT,
365 NumIntermediates, RegisterVT);
366 }
367
368assert(NumRegs == NumParts &&"Part count doesn't match vector breakdown!");
369 NumParts = NumRegs;// Silence a compiler warning.
370assert(RegisterVT == PartVT &&"Part type doesn't match vector breakdown!");
371assert(RegisterVT.getSizeInBits() ==
372 Parts[0].getSimpleValueType().getSizeInBits() &&
373"Part type sizes don't match!");
374
375// Assemble the parts into intermediate operands.
376SmallVector<SDValue, 8> Ops(NumIntermediates);
377if (NumIntermediates == NumParts) {
378// If the register was not expanded, truncate or copy the value,
379// as appropriate.
380for (unsigned i = 0; i != NumParts; ++i)
381 Ops[i] =getCopyFromParts(DAG,DL, &Parts[i], 1, PartVT, IntermediateVT,
382 V, InChain, CallConv);
383 }elseif (NumParts > 0) {
384// If the intermediate type was expanded, build the intermediate
385// operands from the parts.
386assert(NumParts % NumIntermediates == 0 &&
387"Must expand into a divisible number of parts!");
388unsigned Factor = NumParts / NumIntermediates;
389for (unsigned i = 0; i != NumIntermediates; ++i)
390 Ops[i] =getCopyFromParts(DAG,DL, &Parts[i * Factor], Factor, PartVT,
391 IntermediateVT, V, InChain, CallConv);
392 }
393
394// Build a vector with BUILD_VECTOR or CONCAT_VECTORS from the
395// intermediate operands.
396EVT BuiltVectorTy =
397 IntermediateVT.isVector()
398 ?EVT::getVectorVT(
399 *DAG.getContext(), IntermediateVT.getScalarType(),
400 IntermediateVT.getVectorElementCount() * NumParts)
401 :EVT::getVectorVT(*DAG.getContext(),
402 IntermediateVT.getScalarType(),
403 NumIntermediates);
404 Val = DAG.getNode(IntermediateVT.isVector() ?ISD::CONCAT_VECTORS
405 :ISD::BUILD_VECTOR,
406DL, BuiltVectorTy, Ops);
407 }
408
409// There is now one part, held in Val. Correct it to match ValueVT.
410EVT PartEVT = Val.getValueType();
411
412if (PartEVT == ValueVT)
413return Val;
414
415if (PartEVT.isVector()) {
416// Vector/Vector bitcast.
417if (ValueVT.getSizeInBits() == PartEVT.getSizeInBits())
418return DAG.getNode(ISD::BITCAST,DL, ValueVT, Val);
419
420// If the parts vector has more elements than the value vector, then we
421// have a vector widening case (e.g. <2 x float> -> <4 x float>).
422// Extract the elements we want.
423if (PartEVT.getVectorElementCount() != ValueVT.getVectorElementCount()) {
424assert((PartEVT.getVectorElementCount().getKnownMinValue() >
425 ValueVT.getVectorElementCount().getKnownMinValue()) &&
426 (PartEVT.getVectorElementCount().isScalable() ==
427 ValueVT.getVectorElementCount().isScalable()) &&
428"Cannot narrow, it would be a lossy transformation");
429 PartEVT =
430EVT::getVectorVT(*DAG.getContext(), PartEVT.getVectorElementType(),
431 ValueVT.getVectorElementCount());
432 Val = DAG.getNode(ISD::EXTRACT_SUBVECTOR,DL, PartEVT, Val,
433 DAG.getVectorIdxConstant(0,DL));
434if (PartEVT == ValueVT)
435return Val;
436if (PartEVT.isInteger() && ValueVT.isFloatingPoint())
437return DAG.getNode(ISD::BITCAST,DL, ValueVT, Val);
438
439// Vector/Vector bitcast (e.g. <2 x bfloat> -> <2 x half>).
440if (ValueVT.getSizeInBits() == PartEVT.getSizeInBits())
441return DAG.getNode(ISD::BITCAST,DL, ValueVT, Val);
442 }
443
444// Promoted vector extract
445return DAG.getAnyExtOrTrunc(Val,DL, ValueVT);
446 }
447
448// Trivial bitcast if the types are the same size and the destination
449// vector type is legal.
450if (PartEVT.getSizeInBits() == ValueVT.getSizeInBits() &&
451 TLI.isTypeLegal(ValueVT))
452return DAG.getNode(ISD::BITCAST,DL, ValueVT, Val);
453
454if (ValueVT.getVectorNumElements() != 1) {
455// Certain ABIs require that vectors are passed as integers. For vectors
456// are the same size, this is an obvious bitcast.
457if (ValueVT.getSizeInBits() == PartEVT.getSizeInBits()) {
458return DAG.getNode(ISD::BITCAST,DL, ValueVT, Val);
459 }elseif (ValueVT.bitsLT(PartEVT)) {
460constuint64_t ValueSize = ValueVT.getFixedSizeInBits();
461EVT IntermediateType =EVT::getIntegerVT(*DAG.getContext(), ValueSize);
462// Drop the extra bits.
463 Val = DAG.getNode(ISD::TRUNCATE,DL, IntermediateType, Val);
464return DAG.getBitcast(ValueVT, Val);
465 }
466
467diagnosePossiblyInvalidConstraint(
468 *DAG.getContext(), V,"non-trivial scalar-to-vector conversion");
469return DAG.getUNDEF(ValueVT);
470 }
471
472// Handle cases such as i8 -> <1 x i1>
473EVT ValueSVT = ValueVT.getVectorElementType();
474if (ValueVT.getVectorNumElements() == 1 && ValueSVT != PartEVT) {
475unsigned ValueSize = ValueSVT.getSizeInBits();
476if (ValueSize == PartEVT.getSizeInBits()) {
477 Val = DAG.getNode(ISD::BITCAST,DL, ValueSVT, Val);
478 }elseif (ValueSVT.isFloatingPoint() && PartEVT.isInteger()) {
479// It's possible a scalar floating point type gets softened to integer and
480// then promoted to a larger integer. If PartEVT is the larger integer
481// we need to truncate it and then bitcast to the FP type.
482assert(ValueSVT.bitsLT(PartEVT) &&"Unexpected types");
483EVT IntermediateType =EVT::getIntegerVT(*DAG.getContext(), ValueSize);
484 Val = DAG.getNode(ISD::TRUNCATE,DL, IntermediateType, Val);
485 Val = DAG.getBitcast(ValueSVT, Val);
486 }else {
487 Val = ValueVT.isFloatingPoint()
488 ? DAG.getFPExtendOrRound(Val,DL, ValueSVT)
489 : DAG.getAnyExtOrTrunc(Val,DL, ValueSVT);
490 }
491 }
492
493return DAG.getBuildVector(ValueVT,DL, Val);
494}
495
496staticvoidgetCopyToPartsVector(SelectionDAG &DAG,constSDLoc &dl,
497SDValue Val,SDValue *Parts,unsigned NumParts,
498MVT PartVT,constValue *V,
499 std::optional<CallingConv::ID> CallConv);
500
501/// getCopyToParts - Create a series of nodes that contain the specified value
502/// split into legal parts. If the parts contain more bits than Val, then, for
503/// integers, ExtendKind can be used to specify how to generate the extra bits.
504staticvoid
505getCopyToParts(SelectionDAG &DAG,constSDLoc &DL,SDValue Val,SDValue *Parts,
506unsigned NumParts,MVT PartVT,constValue *V,
507 std::optional<CallingConv::ID> CallConv = std::nullopt,
508ISD::NodeType ExtendKind =ISD::ANY_EXTEND) {
509// Let the target split the parts if it wants to
510constTargetLowering &TLI = DAG.getTargetLoweringInfo();
511if (TLI.splitValueIntoRegisterParts(DAG,DL, Val, Parts, NumParts, PartVT,
512 CallConv))
513return;
514EVT ValueVT = Val.getValueType();
515
516// Handle the vector case separately.
517if (ValueVT.isVector())
518returngetCopyToPartsVector(DAG,DL, Val, Parts, NumParts, PartVT, V,
519 CallConv);
520
521unsigned OrigNumParts = NumParts;
522assert(DAG.getTargetLoweringInfo().isTypeLegal(PartVT) &&
523"Copying to an illegal type!");
524
525if (NumParts == 0)
526return;
527
528assert(!ValueVT.isVector() &&"Vector case handled elsewhere");
529EVT PartEVT = PartVT;
530if (PartEVT == ValueVT) {
531assert(NumParts == 1 &&"No-op copy with multiple parts!");
532 Parts[0] = Val;
533return;
534 }
535
536unsigned PartBits = PartVT.getSizeInBits();
537if (NumParts * PartBits > ValueVT.getSizeInBits()) {
538// If the parts cover more bits than the value has, promote the value.
539if (PartVT.isFloatingPoint() && ValueVT.isFloatingPoint()) {
540assert(NumParts == 1 &&"Do not know what to promote to!");
541 Val = DAG.getNode(ISD::FP_EXTEND,DL, PartVT, Val);
542 }else {
543if (ValueVT.isFloatingPoint()) {
544// FP values need to be bitcast, then extended if they are being put
545// into a larger container.
546 ValueVT =EVT::getIntegerVT(*DAG.getContext(), ValueVT.getSizeInBits());
547 Val = DAG.getNode(ISD::BITCAST,DL, ValueVT, Val);
548 }
549assert((PartVT.isInteger() || PartVT == MVT::x86mmx) &&
550 ValueVT.isInteger() &&
551"Unknown mismatch!");
552 ValueVT =EVT::getIntegerVT(*DAG.getContext(), NumParts * PartBits);
553 Val = DAG.getNode(ExtendKind,DL, ValueVT, Val);
554if (PartVT == MVT::x86mmx)
555 Val = DAG.getNode(ISD::BITCAST,DL, PartVT, Val);
556 }
557 }elseif (PartBits == ValueVT.getSizeInBits()) {
558// Different types of the same size.
559assert(NumParts == 1 && PartEVT != ValueVT);
560 Val = DAG.getNode(ISD::BITCAST,DL, PartVT, Val);
561 }elseif (NumParts * PartBits < ValueVT.getSizeInBits()) {
562// If the parts cover less bits than value has, truncate the value.
563assert((PartVT.isInteger() || PartVT == MVT::x86mmx) &&
564 ValueVT.isInteger() &&
565"Unknown mismatch!");
566 ValueVT =EVT::getIntegerVT(*DAG.getContext(), NumParts * PartBits);
567 Val = DAG.getNode(ISD::TRUNCATE,DL, ValueVT, Val);
568if (PartVT == MVT::x86mmx)
569 Val = DAG.getNode(ISD::BITCAST,DL, PartVT, Val);
570 }
571
572// The value may have changed - recompute ValueVT.
573 ValueVT = Val.getValueType();
574assert(NumParts * PartBits == ValueVT.getSizeInBits() &&
575"Failed to tile the value with PartVT!");
576
577if (NumParts == 1) {
578if (PartEVT != ValueVT) {
579diagnosePossiblyInvalidConstraint(*DAG.getContext(), V,
580"scalar-to-vector conversion failed");
581 Val = DAG.getNode(ISD::BITCAST,DL, PartVT, Val);
582 }
583
584 Parts[0] = Val;
585return;
586 }
587
588// Expand the value into multiple parts.
589if (NumParts & (NumParts - 1)) {
590// The number of parts is not a power of 2. Split off and copy the tail.
591assert(PartVT.isInteger() && ValueVT.isInteger() &&
592"Do not know what to expand to!");
593unsigned RoundParts =llvm::bit_floor(NumParts);
594unsigned RoundBits = RoundParts * PartBits;
595unsigned OddParts = NumParts - RoundParts;
596SDValue OddVal = DAG.getNode(ISD::SRL,DL, ValueVT, Val,
597 DAG.getShiftAmountConstant(RoundBits, ValueVT,DL));
598
599getCopyToParts(DAG,DL, OddVal, Parts + RoundParts, OddParts, PartVT, V,
600 CallConv);
601
602if (DAG.getDataLayout().isBigEndian())
603// The odd parts were reversed by getCopyToParts - unreverse them.
604 std::reverse(Parts + RoundParts, Parts + NumParts);
605
606 NumParts = RoundParts;
607 ValueVT =EVT::getIntegerVT(*DAG.getContext(), NumParts * PartBits);
608 Val = DAG.getNode(ISD::TRUNCATE,DL, ValueVT, Val);
609 }
610
611// The number of parts is a power of 2. Repeatedly bisect the value using
612// EXTRACT_ELEMENT.
613 Parts[0] = DAG.getNode(ISD::BITCAST,DL,
614EVT::getIntegerVT(*DAG.getContext(),
615 ValueVT.getSizeInBits()),
616 Val);
617
618for (unsigned StepSize = NumParts; StepSize > 1; StepSize /= 2) {
619for (unsigned i = 0; i < NumParts; i += StepSize) {
620unsigned ThisBits = StepSize * PartBits / 2;
621EVT ThisVT =EVT::getIntegerVT(*DAG.getContext(), ThisBits);
622SDValue &Part0 = Parts[i];
623SDValue &Part1 = Parts[i+StepSize/2];
624
625 Part1 = DAG.getNode(ISD::EXTRACT_ELEMENT,DL,
626 ThisVT, Part0, DAG.getIntPtrConstant(1,DL));
627 Part0 = DAG.getNode(ISD::EXTRACT_ELEMENT,DL,
628 ThisVT, Part0, DAG.getIntPtrConstant(0,DL));
629
630if (ThisBits == PartBits && ThisVT != PartVT) {
631 Part0 = DAG.getNode(ISD::BITCAST,DL, PartVT, Part0);
632 Part1 = DAG.getNode(ISD::BITCAST,DL, PartVT, Part1);
633 }
634 }
635 }
636
637if (DAG.getDataLayout().isBigEndian())
638 std::reverse(Parts, Parts + OrigNumParts);
639}
640
641staticSDValuewidenVectorToPartType(SelectionDAG &DAG,SDValue Val,
642constSDLoc &DL,EVT PartVT) {
643if (!PartVT.isVector())
644returnSDValue();
645
646EVT ValueVT = Val.getValueType();
647EVT PartEVT = PartVT.getVectorElementType();
648EVT ValueEVT = ValueVT.getVectorElementType();
649ElementCount PartNumElts = PartVT.getVectorElementCount();
650ElementCount ValueNumElts = ValueVT.getVectorElementCount();
651
652// We only support widening vectors with equivalent element types and
653// fixed/scalable properties. If a target needs to widen a fixed-length type
654// to a scalable one, it should be possible to use INSERT_SUBVECTOR below.
655if (ElementCount::isKnownLE(PartNumElts, ValueNumElts) ||
656 PartNumElts.isScalable() != ValueNumElts.isScalable())
657returnSDValue();
658
659// Have a try for bf16 because some targets share its ABI with fp16.
660if (ValueEVT == MVT::bf16 && PartEVT == MVT::f16) {
661assert(DAG.getTargetLoweringInfo().isTypeLegal(PartVT) &&
662"Cannot widen to illegal type");
663 Val = DAG.getNode(ISD::BITCAST,DL,
664 ValueVT.changeVectorElementType(MVT::f16), Val);
665 }elseif (PartEVT != ValueEVT) {
666returnSDValue();
667 }
668
669// Widening a scalable vector to another scalable vector is done by inserting
670// the vector into a larger undef one.
671if (PartNumElts.isScalable())
672return DAG.getNode(ISD::INSERT_SUBVECTOR,DL, PartVT, DAG.getUNDEF(PartVT),
673 Val, DAG.getVectorIdxConstant(0,DL));
674
675// Vector widening case, e.g. <2 x float> -> <4 x float>. Shuffle in
676// undef elements.
677SmallVector<SDValue, 16> Ops;
678 DAG.ExtractVectorElements(Val, Ops);
679SDValue EltUndef = DAG.getUNDEF(PartEVT);
680 Ops.append((PartNumElts - ValueNumElts).getFixedValue(), EltUndef);
681
682// FIXME: Use CONCAT for 2x -> 4x.
683return DAG.getBuildVector(PartVT,DL, Ops);
684}
685
686/// getCopyToPartsVector - Create a series of nodes that contain the specified
687/// value split into legal parts.
688staticvoidgetCopyToPartsVector(SelectionDAG &DAG,constSDLoc &DL,
689SDValue Val,SDValue *Parts,unsigned NumParts,
690MVT PartVT,constValue *V,
691 std::optional<CallingConv::ID> CallConv) {
692EVT ValueVT = Val.getValueType();
693assert(ValueVT.isVector() &&"Not a vector");
694constTargetLowering &TLI = DAG.getTargetLoweringInfo();
695constbool IsABIRegCopy = CallConv.has_value();
696
697if (NumParts == 1) {
698EVT PartEVT = PartVT;
699if (PartEVT == ValueVT) {
700// Nothing to do.
701 }elseif (PartVT.getSizeInBits() == ValueVT.getSizeInBits()) {
702// Bitconvert vector->vector case.
703 Val = DAG.getNode(ISD::BITCAST,DL, PartVT, Val);
704 }elseif (SDValue Widened =widenVectorToPartType(DAG, Val,DL, PartVT)) {
705 Val = Widened;
706 }elseif (PartVT.isVector() &&
707 PartEVT.getVectorElementType().bitsGE(
708 ValueVT.getVectorElementType()) &&
709 PartEVT.getVectorElementCount() ==
710 ValueVT.getVectorElementCount()) {
711
712// Promoted vector extract
713 Val = DAG.getAnyExtOrTrunc(Val,DL, PartVT);
714 }elseif (PartEVT.isVector() &&
715 PartEVT.getVectorElementType() !=
716 ValueVT.getVectorElementType() &&
717 TLI.getTypeAction(*DAG.getContext(), ValueVT) ==
718 TargetLowering::TypeWidenVector) {
719// Combination of widening and promotion.
720EVT WidenVT =
721EVT::getVectorVT(*DAG.getContext(), ValueVT.getVectorElementType(),
722 PartVT.getVectorElementCount());
723SDValue Widened =widenVectorToPartType(DAG, Val,DL, WidenVT);
724 Val = DAG.getAnyExtOrTrunc(Widened,DL, PartVT);
725 }else {
726// Don't extract an integer from a float vector. This can happen if the
727// FP type gets softened to integer and then promoted. The promotion
728// prevents it from being picked up by the earlier bitcast case.
729if (ValueVT.getVectorElementCount().isScalar() &&
730 (!ValueVT.isFloatingPoint() || !PartVT.isInteger())) {
731// If we reach this condition and PartVT is FP, this means that
732// ValueVT is also FP and both have a different size, otherwise we
733// would have bitcasted them. Producing an EXTRACT_VECTOR_ELT here
734// would be invalid since that would mean the smaller FP type has to
735// be extended to the larger one.
736if (PartVT.isFloatingPoint()) {
737 Val = DAG.getBitcast(ValueVT.getScalarType(), Val);
738 Val = DAG.getNode(ISD::FP_EXTEND,DL, PartVT, Val);
739 }else
740 Val = DAG.getNode(ISD::EXTRACT_VECTOR_ELT,DL, PartVT, Val,
741 DAG.getVectorIdxConstant(0,DL));
742 }else {
743uint64_t ValueSize = ValueVT.getFixedSizeInBits();
744assert(PartVT.getFixedSizeInBits() > ValueSize &&
745"lossy conversion of vector to scalar type");
746EVT IntermediateType =EVT::getIntegerVT(*DAG.getContext(), ValueSize);
747 Val = DAG.getBitcast(IntermediateType, Val);
748 Val = DAG.getAnyExtOrTrunc(Val,DL, PartVT);
749 }
750 }
751
752assert(Val.getValueType() == PartVT &&"Unexpected vector part value type");
753 Parts[0] = Val;
754return;
755 }
756
757// Handle a multi-element vector.
758EVT IntermediateVT;
759MVT RegisterVT;
760unsigned NumIntermediates;
761unsigned NumRegs;
762if (IsABIRegCopy) {
763 NumRegs = TLI.getVectorTypeBreakdownForCallingConv(
764 *DAG.getContext(), *CallConv, ValueVT, IntermediateVT, NumIntermediates,
765 RegisterVT);
766 }else {
767 NumRegs =
768 TLI.getVectorTypeBreakdown(*DAG.getContext(), ValueVT, IntermediateVT,
769 NumIntermediates, RegisterVT);
770 }
771
772assert(NumRegs == NumParts &&"Part count doesn't match vector breakdown!");
773 NumParts = NumRegs;// Silence a compiler warning.
774assert(RegisterVT == PartVT &&"Part type doesn't match vector breakdown!");
775
776assert(IntermediateVT.isScalableVector() == ValueVT.isScalableVector() &&
777"Mixing scalable and fixed vectors when copying in parts");
778
779 std::optional<ElementCount> DestEltCnt;
780
781if (IntermediateVT.isVector())
782 DestEltCnt = IntermediateVT.getVectorElementCount() * NumIntermediates;
783else
784 DestEltCnt =ElementCount::getFixed(NumIntermediates);
785
786EVT BuiltVectorTy =EVT::getVectorVT(
787 *DAG.getContext(), IntermediateVT.getScalarType(), *DestEltCnt);
788
789if (ValueVT == BuiltVectorTy) {
790// Nothing to do.
791 }elseif (ValueVT.getSizeInBits() == BuiltVectorTy.getSizeInBits()) {
792// Bitconvert vector->vector case.
793 Val = DAG.getNode(ISD::BITCAST,DL, BuiltVectorTy, Val);
794 }else {
795if (BuiltVectorTy.getVectorElementType().bitsGT(
796 ValueVT.getVectorElementType())) {
797// Integer promotion.
798 ValueVT =EVT::getVectorVT(*DAG.getContext(),
799 BuiltVectorTy.getVectorElementType(),
800 ValueVT.getVectorElementCount());
801 Val = DAG.getNode(ISD::ANY_EXTEND,DL, ValueVT, Val);
802 }
803
804if (SDValue Widened =widenVectorToPartType(DAG, Val,DL, BuiltVectorTy)) {
805 Val = Widened;
806 }
807 }
808
809assert(Val.getValueType() == BuiltVectorTy &&"Unexpected vector value type");
810
811// Split the vector into intermediate operands.
812SmallVector<SDValue, 8> Ops(NumIntermediates);
813for (unsigned i = 0; i != NumIntermediates; ++i) {
814if (IntermediateVT.isVector()) {
815// This does something sensible for scalable vectors - see the
816// definition of EXTRACT_SUBVECTOR for further details.
817unsigned IntermediateNumElts = IntermediateVT.getVectorMinNumElements();
818 Ops[i] =
819 DAG.getNode(ISD::EXTRACT_SUBVECTOR,DL, IntermediateVT, Val,
820 DAG.getVectorIdxConstant(i * IntermediateNumElts,DL));
821 }else {
822 Ops[i] = DAG.getNode(ISD::EXTRACT_VECTOR_ELT,DL, IntermediateVT, Val,
823 DAG.getVectorIdxConstant(i,DL));
824 }
825 }
826
827// Split the intermediate operands into legal parts.
828if (NumParts == NumIntermediates) {
829// If the register was not expanded, promote or copy the value,
830// as appropriate.
831for (unsigned i = 0; i != NumParts; ++i)
832getCopyToParts(DAG,DL, Ops[i], &Parts[i], 1, PartVT, V, CallConv);
833 }elseif (NumParts > 0) {
834// If the intermediate type was expanded, split each the value into
835// legal parts.
836assert(NumIntermediates != 0 &&"division by zero");
837assert(NumParts % NumIntermediates == 0 &&
838"Must expand into a divisible number of parts!");
839unsigned Factor = NumParts / NumIntermediates;
840for (unsigned i = 0; i != NumIntermediates; ++i)
841getCopyToParts(DAG,DL, Ops[i], &Parts[i * Factor], Factor, PartVT, V,
842 CallConv);
843 }
844}
845
846RegsForValue::RegsForValue(constSmallVector<Register, 4> &regs,MVT regvt,
847EVT valuevt, std::optional<CallingConv::ID>CC)
848 : ValueVTs(1, valuevt), RegVTs(1, regvt), Regs(regs),
849 RegCount(1, regs.size()), CallConv(CC) {}
850
851RegsForValue::RegsForValue(LLVMContext &Context,constTargetLowering &TLI,
852constDataLayout &DL,Register Reg,Type *Ty,
853 std::optional<CallingConv::ID>CC) {
854ComputeValueVTs(TLI,DL, Ty,ValueVTs);
855
856CallConv =CC;
857
858for (EVT ValueVT :ValueVTs) {
859unsigned NumRegs =
860isABIMangled()
861 ? TLI.getNumRegistersForCallingConv(Context, *CC, ValueVT)
862 : TLI.getNumRegisters(Context, ValueVT);
863MVT RegisterVT =
864isABIMangled()
865 ? TLI.getRegisterTypeForCallingConv(Context, *CC, ValueVT)
866 : TLI.getRegisterType(Context, ValueVT);
867for (unsigned i = 0; i != NumRegs; ++i)
868Regs.push_back(Reg + i);
869RegVTs.push_back(RegisterVT);
870RegCount.push_back(NumRegs);
871 Reg = Reg.id() + NumRegs;
872 }
873}
874
875SDValueRegsForValue::getCopyFromRegs(SelectionDAG &DAG,
876FunctionLoweringInfo &FuncInfo,
877constSDLoc &dl,SDValue &Chain,
878SDValue *Glue,constValue *V) const{
879// A Value with type {} or [0 x %t] needs no registers.
880if (ValueVTs.empty())
881returnSDValue();
882
883constTargetLowering &TLI = DAG.getTargetLoweringInfo();
884
885// Assemble the legal parts into the final values.
886SmallVector<SDValue, 4> Values(ValueVTs.size());
887SmallVector<SDValue, 8> Parts;
888for (unsignedValue = 0, Part = 0, e =ValueVTs.size();Value != e; ++Value) {
889// Copy the legal parts from the registers.
890EVT ValueVT =ValueVTs[Value];
891unsigned NumRegs =RegCount[Value];
892MVT RegisterVT =isABIMangled()
893 ? TLI.getRegisterTypeForCallingConv(
894 *DAG.getContext(), *CallConv,RegVTs[Value])
895 :RegVTs[Value];
896
897 Parts.resize(NumRegs);
898for (unsigned i = 0; i != NumRegs; ++i) {
899SDValueP;
900if (!Glue) {
901P = DAG.getCopyFromReg(Chain, dl,Regs[Part+i], RegisterVT);
902 }else {
903P = DAG.getCopyFromReg(Chain, dl,Regs[Part+i], RegisterVT, *Glue);
904 *Glue =P.getValue(2);
905 }
906
907 Chain =P.getValue(1);
908 Parts[i] =P;
909
910// If the source register was virtual and if we know something about it,
911// add an assert node.
912if (!Register::isVirtualRegister(Regs[Part + i]) ||
913 !RegisterVT.isInteger())
914continue;
915
916constFunctionLoweringInfo::LiveOutInfo *LOI =
917 FuncInfo.GetLiveOutRegInfo(Regs[Part+i]);
918if (!LOI)
919continue;
920
921unsignedRegSize = RegisterVT.getScalarSizeInBits();
922unsigned NumSignBits = LOI->NumSignBits;
923unsigned NumZeroBits = LOI->Known.countMinLeadingZeros();
924
925if (NumZeroBits ==RegSize) {
926// The current value is a zero.
927// Explicitly express that as it would be easier for
928// optimizations to kick in.
929 Parts[i] = DAG.getConstant(0, dl, RegisterVT);
930continue;
931 }
932
933// FIXME: We capture more information than the dag can represent. For
934// now, just use the tightest assertzext/assertsext possible.
935bool isSExt;
936EVT FromVT(MVT::Other);
937if (NumZeroBits) {
938 FromVT =EVT::getIntegerVT(*DAG.getContext(),RegSize - NumZeroBits);
939 isSExt =false;
940 }elseif (NumSignBits > 1) {
941 FromVT =
942EVT::getIntegerVT(*DAG.getContext(),RegSize - NumSignBits + 1);
943 isSExt =true;
944 }else {
945continue;
946 }
947// Add an assertion node.
948assert(FromVT != MVT::Other);
949 Parts[i] = DAG.getNode(isSExt ?ISD::AssertSext :ISD::AssertZext, dl,
950 RegisterVT,P, DAG.getValueType(FromVT));
951 }
952
953 Values[Value] =getCopyFromParts(DAG, dl, Parts.begin(), NumRegs,
954 RegisterVT, ValueVT, V, Chain,CallConv);
955 Part += NumRegs;
956 Parts.clear();
957 }
958
959return DAG.getNode(ISD::MERGE_VALUES, dl, DAG.getVTList(ValueVTs), Values);
960}
961
962voidRegsForValue::getCopyToRegs(SDValue Val,SelectionDAG &DAG,
963constSDLoc &dl,SDValue &Chain,SDValue *Glue,
964constValue *V,
965ISD::NodeType PreferredExtendType) const{
966constTargetLowering &TLI = DAG.getTargetLoweringInfo();
967ISD::NodeType ExtendKind = PreferredExtendType;
968
969// Get the list of the values's legal parts.
970unsigned NumRegs =Regs.size();
971SmallVector<SDValue, 8> Parts(NumRegs);
972for (unsignedValue = 0, Part = 0, e =ValueVTs.size();Value != e; ++Value) {
973unsigned NumParts =RegCount[Value];
974
975MVT RegisterVT =isABIMangled()
976 ? TLI.getRegisterTypeForCallingConv(
977 *DAG.getContext(), *CallConv,RegVTs[Value])
978 :RegVTs[Value];
979
980if (ExtendKind ==ISD::ANY_EXTEND && TLI.isZExtFree(Val, RegisterVT))
981 ExtendKind =ISD::ZERO_EXTEND;
982
983getCopyToParts(DAG, dl, Val.getValue(Val.getResNo() +Value), &Parts[Part],
984 NumParts, RegisterVT, V,CallConv, ExtendKind);
985 Part += NumParts;
986 }
987
988// Copy the parts into the registers.
989SmallVector<SDValue, 8> Chains(NumRegs);
990for (unsigned i = 0; i != NumRegs; ++i) {
991SDValue Part;
992if (!Glue) {
993 Part = DAG.getCopyToReg(Chain, dl,Regs[i], Parts[i]);
994 }else {
995 Part = DAG.getCopyToReg(Chain, dl,Regs[i], Parts[i], *Glue);
996 *Glue = Part.getValue(1);
997 }
998
999 Chains[i] = Part.getValue(0);
1000 }
1001
1002if (NumRegs == 1 || Glue)
1003// If NumRegs > 1 && Glue is used then the use of the last CopyToReg is
1004// flagged to it. That is the CopyToReg nodes and the user are considered
1005// a single scheduling unit. If we create a TokenFactor and return it as
1006// chain, then the TokenFactor is both a predecessor (operand) of the
1007// user as well as a successor (the TF operands are flagged to the user).
1008// c1, f1 = CopyToReg
1009// c2, f2 = CopyToReg
1010// c3 = TokenFactor c1, c2
1011// ...
1012// = op c3, ..., f2
1013 Chain = Chains[NumRegs-1];
1014else
1015 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Chains);
1016}
1017
1018voidRegsForValue::AddInlineAsmOperands(InlineAsm::Kind Code,bool HasMatching,
1019unsigned MatchingIdx,constSDLoc &dl,
1020SelectionDAG &DAG,
1021 std::vector<SDValue> &Ops) const{
1022constTargetLowering &TLI = DAG.getTargetLoweringInfo();
1023
1024InlineAsm::Flag Flag(Code,Regs.size());
1025if (HasMatching)
1026 Flag.setMatchingOp(MatchingIdx);
1027elseif (!Regs.empty() &&Register::isVirtualRegister(Regs.front())) {
1028// Put the register class of the virtual registers in the flag word. That
1029// way, later passes can recompute register class constraints for inline
1030// assembly as well as normal instructions.
1031// Don't do this for tied operands that can use the regclass information
1032// from the def.
1033constMachineRegisterInfo &MRI = DAG.getMachineFunction().getRegInfo();
1034constTargetRegisterClass *RC =MRI.getRegClass(Regs.front());
1035 Flag.setRegClass(RC->getID());
1036 }
1037
1038SDValue Res = DAG.getTargetConstant(Flag, dl, MVT::i32);
1039 Ops.push_back(Res);
1040
1041if (Code ==InlineAsm::Kind::Clobber) {
1042// Clobbers should always have a 1:1 mapping with registers, and may
1043// reference registers that have illegal (e.g. vector) types. Hence, we
1044// shouldn't try to apply any sort of splitting logic to them.
1045assert(Regs.size() ==RegVTs.size() &&Regs.size() ==ValueVTs.size() &&
1046"No 1:1 mapping from clobbers to regs?");
1047Register SP = TLI.getStackPointerRegisterToSaveRestore();
1048 (void)SP;
1049for (unsignedI = 0, E =ValueVTs.size();I != E; ++I) {
1050 Ops.push_back(DAG.getRegister(Regs[I],RegVTs[I]));
1051assert(
1052 (Regs[I] != SP ||
1053 DAG.getMachineFunction().getFrameInfo().hasOpaqueSPAdjustment()) &&
1054"If we clobbered the stack pointer, MFI should know about it.");
1055 }
1056return;
1057 }
1058
1059for (unsignedValue = 0, Reg = 0, e =ValueVTs.size();Value != e; ++Value) {
1060MVT RegisterVT =RegVTs[Value];
1061unsigned NumRegs = TLI.getNumRegisters(*DAG.getContext(),ValueVTs[Value],
1062 RegisterVT);
1063for (unsigned i = 0; i != NumRegs; ++i) {
1064assert(Reg <Regs.size() &&"Mismatch in # registers expected");
1065unsigned TheReg =Regs[Reg++];
1066 Ops.push_back(DAG.getRegister(TheReg, RegisterVT));
1067 }
1068 }
1069}
1070
1071SmallVector<std::pair<Register, TypeSize>, 4>
1072RegsForValue::getRegsAndSizes() const{
1073SmallVector<std::pair<Register, TypeSize>, 4> OutVec;
1074unsignedI = 0;
1075for (auto CountAndVT :zip_first(RegCount,RegVTs)) {
1076unsignedRegCount = std::get<0>(CountAndVT);
1077MVT RegisterVT = std::get<1>(CountAndVT);
1078TypeSize RegisterSize = RegisterVT.getSizeInBits();
1079for (unsigned E =I +RegCount;I != E; ++I)
1080 OutVec.push_back(std::make_pair(Regs[I], RegisterSize));
1081 }
1082return OutVec;
1083}
1084
1085voidSelectionDAGBuilder::init(GCFunctionInfo *gfi,BatchAAResults *aa,
1086AssumptionCache *ac,
1087constTargetLibraryInfo *li) {
1088BatchAA =aa;
1089AC = ac;
1090GFI = gfi;
1091LibInfo = li;
1092Context =DAG.getContext();
1093LPadToCallSiteMap.clear();
1094SL->init(DAG.getTargetLoweringInfo(), TM,DAG.getDataLayout());
1095 AssignmentTrackingEnabled =isAssignmentTrackingEnabled(
1096 *DAG.getMachineFunction().getFunction().getParent());
1097}
1098
1099voidSelectionDAGBuilder::clear() {
1100 NodeMap.clear();
1101 UnusedArgNodeMap.clear();
1102PendingLoads.clear();
1103 PendingExports.clear();
1104 PendingConstrainedFP.clear();
1105 PendingConstrainedFPStrict.clear();
1106 CurInst =nullptr;
1107HasTailCall =false;
1108 SDNodeOrder =LowestSDNodeOrder;
1109StatepointLowering.clear();
1110}
1111
1112voidSelectionDAGBuilder::clearDanglingDebugInfo() {
1113 DanglingDebugInfoMap.clear();
1114}
1115
1116// Update DAG root to include dependencies on Pending chains.
1117SDValue SelectionDAGBuilder::updateRoot(SmallVectorImpl<SDValue> &Pending) {
1118SDValue Root =DAG.getRoot();
1119
1120if (Pending.empty())
1121return Root;
1122
1123// Add current root to PendingChains, unless we already indirectly
1124// depend on it.
1125if (Root.getOpcode() !=ISD::EntryToken) {
1126unsigned i = 0, e = Pending.size();
1127for (; i != e; ++i) {
1128assert(Pending[i].getNode()->getNumOperands() > 1);
1129if (Pending[i].getNode()->getOperand(0) == Root)
1130break;// Don't add the root if we already indirectly depend on it.
1131 }
1132
1133if (i == e)
1134 Pending.push_back(Root);
1135 }
1136
1137if (Pending.size() == 1)
1138 Root = Pending[0];
1139else
1140 Root =DAG.getTokenFactor(getCurSDLoc(), Pending);
1141
1142DAG.setRoot(Root);
1143 Pending.clear();
1144return Root;
1145}
1146
1147SDValueSelectionDAGBuilder::getMemoryRoot() {
1148return updateRoot(PendingLoads);
1149}
1150
1151SDValueSelectionDAGBuilder::getRoot() {
1152// Chain up all pending constrained intrinsics together with all
1153// pending loads, by simply appending them to PendingLoads and
1154// then calling getMemoryRoot().
1155PendingLoads.reserve(PendingLoads.size() +
1156 PendingConstrainedFP.size() +
1157 PendingConstrainedFPStrict.size());
1158PendingLoads.append(PendingConstrainedFP.begin(),
1159 PendingConstrainedFP.end());
1160PendingLoads.append(PendingConstrainedFPStrict.begin(),
1161 PendingConstrainedFPStrict.end());
1162 PendingConstrainedFP.clear();
1163 PendingConstrainedFPStrict.clear();
1164returngetMemoryRoot();
1165}
1166
1167SDValueSelectionDAGBuilder::getControlRoot() {
1168// We need to emit pending fpexcept.strict constrained intrinsics,
1169// so append them to the PendingExports list.
1170 PendingExports.append(PendingConstrainedFPStrict.begin(),
1171 PendingConstrainedFPStrict.end());
1172 PendingConstrainedFPStrict.clear();
1173return updateRoot(PendingExports);
1174}
1175
1176voidSelectionDAGBuilder::handleDebugDeclare(Value *Address,
1177DILocalVariable *Variable,
1178DIExpression *Expression,
1179DebugLocDL) {
1180assert(Variable &&"Missing variable");
1181
1182// Check if address has undef value.
1183if (!Address || isa<UndefValue>(Address) ||
1184 (Address->use_empty() && !isa<Argument>(Address))) {
1185LLVM_DEBUG(
1186dbgs()
1187 <<"dbg_declare: Dropping debug info (bad/undef/unused-arg address)\n");
1188return;
1189 }
1190
1191bool IsParameter = Variable->isParameter() || isa<Argument>(Address);
1192
1193SDValue &N = NodeMap[Address];
1194if (!N.getNode() && isa<Argument>(Address))
1195// Check unused arguments map.
1196N = UnusedArgNodeMap[Address];
1197SDDbgValue *SDV;
1198if (N.getNode()) {
1199if (constBitCastInst *BCI = dyn_cast<BitCastInst>(Address))
1200Address = BCI->getOperand(0);
1201// Parameters are handled specially.
1202auto *FINode = dyn_cast<FrameIndexSDNode>(N.getNode());
1203if (IsParameter && FINode) {
1204// Byval parameter. We have a frame index at this point.
1205 SDV =DAG.getFrameIndexDbgValue(Variable,Expression, FINode->getIndex(),
1206/*IsIndirect*/true,DL, SDNodeOrder);
1207 }elseif (isa<Argument>(Address)) {
1208// Address is an argument, so try to emit its dbg value using
1209// virtual register info from the FuncInfo.ValueMap.
1210 EmitFuncArgumentDbgValue(Address, Variable,Expression,DL,
1211 FuncArgumentDbgValueKind::Declare,N);
1212return;
1213 }else {
1214 SDV =DAG.getDbgValue(Variable,Expression,N.getNode(),N.getResNo(),
1215true,DL, SDNodeOrder);
1216 }
1217DAG.AddDbgValue(SDV, IsParameter);
1218 }else {
1219// If Address is an argument then try to emit its dbg value using
1220// virtual register info from the FuncInfo.ValueMap.
1221if (!EmitFuncArgumentDbgValue(Address, Variable,Expression,DL,
1222 FuncArgumentDbgValueKind::Declare,N)) {
1223LLVM_DEBUG(dbgs() <<"dbg_declare: Dropping debug info"
1224 <<" (could not emit func-arg dbg_value)\n");
1225 }
1226 }
1227}
1228
1229voidSelectionDAGBuilder::visitDbgInfo(constInstruction &I) {
1230// Add SDDbgValue nodes for any var locs here. Do so before updating
1231// SDNodeOrder, as this mapping is {Inst -> Locs BEFORE Inst}.
1232if (FunctionVarLocsconst *FnVarLocs =DAG.getFunctionVarLocs()) {
1233// Add SDDbgValue nodes for any var locs here. Do so before updating
1234// SDNodeOrder, as this mapping is {Inst -> Locs BEFORE Inst}.
1235for (auto It = FnVarLocs->locs_begin(&I),End = FnVarLocs->locs_end(&I);
1236 It !=End; ++It) {
1237auto *Var = FnVarLocs->getDILocalVariable(It->VariableID);
1238dropDanglingDebugInfo(Var, It->Expr);
1239if (It->Values.isKillLocation(It->Expr)) {
1240handleKillDebugValue(Var, It->Expr, It->DL, SDNodeOrder);
1241continue;
1242 }
1243SmallVector<Value *> Values(It->Values.location_ops());
1244if (!handleDebugValue(Values, Var, It->Expr, It->DL, SDNodeOrder,
1245 It->Values.hasArgList())) {
1246SmallVector<Value *, 4> Vals(It->Values.location_ops());
1247addDanglingDebugInfo(Vals,
1248 FnVarLocs->getDILocalVariable(It->VariableID),
1249 It->Expr, Vals.size() > 1, It->DL, SDNodeOrder);
1250 }
1251 }
1252 }
1253
1254// We must skip DbgVariableRecords if they've already been processed above as
1255// we have just emitted the debug values resulting from assignment tracking
1256// analysis, making any existing DbgVariableRecords redundant (and probably
1257// less correct). We still need to process DbgLabelRecords. This does sink
1258// DbgLabelRecords to the bottom of the group of debug records. That sholdn't
1259// be important as it does so deterministcally and ordering between
1260// DbgLabelRecords and DbgVariableRecords is immaterial (other than for MIR/IR
1261// printing).
1262bool SkipDbgVariableRecords =DAG.getFunctionVarLocs();
1263// Is there is any debug-info attached to this instruction, in the form of
1264// DbgRecord non-instruction debug-info records.
1265for (DbgRecord &DR :I.getDbgRecordRange()) {
1266if (DbgLabelRecord *DLR = dyn_cast<DbgLabelRecord>(&DR)) {
1267assert(DLR->getLabel() &&"Missing label");
1268SDDbgLabel *SDV =
1269DAG.getDbgLabel(DLR->getLabel(), DLR->getDebugLoc(), SDNodeOrder);
1270DAG.AddDbgLabel(SDV);
1271continue;
1272 }
1273
1274if (SkipDbgVariableRecords)
1275continue;
1276DbgVariableRecord &DVR = cast<DbgVariableRecord>(DR);
1277DILocalVariable *Variable = DVR.getVariable();
1278DIExpression *Expression = DVR.getExpression();
1279dropDanglingDebugInfo(Variable,Expression);
1280
1281if (DVR.getType() ==DbgVariableRecord::LocationType::Declare) {
1282if (FuncInfo.PreprocessedDVRDeclares.contains(&DVR))
1283continue;
1284LLVM_DEBUG(dbgs() <<"SelectionDAG visiting dbg_declare: " << DVR
1285 <<"\n");
1286handleDebugDeclare(DVR.getVariableLocationOp(0), Variable,Expression,
1287 DVR.getDebugLoc());
1288continue;
1289 }
1290
1291// A DbgVariableRecord with no locations is a kill location.
1292SmallVector<Value *, 4> Values(DVR.location_ops());
1293if (Values.empty()) {
1294handleKillDebugValue(Variable,Expression, DVR.getDebugLoc(),
1295 SDNodeOrder);
1296continue;
1297 }
1298
1299// A DbgVariableRecord with an undef or absent location is also a kill
1300// location.
1301if (llvm::any_of(Values,
1302 [](Value *V) {return !V || isa<UndefValue>(V); })) {
1303handleKillDebugValue(Variable,Expression, DVR.getDebugLoc(),
1304 SDNodeOrder);
1305continue;
1306 }
1307
1308bool IsVariadic = DVR.hasArgList();
1309if (!handleDebugValue(Values, Variable,Expression, DVR.getDebugLoc(),
1310 SDNodeOrder, IsVariadic)) {
1311addDanglingDebugInfo(Values, Variable,Expression, IsVariadic,
1312 DVR.getDebugLoc(), SDNodeOrder);
1313 }
1314 }
1315}
1316
1317voidSelectionDAGBuilder::visit(constInstruction &I) {
1318visitDbgInfo(I);
1319
1320// Set up outgoing PHI node register values before emitting the terminator.
1321if (I.isTerminator()) {
1322 HandlePHINodesInSuccessorBlocks(I.getParent());
1323 }
1324
1325// Increase the SDNodeOrder if dealing with a non-debug instruction.
1326if (!isa<DbgInfoIntrinsic>(I))
1327 ++SDNodeOrder;
1328
1329 CurInst = &I;
1330
1331// Set inserted listener only if required.
1332bool NodeInserted =false;
1333 std::unique_ptr<SelectionDAG::DAGNodeInsertedListener> InsertedListener;
1334MDNode *PCSectionsMD =I.getMetadata(LLVMContext::MD_pcsections);
1335MDNode *MMRA =I.getMetadata(LLVMContext::MD_mmra);
1336if (PCSectionsMD || MMRA) {
1337 InsertedListener = std::make_unique<SelectionDAG::DAGNodeInsertedListener>(
1338DAG, [&](SDNode *) { NodeInserted =true; });
1339 }
1340
1341visit(I.getOpcode(),I);
1342
1343if (!I.isTerminator() && !HasTailCall &&
1344 !isa<GCStatepointInst>(I))// statepoints handle their exports internally
1345CopyToExportRegsIfNeeded(&I);
1346
1347// Handle metadata.
1348if (PCSectionsMD || MMRA) {
1349auto It = NodeMap.find(&I);
1350if (It != NodeMap.end()) {
1351if (PCSectionsMD)
1352DAG.addPCSections(It->second.getNode(), PCSectionsMD);
1353if (MMRA)
1354DAG.addMMRAMetadata(It->second.getNode(), MMRA);
1355 }elseif (NodeInserted) {
1356// This should not happen; if it does, don't let it go unnoticed so we can
1357// fix it. Relevant visit*() function is probably missing a setValue().
1358errs() <<"warning: loosing !pcsections and/or !mmra metadata ["
1359 <<I.getModule()->getName() <<"]\n";
1360LLVM_DEBUG(I.dump());
1361assert(false);
1362 }
1363 }
1364
1365 CurInst =nullptr;
1366}
1367
1368void SelectionDAGBuilder::visitPHI(constPHINode &) {
1369llvm_unreachable("SelectionDAGBuilder shouldn't visit PHI nodes!");
1370}
1371
1372voidSelectionDAGBuilder::visit(unsigned Opcode,constUser &I) {
1373// Note: this doesn't use InstVisitor, because it has to work with
1374// ConstantExpr's in addition to instructions.
1375switch (Opcode) {
1376default:llvm_unreachable("Unknown instruction type encountered!");
1377// Build the switch statement using the Instruction.def file.
1378#define HANDLE_INST(NUM, OPCODE, CLASS) \
1379 case Instruction::OPCODE: visit##OPCODE((const CLASS&)I); break;
1380#include "llvm/IR/Instruction.def"
1381 }
1382}
1383
1384staticboolhandleDanglingVariadicDebugInfo(SelectionDAG &DAG,
1385DILocalVariable *Variable,
1386DebugLocDL,unsigned Order,
1387SmallVectorImpl<Value *> &Values,
1388DIExpression *Expression) {
1389// For variadic dbg_values we will now insert an undef.
1390// FIXME: We can potentially recover these!
1391SmallVector<SDDbgOperand, 2> Locs;
1392for (constValue *V : Values) {
1393auto *Undef =UndefValue::get(V->getType());
1394 Locs.push_back(SDDbgOperand::fromConst(Undef));
1395 }
1396SDDbgValue *SDV = DAG.getDbgValueList(Variable,Expression, Locs, {},
1397/*IsIndirect=*/false,DL, Order,
1398/*IsVariadic=*/true);
1399 DAG.AddDbgValue(SDV,/*isParameter=*/false);
1400returntrue;
1401}
1402
1403voidSelectionDAGBuilder::addDanglingDebugInfo(SmallVectorImpl<Value *> &Values,
1404DILocalVariable *Var,
1405DIExpression *Expr,
1406bool IsVariadic,DebugLocDL,
1407unsigned Order) {
1408if (IsVariadic) {
1409handleDanglingVariadicDebugInfo(DAG, Var,DL, Order, Values, Expr);
1410return;
1411 }
1412// TODO: Dangling debug info will eventually either be resolved or produce
1413// an Undef DBG_VALUE. However in the resolution case, a gap may appear
1414// between the original dbg.value location and its resolved DBG_VALUE,
1415// which we should ideally fill with an extra Undef DBG_VALUE.
1416assert(Values.size() == 1);
1417 DanglingDebugInfoMap[Values[0]].emplace_back(Var, Expr,DL, Order);
1418}
1419
1420voidSelectionDAGBuilder::dropDanglingDebugInfo(constDILocalVariable *Variable,
1421constDIExpression *Expr) {
1422auto isMatchingDbgValue = [&](DanglingDebugInfo &DDI) {
1423DIVariable *DanglingVariable = DDI.getVariable();
1424DIExpression *DanglingExpr = DDI.getExpression();
1425if (DanglingVariable == Variable && Expr->fragmentsOverlap(DanglingExpr)) {
1426LLVM_DEBUG(dbgs() <<"Dropping dangling debug info for "
1427 << printDDI(nullptr, DDI) <<"\n");
1428returntrue;
1429 }
1430returnfalse;
1431 };
1432
1433for (auto &DDIMI : DanglingDebugInfoMap) {
1434 DanglingDebugInfoVector &DDIV = DDIMI.second;
1435
1436// If debug info is to be dropped, run it through final checks to see
1437// whether it can be salvaged.
1438for (auto &DDI : DDIV)
1439if (isMatchingDbgValue(DDI))
1440salvageUnresolvedDbgValue(DDIMI.first, DDI);
1441
1442erase_if(DDIV, isMatchingDbgValue);
1443 }
1444}
1445
1446// resolveDanglingDebugInfo - if we saw an earlier dbg_value referring to V,
1447// generate the debug data structures now that we've seen its definition.
1448voidSelectionDAGBuilder::resolveDanglingDebugInfo(constValue *V,
1449SDValue Val) {
1450auto DanglingDbgInfoIt = DanglingDebugInfoMap.find(V);
1451if (DanglingDbgInfoIt == DanglingDebugInfoMap.end())
1452return;
1453
1454 DanglingDebugInfoVector &DDIV = DanglingDbgInfoIt->second;
1455for (auto &DDI : DDIV) {
1456DebugLocDL = DDI.getDebugLoc();
1457unsigned ValSDNodeOrder = Val.getNode()->getIROrder();
1458unsigned DbgSDNodeOrder = DDI.getSDNodeOrder();
1459DILocalVariable *Variable = DDI.getVariable();
1460DIExpression *Expr = DDI.getExpression();
1461assert(Variable->isValidLocationForIntrinsic(DL) &&
1462"Expected inlined-at fields to agree");
1463SDDbgValue *SDV;
1464if (Val.getNode()) {
1465// FIXME: I doubt that it is correct to resolve a dangling DbgValue as a
1466// FuncArgumentDbgValue (it would be hoisted to the function entry, and if
1467// we couldn't resolve it directly when examining the DbgValue intrinsic
1468// in the first place we should not be more successful here). Unless we
1469// have some test case that prove this to be correct we should avoid
1470// calling EmitFuncArgumentDbgValue here.
1471if (!EmitFuncArgumentDbgValue(V, Variable, Expr,DL,
1472 FuncArgumentDbgValueKind::Value, Val)) {
1473LLVM_DEBUG(dbgs() <<"Resolve dangling debug info for "
1474 << printDDI(V, DDI) <<"\n");
1475LLVM_DEBUG(dbgs() <<" By mapping to:\n "; Val.dump());
1476// Increase the SDNodeOrder for the DbgValue here to make sure it is
1477// inserted after the definition of Val when emitting the instructions
1478// after ISel. An alternative could be to teach
1479// ScheduleDAGSDNodes::EmitSchedule to delay the insertion properly.
1480LLVM_DEBUG(if (ValSDNodeOrder > DbgSDNodeOrder)dbgs()
1481 <<"changing SDNodeOrder from " << DbgSDNodeOrder <<" to "
1482 << ValSDNodeOrder <<"\n");
1483 SDV = getDbgValue(Val, Variable, Expr,DL,
1484 std::max(DbgSDNodeOrder, ValSDNodeOrder));
1485DAG.AddDbgValue(SDV,false);
1486 }else
1487LLVM_DEBUG(dbgs() <<"Resolved dangling debug info for "
1488 << printDDI(V, DDI)
1489 <<" in EmitFuncArgumentDbgValue\n");
1490 }else {
1491LLVM_DEBUG(dbgs() <<"Dropping debug info for " << printDDI(V, DDI)
1492 <<"\n");
1493auto Undef =UndefValue::get(V->getType());
1494auto SDV =
1495DAG.getConstantDbgValue(Variable, Expr, Undef,DL, DbgSDNodeOrder);
1496DAG.AddDbgValue(SDV,false);
1497 }
1498 }
1499 DDIV.clear();
1500}
1501
1502voidSelectionDAGBuilder::salvageUnresolvedDbgValue(constValue *V,
1503 DanglingDebugInfo &DDI) {
1504// TODO: For the variadic implementation, instead of only checking the fail
1505// state of `handleDebugValue`, we need know specifically which values were
1506// invalid, so that we attempt to salvage only those values when processing
1507// a DIArgList.
1508constValue *OrigV = V;
1509DILocalVariable *Var = DDI.getVariable();
1510DIExpression *Expr = DDI.getExpression();
1511DebugLocDL = DDI.getDebugLoc();
1512unsigned SDOrder = DDI.getSDNodeOrder();
1513
1514// Currently we consider only dbg.value intrinsics -- we tell the salvager
1515// that DW_OP_stack_value is desired.
1516bool StackValue =true;
1517
1518// Can this Value can be encoded without any further work?
1519if (handleDebugValue(V, Var, Expr,DL, SDOrder,/*IsVariadic=*/false))
1520return;
1521
1522// Attempt to salvage back through as many instructions as possible. Bail if
1523// a non-instruction is seen, such as a constant expression or global
1524// variable. FIXME: Further work could recover those too.
1525while (isa<Instruction>(V)) {
1526constInstruction &VAsInst = *cast<const Instruction>(V);
1527// Temporary "0", awaiting real implementation.
1528SmallVector<uint64_t, 16> Ops;
1529SmallVector<Value *, 4> AdditionalValues;
1530 V =salvageDebugInfoImpl(const_cast<Instruction &>(VAsInst),
1531 Expr->getNumLocationOperands(), Ops,
1532 AdditionalValues);
1533// If we cannot salvage any further, and haven't yet found a suitable debug
1534// expression, bail out.
1535if (!V)
1536break;
1537
1538// TODO: If AdditionalValues isn't empty, then the salvage can only be
1539// represented with a DBG_VALUE_LIST, so we give up. When we have support
1540// here for variadic dbg_values, remove that condition.
1541if (!AdditionalValues.empty())
1542break;
1543
1544// New value and expr now represent this debuginfo.
1545 Expr =DIExpression::appendOpsToArg(Expr, Ops, 0, StackValue);
1546
1547// Some kind of simplification occurred: check whether the operand of the
1548// salvaged debug expression can be encoded in this DAG.
1549if (handleDebugValue(V, Var, Expr,DL, SDOrder,/*IsVariadic=*/false)) {
1550LLVM_DEBUG(
1551dbgs() <<"Salvaged debug location info for:\n " << *Var <<"\n"
1552 << *OrigV <<"\nBy stripping back to:\n " << *V <<"\n");
1553return;
1554 }
1555 }
1556
1557// This was the final opportunity to salvage this debug information, and it
1558// couldn't be done. Place an undef DBG_VALUE at this location to terminate
1559// any earlier variable location.
1560assert(OrigV &&"V shouldn't be null");
1561auto *Undef =UndefValue::get(OrigV->getType());
1562auto *SDV =DAG.getConstantDbgValue(Var, Expr, Undef,DL, SDNodeOrder);
1563DAG.AddDbgValue(SDV,false);
1564LLVM_DEBUG(dbgs() <<"Dropping debug value info for:\n "
1565 << printDDI(OrigV, DDI) <<"\n");
1566}
1567
1568voidSelectionDAGBuilder::handleKillDebugValue(DILocalVariable *Var,
1569DIExpression *Expr,
1570DebugLoc DbgLoc,
1571unsigned Order) {
1572Value *Poison =PoisonValue::get(Type::getInt1Ty(*Context));
1573DIExpression *NewExpr =
1574const_cast<DIExpression *>(DIExpression::convertToUndefExpression(Expr));
1575handleDebugValue(Poison, Var,NewExpr, DbgLoc, Order,
1576/*IsVariadic*/false);
1577}
1578
1579boolSelectionDAGBuilder::handleDebugValue(ArrayRef<const Value *> Values,
1580DILocalVariable *Var,
1581DIExpression *Expr,DebugLoc DbgLoc,
1582unsigned Order,bool IsVariadic) {
1583if (Values.empty())
1584returntrue;
1585
1586// Filter EntryValue locations out early.
1587if (visitEntryValueDbgValue(Values, Var, Expr, DbgLoc))
1588returntrue;
1589
1590SmallVector<SDDbgOperand> LocationOps;
1591SmallVector<SDNode *> Dependencies;
1592for (constValue *V : Values) {
1593// Constant value.
1594if (isa<ConstantInt>(V) || isa<ConstantFP>(V) || isa<UndefValue>(V) ||
1595 isa<ConstantPointerNull>(V)) {
1596 LocationOps.emplace_back(SDDbgOperand::fromConst(V));
1597continue;
1598 }
1599
1600// Look through IntToPtr constants.
1601if (auto *CE = dyn_cast<ConstantExpr>(V))
1602if (CE->getOpcode() == Instruction::IntToPtr) {
1603 LocationOps.emplace_back(SDDbgOperand::fromConst(CE->getOperand(0)));
1604continue;
1605 }
1606
1607// If the Value is a frame index, we can create a FrameIndex debug value
1608// without relying on the DAG at all.
1609if (constAllocaInst *AI = dyn_cast<AllocaInst>(V)) {
1610auto SI =FuncInfo.StaticAllocaMap.find(AI);
1611if (SI !=FuncInfo.StaticAllocaMap.end()) {
1612 LocationOps.emplace_back(SDDbgOperand::fromFrameIdx(SI->second));
1613continue;
1614 }
1615 }
1616
1617// Do not use getValue() in here; we don't want to generate code at
1618// this point if it hasn't been done yet.
1619SDValueN = NodeMap[V];
1620if (!N.getNode() && isa<Argument>(V))// Check unused arguments map.
1621N = UnusedArgNodeMap[V];
1622
1623if (N.getNode()) {
1624// Only emit func arg dbg value for non-variadic dbg.values for now.
1625if (!IsVariadic &&
1626 EmitFuncArgumentDbgValue(V, Var, Expr, DbgLoc,
1627 FuncArgumentDbgValueKind::Value,N))
1628returntrue;
1629if (auto *FISDN = dyn_cast<FrameIndexSDNode>(N.getNode())) {
1630// Construct a FrameIndexDbgValue for FrameIndexSDNodes so we can
1631// describe stack slot locations.
1632//
1633// Consider "int x = 0; int *px = &x;". There are two kinds of
1634// interesting debug values here after optimization:
1635//
1636// dbg.value(i32* %px, !"int *px", !DIExpression()), and
1637// dbg.value(i32* %px, !"int x", !DIExpression(DW_OP_deref))
1638//
1639// Both describe the direct values of their associated variables.
1640 Dependencies.push_back(N.getNode());
1641 LocationOps.emplace_back(SDDbgOperand::fromFrameIdx(FISDN->getIndex()));
1642continue;
1643 }
1644 LocationOps.emplace_back(
1645SDDbgOperand::fromNode(N.getNode(),N.getResNo()));
1646continue;
1647 }
1648
1649constTargetLowering &TLI =DAG.getTargetLoweringInfo();
1650// Special rules apply for the first dbg.values of parameter variables in a
1651// function. Identify them by the fact they reference Argument Values, that
1652// they're parameters, and they are parameters of the current function. We
1653// need to let them dangle until they get an SDNode.
1654bool IsParamOfFunc =
1655 isa<Argument>(V) && Var->isParameter() && !DbgLoc.getInlinedAt();
1656if (IsParamOfFunc)
1657returnfalse;
1658
1659// The value is not used in this block yet (or it would have an SDNode).
1660// We still want the value to appear for the user if possible -- if it has
1661// an associated VReg, we can refer to that instead.
1662auto VMI =FuncInfo.ValueMap.find(V);
1663if (VMI !=FuncInfo.ValueMap.end()) {
1664unsigned Reg = VMI->second;
1665// If this is a PHI node, it may be split up into several MI PHI nodes
1666// (in FunctionLoweringInfo::set).
1667RegsForValue RFV(V->getContext(), TLI,DAG.getDataLayout(), Reg,
1668 V->getType(), std::nullopt);
1669if (RFV.occupiesMultipleRegs()) {
1670// FIXME: We could potentially support variadic dbg_values here.
1671if (IsVariadic)
1672returnfalse;
1673unsignedOffset = 0;
1674unsigned BitsToDescribe = 0;
1675if (auto VarSize = Var->getSizeInBits())
1676 BitsToDescribe = *VarSize;
1677if (auto Fragment = Expr->getFragmentInfo())
1678 BitsToDescribe = Fragment->SizeInBits;
1679for (constauto &RegAndSize : RFV.getRegsAndSizes()) {
1680// Bail out if all bits are described already.
1681if (Offset >= BitsToDescribe)
1682break;
1683// TODO: handle scalable vectors.
1684unsigned RegisterSize = RegAndSize.second;
1685unsigned FragmentSize = (Offset + RegisterSize > BitsToDescribe)
1686 ? BitsToDescribe -Offset
1687 : RegisterSize;
1688auto FragmentExpr =DIExpression::createFragmentExpression(
1689 Expr,Offset, FragmentSize);
1690if (!FragmentExpr)
1691continue;
1692SDDbgValue *SDV =DAG.getVRegDbgValue(
1693 Var, *FragmentExpr, RegAndSize.first,false, DbgLoc, Order);
1694DAG.AddDbgValue(SDV,false);
1695Offset += RegisterSize;
1696 }
1697returntrue;
1698 }
1699// We can use simple vreg locations for variadic dbg_values as well.
1700 LocationOps.emplace_back(SDDbgOperand::fromVReg(Reg));
1701continue;
1702 }
1703// We failed to create a SDDbgOperand for V.
1704returnfalse;
1705 }
1706
1707// We have created a SDDbgOperand for each Value in Values.
1708assert(!LocationOps.empty());
1709SDDbgValue *SDV =
1710DAG.getDbgValueList(Var, Expr, LocationOps, Dependencies,
1711/*IsIndirect=*/false, DbgLoc, Order, IsVariadic);
1712DAG.AddDbgValue(SDV,/*isParameter=*/false);
1713returntrue;
1714}
1715
1716voidSelectionDAGBuilder::resolveOrClearDbgInfo() {
1717// Try to fixup any remaining dangling debug info -- and drop it if we can't.
1718for (auto &Pair : DanglingDebugInfoMap)
1719for (auto &DDI : Pair.second)
1720salvageUnresolvedDbgValue(const_cast<Value *>(Pair.first), DDI);
1721clearDanglingDebugInfo();
1722}
1723
1724/// getCopyFromRegs - If there was virtual register allocated for the value V
1725/// emit CopyFromReg of the specified type Ty. Return empty SDValue() otherwise.
1726SDValueSelectionDAGBuilder::getCopyFromRegs(constValue *V,Type *Ty) {
1727DenseMap<const Value *, Register>::iterator It =FuncInfo.ValueMap.find(V);
1728SDValue Result;
1729
1730if (It !=FuncInfo.ValueMap.end()) {
1731Register InReg = It->second;
1732
1733RegsForValue RFV(*DAG.getContext(),DAG.getTargetLoweringInfo(),
1734DAG.getDataLayout(), InReg, Ty,
1735 std::nullopt);// This is not an ABI copy.
1736SDValue Chain =DAG.getEntryNode();
1737 Result = RFV.getCopyFromRegs(DAG,FuncInfo,getCurSDLoc(), Chain,nullptr,
1738 V);
1739resolveDanglingDebugInfo(V, Result);
1740 }
1741
1742return Result;
1743}
1744
1745/// getValue - Return an SDValue for the given Value.
1746SDValueSelectionDAGBuilder::getValue(constValue *V) {
1747// If we already have an SDValue for this value, use it. It's important
1748// to do this first, so that we don't create a CopyFromReg if we already
1749// have a regular SDValue.
1750SDValue &N = NodeMap[V];
1751if (N.getNode())returnN;
1752
1753// If there's a virtual register allocated and initialized for this
1754// value, use it.
1755if (SDValue copyFromReg =getCopyFromRegs(V, V->getType()))
1756return copyFromReg;
1757
1758// Otherwise create a new SDValue and remember it.
1759SDValue Val =getValueImpl(V);
1760 NodeMap[V] = Val;
1761resolveDanglingDebugInfo(V, Val);
1762return Val;
1763}
1764
1765/// getNonRegisterValue - Return an SDValue for the given Value, but
1766/// don't look in FuncInfo.ValueMap for a virtual register.
1767SDValueSelectionDAGBuilder::getNonRegisterValue(constValue *V) {
1768// If we already have an SDValue for this value, use it.
1769SDValue &N = NodeMap[V];
1770if (N.getNode()) {
1771if (isIntOrFPConstant(N)) {
1772// Remove the debug location from the node as the node is about to be used
1773// in a location which may differ from the original debug location. This
1774// is relevant to Constant and ConstantFP nodes because they can appear
1775// as constant expressions inside PHI nodes.
1776N->setDebugLoc(DebugLoc());
1777 }
1778returnN;
1779 }
1780
1781// Otherwise create a new SDValue and remember it.
1782SDValue Val =getValueImpl(V);
1783 NodeMap[V] = Val;
1784resolveDanglingDebugInfo(V, Val);
1785return Val;
1786}
1787
1788/// getValueImpl - Helper function for getValue and getNonRegisterValue.
1789/// Create an SDValue for the given value.
1790SDValueSelectionDAGBuilder::getValueImpl(constValue *V) {
1791constTargetLowering &TLI =DAG.getTargetLoweringInfo();
1792
1793if (constConstant *C = dyn_cast<Constant>(V)) {
1794EVT VT = TLI.getValueType(DAG.getDataLayout(), V->getType(),true);
1795
1796if (constConstantInt *CI = dyn_cast<ConstantInt>(C))
1797returnDAG.getConstant(*CI,getCurSDLoc(), VT);
1798
1799if (constGlobalValue *GV = dyn_cast<GlobalValue>(C))
1800returnDAG.getGlobalAddress(GV,getCurSDLoc(), VT);
1801
1802if (constConstantPtrAuth *CPA = dyn_cast<ConstantPtrAuth>(C)) {
1803returnDAG.getNode(ISD::PtrAuthGlobalAddress,getCurSDLoc(), VT,
1804getValue(CPA->getPointer()),getValue(CPA->getKey()),
1805getValue(CPA->getAddrDiscriminator()),
1806getValue(CPA->getDiscriminator()));
1807 }
1808
1809if (isa<ConstantPointerNull>(C)) {
1810unsigned AS = V->getType()->getPointerAddressSpace();
1811returnDAG.getConstant(0,getCurSDLoc(),
1812 TLI.getPointerTy(DAG.getDataLayout(), AS));
1813 }
1814
1815if (match(C,m_VScale()))
1816returnDAG.getVScale(getCurSDLoc(), VT,APInt(VT.getSizeInBits(), 1));
1817
1818if (constConstantFP *CFP = dyn_cast<ConstantFP>(C))
1819returnDAG.getConstantFP(*CFP,getCurSDLoc(), VT);
1820
1821if (isa<UndefValue>(C) && !V->getType()->isAggregateType())
1822returnDAG.getUNDEF(VT);
1823
1824if (constConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
1825visit(CE->getOpcode(), *CE);
1826SDValue N1 = NodeMap[V];
1827assert(N1.getNode() &&"visit didn't populate the NodeMap!");
1828return N1;
1829 }
1830
1831if (isa<ConstantStruct>(C) || isa<ConstantArray>(C)) {
1832SmallVector<SDValue, 4> Constants;
1833for (constUse &U :C->operands()) {
1834SDNode *Val =getValue(U).getNode();
1835// If the operand is an empty aggregate, there are no values.
1836if (!Val)continue;
1837// Add each leaf value from the operand to the Constants list
1838// to form a flattened list of all the values.
1839for (unsigned i = 0, e = Val->getNumValues(); i != e; ++i)
1840 Constants.push_back(SDValue(Val, i));
1841 }
1842
1843returnDAG.getMergeValues(Constants,getCurSDLoc());
1844 }
1845
1846if (constConstantDataSequential *CDS =
1847 dyn_cast<ConstantDataSequential>(C)) {
1848SmallVector<SDValue, 4> Ops;
1849for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
1850SDNode *Val =getValue(CDS->getElementAsConstant(i)).getNode();
1851// Add each leaf value from the operand to the Constants list
1852// to form a flattened list of all the values.
1853for (unsigned i = 0, e = Val->getNumValues(); i != e; ++i)
1854 Ops.push_back(SDValue(Val, i));
1855 }
1856
1857if (isa<ArrayType>(CDS->getType()))
1858returnDAG.getMergeValues(Ops,getCurSDLoc());
1859return NodeMap[V] =DAG.getBuildVector(VT,getCurSDLoc(), Ops);
1860 }
1861
1862if (C->getType()->isStructTy() ||C->getType()->isArrayTy()) {
1863assert((isa<ConstantAggregateZero>(C) || isa<UndefValue>(C)) &&
1864"Unknown struct or array constant!");
1865
1866SmallVector<EVT, 4> ValueVTs;
1867ComputeValueVTs(TLI,DAG.getDataLayout(),C->getType(), ValueVTs);
1868unsigned NumElts = ValueVTs.size();
1869if (NumElts == 0)
1870returnSDValue();// empty struct
1871SmallVector<SDValue, 4> Constants(NumElts);
1872for (unsigned i = 0; i != NumElts; ++i) {
1873EVT EltVT = ValueVTs[i];
1874if (isa<UndefValue>(C))
1875 Constants[i] =DAG.getUNDEF(EltVT);
1876elseif (EltVT.isFloatingPoint())
1877 Constants[i] =DAG.getConstantFP(0,getCurSDLoc(), EltVT);
1878else
1879 Constants[i] =DAG.getConstant(0,getCurSDLoc(), EltVT);
1880 }
1881
1882returnDAG.getMergeValues(Constants,getCurSDLoc());
1883 }
1884
1885if (constBlockAddress *BA = dyn_cast<BlockAddress>(C))
1886returnDAG.getBlockAddress(BA, VT);
1887
1888if (constauto *Equiv = dyn_cast<DSOLocalEquivalent>(C))
1889returngetValue(Equiv->getGlobalValue());
1890
1891if (constauto *NC = dyn_cast<NoCFIValue>(C))
1892returngetValue(NC->getGlobalValue());
1893
1894if (VT == MVT::aarch64svcount) {
1895assert(C->isNullValue() &&"Can only zero this target type!");
1896returnDAG.getNode(ISD::BITCAST,getCurSDLoc(), VT,
1897DAG.getConstant(0,getCurSDLoc(), MVT::nxv16i1));
1898 }
1899
1900if (VT.isRISCVVectorTuple()) {
1901assert(C->isNullValue() &&"Can only zero this target type!");
1902return NodeMap[V] =DAG.getNode(
1903ISD::BITCAST,getCurSDLoc(), VT,
1904DAG.getNode(
1905ISD::SPLAT_VECTOR,getCurSDLoc(),
1906EVT::getVectorVT(*DAG.getContext(), MVT::i8,
1907 VT.getSizeInBits().getKnownMinValue() / 8,
1908true),
1909DAG.getConstant(0,getCurSDLoc(),MVT::getIntegerVT(8))));
1910 }
1911
1912VectorType *VecTy = cast<VectorType>(V->getType());
1913
1914// Now that we know the number and type of the elements, get that number of
1915// elements into the Ops array based on what kind of constant it is.
1916if (constConstantVector *CV = dyn_cast<ConstantVector>(C)) {
1917SmallVector<SDValue, 16> Ops;
1918unsigned NumElements = cast<FixedVectorType>(VecTy)->getNumElements();
1919for (unsigned i = 0; i != NumElements; ++i)
1920 Ops.push_back(getValue(CV->getOperand(i)));
1921
1922return NodeMap[V] =DAG.getBuildVector(VT,getCurSDLoc(), Ops);
1923 }
1924
1925if (isa<ConstantAggregateZero>(C)) {
1926EVT EltVT =
1927 TLI.getValueType(DAG.getDataLayout(), VecTy->getElementType());
1928
1929SDValueOp;
1930if (EltVT.isFloatingPoint())
1931Op =DAG.getConstantFP(0,getCurSDLoc(), EltVT);
1932else
1933Op =DAG.getConstant(0,getCurSDLoc(), EltVT);
1934
1935return NodeMap[V] =DAG.getSplat(VT,getCurSDLoc(),Op);
1936 }
1937
1938llvm_unreachable("Unknown vector constant");
1939 }
1940
1941// If this is a static alloca, generate it as the frameindex instead of
1942// computation.
1943if (constAllocaInst *AI = dyn_cast<AllocaInst>(V)) {
1944DenseMap<const AllocaInst*, int>::iterator SI =
1945FuncInfo.StaticAllocaMap.find(AI);
1946if (SI !=FuncInfo.StaticAllocaMap.end())
1947returnDAG.getFrameIndex(
1948 SI->second, TLI.getValueType(DAG.getDataLayout(), AI->getType()));
1949 }
1950
1951// If this is an instruction which fast-isel has deferred, select it now.
1952if (constInstruction *Inst = dyn_cast<Instruction>(V)) {
1953Register InReg =FuncInfo.InitializeRegForValue(Inst);
1954
1955RegsForValue RFV(*DAG.getContext(), TLI,DAG.getDataLayout(), InReg,
1956 Inst->getType(), std::nullopt);
1957SDValue Chain =DAG.getEntryNode();
1958return RFV.getCopyFromRegs(DAG,FuncInfo,getCurSDLoc(), Chain,nullptr, V);
1959 }
1960
1961if (constMetadataAsValue *MD = dyn_cast<MetadataAsValue>(V))
1962returnDAG.getMDNode(cast<MDNode>(MD->getMetadata()));
1963
1964if (constauto *BB = dyn_cast<BasicBlock>(V))
1965returnDAG.getBasicBlock(FuncInfo.getMBB(BB));
1966
1967llvm_unreachable("Can't get register for value!");
1968}
1969
1970void SelectionDAGBuilder::visitCatchPad(constCatchPadInst &I) {
1971auto Pers =classifyEHPersonality(FuncInfo.Fn->getPersonalityFn());
1972bool IsMSVCCXX = Pers ==EHPersonality::MSVC_CXX;
1973bool IsCoreCLR = Pers ==EHPersonality::CoreCLR;
1974bool IsSEH =isAsynchronousEHPersonality(Pers);
1975MachineBasicBlock *CatchPadMBB =FuncInfo.MBB;
1976if (!IsSEH)
1977 CatchPadMBB->setIsEHScopeEntry();
1978// In MSVC C++ and CoreCLR, catchblocks are funclets and need prologues.
1979if (IsMSVCCXX || IsCoreCLR)
1980 CatchPadMBB->setIsEHFuncletEntry();
1981}
1982
1983void SelectionDAGBuilder::visitCatchRet(constCatchReturnInst &I) {
1984// Update machine-CFG edge.
1985MachineBasicBlock *TargetMBB =FuncInfo.getMBB(I.getSuccessor());
1986FuncInfo.MBB->addSuccessor(TargetMBB);
1987 TargetMBB->setIsEHCatchretTarget(true);
1988DAG.getMachineFunction().setHasEHCatchret(true);
1989
1990auto Pers =classifyEHPersonality(FuncInfo.Fn->getPersonalityFn());
1991bool IsSEH =isAsynchronousEHPersonality(Pers);
1992if (IsSEH) {
1993// If this is not a fall-through branch or optimizations are switched off,
1994// emit the branch.
1995if (TargetMBB != NextBlock(FuncInfo.MBB) ||
1996 TM.getOptLevel() ==CodeGenOptLevel::None)
1997DAG.setRoot(DAG.getNode(ISD::BR,getCurSDLoc(), MVT::Other,
1998getControlRoot(),DAG.getBasicBlock(TargetMBB)));
1999return;
2000 }
2001
2002// Figure out the funclet membership for the catchret's successor.
2003// This will be used by the FuncletLayout pass to determine how to order the
2004// BB's.
2005// A 'catchret' returns to the outer scope's color.
2006Value *ParentPad =I.getCatchSwitchParentPad();
2007constBasicBlock *SuccessorColor;
2008if (isa<ConstantTokenNone>(ParentPad))
2009 SuccessorColor = &FuncInfo.Fn->getEntryBlock();
2010else
2011 SuccessorColor = cast<Instruction>(ParentPad)->getParent();
2012assert(SuccessorColor &&"No parent funclet for catchret!");
2013MachineBasicBlock *SuccessorColorMBB =FuncInfo.getMBB(SuccessorColor);
2014assert(SuccessorColorMBB &&"No MBB for SuccessorColor!");
2015
2016// Create the terminator node.
2017SDValueRet =DAG.getNode(ISD::CATCHRET,getCurSDLoc(), MVT::Other,
2018getControlRoot(),DAG.getBasicBlock(TargetMBB),
2019DAG.getBasicBlock(SuccessorColorMBB));
2020DAG.setRoot(Ret);
2021}
2022
2023void SelectionDAGBuilder::visitCleanupPad(constCleanupPadInst &CPI) {
2024// Don't emit any special code for the cleanuppad instruction. It just marks
2025// the start of an EH scope/funclet.
2026FuncInfo.MBB->setIsEHScopeEntry();
2027auto Pers =classifyEHPersonality(FuncInfo.Fn->getPersonalityFn());
2028if (Pers !=EHPersonality::Wasm_CXX) {
2029FuncInfo.MBB->setIsEHFuncletEntry();
2030FuncInfo.MBB->setIsCleanupFuncletEntry();
2031 }
2032}
2033
2034// In wasm EH, even though a catchpad may not catch an exception if a tag does
2035// not match, it is OK to add only the first unwind destination catchpad to the
2036// successors, because there will be at least one invoke instruction within the
2037// catch scope that points to the next unwind destination, if one exists, so
2038// CFGSort cannot mess up with BB sorting order.
2039// (All catchpads with 'catch (type)' clauses have a 'llvm.rethrow' intrinsic
2040// call within them, and catchpads only consisting of 'catch (...)' have a
2041// '__cxa_end_catch' call within them, both of which generate invokes in case
2042// the next unwind destination exists, i.e., the next unwind destination is not
2043// the caller.)
2044//
2045// Having at most one EH pad successor is also simpler and helps later
2046// transformations.
2047//
2048// For example,
2049// current:
2050// invoke void @foo to ... unwind label %catch.dispatch
2051// catch.dispatch:
2052// %0 = catchswitch within ... [label %catch.start] unwind label %next
2053// catch.start:
2054// ...
2055// ... in this BB or some other child BB dominated by this BB there will be an
2056// invoke that points to 'next' BB as an unwind destination
2057//
2058// next: ; We don't need to add this to 'current' BB's successor
2059// ...
2060staticvoidfindWasmUnwindDestinations(
2061FunctionLoweringInfo &FuncInfo,constBasicBlock *EHPadBB,
2062BranchProbability Prob,
2063SmallVectorImpl<std::pair<MachineBasicBlock *, BranchProbability>>
2064 &UnwindDests) {
2065while (EHPadBB) {
2066BasicBlock::const_iterator Pad = EHPadBB->getFirstNonPHIIt();
2067if (isa<CleanupPadInst>(Pad)) {
2068// Stop on cleanup pads.
2069 UnwindDests.emplace_back(FuncInfo.getMBB(EHPadBB), Prob);
2070 UnwindDests.back().first->setIsEHScopeEntry();
2071break;
2072 }elseif (constauto *CatchSwitch = dyn_cast<CatchSwitchInst>(Pad)) {
2073// Add the catchpad handlers to the possible destinations. We don't
2074// continue to the unwind destination of the catchswitch for wasm.
2075for (constBasicBlock *CatchPadBB : CatchSwitch->handlers()) {
2076 UnwindDests.emplace_back(FuncInfo.getMBB(CatchPadBB), Prob);
2077 UnwindDests.back().first->setIsEHScopeEntry();
2078 }
2079break;
2080 }else {
2081continue;
2082 }
2083 }
2084}
2085
2086/// When an invoke or a cleanupret unwinds to the next EH pad, there are
2087/// many places it could ultimately go. In the IR, we have a single unwind
2088/// destination, but in the machine CFG, we enumerate all the possible blocks.
2089/// This function skips over imaginary basic blocks that hold catchswitch
2090/// instructions, and finds all the "real" machine
2091/// basic block destinations. As those destinations may not be successors of
2092/// EHPadBB, here we also calculate the edge probability to those destinations.
2093/// The passed-in Prob is the edge probability to EHPadBB.
2094staticvoidfindUnwindDestinations(
2095FunctionLoweringInfo &FuncInfo,constBasicBlock *EHPadBB,
2096BranchProbability Prob,
2097SmallVectorImpl<std::pair<MachineBasicBlock *, BranchProbability>>
2098 &UnwindDests) {
2099EHPersonality Personality =
2100classifyEHPersonality(FuncInfo.Fn->getPersonalityFn());
2101bool IsMSVCCXX = Personality ==EHPersonality::MSVC_CXX;
2102bool IsCoreCLR = Personality ==EHPersonality::CoreCLR;
2103bool IsWasmCXX = Personality ==EHPersonality::Wasm_CXX;
2104bool IsSEH =isAsynchronousEHPersonality(Personality);
2105
2106if (IsWasmCXX) {
2107findWasmUnwindDestinations(FuncInfo, EHPadBB, Prob, UnwindDests);
2108assert(UnwindDests.size() <= 1 &&
2109"There should be at most one unwind destination for wasm");
2110return;
2111 }
2112
2113while (EHPadBB) {
2114BasicBlock::const_iterator Pad = EHPadBB->getFirstNonPHIIt();
2115BasicBlock *NewEHPadBB =nullptr;
2116if (isa<LandingPadInst>(Pad)) {
2117// Stop on landingpads. They are not funclets.
2118 UnwindDests.emplace_back(FuncInfo.getMBB(EHPadBB), Prob);
2119break;
2120 }elseif (isa<CleanupPadInst>(Pad)) {
2121// Stop on cleanup pads. Cleanups are always funclet entries for all known
2122// personalities.
2123 UnwindDests.emplace_back(FuncInfo.getMBB(EHPadBB), Prob);
2124 UnwindDests.back().first->setIsEHScopeEntry();
2125 UnwindDests.back().first->setIsEHFuncletEntry();
2126break;
2127 }elseif (constauto *CatchSwitch = dyn_cast<CatchSwitchInst>(Pad)) {
2128// Add the catchpad handlers to the possible destinations.
2129for (constBasicBlock *CatchPadBB : CatchSwitch->handlers()) {
2130 UnwindDests.emplace_back(FuncInfo.getMBB(CatchPadBB), Prob);
2131// For MSVC++ and the CLR, catchblocks are funclets and need prologues.
2132if (IsMSVCCXX || IsCoreCLR)
2133 UnwindDests.back().first->setIsEHFuncletEntry();
2134if (!IsSEH)
2135 UnwindDests.back().first->setIsEHScopeEntry();
2136 }
2137 NewEHPadBB = CatchSwitch->getUnwindDest();
2138 }else {
2139continue;
2140 }
2141
2142BranchProbabilityInfo *BPI = FuncInfo.BPI;
2143if (BPI && NewEHPadBB)
2144 Prob *= BPI->getEdgeProbability(EHPadBB, NewEHPadBB);
2145 EHPadBB = NewEHPadBB;
2146 }
2147}
2148
2149void SelectionDAGBuilder::visitCleanupRet(constCleanupReturnInst &I) {
2150// Update successor info.
2151SmallVector<std::pair<MachineBasicBlock *, BranchProbability>, 1> UnwindDests;
2152auto UnwindDest =I.getUnwindDest();
2153BranchProbabilityInfo *BPI =FuncInfo.BPI;
2154BranchProbability UnwindDestProb =
2155 (BPI && UnwindDest)
2156 ? BPI->getEdgeProbability(FuncInfo.MBB->getBasicBlock(), UnwindDest)
2157 :BranchProbability::getZero();
2158findUnwindDestinations(FuncInfo, UnwindDest, UnwindDestProb, UnwindDests);
2159for (auto &UnwindDest : UnwindDests) {
2160 UnwindDest.first->setIsEHPad();
2161 addSuccessorWithProb(FuncInfo.MBB, UnwindDest.first, UnwindDest.second);
2162 }
2163FuncInfo.MBB->normalizeSuccProbs();
2164
2165// Create the terminator node.
2166MachineBasicBlock *CleanupPadMBB =
2167FuncInfo.getMBB(I.getCleanupPad()->getParent());
2168SDValueRet =DAG.getNode(ISD::CLEANUPRET,getCurSDLoc(), MVT::Other,
2169getControlRoot(),DAG.getBasicBlock(CleanupPadMBB));
2170DAG.setRoot(Ret);
2171}
2172
2173void SelectionDAGBuilder::visitCatchSwitch(constCatchSwitchInst &CSI) {
2174report_fatal_error("visitCatchSwitch not yet implemented!");
2175}
2176
2177void SelectionDAGBuilder::visitRet(constReturnInst &I) {
2178constTargetLowering &TLI =DAG.getTargetLoweringInfo();
2179auto &DL =DAG.getDataLayout();
2180SDValue Chain =getControlRoot();
2181SmallVector<ISD::OutputArg, 8> Outs;
2182SmallVector<SDValue, 8> OutVals;
2183
2184// Calls to @llvm.experimental.deoptimize don't generate a return value, so
2185// lower
2186//
2187// %val = call <ty> @llvm.experimental.deoptimize()
2188// ret <ty> %val
2189//
2190// differently.
2191if (I.getParent()->getTerminatingDeoptimizeCall()) {
2192LowerDeoptimizingReturn();
2193return;
2194 }
2195
2196if (!FuncInfo.CanLowerReturn) {
2197Register DemoteReg =FuncInfo.DemoteRegister;
2198
2199// Emit a store of the return value through the virtual register.
2200// Leave Outs empty so that LowerReturn won't try to load return
2201// registers the usual way.
2202MVT PtrValueVT = TLI.getPointerTy(DL,DL.getAllocaAddrSpace());
2203SDValue RetPtr =
2204DAG.getCopyFromReg(Chain,getCurSDLoc(), DemoteReg, PtrValueVT);
2205SDValue RetOp =getValue(I.getOperand(0));
2206
2207SmallVector<EVT, 4> ValueVTs, MemVTs;
2208SmallVector<uint64_t, 4>Offsets;
2209ComputeValueVTs(TLI,DL,I.getOperand(0)->getType(), ValueVTs, &MemVTs,
2210 &Offsets, 0);
2211unsigned NumValues = ValueVTs.size();
2212
2213SmallVector<SDValue, 4> Chains(NumValues);
2214Align BaseAlign =DL.getPrefTypeAlign(I.getOperand(0)->getType());
2215for (unsigned i = 0; i != NumValues; ++i) {
2216// An aggregate return value cannot wrap around the address space, so
2217// offsets to its parts don't wrap either.
2218SDValuePtr =DAG.getObjectPtrOffset(getCurSDLoc(), RetPtr,
2219TypeSize::getFixed(Offsets[i]));
2220
2221SDValue Val = RetOp.getValue(RetOp.getResNo() + i);
2222if (MemVTs[i] != ValueVTs[i])
2223 Val =DAG.getPtrExtOrTrunc(Val,getCurSDLoc(), MemVTs[i]);
2224 Chains[i] =DAG.getStore(
2225 Chain,getCurSDLoc(), Val,
2226// FIXME: better loc info would be nice.
2227Ptr,MachinePointerInfo::getUnknownStack(DAG.getMachineFunction()),
2228commonAlignment(BaseAlign, Offsets[i]));
2229 }
2230
2231 Chain =DAG.getNode(ISD::TokenFactor,getCurSDLoc(),
2232 MVT::Other, Chains);
2233 }elseif (I.getNumOperands() != 0) {
2234SmallVector<EVT, 4> ValueVTs;
2235ComputeValueVTs(TLI,DL,I.getOperand(0)->getType(), ValueVTs);
2236unsigned NumValues = ValueVTs.size();
2237if (NumValues) {
2238SDValue RetOp =getValue(I.getOperand(0));
2239
2240constFunction *F =I.getParent()->getParent();
2241
2242bool NeedsRegBlock = TLI.functionArgumentNeedsConsecutiveRegisters(
2243I.getOperand(0)->getType(),F->getCallingConv(),
2244/*IsVarArg*/false,DL);
2245
2246ISD::NodeType ExtendKind =ISD::ANY_EXTEND;
2247if (F->getAttributes().hasRetAttr(Attribute::SExt))
2248 ExtendKind =ISD::SIGN_EXTEND;
2249elseif (F->getAttributes().hasRetAttr(Attribute::ZExt))
2250 ExtendKind =ISD::ZERO_EXTEND;
2251
2252LLVMContext &Context =F->getContext();
2253bool RetInReg =F->getAttributes().hasRetAttr(Attribute::InReg);
2254
2255for (unsigned j = 0;j != NumValues; ++j) {
2256EVT VT = ValueVTs[j];
2257
2258if (ExtendKind !=ISD::ANY_EXTEND && VT.isInteger())
2259 VT = TLI.getTypeForExtReturn(Context, VT, ExtendKind);
2260
2261CallingConv::IDCC =F->getCallingConv();
2262
2263unsigned NumParts = TLI.getNumRegistersForCallingConv(Context,CC, VT);
2264MVT PartVT = TLI.getRegisterTypeForCallingConv(Context,CC, VT);
2265SmallVector<SDValue, 4> Parts(NumParts);
2266getCopyToParts(DAG,getCurSDLoc(),
2267SDValue(RetOp.getNode(), RetOp.getResNo() + j),
2268 &Parts[0], NumParts, PartVT, &I,CC, ExtendKind);
2269
2270// 'inreg' on function refers to return value
2271ISD::ArgFlagsTyFlags =ISD::ArgFlagsTy();
2272if (RetInReg)
2273Flags.setInReg();
2274
2275if (I.getOperand(0)->getType()->isPointerTy()) {
2276Flags.setPointer();
2277Flags.setPointerAddrSpace(
2278 cast<PointerType>(I.getOperand(0)->getType())->getAddressSpace());
2279 }
2280
2281if (NeedsRegBlock) {
2282Flags.setInConsecutiveRegs();
2283if (j == NumValues - 1)
2284Flags.setInConsecutiveRegsLast();
2285 }
2286
2287// Propagate extension type if any
2288if (ExtendKind ==ISD::SIGN_EXTEND)
2289Flags.setSExt();
2290elseif (ExtendKind ==ISD::ZERO_EXTEND)
2291Flags.setZExt();
2292elseif (F->getAttributes().hasRetAttr(Attribute::NoExt))
2293Flags.setNoExt();
2294
2295for (unsigned i = 0; i < NumParts; ++i) {
2296 Outs.push_back(ISD::OutputArg(Flags,
2297 Parts[i].getValueType().getSimpleVT(),
2298 VT,/*isfixed=*/true, 0, 0));
2299 OutVals.push_back(Parts[i]);
2300 }
2301 }
2302 }
2303 }
2304
2305// Push in swifterror virtual register as the last element of Outs. This makes
2306// sure swifterror virtual register will be returned in the swifterror
2307// physical register.
2308constFunction *F =I.getParent()->getParent();
2309if (TLI.supportSwiftError() &&
2310F->getAttributes().hasAttrSomewhere(Attribute::SwiftError)) {
2311assert(SwiftError.getFunctionArg() &&"Need a swift error argument");
2312ISD::ArgFlagsTyFlags =ISD::ArgFlagsTy();
2313Flags.setSwiftError();
2314 Outs.push_back(ISD::OutputArg(
2315 Flags,/*vt=*/TLI.getPointerTy(DL),/*argvt=*/EVT(TLI.getPointerTy(DL)),
2316/*isfixed=*/true,/*origidx=*/1,/*partOffs=*/0));
2317// Create SDNode for the swifterror virtual register.
2318 OutVals.push_back(
2319DAG.getRegister(SwiftError.getOrCreateVRegUseAt(
2320 &I,FuncInfo.MBB,SwiftError.getFunctionArg()),
2321EVT(TLI.getPointerTy(DL))));
2322 }
2323
2324bool isVarArg =DAG.getMachineFunction().getFunction().isVarArg();
2325CallingConv::ID CallConv =
2326DAG.getMachineFunction().getFunction().getCallingConv();
2327 Chain =DAG.getTargetLoweringInfo().LowerReturn(
2328 Chain, CallConv, isVarArg, Outs, OutVals,getCurSDLoc(),DAG);
2329
2330// Verify that the target's LowerReturn behaved as expected.
2331assert(Chain.getNode() && Chain.getValueType() == MVT::Other &&
2332"LowerReturn didn't return a valid chain!");
2333
2334// Update the DAG with the new chain value resulting from return lowering.
2335DAG.setRoot(Chain);
2336}
2337
2338/// CopyToExportRegsIfNeeded - If the given value has virtual registers
2339/// created for it, emit nodes to copy the value into the virtual
2340/// registers.
2341voidSelectionDAGBuilder::CopyToExportRegsIfNeeded(constValue *V) {
2342// Skip empty types
2343if (V->getType()->isEmptyTy())
2344return;
2345
2346DenseMap<const Value *, Register>::iterator VMI =FuncInfo.ValueMap.find(V);
2347if (VMI !=FuncInfo.ValueMap.end()) {
2348assert((!V->use_empty() || isa<CallBrInst>(V)) &&
2349"Unused value assigned virtual registers!");
2350CopyValueToVirtualRegister(V, VMI->second);
2351 }
2352}
2353
2354/// ExportFromCurrentBlock - If this condition isn't known to be exported from
2355/// the current basic block, add it to ValueMap now so that we'll get a
2356/// CopyTo/FromReg.
2357voidSelectionDAGBuilder::ExportFromCurrentBlock(constValue *V) {
2358// No need to export constants.
2359if (!isa<Instruction>(V) && !isa<Argument>(V))return;
2360
2361// Already exported?
2362if (FuncInfo.isExportedInst(V))return;
2363
2364Register Reg =FuncInfo.InitializeRegForValue(V);
2365CopyValueToVirtualRegister(V, Reg);
2366}
2367
2368boolSelectionDAGBuilder::isExportableFromCurrentBlock(constValue *V,
2369constBasicBlock *FromBB) {
2370// The operands of the setcc have to be in this block. We don't know
2371// how to export them from some other block.
2372if (constInstruction *VI = dyn_cast<Instruction>(V)) {
2373// Can export from current BB.
2374if (VI->getParent() == FromBB)
2375returntrue;
2376
2377// Is already exported, noop.
2378returnFuncInfo.isExportedInst(V);
2379 }
2380
2381// If this is an argument, we can export it if the BB is the entry block or
2382// if it is already exported.
2383if (isa<Argument>(V)) {
2384if (FromBB->isEntryBlock())
2385returntrue;
2386
2387// Otherwise, can only export this if it is already exported.
2388returnFuncInfo.isExportedInst(V);
2389 }
2390
2391// Otherwise, constants can always be exported.
2392returntrue;
2393}
2394
2395/// Return branch probability calculated by BranchProbabilityInfo for IR blocks.
2396BranchProbability
2397SelectionDAGBuilder::getEdgeProbability(constMachineBasicBlock *Src,
2398constMachineBasicBlock *Dst) const{
2399BranchProbabilityInfo *BPI =FuncInfo.BPI;
2400constBasicBlock *SrcBB = Src->getBasicBlock();
2401constBasicBlock *DstBB = Dst->getBasicBlock();
2402if (!BPI) {
2403// If BPI is not available, set the default probability as 1 / N, where N is
2404// the number of successors.
2405auto SuccSize = std::max<uint32_t>(succ_size(SrcBB), 1);
2406returnBranchProbability(1, SuccSize);
2407 }
2408return BPI->getEdgeProbability(SrcBB, DstBB);
2409}
2410
2411void SelectionDAGBuilder::addSuccessorWithProb(MachineBasicBlock *Src,
2412MachineBasicBlock *Dst,
2413BranchProbability Prob) {
2414if (!FuncInfo.BPI)
2415 Src->addSuccessorWithoutProb(Dst);
2416else {
2417if (Prob.isUnknown())
2418 Prob = getEdgeProbability(Src, Dst);
2419 Src->addSuccessor(Dst, Prob);
2420 }
2421}
2422
2423staticboolInBlock(constValue *V,constBasicBlock *BB) {
2424if (constInstruction *I = dyn_cast<Instruction>(V))
2425returnI->getParent() == BB;
2426returntrue;
2427}
2428
2429/// EmitBranchForMergedCondition - Helper method for FindMergedConditions.
2430/// This function emits a branch and is used at the leaves of an OR or an
2431/// AND operator tree.
2432void
2433SelectionDAGBuilder::EmitBranchForMergedCondition(constValue *Cond,
2434MachineBasicBlock *TBB,
2435MachineBasicBlock *FBB,
2436MachineBasicBlock *CurBB,
2437MachineBasicBlock *SwitchBB,
2438BranchProbability TProb,
2439BranchProbability FProb,
2440bool InvertCond) {
2441constBasicBlock *BB = CurBB->getBasicBlock();
2442
2443// If the leaf of the tree is a comparison, merge the condition into
2444// the caseblock.
2445if (constCmpInst *BOp = dyn_cast<CmpInst>(Cond)) {
2446// The operands of the cmp have to be in this block. We don't know
2447// how to export them from some other block. If this is the first block
2448// of the sequence, no exporting is needed.
2449if (CurBB == SwitchBB ||
2450 (isExportableFromCurrentBlock(BOp->getOperand(0), BB) &&
2451isExportableFromCurrentBlock(BOp->getOperand(1), BB))) {
2452ISD::CondCode Condition;
2453if (constICmpInst *IC = dyn_cast<ICmpInst>(Cond)) {
2454ICmpInst::Predicate Pred =
2455 InvertCond ? IC->getInversePredicate() : IC->getPredicate();
2456 Condition =getICmpCondCode(Pred);
2457 }else {
2458constFCmpInst *FC = cast<FCmpInst>(Cond);
2459FCmpInst::Predicate Pred =
2460 InvertCond ? FC->getInversePredicate() : FC->getPredicate();
2461 Condition =getFCmpCondCode(Pred);
2462if (TM.Options.NoNaNsFPMath)
2463 Condition =getFCmpCodeWithoutNaN(Condition);
2464 }
2465
2466CaseBlock CB(Condition, BOp->getOperand(0), BOp->getOperand(1),nullptr,
2467TBB, FBB, CurBB,getCurSDLoc(), TProb, FProb);
2468SL->SwitchCases.push_back(CB);
2469return;
2470 }
2471 }
2472
2473// Create a CaseBlock record representing this branch.
2474ISD::CondCode Opc = InvertCond ?ISD::SETNE :ISD::SETEQ;
2475CaseBlock CB(Opc,Cond,ConstantInt::getTrue(*DAG.getContext()),
2476nullptr,TBB, FBB, CurBB,getCurSDLoc(), TProb, FProb);
2477SL->SwitchCases.push_back(CB);
2478}
2479
2480// Collect dependencies on V recursively. This is used for the cost analysis in
2481// `shouldKeepJumpConditionsTogether`.
2482staticboolcollectInstructionDeps(
2483SmallMapVector<const Instruction *, bool, 8> *Deps,constValue *V,
2484SmallMapVector<const Instruction *, bool, 8> *Necessary =nullptr,
2485unsignedDepth = 0) {
2486// Return false if we have an incomplete count.
2487if (Depth >=SelectionDAG::MaxRecursionDepth)
2488returnfalse;
2489
2490auto *I = dyn_cast<Instruction>(V);
2491if (I ==nullptr)
2492returntrue;
2493
2494if (Necessary !=nullptr) {
2495// This instruction is necessary for the other side of the condition so
2496// don't count it.
2497if (Necessary->contains(I))
2498returntrue;
2499 }
2500
2501// Already added this dep.
2502if (!Deps->try_emplace(I,false).second)
2503returntrue;
2504
2505for (unsigned OpIdx = 0, E =I->getNumOperands(); OpIdx < E; ++OpIdx)
2506if (!collectInstructionDeps(Deps,I->getOperand(OpIdx), Necessary,
2507Depth + 1))
2508returnfalse;
2509returntrue;
2510}
2511
2512boolSelectionDAGBuilder::shouldKeepJumpConditionsTogether(
2513constFunctionLoweringInfo &FuncInfo,constBranchInst &I,
2514Instruction::BinaryOps Opc,constValue *Lhs,constValue *Rhs,
2515TargetLoweringBase::CondMergingParams Params) const{
2516if (I.getNumSuccessors() != 2)
2517returnfalse;
2518
2519if (!I.isConditional())
2520returnfalse;
2521
2522if (Params.BaseCost < 0)
2523returnfalse;
2524
2525// Baseline cost.
2526InstructionCost CostThresh = Params.BaseCost;
2527
2528BranchProbabilityInfo *BPI =nullptr;
2529if (Params.LikelyBias || Params.UnlikelyBias)
2530 BPI =FuncInfo.BPI;
2531if (BPI !=nullptr) {
2532// See if we are either likely to get an early out or compute both lhs/rhs
2533// of the condition.
2534BasicBlock *IfFalse =I.getSuccessor(0);
2535BasicBlock *IfTrue =I.getSuccessor(1);
2536
2537 std::optional<bool> Likely;
2538if (BPI->isEdgeHot(I.getParent(), IfTrue))
2539 Likely =true;
2540elseif (BPI->isEdgeHot(I.getParent(), IfFalse))
2541 Likely =false;
2542
2543if (Likely) {
2544if (Opc == (*Likely ? Instruction::And : Instruction::Or))
2545// Its likely we will have to compute both lhs and rhs of condition
2546 CostThresh += Params.LikelyBias;
2547else {
2548if (Params.UnlikelyBias < 0)
2549returnfalse;
2550// Its likely we will get an early out.
2551 CostThresh -= Params.UnlikelyBias;
2552 }
2553 }
2554 }
2555
2556if (CostThresh <= 0)
2557returnfalse;
2558
2559// Collect "all" instructions that lhs condition is dependent on.
2560// Use map for stable iteration (to avoid non-determanism of iteration of
2561// SmallPtrSet). The `bool` value is just a dummy.
2562SmallMapVector<const Instruction *, bool, 8> LhsDeps, RhsDeps;
2563collectInstructionDeps(&LhsDeps, Lhs);
2564// Collect "all" instructions that rhs condition is dependent on AND are
2565// dependencies of lhs. This gives us an estimate on which instructions we
2566// stand to save by splitting the condition.
2567if (!collectInstructionDeps(&RhsDeps, Rhs, &LhsDeps))
2568returnfalse;
2569// Add the compare instruction itself unless its a dependency on the LHS.
2570if (constauto *RhsI = dyn_cast<Instruction>(Rhs))
2571if (!LhsDeps.contains(RhsI))
2572 RhsDeps.try_emplace(RhsI,false);
2573
2574constauto &TLI =DAG.getTargetLoweringInfo();
2575constauto &TTI =
2576 TLI.getTargetMachine().getTargetTransformInfo(*I.getFunction());
2577
2578InstructionCost CostOfIncluding = 0;
2579// See if this instruction will need to computed independently of whether RHS
2580// is.
2581Value *BrCond =I.getCondition();
2582auto ShouldCountInsn = [&RhsDeps, &BrCond](constInstruction *Ins) {
2583for (constauto *U : Ins->users()) {
2584// If user is independent of RHS calculation we don't need to count it.
2585if (auto *UIns = dyn_cast<Instruction>(U))
2586if (UIns != BrCond && !RhsDeps.contains(UIns))
2587returnfalse;
2588 }
2589returntrue;
2590 };
2591
2592// Prune instructions from RHS Deps that are dependencies of unrelated
2593// instructions. The value (SelectionDAG::MaxRecursionDepth) is fairly
2594// arbitrary and just meant to cap the how much time we spend in the pruning
2595// loop. Its highly unlikely to come into affect.
2596constunsigned MaxPruneIters =SelectionDAG::MaxRecursionDepth;
2597// Stop after a certain point. No incorrectness from including too many
2598// instructions.
2599for (unsigned PruneIters = 0; PruneIters < MaxPruneIters; ++PruneIters) {
2600constInstruction *ToDrop =nullptr;
2601for (constauto &InsPair : RhsDeps) {
2602if (!ShouldCountInsn(InsPair.first)) {
2603 ToDrop = InsPair.first;
2604break;
2605 }
2606 }
2607if (ToDrop ==nullptr)
2608break;
2609 RhsDeps.erase(ToDrop);
2610 }
2611
2612for (constauto &InsPair : RhsDeps) {
2613// Finally accumulate latency that we can only attribute to computing the
2614// RHS condition. Use latency because we are essentially trying to calculate
2615// the cost of the dependency chain.
2616// Possible TODO: We could try to estimate ILP and make this more precise.
2617 CostOfIncluding +=
2618TTI.getInstructionCost(InsPair.first,TargetTransformInfo::TCK_Latency);
2619
2620if (CostOfIncluding > CostThresh)
2621returnfalse;
2622 }
2623returntrue;
2624}
2625
2626voidSelectionDAGBuilder::FindMergedConditions(constValue *Cond,
2627MachineBasicBlock *TBB,
2628MachineBasicBlock *FBB,
2629MachineBasicBlock *CurBB,
2630MachineBasicBlock *SwitchBB,
2631Instruction::BinaryOps Opc,
2632BranchProbability TProb,
2633BranchProbability FProb,
2634bool InvertCond) {
2635// Skip over not part of the tree and remember to invert op and operands at
2636// next level.
2637Value *NotCond;
2638if (match(Cond,m_OneUse(m_Not(m_Value(NotCond)))) &&
2639InBlock(NotCond, CurBB->getBasicBlock())) {
2640FindMergedConditions(NotCond,TBB, FBB, CurBB, SwitchBB, Opc, TProb, FProb,
2641 !InvertCond);
2642return;
2643 }
2644
2645constInstruction *BOp = dyn_cast<Instruction>(Cond);
2646constValue *BOpOp0, *BOpOp1;
2647// Compute the effective opcode for Cond, taking into account whether it needs
2648// to be inverted, e.g.
2649// and (not (or A, B)), C
2650// gets lowered as
2651// and (and (not A, not B), C)
2652Instruction::BinaryOps BOpc = (Instruction::BinaryOps)0;
2653if (BOp) {
2654 BOpc =match(BOp,m_LogicalAnd(m_Value(BOpOp0),m_Value(BOpOp1)))
2655 ? Instruction::And
2656 : (match(BOp,m_LogicalOr(m_Value(BOpOp0),m_Value(BOpOp1)))
2657 ? Instruction::Or
2658 : (Instruction::BinaryOps)0);
2659if (InvertCond) {
2660if (BOpc == Instruction::And)
2661 BOpc = Instruction::Or;
2662elseif (BOpc == Instruction::Or)
2663 BOpc = Instruction::And;
2664 }
2665 }
2666
2667// If this node is not part of the or/and tree, emit it as a branch.
2668// Note that all nodes in the tree should have same opcode.
2669bool BOpIsInOrAndTree = BOpc && BOpc == Opc && BOp->hasOneUse();
2670if (!BOpIsInOrAndTree || BOp->getParent() != CurBB->getBasicBlock() ||
2671 !InBlock(BOpOp0, CurBB->getBasicBlock()) ||
2672 !InBlock(BOpOp1, CurBB->getBasicBlock())) {
2673EmitBranchForMergedCondition(Cond,TBB, FBB, CurBB, SwitchBB,
2674 TProb, FProb, InvertCond);
2675return;
2676 }
2677
2678// Create TmpBB after CurBB.
2679MachineFunction::iterator BBI(CurBB);
2680MachineFunction &MF =DAG.getMachineFunction();
2681MachineBasicBlock *TmpBB = MF.CreateMachineBasicBlock(CurBB->getBasicBlock());
2682 CurBB->getParent()->insert(++BBI, TmpBB);
2683
2684if (Opc == Instruction::Or) {
2685// Codegen X | Y as:
2686// BB1:
2687// jmp_if_X TBB
2688// jmp TmpBB
2689// TmpBB:
2690// jmp_if_Y TBB
2691// jmp FBB
2692//
2693
2694// We have flexibility in setting Prob for BB1 and Prob for TmpBB.
2695// The requirement is that
2696// TrueProb for BB1 + (FalseProb for BB1 * TrueProb for TmpBB)
2697// = TrueProb for original BB.
2698// Assuming the original probabilities are A and B, one choice is to set
2699// BB1's probabilities to A/2 and A/2+B, and set TmpBB's probabilities to
2700// A/(1+B) and 2B/(1+B). This choice assumes that
2701// TrueProb for BB1 == FalseProb for BB1 * TrueProb for TmpBB.
2702// Another choice is to assume TrueProb for BB1 equals to TrueProb for
2703// TmpBB, but the math is more complicated.
2704
2705auto NewTrueProb = TProb / 2;
2706auto NewFalseProb = TProb / 2 + FProb;
2707// Emit the LHS condition.
2708FindMergedConditions(BOpOp0,TBB, TmpBB, CurBB, SwitchBB, Opc, NewTrueProb,
2709 NewFalseProb, InvertCond);
2710
2711// Normalize A/2 and B to get A/(1+B) and 2B/(1+B).
2712SmallVector<BranchProbability, 2> Probs{TProb / 2, FProb};
2713BranchProbability::normalizeProbabilities(Probs.begin(), Probs.end());
2714// Emit the RHS condition into TmpBB.
2715FindMergedConditions(BOpOp1,TBB, FBB, TmpBB, SwitchBB, Opc, Probs[0],
2716 Probs[1], InvertCond);
2717 }else {
2718assert(Opc == Instruction::And &&"Unknown merge op!");
2719// Codegen X & Y as:
2720// BB1:
2721// jmp_if_X TmpBB
2722// jmp FBB
2723// TmpBB:
2724// jmp_if_Y TBB
2725// jmp FBB
2726//
2727// This requires creation of TmpBB after CurBB.
2728
2729// We have flexibility in setting Prob for BB1 and Prob for TmpBB.
2730// The requirement is that
2731// FalseProb for BB1 + (TrueProb for BB1 * FalseProb for TmpBB)
2732// = FalseProb for original BB.
2733// Assuming the original probabilities are A and B, one choice is to set
2734// BB1's probabilities to A+B/2 and B/2, and set TmpBB's probabilities to
2735// 2A/(1+A) and B/(1+A). This choice assumes that FalseProb for BB1 ==
2736// TrueProb for BB1 * FalseProb for TmpBB.
2737
2738auto NewTrueProb = TProb + FProb / 2;
2739auto NewFalseProb = FProb / 2;
2740// Emit the LHS condition.
2741FindMergedConditions(BOpOp0, TmpBB, FBB, CurBB, SwitchBB, Opc, NewTrueProb,
2742 NewFalseProb, InvertCond);
2743
2744// Normalize A and B/2 to get 2A/(1+A) and B/(1+A).
2745SmallVector<BranchProbability, 2> Probs{TProb, FProb / 2};
2746BranchProbability::normalizeProbabilities(Probs.begin(), Probs.end());
2747// Emit the RHS condition into TmpBB.
2748FindMergedConditions(BOpOp1,TBB, FBB, TmpBB, SwitchBB, Opc, Probs[0],
2749 Probs[1], InvertCond);
2750 }
2751}
2752
2753/// If the set of cases should be emitted as a series of branches, return true.
2754/// If we should emit this as a bunch of and/or'd together conditions, return
2755/// false.
2756bool
2757SelectionDAGBuilder::ShouldEmitAsBranches(const std::vector<CaseBlock> &Cases) {
2758if (Cases.size() != 2)returntrue;
2759
2760// If this is two comparisons of the same values or'd or and'd together, they
2761// will get folded into a single comparison, so don't emit two blocks.
2762if ((Cases[0].CmpLHS == Cases[1].CmpLHS &&
2763 Cases[0].CmpRHS == Cases[1].CmpRHS) ||
2764 (Cases[0].CmpRHS == Cases[1].CmpLHS &&
2765 Cases[0].CmpLHS == Cases[1].CmpRHS)) {
2766returnfalse;
2767 }
2768
2769// Handle: (X != null) | (Y != null) --> (X|Y) != 0
2770// Handle: (X == null) & (Y == null) --> (X|Y) == 0
2771if (Cases[0].CmpRHS == Cases[1].CmpRHS &&
2772 Cases[0].CC == Cases[1].CC &&
2773 isa<Constant>(Cases[0].CmpRHS) &&
2774 cast<Constant>(Cases[0].CmpRHS)->isNullValue()) {
2775if (Cases[0].CC ==ISD::SETEQ && Cases[0].TrueBB == Cases[1].ThisBB)
2776returnfalse;
2777if (Cases[0].CC ==ISD::SETNE && Cases[0].FalseBB == Cases[1].ThisBB)
2778returnfalse;
2779 }
2780
2781returntrue;
2782}
2783
2784void SelectionDAGBuilder::visitBr(constBranchInst &I) {
2785MachineBasicBlock *BrMBB =FuncInfo.MBB;
2786
2787// Update machine-CFG edges.
2788MachineBasicBlock *Succ0MBB =FuncInfo.getMBB(I.getSuccessor(0));
2789
2790if (I.isUnconditional()) {
2791// Update machine-CFG edges.
2792 BrMBB->addSuccessor(Succ0MBB);
2793
2794// If this is not a fall-through branch or optimizations are switched off,
2795// emit the branch.
2796if (Succ0MBB != NextBlock(BrMBB) ||
2797 TM.getOptLevel() ==CodeGenOptLevel::None) {
2798auto Br =DAG.getNode(ISD::BR,getCurSDLoc(), MVT::Other,
2799getControlRoot(),DAG.getBasicBlock(Succ0MBB));
2800setValue(&I, Br);
2801DAG.setRoot(Br);
2802 }
2803
2804return;
2805 }
2806
2807// If this condition is one of the special cases we handle, do special stuff
2808// now.
2809constValue *CondVal =I.getCondition();
2810MachineBasicBlock *Succ1MBB =FuncInfo.getMBB(I.getSuccessor(1));
2811
2812// If this is a series of conditions that are or'd or and'd together, emit
2813// this as a sequence of branches instead of setcc's with and/or operations.
2814// As long as jumps are not expensive (exceptions for multi-use logic ops,
2815// unpredictable branches, and vector extracts because those jumps are likely
2816// expensive for any target), this should improve performance.
2817// For example, instead of something like:
2818// cmp A, B
2819// C = seteq
2820// cmp D, E
2821// F = setle
2822// or C, F
2823// jnz foo
2824// Emit:
2825// cmp A, B
2826// je foo
2827// cmp D, E
2828// jle foo
2829bool IsUnpredictable =I.hasMetadata(LLVMContext::MD_unpredictable);
2830constInstruction *BOp = dyn_cast<Instruction>(CondVal);
2831if (!DAG.getTargetLoweringInfo().isJumpExpensive() && BOp &&
2832 BOp->hasOneUse() && !IsUnpredictable) {
2833Value *Vec;
2834constValue *BOp0, *BOp1;
2835Instruction::BinaryOps Opcode = (Instruction::BinaryOps)0;
2836if (match(BOp,m_LogicalAnd(m_Value(BOp0),m_Value(BOp1))))
2837 Opcode = Instruction::And;
2838elseif (match(BOp,m_LogicalOr(m_Value(BOp0),m_Value(BOp1))))
2839 Opcode = Instruction::Or;
2840
2841if (Opcode &&
2842 !(match(BOp0,m_ExtractElt(m_Value(Vec),m_Value())) &&
2843match(BOp1,m_ExtractElt(m_Specific(Vec),m_Value()))) &&
2844 !shouldKeepJumpConditionsTogether(
2845FuncInfo,I, Opcode, BOp0, BOp1,
2846DAG.getTargetLoweringInfo().getJumpConditionMergingParams(
2847 Opcode, BOp0, BOp1))) {
2848FindMergedConditions(BOp, Succ0MBB, Succ1MBB, BrMBB, BrMBB, Opcode,
2849 getEdgeProbability(BrMBB, Succ0MBB),
2850 getEdgeProbability(BrMBB, Succ1MBB),
2851/*InvertCond=*/false);
2852// If the compares in later blocks need to use values not currently
2853// exported from this block, export them now. This block should always
2854// be the first entry.
2855assert(SL->SwitchCases[0].ThisBB == BrMBB &&"Unexpected lowering!");
2856
2857// Allow some cases to be rejected.
2858if (ShouldEmitAsBranches(SL->SwitchCases)) {
2859for (unsigned i = 1, e =SL->SwitchCases.size(); i != e; ++i) {
2860ExportFromCurrentBlock(SL->SwitchCases[i].CmpLHS);
2861ExportFromCurrentBlock(SL->SwitchCases[i].CmpRHS);
2862 }
2863
2864// Emit the branch for this block.
2865visitSwitchCase(SL->SwitchCases[0], BrMBB);
2866SL->SwitchCases.erase(SL->SwitchCases.begin());
2867return;
2868 }
2869
2870// Okay, we decided not to do this, remove any inserted MBB's and clear
2871// SwitchCases.
2872for (unsigned i = 1, e =SL->SwitchCases.size(); i != e; ++i)
2873FuncInfo.MF->erase(SL->SwitchCases[i].ThisBB);
2874
2875SL->SwitchCases.clear();
2876 }
2877 }
2878
2879// Create a CaseBlock record representing this branch.
2880CaseBlock CB(ISD::SETEQ, CondVal,ConstantInt::getTrue(*DAG.getContext()),
2881nullptr, Succ0MBB, Succ1MBB, BrMBB,getCurSDLoc(),
2882BranchProbability::getUnknown(),BranchProbability::getUnknown(),
2883 IsUnpredictable);
2884
2885// Use visitSwitchCase to actually insert the fast branch sequence for this
2886// cond branch.
2887visitSwitchCase(CB, BrMBB);
2888}
2889
2890/// visitSwitchCase - Emits the necessary code to represent a single node in
2891/// the binary search tree resulting from lowering a switch instruction.
2892voidSelectionDAGBuilder::visitSwitchCase(CaseBlock &CB,
2893MachineBasicBlock *SwitchBB) {
2894SDValueCond;
2895SDValue CondLHS =getValue(CB.CmpLHS);
2896SDLoc dl = CB.DL;
2897
2898if (CB.CC ==ISD::SETTRUE) {
2899// Branch or fall through to TrueBB.
2900 addSuccessorWithProb(SwitchBB, CB.TrueBB, CB.TrueProb);
2901 SwitchBB->normalizeSuccProbs();
2902if (CB.TrueBB != NextBlock(SwitchBB)) {
2903DAG.setRoot(DAG.getNode(ISD::BR, dl, MVT::Other,getControlRoot(),
2904DAG.getBasicBlock(CB.TrueBB)));
2905 }
2906return;
2907 }
2908
2909auto &TLI =DAG.getTargetLoweringInfo();
2910EVT MemVT = TLI.getMemValueType(DAG.getDataLayout(), CB.CmpLHS->getType());
2911
2912// Build the setcc now.
2913if (!CB.CmpMHS) {
2914// Fold "(X == true)" to X and "(X == false)" to !X to
2915// handle common cases produced by branch lowering.
2916if (CB.CmpRHS ==ConstantInt::getTrue(*DAG.getContext()) &&
2917 CB.CC ==ISD::SETEQ)
2918Cond = CondLHS;
2919elseif (CB.CmpRHS ==ConstantInt::getFalse(*DAG.getContext()) &&
2920 CB.CC ==ISD::SETEQ) {
2921SDValue True =DAG.getConstant(1, dl, CondLHS.getValueType());
2922Cond =DAG.getNode(ISD::XOR, dl, CondLHS.getValueType(), CondLHS, True);
2923 }else {
2924SDValue CondRHS =getValue(CB.CmpRHS);
2925
2926// If a pointer's DAG type is larger than its memory type then the DAG
2927// values are zero-extended. This breaks signed comparisons so truncate
2928// back to the underlying type before doing the compare.
2929if (CondLHS.getValueType() != MemVT) {
2930 CondLHS =DAG.getPtrExtOrTrunc(CondLHS,getCurSDLoc(), MemVT);
2931 CondRHS =DAG.getPtrExtOrTrunc(CondRHS,getCurSDLoc(), MemVT);
2932 }
2933Cond =DAG.getSetCC(dl, MVT::i1, CondLHS, CondRHS, CB.CC);
2934 }
2935 }else {
2936assert(CB.CC ==ISD::SETLE &&"Can handle only LE ranges now");
2937
2938constAPInt&Low = cast<ConstantInt>(CB.CmpLHS)->getValue();
2939constAPInt&High = cast<ConstantInt>(CB.CmpRHS)->getValue();
2940
2941SDValue CmpOp =getValue(CB.CmpMHS);
2942EVT VT = CmpOp.getValueType();
2943
2944if (cast<ConstantInt>(CB.CmpLHS)->isMinValue(true)) {
2945Cond =DAG.getSetCC(dl, MVT::i1, CmpOp,DAG.getConstant(High, dl, VT),
2946ISD::SETLE);
2947 }else {
2948SDValue SUB =DAG.getNode(ISD::SUB, dl,
2949 VT, CmpOp,DAG.getConstant(Low, dl, VT));
2950Cond =DAG.getSetCC(dl, MVT::i1, SUB,
2951DAG.getConstant(High-Low, dl, VT),ISD::SETULE);
2952 }
2953 }
2954
2955// Update successor info
2956 addSuccessorWithProb(SwitchBB, CB.TrueBB, CB.TrueProb);
2957// TrueBB and FalseBB are always different unless the incoming IR is
2958// degenerate. This only happens when running llc on weird IR.
2959if (CB.TrueBB != CB.FalseBB)
2960 addSuccessorWithProb(SwitchBB, CB.FalseBB, CB.FalseProb);
2961 SwitchBB->normalizeSuccProbs();
2962
2963// If the lhs block is the next block, invert the condition so that we can
2964// fall through to the lhs instead of the rhs block.
2965if (CB.TrueBB == NextBlock(SwitchBB)) {
2966std::swap(CB.TrueBB, CB.FalseBB);
2967SDValue True =DAG.getConstant(1, dl,Cond.getValueType());
2968Cond =DAG.getNode(ISD::XOR, dl,Cond.getValueType(),Cond, True);
2969 }
2970
2971SDNodeFlags Flags;
2972 Flags.setUnpredictable(CB.IsUnpredictable);
2973SDValue BrCond =DAG.getNode(ISD::BRCOND, dl, MVT::Other,getControlRoot(),
2974Cond,DAG.getBasicBlock(CB.TrueBB), Flags);
2975
2976setValue(CurInst, BrCond);
2977
2978// Insert the false branch. Do this even if it's a fall through branch,
2979// this makes it easier to do DAG optimizations which require inverting
2980// the branch condition.
2981 BrCond =DAG.getNode(ISD::BR, dl, MVT::Other, BrCond,
2982DAG.getBasicBlock(CB.FalseBB));
2983
2984DAG.setRoot(BrCond);
2985}
2986
2987/// visitJumpTable - Emit JumpTable node in the current MBB
2988voidSelectionDAGBuilder::visitJumpTable(SwitchCG::JumpTable &JT) {
2989// Emit the code for the jump table
2990assert(JT.SL &&"Should set SDLoc for SelectionDAG!");
2991assert(JT.Reg &&"Should lower JT Header first!");
2992EVT PTy =DAG.getTargetLoweringInfo().getJumpTableRegTy(DAG.getDataLayout());
2993SDValue Index =DAG.getCopyFromReg(getControlRoot(), *JT.SL, JT.Reg, PTy);
2994SDValue Table =DAG.getJumpTable(JT.JTI, PTy);
2995SDValue BrJumpTable =DAG.getNode(ISD::BR_JT, *JT.SL, MVT::Other,
2996 Index.getValue(1), Table, Index);
2997DAG.setRoot(BrJumpTable);
2998}
2999
3000/// visitJumpTableHeader - This function emits necessary code to produce index
3001/// in the JumpTable from switch case.
3002voidSelectionDAGBuilder::visitJumpTableHeader(SwitchCG::JumpTable &JT,
3003JumpTableHeader &JTH,
3004MachineBasicBlock *SwitchBB) {
3005assert(JT.SL &&"Should set SDLoc for SelectionDAG!");
3006constSDLoc &dl = *JT.SL;
3007
3008// Subtract the lowest switch case value from the value being switched on.
3009SDValue SwitchOp =getValue(JTH.SValue);
3010EVT VT = SwitchOp.getValueType();
3011SDValue Sub =DAG.getNode(ISD::SUB, dl, VT, SwitchOp,
3012DAG.getConstant(JTH.First, dl, VT));
3013
3014// The SDNode we just created, which holds the value being switched on minus
3015// the smallest case value, needs to be copied to a virtual register so it
3016// can be used as an index into the jump table in a subsequent basic block.
3017// This value may be smaller or larger than the target's pointer type, and
3018// therefore require extension or truncating.
3019constTargetLowering &TLI =DAG.getTargetLoweringInfo();
3020 SwitchOp =
3021DAG.getZExtOrTrunc(Sub, dl, TLI.getJumpTableRegTy(DAG.getDataLayout()));
3022
3023Register JumpTableReg =
3024FuncInfo.CreateReg(TLI.getJumpTableRegTy(DAG.getDataLayout()));
3025SDValue CopyTo =
3026DAG.getCopyToReg(getControlRoot(), dl, JumpTableReg, SwitchOp);
3027 JT.Reg = JumpTableReg;
3028
3029if (!JTH.FallthroughUnreachable) {
3030// Emit the range check for the jump table, and branch to the default block
3031// for the switch statement if the value being switched on exceeds the
3032// largest case in the switch.
3033SDValue CMP =DAG.getSetCC(
3034 dl, TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(),
3035 Sub.getValueType()),
3036 Sub,DAG.getConstant(JTH.Last - JTH.First, dl, VT),ISD::SETUGT);
3037
3038SDValue BrCond =DAG.getNode(ISD::BRCOND, dl,
3039 MVT::Other, CopyTo, CMP,
3040DAG.getBasicBlock(JT.Default));
3041
3042// Avoid emitting unnecessary branches to the next block.
3043if (JT.MBB != NextBlock(SwitchBB))
3044 BrCond =DAG.getNode(ISD::BR, dl, MVT::Other, BrCond,
3045DAG.getBasicBlock(JT.MBB));
3046
3047DAG.setRoot(BrCond);
3048 }else {
3049// Avoid emitting unnecessary branches to the next block.
3050if (JT.MBB != NextBlock(SwitchBB))
3051DAG.setRoot(DAG.getNode(ISD::BR, dl, MVT::Other, CopyTo,
3052DAG.getBasicBlock(JT.MBB)));
3053else
3054DAG.setRoot(CopyTo);
3055 }
3056}
3057
3058/// Create a LOAD_STACK_GUARD node, and let it carry the target specific global
3059/// variable if there exists one.
3060staticSDValuegetLoadStackGuard(SelectionDAG &DAG,constSDLoc &DL,
3061SDValue &Chain) {
3062constTargetLowering &TLI = DAG.getTargetLoweringInfo();
3063EVT PtrTy = TLI.getPointerTy(DAG.getDataLayout());
3064EVT PtrMemTy = TLI.getPointerMemTy(DAG.getDataLayout());
3065MachineFunction &MF = DAG.getMachineFunction();
3066Value *Global = TLI.getSDagStackGuard(*MF.getFunction().getParent());
3067MachineSDNode *Node =
3068 DAG.getMachineNode(TargetOpcode::LOAD_STACK_GUARD,DL, PtrTy, Chain);
3069if (Global) {
3070MachinePointerInfo MPInfo(Global);
3071auto Flags =MachineMemOperand::MOLoad |MachineMemOperand::MOInvariant |
3072MachineMemOperand::MODereferenceable;
3073MachineMemOperand *MemRef = MF.getMachineMemOperand(
3074 MPInfo, Flags,LocationSize::precise(PtrTy.getSizeInBits() / 8),
3075 DAG.getEVTAlign(PtrTy));
3076 DAG.setNodeMemRefs(Node, {MemRef});
3077 }
3078if (PtrTy != PtrMemTy)
3079return DAG.getPtrExtOrTrunc(SDValue(Node, 0),DL, PtrMemTy);
3080returnSDValue(Node, 0);
3081}
3082
3083/// Codegen a new tail for a stack protector check ParentMBB which has had its
3084/// tail spliced into a stack protector check success bb.
3085///
3086/// For a high level explanation of how this fits into the stack protector
3087/// generation see the comment on the declaration of class
3088/// StackProtectorDescriptor.
3089voidSelectionDAGBuilder::visitSPDescriptorParent(StackProtectorDescriptor &SPD,
3090MachineBasicBlock *ParentBB) {
3091
3092// First create the loads to the guard/stack slot for the comparison.
3093constTargetLowering &TLI =DAG.getTargetLoweringInfo();
3094EVT PtrTy = TLI.getPointerTy(DAG.getDataLayout());
3095EVT PtrMemTy = TLI.getPointerMemTy(DAG.getDataLayout());
3096
3097MachineFrameInfo &MFI = ParentBB->getParent()->getFrameInfo();
3098int FI = MFI.getStackProtectorIndex();
3099
3100SDValue Guard;
3101SDLoc dl =getCurSDLoc();
3102SDValue StackSlotPtr =DAG.getFrameIndex(FI, PtrTy);
3103constModule &M = *ParentBB->getParent()->getFunction().getParent();
3104AlignAlign =
3105DAG.getDataLayout().getPrefTypeAlign(PointerType::get(M.getContext(), 0));
3106
3107// Generate code to load the content of the guard slot.
3108SDValue GuardVal =DAG.getLoad(
3109 PtrMemTy, dl,DAG.getEntryNode(), StackSlotPtr,
3110MachinePointerInfo::getFixedStack(DAG.getMachineFunction(), FI),Align,
3111MachineMemOperand::MOVolatile);
3112
3113if (TLI.useStackGuardXorFP())
3114 GuardVal = TLI.emitStackGuardXorFP(DAG, GuardVal, dl);
3115
3116// Retrieve guard check function, nullptr if instrumentation is inlined.
3117if (constFunction *GuardCheckFn = TLI.getSSPStackGuardCheck(M)) {
3118// The target provides a guard check function to validate the guard value.
3119// Generate a call to that function with the content of the guard slot as
3120// argument.
3121FunctionType *FnTy = GuardCheckFn->getFunctionType();
3122assert(FnTy->getNumParams() == 1 &&"Invalid function signature");
3123
3124TargetLowering::ArgListTy Args;
3125TargetLowering::ArgListEntry Entry;
3126 Entry.Node = GuardVal;
3127 Entry.Ty = FnTy->getParamType(0);
3128if (GuardCheckFn->hasParamAttribute(0, Attribute::AttrKind::InReg))
3129 Entry.IsInReg =true;
3130 Args.push_back(Entry);
3131
3132TargetLowering::CallLoweringInfo CLI(DAG);
3133 CLI.setDebugLoc(getCurSDLoc())
3134 .setChain(DAG.getEntryNode())
3135 .setCallee(GuardCheckFn->getCallingConv(), FnTy->getReturnType(),
3136getValue(GuardCheckFn), std::move(Args));
3137
3138 std::pair<SDValue, SDValue> Result = TLI.LowerCallTo(CLI);
3139DAG.setRoot(Result.second);
3140return;
3141 }
3142
3143// If useLoadStackGuardNode returns true, generate LOAD_STACK_GUARD.
3144// Otherwise, emit a volatile load to retrieve the stack guard value.
3145SDValue Chain =DAG.getEntryNode();
3146if (TLI.useLoadStackGuardNode(M)) {
3147 Guard =getLoadStackGuard(DAG, dl, Chain);
3148 }else {
3149constValue *IRGuard = TLI.getSDagStackGuard(M);
3150SDValue GuardPtr =getValue(IRGuard);
3151
3152 Guard =DAG.getLoad(PtrMemTy, dl, Chain, GuardPtr,
3153MachinePointerInfo(IRGuard, 0),Align,
3154MachineMemOperand::MOVolatile);
3155 }
3156
3157// Perform the comparison via a getsetcc.
3158SDValue Cmp =DAG.getSetCC(dl, TLI.getSetCCResultType(DAG.getDataLayout(),
3159 *DAG.getContext(),
3160 Guard.getValueType()),
3161 Guard, GuardVal,ISD::SETNE);
3162
3163// If the guard/stackslot do not equal, branch to failure MBB.
3164SDValue BrCond =DAG.getNode(ISD::BRCOND, dl,
3165 MVT::Other, GuardVal.getOperand(0),
3166 Cmp,DAG.getBasicBlock(SPD.getFailureMBB()));
3167// Otherwise branch to success MBB.
3168SDValue Br =DAG.getNode(ISD::BR, dl,
3169 MVT::Other, BrCond,
3170DAG.getBasicBlock(SPD.getSuccessMBB()));
3171
3172DAG.setRoot(Br);
3173}
3174
3175/// Codegen the failure basic block for a stack protector check.
3176///
3177/// A failure stack protector machine basic block consists simply of a call to
3178/// __stack_chk_fail().
3179///
3180/// For a high level explanation of how this fits into the stack protector
3181/// generation see the comment on the declaration of class
3182/// StackProtectorDescriptor.
3183void
3184SelectionDAGBuilder::visitSPDescriptorFailure(StackProtectorDescriptor &SPD) {
3185constTargetLowering &TLI =DAG.getTargetLoweringInfo();
3186TargetLowering::MakeLibCallOptions CallOptions;
3187 CallOptions.setDiscardResult(true);
3188SDValue Chain = TLI.makeLibCall(DAG, RTLIB::STACKPROTECTOR_CHECK_FAIL,
3189 MVT::isVoid, {}, CallOptions,getCurSDLoc())
3190 .second;
3191
3192// Emit a trap instruction if we are required to do so.
3193constTargetOptions &TargetOpts =DAG.getTarget().Options;
3194if (TargetOpts.TrapUnreachable && !TargetOpts.NoTrapAfterNoreturn)
3195 Chain =DAG.getNode(ISD::TRAP,getCurSDLoc(), MVT::Other, Chain);
3196
3197DAG.setRoot(Chain);
3198}
3199
3200/// visitBitTestHeader - This function emits necessary code to produce value
3201/// suitable for "bit tests"
3202voidSelectionDAGBuilder::visitBitTestHeader(BitTestBlock &B,
3203MachineBasicBlock *SwitchBB) {
3204SDLoc dl =getCurSDLoc();
3205
3206// Subtract the minimum value.
3207SDValue SwitchOp =getValue(B.SValue);
3208EVT VT = SwitchOp.getValueType();
3209SDValue RangeSub =
3210DAG.getNode(ISD::SUB, dl, VT, SwitchOp,DAG.getConstant(B.First, dl, VT));
3211
3212// Determine the type of the test operands.
3213constTargetLowering &TLI =DAG.getTargetLoweringInfo();
3214bool UsePtrType =false;
3215if (!TLI.isTypeLegal(VT)) {
3216 UsePtrType =true;
3217 }else {
3218for (unsigned i = 0, e =B.Cases.size(); i != e; ++i)
3219if (!isUIntN(VT.getSizeInBits(),B.Cases[i].Mask)) {
3220// Switch table case range are encoded into series of masks.
3221// Just use pointer type, it's guaranteed to fit.
3222 UsePtrType =true;
3223break;
3224 }
3225 }
3226SDValue Sub = RangeSub;
3227if (UsePtrType) {
3228 VT = TLI.getPointerTy(DAG.getDataLayout());
3229 Sub =DAG.getZExtOrTrunc(Sub, dl, VT);
3230 }
3231
3232B.RegVT = VT.getSimpleVT();
3233B.Reg =FuncInfo.CreateReg(B.RegVT);
3234SDValue CopyTo =DAG.getCopyToReg(getControlRoot(), dl,B.Reg, Sub);
3235
3236MachineBasicBlock*MBB =B.Cases[0].ThisBB;
3237
3238if (!B.FallthroughUnreachable)
3239 addSuccessorWithProb(SwitchBB,B.Default,B.DefaultProb);
3240 addSuccessorWithProb(SwitchBB,MBB,B.Prob);
3241 SwitchBB->normalizeSuccProbs();
3242
3243SDValue Root = CopyTo;
3244if (!B.FallthroughUnreachable) {
3245// Conditional branch to the default block.
3246SDValue RangeCmp =DAG.getSetCC(dl,
3247 TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(),
3248 RangeSub.getValueType()),
3249 RangeSub,DAG.getConstant(B.Range, dl, RangeSub.getValueType()),
3250ISD::SETUGT);
3251
3252 Root =DAG.getNode(ISD::BRCOND, dl, MVT::Other, Root, RangeCmp,
3253DAG.getBasicBlock(B.Default));
3254 }
3255
3256// Avoid emitting unnecessary branches to the next block.
3257if (MBB != NextBlock(SwitchBB))
3258 Root =DAG.getNode(ISD::BR, dl, MVT::Other, Root,DAG.getBasicBlock(MBB));
3259
3260DAG.setRoot(Root);
3261}
3262
3263/// visitBitTestCase - this function produces one "bit test"
3264voidSelectionDAGBuilder::visitBitTestCase(BitTestBlock &BB,
3265MachineBasicBlock *NextMBB,
3266BranchProbability BranchProbToNext,
3267Register Reg,BitTestCase &B,
3268MachineBasicBlock *SwitchBB) {
3269SDLoc dl =getCurSDLoc();
3270MVT VT = BB.RegVT;
3271SDValue ShiftOp =DAG.getCopyFromReg(getControlRoot(), dl, Reg, VT);
3272SDValue Cmp;
3273unsigned PopCount =llvm::popcount(B.Mask);
3274constTargetLowering &TLI =DAG.getTargetLoweringInfo();
3275if (PopCount == 1) {
3276// Testing for a single bit; just compare the shift count with what it
3277// would need to be to shift a 1 bit in that position.
3278 Cmp =DAG.getSetCC(
3279 dl, TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), VT),
3280 ShiftOp,DAG.getConstant(llvm::countr_zero(B.Mask), dl, VT),
3281ISD::SETEQ);
3282 }elseif (PopCount == BB.Range) {
3283// There is only one zero bit in the range, test for it directly.
3284 Cmp =DAG.getSetCC(
3285 dl, TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), VT),
3286 ShiftOp,DAG.getConstant(llvm::countr_one(B.Mask), dl, VT),ISD::SETNE);
3287 }else {
3288// Make desired shift
3289SDValue SwitchVal =DAG.getNode(ISD::SHL, dl, VT,
3290DAG.getConstant(1, dl, VT), ShiftOp);
3291
3292// Emit bit tests and jumps
3293SDValue AndOp =DAG.getNode(ISD::AND, dl,
3294 VT, SwitchVal,DAG.getConstant(B.Mask, dl, VT));
3295 Cmp =DAG.getSetCC(
3296 dl, TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), VT),
3297 AndOp,DAG.getConstant(0, dl, VT),ISD::SETNE);
3298 }
3299
3300// The branch probability from SwitchBB to B.TargetBB is B.ExtraProb.
3301 addSuccessorWithProb(SwitchBB,B.TargetBB,B.ExtraProb);
3302// The branch probability from SwitchBB to NextMBB is BranchProbToNext.
3303 addSuccessorWithProb(SwitchBB, NextMBB, BranchProbToNext);
3304// It is not guaranteed that the sum of B.ExtraProb and BranchProbToNext is
3305// one as they are relative probabilities (and thus work more like weights),
3306// and hence we need to normalize them to let the sum of them become one.
3307 SwitchBB->normalizeSuccProbs();
3308
3309SDValue BrAnd =DAG.getNode(ISD::BRCOND, dl,
3310 MVT::Other,getControlRoot(),
3311 Cmp,DAG.getBasicBlock(B.TargetBB));
3312
3313// Avoid emitting unnecessary branches to the next block.
3314if (NextMBB != NextBlock(SwitchBB))
3315 BrAnd =DAG.getNode(ISD::BR, dl, MVT::Other, BrAnd,
3316DAG.getBasicBlock(NextMBB));
3317
3318DAG.setRoot(BrAnd);
3319}
3320
3321void SelectionDAGBuilder::visitInvoke(constInvokeInst &I) {
3322MachineBasicBlock *InvokeMBB =FuncInfo.MBB;
3323
3324// Retrieve successors. Look through artificial IR level blocks like
3325// catchswitch for successors.
3326MachineBasicBlock *Return =FuncInfo.getMBB(I.getSuccessor(0));
3327constBasicBlock *EHPadBB =I.getSuccessor(1);
3328MachineBasicBlock *EHPadMBB =FuncInfo.getMBB(EHPadBB);
3329
3330// Deopt and ptrauth bundles are lowered in helper functions, and we don't
3331// have to do anything here to lower funclet bundles.
3332assert(!I.hasOperandBundlesOtherThan(
3333 {LLVMContext::OB_deopt, LLVMContext::OB_gc_transition,
3334 LLVMContext::OB_gc_live, LLVMContext::OB_funclet,
3335 LLVMContext::OB_cfguardtarget, LLVMContext::OB_ptrauth,
3336 LLVMContext::OB_clang_arc_attachedcall}) &&
3337"Cannot lower invokes with arbitrary operand bundles yet!");
3338
3339constValue *Callee(I.getCalledOperand());
3340constFunction *Fn = dyn_cast<Function>(Callee);
3341if (isa<InlineAsm>(Callee))
3342 visitInlineAsm(I, EHPadBB);
3343elseif (Fn && Fn->isIntrinsic()) {
3344switch (Fn->getIntrinsicID()) {
3345default:
3346llvm_unreachable("Cannot invoke this intrinsic");
3347case Intrinsic::donothing:
3348// Ignore invokes to @llvm.donothing: jump directly to the next BB.
3349case Intrinsic::seh_try_begin:
3350case Intrinsic::seh_scope_begin:
3351case Intrinsic::seh_try_end:
3352case Intrinsic::seh_scope_end:
3353if (EHPadMBB)
3354// a block referenced by EH table
3355// so dtor-funclet not removed by opts
3356 EHPadMBB->setMachineBlockAddressTaken();
3357break;
3358case Intrinsic::experimental_patchpoint_void:
3359case Intrinsic::experimental_patchpoint:
3360 visitPatchpoint(I, EHPadBB);
3361break;
3362case Intrinsic::experimental_gc_statepoint:
3363LowerStatepoint(cast<GCStatepointInst>(I), EHPadBB);
3364break;
3365case Intrinsic::wasm_rethrow: {
3366// This is usually done in visitTargetIntrinsic, but this intrinsic is
3367// special because it can be invoked, so we manually lower it to a DAG
3368// node here.
3369SmallVector<SDValue, 8> Ops;
3370 Ops.push_back(getControlRoot());// inchain for the terminator node
3371constTargetLowering &TLI =DAG.getTargetLoweringInfo();
3372 Ops.push_back(
3373DAG.getTargetConstant(Intrinsic::wasm_rethrow,getCurSDLoc(),
3374 TLI.getPointerTy(DAG.getDataLayout())));
3375SDVTList VTs =DAG.getVTList(ArrayRef<EVT>({MVT::Other}));// outchain
3376DAG.setRoot(DAG.getNode(ISD::INTRINSIC_VOID,getCurSDLoc(), VTs, Ops));
3377break;
3378 }
3379 }
3380 }elseif (I.hasDeoptState()) {
3381// Currently we do not lower any intrinsic calls with deopt operand bundles.
3382// Eventually we will support lowering the @llvm.experimental.deoptimize
3383// intrinsic, and right now there are no plans to support other intrinsics
3384// with deopt state.
3385LowerCallSiteWithDeoptBundle(&I,getValue(Callee), EHPadBB);
3386 }elseif (I.countOperandBundlesOfType(LLVMContext::OB_ptrauth)) {
3387LowerCallSiteWithPtrAuthBundle(cast<CallBase>(I), EHPadBB);
3388 }else {
3389LowerCallTo(I,getValue(Callee),false,false, EHPadBB);
3390 }
3391
3392// If the value of the invoke is used outside of its defining block, make it
3393// available as a virtual register.
3394// We already took care of the exported value for the statepoint instruction
3395// during call to the LowerStatepoint.
3396if (!isa<GCStatepointInst>(I)) {
3397CopyToExportRegsIfNeeded(&I);
3398 }
3399
3400SmallVector<std::pair<MachineBasicBlock *, BranchProbability>, 1> UnwindDests;
3401BranchProbabilityInfo *BPI =FuncInfo.BPI;
3402BranchProbability EHPadBBProb =
3403 BPI ? BPI->getEdgeProbability(InvokeMBB->getBasicBlock(), EHPadBB)
3404 :BranchProbability::getZero();
3405findUnwindDestinations(FuncInfo, EHPadBB, EHPadBBProb, UnwindDests);
3406
3407// Update successor info.
3408 addSuccessorWithProb(InvokeMBB, Return);
3409for (auto &UnwindDest : UnwindDests) {
3410 UnwindDest.first->setIsEHPad();
3411 addSuccessorWithProb(InvokeMBB, UnwindDest.first, UnwindDest.second);
3412 }
3413 InvokeMBB->normalizeSuccProbs();
3414
3415// Drop into normal successor.
3416DAG.setRoot(DAG.getNode(ISD::BR,getCurSDLoc(), MVT::Other,getControlRoot(),
3417DAG.getBasicBlock(Return)));
3418}
3419
3420void SelectionDAGBuilder::visitCallBr(constCallBrInst &I) {
3421MachineBasicBlock *CallBrMBB =FuncInfo.MBB;
3422
3423// Deopt bundles are lowered in LowerCallSiteWithDeoptBundle, and we don't
3424// have to do anything here to lower funclet bundles.
3425assert(!I.hasOperandBundlesOtherThan(
3426 {LLVMContext::OB_deopt, LLVMContext::OB_funclet}) &&
3427"Cannot lower callbrs with arbitrary operand bundles yet!");
3428
3429assert(I.isInlineAsm() &&"Only know how to handle inlineasm callbr");
3430 visitInlineAsm(I);
3431CopyToExportRegsIfNeeded(&I);
3432
3433// Retrieve successors.
3434SmallPtrSet<BasicBlock *, 8> Dests;
3435 Dests.insert(I.getDefaultDest());
3436MachineBasicBlock *Return =FuncInfo.getMBB(I.getDefaultDest());
3437
3438// Update successor info.
3439 addSuccessorWithProb(CallBrMBB, Return,BranchProbability::getOne());
3440for (unsigned i = 0, e =I.getNumIndirectDests(); i < e; ++i) {
3441BasicBlock *Dest =I.getIndirectDest(i);
3442MachineBasicBlock *Target =FuncInfo.getMBB(Dest);
3443Target->setIsInlineAsmBrIndirectTarget();
3444Target->setMachineBlockAddressTaken();
3445Target->setLabelMustBeEmitted();
3446// Don't add duplicate machine successors.
3447if (Dests.insert(Dest).second)
3448 addSuccessorWithProb(CallBrMBB,Target,BranchProbability::getZero());
3449 }
3450 CallBrMBB->normalizeSuccProbs();
3451
3452// Drop into default successor.
3453DAG.setRoot(DAG.getNode(ISD::BR,getCurSDLoc(),
3454 MVT::Other,getControlRoot(),
3455DAG.getBasicBlock(Return)));
3456}
3457
3458void SelectionDAGBuilder::visitResume(constResumeInst &RI) {
3459llvm_unreachable("SelectionDAGBuilder shouldn't visit resume instructions!");
3460}
3461
3462void SelectionDAGBuilder::visitLandingPad(constLandingPadInst &LP) {
3463assert(FuncInfo.MBB->isEHPad() &&
3464"Call to landingpad not in landing pad!");
3465
3466// If there aren't registers to copy the values into (e.g., during SjLj
3467// exceptions), then don't bother to create these DAG nodes.
3468constTargetLowering &TLI =DAG.getTargetLoweringInfo();
3469constConstant *PersonalityFn =FuncInfo.Fn->getPersonalityFn();
3470if (TLI.getExceptionPointerRegister(PersonalityFn) == 0 &&
3471 TLI.getExceptionSelectorRegister(PersonalityFn) == 0)
3472return;
3473
3474// If landingpad's return type is token type, we don't create DAG nodes
3475// for its exception pointer and selector value. The extraction of exception
3476// pointer or selector value from token type landingpads is not currently
3477// supported.
3478if (LP.getType()->isTokenTy())
3479return;
3480
3481SmallVector<EVT, 2> ValueVTs;
3482SDLoc dl =getCurSDLoc();
3483ComputeValueVTs(TLI,DAG.getDataLayout(), LP.getType(), ValueVTs);
3484assert(ValueVTs.size() == 2 &&"Only two-valued landingpads are supported");
3485
3486// Get the two live-in registers as SDValues. The physregs have already been
3487// copied into virtual registers.
3488SDValue Ops[2];
3489if (FuncInfo.ExceptionPointerVirtReg) {
3490 Ops[0] =DAG.getZExtOrTrunc(
3491DAG.getCopyFromReg(DAG.getEntryNode(), dl,
3492FuncInfo.ExceptionPointerVirtReg,
3493 TLI.getPointerTy(DAG.getDataLayout())),
3494 dl, ValueVTs[0]);
3495 }else {
3496 Ops[0] =DAG.getConstant(0, dl, TLI.getPointerTy(DAG.getDataLayout()));
3497 }
3498 Ops[1] =DAG.getZExtOrTrunc(
3499DAG.getCopyFromReg(DAG.getEntryNode(), dl,
3500FuncInfo.ExceptionSelectorVirtReg,
3501 TLI.getPointerTy(DAG.getDataLayout())),
3502 dl, ValueVTs[1]);
3503
3504// Merge into one.
3505SDValue Res =DAG.getNode(ISD::MERGE_VALUES, dl,
3506DAG.getVTList(ValueVTs), Ops);
3507setValue(&LP, Res);
3508}
3509
3510voidSelectionDAGBuilder::UpdateSplitBlock(MachineBasicBlock *First,
3511MachineBasicBlock *Last) {
3512// Update JTCases.
3513for (JumpTableBlock &JTB :SL->JTCases)
3514if (JTB.first.HeaderBB ==First)
3515 JTB.first.HeaderBB =Last;
3516
3517// Update BitTestCases.
3518for (BitTestBlock &BTB :SL->BitTestCases)
3519if (BTB.Parent ==First)
3520 BTB.Parent =Last;
3521}
3522
3523void SelectionDAGBuilder::visitIndirectBr(constIndirectBrInst &I) {
3524MachineBasicBlock *IndirectBrMBB =FuncInfo.MBB;
3525
3526// Update machine-CFG edges with unique successors.
3527SmallSet<BasicBlock*, 32>Done;
3528for (unsigned i = 0, e =I.getNumSuccessors(); i != e; ++i) {
3529BasicBlock *BB =I.getSuccessor(i);
3530bool Inserted =Done.insert(BB).second;
3531if (!Inserted)
3532continue;
3533
3534MachineBasicBlock *Succ =FuncInfo.getMBB(BB);
3535 addSuccessorWithProb(IndirectBrMBB, Succ);
3536 }
3537 IndirectBrMBB->normalizeSuccProbs();
3538
3539DAG.setRoot(DAG.getNode(ISD::BRIND,getCurSDLoc(),
3540 MVT::Other,getControlRoot(),
3541getValue(I.getAddress())));
3542}
3543
3544void SelectionDAGBuilder::visitUnreachable(constUnreachableInst &I) {
3545if (!DAG.getTarget().Options.TrapUnreachable)
3546return;
3547
3548// We may be able to ignore unreachable behind a noreturn call.
3549if (constCallInst *Call = dyn_cast_or_null<CallInst>(I.getPrevNode());
3550 Call &&Call->doesNotReturn()) {
3551if (DAG.getTarget().Options.NoTrapAfterNoreturn)
3552return;
3553// Do not emit an additional trap instruction.
3554if (Call->isNonContinuableTrap())
3555return;
3556 }
3557
3558DAG.setRoot(DAG.getNode(ISD::TRAP,getCurSDLoc(), MVT::Other,DAG.getRoot()));
3559}
3560
3561void SelectionDAGBuilder::visitUnary(constUser &I,unsigned Opcode) {
3562SDNodeFlagsFlags;
3563if (auto *FPOp = dyn_cast<FPMathOperator>(&I))
3564Flags.copyFMF(*FPOp);
3565
3566SDValueOp =getValue(I.getOperand(0));
3567SDValue UnNodeValue =DAG.getNode(Opcode,getCurSDLoc(),Op.getValueType(),
3568Op, Flags);
3569setValue(&I, UnNodeValue);
3570}
3571
3572void SelectionDAGBuilder::visitBinary(constUser &I,unsigned Opcode) {
3573SDNodeFlagsFlags;
3574if (auto *OFBinOp = dyn_cast<OverflowingBinaryOperator>(&I)) {
3575Flags.setNoSignedWrap(OFBinOp->hasNoSignedWrap());
3576Flags.setNoUnsignedWrap(OFBinOp->hasNoUnsignedWrap());
3577 }
3578if (auto *ExactOp = dyn_cast<PossiblyExactOperator>(&I))
3579Flags.setExact(ExactOp->isExact());
3580if (auto *DisjointOp = dyn_cast<PossiblyDisjointInst>(&I))
3581Flags.setDisjoint(DisjointOp->isDisjoint());
3582if (auto *FPOp = dyn_cast<FPMathOperator>(&I))
3583Flags.copyFMF(*FPOp);
3584
3585SDValue Op1 =getValue(I.getOperand(0));
3586SDValue Op2 =getValue(I.getOperand(1));
3587SDValue BinNodeValue =DAG.getNode(Opcode,getCurSDLoc(), Op1.getValueType(),
3588 Op1, Op2, Flags);
3589setValue(&I, BinNodeValue);
3590}
3591
3592void SelectionDAGBuilder::visitShift(constUser &I,unsigned Opcode) {
3593SDValue Op1 =getValue(I.getOperand(0));
3594SDValue Op2 =getValue(I.getOperand(1));
3595
3596EVT ShiftTy =DAG.getTargetLoweringInfo().getShiftAmountTy(
3597 Op1.getValueType(),DAG.getDataLayout());
3598
3599// Coerce the shift amount to the right type if we can. This exposes the
3600// truncate or zext to optimization early.
3601if (!I.getType()->isVectorTy() && Op2.getValueType() != ShiftTy) {
3602assert(ShiftTy.getSizeInBits() >=Log2_32_Ceil(Op1.getValueSizeInBits()) &&
3603"Unexpected shift type");
3604 Op2 =DAG.getZExtOrTrunc(Op2,getCurSDLoc(), ShiftTy);
3605 }
3606
3607bool nuw =false;
3608bool nsw =false;
3609bool exact =false;
3610
3611if (Opcode ==ISD::SRL || Opcode ==ISD::SRA || Opcode ==ISD::SHL) {
3612
3613if (constOverflowingBinaryOperator *OFBinOp =
3614 dyn_cast<const OverflowingBinaryOperator>(&I)) {
3615 nuw = OFBinOp->hasNoUnsignedWrap();
3616 nsw = OFBinOp->hasNoSignedWrap();
3617 }
3618if (constPossiblyExactOperator *ExactOp =
3619 dyn_cast<const PossiblyExactOperator>(&I))
3620 exact = ExactOp->isExact();
3621 }
3622SDNodeFlagsFlags;
3623Flags.setExact(exact);
3624Flags.setNoSignedWrap(nsw);
3625Flags.setNoUnsignedWrap(nuw);
3626SDValue Res =DAG.getNode(Opcode,getCurSDLoc(), Op1.getValueType(), Op1, Op2,
3627 Flags);
3628setValue(&I, Res);
3629}
3630
3631void SelectionDAGBuilder::visitSDiv(constUser &I) {
3632SDValue Op1 =getValue(I.getOperand(0));
3633SDValue Op2 =getValue(I.getOperand(1));
3634
3635SDNodeFlagsFlags;
3636Flags.setExact(isa<PossiblyExactOperator>(&I) &&
3637 cast<PossiblyExactOperator>(&I)->isExact());
3638setValue(&I,DAG.getNode(ISD::SDIV,getCurSDLoc(), Op1.getValueType(), Op1,
3639 Op2, Flags));
3640}
3641
3642void SelectionDAGBuilder::visitICmp(constICmpInst &I) {
3643ICmpInst::Predicate predicate =I.getPredicate();
3644SDValue Op1 =getValue(I.getOperand(0));
3645SDValue Op2 =getValue(I.getOperand(1));
3646ISD::CondCode Opcode =getICmpCondCode(predicate);
3647
3648auto &TLI =DAG.getTargetLoweringInfo();
3649EVT MemVT =
3650 TLI.getMemValueType(DAG.getDataLayout(),I.getOperand(0)->getType());
3651
3652// If a pointer's DAG type is larger than its memory type then the DAG values
3653// are zero-extended. This breaks signed comparisons so truncate back to the
3654// underlying type before doing the compare.
3655if (Op1.getValueType() != MemVT) {
3656 Op1 =DAG.getPtrExtOrTrunc(Op1,getCurSDLoc(), MemVT);
3657 Op2 =DAG.getPtrExtOrTrunc(Op2,getCurSDLoc(), MemVT);
3658 }
3659
3660SDNodeFlagsFlags;
3661Flags.setSameSign(I.hasSameSign());
3662SelectionDAG::FlagInserter FlagsInserter(DAG, Flags);
3663
3664EVT DestVT =DAG.getTargetLoweringInfo().getValueType(DAG.getDataLayout(),
3665I.getType());
3666setValue(&I,DAG.getSetCC(getCurSDLoc(), DestVT, Op1, Op2, Opcode));
3667}
3668
3669void SelectionDAGBuilder::visitFCmp(constFCmpInst &I) {
3670FCmpInst::Predicate predicate =I.getPredicate();
3671SDValue Op1 =getValue(I.getOperand(0));
3672SDValue Op2 =getValue(I.getOperand(1));
3673
3674ISD::CondCode Condition =getFCmpCondCode(predicate);
3675auto *FPMO = cast<FPMathOperator>(&I);
3676if (FPMO->hasNoNaNs() || TM.Options.NoNaNsFPMath)
3677 Condition =getFCmpCodeWithoutNaN(Condition);
3678
3679SDNodeFlagsFlags;
3680Flags.copyFMF(*FPMO);
3681SelectionDAG::FlagInserter FlagsInserter(DAG, Flags);
3682
3683EVT DestVT =DAG.getTargetLoweringInfo().getValueType(DAG.getDataLayout(),
3684I.getType());
3685setValue(&I,DAG.getSetCC(getCurSDLoc(), DestVT, Op1, Op2, Condition));
3686}
3687
3688// Check if the condition of the select has one use or two users that are both
3689// selects with the same condition.
3690staticboolhasOnlySelectUsers(constValue *Cond) {
3691returnllvm::all_of(Cond->users(), [](constValue *V) {
3692 return isa<SelectInst>(V);
3693 });
3694}
3695
3696void SelectionDAGBuilder::visitSelect(constUser &I) {
3697SmallVector<EVT, 4> ValueVTs;
3698ComputeValueVTs(DAG.getTargetLoweringInfo(),DAG.getDataLayout(),I.getType(),
3699 ValueVTs);
3700unsigned NumValues = ValueVTs.size();
3701if (NumValues == 0)return;
3702
3703SmallVector<SDValue, 4> Values(NumValues);
3704SDValueCond =getValue(I.getOperand(0));
3705SDValue LHSVal =getValue(I.getOperand(1));
3706SDValue RHSVal =getValue(I.getOperand(2));
3707SmallVector<SDValue, 1> BaseOps(1,Cond);
3708ISD::NodeTypeOpCode =
3709Cond.getValueType().isVector() ?ISD::VSELECT :ISD::SELECT;
3710
3711bool IsUnaryAbs =false;
3712bool Negate =false;
3713
3714SDNodeFlagsFlags;
3715if (auto *FPOp = dyn_cast<FPMathOperator>(&I))
3716Flags.copyFMF(*FPOp);
3717
3718Flags.setUnpredictable(
3719 cast<SelectInst>(I).getMetadata(LLVMContext::MD_unpredictable));
3720
3721// Min/max matching is only viable if all output VTs are the same.
3722if (all_equal(ValueVTs)) {
3723EVT VT = ValueVTs[0];
3724LLVMContext &Ctx = *DAG.getContext();
3725auto &TLI =DAG.getTargetLoweringInfo();
3726
3727// We care about the legality of the operation after it has been type
3728// legalized.
3729while (TLI.getTypeAction(Ctx, VT) !=TargetLoweringBase::TypeLegal)
3730 VT = TLI.getTypeToTransformTo(Ctx, VT);
3731
3732// If the vselect is legal, assume we want to leave this as a vector setcc +
3733// vselect. Otherwise, if this is going to be scalarized, we want to see if
3734// min/max is legal on the scalar type.
3735bool UseScalarMinMax = VT.isVector() &&
3736 !TLI.isOperationLegalOrCustom(ISD::VSELECT, VT);
3737
3738// ValueTracking's select pattern matching does not account for -0.0,
3739// so we can't lower to FMINIMUM/FMAXIMUM because those nodes specify that
3740// -0.0 is less than +0.0.
3741constValue *LHS, *RHS;
3742auto SPR =matchSelectPattern(&I, LHS, RHS);
3743ISD::NodeType Opc =ISD::DELETED_NODE;
3744switch (SPR.Flavor) {
3745caseSPF_UMAX: Opc =ISD::UMAX;break;
3746caseSPF_UMIN: Opc =ISD::UMIN;break;
3747caseSPF_SMAX: Opc =ISD::SMAX;break;
3748caseSPF_SMIN: Opc =ISD::SMIN;break;
3749caseSPF_FMINNUM:
3750switch (SPR.NaNBehavior) {
3751caseSPNB_NA:llvm_unreachable("No NaN behavior for FP op?");
3752caseSPNB_RETURNS_NAN:break;
3753caseSPNB_RETURNS_OTHER: Opc =ISD::FMINNUM;break;
3754caseSPNB_RETURNS_ANY:
3755if (TLI.isOperationLegalOrCustom(ISD::FMINNUM, VT) ||
3756 (UseScalarMinMax &&
3757 TLI.isOperationLegalOrCustom(ISD::FMINNUM, VT.getScalarType())))
3758 Opc =ISD::FMINNUM;
3759break;
3760 }
3761break;
3762caseSPF_FMAXNUM:
3763switch (SPR.NaNBehavior) {
3764caseSPNB_NA:llvm_unreachable("No NaN behavior for FP op?");
3765caseSPNB_RETURNS_NAN:break;
3766caseSPNB_RETURNS_OTHER: Opc =ISD::FMAXNUM;break;
3767caseSPNB_RETURNS_ANY:
3768if (TLI.isOperationLegalOrCustom(ISD::FMAXNUM, VT) ||
3769 (UseScalarMinMax &&
3770 TLI.isOperationLegalOrCustom(ISD::FMAXNUM, VT.getScalarType())))
3771 Opc =ISD::FMAXNUM;
3772break;
3773 }
3774break;
3775caseSPF_NABS:
3776 Negate =true;
3777 [[fallthrough]];
3778caseSPF_ABS:
3779 IsUnaryAbs =true;
3780 Opc =ISD::ABS;
3781break;
3782default:break;
3783 }
3784
3785if (!IsUnaryAbs && Opc !=ISD::DELETED_NODE &&
3786 (TLI.isOperationLegalOrCustom(Opc, VT) ||
3787 (UseScalarMinMax &&
3788 TLI.isOperationLegalOrCustom(Opc, VT.getScalarType()))) &&
3789// If the underlying comparison instruction is used by any other
3790// instruction, the consumed instructions won't be destroyed, so it is
3791// not profitable to convert to a min/max.
3792hasOnlySelectUsers(cast<SelectInst>(I).getCondition())) {
3793OpCode = Opc;
3794 LHSVal =getValue(LHS);
3795 RHSVal =getValue(RHS);
3796 BaseOps.clear();
3797 }
3798
3799if (IsUnaryAbs) {
3800OpCode = Opc;
3801 LHSVal =getValue(LHS);
3802 BaseOps.clear();
3803 }
3804 }
3805
3806if (IsUnaryAbs) {
3807for (unsigned i = 0; i != NumValues; ++i) {
3808SDLoc dl =getCurSDLoc();
3809EVT VT = LHSVal.getNode()->getValueType(LHSVal.getResNo() + i);
3810 Values[i] =
3811DAG.getNode(OpCode, dl, VT, LHSVal.getValue(LHSVal.getResNo() + i));
3812if (Negate)
3813 Values[i] =DAG.getNegative(Values[i], dl, VT);
3814 }
3815 }else {
3816for (unsigned i = 0; i != NumValues; ++i) {
3817SmallVector<SDValue, 3> Ops(BaseOps.begin(), BaseOps.end());
3818 Ops.push_back(SDValue(LHSVal.getNode(), LHSVal.getResNo() + i));
3819 Ops.push_back(SDValue(RHSVal.getNode(), RHSVal.getResNo() + i));
3820 Values[i] =DAG.getNode(
3821 OpCode,getCurSDLoc(),
3822 LHSVal.getNode()->getValueType(LHSVal.getResNo() + i), Ops, Flags);
3823 }
3824 }
3825
3826setValue(&I,DAG.getNode(ISD::MERGE_VALUES,getCurSDLoc(),
3827DAG.getVTList(ValueVTs), Values));
3828}
3829
3830void SelectionDAGBuilder::visitTrunc(constUser &I) {
3831// TruncInst cannot be a no-op cast because sizeof(src) > sizeof(dest).
3832SDValueN =getValue(I.getOperand(0));
3833EVT DestVT =DAG.getTargetLoweringInfo().getValueType(DAG.getDataLayout(),
3834I.getType());
3835SDNodeFlagsFlags;
3836if (auto *Trunc = dyn_cast<TruncInst>(&I)) {
3837Flags.setNoSignedWrap(Trunc->hasNoSignedWrap());
3838Flags.setNoUnsignedWrap(Trunc->hasNoUnsignedWrap());
3839 }
3840
3841setValue(&I,DAG.getNode(ISD::TRUNCATE,getCurSDLoc(), DestVT,N, Flags));
3842}
3843
3844void SelectionDAGBuilder::visitZExt(constUser &I) {
3845// ZExt cannot be a no-op cast because sizeof(src) < sizeof(dest).
3846// ZExt also can't be a cast to bool for same reason. So, nothing much to do
3847SDValueN =getValue(I.getOperand(0));
3848auto &TLI =DAG.getTargetLoweringInfo();
3849EVT DestVT = TLI.getValueType(DAG.getDataLayout(),I.getType());
3850
3851SDNodeFlagsFlags;
3852if (auto *PNI = dyn_cast<PossiblyNonNegInst>(&I))
3853Flags.setNonNeg(PNI->hasNonNeg());
3854
3855// Eagerly use nonneg information to canonicalize towards sign_extend if
3856// that is the target's preference.
3857// TODO: Let the target do this later.
3858if (Flags.hasNonNeg() &&
3859 TLI.isSExtCheaperThanZExt(N.getValueType(), DestVT)) {
3860setValue(&I,DAG.getNode(ISD::SIGN_EXTEND,getCurSDLoc(), DestVT,N));
3861return;
3862 }
3863
3864setValue(&I,DAG.getNode(ISD::ZERO_EXTEND,getCurSDLoc(), DestVT,N, Flags));
3865}
3866
3867void SelectionDAGBuilder::visitSExt(constUser &I) {
3868// SExt cannot be a no-op cast because sizeof(src) < sizeof(dest).
3869// SExt also can't be a cast to bool for same reason. So, nothing much to do
3870SDValueN =getValue(I.getOperand(0));
3871EVT DestVT =DAG.getTargetLoweringInfo().getValueType(DAG.getDataLayout(),
3872I.getType());
3873setValue(&I,DAG.getNode(ISD::SIGN_EXTEND,getCurSDLoc(), DestVT,N));
3874}
3875
3876void SelectionDAGBuilder::visitFPTrunc(constUser &I) {
3877// FPTrunc is never a no-op cast, no need to check
3878SDValueN =getValue(I.getOperand(0));
3879SDLoc dl =getCurSDLoc();
3880constTargetLowering &TLI =DAG.getTargetLoweringInfo();
3881EVT DestVT = TLI.getValueType(DAG.getDataLayout(),I.getType());
3882setValue(&I,DAG.getNode(ISD::FP_ROUND, dl, DestVT,N,
3883DAG.getTargetConstant(
3884 0, dl, TLI.getPointerTy(DAG.getDataLayout()))));
3885}
3886
3887void SelectionDAGBuilder::visitFPExt(constUser &I) {
3888// FPExt is never a no-op cast, no need to check
3889SDValueN =getValue(I.getOperand(0));
3890EVT DestVT =DAG.getTargetLoweringInfo().getValueType(DAG.getDataLayout(),
3891I.getType());
3892setValue(&I,DAG.getNode(ISD::FP_EXTEND,getCurSDLoc(), DestVT,N));
3893}
3894
3895void SelectionDAGBuilder::visitFPToUI(constUser &I) {
3896// FPToUI is never a no-op cast, no need to check
3897SDValueN =getValue(I.getOperand(0));
3898EVT DestVT =DAG.getTargetLoweringInfo().getValueType(DAG.getDataLayout(),
3899I.getType());
3900setValue(&I,DAG.getNode(ISD::FP_TO_UINT,getCurSDLoc(), DestVT,N));
3901}
3902
3903void SelectionDAGBuilder::visitFPToSI(constUser &I) {
3904// FPToSI is never a no-op cast, no need to check
3905SDValueN =getValue(I.getOperand(0));
3906EVT DestVT =DAG.getTargetLoweringInfo().getValueType(DAG.getDataLayout(),
3907I.getType());
3908setValue(&I,DAG.getNode(ISD::FP_TO_SINT,getCurSDLoc(), DestVT,N));
3909}
3910
3911void SelectionDAGBuilder::visitUIToFP(constUser &I) {
3912// UIToFP is never a no-op cast, no need to check
3913SDValueN =getValue(I.getOperand(0));
3914EVT DestVT =DAG.getTargetLoweringInfo().getValueType(DAG.getDataLayout(),
3915I.getType());
3916SDNodeFlagsFlags;
3917if (auto *PNI = dyn_cast<PossiblyNonNegInst>(&I))
3918Flags.setNonNeg(PNI->hasNonNeg());
3919
3920setValue(&I,DAG.getNode(ISD::UINT_TO_FP,getCurSDLoc(), DestVT,N, Flags));
3921}
3922
3923void SelectionDAGBuilder::visitSIToFP(constUser &I) {
3924// SIToFP is never a no-op cast, no need to check
3925SDValueN =getValue(I.getOperand(0));
3926EVT DestVT =DAG.getTargetLoweringInfo().getValueType(DAG.getDataLayout(),
3927I.getType());
3928setValue(&I,DAG.getNode(ISD::SINT_TO_FP,getCurSDLoc(), DestVT,N));
3929}
3930
3931void SelectionDAGBuilder::visitPtrToInt(constUser &I) {
3932// What to do depends on the size of the integer and the size of the pointer.
3933// We can either truncate, zero extend, or no-op, accordingly.
3934SDValueN =getValue(I.getOperand(0));
3935auto &TLI =DAG.getTargetLoweringInfo();
3936EVT DestVT =DAG.getTargetLoweringInfo().getValueType(DAG.getDataLayout(),
3937I.getType());
3938EVT PtrMemVT =
3939 TLI.getMemValueType(DAG.getDataLayout(),I.getOperand(0)->getType());
3940N =DAG.getPtrExtOrTrunc(N,getCurSDLoc(), PtrMemVT);
3941N =DAG.getZExtOrTrunc(N,getCurSDLoc(), DestVT);
3942setValue(&I,N);
3943}
3944
3945void SelectionDAGBuilder::visitIntToPtr(constUser &I) {
3946// What to do depends on the size of the integer and the size of the pointer.
3947// We can either truncate, zero extend, or no-op, accordingly.
3948SDValueN =getValue(I.getOperand(0));
3949auto &TLI =DAG.getTargetLoweringInfo();
3950EVT DestVT = TLI.getValueType(DAG.getDataLayout(),I.getType());
3951EVT PtrMemVT = TLI.getMemValueType(DAG.getDataLayout(),I.getType());
3952N =DAG.getZExtOrTrunc(N,getCurSDLoc(), PtrMemVT);
3953N =DAG.getPtrExtOrTrunc(N,getCurSDLoc(), DestVT);
3954setValue(&I,N);
3955}
3956
3957void SelectionDAGBuilder::visitBitCast(constUser &I) {
3958SDValueN =getValue(I.getOperand(0));
3959SDLoc dl =getCurSDLoc();
3960EVT DestVT =DAG.getTargetLoweringInfo().getValueType(DAG.getDataLayout(),
3961I.getType());
3962
3963// BitCast assures us that source and destination are the same size so this is
3964// either a BITCAST or a no-op.
3965if (DestVT !=N.getValueType())
3966setValue(&I,DAG.getNode(ISD::BITCAST, dl,
3967 DestVT,N));// convert types.
3968// Check if the original LLVM IR Operand was a ConstantInt, because getValue()
3969// might fold any kind of constant expression to an integer constant and that
3970// is not what we are looking for. Only recognize a bitcast of a genuine
3971// constant integer as an opaque constant.
3972elseif(ConstantInt *C = dyn_cast<ConstantInt>(I.getOperand(0)))
3973setValue(&I,DAG.getConstant(C->getValue(), dl, DestVT,/*isTarget=*/false,
3974/*isOpaque*/true));
3975else
3976setValue(&I,N);// noop cast.
3977}
3978
3979void SelectionDAGBuilder::visitAddrSpaceCast(constUser &I) {
3980constTargetLowering &TLI =DAG.getTargetLoweringInfo();
3981constValue *SV =I.getOperand(0);
3982SDValueN =getValue(SV);
3983EVT DestVT = TLI.getValueType(DAG.getDataLayout(),I.getType());
3984
3985unsigned SrcAS = SV->getType()->getPointerAddressSpace();
3986unsigned DestAS =I.getType()->getPointerAddressSpace();
3987
3988if (!TM.isNoopAddrSpaceCast(SrcAS, DestAS))
3989N =DAG.getAddrSpaceCast(getCurSDLoc(), DestVT,N, SrcAS, DestAS);
3990
3991setValue(&I,N);
3992}
3993
3994void SelectionDAGBuilder::visitInsertElement(constUser &I) {
3995constTargetLowering &TLI =DAG.getTargetLoweringInfo();
3996SDValue InVec =getValue(I.getOperand(0));
3997SDValue InVal =getValue(I.getOperand(1));
3998SDValue InIdx =DAG.getZExtOrTrunc(getValue(I.getOperand(2)),getCurSDLoc(),
3999 TLI.getVectorIdxTy(DAG.getDataLayout()));
4000setValue(&I,DAG.getNode(ISD::INSERT_VECTOR_ELT,getCurSDLoc(),
4001 TLI.getValueType(DAG.getDataLayout(),I.getType()),
4002 InVec, InVal, InIdx));
4003}
4004
4005void SelectionDAGBuilder::visitExtractElement(constUser &I) {
4006constTargetLowering &TLI =DAG.getTargetLoweringInfo();
4007SDValue InVec =getValue(I.getOperand(0));
4008SDValue InIdx =DAG.getZExtOrTrunc(getValue(I.getOperand(1)),getCurSDLoc(),
4009 TLI.getVectorIdxTy(DAG.getDataLayout()));
4010setValue(&I,DAG.getNode(ISD::EXTRACT_VECTOR_ELT,getCurSDLoc(),
4011 TLI.getValueType(DAG.getDataLayout(),I.getType()),
4012 InVec, InIdx));
4013}
4014
4015void SelectionDAGBuilder::visitShuffleVector(constUser &I) {
4016SDValue Src1 =getValue(I.getOperand(0));
4017SDValue Src2 =getValue(I.getOperand(1));
4018ArrayRef<int>Mask;
4019if (auto *SVI = dyn_cast<ShuffleVectorInst>(&I))
4020Mask = SVI->getShuffleMask();
4021else
4022Mask = cast<ConstantExpr>(I).getShuffleMask();
4023SDLocDL =getCurSDLoc();
4024constTargetLowering &TLI =DAG.getTargetLoweringInfo();
4025EVT VT = TLI.getValueType(DAG.getDataLayout(),I.getType());
4026EVT SrcVT = Src1.getValueType();
4027
4028if (all_of(Mask, [](int Elem) {return Elem == 0; }) &&
4029 VT.isScalableVector()) {
4030// Canonical splat form of first element of first input vector.
4031SDValue FirstElt =
4032DAG.getNode(ISD::EXTRACT_VECTOR_ELT,DL, SrcVT.getScalarType(), Src1,
4033DAG.getVectorIdxConstant(0,DL));
4034setValue(&I,DAG.getNode(ISD::SPLAT_VECTOR,DL, VT, FirstElt));
4035return;
4036 }
4037
4038// For now, we only handle splats for scalable vectors.
4039// The DAGCombiner will perform a BUILD_VECTOR -> SPLAT_VECTOR transformation
4040// for targets that support a SPLAT_VECTOR for non-scalable vector types.
4041assert(!VT.isScalableVector() &&"Unsupported scalable vector shuffle");
4042
4043unsigned SrcNumElts = SrcVT.getVectorNumElements();
4044unsigned MaskNumElts =Mask.size();
4045
4046if (SrcNumElts == MaskNumElts) {
4047setValue(&I,DAG.getVectorShuffle(VT,DL, Src1, Src2, Mask));
4048return;
4049 }
4050
4051// Normalize the shuffle vector since mask and vector length don't match.
4052if (SrcNumElts < MaskNumElts) {
4053// Mask is longer than the source vectors. We can use concatenate vector to
4054// make the mask and vectors lengths match.
4055
4056if (MaskNumElts % SrcNumElts == 0) {
4057// Mask length is a multiple of the source vector length.
4058// Check if the shuffle is some kind of concatenation of the input
4059// vectors.
4060unsigned NumConcat = MaskNumElts / SrcNumElts;
4061bool IsConcat =true;
4062SmallVector<int, 8> ConcatSrcs(NumConcat, -1);
4063for (unsigned i = 0; i != MaskNumElts; ++i) {
4064intIdx =Mask[i];
4065if (Idx < 0)
4066continue;
4067// Ensure the indices in each SrcVT sized piece are sequential and that
4068// the same source is used for the whole piece.
4069if ((Idx % SrcNumElts != (i % SrcNumElts)) ||
4070 (ConcatSrcs[i / SrcNumElts] >= 0 &&
4071 ConcatSrcs[i / SrcNumElts] != (int)(Idx / SrcNumElts))) {
4072 IsConcat =false;
4073break;
4074 }
4075// Remember which source this index came from.
4076 ConcatSrcs[i / SrcNumElts] =Idx / SrcNumElts;
4077 }
4078
4079// The shuffle is concatenating multiple vectors together. Just emit
4080// a CONCAT_VECTORS operation.
4081if (IsConcat) {
4082SmallVector<SDValue, 8> ConcatOps;
4083for (auto Src : ConcatSrcs) {
4084if (Src < 0)
4085 ConcatOps.push_back(DAG.getUNDEF(SrcVT));
4086elseif (Src == 0)
4087 ConcatOps.push_back(Src1);
4088else
4089 ConcatOps.push_back(Src2);
4090 }
4091setValue(&I,DAG.getNode(ISD::CONCAT_VECTORS,DL, VT, ConcatOps));
4092return;
4093 }
4094 }
4095
4096unsigned PaddedMaskNumElts =alignTo(MaskNumElts, SrcNumElts);
4097unsigned NumConcat = PaddedMaskNumElts / SrcNumElts;
4098EVT PaddedVT =EVT::getVectorVT(*DAG.getContext(), VT.getScalarType(),
4099 PaddedMaskNumElts);
4100
4101// Pad both vectors with undefs to make them the same length as the mask.
4102SDValue UndefVal =DAG.getUNDEF(SrcVT);
4103
4104SmallVector<SDValue, 8> MOps1(NumConcat, UndefVal);
4105SmallVector<SDValue, 8> MOps2(NumConcat, UndefVal);
4106 MOps1[0] = Src1;
4107 MOps2[0] = Src2;
4108
4109 Src1 =DAG.getNode(ISD::CONCAT_VECTORS,DL, PaddedVT, MOps1);
4110 Src2 =DAG.getNode(ISD::CONCAT_VECTORS,DL, PaddedVT, MOps2);
4111
4112// Readjust mask for new input vector length.
4113SmallVector<int, 8> MappedOps(PaddedMaskNumElts, -1);
4114for (unsigned i = 0; i != MaskNumElts; ++i) {
4115intIdx =Mask[i];
4116if (Idx >= (int)SrcNumElts)
4117Idx -= SrcNumElts - PaddedMaskNumElts;
4118 MappedOps[i] =Idx;
4119 }
4120
4121SDValueResult =DAG.getVectorShuffle(PaddedVT,DL, Src1, Src2, MappedOps);
4122
4123// If the concatenated vector was padded, extract a subvector with the
4124// correct number of elements.
4125if (MaskNumElts != PaddedMaskNumElts)
4126Result =DAG.getNode(ISD::EXTRACT_SUBVECTOR,DL, VT, Result,
4127DAG.getVectorIdxConstant(0,DL));
4128
4129setValue(&I, Result);
4130return;
4131 }
4132
4133assert(SrcNumElts > MaskNumElts);
4134
4135// Analyze the access pattern of the vector to see if we can extract
4136// two subvectors and do the shuffle.
4137int StartIdx[2] = {-1, -1};// StartIdx to extract from
4138bool CanExtract =true;
4139for (intIdx : Mask) {
4140unsigned Input = 0;
4141if (Idx < 0)
4142continue;
4143
4144if (Idx >= (int)SrcNumElts) {
4145 Input = 1;
4146Idx -= SrcNumElts;
4147 }
4148
4149// If all the indices come from the same MaskNumElts sized portion of
4150// the sources we can use extract. Also make sure the extract wouldn't
4151// extract past the end of the source.
4152int NewStartIdx =alignDown(Idx, MaskNumElts);
4153if (NewStartIdx + MaskNumElts > SrcNumElts ||
4154 (StartIdx[Input] >= 0 && StartIdx[Input] != NewStartIdx))
4155 CanExtract =false;
4156// Make sure we always update StartIdx as we use it to track if all
4157// elements are undef.
4158 StartIdx[Input] = NewStartIdx;
4159 }
4160
4161if (StartIdx[0] < 0 && StartIdx[1] < 0) {
4162setValue(&I,DAG.getUNDEF(VT));// Vectors are not used.
4163return;
4164 }
4165if (CanExtract) {
4166// Extract appropriate subvector and generate a vector shuffle
4167for (unsigned Input = 0; Input < 2; ++Input) {
4168SDValue &Src = Input == 0 ? Src1 : Src2;
4169if (StartIdx[Input] < 0)
4170 Src =DAG.getUNDEF(VT);
4171else {
4172 Src =DAG.getNode(ISD::EXTRACT_SUBVECTOR,DL, VT, Src,
4173DAG.getVectorIdxConstant(StartIdx[Input],DL));
4174 }
4175 }
4176
4177// Calculate new mask.
4178SmallVector<int, 8> MappedOps(Mask);
4179for (int &Idx : MappedOps) {
4180if (Idx >= (int)SrcNumElts)
4181Idx -= SrcNumElts + StartIdx[1] - MaskNumElts;
4182elseif (Idx >= 0)
4183Idx -= StartIdx[0];
4184 }
4185
4186setValue(&I,DAG.getVectorShuffle(VT,DL, Src1, Src2, MappedOps));
4187return;
4188 }
4189
4190// We can't use either concat vectors or extract subvectors so fall back to
4191// replacing the shuffle with extract and build vector.
4192// to insert and build vector.
4193EVT EltVT = VT.getVectorElementType();
4194SmallVector<SDValue,8> Ops;
4195for (intIdx : Mask) {
4196SDValue Res;
4197
4198if (Idx < 0) {
4199 Res =DAG.getUNDEF(EltVT);
4200 }else {
4201SDValue &Src =Idx < (int)SrcNumElts ? Src1 : Src2;
4202if (Idx >= (int)SrcNumElts)Idx -= SrcNumElts;
4203
4204 Res =DAG.getNode(ISD::EXTRACT_VECTOR_ELT,DL, EltVT, Src,
4205DAG.getVectorIdxConstant(Idx,DL));
4206 }
4207
4208 Ops.push_back(Res);
4209 }
4210
4211setValue(&I,DAG.getBuildVector(VT,DL, Ops));
4212}
4213
4214void SelectionDAGBuilder::visitInsertValue(constInsertValueInst &I) {
4215ArrayRef<unsigned> Indices =I.getIndices();
4216constValue *Op0 =I.getOperand(0);
4217constValue *Op1 =I.getOperand(1);
4218Type *AggTy =I.getType();
4219Type *ValTy = Op1->getType();
4220bool IntoUndef = isa<UndefValue>(Op0);
4221bool FromUndef = isa<UndefValue>(Op1);
4222
4223unsigned LinearIndex =ComputeLinearIndex(AggTy, Indices);
4224
4225constTargetLowering &TLI =DAG.getTargetLoweringInfo();
4226SmallVector<EVT, 4> AggValueVTs;
4227ComputeValueVTs(TLI,DAG.getDataLayout(), AggTy, AggValueVTs);
4228SmallVector<EVT, 4> ValValueVTs;
4229ComputeValueVTs(TLI,DAG.getDataLayout(), ValTy, ValValueVTs);
4230
4231unsigned NumAggValues = AggValueVTs.size();
4232unsigned NumValValues = ValValueVTs.size();
4233SmallVector<SDValue, 4> Values(NumAggValues);
4234
4235// Ignore an insertvalue that produces an empty object
4236if (!NumAggValues) {
4237setValue(&I,DAG.getUNDEF(MVT(MVT::Other)));
4238return;
4239 }
4240
4241SDValue Agg =getValue(Op0);
4242unsigned i = 0;
4243// Copy the beginning value(s) from the original aggregate.
4244for (; i != LinearIndex; ++i)
4245 Values[i] = IntoUndef ?DAG.getUNDEF(AggValueVTs[i]) :
4246SDValue(Agg.getNode(), Agg.getResNo() + i);
4247// Copy values from the inserted value(s).
4248if (NumValValues) {
4249SDValue Val =getValue(Op1);
4250for (; i != LinearIndex + NumValValues; ++i)
4251 Values[i] = FromUndef ?DAG.getUNDEF(AggValueVTs[i]) :
4252SDValue(Val.getNode(), Val.getResNo() + i - LinearIndex);
4253 }
4254// Copy remaining value(s) from the original aggregate.
4255for (; i != NumAggValues; ++i)
4256 Values[i] = IntoUndef ?DAG.getUNDEF(AggValueVTs[i]) :
4257SDValue(Agg.getNode(), Agg.getResNo() + i);
4258
4259setValue(&I,DAG.getNode(ISD::MERGE_VALUES,getCurSDLoc(),
4260DAG.getVTList(AggValueVTs), Values));
4261}
4262
4263void SelectionDAGBuilder::visitExtractValue(constExtractValueInst &I) {
4264ArrayRef<unsigned> Indices =I.getIndices();
4265constValue *Op0 =I.getOperand(0);
4266Type *AggTy = Op0->getType();
4267Type *ValTy =I.getType();
4268bool OutOfUndef = isa<UndefValue>(Op0);
4269
4270unsigned LinearIndex =ComputeLinearIndex(AggTy, Indices);
4271
4272constTargetLowering &TLI =DAG.getTargetLoweringInfo();
4273SmallVector<EVT, 4> ValValueVTs;
4274ComputeValueVTs(TLI,DAG.getDataLayout(), ValTy, ValValueVTs);
4275
4276unsigned NumValValues = ValValueVTs.size();
4277
4278// Ignore a extractvalue that produces an empty object
4279if (!NumValValues) {
4280setValue(&I,DAG.getUNDEF(MVT(MVT::Other)));
4281return;
4282 }
4283
4284SmallVector<SDValue, 4> Values(NumValValues);
4285
4286SDValue Agg =getValue(Op0);
4287// Copy out the selected value(s).
4288for (unsigned i = LinearIndex; i != LinearIndex + NumValValues; ++i)
4289 Values[i - LinearIndex] =
4290 OutOfUndef ?
4291DAG.getUNDEF(Agg.getNode()->getValueType(Agg.getResNo() + i)) :
4292SDValue(Agg.getNode(), Agg.getResNo() + i);
4293
4294setValue(&I,DAG.getNode(ISD::MERGE_VALUES,getCurSDLoc(),
4295DAG.getVTList(ValValueVTs), Values));
4296}
4297
4298void SelectionDAGBuilder::visitGetElementPtr(constUser &I) {
4299Value *Op0 =I.getOperand(0);
4300// Note that the pointer operand may be a vector of pointers. Take the scalar
4301// element which holds a pointer.
4302unsigned AS = Op0->getType()->getScalarType()->getPointerAddressSpace();
4303SDValueN =getValue(Op0);
4304SDLoc dl =getCurSDLoc();
4305auto &TLI =DAG.getTargetLoweringInfo();
4306GEPNoWrapFlags NW = cast<GEPOperator>(I).getNoWrapFlags();
4307
4308// Normalize Vector GEP - all scalar operands should be converted to the
4309// splat vector.
4310bool IsVectorGEP =I.getType()->isVectorTy();
4311ElementCount VectorElementCount =
4312 IsVectorGEP ? cast<VectorType>(I.getType())->getElementCount()
4313 :ElementCount::getFixed(0);
4314
4315if (IsVectorGEP && !N.getValueType().isVector()) {
4316LLVMContext &Context = *DAG.getContext();
4317EVT VT =EVT::getVectorVT(Context,N.getValueType(), VectorElementCount);
4318N =DAG.getSplat(VT, dl,N);
4319 }
4320
4321for (gep_type_iterator GTI =gep_type_begin(&I), E =gep_type_end(&I);
4322 GTI != E; ++GTI) {
4323constValue *Idx = GTI.getOperand();
4324if (StructType *StTy = GTI.getStructTypeOrNull()) {
4325unsignedField = cast<Constant>(Idx)->getUniqueInteger().getZExtValue();
4326if (Field) {
4327// N = N + Offset
4328uint64_tOffset =
4329DAG.getDataLayout().getStructLayout(StTy)->getElementOffset(Field);
4330
4331// In an inbounds GEP with an offset that is nonnegative even when
4332// interpreted as signed, assume there is no unsigned overflow.
4333SDNodeFlagsFlags;
4334if (NW.hasNoUnsignedWrap() ||
4335 (int64_t(Offset) >= 0 && NW.hasNoUnsignedSignedWrap()))
4336Flags |=SDNodeFlags::NoUnsignedWrap;
4337
4338N =DAG.getNode(ISD::ADD, dl,N.getValueType(),N,
4339DAG.getConstant(Offset, dl,N.getValueType()), Flags);
4340 }
4341 }else {
4342// IdxSize is the width of the arithmetic according to IR semantics.
4343// In SelectionDAG, we may prefer to do arithmetic in a wider bitwidth
4344// (and fix up the result later).
4345unsigned IdxSize =DAG.getDataLayout().getIndexSizeInBits(AS);
4346MVT IdxTy =MVT::getIntegerVT(IdxSize);
4347TypeSize ElementSize =
4348 GTI.getSequentialElementStride(DAG.getDataLayout());
4349// We intentionally mask away the high bits here; ElementSize may not
4350// fit in IdxTy.
4351APInt ElementMul(IdxSize, ElementSize.getKnownMinValue(),
4352/*isSigned=*/false,/*implicitTrunc=*/true);
4353bool ElementScalable = ElementSize.isScalable();
4354
4355// If this is a scalar constant or a splat vector of constants,
4356// handle it quickly.
4357constauto *C = dyn_cast<Constant>(Idx);
4358if (C && isa<VectorType>(C->getType()))
4359C =C->getSplatValue();
4360
4361constauto *CI = dyn_cast_or_null<ConstantInt>(C);
4362if (CI && CI->isZero())
4363continue;
4364if (CI && !ElementScalable) {
4365APInt Offs = ElementMul * CI->getValue().sextOrTrunc(IdxSize);
4366LLVMContext &Context = *DAG.getContext();
4367SDValue OffsVal;
4368if (IsVectorGEP)
4369 OffsVal =DAG.getConstant(
4370 Offs, dl,EVT::getVectorVT(Context, IdxTy, VectorElementCount));
4371else
4372 OffsVal =DAG.getConstant(Offs, dl, IdxTy);
4373
4374// In an inbounds GEP with an offset that is nonnegative even when
4375// interpreted as signed, assume there is no unsigned overflow.
4376SDNodeFlagsFlags;
4377if (NW.hasNoUnsignedWrap() ||
4378 (Offs.isNonNegative() && NW.hasNoUnsignedSignedWrap()))
4379Flags.setNoUnsignedWrap(true);
4380
4381 OffsVal =DAG.getSExtOrTrunc(OffsVal, dl,N.getValueType());
4382
4383N =DAG.getNode(ISD::ADD, dl,N.getValueType(),N, OffsVal, Flags);
4384continue;
4385 }
4386
4387// N = N + Idx * ElementMul;
4388SDValue IdxN =getValue(Idx);
4389
4390if (!IdxN.getValueType().isVector() && IsVectorGEP) {
4391EVT VT =EVT::getVectorVT(*Context, IdxN.getValueType(),
4392 VectorElementCount);
4393 IdxN =DAG.getSplat(VT, dl, IdxN);
4394 }
4395
4396// If the index is smaller or larger than intptr_t, truncate or extend
4397// it.
4398 IdxN =DAG.getSExtOrTrunc(IdxN, dl,N.getValueType());
4399
4400SDNodeFlags ScaleFlags;
4401// The multiplication of an index by the type size does not wrap the
4402// pointer index type in a signed sense (mul nsw).
4403 ScaleFlags.setNoSignedWrap(NW.hasNoUnsignedSignedWrap());
4404
4405// The multiplication of an index by the type size does not wrap the
4406// pointer index type in an unsigned sense (mul nuw).
4407 ScaleFlags.setNoUnsignedWrap(NW.hasNoUnsignedWrap());
4408
4409if (ElementScalable) {
4410EVT VScaleTy =N.getValueType().getScalarType();
4411SDValue VScale =DAG.getNode(
4412ISD::VSCALE, dl, VScaleTy,
4413DAG.getConstant(ElementMul.getZExtValue(), dl, VScaleTy));
4414if (IsVectorGEP)
4415 VScale =DAG.getSplatVector(N.getValueType(), dl, VScale);
4416 IdxN =DAG.getNode(ISD::MUL, dl,N.getValueType(), IdxN, VScale,
4417 ScaleFlags);
4418 }else {
4419// If this is a multiply by a power of two, turn it into a shl
4420// immediately. This is a very common case.
4421if (ElementMul != 1) {
4422if (ElementMul.isPowerOf2()) {
4423unsigned Amt = ElementMul.logBase2();
4424 IdxN =DAG.getNode(ISD::SHL, dl,N.getValueType(), IdxN,
4425DAG.getConstant(Amt, dl, IdxN.getValueType()),
4426 ScaleFlags);
4427 }else {
4428SDValue Scale =DAG.getConstant(ElementMul.getZExtValue(), dl,
4429 IdxN.getValueType());
4430 IdxN =DAG.getNode(ISD::MUL, dl,N.getValueType(), IdxN, Scale,
4431 ScaleFlags);
4432 }
4433 }
4434 }
4435
4436// The successive addition of the current address, truncated to the
4437// pointer index type and interpreted as an unsigned number, and each
4438// offset, also interpreted as an unsigned number, does not wrap the
4439// pointer index type (add nuw).
4440SDNodeFlags AddFlags;
4441 AddFlags.setNoUnsignedWrap(NW.hasNoUnsignedWrap());
4442
4443N =DAG.getNode(ISD::ADD, dl,N.getValueType(),N, IdxN, AddFlags);
4444 }
4445 }
4446
4447MVT PtrTy = TLI.getPointerTy(DAG.getDataLayout(), AS);
4448MVT PtrMemTy = TLI.getPointerMemTy(DAG.getDataLayout(), AS);
4449if (IsVectorGEP) {
4450 PtrTy =MVT::getVectorVT(PtrTy, VectorElementCount);
4451 PtrMemTy =MVT::getVectorVT(PtrMemTy, VectorElementCount);
4452 }
4453
4454if (PtrMemTy != PtrTy && !cast<GEPOperator>(I).isInBounds())
4455N =DAG.getPtrExtendInReg(N, dl, PtrMemTy);
4456
4457setValue(&I,N);
4458}
4459
4460void SelectionDAGBuilder::visitAlloca(constAllocaInst &I) {
4461// If this is a fixed sized alloca in the entry block of the function,
4462// allocate it statically on the stack.
4463if (FuncInfo.StaticAllocaMap.count(&I))
4464return;// getValue will auto-populate this.
4465
4466SDLoc dl =getCurSDLoc();
4467Type *Ty =I.getAllocatedType();
4468constTargetLowering &TLI =DAG.getTargetLoweringInfo();
4469auto &DL =DAG.getDataLayout();
4470TypeSize TySize =DL.getTypeAllocSize(Ty);
4471MaybeAlign Alignment = std::max(DL.getPrefTypeAlign(Ty),I.getAlign());
4472
4473SDValue AllocSize =getValue(I.getArraySize());
4474
4475EVT IntPtr = TLI.getPointerTy(DL,I.getAddressSpace());
4476if (AllocSize.getValueType() != IntPtr)
4477 AllocSize =DAG.getZExtOrTrunc(AllocSize, dl, IntPtr);
4478
4479if (TySize.isScalable())
4480 AllocSize =DAG.getNode(ISD::MUL, dl, IntPtr, AllocSize,
4481DAG.getVScale(dl, IntPtr,
4482APInt(IntPtr.getScalarSizeInBits(),
4483 TySize.getKnownMinValue())));
4484else {
4485SDValue TySizeValue =
4486DAG.getConstant(TySize.getFixedValue(), dl,MVT::getIntegerVT(64));
4487 AllocSize =DAG.getNode(ISD::MUL, dl, IntPtr, AllocSize,
4488DAG.getZExtOrTrunc(TySizeValue, dl, IntPtr));
4489 }
4490
4491// Handle alignment. If the requested alignment is less than or equal to
4492// the stack alignment, ignore it. If the size is greater than or equal to
4493// the stack alignment, we note this in the DYNAMIC_STACKALLOC node.
4494Align StackAlign =DAG.getSubtarget().getFrameLowering()->getStackAlign();
4495if (*Alignment <= StackAlign)
4496 Alignment = std::nullopt;
4497
4498constuint64_t StackAlignMask = StackAlign.value() - 1U;
4499// Round the size of the allocation up to the stack alignment size
4500// by add SA-1 to the size. This doesn't overflow because we're computing
4501// an address inside an alloca.
4502 AllocSize =DAG.getNode(ISD::ADD, dl, AllocSize.getValueType(), AllocSize,
4503DAG.getConstant(StackAlignMask, dl, IntPtr),
4504SDNodeFlags::NoUnsignedWrap);
4505
4506// Mask out the low bits for alignment purposes.
4507 AllocSize =DAG.getNode(ISD::AND, dl, AllocSize.getValueType(), AllocSize,
4508DAG.getSignedConstant(~StackAlignMask, dl, IntPtr));
4509
4510SDValue Ops[] = {
4511getRoot(), AllocSize,
4512DAG.getConstant(Alignment ? Alignment->value() : 0, dl, IntPtr)};
4513SDVTList VTs =DAG.getVTList(AllocSize.getValueType(), MVT::Other);
4514SDValue DSA =DAG.getNode(ISD::DYNAMIC_STACKALLOC, dl, VTs, Ops);
4515setValue(&I, DSA);
4516DAG.setRoot(DSA.getValue(1));
4517
4518assert(FuncInfo.MF->getFrameInfo().hasVarSizedObjects());
4519}
4520
4521staticconstMDNode *getRangeMetadata(constInstruction &I) {
4522// If !noundef is not present, then !range violation results in a poison
4523// value rather than immediate undefined behavior. In theory, transferring
4524// these annotations to SDAG is fine, but in practice there are key SDAG
4525// transforms that are known not to be poison-safe, such as folding logical
4526// and/or to bitwise and/or. For now, only transfer !range if !noundef is
4527// also present.
4528if (!I.hasMetadata(LLVMContext::MD_noundef))
4529returnnullptr;
4530returnI.getMetadata(LLVMContext::MD_range);
4531}
4532
4533static std::optional<ConstantRange>getRange(constInstruction &I) {
4534if (constauto *CB = dyn_cast<CallBase>(&I)) {
4535// see comment in getRangeMetadata about this check
4536if (CB->hasRetAttr(Attribute::NoUndef))
4537return CB->getRange();
4538 }
4539if (constMDNode *Range =getRangeMetadata(I))
4540returngetConstantRangeFromMetadata(*Range);
4541return std::nullopt;
4542}
4543
4544void SelectionDAGBuilder::visitLoad(constLoadInst &I) {
4545if (I.isAtomic())
4546return visitAtomicLoad(I);
4547
4548constTargetLowering &TLI =DAG.getTargetLoweringInfo();
4549constValue *SV =I.getOperand(0);
4550if (TLI.supportSwiftError()) {
4551// Swifterror values can come from either a function parameter with
4552// swifterror attribute or an alloca with swifterror attribute.
4553if (constArgument *Arg = dyn_cast<Argument>(SV)) {
4554if (Arg->hasSwiftErrorAttr())
4555return visitLoadFromSwiftError(I);
4556 }
4557
4558if (constAllocaInst *Alloca = dyn_cast<AllocaInst>(SV)) {
4559if (Alloca->isSwiftError())
4560return visitLoadFromSwiftError(I);
4561 }
4562 }
4563
4564SDValuePtr =getValue(SV);
4565
4566Type *Ty =I.getType();
4567SmallVector<EVT, 4> ValueVTs, MemVTs;
4568SmallVector<TypeSize, 4>Offsets;
4569ComputeValueVTs(TLI,DAG.getDataLayout(), Ty, ValueVTs, &MemVTs, &Offsets);
4570unsigned NumValues = ValueVTs.size();
4571if (NumValues == 0)
4572return;
4573
4574Align Alignment =I.getAlign();
4575AAMDNodes AAInfo =I.getAAMetadata();
4576constMDNode *Ranges =getRangeMetadata(I);
4577bool isVolatile =I.isVolatile();
4578MachineMemOperand::Flags MMOFlags =
4579 TLI.getLoadMemOperandFlags(I,DAG.getDataLayout(),AC,LibInfo);
4580
4581SDValue Root;
4582bool ConstantMemory =false;
4583if (isVolatile)
4584// Serialize volatile loads with other side effects.
4585 Root =getRoot();
4586elseif (NumValues >MaxParallelChains)
4587 Root =getMemoryRoot();
4588elseif (BatchAA &&
4589BatchAA->pointsToConstantMemory(MemoryLocation(
4590 SV,
4591LocationSize::precise(DAG.getDataLayout().getTypeStoreSize(Ty)),
4592 AAInfo))) {
4593// Do not serialize (non-volatile) loads of constant memory with anything.
4594 Root =DAG.getEntryNode();
4595 ConstantMemory =true;
4596 MMOFlags |=MachineMemOperand::MOInvariant;
4597 }else {
4598// Do not serialize non-volatile loads against each other.
4599 Root =DAG.getRoot();
4600 }
4601
4602SDLoc dl =getCurSDLoc();
4603
4604if (isVolatile)
4605 Root = TLI.prepareVolatileOrAtomicLoad(Root, dl,DAG);
4606
4607SmallVector<SDValue, 4> Values(NumValues);
4608SmallVector<SDValue, 4> Chains(std::min(MaxParallelChains, NumValues));
4609
4610unsigned ChainI = 0;
4611for (unsigned i = 0; i != NumValues; ++i, ++ChainI) {
4612// Serializing loads here may result in excessive register pressure, and
4613// TokenFactor places arbitrary choke points on the scheduler. SD scheduling
4614// could recover a bit by hoisting nodes upward in the chain by recognizing
4615// they are side-effect free or do not alias. The optimizer should really
4616// avoid this case by converting large object/array copies to llvm.memcpy
4617// (MaxParallelChains should always remain as failsafe).
4618if (ChainI ==MaxParallelChains) {
4619assert(PendingLoads.empty() &&"PendingLoads must be serialized first");
4620SDValue Chain =DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
4621ArrayRef(Chains.data(), ChainI));
4622 Root = Chain;
4623 ChainI = 0;
4624 }
4625
4626// TODO: MachinePointerInfo only supports a fixed length offset.
4627MachinePointerInfo PtrInfo =
4628 !Offsets[i].isScalable() ||Offsets[i].isZero()
4629 ?MachinePointerInfo(SV, Offsets[i].getKnownMinValue())
4630 :MachinePointerInfo();
4631
4632SDValueA =DAG.getObjectPtrOffset(dl,Ptr, Offsets[i]);
4633SDValueL =DAG.getLoad(MemVTs[i], dl, Root,A, PtrInfo, Alignment,
4634 MMOFlags, AAInfo, Ranges);
4635 Chains[ChainI] =L.getValue(1);
4636
4637if (MemVTs[i] != ValueVTs[i])
4638L =DAG.getPtrExtOrTrunc(L, dl, ValueVTs[i]);
4639
4640 Values[i] =L;
4641 }
4642
4643if (!ConstantMemory) {
4644SDValue Chain =DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
4645ArrayRef(Chains.data(), ChainI));
4646if (isVolatile)
4647DAG.setRoot(Chain);
4648else
4649PendingLoads.push_back(Chain);
4650 }
4651
4652setValue(&I,DAG.getNode(ISD::MERGE_VALUES, dl,
4653DAG.getVTList(ValueVTs), Values));
4654}
4655
4656void SelectionDAGBuilder::visitStoreToSwiftError(constStoreInst &I) {
4657assert(DAG.getTargetLoweringInfo().supportSwiftError() &&
4658"call visitStoreToSwiftError when backend supports swifterror");
4659
4660SmallVector<EVT, 4> ValueVTs;
4661SmallVector<uint64_t, 4>Offsets;
4662constValue *SrcV =I.getOperand(0);
4663ComputeValueVTs(DAG.getTargetLoweringInfo(),DAG.getDataLayout(),
4664 SrcV->getType(), ValueVTs, &Offsets, 0);
4665assert(ValueVTs.size() == 1 && Offsets[0] == 0 &&
4666"expect a single EVT for swifterror");
4667
4668SDValue Src =getValue(SrcV);
4669// Create a virtual register, then update the virtual register.
4670Register VReg =
4671SwiftError.getOrCreateVRegDefAt(&I,FuncInfo.MBB,I.getPointerOperand());
4672// Chain, DL, Reg, N or Chain, DL, Reg, N, Glue
4673// Chain can be getRoot or getControlRoot.
4674SDValue CopyNode =DAG.getCopyToReg(getRoot(),getCurSDLoc(), VReg,
4675SDValue(Src.getNode(), Src.getResNo()));
4676DAG.setRoot(CopyNode);
4677}
4678
4679void SelectionDAGBuilder::visitLoadFromSwiftError(constLoadInst &I) {
4680assert(DAG.getTargetLoweringInfo().supportSwiftError() &&
4681"call visitLoadFromSwiftError when backend supports swifterror");
4682
4683assert(!I.isVolatile() &&
4684 !I.hasMetadata(LLVMContext::MD_nontemporal) &&
4685 !I.hasMetadata(LLVMContext::MD_invariant_load) &&
4686"Support volatile, non temporal, invariant for load_from_swift_error");
4687
4688constValue *SV =I.getOperand(0);
4689Type *Ty =I.getType();
4690assert(
4691 (!BatchAA ||
4692 !BatchAA->pointsToConstantMemory(MemoryLocation(
4693 SV,LocationSize::precise(DAG.getDataLayout().getTypeStoreSize(Ty)),
4694I.getAAMetadata()))) &&
4695"load_from_swift_error should not be constant memory");
4696
4697SmallVector<EVT, 4> ValueVTs;
4698SmallVector<uint64_t, 4>Offsets;
4699ComputeValueVTs(DAG.getTargetLoweringInfo(),DAG.getDataLayout(), Ty,
4700 ValueVTs, &Offsets, 0);
4701assert(ValueVTs.size() == 1 && Offsets[0] == 0 &&
4702"expect a single EVT for swifterror");
4703
4704// Chain, DL, Reg, VT, Glue or Chain, DL, Reg, VT
4705SDValueL =DAG.getCopyFromReg(
4706getRoot(),getCurSDLoc(),
4707SwiftError.getOrCreateVRegUseAt(&I,FuncInfo.MBB, SV), ValueVTs[0]);
4708
4709setValue(&I, L);
4710}
4711
4712void SelectionDAGBuilder::visitStore(constStoreInst &I) {
4713if (I.isAtomic())
4714return visitAtomicStore(I);
4715
4716constValue *SrcV =I.getOperand(0);
4717constValue *PtrV =I.getOperand(1);
4718
4719constTargetLowering &TLI =DAG.getTargetLoweringInfo();
4720if (TLI.supportSwiftError()) {
4721// Swifterror values can come from either a function parameter with
4722// swifterror attribute or an alloca with swifterror attribute.
4723if (constArgument *Arg = dyn_cast<Argument>(PtrV)) {
4724if (Arg->hasSwiftErrorAttr())
4725return visitStoreToSwiftError(I);
4726 }
4727
4728if (constAllocaInst *Alloca = dyn_cast<AllocaInst>(PtrV)) {
4729if (Alloca->isSwiftError())
4730return visitStoreToSwiftError(I);
4731 }
4732 }
4733
4734SmallVector<EVT, 4> ValueVTs, MemVTs;
4735SmallVector<TypeSize, 4>Offsets;
4736ComputeValueVTs(DAG.getTargetLoweringInfo(),DAG.getDataLayout(),
4737 SrcV->getType(), ValueVTs, &MemVTs, &Offsets);
4738unsigned NumValues = ValueVTs.size();
4739if (NumValues == 0)
4740return;
4741
4742// Get the lowered operands. Note that we do this after
4743// checking if NumResults is zero, because with zero results
4744// the operands won't have values in the map.
4745SDValue Src =getValue(SrcV);
4746SDValuePtr =getValue(PtrV);
4747
4748SDValue Root =I.isVolatile() ?getRoot() :getMemoryRoot();
4749SmallVector<SDValue, 4> Chains(std::min(MaxParallelChains, NumValues));
4750SDLoc dl =getCurSDLoc();
4751Align Alignment =I.getAlign();
4752AAMDNodes AAInfo =I.getAAMetadata();
4753
4754auto MMOFlags = TLI.getStoreMemOperandFlags(I,DAG.getDataLayout());
4755
4756unsigned ChainI = 0;
4757for (unsigned i = 0; i != NumValues; ++i, ++ChainI) {
4758// See visitLoad comments.
4759if (ChainI ==MaxParallelChains) {
4760SDValue Chain =DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
4761ArrayRef(Chains.data(), ChainI));
4762 Root = Chain;
4763 ChainI = 0;
4764 }
4765
4766// TODO: MachinePointerInfo only supports a fixed length offset.
4767MachinePointerInfo PtrInfo =
4768 !Offsets[i].isScalable() ||Offsets[i].isZero()
4769 ?MachinePointerInfo(PtrV, Offsets[i].getKnownMinValue())
4770 :MachinePointerInfo();
4771
4772SDValueAdd =DAG.getObjectPtrOffset(dl,Ptr, Offsets[i]);
4773SDValue Val =SDValue(Src.getNode(), Src.getResNo() + i);
4774if (MemVTs[i] != ValueVTs[i])
4775 Val =DAG.getPtrExtOrTrunc(Val, dl, MemVTs[i]);
4776SDValue St =
4777DAG.getStore(Root, dl, Val,Add, PtrInfo, Alignment, MMOFlags, AAInfo);
4778 Chains[ChainI] = St;
4779 }
4780
4781SDValue StoreNode =DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
4782ArrayRef(Chains.data(), ChainI));
4783setValue(&I, StoreNode);
4784DAG.setRoot(StoreNode);
4785}
4786
4787void SelectionDAGBuilder::visitMaskedStore(constCallInst &I,
4788bool IsCompressing) {
4789SDLoc sdl =getCurSDLoc();
4790
4791auto getMaskedStoreOps = [&](Value *&Ptr,Value *&Mask,Value *&Src0,
4792Align &Alignment) {
4793// llvm.masked.store.*(Src0, Ptr, alignment, Mask)
4794 Src0 =I.getArgOperand(0);
4795Ptr =I.getArgOperand(1);
4796 Alignment = cast<ConstantInt>(I.getArgOperand(2))->getAlignValue();
4797Mask =I.getArgOperand(3);
4798 };
4799auto getCompressingStoreOps = [&](Value *&Ptr,Value *&Mask,Value *&Src0,
4800Align &Alignment) {
4801// llvm.masked.compressstore.*(Src0, Ptr, Mask)
4802 Src0 =I.getArgOperand(0);
4803Ptr =I.getArgOperand(1);
4804Mask =I.getArgOperand(2);
4805 Alignment =I.getParamAlign(1).valueOrOne();
4806 };
4807
4808Value *PtrOperand, *MaskOperand, *Src0Operand;
4809Align Alignment;
4810if (IsCompressing)
4811 getCompressingStoreOps(PtrOperand, MaskOperand, Src0Operand, Alignment);
4812else
4813 getMaskedStoreOps(PtrOperand, MaskOperand, Src0Operand, Alignment);
4814
4815SDValuePtr =getValue(PtrOperand);
4816SDValue Src0 =getValue(Src0Operand);
4817SDValueMask =getValue(MaskOperand);
4818SDValueOffset =DAG.getUNDEF(Ptr.getValueType());
4819
4820EVT VT = Src0.getValueType();
4821
4822auto MMOFlags =MachineMemOperand::MOStore;
4823if (I.hasMetadata(LLVMContext::MD_nontemporal))
4824 MMOFlags |=MachineMemOperand::MONonTemporal;
4825
4826MachineMemOperand *MMO =DAG.getMachineFunction().getMachineMemOperand(
4827MachinePointerInfo(PtrOperand), MMOFlags,
4828LocationSize::beforeOrAfterPointer(), Alignment,I.getAAMetadata());
4829
4830constauto &TLI =DAG.getTargetLoweringInfo();
4831constauto &TTI =
4832 TLI.getTargetMachine().getTargetTransformInfo(*I.getFunction());
4833SDValue StoreNode =
4834 !IsCompressing &&
4835TTI.hasConditionalLoadStoreForType(I.getArgOperand(0)->getType())
4836 ? TLI.visitMaskedStore(DAG, sdl,getMemoryRoot(), MMO,Ptr, Src0,
4837 Mask)
4838 :DAG.getMaskedStore(getMemoryRoot(), sdl, Src0,Ptr,Offset, Mask,
4839 VT, MMO,ISD::UNINDEXED,/*Truncating=*/false,
4840 IsCompressing);
4841DAG.setRoot(StoreNode);
4842setValue(&I, StoreNode);
4843}
4844
4845// Get a uniform base for the Gather/Scatter intrinsic.
4846// The first argument of the Gather/Scatter intrinsic is a vector of pointers.
4847// We try to represent it as a base pointer + vector of indices.
4848// Usually, the vector of pointers comes from a 'getelementptr' instruction.
4849// The first operand of the GEP may be a single pointer or a vector of pointers
4850// Example:
4851// %gep.ptr = getelementptr i32, <8 x i32*> %vptr, <8 x i32> %ind
4852// or
4853// %gep.ptr = getelementptr i32, i32* %ptr, <8 x i32> %ind
4854// %res = call <8 x i32> @llvm.masked.gather.v8i32(<8 x i32*> %gep.ptr, ..
4855//
4856// When the first GEP operand is a single pointer - it is the uniform base we
4857// are looking for. If first operand of the GEP is a splat vector - we
4858// extract the splat value and use it as a uniform base.
4859// In all other cases the function returns 'false'.
4860staticboolgetUniformBase(constValue *Ptr,SDValue &Base,SDValue &Index,
4861ISD::MemIndexType &IndexType,SDValue &Scale,
4862SelectionDAGBuilder *SDB,constBasicBlock *CurBB,
4863uint64_t ElemSize) {
4864SelectionDAG& DAG = SDB->DAG;
4865constTargetLowering &TLI = DAG.getTargetLoweringInfo();
4866constDataLayout &DL = DAG.getDataLayout();
4867
4868assert(Ptr->getType()->isVectorTy() &&"Unexpected pointer type");
4869
4870// Handle splat constant pointer.
4871if (auto *C = dyn_cast<Constant>(Ptr)) {
4872C =C->getSplatValue();
4873if (!C)
4874returnfalse;
4875
4876Base = SDB->getValue(C);
4877
4878ElementCount NumElts = cast<VectorType>(Ptr->getType())->getElementCount();
4879EVT VT =EVT::getVectorVT(*DAG.getContext(), TLI.getPointerTy(DL), NumElts);
4880 Index = DAG.getConstant(0, SDB->getCurSDLoc(), VT);
4881 IndexType =ISD::SIGNED_SCALED;
4882 Scale = DAG.getTargetConstant(1, SDB->getCurSDLoc(), TLI.getPointerTy(DL));
4883returntrue;
4884 }
4885
4886constGetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Ptr);
4887if (!GEP ||GEP->getParent() != CurBB)
4888returnfalse;
4889
4890if (GEP->getNumOperands() != 2)
4891returnfalse;
4892
4893constValue *BasePtr =GEP->getPointerOperand();
4894constValue *IndexVal =GEP->getOperand(GEP->getNumOperands() - 1);
4895
4896// Make sure the base is scalar and the index is a vector.
4897if (BasePtr->getType()->isVectorTy() || !IndexVal->getType()->isVectorTy())
4898returnfalse;
4899
4900TypeSize ScaleVal =DL.getTypeAllocSize(GEP->getResultElementType());
4901if (ScaleVal.isScalable())
4902returnfalse;
4903
4904// Target may not support the required addressing mode.
4905if (ScaleVal != 1 &&
4906 !TLI.isLegalScaleForGatherScatter(ScaleVal.getFixedValue(), ElemSize))
4907returnfalse;
4908
4909Base = SDB->getValue(BasePtr);
4910 Index = SDB->getValue(IndexVal);
4911 IndexType =ISD::SIGNED_SCALED;
4912
4913 Scale =
4914 DAG.getTargetConstant(ScaleVal, SDB->getCurSDLoc(), TLI.getPointerTy(DL));
4915returntrue;
4916}
4917
4918void SelectionDAGBuilder::visitMaskedScatter(constCallInst &I) {
4919SDLoc sdl =getCurSDLoc();
4920
4921// llvm.masked.scatter.*(Src0, Ptrs, alignment, Mask)
4922constValue *Ptr =I.getArgOperand(1);
4923SDValue Src0 =getValue(I.getArgOperand(0));
4924SDValueMask =getValue(I.getArgOperand(3));
4925EVT VT = Src0.getValueType();
4926Align Alignment = cast<ConstantInt>(I.getArgOperand(2))
4927 ->getMaybeAlignValue()
4928 .value_or(DAG.getEVTAlign(VT.getScalarType()));
4929constTargetLowering &TLI =DAG.getTargetLoweringInfo();
4930
4931SDValueBase;
4932SDValueIndex;
4933ISD::MemIndexType IndexType;
4934SDValue Scale;
4935bool UniformBase =getUniformBase(Ptr,Base, Index, IndexType, Scale,this,
4936I.getParent(), VT.getScalarStoreSize());
4937
4938unsigned AS =Ptr->getType()->getScalarType()->getPointerAddressSpace();
4939MachineMemOperand *MMO =DAG.getMachineFunction().getMachineMemOperand(
4940MachinePointerInfo(AS),MachineMemOperand::MOStore,
4941LocationSize::beforeOrAfterPointer(), Alignment,I.getAAMetadata());
4942if (!UniformBase) {
4943Base =DAG.getConstant(0, sdl, TLI.getPointerTy(DAG.getDataLayout()));
4944Index =getValue(Ptr);
4945 IndexType =ISD::SIGNED_SCALED;
4946 Scale =DAG.getTargetConstant(1, sdl, TLI.getPointerTy(DAG.getDataLayout()));
4947 }
4948
4949EVT IdxVT =Index.getValueType();
4950EVT EltTy = IdxVT.getVectorElementType();
4951if (TLI.shouldExtendGSIndex(IdxVT, EltTy)) {
4952EVT NewIdxVT = IdxVT.changeVectorElementType(EltTy);
4953Index =DAG.getNode(ISD::SIGN_EXTEND, sdl, NewIdxVT, Index);
4954 }
4955
4956SDValue Ops[] = {getMemoryRoot(), Src0,Mask,Base,Index, Scale };
4957SDValue Scatter =DAG.getMaskedScatter(DAG.getVTList(MVT::Other), VT, sdl,
4958 Ops, MMO, IndexType,false);
4959DAG.setRoot(Scatter);
4960setValue(&I, Scatter);
4961}
4962
4963void SelectionDAGBuilder::visitMaskedLoad(constCallInst &I,bool IsExpanding) {
4964SDLoc sdl =getCurSDLoc();
4965
4966auto getMaskedLoadOps = [&](Value *&Ptr,Value *&Mask,Value *&Src0,
4967Align &Alignment) {
4968// @llvm.masked.load.*(Ptr, alignment, Mask, Src0)
4969Ptr =I.getArgOperand(0);
4970 Alignment = cast<ConstantInt>(I.getArgOperand(1))->getAlignValue();
4971Mask =I.getArgOperand(2);
4972 Src0 =I.getArgOperand(3);
4973 };
4974auto getExpandingLoadOps = [&](Value *&Ptr,Value *&Mask,Value *&Src0,
4975Align &Alignment) {
4976// @llvm.masked.expandload.*(Ptr, Mask, Src0)
4977Ptr =I.getArgOperand(0);
4978 Alignment =I.getParamAlign(0).valueOrOne();
4979Mask =I.getArgOperand(1);
4980 Src0 =I.getArgOperand(2);
4981 };
4982
4983Value *PtrOperand, *MaskOperand, *Src0Operand;
4984Align Alignment;
4985if (IsExpanding)
4986 getExpandingLoadOps(PtrOperand, MaskOperand, Src0Operand, Alignment);
4987else
4988 getMaskedLoadOps(PtrOperand, MaskOperand, Src0Operand, Alignment);
4989
4990SDValuePtr =getValue(PtrOperand);
4991SDValue Src0 =getValue(Src0Operand);
4992SDValueMask =getValue(MaskOperand);
4993SDValueOffset =DAG.getUNDEF(Ptr.getValueType());
4994
4995EVT VT = Src0.getValueType();
4996AAMDNodes AAInfo =I.getAAMetadata();
4997constMDNode *Ranges =getRangeMetadata(I);
4998
4999// Do not serialize masked loads of constant memory with anything.
5000MemoryLocationML =MemoryLocation::getAfter(PtrOperand, AAInfo);
5001bool AddToChain = !BatchAA || !BatchAA->pointsToConstantMemory(ML);
5002
5003SDValue InChain = AddToChain ?DAG.getRoot() :DAG.getEntryNode();
5004
5005auto MMOFlags =MachineMemOperand::MOLoad;
5006if (I.hasMetadata(LLVMContext::MD_nontemporal))
5007 MMOFlags |=MachineMemOperand::MONonTemporal;
5008
5009MachineMemOperand *MMO =DAG.getMachineFunction().getMachineMemOperand(
5010MachinePointerInfo(PtrOperand), MMOFlags,
5011LocationSize::beforeOrAfterPointer(), Alignment, AAInfo, Ranges);
5012
5013constauto &TLI =DAG.getTargetLoweringInfo();
5014constauto &TTI =
5015 TLI.getTargetMachine().getTargetTransformInfo(*I.getFunction());
5016// The Load/Res may point to different values and both of them are output
5017// variables.
5018SDValueLoad;
5019SDValue Res;
5020if (!IsExpanding &&
5021TTI.hasConditionalLoadStoreForType(Src0Operand->getType()))
5022 Res = TLI.visitMaskedLoad(DAG, sdl, InChain, MMO, Load,Ptr, Src0, Mask);
5023else
5024 Res =Load =
5025DAG.getMaskedLoad(VT, sdl, InChain,Ptr,Offset, Mask, Src0, VT, MMO,
5026ISD::UNINDEXED,ISD::NON_EXTLOAD, IsExpanding);
5027if (AddToChain)
5028PendingLoads.push_back(Load.getValue(1));
5029setValue(&I, Res);
5030}
5031
5032void SelectionDAGBuilder::visitMaskedGather(constCallInst &I) {
5033SDLoc sdl =getCurSDLoc();
5034
5035// @llvm.masked.gather.*(Ptrs, alignment, Mask, Src0)
5036constValue *Ptr =I.getArgOperand(0);
5037SDValue Src0 =getValue(I.getArgOperand(3));
5038SDValueMask =getValue(I.getArgOperand(2));
5039
5040constTargetLowering &TLI =DAG.getTargetLoweringInfo();
5041EVT VT = TLI.getValueType(DAG.getDataLayout(),I.getType());
5042Align Alignment = cast<ConstantInt>(I.getArgOperand(1))
5043 ->getMaybeAlignValue()
5044 .value_or(DAG.getEVTAlign(VT.getScalarType()));
5045
5046constMDNode *Ranges =getRangeMetadata(I);
5047
5048SDValue Root =DAG.getRoot();
5049SDValueBase;
5050SDValueIndex;
5051ISD::MemIndexType IndexType;
5052SDValue Scale;
5053bool UniformBase =getUniformBase(Ptr,Base, Index, IndexType, Scale,this,
5054I.getParent(), VT.getScalarStoreSize());
5055unsigned AS =Ptr->getType()->getScalarType()->getPointerAddressSpace();
5056MachineMemOperand *MMO =DAG.getMachineFunction().getMachineMemOperand(
5057MachinePointerInfo(AS),MachineMemOperand::MOLoad,
5058LocationSize::beforeOrAfterPointer(), Alignment,I.getAAMetadata(),
5059 Ranges);
5060
5061if (!UniformBase) {
5062Base =DAG.getConstant(0, sdl, TLI.getPointerTy(DAG.getDataLayout()));
5063Index =getValue(Ptr);
5064 IndexType =ISD::SIGNED_SCALED;
5065 Scale =DAG.getTargetConstant(1, sdl, TLI.getPointerTy(DAG.getDataLayout()));
5066 }
5067
5068EVT IdxVT =Index.getValueType();
5069EVT EltTy = IdxVT.getVectorElementType();
5070if (TLI.shouldExtendGSIndex(IdxVT, EltTy)) {
5071EVT NewIdxVT = IdxVT.changeVectorElementType(EltTy);
5072Index =DAG.getNode(ISD::SIGN_EXTEND, sdl, NewIdxVT, Index);
5073 }
5074
5075SDValue Ops[] = { Root, Src0,Mask,Base,Index, Scale };
5076SDValue Gather =DAG.getMaskedGather(DAG.getVTList(VT, MVT::Other), VT, sdl,
5077 Ops, MMO, IndexType,ISD::NON_EXTLOAD);
5078
5079PendingLoads.push_back(Gather.getValue(1));
5080setValue(&I, Gather);
5081}
5082
5083void SelectionDAGBuilder::visitAtomicCmpXchg(constAtomicCmpXchgInst &I) {
5084SDLoc dl =getCurSDLoc();
5085AtomicOrdering SuccessOrdering =I.getSuccessOrdering();
5086AtomicOrdering FailureOrdering =I.getFailureOrdering();
5087SyncScope::ID SSID =I.getSyncScopeID();
5088
5089SDValue InChain =getRoot();
5090
5091MVT MemVT =getValue(I.getCompareOperand()).getSimpleValueType();
5092SDVTList VTs =DAG.getVTList(MemVT, MVT::i1, MVT::Other);
5093
5094constTargetLowering &TLI =DAG.getTargetLoweringInfo();
5095autoFlags = TLI.getAtomicMemOperandFlags(I,DAG.getDataLayout());
5096
5097MachineFunction &MF =DAG.getMachineFunction();
5098MachineMemOperand *MMO = MF.getMachineMemOperand(
5099MachinePointerInfo(I.getPointerOperand()), Flags,
5100LocationSize::precise(MemVT.getStoreSize()),DAG.getEVTAlign(MemVT),
5101AAMDNodes(),nullptr, SSID, SuccessOrdering, FailureOrdering);
5102
5103SDValueL =DAG.getAtomicCmpSwap(ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS,
5104 dl, MemVT, VTs, InChain,
5105getValue(I.getPointerOperand()),
5106getValue(I.getCompareOperand()),
5107getValue(I.getNewValOperand()), MMO);
5108
5109SDValue OutChain =L.getValue(2);
5110
5111setValue(&I, L);
5112DAG.setRoot(OutChain);
5113}
5114
5115void SelectionDAGBuilder::visitAtomicRMW(constAtomicRMWInst &I) {
5116SDLoc dl =getCurSDLoc();
5117ISD::NodeTypeNT;
5118switch (I.getOperation()) {
5119default:llvm_unreachable("Unknown atomicrmw operation");
5120caseAtomicRMWInst::Xchg:NT =ISD::ATOMIC_SWAP;break;
5121caseAtomicRMWInst::Add:NT =ISD::ATOMIC_LOAD_ADD;break;
5122caseAtomicRMWInst::Sub:NT =ISD::ATOMIC_LOAD_SUB;break;
5123caseAtomicRMWInst::And:NT =ISD::ATOMIC_LOAD_AND;break;
5124caseAtomicRMWInst::Nand:NT =ISD::ATOMIC_LOAD_NAND;break;
5125caseAtomicRMWInst::Or:NT =ISD::ATOMIC_LOAD_OR;break;
5126caseAtomicRMWInst::Xor:NT =ISD::ATOMIC_LOAD_XOR;break;
5127caseAtomicRMWInst::Max:NT =ISD::ATOMIC_LOAD_MAX;break;
5128caseAtomicRMWInst::Min:NT =ISD::ATOMIC_LOAD_MIN;break;
5129caseAtomicRMWInst::UMax:NT =ISD::ATOMIC_LOAD_UMAX;break;
5130caseAtomicRMWInst::UMin:NT =ISD::ATOMIC_LOAD_UMIN;break;
5131caseAtomicRMWInst::FAdd:NT =ISD::ATOMIC_LOAD_FADD;break;
5132caseAtomicRMWInst::FSub:NT =ISD::ATOMIC_LOAD_FSUB;break;
5133caseAtomicRMWInst::FMax:NT =ISD::ATOMIC_LOAD_FMAX;break;
5134caseAtomicRMWInst::FMin:NT =ISD::ATOMIC_LOAD_FMIN;break;
5135caseAtomicRMWInst::UIncWrap:
5136NT =ISD::ATOMIC_LOAD_UINC_WRAP;
5137break;
5138caseAtomicRMWInst::UDecWrap:
5139NT =ISD::ATOMIC_LOAD_UDEC_WRAP;
5140break;
5141caseAtomicRMWInst::USubCond:
5142NT =ISD::ATOMIC_LOAD_USUB_COND;
5143break;
5144caseAtomicRMWInst::USubSat:
5145NT =ISD::ATOMIC_LOAD_USUB_SAT;
5146break;
5147 }
5148AtomicOrderingOrdering =I.getOrdering();
5149SyncScope::ID SSID =I.getSyncScopeID();
5150
5151SDValue InChain =getRoot();
5152
5153auto MemVT =getValue(I.getValOperand()).getSimpleValueType();
5154constTargetLowering &TLI =DAG.getTargetLoweringInfo();
5155autoFlags = TLI.getAtomicMemOperandFlags(I,DAG.getDataLayout());
5156
5157MachineFunction &MF =DAG.getMachineFunction();
5158MachineMemOperand *MMO = MF.getMachineMemOperand(
5159MachinePointerInfo(I.getPointerOperand()), Flags,
5160LocationSize::precise(MemVT.getStoreSize()),DAG.getEVTAlign(MemVT),
5161AAMDNodes(),nullptr, SSID, Ordering);
5162
5163SDValueL =
5164DAG.getAtomic(NT, dl, MemVT, InChain,
5165getValue(I.getPointerOperand()),getValue(I.getValOperand()),
5166 MMO);
5167
5168SDValue OutChain =L.getValue(1);
5169
5170setValue(&I, L);
5171DAG.setRoot(OutChain);
5172}
5173
5174void SelectionDAGBuilder::visitFence(constFenceInst &I) {
5175SDLoc dl =getCurSDLoc();
5176constTargetLowering &TLI =DAG.getTargetLoweringInfo();
5177SDValue Ops[3];
5178 Ops[0] =getRoot();
5179 Ops[1] =DAG.getTargetConstant((unsigned)I.getOrdering(), dl,
5180 TLI.getFenceOperandTy(DAG.getDataLayout()));
5181 Ops[2] =DAG.getTargetConstant(I.getSyncScopeID(), dl,
5182 TLI.getFenceOperandTy(DAG.getDataLayout()));
5183SDValueN =DAG.getNode(ISD::ATOMIC_FENCE, dl, MVT::Other, Ops);
5184setValue(&I,N);
5185DAG.setRoot(N);
5186}
5187
5188void SelectionDAGBuilder::visitAtomicLoad(constLoadInst &I) {
5189SDLoc dl =getCurSDLoc();
5190AtomicOrdering Order =I.getOrdering();
5191SyncScope::ID SSID =I.getSyncScopeID();
5192
5193SDValue InChain =getRoot();
5194
5195constTargetLowering &TLI =DAG.getTargetLoweringInfo();
5196EVT VT = TLI.getValueType(DAG.getDataLayout(),I.getType());
5197EVT MemVT = TLI.getMemValueType(DAG.getDataLayout(),I.getType());
5198
5199if (!TLI.supportsUnalignedAtomics() &&
5200I.getAlign().value() < MemVT.getSizeInBits() / 8)
5201report_fatal_error("Cannot generate unaligned atomic load");
5202
5203autoFlags = TLI.getLoadMemOperandFlags(I,DAG.getDataLayout(),AC,LibInfo);
5204
5205MachineMemOperand *MMO =DAG.getMachineFunction().getMachineMemOperand(
5206MachinePointerInfo(I.getPointerOperand()), Flags,
5207LocationSize::precise(MemVT.getStoreSize()),I.getAlign(),AAMDNodes(),
5208nullptr, SSID, Order);
5209
5210 InChain = TLI.prepareVolatileOrAtomicLoad(InChain, dl,DAG);
5211
5212SDValuePtr =getValue(I.getPointerOperand());
5213SDValueL =DAG.getAtomic(ISD::ATOMIC_LOAD, dl, MemVT, MemVT, InChain,
5214Ptr, MMO);
5215
5216SDValue OutChain =L.getValue(1);
5217if (MemVT != VT)
5218L =DAG.getPtrExtOrTrunc(L, dl, VT);
5219
5220setValue(&I, L);
5221DAG.setRoot(OutChain);
5222}
5223
5224void SelectionDAGBuilder::visitAtomicStore(constStoreInst &I) {
5225SDLoc dl =getCurSDLoc();
5226
5227AtomicOrderingOrdering =I.getOrdering();
5228SyncScope::ID SSID =I.getSyncScopeID();
5229
5230SDValue InChain =getRoot();
5231
5232constTargetLowering &TLI =DAG.getTargetLoweringInfo();
5233EVT MemVT =
5234 TLI.getMemValueType(DAG.getDataLayout(),I.getValueOperand()->getType());
5235
5236if (!TLI.supportsUnalignedAtomics() &&
5237I.getAlign().value() < MemVT.getSizeInBits() / 8)
5238report_fatal_error("Cannot generate unaligned atomic store");
5239
5240autoFlags = TLI.getStoreMemOperandFlags(I,DAG.getDataLayout());
5241
5242MachineFunction &MF =DAG.getMachineFunction();
5243MachineMemOperand *MMO = MF.getMachineMemOperand(
5244MachinePointerInfo(I.getPointerOperand()), Flags,
5245LocationSize::precise(MemVT.getStoreSize()),I.getAlign(),AAMDNodes(),
5246nullptr, SSID, Ordering);
5247
5248SDValue Val =getValue(I.getValueOperand());
5249if (Val.getValueType() != MemVT)
5250 Val =DAG.getPtrExtOrTrunc(Val, dl, MemVT);
5251SDValuePtr =getValue(I.getPointerOperand());
5252
5253SDValue OutChain =
5254DAG.getAtomic(ISD::ATOMIC_STORE, dl, MemVT, InChain, Val,Ptr, MMO);
5255
5256setValue(&I, OutChain);
5257DAG.setRoot(OutChain);
5258}
5259
5260/// visitTargetIntrinsic - Lower a call of a target intrinsic to an INTRINSIC
5261/// node.
5262void SelectionDAGBuilder::visitTargetIntrinsic(constCallInst &I,
5263unsigned Intrinsic) {
5264// Ignore the callsite's attributes. A specific call site may be marked with
5265// readnone, but the lowering code will expect the chain based on the
5266// definition.
5267constFunction *F =I.getCalledFunction();
5268bool HasChain = !F->doesNotAccessMemory();
5269bool OnlyLoad =
5270 HasChain &&F->onlyReadsMemory() &&F->willReturn() &&F->doesNotThrow();
5271
5272// Build the operand list.
5273SmallVector<SDValue, 8> Ops;
5274if (HasChain) {// If this intrinsic has side-effects, chainify it.
5275if (OnlyLoad) {
5276// We don't need to serialize loads against other loads.
5277 Ops.push_back(DAG.getRoot());
5278 }else {
5279 Ops.push_back(getRoot());
5280 }
5281 }
5282
5283// Info is set by getTgtMemIntrinsic
5284TargetLowering::IntrinsicInfoInfo;
5285constTargetLowering &TLI =DAG.getTargetLoweringInfo();
5286bool IsTgtIntrinsic = TLI.getTgtMemIntrinsic(Info,I,
5287DAG.getMachineFunction(),
5288 Intrinsic);
5289
5290// Add the intrinsic ID as an integer operand if it's not a target intrinsic.
5291if (!IsTgtIntrinsic ||Info.opc ==ISD::INTRINSIC_VOID ||
5292Info.opc ==ISD::INTRINSIC_W_CHAIN)
5293 Ops.push_back(DAG.getTargetConstant(Intrinsic,getCurSDLoc(),
5294 TLI.getPointerTy(DAG.getDataLayout())));
5295
5296// Add all operands of the call to the operand list.
5297for (unsigned i = 0, e =I.arg_size(); i != e; ++i) {
5298constValue *Arg =I.getArgOperand(i);
5299if (!I.paramHasAttr(i, Attribute::ImmArg)) {
5300 Ops.push_back(getValue(Arg));
5301continue;
5302 }
5303
5304// Use TargetConstant instead of a regular constant for immarg.
5305EVT VT = TLI.getValueType(DAG.getDataLayout(), Arg->getType(),true);
5306if (constConstantInt *CI = dyn_cast<ConstantInt>(Arg)) {
5307assert(CI->getBitWidth() <= 64 &&
5308"large intrinsic immediates not handled");
5309 Ops.push_back(DAG.getTargetConstant(*CI,SDLoc(), VT));
5310 }else {
5311 Ops.push_back(
5312DAG.getTargetConstantFP(*cast<ConstantFP>(Arg),SDLoc(), VT));
5313 }
5314 }
5315
5316SmallVector<EVT, 4> ValueVTs;
5317ComputeValueVTs(TLI,DAG.getDataLayout(),I.getType(), ValueVTs);
5318
5319if (HasChain)
5320 ValueVTs.push_back(MVT::Other);
5321
5322SDVTList VTs =DAG.getVTList(ValueVTs);
5323
5324// Propagate fast-math-flags from IR to node(s).
5325SDNodeFlagsFlags;
5326if (auto *FPMO = dyn_cast<FPMathOperator>(&I))
5327Flags.copyFMF(*FPMO);
5328SelectionDAG::FlagInserter FlagsInserter(DAG, Flags);
5329
5330// Create the node.
5331SDValueResult;
5332
5333if (auto Bundle =I.getOperandBundle(LLVMContext::OB_convergencectrl)) {
5334auto *Token = Bundle->Inputs[0].get();
5335SDValue ConvControlToken =getValue(Token);
5336assert(Ops.back().getValueType() != MVT::Glue &&
5337"Did not expected another glue node here.");
5338 ConvControlToken =
5339DAG.getNode(ISD::CONVERGENCECTRL_GLUE, {}, MVT::Glue, ConvControlToken);
5340 Ops.push_back(ConvControlToken);
5341 }
5342
5343// In some cases, custom collection of operands from CallInst I may be needed.
5344 TLI.CollectTargetIntrinsicOperands(I, Ops,DAG);
5345if (IsTgtIntrinsic) {
5346// This is target intrinsic that touches memory
5347//
5348// TODO: We currently just fallback to address space 0 if getTgtMemIntrinsic
5349// didn't yield anything useful.
5350MachinePointerInfo MPI;
5351if (Info.ptrVal)
5352 MPI =MachinePointerInfo(Info.ptrVal,Info.offset);
5353elseif (Info.fallbackAddressSpace)
5354 MPI =MachinePointerInfo(*Info.fallbackAddressSpace);
5355Result =DAG.getMemIntrinsicNode(Info.opc,getCurSDLoc(), VTs, Ops,
5356Info.memVT, MPI,Info.align,Info.flags,
5357Info.size,I.getAAMetadata());
5358 }elseif (!HasChain) {
5359Result =DAG.getNode(ISD::INTRINSIC_WO_CHAIN,getCurSDLoc(), VTs, Ops);
5360 }elseif (!I.getType()->isVoidTy()) {
5361Result =DAG.getNode(ISD::INTRINSIC_W_CHAIN,getCurSDLoc(), VTs, Ops);
5362 }else {
5363Result =DAG.getNode(ISD::INTRINSIC_VOID,getCurSDLoc(), VTs, Ops);
5364 }
5365
5366if (HasChain) {
5367SDValue Chain =Result.getValue(Result.getNode()->getNumValues()-1);
5368if (OnlyLoad)
5369PendingLoads.push_back(Chain);
5370else
5371DAG.setRoot(Chain);
5372 }
5373
5374if (!I.getType()->isVoidTy()) {
5375if (!isa<VectorType>(I.getType()))
5376Result =lowerRangeToAssertZExt(DAG,I, Result);
5377
5378MaybeAlign Alignment =I.getRetAlign();
5379
5380// Insert `assertalign` node if there's an alignment.
5381if (InsertAssertAlign && Alignment) {
5382Result =
5383DAG.getAssertAlign(getCurSDLoc(), Result, Alignment.valueOrOne());
5384 }
5385 }
5386
5387setValue(&I, Result);
5388}
5389
5390/// GetSignificand - Get the significand and build it into a floating-point
5391/// number with exponent of 1:
5392///
5393/// Op = (Op & 0x007fffff) | 0x3f800000;
5394///
5395/// where Op is the hexadecimal representation of floating point value.
5396staticSDValueGetSignificand(SelectionDAG &DAG,SDValueOp,constSDLoc &dl) {
5397SDValue t1 = DAG.getNode(ISD::AND, dl, MVT::i32,Op,
5398 DAG.getConstant(0x007fffff, dl, MVT::i32));
5399SDValue t2 = DAG.getNode(ISD::OR, dl, MVT::i32, t1,
5400 DAG.getConstant(0x3f800000, dl, MVT::i32));
5401return DAG.getNode(ISD::BITCAST, dl, MVT::f32, t2);
5402}
5403
5404/// GetExponent - Get the exponent:
5405///
5406/// (float)(int)(((Op & 0x7f800000) >> 23) - 127);
5407///
5408/// where Op is the hexadecimal representation of floating point value.
5409staticSDValueGetExponent(SelectionDAG &DAG,SDValueOp,
5410constTargetLowering &TLI,constSDLoc &dl) {
5411SDValue t0 = DAG.getNode(ISD::AND, dl, MVT::i32,Op,
5412 DAG.getConstant(0x7f800000, dl, MVT::i32));
5413SDValue t1 = DAG.getNode(
5414ISD::SRL, dl, MVT::i32, t0,
5415 DAG.getConstant(23, dl,
5416 TLI.getShiftAmountTy(MVT::i32, DAG.getDataLayout())));
5417SDValue t2 = DAG.getNode(ISD::SUB, dl, MVT::i32, t1,
5418 DAG.getConstant(127, dl, MVT::i32));
5419return DAG.getNode(ISD::SINT_TO_FP, dl, MVT::f32, t2);
5420}
5421
5422/// getF32Constant - Get 32-bit floating point constant.
5423staticSDValuegetF32Constant(SelectionDAG &DAG,unsignedFlt,
5424constSDLoc &dl) {
5425return DAG.getConstantFP(APFloat(APFloat::IEEEsingle(),APInt(32,Flt)), dl,
5426 MVT::f32);
5427}
5428
5429staticSDValuegetLimitedPrecisionExp2(SDValue t0,constSDLoc &dl,
5430SelectionDAG &DAG) {
5431// TODO: What fast-math-flags should be set on the floating-point nodes?
5432
5433// IntegerPartOfX = ((int32_t)(t0);
5434SDValue IntegerPartOfX = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::i32, t0);
5435
5436// FractionalPartOfX = t0 - (float)IntegerPartOfX;
5437SDValue t1 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::f32, IntegerPartOfX);
5438SDValueX = DAG.getNode(ISD::FSUB, dl, MVT::f32, t0, t1);
5439
5440// IntegerPartOfX <<= 23;
5441 IntegerPartOfX =
5442 DAG.getNode(ISD::SHL, dl, MVT::i32, IntegerPartOfX,
5443 DAG.getConstant(23, dl,
5444 DAG.getTargetLoweringInfo().getShiftAmountTy(
5445 MVT::i32, DAG.getDataLayout())));
5446
5447SDValue TwoToFractionalPartOfX;
5448if (LimitFloatPrecision <= 6) {
5449// For floating-point precision of 6:
5450//
5451// TwoToFractionalPartOfX =
5452// 0.997535578f +
5453// (0.735607626f + 0.252464424f * x) * x;
5454//
5455// error 0.0144103317, which is 6 bits
5456SDValue t2 = DAG.getNode(ISD::FMUL, dl, MVT::f32,X,
5457getF32Constant(DAG, 0x3e814304, dl));
5458SDValue t3 = DAG.getNode(ISD::FADD, dl, MVT::f32, t2,
5459getF32Constant(DAG, 0x3f3c50c8, dl));
5460SDValue t4 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t3,X);
5461 TwoToFractionalPartOfX = DAG.getNode(ISD::FADD, dl, MVT::f32, t4,
5462getF32Constant(DAG, 0x3f7f5e7e, dl));
5463 }elseif (LimitFloatPrecision <= 12) {
5464// For floating-point precision of 12:
5465//
5466// TwoToFractionalPartOfX =
5467// 0.999892986f +
5468// (0.696457318f +
5469// (0.224338339f + 0.792043434e-1f * x) * x) * x;
5470//
5471// error 0.000107046256, which is 13 to 14 bits
5472SDValue t2 = DAG.getNode(ISD::FMUL, dl, MVT::f32,X,
5473getF32Constant(DAG, 0x3da235e3, dl));
5474SDValue t3 = DAG.getNode(ISD::FADD, dl, MVT::f32, t2,
5475getF32Constant(DAG, 0x3e65b8f3, dl));
5476SDValue t4 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t3,X);
5477SDValue t5 = DAG.getNode(ISD::FADD, dl, MVT::f32, t4,
5478getF32Constant(DAG, 0x3f324b07, dl));
5479SDValue t6 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t5,X);
5480 TwoToFractionalPartOfX = DAG.getNode(ISD::FADD, dl, MVT::f32, t6,
5481getF32Constant(DAG, 0x3f7ff8fd, dl));
5482 }else {// LimitFloatPrecision <= 18
5483// For floating-point precision of 18:
5484//
5485// TwoToFractionalPartOfX =
5486// 0.999999982f +
5487// (0.693148872f +
5488// (0.240227044f +
5489// (0.554906021e-1f +
5490// (0.961591928e-2f +
5491// (0.136028312e-2f + 0.157059148e-3f *x)*x)*x)*x)*x)*x;
5492// error 2.47208000*10^(-7), which is better than 18 bits
5493SDValue t2 = DAG.getNode(ISD::FMUL, dl, MVT::f32,X,
5494getF32Constant(DAG, 0x3924b03e, dl));
5495SDValue t3 = DAG.getNode(ISD::FADD, dl, MVT::f32, t2,
5496getF32Constant(DAG, 0x3ab24b87, dl));
5497SDValue t4 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t3,X);
5498SDValue t5 = DAG.getNode(ISD::FADD, dl, MVT::f32, t4,
5499getF32Constant(DAG, 0x3c1d8c17, dl));
5500SDValue t6 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t5,X);
5501SDValue t7 = DAG.getNode(ISD::FADD, dl, MVT::f32, t6,
5502getF32Constant(DAG, 0x3d634a1d, dl));
5503SDValue t8 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t7,X);
5504SDValue t9 = DAG.getNode(ISD::FADD, dl, MVT::f32, t8,
5505getF32Constant(DAG, 0x3e75fe14, dl));
5506SDValue t10 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t9,X);
5507SDValue t11 = DAG.getNode(ISD::FADD, dl, MVT::f32, t10,
5508getF32Constant(DAG, 0x3f317234, dl));
5509SDValue t12 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t11,X);
5510 TwoToFractionalPartOfX = DAG.getNode(ISD::FADD, dl, MVT::f32, t12,
5511getF32Constant(DAG, 0x3f800000, dl));
5512 }
5513
5514// Add the exponent into the result in integer domain.
5515SDValue t13 = DAG.getNode(ISD::BITCAST, dl, MVT::i32, TwoToFractionalPartOfX);
5516return DAG.getNode(ISD::BITCAST, dl, MVT::f32,
5517 DAG.getNode(ISD::ADD, dl, MVT::i32, t13, IntegerPartOfX));
5518}
5519
5520/// expandExp - Lower an exp intrinsic. Handles the special sequences for
5521/// limited-precision mode.
5522staticSDValueexpandExp(constSDLoc &dl,SDValueOp,SelectionDAG &DAG,
5523constTargetLowering &TLI,SDNodeFlags Flags) {
5524if (Op.getValueType() == MVT::f32 &&
5525LimitFloatPrecision > 0 &&LimitFloatPrecision <= 18) {
5526
5527// Put the exponent in the right bit position for later addition to the
5528// final result:
5529//
5530// t0 = Op * log2(e)
5531
5532// TODO: What fast-math-flags should be set here?
5533SDValue t0 = DAG.getNode(ISD::FMUL, dl, MVT::f32,Op,
5534 DAG.getConstantFP(numbers::log2ef, dl, MVT::f32));
5535returngetLimitedPrecisionExp2(t0, dl, DAG);
5536 }
5537
5538// No special expansion.
5539return DAG.getNode(ISD::FEXP, dl,Op.getValueType(),Op, Flags);
5540}
5541
5542/// expandLog - Lower a log intrinsic. Handles the special sequences for
5543/// limited-precision mode.
5544staticSDValueexpandLog(constSDLoc &dl,SDValueOp,SelectionDAG &DAG,
5545constTargetLowering &TLI,SDNodeFlags Flags) {
5546// TODO: What fast-math-flags should be set on the floating-point nodes?
5547
5548if (Op.getValueType() == MVT::f32 &&
5549LimitFloatPrecision > 0 &&LimitFloatPrecision <= 18) {
5550SDValue Op1 = DAG.getNode(ISD::BITCAST, dl, MVT::i32,Op);
5551
5552// Scale the exponent by log(2).
5553SDValue Exp =GetExponent(DAG, Op1, TLI, dl);
5554SDValue LogOfExponent =
5555 DAG.getNode(ISD::FMUL, dl, MVT::f32, Exp,
5556 DAG.getConstantFP(numbers::ln2f, dl, MVT::f32));
5557
5558// Get the significand and build it into a floating-point number with
5559// exponent of 1.
5560SDValueX =GetSignificand(DAG, Op1, dl);
5561
5562SDValue LogOfMantissa;
5563if (LimitFloatPrecision <= 6) {
5564// For floating-point precision of 6:
5565//
5566// LogofMantissa =
5567// -1.1609546f +
5568// (1.4034025f - 0.23903021f * x) * x;
5569//
5570// error 0.0034276066, which is better than 8 bits
5571SDValue t0 = DAG.getNode(ISD::FMUL, dl, MVT::f32,X,
5572getF32Constant(DAG, 0xbe74c456, dl));
5573SDValue t1 = DAG.getNode(ISD::FADD, dl, MVT::f32, t0,
5574getF32Constant(DAG, 0x3fb3a2b1, dl));
5575SDValue t2 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t1,X);
5576 LogOfMantissa = DAG.getNode(ISD::FSUB, dl, MVT::f32, t2,
5577getF32Constant(DAG, 0x3f949a29, dl));
5578 }elseif (LimitFloatPrecision <= 12) {
5579// For floating-point precision of 12:
5580//
5581// LogOfMantissa =
5582// -1.7417939f +
5583// (2.8212026f +
5584// (-1.4699568f +
5585// (0.44717955f - 0.56570851e-1f * x) * x) * x) * x;
5586//
5587// error 0.000061011436, which is 14 bits
5588SDValue t0 = DAG.getNode(ISD::FMUL, dl, MVT::f32,X,
5589getF32Constant(DAG, 0xbd67b6d6, dl));
5590SDValue t1 = DAG.getNode(ISD::FADD, dl, MVT::f32, t0,
5591getF32Constant(DAG, 0x3ee4f4b8, dl));
5592SDValue t2 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t1,X);
5593SDValue t3 = DAG.getNode(ISD::FSUB, dl, MVT::f32, t2,
5594getF32Constant(DAG, 0x3fbc278b, dl));
5595SDValue t4 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t3,X);
5596SDValue t5 = DAG.getNode(ISD::FADD, dl, MVT::f32, t4,
5597getF32Constant(DAG, 0x40348e95, dl));
5598SDValue t6 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t5,X);
5599 LogOfMantissa = DAG.getNode(ISD::FSUB, dl, MVT::f32, t6,
5600getF32Constant(DAG, 0x3fdef31a, dl));
5601 }else {// LimitFloatPrecision <= 18
5602// For floating-point precision of 18:
5603//
5604// LogOfMantissa =
5605// -2.1072184f +
5606// (4.2372794f +
5607// (-3.7029485f +
5608// (2.2781945f +
5609// (-0.87823314f +
5610// (0.19073739f - 0.17809712e-1f * x) * x) * x) * x) * x)*x;
5611//
5612// error 0.0000023660568, which is better than 18 bits
5613SDValue t0 = DAG.getNode(ISD::FMUL, dl, MVT::f32,X,
5614getF32Constant(DAG, 0xbc91e5ac, dl));
5615SDValue t1 = DAG.getNode(ISD::FADD, dl, MVT::f32, t0,
5616getF32Constant(DAG, 0x3e4350aa, dl));
5617SDValue t2 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t1,X);
5618SDValue t3 = DAG.getNode(ISD::FSUB, dl, MVT::f32, t2,
5619getF32Constant(DAG, 0x3f60d3e3, dl));
5620SDValue t4 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t3,X);
5621SDValue t5 = DAG.getNode(ISD::FADD, dl, MVT::f32, t4,
5622getF32Constant(DAG, 0x4011cdf0, dl));
5623SDValue t6 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t5,X);
5624SDValue t7 = DAG.getNode(ISD::FSUB, dl, MVT::f32, t6,
5625getF32Constant(DAG, 0x406cfd1c, dl));
5626SDValue t8 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t7,X);
5627SDValue t9 = DAG.getNode(ISD::FADD, dl, MVT::f32, t8,
5628getF32Constant(DAG, 0x408797cb, dl));
5629SDValue t10 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t9,X);
5630 LogOfMantissa = DAG.getNode(ISD::FSUB, dl, MVT::f32, t10,
5631getF32Constant(DAG, 0x4006dcab, dl));
5632 }
5633
5634return DAG.getNode(ISD::FADD, dl, MVT::f32, LogOfExponent, LogOfMantissa);
5635 }
5636
5637// No special expansion.
5638return DAG.getNode(ISD::FLOG, dl,Op.getValueType(),Op, Flags);
5639}
5640
5641/// expandLog2 - Lower a log2 intrinsic. Handles the special sequences for
5642/// limited-precision mode.
5643staticSDValueexpandLog2(constSDLoc &dl,SDValueOp,SelectionDAG &DAG,
5644constTargetLowering &TLI,SDNodeFlags Flags) {
5645// TODO: What fast-math-flags should be set on the floating-point nodes?
5646
5647if (Op.getValueType() == MVT::f32 &&
5648LimitFloatPrecision > 0 &&LimitFloatPrecision <= 18) {
5649SDValue Op1 = DAG.getNode(ISD::BITCAST, dl, MVT::i32,Op);
5650
5651// Get the exponent.
5652SDValue LogOfExponent =GetExponent(DAG, Op1, TLI, dl);
5653
5654// Get the significand and build it into a floating-point number with
5655// exponent of 1.
5656SDValueX =GetSignificand(DAG, Op1, dl);
5657
5658// Different possible minimax approximations of significand in
5659// floating-point for various degrees of accuracy over [1,2].
5660SDValue Log2ofMantissa;
5661if (LimitFloatPrecision <= 6) {
5662// For floating-point precision of 6:
5663//
5664// Log2ofMantissa = -1.6749035f + (2.0246817f - .34484768f * x) * x;
5665//
5666// error 0.0049451742, which is more than 7 bits
5667SDValue t0 = DAG.getNode(ISD::FMUL, dl, MVT::f32,X,
5668getF32Constant(DAG, 0xbeb08fe0, dl));
5669SDValue t1 = DAG.getNode(ISD::FADD, dl, MVT::f32, t0,
5670getF32Constant(DAG, 0x40019463, dl));
5671SDValue t2 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t1,X);
5672 Log2ofMantissa = DAG.getNode(ISD::FSUB, dl, MVT::f32, t2,
5673getF32Constant(DAG, 0x3fd6633d, dl));
5674 }elseif (LimitFloatPrecision <= 12) {
5675// For floating-point precision of 12:
5676//
5677// Log2ofMantissa =
5678// -2.51285454f +
5679// (4.07009056f +
5680// (-2.12067489f +
5681// (.645142248f - 0.816157886e-1f * x) * x) * x) * x;
5682//
5683// error 0.0000876136000, which is better than 13 bits
5684SDValue t0 = DAG.getNode(ISD::FMUL, dl, MVT::f32,X,
5685getF32Constant(DAG, 0xbda7262e, dl));
5686SDValue t1 = DAG.getNode(ISD::FADD, dl, MVT::f32, t0,
5687getF32Constant(DAG, 0x3f25280b, dl));
5688SDValue t2 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t1,X);
5689SDValue t3 = DAG.getNode(ISD::FSUB, dl, MVT::f32, t2,
5690getF32Constant(DAG, 0x4007b923, dl));
5691SDValue t4 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t3,X);
5692SDValue t5 = DAG.getNode(ISD::FADD, dl, MVT::f32, t4,
5693getF32Constant(DAG, 0x40823e2f, dl));
5694SDValue t6 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t5,X);
5695 Log2ofMantissa = DAG.getNode(ISD::FSUB, dl, MVT::f32, t6,
5696getF32Constant(DAG, 0x4020d29c, dl));
5697 }else {// LimitFloatPrecision <= 18
5698// For floating-point precision of 18:
5699//
5700// Log2ofMantissa =
5701// -3.0400495f +
5702// (6.1129976f +
5703// (-5.3420409f +
5704// (3.2865683f +
5705// (-1.2669343f +
5706// (0.27515199f -
5707// 0.25691327e-1f * x) * x) * x) * x) * x) * x;
5708//
5709// error 0.0000018516, which is better than 18 bits
5710SDValue t0 = DAG.getNode(ISD::FMUL, dl, MVT::f32,X,
5711getF32Constant(DAG, 0xbcd2769e, dl));
5712SDValue t1 = DAG.getNode(ISD::FADD, dl, MVT::f32, t0,
5713getF32Constant(DAG, 0x3e8ce0b9, dl));
5714SDValue t2 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t1,X);
5715SDValue t3 = DAG.getNode(ISD::FSUB, dl, MVT::f32, t2,
5716getF32Constant(DAG, 0x3fa22ae7, dl));
5717SDValue t4 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t3,X);
5718SDValue t5 = DAG.getNode(ISD::FADD, dl, MVT::f32, t4,
5719getF32Constant(DAG, 0x40525723, dl));
5720SDValue t6 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t5,X);
5721SDValue t7 = DAG.getNode(ISD::FSUB, dl, MVT::f32, t6,
5722getF32Constant(DAG, 0x40aaf200, dl));
5723SDValue t8 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t7,X);
5724SDValue t9 = DAG.getNode(ISD::FADD, dl, MVT::f32, t8,
5725getF32Constant(DAG, 0x40c39dad, dl));
5726SDValue t10 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t9,X);
5727 Log2ofMantissa = DAG.getNode(ISD::FSUB, dl, MVT::f32, t10,
5728getF32Constant(DAG, 0x4042902c, dl));
5729 }
5730
5731return DAG.getNode(ISD::FADD, dl, MVT::f32, LogOfExponent, Log2ofMantissa);
5732 }
5733
5734// No special expansion.
5735return DAG.getNode(ISD::FLOG2, dl,Op.getValueType(),Op, Flags);
5736}
5737
5738/// expandLog10 - Lower a log10 intrinsic. Handles the special sequences for
5739/// limited-precision mode.
5740staticSDValueexpandLog10(constSDLoc &dl,SDValueOp,SelectionDAG &DAG,
5741constTargetLowering &TLI,SDNodeFlags Flags) {
5742// TODO: What fast-math-flags should be set on the floating-point nodes?
5743
5744if (Op.getValueType() == MVT::f32 &&
5745LimitFloatPrecision > 0 &&LimitFloatPrecision <= 18) {
5746SDValue Op1 = DAG.getNode(ISD::BITCAST, dl, MVT::i32,Op);
5747
5748// Scale the exponent by log10(2) [0.30102999f].
5749SDValue Exp =GetExponent(DAG, Op1, TLI, dl);
5750SDValue LogOfExponent = DAG.getNode(ISD::FMUL, dl, MVT::f32, Exp,
5751getF32Constant(DAG, 0x3e9a209a, dl));
5752
5753// Get the significand and build it into a floating-point number with
5754// exponent of 1.
5755SDValueX =GetSignificand(DAG, Op1, dl);
5756
5757SDValue Log10ofMantissa;
5758if (LimitFloatPrecision <= 6) {
5759// For floating-point precision of 6:
5760//
5761// Log10ofMantissa =
5762// -0.50419619f +
5763// (0.60948995f - 0.10380950f * x) * x;
5764//
5765// error 0.0014886165, which is 6 bits
5766SDValue t0 = DAG.getNode(ISD::FMUL, dl, MVT::f32,X,
5767getF32Constant(DAG, 0xbdd49a13, dl));
5768SDValue t1 = DAG.getNode(ISD::FADD, dl, MVT::f32, t0,
5769getF32Constant(DAG, 0x3f1c0789, dl));
5770SDValue t2 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t1,X);
5771 Log10ofMantissa = DAG.getNode(ISD::FSUB, dl, MVT::f32, t2,
5772getF32Constant(DAG, 0x3f011300, dl));
5773 }elseif (LimitFloatPrecision <= 12) {
5774// For floating-point precision of 12:
5775//
5776// Log10ofMantissa =
5777// -0.64831180f +
5778// (0.91751397f +
5779// (-0.31664806f + 0.47637168e-1f * x) * x) * x;
5780//
5781// error 0.00019228036, which is better than 12 bits
5782SDValue t0 = DAG.getNode(ISD::FMUL, dl, MVT::f32,X,
5783getF32Constant(DAG, 0x3d431f31, dl));
5784SDValue t1 = DAG.getNode(ISD::FSUB, dl, MVT::f32, t0,
5785getF32Constant(DAG, 0x3ea21fb2, dl));
5786SDValue t2 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t1,X);
5787SDValue t3 = DAG.getNode(ISD::FADD, dl, MVT::f32, t2,
5788getF32Constant(DAG, 0x3f6ae232, dl));
5789SDValue t4 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t3,X);
5790 Log10ofMantissa = DAG.getNode(ISD::FSUB, dl, MVT::f32, t4,
5791getF32Constant(DAG, 0x3f25f7c3, dl));
5792 }else {// LimitFloatPrecision <= 18
5793// For floating-point precision of 18:
5794//
5795// Log10ofMantissa =
5796// -0.84299375f +
5797// (1.5327582f +
5798// (-1.0688956f +
5799// (0.49102474f +
5800// (-0.12539807f + 0.13508273e-1f * x) * x) * x) * x) * x;
5801//
5802// error 0.0000037995730, which is better than 18 bits
5803SDValue t0 = DAG.getNode(ISD::FMUL, dl, MVT::f32,X,
5804getF32Constant(DAG, 0x3c5d51ce, dl));
5805SDValue t1 = DAG.getNode(ISD::FSUB, dl, MVT::f32, t0,
5806getF32Constant(DAG, 0x3e00685a, dl));
5807SDValue t2 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t1,X);
5808SDValue t3 = DAG.getNode(ISD::FADD, dl, MVT::f32, t2,
5809getF32Constant(DAG, 0x3efb6798, dl));
5810SDValue t4 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t3,X);
5811SDValue t5 = DAG.getNode(ISD::FSUB, dl, MVT::f32, t4,
5812getF32Constant(DAG, 0x3f88d192, dl));
5813SDValue t6 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t5,X);
5814SDValue t7 = DAG.getNode(ISD::FADD, dl, MVT::f32, t6,
5815getF32Constant(DAG, 0x3fc4316c, dl));
5816SDValue t8 = DAG.getNode(ISD::FMUL, dl, MVT::f32, t7,X);
5817 Log10ofMantissa = DAG.getNode(ISD::FSUB, dl, MVT::f32, t8,
5818getF32Constant(DAG, 0x3f57ce70, dl));
5819 }
5820
5821return DAG.getNode(ISD::FADD, dl, MVT::f32, LogOfExponent, Log10ofMantissa);
5822 }
5823
5824// No special expansion.
5825return DAG.getNode(ISD::FLOG10, dl,Op.getValueType(),Op, Flags);
5826}
5827
5828/// expandExp2 - Lower an exp2 intrinsic. Handles the special sequences for
5829/// limited-precision mode.
5830staticSDValueexpandExp2(constSDLoc &dl,SDValueOp,SelectionDAG &DAG,
5831constTargetLowering &TLI,SDNodeFlags Flags) {
5832if (Op.getValueType() == MVT::f32 &&
5833LimitFloatPrecision > 0 &&LimitFloatPrecision <= 18)
5834returngetLimitedPrecisionExp2(Op, dl, DAG);
5835
5836// No special expansion.
5837return DAG.getNode(ISD::FEXP2, dl,Op.getValueType(),Op, Flags);
5838}
5839
5840/// visitPow - Lower a pow intrinsic. Handles the special sequences for
5841/// limited-precision mode with x == 10.0f.
5842staticSDValueexpandPow(constSDLoc &dl,SDValue LHS,SDValue RHS,
5843SelectionDAG &DAG,constTargetLowering &TLI,
5844SDNodeFlags Flags) {
5845bool IsExp10 =false;
5846if (LHS.getValueType() == MVT::f32 &&RHS.getValueType() == MVT::f32 &&
5847LimitFloatPrecision > 0 &&LimitFloatPrecision <= 18) {
5848if (ConstantFPSDNode *LHSC = dyn_cast<ConstantFPSDNode>(LHS)) {
5849APFloat Ten(10.0f);
5850 IsExp10 = LHSC->isExactlyValue(Ten);
5851 }
5852 }
5853
5854// TODO: What fast-math-flags should be set on the FMUL node?
5855if (IsExp10) {
5856// Put the exponent in the right bit position for later addition to the
5857// final result:
5858//
5859// #define LOG2OF10 3.3219281f
5860// t0 = Op * LOG2OF10;
5861SDValue t0 = DAG.getNode(ISD::FMUL, dl, MVT::f32,RHS,
5862getF32Constant(DAG, 0x40549a78, dl));
5863returngetLimitedPrecisionExp2(t0, dl, DAG);
5864 }
5865
5866// No special expansion.
5867return DAG.getNode(ISD::FPOW, dl,LHS.getValueType(),LHS,RHS, Flags);
5868}
5869
5870/// ExpandPowI - Expand a llvm.powi intrinsic.
5871staticSDValueExpandPowI(constSDLoc &DL,SDValue LHS,SDValue RHS,
5872SelectionDAG &DAG) {
5873// If RHS is a constant, we can expand this out to a multiplication tree if
5874// it's beneficial on the target, otherwise we end up lowering to a call to
5875// __powidf2 (for example).
5876if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(RHS)) {
5877unsigned Val = RHSC->getSExtValue();
5878
5879// powi(x, 0) -> 1.0
5880if (Val == 0)
5881return DAG.getConstantFP(1.0,DL,LHS.getValueType());
5882
5883if (DAG.getTargetLoweringInfo().isBeneficialToExpandPowI(
5884 Val, DAG.shouldOptForSize())) {
5885// Get the exponent as a positive value.
5886if ((int)Val < 0)
5887 Val = -Val;
5888// We use the simple binary decomposition method to generate the multiply
5889// sequence. There are more optimal ways to do this (for example,
5890// powi(x,15) generates one more multiply than it should), but this has
5891// the benefit of being both really simple and much better than a libcall.
5892SDValue Res;// Logically starts equal to 1.0
5893SDValue CurSquare =LHS;
5894// TODO: Intrinsics should have fast-math-flags that propagate to these
5895// nodes.
5896while (Val) {
5897if (Val & 1) {
5898if (Res.getNode())
5899 Res =
5900 DAG.getNode(ISD::FMUL,DL, Res.getValueType(), Res, CurSquare);
5901else
5902 Res = CurSquare;// 1.0*CurSquare.
5903 }
5904
5905 CurSquare = DAG.getNode(ISD::FMUL,DL, CurSquare.getValueType(),
5906 CurSquare, CurSquare);
5907 Val >>= 1;
5908 }
5909
5910// If the original was negative, invert the result, producing 1/(x*x*x).
5911if (RHSC->getSExtValue() < 0)
5912 Res = DAG.getNode(ISD::FDIV,DL,LHS.getValueType(),
5913 DAG.getConstantFP(1.0,DL,LHS.getValueType()), Res);
5914return Res;
5915 }
5916 }
5917
5918// Otherwise, expand to a libcall.
5919return DAG.getNode(ISD::FPOWI,DL,LHS.getValueType(),LHS,RHS);
5920}
5921
5922staticSDValueexpandDivFix(unsigned Opcode,constSDLoc &DL,
5923SDValue LHS,SDValue RHS,SDValue Scale,
5924SelectionDAG &DAG,constTargetLowering &TLI) {
5925EVT VT =LHS.getValueType();
5926boolSigned = Opcode ==ISD::SDIVFIX || Opcode ==ISD::SDIVFIXSAT;
5927bool Saturating = Opcode ==ISD::SDIVFIXSAT || Opcode ==ISD::UDIVFIXSAT;
5928LLVMContext &Ctx = *DAG.getContext();
5929
5930// If the type is legal but the operation isn't, this node might survive all
5931// the way to operation legalization. If we end up there and we do not have
5932// the ability to widen the type (if VT*2 is not legal), we cannot expand the
5933// node.
5934
5935// Coax the legalizer into expanding the node during type legalization instead
5936// by bumping the size by one bit. This will force it to Promote, enabling the
5937// early expansion and avoiding the need to expand later.
5938
5939// We don't have to do this if Scale is 0; that can always be expanded, unless
5940// it's a saturating signed operation. Those can experience true integer
5941// division overflow, a case which we must avoid.
5942
5943// FIXME: We wouldn't have to do this (or any of the early
5944// expansion/promotion) if it was possible to expand a libcall of an
5945// illegal type during operation legalization. But it's not, so things
5946// get a bit hacky.
5947unsigned ScaleInt = Scale->getAsZExtVal();
5948if ((ScaleInt > 0 || (Saturating &&Signed)) &&
5949 (TLI.isTypeLegal(VT) ||
5950 (VT.isVector() && TLI.isTypeLegal(VT.getVectorElementType())))) {
5951TargetLowering::LegalizeAction Action = TLI.getFixedPointOperationAction(
5952 Opcode, VT, ScaleInt);
5953if (Action !=TargetLowering::Legal && Action !=TargetLowering::Custom) {
5954EVT PromVT;
5955if (VT.isScalarInteger())
5956 PromVT =EVT::getIntegerVT(Ctx, VT.getSizeInBits() + 1);
5957elseif (VT.isVector()) {
5958 PromVT = VT.getVectorElementType();
5959 PromVT =EVT::getIntegerVT(Ctx, PromVT.getSizeInBits() + 1);
5960 PromVT =EVT::getVectorVT(Ctx, PromVT, VT.getVectorElementCount());
5961 }else
5962llvm_unreachable("Wrong VT for DIVFIX?");
5963LHS = DAG.getExtOrTrunc(Signed,LHS,DL, PromVT);
5964RHS = DAG.getExtOrTrunc(Signed,RHS,DL, PromVT);
5965EVT ShiftTy = TLI.getShiftAmountTy(PromVT, DAG.getDataLayout());
5966// For saturating operations, we need to shift up the LHS to get the
5967// proper saturation width, and then shift down again afterwards.
5968if (Saturating)
5969LHS = DAG.getNode(ISD::SHL,DL, PromVT,LHS,
5970 DAG.getConstant(1,DL, ShiftTy));
5971SDValue Res = DAG.getNode(Opcode,DL, PromVT,LHS,RHS, Scale);
5972if (Saturating)
5973 Res = DAG.getNode(Signed ?ISD::SRA :ISD::SRL,DL, PromVT, Res,
5974 DAG.getConstant(1,DL, ShiftTy));
5975return DAG.getZExtOrTrunc(Res,DL, VT);
5976 }
5977 }
5978
5979return DAG.getNode(Opcode,DL, VT,LHS,RHS, Scale);
5980}
5981
5982// getUnderlyingArgRegs - Find underlying registers used for a truncated,
5983// bitcasted, or split argument. Returns a list of <Register, size in bits>
5984staticvoid
5985getUnderlyingArgRegs(SmallVectorImpl<std::pair<Register, TypeSize>> &Regs,
5986constSDValue &N) {
5987switch (N.getOpcode()) {
5988caseISD::CopyFromReg: {
5989SDValueOp =N.getOperand(1);
5990 Regs.emplace_back(cast<RegisterSDNode>(Op)->getReg(),
5991Op.getValueType().getSizeInBits());
5992return;
5993 }
5994caseISD::BITCAST:
5995caseISD::AssertZext:
5996caseISD::AssertSext:
5997caseISD::TRUNCATE:
5998getUnderlyingArgRegs(Regs,N.getOperand(0));
5999return;
6000caseISD::BUILD_PAIR:
6001caseISD::BUILD_VECTOR:
6002caseISD::CONCAT_VECTORS:
6003for (SDValueOp :N->op_values())
6004getUnderlyingArgRegs(Regs,Op);
6005return;
6006default:
6007return;
6008 }
6009}
6010
6011/// If the DbgValueInst is a dbg_value of a function argument, create the
6012/// corresponding DBG_VALUE machine instruction for it now. At the end of
6013/// instruction selection, they will be inserted to the entry BB.
6014/// We don't currently support this for variadic dbg_values, as they shouldn't
6015/// appear for function arguments or in the prologue.
6016bool SelectionDAGBuilder::EmitFuncArgumentDbgValue(
6017constValue *V,DILocalVariable *Variable,DIExpression *Expr,
6018DILocation *DL, FuncArgumentDbgValueKind Kind,constSDValue &N) {
6019constArgument *Arg = dyn_cast<Argument>(V);
6020if (!Arg)
6021returnfalse;
6022
6023MachineFunction &MF =DAG.getMachineFunction();
6024constTargetInstrInfo *TII =DAG.getSubtarget().getInstrInfo();
6025
6026// Helper to create DBG_INSTR_REFs or DBG_VALUEs, depending on what kind
6027// we've been asked to pursue.
6028auto MakeVRegDbgValue = [&](RegisterReg,DIExpression *FragExpr,
6029boolIndirect) {
6030if (Reg.isVirtual() && MF.useDebugInstrRef()) {
6031// For VRegs, in instruction referencing mode, create a DBG_INSTR_REF
6032// pointing at the VReg, which will be patched up later.
6033auto &Inst =TII->get(TargetOpcode::DBG_INSTR_REF);
6034SmallVector<MachineOperand, 1> MOs({MachineOperand::CreateReg(
6035/* Reg */ Reg,/* isDef */false,/* isImp */false,
6036/* isKill */false,/* isDead */false,
6037/* isUndef */false,/* isEarlyClobber */false,
6038/* SubReg */ 0,/* isDebug */true)});
6039
6040auto *NewDIExpr = FragExpr;
6041// We don't have an "Indirect" field in DBG_INSTR_REF, fold that into
6042// the DIExpression.
6043if (Indirect)
6044 NewDIExpr =DIExpression::prepend(FragExpr,DIExpression::DerefBefore);
6045SmallVector<uint64_t, 2> Ops({dwarf::DW_OP_LLVM_arg, 0});
6046 NewDIExpr =DIExpression::prependOpcodes(NewDIExpr, Ops);
6047returnBuildMI(MF,DL, Inst,false, MOs, Variable, NewDIExpr);
6048 }else {
6049// Create a completely standard DBG_VALUE.
6050auto &Inst =TII->get(TargetOpcode::DBG_VALUE);
6051returnBuildMI(MF,DL, Inst, Indirect, Reg, Variable, FragExpr);
6052 }
6053 };
6054
6055if (Kind == FuncArgumentDbgValueKind::Value) {
6056// ArgDbgValues are hoisted to the beginning of the entry block. So we
6057// should only emit as ArgDbgValue if the dbg.value intrinsic is found in
6058// the entry block.
6059bool IsInEntryBlock =FuncInfo.MBB == &FuncInfo.MF->front();
6060if (!IsInEntryBlock)
6061returnfalse;
6062
6063// ArgDbgValues are hoisted to the beginning of the entry block. So we
6064// should only emit as ArgDbgValue if the dbg.value intrinsic describes a
6065// variable that also is a param.
6066//
6067// Although, if we are at the top of the entry block already, we can still
6068// emit using ArgDbgValue. This might catch some situations when the
6069// dbg.value refers to an argument that isn't used in the entry block, so
6070// any CopyToReg node would be optimized out and the only way to express
6071// this DBG_VALUE is by using the physical reg (or FI) as done in this
6072// method. ArgDbgValues are hoisted to the beginning of the entry block. So
6073// we should only emit as ArgDbgValue if the Variable is an argument to the
6074// current function, and the dbg.value intrinsic is found in the entry
6075// block.
6076bool VariableIsFunctionInputArg = Variable->isParameter() &&
6077 !DL->getInlinedAt();
6078bool IsInPrologue = SDNodeOrder ==LowestSDNodeOrder;
6079if (!IsInPrologue && !VariableIsFunctionInputArg)
6080returnfalse;
6081
6082// Here we assume that a function argument on IR level only can be used to
6083// describe one input parameter on source level. If we for example have
6084// source code like this
6085//
6086// struct A { long x, y; };
6087// void foo(struct A a, long b) {
6088// ...
6089// b = a.x;
6090// ...
6091// }
6092//
6093// and IR like this
6094//
6095// define void @foo(i32 %a1, i32 %a2, i32 %b) {
6096// entry:
6097// call void @llvm.dbg.value(metadata i32 %a1, "a", DW_OP_LLVM_fragment
6098// call void @llvm.dbg.value(metadata i32 %a2, "a", DW_OP_LLVM_fragment
6099// call void @llvm.dbg.value(metadata i32 %b, "b",
6100// ...
6101// call void @llvm.dbg.value(metadata i32 %a1, "b"
6102// ...
6103//
6104// then the last dbg.value is describing a parameter "b" using a value that
6105// is an argument. But since we already has used %a1 to describe a parameter
6106// we should not handle that last dbg.value here (that would result in an
6107// incorrect hoisting of the DBG_VALUE to the function entry).
6108// Notice that we allow one dbg.value per IR level argument, to accommodate
6109// for the situation with fragments above.
6110// If there is no node for the value being handled, we return true to skip
6111// the normal generation of debug info, as it would kill existing debug
6112// info for the parameter in case of duplicates.
6113if (VariableIsFunctionInputArg) {
6114unsigned ArgNo = Arg->getArgNo();
6115if (ArgNo >=FuncInfo.DescribedArgs.size())
6116FuncInfo.DescribedArgs.resize(ArgNo + 1,false);
6117elseif (!IsInPrologue &&FuncInfo.DescribedArgs.test(ArgNo))
6118return !NodeMap[V].getNode();
6119FuncInfo.DescribedArgs.set(ArgNo);
6120 }
6121 }
6122
6123bool IsIndirect =false;
6124 std::optional<MachineOperand>Op;
6125// Some arguments' frame index is recorded during argument lowering.
6126int FI =FuncInfo.getArgumentFrameIndex(Arg);
6127if (FI != std::numeric_limits<int>::max())
6128Op =MachineOperand::CreateFI(FI);
6129
6130SmallVector<std::pair<Register, TypeSize>, 8> ArgRegsAndSizes;
6131if (!Op &&N.getNode()) {
6132getUnderlyingArgRegs(ArgRegsAndSizes,N);
6133RegisterReg;
6134if (ArgRegsAndSizes.size() == 1)
6135Reg = ArgRegsAndSizes.front().first;
6136
6137if (Reg &&Reg.isVirtual()) {
6138MachineRegisterInfo &RegInfo = MF.getRegInfo();
6139Register PR =RegInfo.getLiveInPhysReg(Reg);
6140if (PR)
6141Reg = PR;
6142 }
6143if (Reg) {
6144Op =MachineOperand::CreateReg(Reg,false);
6145 IsIndirect =Kind != FuncArgumentDbgValueKind::Value;
6146 }
6147 }
6148
6149if (!Op &&N.getNode()) {
6150// Check if frame index is available.
6151SDValue LCandidate =peekThroughBitcasts(N);
6152if (LoadSDNode *LNode = dyn_cast<LoadSDNode>(LCandidate.getNode()))
6153if (FrameIndexSDNode *FINode =
6154 dyn_cast<FrameIndexSDNode>(LNode->getBasePtr().getNode()))
6155Op =MachineOperand::CreateFI(FINode->getIndex());
6156 }
6157
6158if (!Op) {
6159// Create a DBG_VALUE for each decomposed value in ArgRegs to cover Reg
6160auto splitMultiRegDbgValue = [&](ArrayRef<std::pair<Register, TypeSize>>
6161 SplitRegs) {
6162unsignedOffset = 0;
6163for (constauto &RegAndSize : SplitRegs) {
6164// If the expression is already a fragment, the current register
6165// offset+size might extend beyond the fragment. In this case, only
6166// the register bits that are inside the fragment are relevant.
6167int RegFragmentSizeInBits = RegAndSize.second;
6168if (auto ExprFragmentInfo = Expr->getFragmentInfo()) {
6169uint64_t ExprFragmentSizeInBits = ExprFragmentInfo->SizeInBits;
6170// The register is entirely outside the expression fragment,
6171// so is irrelevant for debug info.
6172if (Offset >= ExprFragmentSizeInBits)
6173break;
6174// The register is partially outside the expression fragment, only
6175// the low bits within the fragment are relevant for debug info.
6176if (Offset + RegFragmentSizeInBits > ExprFragmentSizeInBits) {
6177 RegFragmentSizeInBits = ExprFragmentSizeInBits -Offset;
6178 }
6179 }
6180
6181auto FragmentExpr =DIExpression::createFragmentExpression(
6182 Expr,Offset, RegFragmentSizeInBits);
6183Offset += RegAndSize.second;
6184// If a valid fragment expression cannot be created, the variable's
6185// correct value cannot be determined and so it is set as Undef.
6186if (!FragmentExpr) {
6187SDDbgValue *SDV =DAG.getConstantDbgValue(
6188 Variable, Expr,UndefValue::get(V->getType()),DL, SDNodeOrder);
6189DAG.AddDbgValue(SDV,false);
6190continue;
6191 }
6192MachineInstr *NewMI =
6193 MakeVRegDbgValue(RegAndSize.first, *FragmentExpr,
6194 Kind != FuncArgumentDbgValueKind::Value);
6195FuncInfo.ArgDbgValues.push_back(NewMI);
6196 }
6197 };
6198
6199// Check if ValueMap has reg number.
6200DenseMap<const Value *, Register>::const_iterator
6201 VMI =FuncInfo.ValueMap.find(V);
6202if (VMI !=FuncInfo.ValueMap.end()) {
6203constauto &TLI =DAG.getTargetLoweringInfo();
6204RegsForValue RFV(V->getContext(), TLI,DAG.getDataLayout(), VMI->second,
6205V->getType(), std::nullopt);
6206if (RFV.occupiesMultipleRegs()) {
6207 splitMultiRegDbgValue(RFV.getRegsAndSizes());
6208returntrue;
6209 }
6210
6211Op =MachineOperand::CreateReg(VMI->second,false);
6212 IsIndirect =Kind != FuncArgumentDbgValueKind::Value;
6213 }elseif (ArgRegsAndSizes.size() > 1) {
6214// This was split due to the calling convention, and no virtual register
6215// mapping exists for the value.
6216 splitMultiRegDbgValue(ArgRegsAndSizes);
6217returntrue;
6218 }
6219 }
6220
6221if (!Op)
6222returnfalse;
6223
6224assert(Variable->isValidLocationForIntrinsic(DL) &&
6225"Expected inlined-at fields to agree");
6226MachineInstr *NewMI =nullptr;
6227
6228if (Op->isReg())
6229 NewMI = MakeVRegDbgValue(Op->getReg(), Expr, IsIndirect);
6230else
6231 NewMI =BuildMI(MF,DL,TII->get(TargetOpcode::DBG_VALUE),true, *Op,
6232 Variable, Expr);
6233
6234// Otherwise, use ArgDbgValues.
6235FuncInfo.ArgDbgValues.push_back(NewMI);
6236returntrue;
6237}
6238
6239/// Return the appropriate SDDbgValue based on N.
6240SDDbgValue *SelectionDAGBuilder::getDbgValue(SDValueN,
6241DILocalVariable *Variable,
6242DIExpression *Expr,
6243constDebugLoc &dl,
6244unsigned DbgSDNodeOrder) {
6245if (auto *FISDN = dyn_cast<FrameIndexSDNode>(N.getNode())) {
6246// Construct a FrameIndexDbgValue for FrameIndexSDNodes so we can describe
6247// stack slot locations.
6248//
6249// Consider "int x = 0; int *px = &x;". There are two kinds of interesting
6250// debug values here after optimization:
6251//
6252// dbg.value(i32* %px, !"int *px", !DIExpression()), and
6253// dbg.value(i32* %px, !"int x", !DIExpression(DW_OP_deref))
6254//
6255// Both describe the direct values of their associated variables.
6256returnDAG.getFrameIndexDbgValue(Variable, Expr, FISDN->getIndex(),
6257/*IsIndirect*/false, dl, DbgSDNodeOrder);
6258 }
6259returnDAG.getDbgValue(Variable, Expr,N.getNode(),N.getResNo(),
6260/*IsIndirect*/false, dl, DbgSDNodeOrder);
6261}
6262
6263staticunsignedFixedPointIntrinsicToOpcode(unsigned Intrinsic) {
6264switch (Intrinsic) {
6265case Intrinsic::smul_fix:
6266returnISD::SMULFIX;
6267case Intrinsic::umul_fix:
6268returnISD::UMULFIX;
6269case Intrinsic::smul_fix_sat:
6270returnISD::SMULFIXSAT;
6271case Intrinsic::umul_fix_sat:
6272returnISD::UMULFIXSAT;
6273case Intrinsic::sdiv_fix:
6274returnISD::SDIVFIX;
6275case Intrinsic::udiv_fix:
6276returnISD::UDIVFIX;
6277case Intrinsic::sdiv_fix_sat:
6278returnISD::SDIVFIXSAT;
6279case Intrinsic::udiv_fix_sat:
6280returnISD::UDIVFIXSAT;
6281default:
6282llvm_unreachable("Unhandled fixed point intrinsic");
6283 }
6284}
6285
6286void SelectionDAGBuilder::lowerCallToExternalSymbol(constCallInst &I,
6287constchar *FunctionName) {
6288assert(FunctionName &&"FunctionName must not be nullptr");
6289SDValueCallee =DAG.getExternalSymbol(
6290 FunctionName,
6291DAG.getTargetLoweringInfo().getPointerTy(DAG.getDataLayout()));
6292LowerCallTo(I, Callee,I.isTailCall(),I.isMustTailCall());
6293}
6294
6295/// Given a @llvm.call.preallocated.setup, return the corresponding
6296/// preallocated call.
6297staticconstCallBase *FindPreallocatedCall(constValue *PreallocatedSetup) {
6298assert(cast<CallBase>(PreallocatedSetup)
6299 ->getCalledFunction()
6300 ->getIntrinsicID() == Intrinsic::call_preallocated_setup &&
6301"expected call_preallocated_setup Value");
6302for (constauto *U : PreallocatedSetup->users()) {
6303auto *UseCall = cast<CallBase>(U);
6304constFunction *Fn = UseCall->getCalledFunction();
6305if (!Fn || Fn->getIntrinsicID() != Intrinsic::call_preallocated_arg) {
6306return UseCall;
6307 }
6308 }
6309llvm_unreachable("expected corresponding call to preallocated setup/arg");
6310}
6311
6312/// If DI is a debug value with an EntryValue expression, lower it using the
6313/// corresponding physical register of the associated Argument value
6314/// (guaranteed to exist by the verifier).
6315bool SelectionDAGBuilder::visitEntryValueDbgValue(
6316ArrayRef<const Value *> Values,DILocalVariable *Variable,
6317DIExpression *Expr,DebugLoc DbgLoc) {
6318if (!Expr->isEntryValue() || !hasSingleElement(Values))
6319returnfalse;
6320
6321// These properties are guaranteed by the verifier.
6322constArgument *Arg = cast<Argument>(Values[0]);
6323assert(Arg->hasAttribute(Attribute::AttrKind::SwiftAsync));
6324
6325auto ArgIt =FuncInfo.ValueMap.find(Arg);
6326if (ArgIt ==FuncInfo.ValueMap.end()) {
6327LLVM_DEBUG(
6328dbgs() <<"Dropping dbg.value: expression is entry_value but "
6329"couldn't find an associated register for the Argument\n");
6330returntrue;
6331 }
6332Register ArgVReg = ArgIt->getSecond();
6333
6334for (auto [PhysReg, VirtReg] :FuncInfo.RegInfo->liveins())
6335if (ArgVReg == VirtReg || ArgVReg == PhysReg) {
6336SDDbgValue *SDV =DAG.getVRegDbgValue(
6337 Variable, Expr, PhysReg,false/*IsIndidrect*/, DbgLoc, SDNodeOrder);
6338DAG.AddDbgValue(SDV,false/*treat as dbg.declare byval parameter*/);
6339returntrue;
6340 }
6341LLVM_DEBUG(dbgs() <<"Dropping dbg.value: expression is entry_value but "
6342"couldn't find a physical register\n");
6343returntrue;
6344}
6345
6346/// Lower the call to the specified intrinsic function.
6347void SelectionDAGBuilder::visitConvergenceControl(constCallInst &I,
6348unsigned Intrinsic) {
6349SDLoc sdl =getCurSDLoc();
6350switch (Intrinsic) {
6351case Intrinsic::experimental_convergence_anchor:
6352setValue(&I,DAG.getNode(ISD::CONVERGENCECTRL_ANCHOR, sdl, MVT::Untyped));
6353break;
6354case Intrinsic::experimental_convergence_entry:
6355setValue(&I,DAG.getNode(ISD::CONVERGENCECTRL_ENTRY, sdl, MVT::Untyped));
6356break;
6357case Intrinsic::experimental_convergence_loop: {
6358auto Bundle =I.getOperandBundle(LLVMContext::OB_convergencectrl);
6359auto *Token = Bundle->Inputs[0].get();
6360setValue(&I,DAG.getNode(ISD::CONVERGENCECTRL_LOOP, sdl, MVT::Untyped,
6361getValue(Token)));
6362break;
6363 }
6364 }
6365}
6366
6367void SelectionDAGBuilder::visitVectorHistogram(constCallInst &I,
6368unsigned IntrinsicID) {
6369// For now, we're only lowering an 'add' histogram.
6370// We can add others later, e.g. saturating adds, min/max.
6371assert(IntrinsicID == Intrinsic::experimental_vector_histogram_add &&
6372"Tried to lower unsupported histogram type");
6373SDLoc sdl =getCurSDLoc();
6374Value *Ptr =I.getOperand(0);
6375SDValue Inc =getValue(I.getOperand(1));
6376SDValueMask =getValue(I.getOperand(2));
6377
6378constTargetLowering &TLI =DAG.getTargetLoweringInfo();
6379DataLayout TargetDL =DAG.getDataLayout();
6380EVT VT = Inc.getValueType();
6381Align Alignment =DAG.getEVTAlign(VT);
6382
6383constMDNode *Ranges =getRangeMetadata(I);
6384
6385SDValue Root =DAG.getRoot();
6386SDValueBase;
6387SDValueIndex;
6388ISD::MemIndexType IndexType;
6389SDValue Scale;
6390bool UniformBase =getUniformBase(Ptr,Base, Index, IndexType, Scale,this,
6391I.getParent(), VT.getScalarStoreSize());
6392
6393unsigned AS =Ptr->getType()->getScalarType()->getPointerAddressSpace();
6394
6395MachineMemOperand *MMO =DAG.getMachineFunction().getMachineMemOperand(
6396MachinePointerInfo(AS),
6397MachineMemOperand::MOLoad |MachineMemOperand::MOStore,
6398MemoryLocation::UnknownSize, Alignment,I.getAAMetadata(), Ranges);
6399
6400if (!UniformBase) {
6401Base =DAG.getConstant(0, sdl, TLI.getPointerTy(DAG.getDataLayout()));
6402Index =getValue(Ptr);
6403 IndexType =ISD::SIGNED_SCALED;
6404 Scale =
6405DAG.getTargetConstant(1, sdl, TLI.getPointerTy(DAG.getDataLayout()));
6406 }
6407
6408EVT IdxVT =Index.getValueType();
6409EVT EltTy = IdxVT.getVectorElementType();
6410if (TLI.shouldExtendGSIndex(IdxVT, EltTy)) {
6411EVT NewIdxVT = IdxVT.changeVectorElementType(EltTy);
6412Index =DAG.getNode(ISD::SIGN_EXTEND, sdl, NewIdxVT, Index);
6413 }
6414
6415SDValueID =DAG.getTargetConstant(IntrinsicID, sdl, MVT::i32);
6416
6417SDValue Ops[] = {Root, Inc,Mask,Base,Index, Scale,ID};
6418SDValue Histogram =DAG.getMaskedHistogram(DAG.getVTList(MVT::Other), VT, sdl,
6419 Ops, MMO, IndexType);
6420
6421setValue(&I, Histogram);
6422DAG.setRoot(Histogram);
6423}
6424
6425void SelectionDAGBuilder::visitVectorExtractLastActive(constCallInst &I,
6426unsigned Intrinsic) {
6427assert(Intrinsic == Intrinsic::experimental_vector_extract_last_active &&
6428"Tried lowering invalid vector extract last");
6429SDLoc sdl =getCurSDLoc();
6430constDataLayout &Layout =DAG.getDataLayout();
6431SDValueData =getValue(I.getOperand(0));
6432SDValueMask =getValue(I.getOperand(1));
6433
6434constTargetLowering &TLI =DAG.getTargetLoweringInfo();
6435EVT ResVT = TLI.getValueType(Layout,I.getType());
6436
6437EVT ExtVT = TLI.getVectorIdxTy(Layout);
6438SDValueIdx =DAG.getNode(ISD::VECTOR_FIND_LAST_ACTIVE, sdl, ExtVT, Mask);
6439SDValueResult =DAG.getNode(ISD::EXTRACT_VECTOR_ELT, sdl, ResVT,Data,Idx);
6440
6441Value *Default =I.getOperand(2);
6442if (!isa<PoisonValue>(Default) && !isa<UndefValue>(Default)) {
6443SDValue PassThru =getValue(Default);
6444EVT BoolVT =Mask.getValueType().getScalarType();
6445SDValue AnyActive =DAG.getNode(ISD::VECREDUCE_OR, sdl, BoolVT, Mask);
6446Result =DAG.getSelect(sdl, ResVT, AnyActive, Result, PassThru);
6447 }
6448
6449setValue(&I, Result);
6450}
6451
6452/// Lower the call to the specified intrinsic function.
6453void SelectionDAGBuilder::visitIntrinsicCall(constCallInst &I,
6454unsigned Intrinsic) {
6455constTargetLowering &TLI =DAG.getTargetLoweringInfo();
6456SDLoc sdl =getCurSDLoc();
6457DebugLoc dl =getCurDebugLoc();
6458SDValue Res;
6459
6460SDNodeFlagsFlags;
6461if (auto *FPOp = dyn_cast<FPMathOperator>(&I))
6462Flags.copyFMF(*FPOp);
6463
6464switch (Intrinsic) {
6465default:
6466// By default, turn this into a target intrinsic node.
6467 visitTargetIntrinsic(I, Intrinsic);
6468return;
6469case Intrinsic::vscale: {
6470EVT VT = TLI.getValueType(DAG.getDataLayout(),I.getType());
6471setValue(&I,DAG.getVScale(sdl, VT,APInt(VT.getSizeInBits(), 1)));
6472return;
6473 }
6474case Intrinsic::vastart: visitVAStart(I);return;
6475case Intrinsic::vaend: visitVAEnd(I);return;
6476case Intrinsic::vacopy: visitVACopy(I);return;
6477case Intrinsic::returnaddress:
6478setValue(&I,DAG.getNode(ISD::RETURNADDR, sdl,
6479 TLI.getValueType(DAG.getDataLayout(),I.getType()),
6480getValue(I.getArgOperand(0))));
6481return;
6482case Intrinsic::addressofreturnaddress:
6483setValue(&I,
6484DAG.getNode(ISD::ADDROFRETURNADDR, sdl,
6485 TLI.getValueType(DAG.getDataLayout(),I.getType())));
6486return;
6487case Intrinsic::sponentry:
6488setValue(&I,
6489DAG.getNode(ISD::SPONENTRY, sdl,
6490 TLI.getValueType(DAG.getDataLayout(),I.getType())));
6491return;
6492case Intrinsic::frameaddress:
6493setValue(&I,DAG.getNode(ISD::FRAMEADDR, sdl,
6494 TLI.getFrameIndexTy(DAG.getDataLayout()),
6495getValue(I.getArgOperand(0))));
6496return;
6497case Intrinsic::read_volatile_register:
6498case Intrinsic::read_register: {
6499Value *Reg =I.getArgOperand(0);
6500SDValue Chain =getRoot();
6501SDValueRegName =
6502DAG.getMDNode(cast<MDNode>(cast<MetadataAsValue>(Reg)->getMetadata()));
6503EVT VT = TLI.getValueType(DAG.getDataLayout(),I.getType());
6504 Res =DAG.getNode(ISD::READ_REGISTER, sdl,
6505DAG.getVTList(VT, MVT::Other), Chain,RegName);
6506setValue(&I, Res);
6507DAG.setRoot(Res.getValue(1));
6508return;
6509 }
6510case Intrinsic::write_register: {
6511Value *Reg =I.getArgOperand(0);
6512Value *RegValue =I.getArgOperand(1);
6513SDValue Chain =getRoot();
6514SDValueRegName =
6515DAG.getMDNode(cast<MDNode>(cast<MetadataAsValue>(Reg)->getMetadata()));
6516DAG.setRoot(DAG.getNode(ISD::WRITE_REGISTER, sdl, MVT::Other, Chain,
6517RegName,getValue(RegValue)));
6518return;
6519 }
6520case Intrinsic::memcpy: {
6521constauto &MCI = cast<MemCpyInst>(I);
6522SDValue Op1 =getValue(I.getArgOperand(0));
6523SDValue Op2 =getValue(I.getArgOperand(1));
6524SDValue Op3 =getValue(I.getArgOperand(2));
6525// @llvm.memcpy defines 0 and 1 to both mean no alignment.
6526Align DstAlign = MCI.getDestAlign().valueOrOne();
6527Align SrcAlign = MCI.getSourceAlign().valueOrOne();
6528Align Alignment = std::min(DstAlign, SrcAlign);
6529bool isVol = MCI.isVolatile();
6530// FIXME: Support passing different dest/src alignments to the memcpy DAG
6531// node.
6532SDValue Root = isVol ?getRoot() :getMemoryRoot();
6533SDValue MC =DAG.getMemcpy(Root, sdl, Op1, Op2, Op3, Alignment, isVol,
6534/* AlwaysInline */false, &I, std::nullopt,
6535MachinePointerInfo(I.getArgOperand(0)),
6536MachinePointerInfo(I.getArgOperand(1)),
6537I.getAAMetadata(),BatchAA);
6538 updateDAGForMaybeTailCall(MC);
6539return;
6540 }
6541case Intrinsic::memcpy_inline: {
6542constauto &MCI = cast<MemCpyInlineInst>(I);
6543SDValue Dst =getValue(I.getArgOperand(0));
6544SDValue Src =getValue(I.getArgOperand(1));
6545SDValueSize =getValue(I.getArgOperand(2));
6546assert(isa<ConstantSDNode>(Size) &&"memcpy_inline needs constant size");
6547// @llvm.memcpy.inline defines 0 and 1 to both mean no alignment.
6548Align DstAlign = MCI.getDestAlign().valueOrOne();
6549Align SrcAlign = MCI.getSourceAlign().valueOrOne();
6550Align Alignment = std::min(DstAlign, SrcAlign);
6551bool isVol = MCI.isVolatile();
6552// FIXME: Support passing different dest/src alignments to the memcpy DAG
6553// node.
6554SDValue MC =DAG.getMemcpy(getRoot(), sdl, Dst, Src,Size, Alignment, isVol,
6555/* AlwaysInline */true, &I, std::nullopt,
6556MachinePointerInfo(I.getArgOperand(0)),
6557MachinePointerInfo(I.getArgOperand(1)),
6558I.getAAMetadata(),BatchAA);
6559 updateDAGForMaybeTailCall(MC);
6560return;
6561 }
6562case Intrinsic::memset: {
6563constauto &MSI = cast<MemSetInst>(I);
6564SDValue Op1 =getValue(I.getArgOperand(0));
6565SDValue Op2 =getValue(I.getArgOperand(1));
6566SDValue Op3 =getValue(I.getArgOperand(2));
6567// @llvm.memset defines 0 and 1 to both mean no alignment.
6568Align Alignment = MSI.getDestAlign().valueOrOne();
6569bool isVol = MSI.isVolatile();
6570SDValue Root = isVol ?getRoot() :getMemoryRoot();
6571SDValue MS =DAG.getMemset(
6572 Root, sdl, Op1, Op2, Op3, Alignment, isVol,/* AlwaysInline */false,
6573 &I,MachinePointerInfo(I.getArgOperand(0)),I.getAAMetadata());
6574 updateDAGForMaybeTailCall(MS);
6575return;
6576 }
6577case Intrinsic::memset_inline: {
6578constauto &MSII = cast<MemSetInlineInst>(I);
6579SDValue Dst =getValue(I.getArgOperand(0));
6580SDValueValue =getValue(I.getArgOperand(1));
6581SDValueSize =getValue(I.getArgOperand(2));
6582assert(isa<ConstantSDNode>(Size) &&"memset_inline needs constant size");
6583// @llvm.memset defines 0 and 1 to both mean no alignment.
6584Align DstAlign = MSII.getDestAlign().valueOrOne();
6585bool isVol = MSII.isVolatile();
6586SDValue Root = isVol ?getRoot() :getMemoryRoot();
6587SDValue MC =DAG.getMemset(Root, sdl, Dst,Value,Size, DstAlign, isVol,
6588/* AlwaysInline */true, &I,
6589MachinePointerInfo(I.getArgOperand(0)),
6590I.getAAMetadata());
6591 updateDAGForMaybeTailCall(MC);
6592return;
6593 }
6594case Intrinsic::memmove: {
6595constauto &MMI = cast<MemMoveInst>(I);
6596SDValue Op1 =getValue(I.getArgOperand(0));
6597SDValue Op2 =getValue(I.getArgOperand(1));
6598SDValue Op3 =getValue(I.getArgOperand(2));
6599// @llvm.memmove defines 0 and 1 to both mean no alignment.
6600Align DstAlign = MMI.getDestAlign().valueOrOne();
6601Align SrcAlign = MMI.getSourceAlign().valueOrOne();
6602Align Alignment = std::min(DstAlign, SrcAlign);
6603bool isVol = MMI.isVolatile();
6604// FIXME: Support passing different dest/src alignments to the memmove DAG
6605// node.
6606SDValue Root = isVol ?getRoot() :getMemoryRoot();
6607SDValue MM =DAG.getMemmove(Root, sdl, Op1, Op2, Op3, Alignment, isVol, &I,
6608/* OverrideTailCall */ std::nullopt,
6609MachinePointerInfo(I.getArgOperand(0)),
6610MachinePointerInfo(I.getArgOperand(1)),
6611I.getAAMetadata(),BatchAA);
6612 updateDAGForMaybeTailCall(MM);
6613return;
6614 }
6615case Intrinsic::memcpy_element_unordered_atomic: {
6616constAtomicMemCpyInst &MI = cast<AtomicMemCpyInst>(I);
6617SDValue Dst =getValue(MI.getRawDest());
6618SDValue Src =getValue(MI.getRawSource());
6619SDValueLength =getValue(MI.getLength());
6620
6621Type *LengthTy =MI.getLength()->getType();
6622unsigned ElemSz =MI.getElementSizeInBytes();
6623bool isTC =I.isTailCall() &&isInTailCallPosition(I,DAG.getTarget());
6624SDValue MC =
6625DAG.getAtomicMemcpy(getRoot(), sdl, Dst, Src,Length, LengthTy, ElemSz,
6626 isTC,MachinePointerInfo(MI.getRawDest()),
6627MachinePointerInfo(MI.getRawSource()));
6628 updateDAGForMaybeTailCall(MC);
6629return;
6630 }
6631case Intrinsic::memmove_element_unordered_atomic: {
6632auto &MI = cast<AtomicMemMoveInst>(I);
6633SDValue Dst =getValue(MI.getRawDest());
6634SDValue Src =getValue(MI.getRawSource());
6635SDValueLength =getValue(MI.getLength());
6636
6637Type *LengthTy =MI.getLength()->getType();
6638unsigned ElemSz =MI.getElementSizeInBytes();
6639bool isTC =I.isTailCall() &&isInTailCallPosition(I,DAG.getTarget());
6640SDValue MC =
6641DAG.getAtomicMemmove(getRoot(), sdl, Dst, Src,Length, LengthTy, ElemSz,
6642 isTC,MachinePointerInfo(MI.getRawDest()),
6643MachinePointerInfo(MI.getRawSource()));
6644 updateDAGForMaybeTailCall(MC);
6645return;
6646 }
6647case Intrinsic::memset_element_unordered_atomic: {
6648auto &MI = cast<AtomicMemSetInst>(I);
6649SDValue Dst =getValue(MI.getRawDest());
6650SDValue Val =getValue(MI.getValue());
6651SDValueLength =getValue(MI.getLength());
6652
6653Type *LengthTy =MI.getLength()->getType();
6654unsigned ElemSz =MI.getElementSizeInBytes();
6655bool isTC =I.isTailCall() &&isInTailCallPosition(I,DAG.getTarget());
6656SDValue MC =
6657DAG.getAtomicMemset(getRoot(), sdl, Dst, Val,Length, LengthTy, ElemSz,
6658 isTC,MachinePointerInfo(MI.getRawDest()));
6659 updateDAGForMaybeTailCall(MC);
6660return;
6661 }
6662case Intrinsic::call_preallocated_setup: {
6663constCallBase *PreallocatedCall =FindPreallocatedCall(&I);
6664SDValue SrcValue =DAG.getSrcValue(PreallocatedCall);
6665SDValue Res =DAG.getNode(ISD::PREALLOCATED_SETUP, sdl, MVT::Other,
6666getRoot(), SrcValue);
6667setValue(&I, Res);
6668DAG.setRoot(Res);
6669return;
6670 }
6671case Intrinsic::call_preallocated_arg: {
6672constCallBase *PreallocatedCall =FindPreallocatedCall(I.getOperand(0));
6673SDValue SrcValue =DAG.getSrcValue(PreallocatedCall);
6674SDValue Ops[3];
6675 Ops[0] =getRoot();
6676 Ops[1] = SrcValue;
6677 Ops[2] =DAG.getTargetConstant(*cast<ConstantInt>(I.getArgOperand(1)), sdl,
6678 MVT::i32);// arg index
6679SDValue Res =DAG.getNode(
6680ISD::PREALLOCATED_ARG, sdl,
6681DAG.getVTList(TLI.getPointerTy(DAG.getDataLayout()), MVT::Other), Ops);
6682setValue(&I, Res);
6683DAG.setRoot(Res.getValue(1));
6684return;
6685 }
6686case Intrinsic::dbg_declare: {
6687constauto &DI = cast<DbgDeclareInst>(I);
6688// Debug intrinsics are handled separately in assignment tracking mode.
6689// Some intrinsics are handled right after Argument lowering.
6690if (AssignmentTrackingEnabled ||
6691FuncInfo.PreprocessedDbgDeclares.count(&DI))
6692return;
6693LLVM_DEBUG(dbgs() <<"SelectionDAG visiting dbg_declare: " << DI <<"\n");
6694DILocalVariable *Variable = DI.getVariable();
6695DIExpression *Expression = DI.getExpression();
6696dropDanglingDebugInfo(Variable,Expression);
6697// Assume dbg.declare can not currently use DIArgList, i.e.
6698// it is non-variadic.
6699assert(!DI.hasArgList() &&"Only dbg.value should currently use DIArgList");
6700handleDebugDeclare(DI.getVariableLocationOp(0), Variable,Expression,
6701 DI.getDebugLoc());
6702return;
6703 }
6704case Intrinsic::dbg_label: {
6705constDbgLabelInst &DI = cast<DbgLabelInst>(I);
6706DILabel *Label = DI.getLabel();
6707assert(Label &&"Missing label");
6708
6709SDDbgLabel *SDV;
6710 SDV =DAG.getDbgLabel(Label, dl, SDNodeOrder);
6711DAG.AddDbgLabel(SDV);
6712return;
6713 }
6714case Intrinsic::dbg_assign: {
6715// Debug intrinsics are handled separately in assignment tracking mode.
6716if (AssignmentTrackingEnabled)
6717return;
6718// If assignment tracking hasn't been enabled then fall through and treat
6719// the dbg.assign as a dbg.value.
6720 [[fallthrough]];
6721 }
6722case Intrinsic::dbg_value: {
6723// Debug intrinsics are handled separately in assignment tracking mode.
6724if (AssignmentTrackingEnabled)
6725return;
6726constDbgValueInst &DI = cast<DbgValueInst>(I);
6727assert(DI.getVariable() &&"Missing variable");
6728
6729DILocalVariable *Variable = DI.getVariable();
6730DIExpression *Expression = DI.getExpression();
6731dropDanglingDebugInfo(Variable,Expression);
6732
6733if (DI.isKillLocation()) {
6734handleKillDebugValue(Variable,Expression, DI.getDebugLoc(), SDNodeOrder);
6735return;
6736 }
6737
6738SmallVector<Value *, 4> Values(DI.getValues());
6739if (Values.empty())
6740return;
6741
6742bool IsVariadic = DI.hasArgList();
6743if (!handleDebugValue(Values, Variable,Expression, DI.getDebugLoc(),
6744 SDNodeOrder, IsVariadic))
6745addDanglingDebugInfo(Values, Variable,Expression, IsVariadic,
6746 DI.getDebugLoc(), SDNodeOrder);
6747return;
6748 }
6749
6750case Intrinsic::eh_typeid_for: {
6751// Find the type id for the given typeinfo.
6752GlobalValue *GV =ExtractTypeInfo(I.getArgOperand(0));
6753unsignedTypeID =DAG.getMachineFunction().getTypeIDFor(GV);
6754 Res =DAG.getConstant(TypeID, sdl, MVT::i32);
6755setValue(&I, Res);
6756return;
6757 }
6758
6759case Intrinsic::eh_return_i32:
6760case Intrinsic::eh_return_i64:
6761DAG.getMachineFunction().setCallsEHReturn(true);
6762DAG.setRoot(DAG.getNode(ISD::EH_RETURN, sdl,
6763 MVT::Other,
6764getControlRoot(),
6765getValue(I.getArgOperand(0)),
6766getValue(I.getArgOperand(1))));
6767return;
6768case Intrinsic::eh_unwind_init:
6769DAG.getMachineFunction().setCallsUnwindInit(true);
6770return;
6771case Intrinsic::eh_dwarf_cfa:
6772setValue(&I,DAG.getNode(ISD::EH_DWARF_CFA, sdl,
6773 TLI.getPointerTy(DAG.getDataLayout()),
6774getValue(I.getArgOperand(0))));
6775return;
6776case Intrinsic::eh_sjlj_callsite: {
6777ConstantInt *CI = cast<ConstantInt>(I.getArgOperand(0));
6778assert(FuncInfo.getCurrentCallSite() == 0 &&"Overlapping call sites!");
6779
6780FuncInfo.setCurrentCallSite(CI->getZExtValue());
6781return;
6782 }
6783case Intrinsic::eh_sjlj_functioncontext: {
6784// Get and store the index of the function context.
6785MachineFrameInfo &MFI =DAG.getMachineFunction().getFrameInfo();
6786AllocaInst *FnCtx =
6787 cast<AllocaInst>(I.getArgOperand(0)->stripPointerCasts());
6788int FI =FuncInfo.StaticAllocaMap[FnCtx];
6789 MFI.setFunctionContextIndex(FI);
6790return;
6791 }
6792case Intrinsic::eh_sjlj_setjmp: {
6793SDValue Ops[2];
6794 Ops[0] =getRoot();
6795 Ops[1] =getValue(I.getArgOperand(0));
6796SDValueOp =DAG.getNode(ISD::EH_SJLJ_SETJMP, sdl,
6797DAG.getVTList(MVT::i32, MVT::Other), Ops);
6798setValue(&I,Op.getValue(0));
6799DAG.setRoot(Op.getValue(1));
6800return;
6801 }
6802case Intrinsic::eh_sjlj_longjmp:
6803DAG.setRoot(DAG.getNode(ISD::EH_SJLJ_LONGJMP, sdl, MVT::Other,
6804getRoot(),getValue(I.getArgOperand(0))));
6805return;
6806case Intrinsic::eh_sjlj_setup_dispatch:
6807DAG.setRoot(DAG.getNode(ISD::EH_SJLJ_SETUP_DISPATCH, sdl, MVT::Other,
6808getRoot()));
6809return;
6810case Intrinsic::masked_gather:
6811 visitMaskedGather(I);
6812return;
6813case Intrinsic::masked_load:
6814 visitMaskedLoad(I);
6815return;
6816case Intrinsic::masked_scatter:
6817 visitMaskedScatter(I);
6818return;
6819case Intrinsic::masked_store:
6820 visitMaskedStore(I);
6821return;
6822case Intrinsic::masked_expandload:
6823 visitMaskedLoad(I,true/* IsExpanding */);
6824return;
6825case Intrinsic::masked_compressstore:
6826 visitMaskedStore(I,true/* IsCompressing */);
6827return;
6828case Intrinsic::powi:
6829setValue(&I,ExpandPowI(sdl,getValue(I.getArgOperand(0)),
6830getValue(I.getArgOperand(1)),DAG));
6831return;
6832case Intrinsic::log:
6833setValue(&I,expandLog(sdl,getValue(I.getArgOperand(0)),DAG, TLI, Flags));
6834return;
6835case Intrinsic::log2:
6836setValue(&I,
6837expandLog2(sdl,getValue(I.getArgOperand(0)),DAG, TLI, Flags));
6838return;
6839case Intrinsic::log10:
6840setValue(&I,
6841expandLog10(sdl,getValue(I.getArgOperand(0)),DAG, TLI, Flags));
6842return;
6843case Intrinsic::exp:
6844setValue(&I,expandExp(sdl,getValue(I.getArgOperand(0)),DAG, TLI, Flags));
6845return;
6846case Intrinsic::exp2:
6847setValue(&I,
6848expandExp2(sdl,getValue(I.getArgOperand(0)),DAG, TLI, Flags));
6849return;
6850case Intrinsic::pow:
6851setValue(&I,expandPow(sdl,getValue(I.getArgOperand(0)),
6852getValue(I.getArgOperand(1)),DAG, TLI, Flags));
6853return;
6854case Intrinsic::sqrt:
6855case Intrinsic::fabs:
6856case Intrinsic::sin:
6857case Intrinsic::cos:
6858case Intrinsic::tan:
6859case Intrinsic::asin:
6860case Intrinsic::acos:
6861case Intrinsic::atan:
6862case Intrinsic::sinh:
6863case Intrinsic::cosh:
6864case Intrinsic::tanh:
6865case Intrinsic::exp10:
6866case Intrinsic::floor:
6867case Intrinsic::ceil:
6868case Intrinsic::trunc:
6869case Intrinsic::rint:
6870case Intrinsic::nearbyint:
6871case Intrinsic::round:
6872case Intrinsic::roundeven:
6873case Intrinsic::canonicalize: {
6874unsigned Opcode;
6875// clang-format off
6876switch (Intrinsic) {
6877default:llvm_unreachable("Impossible intrinsic");// Can't reach here.
6878case Intrinsic::sqrt: Opcode =ISD::FSQRT;break;
6879case Intrinsic::fabs: Opcode =ISD::FABS;break;
6880case Intrinsic::sin: Opcode =ISD::FSIN;break;
6881case Intrinsic::cos: Opcode =ISD::FCOS;break;
6882case Intrinsic::tan: Opcode =ISD::FTAN;break;
6883case Intrinsic::asin: Opcode =ISD::FASIN;break;
6884case Intrinsic::acos: Opcode =ISD::FACOS;break;
6885case Intrinsic::atan: Opcode =ISD::FATAN;break;
6886case Intrinsic::sinh: Opcode =ISD::FSINH;break;
6887case Intrinsic::cosh: Opcode =ISD::FCOSH;break;
6888case Intrinsic::tanh: Opcode =ISD::FTANH;break;
6889case Intrinsic::exp10: Opcode =ISD::FEXP10;break;
6890case Intrinsic::floor: Opcode =ISD::FFLOOR;break;
6891case Intrinsic::ceil: Opcode =ISD::FCEIL;break;
6892case Intrinsic::trunc: Opcode =ISD::FTRUNC;break;
6893case Intrinsic::rint: Opcode =ISD::FRINT;break;
6894case Intrinsic::nearbyint: Opcode =ISD::FNEARBYINT;break;
6895case Intrinsic::round: Opcode =ISD::FROUND;break;
6896case Intrinsic::roundeven: Opcode =ISD::FROUNDEVEN;break;
6897case Intrinsic::canonicalize: Opcode =ISD::FCANONICALIZE;break;
6898 }
6899// clang-format on
6900
6901setValue(&I,DAG.getNode(Opcode, sdl,
6902getValue(I.getArgOperand(0)).getValueType(),
6903getValue(I.getArgOperand(0)), Flags));
6904return;
6905 }
6906case Intrinsic::atan2:
6907setValue(&I,DAG.getNode(ISD::FATAN2, sdl,
6908getValue(I.getArgOperand(0)).getValueType(),
6909getValue(I.getArgOperand(0)),
6910getValue(I.getArgOperand(1)), Flags));
6911return;
6912case Intrinsic::lround:
6913case Intrinsic::llround:
6914case Intrinsic::lrint:
6915case Intrinsic::llrint: {
6916unsigned Opcode;
6917// clang-format off
6918switch (Intrinsic) {
6919default:llvm_unreachable("Impossible intrinsic");// Can't reach here.
6920case Intrinsic::lround: Opcode =ISD::LROUND;break;
6921case Intrinsic::llround: Opcode =ISD::LLROUND;break;
6922case Intrinsic::lrint: Opcode =ISD::LRINT;break;
6923case Intrinsic::llrint: Opcode =ISD::LLRINT;break;
6924 }
6925// clang-format on
6926
6927EVT RetVT = TLI.getValueType(DAG.getDataLayout(),I.getType());
6928setValue(&I,DAG.getNode(Opcode, sdl, RetVT,
6929getValue(I.getArgOperand(0))));
6930return;
6931 }
6932case Intrinsic::minnum:
6933setValue(&I,DAG.getNode(ISD::FMINNUM, sdl,
6934getValue(I.getArgOperand(0)).getValueType(),
6935getValue(I.getArgOperand(0)),
6936getValue(I.getArgOperand(1)), Flags));
6937return;
6938case Intrinsic::maxnum:
6939setValue(&I,DAG.getNode(ISD::FMAXNUM, sdl,
6940getValue(I.getArgOperand(0)).getValueType(),
6941getValue(I.getArgOperand(0)),
6942getValue(I.getArgOperand(1)), Flags));
6943return;
6944case Intrinsic::minimum:
6945setValue(&I,DAG.getNode(ISD::FMINIMUM, sdl,
6946getValue(I.getArgOperand(0)).getValueType(),
6947getValue(I.getArgOperand(0)),
6948getValue(I.getArgOperand(1)), Flags));
6949return;
6950case Intrinsic::maximum:
6951setValue(&I,DAG.getNode(ISD::FMAXIMUM, sdl,
6952getValue(I.getArgOperand(0)).getValueType(),
6953getValue(I.getArgOperand(0)),
6954getValue(I.getArgOperand(1)), Flags));
6955return;
6956case Intrinsic::minimumnum:
6957setValue(&I,DAG.getNode(ISD::FMINIMUMNUM, sdl,
6958getValue(I.getArgOperand(0)).getValueType(),
6959getValue(I.getArgOperand(0)),
6960getValue(I.getArgOperand(1)), Flags));
6961return;
6962case Intrinsic::maximumnum:
6963setValue(&I,DAG.getNode(ISD::FMAXIMUMNUM, sdl,
6964getValue(I.getArgOperand(0)).getValueType(),
6965getValue(I.getArgOperand(0)),
6966getValue(I.getArgOperand(1)), Flags));
6967return;
6968case Intrinsic::copysign:
6969setValue(&I,DAG.getNode(ISD::FCOPYSIGN, sdl,
6970getValue(I.getArgOperand(0)).getValueType(),
6971getValue(I.getArgOperand(0)),
6972getValue(I.getArgOperand(1)), Flags));
6973return;
6974case Intrinsic::ldexp:
6975setValue(&I,DAG.getNode(ISD::FLDEXP, sdl,
6976getValue(I.getArgOperand(0)).getValueType(),
6977getValue(I.getArgOperand(0)),
6978getValue(I.getArgOperand(1)), Flags));
6979return;
6980case Intrinsic::sincos:
6981case Intrinsic::frexp: {
6982unsigned Opcode;
6983switch (Intrinsic) {
6984default:
6985llvm_unreachable("unexpected intrinsic");
6986case Intrinsic::sincos:
6987 Opcode =ISD::FSINCOS;
6988break;
6989case Intrinsic::frexp:
6990 Opcode =ISD::FFREXP;
6991break;
6992 }
6993SmallVector<EVT, 2> ValueVTs;
6994ComputeValueVTs(TLI,DAG.getDataLayout(),I.getType(), ValueVTs);
6995SDVTList VTs =DAG.getVTList(ValueVTs);
6996setValue(
6997 &I,DAG.getNode(Opcode, sdl, VTs,getValue(I.getArgOperand(0)), Flags));
6998return;
6999 }
7000case Intrinsic::arithmetic_fence: {
7001setValue(&I,DAG.getNode(ISD::ARITH_FENCE, sdl,
7002getValue(I.getArgOperand(0)).getValueType(),
7003getValue(I.getArgOperand(0)), Flags));
7004return;
7005 }
7006case Intrinsic::fma:
7007setValue(&I,DAG.getNode(
7008ISD::FMA, sdl,getValue(I.getArgOperand(0)).getValueType(),
7009getValue(I.getArgOperand(0)),getValue(I.getArgOperand(1)),
7010getValue(I.getArgOperand(2)), Flags));
7011return;
7012#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
7013 case Intrinsic::INTRINSIC:
7014#include "llvm/IR/ConstrainedOps.def"
7015 visitConstrainedFPIntrinsic(cast<ConstrainedFPIntrinsic>(I));
7016return;
7017#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID:
7018#include "llvm/IR/VPIntrinsics.def"
7019 visitVectorPredicationIntrinsic(cast<VPIntrinsic>(I));
7020return;
7021case Intrinsic::fptrunc_round: {
7022// Get the last argument, the metadata and convert it to an integer in the
7023// call
7024Metadata *MD = cast<MetadataAsValue>(I.getArgOperand(1))->getMetadata();
7025 std::optional<RoundingMode> RoundMode =
7026convertStrToRoundingMode(cast<MDString>(MD)->getString());
7027
7028EVT VT = TLI.getValueType(DAG.getDataLayout(),I.getType());
7029
7030// Propagate fast-math-flags from IR to node(s).
7031SDNodeFlagsFlags;
7032Flags.copyFMF(*cast<FPMathOperator>(&I));
7033SelectionDAG::FlagInserter FlagsInserter(DAG, Flags);
7034
7035SDValueResult;
7036Result =DAG.getNode(
7037ISD::FPTRUNC_ROUND, sdl, VT,getValue(I.getArgOperand(0)),
7038DAG.getTargetConstant((int)*RoundMode, sdl, MVT::i32));
7039setValue(&I, Result);
7040
7041return;
7042 }
7043case Intrinsic::fmuladd: {
7044EVT VT = TLI.getValueType(DAG.getDataLayout(),I.getType());
7045if (TM.Options.AllowFPOpFusion !=FPOpFusion::Strict &&
7046 TLI.isFMAFasterThanFMulAndFAdd(DAG.getMachineFunction(), VT)) {
7047setValue(&I,DAG.getNode(ISD::FMA, sdl,
7048getValue(I.getArgOperand(0)).getValueType(),
7049getValue(I.getArgOperand(0)),
7050getValue(I.getArgOperand(1)),
7051getValue(I.getArgOperand(2)), Flags));
7052 }else {
7053// TODO: Intrinsic calls should have fast-math-flags.
7054SDValueMul =DAG.getNode(
7055ISD::FMUL, sdl,getValue(I.getArgOperand(0)).getValueType(),
7056getValue(I.getArgOperand(0)),getValue(I.getArgOperand(1)), Flags);
7057SDValueAdd =DAG.getNode(ISD::FADD, sdl,
7058getValue(I.getArgOperand(0)).getValueType(),
7059Mul,getValue(I.getArgOperand(2)), Flags);
7060setValue(&I,Add);
7061 }
7062return;
7063 }
7064case Intrinsic::convert_to_fp16:
7065setValue(&I,DAG.getNode(ISD::BITCAST, sdl, MVT::i16,
7066DAG.getNode(ISD::FP_ROUND, sdl, MVT::f16,
7067getValue(I.getArgOperand(0)),
7068DAG.getTargetConstant(0, sdl,
7069 MVT::i32))));
7070return;
7071case Intrinsic::convert_from_fp16:
7072setValue(&I,DAG.getNode(ISD::FP_EXTEND, sdl,
7073 TLI.getValueType(DAG.getDataLayout(),I.getType()),
7074DAG.getNode(ISD::BITCAST, sdl, MVT::f16,
7075getValue(I.getArgOperand(0)))));
7076return;
7077case Intrinsic::fptosi_sat: {
7078EVT VT = TLI.getValueType(DAG.getDataLayout(),I.getType());
7079setValue(&I,DAG.getNode(ISD::FP_TO_SINT_SAT, sdl, VT,
7080getValue(I.getArgOperand(0)),
7081DAG.getValueType(VT.getScalarType())));
7082return;
7083 }
7084case Intrinsic::fptoui_sat: {
7085EVT VT = TLI.getValueType(DAG.getDataLayout(),I.getType());
7086setValue(&I,DAG.getNode(ISD::FP_TO_UINT_SAT, sdl, VT,
7087getValue(I.getArgOperand(0)),
7088DAG.getValueType(VT.getScalarType())));
7089return;
7090 }
7091case Intrinsic::set_rounding:
7092 Res =DAG.getNode(ISD::SET_ROUNDING, sdl, MVT::Other,
7093 {getRoot(),getValue(I.getArgOperand(0))});
7094setValue(&I, Res);
7095DAG.setRoot(Res.getValue(0));
7096return;
7097case Intrinsic::is_fpclass: {
7098constDataLayout DLayout =DAG.getDataLayout();
7099EVT DestVT = TLI.getValueType(DLayout,I.getType());
7100EVT ArgVT = TLI.getValueType(DLayout,I.getArgOperand(0)->getType());
7101FPClassTestTest =static_cast<FPClassTest>(
7102 cast<ConstantInt>(I.getArgOperand(1))->getZExtValue());
7103MachineFunction &MF =DAG.getMachineFunction();
7104constFunction &F = MF.getFunction();
7105SDValueOp =getValue(I.getArgOperand(0));
7106SDNodeFlagsFlags;
7107Flags.setNoFPExcept(
7108 !F.getAttributes().hasFnAttr(llvm::Attribute::StrictFP));
7109// If ISD::IS_FPCLASS should be expanded, do it right now, because the
7110// expansion can use illegal types. Making expansion early allows
7111// legalizing these types prior to selection.
7112if (!TLI.isOperationLegal(ISD::IS_FPCLASS, ArgVT) &&
7113 !TLI.isOperationCustom(ISD::IS_FPCLASS, ArgVT)) {
7114SDValueResult = TLI.expandIS_FPCLASS(DestVT,Op,Test, Flags, sdl,DAG);
7115setValue(&I, Result);
7116return;
7117 }
7118
7119SDValueCheck =DAG.getTargetConstant(Test, sdl, MVT::i32);
7120SDValueV =DAG.getNode(ISD::IS_FPCLASS, sdl, DestVT, {Op,Check},Flags);
7121setValue(&I, V);
7122return;
7123 }
7124case Intrinsic::get_fpenv: {
7125constDataLayout DLayout =DAG.getDataLayout();
7126EVT EnvVT = TLI.getValueType(DLayout,I.getType());
7127Align TempAlign =DAG.getEVTAlign(EnvVT);
7128SDValue Chain =getRoot();
7129// Use GET_FPENV if it is legal or custom. Otherwise use memory-based node
7130// and temporary storage in stack.
7131if (TLI.isOperationLegalOrCustom(ISD::GET_FPENV, EnvVT)) {
7132 Res =DAG.getNode(
7133ISD::GET_FPENV, sdl,
7134DAG.getVTList(TLI.getValueType(DAG.getDataLayout(),I.getType()),
7135 MVT::Other),
7136 Chain);
7137 }else {
7138SDValue Temp =DAG.CreateStackTemporary(EnvVT, TempAlign.value());
7139int SPFI = cast<FrameIndexSDNode>(Temp.getNode())->getIndex();
7140auto MPI =
7141MachinePointerInfo::getFixedStack(DAG.getMachineFunction(), SPFI);
7142MachineMemOperand *MMO =DAG.getMachineFunction().getMachineMemOperand(
7143 MPI,MachineMemOperand::MOStore,LocationSize::beforeOrAfterPointer(),
7144 TempAlign);
7145 Chain =DAG.getGetFPEnv(Chain, sdl, Temp, EnvVT, MMO);
7146 Res =DAG.getLoad(EnvVT, sdl, Chain, Temp, MPI);
7147 }
7148setValue(&I, Res);
7149DAG.setRoot(Res.getValue(1));
7150return;
7151 }
7152case Intrinsic::set_fpenv: {
7153constDataLayout DLayout =DAG.getDataLayout();
7154SDValue Env =getValue(I.getArgOperand(0));
7155EVT EnvVT = Env.getValueType();
7156Align TempAlign =DAG.getEVTAlign(EnvVT);
7157SDValue Chain =getRoot();
7158// If SET_FPENV is custom or legal, use it. Otherwise use loading
7159// environment from memory.
7160if (TLI.isOperationLegalOrCustom(ISD::SET_FPENV, EnvVT)) {
7161 Chain =DAG.getNode(ISD::SET_FPENV, sdl, MVT::Other, Chain, Env);
7162 }else {
7163// Allocate space in stack, copy environment bits into it and use this
7164// memory in SET_FPENV_MEM.
7165SDValue Temp =DAG.CreateStackTemporary(EnvVT, TempAlign.value());
7166int SPFI = cast<FrameIndexSDNode>(Temp.getNode())->getIndex();
7167auto MPI =
7168MachinePointerInfo::getFixedStack(DAG.getMachineFunction(), SPFI);
7169 Chain =DAG.getStore(Chain, sdl, Env, Temp, MPI, TempAlign,
7170MachineMemOperand::MOStore);
7171MachineMemOperand *MMO =DAG.getMachineFunction().getMachineMemOperand(
7172 MPI,MachineMemOperand::MOLoad,LocationSize::beforeOrAfterPointer(),
7173 TempAlign);
7174 Chain =DAG.getSetFPEnv(Chain, sdl, Temp, EnvVT, MMO);
7175 }
7176DAG.setRoot(Chain);
7177return;
7178 }
7179case Intrinsic::reset_fpenv:
7180DAG.setRoot(DAG.getNode(ISD::RESET_FPENV, sdl, MVT::Other,getRoot()));
7181return;
7182case Intrinsic::get_fpmode:
7183 Res =DAG.getNode(
7184ISD::GET_FPMODE, sdl,
7185DAG.getVTList(TLI.getValueType(DAG.getDataLayout(),I.getType()),
7186 MVT::Other),
7187DAG.getRoot());
7188setValue(&I, Res);
7189DAG.setRoot(Res.getValue(1));
7190return;
7191case Intrinsic::set_fpmode:
7192 Res =DAG.getNode(ISD::SET_FPMODE, sdl, MVT::Other, {DAG.getRoot()},
7193getValue(I.getArgOperand(0)));
7194DAG.setRoot(Res);
7195return;
7196case Intrinsic::reset_fpmode: {
7197 Res =DAG.getNode(ISD::RESET_FPMODE, sdl, MVT::Other,getRoot());
7198DAG.setRoot(Res);
7199return;
7200 }
7201case Intrinsic::pcmarker: {
7202SDValue Tmp =getValue(I.getArgOperand(0));
7203DAG.setRoot(DAG.getNode(ISD::PCMARKER, sdl, MVT::Other,getRoot(), Tmp));
7204return;
7205 }
7206case Intrinsic::readcyclecounter: {
7207SDValueOp =getRoot();
7208 Res =DAG.getNode(ISD::READCYCLECOUNTER, sdl,
7209DAG.getVTList(MVT::i64, MVT::Other),Op);
7210setValue(&I, Res);
7211DAG.setRoot(Res.getValue(1));
7212return;
7213 }
7214case Intrinsic::readsteadycounter: {
7215SDValueOp =getRoot();
7216 Res =DAG.getNode(ISD::READSTEADYCOUNTER, sdl,
7217DAG.getVTList(MVT::i64, MVT::Other),Op);
7218setValue(&I, Res);
7219DAG.setRoot(Res.getValue(1));
7220return;
7221 }
7222case Intrinsic::bitreverse:
7223setValue(&I,DAG.getNode(ISD::BITREVERSE, sdl,
7224getValue(I.getArgOperand(0)).getValueType(),
7225getValue(I.getArgOperand(0))));
7226return;
7227case Intrinsic::bswap:
7228setValue(&I,DAG.getNode(ISD::BSWAP, sdl,
7229getValue(I.getArgOperand(0)).getValueType(),
7230getValue(I.getArgOperand(0))));
7231return;
7232case Intrinsic::cttz: {
7233SDValue Arg =getValue(I.getArgOperand(0));
7234ConstantInt *CI = cast<ConstantInt>(I.getArgOperand(1));
7235EVT Ty = Arg.getValueType();
7236setValue(&I,DAG.getNode(CI->isZero() ?ISD::CTTZ :ISD::CTTZ_ZERO_UNDEF,
7237 sdl, Ty, Arg));
7238return;
7239 }
7240case Intrinsic::ctlz: {
7241SDValue Arg =getValue(I.getArgOperand(0));
7242ConstantInt *CI = cast<ConstantInt>(I.getArgOperand(1));
7243EVT Ty = Arg.getValueType();
7244setValue(&I,DAG.getNode(CI->isZero() ?ISD::CTLZ :ISD::CTLZ_ZERO_UNDEF,
7245 sdl, Ty, Arg));
7246return;
7247 }
7248case Intrinsic::ctpop: {
7249SDValue Arg =getValue(I.getArgOperand(0));
7250EVT Ty = Arg.getValueType();
7251setValue(&I,DAG.getNode(ISD::CTPOP, sdl, Ty, Arg));
7252return;
7253 }
7254case Intrinsic::fshl:
7255case Intrinsic::fshr: {
7256bool IsFSHL =Intrinsic == Intrinsic::fshl;
7257SDValueX =getValue(I.getArgOperand(0));
7258SDValueY =getValue(I.getArgOperand(1));
7259SDValueZ =getValue(I.getArgOperand(2));
7260EVT VT =X.getValueType();
7261
7262if (X ==Y) {
7263auto RotateOpcode = IsFSHL ?ISD::ROTL :ISD::ROTR;
7264setValue(&I,DAG.getNode(RotateOpcode, sdl, VT,X, Z));
7265 }else {
7266auto FunnelOpcode = IsFSHL ?ISD::FSHL :ISD::FSHR;
7267setValue(&I,DAG.getNode(FunnelOpcode, sdl, VT,X,Y, Z));
7268 }
7269return;
7270 }
7271case Intrinsic::sadd_sat: {
7272SDValue Op1 =getValue(I.getArgOperand(0));
7273SDValue Op2 =getValue(I.getArgOperand(1));
7274setValue(&I,DAG.getNode(ISD::SADDSAT, sdl, Op1.getValueType(), Op1, Op2));
7275return;
7276 }
7277case Intrinsic::uadd_sat: {
7278SDValue Op1 =getValue(I.getArgOperand(0));
7279SDValue Op2 =getValue(I.getArgOperand(1));
7280setValue(&I,DAG.getNode(ISD::UADDSAT, sdl, Op1.getValueType(), Op1, Op2));
7281return;
7282 }
7283case Intrinsic::ssub_sat: {
7284SDValue Op1 =getValue(I.getArgOperand(0));
7285SDValue Op2 =getValue(I.getArgOperand(1));
7286setValue(&I,DAG.getNode(ISD::SSUBSAT, sdl, Op1.getValueType(), Op1, Op2));
7287return;
7288 }
7289case Intrinsic::usub_sat: {
7290SDValue Op1 =getValue(I.getArgOperand(0));
7291SDValue Op2 =getValue(I.getArgOperand(1));
7292setValue(&I,DAG.getNode(ISD::USUBSAT, sdl, Op1.getValueType(), Op1, Op2));
7293return;
7294 }
7295case Intrinsic::sshl_sat: {
7296SDValue Op1 =getValue(I.getArgOperand(0));
7297SDValue Op2 =getValue(I.getArgOperand(1));
7298setValue(&I,DAG.getNode(ISD::SSHLSAT, sdl, Op1.getValueType(), Op1, Op2));
7299return;
7300 }
7301case Intrinsic::ushl_sat: {
7302SDValue Op1 =getValue(I.getArgOperand(0));
7303SDValue Op2 =getValue(I.getArgOperand(1));
7304setValue(&I,DAG.getNode(ISD::USHLSAT, sdl, Op1.getValueType(), Op1, Op2));
7305return;
7306 }
7307case Intrinsic::smul_fix:
7308case Intrinsic::umul_fix:
7309case Intrinsic::smul_fix_sat:
7310case Intrinsic::umul_fix_sat: {
7311SDValue Op1 =getValue(I.getArgOperand(0));
7312SDValue Op2 =getValue(I.getArgOperand(1));
7313SDValue Op3 =getValue(I.getArgOperand(2));
7314setValue(&I,DAG.getNode(FixedPointIntrinsicToOpcode(Intrinsic), sdl,
7315 Op1.getValueType(), Op1, Op2, Op3));
7316return;
7317 }
7318case Intrinsic::sdiv_fix:
7319case Intrinsic::udiv_fix:
7320case Intrinsic::sdiv_fix_sat:
7321case Intrinsic::udiv_fix_sat: {
7322SDValue Op1 =getValue(I.getArgOperand(0));
7323SDValue Op2 =getValue(I.getArgOperand(1));
7324SDValue Op3 =getValue(I.getArgOperand(2));
7325setValue(&I,expandDivFix(FixedPointIntrinsicToOpcode(Intrinsic), sdl,
7326 Op1, Op2, Op3,DAG, TLI));
7327return;
7328 }
7329case Intrinsic::smax: {
7330SDValue Op1 =getValue(I.getArgOperand(0));
7331SDValue Op2 =getValue(I.getArgOperand(1));
7332setValue(&I,DAG.getNode(ISD::SMAX, sdl, Op1.getValueType(), Op1, Op2));
7333return;
7334 }
7335case Intrinsic::smin: {
7336SDValue Op1 =getValue(I.getArgOperand(0));
7337SDValue Op2 =getValue(I.getArgOperand(1));
7338setValue(&I,DAG.getNode(ISD::SMIN, sdl, Op1.getValueType(), Op1, Op2));
7339return;
7340 }
7341case Intrinsic::umax: {
7342SDValue Op1 =getValue(I.getArgOperand(0));
7343SDValue Op2 =getValue(I.getArgOperand(1));
7344setValue(&I,DAG.getNode(ISD::UMAX, sdl, Op1.getValueType(), Op1, Op2));
7345return;
7346 }
7347case Intrinsic::umin: {
7348SDValue Op1 =getValue(I.getArgOperand(0));
7349SDValue Op2 =getValue(I.getArgOperand(1));
7350setValue(&I,DAG.getNode(ISD::UMIN, sdl, Op1.getValueType(), Op1, Op2));
7351return;
7352 }
7353case Intrinsic::abs: {
7354// TODO: Preserve "int min is poison" arg in SDAG?
7355SDValue Op1 =getValue(I.getArgOperand(0));
7356setValue(&I,DAG.getNode(ISD::ABS, sdl, Op1.getValueType(), Op1));
7357return;
7358 }
7359case Intrinsic::scmp: {
7360SDValue Op1 =getValue(I.getArgOperand(0));
7361SDValue Op2 =getValue(I.getArgOperand(1));
7362EVT DestVT = TLI.getValueType(DAG.getDataLayout(),I.getType());
7363setValue(&I,DAG.getNode(ISD::SCMP, sdl, DestVT, Op1, Op2));
7364break;
7365 }
7366case Intrinsic::ucmp: {
7367SDValue Op1 =getValue(I.getArgOperand(0));
7368SDValue Op2 =getValue(I.getArgOperand(1));
7369EVT DestVT = TLI.getValueType(DAG.getDataLayout(),I.getType());
7370setValue(&I,DAG.getNode(ISD::UCMP, sdl, DestVT, Op1, Op2));
7371break;
7372 }
7373case Intrinsic::stacksave: {
7374SDValueOp =getRoot();
7375EVT VT = TLI.getValueType(DAG.getDataLayout(),I.getType());
7376 Res =DAG.getNode(ISD::STACKSAVE, sdl,DAG.getVTList(VT, MVT::Other),Op);
7377setValue(&I, Res);
7378DAG.setRoot(Res.getValue(1));
7379return;
7380 }
7381case Intrinsic::stackrestore:
7382 Res =getValue(I.getArgOperand(0));
7383DAG.setRoot(DAG.getNode(ISD::STACKRESTORE, sdl, MVT::Other,getRoot(), Res));
7384return;
7385case Intrinsic::get_dynamic_area_offset: {
7386SDValueOp =getRoot();
7387EVT PtrTy = TLI.getFrameIndexTy(DAG.getDataLayout());
7388EVT ResTy = TLI.getValueType(DAG.getDataLayout(),I.getType());
7389// Result type for @llvm.get.dynamic.area.offset should match PtrTy for
7390// target.
7391if (PtrTy.getFixedSizeInBits() < ResTy.getFixedSizeInBits())
7392report_fatal_error("Wrong result type for @llvm.get.dynamic.area.offset"
7393" intrinsic!");
7394 Res =DAG.getNode(ISD::GET_DYNAMIC_AREA_OFFSET, sdl,DAG.getVTList(ResTy),
7395Op);
7396DAG.setRoot(Op);
7397setValue(&I, Res);
7398return;
7399 }
7400case Intrinsic::stackguard: {
7401MachineFunction &MF =DAG.getMachineFunction();
7402constModule &M = *MF.getFunction().getParent();
7403EVT PtrTy = TLI.getValueType(DAG.getDataLayout(),I.getType());
7404SDValue Chain =getRoot();
7405if (TLI.useLoadStackGuardNode(M)) {
7406 Res =getLoadStackGuard(DAG, sdl, Chain);
7407 Res =DAG.getPtrExtOrTrunc(Res, sdl, PtrTy);
7408 }else {
7409constValue *Global = TLI.getSDagStackGuard(M);
7410AlignAlign =DAG.getDataLayout().getPrefTypeAlign(Global->getType());
7411 Res =DAG.getLoad(PtrTy, sdl, Chain,getValue(Global),
7412MachinePointerInfo(Global, 0),Align,
7413MachineMemOperand::MOVolatile);
7414 }
7415if (TLI.useStackGuardXorFP())
7416 Res = TLI.emitStackGuardXorFP(DAG, Res, sdl);
7417DAG.setRoot(Chain);
7418setValue(&I, Res);
7419return;
7420 }
7421case Intrinsic::stackprotector: {
7422// Emit code into the DAG to store the stack guard onto the stack.
7423MachineFunction &MF =DAG.getMachineFunction();
7424MachineFrameInfo &MFI = MF.getFrameInfo();
7425constModule &M = *MF.getFunction().getParent();
7426SDValue Src, Chain =getRoot();
7427
7428if (TLI.useLoadStackGuardNode(M))
7429 Src =getLoadStackGuard(DAG, sdl, Chain);
7430else
7431 Src =getValue(I.getArgOperand(0));// The guard's value.
7432
7433AllocaInst *Slot = cast<AllocaInst>(I.getArgOperand(1));
7434
7435int FI =FuncInfo.StaticAllocaMap[Slot];
7436 MFI.setStackProtectorIndex(FI);
7437EVT PtrTy = TLI.getFrameIndexTy(DAG.getDataLayout());
7438
7439SDValue FIN =DAG.getFrameIndex(FI, PtrTy);
7440
7441// Store the stack protector onto the stack.
7442 Res =DAG.getStore(
7443 Chain, sdl, Src, FIN,
7444MachinePointerInfo::getFixedStack(DAG.getMachineFunction(), FI),
7445MaybeAlign(),MachineMemOperand::MOVolatile);
7446setValue(&I, Res);
7447DAG.setRoot(Res);
7448return;
7449 }
7450case Intrinsic::objectsize:
7451llvm_unreachable("llvm.objectsize.* should have been lowered already");
7452
7453case Intrinsic::is_constant:
7454llvm_unreachable("llvm.is.constant.* should have been lowered already");
7455
7456case Intrinsic::annotation:
7457case Intrinsic::ptr_annotation:
7458case Intrinsic::launder_invariant_group:
7459case Intrinsic::strip_invariant_group:
7460// Drop the intrinsic, but forward the value
7461setValue(&I,getValue(I.getOperand(0)));
7462return;
7463
7464case Intrinsic::assume:
7465case Intrinsic::experimental_noalias_scope_decl:
7466case Intrinsic::var_annotation:
7467case Intrinsic::sideeffect:
7468// Discard annotate attributes, noalias scope declarations, assumptions, and
7469// artificial side-effects.
7470return;
7471
7472case Intrinsic::codeview_annotation: {
7473// Emit a label associated with this metadata.
7474MachineFunction &MF =DAG.getMachineFunction();
7475MCSymbol *Label = MF.getContext().createTempSymbol("annotation",true);
7476Metadata *MD = cast<MetadataAsValue>(I.getArgOperand(0))->getMetadata();
7477 MF.addCodeViewAnnotation(Label, cast<MDNode>(MD));
7478 Res =DAG.getLabelNode(ISD::ANNOTATION_LABEL, sdl,getRoot(), Label);
7479DAG.setRoot(Res);
7480return;
7481 }
7482
7483case Intrinsic::init_trampoline: {
7484constFunction *F = cast<Function>(I.getArgOperand(1)->stripPointerCasts());
7485
7486SDValue Ops[6];
7487 Ops[0] =getRoot();
7488 Ops[1] =getValue(I.getArgOperand(0));
7489 Ops[2] =getValue(I.getArgOperand(1));
7490 Ops[3] =getValue(I.getArgOperand(2));
7491 Ops[4] =DAG.getSrcValue(I.getArgOperand(0));
7492 Ops[5] =DAG.getSrcValue(F);
7493
7494 Res =DAG.getNode(ISD::INIT_TRAMPOLINE, sdl, MVT::Other, Ops);
7495
7496DAG.setRoot(Res);
7497return;
7498 }
7499case Intrinsic::adjust_trampoline:
7500setValue(&I,DAG.getNode(ISD::ADJUST_TRAMPOLINE, sdl,
7501 TLI.getPointerTy(DAG.getDataLayout()),
7502getValue(I.getArgOperand(0))));
7503return;
7504case Intrinsic::gcroot: {
7505assert(DAG.getMachineFunction().getFunction().hasGC() &&
7506"only valid in functions with gc specified, enforced by Verifier");
7507assert(GFI &&"implied by previous");
7508constValue *Alloca =I.getArgOperand(0)->stripPointerCasts();
7509constConstant *TypeMap = cast<Constant>(I.getArgOperand(1));
7510
7511FrameIndexSDNode *FI = cast<FrameIndexSDNode>(getValue(Alloca).getNode());
7512GFI->addStackRoot(FI->getIndex(), TypeMap);
7513return;
7514 }
7515case Intrinsic::gcread:
7516case Intrinsic::gcwrite:
7517llvm_unreachable("GC failed to lower gcread/gcwrite intrinsics!");
7518case Intrinsic::get_rounding:
7519 Res =DAG.getNode(ISD::GET_ROUNDING, sdl, {MVT::i32, MVT::Other},getRoot());
7520setValue(&I, Res);
7521DAG.setRoot(Res.getValue(1));
7522return;
7523
7524case Intrinsic::expect:
7525case Intrinsic::expect_with_probability:
7526// Just replace __builtin_expect(exp, c) and
7527// __builtin_expect_with_probability(exp, c, p) with EXP.
7528setValue(&I,getValue(I.getArgOperand(0)));
7529return;
7530
7531case Intrinsic::ubsantrap:
7532case Intrinsic::debugtrap:
7533case Intrinsic::trap: {
7534StringRef TrapFuncName =
7535I.getAttributes().getFnAttr("trap-func-name").getValueAsString();
7536if (TrapFuncName.empty()) {
7537switch (Intrinsic) {
7538case Intrinsic::trap:
7539DAG.setRoot(DAG.getNode(ISD::TRAP, sdl, MVT::Other,getRoot()));
7540break;
7541case Intrinsic::debugtrap:
7542DAG.setRoot(DAG.getNode(ISD::DEBUGTRAP, sdl, MVT::Other,getRoot()));
7543break;
7544case Intrinsic::ubsantrap:
7545DAG.setRoot(DAG.getNode(
7546ISD::UBSANTRAP, sdl, MVT::Other,getRoot(),
7547DAG.getTargetConstant(
7548 cast<ConstantInt>(I.getArgOperand(0))->getZExtValue(), sdl,
7549 MVT::i32)));
7550break;
7551default:llvm_unreachable("unknown trap intrinsic");
7552 }
7553DAG.addNoMergeSiteInfo(DAG.getRoot().getNode(),
7554I.hasFnAttr(Attribute::NoMerge));
7555return;
7556 }
7557TargetLowering::ArgListTyArgs;
7558if (Intrinsic == Intrinsic::ubsantrap) {
7559Args.push_back(TargetLoweringBase::ArgListEntry());
7560Args[0].Val =I.getArgOperand(0);
7561Args[0].Node =getValue(Args[0].Val);
7562Args[0].Ty =Args[0].Val->getType();
7563 }
7564
7565TargetLowering::CallLoweringInfo CLI(DAG);
7566 CLI.setDebugLoc(sdl).setChain(getRoot()).setLibCallee(
7567CallingConv::C,I.getType(),
7568DAG.getExternalSymbol(TrapFuncName.data(),
7569 TLI.getPointerTy(DAG.getDataLayout())),
7570 std::move(Args));
7571 CLI.NoMerge =I.hasFnAttr(Attribute::NoMerge);
7572 std::pair<SDValue, SDValue>Result = TLI.LowerCallTo(CLI);
7573DAG.setRoot(Result.second);
7574return;
7575 }
7576
7577case Intrinsic::allow_runtime_check:
7578case Intrinsic::allow_ubsan_check:
7579setValue(&I,getValue(ConstantInt::getTrue(I.getType())));
7580return;
7581
7582case Intrinsic::uadd_with_overflow:
7583case Intrinsic::sadd_with_overflow:
7584case Intrinsic::usub_with_overflow:
7585case Intrinsic::ssub_with_overflow:
7586case Intrinsic::umul_with_overflow:
7587case Intrinsic::smul_with_overflow: {
7588ISD::NodeTypeOp;
7589switch (Intrinsic) {
7590default:llvm_unreachable("Impossible intrinsic");// Can't reach here.
7591case Intrinsic::uadd_with_overflow:Op =ISD::UADDO;break;
7592case Intrinsic::sadd_with_overflow:Op =ISD::SADDO;break;
7593case Intrinsic::usub_with_overflow:Op =ISD::USUBO;break;
7594case Intrinsic::ssub_with_overflow:Op =ISD::SSUBO;break;
7595case Intrinsic::umul_with_overflow:Op =ISD::UMULO;break;
7596case Intrinsic::smul_with_overflow:Op =ISD::SMULO;break;
7597 }
7598SDValue Op1 =getValue(I.getArgOperand(0));
7599SDValue Op2 =getValue(I.getArgOperand(1));
7600
7601EVT ResultVT = Op1.getValueType();
7602EVT OverflowVT = MVT::i1;
7603if (ResultVT.isVector())
7604 OverflowVT =EVT::getVectorVT(
7605 *Context, OverflowVT, ResultVT.getVectorElementCount());
7606
7607SDVTList VTs =DAG.getVTList(ResultVT, OverflowVT);
7608setValue(&I,DAG.getNode(Op, sdl, VTs, Op1, Op2));
7609return;
7610 }
7611case Intrinsic::prefetch: {
7612SDValue Ops[5];
7613unsigned rw = cast<ConstantInt>(I.getArgOperand(1))->getZExtValue();
7614autoFlags = rw == 0 ?MachineMemOperand::MOLoad :MachineMemOperand::MOStore;
7615 Ops[0] =DAG.getRoot();
7616 Ops[1] =getValue(I.getArgOperand(0));
7617 Ops[2] =DAG.getTargetConstant(*cast<ConstantInt>(I.getArgOperand(1)), sdl,
7618 MVT::i32);
7619 Ops[3] =DAG.getTargetConstant(*cast<ConstantInt>(I.getArgOperand(2)), sdl,
7620 MVT::i32);
7621 Ops[4] =DAG.getTargetConstant(*cast<ConstantInt>(I.getArgOperand(3)), sdl,
7622 MVT::i32);
7623SDValueResult =DAG.getMemIntrinsicNode(
7624ISD::PREFETCH, sdl,DAG.getVTList(MVT::Other), Ops,
7625EVT::getIntegerVT(*Context, 8),MachinePointerInfo(I.getArgOperand(0)),
7626/* align */ std::nullopt, Flags);
7627
7628// Chain the prefetch in parallel with any pending loads, to stay out of
7629// the way of later optimizations.
7630PendingLoads.push_back(Result);
7631Result =getRoot();
7632DAG.setRoot(Result);
7633return;
7634 }
7635case Intrinsic::lifetime_start:
7636case Intrinsic::lifetime_end: {
7637bool IsStart = (Intrinsic == Intrinsic::lifetime_start);
7638// Stack coloring is not enabled in O0, discard region information.
7639if (TM.getOptLevel() ==CodeGenOptLevel::None)
7640return;
7641
7642const int64_t ObjectSize =
7643 cast<ConstantInt>(I.getArgOperand(0))->getSExtValue();
7644Value *constObjectPtr =I.getArgOperand(1);
7645SmallVector<const Value *, 4> Allocas;
7646getUnderlyingObjects(ObjectPtr, Allocas);
7647
7648for (constValue *Alloca : Allocas) {
7649constAllocaInst *LifetimeObject = dyn_cast_or_null<AllocaInst>(Alloca);
7650
7651// Could not find an Alloca.
7652if (!LifetimeObject)
7653continue;
7654
7655// First check that the Alloca is static, otherwise it won't have a
7656// valid frame index.
7657autoSI =FuncInfo.StaticAllocaMap.find(LifetimeObject);
7658if (SI ==FuncInfo.StaticAllocaMap.end())
7659return;
7660
7661constintFrameIndex =SI->second;
7662 int64_tOffset;
7663if (GetPointerBaseWithConstantOffset(
7664 ObjectPtr,Offset,DAG.getDataLayout()) != LifetimeObject)
7665Offset = -1;// Cannot determine offset from alloca to lifetime object.
7666 Res =DAG.getLifetimeNode(IsStart, sdl,getRoot(), FrameIndex, ObjectSize,
7667Offset);
7668DAG.setRoot(Res);
7669 }
7670return;
7671 }
7672case Intrinsic::pseudoprobe: {
7673autoGuid = cast<ConstantInt>(I.getArgOperand(0))->getZExtValue();
7674autoIndex = cast<ConstantInt>(I.getArgOperand(1))->getZExtValue();
7675auto Attr = cast<ConstantInt>(I.getArgOperand(2))->getZExtValue();
7676 Res =DAG.getPseudoProbeNode(sdl,getRoot(),Guid, Index, Attr);
7677DAG.setRoot(Res);
7678return;
7679 }
7680case Intrinsic::invariant_start:
7681// Discard region information.
7682setValue(&I,
7683DAG.getUNDEF(TLI.getValueType(DAG.getDataLayout(),I.getType())));
7684return;
7685case Intrinsic::invariant_end:
7686// Discard region information.
7687return;
7688case Intrinsic::clear_cache: {
7689SDValue InputChain =DAG.getRoot();
7690SDValue StartVal =getValue(I.getArgOperand(0));
7691SDValue EndVal =getValue(I.getArgOperand(1));
7692 Res =DAG.getNode(ISD::CLEAR_CACHE, sdl,DAG.getVTList(MVT::Other),
7693 {InputChain, StartVal, EndVal});
7694setValue(&I, Res);
7695DAG.setRoot(Res);
7696return;
7697 }
7698case Intrinsic::donothing:
7699case Intrinsic::seh_try_begin:
7700case Intrinsic::seh_scope_begin:
7701case Intrinsic::seh_try_end:
7702case Intrinsic::seh_scope_end:
7703// ignore
7704return;
7705case Intrinsic::experimental_stackmap:
7706 visitStackmap(I);
7707return;
7708case Intrinsic::experimental_patchpoint_void:
7709case Intrinsic::experimental_patchpoint:
7710 visitPatchpoint(I);
7711return;
7712case Intrinsic::experimental_gc_statepoint:
7713LowerStatepoint(cast<GCStatepointInst>(I));
7714return;
7715case Intrinsic::experimental_gc_result:
7716 visitGCResult(cast<GCResultInst>(I));
7717return;
7718case Intrinsic::experimental_gc_relocate:
7719 visitGCRelocate(cast<GCRelocateInst>(I));
7720return;
7721case Intrinsic::instrprof_cover:
7722llvm_unreachable("instrprof failed to lower a cover");
7723case Intrinsic::instrprof_increment:
7724llvm_unreachable("instrprof failed to lower an increment");
7725case Intrinsic::instrprof_timestamp:
7726llvm_unreachable("instrprof failed to lower a timestamp");
7727case Intrinsic::instrprof_value_profile:
7728llvm_unreachable("instrprof failed to lower a value profiling call");
7729case Intrinsic::instrprof_mcdc_parameters:
7730llvm_unreachable("instrprof failed to lower mcdc parameters");
7731case Intrinsic::instrprof_mcdc_tvbitmap_update:
7732llvm_unreachable("instrprof failed to lower an mcdc tvbitmap update");
7733case Intrinsic::localescape: {
7734MachineFunction &MF =DAG.getMachineFunction();
7735constTargetInstrInfo *TII =DAG.getSubtarget().getInstrInfo();
7736
7737// Directly emit some LOCAL_ESCAPE machine instrs. Label assignment emission
7738// is the same on all targets.
7739for (unsignedIdx = 0, E =I.arg_size();Idx < E; ++Idx) {
7740Value *Arg =I.getArgOperand(Idx)->stripPointerCasts();
7741if (isa<ConstantPointerNull>(Arg))
7742continue;// Skip null pointers. They represent a hole in index space.
7743AllocaInst *Slot = cast<AllocaInst>(Arg);
7744assert(FuncInfo.StaticAllocaMap.count(Slot) &&
7745"can only escape static allocas");
7746int FI =FuncInfo.StaticAllocaMap[Slot];
7747MCSymbol *FrameAllocSym = MF.getContext().getOrCreateFrameAllocSymbol(
7748GlobalValue::dropLLVMManglingEscape(MF.getName()),Idx);
7749BuildMI(*FuncInfo.MBB,FuncInfo.InsertPt, dl,
7750TII->get(TargetOpcode::LOCAL_ESCAPE))
7751 .addSym(FrameAllocSym)
7752 .addFrameIndex(FI);
7753 }
7754
7755return;
7756 }
7757
7758case Intrinsic::localrecover: {
7759// i8* @llvm.localrecover(i8* %fn, i8* %fp, i32 %idx)
7760MachineFunction &MF =DAG.getMachineFunction();
7761
7762// Get the symbol that defines the frame offset.
7763auto *Fn = cast<Function>(I.getArgOperand(0)->stripPointerCasts());
7764auto *Idx = cast<ConstantInt>(I.getArgOperand(2));
7765unsigned IdxVal =
7766unsigned(Idx->getLimitedValue(std::numeric_limits<int>::max()));
7767MCSymbol *FrameAllocSym = MF.getContext().getOrCreateFrameAllocSymbol(
7768GlobalValue::dropLLVMManglingEscape(Fn->getName()), IdxVal);
7769
7770Value *FP =I.getArgOperand(1);
7771SDValue FPVal =getValue(FP);
7772EVT PtrVT = FPVal.getValueType();
7773
7774// Create a MCSymbol for the label to avoid any target lowering
7775// that would make this PC relative.
7776SDValue OffsetSym =DAG.getMCSymbol(FrameAllocSym, PtrVT);
7777SDValue OffsetVal =
7778DAG.getNode(ISD::LOCAL_RECOVER, sdl, PtrVT, OffsetSym);
7779
7780// Add the offset to the FP.
7781SDValueAdd =DAG.getMemBasePlusOffset(FPVal, OffsetVal, sdl);
7782setValue(&I,Add);
7783
7784return;
7785 }
7786
7787case Intrinsic::fake_use: {
7788Value *V =I.getArgOperand(0);
7789SDValue Ops[2];
7790// For Values not declared or previously used in this basic block, the
7791// NodeMap will not have an entry, and `getValue` will assert if V has no
7792// valid register value.
7793auto FakeUseValue = [&]() ->SDValue {
7794SDValue &N = NodeMap[V];
7795if (N.getNode())
7796returnN;
7797
7798// If there's a virtual register allocated and initialized for this
7799// value, use it.
7800if (SDValue copyFromReg =getCopyFromRegs(V,V->getType()))
7801return copyFromReg;
7802// FIXME: Do we want to preserve constants? It seems pointless.
7803if (isa<Constant>(V))
7804returngetValue(V);
7805returnSDValue();
7806 }();
7807if (!FakeUseValue || FakeUseValue.isUndef())
7808return;
7809 Ops[0] =getRoot();
7810 Ops[1] = FakeUseValue;
7811// Also, do not translate a fake use with an undef operand, or any other
7812// empty SDValues.
7813if (!Ops[1] || Ops[1].isUndef())
7814return;
7815DAG.setRoot(DAG.getNode(ISD::FAKE_USE, sdl, MVT::Other, Ops));
7816return;
7817 }
7818
7819case Intrinsic::eh_exceptionpointer:
7820case Intrinsic::eh_exceptioncode: {
7821// Get the exception pointer vreg, copy from it, and resize it to fit.
7822constauto *CPI = cast<CatchPadInst>(I.getArgOperand(0));
7823MVT PtrVT = TLI.getPointerTy(DAG.getDataLayout());
7824constTargetRegisterClass *PtrRC = TLI.getRegClassFor(PtrVT);
7825Register VReg =FuncInfo.getCatchPadExceptionPointerVReg(CPI, PtrRC);
7826SDValueN =DAG.getCopyFromReg(DAG.getEntryNode(), sdl, VReg, PtrVT);
7827if (Intrinsic == Intrinsic::eh_exceptioncode)
7828N =DAG.getZExtOrTrunc(N, sdl, MVT::i32);
7829setValue(&I,N);
7830return;
7831 }
7832case Intrinsic::xray_customevent: {
7833// Here we want to make sure that the intrinsic behaves as if it has a
7834// specific calling convention.
7835constauto &Triple =DAG.getTarget().getTargetTriple();
7836if (!Triple.isAArch64(64) &&Triple.getArch() !=Triple::x86_64)
7837return;
7838
7839SmallVector<SDValue, 8> Ops;
7840
7841// We want to say that we always want the arguments in registers.
7842SDValue LogEntryVal =getValue(I.getArgOperand(0));
7843SDValue StrSizeVal =getValue(I.getArgOperand(1));
7844SDVTList NodeTys =DAG.getVTList(MVT::Other, MVT::Glue);
7845SDValue Chain =getRoot();
7846 Ops.push_back(LogEntryVal);
7847 Ops.push_back(StrSizeVal);
7848 Ops.push_back(Chain);
7849
7850// We need to enforce the calling convention for the callsite, so that
7851// argument ordering is enforced correctly, and that register allocation can
7852// see that some registers may be assumed clobbered and have to preserve
7853// them across calls to the intrinsic.
7854MachineSDNode *MN =DAG.getMachineNode(TargetOpcode::PATCHABLE_EVENT_CALL,
7855 sdl, NodeTys, Ops);
7856SDValue patchableNode =SDValue(MN, 0);
7857DAG.setRoot(patchableNode);
7858setValue(&I, patchableNode);
7859return;
7860 }
7861case Intrinsic::xray_typedevent: {
7862// Here we want to make sure that the intrinsic behaves as if it has a
7863// specific calling convention.
7864constauto &Triple =DAG.getTarget().getTargetTriple();
7865if (!Triple.isAArch64(64) &&Triple.getArch() !=Triple::x86_64)
7866return;
7867
7868SmallVector<SDValue, 8> Ops;
7869
7870// We want to say that we always want the arguments in registers.
7871// It's unclear to me how manipulating the selection DAG here forces callers
7872// to provide arguments in registers instead of on the stack.
7873SDValue LogTypeId =getValue(I.getArgOperand(0));
7874SDValue LogEntryVal =getValue(I.getArgOperand(1));
7875SDValue StrSizeVal =getValue(I.getArgOperand(2));
7876SDVTList NodeTys =DAG.getVTList(MVT::Other, MVT::Glue);
7877SDValue Chain =getRoot();
7878 Ops.push_back(LogTypeId);
7879 Ops.push_back(LogEntryVal);
7880 Ops.push_back(StrSizeVal);
7881 Ops.push_back(Chain);
7882
7883// We need to enforce the calling convention for the callsite, so that
7884// argument ordering is enforced correctly, and that register allocation can
7885// see that some registers may be assumed clobbered and have to preserve
7886// them across calls to the intrinsic.
7887MachineSDNode *MN =DAG.getMachineNode(
7888 TargetOpcode::PATCHABLE_TYPED_EVENT_CALL, sdl, NodeTys, Ops);
7889SDValue patchableNode =SDValue(MN, 0);
7890DAG.setRoot(patchableNode);
7891setValue(&I, patchableNode);
7892return;
7893 }
7894case Intrinsic::experimental_deoptimize:
7895LowerDeoptimizeCall(&I);
7896return;
7897case Intrinsic::stepvector:
7898 visitStepVector(I);
7899return;
7900case Intrinsic::vector_reduce_fadd:
7901case Intrinsic::vector_reduce_fmul:
7902case Intrinsic::vector_reduce_add:
7903case Intrinsic::vector_reduce_mul:
7904case Intrinsic::vector_reduce_and:
7905case Intrinsic::vector_reduce_or:
7906case Intrinsic::vector_reduce_xor:
7907case Intrinsic::vector_reduce_smax:
7908case Intrinsic::vector_reduce_smin:
7909case Intrinsic::vector_reduce_umax:
7910case Intrinsic::vector_reduce_umin:
7911case Intrinsic::vector_reduce_fmax:
7912case Intrinsic::vector_reduce_fmin:
7913case Intrinsic::vector_reduce_fmaximum:
7914case Intrinsic::vector_reduce_fminimum:
7915 visitVectorReduce(I, Intrinsic);
7916return;
7917
7918case Intrinsic::icall_branch_funnel: {
7919SmallVector<SDValue, 16> Ops;
7920 Ops.push_back(getValue(I.getArgOperand(0)));
7921
7922 int64_tOffset;
7923auto *Base = dyn_cast<GlobalObject>(GetPointerBaseWithConstantOffset(
7924I.getArgOperand(1),Offset,DAG.getDataLayout()));
7925if (!Base)
7926report_fatal_error(
7927"llvm.icall.branch.funnel operand must be a GlobalValue");
7928 Ops.push_back(DAG.getTargetGlobalAddress(Base, sdl, MVT::i64, 0));
7929
7930structBranchFunnelTarget {
7931 int64_tOffset;
7932SDValueTarget;
7933 };
7934SmallVector<BranchFunnelTarget, 8> Targets;
7935
7936for (unsignedOp = 1,N =I.arg_size();Op !=N;Op += 2) {
7937auto *ElemBase = dyn_cast<GlobalObject>(GetPointerBaseWithConstantOffset(
7938I.getArgOperand(Op),Offset,DAG.getDataLayout()));
7939if (ElemBase !=Base)
7940report_fatal_error("all llvm.icall.branch.funnel operands must refer "
7941"to the same GlobalValue");
7942
7943SDValue Val =getValue(I.getArgOperand(Op + 1));
7944auto *GA = dyn_cast<GlobalAddressSDNode>(Val);
7945if (!GA)
7946report_fatal_error(
7947"llvm.icall.branch.funnel operand must be a GlobalValue");
7948 Targets.push_back({Offset,DAG.getTargetGlobalAddress(
7949 GA->getGlobal(), sdl, Val.getValueType(),
7950 GA->getOffset())});
7951 }
7952llvm::sort(Targets,
7953 [](const BranchFunnelTarget &T1,const BranchFunnelTarget &T2) {
7954returnT1.Offset < T2.Offset;
7955 });
7956
7957for (auto &T : Targets) {
7958 Ops.push_back(DAG.getTargetConstant(T.Offset, sdl, MVT::i32));
7959 Ops.push_back(T.Target);
7960 }
7961
7962 Ops.push_back(DAG.getRoot());// Chain
7963SDValueN(DAG.getMachineNode(TargetOpcode::ICALL_BRANCH_FUNNEL, sdl,
7964 MVT::Other, Ops),
7965 0);
7966DAG.setRoot(N);
7967setValue(&I,N);
7968HasTailCall =true;
7969return;
7970 }
7971
7972case Intrinsic::wasm_landingpad_index:
7973// Information this intrinsic contained has been transferred to
7974// MachineFunction in SelectionDAGISel::PrepareEHLandingPad. We can safely
7975// delete it now.
7976return;
7977
7978case Intrinsic::aarch64_settag:
7979case Intrinsic::aarch64_settag_zero: {
7980constSelectionDAGTargetInfo &TSI =DAG.getSelectionDAGInfo();
7981bool ZeroMemory =Intrinsic == Intrinsic::aarch64_settag_zero;
7982SDValue Val = TSI.EmitTargetCodeForSetTag(
7983DAG, sdl,getRoot(),getValue(I.getArgOperand(0)),
7984getValue(I.getArgOperand(1)),MachinePointerInfo(I.getArgOperand(0)),
7985 ZeroMemory);
7986DAG.setRoot(Val);
7987setValue(&I, Val);
7988return;
7989 }
7990case Intrinsic::amdgcn_cs_chain: {
7991assert(I.arg_size() == 5 &&"Additional args not supported yet");
7992assert(cast<ConstantInt>(I.getOperand(4))->isZero() &&
7993"Non-zero flags not supported yet");
7994
7995// At this point we don't care if it's amdgpu_cs_chain or
7996// amdgpu_cs_chain_preserve.
7997CallingConv::IDCC =CallingConv::AMDGPU_CS_Chain;
7998
7999Type *RetTy =I.getType();
8000assert(RetTy->isVoidTy() &&"Should not return");
8001
8002SDValueCallee =getValue(I.getOperand(0));
8003
8004// We only have 2 actual args: one for the SGPRs and one for the VGPRs.
8005// We'll also tack the value of the EXEC mask at the end.
8006TargetLowering::ArgListTyArgs;
8007Args.reserve(3);
8008
8009for (unsignedIdx : {2, 3, 1}) {
8010TargetLowering::ArgListEntry Arg;
8011 Arg.Node =getValue(I.getOperand(Idx));
8012 Arg.Ty =I.getOperand(Idx)->getType();
8013 Arg.setAttributes(&I,Idx);
8014Args.push_back(Arg);
8015 }
8016
8017assert(Args[0].IsInReg &&"SGPR args should be marked inreg");
8018assert(!Args[1].IsInReg &&"VGPR args should not be marked inreg");
8019Args[2].IsInReg =true;// EXEC should be inreg
8020
8021TargetLowering::CallLoweringInfo CLI(DAG);
8022 CLI.setDebugLoc(getCurSDLoc())
8023 .setChain(getRoot())
8024 .setCallee(CC,RetTy, Callee, std::move(Args))
8025 .setNoReturn(true)
8026 .setTailCall(true)
8027 .setConvergent(I.isConvergent());
8028 CLI.CB = &I;
8029 std::pair<SDValue, SDValue>Result =
8030lowerInvokable(CLI,/*EHPadBB*/nullptr);
8031 (void)Result;
8032assert(!Result.first.getNode() && !Result.second.getNode() &&
8033"Should've lowered as tail call");
8034
8035HasTailCall =true;
8036return;
8037 }
8038case Intrinsic::ptrmask: {
8039SDValuePtr =getValue(I.getOperand(0));
8040SDValueMask =getValue(I.getOperand(1));
8041
8042// On arm64_32, pointers are 32 bits when stored in memory, but
8043// zero-extended to 64 bits when in registers. Thus the mask is 32 bits to
8044// match the index type, but the pointer is 64 bits, so the the mask must be
8045// zero-extended up to 64 bits to match the pointer.
8046EVT PtrVT =
8047 TLI.getValueType(DAG.getDataLayout(),I.getOperand(0)->getType());
8048EVT MemVT =
8049 TLI.getMemValueType(DAG.getDataLayout(),I.getOperand(0)->getType());
8050assert(PtrVT ==Ptr.getValueType());
8051assert(MemVT ==Mask.getValueType());
8052if (MemVT != PtrVT)
8053Mask =DAG.getPtrExtOrTrunc(Mask, sdl, PtrVT);
8054
8055setValue(&I,DAG.getNode(ISD::AND, sdl, PtrVT,Ptr, Mask));
8056return;
8057 }
8058case Intrinsic::threadlocal_address: {
8059setValue(&I,getValue(I.getOperand(0)));
8060return;
8061 }
8062case Intrinsic::get_active_lane_mask: {
8063EVT CCVT = TLI.getValueType(DAG.getDataLayout(),I.getType());
8064SDValueIndex =getValue(I.getOperand(0));
8065EVT ElementVT =Index.getValueType();
8066
8067if (!TLI.shouldExpandGetActiveLaneMask(CCVT, ElementVT)) {
8068 visitTargetIntrinsic(I, Intrinsic);
8069return;
8070 }
8071
8072SDValue TripCount =getValue(I.getOperand(1));
8073EVT VecTy =EVT::getVectorVT(*DAG.getContext(), ElementVT,
8074 CCVT.getVectorElementCount());
8075
8076SDValue VectorIndex =DAG.getSplat(VecTy, sdl, Index);
8077SDValue VectorTripCount =DAG.getSplat(VecTy, sdl, TripCount);
8078SDValue VectorStep =DAG.getStepVector(sdl, VecTy);
8079SDValue VectorInduction =DAG.getNode(
8080ISD::UADDSAT, sdl, VecTy, VectorIndex, VectorStep);
8081SDValue SetCC =DAG.getSetCC(sdl, CCVT, VectorInduction,
8082 VectorTripCount,ISD::CondCode::SETULT);
8083setValue(&I, SetCC);
8084return;
8085 }
8086case Intrinsic::experimental_get_vector_length: {
8087assert(cast<ConstantInt>(I.getOperand(1))->getSExtValue() > 0 &&
8088"Expected positive VF");
8089unsigned VF = cast<ConstantInt>(I.getOperand(1))->getZExtValue();
8090bool IsScalable = cast<ConstantInt>(I.getOperand(2))->isOne();
8091
8092SDValue Count =getValue(I.getOperand(0));
8093EVT CountVT = Count.getValueType();
8094
8095if (!TLI.shouldExpandGetVectorLength(CountVT, VF, IsScalable)) {
8096 visitTargetIntrinsic(I, Intrinsic);
8097return;
8098 }
8099
8100// Expand to a umin between the trip count and the maximum elements the type
8101// can hold.
8102EVT VT = TLI.getValueType(DAG.getDataLayout(),I.getType());
8103
8104// Extend the trip count to at least the result VT.
8105if (CountVT.bitsLT(VT)) {
8106 Count =DAG.getNode(ISD::ZERO_EXTEND, sdl, VT, Count);
8107 CountVT = VT;
8108 }
8109
8110SDValue MaxEVL =DAG.getElementCount(sdl, CountVT,
8111ElementCount::get(VF, IsScalable));
8112
8113SDValueUMin =DAG.getNode(ISD::UMIN, sdl, CountVT, Count, MaxEVL);
8114// Clip to the result type if needed.
8115SDValue Trunc =DAG.getNode(ISD::TRUNCATE, sdl, VT,UMin);
8116
8117setValue(&I, Trunc);
8118return;
8119 }
8120case Intrinsic::experimental_vector_partial_reduce_add: {
8121
8122if (!TLI.shouldExpandPartialReductionIntrinsic(cast<IntrinsicInst>(&I))) {
8123 visitTargetIntrinsic(I, Intrinsic);
8124return;
8125 }
8126
8127setValue(&I,DAG.getPartialReduceAdd(sdl,EVT::getEVT(I.getType()),
8128getValue(I.getOperand(0)),
8129getValue(I.getOperand(1))));
8130return;
8131 }
8132case Intrinsic::experimental_cttz_elts: {
8133autoDL =getCurSDLoc();
8134SDValueOp =getValue(I.getOperand(0));
8135EVT OpVT =Op.getValueType();
8136
8137if (!TLI.shouldExpandCttzElements(OpVT)) {
8138 visitTargetIntrinsic(I, Intrinsic);
8139return;
8140 }
8141
8142if (OpVT.getScalarType() != MVT::i1) {
8143// Compare the input vector elements to zero & use to count trailing zeros
8144SDValue AllZero =DAG.getConstant(0,DL, OpVT);
8145 OpVT =EVT::getVectorVT(*DAG.getContext(), MVT::i1,
8146 OpVT.getVectorElementCount());
8147Op =DAG.getSetCC(DL, OpVT,Op, AllZero,ISD::SETNE);
8148 }
8149
8150// If the zero-is-poison flag is set, we can assume the upper limit
8151// of the result is VF-1.
8152bool ZeroIsPoison =
8153 !cast<ConstantSDNode>(getValue(I.getOperand(1)))->isZero();
8154ConstantRange VScaleRange(1,true);// Dummy value.
8155if (isa<ScalableVectorType>(I.getOperand(0)->getType()))
8156 VScaleRange =getVScaleRange(I.getCaller(), 64);
8157unsigned EltWidth = TLI.getBitWidthForCttzElements(
8158I.getType(), OpVT.getVectorElementCount(), ZeroIsPoison, &VScaleRange);
8159
8160MVT NewEltTy =MVT::getIntegerVT(EltWidth);
8161
8162// Create the new vector type & get the vector length
8163EVT NewVT =EVT::getVectorVT(*DAG.getContext(), NewEltTy,
8164 OpVT.getVectorElementCount());
8165
8166SDValue VL =
8167DAG.getElementCount(DL, NewEltTy, OpVT.getVectorElementCount());
8168
8169SDValue StepVec =DAG.getStepVector(DL, NewVT);
8170SDValue SplatVL =DAG.getSplat(NewVT,DL, VL);
8171SDValue StepVL =DAG.getNode(ISD::SUB,DL, NewVT, SplatVL, StepVec);
8172SDValueExt =DAG.getNode(ISD::SIGN_EXTEND,DL, NewVT,Op);
8173SDValueAnd =DAG.getNode(ISD::AND,DL, NewVT, StepVL, Ext);
8174SDValueMax =DAG.getNode(ISD::VECREDUCE_UMAX,DL, NewEltTy,And);
8175SDValue Sub =DAG.getNode(ISD::SUB,DL, NewEltTy, VL, Max);
8176
8177EVTRetTy = TLI.getValueType(DAG.getDataLayout(),I.getType());
8178SDValueRet =DAG.getZExtOrTrunc(Sub,DL,RetTy);
8179
8180setValue(&I, Ret);
8181return;
8182 }
8183case Intrinsic::vector_insert: {
8184SDValue Vec =getValue(I.getOperand(0));
8185SDValue SubVec =getValue(I.getOperand(1));
8186SDValueIndex =getValue(I.getOperand(2));
8187
8188// The intrinsic's index type is i64, but the SDNode requires an index type
8189// suitable for the target. Convert the index as required.
8190MVT VectorIdxTy = TLI.getVectorIdxTy(DAG.getDataLayout());
8191if (Index.getValueType() != VectorIdxTy)
8192Index =DAG.getVectorIdxConstant(Index->getAsZExtVal(), sdl);
8193
8194EVT ResultVT = TLI.getValueType(DAG.getDataLayout(),I.getType());
8195setValue(&I,DAG.getNode(ISD::INSERT_SUBVECTOR, sdl, ResultVT, Vec, SubVec,
8196 Index));
8197return;
8198 }
8199case Intrinsic::vector_extract: {
8200SDValue Vec =getValue(I.getOperand(0));
8201SDValueIndex =getValue(I.getOperand(1));
8202EVT ResultVT = TLI.getValueType(DAG.getDataLayout(),I.getType());
8203
8204// The intrinsic's index type is i64, but the SDNode requires an index type
8205// suitable for the target. Convert the index as required.
8206MVT VectorIdxTy = TLI.getVectorIdxTy(DAG.getDataLayout());
8207if (Index.getValueType() != VectorIdxTy)
8208Index =DAG.getVectorIdxConstant(Index->getAsZExtVal(), sdl);
8209
8210setValue(&I,
8211DAG.getNode(ISD::EXTRACT_SUBVECTOR, sdl, ResultVT, Vec, Index));
8212return;
8213 }
8214case Intrinsic::experimental_vector_match: {
8215SDValue Op1 =getValue(I.getOperand(0));
8216SDValue Op2 =getValue(I.getOperand(1));
8217SDValueMask =getValue(I.getOperand(2));
8218EVT Op1VT = Op1.getValueType();
8219EVT Op2VT = Op2.getValueType();
8220EVT ResVT =Mask.getValueType();
8221unsigned SearchSize = Op2VT.getVectorNumElements();
8222
8223// If the target has native support for this vector match operation, lower
8224// the intrinsic untouched; otherwise, expand it below.
8225if (!TLI.shouldExpandVectorMatch(Op1VT, SearchSize)) {
8226 visitTargetIntrinsic(I, Intrinsic);
8227return;
8228 }
8229
8230SDValueRet =DAG.getConstant(0, sdl, ResVT);
8231
8232for (unsigned i = 0; i < SearchSize; ++i) {
8233SDValue Op2Elem =DAG.getNode(ISD::EXTRACT_VECTOR_ELT, sdl,
8234 Op2VT.getVectorElementType(), Op2,
8235DAG.getVectorIdxConstant(i, sdl));
8236SDValueSplat =DAG.getNode(ISD::SPLAT_VECTOR, sdl, Op1VT, Op2Elem);
8237SDValueCmp =DAG.getSetCC(sdl, ResVT, Op1,Splat,ISD::SETEQ);
8238Ret =DAG.getNode(ISD::OR, sdl, ResVT, Ret, Cmp);
8239 }
8240
8241setValue(&I,DAG.getNode(ISD::AND, sdl, ResVT, Ret, Mask));
8242return;
8243 }
8244case Intrinsic::vector_reverse:
8245 visitVectorReverse(I);
8246return;
8247case Intrinsic::vector_splice:
8248 visitVectorSplice(I);
8249return;
8250case Intrinsic::callbr_landingpad:
8251 visitCallBrLandingPad(I);
8252return;
8253case Intrinsic::vector_interleave2:
8254 visitVectorInterleave(I);
8255return;
8256case Intrinsic::vector_deinterleave2:
8257 visitVectorDeinterleave(I);
8258return;
8259case Intrinsic::experimental_vector_compress:
8260setValue(&I,DAG.getNode(ISD::VECTOR_COMPRESS, sdl,
8261getValue(I.getArgOperand(0)).getValueType(),
8262getValue(I.getArgOperand(0)),
8263getValue(I.getArgOperand(1)),
8264getValue(I.getArgOperand(2)), Flags));
8265return;
8266case Intrinsic::experimental_convergence_anchor:
8267case Intrinsic::experimental_convergence_entry:
8268case Intrinsic::experimental_convergence_loop:
8269 visitConvergenceControl(I, Intrinsic);
8270return;
8271case Intrinsic::experimental_vector_histogram_add: {
8272 visitVectorHistogram(I, Intrinsic);
8273return;
8274 }
8275case Intrinsic::experimental_vector_extract_last_active: {
8276 visitVectorExtractLastActive(I, Intrinsic);
8277return;
8278 }
8279 }
8280}
8281
8282void SelectionDAGBuilder::visitConstrainedFPIntrinsic(
8283constConstrainedFPIntrinsic &FPI) {
8284SDLoc sdl =getCurSDLoc();
8285
8286// We do not need to serialize constrained FP intrinsics against
8287// each other or against (nonvolatile) loads, so they can be
8288// chained like loads.
8289SDValue Chain =DAG.getRoot();
8290SmallVector<SDValue, 4> Opers;
8291 Opers.push_back(Chain);
8292for (unsignedI = 0, E = FPI.getNonMetadataArgCount();I != E; ++I)
8293 Opers.push_back(getValue(FPI.getArgOperand(I)));
8294
8295auto pushOutChain = [this](SDValueResult,fp::ExceptionBehavior EB) {
8296assert(Result.getNode()->getNumValues() == 2);
8297
8298// Push node to the appropriate list so that future instructions can be
8299// chained up correctly.
8300SDValue OutChain =Result.getValue(1);
8301switch (EB) {
8302casefp::ExceptionBehavior::ebIgnore:
8303// The only reason why ebIgnore nodes still need to be chained is that
8304// they might depend on the current rounding mode, and therefore must
8305// not be moved across instruction that may change that mode.
8306 [[fallthrough]];
8307casefp::ExceptionBehavior::ebMayTrap:
8308// These must not be moved across calls or instructions that may change
8309// floating-point exception masks.
8310 PendingConstrainedFP.push_back(OutChain);
8311break;
8312casefp::ExceptionBehavior::ebStrict:
8313// These must not be moved across calls or instructions that may change
8314// floating-point exception masks or read floating-point exception flags.
8315// In addition, they cannot be optimized out even if unused.
8316 PendingConstrainedFPStrict.push_back(OutChain);
8317break;
8318 }
8319 };
8320
8321constTargetLowering &TLI =DAG.getTargetLoweringInfo();
8322EVT VT = TLI.getValueType(DAG.getDataLayout(), FPI.getType());
8323SDVTList VTs =DAG.getVTList(VT, MVT::Other);
8324fp::ExceptionBehavior EB = *FPI.getExceptionBehavior();
8325
8326SDNodeFlagsFlags;
8327if (EB ==fp::ExceptionBehavior::ebIgnore)
8328Flags.setNoFPExcept(true);
8329
8330if (auto *FPOp = dyn_cast<FPMathOperator>(&FPI))
8331Flags.copyFMF(*FPOp);
8332
8333unsigned Opcode;
8334switch (FPI.getIntrinsicID()) {
8335default:llvm_unreachable("Impossible intrinsic");// Can't reach here.
8336#define DAG_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN) \
8337 case Intrinsic::INTRINSIC: \
8338 Opcode = ISD::STRICT_##DAGN; \
8339 break;
8340#include "llvm/IR/ConstrainedOps.def"
8341case Intrinsic::experimental_constrained_fmuladd: {
8342 Opcode =ISD::STRICT_FMA;
8343// Break fmuladd into fmul and fadd.
8344if (TM.Options.AllowFPOpFusion ==FPOpFusion::Strict ||
8345 !TLI.isFMAFasterThanFMulAndFAdd(DAG.getMachineFunction(), VT)) {
8346 Opers.pop_back();
8347SDValueMul =DAG.getNode(ISD::STRICT_FMUL, sdl, VTs, Opers, Flags);
8348 pushOutChain(Mul, EB);
8349 Opcode =ISD::STRICT_FADD;
8350 Opers.clear();
8351 Opers.push_back(Mul.getValue(1));
8352 Opers.push_back(Mul.getValue(0));
8353 Opers.push_back(getValue(FPI.getArgOperand(2)));
8354 }
8355break;
8356 }
8357 }
8358
8359// A few strict DAG nodes carry additional operands that are not
8360// set up by the default code above.
8361switch (Opcode) {
8362default:break;
8363caseISD::STRICT_FP_ROUND:
8364 Opers.push_back(
8365DAG.getTargetConstant(0, sdl, TLI.getPointerTy(DAG.getDataLayout())));
8366break;
8367caseISD::STRICT_FSETCC:
8368caseISD::STRICT_FSETCCS: {
8369auto *FPCmp = dyn_cast<ConstrainedFPCmpIntrinsic>(&FPI);
8370ISD::CondCode Condition =getFCmpCondCode(FPCmp->getPredicate());
8371if (TM.Options.NoNaNsFPMath)
8372 Condition =getFCmpCodeWithoutNaN(Condition);
8373 Opers.push_back(DAG.getCondCode(Condition));
8374break;
8375 }
8376 }
8377
8378SDValueResult =DAG.getNode(Opcode, sdl, VTs, Opers, Flags);
8379 pushOutChain(Result, EB);
8380
8381SDValue FPResult =Result.getValue(0);
8382setValue(&FPI, FPResult);
8383}
8384
8385staticunsignedgetISDForVPIntrinsic(constVPIntrinsic &VPIntrin) {
8386 std::optional<unsigned> ResOPC;
8387switch (VPIntrin.getIntrinsicID()) {
8388case Intrinsic::vp_ctlz: {
8389bool IsZeroUndef = cast<ConstantInt>(VPIntrin.getArgOperand(1))->isOne();
8390 ResOPC = IsZeroUndef ? ISD::VP_CTLZ_ZERO_UNDEF : ISD::VP_CTLZ;
8391break;
8392 }
8393case Intrinsic::vp_cttz: {
8394bool IsZeroUndef = cast<ConstantInt>(VPIntrin.getArgOperand(1))->isOne();
8395 ResOPC = IsZeroUndef ? ISD::VP_CTTZ_ZERO_UNDEF : ISD::VP_CTTZ;
8396break;
8397 }
8398case Intrinsic::vp_cttz_elts: {
8399bool IsZeroPoison = cast<ConstantInt>(VPIntrin.getArgOperand(1))->isOne();
8400 ResOPC = IsZeroPoison ? ISD::VP_CTTZ_ELTS_ZERO_UNDEF : ISD::VP_CTTZ_ELTS;
8401break;
8402 }
8403#define HELPER_MAP_VPID_TO_VPSD(VPID, VPSD) \
8404 case Intrinsic::VPID: \
8405 ResOPC = ISD::VPSD; \
8406 break;
8407#include "llvm/IR/VPIntrinsics.def"
8408 }
8409
8410if (!ResOPC)
8411llvm_unreachable(
8412"Inconsistency: no SDNode available for this VPIntrinsic!");
8413
8414if (*ResOPC == ISD::VP_REDUCE_SEQ_FADD ||
8415 *ResOPC == ISD::VP_REDUCE_SEQ_FMUL) {
8416if (VPIntrin.getFastMathFlags().allowReassoc())
8417return *ResOPC == ISD::VP_REDUCE_SEQ_FADD ? ISD::VP_REDUCE_FADD
8418 : ISD::VP_REDUCE_FMUL;
8419 }
8420
8421return *ResOPC;
8422}
8423
8424void SelectionDAGBuilder::visitVPLoad(
8425constVPIntrinsic &VPIntrin,EVT VT,
8426constSmallVectorImpl<SDValue> &OpValues) {
8427SDLocDL =getCurSDLoc();
8428Value *PtrOperand = VPIntrin.getArgOperand(0);
8429MaybeAlign Alignment = VPIntrin.getPointerAlignment();
8430AAMDNodes AAInfo = VPIntrin.getAAMetadata();
8431constMDNode *Ranges =getRangeMetadata(VPIntrin);
8432SDValueLD;
8433// Do not serialize variable-length loads of constant memory with
8434// anything.
8435if (!Alignment)
8436 Alignment =DAG.getEVTAlign(VT);
8437MemoryLocationML =MemoryLocation::getAfter(PtrOperand, AAInfo);
8438bool AddToChain = !BatchAA || !BatchAA->pointsToConstantMemory(ML);
8439SDValue InChain = AddToChain ?DAG.getRoot() :DAG.getEntryNode();
8440MachineMemOperand *MMO =DAG.getMachineFunction().getMachineMemOperand(
8441MachinePointerInfo(PtrOperand),MachineMemOperand::MOLoad,
8442LocationSize::beforeOrAfterPointer(), *Alignment, AAInfo, Ranges);
8443LD =DAG.getLoadVP(VT,DL, InChain, OpValues[0], OpValues[1], OpValues[2],
8444 MMO,false/*IsExpanding */);
8445if (AddToChain)
8446PendingLoads.push_back(LD.getValue(1));
8447setValue(&VPIntrin, LD);
8448}
8449
8450void SelectionDAGBuilder::visitVPGather(
8451constVPIntrinsic &VPIntrin,EVT VT,
8452constSmallVectorImpl<SDValue> &OpValues) {
8453SDLocDL =getCurSDLoc();
8454constTargetLowering &TLI =DAG.getTargetLoweringInfo();
8455Value *PtrOperand = VPIntrin.getArgOperand(0);
8456MaybeAlign Alignment = VPIntrin.getPointerAlignment();
8457AAMDNodes AAInfo = VPIntrin.getAAMetadata();
8458constMDNode *Ranges =getRangeMetadata(VPIntrin);
8459SDValueLD;
8460if (!Alignment)
8461 Alignment =DAG.getEVTAlign(VT.getScalarType());
8462unsigned AS =
8463 PtrOperand->getType()->getScalarType()->getPointerAddressSpace();
8464MachineMemOperand *MMO =DAG.getMachineFunction().getMachineMemOperand(
8465MachinePointerInfo(AS),MachineMemOperand::MOLoad,
8466LocationSize::beforeOrAfterPointer(), *Alignment, AAInfo, Ranges);
8467SDValueBase,Index, Scale;
8468ISD::MemIndexType IndexType;
8469bool UniformBase =getUniformBase(PtrOperand,Base, Index, IndexType, Scale,
8470this, VPIntrin.getParent(),
8471 VT.getScalarStoreSize());
8472if (!UniformBase) {
8473Base =DAG.getConstant(0,DL, TLI.getPointerTy(DAG.getDataLayout()));
8474Index =getValue(PtrOperand);
8475 IndexType =ISD::SIGNED_SCALED;
8476 Scale =DAG.getTargetConstant(1,DL, TLI.getPointerTy(DAG.getDataLayout()));
8477 }
8478EVT IdxVT =Index.getValueType();
8479EVT EltTy = IdxVT.getVectorElementType();
8480if (TLI.shouldExtendGSIndex(IdxVT, EltTy)) {
8481EVT NewIdxVT = IdxVT.changeVectorElementType(EltTy);
8482Index =DAG.getNode(ISD::SIGN_EXTEND,DL, NewIdxVT, Index);
8483 }
8484LD =DAG.getGatherVP(
8485DAG.getVTList(VT, MVT::Other), VT,DL,
8486 {DAG.getRoot(), Base, Index, Scale, OpValues[1], OpValues[2]}, MMO,
8487 IndexType);
8488PendingLoads.push_back(LD.getValue(1));
8489setValue(&VPIntrin, LD);
8490}
8491
8492void SelectionDAGBuilder::visitVPStore(
8493constVPIntrinsic &VPIntrin,constSmallVectorImpl<SDValue> &OpValues) {
8494SDLocDL =getCurSDLoc();
8495Value *PtrOperand = VPIntrin.getArgOperand(1);
8496EVT VT = OpValues[0].getValueType();
8497MaybeAlign Alignment = VPIntrin.getPointerAlignment();
8498AAMDNodes AAInfo = VPIntrin.getAAMetadata();
8499SDValueST;
8500if (!Alignment)
8501 Alignment =DAG.getEVTAlign(VT);
8502SDValuePtr = OpValues[1];
8503SDValueOffset =DAG.getUNDEF(Ptr.getValueType());
8504MachineMemOperand *MMO =DAG.getMachineFunction().getMachineMemOperand(
8505MachinePointerInfo(PtrOperand),MachineMemOperand::MOStore,
8506LocationSize::beforeOrAfterPointer(), *Alignment, AAInfo);
8507ST =DAG.getStoreVP(getMemoryRoot(),DL, OpValues[0],Ptr,Offset,
8508 OpValues[2], OpValues[3], VT, MMO,ISD::UNINDEXED,
8509/* IsTruncating */false,/*IsCompressing*/false);
8510DAG.setRoot(ST);
8511setValue(&VPIntrin, ST);
8512}
8513
8514void SelectionDAGBuilder::visitVPScatter(
8515constVPIntrinsic &VPIntrin,constSmallVectorImpl<SDValue> &OpValues) {
8516SDLocDL =getCurSDLoc();
8517constTargetLowering &TLI =DAG.getTargetLoweringInfo();
8518Value *PtrOperand = VPIntrin.getArgOperand(1);
8519EVT VT = OpValues[0].getValueType();
8520MaybeAlign Alignment = VPIntrin.getPointerAlignment();
8521AAMDNodes AAInfo = VPIntrin.getAAMetadata();
8522SDValueST;
8523if (!Alignment)
8524 Alignment =DAG.getEVTAlign(VT.getScalarType());
8525unsigned AS =
8526 PtrOperand->getType()->getScalarType()->getPointerAddressSpace();
8527MachineMemOperand *MMO =DAG.getMachineFunction().getMachineMemOperand(
8528MachinePointerInfo(AS),MachineMemOperand::MOStore,
8529LocationSize::beforeOrAfterPointer(), *Alignment, AAInfo);
8530SDValueBase,Index, Scale;
8531ISD::MemIndexType IndexType;
8532bool UniformBase =getUniformBase(PtrOperand,Base, Index, IndexType, Scale,
8533this, VPIntrin.getParent(),
8534 VT.getScalarStoreSize());
8535if (!UniformBase) {
8536Base =DAG.getConstant(0,DL, TLI.getPointerTy(DAG.getDataLayout()));
8537Index =getValue(PtrOperand);
8538 IndexType =ISD::SIGNED_SCALED;
8539 Scale =
8540DAG.getTargetConstant(1,DL, TLI.getPointerTy(DAG.getDataLayout()));
8541 }
8542EVT IdxVT =Index.getValueType();
8543EVT EltTy = IdxVT.getVectorElementType();
8544if (TLI.shouldExtendGSIndex(IdxVT, EltTy)) {
8545EVT NewIdxVT = IdxVT.changeVectorElementType(EltTy);
8546Index =DAG.getNode(ISD::SIGN_EXTEND,DL, NewIdxVT, Index);
8547 }
8548ST =DAG.getScatterVP(DAG.getVTList(MVT::Other), VT,DL,
8549 {getMemoryRoot(), OpValues[0], Base, Index, Scale,
8550 OpValues[2], OpValues[3]},
8551 MMO, IndexType);
8552DAG.setRoot(ST);
8553setValue(&VPIntrin, ST);
8554}
8555
8556void SelectionDAGBuilder::visitVPStridedLoad(
8557constVPIntrinsic &VPIntrin,EVT VT,
8558constSmallVectorImpl<SDValue> &OpValues) {
8559SDLocDL =getCurSDLoc();
8560Value *PtrOperand = VPIntrin.getArgOperand(0);
8561MaybeAlign Alignment = VPIntrin.getPointerAlignment();
8562if (!Alignment)
8563 Alignment =DAG.getEVTAlign(VT.getScalarType());
8564AAMDNodes AAInfo = VPIntrin.getAAMetadata();
8565constMDNode *Ranges =getRangeMetadata(VPIntrin);
8566MemoryLocationML =MemoryLocation::getAfter(PtrOperand, AAInfo);
8567bool AddToChain = !BatchAA || !BatchAA->pointsToConstantMemory(ML);
8568SDValue InChain = AddToChain ?DAG.getRoot() :DAG.getEntryNode();
8569unsigned AS = PtrOperand->getType()->getPointerAddressSpace();
8570MachineMemOperand *MMO =DAG.getMachineFunction().getMachineMemOperand(
8571MachinePointerInfo(AS),MachineMemOperand::MOLoad,
8572LocationSize::beforeOrAfterPointer(), *Alignment, AAInfo, Ranges);
8573
8574SDValueLD =DAG.getStridedLoadVP(VT,DL, InChain, OpValues[0], OpValues[1],
8575 OpValues[2], OpValues[3], MMO,
8576false/*IsExpanding*/);
8577
8578if (AddToChain)
8579PendingLoads.push_back(LD.getValue(1));
8580setValue(&VPIntrin, LD);
8581}
8582
8583void SelectionDAGBuilder::visitVPStridedStore(
8584constVPIntrinsic &VPIntrin,constSmallVectorImpl<SDValue> &OpValues) {
8585SDLocDL =getCurSDLoc();
8586Value *PtrOperand = VPIntrin.getArgOperand(1);
8587EVT VT = OpValues[0].getValueType();
8588MaybeAlign Alignment = VPIntrin.getPointerAlignment();
8589if (!Alignment)
8590 Alignment =DAG.getEVTAlign(VT.getScalarType());
8591AAMDNodes AAInfo = VPIntrin.getAAMetadata();
8592unsigned AS = PtrOperand->getType()->getPointerAddressSpace();
8593MachineMemOperand *MMO =DAG.getMachineFunction().getMachineMemOperand(
8594MachinePointerInfo(AS),MachineMemOperand::MOStore,
8595LocationSize::beforeOrAfterPointer(), *Alignment, AAInfo);
8596
8597SDValueST =DAG.getStridedStoreVP(
8598getMemoryRoot(),DL, OpValues[0], OpValues[1],
8599DAG.getUNDEF(OpValues[1].getValueType()), OpValues[2], OpValues[3],
8600 OpValues[4], VT, MMO,ISD::UNINDEXED,/*IsTruncating*/false,
8601/*IsCompressing*/false);
8602
8603DAG.setRoot(ST);
8604setValue(&VPIntrin, ST);
8605}
8606
8607void SelectionDAGBuilder::visitVPCmp(constVPCmpIntrinsic &VPIntrin) {
8608constTargetLowering &TLI =DAG.getTargetLoweringInfo();
8609SDLocDL =getCurSDLoc();
8610
8611ISD::CondCode Condition;
8612CmpInst::PredicateCondCode = VPIntrin.getPredicate();
8613bool IsFP = VPIntrin.getOperand(0)->getType()->isFPOrFPVectorTy();
8614if (IsFP) {
8615// FIXME: Regular fcmps are FPMathOperators which may have fast-math (nnan)
8616// flags, but calls that don't return floating-point types can't be
8617// FPMathOperators, like vp.fcmp. This affects constrained fcmp too.
8618 Condition =getFCmpCondCode(CondCode);
8619if (TM.Options.NoNaNsFPMath)
8620 Condition =getFCmpCodeWithoutNaN(Condition);
8621 }else {
8622 Condition =getICmpCondCode(CondCode);
8623 }
8624
8625SDValue Op1 =getValue(VPIntrin.getOperand(0));
8626SDValue Op2 =getValue(VPIntrin.getOperand(1));
8627// #2 is the condition code
8628SDValue MaskOp =getValue(VPIntrin.getOperand(3));
8629SDValue EVL =getValue(VPIntrin.getOperand(4));
8630MVT EVLParamVT = TLI.getVPExplicitVectorLengthTy();
8631assert(EVLParamVT.isScalarInteger() && EVLParamVT.bitsGE(MVT::i32) &&
8632"Unexpected target EVL type");
8633 EVL =DAG.getNode(ISD::ZERO_EXTEND,DL, EVLParamVT, EVL);
8634
8635EVT DestVT =DAG.getTargetLoweringInfo().getValueType(DAG.getDataLayout(),
8636 VPIntrin.getType());
8637setValue(&VPIntrin,
8638DAG.getSetCCVP(DL, DestVT, Op1, Op2, Condition, MaskOp, EVL));
8639}
8640
8641void SelectionDAGBuilder::visitVectorPredicationIntrinsic(
8642constVPIntrinsic &VPIntrin) {
8643SDLocDL =getCurSDLoc();
8644unsigned Opcode =getISDForVPIntrinsic(VPIntrin);
8645
8646auto IID = VPIntrin.getIntrinsicID();
8647
8648if (constauto *CmpI = dyn_cast<VPCmpIntrinsic>(&VPIntrin))
8649return visitVPCmp(*CmpI);
8650
8651SmallVector<EVT, 4> ValueVTs;
8652constTargetLowering &TLI =DAG.getTargetLoweringInfo();
8653ComputeValueVTs(TLI,DAG.getDataLayout(), VPIntrin.getType(), ValueVTs);
8654SDVTList VTs =DAG.getVTList(ValueVTs);
8655
8656auto EVLParamPos =VPIntrinsic::getVectorLengthParamPos(IID);
8657
8658MVT EVLParamVT = TLI.getVPExplicitVectorLengthTy();
8659assert(EVLParamVT.isScalarInteger() && EVLParamVT.bitsGE(MVT::i32) &&
8660"Unexpected target EVL type");
8661
8662// Request operands.
8663SmallVector<SDValue, 7> OpValues;
8664for (unsignedI = 0;I < VPIntrin.arg_size(); ++I) {
8665autoOp =getValue(VPIntrin.getArgOperand(I));
8666if (I == EVLParamPos)
8667Op =DAG.getNode(ISD::ZERO_EXTEND,DL, EVLParamVT,Op);
8668 OpValues.push_back(Op);
8669 }
8670
8671switch (Opcode) {
8672default: {
8673SDNodeFlags SDFlags;
8674if (auto *FPMO = dyn_cast<FPMathOperator>(&VPIntrin))
8675 SDFlags.copyFMF(*FPMO);
8676SDValueResult =DAG.getNode(Opcode,DL, VTs, OpValues, SDFlags);
8677setValue(&VPIntrin, Result);
8678break;
8679 }
8680case ISD::VP_LOAD:
8681 visitVPLoad(VPIntrin, ValueVTs[0], OpValues);
8682break;
8683case ISD::VP_GATHER:
8684 visitVPGather(VPIntrin, ValueVTs[0], OpValues);
8685break;
8686case ISD::EXPERIMENTAL_VP_STRIDED_LOAD:
8687 visitVPStridedLoad(VPIntrin, ValueVTs[0], OpValues);
8688break;
8689case ISD::VP_STORE:
8690 visitVPStore(VPIntrin, OpValues);
8691break;
8692case ISD::VP_SCATTER:
8693 visitVPScatter(VPIntrin, OpValues);
8694break;
8695case ISD::EXPERIMENTAL_VP_STRIDED_STORE:
8696 visitVPStridedStore(VPIntrin, OpValues);
8697break;
8698case ISD::VP_FMULADD: {
8699assert(OpValues.size() == 5 &&"Unexpected number of operands");
8700SDNodeFlags SDFlags;
8701if (auto *FPMO = dyn_cast<FPMathOperator>(&VPIntrin))
8702 SDFlags.copyFMF(*FPMO);
8703if (TM.Options.AllowFPOpFusion !=FPOpFusion::Strict &&
8704 TLI.isFMAFasterThanFMulAndFAdd(DAG.getMachineFunction(), ValueVTs[0])) {
8705setValue(&VPIntrin,DAG.getNode(ISD::VP_FMA,DL, VTs, OpValues, SDFlags));
8706 }else {
8707SDValueMul =DAG.getNode(
8708 ISD::VP_FMUL,DL, VTs,
8709 {OpValues[0], OpValues[1], OpValues[3], OpValues[4]}, SDFlags);
8710SDValueAdd =
8711DAG.getNode(ISD::VP_FADD,DL, VTs,
8712 {Mul, OpValues[2], OpValues[3], OpValues[4]}, SDFlags);
8713setValue(&VPIntrin,Add);
8714 }
8715break;
8716 }
8717case ISD::VP_IS_FPCLASS: {
8718constDataLayout DLayout =DAG.getDataLayout();
8719EVT DestVT = TLI.getValueType(DLayout, VPIntrin.getType());
8720autoConstant = OpValues[1]->getAsZExtVal();
8721SDValueCheck =DAG.getTargetConstant(Constant,DL, MVT::i32);
8722SDValueV =DAG.getNode(ISD::VP_IS_FPCLASS,DL, DestVT,
8723 {OpValues[0],Check, OpValues[2], OpValues[3]});
8724setValue(&VPIntrin, V);
8725return;
8726 }
8727case ISD::VP_INTTOPTR: {
8728SDValueN = OpValues[0];
8729EVT DestVT = TLI.getValueType(DAG.getDataLayout(), VPIntrin.getType());
8730EVT PtrMemVT = TLI.getMemValueType(DAG.getDataLayout(), VPIntrin.getType());
8731N =DAG.getVPPtrExtOrTrunc(getCurSDLoc(), DestVT,N, OpValues[1],
8732 OpValues[2]);
8733N =DAG.getVPZExtOrTrunc(getCurSDLoc(), PtrMemVT,N, OpValues[1],
8734 OpValues[2]);
8735setValue(&VPIntrin,N);
8736break;
8737 }
8738case ISD::VP_PTRTOINT: {
8739SDValueN = OpValues[0];
8740EVT DestVT =DAG.getTargetLoweringInfo().getValueType(DAG.getDataLayout(),
8741 VPIntrin.getType());
8742EVT PtrMemVT = TLI.getMemValueType(DAG.getDataLayout(),
8743 VPIntrin.getOperand(0)->getType());
8744N =DAG.getVPPtrExtOrTrunc(getCurSDLoc(), PtrMemVT,N, OpValues[1],
8745 OpValues[2]);
8746N =DAG.getVPZExtOrTrunc(getCurSDLoc(), DestVT,N, OpValues[1],
8747 OpValues[2]);
8748setValue(&VPIntrin,N);
8749break;
8750 }
8751case ISD::VP_ABS:
8752case ISD::VP_CTLZ:
8753case ISD::VP_CTLZ_ZERO_UNDEF:
8754case ISD::VP_CTTZ:
8755case ISD::VP_CTTZ_ZERO_UNDEF:
8756case ISD::VP_CTTZ_ELTS_ZERO_UNDEF:
8757case ISD::VP_CTTZ_ELTS: {
8758SDValueResult =
8759DAG.getNode(Opcode,DL, VTs, {OpValues[0], OpValues[2], OpValues[3]});
8760setValue(&VPIntrin, Result);
8761break;
8762 }
8763 }
8764}
8765
8766SDValue SelectionDAGBuilder::lowerStartEH(SDValue Chain,
8767constBasicBlock *EHPadBB,
8768MCSymbol *&BeginLabel) {
8769MachineFunction &MF =DAG.getMachineFunction();
8770
8771// Insert a label before the invoke call to mark the try range. This can be
8772// used to detect deletion of the invoke via the MachineModuleInfo.
8773 BeginLabel = MF.getContext().createTempSymbol();
8774
8775// For SjLj, keep track of which landing pads go with which invokes
8776// so as to maintain the ordering of pads in the LSDA.
8777unsigned CallSiteIndex =FuncInfo.getCurrentCallSite();
8778if (CallSiteIndex) {
8779 MF.setCallSiteBeginLabel(BeginLabel, CallSiteIndex);
8780LPadToCallSiteMap[FuncInfo.getMBB(EHPadBB)].push_back(CallSiteIndex);
8781
8782// Now that the call site is handled, stop tracking it.
8783FuncInfo.setCurrentCallSite(0);
8784 }
8785
8786returnDAG.getEHLabel(getCurSDLoc(), Chain, BeginLabel);
8787}
8788
8789SDValue SelectionDAGBuilder::lowerEndEH(SDValue Chain,constInvokeInst *II,
8790constBasicBlock *EHPadBB,
8791MCSymbol *BeginLabel) {
8792assert(BeginLabel &&"BeginLabel should've been set");
8793
8794MachineFunction &MF =DAG.getMachineFunction();
8795
8796// Insert a label at the end of the invoke call to mark the try range. This
8797// can be used to detect deletion of the invoke via the MachineModuleInfo.
8798MCSymbol *EndLabel = MF.getContext().createTempSymbol();
8799 Chain =DAG.getEHLabel(getCurSDLoc(), Chain, EndLabel);
8800
8801// Inform MachineModuleInfo of range.
8802auto Pers =classifyEHPersonality(FuncInfo.Fn->getPersonalityFn());
8803// There is a platform (e.g. wasm) that uses funclet style IR but does not
8804// actually use outlined funclets and their LSDA info style.
8805if (MF.hasEHFunclets() &&isFuncletEHPersonality(Pers)) {
8806assert(II &&"II should've been set");
8807WinEHFuncInfo *EHInfo = MF.getWinEHFuncInfo();
8808 EHInfo->addIPToStateRange(II, BeginLabel, EndLabel);
8809 }elseif (!isScopedEHPersonality(Pers)) {
8810assert(EHPadBB);
8811 MF.addInvoke(FuncInfo.getMBB(EHPadBB), BeginLabel, EndLabel);
8812 }
8813
8814return Chain;
8815}
8816
8817std::pair<SDValue, SDValue>
8818SelectionDAGBuilder::lowerInvokable(TargetLowering::CallLoweringInfo &CLI,
8819constBasicBlock *EHPadBB) {
8820MCSymbol *BeginLabel =nullptr;
8821
8822if (EHPadBB) {
8823// Both PendingLoads and PendingExports must be flushed here;
8824// this call might not return.
8825 (void)getRoot();
8826DAG.setRoot(lowerStartEH(getControlRoot(), EHPadBB, BeginLabel));
8827 CLI.setChain(getRoot());
8828 }
8829
8830constTargetLowering &TLI =DAG.getTargetLoweringInfo();
8831 std::pair<SDValue, SDValue> Result = TLI.LowerCallTo(CLI);
8832
8833assert((CLI.IsTailCall || Result.second.getNode()) &&
8834"Non-null chain expected with non-tail call!");
8835assert((Result.second.getNode() || !Result.first.getNode()) &&
8836"Null value expected with tail call!");
8837
8838if (!Result.second.getNode()) {
8839// As a special case, a null chain means that a tail call has been emitted
8840// and the DAG root is already updated.
8841HasTailCall =true;
8842
8843// Since there's no actual continuation from this block, nothing can be
8844// relying on us setting vregs for them.
8845 PendingExports.clear();
8846 }else {
8847DAG.setRoot(Result.second);
8848 }
8849
8850if (EHPadBB) {
8851DAG.setRoot(lowerEndEH(getRoot(), cast_or_null<InvokeInst>(CLI.CB), EHPadBB,
8852 BeginLabel));
8853 Result.second =getRoot();
8854 }
8855
8856return Result;
8857}
8858
8859voidSelectionDAGBuilder::LowerCallTo(constCallBase &CB,SDValue Callee,
8860bool isTailCall,bool isMustTailCall,
8861constBasicBlock *EHPadBB,
8862constTargetLowering::PtrAuthInfo *PAI) {
8863auto &DL =DAG.getDataLayout();
8864FunctionType *FTy = CB.getFunctionType();
8865Type *RetTy = CB.getType();
8866
8867TargetLowering::ArgListTy Args;
8868 Args.reserve(CB.arg_size());
8869
8870constValue *SwiftErrorVal =nullptr;
8871constTargetLowering &TLI =DAG.getTargetLoweringInfo();
8872
8873if (isTailCall) {
8874// Avoid emitting tail calls in functions with the disable-tail-calls
8875// attribute.
8876auto *Caller = CB.getParent()->getParent();
8877if (Caller->getFnAttribute("disable-tail-calls").getValueAsString() ==
8878"true" && !isMustTailCall)
8879 isTailCall =false;
8880
8881// We can't tail call inside a function with a swifterror argument. Lowering
8882// does not support this yet. It would have to move into the swifterror
8883// register before the call.
8884if (TLI.supportSwiftError() &&
8885 Caller->getAttributes().hasAttrSomewhere(Attribute::SwiftError))
8886 isTailCall =false;
8887 }
8888
8889for (autoI = CB.arg_begin(), E = CB.arg_end();I != E; ++I) {
8890TargetLowering::ArgListEntry Entry;
8891constValue *V = *I;
8892
8893// Skip empty types
8894if (V->getType()->isEmptyTy())
8895continue;
8896
8897SDValue ArgNode =getValue(V);
8898 Entry.Node = ArgNode; Entry.Ty = V->getType();
8899
8900 Entry.setAttributes(&CB,I - CB.arg_begin());
8901
8902// Use swifterror virtual register as input to the call.
8903if (Entry.IsSwiftError && TLI.supportSwiftError()) {
8904 SwiftErrorVal = V;
8905// We find the virtual register for the actual swifterror argument.
8906// Instead of using the Value, we use the virtual register instead.
8907 Entry.Node =
8908DAG.getRegister(SwiftError.getOrCreateVRegUseAt(&CB,FuncInfo.MBB, V),
8909EVT(TLI.getPointerTy(DL)));
8910 }
8911
8912 Args.push_back(Entry);
8913
8914// If we have an explicit sret argument that is an Instruction, (i.e., it
8915// might point to function-local memory), we can't meaningfully tail-call.
8916if (Entry.IsSRet && isa<Instruction>(V))
8917 isTailCall =false;
8918 }
8919
8920// If call site has a cfguardtarget operand bundle, create and add an
8921// additional ArgListEntry.
8922if (auto Bundle = CB.getOperandBundle(LLVMContext::OB_cfguardtarget)) {
8923TargetLowering::ArgListEntry Entry;
8924Value *V = Bundle->Inputs[0];
8925SDValue ArgNode =getValue(V);
8926 Entry.Node = ArgNode;
8927 Entry.Ty = V->getType();
8928 Entry.IsCFGuardTarget =true;
8929 Args.push_back(Entry);
8930 }
8931
8932// Check if target-independent constraints permit a tail call here.
8933// Target-dependent constraints are checked within TLI->LowerCallTo.
8934if (isTailCall && !isInTailCallPosition(CB,DAG.getTarget()))
8935 isTailCall =false;
8936
8937// Disable tail calls if there is an swifterror argument. Targets have not
8938// been updated to support tail calls.
8939if (TLI.supportSwiftError() && SwiftErrorVal)
8940 isTailCall =false;
8941
8942ConstantInt *CFIType =nullptr;
8943if (CB.isIndirectCall()) {
8944if (auto Bundle = CB.getOperandBundle(LLVMContext::OB_kcfi)) {
8945if (!TLI.supportKCFIBundles())
8946report_fatal_error(
8947"Target doesn't support calls with kcfi operand bundles.");
8948 CFIType = cast<ConstantInt>(Bundle->Inputs[0]);
8949assert(CFIType->getType()->isIntegerTy(32) &&"Invalid CFI type");
8950 }
8951 }
8952
8953SDValue ConvControlToken;
8954if (auto Bundle = CB.getOperandBundle(LLVMContext::OB_convergencectrl)) {
8955auto *Token = Bundle->Inputs[0].get();
8956 ConvControlToken =getValue(Token);
8957 }
8958
8959TargetLowering::CallLoweringInfo CLI(DAG);
8960 CLI.setDebugLoc(getCurSDLoc())
8961 .setChain(getRoot())
8962 .setCallee(RetTy, FTy, Callee, std::move(Args), CB)
8963 .setTailCall(isTailCall)
8964 .setConvergent(CB.isConvergent())
8965 .setIsPreallocated(
8966 CB.countOperandBundlesOfType(LLVMContext::OB_preallocated) != 0)
8967 .setCFIType(CFIType)
8968 .setConvergenceControlToken(ConvControlToken);
8969
8970// Set the pointer authentication info if we have it.
8971if (PAI) {
8972if (!TLI.supportPtrAuthBundles())
8973report_fatal_error(
8974"This target doesn't support calls with ptrauth operand bundles.");
8975 CLI.setPtrAuth(*PAI);
8976 }
8977
8978 std::pair<SDValue, SDValue> Result =lowerInvokable(CLI, EHPadBB);
8979
8980if (Result.first.getNode()) {
8981 Result.first =lowerRangeToAssertZExt(DAG, CB, Result.first);
8982setValue(&CB, Result.first);
8983 }
8984
8985// The last element of CLI.InVals has the SDValue for swifterror return.
8986// Here we copy it to a virtual register and update SwiftErrorMap for
8987// book-keeping.
8988if (SwiftErrorVal && TLI.supportSwiftError()) {
8989// Get the last element of InVals.
8990SDValue Src = CLI.InVals.back();
8991Register VReg =
8992SwiftError.getOrCreateVRegDefAt(&CB,FuncInfo.MBB, SwiftErrorVal);
8993SDValue CopyNode = CLI.DAG.getCopyToReg(Result.second, CLI.DL, VReg, Src);
8994DAG.setRoot(CopyNode);
8995 }
8996}
8997
8998staticSDValuegetMemCmpLoad(constValue *PtrVal,MVT LoadVT,
8999SelectionDAGBuilder &Builder) {
9000// Check to see if this load can be trivially constant folded, e.g. if the
9001// input is from a string literal.
9002if (constConstant *LoadInput = dyn_cast<Constant>(PtrVal)) {
9003// Cast pointer to the type we really want to load.
9004Type *LoadTy =
9005Type::getIntNTy(PtrVal->getContext(), LoadVT.getScalarSizeInBits());
9006if (LoadVT.isVector())
9007 LoadTy =FixedVectorType::get(LoadTy, LoadVT.getVectorNumElements());
9008if (constConstant *LoadCst =
9009ConstantFoldLoadFromConstPtr(const_cast<Constant *>(LoadInput),
9010 LoadTy, Builder.DAG.getDataLayout()))
9011return Builder.getValue(LoadCst);
9012 }
9013
9014// Otherwise, we have to emit the load. If the pointer is to unfoldable but
9015// still constant memory, the input chain can be the entry node.
9016SDValue Root;
9017bool ConstantMemory =false;
9018
9019// Do not serialize (non-volatile) loads of constant memory with anything.
9020if (Builder.BatchAA && Builder.BatchAA->pointsToConstantMemory(PtrVal)) {
9021 Root = Builder.DAG.getEntryNode();
9022 ConstantMemory =true;
9023 }else {
9024// Do not serialize non-volatile loads against each other.
9025 Root = Builder.DAG.getRoot();
9026 }
9027
9028SDValuePtr = Builder.getValue(PtrVal);
9029SDValue LoadVal =
9030 Builder.DAG.getLoad(LoadVT, Builder.getCurSDLoc(), Root,Ptr,
9031MachinePointerInfo(PtrVal),Align(1));
9032
9033if (!ConstantMemory)
9034 Builder.PendingLoads.push_back(LoadVal.getValue(1));
9035return LoadVal;
9036}
9037
9038/// Record the value for an instruction that produces an integer result,
9039/// converting the type where necessary.
9040void SelectionDAGBuilder::processIntegerCallValue(constInstruction &I,
9041SDValueValue,
9042bool IsSigned) {
9043EVT VT =DAG.getTargetLoweringInfo().getValueType(DAG.getDataLayout(),
9044I.getType(),true);
9045Value =DAG.getExtOrTrunc(IsSigned,Value,getCurSDLoc(), VT);
9046setValue(&I,Value);
9047}
9048
9049/// See if we can lower a memcmp/bcmp call into an optimized form. If so, return
9050/// true and lower it. Otherwise return false, and it will be lowered like a
9051/// normal call.
9052/// The caller already checked that \p I calls the appropriate LibFunc with a
9053/// correct prototype.
9054bool SelectionDAGBuilder::visitMemCmpBCmpCall(constCallInst &I) {
9055constValue *LHS =I.getArgOperand(0), *RHS =I.getArgOperand(1);
9056constValue *Size =I.getArgOperand(2);
9057constConstantSDNode *CSize = dyn_cast<ConstantSDNode>(getValue(Size));
9058if (CSize && CSize->getZExtValue() == 0) {
9059EVT CallVT =DAG.getTargetLoweringInfo().getValueType(DAG.getDataLayout(),
9060I.getType(),true);
9061setValue(&I,DAG.getConstant(0,getCurSDLoc(), CallVT));
9062returntrue;
9063 }
9064
9065constSelectionDAGTargetInfo &TSI =DAG.getSelectionDAGInfo();
9066 std::pair<SDValue, SDValue> Res = TSI.EmitTargetCodeForMemcmp(
9067DAG,getCurSDLoc(),DAG.getRoot(),getValue(LHS),getValue(RHS),
9068getValue(Size),MachinePointerInfo(LHS),MachinePointerInfo(RHS));
9069if (Res.first.getNode()) {
9070 processIntegerCallValue(I, Res.first,true);
9071PendingLoads.push_back(Res.second);
9072returntrue;
9073 }
9074
9075// memcmp(S1,S2,2) != 0 -> (*(short*)LHS != *(short*)RHS) != 0
9076// memcmp(S1,S2,4) != 0 -> (*(int*)LHS != *(int*)RHS) != 0
9077if (!CSize || !isOnlyUsedInZeroEqualityComparison(&I))
9078returnfalse;
9079
9080// If the target has a fast compare for the given size, it will return a
9081// preferred load type for that size. Require that the load VT is legal and
9082// that the target supports unaligned loads of that type. Otherwise, return
9083// INVALID.
9084auto hasFastLoadsAndCompare = [&](unsigned NumBits) {
9085constTargetLowering &TLI =DAG.getTargetLoweringInfo();
9086MVT LVT = TLI.hasFastEqualityCompare(NumBits);
9087if (LVT !=MVT::INVALID_SIMPLE_VALUE_TYPE) {
9088// TODO: Handle 5 byte compare as 4-byte + 1 byte.
9089// TODO: Handle 8 byte compare on x86-32 as two 32-bit loads.
9090// TODO: Check alignment of src and dest ptrs.
9091unsigned DstAS =LHS->getType()->getPointerAddressSpace();
9092unsigned SrcAS =RHS->getType()->getPointerAddressSpace();
9093if (!TLI.isTypeLegal(LVT) ||
9094 !TLI.allowsMisalignedMemoryAccesses(LVT, SrcAS) ||
9095 !TLI.allowsMisalignedMemoryAccesses(LVT, DstAS))
9096 LVT =MVT::INVALID_SIMPLE_VALUE_TYPE;
9097 }
9098
9099return LVT;
9100 };
9101
9102// This turns into unaligned loads. We only do this if the target natively
9103// supports the MVT we'll be loading or if it is small enough (<= 4) that
9104// we'll only produce a small number of byte loads.
9105MVT LoadVT;
9106unsigned NumBitsToCompare = CSize->getZExtValue() * 8;
9107switch (NumBitsToCompare) {
9108default:
9109returnfalse;
9110case 16:
9111 LoadVT = MVT::i16;
9112break;
9113case 32:
9114 LoadVT = MVT::i32;
9115break;
9116case 64:
9117case 128:
9118case 256:
9119 LoadVT = hasFastLoadsAndCompare(NumBitsToCompare);
9120break;
9121 }
9122
9123if (LoadVT ==MVT::INVALID_SIMPLE_VALUE_TYPE)
9124returnfalse;
9125
9126SDValue LoadL =getMemCmpLoad(LHS, LoadVT, *this);
9127SDValue LoadR =getMemCmpLoad(RHS, LoadVT, *this);
9128
9129// Bitcast to a wide integer type if the loads are vectors.
9130if (LoadVT.isVector()) {
9131EVT CmpVT =EVT::getIntegerVT(LHS->getContext(), LoadVT.getSizeInBits());
9132 LoadL =DAG.getBitcast(CmpVT, LoadL);
9133 LoadR =DAG.getBitcast(CmpVT, LoadR);
9134 }
9135
9136SDValueCmp =DAG.getSetCC(getCurSDLoc(), MVT::i1, LoadL, LoadR,ISD::SETNE);
9137 processIntegerCallValue(I, Cmp,false);
9138returntrue;
9139}
9140
9141/// See if we can lower a memchr call into an optimized form. If so, return
9142/// true and lower it. Otherwise return false, and it will be lowered like a
9143/// normal call.
9144/// The caller already checked that \p I calls the appropriate LibFunc with a
9145/// correct prototype.
9146bool SelectionDAGBuilder::visitMemChrCall(constCallInst &I) {
9147constValue *Src =I.getArgOperand(0);
9148constValue *Char =I.getArgOperand(1);
9149constValue *Length =I.getArgOperand(2);
9150
9151constSelectionDAGTargetInfo &TSI =DAG.getSelectionDAGInfo();
9152 std::pair<SDValue, SDValue> Res =
9153 TSI.EmitTargetCodeForMemchr(DAG,getCurSDLoc(),DAG.getRoot(),
9154getValue(Src),getValue(Char),getValue(Length),
9155MachinePointerInfo(Src));
9156if (Res.first.getNode()) {
9157setValue(&I, Res.first);
9158PendingLoads.push_back(Res.second);
9159returntrue;
9160 }
9161
9162returnfalse;
9163}
9164
9165/// See if we can lower a mempcpy call into an optimized form. If so, return
9166/// true and lower it. Otherwise return false, and it will be lowered like a
9167/// normal call.
9168/// The caller already checked that \p I calls the appropriate LibFunc with a
9169/// correct prototype.
9170bool SelectionDAGBuilder::visitMemPCpyCall(constCallInst &I) {
9171SDValue Dst =getValue(I.getArgOperand(0));
9172SDValue Src =getValue(I.getArgOperand(1));
9173SDValueSize =getValue(I.getArgOperand(2));
9174
9175Align DstAlign =DAG.InferPtrAlign(Dst).valueOrOne();
9176Align SrcAlign =DAG.InferPtrAlign(Src).valueOrOne();
9177// DAG::getMemcpy needs Alignment to be defined.
9178Align Alignment = std::min(DstAlign, SrcAlign);
9179
9180SDLoc sdl =getCurSDLoc();
9181
9182// In the mempcpy context we need to pass in a false value for isTailCall
9183// because the return pointer needs to be adjusted by the size of
9184// the copied memory.
9185SDValue Root =getMemoryRoot();
9186SDValue MC =DAG.getMemcpy(
9187 Root, sdl, Dst, Src,Size, Alignment,false,false,/*CI=*/nullptr,
9188 std::nullopt,MachinePointerInfo(I.getArgOperand(0)),
9189MachinePointerInfo(I.getArgOperand(1)),I.getAAMetadata());
9190assert(MC.getNode() !=nullptr &&
9191"** memcpy should not be lowered as TailCall in mempcpy context **");
9192DAG.setRoot(MC);
9193
9194// Check if Size needs to be truncated or extended.
9195Size =DAG.getSExtOrTrunc(Size, sdl, Dst.getValueType());
9196
9197// Adjust return pointer to point just past the last dst byte.
9198SDValue DstPlusSize =DAG.getNode(ISD::ADD, sdl, Dst.getValueType(),
9199 Dst,Size);
9200setValue(&I, DstPlusSize);
9201returntrue;
9202}
9203
9204/// See if we can lower a strcpy call into an optimized form. If so, return
9205/// true and lower it, otherwise return false and it will be lowered like a
9206/// normal call.
9207/// The caller already checked that \p I calls the appropriate LibFunc with a
9208/// correct prototype.
9209bool SelectionDAGBuilder::visitStrCpyCall(constCallInst &I,bool isStpcpy) {
9210constValue *Arg0 =I.getArgOperand(0), *Arg1 =I.getArgOperand(1);
9211
9212constSelectionDAGTargetInfo &TSI =DAG.getSelectionDAGInfo();
9213 std::pair<SDValue, SDValue> Res =
9214 TSI.EmitTargetCodeForStrcpy(DAG,getCurSDLoc(),getRoot(),
9215getValue(Arg0),getValue(Arg1),
9216MachinePointerInfo(Arg0),
9217MachinePointerInfo(Arg1), isStpcpy);
9218if (Res.first.getNode()) {
9219setValue(&I, Res.first);
9220DAG.setRoot(Res.second);
9221returntrue;
9222 }
9223
9224returnfalse;
9225}
9226
9227/// See if we can lower a strcmp call into an optimized form. If so, return
9228/// true and lower it, otherwise return false and it will be lowered like a
9229/// normal call.
9230/// The caller already checked that \p I calls the appropriate LibFunc with a
9231/// correct prototype.
9232bool SelectionDAGBuilder::visitStrCmpCall(constCallInst &I) {
9233constValue *Arg0 =I.getArgOperand(0), *Arg1 =I.getArgOperand(1);
9234
9235constSelectionDAGTargetInfo &TSI =DAG.getSelectionDAGInfo();
9236 std::pair<SDValue, SDValue> Res =
9237 TSI.EmitTargetCodeForStrcmp(DAG,getCurSDLoc(),DAG.getRoot(),
9238getValue(Arg0),getValue(Arg1),
9239MachinePointerInfo(Arg0),
9240MachinePointerInfo(Arg1));
9241if (Res.first.getNode()) {
9242 processIntegerCallValue(I, Res.first,true);
9243PendingLoads.push_back(Res.second);
9244returntrue;
9245 }
9246
9247returnfalse;
9248}
9249
9250/// See if we can lower a strlen call into an optimized form. If so, return
9251/// true and lower it, otherwise return false and it will be lowered like a
9252/// normal call.
9253/// The caller already checked that \p I calls the appropriate LibFunc with a
9254/// correct prototype.
9255bool SelectionDAGBuilder::visitStrLenCall(constCallInst &I) {
9256constValue *Arg0 =I.getArgOperand(0);
9257
9258constSelectionDAGTargetInfo &TSI =DAG.getSelectionDAGInfo();
9259 std::pair<SDValue, SDValue> Res =
9260 TSI.EmitTargetCodeForStrlen(DAG,getCurSDLoc(),DAG.getRoot(),
9261getValue(Arg0),MachinePointerInfo(Arg0));
9262if (Res.first.getNode()) {
9263 processIntegerCallValue(I, Res.first,false);
9264PendingLoads.push_back(Res.second);
9265returntrue;
9266 }
9267
9268returnfalse;
9269}
9270
9271/// See if we can lower a strnlen call into an optimized form. If so, return
9272/// true and lower it, otherwise return false and it will be lowered like a
9273/// normal call.
9274/// The caller already checked that \p I calls the appropriate LibFunc with a
9275/// correct prototype.
9276bool SelectionDAGBuilder::visitStrNLenCall(constCallInst &I) {
9277constValue *Arg0 =I.getArgOperand(0), *Arg1 =I.getArgOperand(1);
9278
9279constSelectionDAGTargetInfo &TSI =DAG.getSelectionDAGInfo();
9280 std::pair<SDValue, SDValue> Res =
9281 TSI.EmitTargetCodeForStrnlen(DAG,getCurSDLoc(),DAG.getRoot(),
9282getValue(Arg0),getValue(Arg1),
9283MachinePointerInfo(Arg0));
9284if (Res.first.getNode()) {
9285 processIntegerCallValue(I, Res.first,false);
9286PendingLoads.push_back(Res.second);
9287returntrue;
9288 }
9289
9290returnfalse;
9291}
9292
9293/// See if we can lower a unary floating-point operation into an SDNode with
9294/// the specified Opcode. If so, return true and lower it, otherwise return
9295/// false and it will be lowered like a normal call.
9296/// The caller already checked that \p I calls the appropriate LibFunc with a
9297/// correct prototype.
9298bool SelectionDAGBuilder::visitUnaryFloatCall(constCallInst &I,
9299unsigned Opcode) {
9300// We already checked this call's prototype; verify it doesn't modify errno.
9301if (!I.onlyReadsMemory())
9302returnfalse;
9303
9304SDNodeFlagsFlags;
9305Flags.copyFMF(cast<FPMathOperator>(I));
9306
9307SDValue Tmp =getValue(I.getArgOperand(0));
9308setValue(&I,
9309DAG.getNode(Opcode,getCurSDLoc(), Tmp.getValueType(), Tmp, Flags));
9310returntrue;
9311}
9312
9313/// See if we can lower a binary floating-point operation into an SDNode with
9314/// the specified Opcode. If so, return true and lower it. Otherwise return
9315/// false, and it will be lowered like a normal call.
9316/// The caller already checked that \p I calls the appropriate LibFunc with a
9317/// correct prototype.
9318bool SelectionDAGBuilder::visitBinaryFloatCall(constCallInst &I,
9319unsigned Opcode) {
9320// We already checked this call's prototype; verify it doesn't modify errno.
9321if (!I.onlyReadsMemory())
9322returnfalse;
9323
9324SDNodeFlagsFlags;
9325Flags.copyFMF(cast<FPMathOperator>(I));
9326
9327SDValue Tmp0 =getValue(I.getArgOperand(0));
9328SDValue Tmp1 =getValue(I.getArgOperand(1));
9329EVT VT = Tmp0.getValueType();
9330setValue(&I,DAG.getNode(Opcode,getCurSDLoc(), VT, Tmp0, Tmp1, Flags));
9331returntrue;
9332}
9333
9334void SelectionDAGBuilder::visitCall(constCallInst &I) {
9335// Handle inline assembly differently.
9336if (I.isInlineAsm()) {
9337 visitInlineAsm(I);
9338return;
9339 }
9340
9341diagnoseDontCall(I);
9342
9343if (Function *F =I.getCalledFunction()) {
9344if (F->isDeclaration()) {
9345// Is this an LLVM intrinsic or a target-specific intrinsic?
9346unsigned IID =F->getIntrinsicID();
9347if (!IID)
9348if (constTargetIntrinsicInfo *II = TM.getIntrinsicInfo())
9349 IID =II->getIntrinsicID(F);
9350
9351if (IID) {
9352 visitIntrinsicCall(I, IID);
9353return;
9354 }
9355 }
9356
9357// Check for well-known libc/libm calls. If the function is internal, it
9358// can't be a library call. Don't do the check if marked as nobuiltin for
9359// some reason or the call site requires strict floating point semantics.
9360LibFuncFunc;
9361if (!I.isNoBuiltin() && !I.isStrictFP() && !F->hasLocalLinkage() &&
9362F->hasName() &&LibInfo->getLibFunc(*F, Func) &&
9363LibInfo->hasOptimizedCodeGen(Func)) {
9364switch (Func) {
9365default:break;
9366case LibFunc_bcmp:
9367if (visitMemCmpBCmpCall(I))
9368return;
9369break;
9370case LibFunc_copysign:
9371case LibFunc_copysignf:
9372case LibFunc_copysignl:
9373// We already checked this call's prototype; verify it doesn't modify
9374// errno.
9375if (I.onlyReadsMemory()) {
9376SDValueLHS =getValue(I.getArgOperand(0));
9377SDValueRHS =getValue(I.getArgOperand(1));
9378setValue(&I,DAG.getNode(ISD::FCOPYSIGN,getCurSDLoc(),
9379LHS.getValueType(), LHS, RHS));
9380return;
9381 }
9382break;
9383case LibFunc_fabs:
9384case LibFunc_fabsf:
9385case LibFunc_fabsl:
9386if (visitUnaryFloatCall(I,ISD::FABS))
9387return;
9388break;
9389case LibFunc_fmin:
9390case LibFunc_fminf:
9391case LibFunc_fminl:
9392if (visitBinaryFloatCall(I,ISD::FMINNUM))
9393return;
9394break;
9395case LibFunc_fmax:
9396case LibFunc_fmaxf:
9397case LibFunc_fmaxl:
9398if (visitBinaryFloatCall(I,ISD::FMAXNUM))
9399return;
9400break;
9401case LibFunc_fminimum_num:
9402case LibFunc_fminimum_numf:
9403case LibFunc_fminimum_numl:
9404if (visitBinaryFloatCall(I,ISD::FMINIMUMNUM))
9405return;
9406break;
9407case LibFunc_fmaximum_num:
9408case LibFunc_fmaximum_numf:
9409case LibFunc_fmaximum_numl:
9410if (visitBinaryFloatCall(I,ISD::FMAXIMUMNUM))
9411return;
9412break;
9413case LibFunc_sin:
9414case LibFunc_sinf:
9415case LibFunc_sinl:
9416if (visitUnaryFloatCall(I,ISD::FSIN))
9417return;
9418break;
9419case LibFunc_cos:
9420case LibFunc_cosf:
9421case LibFunc_cosl:
9422if (visitUnaryFloatCall(I,ISD::FCOS))
9423return;
9424break;
9425case LibFunc_tan:
9426case LibFunc_tanf:
9427case LibFunc_tanl:
9428if (visitUnaryFloatCall(I,ISD::FTAN))
9429return;
9430break;
9431case LibFunc_asin:
9432case LibFunc_asinf:
9433case LibFunc_asinl:
9434if (visitUnaryFloatCall(I,ISD::FASIN))
9435return;
9436break;
9437case LibFunc_acos:
9438case LibFunc_acosf:
9439case LibFunc_acosl:
9440if (visitUnaryFloatCall(I,ISD::FACOS))
9441return;
9442break;
9443case LibFunc_atan:
9444case LibFunc_atanf:
9445case LibFunc_atanl:
9446if (visitUnaryFloatCall(I,ISD::FATAN))
9447return;
9448break;
9449case LibFunc_atan2:
9450case LibFunc_atan2f:
9451case LibFunc_atan2l:
9452if (visitBinaryFloatCall(I,ISD::FATAN2))
9453return;
9454break;
9455case LibFunc_sinh:
9456case LibFunc_sinhf:
9457case LibFunc_sinhl:
9458if (visitUnaryFloatCall(I,ISD::FSINH))
9459return;
9460break;
9461case LibFunc_cosh:
9462case LibFunc_coshf:
9463case LibFunc_coshl:
9464if (visitUnaryFloatCall(I,ISD::FCOSH))
9465return;
9466break;
9467case LibFunc_tanh:
9468case LibFunc_tanhf:
9469case LibFunc_tanhl:
9470if (visitUnaryFloatCall(I,ISD::FTANH))
9471return;
9472break;
9473case LibFunc_sqrt:
9474case LibFunc_sqrtf:
9475case LibFunc_sqrtl:
9476case LibFunc_sqrt_finite:
9477case LibFunc_sqrtf_finite:
9478case LibFunc_sqrtl_finite:
9479if (visitUnaryFloatCall(I,ISD::FSQRT))
9480return;
9481break;
9482case LibFunc_floor:
9483case LibFunc_floorf:
9484case LibFunc_floorl:
9485if (visitUnaryFloatCall(I,ISD::FFLOOR))
9486return;
9487break;
9488case LibFunc_nearbyint:
9489case LibFunc_nearbyintf:
9490case LibFunc_nearbyintl:
9491if (visitUnaryFloatCall(I,ISD::FNEARBYINT))
9492return;
9493break;
9494case LibFunc_ceil:
9495case LibFunc_ceilf:
9496case LibFunc_ceill:
9497if (visitUnaryFloatCall(I,ISD::FCEIL))
9498return;
9499break;
9500case LibFunc_rint:
9501case LibFunc_rintf:
9502case LibFunc_rintl:
9503if (visitUnaryFloatCall(I,ISD::FRINT))
9504return;
9505break;
9506case LibFunc_round:
9507case LibFunc_roundf:
9508case LibFunc_roundl:
9509if (visitUnaryFloatCall(I,ISD::FROUND))
9510return;
9511break;
9512case LibFunc_trunc:
9513case LibFunc_truncf:
9514case LibFunc_truncl:
9515if (visitUnaryFloatCall(I,ISD::FTRUNC))
9516return;
9517break;
9518case LibFunc_log2:
9519case LibFunc_log2f:
9520case LibFunc_log2l:
9521if (visitUnaryFloatCall(I,ISD::FLOG2))
9522return;
9523break;
9524case LibFunc_exp2:
9525case LibFunc_exp2f:
9526case LibFunc_exp2l:
9527if (visitUnaryFloatCall(I,ISD::FEXP2))
9528return;
9529break;
9530case LibFunc_exp10:
9531case LibFunc_exp10f:
9532case LibFunc_exp10l:
9533if (visitUnaryFloatCall(I,ISD::FEXP10))
9534return;
9535break;
9536case LibFunc_ldexp:
9537case LibFunc_ldexpf:
9538case LibFunc_ldexpl:
9539if (visitBinaryFloatCall(I,ISD::FLDEXP))
9540return;
9541break;
9542case LibFunc_memcmp:
9543if (visitMemCmpBCmpCall(I))
9544return;
9545break;
9546case LibFunc_mempcpy:
9547if (visitMemPCpyCall(I))
9548return;
9549break;
9550case LibFunc_memchr:
9551if (visitMemChrCall(I))
9552return;
9553break;
9554case LibFunc_strcpy:
9555if (visitStrCpyCall(I,false))
9556return;
9557break;
9558case LibFunc_stpcpy:
9559if (visitStrCpyCall(I,true))
9560return;
9561break;
9562case LibFunc_strcmp:
9563if (visitStrCmpCall(I))
9564return;
9565break;
9566case LibFunc_strlen:
9567if (visitStrLenCall(I))
9568return;
9569break;
9570case LibFunc_strnlen:
9571if (visitStrNLenCall(I))
9572return;
9573break;
9574 }
9575 }
9576 }
9577
9578if (I.countOperandBundlesOfType(LLVMContext::OB_ptrauth)) {
9579LowerCallSiteWithPtrAuthBundle(cast<CallBase>(I),/*EHPadBB=*/nullptr);
9580return;
9581 }
9582
9583// Deopt bundles are lowered in LowerCallSiteWithDeoptBundle, and we don't
9584// have to do anything here to lower funclet bundles.
9585// CFGuardTarget bundles are lowered in LowerCallTo.
9586assert(!I.hasOperandBundlesOtherThan(
9587 {LLVMContext::OB_deopt, LLVMContext::OB_funclet,
9588 LLVMContext::OB_cfguardtarget, LLVMContext::OB_preallocated,
9589 LLVMContext::OB_clang_arc_attachedcall, LLVMContext::OB_kcfi,
9590 LLVMContext::OB_convergencectrl}) &&
9591"Cannot lower calls with arbitrary operand bundles!");
9592
9593SDValueCallee =getValue(I.getCalledOperand());
9594
9595if (I.hasDeoptState())
9596LowerCallSiteWithDeoptBundle(&I, Callee,nullptr);
9597else
9598// Check if we can potentially perform a tail call. More detailed checking
9599// is be done within LowerCallTo, after more information about the call is
9600// known.
9601LowerCallTo(I, Callee,I.isTailCall(),I.isMustTailCall());
9602}
9603
9604voidSelectionDAGBuilder::LowerCallSiteWithPtrAuthBundle(
9605constCallBase &CB,constBasicBlock *EHPadBB) {
9606auto PAB = CB.getOperandBundle("ptrauth");
9607constValue *CalleeV = CB.getCalledOperand();
9608
9609// Gather the call ptrauth data from the operand bundle:
9610// [ i32 <key>, i64 <discriminator> ]
9611constauto *Key = cast<ConstantInt>(PAB->Inputs[0]);
9612constValue *Discriminator = PAB->Inputs[1];
9613
9614assert(Key->getType()->isIntegerTy(32) &&"Invalid ptrauth key");
9615assert(Discriminator->getType()->isIntegerTy(64) &&
9616"Invalid ptrauth discriminator");
9617
9618// Look through ptrauth constants to find the raw callee.
9619// Do a direct unauthenticated call if we found it and everything matches.
9620if (constauto *CalleeCPA = dyn_cast<ConstantPtrAuth>(CalleeV))
9621if (CalleeCPA->isKnownCompatibleWith(Key, Discriminator,
9622DAG.getDataLayout()))
9623returnLowerCallTo(CB,getValue(CalleeCPA->getPointer()), CB.isTailCall(),
9624 CB.isMustTailCall(), EHPadBB);
9625
9626// Functions should never be ptrauth-called directly.
9627assert(!isa<Function>(CalleeV) &&"invalid direct ptrauth call");
9628
9629// Otherwise, do an authenticated indirect call.
9630TargetLowering::PtrAuthInfo PAI = {Key->getZExtValue(),
9631getValue(Discriminator)};
9632
9633LowerCallTo(CB,getValue(CalleeV), CB.isTailCall(), CB.isMustTailCall(),
9634 EHPadBB, &PAI);
9635}
9636
9637namespace{
9638
9639/// AsmOperandInfo - This contains information for each constraint that we are
9640/// lowering.
9641classSDISelAsmOperandInfo :publicTargetLowering::AsmOperandInfo {
9642public:
9643 /// CallOperand - If this is the result output operand or a clobber
9644 /// this is null, otherwise it is the incoming operand to the CallInst.
9645 /// This gets modified as the asm is processed.
9646SDValue CallOperand;
9647
9648 /// AssignedRegs - If this is a register or register class operand, this
9649 /// contains the set of register corresponding to the operand.
9650RegsForValue AssignedRegs;
9651
9652explicit SDISelAsmOperandInfo(constTargetLowering::AsmOperandInfo &info)
9653 :TargetLowering::AsmOperandInfo(info), CallOperand(nullptr, 0) {
9654 }
9655
9656 /// Whether or not this operand accesses memory
9657bool hasMemory(constTargetLowering &TLI) const{
9658// Indirect operand accesses access memory.
9659if (isIndirect)
9660returntrue;
9661
9662for (constauto &Code : Codes)
9663if (TLI.getConstraintType(Code) ==TargetLowering::C_Memory)
9664returntrue;
9665
9666returnfalse;
9667 }
9668};
9669
9670
9671}// end anonymous namespace
9672
9673/// Make sure that the output operand \p OpInfo and its corresponding input
9674/// operand \p MatchingOpInfo have compatible constraint types (otherwise error
9675/// out).
9676staticvoidpatchMatchingInput(const SDISelAsmOperandInfo &OpInfo,
9677 SDISelAsmOperandInfo &MatchingOpInfo,
9678SelectionDAG &DAG) {
9679if (OpInfo.ConstraintVT == MatchingOpInfo.ConstraintVT)
9680return;
9681
9682constTargetRegisterInfo *TRI = DAG.getSubtarget().getRegisterInfo();
9683constauto &TLI = DAG.getTargetLoweringInfo();
9684
9685 std::pair<unsigned, const TargetRegisterClass *> MatchRC =
9686 TLI.getRegForInlineAsmConstraint(TRI, OpInfo.ConstraintCode,
9687 OpInfo.ConstraintVT);
9688 std::pair<unsigned, const TargetRegisterClass *> InputRC =
9689 TLI.getRegForInlineAsmConstraint(TRI, MatchingOpInfo.ConstraintCode,
9690 MatchingOpInfo.ConstraintVT);
9691constbool OutOpIsIntOrFP =
9692 OpInfo.ConstraintVT.isInteger() || OpInfo.ConstraintVT.isFloatingPoint();
9693constbool InOpIsIntOrFP = MatchingOpInfo.ConstraintVT.isInteger() ||
9694 MatchingOpInfo.ConstraintVT.isFloatingPoint();
9695if ((OutOpIsIntOrFP != InOpIsIntOrFP) || (MatchRC.second != InputRC.second)) {
9696// FIXME: error out in a more elegant fashion
9697report_fatal_error("Unsupported asm: input constraint"
9698" with a matching output constraint of"
9699" incompatible type!");
9700 }
9701 MatchingOpInfo.ConstraintVT = OpInfo.ConstraintVT;
9702}
9703
9704/// Get a direct memory input to behave well as an indirect operand.
9705/// This may introduce stores, hence the need for a \p Chain.
9706/// \return The (possibly updated) chain.
9707staticSDValuegetAddressForMemoryInput(SDValue Chain,constSDLoc &Location,
9708 SDISelAsmOperandInfo &OpInfo,
9709SelectionDAG &DAG) {
9710constTargetLowering &TLI = DAG.getTargetLoweringInfo();
9711
9712// If we don't have an indirect input, put it in the constpool if we can,
9713// otherwise spill it to a stack slot.
9714// TODO: This isn't quite right. We need to handle these according to
9715// the addressing mode that the constraint wants. Also, this may take
9716// an additional register for the computation and we don't want that
9717// either.
9718
9719// If the operand is a float, integer, or vector constant, spill to a
9720// constant pool entry to get its address.
9721constValue *OpVal = OpInfo.CallOperandVal;
9722if (isa<ConstantFP>(OpVal) || isa<ConstantInt>(OpVal) ||
9723 isa<ConstantVector>(OpVal) || isa<ConstantDataVector>(OpVal)) {
9724 OpInfo.CallOperand = DAG.getConstantPool(
9725 cast<Constant>(OpVal), TLI.getPointerTy(DAG.getDataLayout()));
9726return Chain;
9727 }
9728
9729// Otherwise, create a stack slot and emit a store to it before the asm.
9730Type *Ty = OpVal->getType();
9731auto &DL = DAG.getDataLayout();
9732TypeSize TySize =DL.getTypeAllocSize(Ty);
9733MachineFunction &MF = DAG.getMachineFunction();
9734constTargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering();
9735int StackID = 0;
9736if (TySize.isScalable())
9737 StackID = TFI->getStackIDForScalableVectors();
9738int SSFI = MF.getFrameInfo().CreateStackObject(TySize.getKnownMinValue(),
9739DL.getPrefTypeAlign(Ty),false,
9740nullptr, StackID);
9741SDValue StackSlot = DAG.getFrameIndex(SSFI, TLI.getFrameIndexTy(DL));
9742 Chain = DAG.getTruncStore(Chain, Location, OpInfo.CallOperand, StackSlot,
9743MachinePointerInfo::getFixedStack(MF, SSFI),
9744 TLI.getMemValueType(DL, Ty));
9745 OpInfo.CallOperand = StackSlot;
9746
9747return Chain;
9748}
9749
9750/// GetRegistersForValue - Assign registers (virtual or physical) for the
9751/// specified operand. We prefer to assign virtual registers, to allow the
9752/// register allocator to handle the assignment process. However, if the asm
9753/// uses features that we can't model on machineinstrs, we have SDISel do the
9754/// allocation. This produces generally horrible, but correct, code.
9755///
9756/// OpInfo describes the operand
9757/// RefOpInfo describes the matching operand if any, the operand otherwise
9758static std::optional<unsigned>
9759getRegistersForValue(SelectionDAG &DAG,constSDLoc &DL,
9760 SDISelAsmOperandInfo &OpInfo,
9761 SDISelAsmOperandInfo &RefOpInfo) {
9762LLVMContext &Context = *DAG.getContext();
9763constTargetLowering &TLI = DAG.getTargetLoweringInfo();
9764
9765MachineFunction &MF = DAG.getMachineFunction();
9766SmallVector<Register, 4> Regs;
9767constTargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo();
9768
9769// No work to do for memory/address operands.
9770if (OpInfo.ConstraintType ==TargetLowering::C_Memory ||
9771 OpInfo.ConstraintType ==TargetLowering::C_Address)
9772return std::nullopt;
9773
9774// If this is a constraint for a single physreg, or a constraint for a
9775// register class, find it.
9776unsigned AssignedReg;
9777constTargetRegisterClass *RC;
9778 std::tie(AssignedReg, RC) = TLI.getRegForInlineAsmConstraint(
9779 &TRI, RefOpInfo.ConstraintCode, RefOpInfo.ConstraintVT);
9780// RC is unset only on failure. Return immediately.
9781if (!RC)
9782return std::nullopt;
9783
9784// Get the actual register value type. This is important, because the user
9785// may have asked for (e.g.) the AX register in i32 type. We need to
9786// remember that AX is actually i16 to get the right extension.
9787constMVT RegVT = *TRI.legalclasstypes_begin(*RC);
9788
9789if (OpInfo.ConstraintVT != MVT::Other && RegVT != MVT::Untyped) {
9790// If this is an FP operand in an integer register (or visa versa), or more
9791// generally if the operand value disagrees with the register class we plan
9792// to stick it in, fix the operand type.
9793//
9794// If this is an input value, the bitcast to the new type is done now.
9795// Bitcast for output value is done at the end of visitInlineAsm().
9796if ((OpInfo.Type ==InlineAsm::isOutput ||
9797 OpInfo.Type ==InlineAsm::isInput) &&
9798 !TRI.isTypeLegalForClass(*RC, OpInfo.ConstraintVT)) {
9799// Try to convert to the first EVT that the reg class contains. If the
9800// types are identical size, use a bitcast to convert (e.g. two differing
9801// vector types). Note: output bitcast is done at the end of
9802// visitInlineAsm().
9803if (RegVT.getSizeInBits() == OpInfo.ConstraintVT.getSizeInBits()) {
9804// Exclude indirect inputs while they are unsupported because the code
9805// to perform the load is missing and thus OpInfo.CallOperand still
9806// refers to the input address rather than the pointed-to value.
9807if (OpInfo.Type ==InlineAsm::isInput && !OpInfo.isIndirect)
9808 OpInfo.CallOperand =
9809 DAG.getNode(ISD::BITCAST,DL, RegVT, OpInfo.CallOperand);
9810 OpInfo.ConstraintVT = RegVT;
9811// If the operand is an FP value and we want it in integer registers,
9812// use the corresponding integer type. This turns an f64 value into
9813// i64, which can be passed with two i32 values on a 32-bit machine.
9814 }elseif (RegVT.isInteger() && OpInfo.ConstraintVT.isFloatingPoint()) {
9815MVT VT =MVT::getIntegerVT(OpInfo.ConstraintVT.getSizeInBits());
9816if (OpInfo.Type ==InlineAsm::isInput)
9817 OpInfo.CallOperand =
9818 DAG.getNode(ISD::BITCAST,DL, VT, OpInfo.CallOperand);
9819 OpInfo.ConstraintVT = VT;
9820 }
9821 }
9822 }
9823
9824// No need to allocate a matching input constraint since the constraint it's
9825// matching to has already been allocated.
9826if (OpInfo.isMatchingInputConstraint())
9827return std::nullopt;
9828
9829EVT ValueVT = OpInfo.ConstraintVT;
9830if (OpInfo.ConstraintVT == MVT::Other)
9831 ValueVT = RegVT;
9832
9833// Initialize NumRegs.
9834unsigned NumRegs = 1;
9835if (OpInfo.ConstraintVT != MVT::Other)
9836 NumRegs = TLI.getNumRegisters(Context, OpInfo.ConstraintVT, RegVT);
9837
9838// If this is a constraint for a specific physical register, like {r17},
9839// assign it now.
9840
9841// If this associated to a specific register, initialize iterator to correct
9842// place. If virtual, make sure we have enough registers
9843
9844// Initialize iterator if necessary
9845TargetRegisterClass::iteratorI = RC->begin();
9846MachineRegisterInfo &RegInfo = MF.getRegInfo();
9847
9848// Do not check for single registers.
9849if (AssignedReg) {
9850I = std::find(I, RC->end(), AssignedReg);
9851if (I == RC->end()) {
9852// RC does not contain the selected register, which indicates a
9853// mismatch between the register and the required type/bitwidth.
9854return {AssignedReg};
9855 }
9856 }
9857
9858for (; NumRegs; --NumRegs, ++I) {
9859assert(I != RC->end() &&"Ran out of registers to allocate!");
9860Register R = AssignedReg ?Register(*I) :RegInfo.createVirtualRegister(RC);
9861 Regs.push_back(R);
9862 }
9863
9864 OpInfo.AssignedRegs =RegsForValue(Regs, RegVT, ValueVT);
9865return std::nullopt;
9866}
9867
9868staticunsigned
9869findMatchingInlineAsmOperand(unsigned OperandNo,
9870const std::vector<SDValue> &AsmNodeOperands) {
9871// Scan until we find the definition we already emitted of this operand.
9872unsigned CurOp =InlineAsm::Op_FirstOperand;
9873for (; OperandNo; --OperandNo) {
9874// Advance to the next operand.
9875unsigned OpFlag = AsmNodeOperands[CurOp]->getAsZExtVal();
9876constInlineAsm::FlagF(OpFlag);
9877assert(
9878 (F.isRegDefKind() ||F.isRegDefEarlyClobberKind() ||F.isMemKind()) &&
9879"Skipped past definitions?");
9880 CurOp +=F.getNumOperandRegisters() + 1;
9881 }
9882return CurOp;
9883}
9884
9885namespace{
9886
9887classExtraFlags {
9888unsignedFlags = 0;
9889
9890public:
9891explicit ExtraFlags(constCallBase &Call) {
9892constInlineAsm *IA = cast<InlineAsm>(Call.getCalledOperand());
9893if (IA->hasSideEffects())
9894Flags |=InlineAsm::Extra_HasSideEffects;
9895if (IA->isAlignStack())
9896Flags |=InlineAsm::Extra_IsAlignStack;
9897if (Call.isConvergent())
9898Flags |=InlineAsm::Extra_IsConvergent;
9899Flags |=IA->getDialect() *InlineAsm::Extra_AsmDialect;
9900 }
9901
9902void update(constTargetLowering::AsmOperandInfo &OpInfo) {
9903// Ideally, we would only check against memory constraints. However, the
9904// meaning of an Other constraint can be target-specific and we can't easily
9905// reason about it. Therefore, be conservative and set MayLoad/MayStore
9906// for Other constraints as well.
9907if (OpInfo.ConstraintType ==TargetLowering::C_Memory ||
9908 OpInfo.ConstraintType ==TargetLowering::C_Other) {
9909if (OpInfo.Type ==InlineAsm::isInput)
9910Flags |=InlineAsm::Extra_MayLoad;
9911elseif (OpInfo.Type ==InlineAsm::isOutput)
9912Flags |=InlineAsm::Extra_MayStore;
9913elseif (OpInfo.Type ==InlineAsm::isClobber)
9914Flags |= (InlineAsm::Extra_MayLoad |InlineAsm::Extra_MayStore);
9915 }
9916 }
9917
9918unsignedget() const{returnFlags; }
9919};
9920
9921}// end anonymous namespace
9922
9923staticboolisFunction(SDValueOp) {
9924if (Op &&Op.getOpcode() ==ISD::GlobalAddress) {
9925if (auto *GA = dyn_cast<GlobalAddressSDNode>(Op)) {
9926auto Fn = dyn_cast_or_null<Function>(GA->getGlobal());
9927
9928// In normal "call dllimport func" instruction (non-inlineasm) it force
9929// indirect access by specifing call opcode. And usually specially print
9930// asm with indirect symbol (i.g: "*") according to opcode. Inline asm can
9931// not do in this way now. (In fact, this is similar with "Data Access"
9932// action). So here we ignore dllimport function.
9933if (Fn && !Fn->hasDLLImportStorageClass())
9934returntrue;
9935 }
9936 }
9937returnfalse;
9938}
9939
9940/// visitInlineAsm - Handle a call to an InlineAsm object.
9941void SelectionDAGBuilder::visitInlineAsm(constCallBase &Call,
9942constBasicBlock *EHPadBB) {
9943constInlineAsm *IA = cast<InlineAsm>(Call.getCalledOperand());
9944
9945 /// ConstraintOperands - Information about all of the constraints.
9946SmallVector<SDISelAsmOperandInfo, 16> ConstraintOperands;
9947
9948constTargetLowering &TLI =DAG.getTargetLoweringInfo();
9949TargetLowering::AsmOperandInfoVector TargetConstraints = TLI.ParseConstraints(
9950DAG.getDataLayout(),DAG.getSubtarget().getRegisterInfo(), Call);
9951
9952// First Pass: Calculate HasSideEffects and ExtraFlags (AlignStack,
9953// AsmDialect, MayLoad, MayStore).
9954bool HasSideEffect =IA->hasSideEffects();
9955 ExtraFlags ExtraInfo(Call);
9956
9957for (auto &T : TargetConstraints) {
9958 ConstraintOperands.push_back(SDISelAsmOperandInfo(T));
9959 SDISelAsmOperandInfo &OpInfo = ConstraintOperands.back();
9960
9961if (OpInfo.CallOperandVal)
9962 OpInfo.CallOperand =getValue(OpInfo.CallOperandVal);
9963
9964if (!HasSideEffect)
9965 HasSideEffect = OpInfo.hasMemory(TLI);
9966
9967// Determine if this InlineAsm MayLoad or MayStore based on the constraints.
9968// FIXME: Could we compute this on OpInfo rather than T?
9969
9970// Compute the constraint code and ConstraintType to use.
9971 TLI.ComputeConstraintToUse(T,SDValue());
9972
9973if (T.ConstraintType ==TargetLowering::C_Immediate &&
9974 OpInfo.CallOperand && !isa<ConstantSDNode>(OpInfo.CallOperand))
9975// We've delayed emitting a diagnostic like the "n" constraint because
9976// inlining could cause an integer showing up.
9977return emitInlineAsmError(Call,"constraint '" +Twine(T.ConstraintCode) +
9978"' expects an integer constant "
9979"expression");
9980
9981 ExtraInfo.update(T);
9982 }
9983
9984// We won't need to flush pending loads if this asm doesn't touch
9985// memory and is nonvolatile.
9986SDValue Glue, Chain = (HasSideEffect) ?getRoot() :DAG.getRoot();
9987
9988bool EmitEHLabels = isa<InvokeInst>(Call);
9989if (EmitEHLabels) {
9990assert(EHPadBB &&"InvokeInst must have an EHPadBB");
9991 }
9992bool IsCallBr = isa<CallBrInst>(Call);
9993
9994if (IsCallBr || EmitEHLabels) {
9995// If this is a callbr or invoke we need to flush pending exports since
9996// inlineasm_br and invoke are terminators.
9997// We need to do this before nodes are glued to the inlineasm_br node.
9998 Chain =getControlRoot();
9999 }
10000
10001MCSymbol *BeginLabel =nullptr;
10002if (EmitEHLabels) {
10003 Chain = lowerStartEH(Chain, EHPadBB, BeginLabel);
10004 }
10005
10006int OpNo = -1;
10007SmallVector<StringRef> AsmStrs;
10008IA->collectAsmStrs(AsmStrs);
10009
10010// Second pass over the constraints: compute which constraint option to use.
10011for (SDISelAsmOperandInfo &OpInfo : ConstraintOperands) {
10012if (OpInfo.hasArg() || OpInfo.Type ==InlineAsm::isOutput)
10013 OpNo++;
10014
10015// If this is an output operand with a matching input operand, look up the
10016// matching input. If their types mismatch, e.g. one is an integer, the
10017// other is floating point, or their sizes are different, flag it as an
10018// error.
10019if (OpInfo.hasMatchingInput()) {
10020 SDISelAsmOperandInfo &Input = ConstraintOperands[OpInfo.MatchingInput];
10021patchMatchingInput(OpInfo, Input,DAG);
10022 }
10023
10024// Compute the constraint code and ConstraintType to use.
10025 TLI.ComputeConstraintToUse(OpInfo, OpInfo.CallOperand, &DAG);
10026
10027if ((OpInfo.ConstraintType ==TargetLowering::C_Memory &&
10028 OpInfo.Type ==InlineAsm::isClobber) ||
10029 OpInfo.ConstraintType ==TargetLowering::C_Address)
10030continue;
10031
10032// In Linux PIC model, there are 4 cases about value/label addressing:
10033//
10034// 1: Function call or Label jmp inside the module.
10035// 2: Data access (such as global variable, static variable) inside module.
10036// 3: Function call or Label jmp outside the module.
10037// 4: Data access (such as global variable) outside the module.
10038//
10039// Due to current llvm inline asm architecture designed to not "recognize"
10040// the asm code, there are quite troubles for us to treat mem addressing
10041// differently for same value/adress used in different instuctions.
10042// For example, in pic model, call a func may in plt way or direclty
10043// pc-related, but lea/mov a function adress may use got.
10044//
10045// Here we try to "recognize" function call for the case 1 and case 3 in
10046// inline asm. And try to adjust the constraint for them.
10047//
10048// TODO: Due to current inline asm didn't encourage to jmp to the outsider
10049// label, so here we don't handle jmp function label now, but we need to
10050// enhance it (especilly in PIC model) if we meet meaningful requirements.
10051if (OpInfo.isIndirect &&isFunction(OpInfo.CallOperand) &&
10052 TLI.isInlineAsmTargetBranch(AsmStrs, OpNo) &&
10053 TM.getCodeModel() !=CodeModel::Large) {
10054 OpInfo.isIndirect =false;
10055 OpInfo.ConstraintType =TargetLowering::C_Address;
10056 }
10057
10058// If this is a memory input, and if the operand is not indirect, do what we
10059// need to provide an address for the memory input.
10060if (OpInfo.ConstraintType ==TargetLowering::C_Memory &&
10061 !OpInfo.isIndirect) {
10062assert((OpInfo.isMultipleAlternative ||
10063 (OpInfo.Type ==InlineAsm::isInput)) &&
10064"Can only indirectify direct input operands!");
10065
10066// Memory operands really want the address of the value.
10067 Chain =getAddressForMemoryInput(Chain,getCurSDLoc(), OpInfo,DAG);
10068
10069// There is no longer a Value* corresponding to this operand.
10070 OpInfo.CallOperandVal =nullptr;
10071
10072// It is now an indirect operand.
10073 OpInfo.isIndirect =true;
10074 }
10075
10076 }
10077
10078// AsmNodeOperands - The operands for the ISD::INLINEASM node.
10079 std::vector<SDValue> AsmNodeOperands;
10080 AsmNodeOperands.push_back(SDValue());// reserve space for input chain
10081 AsmNodeOperands.push_back(DAG.getTargetExternalSymbol(
10082IA->getAsmString().c_str(), TLI.getProgramPointerTy(DAG.getDataLayout())));
10083
10084// If we have a !srcloc metadata node associated with it, we want to attach
10085// this to the ultimately generated inline asm machineinstr. To do this, we
10086// pass in the third operand as this (potentially null) inline asm MDNode.
10087constMDNode *SrcLoc =Call.getMetadata("srcloc");
10088 AsmNodeOperands.push_back(DAG.getMDNode(SrcLoc));
10089
10090// Remember the HasSideEffect, AlignStack, AsmDialect, MayLoad and MayStore
10091// bits as operand 3.
10092 AsmNodeOperands.push_back(DAG.getTargetConstant(
10093 ExtraInfo.get(),getCurSDLoc(), TLI.getPointerTy(DAG.getDataLayout())));
10094
10095// Third pass: Loop over operands to prepare DAG-level operands.. As part of
10096// this, assign virtual and physical registers for inputs and otput.
10097for (SDISelAsmOperandInfo &OpInfo : ConstraintOperands) {
10098// Assign Registers.
10099 SDISelAsmOperandInfo &RefOpInfo =
10100 OpInfo.isMatchingInputConstraint()
10101 ? ConstraintOperands[OpInfo.getMatchedOperand()]
10102 : OpInfo;
10103constauto RegError =
10104getRegistersForValue(DAG,getCurSDLoc(), OpInfo, RefOpInfo);
10105if (RegError) {
10106constMachineFunction &MF =DAG.getMachineFunction();
10107constTargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo();
10108constchar *RegName =TRI.getName(*RegError);
10109 emitInlineAsmError(Call,"register '" +Twine(RegName) +
10110"' allocated for constraint '" +
10111Twine(OpInfo.ConstraintCode) +
10112"' does not match required type");
10113return;
10114 }
10115
10116auto DetectWriteToReservedRegister = [&]() {
10117constMachineFunction &MF =DAG.getMachineFunction();
10118constTargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo();
10119for (unsigned Reg : OpInfo.AssignedRegs.Regs) {
10120if (Register::isPhysicalRegister(Reg) &&
10121TRI.isInlineAsmReadOnlyReg(MF, Reg)) {
10122constchar *RegName =TRI.getName(Reg);
10123 emitInlineAsmError(Call,"write to reserved register '" +
10124Twine(RegName) +"'");
10125returntrue;
10126 }
10127 }
10128returnfalse;
10129 };
10130assert((OpInfo.ConstraintType !=TargetLowering::C_Address ||
10131 (OpInfo.Type ==InlineAsm::isInput &&
10132 !OpInfo.isMatchingInputConstraint())) &&
10133"Only address as input operand is allowed.");
10134
10135switch (OpInfo.Type) {
10136caseInlineAsm::isOutput:
10137if (OpInfo.ConstraintType ==TargetLowering::C_Memory) {
10138constInlineAsm::ConstraintCode ConstraintID =
10139 TLI.getInlineAsmMemConstraint(OpInfo.ConstraintCode);
10140assert(ConstraintID !=InlineAsm::ConstraintCode::Unknown &&
10141"Failed to convert memory constraint code to constraint id.");
10142
10143// Add information to the INLINEASM node to know about this output.
10144InlineAsm::Flag OpFlags(InlineAsm::Kind::Mem, 1);
10145 OpFlags.setMemConstraint(ConstraintID);
10146 AsmNodeOperands.push_back(DAG.getTargetConstant(OpFlags,getCurSDLoc(),
10147 MVT::i32));
10148 AsmNodeOperands.push_back(OpInfo.CallOperand);
10149 }else {
10150// Otherwise, this outputs to a register (directly for C_Register /
10151// C_RegisterClass, and a target-defined fashion for
10152// C_Immediate/C_Other). Find a register that we can use.
10153if (OpInfo.AssignedRegs.Regs.empty()) {
10154 emitInlineAsmError(
10155 Call,"couldn't allocate output register for constraint '" +
10156Twine(OpInfo.ConstraintCode) +"'");
10157return;
10158 }
10159
10160if (DetectWriteToReservedRegister())
10161return;
10162
10163// Add information to the INLINEASM node to know that this register is
10164// set.
10165 OpInfo.AssignedRegs.AddInlineAsmOperands(
10166 OpInfo.isEarlyClobber ?InlineAsm::Kind::RegDefEarlyClobber
10167 :InlineAsm::Kind::RegDef,
10168false, 0,getCurSDLoc(),DAG, AsmNodeOperands);
10169 }
10170break;
10171
10172caseInlineAsm::isInput:
10173caseInlineAsm::isLabel: {
10174SDValue InOperandVal = OpInfo.CallOperand;
10175
10176if (OpInfo.isMatchingInputConstraint()) {
10177// If this is required to match an output register we have already set,
10178// just use its register.
10179auto CurOp =findMatchingInlineAsmOperand(OpInfo.getMatchedOperand(),
10180 AsmNodeOperands);
10181InlineAsm::FlagFlag(AsmNodeOperands[CurOp]->getAsZExtVal());
10182if (Flag.isRegDefKind() ||Flag.isRegDefEarlyClobberKind()) {
10183if (OpInfo.isIndirect) {
10184// This happens on gcc/testsuite/gcc.dg/pr8788-1.c
10185 emitInlineAsmError(Call,"inline asm not supported yet: "
10186"don't know how to handle tied "
10187"indirect register inputs");
10188return;
10189 }
10190
10191SmallVector<Register, 4> Regs;
10192MachineFunction &MF =DAG.getMachineFunction();
10193MachineRegisterInfo &MRI = MF.getRegInfo();
10194constTargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo();
10195auto *R = cast<RegisterSDNode>(AsmNodeOperands[CurOp+1]);
10196Register TiedReg =R->getReg();
10197MVT RegVT =R->getSimpleValueType(0);
10198constTargetRegisterClass *RC =
10199 TiedReg.isVirtual() ?MRI.getRegClass(TiedReg)
10200 : RegVT != MVT::Untyped ? TLI.getRegClassFor(RegVT)
10201 :TRI.getMinimalPhysRegClass(TiedReg);
10202for (unsigned i = 0, e =Flag.getNumOperandRegisters(); i != e; ++i)
10203 Regs.push_back(MRI.createVirtualRegister(RC));
10204
10205RegsForValue MatchedRegs(Regs, RegVT, InOperandVal.getValueType());
10206
10207SDLoc dl =getCurSDLoc();
10208// Use the produced MatchedRegs object to
10209 MatchedRegs.getCopyToRegs(InOperandVal,DAG, dl, Chain, &Glue, &Call);
10210 MatchedRegs.AddInlineAsmOperands(InlineAsm::Kind::RegUse,true,
10211 OpInfo.getMatchedOperand(), dl,DAG,
10212 AsmNodeOperands);
10213break;
10214 }
10215
10216assert(Flag.isMemKind() &&"Unknown matching constraint!");
10217assert(Flag.getNumOperandRegisters() == 1 &&
10218"Unexpected number of operands");
10219// Add information to the INLINEASM node to know about this input.
10220// See InlineAsm.h isUseOperandTiedToDef.
10221Flag.clearMemConstraint();
10222Flag.setMatchingOp(OpInfo.getMatchedOperand());
10223 AsmNodeOperands.push_back(DAG.getTargetConstant(
10224 Flag,getCurSDLoc(), TLI.getPointerTy(DAG.getDataLayout())));
10225 AsmNodeOperands.push_back(AsmNodeOperands[CurOp+1]);
10226break;
10227 }
10228
10229// Treat indirect 'X' constraint as memory.
10230if (OpInfo.ConstraintType ==TargetLowering::C_Other &&
10231 OpInfo.isIndirect)
10232 OpInfo.ConstraintType =TargetLowering::C_Memory;
10233
10234if (OpInfo.ConstraintType ==TargetLowering::C_Immediate ||
10235 OpInfo.ConstraintType ==TargetLowering::C_Other) {
10236 std::vector<SDValue> Ops;
10237 TLI.LowerAsmOperandForConstraint(InOperandVal, OpInfo.ConstraintCode,
10238 Ops,DAG);
10239if (Ops.empty()) {
10240if (OpInfo.ConstraintType ==TargetLowering::C_Immediate)
10241if (isa<ConstantSDNode>(InOperandVal)) {
10242 emitInlineAsmError(Call,"value out of range for constraint '" +
10243Twine(OpInfo.ConstraintCode) +"'");
10244return;
10245 }
10246
10247 emitInlineAsmError(Call,
10248"invalid operand for inline asm constraint '" +
10249Twine(OpInfo.ConstraintCode) +"'");
10250return;
10251 }
10252
10253// Add information to the INLINEASM node to know about this input.
10254InlineAsm::Flag ResOpType(InlineAsm::Kind::Imm, Ops.size());
10255 AsmNodeOperands.push_back(DAG.getTargetConstant(
10256 ResOpType,getCurSDLoc(), TLI.getPointerTy(DAG.getDataLayout())));
10257llvm::append_range(AsmNodeOperands, Ops);
10258break;
10259 }
10260
10261if (OpInfo.ConstraintType ==TargetLowering::C_Memory) {
10262assert((OpInfo.isIndirect ||
10263 OpInfo.ConstraintType !=TargetLowering::C_Memory) &&
10264"Operand must be indirect to be a mem!");
10265assert(InOperandVal.getValueType() ==
10266 TLI.getPointerTy(DAG.getDataLayout()) &&
10267"Memory operands expect pointer values");
10268
10269constInlineAsm::ConstraintCode ConstraintID =
10270 TLI.getInlineAsmMemConstraint(OpInfo.ConstraintCode);
10271assert(ConstraintID !=InlineAsm::ConstraintCode::Unknown &&
10272"Failed to convert memory constraint code to constraint id.");
10273
10274// Add information to the INLINEASM node to know about this input.
10275InlineAsm::Flag ResOpType(InlineAsm::Kind::Mem, 1);
10276 ResOpType.setMemConstraint(ConstraintID);
10277 AsmNodeOperands.push_back(DAG.getTargetConstant(ResOpType,
10278getCurSDLoc(),
10279 MVT::i32));
10280 AsmNodeOperands.push_back(InOperandVal);
10281break;
10282 }
10283
10284if (OpInfo.ConstraintType ==TargetLowering::C_Address) {
10285constInlineAsm::ConstraintCode ConstraintID =
10286 TLI.getInlineAsmMemConstraint(OpInfo.ConstraintCode);
10287assert(ConstraintID !=InlineAsm::ConstraintCode::Unknown &&
10288"Failed to convert memory constraint code to constraint id.");
10289
10290InlineAsm::Flag ResOpType(InlineAsm::Kind::Mem, 1);
10291
10292SDValue AsmOp = InOperandVal;
10293if (isFunction(InOperandVal)) {
10294auto *GA = cast<GlobalAddressSDNode>(InOperandVal);
10295 ResOpType =InlineAsm::Flag(InlineAsm::Kind::Func, 1);
10296 AsmOp =DAG.getTargetGlobalAddress(GA->getGlobal(),getCurSDLoc(),
10297 InOperandVal.getValueType(),
10298 GA->getOffset());
10299 }
10300
10301// Add information to the INLINEASM node to know about this input.
10302 ResOpType.setMemConstraint(ConstraintID);
10303
10304 AsmNodeOperands.push_back(
10305DAG.getTargetConstant(ResOpType,getCurSDLoc(), MVT::i32));
10306
10307 AsmNodeOperands.push_back(AsmOp);
10308break;
10309 }
10310
10311if (OpInfo.ConstraintType !=TargetLowering::C_RegisterClass &&
10312 OpInfo.ConstraintType !=TargetLowering::C_Register) {
10313 emitInlineAsmError(Call,"unknown asm constraint '" +
10314Twine(OpInfo.ConstraintCode) +"'");
10315return;
10316 }
10317
10318// TODO: Support this.
10319if (OpInfo.isIndirect) {
10320 emitInlineAsmError(
10321 Call,"Don't know how to handle indirect register inputs yet "
10322"for constraint '" +
10323Twine(OpInfo.ConstraintCode) +"'");
10324return;
10325 }
10326
10327// Copy the input into the appropriate registers.
10328if (OpInfo.AssignedRegs.Regs.empty()) {
10329 emitInlineAsmError(Call,
10330"couldn't allocate input reg for constraint '" +
10331Twine(OpInfo.ConstraintCode) +"'");
10332return;
10333 }
10334
10335if (DetectWriteToReservedRegister())
10336return;
10337
10338SDLoc dl =getCurSDLoc();
10339
10340 OpInfo.AssignedRegs.getCopyToRegs(InOperandVal,DAG, dl, Chain, &Glue,
10341 &Call);
10342
10343 OpInfo.AssignedRegs.AddInlineAsmOperands(InlineAsm::Kind::RegUse,false,
10344 0, dl,DAG, AsmNodeOperands);
10345break;
10346 }
10347caseInlineAsm::isClobber:
10348// Add the clobbered value to the operand list, so that the register
10349// allocator is aware that the physreg got clobbered.
10350if (!OpInfo.AssignedRegs.Regs.empty())
10351 OpInfo.AssignedRegs.AddInlineAsmOperands(InlineAsm::Kind::Clobber,
10352false, 0,getCurSDLoc(),DAG,
10353 AsmNodeOperands);
10354break;
10355 }
10356 }
10357
10358// Finish up input operands. Set the input chain and add the flag last.
10359 AsmNodeOperands[InlineAsm::Op_InputChain] = Chain;
10360if (Glue.getNode()) AsmNodeOperands.push_back(Glue);
10361
10362unsigned ISDOpc = IsCallBr ?ISD::INLINEASM_BR :ISD::INLINEASM;
10363 Chain =DAG.getNode(ISDOpc,getCurSDLoc(),
10364DAG.getVTList(MVT::Other, MVT::Glue), AsmNodeOperands);
10365 Glue = Chain.getValue(1);
10366
10367// Do additional work to generate outputs.
10368
10369SmallVector<EVT, 1> ResultVTs;
10370SmallVector<SDValue, 1> ResultValues;
10371SmallVector<SDValue, 8> OutChains;
10372
10373llvm::Type *CallResultType =Call.getType();
10374ArrayRef<Type *> ResultTypes;
10375if (StructType *StructResult = dyn_cast<StructType>(CallResultType))
10376 ResultTypes = StructResult->elements();
10377elseif (!CallResultType->isVoidTy())
10378 ResultTypes =ArrayRef(CallResultType);
10379
10380auto CurResultType = ResultTypes.begin();
10381auto handleRegAssign = [&](SDValueV) {
10382assert(CurResultType != ResultTypes.end() &&"Unexpected value");
10383assert((*CurResultType)->isSized() &&"Unexpected unsized type");
10384EVT ResultVT = TLI.getValueType(DAG.getDataLayout(), *CurResultType);
10385 ++CurResultType;
10386// If the type of the inline asm call site return value is different but has
10387// same size as the type of the asm output bitcast it. One example of this
10388// is for vectors with different width / number of elements. This can
10389// happen for register classes that can contain multiple different value
10390// types. The preg or vreg allocated may not have the same VT as was
10391// expected.
10392//
10393// This can also happen for a return value that disagrees with the register
10394// class it is put in, eg. a double in a general-purpose register on a
10395// 32-bit machine.
10396if (ResultVT !=V.getValueType() &&
10397 ResultVT.getSizeInBits() ==V.getValueSizeInBits())
10398V =DAG.getNode(ISD::BITCAST,getCurSDLoc(), ResultVT, V);
10399elseif (ResultVT !=V.getValueType() && ResultVT.isInteger() &&
10400V.getValueType().isInteger()) {
10401// If a result value was tied to an input value, the computed result
10402// may have a wider width than the expected result. Extract the
10403// relevant portion.
10404V =DAG.getNode(ISD::TRUNCATE,getCurSDLoc(), ResultVT, V);
10405 }
10406assert(ResultVT ==V.getValueType() &&"Asm result value mismatch!");
10407 ResultVTs.push_back(ResultVT);
10408 ResultValues.push_back(V);
10409 };
10410
10411// Deal with output operands.
10412for (SDISelAsmOperandInfo &OpInfo : ConstraintOperands) {
10413if (OpInfo.Type ==InlineAsm::isOutput) {
10414SDValue Val;
10415// Skip trivial output operands.
10416if (OpInfo.AssignedRegs.Regs.empty())
10417continue;
10418
10419switch (OpInfo.ConstraintType) {
10420caseTargetLowering::C_Register:
10421caseTargetLowering::C_RegisterClass:
10422 Val = OpInfo.AssignedRegs.getCopyFromRegs(DAG,FuncInfo,getCurSDLoc(),
10423 Chain, &Glue, &Call);
10424break;
10425caseTargetLowering::C_Immediate:
10426caseTargetLowering::C_Other:
10427 Val = TLI.LowerAsmOutputForConstraint(Chain, Glue,getCurSDLoc(),
10428 OpInfo,DAG);
10429break;
10430caseTargetLowering::C_Memory:
10431break;// Already handled.
10432caseTargetLowering::C_Address:
10433break;// Silence warning.
10434caseTargetLowering::C_Unknown:
10435assert(false &&"Unexpected unknown constraint");
10436 }
10437
10438// Indirect output manifest as stores. Record output chains.
10439if (OpInfo.isIndirect) {
10440constValue *Ptr = OpInfo.CallOperandVal;
10441assert(Ptr &&"Expected value CallOperandVal for indirect asm operand");
10442SDValueStore =DAG.getStore(Chain,getCurSDLoc(), Val,getValue(Ptr),
10443MachinePointerInfo(Ptr));
10444 OutChains.push_back(Store);
10445 }else {
10446// generate CopyFromRegs to associated registers.
10447assert(!Call.getType()->isVoidTy() &&"Bad inline asm!");
10448if (Val.getOpcode() ==ISD::MERGE_VALUES) {
10449for (constSDValue &V : Val->op_values())
10450 handleRegAssign(V);
10451 }else
10452 handleRegAssign(Val);
10453 }
10454 }
10455 }
10456
10457// Set results.
10458if (!ResultValues.empty()) {
10459assert(CurResultType == ResultTypes.end() &&
10460"Mismatch in number of ResultTypes");
10461assert(ResultValues.size() == ResultTypes.size() &&
10462"Mismatch in number of output operands in asm result");
10463
10464SDValueV =DAG.getNode(ISD::MERGE_VALUES,getCurSDLoc(),
10465DAG.getVTList(ResultVTs), ResultValues);
10466setValue(&Call, V);
10467 }
10468
10469// Collect store chains.
10470if (!OutChains.empty())
10471 Chain =DAG.getNode(ISD::TokenFactor,getCurSDLoc(), MVT::Other, OutChains);
10472
10473if (EmitEHLabels) {
10474 Chain = lowerEndEH(Chain, cast<InvokeInst>(&Call), EHPadBB, BeginLabel);
10475 }
10476
10477// Only Update Root if inline assembly has a memory effect.
10478if (ResultValues.empty() || HasSideEffect || !OutChains.empty() || IsCallBr ||
10479 EmitEHLabels)
10480DAG.setRoot(Chain);
10481}
10482
10483void SelectionDAGBuilder::emitInlineAsmError(constCallBase &Call,
10484constTwine &Message) {
10485LLVMContext &Ctx = *DAG.getContext();
10486 Ctx.diagnose(DiagnosticInfoInlineAsm(Call, Message));
10487
10488// Make sure we leave the DAG in a valid state
10489constTargetLowering &TLI =DAG.getTargetLoweringInfo();
10490SmallVector<EVT, 1> ValueVTs;
10491ComputeValueVTs(TLI,DAG.getDataLayout(),Call.getType(), ValueVTs);
10492
10493if (ValueVTs.empty())
10494return;
10495
10496SmallVector<SDValue, 1> Ops;
10497for (constEVT &VT : ValueVTs)
10498 Ops.push_back(DAG.getUNDEF(VT));
10499
10500setValue(&Call,DAG.getMergeValues(Ops,getCurSDLoc()));
10501}
10502
10503void SelectionDAGBuilder::visitVAStart(constCallInst &I) {
10504DAG.setRoot(DAG.getNode(ISD::VASTART,getCurSDLoc(),
10505 MVT::Other,getRoot(),
10506getValue(I.getArgOperand(0)),
10507DAG.getSrcValue(I.getArgOperand(0))));
10508}
10509
10510void SelectionDAGBuilder::visitVAArg(constVAArgInst &I) {
10511constTargetLowering &TLI =DAG.getTargetLoweringInfo();
10512constDataLayout &DL =DAG.getDataLayout();
10513SDValueV =DAG.getVAArg(
10514 TLI.getMemValueType(DAG.getDataLayout(),I.getType()),getCurSDLoc(),
10515getRoot(),getValue(I.getOperand(0)),DAG.getSrcValue(I.getOperand(0)),
10516DL.getABITypeAlign(I.getType()).value());
10517DAG.setRoot(V.getValue(1));
10518
10519if (I.getType()->isPointerTy())
10520V =DAG.getPtrExtOrTrunc(
10521 V,getCurSDLoc(), TLI.getValueType(DAG.getDataLayout(),I.getType()));
10522setValue(&I, V);
10523}
10524
10525void SelectionDAGBuilder::visitVAEnd(constCallInst &I) {
10526DAG.setRoot(DAG.getNode(ISD::VAEND,getCurSDLoc(),
10527 MVT::Other,getRoot(),
10528getValue(I.getArgOperand(0)),
10529DAG.getSrcValue(I.getArgOperand(0))));
10530}
10531
10532void SelectionDAGBuilder::visitVACopy(constCallInst &I) {
10533DAG.setRoot(DAG.getNode(ISD::VACOPY,getCurSDLoc(),
10534 MVT::Other,getRoot(),
10535getValue(I.getArgOperand(0)),
10536getValue(I.getArgOperand(1)),
10537DAG.getSrcValue(I.getArgOperand(0)),
10538DAG.getSrcValue(I.getArgOperand(1))));
10539}
10540
10541SDValueSelectionDAGBuilder::lowerRangeToAssertZExt(SelectionDAG &DAG,
10542constInstruction &I,
10543SDValueOp) {
10544 std::optional<ConstantRange> CR =getRange(I);
10545
10546if (!CR || CR->isFullSet() || CR->isEmptySet() || CR->isUpperWrapped())
10547returnOp;
10548
10549APIntLo = CR->getUnsignedMin();
10550if (!Lo.isMinValue())
10551returnOp;
10552
10553APIntHi = CR->getUnsignedMax();
10554unsigned Bits = std::max(Hi.getActiveBits(),
10555static_cast<unsigned>(IntegerType::MIN_INT_BITS));
10556
10557EVT SmallVT =EVT::getIntegerVT(*DAG.getContext(), Bits);
10558
10559SDLocSL =getCurSDLoc();
10560
10561SDValue ZExt =DAG.getNode(ISD::AssertZext,SL,Op.getValueType(),Op,
10562DAG.getValueType(SmallVT));
10563unsigned NumVals =Op.getNode()->getNumValues();
10564if (NumVals == 1)
10565return ZExt;
10566
10567SmallVector<SDValue, 4> Ops;
10568
10569 Ops.push_back(ZExt);
10570for (unsignedI = 1;I != NumVals; ++I)
10571 Ops.push_back(Op.getValue(I));
10572
10573returnDAG.getMergeValues(Ops,SL);
10574}
10575
10576/// Populate a CallLowerinInfo (into \p CLI) based on the properties of
10577/// the call being lowered.
10578///
10579/// This is a helper for lowering intrinsics that follow a target calling
10580/// convention or require stack pointer adjustment. Only a subset of the
10581/// intrinsic's operands need to participate in the calling convention.
10582voidSelectionDAGBuilder::populateCallLoweringInfo(
10583TargetLowering::CallLoweringInfo &CLI,constCallBase *Call,
10584unsigned ArgIdx,unsigned NumArgs,SDValue Callee,Type *ReturnTy,
10585AttributeSet RetAttrs,bool IsPatchPoint) {
10586TargetLowering::ArgListTy Args;
10587 Args.reserve(NumArgs);
10588
10589// Populate the argument list.
10590// Attributes for args start at offset 1, after the return attribute.
10591for (unsigned ArgI = ArgIdx, ArgE = ArgIdx + NumArgs;
10592 ArgI != ArgE; ++ArgI) {
10593constValue *V = Call->getOperand(ArgI);
10594
10595assert(!V->getType()->isEmptyTy() &&"Empty type passed to intrinsic.");
10596
10597TargetLowering::ArgListEntry Entry;
10598 Entry.Node =getValue(V);
10599 Entry.Ty = V->getType();
10600 Entry.setAttributes(Call, ArgI);
10601 Args.push_back(Entry);
10602 }
10603
10604 CLI.setDebugLoc(getCurSDLoc())
10605 .setChain(getRoot())
10606 .setCallee(Call->getCallingConv(), ReturnTy, Callee, std::move(Args),
10607 RetAttrs)
10608 .setDiscardResult(Call->use_empty())
10609 .setIsPatchPoint(IsPatchPoint)
10610 .setIsPreallocated(
10611 Call->countOperandBundlesOfType(LLVMContext::OB_preallocated) != 0);
10612}
10613
10614/// Add a stack map intrinsic call's live variable operands to a stackmap
10615/// or patchpoint target node's operand list.
10616///
10617/// Constants are converted to TargetConstants purely as an optimization to
10618/// avoid constant materialization and register allocation.
10619///
10620/// FrameIndex operands are converted to TargetFrameIndex so that ISEL does not
10621/// generate addess computation nodes, and so FinalizeISel can convert the
10622/// TargetFrameIndex into a DirectMemRefOp StackMap location. This avoids
10623/// address materialization and register allocation, but may also be required
10624/// for correctness. If a StackMap (or PatchPoint) intrinsic directly uses an
10625/// alloca in the entry block, then the runtime may assume that the alloca's
10626/// StackMap location can be read immediately after compilation and that the
10627/// location is valid at any point during execution (this is similar to the
10628/// assumption made by the llvm.gcroot intrinsic). If the alloca's location were
10629/// only available in a register, then the runtime would need to trap when
10630/// execution reaches the StackMap in order to read the alloca's location.
10631staticvoidaddStackMapLiveVars(constCallBase &Call,unsigned StartIdx,
10632constSDLoc &DL,SmallVectorImpl<SDValue> &Ops,
10633SelectionDAGBuilder &Builder) {
10634SelectionDAG &DAG = Builder.DAG;
10635for (unsignedI = StartIdx;I < Call.arg_size();I++) {
10636SDValueOp = Builder.getValue(Call.getArgOperand(I));
10637
10638// Things on the stack are pointer-typed, meaning that they are already
10639// legal and can be emitted directly to target nodes.
10640if (FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(Op)) {
10641 Ops.push_back(DAG.getTargetFrameIndex(FI->getIndex(),Op.getValueType()));
10642 }else {
10643// Otherwise emit a target independent node to be legalised.
10644 Ops.push_back(Builder.getValue(Call.getArgOperand(I)));
10645 }
10646 }
10647}
10648
10649/// Lower llvm.experimental.stackmap.
10650void SelectionDAGBuilder::visitStackmap(constCallInst &CI) {
10651// void @llvm.experimental.stackmap(i64 <id>, i32 <numShadowBytes>,
10652// [live variables...])
10653
10654assert(CI.getType()->isVoidTy() &&"Stackmap cannot return a value.");
10655
10656SDValue Chain, InGlue,Callee;
10657SmallVector<SDValue, 32> Ops;
10658
10659SDLocDL =getCurSDLoc();
10660Callee =getValue(CI.getCalledOperand());
10661
10662// The stackmap intrinsic only records the live variables (the arguments
10663// passed to it) and emits NOPS (if requested). Unlike the patchpoint
10664// intrinsic, this won't be lowered to a function call. This means we don't
10665// have to worry about calling conventions and target specific lowering code.
10666// Instead we perform the call lowering right here.
10667//
10668// chain, flag = CALLSEQ_START(chain, 0, 0)
10669// chain, flag = STACKMAP(id, nbytes, ..., chain, flag)
10670// chain, flag = CALLSEQ_END(chain, 0, 0, flag)
10671//
10672 Chain =DAG.getCALLSEQ_START(getRoot(), 0, 0,DL);
10673 InGlue = Chain.getValue(1);
10674
10675// Add the STACKMAP operands, starting with DAG house-keeping.
10676 Ops.push_back(Chain);
10677 Ops.push_back(InGlue);
10678
10679// Add the <id>, <numShadowBytes> operands.
10680//
10681// These do not require legalisation, and can be emitted directly to target
10682// constant nodes.
10683SDValueID =getValue(CI.getArgOperand(0));
10684assert(ID.getValueType() == MVT::i64);
10685SDValue IDConst =
10686DAG.getTargetConstant(ID->getAsZExtVal(),DL,ID.getValueType());
10687 Ops.push_back(IDConst);
10688
10689SDValue Shad =getValue(CI.getArgOperand(1));
10690assert(Shad.getValueType() == MVT::i32);
10691SDValue ShadConst =
10692DAG.getTargetConstant(Shad->getAsZExtVal(),DL, Shad.getValueType());
10693 Ops.push_back(ShadConst);
10694
10695// Add the live variables.
10696addStackMapLiveVars(CI, 2,DL, Ops, *this);
10697
10698// Create the STACKMAP node.
10699SDVTList NodeTys =DAG.getVTList(MVT::Other, MVT::Glue);
10700 Chain =DAG.getNode(ISD::STACKMAP,DL, NodeTys, Ops);
10701 InGlue = Chain.getValue(1);
10702
10703 Chain =DAG.getCALLSEQ_END(Chain, 0, 0, InGlue,DL);
10704
10705// Stackmaps don't generate values, so nothing goes into the NodeMap.
10706
10707// Set the root to the target-lowered call chain.
10708DAG.setRoot(Chain);
10709
10710// Inform the Frame Information that we have a stackmap in this function.
10711FuncInfo.MF->getFrameInfo().setHasStackMap();
10712}
10713
10714/// Lower llvm.experimental.patchpoint directly to its target opcode.
10715void SelectionDAGBuilder::visitPatchpoint(constCallBase &CB,
10716constBasicBlock *EHPadBB) {
10717// <ty> @llvm.experimental.patchpoint.<ty>(i64 <id>,
10718// i32 <numBytes>,
10719// i8* <target>,
10720// i32 <numArgs>,
10721// [Args...],
10722// [live variables...])
10723
10724CallingConv::IDCC = CB.getCallingConv();
10725bool IsAnyRegCC =CC ==CallingConv::AnyReg;
10726bool HasDef = !CB.getType()->isVoidTy();
10727SDLoc dl =getCurSDLoc();
10728SDValueCallee =getValue(CB.getArgOperand(PatchPointOpers::TargetPos));
10729
10730// Handle immediate and symbolic callees.
10731if (auto* ConstCallee = dyn_cast<ConstantSDNode>(Callee))
10732Callee =DAG.getIntPtrConstant(ConstCallee->getZExtValue(), dl,
10733/*isTarget=*/true);
10734elseif (auto* SymbolicCallee = dyn_cast<GlobalAddressSDNode>(Callee))
10735Callee =DAG.getTargetGlobalAddress(SymbolicCallee->getGlobal(),
10736SDLoc(SymbolicCallee),
10737 SymbolicCallee->getValueType(0));
10738
10739// Get the real number of arguments participating in the call <numArgs>
10740SDValue NArgVal =getValue(CB.getArgOperand(PatchPointOpers::NArgPos));
10741unsigned NumArgs = NArgVal->getAsZExtVal();
10742
10743// Skip the four meta args: <id>, <numNopBytes>, <target>, <numArgs>
10744// Intrinsics include all meta-operands up to but not including CC.
10745unsigned NumMetaOpers =PatchPointOpers::CCPos;
10746assert(CB.arg_size() >= NumMetaOpers + NumArgs &&
10747"Not enough arguments provided to the patchpoint intrinsic");
10748
10749// For AnyRegCC the arguments are lowered later on manually.
10750unsigned NumCallArgs = IsAnyRegCC ? 0 : NumArgs;
10751Type *ReturnTy =
10752 IsAnyRegCC ?Type::getVoidTy(*DAG.getContext()) : CB.getType();
10753
10754TargetLowering::CallLoweringInfo CLI(DAG);
10755populateCallLoweringInfo(CLI, &CB, NumMetaOpers, NumCallArgs, Callee,
10756 ReturnTy, CB.getAttributes().getRetAttrs(),true);
10757 std::pair<SDValue, SDValue>Result =lowerInvokable(CLI, EHPadBB);
10758
10759SDNode *CallEnd =Result.second.getNode();
10760if (CallEnd->getOpcode() ==ISD::EH_LABEL)
10761 CallEnd = CallEnd->getOperand(0).getNode();
10762if (HasDef && (CallEnd->getOpcode() ==ISD::CopyFromReg))
10763 CallEnd = CallEnd->getOperand(0).getNode();
10764
10765 /// Get a call instruction from the call sequence chain.
10766 /// Tail calls are not allowed.
10767assert(CallEnd->getOpcode() ==ISD::CALLSEQ_END &&
10768"Expected a callseq node.");
10769SDNode *Call = CallEnd->getOperand(0).getNode();
10770bool HasGlue =Call->getGluedNode();
10771
10772// Replace the target specific call node with the patchable intrinsic.
10773SmallVector<SDValue, 8> Ops;
10774
10775// Push the chain.
10776 Ops.push_back(*(Call->op_begin()));
10777
10778// Optionally, push the glue (if any).
10779if (HasGlue)
10780 Ops.push_back(*(Call->op_end() - 1));
10781
10782// Push the register mask info.
10783if (HasGlue)
10784 Ops.push_back(*(Call->op_end() - 2));
10785else
10786 Ops.push_back(*(Call->op_end() - 1));
10787
10788// Add the <id> and <numBytes> constants.
10789SDValue IDVal =getValue(CB.getArgOperand(PatchPointOpers::IDPos));
10790 Ops.push_back(DAG.getTargetConstant(IDVal->getAsZExtVal(), dl, MVT::i64));
10791SDValue NBytesVal =getValue(CB.getArgOperand(PatchPointOpers::NBytesPos));
10792 Ops.push_back(DAG.getTargetConstant(NBytesVal->getAsZExtVal(), dl, MVT::i32));
10793
10794// Add the callee.
10795 Ops.push_back(Callee);
10796
10797// Adjust <numArgs> to account for any arguments that have been passed on the
10798// stack instead.
10799// Call Node: Chain, Target, {Args}, RegMask, [Glue]
10800unsigned NumCallRegArgs =Call->getNumOperands() - (HasGlue ? 4 : 3);
10801 NumCallRegArgs = IsAnyRegCC ? NumArgs : NumCallRegArgs;
10802 Ops.push_back(DAG.getTargetConstant(NumCallRegArgs, dl, MVT::i32));
10803
10804// Add the calling convention
10805 Ops.push_back(DAG.getTargetConstant((unsigned)CC, dl, MVT::i32));
10806
10807// Add the arguments we omitted previously. The register allocator should
10808// place these in any free register.
10809if (IsAnyRegCC)
10810for (unsigned i = NumMetaOpers, e = NumMetaOpers + NumArgs; i !=e; ++i)
10811 Ops.push_back(getValue(CB.getArgOperand(i)));
10812
10813// Push the arguments from the call instruction.
10814SDNode::op_iteratore = HasGlue ?Call->op_end()-2 :Call->op_end()-1;
10815 Ops.append(Call->op_begin() + 2,e);
10816
10817// Push live variables for the stack map.
10818addStackMapLiveVars(CB, NumMetaOpers + NumArgs, dl, Ops, *this);
10819
10820SDVTList NodeTys;
10821if (IsAnyRegCC && HasDef) {
10822// Create the return types based on the intrinsic definition
10823constTargetLowering &TLI =DAG.getTargetLoweringInfo();
10824SmallVector<EVT, 3> ValueVTs;
10825ComputeValueVTs(TLI,DAG.getDataLayout(), CB.getType(), ValueVTs);
10826assert(ValueVTs.size() == 1 &&"Expected only one return value type.");
10827
10828// There is always a chain and a glue type at the end
10829 ValueVTs.push_back(MVT::Other);
10830 ValueVTs.push_back(MVT::Glue);
10831 NodeTys =DAG.getVTList(ValueVTs);
10832 }else
10833 NodeTys =DAG.getVTList(MVT::Other, MVT::Glue);
10834
10835// Replace the target specific call node with a PATCHPOINT node.
10836SDValue PPV =DAG.getNode(ISD::PATCHPOINT, dl, NodeTys, Ops);
10837
10838// Update the NodeMap.
10839if (HasDef) {
10840if (IsAnyRegCC)
10841setValue(&CB,SDValue(PPV.getNode(), 0));
10842else
10843setValue(&CB,Result.first);
10844 }
10845
10846// Fixup the consumers of the intrinsic. The chain and glue may be used in the
10847// call sequence. Furthermore the location of the chain and glue can change
10848// when the AnyReg calling convention is used and the intrinsic returns a
10849// value.
10850if (IsAnyRegCC && HasDef) {
10851SDValueFrom[] = {SDValue(Call, 0),SDValue(Call, 1)};
10852SDValue To[] = {PPV.getValue(1), PPV.getValue(2)};
10853DAG.ReplaceAllUsesOfValuesWith(From, To, 2);
10854 }else
10855DAG.ReplaceAllUsesWith(Call, PPV.getNode());
10856DAG.DeleteNode(Call);
10857
10858// Inform the Frame Information that we have a patchpoint in this function.
10859FuncInfo.MF->getFrameInfo().setHasPatchPoint();
10860}
10861
10862void SelectionDAGBuilder::visitVectorReduce(constCallInst &I,
10863unsigned Intrinsic) {
10864constTargetLowering &TLI =DAG.getTargetLoweringInfo();
10865SDValue Op1 =getValue(I.getArgOperand(0));
10866SDValue Op2;
10867if (I.arg_size() > 1)
10868 Op2 =getValue(I.getArgOperand(1));
10869SDLoc dl =getCurSDLoc();
10870EVT VT = TLI.getValueType(DAG.getDataLayout(),I.getType());
10871SDValue Res;
10872SDNodeFlags SDFlags;
10873if (auto *FPMO = dyn_cast<FPMathOperator>(&I))
10874 SDFlags.copyFMF(*FPMO);
10875
10876switch (Intrinsic) {
10877case Intrinsic::vector_reduce_fadd:
10878if (SDFlags.hasAllowReassociation())
10879 Res =DAG.getNode(ISD::FADD, dl, VT, Op1,
10880DAG.getNode(ISD::VECREDUCE_FADD, dl, VT, Op2, SDFlags),
10881 SDFlags);
10882else
10883 Res =DAG.getNode(ISD::VECREDUCE_SEQ_FADD, dl, VT, Op1, Op2, SDFlags);
10884break;
10885case Intrinsic::vector_reduce_fmul:
10886if (SDFlags.hasAllowReassociation())
10887 Res =DAG.getNode(ISD::FMUL, dl, VT, Op1,
10888DAG.getNode(ISD::VECREDUCE_FMUL, dl, VT, Op2, SDFlags),
10889 SDFlags);
10890else
10891 Res =DAG.getNode(ISD::VECREDUCE_SEQ_FMUL, dl, VT, Op1, Op2, SDFlags);
10892break;
10893case Intrinsic::vector_reduce_add:
10894 Res =DAG.getNode(ISD::VECREDUCE_ADD, dl, VT, Op1);
10895break;
10896case Intrinsic::vector_reduce_mul:
10897 Res =DAG.getNode(ISD::VECREDUCE_MUL, dl, VT, Op1);
10898break;
10899case Intrinsic::vector_reduce_and:
10900 Res =DAG.getNode(ISD::VECREDUCE_AND, dl, VT, Op1);
10901break;
10902case Intrinsic::vector_reduce_or:
10903 Res =DAG.getNode(ISD::VECREDUCE_OR, dl, VT, Op1);
10904break;
10905case Intrinsic::vector_reduce_xor:
10906 Res =DAG.getNode(ISD::VECREDUCE_XOR, dl, VT, Op1);
10907break;
10908case Intrinsic::vector_reduce_smax:
10909 Res =DAG.getNode(ISD::VECREDUCE_SMAX, dl, VT, Op1);
10910break;
10911case Intrinsic::vector_reduce_smin:
10912 Res =DAG.getNode(ISD::VECREDUCE_SMIN, dl, VT, Op1);
10913break;
10914case Intrinsic::vector_reduce_umax:
10915 Res =DAG.getNode(ISD::VECREDUCE_UMAX, dl, VT, Op1);
10916break;
10917case Intrinsic::vector_reduce_umin:
10918 Res =DAG.getNode(ISD::VECREDUCE_UMIN, dl, VT, Op1);
10919break;
10920case Intrinsic::vector_reduce_fmax:
10921 Res =DAG.getNode(ISD::VECREDUCE_FMAX, dl, VT, Op1, SDFlags);
10922break;
10923case Intrinsic::vector_reduce_fmin:
10924 Res =DAG.getNode(ISD::VECREDUCE_FMIN, dl, VT, Op1, SDFlags);
10925break;
10926case Intrinsic::vector_reduce_fmaximum:
10927 Res =DAG.getNode(ISD::VECREDUCE_FMAXIMUM, dl, VT, Op1, SDFlags);
10928break;
10929case Intrinsic::vector_reduce_fminimum:
10930 Res =DAG.getNode(ISD::VECREDUCE_FMINIMUM, dl, VT, Op1, SDFlags);
10931break;
10932default:
10933llvm_unreachable("Unhandled vector reduce intrinsic");
10934 }
10935setValue(&I, Res);
10936}
10937
10938/// Returns an AttributeList representing the attributes applied to the return
10939/// value of the given call.
10940staticAttributeListgetReturnAttrs(TargetLowering::CallLoweringInfo &CLI) {
10941SmallVector<Attribute::AttrKind, 2> Attrs;
10942if (CLI.RetSExt)
10943 Attrs.push_back(Attribute::SExt);
10944if (CLI.RetZExt)
10945 Attrs.push_back(Attribute::ZExt);
10946if (CLI.IsInReg)
10947 Attrs.push_back(Attribute::InReg);
10948
10949returnAttributeList::get(CLI.RetTy->getContext(),AttributeList::ReturnIndex,
10950 Attrs);
10951}
10952
10953/// TargetLowering::LowerCallTo - This is the default LowerCallTo
10954/// implementation, which just calls LowerCall.
10955/// FIXME: When all targets are
10956/// migrated to using LowerCall, this hook should be integrated into SDISel.
10957std::pair<SDValue, SDValue>
10958TargetLowering::LowerCallTo(TargetLowering::CallLoweringInfo &CLI) const{
10959// Handle the incoming return values from the call.
10960 CLI.Ins.clear();
10961SmallVector<EVT, 4> RetTys;
10962SmallVector<TypeSize, 4> Offsets;
10963auto &DL = CLI.DAG.getDataLayout();
10964ComputeValueVTs(*this,DL, CLI.RetTy, RetTys, &Offsets);
10965
10966if (CLI.IsPostTypeLegalization) {
10967// If we are lowering a libcall after legalization, split the return type.
10968SmallVector<EVT, 4> OldRetTys;
10969SmallVector<TypeSize, 4> OldOffsets;
10970 RetTys.swap(OldRetTys);
10971 Offsets.swap(OldOffsets);
10972
10973for (size_t i = 0, e = OldRetTys.size(); i != e; ++i) {
10974EVT RetVT = OldRetTys[i];
10975uint64_tOffset = OldOffsets[i];
10976MVT RegisterVT =getRegisterType(CLI.RetTy->getContext(), RetVT);
10977unsigned NumRegs =getNumRegisters(CLI.RetTy->getContext(), RetVT);
10978unsigned RegisterVTByteSZ = RegisterVT.getSizeInBits() / 8;
10979 RetTys.append(NumRegs, RegisterVT);
10980for (unsigned j = 0; j != NumRegs; ++j)
10981 Offsets.push_back(TypeSize::getFixed(Offset + j * RegisterVTByteSZ));
10982 }
10983 }
10984
10985SmallVector<ISD::OutputArg, 4> Outs;
10986GetReturnInfo(CLI.CallConv, CLI.RetTy,getReturnAttrs(CLI), Outs, *this,DL);
10987
10988boolCanLowerReturn =
10989 this->CanLowerReturn(CLI.CallConv, CLI.DAG.getMachineFunction(),
10990 CLI.IsVarArg, Outs, CLI.RetTy->getContext(), CLI.RetTy);
10991
10992SDValue DemoteStackSlot;
10993int DemoteStackIdx = -100;
10994if (!CanLowerReturn) {
10995// FIXME: equivalent assert?
10996// assert(!CS.hasInAllocaArgument() &&
10997// "sret demotion is incompatible with inalloca");
10998uint64_t TySize =DL.getTypeAllocSize(CLI.RetTy);
10999Align Alignment =DL.getPrefTypeAlign(CLI.RetTy);
11000MachineFunction &MF = CLI.DAG.getMachineFunction();
11001 DemoteStackIdx =
11002 MF.getFrameInfo().CreateStackObject(TySize, Alignment,false);
11003Type *StackSlotPtrType =
11004PointerType::get(CLI.RetTy->getContext(),DL.getAllocaAddrSpace());
11005
11006 DemoteStackSlot = CLI.DAG.getFrameIndex(DemoteStackIdx,getFrameIndexTy(DL));
11007ArgListEntry Entry;
11008 Entry.Node = DemoteStackSlot;
11009 Entry.Ty = StackSlotPtrType;
11010 Entry.IsSExt =false;
11011 Entry.IsZExt =false;
11012 Entry.IsInReg =false;
11013 Entry.IsSRet =true;
11014 Entry.IsNest =false;
11015 Entry.IsByVal =false;
11016 Entry.IsByRef =false;
11017 Entry.IsReturned =false;
11018 Entry.IsSwiftSelf =false;
11019 Entry.IsSwiftAsync =false;
11020 Entry.IsSwiftError =false;
11021 Entry.IsCFGuardTarget =false;
11022 Entry.Alignment = Alignment;
11023 CLI.getArgs().insert(CLI.getArgs().begin(), Entry);
11024 CLI.NumFixedArgs += 1;
11025 CLI.getArgs()[0].IndirectType = CLI.RetTy;
11026 CLI.RetTy =Type::getVoidTy(CLI.RetTy->getContext());
11027
11028// sret demotion isn't compatible with tail-calls, since the sret argument
11029// points into the callers stack frame.
11030 CLI.IsTailCall =false;
11031 }else {
11032bool NeedsRegBlock =functionArgumentNeedsConsecutiveRegisters(
11033 CLI.RetTy, CLI.CallConv, CLI.IsVarArg,DL);
11034for (unsignedI = 0, E = RetTys.size();I != E; ++I) {
11035ISD::ArgFlagsTy Flags;
11036if (NeedsRegBlock) {
11037 Flags.setInConsecutiveRegs();
11038if (I == RetTys.size() - 1)
11039 Flags.setInConsecutiveRegsLast();
11040 }
11041EVT VT = RetTys[I];
11042MVT RegisterVT =getRegisterTypeForCallingConv(CLI.RetTy->getContext(),
11043 CLI.CallConv, VT);
11044unsigned NumRegs =getNumRegistersForCallingConv(CLI.RetTy->getContext(),
11045 CLI.CallConv, VT);
11046for (unsigned i = 0; i != NumRegs; ++i) {
11047ISD::InputArg MyFlags;
11048 MyFlags.Flags = Flags;
11049 MyFlags.VT = RegisterVT;
11050 MyFlags.ArgVT = VT;
11051 MyFlags.Used = CLI.IsReturnValueUsed;
11052if (CLI.RetTy->isPointerTy()) {
11053 MyFlags.Flags.setPointer();
11054 MyFlags.Flags.setPointerAddrSpace(
11055 cast<PointerType>(CLI.RetTy)->getAddressSpace());
11056 }
11057if (CLI.RetSExt)
11058 MyFlags.Flags.setSExt();
11059if (CLI.RetZExt)
11060 MyFlags.Flags.setZExt();
11061if (CLI.IsInReg)
11062 MyFlags.Flags.setInReg();
11063 CLI.Ins.push_back(MyFlags);
11064 }
11065 }
11066 }
11067
11068// We push in swifterror return as the last element of CLI.Ins.
11069ArgListTy &Args = CLI.getArgs();
11070if (supportSwiftError()) {
11071for (constArgListEntry &Arg : Args) {
11072if (Arg.IsSwiftError) {
11073ISD::InputArg MyFlags;
11074 MyFlags.VT =getPointerTy(DL);
11075 MyFlags.ArgVT =EVT(getPointerTy(DL));
11076 MyFlags.Flags.setSwiftError();
11077 CLI.Ins.push_back(MyFlags);
11078 }
11079 }
11080 }
11081
11082// Handle all of the outgoing arguments.
11083 CLI.Outs.clear();
11084 CLI.OutVals.clear();
11085for (unsigned i = 0, e = Args.size(); i != e; ++i) {
11086SmallVector<EVT, 4> ValueVTs;
11087ComputeValueVTs(*this,DL, Args[i].Ty, ValueVTs);
11088// FIXME: Split arguments if CLI.IsPostTypeLegalization
11089Type *FinalType = Args[i].Ty;
11090if (Args[i].IsByVal)
11091 FinalType = Args[i].IndirectType;
11092bool NeedsRegBlock =functionArgumentNeedsConsecutiveRegisters(
11093 FinalType, CLI.CallConv, CLI.IsVarArg,DL);
11094for (unsignedValue = 0, NumValues = ValueVTs.size();Value != NumValues;
11095 ++Value) {
11096EVT VT = ValueVTs[Value];
11097Type *ArgTy = VT.getTypeForEVT(CLI.RetTy->getContext());
11098SDValueOp =SDValue(Args[i].Node.getNode(),
11099 Args[i].Node.getResNo() +Value);
11100ISD::ArgFlagsTy Flags;
11101
11102// Certain targets (such as MIPS), may have a different ABI alignment
11103// for a type depending on the context. Give the target a chance to
11104// specify the alignment it wants.
11105constAlign OriginalAlignment(getABIAlignmentForCallingConv(ArgTy,DL));
11106 Flags.setOrigAlign(OriginalAlignment);
11107
11108if (Args[i].Ty->isPointerTy()) {
11109 Flags.setPointer();
11110 Flags.setPointerAddrSpace(
11111 cast<PointerType>(Args[i].Ty)->getAddressSpace());
11112 }
11113if (Args[i].IsZExt)
11114 Flags.setZExt();
11115if (Args[i].IsSExt)
11116 Flags.setSExt();
11117if (Args[i].IsNoExt)
11118 Flags.setNoExt();
11119if (Args[i].IsInReg) {
11120// If we are using vectorcall calling convention, a structure that is
11121// passed InReg - is surely an HVA
11122if (CLI.CallConv ==CallingConv::X86_VectorCall &&
11123 isa<StructType>(FinalType)) {
11124// The first value of a structure is marked
11125if (0 ==Value)
11126 Flags.setHvaStart();
11127 Flags.setHva();
11128 }
11129// Set InReg Flag
11130 Flags.setInReg();
11131 }
11132if (Args[i].IsSRet)
11133 Flags.setSRet();
11134if (Args[i].IsSwiftSelf)
11135 Flags.setSwiftSelf();
11136if (Args[i].IsSwiftAsync)
11137 Flags.setSwiftAsync();
11138if (Args[i].IsSwiftError)
11139 Flags.setSwiftError();
11140if (Args[i].IsCFGuardTarget)
11141 Flags.setCFGuardTarget();
11142if (Args[i].IsByVal)
11143 Flags.setByVal();
11144if (Args[i].IsByRef)
11145 Flags.setByRef();
11146if (Args[i].IsPreallocated) {
11147 Flags.setPreallocated();
11148// Set the byval flag for CCAssignFn callbacks that don't know about
11149// preallocated. This way we can know how many bytes we should've
11150// allocated and how many bytes a callee cleanup function will pop. If
11151// we port preallocated to more targets, we'll have to add custom
11152// preallocated handling in the various CC lowering callbacks.
11153 Flags.setByVal();
11154 }
11155if (Args[i].IsInAlloca) {
11156 Flags.setInAlloca();
11157// Set the byval flag for CCAssignFn callbacks that don't know about
11158// inalloca. This way we can know how many bytes we should've allocated
11159// and how many bytes a callee cleanup function will pop. If we port
11160// inalloca to more targets, we'll have to add custom inalloca handling
11161// in the various CC lowering callbacks.
11162 Flags.setByVal();
11163 }
11164Align MemAlign;
11165if (Args[i].IsByVal || Args[i].IsInAlloca || Args[i].IsPreallocated) {
11166unsigned FrameSize =DL.getTypeAllocSize(Args[i].IndirectType);
11167 Flags.setByValSize(FrameSize);
11168
11169// info is not there but there are cases it cannot get right.
11170if (auto MA = Args[i].Alignment)
11171 MemAlign = *MA;
11172else
11173 MemAlign =getByValTypeAlignment(Args[i].IndirectType,DL);
11174 }elseif (auto MA = Args[i].Alignment) {
11175 MemAlign = *MA;
11176 }else {
11177 MemAlign = OriginalAlignment;
11178 }
11179 Flags.setMemAlign(MemAlign);
11180if (Args[i].IsNest)
11181 Flags.setNest();
11182if (NeedsRegBlock)
11183 Flags.setInConsecutiveRegs();
11184
11185MVT PartVT =getRegisterTypeForCallingConv(CLI.RetTy->getContext(),
11186 CLI.CallConv, VT);
11187unsigned NumParts =getNumRegistersForCallingConv(CLI.RetTy->getContext(),
11188 CLI.CallConv, VT);
11189SmallVector<SDValue, 4> Parts(NumParts);
11190ISD::NodeType ExtendKind =ISD::ANY_EXTEND;
11191
11192if (Args[i].IsSExt)
11193 ExtendKind =ISD::SIGN_EXTEND;
11194elseif (Args[i].IsZExt)
11195 ExtendKind =ISD::ZERO_EXTEND;
11196
11197// Conservatively only handle 'returned' on non-vectors that can be lowered,
11198// for now.
11199if (Args[i].IsReturned && !Op.getValueType().isVector() &&
11200CanLowerReturn) {
11201assert((CLI.RetTy == Args[i].Ty ||
11202 (CLI.RetTy->isPointerTy() && Args[i].Ty->isPointerTy() &&
11203 CLI.RetTy->getPointerAddressSpace() ==
11204 Args[i].Ty->getPointerAddressSpace())) &&
11205 RetTys.size() == NumValues &&"unexpected use of 'returned'");
11206// Before passing 'returned' to the target lowering code, ensure that
11207// either the register MVT and the actual EVT are the same size or that
11208// the return value and argument are extended in the same way; in these
11209// cases it's safe to pass the argument register value unchanged as the
11210// return register value (although it's at the target's option whether
11211// to do so)
11212// TODO: allow code generation to take advantage of partially preserved
11213// registers rather than clobbering the entire register when the
11214// parameter extension method is not compatible with the return
11215// extension method
11216if ((NumParts * PartVT.getSizeInBits() == VT.getSizeInBits()) ||
11217 (ExtendKind !=ISD::ANY_EXTEND && CLI.RetSExt == Args[i].IsSExt &&
11218 CLI.RetZExt == Args[i].IsZExt))
11219 Flags.setReturned();
11220 }
11221
11222getCopyToParts(CLI.DAG, CLI.DL,Op, &Parts[0], NumParts, PartVT, CLI.CB,
11223 CLI.CallConv, ExtendKind);
11224
11225for (unsigned j = 0; j != NumParts; ++j) {
11226// if it isn't first piece, alignment must be 1
11227// For scalable vectors the scalable part is currently handled
11228// by individual targets, so we just use the known minimum size here.
11229ISD::OutputArg MyFlags(
11230 Flags, Parts[j].getValueType().getSimpleVT(), VT,
11231 i < CLI.NumFixedArgs, i,
11232 j * Parts[j].getValueType().getStoreSize().getKnownMinValue());
11233if (NumParts > 1 && j == 0)
11234 MyFlags.Flags.setSplit();
11235elseif (j != 0) {
11236 MyFlags.Flags.setOrigAlign(Align(1));
11237if (j == NumParts - 1)
11238 MyFlags.Flags.setSplitEnd();
11239 }
11240
11241 CLI.Outs.push_back(MyFlags);
11242 CLI.OutVals.push_back(Parts[j]);
11243 }
11244
11245if (NeedsRegBlock &&Value == NumValues - 1)
11246 CLI.Outs[CLI.Outs.size() - 1].Flags.setInConsecutiveRegsLast();
11247 }
11248 }
11249
11250SmallVector<SDValue, 4> InVals;
11251 CLI.Chain =LowerCall(CLI, InVals);
11252
11253// Update CLI.InVals to use outside of this function.
11254 CLI.InVals = InVals;
11255
11256// Verify that the target's LowerCall behaved as expected.
11257assert(CLI.Chain.getNode() && CLI.Chain.getValueType() == MVT::Other &&
11258"LowerCall didn't return a valid chain!");
11259assert((!CLI.IsTailCall || InVals.empty()) &&
11260"LowerCall emitted a return value for a tail call!");
11261assert((CLI.IsTailCall || InVals.size() == CLI.Ins.size()) &&
11262"LowerCall didn't emit the correct number of values!");
11263
11264// For a tail call, the return value is merely live-out and there aren't
11265// any nodes in the DAG representing it. Return a special value to
11266// indicate that a tail call has been emitted and no more Instructions
11267// should be processed in the current block.
11268if (CLI.IsTailCall) {
11269 CLI.DAG.setRoot(CLI.Chain);
11270return std::make_pair(SDValue(),SDValue());
11271 }
11272
11273#ifndef NDEBUG
11274for (unsigned i = 0, e = CLI.Ins.size(); i != e; ++i) {
11275assert(InVals[i].getNode() &&"LowerCall emitted a null value!");
11276assert(EVT(CLI.Ins[i].VT) == InVals[i].getValueType() &&
11277"LowerCall emitted a value with the wrong type!");
11278 }
11279#endif
11280
11281SmallVector<SDValue, 4> ReturnValues;
11282if (!CanLowerReturn) {
11283// The instruction result is the result of loading from the
11284// hidden sret parameter.
11285MVT PtrVT =getPointerTy(DL,DL.getAllocaAddrSpace());
11286
11287unsigned NumValues = RetTys.size();
11288 ReturnValues.resize(NumValues);
11289SmallVector<SDValue, 4> Chains(NumValues);
11290
11291// An aggregate return value cannot wrap around the address space, so
11292// offsets to its parts don't wrap either.
11293MachineFunction &MF = CLI.DAG.getMachineFunction();
11294Align HiddenSRetAlign = MF.getFrameInfo().getObjectAlign(DemoteStackIdx);
11295for (unsigned i = 0; i < NumValues; ++i) {
11296SDValueAdd =
11297 CLI.DAG.getNode(ISD::ADD, CLI.DL, PtrVT, DemoteStackSlot,
11298 CLI.DAG.getConstant(Offsets[i], CLI.DL, PtrVT),
11299SDNodeFlags::NoUnsignedWrap);
11300SDValue L = CLI.DAG.getLoad(
11301 RetTys[i], CLI.DL, CLI.Chain,Add,
11302MachinePointerInfo::getFixedStack(CLI.DAG.getMachineFunction(),
11303 DemoteStackIdx, Offsets[i]),
11304 HiddenSRetAlign);
11305 ReturnValues[i] = L;
11306 Chains[i] = L.getValue(1);
11307 }
11308
11309 CLI.Chain = CLI.DAG.getNode(ISD::TokenFactor, CLI.DL, MVT::Other, Chains);
11310 }else {
11311// Collect the legal value parts into potentially illegal values
11312// that correspond to the original function's return values.
11313 std::optional<ISD::NodeType> AssertOp;
11314if (CLI.RetSExt)
11315 AssertOp =ISD::AssertSext;
11316elseif (CLI.RetZExt)
11317 AssertOp =ISD::AssertZext;
11318unsigned CurReg = 0;
11319for (EVT VT : RetTys) {
11320MVT RegisterVT =getRegisterTypeForCallingConv(CLI.RetTy->getContext(),
11321 CLI.CallConv, VT);
11322unsigned NumRegs =getNumRegistersForCallingConv(CLI.RetTy->getContext(),
11323 CLI.CallConv, VT);
11324
11325 ReturnValues.push_back(getCopyFromParts(
11326 CLI.DAG, CLI.DL, &InVals[CurReg], NumRegs, RegisterVT, VT,nullptr,
11327 CLI.Chain, CLI.CallConv, AssertOp));
11328 CurReg += NumRegs;
11329 }
11330
11331// For a function returning void, there is no return value. We can't create
11332// such a node, so we just return a null return value in that case. In
11333// that case, nothing will actually look at the value.
11334if (ReturnValues.empty())
11335return std::make_pair(SDValue(), CLI.Chain);
11336 }
11337
11338SDValue Res = CLI.DAG.getNode(ISD::MERGE_VALUES, CLI.DL,
11339 CLI.DAG.getVTList(RetTys), ReturnValues);
11340return std::make_pair(Res, CLI.Chain);
11341}
11342
11343/// Places new result values for the node in Results (their number
11344/// and types must exactly match those of the original return values of
11345/// the node), or leaves Results empty, which indicates that the node is not
11346/// to be custom lowered after all.
11347voidTargetLowering::LowerOperationWrapper(SDNode *N,
11348SmallVectorImpl<SDValue> &Results,
11349SelectionDAG &DAG) const{
11350SDValue Res =LowerOperation(SDValue(N, 0), DAG);
11351
11352if (!Res.getNode())
11353return;
11354
11355// If the original node has one result, take the return value from
11356// LowerOperation as is. It might not be result number 0.
11357if (N->getNumValues() == 1) {
11358Results.push_back(Res);
11359return;
11360 }
11361
11362// If the original node has multiple results, then the return node should
11363// have the same number of results.
11364assert((N->getNumValues() == Res->getNumValues()) &&
11365"Lowering returned the wrong number of results!");
11366
11367// Places new result values base on N result number.
11368for (unsignedI = 0, E =N->getNumValues();I != E; ++I)
11369Results.push_back(Res.getValue(I));
11370}
11371
11372SDValueTargetLowering::LowerOperation(SDValueOp,SelectionDAG &DAG) const{
11373llvm_unreachable("LowerOperation not implemented for this target!");
11374}
11375
11376voidSelectionDAGBuilder::CopyValueToVirtualRegister(constValue *V,
11377unsigned Reg,
11378ISD::NodeType ExtendType) {
11379SDValueOp =getNonRegisterValue(V);
11380assert((Op.getOpcode() !=ISD::CopyFromReg ||
11381 cast<RegisterSDNode>(Op.getOperand(1))->getReg() != Reg) &&
11382"Copy from a reg to the same reg!");
11383assert(!Register::isPhysicalRegister(Reg) &&"Is a physreg");
11384
11385constTargetLowering &TLI =DAG.getTargetLoweringInfo();
11386// If this is an InlineAsm we have to match the registers required, not the
11387// notional registers required by the type.
11388
11389RegsForValue RFV(V->getContext(), TLI,DAG.getDataLayout(), Reg, V->getType(),
11390 std::nullopt);// This is not an ABI copy.
11391SDValue Chain =DAG.getEntryNode();
11392
11393if (ExtendType ==ISD::ANY_EXTEND) {
11394auto PreferredExtendIt =FuncInfo.PreferredExtendType.find(V);
11395if (PreferredExtendIt !=FuncInfo.PreferredExtendType.end())
11396 ExtendType = PreferredExtendIt->second;
11397 }
11398 RFV.getCopyToRegs(Op,DAG,getCurSDLoc(), Chain,nullptr, V, ExtendType);
11399 PendingExports.push_back(Chain);
11400}
11401
11402#include "llvm/CodeGen/SelectionDAGISel.h"
11403
11404/// isOnlyUsedInEntryBlock - If the specified argument is only used in the
11405/// entry block, return true. This includes arguments used by switches, since
11406/// the switch may expand into multiple basic blocks.
11407staticboolisOnlyUsedInEntryBlock(constArgument *A,boolFastISel) {
11408// With FastISel active, we may be splitting blocks, so force creation
11409// of virtual registers for all non-dead arguments.
11410if (FastISel)
11411returnA->use_empty();
11412
11413constBasicBlock &Entry =A->getParent()->front();
11414for (constUser *U :A->users())
11415if (cast<Instruction>(U)->getParent() != &Entry || isa<SwitchInst>(U))
11416returnfalse;// Use not in entry block.
11417
11418returntrue;
11419}
11420
11421usingArgCopyElisionMapTy =
11422DenseMap<constArgument *,
11423 std::pair<const AllocaInst *, const StoreInst *>>;
11424
11425/// Scan the entry block of the function in FuncInfo for arguments that look
11426/// like copies into a local alloca. Record any copied arguments in
11427/// ArgCopyElisionCandidates.
11428staticvoid
11429findArgumentCopyElisionCandidates(constDataLayout &DL,
11430FunctionLoweringInfo *FuncInfo,
11431ArgCopyElisionMapTy &ArgCopyElisionCandidates) {
11432// Record the state of every static alloca used in the entry block. Argument
11433// allocas are all used in the entry block, so we need approximately as many
11434// entries as we have arguments.
11435enum StaticAllocaInfo {Unknown, Clobbered, Elidable };
11436SmallDenseMap<const AllocaInst *, StaticAllocaInfo, 8> StaticAllocas;
11437unsigned NumArgs = FuncInfo->Fn->arg_size();
11438 StaticAllocas.reserve(NumArgs * 2);
11439
11440auto GetInfoIfStaticAlloca = [&](constValue *V) -> StaticAllocaInfo * {
11441if (!V)
11442returnnullptr;
11443 V = V->stripPointerCasts();
11444constauto *AI = dyn_cast<AllocaInst>(V);
11445if (!AI || !AI->isStaticAlloca() || !FuncInfo->StaticAllocaMap.count(AI))
11446returnnullptr;
11447auto Iter = StaticAllocas.insert({AI,Unknown});
11448return &Iter.first->second;
11449 };
11450
11451// Look for stores of arguments to static allocas. Look through bitcasts and
11452// GEPs to handle type coercions, as long as the alloca is fully initialized
11453// by the store. Any non-store use of an alloca escapes it and any subsequent
11454// unanalyzed store might write it.
11455// FIXME: Handle structs initialized with multiple stores.
11456for (constInstruction &I : FuncInfo->Fn->getEntryBlock()) {
11457// Look for stores, and handle non-store uses conservatively.
11458constauto *SI = dyn_cast<StoreInst>(&I);
11459if (!SI) {
11460// We will look through cast uses, so ignore them completely.
11461if (I.isCast())
11462continue;
11463// Ignore debug info and pseudo op intrinsics, they don't escape or store
11464// to allocas.
11465if (I.isDebugOrPseudoInst())
11466continue;
11467// This is an unknown instruction. Assume it escapes or writes to all
11468// static alloca operands.
11469for (constUse &U :I.operands()) {
11470if (StaticAllocaInfo *Info = GetInfoIfStaticAlloca(U))
11471 *Info = StaticAllocaInfo::Clobbered;
11472 }
11473continue;
11474 }
11475
11476// If the stored value is a static alloca, mark it as escaped.
11477if (StaticAllocaInfo *Info = GetInfoIfStaticAlloca(SI->getValueOperand()))
11478 *Info = StaticAllocaInfo::Clobbered;
11479
11480// Check if the destination is a static alloca.
11481constValue *Dst = SI->getPointerOperand()->stripPointerCasts();
11482 StaticAllocaInfo *Info = GetInfoIfStaticAlloca(Dst);
11483if (!Info)
11484continue;
11485constAllocaInst *AI = cast<AllocaInst>(Dst);
11486
11487// Skip allocas that have been initialized or clobbered.
11488if (*Info != StaticAllocaInfo::Unknown)
11489continue;
11490
11491// Check if the stored value is an argument, and that this store fully
11492// initializes the alloca.
11493// If the argument type has padding bits we can't directly forward a pointer
11494// as the upper bits may contain garbage.
11495// Don't elide copies from the same argument twice.
11496constValue *Val = SI->getValueOperand()->stripPointerCasts();
11497constauto *Arg = dyn_cast<Argument>(Val);
11498if (!Arg || Arg->hasPassPointeeByValueCopyAttr() ||
11499 Arg->getType()->isEmptyTy() ||
11500DL.getTypeStoreSize(Arg->getType()) !=
11501DL.getTypeAllocSize(AI->getAllocatedType()) ||
11502 !DL.typeSizeEqualsStoreSize(Arg->getType()) ||
11503 ArgCopyElisionCandidates.count(Arg)) {
11504 *Info = StaticAllocaInfo::Clobbered;
11505continue;
11506 }
11507
11508LLVM_DEBUG(dbgs() <<"Found argument copy elision candidate: " << *AI
11509 <<'\n');
11510
11511// Mark this alloca and store for argument copy elision.
11512 *Info = StaticAllocaInfo::Elidable;
11513 ArgCopyElisionCandidates.insert({Arg, {AI, SI}});
11514
11515// Stop scanning if we've seen all arguments. This will happen early in -O0
11516// builds, which is useful, because -O0 builds have large entry blocks and
11517// many allocas.
11518if (ArgCopyElisionCandidates.size() == NumArgs)
11519break;
11520 }
11521}
11522
11523/// Try to elide argument copies from memory into a local alloca. Succeeds if
11524/// ArgVal is a load from a suitable fixed stack object.
11525staticvoidtryToElideArgumentCopy(
11526FunctionLoweringInfo &FuncInfo,SmallVectorImpl<SDValue> &Chains,
11527DenseMap<int, int> &ArgCopyElisionFrameIndexMap,
11528SmallPtrSetImpl<const Instruction *> &ElidedArgCopyInstrs,
11529ArgCopyElisionMapTy &ArgCopyElisionCandidates,constArgument &Arg,
11530ArrayRef<SDValue> ArgVals,bool &ArgHasUses) {
11531// Check if this is a load from a fixed stack object.
11532auto *LNode = dyn_cast<LoadSDNode>(ArgVals[0]);
11533if (!LNode)
11534return;
11535auto *FINode = dyn_cast<FrameIndexSDNode>(LNode->getBasePtr().getNode());
11536if (!FINode)
11537return;
11538
11539// Check that the fixed stack object is the right size and alignment.
11540// Look at the alignment that the user wrote on the alloca instead of looking
11541// at the stack object.
11542auto ArgCopyIter = ArgCopyElisionCandidates.find(&Arg);
11543assert(ArgCopyIter != ArgCopyElisionCandidates.end());
11544constAllocaInst *AI = ArgCopyIter->second.first;
11545int FixedIndex = FINode->getIndex();
11546int &AllocaIndex = FuncInfo.StaticAllocaMap[AI];
11547int OldIndex = AllocaIndex;
11548MachineFrameInfo &MFI = FuncInfo.MF->getFrameInfo();
11549if (MFI.getObjectSize(FixedIndex) != MFI.getObjectSize(OldIndex)) {
11550LLVM_DEBUG(
11551dbgs() <<" argument copy elision failed due to bad fixed stack "
11552"object size\n");
11553return;
11554 }
11555Align RequiredAlignment = AI->getAlign();
11556if (MFI.getObjectAlign(FixedIndex) < RequiredAlignment) {
11557LLVM_DEBUG(dbgs() <<" argument copy elision failed: alignment of alloca "
11558"greater than stack argument alignment ("
11559 <<DebugStr(RequiredAlignment) <<" vs "
11560 <<DebugStr(MFI.getObjectAlign(FixedIndex)) <<")\n");
11561return;
11562 }
11563
11564// Perform the elision. Delete the old stack object and replace its only use
11565// in the variable info map. Mark the stack object as mutable and aliased.
11566LLVM_DEBUG({
11567dbgs() <<"Eliding argument copy from " << Arg <<" to " << *AI <<'\n'
11568 <<" Replacing frame index " << OldIndex <<" with " << FixedIndex
11569 <<'\n';
11570 });
11571 MFI.RemoveStackObject(OldIndex);
11572 MFI.setIsImmutableObjectIndex(FixedIndex,false);
11573 MFI.setIsAliasedObjectIndex(FixedIndex,true);
11574 AllocaIndex = FixedIndex;
11575 ArgCopyElisionFrameIndexMap.insert({OldIndex, FixedIndex});
11576for (SDValue ArgVal : ArgVals)
11577 Chains.push_back(ArgVal.getValue(1));
11578
11579// Avoid emitting code for the store implementing the copy.
11580constStoreInst *SI = ArgCopyIter->second.second;
11581 ElidedArgCopyInstrs.insert(SI);
11582
11583// Check for uses of the argument again so that we can avoid exporting ArgVal
11584// if it is't used by anything other than the store.
11585for (constValue *U : Arg.users()) {
11586if (U != SI) {
11587 ArgHasUses =true;
11588break;
11589 }
11590 }
11591}
11592
11593void SelectionDAGISel::LowerArguments(constFunction &F) {
11594SelectionDAG &DAG =SDB->DAG;
11595SDLoc dl =SDB->getCurSDLoc();
11596constDataLayout &DL = DAG.getDataLayout();
11597SmallVector<ISD::InputArg, 16>Ins;
11598
11599// In Naked functions we aren't going to save any registers.
11600if (F.hasFnAttribute(Attribute::Naked))
11601return;
11602
11603if (!FuncInfo->CanLowerReturn) {
11604// Put in an sret pointer parameter before all the other parameters.
11605MVT ValueVT =TLI->getPointerTy(DL,DL.getAllocaAddrSpace());
11606
11607ISD::ArgFlagsTyFlags;
11608Flags.setSRet();
11609MVT RegisterVT =TLI->getRegisterType(*DAG.getContext(), ValueVT);
11610ISD::InputArg RetArg(Flags, RegisterVT, ValueVT,true,
11611ISD::InputArg::NoArgIndex, 0);
11612Ins.push_back(RetArg);
11613 }
11614
11615// Look for stores of arguments to static allocas. Mark such arguments with a
11616// flag to ask the target to give us the memory location of that argument if
11617// available.
11618ArgCopyElisionMapTy ArgCopyElisionCandidates;
11619findArgumentCopyElisionCandidates(DL,FuncInfo.get(),
11620 ArgCopyElisionCandidates);
11621
11622// Set up the incoming argument description vector.
11623for (constArgument &Arg :F.args()) {
11624unsigned ArgNo = Arg.getArgNo();
11625SmallVector<EVT, 4> ValueVTs;
11626ComputeValueVTs(*TLI, DAG.getDataLayout(), Arg.getType(), ValueVTs);
11627bool isArgValueUsed = !Arg.use_empty();
11628unsigned PartBase = 0;
11629Type *FinalType = Arg.getType();
11630if (Arg.hasAttribute(Attribute::ByVal))
11631 FinalType = Arg.getParamByValType();
11632bool NeedsRegBlock =TLI->functionArgumentNeedsConsecutiveRegisters(
11633 FinalType,F.getCallingConv(),F.isVarArg(),DL);
11634for (unsignedValue = 0, NumValues = ValueVTs.size();
11635Value != NumValues; ++Value) {
11636EVT VT = ValueVTs[Value];
11637Type *ArgTy = VT.getTypeForEVT(*DAG.getContext());
11638ISD::ArgFlagsTyFlags;
11639
11640
11641if (Arg.getType()->isPointerTy()) {
11642Flags.setPointer();
11643Flags.setPointerAddrSpace(
11644 cast<PointerType>(Arg.getType())->getAddressSpace());
11645 }
11646if (Arg.hasAttribute(Attribute::ZExt))
11647Flags.setZExt();
11648if (Arg.hasAttribute(Attribute::SExt))
11649Flags.setSExt();
11650if (Arg.hasAttribute(Attribute::InReg)) {
11651// If we are using vectorcall calling convention, a structure that is
11652// passed InReg - is surely an HVA
11653if (F.getCallingConv() ==CallingConv::X86_VectorCall &&
11654 isa<StructType>(Arg.getType())) {
11655// The first value of a structure is marked
11656if (0 ==Value)
11657Flags.setHvaStart();
11658Flags.setHva();
11659 }
11660// Set InReg Flag
11661Flags.setInReg();
11662 }
11663if (Arg.hasAttribute(Attribute::StructRet))
11664Flags.setSRet();
11665if (Arg.hasAttribute(Attribute::SwiftSelf))
11666Flags.setSwiftSelf();
11667if (Arg.hasAttribute(Attribute::SwiftAsync))
11668Flags.setSwiftAsync();
11669if (Arg.hasAttribute(Attribute::SwiftError))
11670Flags.setSwiftError();
11671if (Arg.hasAttribute(Attribute::ByVal))
11672Flags.setByVal();
11673if (Arg.hasAttribute(Attribute::ByRef))
11674Flags.setByRef();
11675if (Arg.hasAttribute(Attribute::InAlloca)) {
11676Flags.setInAlloca();
11677// Set the byval flag for CCAssignFn callbacks that don't know about
11678// inalloca. This way we can know how many bytes we should've allocated
11679// and how many bytes a callee cleanup function will pop. If we port
11680// inalloca to more targets, we'll have to add custom inalloca handling
11681// in the various CC lowering callbacks.
11682Flags.setByVal();
11683 }
11684if (Arg.hasAttribute(Attribute::Preallocated)) {
11685Flags.setPreallocated();
11686// Set the byval flag for CCAssignFn callbacks that don't know about
11687// preallocated. This way we can know how many bytes we should've
11688// allocated and how many bytes a callee cleanup function will pop. If
11689// we port preallocated to more targets, we'll have to add custom
11690// preallocated handling in the various CC lowering callbacks.
11691Flags.setByVal();
11692 }
11693
11694// Certain targets (such as MIPS), may have a different ABI alignment
11695// for a type depending on the context. Give the target a chance to
11696// specify the alignment it wants.
11697constAlign OriginalAlignment(
11698TLI->getABIAlignmentForCallingConv(ArgTy,DL));
11699Flags.setOrigAlign(OriginalAlignment);
11700
11701Align MemAlign;
11702Type *ArgMemTy =nullptr;
11703if (Flags.isByVal() ||Flags.isInAlloca() ||Flags.isPreallocated() ||
11704Flags.isByRef()) {
11705if (!ArgMemTy)
11706 ArgMemTy = Arg.getPointeeInMemoryValueType();
11707
11708uint64_t MemSize =DL.getTypeAllocSize(ArgMemTy);
11709
11710// For in-memory arguments, size and alignment should be passed from FE.
11711// BE will guess if this info is not there but there are cases it cannot
11712// get right.
11713if (auto ParamAlign = Arg.getParamStackAlign())
11714 MemAlign = *ParamAlign;
11715elseif ((ParamAlign = Arg.getParamAlign()))
11716 MemAlign = *ParamAlign;
11717else
11718 MemAlign =TLI->getByValTypeAlignment(ArgMemTy,DL);
11719if (Flags.isByRef())
11720Flags.setByRefSize(MemSize);
11721else
11722Flags.setByValSize(MemSize);
11723 }elseif (auto ParamAlign = Arg.getParamStackAlign()) {
11724 MemAlign = *ParamAlign;
11725 }else {
11726 MemAlign = OriginalAlignment;
11727 }
11728Flags.setMemAlign(MemAlign);
11729
11730if (Arg.hasAttribute(Attribute::Nest))
11731Flags.setNest();
11732if (NeedsRegBlock)
11733Flags.setInConsecutiveRegs();
11734if (ArgCopyElisionCandidates.count(&Arg))
11735Flags.setCopyElisionCandidate();
11736if (Arg.hasAttribute(Attribute::Returned))
11737Flags.setReturned();
11738
11739MVT RegisterVT =TLI->getRegisterTypeForCallingConv(
11740 *CurDAG->getContext(),F.getCallingConv(), VT);
11741unsigned NumRegs =TLI->getNumRegistersForCallingConv(
11742 *CurDAG->getContext(),F.getCallingConv(), VT);
11743for (unsigned i = 0; i != NumRegs; ++i) {
11744// For scalable vectors, use the minimum size; individual targets
11745// are responsible for handling scalable vector arguments and
11746// return values.
11747ISD::InputArg MyFlags(
11748 Flags, RegisterVT, VT, isArgValueUsed, ArgNo,
11749 PartBase + i * RegisterVT.getStoreSize().getKnownMinValue());
11750if (NumRegs > 1 && i == 0)
11751 MyFlags.Flags.setSplit();
11752// if it isn't first piece, alignment must be 1
11753elseif (i > 0) {
11754 MyFlags.Flags.setOrigAlign(Align(1));
11755if (i == NumRegs - 1)
11756 MyFlags.Flags.setSplitEnd();
11757 }
11758Ins.push_back(MyFlags);
11759 }
11760if (NeedsRegBlock &&Value == NumValues - 1)
11761Ins[Ins.size() - 1].Flags.setInConsecutiveRegsLast();
11762 PartBase += VT.getStoreSize().getKnownMinValue();
11763 }
11764 }
11765
11766// Call the target to set up the argument values.
11767SmallVector<SDValue, 8> InVals;
11768SDValue NewRoot =TLI->LowerFormalArguments(
11769 DAG.getRoot(),F.getCallingConv(),F.isVarArg(), Ins, dl, DAG, InVals);
11770
11771// Verify that the target's LowerFormalArguments behaved as expected.
11772assert(NewRoot.getNode() && NewRoot.getValueType() == MVT::Other &&
11773"LowerFormalArguments didn't return a valid chain!");
11774assert(InVals.size() ==Ins.size() &&
11775"LowerFormalArguments didn't emit the correct number of values!");
11776LLVM_DEBUG({
11777for (unsigned i = 0, e =Ins.size(); i != e; ++i) {
11778 assert(InVals[i].getNode() &&
11779"LowerFormalArguments emitted a null value!");
11780 assert(EVT(Ins[i].VT) == InVals[i].getValueType() &&
11781"LowerFormalArguments emitted a value with the wrong type!");
11782 }
11783 });
11784
11785// Update the DAG with the new chain value resulting from argument lowering.
11786 DAG.setRoot(NewRoot);
11787
11788// Set up the argument values.
11789unsigned i = 0;
11790if (!FuncInfo->CanLowerReturn) {
11791// Create a virtual register for the sret pointer, and put in a copy
11792// from the sret argument into it.
11793MVT VT =TLI->getPointerTy(DL,DL.getAllocaAddrSpace());
11794MVT RegVT =TLI->getRegisterType(*CurDAG->getContext(), VT);
11795 std::optional<ISD::NodeType> AssertOp;
11796SDValue ArgValue =
11797getCopyFromParts(DAG, dl, &InVals[0], 1, RegVT, VT,nullptr, NewRoot,
11798F.getCallingConv(), AssertOp);
11799
11800MachineFunction&MF =SDB->DAG.getMachineFunction();
11801MachineRegisterInfo&RegInfo =MF.getRegInfo();
11802Register SRetReg =
11803RegInfo.createVirtualRegister(TLI->getRegClassFor(RegVT));
11804FuncInfo->DemoteRegister = SRetReg;
11805 NewRoot =
11806SDB->DAG.getCopyToReg(NewRoot,SDB->getCurSDLoc(), SRetReg, ArgValue);
11807 DAG.setRoot(NewRoot);
11808
11809// i indexes lowered arguments. Bump it past the hidden sret argument.
11810 ++i;
11811 }
11812
11813SmallVector<SDValue, 4> Chains;
11814DenseMap<int, int> ArgCopyElisionFrameIndexMap;
11815for (constArgument &Arg :F.args()) {
11816SmallVector<SDValue, 4> ArgValues;
11817SmallVector<EVT, 4> ValueVTs;
11818ComputeValueVTs(*TLI, DAG.getDataLayout(), Arg.getType(), ValueVTs);
11819unsigned NumValues = ValueVTs.size();
11820if (NumValues == 0)
11821continue;
11822
11823bool ArgHasUses = !Arg.use_empty();
11824
11825// Elide the copying store if the target loaded this argument from a
11826// suitable fixed stack object.
11827if (Ins[i].Flags.isCopyElisionCandidate()) {
11828unsigned NumParts = 0;
11829for (EVT VT : ValueVTs)
11830 NumParts +=TLI->getNumRegistersForCallingConv(*CurDAG->getContext(),
11831F.getCallingConv(), VT);
11832
11833tryToElideArgumentCopy(*FuncInfo, Chains, ArgCopyElisionFrameIndexMap,
11834ElidedArgCopyInstrs, ArgCopyElisionCandidates, Arg,
11835ArrayRef(&InVals[i], NumParts), ArgHasUses);
11836 }
11837
11838// If this argument is unused then remember its value. It is used to generate
11839// debugging information.
11840bool isSwiftErrorArg =
11841TLI->supportSwiftError() &&
11842 Arg.hasAttribute(Attribute::SwiftError);
11843if (!ArgHasUses && !isSwiftErrorArg) {
11844SDB->setUnusedArgValue(&Arg, InVals[i]);
11845
11846// Also remember any frame index for use in FastISel.
11847if (FrameIndexSDNode *FI =
11848 dyn_cast<FrameIndexSDNode>(InVals[i].getNode()))
11849FuncInfo->setArgumentFrameIndex(&Arg, FI->getIndex());
11850 }
11851
11852for (unsigned Val = 0; Val != NumValues; ++Val) {
11853EVT VT = ValueVTs[Val];
11854MVT PartVT =TLI->getRegisterTypeForCallingConv(*CurDAG->getContext(),
11855F.getCallingConv(), VT);
11856unsigned NumParts =TLI->getNumRegistersForCallingConv(
11857 *CurDAG->getContext(),F.getCallingConv(), VT);
11858
11859// Even an apparent 'unused' swifterror argument needs to be returned. So
11860// we do generate a copy for it that can be used on return from the
11861// function.
11862if (ArgHasUses || isSwiftErrorArg) {
11863 std::optional<ISD::NodeType> AssertOp;
11864if (Arg.hasAttribute(Attribute::SExt))
11865 AssertOp =ISD::AssertSext;
11866elseif (Arg.hasAttribute(Attribute::ZExt))
11867 AssertOp =ISD::AssertZext;
11868
11869 ArgValues.push_back(getCopyFromParts(DAG, dl, &InVals[i], NumParts,
11870 PartVT, VT,nullptr, NewRoot,
11871F.getCallingConv(), AssertOp));
11872 }
11873
11874 i += NumParts;
11875 }
11876
11877// We don't need to do anything else for unused arguments.
11878if (ArgValues.empty())
11879continue;
11880
11881// Note down frame index.
11882if (FrameIndexSDNode *FI =
11883 dyn_cast<FrameIndexSDNode>(ArgValues[0].getNode()))
11884FuncInfo->setArgumentFrameIndex(&Arg, FI->getIndex());
11885
11886SDValue Res = DAG.getMergeValues(ArrayRef(ArgValues.data(), NumValues),
11887SDB->getCurSDLoc());
11888
11889SDB->setValue(&Arg, Res);
11890if (!TM.Options.EnableFastISel && Res.getOpcode() ==ISD::BUILD_PAIR) {
11891// We want to associate the argument with the frame index, among
11892// involved operands, that correspond to the lowest address. The
11893// getCopyFromParts function, called earlier, is swapping the order of
11894// the operands to BUILD_PAIR depending on endianness. The result of
11895// that swapping is that the least significant bits of the argument will
11896// be in the first operand of the BUILD_PAIR node, and the most
11897// significant bits will be in the second operand.
11898unsigned LowAddressOp = DAG.getDataLayout().isBigEndian() ? 1 : 0;
11899if (LoadSDNode *LNode =
11900 dyn_cast<LoadSDNode>(Res.getOperand(LowAddressOp).getNode()))
11901if (FrameIndexSDNode *FI =
11902 dyn_cast<FrameIndexSDNode>(LNode->getBasePtr().getNode()))
11903FuncInfo->setArgumentFrameIndex(&Arg, FI->getIndex());
11904 }
11905
11906// Analyses past this point are naive and don't expect an assertion.
11907if (Res.getOpcode() ==ISD::AssertZext)
11908 Res = Res.getOperand(0);
11909
11910// Update the SwiftErrorVRegDefMap.
11911if (Res.getOpcode() ==ISD::CopyFromReg && isSwiftErrorArg) {
11912RegisterReg = cast<RegisterSDNode>(Res.getOperand(1))->getReg();
11913if (Reg.isVirtual())
11914SwiftError->setCurrentVReg(FuncInfo->MBB,SwiftError->getFunctionArg(),
11915 Reg);
11916 }
11917
11918// If this argument is live outside of the entry block, insert a copy from
11919// wherever we got it to the vreg that other BB's will reference it as.
11920if (Res.getOpcode() ==ISD::CopyFromReg) {
11921// If we can, though, try to skip creating an unnecessary vreg.
11922// FIXME: This isn't very clean... it would be nice to make this more
11923// general.
11924RegisterReg = cast<RegisterSDNode>(Res.getOperand(1))->getReg();
11925if (Reg.isVirtual()) {
11926FuncInfo->ValueMap[&Arg] =Reg;
11927continue;
11928 }
11929 }
11930if (!isOnlyUsedInEntryBlock(&Arg,TM.Options.EnableFastISel)) {
11931FuncInfo->InitializeRegForValue(&Arg);
11932SDB->CopyToExportRegsIfNeeded(&Arg);
11933 }
11934 }
11935
11936if (!Chains.empty()) {
11937 Chains.push_back(NewRoot);
11938 NewRoot = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Chains);
11939 }
11940
11941 DAG.setRoot(NewRoot);
11942
11943assert(i == InVals.size() &&"Argument register count mismatch!");
11944
11945// If any argument copy elisions occurred and we have debug info, update the
11946// stale frame indices used in the dbg.declare variable info table.
11947if (!ArgCopyElisionFrameIndexMap.empty()) {
11948for (MachineFunction::VariableDbgInfo &VI :
11949MF->getInStackSlotVariableDbgInfo()) {
11950autoI = ArgCopyElisionFrameIndexMap.find(VI.getStackSlot());
11951if (I != ArgCopyElisionFrameIndexMap.end())
11952VI.updateStackSlot(I->second);
11953 }
11954 }
11955
11956// Finally, if the target has anything special to do, allow it to do so.
11957emitFunctionEntryCode();
11958}
11959
11960/// Handle PHI nodes in successor blocks. Emit code into the SelectionDAG to
11961/// ensure constants are generated when needed. Remember the virtual registers
11962/// that need to be added to the Machine PHI nodes as input. We cannot just
11963/// directly add them, because expansion might result in multiple MBB's for one
11964/// BB. As such, the start of the BB might correspond to a different MBB than
11965/// the end.
11966void
11967SelectionDAGBuilder::HandlePHINodesInSuccessorBlocks(constBasicBlock *LLVMBB) {
11968constTargetLowering &TLI =DAG.getTargetLoweringInfo();
11969
11970SmallPtrSet<MachineBasicBlock *, 4> SuccsHandled;
11971
11972// Check PHI nodes in successors that expect a value to be available from this
11973// block.
11974for (constBasicBlock *SuccBB :successors(LLVMBB->getTerminator())) {
11975if (!isa<PHINode>(SuccBB->begin()))continue;
11976MachineBasicBlock *SuccMBB =FuncInfo.getMBB(SuccBB);
11977
11978// If this terminator has multiple identical successors (common for
11979// switches), only handle each succ once.
11980if (!SuccsHandled.insert(SuccMBB).second)
11981continue;
11982
11983MachineBasicBlock::iteratorMBBI = SuccMBB->begin();
11984
11985// At this point we know that there is a 1-1 correspondence between LLVM PHI
11986// nodes and Machine PHI nodes, but the incoming operands have not been
11987// emitted yet.
11988for (constPHINode &PN : SuccBB->phis()) {
11989// Ignore dead phi's.
11990if (PN.use_empty())
11991continue;
11992
11993// Skip empty types
11994if (PN.getType()->isEmptyTy())
11995continue;
11996
11997unsignedReg;
11998constValue *PHIOp = PN.getIncomingValueForBlock(LLVMBB);
11999
12000if (constauto *C = dyn_cast<Constant>(PHIOp)) {
12001unsigned &RegOut =ConstantsOut[C];
12002if (RegOut == 0) {
12003 RegOut =FuncInfo.CreateRegs(C);
12004// We need to zero/sign extend ConstantInt phi operands to match
12005// assumptions in FunctionLoweringInfo::ComputePHILiveOutRegInfo.
12006ISD::NodeType ExtendType =ISD::ANY_EXTEND;
12007if (auto *CI = dyn_cast<ConstantInt>(C))
12008 ExtendType = TLI.signExtendConstant(CI) ?ISD::SIGN_EXTEND
12009 :ISD::ZERO_EXTEND;
12010CopyValueToVirtualRegister(C, RegOut, ExtendType);
12011 }
12012Reg = RegOut;
12013 }else {
12014DenseMap<const Value *, Register>::iteratorI =
12015FuncInfo.ValueMap.find(PHIOp);
12016if (I !=FuncInfo.ValueMap.end())
12017Reg =I->second;
12018else {
12019assert(isa<AllocaInst>(PHIOp) &&
12020FuncInfo.StaticAllocaMap.count(cast<AllocaInst>(PHIOp)) &&
12021"Didn't codegen value into a register!??");
12022Reg =FuncInfo.CreateRegs(PHIOp);
12023CopyValueToVirtualRegister(PHIOp, Reg);
12024 }
12025 }
12026
12027// Remember that this register needs to added to the machine PHI node as
12028// the input for this MBB.
12029SmallVector<EVT, 4> ValueVTs;
12030ComputeValueVTs(TLI,DAG.getDataLayout(), PN.getType(), ValueVTs);
12031for (EVT VT : ValueVTs) {
12032constunsigned NumRegisters = TLI.getNumRegisters(*DAG.getContext(), VT);
12033for (unsigned i = 0; i != NumRegisters; ++i)
12034FuncInfo.PHINodesToUpdate.push_back(
12035 std::make_pair(&*MBBI++, Reg + i));
12036Reg += NumRegisters;
12037 }
12038 }
12039 }
12040
12041ConstantsOut.clear();
12042}
12043
12044MachineBasicBlock *SelectionDAGBuilder::NextBlock(MachineBasicBlock *MBB) {
12045MachineFunction::iteratorI(MBB);
12046if (++I ==FuncInfo.MF->end())
12047returnnullptr;
12048return &*I;
12049}
12050
12051/// During lowering new call nodes can be created (such as memset, etc.).
12052/// Those will become new roots of the current DAG, but complications arise
12053/// when they are tail calls. In such cases, the call lowering will update
12054/// the root, but the builder still needs to know that a tail call has been
12055/// lowered in order to avoid generating an additional return.
12056void SelectionDAGBuilder::updateDAGForMaybeTailCall(SDValue MaybeTC) {
12057// If the node is null, we do have a tail call.
12058if (MaybeTC.getNode() !=nullptr)
12059DAG.setRoot(MaybeTC);
12060else
12061HasTailCall =true;
12062}
12063
12064void SelectionDAGBuilder::lowerWorkItem(SwitchWorkListItem W,Value *Cond,
12065MachineBasicBlock *SwitchMBB,
12066MachineBasicBlock *DefaultMBB) {
12067MachineFunction *CurMF =FuncInfo.MF;
12068MachineBasicBlock *NextMBB =nullptr;
12069MachineFunction::iterator BBI(W.MBB);
12070if (++BBI !=FuncInfo.MF->end())
12071 NextMBB = &*BBI;
12072
12073unsignedSize =W.LastCluster -W.FirstCluster + 1;
12074
12075BranchProbabilityInfo *BPI =FuncInfo.BPI;
12076
12077if (Size == 2 &&W.MBB == SwitchMBB) {
12078// If any two of the cases has the same destination, and if one value
12079// is the same as the other, but has one bit unset that the other has set,
12080// use bit manipulation to do two compares at once. For example:
12081// "if (X == 6 || X == 4)" -> "if ((X|2) == 6)"
12082// TODO: This could be extended to merge any 2 cases in switches with 3
12083// cases.
12084// TODO: Handle cases where W.CaseBB != SwitchBB.
12085CaseCluster &Small = *W.FirstCluster;
12086CaseCluster &Big = *W.LastCluster;
12087
12088if (Small.Low ==Small.High &&Big.Low ==Big.High &&
12089Small.MBB ==Big.MBB) {
12090constAPInt &SmallValue =Small.Low->getValue();
12091constAPInt &BigValue =Big.Low->getValue();
12092
12093// Check that there is only one bit different.
12094APInt CommonBit = BigValue ^ SmallValue;
12095if (CommonBit.isPowerOf2()) {
12096SDValue CondLHS =getValue(Cond);
12097EVT VT = CondLHS.getValueType();
12098SDLocDL =getCurSDLoc();
12099
12100SDValueOr =DAG.getNode(ISD::OR,DL, VT, CondLHS,
12101DAG.getConstant(CommonBit,DL, VT));
12102SDValueCond =DAG.getSetCC(
12103DL, MVT::i1,Or,DAG.getConstant(BigValue | SmallValue,DL, VT),
12104ISD::SETEQ);
12105
12106// Update successor info.
12107// Both Small and Big will jump to Small.BB, so we sum up the
12108// probabilities.
12109 addSuccessorWithProb(SwitchMBB,Small.MBB,Small.Prob +Big.Prob);
12110if (BPI)
12111 addSuccessorWithProb(
12112 SwitchMBB, DefaultMBB,
12113// The default destination is the first successor in IR.
12114 BPI->getEdgeProbability(SwitchMBB->getBasicBlock(), (unsigned)0));
12115else
12116 addSuccessorWithProb(SwitchMBB, DefaultMBB);
12117
12118// Insert the true branch.
12119SDValue BrCond =
12120DAG.getNode(ISD::BRCOND,DL, MVT::Other,getControlRoot(),Cond,
12121DAG.getBasicBlock(Small.MBB));
12122// Insert the false branch.
12123 BrCond =DAG.getNode(ISD::BR,DL, MVT::Other, BrCond,
12124DAG.getBasicBlock(DefaultMBB));
12125
12126DAG.setRoot(BrCond);
12127return;
12128 }
12129 }
12130 }
12131
12132if (TM.getOptLevel() !=CodeGenOptLevel::None) {
12133// Here, we order cases by probability so the most likely case will be
12134// checked first. However, two clusters can have the same probability in
12135// which case their relative ordering is non-deterministic. So we use Low
12136// as a tie-breaker as clusters are guaranteed to never overlap.
12137llvm::sort(W.FirstCluster,W.LastCluster + 1,
12138 [](constCaseCluster &a,constCaseCluster &b) {
12139 return a.Prob != b.Prob ?
12140 a.Prob > b.Prob :
12141 a.Low->getValue().slt(b.Low->getValue());
12142 });
12143
12144// Rearrange the case blocks so that the last one falls through if possible
12145// without changing the order of probabilities.
12146for (CaseClusterItI =W.LastCluster;I >W.FirstCluster; ) {
12147 --I;
12148if (I->Prob >W.LastCluster->Prob)
12149break;
12150if (I->Kind ==CC_Range &&I->MBB == NextMBB) {
12151std::swap(*I, *W.LastCluster);
12152break;
12153 }
12154 }
12155 }
12156
12157// Compute total probability.
12158BranchProbability DefaultProb =W.DefaultProb;
12159BranchProbability UnhandledProbs = DefaultProb;
12160for (CaseClusterItI =W.FirstCluster;I <=W.LastCluster; ++I)
12161 UnhandledProbs +=I->Prob;
12162
12163MachineBasicBlock *CurMBB =W.MBB;
12164for (CaseClusterItI =W.FirstCluster, E =W.LastCluster;I <= E; ++I) {
12165bool FallthroughUnreachable =false;
12166MachineBasicBlock *Fallthrough;
12167if (I ==W.LastCluster) {
12168// For the last cluster, fall through to the default destination.
12169 Fallthrough = DefaultMBB;
12170 FallthroughUnreachable = isa<UnreachableInst>(
12171 DefaultMBB->getBasicBlock()->getFirstNonPHIOrDbg());
12172 }else {
12173 Fallthrough = CurMF->CreateMachineBasicBlock(CurMBB->getBasicBlock());
12174 CurMF->insert(BBI, Fallthrough);
12175// Put Cond in a virtual register to make it available from the new blocks.
12176ExportFromCurrentBlock(Cond);
12177 }
12178 UnhandledProbs -=I->Prob;
12179
12180switch (I->Kind) {
12181caseCC_JumpTable: {
12182// FIXME: Optimize away range check based on pivot comparisons.
12183JumpTableHeader *JTH = &SL->JTCases[I->JTCasesIndex].first;
12184SwitchCG::JumpTable *JT = &SL->JTCases[I->JTCasesIndex].second;
12185
12186// The jump block hasn't been inserted yet; insert it here.
12187MachineBasicBlock *JumpMBB =JT->MBB;
12188 CurMF->insert(BBI, JumpMBB);
12189
12190auto JumpProb =I->Prob;
12191auto FallthroughProb = UnhandledProbs;
12192
12193// If the default statement is a target of the jump table, we evenly
12194// distribute the default probability to successors of CurMBB. Also
12195// update the probability on the edge from JumpMBB to Fallthrough.
12196for (MachineBasicBlock::succ_iterator SI = JumpMBB->succ_begin(),
12197 SE = JumpMBB->succ_end();
12198 SI != SE; ++SI) {
12199if (*SI == DefaultMBB) {
12200 JumpProb += DefaultProb / 2;
12201 FallthroughProb -= DefaultProb / 2;
12202 JumpMBB->setSuccProbability(SI, DefaultProb / 2);
12203 JumpMBB->normalizeSuccProbs();
12204break;
12205 }
12206 }
12207
12208// If the default clause is unreachable, propagate that knowledge into
12209// JTH->FallthroughUnreachable which will use it to suppress the range
12210// check.
12211//
12212// However, don't do this if we're doing branch target enforcement,
12213// because a table branch _without_ a range check can be a tempting JOP
12214// gadget - out-of-bounds inputs that are impossible in correct
12215// execution become possible again if an attacker can influence the
12216// control flow. So if an attacker doesn't already have a BTI bypass
12217// available, we don't want them to be able to get one out of this
12218// table branch.
12219if (FallthroughUnreachable) {
12220Function &CurFunc = CurMF->getFunction();
12221if (!CurFunc.hasFnAttribute("branch-target-enforcement"))
12222 JTH->FallthroughUnreachable =true;
12223 }
12224
12225if (!JTH->FallthroughUnreachable)
12226 addSuccessorWithProb(CurMBB, Fallthrough, FallthroughProb);
12227 addSuccessorWithProb(CurMBB, JumpMBB, JumpProb);
12228 CurMBB->normalizeSuccProbs();
12229
12230// The jump table header will be inserted in our current block, do the
12231// range check, and fall through to our fallthrough block.
12232 JTH->HeaderBB = CurMBB;
12233JT->Default = Fallthrough;// FIXME: Move Default to JumpTableHeader.
12234
12235// If we're in the right place, emit the jump table header right now.
12236if (CurMBB == SwitchMBB) {
12237visitJumpTableHeader(*JT, *JTH, SwitchMBB);
12238 JTH->Emitted =true;
12239 }
12240break;
12241 }
12242caseCC_BitTests: {
12243// FIXME: Optimize away range check based on pivot comparisons.
12244BitTestBlock *BTB = &SL->BitTestCases[I->BTCasesIndex];
12245
12246// The bit test blocks haven't been inserted yet; insert them here.
12247for (BitTestCase &BTC : BTB->Cases)
12248 CurMF->insert(BBI, BTC.ThisBB);
12249
12250// Fill in fields of the BitTestBlock.
12251 BTB->Parent = CurMBB;
12252 BTB->Default = Fallthrough;
12253
12254 BTB->DefaultProb = UnhandledProbs;
12255// If the cases in bit test don't form a contiguous range, we evenly
12256// distribute the probability on the edge to Fallthrough to two
12257// successors of CurMBB.
12258if (!BTB->ContiguousRange) {
12259 BTB->Prob += DefaultProb / 2;
12260 BTB->DefaultProb -= DefaultProb / 2;
12261 }
12262
12263if (FallthroughUnreachable)
12264 BTB->FallthroughUnreachable =true;
12265
12266// If we're in the right place, emit the bit test header right now.
12267if (CurMBB == SwitchMBB) {
12268visitBitTestHeader(*BTB, SwitchMBB);
12269 BTB->Emitted =true;
12270 }
12271break;
12272 }
12273caseCC_Range: {
12274constValue *RHS, *LHS, *MHS;
12275ISD::CondCodeCC;
12276if (I->Low ==I->High) {
12277// Check Cond == I->Low.
12278CC =ISD::SETEQ;
12279LHS =Cond;
12280RHS=I->Low;
12281 MHS =nullptr;
12282 }else {
12283// Check I->Low <= Cond <= I->High.
12284CC =ISD::SETLE;
12285LHS =I->Low;
12286 MHS =Cond;
12287RHS =I->High;
12288 }
12289
12290// If Fallthrough is unreachable, fold away the comparison.
12291if (FallthroughUnreachable)
12292CC =ISD::SETTRUE;
12293
12294// The false probability is the sum of all unhandled cases.
12295CaseBlock CB(CC, LHS, RHS, MHS,I->MBB, Fallthrough, CurMBB,
12296getCurSDLoc(),I->Prob, UnhandledProbs);
12297
12298if (CurMBB == SwitchMBB)
12299visitSwitchCase(CB, SwitchMBB);
12300else
12301SL->SwitchCases.push_back(CB);
12302
12303break;
12304 }
12305 }
12306 CurMBB = Fallthrough;
12307 }
12308}
12309
12310void SelectionDAGBuilder::splitWorkItem(SwitchWorkList &WorkList,
12311constSwitchWorkListItem &W,
12312Value *Cond,
12313MachineBasicBlock *SwitchMBB) {
12314assert(W.FirstCluster->Low->getValue().slt(W.LastCluster->Low->getValue()) &&
12315"Clusters not sorted?");
12316assert(W.LastCluster -W.FirstCluster + 1 >= 2 &&"Too small to split!");
12317
12318auto [LastLeft, FirstRight, LeftProb, RightProb] =
12319SL->computeSplitWorkItemInfo(W);
12320
12321// Use the first element on the right as pivot since we will make less-than
12322// comparisons against it.
12323CaseClusterIt PivotCluster = FirstRight;
12324assert(PivotCluster >W.FirstCluster);
12325assert(PivotCluster <=W.LastCluster);
12326
12327CaseClusterIt FirstLeft =W.FirstCluster;
12328CaseClusterIt LastRight =W.LastCluster;
12329
12330constConstantInt *Pivot = PivotCluster->Low;
12331
12332// New blocks will be inserted immediately after the current one.
12333MachineFunction::iterator BBI(W.MBB);
12334 ++BBI;
12335
12336// We will branch to the LHS if Value < Pivot. If LHS is a single cluster,
12337// we can branch to its destination directly if it's squeezed exactly in
12338// between the known lower bound and Pivot - 1.
12339MachineBasicBlock *LeftMBB;
12340if (FirstLeft == LastLeft && FirstLeft->Kind ==CC_Range &&
12341 FirstLeft->Low ==W.GE &&
12342 (FirstLeft->High->getValue() + 1LL) == Pivot->getValue()) {
12343 LeftMBB = FirstLeft->MBB;
12344 }else {
12345 LeftMBB =FuncInfo.MF->CreateMachineBasicBlock(W.MBB->getBasicBlock());
12346FuncInfo.MF->insert(BBI, LeftMBB);
12347 WorkList.push_back(
12348 {LeftMBB, FirstLeft, LastLeft,W.GE, Pivot,W.DefaultProb / 2});
12349// Put Cond in a virtual register to make it available from the new blocks.
12350ExportFromCurrentBlock(Cond);
12351 }
12352
12353// Similarly, we will branch to the RHS if Value >= Pivot. If RHS is a
12354// single cluster, RHS.Low == Pivot, and we can branch to its destination
12355// directly if RHS.High equals the current upper bound.
12356MachineBasicBlock *RightMBB;
12357if (FirstRight == LastRight && FirstRight->Kind ==CC_Range &&
12358W.LT && (FirstRight->High->getValue() + 1ULL) ==W.LT->getValue()) {
12359 RightMBB = FirstRight->MBB;
12360 }else {
12361 RightMBB =FuncInfo.MF->CreateMachineBasicBlock(W.MBB->getBasicBlock());
12362FuncInfo.MF->insert(BBI, RightMBB);
12363 WorkList.push_back(
12364 {RightMBB, FirstRight, LastRight, Pivot,W.LT,W.DefaultProb / 2});
12365// Put Cond in a virtual register to make it available from the new blocks.
12366ExportFromCurrentBlock(Cond);
12367 }
12368
12369// Create the CaseBlock record that will be used to lower the branch.
12370CaseBlock CB(ISD::SETLT,Cond, Pivot,nullptr, LeftMBB, RightMBB,W.MBB,
12371getCurSDLoc(), LeftProb, RightProb);
12372
12373if (W.MBB == SwitchMBB)
12374visitSwitchCase(CB, SwitchMBB);
12375else
12376SL->SwitchCases.push_back(CB);
12377}
12378
12379// Scale CaseProb after peeling a case with the probablity of PeeledCaseProb
12380// from the swith statement.
12381staticBranchProbabilityscaleCaseProbality(BranchProbability CaseProb,
12382BranchProbability PeeledCaseProb) {
12383if (PeeledCaseProb ==BranchProbability::getOne())
12384returnBranchProbability::getZero();
12385BranchProbability SwitchProb = PeeledCaseProb.getCompl();
12386
12387uint32_t Numerator = CaseProb.getNumerator();
12388uint32_t Denominator = SwitchProb.scale(CaseProb.getDenominator());
12389returnBranchProbability(Numerator, std::max(Numerator, Denominator));
12390}
12391
12392// Try to peel the top probability case if it exceeds the threshold.
12393// Return current MachineBasicBlock for the switch statement if the peeling
12394// does not occur.
12395// If the peeling is performed, return the newly created MachineBasicBlock
12396// for the peeled switch statement. Also update Clusters to remove the peeled
12397// case. PeeledCaseProb is the BranchProbability for the peeled case.
12398MachineBasicBlock *SelectionDAGBuilder::peelDominantCaseCluster(
12399constSwitchInst &SI,CaseClusterVector &Clusters,
12400BranchProbability &PeeledCaseProb) {
12401MachineBasicBlock *SwitchMBB =FuncInfo.MBB;
12402// Don't perform if there is only one cluster or optimizing for size.
12403if (SwitchPeelThreshold > 100 || !FuncInfo.BPI || Clusters.size() < 2 ||
12404 TM.getOptLevel() ==CodeGenOptLevel::None ||
12405 SwitchMBB->getParent()->getFunction().hasMinSize())
12406return SwitchMBB;
12407
12408BranchProbability TopCaseProb =BranchProbability(SwitchPeelThreshold, 100);
12409unsigned PeeledCaseIndex = 0;
12410bool SwitchPeeled =false;
12411for (unsigned Index = 0;Index < Clusters.size(); ++Index) {
12412CaseCluster &CC = Clusters[Index];
12413if (CC.Prob < TopCaseProb)
12414continue;
12415 TopCaseProb =CC.Prob;
12416 PeeledCaseIndex =Index;
12417 SwitchPeeled =true;
12418 }
12419if (!SwitchPeeled)
12420return SwitchMBB;
12421
12422LLVM_DEBUG(dbgs() <<"Peeled one top case in switch stmt, prob: "
12423 << TopCaseProb <<"\n");
12424
12425// Record the MBB for the peeled switch statement.
12426MachineFunction::iterator BBI(SwitchMBB);
12427 ++BBI;
12428MachineBasicBlock *PeeledSwitchMBB =
12429FuncInfo.MF->CreateMachineBasicBlock(SwitchMBB->getBasicBlock());
12430FuncInfo.MF->insert(BBI, PeeledSwitchMBB);
12431
12432ExportFromCurrentBlock(SI.getCondition());
12433auto PeeledCaseIt = Clusters.begin() + PeeledCaseIndex;
12434SwitchWorkListItemW = {SwitchMBB, PeeledCaseIt, PeeledCaseIt,
12435nullptr,nullptr, TopCaseProb.getCompl()};
12436 lowerWorkItem(W,SI.getCondition(), SwitchMBB, PeeledSwitchMBB);
12437
12438 Clusters.erase(PeeledCaseIt);
12439for (CaseCluster &CC : Clusters) {
12440LLVM_DEBUG(
12441dbgs() <<"Scale the probablity for one cluster, before scaling: "
12442 <<CC.Prob <<"\n");
12443CC.Prob =scaleCaseProbality(CC.Prob, TopCaseProb);
12444LLVM_DEBUG(dbgs() <<"After scaling: " <<CC.Prob <<"\n");
12445 }
12446 PeeledCaseProb = TopCaseProb;
12447return PeeledSwitchMBB;
12448}
12449
12450void SelectionDAGBuilder::visitSwitch(constSwitchInst &SI) {
12451// Extract cases from the switch.
12452BranchProbabilityInfo *BPI =FuncInfo.BPI;
12453CaseClusterVector Clusters;
12454 Clusters.reserve(SI.getNumCases());
12455for (autoI :SI.cases()) {
12456MachineBasicBlock *Succ =FuncInfo.getMBB(I.getCaseSuccessor());
12457constConstantInt *CaseVal =I.getCaseValue();
12458BranchProbability Prob =
12459 BPI ? BPI->getEdgeProbability(SI.getParent(),I.getSuccessorIndex())
12460 :BranchProbability(1,SI.getNumCases() + 1);
12461 Clusters.push_back(CaseCluster::range(CaseVal, CaseVal, Succ, Prob));
12462 }
12463
12464MachineBasicBlock *DefaultMBB =FuncInfo.getMBB(SI.getDefaultDest());
12465
12466// Cluster adjacent cases with the same destination. We do this at all
12467// optimization levels because it's cheap to do and will make codegen faster
12468// if there are many clusters.
12469sortAndRangeify(Clusters);
12470
12471// The branch probablity of the peeled case.
12472BranchProbability PeeledCaseProb =BranchProbability::getZero();
12473MachineBasicBlock *PeeledSwitchMBB =
12474 peelDominantCaseCluster(SI, Clusters, PeeledCaseProb);
12475
12476// If there is only the default destination, jump there directly.
12477MachineBasicBlock *SwitchMBB =FuncInfo.MBB;
12478if (Clusters.empty()) {
12479assert(PeeledSwitchMBB == SwitchMBB);
12480 SwitchMBB->addSuccessor(DefaultMBB);
12481if (DefaultMBB != NextBlock(SwitchMBB)) {
12482DAG.setRoot(DAG.getNode(ISD::BR,getCurSDLoc(), MVT::Other,
12483getControlRoot(),DAG.getBasicBlock(DefaultMBB)));
12484 }
12485return;
12486 }
12487
12488SL->findJumpTables(Clusters, &SI,getCurSDLoc(), DefaultMBB,DAG.getPSI(),
12489DAG.getBFI());
12490SL->findBitTestClusters(Clusters, &SI);
12491
12492LLVM_DEBUG({
12493dbgs() <<"Case clusters: ";
12494for (constCaseCluster &C : Clusters) {
12495if (C.Kind ==CC_JumpTable)
12496dbgs() <<"JT:";
12497if (C.Kind ==CC_BitTests)
12498dbgs() <<"BT:";
12499
12500C.Low->getValue().print(dbgs(),true);
12501if (C.Low !=C.High) {
12502dbgs() <<'-';
12503C.High->getValue().print(dbgs(),true);
12504 }
12505dbgs() <<' ';
12506 }
12507dbgs() <<'\n';
12508 });
12509
12510assert(!Clusters.empty());
12511SwitchWorkList WorkList;
12512CaseClusterItFirst = Clusters.begin();
12513CaseClusterItLast = Clusters.end() - 1;
12514auto DefaultProb = getEdgeProbability(PeeledSwitchMBB, DefaultMBB);
12515// Scale the branchprobability for DefaultMBB if the peel occurs and
12516// DefaultMBB is not replaced.
12517if (PeeledCaseProb !=BranchProbability::getZero() &&
12518 DefaultMBB ==FuncInfo.getMBB(SI.getDefaultDest()))
12519 DefaultProb =scaleCaseProbality(DefaultProb, PeeledCaseProb);
12520 WorkList.push_back(
12521 {PeeledSwitchMBB,First,Last,nullptr,nullptr, DefaultProb});
12522
12523while (!WorkList.empty()) {
12524SwitchWorkListItemW = WorkList.pop_back_val();
12525unsigned NumClusters =W.LastCluster -W.FirstCluster + 1;
12526
12527if (NumClusters > 3 && TM.getOptLevel() !=CodeGenOptLevel::None &&
12528 !DefaultMBB->getParent()->getFunction().hasMinSize()) {
12529// For optimized builds, lower large range as a balanced binary tree.
12530 splitWorkItem(WorkList, W,SI.getCondition(), SwitchMBB);
12531continue;
12532 }
12533
12534 lowerWorkItem(W,SI.getCondition(), SwitchMBB, DefaultMBB);
12535 }
12536}
12537
12538void SelectionDAGBuilder::visitStepVector(constCallInst &I) {
12539constTargetLowering &TLI =DAG.getTargetLoweringInfo();
12540autoDL =getCurSDLoc();
12541EVT ResultVT = TLI.getValueType(DAG.getDataLayout(),I.getType());
12542setValue(&I,DAG.getStepVector(DL, ResultVT));
12543}
12544
12545void SelectionDAGBuilder::visitVectorReverse(constCallInst &I) {
12546constTargetLowering &TLI =DAG.getTargetLoweringInfo();
12547EVT VT = TLI.getValueType(DAG.getDataLayout(),I.getType());
12548
12549SDLocDL =getCurSDLoc();
12550SDValueV =getValue(I.getOperand(0));
12551assert(VT ==V.getValueType() &&"Malformed vector.reverse!");
12552
12553if (VT.isScalableVector()) {
12554setValue(&I,DAG.getNode(ISD::VECTOR_REVERSE,DL, VT, V));
12555return;
12556 }
12557
12558// Use VECTOR_SHUFFLE for the fixed-length vector
12559// to maintain existing behavior.
12560SmallVector<int, 8>Mask;
12561unsigned NumElts = VT.getVectorMinNumElements();
12562for (unsigned i = 0; i != NumElts; ++i)
12563Mask.push_back(NumElts - 1 - i);
12564
12565setValue(&I,DAG.getVectorShuffle(VT,DL, V,DAG.getUNDEF(VT), Mask));
12566}
12567
12568void SelectionDAGBuilder::visitVectorDeinterleave(constCallInst &I) {
12569autoDL =getCurSDLoc();
12570SDValue InVec =getValue(I.getOperand(0));
12571EVT OutVT =
12572 InVec.getValueType().getHalfNumVectorElementsVT(*DAG.getContext());
12573
12574unsigned OutNumElts = OutVT.getVectorMinNumElements();
12575
12576// ISD Node needs the input vectors split into two equal parts
12577SDValueLo =DAG.getNode(ISD::EXTRACT_SUBVECTOR,DL, OutVT, InVec,
12578DAG.getVectorIdxConstant(0,DL));
12579SDValueHi =DAG.getNode(ISD::EXTRACT_SUBVECTOR,DL, OutVT, InVec,
12580DAG.getVectorIdxConstant(OutNumElts,DL));
12581
12582// Use VECTOR_SHUFFLE for fixed-length vectors to benefit from existing
12583// legalisation and combines.
12584if (OutVT.isFixedLengthVector()) {
12585SDValue Even =DAG.getVectorShuffle(OutVT,DL,Lo,Hi,
12586createStrideMask(0, 2, OutNumElts));
12587SDValue Odd =DAG.getVectorShuffle(OutVT,DL,Lo,Hi,
12588createStrideMask(1, 2, OutNumElts));
12589SDValue Res =DAG.getMergeValues({Even, Odd},getCurSDLoc());
12590setValue(&I, Res);
12591return;
12592 }
12593
12594SDValue Res =DAG.getNode(ISD::VECTOR_DEINTERLEAVE,DL,
12595DAG.getVTList(OutVT, OutVT),Lo,Hi);
12596setValue(&I, Res);
12597}
12598
12599void SelectionDAGBuilder::visitVectorInterleave(constCallInst &I) {
12600autoDL =getCurSDLoc();
12601EVT InVT =getValue(I.getOperand(0)).getValueType();
12602SDValue InVec0 =getValue(I.getOperand(0));
12603SDValue InVec1 =getValue(I.getOperand(1));
12604constTargetLowering &TLI =DAG.getTargetLoweringInfo();
12605EVT OutVT = TLI.getValueType(DAG.getDataLayout(),I.getType());
12606
12607// Use VECTOR_SHUFFLE for fixed-length vectors to benefit from existing
12608// legalisation and combines.
12609if (OutVT.isFixedLengthVector()) {
12610unsigned NumElts = InVT.getVectorMinNumElements();
12611SDValueV =DAG.getNode(ISD::CONCAT_VECTORS,DL, OutVT, InVec0, InVec1);
12612setValue(&I,DAG.getVectorShuffle(OutVT,DL, V,DAG.getUNDEF(OutVT),
12613createInterleaveMask(NumElts, 2)));
12614return;
12615 }
12616
12617SDValue Res =DAG.getNode(ISD::VECTOR_INTERLEAVE,DL,
12618DAG.getVTList(InVT, InVT), InVec0, InVec1);
12619 Res =DAG.getNode(ISD::CONCAT_VECTORS,DL, OutVT, Res.getValue(0),
12620 Res.getValue(1));
12621setValue(&I, Res);
12622}
12623
12624void SelectionDAGBuilder::visitFreeze(constFreezeInst &I) {
12625SmallVector<EVT, 4> ValueVTs;
12626ComputeValueVTs(DAG.getTargetLoweringInfo(),DAG.getDataLayout(),I.getType(),
12627 ValueVTs);
12628unsigned NumValues = ValueVTs.size();
12629if (NumValues == 0)return;
12630
12631SmallVector<SDValue, 4> Values(NumValues);
12632SDValueOp =getValue(I.getOperand(0));
12633
12634for (unsigned i = 0; i != NumValues; ++i)
12635 Values[i] =DAG.getNode(ISD::FREEZE,getCurSDLoc(), ValueVTs[i],
12636SDValue(Op.getNode(),Op.getResNo() + i));
12637
12638setValue(&I,DAG.getNode(ISD::MERGE_VALUES,getCurSDLoc(),
12639DAG.getVTList(ValueVTs), Values));
12640}
12641
12642void SelectionDAGBuilder::visitVectorSplice(constCallInst &I) {
12643constTargetLowering &TLI =DAG.getTargetLoweringInfo();
12644EVT VT = TLI.getValueType(DAG.getDataLayout(),I.getType());
12645
12646SDLocDL =getCurSDLoc();
12647SDValue V1 =getValue(I.getOperand(0));
12648SDValueV2 =getValue(I.getOperand(1));
12649 int64_tImm = cast<ConstantInt>(I.getOperand(2))->getSExtValue();
12650
12651// VECTOR_SHUFFLE doesn't support a scalable mask so use a dedicated node.
12652if (VT.isScalableVector()) {
12653setValue(
12654 &I,DAG.getNode(ISD::VECTOR_SPLICE,DL, VT, V1, V2,
12655DAG.getSignedConstant(
12656 Imm,DL, TLI.getVectorIdxTy(DAG.getDataLayout()))));
12657return;
12658 }
12659
12660unsigned NumElts = VT.getVectorNumElements();
12661
12662uint64_tIdx = (NumElts +Imm) % NumElts;
12663
12664// Use VECTOR_SHUFFLE to maintain original behaviour for fixed-length vectors.
12665SmallVector<int, 8>Mask;
12666for (unsigned i = 0; i < NumElts; ++i)
12667Mask.push_back(Idx + i);
12668setValue(&I,DAG.getVectorShuffle(VT,DL, V1, V2, Mask));
12669}
12670
12671// Consider the following MIR after SelectionDAG, which produces output in
12672// phyregs in the first case or virtregs in the second case.
12673//
12674// INLINEASM_BR ..., implicit-def $ebx, ..., implicit-def $edx
12675// %5:gr32 = COPY $ebx
12676// %6:gr32 = COPY $edx
12677// %1:gr32 = COPY %6:gr32
12678// %0:gr32 = COPY %5:gr32
12679//
12680// INLINEASM_BR ..., def %5:gr32, ..., def %6:gr32
12681// %1:gr32 = COPY %6:gr32
12682// %0:gr32 = COPY %5:gr32
12683//
12684// Given %0, we'd like to return $ebx in the first case and %5 in the second.
12685// Given %1, we'd like to return $edx in the first case and %6 in the second.
12686//
12687// If a callbr has outputs, it will have a single mapping in FuncInfo.ValueMap
12688// to a single virtreg (such as %0). The remaining outputs monotonically
12689// increase in virtreg number from there. If a callbr has no outputs, then it
12690// should not have a corresponding callbr landingpad; in fact, the callbr
12691// landingpad would not even be able to refer to such a callbr.
12692staticRegisterFollowCopyChain(MachineRegisterInfo &MRI,Register Reg) {
12693MachineInstr *MI =MRI.def_begin(Reg)->getParent();
12694// There is definitely at least one copy.
12695assert(MI->getOpcode() == TargetOpcode::COPY &&
12696"start of copy chain MUST be COPY");
12697 Reg =MI->getOperand(1).getReg();
12698MI =MRI.def_begin(Reg)->getParent();
12699// There may be an optional second copy.
12700if (MI->getOpcode() == TargetOpcode::COPY) {
12701assert(Reg.isVirtual() &&"expected COPY of virtual register");
12702 Reg =MI->getOperand(1).getReg();
12703assert(Reg.isPhysical() &&"expected COPY of physical register");
12704MI =MRI.def_begin(Reg)->getParent();
12705 }
12706// The start of the chain must be an INLINEASM_BR.
12707assert(MI->getOpcode() == TargetOpcode::INLINEASM_BR &&
12708"end of copy chain MUST be INLINEASM_BR");
12709return Reg;
12710}
12711
12712// We must do this walk rather than the simpler
12713// setValue(&I, getCopyFromRegs(CBR, CBR->getType()));
12714// otherwise we will end up with copies of virtregs only valid along direct
12715// edges.
12716void SelectionDAGBuilder::visitCallBrLandingPad(constCallInst &I) {
12717SmallVector<EVT, 8> ResultVTs;
12718SmallVector<SDValue, 8> ResultValues;
12719constauto *CBR =
12720 cast<CallBrInst>(I.getParent()->getUniquePredecessor()->getTerminator());
12721
12722constTargetLowering &TLI =DAG.getTargetLoweringInfo();
12723constTargetRegisterInfo *TRI =DAG.getSubtarget().getRegisterInfo();
12724MachineRegisterInfo &MRI =DAG.getMachineFunction().getRegInfo();
12725
12726unsigned InitialDef =FuncInfo.ValueMap[CBR];
12727SDValue Chain =DAG.getRoot();
12728
12729// Re-parse the asm constraints string.
12730TargetLowering::AsmOperandInfoVector TargetConstraints =
12731 TLI.ParseConstraints(DAG.getDataLayout(),TRI, *CBR);
12732for (auto &T : TargetConstraints) {
12733 SDISelAsmOperandInfo OpInfo(T);
12734if (OpInfo.Type !=InlineAsm::isOutput)
12735continue;
12736
12737// Pencil in OpInfo.ConstraintType and OpInfo.ConstraintVT based on the
12738// individual constraint.
12739 TLI.ComputeConstraintToUse(OpInfo, OpInfo.CallOperand, &DAG);
12740
12741switch (OpInfo.ConstraintType) {
12742caseTargetLowering::C_Register:
12743caseTargetLowering::C_RegisterClass: {
12744// Fill in OpInfo.AssignedRegs.Regs.
12745getRegistersForValue(DAG,getCurSDLoc(), OpInfo, OpInfo);
12746
12747// getRegistersForValue may produce 1 to many registers based on whether
12748// the OpInfo.ConstraintVT is legal on the target or not.
12749for (Register &Reg : OpInfo.AssignedRegs.Regs) {
12750Register OriginalDef =FollowCopyChain(MRI, InitialDef++);
12751if (OriginalDef.isPhysical())
12752FuncInfo.MBB->addLiveIn(OriginalDef);
12753// Update the assigned registers to use the original defs.
12754Reg = OriginalDef;
12755 }
12756
12757SDValueV = OpInfo.AssignedRegs.getCopyFromRegs(
12758DAG,FuncInfo,getCurSDLoc(), Chain,nullptr, CBR);
12759 ResultValues.push_back(V);
12760 ResultVTs.push_back(OpInfo.ConstraintVT);
12761break;
12762 }
12763caseTargetLowering::C_Other: {
12764SDValueFlag;
12765SDValueV = TLI.LowerAsmOutputForConstraint(Chain, Flag,getCurSDLoc(),
12766 OpInfo,DAG);
12767 ++InitialDef;
12768 ResultValues.push_back(V);
12769 ResultVTs.push_back(OpInfo.ConstraintVT);
12770break;
12771 }
12772default:
12773break;
12774 }
12775 }
12776SDValueV =DAG.getNode(ISD::MERGE_VALUES,getCurSDLoc(),
12777DAG.getVTList(ResultVTs), ResultValues);
12778setValue(&I, V);
12779}
MRI
unsigned const MachineRegisterInfo * MRI
Definition:AArch64AdvSIMDScalarPass.cpp:105
Poison
@ Poison
Definition:AArch64AsmPrinter.cpp:72
SelectTypeKind::FP
@ FP
getIntrinsicID
static unsigned getIntrinsicID(const SDNode *N)
Definition:AArch64ISelLowering.cpp:7713
RegSize
unsigned RegSize
Definition:AArch64MIPeepholeOpt.cpp:161
getNode
static msgpack::DocNode getNode(msgpack::DocNode DN, msgpack::Type Type, MCValue Val)
Definition:AMDGPUDelayedMCExpr.cpp:15
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...
MBB
MachineBasicBlock & MBB
Definition:ARMSLSHardening.cpp:71
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition:ARMSLSHardening.cpp:73
MBBI
MachineBasicBlock MachineBasicBlock::iterator MBBI
Definition:ARMSLSHardening.cpp:72
aa
aa
Definition:AliasAnalysis.cpp:730
Results
Function Alias Analysis Results
Definition:AliasAnalysis.cpp:731
AliasAnalysis.h
AssignmentTrackingAnalysis.h
AtomicOrdering.h
Atomic ordering constants.
Attributes.h
This file contains the simple types necessary to represent the attributes associated with functions a...
getParent
static const Function * getParent(const Value *V)
Definition:BasicAliasAnalysis.cpp:863
BitVector.h
This file implements the BitVector class.
From
BlockVerifier::State From
Definition:BlockVerifier.cpp:57
BranchProbabilityInfo.h
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
A
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
Info
Analysis containing CSE Info
Definition:CSEInfo.cpp:27
CallingConv.h
Casting.h
CodeGenCommonISel.h
CommandLine.h
Compiler.h
ConstantFolding.h
ConstantRange.h
Constants.h
This file contains the declarations for the subclasses of Constant, which represent the different fla...
DataLayout.h
RetTy
return RetTy
Definition:DeadArgumentElimination.cpp:361
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
DebugInfoMetadata.h
Debug.h
LLVM_DEBUG
#define LLVM_DEBUG(...)
Definition:Debug.h:106
DerivedTypes.h
DiagnosticInfo.h
EHPersonalities.h
Size
uint64_t Size
Definition:ELFObjHandler.cpp:81
End
bool End
Definition:ELF_riscv.cpp:480
X
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
getReturnAttrs
static AttributeList getReturnAttrs(FastISel::CallLoweringInfo &CLI)
Returns an AttributeList representing the attributes applied to the return value of the given call.
Definition:FastISel.cpp:943
FunctionLoweringInfo.h
GCMetadata.h
Check
#define Check(C,...)
Definition:GenericConvergenceVerifierImpl.h:34
GetElementPtrTypeIterator.h
GEP
Hexagon Common GEP
Definition:HexagonCommonGEP.cpp:170
TII
const HexagonInstrInfo * TII
Definition:HexagonCopyToCombine.cpp:125
MI
IRTranslator LLVM IR MI
Definition:IRTranslator.cpp:112
Argument.h
BasicBlock.h
CFG.h
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
Constant.h
Function.h
IntrinsicInst.h
Module.h
Module.h This file contains the declarations for the Module class.
Operator.h
Type.h
User.h
Value.h
ISDOpcodes.h
getRegistersForValue
static void getRegistersForValue(MachineFunction &MF, MachineIRBuilder &MIRBuilder, GISelAsmOperandInfo &OpInfo, GISelAsmOperandInfo &RefOpInfo)
Assign virtual/physical registers for the specified register operand.
Definition:InlineAsmLowering.cpp:80
InlineAsm.h
InlinePriorityMode::ML
@ ML
InstrTypes.h
InstructionCost.h
This file defines an InstructionCost class that is used when calculating the cost of an instruction,...
getRange
static std::optional< ConstantRange > getRange(Value *V, const InstrInfoQuery &IIQ)
Helper method to get range from metadata or attribute.
Definition:InstructionSimplify.cpp:3725
Instructions.h
Intrinsics.h
LLVMContext.h
RegName
#define RegName(no)
info
lazy value info
Definition:LazyValueInfo.cpp:61
Loads.h
MCContext.h
F
#define F(x, y, z)
Definition:MD5.cpp:55
I
#define I(x, y, z)
Definition:MD5.cpp:58
MachineBasicBlock.h
MachineFrameInfo.h
MachineFunction.h
MachineInstrBuilder.h
MachineInstrBundleIterator.h
MachineMemOperand.h
MachineModuleInfo.h
MachineOperand.h
MachineRegisterInfo.h
isUndef
static bool isUndef(const MachineInstr &MI)
Definition:MachineSSAContext.cpp:57
TRI
unsigned const TargetRegisterInfo * TRI
Definition:MachineSink.cpp:2029
MathExtras.h
getCalledFunction
static const Function * getCalledFunction(const Value *V)
Definition:MemoryBuiltins.cpp:159
MemoryLocation.h
This file provides utility analysis objects describing memory locations.
MemoryModelRelaxationAnnotations.h
This file provides utility for Memory Model Relaxation Annotations (MMRAs).
Metadata.h
This file contains the declarations for metadata subclasses.
T1
#define T1
Definition:Mips16ISelLowering.cpp:340
getReg
static unsigned getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
Definition:MipsDisassembler.cpp:520
getAddressSpace
static unsigned getAddressSpace(const Value *V, unsigned MaxLookup)
Definition:NVPTXAliasAnalysis.cpp:55
Signed
@ Signed
Definition:NVPTXISelLowering.cpp:4789
Range
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
High
uint64_t High
Definition:NVVMIntrRange.cpp:51
II
uint64_t IntrinsicInst * II
Definition:NVVMIntrRange.cpp:51
Y
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
P
#define P(N)
PatternMatch.h
TBB
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
Definition:RISCVRedundantCopyElimination.cpp:76
Cond
const SmallVectorImpl< MachineOperand > & Cond
Definition:RISCVRedundantCopyElimination.cpp:75
CC
auto CC
Definition:RISCVRedundantCopyElimination.cpp:79
SDNodeDbgValue.h
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.
hasOnlySelectUsers
static bool hasOnlySelectUsers(const Value *Cond)
Definition:SelectionDAGBuilder.cpp:3690
getLoadStackGuard
static SDValue getLoadStackGuard(SelectionDAG &DAG, const SDLoc &DL, SDValue &Chain)
Create a LOAD_STACK_GUARD node, and let it carry the target specific global variable if there exists ...
Definition:SelectionDAGBuilder.cpp:3060
addStackMapLiveVars
static void addStackMapLiveVars(const CallBase &Call, unsigned StartIdx, const SDLoc &DL, SmallVectorImpl< SDValue > &Ops, SelectionDAGBuilder &Builder)
Add a stack map intrinsic call's live variable operands to a stackmap or patchpoint target node's ope...
Definition:SelectionDAGBuilder.cpp:10631
MaxParallelChains
static const unsigned MaxParallelChains
Definition:SelectionDAGBuilder.cpp:152
expandPow
static SDValue expandPow(const SDLoc &dl, SDValue LHS, SDValue RHS, SelectionDAG &DAG, const TargetLowering &TLI, SDNodeFlags Flags)
visitPow - Lower a pow intrinsic.
Definition:SelectionDAGBuilder.cpp:5842
getUniformBase
static bool getUniformBase(const Value *Ptr, SDValue &Base, SDValue &Index, ISD::MemIndexType &IndexType, SDValue &Scale, SelectionDAGBuilder *SDB, const BasicBlock *CurBB, uint64_t ElemSize)
Definition:SelectionDAGBuilder.cpp:4860
FindPreallocatedCall
static const CallBase * FindPreallocatedCall(const Value *PreallocatedSetup)
Given a @llvm.call.preallocated.setup, return the corresponding preallocated call.
Definition:SelectionDAGBuilder.cpp:6297
SwitchPeelThreshold
static cl::opt< unsigned > SwitchPeelThreshold("switch-peel-threshold", cl::Hidden, cl::init(66), cl::desc("Set the case probability threshold for peeling the case from a " "switch statement. A value greater than 100 will void this " "optimization"))
InsertAssertAlign
static cl::opt< bool > InsertAssertAlign("insert-assert-align", cl::init(true), cl::desc("Insert the experimental `assertalign` node."), cl::ReallyHidden)
getISDForVPIntrinsic
static unsigned getISDForVPIntrinsic(const VPIntrinsic &VPIntrin)
Definition:SelectionDAGBuilder.cpp:8385
handleDanglingVariadicDebugInfo
static bool handleDanglingVariadicDebugInfo(SelectionDAG &DAG, DILocalVariable *Variable, DebugLoc DL, unsigned Order, SmallVectorImpl< Value * > &Values, DIExpression *Expression)
Definition:SelectionDAGBuilder.cpp:1384
findMatchingInlineAsmOperand
static unsigned findMatchingInlineAsmOperand(unsigned OperandNo, const std::vector< SDValue > &AsmNodeOperands)
Definition:SelectionDAGBuilder.cpp:9869
patchMatchingInput
static void patchMatchingInput(const SDISelAsmOperandInfo &OpInfo, SDISelAsmOperandInfo &MatchingOpInfo, SelectionDAG &DAG)
Make sure that the output operand OpInfo and its corresponding input operand MatchingOpInfo have comp...
Definition:SelectionDAGBuilder.cpp:9676
findUnwindDestinations
static void findUnwindDestinations(FunctionLoweringInfo &FuncInfo, const BasicBlock *EHPadBB, BranchProbability Prob, SmallVectorImpl< std::pair< MachineBasicBlock *, BranchProbability > > &UnwindDests)
When an invoke or a cleanupret unwinds to the next EH pad, there are many places it could ultimately ...
Definition:SelectionDAGBuilder.cpp:2094
FixedPointIntrinsicToOpcode
static unsigned FixedPointIntrinsicToOpcode(unsigned Intrinsic)
Definition:SelectionDAGBuilder.cpp:6263
scaleCaseProbality
static BranchProbability scaleCaseProbality(BranchProbability CaseProb, BranchProbability PeeledCaseProb)
Definition:SelectionDAGBuilder.cpp:12381
expandExp2
static SDValue expandExp2(const SDLoc &dl, SDValue Op, SelectionDAG &DAG, const TargetLowering &TLI, SDNodeFlags Flags)
expandExp2 - Lower an exp2 intrinsic.
Definition:SelectionDAGBuilder.cpp:5830
expandDivFix
static SDValue expandDivFix(unsigned Opcode, const SDLoc &DL, SDValue LHS, SDValue RHS, SDValue Scale, SelectionDAG &DAG, const TargetLowering &TLI)
Definition:SelectionDAGBuilder.cpp:5922
getF32Constant
static SDValue getF32Constant(SelectionDAG &DAG, unsigned Flt, const SDLoc &dl)
getF32Constant - Get 32-bit floating point constant.
Definition:SelectionDAGBuilder.cpp:5423
widenVectorToPartType
static SDValue widenVectorToPartType(SelectionDAG &DAG, SDValue Val, const SDLoc &DL, EVT PartVT)
Definition:SelectionDAGBuilder.cpp:641
expandLog10
static SDValue expandLog10(const SDLoc &dl, SDValue Op, SelectionDAG &DAG, const TargetLowering &TLI, SDNodeFlags Flags)
expandLog10 - Lower a log10 intrinsic.
Definition:SelectionDAGBuilder.cpp:5740
getCopyToPartsVector
static void getCopyToPartsVector(SelectionDAG &DAG, const SDLoc &dl, SDValue Val, SDValue *Parts, unsigned NumParts, MVT PartVT, const Value *V, std::optional< CallingConv::ID > CallConv)
getCopyToPartsVector - Create a series of nodes that contain the specified value split into legal par...
Definition:SelectionDAGBuilder.cpp:688
getUnderlyingArgRegs
static void getUnderlyingArgRegs(SmallVectorImpl< std::pair< Register, TypeSize > > &Regs, const SDValue &N)
Definition:SelectionDAGBuilder.cpp:5985
getCopyToParts
static void getCopyToParts(SelectionDAG &DAG, const SDLoc &DL, SDValue Val, SDValue *Parts, unsigned NumParts, MVT PartVT, const Value *V, std::optional< CallingConv::ID > CallConv=std::nullopt, ISD::NodeType ExtendKind=ISD::ANY_EXTEND)
getCopyToParts - Create a series of nodes that contain the specified value split into legal parts.
Definition:SelectionDAGBuilder.cpp:505
getMemCmpLoad
static SDValue getMemCmpLoad(const Value *PtrVal, MVT LoadVT, SelectionDAGBuilder &Builder)
Definition:SelectionDAGBuilder.cpp:8998
expandLog2
static SDValue expandLog2(const SDLoc &dl, SDValue Op, SelectionDAG &DAG, const TargetLowering &TLI, SDNodeFlags Flags)
expandLog2 - Lower a log2 intrinsic.
Definition:SelectionDAGBuilder.cpp:5643
getAddressForMemoryInput
static SDValue getAddressForMemoryInput(SDValue Chain, const SDLoc &Location, SDISelAsmOperandInfo &OpInfo, SelectionDAG &DAG)
Get a direct memory input to behave well as an indirect operand.
Definition:SelectionDAGBuilder.cpp:9707
isOnlyUsedInEntryBlock
static bool isOnlyUsedInEntryBlock(const Argument *A, bool FastISel)
isOnlyUsedInEntryBlock - If the specified argument is only used in the entry block,...
Definition:SelectionDAGBuilder.cpp:11407
diagnosePossiblyInvalidConstraint
static void diagnosePossiblyInvalidConstraint(LLVMContext &Ctx, const Value *V, const Twine &ErrMsg)
Definition:SelectionDAGBuilder.cpp:319
collectInstructionDeps
static bool collectInstructionDeps(SmallMapVector< const Instruction *, bool, 8 > *Deps, const Value *V, SmallMapVector< const Instruction *, bool, 8 > *Necessary=nullptr, unsigned Depth=0)
Definition:SelectionDAGBuilder.cpp:2482
findArgumentCopyElisionCandidates
static void findArgumentCopyElisionCandidates(const DataLayout &DL, FunctionLoweringInfo *FuncInfo, ArgCopyElisionMapTy &ArgCopyElisionCandidates)
Scan the entry block of the function in FuncInfo for arguments that look like copies into a local all...
Definition:SelectionDAGBuilder.cpp:11429
isFunction
static bool isFunction(SDValue Op)
Definition:SelectionDAGBuilder.cpp:9923
GetExponent
static SDValue GetExponent(SelectionDAG &DAG, SDValue Op, const TargetLowering &TLI, const SDLoc &dl)
GetExponent - Get the exponent:
Definition:SelectionDAGBuilder.cpp:5409
FollowCopyChain
static Register FollowCopyChain(MachineRegisterInfo &MRI, Register Reg)
Definition:SelectionDAGBuilder.cpp:12692
ExpandPowI
static SDValue ExpandPowI(const SDLoc &DL, SDValue LHS, SDValue RHS, SelectionDAG &DAG)
ExpandPowI - Expand a llvm.powi intrinsic.
Definition:SelectionDAGBuilder.cpp:5871
findWasmUnwindDestinations
static void findWasmUnwindDestinations(FunctionLoweringInfo &FuncInfo, const BasicBlock *EHPadBB, BranchProbability Prob, SmallVectorImpl< std::pair< MachineBasicBlock *, BranchProbability > > &UnwindDests)
Definition:SelectionDAGBuilder.cpp:2060
expandLog
static SDValue expandLog(const SDLoc &dl, SDValue Op, SelectionDAG &DAG, const TargetLowering &TLI, SDNodeFlags Flags)
expandLog - Lower a log intrinsic.
Definition:SelectionDAGBuilder.cpp:5544
getCopyFromParts
static SDValue getCopyFromParts(SelectionDAG &DAG, const SDLoc &DL, const SDValue *Parts, unsigned NumParts, MVT PartVT, EVT ValueVT, const Value *V, SDValue InChain, std::optional< CallingConv::ID > CC=std::nullopt, std::optional< ISD::NodeType > AssertOp=std::nullopt)
getCopyFromParts - Create a value that contains the specified legal parts combined into the value the...
Definition:SelectionDAGBuilder.cpp:166
getLimitedPrecisionExp2
static SDValue getLimitedPrecisionExp2(SDValue t0, const SDLoc &dl, SelectionDAG &DAG)
Definition:SelectionDAGBuilder.cpp:5429
GetSignificand
static SDValue GetSignificand(SelectionDAG &DAG, SDValue Op, const SDLoc &dl)
GetSignificand - Get the significand and build it into a floating-point number with exponent of 1:
Definition:SelectionDAGBuilder.cpp:5396
expandExp
static SDValue expandExp(const SDLoc &dl, SDValue Op, SelectionDAG &DAG, const TargetLowering &TLI, SDNodeFlags Flags)
expandExp - Lower an exp intrinsic.
Definition:SelectionDAGBuilder.cpp:5522
getRangeMetadata
static const MDNode * getRangeMetadata(const Instruction &I)
Definition:SelectionDAGBuilder.cpp:4521
LimitFPPrecision
static cl::opt< unsigned, true > LimitFPPrecision("limit-float-precision", cl::desc("Generate low-precision inline sequences " "for some float libcalls"), cl::location(LimitFloatPrecision), cl::Hidden, cl::init(0))
tryToElideArgumentCopy
static void tryToElideArgumentCopy(FunctionLoweringInfo &FuncInfo, SmallVectorImpl< SDValue > &Chains, DenseMap< int, int > &ArgCopyElisionFrameIndexMap, SmallPtrSetImpl< const Instruction * > &ElidedArgCopyInstrs, ArgCopyElisionMapTy &ArgCopyElisionCandidates, const Argument &Arg, ArrayRef< SDValue > ArgVals, bool &ArgHasUses)
Try to elide argument copies from memory into a local alloca.
Definition:SelectionDAGBuilder.cpp:11525
LimitFloatPrecision
static unsigned LimitFloatPrecision
LimitFloatPrecision - Generate low-precision inline sequences for some float libcalls (6,...
Definition:SelectionDAGBuilder.cpp:118
getCopyFromPartsVector
static SDValue getCopyFromPartsVector(SelectionDAG &DAG, const SDLoc &DL, const SDValue *Parts, unsigned NumParts, MVT PartVT, EVT ValueVT, const Value *V, SDValue InChain, std::optional< CallingConv::ID > CC)
getCopyFromPartsVector - Create a value that contains the specified legal parts combined into the val...
Definition:SelectionDAGBuilder.cpp:339
InBlock
static bool InBlock(const Value *V, const BasicBlock *BB)
Definition:SelectionDAGBuilder.cpp:2423
SelectionDAGBuilder.h
getSimpleVT
static LLVM_ATTRIBUTE_ALWAYS_INLINE MVT::SimpleValueType getSimpleVT(const unsigned char *MatcherTable, unsigned &MatcherIndex)
getSimpleVT - Decode a value in MatcherTable, if it's a VBR encoded value, use GetVBR to decode it.
Definition:SelectionDAGISel.cpp:2663
SelectionDAGISel.h
SelectionDAGTargetInfo.h
SelectionDAG.h
SmallPtrSet.h
This file defines the SmallPtrSet class.
SmallSet.h
This file defines the SmallSet class.
StackMaps.h
Statepoint.h
StringRef.h
SwiftErrorValueTracking.h
getType
static SymbolRef::Type getType(const Symbol *Sym)
Definition:TapiFile.cpp:39
TargetFrameLowering.h
TargetInstrInfo.h
TargetIntrinsicInfo.h
Flt
@ Flt
Definition:TargetLibraryInfo.cpp:73
Ptr
@ Ptr
Definition:TargetLibraryInfo.cpp:77
TargetLibraryInfo.h
TargetOpcodes.h
TargetOptions.h
TargetRegisterInfo.h
TargetSubtargetInfo.h
TargetTransformInfo.h
This pass exposes codegen information to IR-level passes.
Local.h
Triple.h
Twine.h
ValueTracking.h
VectorUtils.h
WinEHFuncInfo.h
RHS
Value * RHS
Definition:X86PartialReduction.cpp:74
LHS
Value * LHS
Definition:X86PartialReduction.cpp:73
Lo
support::ulittle16_t & Lo
Definition:aarch32.cpp:204
Hi
support::ulittle16_t & Hi
Definition:aarch32.cpp:203
NewExpr
Definition:ItaniumDemangle.h:2103
Node
Definition:ItaniumDemangle.h:163
T
llvm::APFloat
Definition:APFloat.h:904
llvm::APInt
Class for arbitrary precision integers.
Definition:APInt.h:78
llvm::APInt::sextOrTrunc
APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
Definition:APInt.cpp:1015
llvm::APInt::isNonNegative
bool isNonNegative() const
Determine if this APInt Value is non-negative (>= 0)
Definition:APInt.h:334
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::AllocaInst
an instruction to allocate memory on the stack
Definition:Instructions.h:63
llvm::AllocaInst::getAlign
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
Definition:Instructions.h:124
llvm::AllocaInst::getAllocatedType
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
Definition:Instructions.h:117
llvm::Argument
This class represents an incoming formal argument to a Function.
Definition:Argument.h:31
llvm::Argument::hasAttribute
bool hasAttribute(Attribute::AttrKind Kind) const
Check if an argument has a given attribute.
Definition:Function.cpp:349
llvm::Argument::getArgNo
unsigned getArgNo() const
Return the index of this formal argument in its containing function.
Definition:Argument.h:49
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::AssumptionCache
A cache of @llvm.assume calls within a function.
Definition:AssumptionCache.h:42
llvm::AtomicCmpXchgInst
An instruction that atomically checks whether a specified value is in a memory location,...
Definition:Instructions.h:501
llvm::AtomicMemCpyInst
This class represents the atomic memcpy intrinsic i.e.
Definition:IntrinsicInst.h:1182
llvm::AtomicRMWInst
an instruction that atomically reads a memory location, combines it with another value,...
Definition:Instructions.h:704
llvm::AtomicRMWInst::Add
@ Add
*p = old + v
Definition:Instructions.h:720
llvm::AtomicRMWInst::FAdd
@ FAdd
*p = old + v
Definition:Instructions.h:741
llvm::AtomicRMWInst::USubCond
@ USubCond
Subtract only if no unsigned overflow.
Definition:Instructions.h:764
llvm::AtomicRMWInst::Min
@ Min
*p = old <signed v ? old : v
Definition:Instructions.h:734
llvm::AtomicRMWInst::Or
@ Or
*p = old | v
Definition:Instructions.h:728
llvm::AtomicRMWInst::Sub
@ Sub
*p = old - v
Definition:Instructions.h:722
llvm::AtomicRMWInst::And
@ And
*p = old & v
Definition:Instructions.h:724
llvm::AtomicRMWInst::Xor
@ Xor
*p = old ^ v
Definition:Instructions.h:730
llvm::AtomicRMWInst::USubSat
@ USubSat
*p = usub.sat(old, v) usub.sat matches the behavior of llvm.usub.sat.
Definition:Instructions.h:768
llvm::AtomicRMWInst::FSub
@ FSub
*p = old - v
Definition:Instructions.h:744
llvm::AtomicRMWInst::UIncWrap
@ UIncWrap
Increment one up to a maximum value.
Definition:Instructions.h:756
llvm::AtomicRMWInst::Max
@ Max
*p = old >signed v ? old : v
Definition:Instructions.h:732
llvm::AtomicRMWInst::UMin
@ UMin
*p = old <unsigned v ? old : v
Definition:Instructions.h:738
llvm::AtomicRMWInst::FMin
@ FMin
*p = minnum(old, v) minnum matches the behavior of llvm.minnum.
Definition:Instructions.h:752
llvm::AtomicRMWInst::UMax
@ UMax
*p = old >unsigned v ? old : v
Definition:Instructions.h:736
llvm::AtomicRMWInst::FMax
@ FMax
*p = maxnum(old, v) maxnum matches the behavior of llvm.maxnum.
Definition:Instructions.h:748
llvm::AtomicRMWInst::UDecWrap
@ UDecWrap
Decrement one until a minimum value or zero.
Definition:Instructions.h:760
llvm::AtomicRMWInst::Xchg
@ Xchg
*p = v
Definition:Instructions.h:718
llvm::AtomicRMWInst::Nand
@ Nand
*p = ~(old & v)
Definition:Instructions.h:726
llvm::AttributeList
Definition:Attributes.h:490
llvm::AttributeList::get
static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute > > Attrs)
Create an AttributeList with the specified parameters in it.
Definition:Attributes.cpp:1499
llvm::AttributeList::getRetAttrs
AttributeSet getRetAttrs() const
The attributes for the ret value are returned.
Definition:Attributes.cpp:1856
llvm::AttributeList::hasFnAttr
bool hasFnAttr(Attribute::AttrKind Kind) const
Return true if the attribute exists for the function.
Definition:Attributes.cpp:1877
llvm::AttributeList::ReturnIndex
@ ReturnIndex
Definition:Attributes.h:493
llvm::AttributeSet
Definition:Attributes.h:345
llvm::BasicBlock
LLVM Basic Block Representation.
Definition:BasicBlock.h:61
llvm::BasicBlock::getFirstNonPHIIt
InstListType::const_iterator getFirstNonPHIIt() const
Returns an iterator to the first instruction in this block that is not a PHINode instruction.
Definition:BasicBlock.cpp:381
llvm::BasicBlock::const_iterator
InstListType::const_iterator const_iterator
Definition:BasicBlock.h:178
llvm::BasicBlock::isEntryBlock
bool isEntryBlock() const
Return true if this is the entry block of the containing function.
Definition:BasicBlock.cpp:593
llvm::BasicBlock::getFirstNonPHIOrDbg
InstListType::const_iterator getFirstNonPHIOrDbg(bool SkipPseudoOp=true) const
Returns a pointer to the first instruction in this block that is not a PHINode or a debug intrinsic,...
Definition:BasicBlock.cpp:398
llvm::BasicBlock::getParent
const Function * getParent() const
Return the enclosing method, or null if none.
Definition:BasicBlock.h:220
llvm::BasicBlock::getTerminator
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Definition:BasicBlock.h:240
llvm::BasicBlock::back
const Instruction & back() const
Definition:BasicBlock.h:486
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::BitCastInst
This class represents a no-op cast from one type to another.
Definition:Instructions.h:4894
llvm::BitVector::test
bool test(unsigned Idx) const
Definition:BitVector.h:461
llvm::BitVector::resize
void resize(unsigned N, bool t=false)
resize - Grow or shrink the bitvector.
Definition:BitVector.h:341
llvm::BitVector::set
BitVector & set()
Definition:BitVector.h:351
llvm::BitVector::size
size_type size() const
size - Returns the number of bits in this bitvector.
Definition:BitVector.h:159
llvm::BlockAddress
The address of a basic block.
Definition:Constants.h:893
llvm::BranchInst
Conditional or Unconditional Branch instruction.
Definition:Instructions.h:3016
llvm::BranchProbabilityInfo
Analysis providing branch probability information.
Definition:BranchProbabilityInfo.h:112
llvm::BranchProbabilityInfo::getEdgeProbability
BranchProbability getEdgeProbability(const BasicBlock *Src, unsigned IndexInSuccessors) const
Get an edge's probability, relative to other out-edges of the Src.
Definition:BranchProbabilityInfo.cpp:1094
llvm::BranchProbabilityInfo::isEdgeHot
bool isEdgeHot(const BasicBlock *Src, const BasicBlock *Dst) const
Test if an edge is hot relative to other out-edges of the Src.
Definition:BranchProbabilityInfo.cpp:1083
llvm::BranchProbability
Definition:BranchProbability.h:30
llvm::BranchProbability::getDenominator
static uint32_t getDenominator()
Definition:BranchProbability.h:66
llvm::BranchProbability::getOne
static BranchProbability getOne()
Definition:BranchProbability.h:50
llvm::BranchProbability::getUnknown
static BranchProbability getUnknown()
Definition:BranchProbability.h:51
llvm::BranchProbability::getNumerator
uint32_t getNumerator() const
Definition:BranchProbability.h:65
llvm::BranchProbability::isUnknown
bool isUnknown() const
Definition:BranchProbability.h:47
llvm::BranchProbability::scale
uint64_t scale(uint64_t Num) const
Scale a large integer.
Definition:BranchProbability.cpp:107
llvm::BranchProbability::getCompl
BranchProbability getCompl() const
Definition:BranchProbability.h:69
llvm::BranchProbability::getZero
static BranchProbability getZero()
Definition:BranchProbability.h:49
llvm::BranchProbability::normalizeProbabilities
static void normalizeProbabilities(ProbabilityIter Begin, ProbabilityIter End)
Definition:BranchProbability.h:205
llvm::CallBase
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition:InstrTypes.h:1112
llvm::CallBase::getOperandBundle
std::optional< OperandBundleUse > getOperandBundle(StringRef Name) const
Return an operand bundle by name, if present.
Definition:InstrTypes.h:2053
llvm::CallBase::getCallingConv
CallingConv::ID getCallingConv() const
Definition:InstrTypes.h:1399
llvm::CallBase::arg_begin
User::op_iterator arg_begin()
Return the iterator pointing to the beginning of the argument list.
Definition:InstrTypes.h:1261
llvm::CallBase::isMustTailCall
bool isMustTailCall() const
Tests if this call site must be tail call optimized.
Definition:Instructions.cpp:343
llvm::CallBase::isIndirectCall
bool isIndirectCall() const
Return true if the callsite is an indirect call.
Definition:Instructions.cpp:334
llvm::CallBase::countOperandBundlesOfType
unsigned countOperandBundlesOfType(StringRef Name) const
Return the number of operand bundles with the tag Name attached to this instruction.
Definition:InstrTypes.h:2029
llvm::CallBase::getCalledOperand
Value * getCalledOperand() const
Definition:InstrTypes.h:1334
llvm::CallBase::getArgOperand
Value * getArgOperand(unsigned i) const
Definition:InstrTypes.h:1286
llvm::CallBase::arg_end
User::op_iterator arg_end()
Return the iterator pointing to the end of the argument list.
Definition:InstrTypes.h:1267
llvm::CallBase::isConvergent
bool isConvergent() const
Determine if the invoke is convergent.
Definition:InstrTypes.h:1937
llvm::CallBase::getFunctionType
FunctionType * getFunctionType() const
Definition:InstrTypes.h:1199
llvm::CallBase::arg_size
unsigned arg_size() const
Definition:InstrTypes.h:1284
llvm::CallBase::getAttributes
AttributeList getAttributes() const
Return the attributes for this call.
Definition:InstrTypes.h:1417
llvm::CallBase::isTailCall
bool isTailCall() const
Tests if this call site is marked as a tail call.
Definition:Instructions.cpp:350
llvm::CallBrInst
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
Definition:Instructions.h:3830
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition:Instructions.h:1479
llvm::CatchPadInst
Definition:Instructions.h:4250
llvm::CatchReturnInst
Definition:Instructions.h:4289
llvm::CatchSwitchInst
Definition:Instructions.h:4056
llvm::CleanupPadInst
Definition:Instructions.h:4221
llvm::CleanupReturnInst
Definition:Instructions.h:4364
llvm::CmpInst
This class is the base class for the comparison instructions.
Definition:InstrTypes.h:661
llvm::CmpInst::Predicate
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition:InstrTypes.h:673
llvm::ConstantDataSequential
ConstantDataSequential - A vector or array constant whose element type is a simple 1/2/4/8-byte integ...
Definition:Constants.h:587
llvm::ConstantExpr
A constant value that is initialized with an expression using other constant values.
Definition:Constants.h:1108
llvm::ConstantFPSDNode
Definition:SelectionDAGNodes.h:1739
llvm::ConstantFP
ConstantFP - Floating Point Values [float, double].
Definition:Constants.h:271
llvm::ConstantInt
This is the shared class of boolean and integer constants.
Definition:Constants.h:83
llvm::ConstantInt::getTrue
static ConstantInt * getTrue(LLVMContext &Context)
Definition:Constants.cpp:866
llvm::ConstantInt::isZero
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
Definition:Constants.h:208
llvm::ConstantInt::getFalse
static ConstantInt * getFalse(LLVMContext &Context)
Definition:Constants.cpp:873
llvm::ConstantInt::getZExtValue
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
Definition:Constants.h:157
llvm::ConstantInt::getValue
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition:Constants.h:148
llvm::ConstantPtrAuth
A signed pointer, in the ptrauth sense.
Definition:Constants.h:1021
llvm::ConstantRange
This class represents a range of values.
Definition:ConstantRange.h:47
llvm::ConstantSDNode
Definition:SelectionDAGNodes.h:1684
llvm::ConstantSDNode::getZExtValue
uint64_t getZExtValue() const
Definition:SelectionDAGNodes.h:1701
llvm::ConstantVector
Constant Vector Declarations.
Definition:Constants.h:511
llvm::Constant
This is an important base class in LLVM.
Definition:Constant.h:42
llvm::ConstrainedFPIntrinsic
This is the common base class for constrained floating point intrinsics.
Definition:IntrinsicInst.h:723
llvm::ConstrainedFPIntrinsic::getExceptionBehavior
std::optional< fp::ExceptionBehavior > getExceptionBehavior() const
Definition:IntrinsicInst.cpp:288
llvm::ConstrainedFPIntrinsic::getNonMetadataArgCount
unsigned getNonMetadataArgCount() const
Definition:IntrinsicInst.cpp:341
llvm::DIExpression
DWARF expression.
Definition:DebugInfoMetadata.h:2763
llvm::DIExpression::isEntryValue
bool isEntryValue() const
Check if the expression consists of exactly one entry value operand.
Definition:DebugInfoMetadata.cpp:1375
llvm::DIExpression::fragmentsOverlap
static bool fragmentsOverlap(const FragmentInfo &A, const FragmentInfo &B)
Check if fragments overlap between a pair of FragmentInfos.
Definition:DebugInfoMetadata.h:3172
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::DerefBefore
@ DerefBefore
Definition:DebugInfoMetadata.h:3045
llvm::DIExpression::getFragmentInfo
static std::optional< FragmentInfo > getFragmentInfo(expr_op_iterator Start, expr_op_iterator End)
Retrieve the details of this fragment expression.
Definition:DebugInfoMetadata.cpp:1677
llvm::DIExpression::getNumLocationOperands
uint64_t getNumLocationOperands() const
Return the number of unique location operands referred to (via DW_OP_LLVM_arg) in this expression; th...
Definition:DebugInfoMetadata.cpp:2206
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::DIExpression::convertToUndefExpression
static const DIExpression * convertToUndefExpression(const DIExpression *Expr)
Removes all elements from Expr that do not apply to an undef debug value, which includes every operat...
Definition:DebugInfoMetadata.cpp:1601
llvm::DIExpression::prepend
static DIExpression * prepend(const DIExpression *Expr, uint8_t Flags, int64_t Offset=0)
Prepend DIExpr with a deref and offset operation and optionally turn it into a stack value or/and an ...
Definition:DebugInfoMetadata.cpp:1842
llvm::DIExpression::prependOpcodes
static DIExpression * prependOpcodes(const DIExpression *Expr, SmallVectorImpl< uint64_t > &Ops, bool StackValue=false, bool EntryValue=false)
Prepend DIExpr with the given opcodes and optionally turn it into a stack value.
Definition:DebugInfoMetadata.cpp:1915
llvm::DILabel
Label.
Definition:DebugInfoMetadata.h:3551
llvm::DILocalVariable
Local variable.
Definition:DebugInfoMetadata.h:3460
llvm::DILocalVariable::isParameter
bool isParameter() const
Definition:DebugInfoMetadata.h:3522
llvm::DILocalVariable::isValidLocationForIntrinsic
bool isValidLocationForIntrinsic(const DILocation *DL) const
Check that a location is valid for this variable.
Definition:DebugInfoMetadata.h:3539
llvm::DILocation
Debug location.
Definition:DebugInfoMetadata.h:1988
llvm::DIVariable
Base class for variables.
Definition:DebugInfoMetadata.h:2698
llvm::DIVariable::getSizeInBits
std::optional< uint64_t > getSizeInBits() const
Determines the size of the variable's type.
Definition:DebugInfoMetadata.cpp:1331
llvm::DWARFExpression::Operation
This class represents an Operation in the Expression.
Definition:DWARFExpression.h:32
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition:DataLayout.h:63
llvm::DataLayout::getStructLayout
const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
Definition:DataLayout.cpp:709
llvm::DataLayout::isBigEndian
bool isBigEndian() const
Definition:DataLayout.h:198
llvm::DataLayout::getIndexSizeInBits
unsigned getIndexSizeInBits(unsigned AS) const
Size in bits of index used for address calculation in getelementptr.
Definition:DataLayout.h:369
llvm::DataLayout::getTypeStoreSize
TypeSize getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type.
Definition:DataLayout.h:421
llvm::DataLayout::getPrefTypeAlign
Align getPrefTypeAlign(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
Definition:DataLayout.cpp:847
llvm::DbgLabelInst
This represents the llvm.dbg.label instruction.
Definition:IntrinsicInst.h:543
llvm::DbgLabelInst::getLabel
DILabel * getLabel() const
Definition:IntrinsicInst.h:545
llvm::DbgLabelRecord
Records a position in IR for a source label (DILabel).
Definition:DebugProgramInstruction.h:231
llvm::DbgRecord
Base class for non-instruction debug metadata records that have positions within IR.
Definition:DebugProgramInstruction.h:134
llvm::DbgRecord::getDebugLoc
DebugLoc getDebugLoc() const
Definition:DebugProgramInstruction.h:208
llvm::DbgValueInst
This represents the llvm.dbg.value instruction.
Definition:IntrinsicInst.h:468
llvm::DbgValueInst::getValues
iterator_range< location_op_iterator > getValues() const
Definition:IntrinsicInst.h:475
llvm::DbgVariableIntrinsic::getVariable
DILocalVariable * getVariable() const
Definition:IntrinsicInst.h:371
llvm::DbgVariableIntrinsic::hasArgList
bool hasArgList() const
Definition:IntrinsicInst.h:338
llvm::DbgVariableIntrinsic::getExpression
DIExpression * getExpression() const
Definition:IntrinsicInst.h:375
llvm::DbgVariableIntrinsic::isKillLocation
bool isKillLocation() const
Definition:IntrinsicInst.h:367
llvm::DbgVariableRecord
Record of a variable value-assignment, aka a non instruction representation of the dbg....
Definition:DebugProgramInstruction.h:270
llvm::DbgVariableRecord::getType
LocationType getType() const
Definition:DebugProgramInstruction.h:443
llvm::DbgVariableRecord::getExpression
DIExpression * getExpression() const
Definition:DebugProgramInstruction.h:453
llvm::DbgVariableRecord::getVariableLocationOp
Value * getVariableLocationOp(unsigned OpIdx) const
Definition:DebugProgramInstruction.cpp:263
llvm::DbgVariableRecord::getVariable
DILocalVariable * getVariable() const
Definition:DebugProgramInstruction.h:449
llvm::DbgVariableRecord::LocationType::Declare
@ Declare
llvm::DbgVariableRecord::hasArgList
bool hasArgList() const
Definition:DebugProgramInstruction.h:430
llvm::DbgVariableRecord::location_ops
iterator_range< location_op_iterator > location_ops() const
Get the locations corresponding to the variable referenced by the debug info intrinsic.
Definition:DebugProgramInstruction.cpp:234
llvm::DebugLoc
A debug info location.
Definition:DebugLoc.h:33
llvm::DebugLoc::getInlinedAt
DILocation * getInlinedAt() const
Definition:DebugLoc.cpp:39
llvm::DenseMapBase::find
iterator find(const_arg_type_t< KeyT > Val)
Definition:DenseMap.h:156
llvm::DenseMapBase::size
unsigned size() const
Definition:DenseMap.h:99
llvm::DenseMapBase::empty
bool empty() const
Definition:DenseMap.h:98
llvm::DenseMapBase::count
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition:DenseMap.h:152
llvm::DenseMapBase::end
iterator end()
Definition:DenseMap.h:84
llvm::DenseMapBase::insert
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition:DenseMap.h:211
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::DiagnosticInfoInlineAsm
Diagnostic information for inline asm reporting.
Definition:DiagnosticInfo.h:169
llvm::ElementCount
Definition:TypeSize.h:300
llvm::ElementCount::getFixed
static constexpr ElementCount getFixed(ScalarTy MinVal)
Definition:TypeSize.h:311
llvm::ElementCount::get
static constexpr ElementCount get(ScalarTy MinVal, bool Scalable)
Definition:TypeSize.h:317
llvm::ElementCount::isScalar
constexpr bool isScalar() const
Exactly one element.
Definition:TypeSize.h:322
llvm::Expression
Class representing an expression and its matching format.
Definition:FileCheckImpl.h:189
llvm::ExtractValueInst
This instruction extracts a struct member or array element value from an aggregate value.
Definition:Instructions.h:2397
llvm::FCmpInst
This instruction compares its operands according to the predicate given to the constructor.
Definition:Instructions.h:1379
llvm::FastISel
This is a fast-path instruction selection class that generates poor code and doesn't support illegal ...
Definition:FastISel.h:66
llvm::FastMathFlags::allowReassoc
bool allowReassoc() const
Flag queries.
Definition:FMF.h:65
llvm::FenceInst
An instruction for ordering other memory operations.
Definition:Instructions.h:424
llvm::FixedVectorType::get
static FixedVectorType * get(Type *ElementType, unsigned NumElts)
Definition:Type.cpp:791
llvm::FrameIndexSDNode
Definition:SelectionDAGNodes.h:1904
llvm::FrameIndexSDNode::getIndex
int getIndex() const
Definition:SelectionDAGNodes.h:1915
llvm::FreezeInst
This class represents a freeze function that returns random concrete value if an operand is either a ...
Definition:Instructions.h:5088
llvm::FunctionLoweringInfo
FunctionLoweringInfo - This contains information that is global to a function that is used when lower...
Definition:FunctionLoweringInfo.h:57
llvm::FunctionLoweringInfo::BPI
BranchProbabilityInfo * BPI
Definition:FunctionLoweringInfo.h:63
llvm::FunctionLoweringInfo::CreateRegs
Register CreateRegs(const Value *V)
Definition:FunctionLoweringInfo.cpp:405
llvm::FunctionLoweringInfo::PreprocessedDVRDeclares
SmallPtrSet< const DbgVariableRecord *, 8 > PreprocessedDVRDeclares
Definition:FunctionLoweringInfo.h:197
llvm::FunctionLoweringInfo::getMBB
MachineBasicBlock * getMBB(const BasicBlock *BB) const
Definition:FunctionLoweringInfo.h:215
llvm::FunctionLoweringInfo::DemoteRegister
Register DemoteRegister
DemoteRegister - if CanLowerReturn is false, DemoteRegister is a vreg allocated to hold a pointer to ...
Definition:FunctionLoweringInfo.h:74
llvm::FunctionLoweringInfo::DescribedArgs
BitVector DescribedArgs
Bitvector with a bit set if corresponding argument is described in ArgDbgValues.
Definition:FunctionLoweringInfo.h:144
llvm::FunctionLoweringInfo::StaticAllocaMap
DenseMap< const AllocaInst *, int > StaticAllocaMap
StaticAllocaMap - Keep track of frame indices for fixed sized allocas in the entry block.
Definition:FunctionLoweringInfo.h:133
llvm::FunctionLoweringInfo::getArgumentFrameIndex
int getArgumentFrameIndex(const Argument *A)
getArgumentFrameIndex - Get frame index for the byval argument.
Definition:FunctionLoweringInfo.cpp:554
llvm::FunctionLoweringInfo::isExportedInst
bool isExportedInst(const Value *V) const
isExportedInst - Return true if the specified value is an instruction exported from its block.
Definition:FunctionLoweringInfo.h:211
llvm::FunctionLoweringInfo::GetLiveOutRegInfo
const LiveOutInfo * GetLiveOutRegInfo(Register Reg)
GetLiveOutRegInfo - Gets LiveOutInfo for a register, returning NULL if the register is a PHI destinat...
Definition:FunctionLoweringInfo.h:230
llvm::FunctionLoweringInfo::InitializeRegForValue
Register InitializeRegForValue(const Value *V)
Definition:FunctionLoweringInfo.cpp:410
llvm::FunctionLoweringInfo::ExceptionPointerVirtReg
unsigned ExceptionPointerVirtReg
If the current MBB is a landing pad, the exception pointer and exception selector registers are copie...
Definition:FunctionLoweringInfo.h:189
llvm::FunctionLoweringInfo::PreprocessedDbgDeclares
SmallPtrSet< const DbgDeclareInst *, 8 > PreprocessedDbgDeclares
Collection of dbg.declare instructions handled after argument lowering and before ISel proper.
Definition:FunctionLoweringInfo.h:196
llvm::FunctionLoweringInfo::ValueMap
DenseMap< const Value *, Register > ValueMap
ValueMap - Since we emit code for the function a basic block at a time, we must remember which virtua...
Definition:FunctionLoweringInfo.h:82
llvm::FunctionLoweringInfo::InsertPt
MachineBasicBlock::iterator InsertPt
MBB - The current insert position inside the current block.
Definition:FunctionLoweringInfo.h:161
llvm::FunctionLoweringInfo::MBB
MachineBasicBlock * MBB
MBB - The current block.
Definition:FunctionLoweringInfo.h:158
llvm::FunctionLoweringInfo::PHINodesToUpdate
std::vector< std::pair< MachineInstr *, unsigned > > PHINodesToUpdate
PHINodesToUpdate - A list of phi instructions whose operand list will be updated after processing the...
Definition:FunctionLoweringInfo.h:183
llvm::FunctionLoweringInfo::Fn
const Function * Fn
Definition:FunctionLoweringInfo.h:59
llvm::FunctionLoweringInfo::ExceptionSelectorVirtReg
unsigned ExceptionSelectorVirtReg
Definition:FunctionLoweringInfo.h:189
llvm::FunctionLoweringInfo::ArgDbgValues
SmallVector< MachineInstr *, 8 > ArgDbgValues
ArgDbgValues - A list of DBG_VALUE instructions created during isel for function arguments that are i...
Definition:FunctionLoweringInfo.h:140
llvm::FunctionLoweringInfo::getCurrentCallSite
unsigned getCurrentCallSite()
Get the call site currently being processed, if any. Return zero if none.
Definition:FunctionLoweringInfo.h:296
llvm::FunctionLoweringInfo::MF
MachineFunction * MF
Definition:FunctionLoweringInfo.h:60
llvm::FunctionLoweringInfo::setCurrentCallSite
void setCurrentCallSite(unsigned Site)
Set the call site currently being processed.
Definition:FunctionLoweringInfo.h:293
llvm::FunctionLoweringInfo::RegInfo
MachineRegisterInfo * RegInfo
Definition:FunctionLoweringInfo.h:62
llvm::FunctionLoweringInfo::CreateReg
Register CreateReg(MVT VT, bool isDivergent=false)
CreateReg - Allocate a single virtual register for the given type.
Definition:FunctionLoweringInfo.cpp:377
llvm::FunctionLoweringInfo::CanLowerReturn
bool CanLowerReturn
CanLowerReturn - true iff the function's return value can be lowered to registers.
Definition:FunctionLoweringInfo.h:67
llvm::FunctionLoweringInfo::PreferredExtendType
DenseMap< const Value *, ISD::NodeType > PreferredExtendType
Record the preferred extend type (ISD::SIGN_EXTEND or ISD::ZERO_EXTEND) for a value.
Definition:FunctionLoweringInfo.h:173
llvm::FunctionLoweringInfo::getCatchPadExceptionPointerVReg
Register getCatchPadExceptionPointerVReg(const Value *CPI, const TargetRegisterClass *RC)
Definition:FunctionLoweringInfo.cpp:562
llvm::FunctionType
Class to represent function types.
Definition:DerivedTypes.h:105
llvm::FunctionType::getNumParams
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
Definition:DerivedTypes.h:144
llvm::FunctionType::getParamType
Type * getParamType(unsigned i) const
Parameter type accessors.
Definition:DerivedTypes.h:137
llvm::FunctionType::getReturnType
Type * getReturnType() const
Definition:DerivedTypes.h:126
llvm::FunctionVarLocs
Data structure describing the variable locations in a function.
Definition:AssignmentTrackingAnalysis.h:38
llvm::Function
Definition:Function.h:63
llvm::Function::getEntryBlock
const BasicBlock & getEntryBlock() const
Definition:Function.h:809
llvm::Function::getIntrinsicID
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
Definition:Function.h:251
llvm::Function::hasMinSize
bool hasMinSize() const
Optimize this function for minimum size (-Oz).
Definition:Function.h:704
llvm::Function::hasGC
bool hasGC() const
hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm to use during code generatio...
Definition:Function.h:345
llvm::Function::getCallingConv
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition:Function.h:277
llvm::Function::getPersonalityFn
Constant * getPersonalityFn() const
Get the personality function associated with this function.
Definition:Function.cpp:1048
llvm::Function::getAttributes
AttributeList getAttributes() const
Return the attribute list for this Function.
Definition:Function.h:353
llvm::Function::isIntrinsic
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
Definition:Function.h:256
llvm::Function::arg_size
size_t arg_size() const
Definition:Function.h:901
llvm::Function::isVarArg
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
Definition:Function.h:234
llvm::Function::hasFnAttribute
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition:Function.cpp:731
llvm::GCFunctionInfo
Garbage collection metadata for a single function.
Definition:GCMetadata.h:78
llvm::GCFunctionInfo::addStackRoot
void addStackRoot(int Num, const Constant *Metadata)
addStackRoot - Registers a root that lives on the stack.
Definition:GCMetadata.h:118
llvm::GEPNoWrapFlags
Represents flags for the getelementptr instruction/expression.
Definition:GEPNoWrapFlags.h:26
llvm::GEPNoWrapFlags::hasNoUnsignedSignedWrap
bool hasNoUnsignedSignedWrap() const
Definition:GEPNoWrapFlags.h:64
llvm::GEPNoWrapFlags::hasNoUnsignedWrap
bool hasNoUnsignedWrap() const
Definition:GEPNoWrapFlags.h:65
llvm::GetElementPtrInst
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
Definition:Instructions.h:933
llvm::GlobalValue
Definition:GlobalValue.h:48
llvm::GlobalValue::dropLLVMManglingEscape
static StringRef dropLLVMManglingEscape(StringRef Name)
If the given string begins with the GlobalValue name mangling escape character '\1',...
Definition:GlobalValue.h:568
llvm::GlobalValue::hasDLLImportStorageClass
bool hasDLLImportStorageClass() const
Definition:GlobalValue.h:279
llvm::GlobalValue::getParent
Module * getParent()
Get the module that this global value is contained inside of...
Definition:GlobalValue.h:657
llvm::ICmpInst
This instruction compares its operands according to the predicate given to the constructor.
Definition:Instructions.h:1158
llvm::IndirectBrInst
Indirect Branch Instruction.
Definition:Instructions.h:3544
llvm::InlineAsm::Flag
Definition:InlineAsm.h:303
llvm::InlineAsm
Definition:InlineAsm.h:34
llvm::InlineAsm::Kind
Kind
Definition:InlineAsm.h:225
llvm::InlineAsm::Kind::Func
@ Func
llvm::InlineAsm::Kind::RegDef
@ RegDef
llvm::InlineAsm::Kind::RegUse
@ RegUse
llvm::InlineAsm::Kind::Clobber
@ Clobber
llvm::InlineAsm::Kind::Imm
@ Imm
llvm::InlineAsm::Kind::Mem
@ Mem
llvm::InlineAsm::Kind::RegDefEarlyClobber
@ RegDefEarlyClobber
llvm::InlineAsm::isLabel
@ isLabel
Definition:InlineAsm.h:99
llvm::InlineAsm::isInput
@ isInput
Definition:InlineAsm.h:96
llvm::InlineAsm::isOutput
@ isOutput
Definition:InlineAsm.h:97
llvm::InlineAsm::isClobber
@ isClobber
Definition:InlineAsm.h:98
llvm::InlineAsm::Op_InputChain
@ Op_InputChain
Definition:InlineAsm.h:202
llvm::InlineAsm::Extra_HasSideEffects
@ Extra_HasSideEffects
Definition:InlineAsm.h:214
llvm::InlineAsm::Extra_IsConvergent
@ Extra_IsConvergent
Definition:InlineAsm.h:219
llvm::InlineAsm::Extra_MayLoad
@ Extra_MayLoad
Definition:InlineAsm.h:217
llvm::InlineAsm::Extra_MayStore
@ Extra_MayStore
Definition:InlineAsm.h:218
llvm::InlineAsm::Extra_AsmDialect
@ Extra_AsmDialect
Definition:InlineAsm.h:216
llvm::InlineAsm::Extra_IsAlignStack
@ Extra_IsAlignStack
Definition:InlineAsm.h:215
llvm::InlineAsm::Op_FirstOperand
@ Op_FirstOperand
Definition:InlineAsm.h:206
llvm::InlineAsm::ConstraintCode
ConstraintCode
Definition:InlineAsm.h:239
llvm::InlineAsm::ConstraintCode::Unknown
@ Unknown
llvm::InsertValueInst
This instruction inserts a struct field of array element value into an aggregate value.
Definition:Instructions.h:2485
llvm::InstructionCost
Definition:InstructionCost.h:29
llvm::Instruction
Definition:Instruction.h:68
llvm::Instruction::getDebugLoc
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Definition:Instruction.h:511
llvm::Instruction::getFastMathFlags
FastMathFlags getFastMathFlags() const LLVM_READONLY
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
Definition:Instruction.cpp:651
llvm::Instruction::getAAMetadata
AAMDNodes getAAMetadata() const
Returns the AA metadata for this instruction.
Definition:Metadata.cpp:1750
llvm::Instruction::BinaryOps
BinaryOps
Definition:Instruction.h:1008
llvm::IntegerType::MIN_INT_BITS
@ MIN_INT_BITS
Minimum number of bits that can be specified.
Definition:DerivedTypes.h:53
llvm::IntrinsicInst::getIntrinsicID
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
Definition:IntrinsicInst.h:55
llvm::InvokeInst
Invoke instruction.
Definition:Instructions.h:3670
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition:LLVMContext.h:67
llvm::LLVMContext::emitError
void emitError(const Instruction *I, const Twine &ErrorStr)
emitError - Emit an error message to the currently installed error handler with optional location inf...
Definition:LLVMContext.cpp:210
llvm::LLVMContext::diagnose
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
Definition:LLVMContext.cpp:245
llvm::LLVMContext::OB_preallocated
@ OB_preallocated
Definition:LLVMContext.h:93
llvm::LLVMContext::OB_cfguardtarget
@ OB_cfguardtarget
Definition:LLVMContext.h:92
llvm::LLVMContext::OB_convergencectrl
@ OB_convergencectrl
Definition:LLVMContext.h:98
llvm::LLVMContext::OB_kcfi
@ OB_kcfi
Definition:LLVMContext.h:97
llvm::LLVMContext::OB_ptrauth
@ OB_ptrauth
Definition:LLVMContext.h:96
llvm::LandingPadInst
The landingpad instruction holds all of the information necessary to generate correct exception handl...
Definition:Instructions.h:2840
llvm::LoadInst
An instruction for reading from memory.
Definition:Instructions.h:176
llvm::LoadSDNode
This class is used to represent ISD::LOAD nodes.
Definition:SelectionDAGNodes.h:2464
llvm::LocationSize::precise
static LocationSize precise(uint64_t Value)
Definition:MemoryLocation.h:108
llvm::LocationSize::beforeOrAfterPointer
static constexpr LocationSize beforeOrAfterPointer()
Any location before or after the base pointer (but still within the underlying object).
Definition:MemoryLocation.h:137
llvm::MCContext::createTempSymbol
MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
Definition:MCContext.cpp:345
llvm::MCContext::getOrCreateFrameAllocSymbol
MCSymbol * getOrCreateFrameAllocSymbol(const Twine &FuncName, unsigned Idx)
Gets a symbol that will be defined to the final stack offset of a local variable after codegen.
Definition:MCContext.cpp:235
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::INVALID_SIMPLE_VALUE_TYPE
@ INVALID_SIMPLE_VALUE_TYPE
Definition:MachineValueType.h:40
llvm::MVT::getScalarSizeInBits
uint64_t getScalarSizeInBits() const
Definition:MachineValueType.h:346
llvm::MVT::getVectorNumElements
unsigned getVectorNumElements() const
Definition:MachineValueType.h:294
llvm::MVT::isVector
bool isVector() const
Return true if this is a vector value type.
Definition:MachineValueType.h:106
llvm::MVT::isInteger
bool isInteger() const
Return true if this is an integer or a vector integer type.
Definition:MachineValueType.h:90
llvm::MVT::getSizeInBits
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
Definition:MachineValueType.h:308
llvm::MVT::getFixedSizeInBits
uint64_t getFixedSizeInBits() const
Return the size of the specified fixed width value type in bits.
Definition:MachineValueType.h:342
llvm::MVT::getVectorElementCount
ElementCount getVectorElementCount() const
Definition:MachineValueType.h:290
llvm::MVT::getStoreSize
TypeSize getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
Definition:MachineValueType.h:356
llvm::MVT::bitsGE
bool bitsGE(MVT VT) const
Return true if this has no less bits than VT.
Definition:MachineValueType.h:411
llvm::MVT::isScalarInteger
bool isScalarInteger() const
Return true if this is an integer, not including vectors.
Definition:MachineValueType.h:100
llvm::MVT::getVectorVT
static MVT getVectorVT(MVT VT, unsigned NumElements)
Definition:MachineValueType.h:451
llvm::MVT::isFloatingPoint
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
Definition:MachineValueType.h:80
llvm::MVT::getIntegerVT
static MVT getIntegerVT(unsigned BitWidth)
Definition:MachineValueType.h:441
llvm::MachineBasicBlock
Definition:MachineBasicBlock.h:125
llvm::MachineBasicBlock::normalizeSuccProbs
void normalizeSuccProbs()
Normalize probabilities of all successors so that the sum of them becomes one.
Definition:MachineBasicBlock.h:764
llvm::MachineBasicBlock::isEHPad
bool isEHPad() const
Returns true if the block is a landing pad.
Definition:MachineBasicBlock.h:634
llvm::MachineBasicBlock::setIsEHCatchretTarget
void setIsEHCatchretTarget(bool V=true)
Indicates if this is a target block of a catchret.
Definition:MachineBasicBlock.h:657
llvm::MachineBasicBlock::setIsCleanupFuncletEntry
void setIsCleanupFuncletEntry(bool V=true)
Indicates if this is the entry block of a cleanup funclet.
Definition:MachineBasicBlock.h:669
llvm::MachineBasicBlock::succ_end
succ_iterator succ_end()
Definition:MachineBasicBlock.h:423
llvm::MachineBasicBlock::getBasicBlock
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
Definition:MachineBasicBlock.h:256
llvm::MachineBasicBlock::setSuccProbability
void setSuccProbability(succ_iterator I, BranchProbability Prob)
Set successor probability of a given iterator.
Definition:MachineBasicBlock.cpp:1598
llvm::MachineBasicBlock::succ_begin
succ_iterator succ_begin()
Definition:MachineBasicBlock.h:421
llvm::MachineBasicBlock::addSuccessor
void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
Definition:MachineBasicBlock.cpp:798
llvm::MachineBasicBlock::succ_iterator
SmallVectorImpl< MachineBasicBlock * >::iterator succ_iterator
Definition:MachineBasicBlock.h:394
llvm::MachineBasicBlock::begin
iterator begin()
Definition:MachineBasicBlock.h:355
llvm::MachineBasicBlock::addLiveIn
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
Definition:MachineBasicBlock.h:456
llvm::MachineBasicBlock::getParent
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
Definition:MachineBasicBlock.h:311
llvm::MachineBasicBlock::setIsEHFuncletEntry
void setIsEHFuncletEntry(bool V=true)
Indicates if this is the entry block of an EH funclet.
Definition:MachineBasicBlock.h:663
llvm::MachineBasicBlock::setIsEHScopeEntry
void setIsEHScopeEntry(bool V=true)
Indicates if this is the entry block of an EH scope, i.e., the block that that used to have a catchpa...
Definition:MachineBasicBlock.h:651
llvm::MachineBasicBlock::setMachineBlockAddressTaken
void setMachineBlockAddressTaken()
Set this block to indicate that its address is used as something other than the target of a terminato...
Definition:MachineBasicBlock.h:297
llvm::MachineFrameInfo
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
Definition:MachineFrameInfo.h:106
llvm::MachineFrameInfo::hasVarSizedObjects
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
Definition:MachineFrameInfo.h:357
llvm::MachineFrameInfo::setIsImmutableObjectIndex
void setIsImmutableObjectIndex(int ObjectIdx, bool IsImmutable)
Marks the immutability of an object.
Definition:MachineFrameInfo.h:730
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::setHasPatchPoint
void setHasPatchPoint(bool s=true)
Definition:MachineFrameInfo.h:392
llvm::MachineFrameInfo::setHasStackMap
void setHasStackMap(bool s=true)
Definition:MachineFrameInfo.h:386
llvm::MachineFrameInfo::hasOpaqueSPAdjustment
bool hasOpaqueSPAdjustment() const
Returns true if the function contains opaque dynamic stack adjustments.
Definition:MachineFrameInfo.h:625
llvm::MachineFrameInfo::getStackProtectorIndex
int getStackProtectorIndex() const
Return the index for the stack protector object.
Definition:MachineFrameInfo.h:360
llvm::MachineFrameInfo::setStackProtectorIndex
void setStackProtectorIndex(int I)
Definition:MachineFrameInfo.h:361
llvm::MachineFrameInfo::setIsAliasedObjectIndex
void setIsAliasedObjectIndex(int ObjectIdx, bool IsAliased)
Set "maybe pointed to by an LLVM IR value" for an object.
Definition:MachineFrameInfo.h:713
llvm::MachineFrameInfo::getObjectAlign
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
Definition:MachineFrameInfo.h:486
llvm::MachineFrameInfo::getObjectSize
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
Definition:MachineFrameInfo.h:472
llvm::MachineFrameInfo::RemoveStackObject
void RemoveStackObject(int ObjectIdx)
Remove or mark dead a statically sized stack object.
Definition:MachineFrameInfo.h:795
llvm::MachineFrameInfo::setFunctionContextIndex
void setFunctionContextIndex(int I)
Definition:MachineFrameInfo.h:367
llvm::MachineFunction::VariableDbgInfo
Description of the location of a variable whose Address is valid and unchanging during function execu...
Definition:MachineFunction.h:427
llvm::MachineFunction
Definition:MachineFunction.h:267
llvm::MachineFunction::getWinEHFuncInfo
const WinEHFuncInfo * getWinEHFuncInfo() const
getWinEHFuncInfo - Return information about how the current function uses Windows exception handling.
Definition:MachineFunction.h:777
llvm::MachineFunction::setCallsUnwindInit
void setCallsUnwindInit(bool b)
Definition:MachineFunction.h:1229
llvm::MachineFunction::useDebugInstrRef
bool useDebugInstrRef() const
Returns true if the function's variable locations are tracked with instruction referencing.
Definition:MachineFunction.cpp:1298
llvm::MachineFunction::setCallSiteBeginLabel
void setCallSiteBeginLabel(MCSymbol *BeginLabel, unsigned Site)
Map the begin label for a call site.
Definition:MachineFunction.h:1315
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::getName
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
Definition:MachineFunction.cpp:645
llvm::MachineFunction::setHasEHCatchret
void setHasEHCatchret(bool V)
Definition:MachineFunction.h:1232
llvm::MachineFunction::setCallsEHReturn
void setCallsEHReturn(bool b)
Definition:MachineFunction.h:1226
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::getTypeIDFor
unsigned getTypeIDFor(const GlobalValue *TI)
Return the type id for the specified typeinfo. This is function wide.
Definition:MachineFunction.cpp:883
llvm::MachineFunction::getContext
MCContext & getContext() const
Definition:MachineFunction.h:690
llvm::MachineFunction::getRegInfo
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Definition:MachineFunction.h:743
llvm::MachineFunction::getInStackSlotVariableDbgInfo
auto getInStackSlotVariableDbgInfo()
Returns the collection of variables for which we have debug info and that have been assigned a stack ...
Definition:MachineFunction.h:1374
llvm::MachineFunction::addCodeViewAnnotation
void addCodeViewAnnotation(MCSymbol *Label, MDNode *MD)
Record annotations associated with a particular label.
Definition:MachineFunction.h:1332
llvm::MachineFunction::getFunction
Function & getFunction()
Return the LLVM function that this machine code represents.
Definition:MachineFunction.h:704
llvm::MachineFunction::end
iterator end()
Definition:MachineFunction.h:949
llvm::MachineFunction::front
const MachineBasicBlock & front() const
Definition:MachineFunction.h:959
llvm::MachineFunction::hasEHFunclets
bool hasEHFunclets() const
Definition:MachineFunction.h:1237
llvm::MachineFunction::addInvoke
void addInvoke(MachineBasicBlock *LandingPad, MCSymbol *BeginLabel, MCSymbol *EndLabel)
Provide the begin and end labels of an invoke style call and associate it with a try landing pad bloc...
Definition:MachineFunction.cpp:824
llvm::MachineFunction::CreateMachineBasicBlock
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *BB=nullptr, std::optional< UniqueBBID > BBID=std::nullopt)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
Definition:MachineFunction.cpp:499
llvm::MachineFunction::erase
void erase(iterator MBBI)
Definition:MachineFunction.h:981
llvm::MachineFunction::insert
void insert(iterator MBBI, MachineBasicBlock *MBB)
Definition:MachineFunction.h:966
llvm::MachineInstrBuilder::addSym
const MachineInstrBuilder & addSym(MCSymbol *Sym, unsigned char TargetFlags=0) const
Definition:MachineInstrBuilder.h:269
llvm::MachineInstrBuilder::addFrameIndex
const MachineInstrBuilder & addFrameIndex(int Idx) const
Definition:MachineInstrBuilder.h:154
llvm::MachineInstrBundleIterator< MachineInstr >
llvm::MachineInstr
Representation of each machine instruction.
Definition:MachineInstr.h:71
llvm::MachineMemOperand
A description of a memory reference used in the backend.
Definition:MachineMemOperand.h:129
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::MONonTemporal
@ MONonTemporal
The memory access is non-temporal.
Definition:MachineMemOperand.h:142
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::MachineOperand::CreateReg
static MachineOperand CreateReg(Register Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isEarlyClobber=false, unsigned SubReg=0, bool isDebug=false, bool isInternalRead=false, bool isRenamable=false)
Definition:MachineOperand.h:838
llvm::MachineOperand::CreateFI
static MachineOperand CreateFI(int Idx)
Definition:MachineOperand.h:870
llvm::MachineRegisterInfo
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Definition:MachineRegisterInfo.h:51
llvm::MachineRegisterInfo::liveins
ArrayRef< std::pair< MCRegister, Register > > liveins() const
Definition:MachineRegisterInfo.h:1018
llvm::MachineSDNode
An SDNode that represents everything that will be needed to construct a MachineInstr.
Definition:SelectionDAGNodes.h:3060
llvm::MapVector::contains
bool contains(const KeyT &Key) const
Definition:MapVector.h:163
llvm::MapVector::try_emplace
std::pair< iterator, bool > try_emplace(const KeyT &Key, Ts &&...Args)
Definition:MapVector.h:118
llvm::MemoryLocation
Representation for a specific memory location.
Definition:MemoryLocation.h:227
llvm::MemoryLocation::getAfter
static MemoryLocation getAfter(const Value *Ptr, const AAMDNodes &AATags=AAMDNodes())
Return a location that may access any location after Ptr, while remaining within the underlying objec...
Definition:MemoryLocation.h:287
llvm::MemoryLocation::UnknownSize
@ UnknownSize
Definition:MemoryLocation.h:232
llvm::MetadataAsValue
Metadata wrapper in the Value hierarchy.
Definition:Metadata.h:180
llvm::Metadata
Root of the metadata hierarchy.
Definition:Metadata.h:62
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition:Module.h:65
llvm::OverflowingBinaryOperator
Utility class for integer operators which may exhibit overflow - Add, Sub, Mul, and Shl.
Definition:Operator.h:77
llvm::PHINode
Definition:Instructions.h:2600
llvm::PatchPointOpers::IDPos
@ IDPos
Definition:StackMaps.h:79
llvm::PatchPointOpers::CCPos
@ CCPos
Definition:StackMaps.h:79
llvm::PatchPointOpers::NBytesPos
@ NBytesPos
Definition:StackMaps.h:79
llvm::PatchPointOpers::TargetPos
@ TargetPos
Definition:StackMaps.h:79
llvm::PatchPointOpers::NArgPos
@ NArgPos
Definition:StackMaps.h:79
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::PoisonValue::get
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Definition:Constants.cpp:1878
llvm::PossiblyExactOperator
A udiv or sdiv instruction, which can be marked as "exact", indicating that no bits are destroyed.
Definition:Operator.h:155
llvm::Register
Wrapper class representing virtual and physical registers.
Definition:Register.h:19
llvm::Register::isVirtual
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
Definition:Register.h:91
llvm::Register::isVirtualRegister
static constexpr bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
Definition:Register.h:71
llvm::Register::isPhysicalRegister
static constexpr bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
Definition:Register.h:65
llvm::Register::isPhysical
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
Definition:Register.h:95
llvm::ResumeInst
Resume the propagation of an exception.
Definition:Instructions.h:4002
llvm::ReturnInst
Return a value (possibly void), from a function.
Definition:Instructions.h:2938
llvm::SDDbgLabel
Holds the information from a dbg_label node through SDISel.
Definition:SDNodeDbgValue.h:242
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::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::SDNode
Represents one node in the SelectionDAG.
Definition:SelectionDAGNodes.h:496
llvm::SDNode::getOpcode
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
Definition:SelectionDAGNodes.h:687
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::getAsZExtVal
uint64_t getAsZExtVal() const
Helper method returns the zero-extended integer value of a ConstantSDNode.
Definition:SelectionDAGNodes.h:1727
llvm::SDNode::getNumValues
unsigned getNumValues() const
Return the number of values defined/returned by this operator.
Definition:SelectionDAGNodes.h:1059
llvm::SDNode::getOperand
const SDValue & getOperand(unsigned Num) const
Definition:SelectionDAGNodes.h:992
llvm::SDNode::getValueType
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
Definition:SelectionDAGNodes.h:1062
llvm::SDUse
Represents a use of a SDNode.
Definition:SelectionDAGNodes.h:283
llvm::SDValue
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
Definition:SelectionDAGNodes.h:145
llvm::SDValue::getNode
SDNode * getNode() const
get the SDNode which holds the desired result
Definition:SelectionDAGNodes.h:159
llvm::SDValue::getValue
SDValue getValue(unsigned R) const
Definition:SelectionDAGNodes.h:179
llvm::SDValue::dump
void dump() const
Definition:SelectionDAGNodes.h:1265
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::getResNo
unsigned getResNo() const
get the index which selects a specific result in the SDNode
Definition:SelectionDAGNodes.h:156
llvm::SDValue::getSimpleValueType
MVT getSimpleValueType() const
Return the simple ValueType of the referenced return value.
Definition:SelectionDAGNodes.h:190
llvm::SDValue::getOpcode
unsigned getOpcode() const
Definition:SelectionDAGNodes.h:1213
llvm::SelectionDAGBuilder
SelectionDAGBuilder - This is the common target-independent lowering implementation that is parameter...
Definition:SelectionDAGBuilder.h:97
llvm::SelectionDAGBuilder::getValue
SDValue getValue(const Value *V)
getValue - Return an SDValue for the given Value.
Definition:SelectionDAGBuilder.cpp:1746
llvm::SelectionDAGBuilder::addDanglingDebugInfo
void addDanglingDebugInfo(SmallVectorImpl< Value * > &Values, DILocalVariable *Var, DIExpression *Expr, bool IsVariadic, DebugLoc DL, unsigned Order)
Register a dbg_value which relies on a Value which we have not yet seen.
Definition:SelectionDAGBuilder.cpp:1403
llvm::SelectionDAGBuilder::visitDbgInfo
void visitDbgInfo(const Instruction &I)
Definition:SelectionDAGBuilder.cpp:1229
llvm::SelectionDAGBuilder::clearDanglingDebugInfo
void clearDanglingDebugInfo()
Clear the dangling debug information map.
Definition:SelectionDAGBuilder.cpp:1112
llvm::SelectionDAGBuilder::BatchAA
BatchAAResults * BatchAA
Definition:SelectionDAGBuilder.h:228
llvm::SelectionDAGBuilder::LowerCallTo
void LowerCallTo(const CallBase &CB, SDValue Callee, bool IsTailCall, bool IsMustTailCall, const BasicBlock *EHPadBB=nullptr, const TargetLowering::PtrAuthInfo *PAI=nullptr)
Definition:SelectionDAGBuilder.cpp:8859
llvm::SelectionDAGBuilder::clear
void clear()
Clear out the current SelectionDAG and the associated state and prepare this SelectionDAGBuilder obje...
Definition:SelectionDAGBuilder.cpp:1099
llvm::SelectionDAGBuilder::visitBitTestHeader
void visitBitTestHeader(SwitchCG::BitTestBlock &B, MachineBasicBlock *SwitchBB)
visitBitTestHeader - This function emits necessary code to produce value suitable for "bit tests"
Definition:SelectionDAGBuilder.cpp:3202
llvm::SelectionDAGBuilder::LowerStatepoint
void LowerStatepoint(const GCStatepointInst &I, const BasicBlock *EHPadBB=nullptr)
Definition:StatepointLowering.cpp:1014
llvm::SelectionDAGBuilder::SL
std::unique_ptr< SDAGSwitchLowering > SL
Definition:SelectionDAGBuilder.h:249
llvm::SelectionDAGBuilder::lowerRangeToAssertZExt
SDValue lowerRangeToAssertZExt(SelectionDAG &DAG, const Instruction &I, SDValue Op)
Definition:SelectionDAGBuilder.cpp:10541
llvm::SelectionDAGBuilder::HasTailCall
bool HasTailCall
This is set to true if a call in the current block has been translated as a tail call.
Definition:SelectionDAGBuilder.h:273
llvm::SelectionDAGBuilder::ShouldEmitAsBranches
bool ShouldEmitAsBranches(const std::vector< SwitchCG::CaseBlock > &Cases)
If the set of cases should be emitted as a series of branches, return true.
Definition:SelectionDAGBuilder.cpp:2757
llvm::SelectionDAGBuilder::EmitBranchForMergedCondition
void EmitBranchForMergedCondition(const Value *Cond, MachineBasicBlock *TBB, MachineBasicBlock *FBB, MachineBasicBlock *CurBB, MachineBasicBlock *SwitchBB, BranchProbability TProb, BranchProbability FProb, bool InvertCond)
EmitBranchForMergedCondition - Helper method for FindMergedConditions.
Definition:SelectionDAGBuilder.cpp:2433
llvm::SelectionDAGBuilder::LowerDeoptimizeCall
void LowerDeoptimizeCall(const CallInst *CI)
Definition:StatepointLowering.cpp:1302
llvm::SelectionDAGBuilder::LowerCallSiteWithDeoptBundle
void LowerCallSiteWithDeoptBundle(const CallBase *Call, SDValue Callee, const BasicBlock *EHPadBB)
Definition:StatepointLowering.cpp:1174
llvm::SelectionDAGBuilder::SwiftError
SwiftErrorValueTracking & SwiftError
Information about the swifterror values used throughout the function.
Definition:SelectionDAGBuilder.h:263
llvm::SelectionDAGBuilder::getNonRegisterValue
SDValue getNonRegisterValue(const Value *V)
getNonRegisterValue - Return an SDValue for the given Value, but don't look in FuncInfo....
Definition:SelectionDAGBuilder.cpp:1767
llvm::SelectionDAGBuilder::CopyValueToVirtualRegister
void CopyValueToVirtualRegister(const Value *V, unsigned Reg, ISD::NodeType ExtendType=ISD::ANY_EXTEND)
Definition:SelectionDAGBuilder.cpp:11376
llvm::SelectionDAGBuilder::LPadToCallSiteMap
DenseMap< MachineBasicBlock *, SmallVector< unsigned, 4 > > LPadToCallSiteMap
Map a landing pad to the call site indexes.
Definition:SelectionDAGBuilder.h:269
llvm::SelectionDAGBuilder::handleDebugDeclare
void handleDebugDeclare(Value *Address, DILocalVariable *Variable, DIExpression *Expression, DebugLoc DL)
Definition:SelectionDAGBuilder.cpp:1176
llvm::SelectionDAGBuilder::shouldKeepJumpConditionsTogether
bool shouldKeepJumpConditionsTogether(const FunctionLoweringInfo &FuncInfo, const BranchInst &I, Instruction::BinaryOps Opc, const Value *Lhs, const Value *Rhs, TargetLoweringBase::CondMergingParams Params) const
Definition:SelectionDAGBuilder.cpp:2512
llvm::SelectionDAGBuilder::StatepointLowering
StatepointLoweringState StatepointLowering
State used while lowering a statepoint sequence (gc_statepoint, gc_relocate, and gc_result).
Definition:SelectionDAGBuilder.h:176
llvm::SelectionDAGBuilder::visitBitTestCase
void visitBitTestCase(SwitchCG::BitTestBlock &BB, MachineBasicBlock *NextMBB, BranchProbability BranchProbToNext, Register Reg, SwitchCG::BitTestCase &B, MachineBasicBlock *SwitchBB)
visitBitTestCase - this function produces one "bit test"
Definition:SelectionDAGBuilder.cpp:3264
llvm::SelectionDAGBuilder::ConstantsOut
DenseMap< const Constant *, unsigned > ConstantsOut
Definition:SelectionDAGBuilder.h:257
llvm::SelectionDAGBuilder::populateCallLoweringInfo
void populateCallLoweringInfo(TargetLowering::CallLoweringInfo &CLI, const CallBase *Call, unsigned ArgIdx, unsigned NumArgs, SDValue Callee, Type *ReturnTy, AttributeSet RetAttrs, bool IsPatchPoint)
Populate a CallLowerinInfo (into CLI) based on the properties of the call being lowered.
Definition:SelectionDAGBuilder.cpp:10582
llvm::SelectionDAGBuilder::salvageUnresolvedDbgValue
void salvageUnresolvedDbgValue(const Value *V, DanglingDebugInfo &DDI)
For the given dangling debuginfo record, perform last-ditch efforts to resolve the debuginfo to somet...
Definition:SelectionDAGBuilder.cpp:1502
llvm::SelectionDAGBuilder::PendingLoads
SmallVector< SDValue, 8 > PendingLoads
Loads are not emitted to the program immediately.
Definition:SelectionDAGBuilder.h:172
llvm::SelectionDAGBuilder::GFI
GCFunctionInfo * GFI
Garbage collection metadata for the function.
Definition:SelectionDAGBuilder.h:266
llvm::SelectionDAGBuilder::getRoot
SDValue getRoot()
Similar to getMemoryRoot, but also flushes PendingConstrainedFP(Strict) items.
Definition:SelectionDAGBuilder.cpp:1151
llvm::SelectionDAGBuilder::ExportFromCurrentBlock
void ExportFromCurrentBlock(const Value *V)
ExportFromCurrentBlock - If this condition isn't known to be exported from the current basic block,...
Definition:SelectionDAGBuilder.cpp:2357
llvm::SelectionDAGBuilder::init
void init(GCFunctionInfo *gfi, BatchAAResults *BatchAA, AssumptionCache *AC, const TargetLibraryInfo *li)
Definition:SelectionDAGBuilder.cpp:1085
llvm::SelectionDAGBuilder::getCurDebugLoc
DebugLoc getCurDebugLoc() const
Definition:SelectionDAGBuilder.h:319
llvm::SelectionDAGBuilder::resolveOrClearDbgInfo
void resolveOrClearDbgInfo()
Evict any dangling debug information, attempting to salvage it first.
Definition:SelectionDAGBuilder.cpp:1716
llvm::SelectionDAGBuilder::lowerInvokable
std::pair< SDValue, SDValue > lowerInvokable(TargetLowering::CallLoweringInfo &CLI, const BasicBlock *EHPadBB=nullptr)
Definition:SelectionDAGBuilder.cpp:8818
llvm::SelectionDAGBuilder::getMemoryRoot
SDValue getMemoryRoot()
Return the current virtual root of the Selection DAG, flushing any PendingLoad items.
Definition:SelectionDAGBuilder.cpp:1147
llvm::SelectionDAGBuilder::resolveDanglingDebugInfo
void resolveDanglingDebugInfo(const Value *V, SDValue Val)
If we saw an earlier dbg_value referring to V, generate the debug data structures now that we've seen...
Definition:SelectionDAGBuilder.cpp:1448
llvm::SelectionDAGBuilder::getCurSDLoc
SDLoc getCurSDLoc() const
Definition:SelectionDAGBuilder.h:315
llvm::SelectionDAGBuilder::visit
void visit(const Instruction &I)
Definition:SelectionDAGBuilder.cpp:1317
llvm::SelectionDAGBuilder::dropDanglingDebugInfo
void dropDanglingDebugInfo(const DILocalVariable *Variable, const DIExpression *Expr)
If we have dangling debug info that describes Variable, or an overlapping part of variable considerin...
Definition:SelectionDAGBuilder.cpp:1420
llvm::SelectionDAGBuilder::getCopyFromRegs
SDValue getCopyFromRegs(const Value *V, Type *Ty)
If there was virtual register allocated for the value V emit CopyFromReg of the specified type Ty.
Definition:SelectionDAGBuilder.cpp:1726
llvm::SelectionDAGBuilder::CopyToExportRegsIfNeeded
void CopyToExportRegsIfNeeded(const Value *V)
CopyToExportRegsIfNeeded - If the given value has virtual registers created for it,...
Definition:SelectionDAGBuilder.cpp:2341
llvm::SelectionDAGBuilder::handleKillDebugValue
void handleKillDebugValue(DILocalVariable *Var, DIExpression *Expr, DebugLoc DbgLoc, unsigned Order)
Create a record for a kill location debug intrinsic.
Definition:SelectionDAGBuilder.cpp:1568
llvm::SelectionDAGBuilder::Context
LLVMContext * Context
Definition:SelectionDAGBuilder.h:275
llvm::SelectionDAGBuilder::visitJumpTable
void visitJumpTable(SwitchCG::JumpTable &JT)
visitJumpTable - Emit JumpTable node in the current MBB
Definition:SelectionDAGBuilder.cpp:2988
llvm::SelectionDAGBuilder::visitJumpTableHeader
void visitJumpTableHeader(SwitchCG::JumpTable &JT, SwitchCG::JumpTableHeader &JTH, MachineBasicBlock *SwitchBB)
visitJumpTableHeader - This function emits necessary code to produce index in the JumpTable from swit...
Definition:SelectionDAGBuilder.cpp:3002
llvm::SelectionDAGBuilder::LowerCallSiteWithPtrAuthBundle
void LowerCallSiteWithPtrAuthBundle(const CallBase &CB, const BasicBlock *EHPadBB)
Definition:SelectionDAGBuilder.cpp:9604
llvm::SelectionDAGBuilder::AC
AssumptionCache * AC
Definition:SelectionDAGBuilder.h:229
llvm::SelectionDAGBuilder::LowestSDNodeOrder
static const unsigned LowestSDNodeOrder
Lowest valid SDNodeOrder.
Definition:SelectionDAGBuilder.h:225
llvm::SelectionDAGBuilder::LowerDeoptimizingReturn
void LowerDeoptimizingReturn()
Definition:StatepointLowering.cpp:1315
llvm::SelectionDAGBuilder::FuncInfo
FunctionLoweringInfo & FuncInfo
Information about the function as a whole.
Definition:SelectionDAGBuilder.h:260
llvm::SelectionDAGBuilder::setValue
void setValue(const Value *V, SDValue NewN)
Definition:SelectionDAGBuilder.h:376
llvm::SelectionDAGBuilder::DAG
SelectionDAG & DAG
Definition:SelectionDAGBuilder.h:227
llvm::SelectionDAGBuilder::FindMergedConditions
void FindMergedConditions(const Value *Cond, MachineBasicBlock *TBB, MachineBasicBlock *FBB, MachineBasicBlock *CurBB, MachineBasicBlock *SwitchBB, Instruction::BinaryOps Opc, BranchProbability TProb, BranchProbability FProb, bool InvertCond)
Definition:SelectionDAGBuilder.cpp:2626
llvm::SelectionDAGBuilder::LibInfo
const TargetLibraryInfo * LibInfo
Definition:SelectionDAGBuilder.h:230
llvm::SelectionDAGBuilder::isExportableFromCurrentBlock
bool isExportableFromCurrentBlock(const Value *V, const BasicBlock *FromBB)
Definition:SelectionDAGBuilder.cpp:2368
llvm::SelectionDAGBuilder::visitSPDescriptorParent
void visitSPDescriptorParent(StackProtectorDescriptor &SPD, MachineBasicBlock *ParentBB)
Codegen a new tail for a stack protector check ParentMBB which has had its tail spliced into a stack ...
Definition:SelectionDAGBuilder.cpp:3089
llvm::SelectionDAGBuilder::handleDebugValue
bool handleDebugValue(ArrayRef< const Value * > Values, DILocalVariable *Var, DIExpression *Expr, DebugLoc DbgLoc, unsigned Order, bool IsVariadic)
For a given list of Values, attempt to create and record a SDDbgValue in the SelectionDAG.
Definition:SelectionDAGBuilder.cpp:1579
llvm::SelectionDAGBuilder::getControlRoot
SDValue getControlRoot()
Similar to getRoot, but instead of flushing all the PendingLoad items, flush all the PendingExports (...
Definition:SelectionDAGBuilder.cpp:1167
llvm::SelectionDAGBuilder::UpdateSplitBlock
void UpdateSplitBlock(MachineBasicBlock *First, MachineBasicBlock *Last)
When an MBB was split during scheduling, update the references that need to refer to the last resulti...
Definition:SelectionDAGBuilder.cpp:3510
llvm::SelectionDAGBuilder::getValueImpl
SDValue getValueImpl(const Value *V)
getValueImpl - Helper function for getValue and getNonRegisterValue.
Definition:SelectionDAGBuilder.cpp:1790
llvm::SelectionDAGBuilder::visitSwitchCase
void visitSwitchCase(SwitchCG::CaseBlock &CB, MachineBasicBlock *SwitchBB)
visitSwitchCase - Emits the necessary code to represent a single node in the binary search tree resul...
Definition:SelectionDAGBuilder.cpp:2892
llvm::SelectionDAGBuilder::visitSPDescriptorFailure
void visitSPDescriptorFailure(StackProtectorDescriptor &SPD)
Codegen the failure basic block for a stack protector check.
Definition:SelectionDAGBuilder.cpp:3184
llvm::SelectionDAGISel::FuncInfo
std::unique_ptr< FunctionLoweringInfo > FuncInfo
Definition:SelectionDAGISel.h:49
llvm::SelectionDAGISel::ElidedArgCopyInstrs
SmallPtrSet< const Instruction *, 4 > ElidedArgCopyInstrs
Definition:SelectionDAGISel.h:67
llvm::SelectionDAGISel::TM
TargetMachine & TM
Definition:SelectionDAGISel.h:47
llvm::SelectionDAGISel::TLI
const TargetLowering * TLI
Definition:SelectionDAGISel.h:65
llvm::SelectionDAGISel::MF
MachineFunction * MF
Definition:SelectionDAGISel.h:51
llvm::SelectionDAGISel::CurDAG
SelectionDAG * CurDAG
Definition:SelectionDAGISel.h:54
llvm::SelectionDAGISel::emitFunctionEntryCode
virtual void emitFunctionEntryCode()
Definition:SelectionDAGISel.h:99
llvm::SelectionDAGISel::SwiftError
SwiftErrorValueTracking * SwiftError
Definition:SelectionDAGISel.h:50
llvm::SelectionDAGISel::SDB
std::unique_ptr< SelectionDAGBuilder > SDB
Definition:SelectionDAGISel.h:55
llvm::SelectionDAGTargetInfo
Targets can subclass this to parameterize the SelectionDAG lowering and instruction selection process...
Definition:SelectionDAGTargetInfo.h:31
llvm::SelectionDAGTargetInfo::EmitTargetCodeForStrnlen
virtual std::pair< SDValue, SDValue > EmitTargetCodeForStrnlen(SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Src, SDValue MaxLength, MachinePointerInfo SrcPtrInfo) const
Definition:SelectionDAGTargetInfo.h:159
llvm::SelectionDAGTargetInfo::EmitTargetCodeForMemcmp
virtual std::pair< SDValue, SDValue > EmitTargetCodeForMemcmp(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Op1, SDValue Op2, SDValue Op3, MachinePointerInfo Op1PtrInfo, MachinePointerInfo Op2PtrInfo) const
Emit target-specific code that performs a memcmp/bcmp, in cases where that is faster than a libcall.
Definition:SelectionDAGTargetInfo.h:108
llvm::SelectionDAGTargetInfo::EmitTargetCodeForStrcpy
virtual std::pair< SDValue, SDValue > EmitTargetCodeForStrcpy(SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Dest, SDValue Src, MachinePointerInfo DestPtrInfo, MachinePointerInfo SrcPtrInfo, bool isStpcpy) const
Emit target-specific code that performs a strcpy or stpcpy, in cases where that is faster than a libc...
Definition:SelectionDAGTargetInfo.h:133
llvm::SelectionDAGTargetInfo::EmitTargetCodeForMemchr
virtual std::pair< SDValue, SDValue > EmitTargetCodeForMemchr(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Src, SDValue Char, SDValue Length, MachinePointerInfo SrcPtrInfo) const
Emit target-specific code that performs a memchr, in cases where that is faster than a libcall.
Definition:SelectionDAGTargetInfo.h:120
llvm::SelectionDAGTargetInfo::EmitTargetCodeForStrcmp
virtual std::pair< SDValue, SDValue > EmitTargetCodeForStrcmp(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Op1, SDValue Op2, MachinePointerInfo Op1PtrInfo, MachinePointerInfo Op2PtrInfo) const
Emit target-specific code that performs a strcmp, in cases where that is faster than a libcall.
Definition:SelectionDAGTargetInfo.h:145
llvm::SelectionDAGTargetInfo::EmitTargetCodeForStrlen
virtual std::pair< SDValue, SDValue > EmitTargetCodeForStrlen(SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Src, MachinePointerInfo SrcPtrInfo) const
Definition:SelectionDAGTargetInfo.h:153
llvm::SelectionDAGTargetInfo::EmitTargetCodeForSetTag
virtual SDValue EmitTargetCodeForSetTag(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Addr, SDValue Size, MachinePointerInfo DstPtrInfo, bool ZeroData) const
Definition:SelectionDAGTargetInfo.h:165
llvm::SelectionDAG::FlagInserter
Help to insert SDNodeFlags automatically in transforming.
Definition:SelectionDAG.h:371
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::getTargetGlobalAddress
SDValue getTargetGlobalAddress(const GlobalValue *GV, const SDLoc &DL, EVT VT, int64_t offset=0, unsigned TargetFlags=0)
Definition:SelectionDAG.h:751
llvm::SelectionDAG::getExtOrTrunc
SDValue getExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT, unsigned Opcode)
Convert Op, which must be of integer type, to the integer type VT, by either any/sign/zero-extending ...
Definition:SelectionDAG.h:983
llvm::SelectionDAG::getLabelNode
SDValue getLabelNode(unsigned Opcode, const SDLoc &dl, SDValue Root, MCSymbol *Label)
Definition:SelectionDAG.cpp:2363
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::getAddrSpaceCast
SDValue getAddrSpaceCast(const SDLoc &dl, EVT VT, SDValue Ptr, unsigned SrcAS, unsigned DestAS)
Return an AddrSpaceCastSDNode.
Definition:SelectionDAG.cpp:2440
llvm::SelectionDAG::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
Definition:SelectionDAG.h:499
llvm::SelectionDAG::getCopyToReg
SDValue getCopyToReg(SDValue Chain, const SDLoc &dl, Register Reg, SDValue N)
Definition:SelectionDAG.h:802
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::getBFI
BlockFrequencyInfo * getBFI() const
Definition:SelectionDAG.h:513
llvm::SelectionDAG::getShiftAmountConstant
SDValue getShiftAmountConstant(uint64_t Val, EVT VT, const SDLoc &DL)
Definition:SelectionDAG.cpp:1811
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::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::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::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::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::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::addMMRAMetadata
void addMMRAMetadata(const SDNode *Node, MDNode *MMRA)
Set MMRAMetadata to be associated with Node.
Definition:SelectionDAG.h:2367
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::getRegister
SDValue getRegister(Register Reg, EVT VT)
Definition:SelectionDAG.cpp:2328
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::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::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::getEVTAlign
Align getEVTAlign(EVT MemoryVT) const
Compute the default alignment value for the given type.
Definition:SelectionDAG.cpp:1358
llvm::SelectionDAG::addNoMergeSiteInfo
void addNoMergeSiteInfo(const SDNode *Node, bool NoMerge)
Set NoMergeSiteInfo to be associated with Node if NoMerge is true.
Definition:SelectionDAG.h:2394
llvm::SelectionDAG::shouldOptForSize
bool shouldOptForSize() const
Definition:SelectionDAG.cpp:1401
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::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::AddDbgValue
void AddDbgValue(SDDbgValue *DB, bool isParameter)
Add a dbg_value SDNode.
Definition:SelectionDAG.cpp:12140
llvm::SelectionDAG::getUNDEF
SDValue getUNDEF(EVT VT)
Return an UNDEF node. UNDEF does not have a useful SDLoc.
Definition:SelectionDAG.h:1129
llvm::SelectionDAG::getCALLSEQ_END
SDValue getCALLSEQ_END(SDValue Chain, SDValue Op1, SDValue Op2, SDValue InGlue, const SDLoc &DL)
Return a new CALLSEQ_END node, which always must have a glue result (to ensure it's not CSE'd).
Definition:SelectionDAG.h:1106
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::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::getCopyFromReg
SDValue getCopyFromReg(SDValue Chain, const SDLoc &dl, Register Reg, EVT VT)
Definition:SelectionDAG.h:828
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::getDataLayout
const DataLayout & getDataLayout() const
Definition:SelectionDAG.h:497
llvm::SelectionDAG::getPSI
ProfileSummaryInfo * getPSI() const
Definition:SelectionDAG.h:512
llvm::SelectionDAG::getTargetFrameIndex
SDValue getTargetFrameIndex(int FI, EVT VT)
Definition:SelectionDAG.h:756
llvm::SelectionDAG::getTokenFactor
SDValue getTokenFactor(const SDLoc &DL, SmallVectorImpl< SDValue > &Vals)
Creates a new TokenFactor containing Vals.
Definition:SelectionDAG.cpp:13532
llvm::SelectionDAG::getSelectionDAGInfo
const SelectionDAGTargetInfo & getSelectionDAGInfo() const
Definition:SelectionDAG.h:505
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::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::ReplaceAllUsesWith
void ReplaceAllUsesWith(SDValue From, SDValue To)
Modify anything using 'From' to use 'To' instead.
Definition:SelectionDAG.cpp:11653
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::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::InferPtrAlign
MaybeAlign InferPtrAlign(SDValue Ptr) const
Infer alignment of a load / store address.
Definition:SelectionDAG.cpp:12910
llvm::SelectionDAG::getCALLSEQ_START
SDValue getCALLSEQ_START(SDValue Chain, uint64_t InSize, uint64_t OutSize, const SDLoc &DL)
Return a new CALLSEQ_START node, that starts new call frame, in which InSize bytes are set up inside ...
Definition:SelectionDAG.h:1094
llvm::SelectionDAG::AddDbgLabel
void AddDbgLabel(SDDbgLabel *DB)
Add a dbg_label SDNode.
Definition:SelectionDAG.cpp:12150
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::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::getSetFPEnv
SDValue getSetFPEnv(SDValue Chain, const SDLoc &dl, SDValue Ptr, EVT MemVT, MachineMemOperand *MMO)
Definition:SelectionDAG.cpp:10198
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::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::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::getBlockAddress
SDValue getBlockAddress(const BlockAddress *BA, EVT VT, int64_t Offset=0, bool isTarget=false, unsigned TargetFlags=0)
Definition:SelectionDAG.cpp:2382
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::getTargetConstantFP
SDValue getTargetConstantFP(double Val, const SDLoc &DL, EVT VT)
Definition:SelectionDAG.h:737
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::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::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::getTargetConstant
SDValue getTargetConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isOpaque=false)
Definition:SelectionDAG.h:701
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::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::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::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::getFrameIndex
SDValue getFrameIndex(int FI, EVT VT, bool isTarget=false)
Definition:SelectionDAG.cpp:1925
llvm::SelectionDAG::getFunctionVarLocs
const FunctionVarLocs * getFunctionVarLocs() const
Returns the result of the AssignmentTrackingAnalysis pass if it's available, otherwise return nullptr...
Definition:SelectionDAG.h:509
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::getObjectPtrOffset
SDValue getObjectPtrOffset(const SDLoc &SL, SDValue Ptr, TypeSize Offset)
Create an add instruction with appropriate flags when used for addressing some offset of an object.
Definition:SelectionDAG.h:1081
llvm::SelectionDAG::getContext
LLVMContext * getContext() const
Definition:SelectionDAG.h:510
llvm::SelectionDAG::setRoot
const SDValue & setRoot(SDValue N)
Set the current root tag of the SelectionDAG.
Definition:SelectionDAG.h:586
llvm::SelectionDAG::addPCSections
void addPCSections(const SDNode *Node, MDNode *MD)
Set PCSections to be associated with Node.
Definition:SelectionDAG.h:2363
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::getSetCCVP
SDValue getSetCCVP(const SDLoc &DL, EVT VT, SDValue LHS, SDValue RHS, ISD::CondCode Cond, SDValue Mask, SDValue EVL)
Helper function to make it easier to build VP_SETCCs if you just have an ISD::CondCode instead of an ...
Definition:SelectionDAG.h:1268
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::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::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::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::SmallDenseMap
Definition:DenseMap.h:883
llvm::SmallPtrSetImpl
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition:SmallPtrSet.h:363
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::SmallSet
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition:SmallSet.h:132
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::emplace_back
reference emplace_back(ArgTypes &&... Args)
Definition:SmallVector.h:937
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::SmallVectorImpl::swap
void swap(SmallVectorImpl &RHS)
Definition:SmallVector.h:968
llvm::SmallVectorImpl::resize
void resize(size_type N)
Definition:SmallVector.h:638
llvm::SmallVectorTemplateBase::pop_back
void pop_back()
Definition:SmallVector.h:425
llvm::SmallVectorTemplateBase::push_back
void push_back(const T &Elt)
Definition:SmallVector.h:413
llvm::SmallVectorTemplateCommon::front
reference front()
Definition:SmallVector.h:299
llvm::SmallVectorTemplateCommon::data
pointer data()
Return a pointer to the vector's buffer, even if empty().
Definition:SmallVector.h:286
llvm::SmallVectorTemplateCommon::begin
iterator begin()
Definition:SmallVector.h:267
llvm::SmallVectorTemplateCommon::back
reference back()
Definition:SmallVector.h:308
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::StackProtectorDescriptor
Encapsulates all of the information needed to generate a stack protector check, and signals to isel w...
Definition:CodeGenCommonISel.h:116
llvm::StackProtectorDescriptor::getSuccessMBB
MachineBasicBlock * getSuccessMBB()
Definition:CodeGenCommonISel.h:171
llvm::StackProtectorDescriptor::getFailureMBB
MachineBasicBlock * getFailureMBB()
Definition:CodeGenCommonISel.h:172
llvm::StatepointLoweringState::clear
void clear()
Clear the memory usage of this object.
Definition:StatepointLowering.cpp:99
llvm::StoreInst
An instruction for storing to memory.
Definition:Instructions.h:292
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition:StringRef.h:51
llvm::StringRef::empty
constexpr bool empty() const
empty - Check if the string is empty.
Definition:StringRef.h:147
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::StructLayout::getElementOffset
TypeSize getElementOffset(unsigned Idx) const
Definition:DataLayout.h:596
llvm::StructType
Class to represent struct types.
Definition:DerivedTypes.h:218
llvm::SwiftErrorValueTracking::setCurrentVReg
void setCurrentVReg(const MachineBasicBlock *MBB, const Value *, Register)
Set the swifterror virtual register in the VRegDefMap for this basic block.
Definition:SwiftErrorValueTracking.cpp:45
llvm::SwiftErrorValueTracking::getOrCreateVRegUseAt
Register getOrCreateVRegUseAt(const Instruction *, const MachineBasicBlock *, const Value *)
Get or create the swifterror value virtual register for a use of a swifterror by an instruction.
Definition:SwiftErrorValueTracking.cpp:65
llvm::SwiftErrorValueTracking::getOrCreateVRegDefAt
Register getOrCreateVRegDefAt(const Instruction *, const MachineBasicBlock *, const Value *)
Get or create the swifterror value virtual register for a def of a swifterror by an instruction.
Definition:SwiftErrorValueTracking.cpp:50
llvm::SwiftErrorValueTracking::getFunctionArg
const Value * getFunctionArg() const
Get the (unique) function argument that was marked swifterror, or nullptr if this function has no swi...
Definition:SwiftErrorValueTracking.h:72
llvm::SwitchInst
Multiway switch.
Definition:Instructions.h:3154
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::TargetInstrInfo
TargetInstrInfo - Interface to description of machine instruction set.
Definition:TargetInstrInfo.h:112
llvm::TargetIntrinsicInfo
TargetIntrinsicInfo - Interface to description of machine instruction set.
Definition:TargetIntrinsicInfo.h:29
llvm::TargetLibraryInfo
Provides information about what library functions are available for the current target.
Definition:TargetLibraryInfo.h:280
llvm::TargetLibraryInfo::hasOptimizedCodeGen
bool hasOptimizedCodeGen(LibFunc F) const
Tests if the function is both available and a candidate for optimized code generation.
Definition:TargetLibraryInfo.h:407
llvm::TargetLibraryInfo::getLibFunc
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
Definition:TargetLibraryInfo.h:345
llvm::TargetLoweringBase::ArgListEntry
Definition:TargetLowering.h:297
llvm::TargetLoweringBase::ArgListEntry::setAttributes
void setAttributes(const CallBase *Call, unsigned ArgIdx)
Set CallLoweringInfo attribute flags based on a call instruction and called function attributes.
Definition:TargetLowering.cpp:112
llvm::TargetLoweringBase::ArgListEntry::Node
SDValue Node
Definition:TargetLowering.h:300
llvm::TargetLoweringBase::ArgListEntry::Ty
Type * Ty
Definition:TargetLowering.h:301
llvm::TargetLoweringBase::ArgListEntry::IsSwiftError
bool IsSwiftError
Definition:TargetLowering.h:315
llvm::TargetLoweringBase::getByValTypeAlignment
virtual Align getByValTypeAlignment(Type *Ty, const DataLayout &DL) const
Returns the desired alignment for ByVal or InAlloca aggregate function arguments in the caller parame...
Definition:TargetLoweringBase.cpp:1703
llvm::TargetLoweringBase::isFMAFasterThanFMulAndFAdd
virtual bool isFMAFasterThanFMulAndFAdd(const MachineFunction &MF, EVT) const
Return true if an FMA operation is faster than a pair of fmul and fadd instructions.
Definition:TargetLowering.h:3239
llvm::TargetLoweringBase::getMemValueType
EVT getMemValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
Definition:TargetLowering.h:1697
llvm::TargetLoweringBase::getValueType
EVT getValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
Return the EVT corresponding to this LLVM type.
Definition:TargetLowering.h:1677
llvm::TargetLoweringBase::LegalizeAction
LegalizeAction
This enum indicates whether operations are valid for a target, and if not, what action should be used...
Definition:TargetLowering.h:199
llvm::TargetLoweringBase::Custom
@ Custom
Definition:TargetLowering.h:204
llvm::TargetLoweringBase::Legal
@ Legal
Definition:TargetLowering.h:200
llvm::TargetLoweringBase::useStackGuardXorFP
virtual bool useStackGuardXorFP() const
If this function returns true, stack protection checks should XOR the frame pointer (or whichever poi...
Definition:TargetLowering.h:2079
llvm::TargetLoweringBase::getRegClassFor
virtual const TargetRegisterClass * getRegClassFor(MVT VT, bool isDivergent=false) const
Return the register class that should be used for the specified value type.
Definition:TargetLowering.h:1042
llvm::TargetLoweringBase::isLegalScaleForGatherScatter
virtual bool isLegalScaleForGatherScatter(uint64_t Scale, uint64_t ElemSize) const
Definition:TargetLowering.h:1603
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::getJumpConditionMergingParams
virtual CondMergingParams getJumpConditionMergingParams(Instruction::BinaryOps, const Value *, const Value *) const
Definition:TargetLowering.h:649
llvm::TargetLoweringBase::getTargetMachine
const TargetMachine & getTargetMachine() const
Definition:TargetLowering.h:364
llvm::TargetLoweringBase::getNumRegistersForCallingConv
virtual unsigned getNumRegistersForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const
Certain targets require unusual breakdowns of certain types.
Definition:TargetLowering.h:1795
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::getRegisterTypeForCallingConv
virtual MVT getRegisterTypeForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const
Certain combinations of ABIs, Targets and features require that types are legal for some operations a...
Definition:TargetLowering.h:1787
llvm::TargetLoweringBase::TypeLegal
@ TypeLegal
Definition:TargetLowering.h:210
llvm::TargetLoweringBase::getSDagStackGuard
virtual Value * getSDagStackGuard(const Module &M) const
Return the variable that's previously inserted by insertSSPDeclarations, if any, otherwise return nul...
Definition:TargetLoweringBase.cpp:1989
llvm::TargetLoweringBase::getNumRegisters
virtual unsigned getNumRegisters(LLVMContext &Context, EVT VT, std::optional< MVT > RegisterVT=std::nullopt) const
Return the number of registers that this ValueType will eventually require.
Definition:TargetLowering.h:1763
llvm::TargetLoweringBase::isJumpExpensive
bool isJumpExpensive() const
Return true if Flow Control is an expensive operation that should be avoided.
Definition:TargetLowering.h:617
llvm::TargetLoweringBase::getBitWidthForCttzElements
unsigned getBitWidthForCttzElements(Type *RetTy, ElementCount EC, bool ZeroIsPoison, const ConstantRange *VScaleRange) const
Return the minimum number of bits required to hold the maximum possible number of trailing zero vecto...
Definition:TargetLoweringBase.cpp:923
llvm::TargetLoweringBase::shouldExtendGSIndex
virtual bool shouldExtendGSIndex(EVT VT, EVT &EltTy) const
Returns true if the index type for a masked gather/scatter requires extending.
Definition:TargetLowering.h:1592
llvm::TargetLoweringBase::getVectorTypeBreakdownForCallingConv
virtual unsigned getVectorTypeBreakdownForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT, EVT &IntermediateVT, unsigned &NumIntermediates, MVT &RegisterVT) const
Certain targets such as MIPS require that some types such as vectors are always broken down into scal...
Definition:TargetLowering.h:1195
llvm::TargetLoweringBase::getSSPStackGuardCheck
virtual Function * getSSPStackGuardCheck(const Module &M) const
If the target has a standard stack protection check function that performs validation and error handl...
Definition:TargetLoweringBase.cpp:1993
llvm::TargetLoweringBase::getStackPointerRegisterToSaveRestore
Register getStackPointerRegisterToSaveRestore() const
If a physical register, this specifies the register that llvm.savestack/llvm.restorestack should save...
Definition:TargetLowering.h:2015
llvm::TargetLoweringBase::getFixedPointOperationAction
LegalizeAction getFixedPointOperationAction(unsigned Op, EVT VT, unsigned Scale) const
Some fixed point operations may be natively supported by the target but only for specific scales.
Definition:TargetLowering.h:1292
llvm::TargetLoweringBase::getAtomicMemOperandFlags
MachineMemOperand::Flags getAtomicMemOperandFlags(const Instruction &AI, const DataLayout &DL) const
Definition:TargetLoweringBase.cpp:2289
llvm::TargetLoweringBase::getTgtMemIntrinsic
virtual bool getTgtMemIntrinsic(IntrinsicInfo &, const CallInst &, MachineFunction &, unsigned) const
Given an intrinsic, checks if on the target the intrinsic will need to map to a MemIntrinsicNode (tou...
Definition:TargetLowering.h:1226
llvm::TargetLoweringBase::allowsMisalignedMemoryAccesses
virtual bool allowsMisalignedMemoryAccesses(EVT, unsigned AddrSpace=0, Align Alignment=Align(1), MachineMemOperand::Flags Flags=MachineMemOperand::MONone, unsigned *=nullptr) const
Determine if the target supports unaligned memory accesses.
Definition:TargetLowering.h:1918
llvm::TargetLoweringBase::isOperationCustom
bool isOperationCustom(unsigned Op, EVT VT) const
Return true if the operation uses custom lowering, regardless of whether the type is legal or not.
Definition:TargetLowering.h:1380
llvm::TargetLoweringBase::hasBigEndianPartOrdering
bool hasBigEndianPartOrdering(EVT VT, const DataLayout &DL) const
When splitting a value of the specified type into parts, does the Lo or Hi part come first?...
Definition:TargetLowering.h:1839
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::getABIAlignmentForCallingConv
virtual Align getABIAlignmentForCallingConv(Type *ArgTy, const DataLayout &DL) const
Certain targets have context sensitive alignment requirements, where one type has the alignment requi...
Definition:TargetLowering.h:1803
llvm::TargetLoweringBase::shouldExpandGetActiveLaneMask
virtual bool shouldExpandGetActiveLaneMask(EVT VT, EVT OpVT) const
Return true if the @llvm.get.active.lane.mask intrinsic should be expanded using generic code in Sele...
Definition:TargetLowering.h:467
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::getLoadMemOperandFlags
MachineMemOperand::Flags getLoadMemOperandFlags(const LoadInst &LI, const DataLayout &DL, AssumptionCache *AC=nullptr, const TargetLibraryInfo *LibInfo=nullptr) const
Definition:TargetLoweringBase.cpp:2250
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::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::getProgramPointerTy
MVT getProgramPointerTy(const DataLayout &DL) const
Return the type for code pointers, which is determined by the program address space specified through...
Definition:TargetLowering.h:390
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::shouldExpandVectorMatch
virtual bool shouldExpandVectorMatch(EVT VT, unsigned SearchSize) const
Return true if the @llvm.experimental.vector.match intrinsic should be expanded for vector type ‘VT’ ...
Definition:TargetLowering.h:489
llvm::TargetLoweringBase::getFenceOperandTy
virtual MVT getFenceOperandTy(const DataLayout &DL) const
Return the type for operands of fence.
Definition:TargetLowering.h:396
llvm::TargetLoweringBase::shouldExpandGetVectorLength
virtual bool shouldExpandGetVectorLength(EVT CountVT, unsigned VF, bool IsScalable) const
Definition:TargetLowering.h:471
llvm::TargetLoweringBase::isOperationLegalOrCustom
bool isOperationLegalOrCustom(unsigned Op, EVT VT, bool LegalOnly=false) const
Return true if the specified operation is legal on this target or can be made legal with custom lower...
Definition:TargetLowering.h:1339
llvm::TargetLoweringBase::hasFastEqualityCompare
virtual MVT hasFastEqualityCompare(unsigned NumBits) const
Return the preferred operand type if the target has a quick way to compare integer values of the give...
Definition:TargetLowering.h:780
llvm::TargetLoweringBase::getStoreMemOperandFlags
MachineMemOperand::Flags getStoreMemOperandFlags(const StoreInst &SI, const DataLayout &DL) const
Definition:TargetLoweringBase.cpp:2273
llvm::TargetLoweringBase::shouldExpandPartialReductionIntrinsic
virtual bool shouldExpandPartialReductionIntrinsic(const IntrinsicInst *I) const
Return true if the @llvm.experimental.vector.partial.reduce.
Definition:TargetLowering.h:461
llvm::TargetLoweringBase::shouldExpandCttzElements
virtual bool shouldExpandCttzElements(EVT VT) const
Return true if the @llvm.experimental.cttz.elts intrinsic should be expanded using generic code in Se...
Definition:TargetLowering.h:478
llvm::TargetLoweringBase::signExtendConstant
virtual bool signExtendConstant(const ConstantInt *C) const
Return true if this constant should be sign extended when promoting to a larger type.
Definition:TargetLowering.h:3091
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::getExceptionPointerRegister
virtual Register getExceptionPointerRegister(const Constant *PersonalityFn) const
If a physical register, this returns the register that receives the exception address on entry to an ...
Definition:TargetLowering.h:2022
llvm::TargetLoweringBase::supportsUnalignedAtomics
bool supportsUnalignedAtomics() const
Whether the target supports unaligned atomic operations.
Definition:TargetLowering.h:2166
llvm::TargetLoweringBase::ArgListTy
std::vector< ArgListEntry > ArgListTy
Definition:TargetLowering.h:329
llvm::TargetLoweringBase::isBeneficialToExpandPowI
bool isBeneficialToExpandPowI(int64_t Exponent, bool OptForSize) const
Return true if it is beneficial to expand an @llvm.powi.
Definition:TargetLowering.h:2465
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::getExceptionSelectorRegister
virtual Register getExceptionSelectorRegister(const Constant *PersonalityFn) const
If a physical register, this returns the register that receives the exception typeid on entry to a la...
Definition:TargetLowering.h:2029
llvm::TargetLoweringBase::getPointerMemTy
virtual MVT getPointerMemTy(const DataLayout &DL, uint32_t AS=0) const
Return the in-memory pointer type for the given address space, defaults to the pointer type from the ...
Definition:TargetLowering.h:378
llvm::TargetLoweringBase::getRegisterType
MVT getRegisterType(MVT VT) const
Return the type of registers that this ValueType will eventually require.
Definition:TargetLowering.h:1728
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::getVPExplicitVectorLengthTy
virtual MVT getVPExplicitVectorLengthTy() const
Returns the type to be used for the EVL/AVL operand of VP nodes: ISD::VP_ADD, ISD::VP_SUB,...
Definition:TargetLowering.h:429
llvm::TargetLowering
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
Definition:TargetLowering.h:3780
llvm::TargetLowering::supportKCFIBundles
virtual bool supportKCFIBundles() const
Return true if the target supports kcfi operand bundles.
Definition:TargetLowering.h:4401
llvm::TargetLowering::C_RegisterClass
@ C_RegisterClass
Definition:TargetLowering.h:4952
llvm::TargetLowering::C_Memory
@ C_Memory
Definition:TargetLowering.h:4953
llvm::TargetLowering::C_Immediate
@ C_Immediate
Definition:TargetLowering.h:4955
llvm::TargetLowering::C_Register
@ C_Register
Definition:TargetLowering.h:4951
llvm::TargetLowering::C_Other
@ C_Other
Definition:TargetLowering.h:4956
llvm::TargetLowering::C_Address
@ C_Address
Definition:TargetLowering.h:4954
llvm::TargetLowering::C_Unknown
@ C_Unknown
Definition:TargetLowering.h:4957
llvm::TargetLowering::supportPtrAuthBundles
virtual bool supportPtrAuthBundles() const
Return true if the target supports ptrauth operand bundles.
Definition:TargetLowering.h:4404
llvm::TargetLowering::supportSwiftError
virtual bool supportSwiftError() const
Return true if the target supports swifterror attribute.
Definition:TargetLowering.h:4390
llvm::TargetLowering::visitMaskedLoad
virtual SDValue visitMaskedLoad(SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, MachineMemOperand *MMO, SDValue &NewLoad, SDValue Ptr, SDValue PassThru, SDValue Mask) const
Definition:TargetLowering.h:3909
llvm::TargetLowering::emitStackGuardXorFP
virtual SDValue emitStackGuardXorFP(SelectionDAG &DAG, SDValue Val, const SDLoc &DL) const
Definition:TargetLowering.h:5595
llvm::TargetLowering::getTypeForExtReturn
virtual EVT getTypeForExtReturn(LLVMContext &Context, EVT VT, ISD::NodeType) const
Return the type that should be used to zero or sign extend a zeroext/signext integer return value.
Definition:TargetLowering.h:4832
llvm::TargetLowering::makeLibCall
std::pair< SDValue, SDValue > makeLibCall(SelectionDAG &DAG, RTLIB::Libcall LC, EVT RetVT, ArrayRef< SDValue > Ops, MakeLibCallOptions CallOptions, const SDLoc &dl, SDValue Chain=SDValue()) const
Returns a pair of (return value, chain).
Definition:TargetLowering.cpp:147
llvm::TargetLowering::getInlineAsmMemConstraint
virtual InlineAsm::ConstraintCode getInlineAsmMemConstraint(StringRef ConstraintCode) const
Definition:TargetLowering.h:5062
llvm::TargetLowering::AsmOperandInfoVector
std::vector< AsmOperandInfo > AsmOperandInfoVector
Definition:TargetLowering.h:5008
llvm::TargetLowering::expandIS_FPCLASS
SDValue expandIS_FPCLASS(EVT ResultVT, SDValue Op, FPClassTest Test, SDNodeFlags Flags, const SDLoc &DL, SelectionDAG &DAG) const
Expand check for floating point class.
Definition:TargetLowering.cpp:8724
llvm::TargetLowering::prepareVolatileOrAtomicLoad
virtual SDValue prepareVolatileOrAtomicLoad(SDValue Chain, const SDLoc &DL, SelectionDAG &DAG) const
This callback is used to prepare for a volatile or atomic load.
Definition:TargetLowering.h:4876
llvm::TargetLowering::getConstraintType
virtual ConstraintType getConstraintType(StringRef Constraint) const
Given a constraint, return the type of constraint it is for this target.
Definition:TargetLowering.cpp:5525
llvm::TargetLowering::splitValueIntoRegisterParts
virtual bool splitValueIntoRegisterParts(SelectionDAG &DAG, const SDLoc &DL, SDValue Val, SDValue *Parts, unsigned NumParts, MVT PartVT, std::optional< CallingConv::ID > CC) const
Target-specific splitting of values into parts that fit a register storing a legal type.
Definition:TargetLowering.h:4474
llvm::TargetLowering::joinRegisterPartsIntoValue
virtual SDValue joinRegisterPartsIntoValue(SelectionDAG &DAG, const SDLoc &DL, const SDValue *Parts, unsigned NumParts, MVT PartVT, EVT ValueVT, std::optional< CallingConv::ID > CC) const
Target-specific combining of register parts into its original value.
Definition:TargetLowering.h:4499
llvm::TargetLowering::LowerCall
virtual SDValue LowerCall(CallLoweringInfo &, SmallVectorImpl< SDValue > &) const
This hook must be implemented to lower calls into the specified DAG.
Definition:TargetLowering.h:4770
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::LowerAsmOutputForConstraint
virtual SDValue LowerAsmOutputForConstraint(SDValue &Chain, SDValue &Glue, const SDLoc &DL, const AsmOperandInfo &OpInfo, SelectionDAG &DAG) const
Definition:TargetLowering.cpp:5579
llvm::TargetLowering::getRegForInlineAsmConstraint
virtual std::pair< unsigned, const TargetRegisterClass * > getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const
Given a physical register constraint (e.g.
Definition:TargetLowering.cpp:5669
llvm::TargetLowering::LowerFormalArguments
virtual SDValue LowerFormalArguments(SDValue, CallingConv::ID, bool, const SmallVectorImpl< ISD::InputArg > &, const SDLoc &, SelectionDAG &, SmallVectorImpl< SDValue > &) const
This hook must be implemented to lower the incoming (formal) arguments, described by the Ins array,...
Definition:TargetLowering.h:4510
llvm::TargetLowering::ParseConstraints
virtual AsmOperandInfoVector ParseConstraints(const DataLayout &DL, const TargetRegisterInfo *TRI, const CallBase &Call) const
Split up the constraint string from the inline assembly value into the specific constraints and their...
Definition:TargetLowering.cpp:5731
llvm::TargetLowering::LowerOperation
virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const
This callback is invoked for operations that are unsupported by the target, which are registered to u...
Definition:SelectionDAGBuilder.cpp:11372
llvm::TargetLowering::LowerReturn
virtual SDValue LowerReturn(SDValue, CallingConv::ID, bool, const SmallVectorImpl< ISD::OutputArg > &, const SmallVectorImpl< SDValue > &, const SDLoc &, SelectionDAG &) const
This hook must be implemented to lower outgoing return values, described by the Outs array,...
Definition:TargetLowering.h:4793
llvm::TargetLowering::functionArgumentNeedsConsecutiveRegisters
virtual bool functionArgumentNeedsConsecutiveRegisters(Type *Ty, CallingConv::ID CallConv, bool isVarArg, const DataLayout &DL) const
For some targets, an LLVM struct type must be broken down into multiple simple types,...
Definition:TargetLowering.h:4842
llvm::TargetLowering::ComputeConstraintToUse
virtual void ComputeConstraintToUse(AsmOperandInfo &OpInfo, SDValue Op, SelectionDAG *DAG=nullptr) const
Determines the constraint code and constraint type to use for the specific AsmOperandInfo,...
Definition:TargetLowering.cpp:6088
llvm::TargetLowering::CollectTargetIntrinsicOperands
virtual void CollectTargetIntrinsicOperands(const CallInst &I, SmallVectorImpl< SDValue > &Ops, SelectionDAG &DAG) const
Definition:TargetLowering.cpp:5664
llvm::TargetLowering::visitMaskedStore
virtual SDValue visitMaskedStore(SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, MachineMemOperand *MMO, SDValue Ptr, SDValue Val, SDValue Mask) const
Definition:TargetLowering.h:3916
llvm::TargetLowering::useLoadStackGuardNode
virtual bool useLoadStackGuardNode(const Module &M) const
If this function returns true, SelectionDAGBuilder emits a LOAD_STACK_GUARD node when it is lowering ...
Definition:TargetLowering.h:5593
llvm::TargetLowering::LowerAsmOperandForConstraint
virtual void LowerAsmOperandForConstraint(SDValue Op, StringRef Constraint, std::vector< SDValue > &Ops, SelectionDAG &DAG) const
Lower the specified operand into the Ops vector.
Definition:TargetLowering.cpp:5587
llvm::TargetLowering::LowerOperationWrapper
virtual void LowerOperationWrapper(SDNode *N, SmallVectorImpl< SDValue > &Results, SelectionDAG &DAG) const
This callback is invoked by the type legalizer to legalize nodes with an illegal operand type but leg...
Definition:SelectionDAGBuilder.cpp:11347
llvm::TargetLowering::isInlineAsmTargetBranch
virtual bool isInlineAsmTargetBranch(const SmallVectorImpl< StringRef > &AsmStrs, unsigned OpNo) const
On x86, return true if the operand with index OpNo is a CALL or JUMP instruction, which can use eithe...
Definition:TargetLowering.h:3890
llvm::TargetLowering::getJumpTableRegTy
virtual MVT getJumpTableRegTy(const DataLayout &DL) const
Definition:TargetLowering.h:3857
llvm::TargetLowering::CanLowerReturn
virtual bool CanLowerReturn(CallingConv::ID, MachineFunction &, bool, const SmallVectorImpl< ISD::OutputArg > &, LLVMContext &, const Type *RetTy) const
This hook should be implemented to check whether the return values described by the Outs array can fi...
Definition:TargetLowering.h:4781
llvm::TargetMachine::getOptLevel
CodeGenOptLevel getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
Definition:TargetMachine.h:257
llvm::TargetMachine::getIntrinsicInfo
virtual const TargetIntrinsicInfo * getIntrinsicInfo() const
If intrinsic information is available, return it. If not, return null.
Definition:TargetMachine.h:219
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::getTargetTransformInfo
virtual TargetTransformInfo getTargetTransformInfo(const Function &F) const
Return a TargetTransformInfo for a given function.
Definition:TargetMachine.cpp:266
llvm::TargetMachine::Options
TargetOptions Options
Definition:TargetMachine.h:118
llvm::TargetMachine::getCodeModel
CodeModel::Model getCodeModel() const
Returns the code model.
Definition:TargetMachine.h:232
llvm::TargetOptions
Definition:TargetOptions.h:132
llvm::TargetOptions::NoNaNsFPMath
unsigned NoNaNsFPMath
NoNaNsFPMath - This flag is enabled when the -enable-no-nans-fp-math flag is specified on the command...
Definition:TargetOptions.h:188
llvm::TargetOptions::EnableFastISel
unsigned EnableFastISel
EnableFastISel - This flag enables fast-path instruction selection which trades away generated code q...
Definition:TargetOptions.h:245
llvm::TargetOptions::NoTrapAfterNoreturn
unsigned NoTrapAfterNoreturn
Do not emit a trap instruction for 'unreachable' IR instructions behind noreturn calls,...
Definition:TargetOptions.h:291
llvm::TargetOptions::TrapUnreachable
unsigned TrapUnreachable
Emit target-specific trap instruction for 'unreachable' IR instructions.
Definition:TargetOptions.h:287
llvm::TargetOptions::AllowFPOpFusion
FPOpFusion::FPOpFusionMode AllowFPOpFusion
AllowFPOpFusion - This flag is set by the -fp-contract=xxx option.
Definition:TargetOptions.h:420
llvm::TargetRegisterClass
Definition:TargetRegisterInfo.h:44
llvm::TargetRegisterClass::getID
unsigned getID() const
Return the register class ID number.
Definition:TargetRegisterInfo.h:73
llvm::TargetRegisterClass::end
iterator end() const
Definition:TargetRegisterInfo.h:78
llvm::TargetRegisterClass::begin
iterator begin() const
begin/end - Return all of the registers in this class.
Definition:TargetRegisterInfo.h:77
llvm::TargetRegisterInfo
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Definition:TargetRegisterInfo.h:235
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::getInstrInfo
virtual const TargetInstrInfo * getInstrInfo() const
Definition:TargetSubtargetInfo.h:97
llvm::TargetTransformInfo
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Definition:TargetTransformInfo.h:212
llvm::TargetTransformInfo::TCK_Latency
@ TCK_Latency
The latency of instruction.
Definition:TargetTransformInfo.h:265
llvm::TargetTransformInfo::getInstructionCost
InstructionCost getInstructionCost(const User *U, ArrayRef< const Value * > Operands, TargetCostKind CostKind) const
Estimate the cost of a given IR user when lowered.
Definition:TargetTransformInfo.cpp:270
llvm::TargetTransformInfo::hasConditionalLoadStoreForType
bool hasConditionalLoadStoreForType(Type *Ty=nullptr) const
Definition:TargetTransformInfo.cpp:763
llvm::Target
Target - Wrapper for Target specific information.
Definition:TargetRegistry.h:144
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition:Triple.h:44
llvm::Triple::x86_64
@ x86_64
Definition:Triple.h:86
llvm::Triple::getArch
ArchType getArch() const
Get the parsed architecture type of this triple.
Definition:Triple.h:395
llvm::Triple::isAArch64
bool isAArch64() const
Tests whether the target is AArch64 (little and big endian).
Definition:Triple.h:951
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::isPointerTy
bool isPointerTy() const
True if this is an instance of PointerType.
Definition:Type.h:264
llvm::Type::getInt1Ty
static IntegerType * getInt1Ty(LLVMContext &C)
llvm::Type::getPointerAddressSpace
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
llvm::Type::TypeID
TypeID
Definitions of all of the base types for the Type system.
Definition:Type.h:54
llvm::Type::getIntNTy
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
llvm::Type::getVoidTy
static Type * getVoidTy(LLVMContext &C)
llvm::Type::getContext
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition:Type.h:128
llvm::Type::isIntegerTy
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition:Type.h:237
llvm::Type::isTokenTy
bool isTokenTy() const
Return true if this is 'token'.
Definition:Type.h:234
llvm::Type::isFPOrFPVectorTy
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
Definition:Type.h:225
llvm::Type::isVoidTy
bool isVoidTy() const
Return true if this is 'void'.
Definition:Type.h:139
llvm::Type::getScalarType
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition:Type.h:355
llvm::UndefValue::get
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Definition:Constants.cpp:1859
llvm::UnreachableInst
This function has undefined behavior.
Definition:Instructions.h:4461
llvm::Use
A Use represents the edge between a Value definition and its users.
Definition:Use.h:43
llvm::User
Definition:User.h:44
llvm::User::getOperand
Value * getOperand(unsigned i) const
Definition:User.h:228
llvm::VAArgInst
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
Definition:Instructions.h:1741
llvm::VPCmpIntrinsic
Definition:IntrinsicInst.h:689
llvm::VPCmpIntrinsic::getPredicate
CmpInst::Predicate getPredicate() const
Definition:IntrinsicInst.cpp:773
llvm::VPIntrinsic
This is the common base class for vector predication intrinsics.
Definition:IntrinsicInst.h:566
llvm::VPIntrinsic::getVectorLengthParamPos
static std::optional< unsigned > getVectorLengthParamPos(Intrinsic::ID IntrinsicID)
Definition:IntrinsicInst.cpp:413
llvm::VPIntrinsic::getPointerAlignment
MaybeAlign getPointerAlignment() const
Definition:IntrinsicInst.cpp:427
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::Value::hasOneUse
bool hasOneUse() const
Return true if there is exactly one use of this value.
Definition:Value.h:434
llvm::Value::users
iterator_range< user_iterator > users()
Definition:Value.h:421
llvm::Value::getContext
LLVMContext & getContext() const
All values hold a context through their type.
Definition:Value.cpp:1075
llvm::Value::getName
StringRef getName() const
Return a constant reference to the value's name.
Definition:Value.cpp:309
llvm::VectorType
Base class of all SIMD vector types.
Definition:DerivedTypes.h:427
llvm::VectorType::getElementType
Type * getElementType() const
Definition:DerivedTypes.h:460
llvm::cl::opt
Definition:CommandLine.h:1423
llvm::details::FixedOrScalableQuantity::getFixedValue
constexpr ScalarTy getFixedValue() const
Definition:TypeSize.h:202
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::getKnownMinValue
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
Definition:TypeSize.h:168
llvm::generic_gep_type_iterator
Definition:GetElementPtrTypeIterator.h:31
llvm::ilist_detail::node_parent_access::getParent
const ParentTy * getParent() const
Definition:ilist_node.h:32
uint16_t
uint32_t
uint64_t
uint8_t
unsigned
Analysis.h
DebugInfo.h
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition:ErrorHandling.h:143
TargetMachine.h
MemRef
Definition:Lint.cpp:87
llvm::AArch64PACKey::IA
@ IA
Definition:AArch64BaseInfo.h:875
llvm::AMDGPU::CPol::NT
@ NT
Definition:SIDefines.h:387
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition:AMDGPUMetadata.h:395
llvm::AMDGPU::Imm
@ Imm
Definition:AMDGPURegBankLegalizeRules.h:105
llvm::ARCCC::Z
@ Z
Definition:ARCInfo.h:41
llvm::ARM_MB::LD
@ LD
Definition:ARMBaseInfo.h:72
llvm::ARM_MB::ST
@ ST
Definition:ARMBaseInfo.h:73
llvm::ARM::ProfileKind::M
@ M
llvm::BitmaskEnumDetail::Mask
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Definition:BitmaskEnum.h:125
llvm::CallingConv::AnyReg
@ AnyReg
OBSOLETED - Used for stack based JavaScript calls.
Definition:CallingConv.h:60
llvm::CallingConv::AMDGPU_CS_Chain
@ AMDGPU_CS_Chain
Used on AMDGPUs to give the middle-end more control over argument placement.
Definition:CallingConv.h:245
llvm::CallingConv::X86_VectorCall
@ X86_VectorCall
MSVC calling convention that passes vectors and vector aggregates in SSE registers.
Definition:CallingConv.h:163
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::CodeModel::Large
@ Large
Definition:CodeGen.h:31
llvm::CodeModel::Small
@ Small
Definition:CodeGen.h:31
llvm::FPOpFusion::Strict
@ Strict
Definition:TargetOptions.h:39
llvm::HexagonISD::JT
@ JT
Definition:HexagonISelLowering.h:52
llvm::ISD::NodeType
NodeType
ISD::NodeType enum - This enum defines the target-independent operators for a SelectionDAG.
Definition:ISDOpcodes.h:40
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::STACKRESTORE
@ STACKRESTORE
STACKRESTORE has two operands, an input chain and a pointer to restore to it returns an output chain.
Definition:ISDOpcodes.h:1197
llvm::ISD::STACKSAVE
@ STACKSAVE
STACKSAVE - STACKSAVE has one operand, an input chain.
Definition:ISDOpcodes.h:1193
llvm::ISD::CTLZ_ZERO_UNDEF
@ CTLZ_ZERO_UNDEF
Definition:ISDOpcodes.h:753
llvm::ISD::CONVERGENCECTRL_ANCHOR
@ CONVERGENCECTRL_ANCHOR
Definition:ISDOpcodes.h:1470
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::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::SET_FPENV
@ SET_FPENV
Sets the current floating-point environment.
Definition:ISDOpcodes.h:1069
llvm::ISD::VECREDUCE_SEQ_FADD
@ VECREDUCE_SEQ_FADD
Generic reduction nodes.
Definition:ISDOpcodes.h:1417
llvm::ISD::FLOG10
@ FLOG10
Definition:ISDOpcodes.h:1008
llvm::ISD::VECREDUCE_SMIN
@ VECREDUCE_SMIN
Definition:ISDOpcodes.h:1450
llvm::ISD::EH_SJLJ_LONGJMP
@ EH_SJLJ_LONGJMP
OUTCHAIN = EH_SJLJ_LONGJMP(INCHAIN, buffer) This corresponds to the eh.sjlj.longjmp intrinsic.
Definition:ISDOpcodes.h:153
llvm::ISD::ATOMIC_LOAD_NAND
@ ATOMIC_LOAD_NAND
Definition:ISDOpcodes.h:1340
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::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::SMULFIX
@ SMULFIX
RESULT = [US]MULFIX(LHS, RHS, SCALE) - Perform fixed point multiplication on 2 integers with the same...
Definition:ISDOpcodes.h:374
llvm::ISD::VAEND
@ VAEND
VAEND, VASTART - VAEND and VASTART have three operands: an input chain, pointer, and a SRCVALUE.
Definition:ISDOpcodes.h:1226
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::RESET_FPENV
@ RESET_FPENV
Set floating-point environment to default state.
Definition:ISDOpcodes.h:1073
llvm::ISD::LLRINT
@ LLRINT
Definition:ISDOpcodes.h:1022
llvm::ISD::ADD
@ ADD
Simple integer binary arithmetic operators.
Definition:ISDOpcodes.h:246
llvm::ISD::SMULFIXSAT
@ SMULFIXSAT
Same as the corresponding unsaturated fixed point instructions, but the result is clamped between the...
Definition:ISDOpcodes.h:380
llvm::ISD::SET_FPMODE
@ SET_FPMODE
Sets the current dynamic floating-point control modes.
Definition:ISDOpcodes.h:1092
llvm::ISD::STRICT_FMA
@ STRICT_FMA
Definition:ISDOpcodes.h:412
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::UMULFIX
@ UMULFIX
Definition:ISDOpcodes.h:375
llvm::ISD::VECTOR_FIND_LAST_ACTIVE
@ VECTOR_FIND_LAST_ACTIVE
Definition:ISDOpcodes.h:1485
llvm::ISD::FATAN2
@ FATAN2
FATAN2 - atan2, inspired by libm.
Definition:ISDOpcodes.h:999
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::RETURNADDR
@ RETURNADDR
Definition:ISDOpcodes.h:101
llvm::ISD::EH_SJLJ_SETUP_DISPATCH
@ EH_SJLJ_SETUP_DISPATCH
OUTCHAIN = EH_SJLJ_SETUP_DISPATCH(INCHAIN) The target initializes the dispatch table here.
Definition:ISDOpcodes.h:157
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::ATOMIC_FENCE
@ ATOMIC_FENCE
OUTCHAIN = ATOMIC_FENCE(INCHAIN, ordering, scope) This corresponds to the fence instruction.
Definition:ISDOpcodes.h:1304
llvm::ISD::RESET_FPMODE
@ RESET_FPMODE
Sets default dynamic floating-point control modes.
Definition:ISDOpcodes.h:1096
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::FATAN
@ FATAN
Definition:ISDOpcodes.h:990
llvm::ISD::FPTRUNC_ROUND
@ FPTRUNC_ROUND
FPTRUNC_ROUND - This corresponds to the fptrunc_round intrinsic.
Definition:ISDOpcodes.h:495
llvm::ISD::FAKE_USE
@ FAKE_USE
FAKE_USE represents a use of the operand but does not do anything.
Definition:ISDOpcodes.h:1383
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::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::INIT_TRAMPOLINE
@ INIT_TRAMPOLINE
INIT_TRAMPOLINE - This corresponds to the init_trampoline intrinsic.
Definition:ISDOpcodes.h:1270
llvm::ISD::FLDEXP
@ FLDEXP
FLDEXP - ldexp, inspired by libm (op0 * 2**op1).
Definition:ISDOpcodes.h:997
llvm::ISD::SDIVFIX
@ SDIVFIX
RESULT = [US]DIVFIX(LHS, RHS, SCALE) - Perform fixed point division on 2 integers with the same width...
Definition:ISDOpcodes.h:387
llvm::ISD::ATOMIC_LOAD_FADD
@ ATOMIC_LOAD_FADD
Definition:ISDOpcodes.h:1345
llvm::ISD::UCMP
@ UCMP
Definition:ISDOpcodes.h:706
llvm::ISD::SRA
@ SRA
Definition:ISDOpcodes.h:736
llvm::ISD::FrameIndex
@ FrameIndex
Definition:ISDOpcodes.h:80
llvm::ISD::STRICT_FMUL
@ STRICT_FMUL
Definition:ISDOpcodes.h:409
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::EH_RETURN
@ EH_RETURN
OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents 'eh_return' gcc dwarf builtin,...
Definition:ISDOpcodes.h:141
llvm::ISD::ANNOTATION_LABEL
@ ANNOTATION_LABEL
ANNOTATION_LABEL - Represents a mid basic block label used by annotations.
Definition:ISDOpcodes.h:1179
llvm::ISD::SET_ROUNDING
@ SET_ROUNDING
Set rounding mode.
Definition:ISDOpcodes.h:936
llvm::ISD::USUBO
@ USUBO
Definition:ISDOpcodes.h:335
llvm::ISD::CONVERGENCECTRL_GLUE
@ CONVERGENCECTRL_GLUE
Definition:ISDOpcodes.h:1476
llvm::ISD::SIGN_EXTEND
@ SIGN_EXTEND
Conversion operators.
Definition:ISDOpcodes.h:805
llvm::ISD::FLOG2
@ FLOG2
Definition:ISDOpcodes.h:1007
llvm::ISD::PREALLOCATED_SETUP
@ PREALLOCATED_SETUP
PREALLOCATED_SETUP - This has 2 operands: an input chain and a SRCVALUE with the preallocated call Va...
Definition:ISDOpcodes.h:1231
llvm::ISD::READSTEADYCOUNTER
@ READSTEADYCOUNTER
READSTEADYCOUNTER - This corresponds to the readfixedcounter intrinsic.
Definition:ISDOpcodes.h:1259
llvm::ISD::ADDROFRETURNADDR
@ ADDROFRETURNADDR
ADDROFRETURNADDR - Represents the llvm.addressofreturnaddress intrinsic.
Definition:ISDOpcodes.h:107
llvm::ISD::CONVERGENCECTRL_ENTRY
@ CONVERGENCECTRL_ENTRY
Definition:ISDOpcodes.h:1471
llvm::ISD::USHLSAT
@ USHLSAT
Definition:ISDOpcodes.h:367
llvm::ISD::BR
@ BR
Control flow instructions. These all have token chains.
Definition:ISDOpcodes.h:1118
llvm::ISD::UDIVFIXSAT
@ UDIVFIXSAT
Definition:ISDOpcodes.h:394
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::WRITE_REGISTER
@ WRITE_REGISTER
Definition:ISDOpcodes.h:125
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::FSINCOS
@ FSINCOS
FSINCOS - Compute both fsin and fcos as a single operation.
Definition:ISDOpcodes.h:1059
llvm::ISD::ATOMIC_LOAD_FSUB
@ ATOMIC_LOAD_FSUB
Definition:ISDOpcodes.h:1346
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::PREALLOCATED_ARG
@ PREALLOCATED_ARG
PREALLOCATED_ARG - This has 3 operands: an input chain, a SRCVALUE with the preallocated call Value,...
Definition:ISDOpcodes.h:1234
llvm::ISD::FP_TO_UINT
@ FP_TO_UINT
Definition:ISDOpcodes.h:888
llvm::ISD::BRIND
@ BRIND
BRIND - Indirect branch.
Definition:ISDOpcodes.h:1123
llvm::ISD::BR_JT
@ BR_JT
BR_JT - Jumptable branch.
Definition:ISDOpcodes.h:1127
llvm::ISD::VECTOR_INTERLEAVE
@ VECTOR_INTERLEAVE
VECTOR_INTERLEAVE(VEC1, VEC2) - Returns two vectors with all input and output vectors having the same...
Definition:ISDOpcodes.h:601
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::IS_FPCLASS
@ IS_FPCLASS
Performs a check of floating point class property, defined by IEEE-754.
Definition:ISDOpcodes.h:522
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::SELECT
@ SELECT
Select(COND, TRUEVAL, FALSEVAL).
Definition:ISDOpcodes.h:757
llvm::ISD::ATOMIC_LOAD
@ ATOMIC_LOAD
Val, OUTCHAIN = ATOMIC_LOAD(INCHAIN, ptr) This corresponds to "load atomic" instruction.
Definition:ISDOpcodes.h:1308
llvm::ISD::VECREDUCE_UMAX
@ VECREDUCE_UMAX
Definition:ISDOpcodes.h:1451
llvm::ISD::FTANH
@ FTANH
Definition:ISDOpcodes.h:993
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::VACOPY
@ VACOPY
VACOPY - VACOPY has 5 operands: an input chain, a destination pointer, a source pointer,...
Definition:ISDOpcodes.h:1222
llvm::ISD::FSHL
@ FSHL
Definition:ISDOpcodes.h:740
llvm::ISD::ATOMIC_LOAD_FMIN
@ ATOMIC_LOAD_FMIN
Definition:ISDOpcodes.h:1348
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::ARITH_FENCE
@ ARITH_FENCE
ARITH_FENCE - This corresponds to a arithmetic fence intrinsic.
Definition:ISDOpcodes.h:1296
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::GET_ROUNDING
@ GET_ROUNDING
Returns current rounding mode: -1 Undefined 0 Round to 0 1 Round to nearest, ties to even 2 Round to ...
Definition:ISDOpcodes.h:931
llvm::ISD::CLEANUPRET
@ CLEANUPRET
CLEANUPRET - Represents a return from a cleanup block funclet.
Definition:ISDOpcodes.h:1188
llvm::ISD::GET_FPMODE
@ GET_FPMODE
Reads the current dynamic floating-point control modes.
Definition:ISDOpcodes.h:1087
llvm::ISD::GET_FPENV
@ GET_FPENV
Gets the current floating-point environment.
Definition:ISDOpcodes.h:1064
llvm::ISD::SHL
@ SHL
Shift and rotation operations.
Definition:ISDOpcodes.h:735
llvm::ISD::PtrAuthGlobalAddress
@ PtrAuthGlobalAddress
A ptrauth constant.
Definition:ISDOpcodes.h:90
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::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::READ_REGISTER
@ READ_REGISTER
READ_REGISTER, WRITE_REGISTER - This node represents llvm.register on the DAG, which implements the n...
Definition:ISDOpcodes.h:124
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::ZERO_EXTEND
@ ZERO_EXTEND
ZERO_EXTEND - Used for integer types, zeroing the new bits.
Definition:ISDOpcodes.h:811
llvm::ISD::DEBUGTRAP
@ DEBUGTRAP
DEBUGTRAP - Trap intended to get the attention of a debugger.
Definition:ISDOpcodes.h:1282
llvm::ISD::FP_TO_UINT_SAT
@ FP_TO_UINT_SAT
Definition:ISDOpcodes.h:907
llvm::ISD::CTPOP
@ CTPOP
Definition:ISDOpcodes.h:747
llvm::ISD::FMUL
@ FMUL
Definition:ISDOpcodes.h:399
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_LOAD_UMAX
@ ATOMIC_LOAD_UMAX
Definition:ISDOpcodes.h:1344
llvm::ISD::LOCAL_RECOVER
@ LOCAL_RECOVER
LOCAL_RECOVER - Represents the llvm.localrecover intrinsic.
Definition:ISDOpcodes.h:120
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::UBSANTRAP
@ UBSANTRAP
UBSANTRAP - Trap with an immediate describing the kind of sanitizer failure.
Definition:ISDOpcodes.h:1286
llvm::ISD::SSHLSAT
@ SSHLSAT
RESULT = [US]SHLSAT(LHS, RHS) - Perform saturation left shift.
Definition:ISDOpcodes.h:366
llvm::ISD::PATCHPOINT
@ PATCHPOINT
Definition:ISDOpcodes.h:1463
llvm::ISD::SMULO
@ SMULO
Same for multiplication.
Definition:ISDOpcodes.h:338
llvm::ISD::VECREDUCE_AND
@ VECREDUCE_AND
Definition:ISDOpcodes.h:1446
llvm::ISD::DYNAMIC_STACKALLOC
@ DYNAMIC_STACKALLOC
DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned to a specified boundary.
Definition:ISDOpcodes.h:1112
llvm::ISD::UDIVFIX
@ UDIVFIX
Definition:ISDOpcodes.h:388
llvm::ISD::UMULFIXSAT
@ UMULFIXSAT
Definition:ISDOpcodes.h:381
llvm::ISD::SMIN
@ SMIN
[US]{MIN/MAX} - Binary minimum or maximum of signed or unsigned integers.
Definition:ISDOpcodes.h:697
llvm::ISD::VECTOR_REVERSE
@ VECTOR_REVERSE
VECTOR_REVERSE(VECTOR) - Returns a vector, of the same type as VECTOR, whose elements are shuffled us...
Definition:ISDOpcodes.h:606
llvm::ISD::SDIVFIXSAT
@ SDIVFIXSAT
Same as the corresponding unsaturated fixed point instructions, but the result is clamped between the...
Definition:ISDOpcodes.h:393
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::FROUNDEVEN
@ FROUNDEVEN
Definition:ISDOpcodes.h:1017
llvm::ISD::VECREDUCE_MUL
@ VECREDUCE_MUL
Definition:ISDOpcodes.h:1445
llvm::ISD::VECREDUCE_UMIN
@ VECREDUCE_UMIN
Definition:ISDOpcodes.h:1452
llvm::ISD::PCMARKER
@ PCMARKER
PCMARKER - This corresponds to the pcmarker intrinsic.
Definition:ISDOpcodes.h:1245
llvm::ISD::INLINEASM_BR
@ INLINEASM_BR
INLINEASM_BR - Branching version of inline asm. Used by asm-goto.
Definition:ISDOpcodes.h:1168
llvm::ISD::EH_DWARF_CFA
@ EH_DWARF_CFA
EH_DWARF_CFA - This node represents the pointer to the DWARF Canonical Frame Address (CFA),...
Definition:ISDOpcodes.h:135
llvm::ISD::FDIV
@ FDIV
Definition:ISDOpcodes.h:400
llvm::ISD::FRAMEADDR
@ FRAMEADDR
FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and llvm.returnaddress on the DAG.
Definition:ISDOpcodes.h:100
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::READCYCLECOUNTER
@ READCYCLECOUNTER
READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
Definition:ISDOpcodes.h:1253
llvm::ISD::AND
@ AND
Bitwise operators - logical and, logical or, logical xor.
Definition:ISDOpcodes.h:709
llvm::ISD::TRAP
@ TRAP
TRAP - Trapping instruction.
Definition:ISDOpcodes.h:1279
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::FLOG
@ FLOG
Definition:ISDOpcodes.h:1006
llvm::ISD::SCMP
@ SCMP
[US]CMP - 3-way comparison of signed or unsigned integers.
Definition:ISDOpcodes.h:705
llvm::ISD::VECREDUCE_FMUL
@ VECREDUCE_FMUL
Definition:ISDOpcodes.h:1433
llvm::ISD::STRICT_FADD
@ STRICT_FADD
Constrained versions of the binary floating point operators.
Definition:ISDOpcodes.h:407
llvm::ISD::STACKMAP
@ STACKMAP
Definition:ISDOpcodes.h:1457
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::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::SPONENTRY
@ SPONENTRY
SPONENTRY - Represents the llvm.sponentry intrinsic.
Definition:ISDOpcodes.h:112
llvm::ISD::CLEAR_CACHE
@ CLEAR_CACHE
Definition:ISDOpcodes.h:1490
llvm::ISD::CONVERGENCECTRL_LOOP
@ CONVERGENCECTRL_LOOP
Definition:ISDOpcodes.h:1472
llvm::ISD::VASTART
@ VASTART
Definition:ISDOpcodes.h:1227
llvm::ISD::FSQRT
@ FSQRT
Definition:ISDOpcodes.h:983
llvm::ISD::INLINEASM
@ INLINEASM
INLINEASM - Represents an inline asm block.
Definition:ISDOpcodes.h:1165
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::EH_SJLJ_SETJMP
@ EH_SJLJ_SETJMP
RESULT, OUTCHAIN = EH_SJLJ_SETJMP(INCHAIN, buffer) This corresponds to the eh.sjlj....
Definition:ISDOpcodes.h:147
llvm::ISD::TRUNCATE
@ TRUNCATE
TRUNCATE - Completely drop the high bits.
Definition:ISDOpcodes.h:817
llvm::ISD::BRCOND
@ BRCOND
BRCOND - Conditional branch.
Definition:ISDOpcodes.h:1141
llvm::ISD::ROTL
@ ROTL
Definition:ISDOpcodes.h:738
llvm::ISD::VECREDUCE_SEQ_FMUL
@ VECREDUCE_SEQ_FMUL
Definition:ISDOpcodes.h:1418
llvm::ISD::CATCHRET
@ CATCHRET
CATCHRET - Represents a return from a catch block funclet.
Definition:ISDOpcodes.h:1184
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::VECTOR_DEINTERLEAVE
@ VECTOR_DEINTERLEAVE
VECTOR_DEINTERLEAVE(VEC1, VEC2) - Returns two vectors with all input and output vectors having the sa...
Definition:ISDOpcodes.h:595
llvm::ISD::GET_DYNAMIC_AREA_OFFSET
@ GET_DYNAMIC_AREA_OFFSET
GET_DYNAMIC_AREA_OFFSET - get offset from native SP to the address of the most recent dynamic alloca.
Definition:ISDOpcodes.h:1398
llvm::ISD::UMAX
@ UMAX
Definition:ISDOpcodes.h:700
llvm::ISD::FMINIMUMNUM
@ FMINIMUMNUM
FMINIMUMNUM/FMAXIMUMNUM - minimumnum/maximumnum that is same with FMINNUM_IEEE and FMAXNUM_IEEE besid...
Definition:ISDOpcodes.h:1055
llvm::ISD::ADJUST_TRAMPOLINE
@ ADJUST_TRAMPOLINE
ADJUST_TRAMPOLINE - This corresponds to the adjust_trampoline intrinsic.
Definition:ISDOpcodes.h:1276
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::BUILD_VECTOR
@ BUILD_VECTOR
BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a fixed-width vector with the specified,...
Definition:ISDOpcodes.h:530
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::SIGNED_SCALED
@ SIGNED_SCALED
Definition:ISDOpcodes.h:1572
llvm::ISD::UNINDEXED
@ UNINDEXED
Definition:ISDOpcodes.h:1559
llvm::ISD::CondCode
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out,...
Definition:ISDOpcodes.h:1610
llvm::ISD::SETNE
@ SETNE
Definition:ISDOpcodes.h:1635
llvm::ISD::SETUGT
@ SETUGT
Definition:ISDOpcodes.h:1622
llvm::ISD::SETULT
@ SETULT
Definition:ISDOpcodes.h:1624
llvm::ISD::SETLT
@ SETLT
Definition:ISDOpcodes.h:1633
llvm::ISD::SETTRUE
@ SETTRUE
Definition:ISDOpcodes.h:1627
llvm::ISD::SETLE
@ SETLE
Definition:ISDOpcodes.h:1634
llvm::ISD::SETULE
@ SETULE
Definition:ISDOpcodes.h:1625
llvm::ISD::SETEQ
@ SETEQ
Definition:ISDOpcodes.h:1630
llvm::ISD::NON_EXTLOAD
@ NON_EXTLOAD
Definition:ISDOpcodes.h:1590
llvm::M68k::MemAddrModeKind::j
@ j
llvm::M68k::MemAddrModeKind::V
@ V
llvm::M68k::MemAddrModeKind::L
@ L
llvm::MCID::Flag
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Definition:MCInstrDesc.h:148
llvm::MCID::Call
@ Call
Definition:MCInstrDesc.h:156
llvm::MCID::Return
@ Return
Definition:MCInstrDesc.h:154
llvm::MipsISD::Ret
@ Ret
Definition:MipsISelLowering.h:117
llvm::MipsISD::FPCmp
@ FPCmp
Definition:MipsISelLowering.h:98
llvm::MipsISD::Ext
@ Ext
Definition:MipsISelLowering.h:157
llvm::MipsISD::Ins
@ Ins
Definition:MipsISelLowering.h:158
llvm::NVPTX::PTXLdStInstCode::V2
@ V2
Definition:NVPTX.h:163
llvm::NVPTX::Ordering
Ordering
Definition:NVPTX.h:116
llvm::PatternMatch::match
bool match(Val *V, const Pattern &P)
Definition:PatternMatch.h:49
llvm::PatternMatch::m_Specific
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
Definition:PatternMatch.h:885
llvm::PatternMatch::m_ExtractElt
TwoOps_match< Val_t, Idx_t, Instruction::ExtractElement > m_ExtractElt(const Val_t &Val, const Idx_t &Idx)
Matches ExtractElementInst.
Definition:PatternMatch.h:1837
llvm::PatternMatch::m_OneUse
OneUse_match< T > m_OneUse(const T &SubPattern)
Definition:PatternMatch.h:67
llvm::PatternMatch::m_LogicalOr
auto m_LogicalOr()
Matches L || R where L and R are arbitrary values.
Definition:PatternMatch.h:3099
llvm::PatternMatch::m_VScale
VScaleVal_match m_VScale()
Definition:PatternMatch.h:3010
llvm::PatternMatch::m_Value
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
Definition:PatternMatch.h:92
llvm::PatternMatch::m_LogicalAnd
auto m_LogicalAnd()
Matches L && R where L and R are arbitrary values.
Definition:PatternMatch.h:3081
llvm::PatternMatch::m_Not
BinaryOp_match< cst_pred_ty< is_all_ones >, ValTy, Instruction::Xor, true > m_Not(const ValTy &V)
Matches a 'Not' as 'xor V, -1' or 'xor -1, V'.
Definition:PatternMatch.h:2467
llvm::RISCVFenceField::W
@ W
Definition:RISCVBaseInfo.h:374
llvm::RISCVFenceField::R
@ R
Definition:RISCVBaseInfo.h:373
llvm::SIEncodingFamily::VI
@ VI
Definition:SIDefines.h:37
llvm::SIEncodingFamily::SI
@ SI
Definition:SIDefines.h:36
llvm::SI::KernelInputOffsets::Offsets
Offsets
Offsets in bytes from the start of the input buffer.
Definition:SIInstrInfo.h:1612
llvm::SPII::Store
@ Store
Definition:SparcInstrInfo.h:33
llvm::SPII::Load
@ Load
Definition:SparcInstrInfo.h:32
llvm::SwitchCG::CaseClusterVector
std::vector< CaseCluster > CaseClusterVector
Definition:SwitchLoweringUtils.h:86
llvm::SwitchCG::sortAndRangeify
void sortAndRangeify(CaseClusterVector &Clusters)
Sort Clusters and merge adjacent cases.
Definition:SwitchLoweringUtils.cpp:467
llvm::SwitchCG::CaseClusterIt
CaseClusterVector::iterator CaseClusterIt
Definition:SwitchLoweringUtils.h:87
llvm::SwitchCG::JumpTableBlock
std::pair< JumpTableHeader, JumpTable > JumpTableBlock
Definition:SwitchLoweringUtils.h:202
llvm::SwitchCG::CC_Range
@ CC_Range
A cluster of adjacent case labels with the same destination, or just one case.
Definition:SwitchLoweringUtils.h:34
llvm::SwitchCG::CC_JumpTable
@ CC_JumpTable
A cluster of cases suitable for jump table lowering.
Definition:SwitchLoweringUtils.h:36
llvm::SwitchCG::CC_BitTests
@ CC_BitTests
A cluster of cases suitable for bit test lowering.
Definition:SwitchLoweringUtils.h:38
llvm::X86Disassembler::Reg
Reg
All possible values of the reg field in the ModR/M byte.
Definition:X86DisassemblerDecoder.h:621
llvm::X86::FirstMacroFusionInstKind::Cmp
@ Cmp
llvm::cl::Hidden
@ Hidden
Definition:CommandLine.h:137
llvm::cl::ReallyHidden
@ ReallyHidden
Definition:CommandLine.h:138
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition:CommandLine.h:443
llvm::cl::location
LocationClass< Ty > location(Ty &L)
Definition:CommandLine.h:463
llvm::codeview::ClassOptions::Intrinsic
@ Intrinsic
llvm::dwarf_linker::DebugSectionKind::DebugStr
@ DebugStr
llvm::dwarf::Index
Index
Definition:Dwarf.h:882
llvm::dwarf::DW_OP_LLVM_arg
@ DW_OP_LLVM_arg
Only used in LLVM metadata.
Definition:Dwarf.h:147
llvm::dxil::OpCode
OpCode
Definition:DXILConstants.h:18
llvm::fp::ExceptionBehavior
ExceptionBehavior
Exception behavior used for floating point operations.
Definition:FPEnv.h:38
llvm::fp::ebStrict
@ ebStrict
This corresponds to "fpexcept.strict".
Definition:FPEnv.h:41
llvm::fp::ebMayTrap
@ ebMayTrap
This corresponds to "fpexcept.maytrap".
Definition:FPEnv.h:40
llvm::fp::ebIgnore
@ ebIgnore
This corresponds to "fpexcept.ignore".
Definition:FPEnv.h:39
llvm::ifs::IFSEndiannessType::Big
@ Big
llvm::lltok::Kind
Kind
Definition:LLToken.h:18
llvm::logicalview::LVWarningKind::Ranges
@ Ranges
llvm::ms_demangle::QualifierMangleMode::Result
@ Result
llvm::numbers::log2ef
constexpr float log2ef
Definition:MathExtras.h:66
llvm::numbers::e
constexpr double e
Definition:MathExtras.h:47
llvm::numbers::ln2f
constexpr float ln2f
Definition:MathExtras.h:64
llvm::objcopy::SymbolFlag::Indirect
@ Indirect
llvm::omp::RTLDependInfoFields::Flags
@ Flags
llvm::pdb::PDB_BuiltinType::Char
@ Char
llvm::pdb::PDB_SymType::Label
@ Label
llvm::pdb::PDB_SymType::Callee
@ Callee
llvm::pdb::PDB_LocType::Slot
@ Slot
llvm::pdb::PDB_DataKind::ObjectPtr
@ ObjectPtr
llvm::pdb::DbgHeaderType::Max
@ Max
llvm::rdf::Func
NodeAddr< FuncNode * > Func
Definition:RDFGraph.h:393
llvm::sampleprof::Base
@ Base
Definition:Discriminator.h:58
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::ThreadPriority::Low
@ Low
Lower the current thread's priority such that it does not affect foreground tasks significantly.
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::Length
@ Length
Definition:DWP.cpp:480
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::CGDataKind::Unknown
@ Unknown
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::popcount
int popcount(T Value) noexcept
Count the number of set bits in a value.
Definition:bit.h:385
llvm::size
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition:STLExtras.h:1697
llvm::GetReturnInfo
void GetReturnInfo(CallingConv::ID CC, Type *ReturnType, AttributeList attr, SmallVectorImpl< ISD::OutputArg > &Outs, const TargetLowering &TLI, const DataLayout &DL)
Given an LLVM IR type and return type attributes, compute the return value EVTs and flags,...
Definition:TargetLoweringBase.cpp:1661
llvm::BuildMI
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
Definition:MachineInstrBuilder.h:373
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::isOnlyUsedInZeroEqualityComparison
bool isOnlyUsedInZeroEqualityComparison(const Instruction *CxtI)
Definition:ValueTracking.cpp:273
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::Done
@ Done
Definition:Threading.h:60
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::diagnoseDontCall
void diagnoseDontCall(const CallInst &CI)
Definition:DiagnosticInfo.cpp:459
llvm::LibFunc
LibFunc
Definition:TargetLibraryInfo.h:68
llvm::successors
auto successors(const MachineBasicBlock *BB)
Definition:MachineBasicBlock.h:1376
llvm::isIntOrFPConstant
bool isIntOrFPConstant(SDValue V)
Return true if V is either a integer or FP constant.
Definition:SelectionDAGNodes.h:1872
llvm::append_range
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition:STLExtras.h:2115
llvm::GetPointerBaseWithConstantOffset
Value * GetPointerBaseWithConstantOffset(Value *Ptr, int64_t &Offset, const DataLayout &DL, bool AllowNonInbounds=true)
Analyze the specified pointer to see if it can be expressed as a base pointer plus a constant offset.
Definition:ValueTracking.h:639
llvm::alignDown
constexpr T alignDown(U Value, V Align, W Skew=0)
Returns the largest unsigned integer less than or equal to Value and is Skew mod Align.
Definition:MathExtras.h:556
llvm::gep_type_end
gep_type_iterator gep_type_end(const User *GEP)
Definition:GetElementPtrTypeIterator.h:180
llvm::getConstantRangeFromMetadata
ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD)
Parse out a conservative ConstantRange from !range metadata.
Definition:ConstantRange.cpp:2264
llvm::isScopedEHPersonality
bool isScopedEHPersonality(EHPersonality Pers)
Returns true if this personality uses scope-style EH IR instructions: catchswitch,...
Definition:EHPersonalities.h:80
llvm::countr_zero
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
Definition:bit.h:215
llvm::EHPersonality
EHPersonality
Definition:EHPersonalities.h:21
llvm::EHPersonality::CoreCLR
@ CoreCLR
llvm::EHPersonality::Wasm_CXX
@ Wasm_CXX
llvm::EHPersonality::MSVC_CXX
@ MSVC_CXX
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::createStrideMask
llvm::SmallVector< int, 16 > createStrideMask(unsigned Start, unsigned Stride, unsigned VF)
Create a stride shuffle mask.
Definition:VectorUtils.cpp:1032
llvm::SPF_ABS
@ SPF_ABS
Floating point maxnum.
Definition:ValueTracking.h:1121
llvm::SPF_NABS
@ SPF_NABS
Absolute value.
Definition:ValueTracking.h:1122
llvm::SPF_FMAXNUM
@ SPF_FMAXNUM
Floating point minnum.
Definition:ValueTracking.h:1120
llvm::SPF_UMIN
@ SPF_UMIN
Signed minimum.
Definition:ValueTracking.h:1116
llvm::SPF_UMAX
@ SPF_UMAX
Signed maximum.
Definition:ValueTracking.h:1118
llvm::SPF_SMIN
@ SPF_SMIN
Definition:ValueTracking.h:1115
llvm::SPF_SMAX
@ SPF_SMAX
Unsigned minimum.
Definition:ValueTracking.h:1117
llvm::SPF_FMINNUM
@ SPF_FMINNUM
Unsigned maximum.
Definition:ValueTracking.h:1119
llvm::get
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
Definition:PointerIntPair.h:270
llvm::zip_first
detail::zippy< detail::zip_first, T, U, Args... > zip_first(T &&t, U &&u, Args &&...args)
zip iterator that, for the sake of efficiency, assumes the first iteratee to be the shortest.
Definition:STLExtras.h:877
llvm::sort
void sort(IteratorTy Start, IteratorTy End)
Definition:STLExtras.h:1664
llvm::ComplexDeinterleavingOperation::Splat
@ Splat
llvm::FPClassTest
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
Definition:FloatingPointMode.h:239
llvm::matchSelectPattern
SelectPatternResult matchSelectPattern(Value *V, Value *&LHS, Value *&RHS, Instruction::CastOps *CastOp=nullptr, unsigned Depth=0)
Pattern match integer [SU]MIN, [SU]MAX and ABS idioms, returning the kind and providing the out param...
Definition:ValueTracking.cpp:9054
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition:Debug.cpp:163
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::succ_size
auto succ_size(const MachineBasicBlock *BB)
Definition:MachineBasicBlock.h:1380
llvm::hasSingleElement
bool hasSingleElement(ContainerTy &&C)
Returns true if the given container only contains a single element.
Definition:STLExtras.h:322
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:1063
llvm::getFCmpCondCode
ISD::CondCode getFCmpCondCode(FCmpInst::Predicate Pred)
getFCmpCondCode - Return the ISD condition code corresponding to the given LLVM IR floating-point con...
Definition:Analysis.cpp:199
llvm::classifyEHPersonality
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
Definition:EHPersonalities.cpp:23
llvm::CaptureComponents::Address
@ Address
llvm::CodeGenOptLevel::None
@ None
-O0
llvm::salvageDebugInfoImpl
Value * salvageDebugInfoImpl(Instruction &I, uint64_t CurrentLocOps, SmallVectorImpl< uint64_t > &Ops, SmallVectorImpl< Value * > &AdditionalValues)
Definition:Local.cpp:2617
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition:raw_ostream.cpp:907
llvm::AsanDtorKind::Global
@ Global
Append to llvm.global_dtors.
llvm::PackElem::Hi
@ Hi
llvm::PackElem::Lo
@ Lo
llvm::AtomicOrdering
AtomicOrdering
Atomic ordering for LLVM's memory model.
Definition:AtomicOrdering.h:56
llvm::IRMemLocation::First
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
llvm::isFuncletEHPersonality
bool isFuncletEHPersonality(EHPersonality Pers)
Returns true if this is a personality function that invokes handler funclets (which must return to it...
Definition:EHPersonalities.h:65
llvm::isAssignmentTrackingEnabled
bool isAssignmentTrackingEnabled(const Module &M)
Return true if assignment tracking is enabled for module M.
Definition:DebugInfo.cpp:2299
llvm::createInterleaveMask
llvm::SmallVector< int, 16 > createInterleaveMask(unsigned VF, unsigned NumVecs)
Create an interleave shuffle mask.
Definition:VectorUtils.cpp:1021
llvm::RecurKind::UMin
@ UMin
Unsigned integer min implemented in terms of select(cmp()).
llvm::RecurKind::Or
@ Or
Bitwise or logical OR of integers.
llvm::RecurKind::Mul
@ Mul
Product of integers.
llvm::RecurKind::And
@ And
Bitwise or logical AND of integers.
llvm::RecurKind::Add
@ Add
Sum of integers.
llvm::alignTo
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition:Alignment.h:155
llvm::SPNB_RETURNS_NAN
@ SPNB_RETURNS_NAN
NaN behavior not applicable.
Definition:ValueTracking.h:1129
llvm::SPNB_RETURNS_OTHER
@ SPNB_RETURNS_OTHER
Given one NaN input, returns the NaN.
Definition:ValueTracking.h:1130
llvm::SPNB_RETURNS_ANY
@ SPNB_RETURNS_ANY
Given one NaN input, returns the non-NaN.
Definition:ValueTracking.h:1131
llvm::SPNB_NA
@ SPNB_NA
Definition:ValueTracking.h:1128
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::getFCmpCodeWithoutNaN
ISD::CondCode getFCmpCodeWithoutNaN(ISD::CondCode CC)
getFCmpCodeWithoutNaN - Given an ISD condition code comparing floats, return the equivalent code if w...
Definition:Analysis.cpp:221
llvm::ComputeValueVTs
void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty, SmallVectorImpl< EVT > &ValueVTs, SmallVectorImpl< EVT > *MemVTs, SmallVectorImpl< TypeSize > *Offsets=nullptr, TypeSize StartingOffset=TypeSize::getZero())
ComputeValueVTs - Given an LLVM IR type, compute a sequence of EVTs that represent all the individual...
Definition:Analysis.cpp:79
llvm::isAsynchronousEHPersonality
bool isAsynchronousEHPersonality(EHPersonality Pers)
Returns true if this personality function catches asynchronous exceptions.
Definition:EHPersonalities.h:50
llvm::PseudoProbeReservedId::Last
@ Last
llvm::convertStrToRoundingMode
std::optional< RoundingMode > convertStrToRoundingMode(StringRef)
Returns a valid RoundingMode enumerator when given a string that is valid as input in constrained int...
Definition:FPEnv.cpp:24
llvm::gep_type_begin
gep_type_iterator gep_type_begin(const User *GEP)
Definition:GetElementPtrTypeIterator.h:173
llvm::erase_if
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
Definition:STLExtras.h:2099
llvm::ExtractTypeInfo
GlobalValue * ExtractTypeInfo(Value *V)
ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V.
Definition:Analysis.cpp:177
llvm::getUnderlyingObjects
void getUnderlyingObjects(const Value *V, SmallVectorImpl< const Value * > &Objects, const LoopInfo *LI=nullptr, unsigned MaxLookup=6)
This method is similar to getUnderlyingObject except that it can look through phi and select instruct...
Definition:ValueTracking.cpp:6822
llvm::commonAlignment
Align commonAlignment(Align A, uint64_t Offset)
Returns the alignment that satisfies both alignments.
Definition:Alignment.h:212
llvm::all_equal
bool all_equal(std::initializer_list< T > Values)
Returns true if all Values in the initializer lists are equal or the list.
Definition:STLExtras.h:2087
llvm::ConstantFoldLoadFromConstPtr
Constant * ConstantFoldLoadFromConstPtr(Constant *C, Type *Ty, APInt Offset, const DataLayout &DL)
Return the value that a load from C with offset Offset would produce if it is constant and determinab...
Definition:ConstantFolding.cpp:735
llvm::ComputeLinearIndex
unsigned ComputeLinearIndex(Type *Ty, const unsigned *Indices, const unsigned *IndicesEnd, unsigned CurIndex=0)
Compute the linearized index of a member in a nested aggregate/struct/array.
Definition:Analysis.cpp:33
llvm::bit_floor
T bit_floor(T Value)
Returns the largest integral power of two no greater than Value if Value is nonzero.
Definition:bit.h:327
llvm::Data
@ Data
Definition:SIMachineScheduler.h:55
llvm::InstructionUniformity::Default
@ Default
The result values are uniform if and only if all operands are uniform.
llvm::PGSOQueryType::Test
@ Test
llvm::Guid
@ Guid
Definition:PGOCtxProfWriter.h:22
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
NC
#define NC
Definition:regutils.h:42
RegInfo
Definition:AMDGPUAsmParser.cpp:2770
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::APFloatBase::IEEEsingle
static const fltSemantics & IEEEsingle() LLVM_READNONE
Definition:APFloat.cpp:257
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition:Alignment.h:39
llvm::Align::value
uint64_t value() const
This is a hole in the type system and should not be abused.
Definition:Alignment.h:85
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::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::getScalarStoreSize
uint64_t getScalarStoreSize() const
Definition:ValueTypes.h:397
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::getEVT
static EVT getEVT(Type *Ty, bool HandleUnknown=false)
Return the value type corresponding to the specified type.
Definition:ValueTypes.cpp:289
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::isRISCVVectorTuple
bool isRISCVVectorTuple() const
Return true if this is a vector value type.
Definition:ValueTypes.h:179
llvm::EVT::getFixedSizeInBits
uint64_t getFixedSizeInBits() const
Return the size of the specified fixed width value type in bits.
Definition:ValueTypes.h:376
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::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::isScalarInteger
bool isScalarInteger() const
Return true if this is an integer, but not a vector.
Definition:ValueTypes.h:157
llvm::EVT::changeVectorElementType
EVT changeVectorElementType(EVT EltVT) const
Return a VT for a vector type whose attributes match ourselves with the exception of the element type...
Definition:ValueTypes.h:102
llvm::EVT::getVectorNumElements
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
Definition:ValueTypes.h:331
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::FunctionLoweringInfo::LiveOutInfo
Definition:FunctionLoweringInfo.h:163
llvm::FunctionLoweringInfo::LiveOutInfo::NumSignBits
unsigned NumSignBits
Definition:FunctionLoweringInfo.h:164
llvm::FunctionLoweringInfo::LiveOutInfo::Known
KnownBits Known
Definition:FunctionLoweringInfo.h:166
llvm::ISD::ArgFlagsTy
Definition:TargetCallingConv.h:27
llvm::ISD::ArgFlagsTy::setSExt
void setSExt()
Definition:TargetCallingConv.h:78
llvm::ISD::ArgFlagsTy::setSplit
void setSplit()
Definition:TargetCallingConv.h:137
llvm::ISD::ArgFlagsTy::setPointer
void setPointer()
Definition:TargetCallingConv.h:146
llvm::ISD::ArgFlagsTy::setPointerAddrSpace
void setPointerAddrSpace(unsigned AS)
Definition:TargetCallingConv.h:192
llvm::ISD::ArgFlagsTy::setSwiftError
void setSwiftError()
Definition:TargetCallingConv.h:108
llvm::ISD::ArgFlagsTy::setZExt
void setZExt()
Definition:TargetCallingConv.h:75
llvm::ISD::ArgFlagsTy::setInReg
void setInReg()
Definition:TargetCallingConv.h:84
llvm::ISD::ArgFlagsTy::setSplitEnd
void setSplitEnd()
Definition:TargetCallingConv.h:140
llvm::ISD::ArgFlagsTy::setOrigAlign
void setOrigAlign(Align A)
Definition:TargetCallingConv.h:168
llvm::ISD::InputArg
InputArg - This struct carries flags and type information about a single incoming (formal) argument o...
Definition:TargetCallingConv.h:199
llvm::ISD::InputArg::Used
bool Used
Definition:TargetCallingConv.h:203
llvm::ISD::InputArg::NoArgIndex
static const unsigned NoArgIndex
Sentinel value for implicit machine-level input arguments.
Definition:TargetCallingConv.h:208
llvm::ISD::InputArg::VT
MVT VT
Definition:TargetCallingConv.h:201
llvm::ISD::InputArg::ArgVT
EVT ArgVT
Definition:TargetCallingConv.h:202
llvm::ISD::InputArg::Flags
ArgFlagsTy Flags
Definition:TargetCallingConv.h:200
llvm::ISD::OutputArg
OutputArg - This struct carries flags and a value for a single outgoing (actual) argument or outgoing...
Definition:TargetCallingConv.h:237
llvm::ISD::OutputArg::Flags
ArgFlagsTy Flags
Definition:TargetCallingConv.h:238
llvm::InlineAsm::ConstraintInfo::Type
ConstraintPrefix Type
Type - The basic type of the constraint: input/output/clobber/label.
Definition:InlineAsm.h:126
llvm::KnownBits::countMinLeadingZeros
unsigned countMinLeadingZeros() const
Returns the minimum number of leading zero bits.
Definition:KnownBits.h:240
llvm::MachinePointerInfo
This class contains a discriminated union of information about pointers in memory operands,...
Definition:MachineMemOperand.h:41
llvm::MachinePointerInfo::getUnknownStack
static MachinePointerInfo getUnknownStack(MachineFunction &MF)
Stack memory without other information.
Definition:MachineOperand.cpp:1090
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::MaybeAlign::valueOrOne
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.
Definition:Alignment.h:141
llvm::OptimizedStructLayoutField
A field in a structure.
Definition:OptimizedStructLayout.h:45
llvm::RegsForValue
This struct represents the registers (physical or virtual) that a particular set of values is assigne...
Definition:SelectionDAGBuilder.h:726
llvm::RegsForValue::getRegsAndSizes
SmallVector< std::pair< Register, TypeSize >, 4 > getRegsAndSizes() const
Return a list of registers and their sizes.
Definition:SelectionDAGBuilder.cpp:1072
llvm::RegsForValue::RegsForValue
RegsForValue()=default
llvm::RegsForValue::RegCount
SmallVector< unsigned, 4 > RegCount
This list holds the number of registers for each value.
Definition:SelectionDAGBuilder.h:747
llvm::RegsForValue::isABIMangled
bool isABIMangled() const
Definition:SelectionDAGBuilder.h:760
llvm::RegsForValue::ValueVTs
SmallVector< EVT, 4 > ValueVTs
The value types of the values, which may not be legal, and may need be promoted or synthesized from o...
Definition:SelectionDAGBuilder.h:729
llvm::RegsForValue::Regs
SmallVector< Register, 4 > Regs
This list holds the registers assigned to the values.
Definition:SelectionDAGBuilder.h:744
llvm::RegsForValue::AddInlineAsmOperands
void AddInlineAsmOperands(InlineAsm::Kind Code, bool HasMatching, unsigned MatchingIdx, const SDLoc &dl, SelectionDAG &DAG, std::vector< SDValue > &Ops) const
Add this value to the specified inlineasm node operand list.
Definition:SelectionDAGBuilder.cpp:1018
llvm::RegsForValue::getCopyFromRegs
SDValue getCopyFromRegs(SelectionDAG &DAG, FunctionLoweringInfo &FuncInfo, const SDLoc &dl, SDValue &Chain, SDValue *Glue, const Value *V=nullptr) const
Emit a series of CopyFromReg nodes that copies from this value and returns the result as a ValueVTs v...
Definition:SelectionDAGBuilder.cpp:875
llvm::RegsForValue::RegVTs
SmallVector< MVT, 4 > RegVTs
The value types of the registers.
Definition:SelectionDAGBuilder.h:739
llvm::RegsForValue::getCopyToRegs
void getCopyToRegs(SDValue Val, SelectionDAG &DAG, const SDLoc &dl, SDValue &Chain, SDValue *Glue, const Value *V=nullptr, ISD::NodeType PreferredExtendType=ISD::ANY_EXTEND) const
Emit a series of CopyToReg nodes that copies the specified value into the registers specified by this...
Definition:SelectionDAGBuilder.cpp:962
llvm::RegsForValue::CallConv
std::optional< CallingConv::ID > CallConv
Records if this value needs to be treated in an ABI dependant manner, different to normal type legali...
Definition:SelectionDAGBuilder.h:751
llvm::RegsForValue::occupiesMultipleRegs
bool occupiesMultipleRegs() const
Check if the total RegCount is greater than one.
Definition:SelectionDAGBuilder.h:795
llvm::SDNodeFlags
These are IR-level optimization flags that may be propagated to SDNodes.
Definition:SelectionDAGNodes.h:381
llvm::SDNodeFlags::copyFMF
void copyFMF(const FPMathOperator &FPMO)
Propagate the fast-math-flags from an IR FPMathOperator.
Definition:SelectionDAGNodes.h:430
llvm::SDNodeFlags::NoUnsignedWrap
@ NoUnsignedWrap
Definition:SelectionDAGNodes.h:394
llvm::SDNodeFlags::hasAllowReassociation
bool hasAllowReassociation() const
Definition:SelectionDAGNodes.h:470
llvm::SDNodeFlags::setNoUnsignedWrap
void setNoUnsignedWrap(bool b)
Definition:SelectionDAGNodes.h:441
llvm::SDNodeFlags::setNoSignedWrap
void setNoSignedWrap(bool b)
Definition:SelectionDAGNodes.h:442
llvm::SDVTList
This represents a list of ValueType's that has been intern'd by a SelectionDAG.
Definition:SelectionDAGNodes.h:79
llvm::SmallMapVector
A MapVector that performs no allocations if smaller than a certain size.
Definition:MapVector.h:254
llvm::SwitchCG::BitTestBlock
Definition:SwitchLoweringUtils.h:217
llvm::SwitchCG::BitTestBlock::Default
MachineBasicBlock * Default
Definition:SwitchLoweringUtils.h:226
llvm::SwitchCG::BitTestBlock::Prob
BranchProbability Prob
Definition:SwitchLoweringUtils.h:228
llvm::SwitchCG::BitTestBlock::ContiguousRange
bool ContiguousRange
Definition:SwitchLoweringUtils.h:224
llvm::SwitchCG::BitTestBlock::RegVT
MVT RegVT
Definition:SwitchLoweringUtils.h:222
llvm::SwitchCG::BitTestBlock::DefaultProb
BranchProbability DefaultProb
Definition:SwitchLoweringUtils.h:229
llvm::SwitchCG::BitTestBlock::Parent
MachineBasicBlock * Parent
Definition:SwitchLoweringUtils.h:225
llvm::SwitchCG::BitTestBlock::Cases
BitTestInfo Cases
Definition:SwitchLoweringUtils.h:227
llvm::SwitchCG::BitTestBlock::FallthroughUnreachable
bool FallthroughUnreachable
Definition:SwitchLoweringUtils.h:230
llvm::SwitchCG::BitTestBlock::Emitted
bool Emitted
Definition:SwitchLoweringUtils.h:223
llvm::SwitchCG::BitTestBlock::Range
APInt Range
Definition:SwitchLoweringUtils.h:219
llvm::SwitchCG::BitTestCase
Definition:SwitchLoweringUtils.h:204
llvm::SwitchCG::BitTestCase::ThisBB
MachineBasicBlock * ThisBB
Definition:SwitchLoweringUtils.h:206
llvm::SwitchCG::CaseBlock
This structure is used to communicate between SelectionDAGBuilder and SDISel for the code generation ...
Definition:SwitchLoweringUtils.h:109
llvm::SwitchCG::CaseBlock::TrueProb
BranchProbability TrueProb
Definition:SwitchLoweringUtils.h:141
llvm::SwitchCG::CaseBlock::CmpRHS
const Value * CmpRHS
Definition:SwitchLoweringUtils.h:127
llvm::SwitchCG::CaseBlock::FalseProb
BranchProbability FalseProb
Definition:SwitchLoweringUtils.h:141
llvm::SwitchCG::CaseBlock::TrueBB
MachineBasicBlock * TrueBB
Definition:SwitchLoweringUtils.h:130
llvm::SwitchCG::CaseBlock::FalseBB
MachineBasicBlock * FalseBB
Definition:SwitchLoweringUtils.h:130
llvm::SwitchCG::CaseBlock::CmpLHS
const Value * CmpLHS
Definition:SwitchLoweringUtils.h:127
llvm::SwitchCG::CaseBlock::IsUnpredictable
bool IsUnpredictable
Definition:SwitchLoweringUtils.h:142
llvm::SwitchCG::CaseBlock::CmpMHS
const Value * CmpMHS
Definition:SwitchLoweringUtils.h:127
llvm::SwitchCG::CaseBlock::CC
ISD::CondCode CC
Definition:SwitchLoweringUtils.h:120
llvm::SwitchCG::CaseBlock::DL
SDLoc DL
The debug location of the instruction this CaseBlock was produced from.
Definition:SwitchLoweringUtils.h:137
llvm::SwitchCG::CaseCluster
A cluster of case labels.
Definition:SwitchLoweringUtils.h:42
llvm::SwitchCG::CaseCluster::range
static CaseCluster range(const ConstantInt *Low, const ConstantInt *High, MachineBasicBlock *MBB, BranchProbability Prob)
Definition:SwitchLoweringUtils.h:52
llvm::SwitchCG::JumpTableHeader
Definition:SwitchLoweringUtils.h:189
llvm::SwitchCG::JumpTableHeader::Last
APInt Last
Definition:SwitchLoweringUtils.h:191
llvm::SwitchCG::JumpTableHeader::Emitted
bool Emitted
Definition:SwitchLoweringUtils.h:194
llvm::SwitchCG::JumpTableHeader::SValue
const Value * SValue
Definition:SwitchLoweringUtils.h:192
llvm::SwitchCG::JumpTableHeader::First
APInt First
Definition:SwitchLoweringUtils.h:190
llvm::SwitchCG::JumpTableHeader::HeaderBB
MachineBasicBlock * HeaderBB
Definition:SwitchLoweringUtils.h:193
llvm::SwitchCG::JumpTableHeader::FallthroughUnreachable
bool FallthroughUnreachable
Definition:SwitchLoweringUtils.h:195
llvm::SwitchCG::JumpTable
Definition:SwitchLoweringUtils.h:170
llvm::SwitchCG::SwitchWorkListItem
Definition:SwitchLoweringUtils.h:248
llvm::TargetLoweringBase::CondMergingParams
Definition:TargetLowering.h:638
llvm::TargetLoweringBase::CondMergingParams::BaseCost
int BaseCost
Definition:TargetLowering.h:639
llvm::TargetLoweringBase::CondMergingParams::LikelyBias
int LikelyBias
Definition:TargetLowering.h:640
llvm::TargetLoweringBase::CondMergingParams::UnlikelyBias
int UnlikelyBias
Definition:TargetLowering.h:641
llvm::TargetLoweringBase::IntrinsicInfo
Definition:TargetLowering.h:1202
llvm::TargetLowering::AsmOperandInfo
This contains information for each constraint that we are lowering.
Definition:TargetLowering.h:4977
llvm::TargetLowering::AsmOperandInfo::ConstraintType
TargetLowering::ConstraintType ConstraintType
Information about the constraint code, e.g.
Definition:TargetLowering.h:4985
llvm::TargetLowering::CallLoweringInfo
This structure contains all information that is necessary for lowering calls.
Definition:TargetLowering.h:4529
llvm::TargetLowering::CallLoweringInfo::setConvergent
CallLoweringInfo & setConvergent(bool Value=true)
Definition:TargetLowering.h:4663
llvm::TargetLowering::CallLoweringInfo::IsInReg
bool IsInReg
Definition:TargetLowering.h:4535
llvm::TargetLowering::CallLoweringInfo::setCFIType
CallLoweringInfo & setCFIType(const ConstantInt *Type)
Definition:TargetLowering.h:4698
llvm::TargetLowering::CallLoweringInfo::IsTailCall
bool IsTailCall
Definition:TargetLowering.h:4545
llvm::TargetLowering::CallLoweringInfo::DL
SDLoc DL
Definition:TargetLowering.h:4555
llvm::TargetLowering::CallLoweringInfo::IsVarArg
bool IsVarArg
Definition:TargetLowering.h:4534
llvm::TargetLowering::CallLoweringInfo::Ins
SmallVector< ISD::InputArg, 32 > Ins
Definition:TargetLowering.h:4559
llvm::TargetLowering::CallLoweringInfo::IsPostTypeLegalization
bool IsPostTypeLegalization
Definition:TargetLowering.h:4548
llvm::TargetLowering::CallLoweringInfo::InVals
SmallVector< SDValue, 4 > InVals
Definition:TargetLowering.h:4560
llvm::TargetLowering::CallLoweringInfo::RetZExt
bool RetZExt
Definition:TargetLowering.h:4533
llvm::TargetLowering::CallLoweringInfo::setDiscardResult
CallLoweringInfo & setDiscardResult(bool Value=true)
Definition:TargetLowering.h:4658
llvm::TargetLowering::CallLoweringInfo::setIsPatchPoint
CallLoweringInfo & setIsPatchPoint(bool Value=true)
Definition:TargetLowering.h:4678
llvm::TargetLowering::CallLoweringInfo::setDebugLoc
CallLoweringInfo & setDebugLoc(const SDLoc &dl)
Definition:TargetLowering.h:4572
llvm::TargetLowering::CallLoweringInfo::NumFixedArgs
unsigned NumFixedArgs
Definition:TargetLowering.h:4550
llvm::TargetLowering::CallLoweringInfo::Chain
SDValue Chain
Definition:TargetLowering.h:4530
llvm::TargetLowering::CallLoweringInfo::RetSExt
bool RetSExt
Definition:TargetLowering.h:4532
llvm::TargetLowering::CallLoweringInfo::setTailCall
CallLoweringInfo & setTailCall(bool Value=true)
Definition:TargetLowering.h:4653
llvm::TargetLowering::CallLoweringInfo::setIsPreallocated
CallLoweringInfo & setIsPreallocated(bool Value=true)
Definition:TargetLowering.h:4683
llvm::TargetLowering::CallLoweringInfo::getArgs
ArgListTy & getArgs()
Definition:TargetLowering.h:4708
llvm::TargetLowering::CallLoweringInfo::setConvergenceControlToken
CallLoweringInfo & setConvergenceControlToken(SDValue Token)
Definition:TargetLowering.h:4703
llvm::TargetLowering::CallLoweringInfo::IsReturnValueUsed
bool IsReturnValueUsed
Definition:TargetLowering.h:4537
llvm::TargetLowering::CallLoweringInfo::CB
const CallBase * CB
Definition:TargetLowering.h:4556
llvm::TargetLowering::CallLoweringInfo::Outs
SmallVector< ISD::OutputArg, 32 > Outs
Definition:TargetLowering.h:4557
llvm::TargetLowering::CallLoweringInfo::OutVals
SmallVector< SDValue, 32 > OutVals
Definition:TargetLowering.h:4558
llvm::TargetLowering::CallLoweringInfo::RetTy
Type * RetTy
Definition:TargetLowering.h:4531
llvm::TargetLowering::CallLoweringInfo::CallConv
CallingConv::ID CallConv
Definition:TargetLowering.h:4551
llvm::TargetLowering::CallLoweringInfo::DAG
SelectionDAG & DAG
Definition:TargetLowering.h:4554
llvm::TargetLowering::CallLoweringInfo::setChain
CallLoweringInfo & setChain(SDValue InChain)
Definition:TargetLowering.h:4577
llvm::TargetLowering::CallLoweringInfo::setPtrAuth
CallLoweringInfo & setPtrAuth(PtrAuthInfo Value)
Definition:TargetLowering.h:4688
llvm::TargetLowering::CallLoweringInfo::setCallee
CallLoweringInfo & setCallee(CallingConv::ID CC, Type *ResultType, SDValue Target, ArgListTy &&ArgsList, AttributeSet ResultAttrs={})
Definition:TargetLowering.h:4596
llvm::TargetLowering::MakeLibCallOptions
This structure is used to pass arguments to makeLibCall function.
Definition:TargetLowering.h:4714
llvm::TargetLowering::MakeLibCallOptions::setDiscardResult
MakeLibCallOptions & setDiscardResult(bool Value=true)
Definition:TargetLowering.h:4739
llvm::TargetLowering::PtrAuthInfo
This structure contains the information necessary for lowering pointer-authenticating indirect calls.
Definition:TargetLowering.h:4520
llvm::WinEHFuncInfo
Definition:WinEHFuncInfo.h:90
llvm::WinEHFuncInfo::addIPToStateRange
void addIPToStateRange(const InvokeInst *II, MCSymbol *InvokeBegin, MCSymbol *InvokeEnd)
Definition:WinEHPrepare.cpp:1396
llvm::cl::desc
Definition:CommandLine.h:409

Generated on Sun Jul 20 2025 08:58:06 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp