From a5e0194709c40212694370e0ea789a1ca14548b5 Mon Sep 17 00:00:00 2001 From: Mircea Trofin Date: Wed, 22 Jul 2020 09:42:17 -0700 Subject: [PATCH] Revert "Rename InlineFeatureAnalysis to FunctionPropertiesAnalysis" This reverts commit 44a6bda19b40f2dfcbe92fc3d58bb6276c71ef78. I forgot to correctly attibute it to tarinduj. Fixing and resubmitting. --- ...onPropertiesAnalysis.h => InlineFeaturesAnalysis.h} | 12 ++++++------ llvm/lib/Analysis/CMakeLists.txt | 2 +- ...opertiesAnalysis.cpp => InlineFeaturesAnalysis.cpp} | 11 +++++------ llvm/lib/Analysis/MLInlineAdvisor.cpp | 18 ++++++++---------- llvm/lib/Passes/PassBuilder.cpp | 2 +- llvm/lib/Passes/PassRegistry.def | 2 +- llvm/unittests/Analysis/CMakeLists.txt | 2 +- ...AnalysisTest.cpp => InlineFeaturesAnalysisTest.cpp} | 8 ++++---- 8 files changed, 27 insertions(+), 30 deletions(-) rename llvm/include/llvm/Analysis/{FunctionPropertiesAnalysis.h => InlineFeaturesAnalysis.h} (80%) rename llvm/lib/Analysis/{FunctionPropertiesAnalysis.cpp => InlineFeaturesAnalysis.cpp} (80%) rename llvm/unittests/Analysis/{FunctionPropertiesAnalysisTest.cpp => InlineFeaturesAnalysisTest.cpp} (90%) diff --git a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h b/llvm/include/llvm/Analysis/InlineFeaturesAnalysis.h similarity index 80% rename from llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h rename to llvm/include/llvm/Analysis/InlineFeaturesAnalysis.h index 0163e69..cc3f96c4 100644 --- a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h +++ b/llvm/include/llvm/Analysis/InlineFeaturesAnalysis.h @@ -1,4 +1,4 @@ -//=- FunctionPropertiesAnalysis.h - Function Properties extraction -*- C++ -=// +//===- InlineFeaturesAnalysis.h - ML Policy Feature extraction -*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,16 +6,16 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_FUNCTIONPROPERTIESANALYSIS_H_ -#define LLVM_FUNCTIONPROPERTIESANALYSIS_H_ +#ifndef LLVM_INLINEFEATURESANALYSIS_H_ +#define LLVM_INLINEFEATURESANALYSIS_H_ #include "llvm/IR/PassManager.h" namespace llvm { class Function; -class FunctionPropertiesAnalysis - : public AnalysisInfoMixin { +class InlineFeaturesAnalysis + : public AnalysisInfoMixin { public: static AnalysisKey Key; struct Result { @@ -42,4 +42,4 @@ public: }; } // namespace llvm -#endif // LLVM_FUNCTIONPROPERTIESANALYSIS_H_ \ No newline at end of file +#endif // LLVM_INLINEFEATURESANALYSIS_H_ \ No newline at end of file diff --git a/llvm/lib/Analysis/CMakeLists.txt b/llvm/lib/Analysis/CMakeLists.txt index 8bb3769..4d7eeaf 100644 --- a/llvm/lib/Analysis/CMakeLists.txt +++ b/llvm/lib/Analysis/CMakeLists.txt @@ -49,7 +49,6 @@ add_llvm_component_library(LLVMAnalysis DomTreeUpdater.cpp DominanceFrontier.cpp EHPersonalities.cpp - FunctionPropertiesAnalysis.cpp GlobalsModRef.cpp GuardUtils.cpp HeatUtils.cpp @@ -58,6 +57,7 @@ add_llvm_component_library(LLVMAnalysis IndirectCallPromotionAnalysis.cpp InlineCost.cpp InlineAdvisor.cpp + InlineFeaturesAnalysis.cpp InlineSizeEstimatorAnalysis.cpp InstCount.cpp InstructionPrecedenceTracking.cpp diff --git a/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp b/llvm/lib/Analysis/InlineFeaturesAnalysis.cpp similarity index 80% rename from llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp rename to llvm/lib/Analysis/InlineFeaturesAnalysis.cpp index a0fc017..90f521b 100644 --- a/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp +++ b/llvm/lib/Analysis/InlineFeaturesAnalysis.cpp @@ -1,4 +1,4 @@ -//===- FunctionPropertiesAnalysis.cpp - Function properties extraction ----===// +//===- InlineFeaturesAnalysis.cpp - Feature extraction for ML Policies ----===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -11,16 +11,15 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Analysis/FunctionPropertiesAnalysis.h" +#include "llvm/Analysis/InlineFeaturesAnalysis.h" #include "llvm/IR/Instructions.h" using namespace llvm; -AnalysisKey FunctionPropertiesAnalysis::Key; +AnalysisKey InlineFeaturesAnalysis::Key; -FunctionPropertiesAnalysis::Result -FunctionPropertiesAnalysis::run(const Function &F, - FunctionAnalysisManager &FAM) { +InlineFeaturesAnalysis::Result +InlineFeaturesAnalysis::run(const Function &F, FunctionAnalysisManager &FAM) { Result Ret; Ret.Uses = ((!F.hasLocalLinkage()) ? 1 : 0) + F.getNumUses(); for (const auto &BB : F) { diff --git a/llvm/lib/Analysis/MLInlineAdvisor.cpp b/llvm/lib/Analysis/MLInlineAdvisor.cpp index e697af9..31cb43b 100644 --- a/llvm/lib/Analysis/MLInlineAdvisor.cpp +++ b/llvm/lib/Analysis/MLInlineAdvisor.cpp @@ -20,8 +20,8 @@ #include "llvm/ADT/SCCIterator.h" #include "llvm/Analysis/CallGraph.h" -#include "llvm/Analysis/FunctionPropertiesAnalysis.h" #include "llvm/Analysis/InlineCost.h" +#include "llvm/Analysis/InlineFeaturesAnalysis.h" #include "llvm/Analysis/MLInlineAdvisor.h" #include "llvm/Analysis/MLModelRunner.h" #include "llvm/Analysis/OptimizationRemarkEmitter.h" @@ -118,8 +118,7 @@ void MLInlineAdvisor::onPassEntry() { } int64_t MLInlineAdvisor::getLocalCalls(Function &F) { - return FAM.getResult(F) - .DirectCallsToDefinedFunctions; + return FAM.getResult(F).DirectCallsToDefinedFunctions; } // Update the internal state of the advisor, and force invalidate feature @@ -134,7 +133,7 @@ void MLInlineAdvisor::onSuccessfulInlining(const MLInlineAdvice &Advice, Function *Callee = Advice.getCallee(); // The caller features aren't valid anymore. - FAM.invalidate(*Caller); + FAM.invalidate(*Caller); int64_t IRSizeAfter = getIRSize(*Caller) + (CalleeWasDeleted ? 0 : Advice.CalleeIRSize); CurrentIRSize += IRSizeAfter - (Advice.CallerIRSize + Advice.CalleeIRSize); @@ -147,15 +146,14 @@ void MLInlineAdvisor::onSuccessfulInlining(const MLInlineAdvice &Advice, // For edges, we 'forget' the edges that the caller and callee used to have // before inlining, and add back what they currently have together. int64_t NewCallerAndCalleeEdges = - FAM.getResult(*Caller) + FAM.getResult(*Caller) .DirectCallsToDefinedFunctions; if (CalleeWasDeleted) --NodeCount; else - NewCallerAndCalleeEdges += - FAM.getResult(*Callee) - .DirectCallsToDefinedFunctions; + NewCallerAndCalleeEdges += FAM.getResult(*Callee) + .DirectCallsToDefinedFunctions; EdgeCount += (NewCallerAndCalleeEdges - Advice.CallerAndCalleeEdges); assert(CurrentIRSize >= 0 && EdgeCount >= 0 && NodeCount >= 0); } @@ -226,8 +224,8 @@ std::unique_ptr MLInlineAdvisor::getAdvice(CallBase &CB) { NrCtantParams += (isa(*I)); } - auto &CallerBefore = FAM.getResult(Caller); - auto &CalleeBefore = FAM.getResult(Callee); + auto &CallerBefore = FAM.getResult(Caller); + auto &CalleeBefore = FAM.getResult(Callee); ModelRunner->setFeature(FeatureIndex::CalleeBasicBlockCount, CalleeBefore.BasicBlockCount); diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp index 771675d..b534853 100644 --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -31,10 +31,10 @@ #include "llvm/Analysis/DemandedBits.h" #include "llvm/Analysis/DependenceAnalysis.h" #include "llvm/Analysis/DominanceFrontier.h" -#include "llvm/Analysis/FunctionPropertiesAnalysis.h" #include "llvm/Analysis/GlobalsModRef.h" #include "llvm/Analysis/IVUsers.h" #include "llvm/Analysis/InlineAdvisor.h" +#include "llvm/Analysis/InlineFeaturesAnalysis.h" #include "llvm/Analysis/InlineSizeEstimatorAnalysis.h" #include "llvm/Analysis/LazyCallGraph.h" #include "llvm/Analysis/LazyValueInfo.h" diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def index f323d37..ad20d02 100644 --- a/llvm/lib/Passes/PassRegistry.def +++ b/llvm/lib/Passes/PassRegistry.def @@ -132,7 +132,7 @@ FUNCTION_ANALYSIS("domfrontier", DominanceFrontierAnalysis()) FUNCTION_ANALYSIS("loops", LoopAnalysis()) FUNCTION_ANALYSIS("lazy-value-info", LazyValueAnalysis()) FUNCTION_ANALYSIS("da", DependenceAnalysis()) -FUNCTION_ANALYSIS("func-properties", FunctionPropertiesAnalysis()) +FUNCTION_ANALYSIS("inliner-features", InlineFeaturesAnalysis()) FUNCTION_ANALYSIS("inliner-size-estimator", InlineSizeEstimatorAnalysis()) FUNCTION_ANALYSIS("memdep", MemoryDependenceAnalysis()) FUNCTION_ANALYSIS("memoryssa", MemorySSAAnalysis()) diff --git a/llvm/unittests/Analysis/CMakeLists.txt b/llvm/unittests/Analysis/CMakeLists.txt index eb97f62..b1b396a 100644 --- a/llvm/unittests/Analysis/CMakeLists.txt +++ b/llvm/unittests/Analysis/CMakeLists.txt @@ -27,7 +27,7 @@ add_llvm_unittest_with_input_files(AnalysisTests DivergenceAnalysisTest.cpp DomTreeUpdaterTest.cpp GlobalsModRefTest.cpp - FunctionPropertiesAnalysisTest.cpp + InlineFeaturesAnalysisTest.cpp IVDescriptorsTest.cpp LazyCallGraphTest.cpp LoadsTest.cpp diff --git a/llvm/unittests/Analysis/FunctionPropertiesAnalysisTest.cpp b/llvm/unittests/Analysis/InlineFeaturesAnalysisTest.cpp similarity index 90% rename from llvm/unittests/Analysis/FunctionPropertiesAnalysisTest.cpp rename to llvm/unittests/Analysis/InlineFeaturesAnalysisTest.cpp index 399c6dd..a3df767 100644 --- a/llvm/unittests/Analysis/FunctionPropertiesAnalysisTest.cpp +++ b/llvm/unittests/Analysis/InlineFeaturesAnalysisTest.cpp @@ -1,4 +1,4 @@ -//===- FunctionPropertiesAnalysisTest.cpp - function properties unit tests-===// +//===- InlineFeaturesAnalysisTest.cpp - inline features unit tests --------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Analysis/FunctionPropertiesAnalysis.h" +#include "llvm/Analysis/InlineFeaturesAnalysis.h" #include "llvm/AsmParser/Parser.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/LLVMContext.h" @@ -24,7 +24,7 @@ static std::unique_ptr parseIR(LLVMContext &C, const char *IR) { return Mod; } -TEST(FunctionPropertiesTest, BasicTest) { +TEST(InlineFeaturesTest, BasicTest) { LLVMContext C; std::unique_ptr M = parseIR(C, R"IR( @@ -59,7 +59,7 @@ define internal i32 @top() { )IR"); FunctionAnalysisManager FAM; - FunctionPropertiesAnalysis FA; + InlineFeaturesAnalysis FA; auto BranchesFeatures = FA.run(*M->getFunction("branches"), FAM); EXPECT_EQ(BranchesFeatures.BasicBlockCount, 4); -- 2.7.4