44 #define DEBUG_TYPE "demanded-bits"
48 "Demanded bits analysis",
false,
false)
70 return isa<TerminatorInst>(
I) || isa<DbgInfoIntrinsic>(I) ||
74 void DemandedBits::determineLiveOperandBits(
85 auto ComputeKnownBits =
86 [&](
unsigned BitWidth,
const Value *V1,
const Value *
V2) {
100 case Instruction::Invoke:
101 if (
const IntrinsicInst *II = dyn_cast<IntrinsicInst>(UserI))
102 switch (II->getIntrinsicID()) {
104 case Intrinsic::bswap:
109 case Intrinsic::bitreverse:
114 case Intrinsic::ctlz:
115 if (OperandNo == 0) {
119 ComputeKnownBits(BitWidth, I,
nullptr);
124 case Intrinsic::cttz:
125 if (OperandNo == 0) {
129 ComputeKnownBits(BitWidth, I,
nullptr);
137 case Instruction::Sub:
138 case Instruction::Mul:
144 case Instruction::Shl:
146 if (
auto *ShiftAmtC = dyn_cast<ConstantInt>(UserI->
getOperand(1))) {
148 AB = AOut.
lshr(ShiftAmt);
159 case Instruction::LShr:
161 if (
auto *ShiftAmtC = dyn_cast<ConstantInt>(UserI->
getOperand(1))) {
163 AB = AOut.
shl(ShiftAmt);
167 if (cast<LShrOperator>(UserI)->isExact())
171 case Instruction::AShr:
173 if (
auto *ShiftAmtC = dyn_cast<ConstantInt>(UserI->
getOperand(1))) {
174 uint64_t ShiftAmt = ShiftAmtC->getLimitedValue(BitWidth - 1);
175 AB = AOut.
shl(ShiftAmt);
185 if (cast<AShrOperator>(UserI)->isExact())
189 case Instruction::And:
196 if (OperandNo == 0) {
197 ComputeKnownBits(BitWidth, I, UserI->
getOperand(1));
201 ComputeKnownBits(BitWidth, UserI->
getOperand(0),
I);
205 case Instruction::Or:
212 if (OperandNo == 0) {
213 ComputeKnownBits(BitWidth, I, UserI->
getOperand(1));
217 ComputeKnownBits(BitWidth, UserI->
getOperand(0),
I);
218 AB &= ~(Known.
One & ~Known2.
One);
221 case Instruction::Xor:
222 case Instruction::PHI:
225 case Instruction::Trunc:
226 AB = AOut.
zext(BitWidth);
228 case Instruction::ZExt:
229 AB = AOut.
trunc(BitWidth);
231 case Instruction::SExt:
232 AB = AOut.
trunc(BitWidth);
249 auto &AC = getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
250 auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
251 DB.emplace(F, AC, DT);
259 void DemandedBits::performAnalysis() {
275 DEBUG(
dbgs() <<
"DemandedBits: Root: " << I <<
"\n");
281 if (AliveBits.try_emplace(&I,
IT->getBitWidth(), 0).
second)
302 while (!Worklist.
empty()) {
305 DEBUG(
dbgs() <<
"DemandedBits: Visiting: " << *UserI);
308 AOut = AliveBits[UserI];
314 Visited.insert(UserI);
323 unsigned BitWidth =
IT->getBitWidth();
327 AB =
APInt(BitWidth, 0);
332 determineLiveOperandBits(UserI, I, OI.getOperandNo(), AOut, AB,
339 APInt ABPrev(BitWidth, 0);
340 auto ABI = AliveBits.find(I);
341 if (ABI != AliveBits.end())
342 ABPrev = ABI->second;
344 APInt ABNew = AB | ABPrev;
345 if (ABNew != ABPrev || ABI == AliveBits.end()) {
346 AliveBits[
I] = std::move(ABNew);
349 }
else if (!Visited.count(I)) {
361 auto Found = AliveBits.find(I);
362 if (Found != AliveBits.end())
363 return Found->second;
370 return !Visited.count(I) && AliveBits.find(I) == AliveBits.end() &&
376 for (
auto &KV : AliveBits) {
377 OS <<
"DemandedBits: 0x" <<
utohexstr(KV.second.getLimitedValue()) <<
" for "
378 << *KV.first <<
"\n";
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::ZeroOrMore, cl::values(clEnumValN(DefaultIT,"arm-default-it","Generate IT block based on arch"), clEnumValN(RestrictedIT,"arm-restrict-it","Disallow deprecated IT based on ARMv8"), clEnumValN(NoRestrictedIT,"arm-no-restrict-it","Allow IT blocks based on ARMv7")))
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
void initializeDemandedBitsWrapperPassPass(PassRegistry &)
void setSignBit()
Set the sign bit to 1.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
static APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
A Module instance is used to store all the information related to an LLVM module. ...
APInt reverseBits() const
bool isInstructionDead(Instruction *I)
Return true if, during analysis, I could not be reached.
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
bool hasNoSignedWrap() const
Test whether this operation is known to never undergo signed overflow, aka the nsw property...
unsigned countMaxLeadingZeros() const
Returns the maximum number of leading zero bits possible.
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Get a value with low bits set.
An immutable pass that tracks lazily created AssumptionCache objects.
bool mayHaveSideEffects() const
Return true if the instruction may have side effects.
Analysis pass which computes a DominatorTree.
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr it the function does no...
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass...
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value...
A Use represents the edge between a Value definition and its users.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs...ExtraArgs)
Get the result of an analysis pass for a given IR unit.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
An analysis that produces DemandedBits for a function.
LLVM_NODISCARD bool empty() const
APInt shl(unsigned shiftAmt) const
Left-shift function.
demanded Demanded bits false
unsigned getActiveBits() const
Compute the number of active bits in the value.
DemandedBits run(Function &F, FunctionAnalysisManager &AM)
Run the analysis pass over a function and produce demanded bits information.
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Get a value with high bits set.
A set of analyses that are preserved following a run of a transformation pass.
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
APInt trunc(unsigned width) const
Truncate to new width.
Represent the analysis usage information of a pass.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
unsigned getBitWidth() const
Return the number of bits in the APInt.
FunctionPass class - This class is used to implement most global optimizations.
Value * getOperand(unsigned i) const
Class to represent integer types.
demanded Demanded bits analysis
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
A function analysis which provides an AssumptionCache.
INITIALIZE_PASS_BEGIN(DemandedBitsWrapperPass,"demanded-bits","Demanded bits analysis", false, false) INITIALIZE_PASS_END(DemandedBitsWrapperPass
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
LLVM_NODISCARD T pop_back_val()
void setPreservesCFG()
This function should be called by the pass, iff they do not:
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.
Class for arbitrary precision integers.
bool isIntegerTy() const
True if this is an instance of IntegerType.
void setPreservesAll()
Set by analyses that do not transform their input at all.
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
void print(raw_ostream &OS, const Module *M) const override
print - Print out the internal state of the pass.
static std::string utohexstr(uint64_t X, bool LowerCase=false)
unsigned countMaxTrailingZeros() const
Returns the maximum number of trailing zero bits possible.
LLVM Value Representation.
static bool isAlwaysLive(Instruction *I)
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
uint64_t getTypeSizeInBits(Type *Ty) const
Size examples:
This class implements an extremely fast bulk output stream that can only output to a stream...
inst_range instructions(Function *F)
APInt zext(unsigned width) const
Zero extend to a new width.
A container for analyses that lazily runs them and caches their results.
Legacy analysis pass which computes a DominatorTree.
FunctionPass * createDemandedBitsWrapperPass()
Create a demanded bits analysis pass.
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, OptimizationRemarkEmitter *ORE=nullptr)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
A special type used by analysis passes to provide an address that identifies that particular analysis...
const BasicBlock * getParent() const
void releaseMemory() override
Clean up memory in between runs.
bool hasNoUnsignedWrap() const
Test whether this operation is known to never undergo unsigned overflow, aka the nuw property...
void print(raw_ostream &OS)
A wrapper class for inspecting calls to intrinsic functions.