31#define DEBUG_TYPE "partially-inline-libcalls"
34 "Controls transformations in partially-inline-libcalls");
42 if (
Call->onlyReadsMemory())
66 Builder.getTrue(),
Call->getNextNode(),
false,
71 CurrBBTerm->swapSuccessors();
76 Builder.SetInsertPoint(JoinBB, JoinBB->
begin());
77 PHINode *Phi = Builder.CreatePHI(Ty, 2);
78 Call->replaceAllUsesWith(Phi);
82 LibCallBB->
setName(
"call.sqrt");
83 Builder.SetInsertPoint(LibCallTerm);
85 Builder.Insert(LibCall);
89 Call->setDoesNotAccessMemory();
92 Builder.SetInsertPoint(CurrBBTerm);
93 Value *FCmp =
TTI->isFCmpOrdCheaperThanFCmpZero(Ty)
95 : Builder.CreateFCmpOGE(
Call->getOperand(0),
96 ConstantFP::get(Ty, 0.0));
97 CurrBBTerm->setCondition(FCmp);
98 if (CurrBBTerm->getFunction()->getEntryCount()) {
102 CurrBBTerm->setMetadata(LLVMContext::MD_prof,
106 Phi->addIncoming(
Call, &CurrBB);
107 Phi->addIncoming(LibCall, LibCallBB);
117 std::optional<DomTreeUpdater> DTU;
119 DTU.emplace(DT, DomTreeUpdater::UpdateStrategy::Lazy);
132 if (!
Call || !(CalledFunc =
Call->getCalledFunction()))
135 if (
Call->isNoBuiltin() ||
Call->isStrictFP())
138 if (
Call->isMustTailCall())
153 if (
TTI->haveFastSqrt(
Call->getType()) &&
155 DTU ? &*DTU :
nullptr, ORE))
184class PartiallyInlineLibCallsLegacyPass :
public FunctionPass {
188 PartiallyInlineLibCallsLegacyPass() :
FunctionPass(ID) {
205 TargetLibraryInfo *TLI =
206 &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(
F);
207 const TargetTransformInfo *
TTI =
208 &getAnalysis<TargetTransformInfoWrapperPass>().getTTI(
F);
209 DominatorTree *DT =
nullptr;
210 if (
auto *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>())
211 DT = &DTWP->getDomTree();
212 auto *ORE = &getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE();
218char PartiallyInlineLibCallsLegacyPass::ID = 0;
220 "partially-inline-libcalls",
221 "Partially inline calls to library functions",
false,
228 "partially-inline-libcalls",
232 return new PartiallyInlineLibCallsLegacyPass();
This file provides an implementation of debug counters.
#define DEBUG_COUNTER(VARNAME, COUNTERNAME, DESC)
static bool runOnFunction(Function &F, bool PostInlining)
uint64_t IntrinsicInst * II
static bool runPartiallyInlineLibCalls(Function &F, TargetLibraryInfo *TLI, const TargetTransformInfo *TTI, DominatorTree *DT, OptimizationRemarkEmitter *ORE)
static bool optimizeSQRT(CallInst *Call, Function *CalledFunc, BasicBlock &CurrBB, Function::iterator &BB, const TargetTransformInfo *TTI, DomTreeUpdater *DTU, OptimizationRemarkEmitter *ORE)
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
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.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
LLVM Basic Block Representation.
iterator begin()
Instruction iterator methods.
InstListType::iterator iterator
Instruction iterators...
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
This class represents a function call, abstracting a target machine's calling convention.
static bool shouldExecute(CounterInfo &Counter)
Analysis pass which computes a DominatorTree.
Legacy analysis pass which computes a DominatorTree.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
FunctionPass class - This class is used to implement most global optimizations.
BasicBlockListType::iterator iterator
bool hasLocalLinkage() const
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
LLVM_ABI BasicBlock * getSuccessor(unsigned Idx) const LLVM_READONLY
Return the specified successor. This instruction must be a terminator.
LLVM_ABI MDNode * createLikelyBranchWeights()
Return metadata containing two branch weights, with significant bias towards true destination.
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
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.
PreservedAnalyses & preserve()
Mark an analysis as preserved.
Analysis pass providing the TargetTransformInfo.
Analysis pass providing the TargetLibraryInfo.
Provides information about what library functions are available for the current target.
bool has(LibFunc F) const
Tests whether a library function is available.
LibFunc getLibFunc(StringRef funcName) const
Searches for a particular function name.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
const ParentTy * getParent() const
self_iterator getIterator()
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI FunctionPass * createPartiallyInlineLibCallsPass()
LLVM_ABI 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 ...
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
LLVM_ABI void initializePartiallyInlineLibCallsLegacyPassPass(PassRegistry &)