Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions llvm/include/llvm/Analysis/InlineAdvisor.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,15 +287,13 @@ class PluginInlineAdvisorAnalysis
: public AnalysisInfoMixin<PluginInlineAdvisorAnalysis> {
public:
static AnalysisKey Key;
static bool HasBeenRegistered;

typedef InlineAdvisor *(*AdvisorFactory)(Module &M,
FunctionAnalysisManager &FAM,
InlineParams Params,
InlineContext IC);

PluginInlineAdvisorAnalysis(AdvisorFactory Factory) : Factory(Factory) {
HasBeenRegistered = true;
assert(Factory != nullptr &&
"The plugin advisor factory should not be a null pointer.");
}
Expand Down
5 changes: 0 additions & 5 deletions llvm/include/llvm/Analysis/InlineOrder.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class PluginInlineOrderAnalysis
ModuleAnalysisManager &MAM, Module &M);

PluginInlineOrderAnalysis(InlineOrderFactory Factory) : Factory(Factory) {
HasBeenRegistered = true;
assert(Factory != nullptr &&
"The plugin inline order factory should not be a null pointer.");
}
Expand All @@ -71,11 +70,7 @@ class PluginInlineOrderAnalysis
Result run(Module &, ModuleAnalysisManager &) { return {Factory}; }
Result getResult() { return {Factory}; }

static bool isRegistered() { return HasBeenRegistered; }
static void unregister() { HasBeenRegistered = false; }

private:
static bool HasBeenRegistered;
InlineOrderFactory Factory;
};

Expand Down
12 changes: 8 additions & 4 deletions llvm/include/llvm/IR/PassManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,11 @@ template <typename IRUnitT, typename... ExtraArgTs> class AnalysisManager {
AnalysisResultLists.clear();
}

/// Returns true if the specified analysis pass is registered.
template <typename PassT> bool isPassRegistered() const {
return AnalysisPasses.count(PassT::ID());
}

