32 #define DEBUG_TYPE "bdce" 34 STATISTIC(NumRemoved,
"Number of instructions removed (unused)");
35 STATISTIC(NumSimplified,
"Number of instructions trivialized (dead bits)");
42 "Trivializing a non-integer value?");
50 if (J && J->getType()->isIntOrIntVectorTy() &&
52 WorkList.push_back(J);
66 while (!WorkList.empty()) {
82 if (K && !Visited.
count(K) && K->getType()->isIntOrIntVectorTy() &&
84 WorkList.push_back(K);
96 if (
I.mayHaveSideEffects() &&
I.use_empty())
102 (
I.getType()->isIntOrIntVectorTy() &&
107 I.dropAllReferences();
112 for (
Use &U :
I.operands()) {
114 if (!U->getType()->isIntOrIntVectorTy())
117 if (!isa<Instruction>(U) && !isa<Argument>(U))
123 LLVM_DEBUG(
dbgs() <<
"BDCE: Trivializing: " << U <<
" (all bits dead)\n");
138 I->eraseFromParent();
165 auto &DB = getAnalysis<DemandedBitsWrapperPass>().getDemandedBits();
179 "Bit-Tracking Dead Code Elimination",
false,
false)
Legacy wrapper pass to provide the GlobalsAAResult object.
void initializeBDCELegacyPassPass(PassRegistry &)
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
This class represents lattice values for constants.
This is the interface for a simple mod/ref and alias analysis over globals.
bool isInstructionDead(Instruction *I)
Return true if, during analysis, I could not be reached.
void push_back(const T &Elt)
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
bool salvageDebugInfo(Instruction &I)
Assuming the instruction I is going to be deleted, attempt to salvage debug users of I by writing the...
STATISTIC(NumFunctions, "Total number of functions")
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
static bool bitTrackingDCE(Function &F, DemandedBits &DB)
A Use represents the edge between a Value definition and its users.
An analysis that produces DemandedBits for a function.
void dropPoisonGeneratingFlags()
Drops flags that may cause this instruction to evaluate to poison despite having non-poison inputs...
Type * getType() const
All values are typed, get the type of this value.
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
static bool runOnFunction(Function &F, bool PostInlining)
bool isAllOnesValue() const
Determine if all bits are set.
A set of analyses that are preserved following a run of a transformation pass.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Represent the analysis usage information of a pass.
Analysis pass providing a never-invalidated alias analysis result.
FunctionPass * createBitTrackingDCEPass()
FunctionPass class - This class is used to implement most global optimizations.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
Bit Tracking Dead Code Elimination
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
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.
void setPreservesCFG()
This function should be called by the pass, iff they do not:
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...
APInt getDemandedBits(Instruction *I)
Return the bits demanded from instruction I.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
iterator_range< user_iterator > users()
Represents analyses that only rely on functions' control flow.
void preserveSet()
Mark an analysis set as preserved.
INITIALIZE_PASS_BEGIN(BDCELegacyPass, "bdce", "Bit-Tracking Dead Code Elimination", false, false) INITIALIZE_PASS_END(BDCELegacyPass
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
void preserve()
Mark an analysis as preserved.
bool isUseDead(Use *U)
Return whether this use is dead by means of not having any demanded bits.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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)
A container for analyses that lazily runs them and caches their results.
bool isNullValue() const
Determine if all bits are clear.