mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-22 20:43:44 +02:00
74eb1e2070
This doesn't implement *every* feature of the existing inliner, but tries to implement the most important ones for building a functional optimization pipeline and beginning to sort out bugs, regressions, and other problems. Notable, but intentional omissions: - No alloca merging support. Why? Because it isn't clear we want to do this at all. Active discussion and investigation is going on to remove it, so for simplicity I omitted it. - No support for trying to iterate on "internally" devirtualized calls. Why? Because it adds what I suspect is inappropriate coupling for little or no benefit. We will have an outer iteration system that tracks devirtualization including that from function passes and iterates already. We should improve that rather than approximate it here. - Optimization remarks. Why? Purely to make the patch smaller, no other reason at all. The last one I'll probably work on almost immediately. But I wanted to skip it in the initial patch to try to focus the change as much as possible as there is already a lot of code moving around and both of these *could* be skipped without really disrupting the core logic. A summary of the different things happening here: 1) Adding the usual new PM class and rigging. 2) Fixing minor underlying assumptions in the inline cost analysis or inline logic that don't generally hold in the new PM world. 3) Adding the core pass logic which is in essence a loop over the calls in the nodes in the call graph. This is a bit duplicated from the old inliner, but only a handful of lines could realistically be shared. (I tried at first, and it really didn't help anything.) All told, this is only about 100 lines of code, and most of that is the mechanics of wiring up analyses from the new PM world. 4) Updating the LazyCallGraph (in the new PM) based on the *newly inlined* calls and references. This is very minimal because we cannot form cycles. 5) When inlining removes the last use of a function, eagerly nuking the body of the function so that any "one use remaining" inline cost heuristics are immediately refined, and queuing these functions to be completely deleted once inlining is complete and the call graph updated to reflect that they have become dead. 6) After all the inlining for a particular function, updating the LazyCallGraph and the CGSCC pass manager to reflect the function-local simplifications that are done immediately and internally by the inline utilties. These are the exact same fundamental set of CG updates done by arbitrary function passes. 7) Adding a bunch of test cases to specifically target CGSCC and other subtle aspects in the new PM world. Many thanks to the careful review from Easwaran and Sanjoy and others! Differential Revision: https://reviews.llvm.org/D24226 llvm-svn: 290161
112 lines
3.7 KiB
C++
112 lines
3.7 KiB
C++
//===- InlineSimple.cpp - Code to perform simple function inlining --------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file implements bottom-up inlining of functions into callees.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/Analysis/AssumptionCache.h"
|
|
#include "llvm/Analysis/CallGraph.h"
|
|
#include "llvm/Analysis/InlineCost.h"
|
|
#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"
|
|
#include "llvm/IR/IntrinsicInst.h"
|
|
#include "llvm/IR/Module.h"
|
|
#include "llvm/IR/Type.h"
|
|
#include "llvm/Transforms/IPO.h"
|
|
#include "llvm/Transforms/IPO/Inliner.h"
|
|
|
|
using namespace llvm;
|
|
|
|
#define DEBUG_TYPE "inline"
|
|
|
|
namespace {
|
|
|
|
/// \brief Actual inliner pass implementation.
|
|
///
|
|
/// The common implementation of the inlining logic is shared between this
|
|
/// inliner pass and the always inliner pass. The two passes use different cost
|
|
/// analyses to determine when to inline.
|
|
class SimpleInliner : public LegacyInlinerBase {
|
|
|
|
InlineParams Params;
|
|
|
|
public:
|
|
SimpleInliner() : LegacyInlinerBase(ID), Params(llvm::getInlineParams()) {
|
|
initializeSimpleInlinerPass(*PassRegistry::getPassRegistry());
|
|
}
|
|
|
|
explicit SimpleInliner(InlineParams Params)
|
|
: LegacyInlinerBase(ID), Params(Params) {
|
|
initializeSimpleInlinerPass(*PassRegistry::getPassRegistry());
|
|
}
|
|
|
|
static char ID; // Pass identification, replacement for typeid
|
|
|
|
InlineCost getInlineCost(CallSite CS) override {
|
|
Function *Callee = CS.getCalledFunction();
|
|
TargetTransformInfo &TTI = TTIWP->getTTI(*Callee);
|
|
std::function<AssumptionCache &(Function &)> GetAssumptionCache =
|
|
[&](Function &F) -> AssumptionCache & {
|
|
return ACT->getAssumptionCache(F);
|
|
};
|
|
return llvm::getInlineCost(CS, Params, TTI, GetAssumptionCache, PSI);
|
|
}
|
|
|
|
bool runOnSCC(CallGraphSCC &SCC) override;
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override;
|
|
|
|
private:
|
|
TargetTransformInfoWrapperPass *TTIWP;
|
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
char SimpleInliner::ID = 0;
|
|
INITIALIZE_PASS_BEGIN(SimpleInliner, "inline", "Function Integration/Inlining",
|
|
false, false)
|
|
INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
|
|
INITIALIZE_PASS_DEPENDENCY(CallGraphWrapperPass)
|
|
INITIALIZE_PASS_DEPENDENCY(ProfileSummaryInfoWrapperPass)
|
|
INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
|
|
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
|
|
INITIALIZE_PASS_END(SimpleInliner, "inline", "Function Integration/Inlining",
|
|
false, false)
|
|
|
|
Pass *llvm::createFunctionInliningPass() { return new SimpleInliner(); }
|
|
|
|
Pass *llvm::createFunctionInliningPass(int Threshold) {
|
|
return new SimpleInliner(llvm::getInlineParams(Threshold));
|
|
}
|
|
|
|
Pass *llvm::createFunctionInliningPass(unsigned OptLevel,
|
|
unsigned SizeOptLevel) {
|
|
return new SimpleInliner(llvm::getInlineParams(OptLevel, SizeOptLevel));
|
|
}
|
|
|
|
Pass *llvm::createFunctionInliningPass(InlineParams &Params) {
|
|
return new SimpleInliner(Params);
|
|
}
|
|
|
|
bool SimpleInliner::runOnSCC(CallGraphSCC &SCC) {
|
|
TTIWP = &getAnalysis<TargetTransformInfoWrapperPass>();
|
|
return LegacyInlinerBase::runOnSCC(SCC);
|
|
}
|
|
|
|
void SimpleInliner::getAnalysisUsage(AnalysisUsage &AU) const {
|
|
AU.addRequired<TargetTransformInfoWrapperPass>();
|
|
LegacyInlinerBase::getAnalysisUsage(AU);
|
|
}
|