34 const unsigned *Indices,
35 const unsigned *IndicesEnd,
38 if (Indices && Indices == IndicesEnd)
42 if (
StructType *STy = dyn_cast<StructType>(Ty)) {
45 if (Indices && *Indices ==
I.index())
49 assert(!Indices &&
"Unexpected out of bound");
53 else if (
ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
54 Type *EltTy = ATy->getElementType();
55 unsigned NumElts = ATy->getNumElements();
59 assert(*Indices < NumElts &&
"Unexpected out of bound");
62 CurIndex += EltLinearOffset* *Indices;
65 CurIndex += EltLinearOffset*NumElts;
85 if (
StructType *STy = dyn_cast<StructType>(Ty)) {
89 const StructLayout *SL = Offsets ?
DL.getStructLayout(STy) :
nullptr;
92 EE = STy->element_end();
98 StartingOffset + EltOffset);
103 if (
ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
104 Type *EltTy = ATy->getElementType();
105 TypeSize EltSize =
DL.getTypeAllocSize(EltTy);
106 for (
unsigned i = 0, e = ATy->getNumElements(); i != e; ++i)
108 StartingOffset + i * EltSize);
119 Offsets->push_back(StartingOffset);
183 if (
StructType *STy = dyn_cast<StructType>(&Ty)) {
187 const StructLayout *SL = Offsets ?
DL.getStructLayout(STy) :
nullptr;
188 for (
unsigned I = 0,
E = STy->getNumElements();
I !=
E; ++
I) {
191 StartingOffset + EltOffset);
196 if (
ArrayType *ATy = dyn_cast<ArrayType>(&Ty)) {
197 Type *EltTy = ATy->getElementType();
198 uint64_t EltSize =
DL.getTypeAllocSize(EltTy).getFixedValue();
199 for (
unsigned i = 0, e = ATy->getNumElements(); i != e; ++i)
201 StartingOffset + i * EltSize);
209 if (Offsets !=
nullptr)
210 Offsets->push_back(StartingOffset * 8);
215 V = V->stripPointerCasts();
219 if (Var && Var->
getName() ==
"llvm.eh.catch.all.value") {
221 "The EH catch-all value must have an initializer");
223 GV = dyn_cast<GlobalValue>(
Init);
224 if (!GV) V = cast<ConstantPointerNull>(
Init);
227 assert((GV || isa<ConstantPointerNull>(V)) &&
228 "TypeInfo must be a global variable or NULL");
245 case FCmpInst::FCMP_ORD:
return ISD::SETO;
290 return ICmpInst::ICMP_EQ;
292 return ICmpInst::ICMP_NE;
294 return ICmpInst::ICMP_SLE;
296 return ICmpInst::ICMP_ULE;
298 return ICmpInst::ICMP_SGE;
300 return ICmpInst::ICMP_UGE;
302 return ICmpInst::ICMP_SLT;
304 return ICmpInst::ICMP_ULT;
306 return ICmpInst::ICMP_SGT;
308 return ICmpInst::ICMP_UGT;
317 (isa<VectorType>(
T1) && isa<VectorType>(T2) &&
341 if (!
I ||
I->getNumOperands() == 0)
return V;
342 const Value *NoopInput =
nullptr;
345 if (isa<BitCastInst>(
I)) {
349 }
else if (isa<GetElementPtrInst>(
I)) {
351 if (cast<GetElementPtrInst>(
I)->hasAllZeroIndices())
353 }
else if (isa<IntToPtrInst>(
I)) {
357 if (!isa<VectorType>(
I->getType()) &&
358 DL.getPointerSizeInBits() ==
359 cast<IntegerType>(
Op->getType())->getBitWidth())
361 }
else if (isa<PtrToIntInst>(
I)) {
365 if (!isa<VectorType>(
I->getType()) &&
366 DL.getPointerSizeInBits() ==
367 cast<IntegerType>(
I->getType())->getBitWidth())
369 }
else if (isa<TruncInst>(
I) &&
373 I->getType()->getPrimitiveSizeInBits().getFixedValue());
375 }
else if (
auto *CB = dyn_cast<CallBase>(
I)) {
376 const Value *ReturnedOp = CB->getReturnedArgOperand();
378 NoopInput = ReturnedOp;
379 }
else if (
const InsertValueInst *IVI = dyn_cast<InsertValueInst>(V)) {
382 if (ValLoc.
size() >= InsertLoc.
size() &&
383 std::equal(InsertLoc.
begin(), InsertLoc.
end(), ValLoc.
rbegin())) {
388 NoopInput = IVI->getInsertedValueOperand();
417 bool AllowDifferingSizes,
425 unsigned BitsRequired = UINT_MAX;
430 if (isa<UndefValue>(RetVal))
437 unsigned BitsProvided = UINT_MAX;
438 CallVal =
getNoopInput(CallVal, CallIndices, BitsProvided, TLI,
DL);
442 if (CallVal != RetVal || CallIndices != RetIndices)
449 if (BitsProvided < BitsRequired ||
450 (!AllowDifferingSizes && BitsProvided != BitsRequired))
460 return Idx < AT->getNumElements();
462 return Idx < cast<StructType>(
T)->getNumElements();
558 assert(!Path.empty() &&
"found a leaf but didn't set the path?");
575 const ReturnInst *Ret = dyn_cast<ReturnInst>(Term);
585 if (!Ret && ((!
TM.Options.GuaranteedTailCallOpt &&
588 !isa<UnreachableInst>(Term)))
599 if (BBI->isDebugOrPseudoInst())
604 if (II->getIntrinsicID() == Intrinsic::lifetime_end ||
605 II->getIntrinsicID() == Intrinsic::assume ||
606 II->getIntrinsicID() == Intrinsic::experimental_noalias_scope_decl)
608 if (BBI->mayHaveSideEffects() || BBI->mayReadFromMemory() ||
615 F, &Call, Ret, *
TM.getSubtargetImpl(*F)->getTargetLowering());
621 bool *AllowDifferingSizes) {
624 bool &ADS = AllowDifferingSizes ? *AllowDifferingSizes : DummyADS;
627 AttrBuilder CallerAttrs(
F->getContext(),
F->getAttributes().getRetAttrs());
629 cast<CallInst>(
I)->getAttributes().getRetAttrs());
633 for (
const auto &Attr : {Attribute::Alignment, Attribute::Dereferenceable,
634 Attribute::DereferenceableOrNull, Attribute::NoAlias,
635 Attribute::NonNull, Attribute::NoUndef}) {
640 if (CallerAttrs.
contains(Attribute::ZExt)) {
641 if (!CalleeAttrs.
contains(Attribute::ZExt))
647 }
else if (CallerAttrs.
contains(Attribute::SExt)) {
648 if (!CalleeAttrs.
contains(Attribute::SExt))
666 if (
I->use_empty()) {
674 return CallerAttrs == CalleeAttrs;
680 assert(
A &&
B &&
"Expected non-null inputs!");
682 auto *BitCastIn = dyn_cast<BitCastInst>(
B);
687 if (!
A->getType()->isPointerTy() || !
B->getType()->isPointerTy())
690 return A == BitCastIn->getOperand(0);
699 if (!Ret || Ret->getNumOperands() == 0)
return true;
703 if (isa<UndefValue>(Ret->getOperand(0)))
return true;
706 bool AllowDifferingSizes;
710 const Value *RetVal = Ret->getOperand(0), *CallVal =
I;
716 const CallInst *Call = cast<CallInst>(
I);
717 if (
Function *
F = Call->getCalledFunction()) {
719 if (((IID == Intrinsic::memcpy &&
721 (IID == Intrinsic::memmove &&
723 (IID == Intrinsic::memset &&
725 (RetVal == Call->getArgOperand(0) ||
734 bool CallEmpty = !
firstRealType(CallVal->getType(), CallSubTypes, CallPath);
768 AllowDifferingSizes, TLI,
769 F->getParent()->getDataLayout()))
782 while (!Worklist.
empty()) {
789 auto P = EHScopeMembership.
insert(std::make_pair(Visiting, EHScope));
793 assert(
P.first->second == EHScope &&
"MBB is part of two scopes!");
812 return EHScopeMembership;
848 if (EHScopeBlocks.
empty())
849 return EHScopeMembership;
863 for (std::pair<const MachineBasicBlock *, int> CatchRetPair :
867 return EHScopeMembership;
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static bool isNoopBitcast(Type *T1, Type *T2, const TargetLoweringBase &TLI)
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.
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...
static void collectEHScopeMembers(DenseMap< const MachineBasicBlock *, int > &EHScopeMembership, int EHScope, const MachineBasicBlock *MBB)
static bool indexReallyValid(Type *T, unsigned Idx)
For an aggregate type, determine whether a given index is within bounds or not.
static bool nextRealType(SmallVectorImpl< Type * > &SubTypes, SmallVectorImpl< unsigned > &Path)
Set the iterator data-structures to the next non-empty, non-aggregate subtype.
static bool isPointerBitcastEqualTo(const Value *A, const Value *B)
Check whether B is a bitcast of a pointer type to another pointer type, which is equal to A.
static bool advanceToNextLeafType(SmallVectorImpl< Type * > &SubTypes, SmallVectorImpl< unsigned > &Path)
Move the given iterators to the next leaf type in depth first traversal.
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.
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
const HexagonInstrInfo * TII
Module.h This file contains the declarations for the Module class.
const char LLVMTargetMachineRef TM
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file describes how to lower LLVM code to machine code.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
reverse_iterator rend() const
size_t size() const
size - Get the array size.
reverse_iterator rbegin() const
Class to represent array types.
bool contains(Attribute::AttrKind A) const
Return true if the builder has the specified attribute.
AttrBuilder & removeAttribute(Attribute::AttrKind Val)
Remove an attribute from the builder.
LLVM Basic Block Representation.
InstListType::const_iterator const_iterator
const Function * getParent() const
Return the enclosing method, or null if none.
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...
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
This class represents a function call, abstracting a target machine's calling convention.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Constant * getPersonalityFn() const
Get the personality function associated with this function.
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.
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
bool isEHScopeEntry() const
Returns true if this is the entry block of an EH scope, i.e., the block that used to have a catchpad ...
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.
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineBasicBlock & front() const
Return a value (possibly void), from a function.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
reverse_iterator rbegin()
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
TypeSize getElementOffset(unsigned Idx) const
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.
const char * getLibcallName(RTLIB::Libcall Call) const
Get the libcall routine name for the specified libcall.
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 const TargetInstrInfo * getInstrInfo() const
static constexpr TypeSize get(ScalarTy Quantity, bool Scalable)
The instances of the Type class are immutable: once they are created, they are never changed.
bool isPointerTy() const
True if this is an instance of PointerType.
bool isAggregateType() const
Return true if the type is an aggregate type.
bool isScalableTy() const
Return true if this is a type whose size is a known multiple of vscale.
bool isVoidTy() const
Return true if this is 'void'.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
StringRef getName() const
Return a constant reference to the value's name.
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
#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...
@ SwiftTail
This follows the Swift calling convention in how arguments are passed but guarantees tail calls will ...
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out,...
This is an optimization pass for GlobalISel generic memory operations.
void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty, SmallVectorImpl< EVT > &ValueVTs, SmallVectorImpl< TypeSize > *Offsets, TypeSize StartingOffset)
ComputeValueVTs - Given an LLVM IR type, compute a sequence of EVTs that represent all the individual...
ISD::CondCode getICmpCondCode(ICmpInst::Predicate Pred)
getICmpCondCode - Return the ISD condition code corresponding to the given LLVM IR integer condition ...
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are are tuples (A,...
void append_range(Container &C, Range &&R)
Wrapper function to append a range to a container.
bool returnTypeIsEligibleForTailCall(const Function *F, const Instruction *I, const ReturnInst *Ret, const TargetLoweringBase &TLI)
Test if given that the input instruction is in the tail call position if the return type or any attri...
auto reverse(ContainerTy &&C)
void computeValueLLTs(const DataLayout &DL, Type &Ty, SmallVectorImpl< LLT > &ValueTys, SmallVectorImpl< uint64_t > *Offsets=nullptr, uint64_t StartingOffset=0)
computeValueLLTs - Given an LLVM IR type, compute a sequence of LLTs that represent all the individua...
ISD::CondCode getFCmpCondCode(FCmpInst::Predicate Pred)
getFCmpCondCode - Return the ISD condition code corresponding to the given LLVM IR floating-point con...
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
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...
DWARFExpression::Operation Op
ISD::CondCode getFCmpCodeWithoutNaN(ISD::CondCode CC)
getFCmpCodeWithoutNaN - Given an ISD condition code comparing floats, return the equivalent code if w...
bool isAsynchronousEHPersonality(EHPersonality Pers)
Returns true if this personality function catches asynchronous exceptions.
bool isSafeToSpeculativelyExecute(const Instruction *I, const Instruction *CtxI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr, const TargetLibraryInfo *TLI=nullptr)
Return true if the instruction does not have any effects besides calculating the result and does not ...
GlobalValue * ExtractTypeInfo(Value *V)
ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V.
bool isInTailCallPosition(const CallBase &Call, const TargetMachine &TM)
Test if the given instruction is in a position to be optimized with a tail-call.
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.
DenseMap< const MachineBasicBlock *, int > getEHScopeMembership(const MachineFunction &MF)
LLT getLLTForType(Type &Ty, const DataLayout &DL)
Construct a low-level type based on an LLVM type.
static EVT getEVT(Type *Ty, bool HandleUnknown=false)
Return the value type corresponding to the specified type.