Skip to content

Commit

Permalink
[llvm][NFC] CallSite removal from inliner-related files
Browse files Browse the repository at this point in the history
Summary: This removes CallSite from inliner files. Some dependencies where thus affected.

Reviewers: dblaikie, davidxl, craig.topper

Subscribers: arsenm, jvesely, nhaehnle, eraman, hiraditya, aheejin, kerbowa, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D77991
  • Loading branch information
Mircea Trofin authored and mtrofin committed Apr 14, 2020
1 parent 0a54887 commit 4aae4e3
Show file tree
Hide file tree
Showing 11 changed files with 205 additions and 243 deletions.
11 changes: 1 addition & 10 deletions llvm/include/llvm/Transforms/IPO/Inliner.h
Expand Up @@ -13,7 +13,6 @@
#include "llvm/Analysis/CallGraphSCCPass.h"
#include "llvm/Analysis/InlineCost.h"
#include "llvm/Analysis/LazyCallGraph.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Transforms/Utils/ImportedFunctionsInliningStatistics.h"
#include <utility>
Expand Down Expand Up @@ -51,15 +50,7 @@ struct LegacyInlinerBase : public CallGraphSCCPass {
/// This method must be implemented by the subclass to determine the cost of
/// inlining the specified call site. If the cost returned is greater than
/// the current inline threshold, the call site is not inlined.
// FIXME(mtrofin): remove this in favor of the CallBase-based one
virtual InlineCost getInlineCost(CallSite CS) = 0;

/// This method must be implemented by the subclass to determine the cost of
/// inlining the specified call site. If the cost returned is greater than
/// the current inline threshold, the call site is not inlined.
virtual InlineCost getInlineCost(CallBase &CB) {
return getInlineCost(CallSite(&CB));
}
virtual InlineCost getInlineCost(CallBase &CB) = 0;

/// Remove dead functions.
///
Expand Down
5 changes: 1 addition & 4 deletions llvm/include/llvm/Transforms/Utils/Cloning.h
Expand Up @@ -228,10 +228,7 @@ class InlineFunctionInfo {
/// and all varargs at the callsite will be passed to any calls to
/// ForwardVarArgsTo. The caller of InlineFunction has to make sure any varargs
/// are only used by ForwardVarArgsTo.
InlineResult InlineFunction(CallBase *CB, InlineFunctionInfo &IFI,
AAResults *CalleeAAR = nullptr,
bool InsertLifetime = true);
InlineResult InlineFunction(CallSite CS, InlineFunctionInfo &IFI,
InlineResult InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
AAResults *CalleeAAR = nullptr,
bool InsertLifetime = true,
Function *ForwardVarArgsTo = nullptr);
Expand Down
27 changes: 13 additions & 14 deletions llvm/lib/CodeGen/SafeStack.cpp
Expand Up @@ -33,7 +33,6 @@
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/IR/Argument.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/ConstantRange.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DIBuilder.h"
Expand Down Expand Up @@ -200,7 +199,7 @@ class SafeStack {
bool IsAccessSafe(Value *Addr, uint64_t Size, const Value *AllocaPtr,
uint64_t AllocaSize);

bool ShouldInlinePointerAddress(CallSite &CS);
bool ShouldInlinePointerAddress(CallInst &CI);
void TryInlinePointerAddress();

public:
Expand Down Expand Up @@ -322,7 +321,7 @@ bool SafeStack::IsSafeStackAlloca(const Value *AllocaPtr, uint64_t AllocaSize) {

case Instruction::Call:
case Instruction::Invoke: {
ImmutableCallSite CS(I);
const CallBase &CS = *cast<CallBase>(I);

if (I->isLifetimeStartOrEnd())
continue;
Expand All @@ -344,8 +343,8 @@ bool SafeStack::IsSafeStackAlloca(const Value *AllocaPtr, uint64_t AllocaSize) {
// FIXME: a more precise solution would require an interprocedural
// analysis here, which would look at all uses of an argument inside
// the function being called.
ImmutableCallSite::arg_iterator B = CS.arg_begin(), E = CS.arg_end();
for (ImmutableCallSite::arg_iterator A = B; A != E; ++A)
auto B = CS.arg_begin(), E = CS.arg_end();
for (auto A = B; A != E; ++A)
if (A->get() == V)
if (!(CS.doesNotCapture(A - B) && (CS.doesNotAccessMemory(A - B) ||
CS.doesNotAccessMemory()))) {
Expand Down Expand Up @@ -705,34 +704,34 @@ void SafeStack::moveDynamicAllocasToUnsafeStack(
}
}

bool SafeStack::ShouldInlinePointerAddress(CallSite &CS) {
Function *Callee = CS.getCalledFunction();
if (CS.hasFnAttr(Attribute::AlwaysInline) &&
bool SafeStack::ShouldInlinePointerAddress(CallInst &CI) {
Function *Callee = CI.getCalledFunction();
if (CI.hasFnAttr(Attribute::AlwaysInline) &&
isInlineViable(*Callee).isSuccess())
return true;
if (Callee->isInterposable() || Callee->hasFnAttribute(Attribute::NoInline) ||
CS.isNoInline())
CI.isNoInline())
return false;
return true;
}

void SafeStack::TryInlinePointerAddress() {
if (!isa<CallInst>(UnsafeStackPtr))
auto *CI = dyn_cast<CallInst>(UnsafeStackPtr);
if (!CI)
return;

if(F.hasOptNone())
return;

CallSite CS(UnsafeStackPtr);
Function *Callee = CS.getCalledFunction();
Function *Callee = CI->getCalledFunction();
if (!Callee || Callee->isDeclaration())
return;

if (!ShouldInlinePointerAddress(CS))
if (!ShouldInlinePointerAddress(*CI))
return;

InlineFunctionInfo IFI;
InlineFunction(CS, IFI);
InlineFunction(*CI, IFI);
}

bool SafeStack::run() {
Expand Down
37 changes: 18 additions & 19 deletions llvm/lib/Target/AMDGPU/AMDGPUInline.cpp
Expand Up @@ -23,7 +23,6 @@
#include "llvm/Analysis/InlineCost.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Module.h"
Expand Down Expand Up @@ -67,9 +66,9 @@ class AMDGPUInliner : public LegacyInlinerBase {

static char ID; // Pass identification, replacement for typeid

unsigned getInlineThreshold(CallSite CS) const;
unsigned getInlineThreshold(CallBase &CB) const;

InlineCost getInlineCost(CallSite CS) override;
InlineCost getInlineCost(CallBase &CB) override;

bool runOnSCC(CallGraphSCC &SCC) override;

Expand Down Expand Up @@ -106,13 +105,13 @@ void AMDGPUInliner::getAnalysisUsage(AnalysisUsage &AU) const {
LegacyInlinerBase::getAnalysisUsage(AU);
}

unsigned AMDGPUInliner::getInlineThreshold(CallSite CS) const {
unsigned AMDGPUInliner::getInlineThreshold(CallBase &CB) const {
int Thres = Params.DefaultThreshold;

Function *Caller = CS.getCaller();
Function *Caller = CB.getCaller();
// Listen to the inlinehint attribute when it would increase the threshold
// and the caller does not need to minimize its size.
Function *Callee = CS.getCalledFunction();
Function *Callee = CB.getCalledFunction();
bool InlineHint = Callee && !Callee->isDeclaration() &&
Callee->hasFnAttribute(Attribute::InlineHint);
if (InlineHint && Params.HintThreshold && Params.HintThreshold > Thres
Expand All @@ -129,7 +128,7 @@ unsigned AMDGPUInliner::getInlineThreshold(CallSite CS) const {
// Increase the inline threshold to allow inliniting in this case.
uint64_t AllocaSize = 0;
SmallPtrSet<const AllocaInst *, 8> AIVisited;
for (Value *PtrArg : CS.args()) {
for (Value *PtrArg : CB.args()) {
PointerType *Ty = dyn_cast<PointerType>(PtrArg->getType());
if (!Ty || (Ty->getAddressSpace() != AMDGPUAS::PRIVATE_ADDRESS &&
Ty->getAddressSpace() != AMDGPUAS::FLAT_ADDRESS))
Expand All @@ -156,8 +155,8 @@ unsigned AMDGPUInliner::getInlineThreshold(CallSite CS) const {

// Check if call is just a wrapper around another call.
// In this case we only have call and ret instructions.
static bool isWrapperOnlyCall(CallSite CS) {
Function *Callee = CS.getCalledFunction();
static bool isWrapperOnlyCall(CallBase &CB) {
Function *Callee = CB.getCalledFunction();
if (!Callee || Callee->size() != 1)
return false;
const BasicBlock &BB = Callee->getEntryBlock();
Expand All @@ -174,32 +173,32 @@ static bool isWrapperOnlyCall(CallSite CS) {
return false;
}

InlineCost AMDGPUInliner::getInlineCost(CallSite CS) {
Function *Callee = CS.getCalledFunction();
Function *Caller = CS.getCaller();
InlineCost AMDGPUInliner::getInlineCost(CallBase &CB) {
Function *Callee = CB.getCalledFunction();
Function *Caller = CB.getCaller();

if (!Callee || Callee->isDeclaration())
return llvm::InlineCost::getNever("undefined callee");

if (CS.isNoInline())
if (CB.isNoInline())
return llvm::InlineCost::getNever("noinline");

TargetTransformInfo &TTI = TTIWP->getTTI(*Callee);
if (!TTI.areInlineCompatible(Caller, Callee))
return llvm::InlineCost::getNever("incompatible");

if (CS.hasFnAttr(Attribute::AlwaysInline)) {
if (CB.hasFnAttr(Attribute::AlwaysInline)) {
auto IsViable = isInlineViable(*Callee);
if (IsViable.isSuccess())
return llvm::InlineCost::getAlways("alwaysinline viable");
return llvm::InlineCost::getNever(IsViable.getFailureReason());
}

if (isWrapperOnlyCall(CS))
if (isWrapperOnlyCall(CB))
return llvm::InlineCost::getAlways("wrapper-only call");

InlineParams LocalParams = Params;
LocalParams.DefaultThreshold = (int)getInlineThreshold(CS);
LocalParams.DefaultThreshold = (int)getInlineThreshold(CB);
bool RemarksEnabled = false;
const auto &BBs = Caller->getBasicBlockList();
if (!BBs.empty()) {
Expand All @@ -214,9 +213,9 @@ InlineCost AMDGPUInliner::getInlineCost(CallSite CS) {
return ACT->getAssumptionCache(F);
};

auto IC = llvm::getInlineCost(cast<CallBase>(*CS.getInstruction()), Callee,
LocalParams, TTI, GetAssumptionCache, None,
GetTLI, PSI, RemarksEnabled ? &ORE : nullptr);
auto IC =
llvm::getInlineCost(CB, Callee, LocalParams, TTI, GetAssumptionCache,
None, GetTLI, PSI, RemarksEnabled ? &ORE : nullptr);

if (IC && !IC.isAlways() && !Callee->hasFnAttribute(Attribute::InlineHint)) {
// Single BB does not increase total BB amount, thus subtract 1
Expand Down
21 changes: 10 additions & 11 deletions llvm/lib/Transforms/IPO/AlwaysInliner.cpp
Expand Up @@ -16,7 +16,6 @@
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/InlineCost.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/CallingConv.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Instructions.h"
Expand All @@ -43,7 +42,7 @@ PreservedAnalyses AlwaysInlinerPass::run(Module &M,
};
InlineFunctionInfo IFI(/*cg=*/nullptr, &GetAssumptionCache);

SmallSetVector<CallSite, 16> Calls;
SmallSetVector<CallBase *, 16> Calls;
bool Changed = false;
SmallVector<Function *, 16> InlinedFunctions;
for (Function &F : M)
Expand All @@ -52,15 +51,15 @@ PreservedAnalyses AlwaysInlinerPass::run(Module &M,
Calls.clear();

for (User *U : F.users())
if (auto CS = CallSite(U))
if (CS.getCalledFunction() == &F)
Calls.insert(CS);
if (auto *CB = dyn_cast<CallBase>(U))
if (CB->getCalledFunction() == &F)
Calls.insert(CB);

for (CallSite CS : Calls)
for (CallBase *CB : Calls)
// FIXME: We really shouldn't be able to fail to inline at this point!
// We should do something to log or check the inline failures here.
Changed |=
InlineFunction(CS, IFI, /*CalleeAAR=*/nullptr, InsertLifetime)
InlineFunction(*CB, IFI, /*CalleeAAR=*/nullptr, InsertLifetime)
.isSuccess();

// Remember to try and delete this function afterward. This both avoids
Expand Down Expand Up @@ -117,7 +116,7 @@ class AlwaysInlinerLegacyPass : public LegacyInlinerBase {

static char ID; // Pass identification, replacement for typeid

InlineCost getInlineCost(CallSite CS) override;
InlineCost getInlineCost(CallBase &CB) override;

using llvm::Pass::doFinalization;
bool doFinalization(CallGraph &CG) override {
Expand Down Expand Up @@ -152,8 +151,8 @@ Pass *llvm::createAlwaysInlinerLegacyPass(bool InsertLifetime) {
/// computed here, but as we only expect to do this for relatively few and
/// small functions which have the explicit attribute to force inlining, it is
/// likely not worth it in practice.
InlineCost AlwaysInlinerLegacyPass::getInlineCost(CallSite CS) {
Function *Callee = CS.getCalledFunction();
InlineCost AlwaysInlinerLegacyPass::getInlineCost(CallBase &CB) {
Function *Callee = CB.getCalledFunction();

// Only inline direct calls to functions with always-inline attributes
// that are viable for inlining.
Expand All @@ -164,7 +163,7 @@ InlineCost AlwaysInlinerLegacyPass::getInlineCost(CallSite CS) {
if (Callee->isDeclaration())
return InlineCost::getNever("no definition");

if (!CS.hasFnAttr(Attribute::AlwaysInline))
if (!CB.hasFnAttr(Attribute::AlwaysInline))
return InlineCost::getNever("no alwaysinline attribute");

auto IsViable = isInlineViable(*Callee);
Expand Down
15 changes: 7 additions & 8 deletions llvm/lib/Transforms/IPO/InlineSimple.cpp
Expand Up @@ -15,7 +15,6 @@
#include "llvm/Analysis/ProfileSummaryInfo.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/CallingConv.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Instructions.h"
Expand Down Expand Up @@ -52,26 +51,26 @@ class SimpleInliner : public LegacyInlinerBase {

static char ID; // Pass identification, replacement for typeid

InlineCost getInlineCost(CallSite CS) override {
Function *Callee = CS.getCalledFunction();
InlineCost getInlineCost(CallBase &CB) override {
Function *Callee = CB.getCalledFunction();
TargetTransformInfo &TTI = TTIWP->getTTI(*Callee);

bool RemarksEnabled = false;
const auto &BBs = CS.getCaller()->getBasicBlockList();
const auto &BBs = CB.getCaller()->getBasicBlockList();
if (!BBs.empty()) {
auto DI = OptimizationRemark(DEBUG_TYPE, "", DebugLoc(), &BBs.front());
if (DI.isEnabled())
RemarksEnabled = true;
}
OptimizationRemarkEmitter ORE(CS.getCaller());
OptimizationRemarkEmitter ORE(CB.getCaller());

std::function<AssumptionCache &(Function &)> GetAssumptionCache =
[&](Function &F) -> AssumptionCache & {
return ACT->getAssumptionCache(F);
};
return llvm::getInlineCost(
cast<CallBase>(*CS.getInstruction()), Params, TTI, GetAssumptionCache,
/*GetBFI=*/None, GetTLI, PSI, RemarksEnabled ? &ORE : nullptr);
return llvm::getInlineCost(CB, Params, TTI, GetAssumptionCache,
/*GetBFI=*/None, GetTLI, PSI,
RemarksEnabled ? &ORE : nullptr);
}

bool runOnSCC(CallGraphSCC &SCC) override;
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/IPO/Inliner.cpp
Expand Up @@ -283,7 +283,7 @@ static InlineResult inlineCallIfPossible(

// Try to inline the function. Get the list of static allocas that were
// inlined.
InlineResult IR = InlineFunction(&CS, IFI, &AAR, InsertLifetime);
InlineResult IR = InlineFunction(CS, IFI, &AAR, InsertLifetime);
if (!IR.isSuccess())
return IR;

Expand Down Expand Up @@ -1087,7 +1087,7 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,

using namespace ore;

InlineResult IR = InlineFunction(CS, IFI);
InlineResult IR = InlineFunction(*CS, IFI);
if (!IR.isSuccess()) {
setInlineRemark(*CS, std::string(IR.getFailureReason()) + "; " +
inlineCostStr(*OIC));
Expand Down

0 comments on commit 4aae4e3

Please sign in to comment.