Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds the ability to load a plugin to control the inline order. This allows developing and distributing inlining heuristics outside of tree. And together with the inline advisor plugins allows for fine grained control of the inliner. The PluginInlineOrderAnalysis class serves as the entry point for dynamic advisors. Plugins must register instances of this class to provide their own InlineOrder. Reviewed By: kazu Differential Revision: https://reviews.llvm.org/D140637
- Loading branch information
Showing
9 changed files
with
426 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# The order plugin expects to not link against the Analysis, Support and Core | ||
# libraries, but expects them to exist in the process loading the plugin. This | ||
# doesn't work with DLLs on Windows (where a shared library can't have undefined | ||
# references), so just skip this testcase on Windows. | ||
if (NOT WIN32) | ||
unset(LLVM_LINK_COMPONENTS) | ||
add_llvm_library(InlineOrderPlugin MODULE BUILDTREE_ONLY InlineOrderPlugin.cpp) | ||
# Put PLUGIN next to the unit test executable. | ||
set_output_directory(InlineOrderPlugin | ||
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/../ | ||
LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/../ | ||
) | ||
set_target_properties(InlineOrderPlugin PROPERTIES FOLDER "Tests") | ||
|
||
# The plugin depends on some of the output files of intrinsics_gen, so make sure | ||
# it is built before the plugin. | ||
add_dependencies(InlineOrderPlugin intrinsics_gen) | ||
add_dependencies(AnalysisTests InlineOrderPlugin) | ||
set_property(TARGET InlineOrderPlugin PROPERTY FOLDER "Tests/UnitTests/AnalysisTests") | ||
endif() |
70 changes: 70 additions & 0 deletions
70
llvm/unittests/Analysis/InlineOrderPlugin/InlineOrderPlugin.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include "llvm/IR/Function.h" | ||
#include "llvm/IR/Module.h" | ||
#include "llvm/Pass.h" | ||
#include "llvm/Passes/PassBuilder.h" | ||
#include "llvm/Passes/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<std::pair<CallBase *, int>> { | ||
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(const std::pair<CallBase *, int> &Elt) override { | ||
// We ignore calles named "foo" | ||
if (Elt.first->getCalledFunction()->getName() == "foo") { | ||
DefaultInlineOrder->push(Elt); | ||
} | ||
} | ||
std::pair<CallBase *, int> pop() override { | ||
return DefaultInlineOrder->pop(); | ||
} | ||
void erase_if(function_ref<bool(std::pair<CallBase *, int>)> Pred) override { | ||
DefaultInlineOrder->erase_if(Pred); | ||
} | ||
|
||
private: | ||
std::unique_ptr<InlineOrder<std::pair<CallBase *, int>>> DefaultInlineOrder; | ||
}; | ||
|
||
std::unique_ptr<InlineOrder<std::pair<CallBase *, int>>> | ||
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.