mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-21 12:02:58 +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
109 lines
4.2 KiB
C++
109 lines
4.2 KiB
C++
//===- Inliner.h - Inliner pass and infrastructure --------------*- C++ -*-===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_TRANSFORMS_IPO_INLINER_H
|
|
#define LLVM_TRANSFORMS_IPO_INLINER_H
|
|
|
|
#include "llvm/Analysis/CGSCCPassManager.h"
|
|
#include "llvm/Analysis/CallGraphSCCPass.h"
|
|
#include "llvm/Analysis/InlineCost.h"
|
|
#include "llvm/Analysis/LazyCallGraph.h"
|
|
#include "llvm/Analysis/TargetTransformInfo.h"
|
|
#include "llvm/Transforms/Utils/ImportedFunctionsInliningStatistics.h"
|
|
|
|
namespace llvm {
|
|
class AssumptionCacheTracker;
|
|
class CallSite;
|
|
class DataLayout;
|
|
class InlineCost;
|
|
class OptimizationRemarkEmitter;
|
|
class ProfileSummaryInfo;
|
|
|
|
/// This class contains all of the helper code which is used to perform the
|
|
/// inlining operations that do not depend on the policy. It contains the core
|
|
/// bottom-up inlining infrastructure that specific inliner passes use.
|
|
struct LegacyInlinerBase : public CallGraphSCCPass {
|
|
explicit LegacyInlinerBase(char &ID);
|
|
explicit LegacyInlinerBase(char &ID, bool InsertLifetime);
|
|
|
|
/// For this class, we declare that we require and preserve the call graph.
|
|
/// If the derived class implements this method, it should always explicitly
|
|
/// call the implementation here.
|
|
void getAnalysisUsage(AnalysisUsage &Info) const override;
|
|
|
|
bool doInitialization(CallGraph &CG) override;
|
|
|
|
/// Main run interface method, this implements the interface required by the
|
|
/// Pass class.
|
|
bool runOnSCC(CallGraphSCC &SCC) override;
|
|
|
|
using llvm::Pass::doFinalization;
|
|
/// Remove now-dead linkonce functions at the end of processing to avoid
|
|
/// breaking the SCC traversal.
|
|
bool doFinalization(CallGraph &CG) override;
|
|
|
|
/// 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(CallSite CS) = 0;
|
|
|
|
/// Remove dead functions.
|
|
///
|
|
/// This also includes a hack in the form of the 'AlwaysInlineOnly' flag
|
|
/// which restricts it to deleting functions with an 'AlwaysInline'
|
|
/// attribute. This is useful for the InlineAlways pass that only wants to
|
|
/// deal with that subset of the functions.
|
|
bool removeDeadFunctions(CallGraph &CG, bool AlwaysInlineOnly = false);
|
|
|
|
/// This function performs the main work of the pass. The default of
|
|
/// Inlinter::runOnSCC() calls skipSCC() before calling this method, but
|
|
/// derived classes which cannot be skipped can override that method and call
|
|
/// this function unconditionally.
|
|
bool inlineCalls(CallGraphSCC &SCC);
|
|
|
|
private:
|
|
// Insert @llvm.lifetime intrinsics.
|
|
bool InsertLifetime;
|
|
|
|
protected:
|
|
AssumptionCacheTracker *ACT;
|
|
ProfileSummaryInfo *PSI;
|
|
ImportedFunctionsInliningStatistics ImportedFunctionsStats;
|
|
};
|
|
|
|
/// The inliner pass for the new pass manager.
|
|
///
|
|
/// This pass wires together the inlining utilities and the inline cost
|
|
/// analysis into a CGSCC pass. It considers every call in every function in
|
|
/// the SCC and tries to inline if profitable. It can be tuned with a number of
|
|
/// parameters to control what cost model is used and what tradeoffs are made
|
|
/// when making the decision.
|
|
///
|
|
/// It should be noted that the legacy inliners do considerably more than this
|
|
/// inliner pass does. They provide logic for manually merging allocas, and
|
|
/// doing considerable DCE including the DCE of dead functions. This pass makes
|
|
/// every attempt to be simpler. DCE of functions requires complex reasoning
|
|
/// about comdat groups, etc. Instead, it is expected that other more focused
|
|
/// passes be composed to achieve the same end result.
|
|
class InlinerPass : public PassInfoMixin<InlinerPass> {
|
|
public:
|
|
InlinerPass(InlineParams Params = getInlineParams())
|
|
: Params(std::move(Params)) {}
|
|
|
|
PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM,
|
|
LazyCallGraph &CG, CGSCCUpdateResult &UR);
|
|
|
|
private:
|
|
InlineParams Params;
|
|
};
|
|
|
|
} // End llvm namespace
|
|
|
|
#endif
|