Go to the documentation of this file.
24 bool maybeReachableFromEachOther(
const SmallVectorImpl<IntrinsicInst *> &Insts,
25 const DominatorTree *DT,
const LoopInfo *LI,
26 size_t MaxLifetimes) {
28 if (Insts.size() > MaxLifetimes)
30 for (
size_t I = 0;
I < Insts.size(); ++
I) {
31 for (
size_t J = 0; J < Insts.size(); ++J) {
47 if (Ends.size() == 1 && PDT.
dominates(Ends[0], Start)) {
52 for (
auto *End : Ends) {
53 EndBlocks.
insert(End->getParent());
56 unsigned NumCoveredExits = 0;
57 for (
auto *RI : RetVec) {
60 ReachableRetVec.push_back(RI);
65 if (EndBlocks.
count(RI->getParent()) > 0 ||
72 if (NumCoveredExits == ReachableRetVec.size()) {
73 for (
auto *End : Ends)
76 for (
auto *RI : ReachableRetVec)
88 size_t MaxLifetimes) {
92 return LifetimeStart.size() == 1 &&
93 (LifetimeEnd.size() == 1 ||
94 (LifetimeEnd.size() > 0 &&
95 !maybeReachableFromEachOther(LifetimeEnd, DT, LI, MaxLifetimes)));
99 if (isa<ReturnInst>(Inst)) {
104 if (isa<ResumeInst, CleanupReturnInst>(Inst)) {
111 if (
CallInst *CI = dyn_cast<CallInst>(&Inst)) {
112 if (CI->canReturnTwice()) {
116 if (
AllocaInst *AI = dyn_cast<AllocaInst>(&Inst)) {
117 if (IsInterestingAlloca(*AI)) {
122 auto *II = dyn_cast<IntrinsicInst>(&Inst);
123 if (II && (II->getIntrinsicID() == Intrinsic::lifetime_start ||
124 II->getIntrinsicID() == Intrinsic::lifetime_end)) {
130 if (!IsInterestingAlloca(*AI))
132 if (II->getIntrinsicID() == Intrinsic::lifetime_start)
138 if (
auto *DVI = dyn_cast<DbgVariableIntrinsic>(&Inst)) {
139 for (
Value *V : DVI->location_ops()) {
140 if (
auto *AI = dyn_cast_or_null<AllocaInst>(V)) {
141 if (!IsInterestingAlloca(*AI))
145 if (DVIVec.empty() || DVIVec.back() != DVI)
146 DVIVec.push_back(DVI);
152 Info.
RetVec.push_back(ExitUntag);
162 Info.AI->setAlignment(NewAlignment);
163 auto &Ctx =
Info.AI->getFunction()->getContext();
167 if (Size == AlignedSize)
171 Type *AllocatedType =
172 Info.AI->isArrayAllocation()
174 Info.AI->getAllocatedType(),
175 cast<ConstantInt>(
Info.AI->getArraySize())->getZExtValue())
176 :
Info.AI->getAllocatedType();
180 new AllocaInst(TypeWithPadding,
Info.AI->getType()->getAddressSpace(),
181 nullptr,
"",
Info.AI);
182 NewAI->takeName(
Info.AI);
183 NewAI->setAlignment(
Info.AI->getAlign());
184 NewAI->setUsedWithInAlloca(
Info.AI->isUsedWithInAlloca());
185 NewAI->setSwiftError(
Info.AI->isSwiftError());
186 NewAI->copyMetadata(*
Info.AI);
189 Info.AI->replaceAllUsesWith(NewPtr);
190 Info.AI->eraseFromParent();
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
This is an optimization pass for GlobalISel generic memory operations.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
SmallVector< DbgVariableIntrinsic *, 2 > DbgVariableIntrinsics
This class represents a no-op cast from one type to another.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
bool forAllReachableExits(const DominatorTree &DT, const PostDominatorTree &PDT, const LoopInfo &LI, const Instruction *Start, const SmallVectorImpl< IntrinsicInst * > &Ends, const SmallVectorImpl< Instruction * > &RetVec, llvm::function_ref< void(Instruction *)> Callback)
The instances of the Type class are immutable: once they are created, they are never changed.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
static IntegerType * getInt8Ty(LLVMContext &C)
SmallVector< Instruction *, 8 > RetVec
bool isPotentiallyReachable(const Instruction *From, const Instruction *To, const SmallPtrSetImpl< BasicBlock * > *ExclusionSet=nullptr, const DominatorTree *DT=nullptr, const LoopInfo *LI=nullptr)
Determine whether instruction 'To' is reachable from 'From', without passing through any blocks in Ex...
Analysis containing CSE Info
This struct is a compact representation of a valid (non-zero power of two) alignment.
Optional< TypeSize > getAllocationSizeInBits(const DataLayout &DL) const
Get allocation size in bits.
An efficient, type-erasing, non-owning reference to a callable.
SmallVector< Instruction *, 4 > UnrecognizedLifetimes
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
void visit(Instruction &Inst)
bool isStandardLifetime(const SmallVectorImpl< IntrinsicInst * > &LifetimeStart, const SmallVectorImpl< IntrinsicInst * > &LifetimeEnd, const DominatorTree *DT, const LoopInfo *LI, size_t MaxLifetimes)
void alignAndPadAlloca(memtag::AllocaInfo &Info, llvm::Align Align)
MapVector< AllocaInst *, AllocaInfo > AllocasToInstrument
const BasicBlock * getParent() const
uint64_t getAllocaSizeInBytes(const AllocaInst &AI)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
This class represents a function call, abstracting a target machine's calling convention.
an instruction to allocate memory on the stack
const CallInst * getTerminatingMustTailCall() const
Returns the call instruction marked 'musttail' prior to the terminating return instruction of this ba...
bool dominates(const Instruction *I1, const Instruction *I2) const
Return true if I1 dominates I2.
LLVM Value Representation.
Instruction * getUntagLocationIfFunctionExit(Instruction &Inst)
AllocaInst * findAllocaForValue(Value *V, bool OffsetZero=false)
Returns unique alloca where the value comes from, or nullptr.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.