/// Get the result of an analysis pass for a given IR unit.
///
/// Runs the analysis if a cached result is not available.
Expand Down Expand Up @@ -458,10 +463,9 @@ template <typename IRUnitT, typename... ExtraArgTs> class AnalysisManager {
/// and this function returns true.
///
/// (Note: Although the return value of this function indicates whether or not
/// an analysis was previously registered, there intentionally isn't a way to
/// query this directly. Instead, you should just register all the analyses
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please keep the bit about just registering analyses without checking if they're already registered

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like "Although the return value of this function indicates whether or not
/// an analysis was previously registered, you should just register all the analyses..."

/// you might want and let this class run them lazily. This idiom lets us
/// minimize the number of times we have to look up analyses in our
/// an analysis was previously registered, you should just register all the
/// analyses you might want and let this class run them lazily. This idiom
/// lets us minimize the number of times we have to look up analyses in our
/// hashtable.)
template <typename PassBuilderT>
bool registerPass(PassBuilderT &&PassBuilder) {
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Analysis/InlineAdvisor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,12 @@ void InlineAdvice::recordInliningWithCalleeDeleted() {

AnalysisKey InlineAdvisorAnalysis::Key;
AnalysisKey PluginInlineAdvisorAnalysis::Key;
bool PluginInlineAdvisorAnalysis::HasBeenRegistered = false;

bool InlineAdvisorAnalysis::Result::tryCreate(
InlineParams Params, InliningAdvisorMode Mode,
const ReplayInlinerSettings &ReplaySettings, InlineContext IC) {
auto &FAM = MAM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
if (PluginInlineAdvisorAnalysis::HasBeenRegistered) {
if (MAM.isPassRegistered<PluginInlineAdvisorAnalysis>()) {
auto &DA = MAM.getResult<PluginInlineAdvisorAnalysis>(M);
Advisor.reset(DA.Factory(M, FAM, Params, IC));
return !!Advisor;
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Analysis/InlineOrder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ class PriorityInlineOrder : public InlineOrder<std::pair<CallBase *, int>> {
} // namespace

AnalysisKey llvm::PluginInlineOrderAnalysis::Key;
bool llvm::PluginInlineOrderAnalysis::HasBeenRegistered;

std::unique_ptr<InlineOrder<std::pair<CallBase *, int>>>
llvm::getDefaultInlineOrder(FunctionAnalysisManager &FAM,
Expand Down Expand Up @@ -313,7 +312,7 @@ llvm::getDefaultInlineOrder(FunctionAnalysisManager &FAM,
std::unique_ptr<InlineOrder<std::pair<CallBase *, int>>>
llvm::getInlineOrder(FunctionAnalysisManager &FAM, const InlineParams &Params,
ModuleAnalysisManager &MAM, Module &M) {
if (llvm::PluginInlineOrderAnalysis::isRegistered()) {
if (MAM.isPassRegistered<PluginInlineOrderAnalysis>()) {
LLVM_DEBUG(dbgs() << " Current used priority: plugin ---- \n");
return MAM.getResult<PluginInlineOrderAnalysis>(M).Factory(FAM, Params, MAM,
M);
Expand Down
41 changes: 10 additions & 31 deletions llvm/unittests/Analysis/PluginInlineAdvisorAnalysisTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,33 +87,10 @@ struct CompilerInstance {
ThinOrFullLTOPhase::None));
}

~CompilerInstance() {
// Reset the static variable that tracks if the plugin has been registered.
// This is needed to allow the test to run multiple times.
PluginInlineAdvisorAnalysis::HasBeenRegistered = false;
}

std::string output;
std::unique_ptr<Module> outputM;

// run with the default inliner
auto run_default(StringRef IR) {
PluginInlineAdvisorAnalysis::HasBeenRegistered = false;
outputM = parseAssemblyString(IR, Error, Ctx);
MPM.run(*outputM, MAM);
ASSERT_TRUE(outputM);
output.clear();
raw_string_ostream o_stream{output};
outputM->print(o_stream, nullptr);
ASSERT_TRUE(true);
}

// run with the dnamic inliner
auto run_dynamic(StringRef IR) {
// note typically the constructor for the DynamicInlineAdvisorAnalysis
// will automatically set this to true, we controll it here only to
// altenate between the default and dynamic inliner in our test
PluginInlineAdvisorAnalysis::HasBeenRegistered = true;
auto run(StringRef IR) {
outputM = parseAssemblyString(IR, Error, Ctx);
MPM.run(*outputM, MAM);
ASSERT_TRUE(outputM);
Expand Down Expand Up @@ -274,14 +251,16 @@ TEST(PluginInlineAdvisorTest, PluginLoad) {
// Skip the test if plugins are disabled.
GTEST_SKIP();
#endif
CompilerInstance CI{};
CI.setupPlugin();
CompilerInstance DefaultCI{};

CompilerInstance PluginCI{};
PluginCI.setupPlugin();

for (StringRef IR : TestIRS) {
CI.run_default(IR);
std::string default_output = CI.output;
CI.run_dynamic(IR);
std::string dynamic_output = CI.output;
DefaultCI.run(IR);
std::string default_output = DefaultCI.output;
PluginCI.run(IR);
std::string dynamic_output = PluginCI.output;
ASSERT_EQ(default_output, dynamic_output);
}
}
Expand All @@ -294,7 +273,7 @@ TEST(PluginInlineAdvisorTest, CustomAdvisor) {
CI.setupFooOnly();

for (StringRef IR : TestIRS) {
CI.run_dynamic(IR);
CI.run(IR);
CallGraph CGraph = CallGraph(*CI.outputM);
for (auto &node : CGraph) {
for (auto &edge : *node.second) {
Expand Down
6 changes: 0 additions & 6 deletions llvm/unittests/Analysis/PluginInlineOrderAnalysisTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ struct CompilerInstance {
ThinOrFullLTOPhase::None));
}

~CompilerInstance() {
// Reset the static variable that tracks if the plugin has been registered.
// This is needed to allow the test to run multiple times.
PluginInlineOrderAnalysis::unregister();
}

std::string Output;
std::unique_ptr<Module> OutputM;

Expand Down
Loading