Go to the documentation of this file.
45 #define DEBUG_TYPE "libcalls-shrinkwrap"
47 STATISTIC(NumWrappedOneCond,
"Number of One-Condition Wrappers Inserted");
48 STATISTIC(NumWrappedTwoCond,
"Number of Two-Condition Wrappers Inserted");
51 class LibCallsShrinkWrapLegacyPass :
public FunctionPass {
65 "Conditionally eliminate dead library calls",
false,
79 for (
auto &CI : WorkList) {
80 LLVM_DEBUG(
dbgs() <<
"CDCE calls: " << CI->getCalledFunction()->getName()
106 auto Cond2 = createCond(BBBuilder,
Arg, Cmp2, Val2);
107 auto Cond1 = createCond(BBBuilder,
Arg, Cmp, Val);
108 return BBBuilder.CreateOr(Cond1, Cond2);
115 if (!
Arg->getType()->isFloatTy())
124 return createCond(BBBuilder,
Arg, Cmp, Val);
134 bool LibCallsShrinkWrap::performCallDomainErrorOnly(
CallInst *CI,
181 shrinkWrapCI(CI,
Cond);
186 bool LibCallsShrinkWrap::performCallRangeErrorOnly(
CallInst *CI,
205 case LibFunc_sinhl: {
206 Cond = generateTwoRangeCond(CI, Func);
213 Cond = generateOneRangeCond(CI, Func);
219 shrinkWrapCI(CI,
Cond);
224 bool LibCallsShrinkWrap::performCallErrors(
CallInst *CI,
273 Cond = generateCondForPow(CI, Func);
281 assert(
Cond &&
"performCallErrors should not see an empty condition");
282 shrinkWrapCI(CI,
Cond);
288 void LibCallsShrinkWrap::checkCandidate(
CallInst &CI) {
302 if (!TLI.getLibFunc(*Callee, Func) || !TLI.has(Func))
313 WorkList.push_back(&CI);
317 Value *LibCallsShrinkWrap::generateOneRangeCond(
CallInst *CI,
328 UpperBound = 11356.0f;
339 Value *LibCallsShrinkWrap::generateTwoRangeCond(
CallInst *CI,
341 float UpperBound, LowerBound;
345 LowerBound = -710.0f;
355 LowerBound = -11357.0f;
356 UpperBound = 11357.0f;
359 LowerBound = -745.0f;
363 LowerBound = -103.0f;
367 LowerBound = -11399.0f;
368 UpperBound = 11356.0f;
371 LowerBound = -323.0f;
379 LowerBound = -4950.0f;
380 UpperBound = 4932.0f;
383 LowerBound = -1074.0f;
384 UpperBound = 1023.0f;
387 LowerBound = -149.0f;
391 LowerBound = -16445.0f;
392 UpperBound = 11383.0f;
421 if (Func != LibFunc_pow) {
432 double D = CF->getValueAPF().convertToDouble();
434 LLVM_DEBUG(
dbgs() <<
"Not handled pow(): constant base out of range\n");
440 if (!
Exp->getType()->isFloatTy())
451 unsigned Opcode =
I->getOpcode();
452 if (Opcode == Instruction::UIToFP || Opcode == Instruction::SIToFP) {
453 unsigned BW =
I->getOperand(0)->getType()->getPrimitiveSizeInBits();
469 if (!
Exp->getType()->isFloatTy())
471 if (!
Base->getType()->isFloatTy())
478 LLVM_DEBUG(
dbgs() <<
"Not handled pow(): base not from integer convert\n");
484 assert(
Cond !=
nullptr &&
"ShrinkWrapCI is not expecting an empty call inst");
493 assert(SuccBB &&
"The split block should have a single successor");
503 bool LibCallsShrinkWrap::perform(
CallInst *CI) {
506 assert(Callee &&
"perform() should apply to a non-empty callee");
507 TLI.getLibFunc(*Callee, Func);
508 assert(Func &&
"perform() is not expecting an empty function");
510 if (performCallDomainErrorOnly(CI, Func) || performCallRangeErrorOnly(CI, Func))
512 return performCallErrors(CI, Func);
515 void LibCallsShrinkWrapLegacyPass::getAnalysisUsage(
AnalysisUsage &AU)
const {
523 if (
F.hasFnAttribute(Attribute::OptimizeForSize))
525 LibCallsShrinkWrap CCDCE(TLI, DT);
527 bool Changed = CCDCE.perform();
535 auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(
F);
536 auto *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>();
537 auto *DT = DTWP ? &DTWP->getDomTree() :
nullptr;
546 return new LibCallsShrinkWrapLegacyPass();
A set of analyses that are preserved following a run of a transformation pass.
partially inline libcalls
This is an optimization pass for GlobalISel generic memory operations.
bool isNoBuiltin() const
Return true if the call should not be treated as a call to a builtin.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
LibCallsShrinkWrap(const TargetLibraryInfo &TLI, DominatorTree *DT)
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="")
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
FunctionAnalysisManager FAM
The instances of the Type class are immutable: once they are created, they are never changed.
const BasicBlock * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
bool isX86_FP80Ty() const
Return true if this is x86 long double.
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
Itanium Name Demangler i e convert the string _Z1fv into and both[sub] projects need to demangle but neither can depend on each other *libcxxabi needs the demangler to implement which is part of the itanium ABI spec *LLVM needs a copy for a bunch of and cannot rely on the system s __cxa_demangle because it a might not be and b may not be up to date on the latest language features The copy of the demangler in LLVM has some extra stuff that aren t needed in which depend on the shared generic components Despite these we want to keep the core generic demangling library identical between both copies to simplify development and testing If you re working on the generic library
LLVM Basic Block Representation.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Itanium Name Demangler i e convert the string _Z1fv into f()". You can also use the CRTP base ManglingParser to perform some simple analysis on the mangled name
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
MDNode * createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight)
Return metadata containing two branch weights.
Represent the analysis usage information of a pass.
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
FunctionPass * createLibCallsShrinkWrapPass()
Legacy analysis pass which computes a DominatorTree.
LLVMContext & getContext() const
STATISTIC(NumFunctions, "Total number of functions")
ConstantFP - Floating Point Values [float, double].
void setName(const Twine &Name)
Change the name of the value.
INITIALIZE_PASS_BEGIN(LibCallsShrinkWrapLegacyPass, "libcalls-shrinkwrap", "Conditionally eliminate dead library calls", false, false) INITIALIZE_PASS_END(LibCallsShrinkWrapLegacyPass
Value * CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
@ FCMP_OLT
0 1 0 0 True if ordered and less than
void removeFromParent()
This method unlinks 'this' from the containing basic block, but does not delete it.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
void visitCallInst(CallInst &CI)
This is an important base class in LLVM.
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
libcalls Conditionally eliminate dead library calls
SmallVector< MachineOperand, 4 > Cond
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Type * getType() const
All values are typed, get the type of this value.
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
LLVMContext & getContext() const
All values hold a context through their type.
Base class for instruction visitors.
static bool runImpl(Function &F, const TargetLibraryInfo &TLI, DominatorTree *DT)
amdgpu Simplify well known AMD library false FunctionCallee Callee
void initializeLibCallsShrinkWrapLegacyPassPass(PassRegistry &)
static bool runOnFunction(Function &F, bool PostInlining)
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
static Constant * get(Type *Ty, double V)
This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in...
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
Provides information about what library functions are available for the current target.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Analysis pass which computes a DominatorTree.
const InstListType & getInstList() const
Return the underlying instruction list container.
static Constant * getFPExtend(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Value * getArgOperand(unsigned i) const
const BasicBlock * getParent() const
Legacy wrapper pass to provide the GlobalsAAResult object.
bool verify(VerificationLevel VL=VerificationLevel::Full) const
verify - checks if the tree is correct.
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
A container for analyses that lazily runs them and caches their results.
FunctionPass class - This class is used to implement most global optimizations.
This class represents a function call, abstracting a target machine's calling convention.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM)
AnalysisUsage & addRequired()
Instruction * SplitBlockAndInsertIfThen(Value *Cond, Instruction *SplitBefore, bool Unreachable, MDNode *BranchWeights, DominatorTree *DT, LoopInfo *LI=nullptr, BasicBlock *ThenBlock=nullptr)
Split the containing block at the specified instruction - everything before SplitBefore stays in the ...
LLVM Value Representation.
Analysis pass providing the TargetLibraryInfo.
char & LibCallsShrinkWrapPassID