Go to the documentation of this file.
34 #define DEBUG_TYPE "bdce"
36 STATISTIC(NumRemoved,
"Number of instructions removed (unused)");
37 STATISTIC(NumSimplified,
"Number of instructions trivialized (dead bits)");
39 "Number of sign extension instructions converted to zero extension");
45 assert(
I->getType()->isIntOrIntVectorTy() &&
46 "Trivializing a non-integer value?");
51 for (
User *JU :
I->users()) {
54 auto *J = dyn_cast<Instruction>(JU);
55 if (J && J->getType()->isIntOrIntVectorTy() &&
58 WorkList.push_back(J);
72 while (!WorkList.empty()) {
85 auto *K = dyn_cast<Instruction>(KU);
86 if (K && Visited.
insert(K).second && K->getType()->isIntOrIntVectorTy() &&
88 WorkList.push_back(K);
100 if (
I.mayHaveSideEffects() &&
I.use_empty())
108 Worklist.push_back(&
I);
114 if (
SExtInst *SE = dyn_cast<SExtInst>(&
I)) {
116 const uint32_t SrcBitSize = SE->getSrcTy()->getScalarSizeInBits();
117 auto *
const DstTy = SE->getDestTy();
118 const uint32_t DestBitSize = DstTy->getScalarSizeInBits();
122 I.replaceAllUsesWith(
123 Builder.CreateZExt(SE->getOperand(0), DstTy, SE->getName()));
124 Worklist.push_back(SE);
131 for (
Use &U :
I.operands()) {
133 if (!U->getType()->isIntOrIntVectorTy())
136 if (!isa<Instruction>(U) && !isa<Argument>(U))
142 LLVM_DEBUG(
dbgs() <<
"BDCE: Trivializing: " << U <<
" (all bits dead)\n");
157 I->dropAllReferences();
162 I->eraseFromParent();
188 auto &DB = getAnalysis<DemandedBitsWrapperPass>().getDemandedBits();
202 "Bit-Tracking Dead Code Elimination",
false,
false)
A set of analyses that are preserved following a run of a transformation pass.
This is an optimization pass for GlobalISel generic memory operations.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Bit Tracking Dead Code Elimination
An analysis that produces DemandedBits for a function.
auto reverse(ContainerTy &&C, std::enable_if_t< has_rbegin< ContainerTy >::value > *=nullptr)
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
LLVM_NODISCARD T pop_back_val()
static void clearAssumptionsOfUsers(Instruction *I, DemandedBits &DB)
If an instruction is trivialized (dead), then the chain of users of that instruction may need to be c...
INITIALIZE_PASS_BEGIN(BDCELegacyPass, "bdce", "Bit-Tracking Dead Code Elimination", false, false) INITIALIZE_PASS_END(BDCELegacyPass
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
Represent the analysis usage information of a pass.
bool isAllOnes() const
Determine if all bits are set. This is true for zero-width values.
STATISTIC(NumFunctions, "Total number of functions")
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
bool wouldInstructionBeTriviallyDead(Instruction *I, const TargetLibraryInfo *TLI=nullptr)
Return true if the result produced by the instruction would have no side effects if it was not used.
inst_range instructions(Function *F)
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void initializeBDCELegacyPassPass(PassRegistry &)
Class for arbitrary precision integers.
void setPreservesCFG()
This function should be called by the pass, iff they do not:
Represents analyses that only rely on functions' control flow.
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
This class represents a sign extension of integer types.
static bool runOnFunction(Function &F, bool PostInlining)
unsigned countLeadingZeros() const
The APInt version of the countLeadingZeros functions in MathExtras.h.
bool isInstructionDead(Instruction *I)
Return true if, during analysis, I could not be reached.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
FunctionPass * createBitTrackingDCEPass()
void salvageDebugInfo(Instruction &I)
Assuming the instruction I is going to be deleted, attempt to salvage debug users of I by writing the...
static bool bitTrackingDCE(Function &F, DemandedBits &DB)
APInt getDemandedBits(Instruction *I)
Return the bits demanded from instruction I.
void preserveSet()
Mark an analysis set as preserved.
Legacy wrapper pass to provide the GlobalsAAResult object.
bool isUseDead(Use *U)
Return whether this use is dead by means of not having any demanded bits.
A container for analyses that lazily runs them and caches their results.
FunctionPass class - This class is used to implement most global optimizations.
AnalysisUsage & addRequired()
iterator_range< user_iterator > users()
void dropPoisonGeneratingFlags()
Drops flags that may cause this instruction to evaluate to poison despite having non-poison inputs.
A Use represents the edge between a Value definition and its users.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.