(Reland of #190092 with verifier change to look through GlobalAliases) So that it's preserved across all inline invocations rather than just one inliner pass run. This prevents cases where devirtualization in the simplification pipeline uncovers inlining opportunities that should be discarded due to inline history, but we dropped the inline history between inliner pass runs, causing code size to blow up, sometimes exponentially. For compile time reasons, we want to limit this to only call sites that have the potential to inline through SCCs, potentially with the help of devirtualization. This means that the callee is in a non-trivial (Ref)SCC, or the call site was previously an indirect call, which can potentially be devirtualized to call any function. The CGSCCUpdater::InlinedInternalEdges logic still seems to be relevant even with this change, as monster_scc.ll blows up if I remove that code. http://llvm-compile-time-tracker.com/compare.php?from=e830d88e8ae5f44a97cc76136a0a4e83aa9157c0&to=ed535e732fc41b79ab8efda2417886cbd0812f7f&stat=instructions:u Fixes #186926.
69 lines
2.2 KiB
C++
69 lines
2.2 KiB
C++
#include "llvm/IR/Function.h"
|
|
#include "llvm/IR/Module.h"
|
|
#include "llvm/Pass.h"
|
|
#include "llvm/Passes/PassBuilder.h"
|
|
#include "llvm/Plugins/PassPlugin.h"
|
|
#include "llvm/Support/CommandLine.h"
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include "llvm/Analysis/InlineOrder.h"
|
|
|
|
using namespace llvm;
|
|
|
|
namespace {
|
|
|
|
class NoFooInlineOrder : public InlineOrder {
|
|
public:
|
|
NoFooInlineOrder(FunctionAnalysisManager &FAM, const InlineParams &Params,
|
|
ModuleAnalysisManager &MAM, Module &M) {
|
|
DefaultInlineOrder = getDefaultInlineOrder(FAM, Params, MAM, M);
|
|
}
|
|
size_t size() override { return DefaultInlineOrder->size(); }
|
|
void push(CallBase *Elt) override {
|
|
// We ignore callees named "foo"
|
|
if (Elt->getCalledFunction()->getName() == "foo") {
|
|
DefaultInlineOrder->push(Elt);
|
|
}
|
|
}
|
|
CallBase *pop() override { return DefaultInlineOrder->pop(); }
|
|
void erase_if(function_ref<bool(CallBase *)> Pred) override {
|
|
DefaultInlineOrder->erase_if(Pred);
|
|
}
|
|
|
|
private:
|
|
std::unique_ptr<InlineOrder> DefaultInlineOrder;
|
|
};
|
|
|
|
std::unique_ptr<InlineOrder>
|
|
NoFooInlineOrderFactory(FunctionAnalysisManager &FAM,
|
|
const InlineParams &Params, ModuleAnalysisManager &MAM,
|
|
Module &M) {
|
|
return std::make_unique<NoFooInlineOrder>(FAM, Params, MAM, M);
|
|
}
|
|
|
|
} // namespace
|
|
|
|
/* New PM Registration */
|
|
llvm::PassPluginLibraryInfo getDefaultDynamicInlineOrderPluginInfo() {
|
|
return {LLVM_PLUGIN_API_VERSION, "DynamicDefaultInlineOrder",
|
|
LLVM_VERSION_STRING, [](PassBuilder &PB) {
|
|
// We use the PassBuilder's callback mechanism
|
|
// to register our Analysis: this will register
|
|
// our PluginInlineOrderAnalysis instance with
|
|
// the ModuleAnalysisManager
|
|
PB.registerAnalysisRegistrationCallback(
|
|
[](ModuleAnalysisManager &MAM) {
|
|
MAM.registerPass([] {
|
|
// defaultInlineOrderFactory will be
|
|
// used to create an InlineOrder
|
|
return PluginInlineOrderAnalysis(NoFooInlineOrderFactory);
|
|
});
|
|
});
|
|
}};
|
|
}
|
|
|
|
extern "C" LLVM_ATTRIBUTE_WEAK ::llvm::PassPluginLibraryInfo
|
|
llvmGetPassPluginInfo() {
|
|
return getDefaultDynamicInlineOrderPluginInfo();
|
|
}
|