LLVM 24.0.0git
Analysis.cpp
Go to the documentation of this file.
1//===-- Analysis.cpp - CodeGen LLVM IR Analysis Utilities -----------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines several CodeGen-specific LLVM IR analysis utilities.
10//
11//===----------------------------------------------------------------------===//
12
20#include "llvm/IR/DataLayout.h"
22#include "llvm/IR/Function.h"
25#include "llvm/IR/Module.h"
29
30using namespace llvm;
31
32/// Compute the linearized index of a member in a nested aggregate/struct/array
33/// by recursing and accumulating CurIndex as long as there are indices in the
34/// index list.
36 const unsigned *Indices,
37 const unsigned *IndicesEnd,
38 unsigned CurIndex) {
39 // Base case: We're done.
40 if (Indices && Indices == IndicesEnd)
41 return CurIndex;
42
43 // Given a struct type, recursively traverse the elements.
44 if (StructType *STy = dyn_cast<StructType>(Ty)) {
45 for (auto I : llvm::enumerate(STy->elements())) {
46 Type *ET = I.value();
47 if (Indices && *Indices == I.index())
48 return ComputeLinearIndex(ET, Indices + 1, IndicesEnd, CurIndex);
49 CurIndex = ComputeLinearIndex(ET, nullptr, nullptr, CurIndex);
50 }
51 assert(!Indices && "Unexpected out of bound");
52 return CurIndex;
53 }
54 // Given an array type, recursively traverse the elements.
55 else if (ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
56 Type *EltTy = ATy->getElementType();
57 unsigned NumElts = ATy->getNumElements();
58 // Compute the Linear offset when jumping one element of the array
59 unsigned EltLinearOffset = ComputeLinearIndex(EltTy, nullptr, nullptr, 0);
60 if (Indices) {
61 assert(*Indices < NumElts && "Unexpected out of bound");
62 // If the indice is inside the array, compute the index to the requested
63 // elt and recurse inside the element with the end of the indices list
64 CurIndex += EltLinearOffset* *Indices;
65 return ComputeLinearIndex(EltTy, Indices+1, IndicesEnd, CurIndex);
66 }
67 CurIndex += EltLinearOffset*NumElts;
68 return CurIndex;
69 }
70 // We haven't found the type we're looking for, so keep searching.
71 return CurIndex + 1;
72}
73
77 TypeSize StartingOffset) {
78 assert((Ty->isScalableTy() == StartingOffset.isScalable() ||
79 StartingOffset.isZero()) &&
80 "Offset/TypeSize mismatch!");
81 // Given a struct type, recursively traverse the elements.
82 if (StructType *STy = dyn_cast<StructType>(Ty)) {
83 // If the Offsets aren't needed, don't query the struct layout. This allows
84 // us to support structs with scalable vectors for operations that don't
85 // need offsets.
86 const StructLayout *SL = Offsets ? DL.getStructLayout(STy) : nullptr;
87 for (StructType::element_iterator EB = STy->element_begin(), EI = EB,
88 EE = STy->element_end();
89 EI != EE; ++EI) {
90 // Don't compute the element offset if we didn't get a StructLayout above.
91 TypeSize EltOffset =
92 SL ? SL->getElementOffset(EI - EB) : TypeSize::getZero();
93 ComputeValueTypes(DL, *EI, Types, Offsets, StartingOffset + EltOffset);
94 }
95 return;
96 }
97 // Given an array type, recursively traverse the elements.
98 if (ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
99 Type *EltTy = ATy->getElementType();
100 TypeSize EltSize = DL.getTypeAllocSize(EltTy);
101 for (unsigned i = 0, e = ATy->getNumElements(); i != e; ++i)
102 ComputeValueTypes(DL, EltTy, Types, Offsets,
103 StartingOffset + i * EltSize);
104 return;
105 }
106 // Interpret void as zero return values.
107 if (Ty->isVoidTy())
108 return;
109 Types.push_back(Ty);
110 if (Offsets)
111 Offsets->push_back(StartingOffset);
112}
113
114/// ComputeValueVTs - Given an LLVM IR type, compute a sequence of
115/// EVTs that represent all the individual underlying
116/// non-aggregate types that comprise it.
117///
118/// If Offsets is non-null, it points to a vector to be filled in
119/// with the in-memory offsets of each of the individual values.
120///
122 Type *Ty, SmallVectorImpl<EVT> &ValueVTs,
123 SmallVectorImpl<EVT> *MemVTs,
125 TypeSize StartingOffset) {
127 ComputeValueTypes(DL, Ty, Types, Offsets, StartingOffset);
128 ValueVTs.reserve(Types.size());
129 if (MemVTs)
130 MemVTs->reserve(Types.size());
131 for (Type *Ty : Types) {
132 ValueVTs.push_back(TLI.getValueType(DL, Ty));
133 if (MemVTs)
134 MemVTs->push_back(TLI.getMemValueType(DL, Ty));
135 }
136}
137
139 Type *Ty, SmallVectorImpl<EVT> &ValueVTs,
140 SmallVectorImpl<EVT> *MemVTs,
141 SmallVectorImpl<uint64_t> *FixedOffsets,
142 uint64_t StartingOffset) {
143 TypeSize Offset = TypeSize::getFixed(StartingOffset);
144 if (FixedOffsets) {
146 ComputeValueVTs(TLI, DL, Ty, ValueVTs, MemVTs, &Offsets, Offset);
147 FixedOffsets->reserve(Offsets.size());
148 for (TypeSize Offset : Offsets)
149 FixedOffsets->push_back(Offset.getFixedValue());
150 } else {
151 ComputeValueVTs(TLI, DL, Ty, ValueVTs, MemVTs, nullptr, Offset);
152 }
153}
154
156 SmallVectorImpl<LLT> &ValueLLTs,
158 TypeSize StartingOffset) {
159 SmallVector<Type *> ValTys;
160 ComputeValueTypes(DL, &Ty, ValTys, Offsets, StartingOffset);
161 ValueLLTs.reserve(ValTys.size());
162 for (Type *ValTy : ValTys)
163 ValueLLTs.push_back(getLLTForType(*ValTy, DL));
164}
165
167 SmallVectorImpl<LLT> &ValueLLTs,
168 SmallVectorImpl<uint64_t> *FixedOffsets,
169 uint64_t FixedStartingOffset) {
170 TypeSize StartingOffset = TypeSize::getFixed(FixedStartingOffset);
171 if (FixedOffsets) {
173 computeValueLLTs(DL, Ty, ValueLLTs, &Offsets, StartingOffset);
174 FixedOffsets->reserve(Offsets.size());
175 for (TypeSize Offset : Offsets)
176 FixedOffsets->push_back(Offset.getFixedValue());
177 } else {
178 computeValueLLTs(DL, Ty, ValueLLTs, nullptr, StartingOffset);
179 }
180}
181
182/// ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V.
184 V = V->stripPointerCasts();
187
188 if (Var && Var->getName() == "llvm.eh.catch.all.value") {
189 assert(Var->hasInitializer() &&
190 "The EH catch-all value must have an initializer");
191 Value *Init = Var->getInitializer();
193 if (!GV) V = cast<ConstantPointerNull>(Init);
194 }
195
196 assert((GV || isa<ConstantPointerNull>(V)) &&
197 "TypeInfo must be a global variable or NULL");
198 return GV;
199}
200
202 auto *STy = dyn_cast<StructType>(Ty);
203 if (!STy || STy->getNumElements() != 2)
204 return false;
205 Type *ExnTy = STy->getElementType(0);
206 return (ExnTy->isPointerTy() || ExnTy->isIntegerTy()) &&
207 STy->getElementType(1)->isIntegerTy();
208}
209
210/// getFCmpCondCode - Return the ISD condition code corresponding to
211/// the given LLVM IR floating-point condition code. This includes
212/// consideration of global floating-point math flags.
213///
215 switch (Pred) {
217 case FCmpInst::FCMP_OEQ: return ISD::SETOEQ;
218 case FCmpInst::FCMP_OGT: return ISD::SETOGT;
219 case FCmpInst::FCMP_OGE: return ISD::SETOGE;
220 case FCmpInst::FCMP_OLT: return ISD::SETOLT;
221 case FCmpInst::FCMP_OLE: return ISD::SETOLE;
222 case FCmpInst::FCMP_ONE: return ISD::SETONE;
223 case FCmpInst::FCMP_ORD: return ISD::SETO;
224 case FCmpInst::FCMP_UNO: return ISD::SETUO;
225 case FCmpInst::FCMP_UEQ: return ISD::SETUEQ;
226 case FCmpInst::FCMP_UGT: return ISD::SETUGT;
227 case FCmpInst::FCMP_UGE: return ISD::SETUGE;
228 case FCmpInst::FCMP_ULT: return ISD::SETULT;
229 case FCmpInst::FCMP_ULE: return ISD::SETULE;
230 case FCmpInst::FCMP_UNE: return ISD::SETUNE;
232 default: llvm_unreachable("Invalid FCmp predicate opcode!");
233 }
234}
235
237 switch (CC) {
238 case ISD::SETOEQ: case ISD::SETUEQ: return ISD::SETEQ;
239 case ISD::SETONE: case ISD::SETUNE: return ISD::SETNE;
240 case ISD::SETOLT: case ISD::SETULT: return ISD::SETLT;
241 case ISD::SETOLE: case ISD::SETULE: return ISD::SETLE;
242 case ISD::SETOGT: case ISD::SETUGT: return ISD::SETGT;
243 case ISD::SETOGE: case ISD::SETUGE: return ISD::SETGE;
244 default: return CC;
245 }
246}
247
249 switch (Pred) {
250 case ICmpInst::ICMP_EQ: return ISD::SETEQ;
251 case ICmpInst::ICMP_NE: return ISD::SETNE;
252 case ICmpInst::ICMP_SLE: return ISD::SETLE;
253 case ICmpInst::ICMP_ULE: return ISD::SETULE;
254 case ICmpInst::ICMP_SGE: return ISD::SETGE;
255 case ICmpInst::ICMP_UGE: return ISD::SETUGE;
256 case ICmpInst::ICMP_SLT: return ISD::SETLT;
257 case ICmpInst::ICMP_ULT: return ISD::SETULT;
258 case ICmpInst::ICMP_SGT: return ISD::SETGT;
259 case ICmpInst::ICMP_UGT: return ISD::SETUGT;
260 default:
261 llvm_unreachable("Invalid ICmp predicate opcode!");
262 }
263}
264
266 switch (Pred) {
267 case ISD::SETEQ:
268 return ICmpInst::ICMP_EQ;
269 case ISD::SETNE:
270 return ICmpInst::ICMP_NE;
271 case ISD::SETLE:
272 return ICmpInst::ICMP_SLE;
273 case ISD::SETULE:
274 return ICmpInst::ICMP_ULE;
275 case ISD::SETGE:
276 return ICmpInst::ICMP_SGE;
277 case ISD::SETUGE:
278 return ICmpInst::ICMP_UGE;
279 case ISD::SETLT:
280 return ICmpInst::ICMP_SLT;
281 case ISD::SETULT:
282 return ICmpInst::ICMP_ULT;
283 case ISD::SETGT:
284 return ICmpInst::ICMP_SGT;
285 case ISD::SETUGT:
286 return ICmpInst::ICMP_UGT;
287 default:
288 llvm_unreachable("Invalid ISD integer condition code!");
289 }
290}
291
292static bool isNoopBitcast(Type *T1, Type *T2,
293 const TargetLoweringBase& TLI) {
294 return T1 == T2 || (T1->isPointerTy() && T2->isPointerTy()) ||
297}
298
299/// Look through operations that will be free to find the earliest source of
300/// this value.
301///
302/// @param ValLoc If V has aggregate type, we will be interested in a particular
303/// scalar component. This records its address; the reverse of this list gives a
304/// sequence of indices appropriate for an extractvalue to locate the important
305/// value. This value is updated during the function and on exit will indicate
306/// similar information for the Value returned.
307///
308/// @param DataBits If this function looks through truncate instructions, this
309/// will record the smallest size attained.
310static const Value *getNoopInput(const Value *V,
312 unsigned &DataBits,
313 const TargetLoweringBase &TLI,
314 const DataLayout &DL) {
315 while (true) {
316 // Try to look through V1; if V1 is not an instruction, it can't be looked
317 // through.
319 if (!I || I->getNumOperands() == 0) return V;
320 const Value *NoopInput = nullptr;
321
322 Value *Op = I->getOperand(0);
323 if (isa<BitCastInst>(I)) {
324 // Look through truly no-op bitcasts.
325 if (isNoopBitcast(Op->getType(), I->getType(), TLI))
326 NoopInput = Op;
327 } else if (isa<GetElementPtrInst>(I)) {
328 // Look through getelementptr
329 if (cast<GetElementPtrInst>(I)->hasAllZeroIndices())
330 NoopInput = Op;
331 } else if (isa<IntToPtrInst>(I)) {
332 // Look through inttoptr.
333 // Make sure this isn't a truncating or extending cast. We could
334 // support this eventually, but don't bother for now.
335 if (!isa<VectorType>(I->getType()) &&
336 DL.getPointerSizeInBits() ==
337 cast<IntegerType>(Op->getType())->getBitWidth())
338 NoopInput = Op;
339 } else if (isa<PtrToIntInst>(I)) {
340 // Look through ptrtoint.
341 // Make sure this isn't a truncating or extending cast. We could
342 // support this eventually, but don't bother for now.
343 if (!isa<VectorType>(I->getType()) &&
344 DL.getPointerSizeInBits() ==
345 cast<IntegerType>(I->getType())->getBitWidth())
346 NoopInput = Op;
347 } else if (isa<TruncInst>(I) &&
348 TLI.allowTruncateForTailCall(Op->getType(), I->getType())) {
349 DataBits =
350 std::min((uint64_t)DataBits,
351 I->getType()->getPrimitiveSizeInBits().getFixedValue());
352 NoopInput = Op;
353 } else if (auto *CB = dyn_cast<CallBase>(I)) {
354 const Value *ReturnedOp = CB->getReturnedArgOperand();
355 if (ReturnedOp && isNoopBitcast(ReturnedOp->getType(), I->getType(), TLI))
356 NoopInput = ReturnedOp;
357 } else if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(V)) {
358 // Value may come from either the aggregate or the scalar
359 ArrayRef<unsigned> InsertLoc = IVI->getIndices();
360 if (ValLoc.size() >= InsertLoc.size() &&
361 std::equal(InsertLoc.begin(), InsertLoc.end(), ValLoc.rbegin())) {
362 // The type being inserted is a nested sub-type of the aggregate; we
363 // have to remove those initial indices to get the location we're
364 // interested in for the operand.
365 ValLoc.resize(ValLoc.size() - InsertLoc.size());
366 NoopInput = IVI->getInsertedValueOperand();
367 } else {
368 // The struct we're inserting into has the value we're interested in, no
369 // change of address.
370 NoopInput = Op;
371 }
372 } else if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(V)) {
373 // The part we're interested in will inevitably be some sub-section of the
374 // previous aggregate. Combine the two paths to obtain the true address of
375 // our element.
376 ArrayRef<unsigned> ExtractLoc = EVI->getIndices();
377 ValLoc.append(ExtractLoc.rbegin(), ExtractLoc.rend());
378 NoopInput = Op;
379 }
380 // Terminate if we couldn't find anything to look through.
381 if (!NoopInput)
382 return V;
383
384 V = NoopInput;
385 }
386}
387
388/// Return true if this scalar return value only has bits discarded on its path
389/// from the "tail call" to the "ret". This includes the obvious noop
390/// instructions handled by getNoopInput above as well as free truncations (or
391/// extensions prior to the call).
392static bool slotOnlyDiscardsData(const Value *RetVal, const Value *CallVal,
393 SmallVectorImpl<unsigned> &RetIndices,
394 SmallVectorImpl<unsigned> &CallIndices,
395 bool AllowDifferingSizes,
396 const TargetLoweringBase &TLI,
397 const DataLayout &DL) {
398
399 // Trace the sub-value needed by the return value as far back up the graph as
400 // possible, in the hope that it will intersect with the value produced by the
401 // call. In the simple case with no "returned" attribute, the hope is actually
402 // that we end up back at the tail call instruction itself.
403 unsigned BitsRequired = UINT_MAX;
404 RetVal = getNoopInput(RetVal, RetIndices, BitsRequired, TLI, DL);
405
406 // If this slot in the value returned is undef, it doesn't matter what the
407 // call puts there, it'll be fine.
408 if (isa<UndefValue>(RetVal))
409 return true;
410
411 // Now do a similar search up through the graph to find where the value
412 // actually returned by the "tail call" comes from. In the simple case without
413 // a "returned" attribute, the search will be blocked immediately and the loop
414 // a Noop.
415 unsigned BitsProvided = UINT_MAX;
416 CallVal = getNoopInput(CallVal, CallIndices, BitsProvided, TLI, DL);
417
418 // There's no hope if we can't actually trace them to (the same part of!) the
419 // same value.
420 if (CallVal != RetVal || CallIndices != RetIndices)
421 return false;
422
423 // However, intervening truncates may have made the call non-tail. Make sure
424 // all the bits that are needed by the "ret" have been provided by the "tail
425 // call". FIXME: with sufficiently cunning bit-tracking, we could look through
426 // extensions too.
427 if (BitsProvided < BitsRequired ||
428 (!AllowDifferingSizes && BitsProvided != BitsRequired))
429 return false;
430
431 return true;
432}
433
434/// For an aggregate type, determine whether a given index is within bounds or
435/// not.
436static bool indexReallyValid(Type *T, unsigned Idx) {
438 return Idx < AT->getNumElements();
439
440 return Idx < cast<StructType>(T)->getNumElements();
441}
442
443/// Move the given iterators to the next leaf type in depth first traversal.
444///
445/// Performs a depth-first traversal of the type as specified by its arguments,
446/// stopping at the next leaf node (which may be a legitimate scalar type or an
447/// empty struct or array).
448///
449/// @param SubTypes List of the partial components making up the type from
450/// outermost to innermost non-empty aggregate. The element currently
451/// represented is SubTypes.back()->getTypeAtIndex(Path.back() - 1).
452///
453/// @param Path Set of extractvalue indices leading from the outermost type
454/// (SubTypes[0]) to the leaf node currently represented.
455///
456/// @returns true if a new type was found, false otherwise. Calling this
457/// function again on a finished iterator will repeatedly return
458/// false. SubTypes.back()->getTypeAtIndex(Path.back()) is either an empty
459/// aggregate or a non-aggregate
462 // First march back up the tree until we can successfully increment one of the
463 // coordinates in Path.
464 while (!Path.empty() && !indexReallyValid(SubTypes.back(), Path.back() + 1)) {
465 Path.pop_back();
466 SubTypes.pop_back();
467 }
468
469 // If we reached the top, then the iterator is done.
470 if (Path.empty())
471 return false;
472
473 // We know there's *some* valid leaf now, so march back down the tree picking
474 // out the left-most element at each node.
475 ++Path.back();
476 Type *DeeperType =
477 ExtractValueInst::getIndexedType(SubTypes.back(), Path.back());
478 while (DeeperType->isAggregateType()) {
479 if (!indexReallyValid(DeeperType, 0))
480 return true;
481
482 SubTypes.push_back(DeeperType);
483 Path.push_back(0);
484
485 DeeperType = ExtractValueInst::getIndexedType(DeeperType, 0);
486 }
487
488 return true;
489}
490
491/// Find the first non-empty, scalar-like type in Next and setup the iterator
492/// components.
493///
494/// Assuming Next is an aggregate of some kind, this function will traverse the
495/// tree from left to right (i.e. depth-first) looking for the first
496/// non-aggregate type which will play a role in function return.
497///
498/// For example, if Next was {[0 x i64], {{}, i32, {}}, i32} then we would setup
499/// Path as [1, 1] and SubTypes as [Next, {{}, i32, {}}] to represent the first
500/// i32 in that type.
503 // First initialise the iterator components to the first "leaf" node
504 // (i.e. node with no valid sub-type at any index, so {} does count as a leaf
505 // despite nominally being an aggregate).
506 while (Type *FirstInner = ExtractValueInst::getIndexedType(Next, 0)) {
507 SubTypes.push_back(Next);
508 Path.push_back(0);
509 Next = FirstInner;
510 }
511
512 // If there's no Path now, Next was originally scalar already (or empty
513 // leaf). We're done.
514 if (Path.empty())
515 return true;
516
517 // Otherwise, use normal iteration to keep looking through the tree until we
518 // find a non-aggregate type.
519 while (ExtractValueInst::getIndexedType(SubTypes.back(), Path.back())
520 ->isAggregateType()) {
521 if (!advanceToNextLeafType(SubTypes, Path))
522 return false;
523 }
524
525 return true;
526}
527
528/// Set the iterator data-structures to the next non-empty, non-aggregate
529/// subtype.
532 do {
533 if (!advanceToNextLeafType(SubTypes, Path))
534 return false;
535
536 assert(!Path.empty() && "found a leaf but didn't set the path?");
537 } while (ExtractValueInst::getIndexedType(SubTypes.back(), Path.back())
538 ->isAggregateType());
539
540 return true;
541}
542
543/// Resolve the DWARF version the way DwarfDebug does.
544/// FIXME: Share this resolution with DwarfDebug's, which has to match.
545static unsigned getDwarfVersion(const MachineFunction &MF) {
546 unsigned DwarfVersion = MF.getTarget().Options.MCOptions.DwarfVersion;
547 if (!DwarfVersion)
548 DwarfVersion = MF.getFunction().getParent()->getDwarfVersion();
549 if (!DwarfVersion)
550 DwarfVersion = dwarf::DWARF_VERSION;
551 return DwarfVersion;
552}
553
555 const MachineFunction &MF) {
556 // Only definitions have an address a symbol reference can name.
557 if (GV->isDeclarationForLinker())
558 return false;
559 // A thread-local's address is not known until it is resolved against a
560 // thread's storage, which a plain symbol reference cannot express.
561 if (GV->isThreadLocal())
562 return false;
563 // Computing the address of a dllimport'd entity requires a load from the
564 // import address table, which a static symbol reference cannot express.
565 if (GV->hasDLLImportStorageClass())
566 return false;
567 // An ifunc resolves to whatever its resolver returns at load time, so the
568 // symbol's own address is not the value of the pointer.
569 if (isa<GlobalIFunc>(GV))
570 return false;
571
572 const Module &M = *MF.getFunction().getParent();
573 const TargetMachine &TM = MF.getTarget();
574
575 // AsmPrinter may fold a GOT equivalent (an unnamed private constant
576 // holding the address of another global) into a GOT-relative
577 // relocation at its use and then never define the symbol. Whether
578 // that happens is only known once every use has been emitted, and a
579 // debug info reference does not count as a use, so it is not safe
580 // return true here.
582 if (const auto *GVar = dyn_cast<GlobalVariable>(GV))
583 if (GVar->hasGlobalUnnamedAddr() && GVar->isConstant() &&
584 GVar->hasInitializer() && GVar->isDiscardableIfUnused() &&
585 isa<GlobalValue>(GVar->getOperand(0)))
586 return false;
587
588 // CodeView has no way to name a symbol in a local variable's location, so
589 // choosing one here would leave the variable with no location at all.
590 if (M.getCodeViewFlag())
591 return false;
592
593 // Saying that the variable holds this address, rather than that it lives at
594 // it, needs DW_OP_stack_value, which DWARF 4 introduced. Nothing older can
595 // express the difference, so leave those versions to describe the variable by
596 // wherever the address is materialized instead. DwarfExpression refuses the
597 // same versions; deciding here only picks the better of the two fallbacks,
598 // while a materialized location is still available to fall back on.
599 if (getDwarfVersion(MF) < 4)
600 return false;
601
602 // On some targets a global does not live at its symbol's address; a base
603 // known only at run time has to be added to it. DwarfCompileUnit builds
604 // those addends for global variables, but they need a relocation, which a
605 // location list cannot carry, so a local pointing at such a global has to
606 // keep being described by whatever register holds the computed address.
607 if (M.getTargetTriple().isWasm() && TM.getRelocationModel() == Reloc::PIC_)
608 return false;
609 if (TM.getRelocationModel() == Reloc::RWPI ||
611 // Only writable globals are addressed relative to the static base;
612 // read-only ones keep an absolute address. An alias may name either, so
613 // give up rather than chase it.
614 const auto *GO = dyn_cast<GlobalObject>(GV);
615 if (!GO || !TM.getObjFileLowering()->getKindForGlobal(GO, TM).isReadOnly())
616 return false;
617 }
618
619 return true;
620}
621
622const GlobalValue *
624 const MachineFunction &MF) {
625 Offset = 0;
626 if (!C->getType()->isPointerTy())
627 return nullptr;
628
629 // Non-inbounds offsets are stripped as well, which is the default. The
630 // inbounds flag constrains what the program may do with the pointer, not
631 // what its value is, and describing an address needs only the value.
632 int64_t GVOffset;
633 const auto *GV = dyn_cast<GlobalValue>(
635 if (!GV || !canDescribeGlobalAddressInDebugInfo(GV, MF))
636 return nullptr;
637
638 Offset = GVOffset;
639 return GV;
640}
641
643 // A location list is emitted as plain bytes, which cannot carry the
644 // relocation a DW_OP_addr needs, so there the address has to be an index into
645 // the address pool. Before DWARF 5 that pool only exists under split DWARF.
646 return getDwarfVersion(MF) >= 5 ||
648}
649
650/// Test if the given instruction is in a position to be optimized
651/// with a tail-call. This roughly means that it's in a block with
652/// a return and there's nothing that needs to be scheduled
653/// between it and the return.
654///
655/// This function only tests target-independent requirements.
657 bool ReturnsFirstArg) {
658 const BasicBlock *ExitBB = Call.getParent();
659 const Instruction *Term = ExitBB->getTerminator();
660 const ReturnInst *Ret = dyn_cast<ReturnInst>(Term);
661
662 // The block must end in a return statement or unreachable.
663 //
664 // FIXME: Decline tailcall if it's not guaranteed and if the block ends in
665 // an unreachable, for now. The way tailcall optimization is currently
666 // implemented means it will add an epilogue followed by a jump. That is
667 // not profitable. Also, if the callee is a special function (e.g.
668 // longjmp on x86), it can end up causing miscompilation that has not
669 // been fully understood.
670 if (!Ret && ((!TM.Options.GuaranteedTailCallOpt &&
671 Call.getCallingConv() != CallingConv::Tail &&
672 Call.getCallingConv() != CallingConv::SwiftTail) ||
673 !isa<UnreachableInst>(Term)))
674 return false;
675
676 // If I will have a chain, make sure no other instruction that will have a
677 // chain interposes between I and the return.
678 // Check for all calls including speculatable functions.
679 for (BasicBlock::const_iterator BBI = std::prev(ExitBB->end(), 2);; --BBI) {
680 if (&*BBI == &Call)
681 break;
682 // Pseudo probe intrinsics do not block tail call optimization.
683 if (isa<PseudoProbeInst>(BBI))
684 continue;
685 // A lifetime end, assume or noalias.decl intrinsic should not stop tail
686 // call optimization.
687 if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(BBI))
688 if (II->getIntrinsicID() == Intrinsic::lifetime_end ||
689 II->getIntrinsicID() == Intrinsic::assume ||
690 II->getIntrinsicID() == Intrinsic::experimental_noalias_scope_decl ||
691 II->getIntrinsicID() == Intrinsic::fake_use)
692 continue;
693 if (BBI->mayHaveSideEffects() || BBI->mayReadFromMemory() ||
695 return false;
696 }
697
698 const Function *F = ExitBB->getParent();
700 F, &Call, Ret, *TM.getSubtargetImpl(*F)->getTargetLowering(),
701 ReturnsFirstArg);
702}
703
705 const ReturnInst *Ret,
706 const TargetLoweringBase &TLI,
707 bool *AllowDifferingSizes) {
708 // ADS may be null, so don't write to it directly.
709 bool DummyADS;
710 bool &ADS = AllowDifferingSizes ? *AllowDifferingSizes : DummyADS;
711 ADS = true;
712
713 AttrBuilder CallerAttrs(F->getContext(), F->getAttributes().getRetAttrs());
714 AttrBuilder CalleeAttrs(F->getContext(),
715 cast<CallInst>(I)->getAttributes().getRetAttrs());
716
717 // Following attributes are completely benign as far as calling convention
718 // goes, they shouldn't affect whether the call is a tail call.
719 for (const auto &Attr : {Attribute::Alignment, Attribute::Dereferenceable,
720 Attribute::DereferenceableOrNull, Attribute::NoAlias,
721 Attribute::NonNull, Attribute::NoUndef,
722 Attribute::Range, Attribute::NoFPClass}) {
723 CallerAttrs.removeAttribute(Attr);
724 CalleeAttrs.removeAttribute(Attr);
725 }
726
727 if (CallerAttrs.contains(Attribute::ZExt)) {
728 if (!CalleeAttrs.contains(Attribute::ZExt))
729 return false;
730
731 ADS = false;
732 CallerAttrs.removeAttribute(Attribute::ZExt);
733 CalleeAttrs.removeAttribute(Attribute::ZExt);
734 } else if (CallerAttrs.contains(Attribute::SExt)) {
735 if (!CalleeAttrs.contains(Attribute::SExt))
736 return false;
737
738 ADS = false;
739 CallerAttrs.removeAttribute(Attribute::SExt);
740 CalleeAttrs.removeAttribute(Attribute::SExt);
741 }
742
743 // Drop sext and zext return attributes if the result is not used.
744 // This enables tail calls for code like:
745 //
746 // define void @caller() {
747 // entry:
748 // %unused_result = tail call zeroext i1 @callee()
749 // br label %retlabel
750 // retlabel:
751 // ret void
752 // }
753 if (I->use_empty()) {
754 CalleeAttrs.removeAttribute(Attribute::SExt);
755 CalleeAttrs.removeAttribute(Attribute::ZExt);
756 }
757
758 // If they're still different, there's some facet we don't understand
759 // (currently only "inreg", but in future who knows). It may be OK but the
760 // only safe option is to reject the tail call.
761 return CallerAttrs == CalleeAttrs;
762}
763
765 const Instruction *I,
766 const ReturnInst *Ret,
767 const TargetLoweringBase &TLI,
768 bool ReturnsFirstArg) {
769 // If the block ends with a void return or unreachable, it doesn't matter
770 // what the call's return type is.
771 if (!Ret || Ret->getNumOperands() == 0) return true;
772
773 // If the return value is undef, it doesn't matter what the call's
774 // return type is.
775 if (isa<UndefValue>(Ret->getOperand(0))) return true;
776
777 // Make sure the attributes attached to each return are compatible.
778 bool AllowDifferingSizes;
779 if (!attributesPermitTailCall(F, I, Ret, TLI, &AllowDifferingSizes))
780 return false;
781
782 // If the return value is the first argument of the call.
783 if (ReturnsFirstArg)
784 return true;
785
786 const Value *RetVal = Ret->getOperand(0), *CallVal = I;
787 SmallVector<unsigned, 4> RetPath, CallPath;
788 SmallVector<Type *, 4> RetSubTypes, CallSubTypes;
789
790 bool RetEmpty = !firstRealType(RetVal->getType(), RetSubTypes, RetPath);
791 bool CallEmpty = !firstRealType(CallVal->getType(), CallSubTypes, CallPath);
792
793 // Nothing's actually returned, it doesn't matter what the callee put there
794 // it's a valid tail call.
795 if (RetEmpty)
796 return true;
797
798 // Iterate pairwise through each of the value types making up the tail call
799 // and the corresponding return. For each one we want to know whether it's
800 // essentially going directly from the tail call to the ret, via operations
801 // that end up not generating any code.
802 //
803 // We allow a certain amount of covariance here. For example it's permitted
804 // for the tail call to define more bits than the ret actually cares about
805 // (e.g. via a truncate).
806 do {
807 if (CallEmpty) {
808 // We've exhausted the values produced by the tail call instruction, the
809 // rest are essentially undef. The type doesn't really matter, but we need
810 // *something*.
811 Type *SlotType =
812 ExtractValueInst::getIndexedType(RetSubTypes.back(), RetPath.back());
813 CallVal = UndefValue::get(SlotType);
814 }
815
816 // The manipulations performed when we're looking through an insertvalue or
817 // an extractvalue would happen at the front of the RetPath list, so since
818 // we have to copy it anyway it's more efficient to create a reversed copy.
819 SmallVector<unsigned, 4> TmpRetPath(llvm::reverse(RetPath));
820 SmallVector<unsigned, 4> TmpCallPath(llvm::reverse(CallPath));
821
822 // Finally, we can check whether the value produced by the tail call at this
823 // index is compatible with the value we return.
824 if (!slotOnlyDiscardsData(RetVal, CallVal, TmpRetPath, TmpCallPath,
825 AllowDifferingSizes, TLI,
826 F->getDataLayout()))
827 return false;
828
829 CallEmpty = !nextRealType(CallSubTypes, CallPath);
830 } while(nextRealType(RetSubTypes, RetPath));
831
832 return true;
833}
834
836 const ReturnInst *Ret = dyn_cast<ReturnInst>(CI.getParent()->getTerminator());
837 Value *RetVal = Ret ? Ret->getReturnValue() : nullptr;
838 bool ReturnsFirstArg = false;
839 if (RetVal && ((RetVal == CI.getArgOperand(0))))
840 ReturnsFirstArg = true;
841 return ReturnsFirstArg;
842}
843
845 DenseMap<const MachineBasicBlock *, int> &EHScopeMembership, int EHScope,
846 const MachineBasicBlock *MBB) {
848 while (!Worklist.empty()) {
849 const MachineBasicBlock *Visiting = Worklist.pop_back_val();
850 // Don't follow blocks which start new scopes.
851 if (Visiting->isEHPad() && Visiting != MBB)
852 continue;
853
854 // Add this MBB to our scope.
855 auto P = EHScopeMembership.insert(std::make_pair(Visiting, EHScope));
856
857 // Don't revisit blocks.
858 if (!P.second) {
859 assert(P.first->second == EHScope && "MBB is part of two scopes!");
860 continue;
861 }
862
863 // Returns are boundaries where scope transfer can occur, don't follow
864 // successors.
865 if (Visiting->isEHScopeReturnBlock())
866 continue;
867
868 append_range(Worklist, Visiting->successors());
869 }
870}
871
875
876 // We don't have anything to do if there aren't any EH pads.
877 if (!MF.hasEHScopes())
878 return EHScopeMembership;
879
880 int EntryBBNumber = MF.front().getNumber();
881 bool IsSEH = isAsynchronousEHPersonality(
883
889 for (const MachineBasicBlock &MBB : MF) {
890 if (MBB.isEHScopeEntry()) {
891 EHScopeBlocks.push_back(&MBB);
892 } else if (IsSEH && MBB.isEHPad()) {
893 SEHCatchPads.push_back(&MBB);
894 } else if (MBB.pred_empty()) {
895 UnreachableBlocks.push_back(&MBB);
896 }
897
898 MachineBasicBlock::const_iterator MBBI = MBB.getFirstTerminator();
899
900 // CatchPads are not scopes for SEH so do not consider CatchRet to
901 // transfer control to another scope.
902 if (MBBI == MBB.end() || MBBI->getOpcode() != TII->getCatchReturnOpcode())
903 continue;
904
905 // FIXME: SEH CatchPads are not necessarily in the parent function:
906 // they could be inside a finally block.
907 const MachineBasicBlock *Successor = MBBI->getOperand(0).getMBB();
908 const MachineBasicBlock *SuccessorColor = MBBI->getOperand(1).getMBB();
909 CatchRetSuccessors.push_back(
910 {Successor, IsSEH ? EntryBBNumber : SuccessorColor->getNumber()});
911 }
912
913 // We don't have anything to do if there aren't any EH pads.
914 if (EHScopeBlocks.empty())
915 return EHScopeMembership;
916
917 // Identify all the basic blocks reachable from the function entry.
918 collectEHScopeMembers(EHScopeMembership, EntryBBNumber, &MF.front());
919 // All blocks not part of a scope are in the parent function.
920 for (const MachineBasicBlock *MBB : UnreachableBlocks)
921 collectEHScopeMembers(EHScopeMembership, EntryBBNumber, MBB);
922 // Next, identify all the blocks inside the scopes.
923 for (const MachineBasicBlock *MBB : EHScopeBlocks)
924 collectEHScopeMembers(EHScopeMembership, MBB->getNumber(), MBB);
925 // SEH CatchPads aren't really scopes, handle them separately.
926 for (const MachineBasicBlock *MBB : SEHCatchPads)
927 collectEHScopeMembers(EHScopeMembership, EntryBBNumber, MBB);
928 // Finally, identify all the targets of a catchret.
929 for (std::pair<const MachineBasicBlock *, int> CatchRetPair :
930 CatchRetSuccessors)
931 collectEHScopeMembers(EHScopeMembership, CatchRetPair.second,
932 CatchRetPair.first);
933
934 // Add any remaining blocks in the function to the unreachable set, which
935 // might not otherwise have been identified as unreachable (such as infinite
936 // loops).
937 for (const MachineBasicBlock &MBB : MF)
938 if (!EHScopeMembership.count(&MBB))
939 collectEHScopeMembers(EHScopeMembership, EntryBBNumber, &MBB);
940
941 return EHScopeMembership;
942}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
unsigned uint64_t
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static bool isNoopBitcast(Type *T1, Type *T2, const TargetLoweringBase &TLI)
Definition Analysis.cpp:292
static bool firstRealType(Type *Next, SmallVectorImpl< Type * > &SubTypes, SmallVectorImpl< unsigned > &Path)
Find the first non-empty, scalar-like type in Next and setup the iterator components.
Definition Analysis.cpp:501
static bool slotOnlyDiscardsData(const Value *RetVal, const Value *CallVal, SmallVectorImpl< unsigned > &RetIndices, SmallVectorImpl< unsigned > &CallIndices, bool AllowDifferingSizes, const TargetLoweringBase &TLI, const DataLayout &DL)
Return true if this scalar return value only has bits discarded on its path from the "tail call" to t...
Definition Analysis.cpp:392
static void collectEHScopeMembers(DenseMap< const MachineBasicBlock *, int > &EHScopeMembership, int EHScope, const MachineBasicBlock *MBB)
Definition Analysis.cpp:844
static bool indexReallyValid(Type *T, unsigned Idx)
For an aggregate type, determine whether a given index is within bounds or not.
Definition Analysis.cpp:436
static bool nextRealType(SmallVectorImpl< Type * > &SubTypes, SmallVectorImpl< unsigned > &Path)
Set the iterator data-structures to the next non-empty, non-aggregate subtype.
Definition Analysis.cpp:530
static unsigned getDwarfVersion(const MachineFunction &MF)
Resolve the DWARF version the way DwarfDebug does.
Definition Analysis.cpp:545
static bool advanceToNextLeafType(SmallVectorImpl< Type * > &SubTypes, SmallVectorImpl< unsigned > &Path)
Move the given iterators to the next leaf type in depth first traversal.
Definition Analysis.cpp:460
static const Value * getNoopInput(const Value *V, SmallVectorImpl< unsigned > &ValLoc, unsigned &DataBits, const TargetLoweringBase &TLI, const DataLayout &DL)
Look through operations that will be free to find the earliest source of this value.
Definition Analysis.cpp:310
This file contains constants used for implementing Dwarf debug support.
const HexagonInstrInfo * TII
Module.h This file contains the declarations for the Module class.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
#define T
#define T1
uint64_t IntrinsicInst * II
#define P(N)
This file describes how to lower LLVM code to machine code.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
reverse_iterator rend() const
Definition ArrayRef.h:133
iterator end() const
Definition ArrayRef.h:130
size_t size() const
Get the array size.
Definition ArrayRef.h:141
iterator begin() const
Definition ArrayRef.h:129
reverse_iterator rbegin() const
Definition ArrayRef.h:132
Class to represent array types.
LLVM Basic Block Representation.
Definition BasicBlock.h:62
iterator end()
Definition BasicBlock.h:459
const Function * getParent() const
Return the enclosing method, or null if none.
Definition BasicBlock.h:213
InstListType::const_iterator const_iterator
Definition BasicBlock.h:171
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
Definition BasicBlock.h:237
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Value * getArgOperand(unsigned i) const
This class represents a function call, abstracting a target machine's calling convention.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:740
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
Definition InstrTypes.h:743
@ FCMP_TRUE
1 1 1 1 Always true (always folded)
Definition InstrTypes.h:757
@ ICMP_SLT
signed less than
Definition InstrTypes.h:769
@ ICMP_SLE
signed less or equal
Definition InstrTypes.h:770
@ FCMP_OLT
0 1 0 0 True if ordered and less than
Definition InstrTypes.h:746
@ FCMP_ULE
1 1 0 1 True if unordered, less than, or equal
Definition InstrTypes.h:755
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
Definition InstrTypes.h:744
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
Definition InstrTypes.h:745
@ ICMP_UGE
unsigned greater or equal
Definition InstrTypes.h:764
@ ICMP_UGT
unsigned greater than
Definition InstrTypes.h:763
@ ICMP_SGT
signed greater than
Definition InstrTypes.h:767
@ FCMP_ULT
1 1 0 0 True if unordered or less than
Definition InstrTypes.h:754
@ FCMP_ONE
0 1 1 0 True if ordered and operands are unequal
Definition InstrTypes.h:748
@ FCMP_UEQ
1 0 0 1 True if unordered or equal
Definition InstrTypes.h:751
@ ICMP_ULT
unsigned less than
Definition InstrTypes.h:765
@ FCMP_UGT
1 0 1 0 True if unordered or greater than
Definition InstrTypes.h:752
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
Definition InstrTypes.h:747
@ FCMP_ORD
0 1 1 1 True if ordered (no nans)
Definition InstrTypes.h:749
@ ICMP_NE
not equal
Definition InstrTypes.h:762
@ ICMP_SGE
signed greater or equal
Definition InstrTypes.h:768
@ FCMP_UNE
1 1 1 0 True if unordered or not equal
Definition InstrTypes.h:756
@ ICMP_ULE
unsigned less or equal
Definition InstrTypes.h:766
@ FCMP_UGE
1 0 1 1 True if unordered, greater than, or equal
Definition InstrTypes.h:753
@ FCMP_FALSE
0 0 0 0 Always false (always folded)
Definition InstrTypes.h:742
@ FCMP_UNO
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
Definition InstrTypes.h:750
This is an important base class in LLVM.
Definition Constant.h:43
const Constant * stripPointerCasts() const
Definition Constant.h:237
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
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:763
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition DenseMap.h:828
This instruction extracts a struct member or array element value from an aggregate value.
static LLVM_ABI Type * getIndexedType(Type *Agg, ArrayRef< unsigned > Idxs)
Returns the type of the element that would be extracted with an extractvalue instruction with the spe...
Constant * getPersonalityFn() const
Get the personality function associated with this function.
bool isThreadLocal() const
If the value is "Thread Local", its value isn't shared by the threads.
bool hasDLLImportStorageClass() const
bool isDeclarationForLinker() const
Module * getParent()
Get the module that this global value is contained inside of...
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
bool hasInitializer() const
Definitions have initializers, declarations don't.
This instruction inserts a struct field of array element value into an aggregate value.
A wrapper class for inspecting calls to intrinsic functions.
bool isEHPad() const
Returns true if the block is a landing pad.
MachineInstrBundleIterator< const MachineInstr > const_iterator
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
iterator_range< succ_iterator > successors()
bool isEHScopeReturnBlock() const
Convenience function that returns true if the bock ends in a EH scope return instruction.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineBasicBlock & front() const
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
unsigned getDwarfVersion() const
Returns the Dwarf Version by checking module flags.
Definition Module.cpp:605
Return a value (possibly void), from a function.
Value * getReturnValue() const
Convenience accessor. Returns null if there is no return value.
bool isReadOnly() const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void reserve(size_type N)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void resize(size_type N)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
Definition DataLayout.h:743
TypeSize getElementOffset(unsigned Idx) const
Definition DataLayout.h:774
Class to represent struct types.
Type::subtype_iterator element_iterator
TargetInstrInfo - Interface to description of machine instruction set.
This base class for TargetLowering contains the SelectionDAG-independent parts that can be used from ...
EVT getMemValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
EVT getValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
Return the EVT corresponding to this LLVM type.
virtual bool allowTruncateForTailCall(Type *FromTy, Type *ToTy) const
Return true if a truncation from FromTy to ToTy is permitted when deciding whether a call is in tail ...
bool isTypeLegal(EVT VT) const
Return true if the target has native support for the specified value type.
static SectionKind getKindForGlobal(const GlobalObject *GO, const TargetMachine &TM)
Classify the specified global variable into a set of target independent categories embodied in Sectio...
bool supportIndirectSymViaGOTPCRel() const
Target supports replacing a data "PC"-relative access to a symbol through another symbol,...
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
Primary interface to the complete machine description for the target machine.
virtual TargetLoweringObjectFile * getObjFileLowering() const
Reloc::Model getRelocationModel() const
Returns the code generation relocation model.
virtual const TargetSubtargetInfo * getSubtargetImpl(const Function &) const
Virtual method implemented by subclasses that returns a reference to that target's TargetSubtargetInf...
TargetOptions Options
MCTargetOptions MCOptions
Machine level options.
unsigned GuaranteedTailCallOpt
GuaranteedTailCallOpt - This flag is enabled when -tailcallopt is specified on the commandline.
virtual const TargetInstrInfo * getInstrInfo() const
virtual const TargetLowering * getTargetLowering() const
static constexpr TypeSize getFixed(ScalarTy ExactSize)
Definition TypeSize.h:339
static constexpr TypeSize getZero()
Definition TypeSize.h:345
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
bool isPointerTy() const
True if this is an instance of PointerType.
Definition Type.h:277
bool isAggregateType() const
Return true if the type is an aggregate type.
Definition Type.h:314
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition Type.h:252
static LLVM_ABI UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Value * getOperand(unsigned i) const
Definition User.h:207
unsigned getNumOperands() const
Definition User.h:229
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:257
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition Value.cpp:319
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
Definition TypeSize.h:168
constexpr bool isZero() const
Definition TypeSize.h:153
const ParentTy * getParent() const
Definition ilist_node.h:34
CallInst * Call
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ Tail
Attemps to make calls as fast as possible while guaranteeing that tail call optimization can always b...
Definition CallingConv.h:76
@ SwiftTail
This follows the Swift calling convention in how arguments are passed but guarantees tail calls will ...
Definition CallingConv.h:87
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out,...
@ DWARF_VERSION
Other constants.
Definition Dwarf.h:63
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
LLVM_ABI bool canDescribeGlobalAddressInLocationList(const MachineFunction &MF)
Test if the debug info for MF can name a describable global address in a location list too,...
Definition Analysis.cpp:642
LLVM_ABI ISD::CondCode getICmpCondCode(ICmpInst::Predicate Pred)
getICmpCondCode - Return the ISD condition code corresponding to the given LLVM IR integer condition ...
Definition Analysis.cpp:248
LLVM_ABI void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty, SmallVectorImpl< EVT > &ValueVTs, SmallVectorImpl< EVT > *MemVTs=nullptr, 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:121
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
Definition STLExtras.h:2570
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
LLVM_ABI bool isExceptionPointerAndSelectorType(Type *Ty)
Return true if landingpad result type Ty is a struct of an exception pointer (pointer or integer) and...
Definition Analysis.cpp:201
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition STLExtras.h:2224
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.
LLVM_ABI bool isSafeToSpeculativelyExecute(const Instruction *I, const Instruction *CtxI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr, const TargetLibraryInfo *TLI=nullptr, bool UseVariableInfo=true, bool IgnoreUBImplyingAttrs=true)
Return true if the instruction does not have any effects besides calculating the result and does not ...
LLVM_ABI void ComputeValueTypes(const DataLayout &DL, Type *Ty, SmallVectorImpl< Type * > &Types, SmallVectorImpl< TypeSize > *Offsets=nullptr, TypeSize StartingOffset=TypeSize::getZero())
Given an LLVM IR type, compute non-aggregate subtypes.
Definition Analysis.cpp:74
auto reverse(ContainerTy &&C)
Definition STLExtras.h:408
LLVM_ABI bool returnTypeIsEligibleForTailCall(const Function *F, const Instruction *I, const ReturnInst *Ret, const TargetLoweringBase &TLI, bool ReturnsFirstArg=false)
Test if given that the input instruction is in the tail call position if the return type or any attri...
Definition Analysis.cpp:764
LLVM_ABI ISD::CondCode getFCmpCondCode(FCmpInst::Predicate Pred)
getFCmpCondCode - Return the ISD condition code corresponding to the given LLVM IR floating-point con...
Definition Analysis.cpp:214
LLVM_ABI EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
LLVM_ABI bool attributesPermitTailCall(const Function *F, const Instruction *I, const ReturnInst *Ret, const TargetLoweringBase &TLI, bool *AllowDifferingSizes=nullptr)
Test if given that the input instruction is in the tail call position, if there is an attribute misma...
Definition Analysis.cpp:704
LLVM_ABI 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:656
DWARFExpression::Operation Op
LLVM_ABI ISD::CondCode getFCmpCodeWithoutNaN(ISD::CondCode CC)
getFCmpCodeWithoutNaN - Given an ISD condition code comparing floats, return the equivalent code if w...
Definition Analysis.cpp:236
LLVM_ABI const GlobalValue * getDescribableGlobalAddress(const Constant *C, int64_t &Offset, const MachineFunction &MF)
If C is the address of a global, possibly displaced by a constant, return that global and set Offset ...
Definition Analysis.cpp:623
bool isAsynchronousEHPersonality(EHPersonality Pers)
Returns true if this personality function catches asynchronous exceptions.
LLVM_ABI bool funcReturnsFirstArgOfCall(const CallInst &CI)
Returns true if the parent of CI returns CI's first argument after calling CI.
Definition Analysis.cpp:835
LLVM_ABI bool canDescribeGlobalAddressInDebugInfo(const GlobalValue *GV, const MachineFunction &MF)
Test if the address of GV can be described in debug info as a plain reference to its symbol,...
Definition Analysis.cpp:554
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
LLVM_ABI void computeValueLLTs(const DataLayout &DL, Type &Ty, SmallVectorImpl< LLT > &ValueLLTs, SmallVectorImpl< TypeSize > *Offsets=nullptr, TypeSize StartingOffset=TypeSize::getZero())
computeValueLLTs - Given an LLVM IR type, compute a sequence of LLTs that represent all the individua...
Definition Analysis.cpp:155
LLVM_ABI GlobalValue * ExtractTypeInfo(Value *V)
ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V.
Definition Analysis.cpp:183
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Next
Definition InstrProf.h:147
LLVM_ABI 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:35
LLVM_ABI DenseMap< const MachineBasicBlock *, int > getEHScopeMembership(const MachineFunction &MF)
Definition Analysis.cpp:873
LLVM_ABI LLT getLLTForType(Type &Ty, const DataLayout &DL)
Construct a low-level type based on an LLVM type.
static LLVM_ABI EVT getEVT(Type *Ty, bool HandleUnknown=false)
Return the value type corresponding to the specified type.