22#define DEBUG_TYPE "code-metrics"
30 const User *U = dyn_cast<User>(V);
34 for (
const Value *Operand : U->operands())
35 if (Visited.
insert(Operand).second)
36 if (
const auto *
I = dyn_cast<Instruction>(Operand))
37 if (!
I->mayHaveSideEffects() && !
I->isTerminator())
51 for (
int i = 0; i < (int)Worklist.
size(); ++i) {
52 const Value *V = Worklist[i];
55 "Failed to add a worklist entry to our visited set!");
58 if (!
all_of(V->users(), [&](
const User *U) { return EphValues.count(U); }))
84 if (!L->contains(
I->getParent()))
104 assert(
I->getParent()->getParent() ==
F &&
105 "Found assumption for the wrong function!");
107 if (EphValues.
insert(
I).second)
127 if (
const auto *Call = dyn_cast<CallBase>(&
I)) {
128 if (
const Function *
F = Call->getCalledFunction()) {
135 if (!Call->isNoInline() && IsLoweredToCall &&
136 ((
F->hasInternalLinkage() &&
F->hasOneLiveUse()) ||
153 if (!Call->isInlineAsm())
158 if (
const AllocaInst *AI = dyn_cast<AllocaInst>(&
I)) {
159 if (!AI->isStaticAlloca())
163 if (isa<ExtractElementInst>(
I) ||
I.getType()->isVectorTy())
166 if (
I.getType()->isTokenTy() &&
I.isUsedOutsideOfBlock(BB))
169 if (
const CallInst *CI = dyn_cast<CallInst>(&
I)) {
170 if (CI->cannotDuplicate())
172 if (CI->isConvergent())
176 if (
const InvokeInst *InvI = dyn_cast<InvokeInst>(&
I))
177 if (InvI->cannotDuplicate())
static void appendSpeculatableOperands(const Value *V, SmallPtrSetImpl< const Value * > &Visited, SmallVectorImpl< const Value * > &Worklist)
static void completeEphemeralValues(SmallPtrSetImpl< const Value * > &Visited, SmallVectorImpl< const Value * > &Worklist, SmallPtrSetImpl< const Value * > &EphValues)
This file defines an InstructionCost class that is used when calculating the cost of an instruction,...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallPtrSet class.
an instruction to allocate memory on the stack
A cache of @llvm.assume calls within a function.
MutableArrayRef< ResultElem > assumptions()
Access the list of assumption handles currently tracked for this function.
LLVM Basic Block Representation.
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...
This class represents a function call, abstracting a target machine's calling convention.
Represents a single loop in the control flow graph.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
LLVM Value Representation.
This is an optimization pass for GlobalISel generic memory operations.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool usesDynamicAlloca
True if this function calls alloca (in the C sense).
unsigned NumBlocks
Number of analyzed blocks.
bool notDuplicatable
True if this function cannot be duplicated.
unsigned NumInlineCandidates
The number of calls to internal functions with a single caller.
bool isRecursive
True if this function calls itself.
static void collectEphemeralValues(const Loop *L, AssumptionCache *AC, SmallPtrSetImpl< const Value * > &EphValues)
Collect a loop's ephemeral values (those used only by an assume or similar intrinsics in the loop).
unsigned NumRets
How many 'ret' instructions the blocks contain.
void analyzeBasicBlock(const BasicBlock *BB, const TargetTransformInfo &TTI, const SmallPtrSetImpl< const Value * > &EphValues, bool PrepareForLTO=false)
Add information about a block to the current state.
DenseMap< const BasicBlock *, InstructionCost > NumBBInsts
Keeps track of basic block code size estimates.
bool convergent
True if this function contains a call to a convergent function.
unsigned NumCalls
Keep track of the number of calls to 'big' functions.
unsigned NumVectorInsts
How many instructions produce vector values.
InstructionCost NumInsts
Code size cost of the analyzed blocks.