47#define DEBUG_TYPE "libcalls-shrinkwrap"
49STATISTIC(NumWrappedOneCond,
"Number of One-Condition Wrappers Inserted");
50STATISTIC(NumWrappedTwoCond,
"Number of Two-Condition Wrappers Inserted");
53class LibCallsShrinkWrap :
public InstVisitor<LibCallsShrinkWrap> {
56 : TLI(TLI), DTU(DTU){};
60 for (
auto &CI : WorkList) {
61 LLVM_DEBUG(
dbgs() <<
"CDCE calls: " << CI->getCalledFunction()->getName()
87 auto Cond2 = createCond(BBBuilder, Arg2, Cmp2, Val2);
88 auto Cond1 = createCond(BBBuilder, Arg, Cmp, Val);
89 return BBBuilder.CreateOr(Cond1, Cond2);
96 return createOrCond(CI, Arg, Cmp, Val, Arg, Cmp2, Val2);
114 return createCond(BBBuilder, Arg, Cmp, Val);
120 return createCond(CI, Arg, Cmp, Val);
130bool LibCallsShrinkWrap::performCallDomainErrorOnly(
CallInst *CI,
177 shrinkWrapCI(CI,
Cond);
182bool LibCallsShrinkWrap::performCallRangeErrorOnly(
CallInst *CI,
201 case LibFunc_sinhl: {
202 Cond = generateTwoRangeCond(CI, Func);
209 Cond = generateOneRangeCond(CI, Func);
215 shrinkWrapCI(CI,
Cond);
220bool LibCallsShrinkWrap::performCallErrors(
CallInst *CI,
269 Cond = generateCondForPow(CI, Func);
277 assert(
Cond &&
"performCallErrors should not see an empty condition");
278 shrinkWrapCI(CI,
Cond);
284void LibCallsShrinkWrap::checkCandidate(
CallInst &CI) {
298 if (!TLI.getLibFunc(*Callee, Func) || !TLI.has(Func))
309 WorkList.push_back(&CI);
324 UpperBound = 11356.0f;
337 float UpperBound, LowerBound;
341 LowerBound = -710.0f;
351 LowerBound = -11357.0f;
352 UpperBound = 11357.0f;
355 LowerBound = -745.0f;
359 LowerBound = -103.0f;
363 LowerBound = -11399.0f;
364 UpperBound = 11356.0f;
367 LowerBound = -323.0f;
375 LowerBound = -4950.0f;
376 UpperBound = 4932.0f;
379 LowerBound = -1074.0f;
380 UpperBound = 1023.0f;
383 LowerBound = -149.0f;
387 LowerBound = -16445.0f;
388 UpperBound = 11383.0f;
417 if (Func != LibFunc_pow) {
427 double D = CF->getValueAPF().convertToDouble();
429 LLVM_DEBUG(
dbgs() <<
"Not handled pow(): constant base out of range\n");
443 unsigned Opcode =
I->getOpcode();
444 if (Opcode == Instruction::UIToFP || Opcode == Instruction::SIToFP) {
445 unsigned BW =
I->getOperand(0)->getType()->getPrimitiveSizeInBits();
462 LLVM_DEBUG(
dbgs() <<
"Not handled pow(): base not from integer convert\n");
468 assert(
Cond !=
nullptr &&
"ShrinkWrapCI is not expecting an empty call inst");
477 assert(SuccBB &&
"The split block should have a single successor");
487bool LibCallsShrinkWrap::perform(
CallInst *CI) {
490 assert(Callee &&
"perform() should apply to a non-empty callee");
491 TLI.getLibFunc(*Callee, Func);
492 assert(Func &&
"perform() is not expecting an empty function");
494 if (performCallDomainErrorOnly(CI, Func) || performCallRangeErrorOnly(CI, Func))
496 return performCallErrors(CI, Func);
501 if (
F.hasFnAttribute(Attribute::OptimizeForSize))
504 LibCallsShrinkWrap CCDCE(TLI, DTU);
506 bool Changed = CCDCE.perform();
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static bool runImpl(Function &F, const TargetLowering &TLI)
This is the interface for a simple mod/ref and alias analysis over globals.
static bool runImpl(Function &F, const TargetLibraryInfo &TLI, DominatorTree *DT)
FunctionAnalysisManager FAM
const SmallVectorImpl< MachineOperand > & Cond
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
A container for analyses that lazily runs them and caches their results.
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
LLVM Basic Block Representation.
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
const BasicBlock * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
const Function * getParent() const
Return the enclosing method, or null if none.
bool isNoBuiltin() const
Return true if the call should not be treated as a call to a builtin.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
Value * getArgOperand(unsigned i) const
This class represents a function call, abstracting a target machine's calling convention.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
@ FCMP_OLT
0 1 0 0 True if ordered and less than
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
ConstantFP - Floating Point Values [float, double].
This is an important base class in LLVM.
Analysis pass which computes a DominatorTree.
bool verify(VerificationLevel VL=VerificationLevel::Full) const
verify - checks if the tree is correct.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
DomTreeT & getDomTree()
Flush DomTree updates and return DomTree.
Value * CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
BasicBlock * GetInsertBlock() const
void setIsFPConstrained(bool IsCon)
Enable/Disable use of constrained floating point math.
LLVMContext & getContext() const
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Base class for instruction visitors.
RetTy visitCallInst(CallInst &I)
void removeFromParent()
This method unlinks 'this' from the containing basic block, but does not delete it.
InstListType::iterator insertInto(BasicBlock *ParentBB, InstListType::iterator It)
Inserts an unlinked instruction into ParentBB at position It and returns the iterator of the inserted...
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM)
MDNode * createUnlikelyBranchWeights()
Return metadata containing two branch weights, with significant bias towards false destination.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Analysis pass providing the TargetLibraryInfo.
Provides information about what library functions are available for the current target.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isX86_FP80Ty() const
Return true if this is x86 long double.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
void setName(const Twine &Name)
Change the name of the value.
LLVMContext & getContext() const
All values hold a context through their type.
const ParentTy * getParent() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
NodeAddr< FuncNode * > Func
This is an optimization pass for GlobalISel generic memory operations.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Constant * ConstantFoldCastInstruction(unsigned opcode, Constant *V, Type *DestTy)
Instruction * SplitBlockAndInsertIfThen(Value *Cond, BasicBlock::iterator SplitBefore, bool Unreachable, MDNode *BranchWeights=nullptr, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr, BasicBlock *ThenBlock=nullptr)
Split the containing block at the specified instruction - everything before SplitBefore stays in the ...