[llvm-branch-commits] [llvm] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
https://github.com/svkeerthy updated
https://github.com/llvm/llvm-project/pull/143479
>From a2bec77ad03e20cd76b6870149863049a96c4f9e Mon Sep 17 00:00:00 2001
From: svkeerthy
Date: Tue, 10 Jun 2025 05:40:38 +
Subject: [PATCH] [MLIniner][IR2Vec] Integrating IR2Vec with MLInliner
---
.../Analysis/FunctionPropertiesAnalysis.h | 26 +++-
llvm/include/llvm/Analysis/InlineAdvisor.h| 4 +
.../llvm/Analysis/InlineModelFeatureMaps.h| 8 +-
llvm/include/llvm/Analysis/MLInlineAdvisor.h | 1 +
.../Analysis/FunctionPropertiesAnalysis.cpp | 115 +-
llvm/lib/Analysis/InlineAdvisor.cpp | 29
llvm/lib/Analysis/MLInlineAdvisor.cpp | 34 +++-
.../FunctionPropertiesAnalysisTest.cpp| 145 --
8 files changed, 338 insertions(+), 24 deletions(-)
diff --git a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
index babb6d9d6cf0c..06dbfc35a5294 100644
--- a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
+++ b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
@@ -15,6 +15,7 @@
#define LLVM_ANALYSIS_FUNCTIONPROPERTIESANALYSIS_H
#include "llvm/ADT/DenseSet.h"
+#include "llvm/Analysis/IR2Vec.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Support/Compiler.h"
@@ -32,17 +33,19 @@ class FunctionPropertiesInfo {
void updateAggregateStats(const Function &F, const LoopInfo &LI);
void reIncludeBB(const BasicBlock &BB);
+ ir2vec::Embedding FunctionEmbedding = ir2vec::Embedding(0.0);
+ std::optional IR2VecVocab;
+
public:
LLVM_ABI static FunctionPropertiesInfo
getFunctionPropertiesInfo(const Function &F, const DominatorTree &DT,
-const LoopInfo &LI);
+const LoopInfo &LI,
+const IR2VecVocabResult *VocabResult);
LLVM_ABI static FunctionPropertiesInfo
getFunctionPropertiesInfo(Function &F, FunctionAnalysisManager &FAM);
- bool operator==(const FunctionPropertiesInfo &FPI) const {
-return std::memcmp(this, &FPI, sizeof(FunctionPropertiesInfo)) == 0;
- }
+ bool operator==(const FunctionPropertiesInfo &FPI) const;
bool operator!=(const FunctionPropertiesInfo &FPI) const {
return !(*this == FPI);
@@ -137,6 +140,19 @@ class FunctionPropertiesInfo {
int64_t CallReturnsVectorPointerCount = 0;
int64_t CallWithManyArgumentsCount = 0;
int64_t CallWithPointerArgumentCount = 0;
+
+ const ir2vec::Embedding &getFunctionEmbedding() const {
+return FunctionEmbedding;
+ }
+
+ const std::optional &getIR2VecVocab() const {
+return IR2VecVocab;
+ }
+
+ // Helper intended to be useful for unittests
+ void setFunctionEmbeddingForTest(const ir2vec::Embedding &Embedding) {
+FunctionEmbedding = Embedding;
+ }
};
// Analysis pass
@@ -192,7 +208,7 @@ class FunctionPropertiesUpdater {
DominatorTree &getUpdatedDominatorTree(FunctionAnalysisManager &FAM) const;
- DenseSet Successors;
+ DenseSet Successors, CallUsers;
// Edges we might potentially need to remove from the dominator tree.
SmallVector DomTreeUpdates;
diff --git a/llvm/include/llvm/Analysis/InlineAdvisor.h
b/llvm/include/llvm/Analysis/InlineAdvisor.h
index 9d15136e81d10..50ba3c13da70f 100644
--- a/llvm/include/llvm/Analysis/InlineAdvisor.h
+++ b/llvm/include/llvm/Analysis/InlineAdvisor.h
@@ -331,6 +331,10 @@ class InlineAdvisorAnalysis : public
AnalysisInfoMixin {
};
Result run(Module &M, ModuleAnalysisManager &MAM) { return Result(M, MAM); }
+
+private:
+ static bool initializeIR2VecVocabIfRequested(Module &M,
+ ModuleAnalysisManager &MAM);
};
/// Printer pass for the InlineAdvisorAnalysis results.
diff --git a/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
b/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
index 961d5091bf9f3..a166621243cad 100644
--- a/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
+++ b/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
@@ -142,6 +142,12 @@ enum class FeatureIndex : size_t {
INLINE_FEATURE_ITERATOR(POPULATE_INDICES)
#undef POPULATE_INDICES
+// IR2Vec embeddings
+// Dimensions of embeddings are not known in the compile time (until vocab is
+// read). Hence macros cannot be used here.
+ callee_embedding,
+ caller_embedding,
+
NumberOfFeatures
};
// clang-format on
@@ -154,7 +160,7 @@ inlineCostFeatureToMlFeature(InlineCostFeatureIndex
Feature) {
constexpr size_t NumberOfFeatures =
static_cast(FeatureIndex::NumberOfFeatures);
-LLVM_ABI extern const std::vector FeatureMap;
+LLVM_ABI extern std::vector FeatureMap;
LLVM_ABI extern const char *const DecisionName;
LLVM_ABI extern const TensorSpec InlineDecisionSpec;
diff --git a/llvm/include/llvm/Analysis/MLInlineAdvisor.h
b/llvm/include/llvm/Analysis/MLInlineAdvisor.h
index 580dd5e95d760..8262dd0846ede 100644
--- a/llvm/include/llvm/Analysis/MLInlin
[llvm-branch-commits] [llvm] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
https://github.com/svkeerthy updated
https://github.com/llvm/llvm-project/pull/143479
>From a2bec77ad03e20cd76b6870149863049a96c4f9e Mon Sep 17 00:00:00 2001
From: svkeerthy
Date: Tue, 10 Jun 2025 05:40:38 +
Subject: [PATCH] [MLIniner][IR2Vec] Integrating IR2Vec with MLInliner
---
.../Analysis/FunctionPropertiesAnalysis.h | 26 +++-
llvm/include/llvm/Analysis/InlineAdvisor.h| 4 +
.../llvm/Analysis/InlineModelFeatureMaps.h| 8 +-
llvm/include/llvm/Analysis/MLInlineAdvisor.h | 1 +
.../Analysis/FunctionPropertiesAnalysis.cpp | 115 +-
llvm/lib/Analysis/InlineAdvisor.cpp | 29
llvm/lib/Analysis/MLInlineAdvisor.cpp | 34 +++-
.../FunctionPropertiesAnalysisTest.cpp| 145 --
8 files changed, 338 insertions(+), 24 deletions(-)
diff --git a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
index babb6d9d6cf0c..06dbfc35a5294 100644
--- a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
+++ b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
@@ -15,6 +15,7 @@
#define LLVM_ANALYSIS_FUNCTIONPROPERTIESANALYSIS_H
#include "llvm/ADT/DenseSet.h"
+#include "llvm/Analysis/IR2Vec.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Support/Compiler.h"
@@ -32,17 +33,19 @@ class FunctionPropertiesInfo {
void updateAggregateStats(const Function &F, const LoopInfo &LI);
void reIncludeBB(const BasicBlock &BB);
+ ir2vec::Embedding FunctionEmbedding = ir2vec::Embedding(0.0);
+ std::optional IR2VecVocab;
+
public:
LLVM_ABI static FunctionPropertiesInfo
getFunctionPropertiesInfo(const Function &F, const DominatorTree &DT,
-const LoopInfo &LI);
+const LoopInfo &LI,
+const IR2VecVocabResult *VocabResult);
LLVM_ABI static FunctionPropertiesInfo
getFunctionPropertiesInfo(Function &F, FunctionAnalysisManager &FAM);
- bool operator==(const FunctionPropertiesInfo &FPI) const {
-return std::memcmp(this, &FPI, sizeof(FunctionPropertiesInfo)) == 0;
- }
+ bool operator==(const FunctionPropertiesInfo &FPI) const;
bool operator!=(const FunctionPropertiesInfo &FPI) const {
return !(*this == FPI);
@@ -137,6 +140,19 @@ class FunctionPropertiesInfo {
int64_t CallReturnsVectorPointerCount = 0;
int64_t CallWithManyArgumentsCount = 0;
int64_t CallWithPointerArgumentCount = 0;
+
+ const ir2vec::Embedding &getFunctionEmbedding() const {
+return FunctionEmbedding;
+ }
+
+ const std::optional &getIR2VecVocab() const {
+return IR2VecVocab;
+ }
+
+ // Helper intended to be useful for unittests
+ void setFunctionEmbeddingForTest(const ir2vec::Embedding &Embedding) {
+FunctionEmbedding = Embedding;
+ }
};
// Analysis pass
@@ -192,7 +208,7 @@ class FunctionPropertiesUpdater {
DominatorTree &getUpdatedDominatorTree(FunctionAnalysisManager &FAM) const;
- DenseSet Successors;
+ DenseSet Successors, CallUsers;
// Edges we might potentially need to remove from the dominator tree.
SmallVector DomTreeUpdates;
diff --git a/llvm/include/llvm/Analysis/InlineAdvisor.h
b/llvm/include/llvm/Analysis/InlineAdvisor.h
index 9d15136e81d10..50ba3c13da70f 100644
--- a/llvm/include/llvm/Analysis/InlineAdvisor.h
+++ b/llvm/include/llvm/Analysis/InlineAdvisor.h
@@ -331,6 +331,10 @@ class InlineAdvisorAnalysis : public
AnalysisInfoMixin {
};
Result run(Module &M, ModuleAnalysisManager &MAM) { return Result(M, MAM); }
+
+private:
+ static bool initializeIR2VecVocabIfRequested(Module &M,
+ ModuleAnalysisManager &MAM);
};
/// Printer pass for the InlineAdvisorAnalysis results.
diff --git a/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
b/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
index 961d5091bf9f3..a166621243cad 100644
--- a/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
+++ b/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
@@ -142,6 +142,12 @@ enum class FeatureIndex : size_t {
INLINE_FEATURE_ITERATOR(POPULATE_INDICES)
#undef POPULATE_INDICES
+// IR2Vec embeddings
+// Dimensions of embeddings are not known in the compile time (until vocab is
+// read). Hence macros cannot be used here.
+ callee_embedding,
+ caller_embedding,
+
NumberOfFeatures
};
// clang-format on
@@ -154,7 +160,7 @@ inlineCostFeatureToMlFeature(InlineCostFeatureIndex
Feature) {
constexpr size_t NumberOfFeatures =
static_cast(FeatureIndex::NumberOfFeatures);
-LLVM_ABI extern const std::vector FeatureMap;
+LLVM_ABI extern std::vector FeatureMap;
LLVM_ABI extern const char *const DecisionName;
LLVM_ABI extern const TensorSpec InlineDecisionSpec;
diff --git a/llvm/include/llvm/Analysis/MLInlineAdvisor.h
b/llvm/include/llvm/Analysis/MLInlineAdvisor.h
index 580dd5e95d760..8262dd0846ede 100644
--- a/llvm/include/llvm/Analysis/MLInlin
[llvm-branch-commits] [llvm] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
@@ -20,33 +21,102 @@
#include "llvm/Support/Compiler.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Transforms/Utils/Cloning.h"
+#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include
using namespace llvm;
+using namespace testing;
namespace llvm {
LLVM_ABI extern cl::opt EnableDetailedFunctionProperties;
LLVM_ABI extern cl::opt BigBasicBlockInstructionThreshold;
LLVM_ABI extern cl::opt MediumBasicBlockInstrutionThreshold;
+LLVM_ABI extern cl::opt ir2vec::OpcWeight;
+LLVM_ABI extern cl::opt ir2vec::TypeWeight;
+LLVM_ABI extern cl::opt ir2vec::ArgWeight;
} // namespace llvm
namespace {
class FunctionPropertiesAnalysisTest : public testing::Test {
public:
FunctionPropertiesAnalysisTest() {
+createTestVocabulary(1);
+MAM.registerPass([&] { return IR2VecVocabAnalysis(Vocabulary); });
+MAM.registerPass([&] { return PassInstrumentationAnalysis(); });
+FAM.registerPass([&] { return ModuleAnalysisManagerFunctionProxy(MAM); });
FAM.registerPass([&] { return DominatorTreeAnalysis(); });
FAM.registerPass([&] { return LoopAnalysis(); });
FAM.registerPass([&] { return PassInstrumentationAnalysis(); });
+
+ir2vec::OpcWeight = 1.0;
+ir2vec::TypeWeight = 1.0;
+ir2vec::ArgWeight = 1.0;
+ }
+
+private:
+ float OriginalOpcWeight = ir2vec::OpcWeight;
+ float OriginalTypeWeight = ir2vec::TypeWeight;
+ float OriginalArgWeight = ir2vec::ArgWeight;
+
+ void createTestVocabulary(unsigned Dim) {
+Vocabulary["add"] = ir2vec::Embedding(Dim, 0.1);
svkeerthy wrote:
Simplified it using lambda. Please let me know if this is better. (Just thought
this would reduce the number of lines)
https://github.com/llvm/llvm-project/pull/143479
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
https://github.com/svkeerthy updated
https://github.com/llvm/llvm-project/pull/143479
>From b7ec65230c731c77dea1f4a484df6731819729b5 Mon Sep 17 00:00:00 2001
From: svkeerthy
Date: Tue, 10 Jun 2025 05:40:38 +
Subject: [PATCH] [MLIniner][IR2Vec] Integrating IR2Vec with MLInliner
---
.../Analysis/FunctionPropertiesAnalysis.h | 26 +++-
llvm/include/llvm/Analysis/InlineAdvisor.h| 4 +
.../llvm/Analysis/InlineModelFeatureMaps.h| 8 +-
llvm/include/llvm/Analysis/MLInlineAdvisor.h | 1 +
.../Analysis/FunctionPropertiesAnalysis.cpp | 115 +-
llvm/lib/Analysis/InlineAdvisor.cpp | 29
llvm/lib/Analysis/MLInlineAdvisor.cpp | 34 +++-
.../FunctionPropertiesAnalysisTest.cpp| 145 --
8 files changed, 338 insertions(+), 24 deletions(-)
diff --git a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
index babb6d9d6cf0c..06dbfc35a5294 100644
--- a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
+++ b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
@@ -15,6 +15,7 @@
#define LLVM_ANALYSIS_FUNCTIONPROPERTIESANALYSIS_H
#include "llvm/ADT/DenseSet.h"
+#include "llvm/Analysis/IR2Vec.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Support/Compiler.h"
@@ -32,17 +33,19 @@ class FunctionPropertiesInfo {
void updateAggregateStats(const Function &F, const LoopInfo &LI);
void reIncludeBB(const BasicBlock &BB);
+ ir2vec::Embedding FunctionEmbedding = ir2vec::Embedding(0.0);
+ std::optional IR2VecVocab;
+
public:
LLVM_ABI static FunctionPropertiesInfo
getFunctionPropertiesInfo(const Function &F, const DominatorTree &DT,
-const LoopInfo &LI);
+const LoopInfo &LI,
+const IR2VecVocabResult *VocabResult);
LLVM_ABI static FunctionPropertiesInfo
getFunctionPropertiesInfo(Function &F, FunctionAnalysisManager &FAM);
- bool operator==(const FunctionPropertiesInfo &FPI) const {
-return std::memcmp(this, &FPI, sizeof(FunctionPropertiesInfo)) == 0;
- }
+ bool operator==(const FunctionPropertiesInfo &FPI) const;
bool operator!=(const FunctionPropertiesInfo &FPI) const {
return !(*this == FPI);
@@ -137,6 +140,19 @@ class FunctionPropertiesInfo {
int64_t CallReturnsVectorPointerCount = 0;
int64_t CallWithManyArgumentsCount = 0;
int64_t CallWithPointerArgumentCount = 0;
+
+ const ir2vec::Embedding &getFunctionEmbedding() const {
+return FunctionEmbedding;
+ }
+
+ const std::optional &getIR2VecVocab() const {
+return IR2VecVocab;
+ }
+
+ // Helper intended to be useful for unittests
+ void setFunctionEmbeddingForTest(const ir2vec::Embedding &Embedding) {
+FunctionEmbedding = Embedding;
+ }
};
// Analysis pass
@@ -192,7 +208,7 @@ class FunctionPropertiesUpdater {
DominatorTree &getUpdatedDominatorTree(FunctionAnalysisManager &FAM) const;
- DenseSet Successors;
+ DenseSet Successors, CallUsers;
// Edges we might potentially need to remove from the dominator tree.
SmallVector DomTreeUpdates;
diff --git a/llvm/include/llvm/Analysis/InlineAdvisor.h
b/llvm/include/llvm/Analysis/InlineAdvisor.h
index 9d15136e81d10..50ba3c13da70f 100644
--- a/llvm/include/llvm/Analysis/InlineAdvisor.h
+++ b/llvm/include/llvm/Analysis/InlineAdvisor.h
@@ -331,6 +331,10 @@ class InlineAdvisorAnalysis : public
AnalysisInfoMixin {
};
Result run(Module &M, ModuleAnalysisManager &MAM) { return Result(M, MAM); }
+
+private:
+ static bool initializeIR2VecVocabIfRequested(Module &M,
+ ModuleAnalysisManager &MAM);
};
/// Printer pass for the InlineAdvisorAnalysis results.
diff --git a/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
b/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
index 961d5091bf9f3..a166621243cad 100644
--- a/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
+++ b/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
@@ -142,6 +142,12 @@ enum class FeatureIndex : size_t {
INLINE_FEATURE_ITERATOR(POPULATE_INDICES)
#undef POPULATE_INDICES
+// IR2Vec embeddings
+// Dimensions of embeddings are not known in the compile time (until vocab is
+// read). Hence macros cannot be used here.
+ callee_embedding,
+ caller_embedding,
+
NumberOfFeatures
};
// clang-format on
@@ -154,7 +160,7 @@ inlineCostFeatureToMlFeature(InlineCostFeatureIndex
Feature) {
constexpr size_t NumberOfFeatures =
static_cast(FeatureIndex::NumberOfFeatures);
-LLVM_ABI extern const std::vector FeatureMap;
+LLVM_ABI extern std::vector FeatureMap;
LLVM_ABI extern const char *const DecisionName;
LLVM_ABI extern const TensorSpec InlineDecisionSpec;
diff --git a/llvm/include/llvm/Analysis/MLInlineAdvisor.h
b/llvm/include/llvm/Analysis/MLInlineAdvisor.h
index 580dd5e95d760..8262dd0846ede 100644
--- a/llvm/include/llvm/Analysis/MLInlin
[llvm-branch-commits] [llvm] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
https://github.com/svkeerthy updated
https://github.com/llvm/llvm-project/pull/143479
>From b7ec65230c731c77dea1f4a484df6731819729b5 Mon Sep 17 00:00:00 2001
From: svkeerthy
Date: Tue, 10 Jun 2025 05:40:38 +
Subject: [PATCH] [MLIniner][IR2Vec] Integrating IR2Vec with MLInliner
---
.../Analysis/FunctionPropertiesAnalysis.h | 26 +++-
llvm/include/llvm/Analysis/InlineAdvisor.h| 4 +
.../llvm/Analysis/InlineModelFeatureMaps.h| 8 +-
llvm/include/llvm/Analysis/MLInlineAdvisor.h | 1 +
.../Analysis/FunctionPropertiesAnalysis.cpp | 115 +-
llvm/lib/Analysis/InlineAdvisor.cpp | 29
llvm/lib/Analysis/MLInlineAdvisor.cpp | 34 +++-
.../FunctionPropertiesAnalysisTest.cpp| 145 --
8 files changed, 338 insertions(+), 24 deletions(-)
diff --git a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
index babb6d9d6cf0c..06dbfc35a5294 100644
--- a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
+++ b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
@@ -15,6 +15,7 @@
#define LLVM_ANALYSIS_FUNCTIONPROPERTIESANALYSIS_H
#include "llvm/ADT/DenseSet.h"
+#include "llvm/Analysis/IR2Vec.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Support/Compiler.h"
@@ -32,17 +33,19 @@ class FunctionPropertiesInfo {
void updateAggregateStats(const Function &F, const LoopInfo &LI);
void reIncludeBB(const BasicBlock &BB);
+ ir2vec::Embedding FunctionEmbedding = ir2vec::Embedding(0.0);
+ std::optional IR2VecVocab;
+
public:
LLVM_ABI static FunctionPropertiesInfo
getFunctionPropertiesInfo(const Function &F, const DominatorTree &DT,
-const LoopInfo &LI);
+const LoopInfo &LI,
+const IR2VecVocabResult *VocabResult);
LLVM_ABI static FunctionPropertiesInfo
getFunctionPropertiesInfo(Function &F, FunctionAnalysisManager &FAM);
- bool operator==(const FunctionPropertiesInfo &FPI) const {
-return std::memcmp(this, &FPI, sizeof(FunctionPropertiesInfo)) == 0;
- }
+ bool operator==(const FunctionPropertiesInfo &FPI) const;
bool operator!=(const FunctionPropertiesInfo &FPI) const {
return !(*this == FPI);
@@ -137,6 +140,19 @@ class FunctionPropertiesInfo {
int64_t CallReturnsVectorPointerCount = 0;
int64_t CallWithManyArgumentsCount = 0;
int64_t CallWithPointerArgumentCount = 0;
+
+ const ir2vec::Embedding &getFunctionEmbedding() const {
+return FunctionEmbedding;
+ }
+
+ const std::optional &getIR2VecVocab() const {
+return IR2VecVocab;
+ }
+
+ // Helper intended to be useful for unittests
+ void setFunctionEmbeddingForTest(const ir2vec::Embedding &Embedding) {
+FunctionEmbedding = Embedding;
+ }
};
// Analysis pass
@@ -192,7 +208,7 @@ class FunctionPropertiesUpdater {
DominatorTree &getUpdatedDominatorTree(FunctionAnalysisManager &FAM) const;
- DenseSet Successors;
+ DenseSet Successors, CallUsers;
// Edges we might potentially need to remove from the dominator tree.
SmallVector DomTreeUpdates;
diff --git a/llvm/include/llvm/Analysis/InlineAdvisor.h
b/llvm/include/llvm/Analysis/InlineAdvisor.h
index 9d15136e81d10..50ba3c13da70f 100644
--- a/llvm/include/llvm/Analysis/InlineAdvisor.h
+++ b/llvm/include/llvm/Analysis/InlineAdvisor.h
@@ -331,6 +331,10 @@ class InlineAdvisorAnalysis : public
AnalysisInfoMixin {
};
Result run(Module &M, ModuleAnalysisManager &MAM) { return Result(M, MAM); }
+
+private:
+ static bool initializeIR2VecVocabIfRequested(Module &M,
+ ModuleAnalysisManager &MAM);
};
/// Printer pass for the InlineAdvisorAnalysis results.
diff --git a/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
b/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
index 961d5091bf9f3..a166621243cad 100644
--- a/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
+++ b/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
@@ -142,6 +142,12 @@ enum class FeatureIndex : size_t {
INLINE_FEATURE_ITERATOR(POPULATE_INDICES)
#undef POPULATE_INDICES
+// IR2Vec embeddings
+// Dimensions of embeddings are not known in the compile time (until vocab is
+// read). Hence macros cannot be used here.
+ callee_embedding,
+ caller_embedding,
+
NumberOfFeatures
};
// clang-format on
@@ -154,7 +160,7 @@ inlineCostFeatureToMlFeature(InlineCostFeatureIndex
Feature) {
constexpr size_t NumberOfFeatures =
static_cast(FeatureIndex::NumberOfFeatures);
-LLVM_ABI extern const std::vector FeatureMap;
+LLVM_ABI extern std::vector FeatureMap;
LLVM_ABI extern const char *const DecisionName;
LLVM_ABI extern const TensorSpec InlineDecisionSpec;
diff --git a/llvm/include/llvm/Analysis/MLInlineAdvisor.h
b/llvm/include/llvm/Analysis/MLInlineAdvisor.h
index 580dd5e95d760..8262dd0846ede 100644
--- a/llvm/include/llvm/Analysis/MLInlin
[llvm-branch-commits] [llvm] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
https://github.com/svkeerthy updated
https://github.com/llvm/llvm-project/pull/143479
>From 5d7a2b0f4e15da7c4322954bda4bf0e9a3795a66 Mon Sep 17 00:00:00 2001
From: svkeerthy
Date: Tue, 10 Jun 2025 05:40:38 +
Subject: [PATCH] [MLIniner][IR2Vec] Integrating IR2Vec with MLInliner
---
.../Analysis/FunctionPropertiesAnalysis.h | 26 ++-
llvm/include/llvm/Analysis/InlineAdvisor.h| 3 +
.../llvm/Analysis/InlineModelFeatureMaps.h| 8 +-
llvm/include/llvm/Analysis/MLInlineAdvisor.h | 1 +
.../Analysis/FunctionPropertiesAnalysis.cpp | 115 ++-
llvm/lib/Analysis/InlineAdvisor.cpp | 29 +++
llvm/lib/Analysis/MLInlineAdvisor.cpp | 34 +++-
.../FunctionPropertiesAnalysisTest.cpp| 179 +++---
8 files changed, 360 insertions(+), 35 deletions(-)
diff --git a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
index babb6d9d6cf0c..06dbfc35a5294 100644
--- a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
+++ b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
@@ -15,6 +15,7 @@
#define LLVM_ANALYSIS_FUNCTIONPROPERTIESANALYSIS_H
#include "llvm/ADT/DenseSet.h"
+#include "llvm/Analysis/IR2Vec.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Support/Compiler.h"
@@ -32,17 +33,19 @@ class FunctionPropertiesInfo {
void updateAggregateStats(const Function &F, const LoopInfo &LI);
void reIncludeBB(const BasicBlock &BB);
+ ir2vec::Embedding FunctionEmbedding = ir2vec::Embedding(0.0);
+ std::optional IR2VecVocab;
+
public:
LLVM_ABI static FunctionPropertiesInfo
getFunctionPropertiesInfo(const Function &F, const DominatorTree &DT,
-const LoopInfo &LI);
+const LoopInfo &LI,
+const IR2VecVocabResult *VocabResult);
LLVM_ABI static FunctionPropertiesInfo
getFunctionPropertiesInfo(Function &F, FunctionAnalysisManager &FAM);
- bool operator==(const FunctionPropertiesInfo &FPI) const {
-return std::memcmp(this, &FPI, sizeof(FunctionPropertiesInfo)) == 0;
- }
+ bool operator==(const FunctionPropertiesInfo &FPI) const;
bool operator!=(const FunctionPropertiesInfo &FPI) const {
return !(*this == FPI);
@@ -137,6 +140,19 @@ class FunctionPropertiesInfo {
int64_t CallReturnsVectorPointerCount = 0;
int64_t CallWithManyArgumentsCount = 0;
int64_t CallWithPointerArgumentCount = 0;
+
+ const ir2vec::Embedding &getFunctionEmbedding() const {
+return FunctionEmbedding;
+ }
+
+ const std::optional &getIR2VecVocab() const {
+return IR2VecVocab;
+ }
+
+ // Helper intended to be useful for unittests
+ void setFunctionEmbeddingForTest(const ir2vec::Embedding &Embedding) {
+FunctionEmbedding = Embedding;
+ }
};
// Analysis pass
@@ -192,7 +208,7 @@ class FunctionPropertiesUpdater {
DominatorTree &getUpdatedDominatorTree(FunctionAnalysisManager &FAM) const;
- DenseSet Successors;
+ DenseSet Successors, CallUsers;
// Edges we might potentially need to remove from the dominator tree.
SmallVector DomTreeUpdates;
diff --git a/llvm/include/llvm/Analysis/InlineAdvisor.h
b/llvm/include/llvm/Analysis/InlineAdvisor.h
index 9d15136e81d10..d2cad4717cbdb 100644
--- a/llvm/include/llvm/Analysis/InlineAdvisor.h
+++ b/llvm/include/llvm/Analysis/InlineAdvisor.h
@@ -331,6 +331,9 @@ class InlineAdvisorAnalysis : public
AnalysisInfoMixin {
};
Result run(Module &M, ModuleAnalysisManager &MAM) { return Result(M, MAM); }
+
+private:
+ static bool initializeIR2VecVocab(Module &M, ModuleAnalysisManager &MAM);
};
/// Printer pass for the InlineAdvisorAnalysis results.
diff --git a/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
b/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
index 961d5091bf9f3..a166621243cad 100644
--- a/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
+++ b/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
@@ -142,6 +142,12 @@ enum class FeatureIndex : size_t {
INLINE_FEATURE_ITERATOR(POPULATE_INDICES)
#undef POPULATE_INDICES
+// IR2Vec embeddings
+// Dimensions of embeddings are not known in the compile time (until vocab is
+// read). Hence macros cannot be used here.
+ callee_embedding,
+ caller_embedding,
+
NumberOfFeatures
};
// clang-format on
@@ -154,7 +160,7 @@ inlineCostFeatureToMlFeature(InlineCostFeatureIndex
Feature) {
constexpr size_t NumberOfFeatures =
static_cast(FeatureIndex::NumberOfFeatures);
-LLVM_ABI extern const std::vector FeatureMap;
+LLVM_ABI extern std::vector FeatureMap;
LLVM_ABI extern const char *const DecisionName;
LLVM_ABI extern const TensorSpec InlineDecisionSpec;
diff --git a/llvm/include/llvm/Analysis/MLInlineAdvisor.h
b/llvm/include/llvm/Analysis/MLInlineAdvisor.h
index 580dd5e95d760..8262dd0846ede 100644
--- a/llvm/include/llvm/Analysis/MLInlineAdvisor.h
+++ b/llvm/include/llvm/Analysis/MLInlineAdvisor.h
@@
[llvm-branch-commits] [llvm] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
https://github.com/svkeerthy updated
https://github.com/llvm/llvm-project/pull/143479
>From b40003fb48e9c135dd1b1a06ba10f3cc2cd81d64 Mon Sep 17 00:00:00 2001
From: svkeerthy
Date: Tue, 10 Jun 2025 05:40:38 +
Subject: [PATCH] [MLIniner][IR2Vec] Integrating IR2Vec with MLInliner
---
.../Analysis/FunctionPropertiesAnalysis.h | 26 ++-
llvm/include/llvm/Analysis/InlineAdvisor.h| 3 +
.../llvm/Analysis/InlineModelFeatureMaps.h| 8 +-
llvm/include/llvm/Analysis/MLInlineAdvisor.h | 1 +
.../Analysis/FunctionPropertiesAnalysis.cpp | 115 ++-
llvm/lib/Analysis/InlineAdvisor.cpp | 29 +++
llvm/lib/Analysis/MLInlineAdvisor.cpp | 34 +++-
.../FunctionPropertiesAnalysisTest.cpp| 179 +++---
8 files changed, 360 insertions(+), 35 deletions(-)
diff --git a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
index babb6d9d6cf0c..06dbfc35a5294 100644
--- a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
+++ b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
@@ -15,6 +15,7 @@
#define LLVM_ANALYSIS_FUNCTIONPROPERTIESANALYSIS_H
#include "llvm/ADT/DenseSet.h"
+#include "llvm/Analysis/IR2Vec.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Support/Compiler.h"
@@ -32,17 +33,19 @@ class FunctionPropertiesInfo {
void updateAggregateStats(const Function &F, const LoopInfo &LI);
void reIncludeBB(const BasicBlock &BB);
+ ir2vec::Embedding FunctionEmbedding = ir2vec::Embedding(0.0);
+ std::optional IR2VecVocab;
+
public:
LLVM_ABI static FunctionPropertiesInfo
getFunctionPropertiesInfo(const Function &F, const DominatorTree &DT,
-const LoopInfo &LI);
+const LoopInfo &LI,
+const IR2VecVocabResult *VocabResult);
LLVM_ABI static FunctionPropertiesInfo
getFunctionPropertiesInfo(Function &F, FunctionAnalysisManager &FAM);
- bool operator==(const FunctionPropertiesInfo &FPI) const {
-return std::memcmp(this, &FPI, sizeof(FunctionPropertiesInfo)) == 0;
- }
+ bool operator==(const FunctionPropertiesInfo &FPI) const;
bool operator!=(const FunctionPropertiesInfo &FPI) const {
return !(*this == FPI);
@@ -137,6 +140,19 @@ class FunctionPropertiesInfo {
int64_t CallReturnsVectorPointerCount = 0;
int64_t CallWithManyArgumentsCount = 0;
int64_t CallWithPointerArgumentCount = 0;
+
+ const ir2vec::Embedding &getFunctionEmbedding() const {
+return FunctionEmbedding;
+ }
+
+ const std::optional &getIR2VecVocab() const {
+return IR2VecVocab;
+ }
+
+ // Helper intended to be useful for unittests
+ void setFunctionEmbeddingForTest(const ir2vec::Embedding &Embedding) {
+FunctionEmbedding = Embedding;
+ }
};
// Analysis pass
@@ -192,7 +208,7 @@ class FunctionPropertiesUpdater {
DominatorTree &getUpdatedDominatorTree(FunctionAnalysisManager &FAM) const;
- DenseSet Successors;
+ DenseSet Successors, CallUsers;
// Edges we might potentially need to remove from the dominator tree.
SmallVector DomTreeUpdates;
diff --git a/llvm/include/llvm/Analysis/InlineAdvisor.h
b/llvm/include/llvm/Analysis/InlineAdvisor.h
index 9d15136e81d10..d2cad4717cbdb 100644
--- a/llvm/include/llvm/Analysis/InlineAdvisor.h
+++ b/llvm/include/llvm/Analysis/InlineAdvisor.h
@@ -331,6 +331,9 @@ class InlineAdvisorAnalysis : public
AnalysisInfoMixin {
};
Result run(Module &M, ModuleAnalysisManager &MAM) { return Result(M, MAM); }
+
+private:
+ static bool initializeIR2VecVocab(Module &M, ModuleAnalysisManager &MAM);
};
/// Printer pass for the InlineAdvisorAnalysis results.
diff --git a/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
b/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
index 961d5091bf9f3..a166621243cad 100644
--- a/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
+++ b/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
@@ -142,6 +142,12 @@ enum class FeatureIndex : size_t {
INLINE_FEATURE_ITERATOR(POPULATE_INDICES)
#undef POPULATE_INDICES
+// IR2Vec embeddings
+// Dimensions of embeddings are not known in the compile time (until vocab is
+// read). Hence macros cannot be used here.
+ callee_embedding,
+ caller_embedding,
+
NumberOfFeatures
};
// clang-format on
@@ -154,7 +160,7 @@ inlineCostFeatureToMlFeature(InlineCostFeatureIndex
Feature) {
constexpr size_t NumberOfFeatures =
static_cast(FeatureIndex::NumberOfFeatures);
-LLVM_ABI extern const std::vector FeatureMap;
+LLVM_ABI extern std::vector FeatureMap;
LLVM_ABI extern const char *const DecisionName;
LLVM_ABI extern const TensorSpec InlineDecisionSpec;
diff --git a/llvm/include/llvm/Analysis/MLInlineAdvisor.h
b/llvm/include/llvm/Analysis/MLInlineAdvisor.h
index 580dd5e95d760..8262dd0846ede 100644
--- a/llvm/include/llvm/Analysis/MLInlineAdvisor.h
+++ b/llvm/include/llvm/Analysis/MLInlineAdvisor.h
@@
[llvm-branch-commits] [llvm] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
https://github.com/svkeerthy updated
https://github.com/llvm/llvm-project/pull/143479
>From b40003fb48e9c135dd1b1a06ba10f3cc2cd81d64 Mon Sep 17 00:00:00 2001
From: svkeerthy
Date: Tue, 10 Jun 2025 05:40:38 +
Subject: [PATCH] [MLIniner][IR2Vec] Integrating IR2Vec with MLInliner
---
.../Analysis/FunctionPropertiesAnalysis.h | 26 ++-
llvm/include/llvm/Analysis/InlineAdvisor.h| 3 +
.../llvm/Analysis/InlineModelFeatureMaps.h| 8 +-
llvm/include/llvm/Analysis/MLInlineAdvisor.h | 1 +
.../Analysis/FunctionPropertiesAnalysis.cpp | 115 ++-
llvm/lib/Analysis/InlineAdvisor.cpp | 29 +++
llvm/lib/Analysis/MLInlineAdvisor.cpp | 34 +++-
.../FunctionPropertiesAnalysisTest.cpp| 179 +++---
8 files changed, 360 insertions(+), 35 deletions(-)
diff --git a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
index babb6d9d6cf0c..06dbfc35a5294 100644
--- a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
+++ b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
@@ -15,6 +15,7 @@
#define LLVM_ANALYSIS_FUNCTIONPROPERTIESANALYSIS_H
#include "llvm/ADT/DenseSet.h"
+#include "llvm/Analysis/IR2Vec.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Support/Compiler.h"
@@ -32,17 +33,19 @@ class FunctionPropertiesInfo {
void updateAggregateStats(const Function &F, const LoopInfo &LI);
void reIncludeBB(const BasicBlock &BB);
+ ir2vec::Embedding FunctionEmbedding = ir2vec::Embedding(0.0);
+ std::optional IR2VecVocab;
+
public:
LLVM_ABI static FunctionPropertiesInfo
getFunctionPropertiesInfo(const Function &F, const DominatorTree &DT,
-const LoopInfo &LI);
+const LoopInfo &LI,
+const IR2VecVocabResult *VocabResult);
LLVM_ABI static FunctionPropertiesInfo
getFunctionPropertiesInfo(Function &F, FunctionAnalysisManager &FAM);
- bool operator==(const FunctionPropertiesInfo &FPI) const {
-return std::memcmp(this, &FPI, sizeof(FunctionPropertiesInfo)) == 0;
- }
+ bool operator==(const FunctionPropertiesInfo &FPI) const;
bool operator!=(const FunctionPropertiesInfo &FPI) const {
return !(*this == FPI);
@@ -137,6 +140,19 @@ class FunctionPropertiesInfo {
int64_t CallReturnsVectorPointerCount = 0;
int64_t CallWithManyArgumentsCount = 0;
int64_t CallWithPointerArgumentCount = 0;
+
+ const ir2vec::Embedding &getFunctionEmbedding() const {
+return FunctionEmbedding;
+ }
+
+ const std::optional &getIR2VecVocab() const {
+return IR2VecVocab;
+ }
+
+ // Helper intended to be useful for unittests
+ void setFunctionEmbeddingForTest(const ir2vec::Embedding &Embedding) {
+FunctionEmbedding = Embedding;
+ }
};
// Analysis pass
@@ -192,7 +208,7 @@ class FunctionPropertiesUpdater {
DominatorTree &getUpdatedDominatorTree(FunctionAnalysisManager &FAM) const;
- DenseSet Successors;
+ DenseSet Successors, CallUsers;
// Edges we might potentially need to remove from the dominator tree.
SmallVector DomTreeUpdates;
diff --git a/llvm/include/llvm/Analysis/InlineAdvisor.h
b/llvm/include/llvm/Analysis/InlineAdvisor.h
index 9d15136e81d10..d2cad4717cbdb 100644
--- a/llvm/include/llvm/Analysis/InlineAdvisor.h
+++ b/llvm/include/llvm/Analysis/InlineAdvisor.h
@@ -331,6 +331,9 @@ class InlineAdvisorAnalysis : public
AnalysisInfoMixin {
};
Result run(Module &M, ModuleAnalysisManager &MAM) { return Result(M, MAM); }
+
+private:
+ static bool initializeIR2VecVocab(Module &M, ModuleAnalysisManager &MAM);
};
/// Printer pass for the InlineAdvisorAnalysis results.
diff --git a/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
b/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
index 961d5091bf9f3..a166621243cad 100644
--- a/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
+++ b/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
@@ -142,6 +142,12 @@ enum class FeatureIndex : size_t {
INLINE_FEATURE_ITERATOR(POPULATE_INDICES)
#undef POPULATE_INDICES
+// IR2Vec embeddings
+// Dimensions of embeddings are not known in the compile time (until vocab is
+// read). Hence macros cannot be used here.
+ callee_embedding,
+ caller_embedding,
+
NumberOfFeatures
};
// clang-format on
@@ -154,7 +160,7 @@ inlineCostFeatureToMlFeature(InlineCostFeatureIndex
Feature) {
constexpr size_t NumberOfFeatures =
static_cast(FeatureIndex::NumberOfFeatures);
-LLVM_ABI extern const std::vector FeatureMap;
+LLVM_ABI extern std::vector FeatureMap;
LLVM_ABI extern const char *const DecisionName;
LLVM_ABI extern const TensorSpec InlineDecisionSpec;
diff --git a/llvm/include/llvm/Analysis/MLInlineAdvisor.h
b/llvm/include/llvm/Analysis/MLInlineAdvisor.h
index 580dd5e95d760..8262dd0846ede 100644
--- a/llvm/include/llvm/Analysis/MLInlineAdvisor.h
+++ b/llvm/include/llvm/Analysis/MLInlineAdvisor.h
@@
[llvm-branch-commits] [llvm] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
@@ -186,6 +186,20 @@ MLInlineAdvisor::MLInlineAdvisor(
EdgeCount += getLocalCalls(KVP.first->getFunction());
}
NodeCount = AllNodes.size();
+
+ if (auto IR2VecVocabResult = MAM.getCachedResult(M)) {
+if (!IR2VecVocabResult->isValid()) {
+ M.getContext().emitError("IR2VecVocabAnalysis is not valid");
+ return;
+}
+// Add the IR2Vec features to the feature map
+auto IR2VecDim = IR2VecVocabResult->getDimension();
+FeatureMap.push_back(
+TensorSpec::createSpec("callee_embedding", {IR2VecDim}));
+FeatureMap.push_back(
+TensorSpec::createSpec("caller_embedding", {IR2VecDim}));
+UseIR2Vec = true;
svkeerthy wrote:
Okay. Done.
https://github.com/llvm/llvm-project/pull/143479
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
@@ -294,8 +294,8 @@ Error IR2VecVocabAnalysis::readVocabulary() {
return Error::success();
}
-IR2VecVocabAnalysis::IR2VecVocabAnalysis(Vocab &&Vocabulary)
-: Vocabulary(std::move(Vocabulary)) {}
+IR2VecVocabAnalysis::IR2VecVocabAnalysis(Vocab Vocabulary)
+: Vocabulary(Vocabulary) {}
svkeerthy wrote:
Yes, moved it to earlier PR (#143200)
https://github.com/llvm/llvm-project/pull/143479
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
@@ -142,6 +142,10 @@ enum class FeatureIndex : size_t {
INLINE_FEATURE_ITERATOR(POPULATE_INDICES)
#undef POPULATE_INDICES
+// IR2Vec embeddings
svkeerthy wrote:
Done
https://github.com/llvm/llvm-project/pull/143479
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
@@ -20,33 +21,102 @@
#include "llvm/Support/Compiler.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Transforms/Utils/Cloning.h"
+#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include
using namespace llvm;
+using namespace testing;
namespace llvm {
LLVM_ABI extern cl::opt EnableDetailedFunctionProperties;
LLVM_ABI extern cl::opt BigBasicBlockInstructionThreshold;
LLVM_ABI extern cl::opt MediumBasicBlockInstrutionThreshold;
+LLVM_ABI extern cl::opt ir2vec::OpcWeight;
+LLVM_ABI extern cl::opt ir2vec::TypeWeight;
+LLVM_ABI extern cl::opt ir2vec::ArgWeight;
} // namespace llvm
namespace {
class FunctionPropertiesAnalysisTest : public testing::Test {
public:
FunctionPropertiesAnalysisTest() {
+createTestVocabulary(1);
+MAM.registerPass([&] { return IR2VecVocabAnalysis(Vocabulary); });
+MAM.registerPass([&] { return PassInstrumentationAnalysis(); });
+FAM.registerPass([&] { return ModuleAnalysisManagerFunctionProxy(MAM); });
FAM.registerPass([&] { return DominatorTreeAnalysis(); });
FAM.registerPass([&] { return LoopAnalysis(); });
FAM.registerPass([&] { return PassInstrumentationAnalysis(); });
+
+ir2vec::OpcWeight = 1.0;
+ir2vec::TypeWeight = 1.0;
+ir2vec::ArgWeight = 1.0;
+ }
+
+private:
+ float OriginalOpcWeight = ir2vec::OpcWeight;
+ float OriginalTypeWeight = ir2vec::TypeWeight;
+ float OriginalArgWeight = ir2vec::ArgWeight;
+
+ void createTestVocabulary(unsigned Dim) {
+Vocabulary["add"] = ir2vec::Embedding(Dim, 0.1);
svkeerthy wrote:
Currently the constructor of vocab analysis could only take in Vocabulary map
and not JSON. It has to be via flags if we need to use JSON. This design of
constructor would help in later patches where vocab map would be autogenerated
during the build time.
https://github.com/llvm/llvm-project/pull/143479
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
@@ -199,6 +199,29 @@ void FunctionPropertiesInfo::updateForBB(const BasicBlock
&BB,
#undef CHECK_OPERAND
}
}
+
+ if (IR2VecVocab) {
+// We instantiate the IR2Vec embedder each time, as having an unique
+// pointer to the embedder as member of the class would make it
+// non-copyable. Instantiating the embedder in itself is not costly.
+auto EmbOrErr = ir2vec::Embedder::create(IR2VecKind::Symbolic,
svkeerthy wrote:
Yes, we can do that. I'll put up a patch to remove it.
https://github.com/llvm/llvm-project/pull/143479
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
https://github.com/svkeerthy updated
https://github.com/llvm/llvm-project/pull/143479
>From 579c3c03fa1117382c810c8d322f5d83689d79dc Mon Sep 17 00:00:00 2001
From: svkeerthy
Date: Tue, 10 Jun 2025 05:40:38 +
Subject: [PATCH] [MLIniner][IR2Vec] Integrating IR2Vec with MLInliner
---
.../Analysis/FunctionPropertiesAnalysis.h | 26 ++-
llvm/include/llvm/Analysis/IR2Vec.h | 2 +-
llvm/include/llvm/Analysis/InlineAdvisor.h| 3 +
.../llvm/Analysis/InlineModelFeatureMaps.h| 6 +-
llvm/include/llvm/Analysis/MLInlineAdvisor.h | 1 +
.../Analysis/FunctionPropertiesAnalysis.cpp | 115 ++-
llvm/lib/Analysis/IR2Vec.cpp | 4 +-
llvm/lib/Analysis/InlineAdvisor.cpp | 29 +++
llvm/lib/Analysis/MLInlineAdvisor.cpp | 34 +++-
.../FunctionPropertiesAnalysisTest.cpp| 179 +++---
10 files changed, 361 insertions(+), 38 deletions(-)
diff --git a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
index babb6d9d6cf0c..06dbfc35a5294 100644
--- a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
+++ b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
@@ -15,6 +15,7 @@
#define LLVM_ANALYSIS_FUNCTIONPROPERTIESANALYSIS_H
#include "llvm/ADT/DenseSet.h"
+#include "llvm/Analysis/IR2Vec.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Support/Compiler.h"
@@ -32,17 +33,19 @@ class FunctionPropertiesInfo {
void updateAggregateStats(const Function &F, const LoopInfo &LI);
void reIncludeBB(const BasicBlock &BB);
+ ir2vec::Embedding FunctionEmbedding = ir2vec::Embedding(0.0);
+ std::optional IR2VecVocab;
+
public:
LLVM_ABI static FunctionPropertiesInfo
getFunctionPropertiesInfo(const Function &F, const DominatorTree &DT,
-const LoopInfo &LI);
+const LoopInfo &LI,
+const IR2VecVocabResult *VocabResult);
LLVM_ABI static FunctionPropertiesInfo
getFunctionPropertiesInfo(Function &F, FunctionAnalysisManager &FAM);
- bool operator==(const FunctionPropertiesInfo &FPI) const {
-return std::memcmp(this, &FPI, sizeof(FunctionPropertiesInfo)) == 0;
- }
+ bool operator==(const FunctionPropertiesInfo &FPI) const;
bool operator!=(const FunctionPropertiesInfo &FPI) const {
return !(*this == FPI);
@@ -137,6 +140,19 @@ class FunctionPropertiesInfo {
int64_t CallReturnsVectorPointerCount = 0;
int64_t CallWithManyArgumentsCount = 0;
int64_t CallWithPointerArgumentCount = 0;
+
+ const ir2vec::Embedding &getFunctionEmbedding() const {
+return FunctionEmbedding;
+ }
+
+ const std::optional &getIR2VecVocab() const {
+return IR2VecVocab;
+ }
+
+ // Helper intended to be useful for unittests
+ void setFunctionEmbeddingForTest(const ir2vec::Embedding &Embedding) {
+FunctionEmbedding = Embedding;
+ }
};
// Analysis pass
@@ -192,7 +208,7 @@ class FunctionPropertiesUpdater {
DominatorTree &getUpdatedDominatorTree(FunctionAnalysisManager &FAM) const;
- DenseSet Successors;
+ DenseSet Successors, CallUsers;
// Edges we might potentially need to remove from the dominator tree.
SmallVector DomTreeUpdates;
diff --git a/llvm/include/llvm/Analysis/IR2Vec.h
b/llvm/include/llvm/Analysis/IR2Vec.h
index 3a6f47ded8ca4..9acffb996283c 100644
--- a/llvm/include/llvm/Analysis/IR2Vec.h
+++ b/llvm/include/llvm/Analysis/IR2Vec.h
@@ -239,7 +239,7 @@ class IR2VecVocabAnalysis : public
AnalysisInfoMixin {
public:
static AnalysisKey Key;
IR2VecVocabAnalysis() = default;
- explicit IR2VecVocabAnalysis(ir2vec::Vocab &&Vocab);
+ explicit IR2VecVocabAnalysis(ir2vec::Vocab Vocab);
using Result = IR2VecVocabResult;
Result run(Module &M, ModuleAnalysisManager &MAM);
};
diff --git a/llvm/include/llvm/Analysis/InlineAdvisor.h
b/llvm/include/llvm/Analysis/InlineAdvisor.h
index 9d15136e81d10..d2cad4717cbdb 100644
--- a/llvm/include/llvm/Analysis/InlineAdvisor.h
+++ b/llvm/include/llvm/Analysis/InlineAdvisor.h
@@ -331,6 +331,9 @@ class InlineAdvisorAnalysis : public
AnalysisInfoMixin {
};
Result run(Module &M, ModuleAnalysisManager &MAM) { return Result(M, MAM); }
+
+private:
+ static bool initializeIR2VecVocab(Module &M, ModuleAnalysisManager &MAM);
};
/// Printer pass for the InlineAdvisorAnalysis results.
diff --git a/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
b/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
index 961d5091bf9f3..91d3378565fc5 100644
--- a/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
+++ b/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
@@ -142,6 +142,10 @@ enum class FeatureIndex : size_t {
INLINE_FEATURE_ITERATOR(POPULATE_INDICES)
#undef POPULATE_INDICES
+// IR2Vec embeddings
+ callee_embedding,
+ caller_embedding,
+
NumberOfFeatures
};
// clang-format on
@@ -154,7 +158,7 @@ inlineCostFeatureToMlFeature(InlineCostFeatu
[llvm-branch-commits] [llvm] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
https://github.com/svkeerthy updated
https://github.com/llvm/llvm-project/pull/143479
>From 579c3c03fa1117382c810c8d322f5d83689d79dc Mon Sep 17 00:00:00 2001
From: svkeerthy
Date: Tue, 10 Jun 2025 05:40:38 +
Subject: [PATCH] [MLIniner][IR2Vec] Integrating IR2Vec with MLInliner
---
.../Analysis/FunctionPropertiesAnalysis.h | 26 ++-
llvm/include/llvm/Analysis/IR2Vec.h | 2 +-
llvm/include/llvm/Analysis/InlineAdvisor.h| 3 +
.../llvm/Analysis/InlineModelFeatureMaps.h| 6 +-
llvm/include/llvm/Analysis/MLInlineAdvisor.h | 1 +
.../Analysis/FunctionPropertiesAnalysis.cpp | 115 ++-
llvm/lib/Analysis/IR2Vec.cpp | 4 +-
llvm/lib/Analysis/InlineAdvisor.cpp | 29 +++
llvm/lib/Analysis/MLInlineAdvisor.cpp | 34 +++-
.../FunctionPropertiesAnalysisTest.cpp| 179 +++---
10 files changed, 361 insertions(+), 38 deletions(-)
diff --git a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
index babb6d9d6cf0c..06dbfc35a5294 100644
--- a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
+++ b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
@@ -15,6 +15,7 @@
#define LLVM_ANALYSIS_FUNCTIONPROPERTIESANALYSIS_H
#include "llvm/ADT/DenseSet.h"
+#include "llvm/Analysis/IR2Vec.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Support/Compiler.h"
@@ -32,17 +33,19 @@ class FunctionPropertiesInfo {
void updateAggregateStats(const Function &F, const LoopInfo &LI);
void reIncludeBB(const BasicBlock &BB);
+ ir2vec::Embedding FunctionEmbedding = ir2vec::Embedding(0.0);
+ std::optional IR2VecVocab;
+
public:
LLVM_ABI static FunctionPropertiesInfo
getFunctionPropertiesInfo(const Function &F, const DominatorTree &DT,
-const LoopInfo &LI);
+const LoopInfo &LI,
+const IR2VecVocabResult *VocabResult);
LLVM_ABI static FunctionPropertiesInfo
getFunctionPropertiesInfo(Function &F, FunctionAnalysisManager &FAM);
- bool operator==(const FunctionPropertiesInfo &FPI) const {
-return std::memcmp(this, &FPI, sizeof(FunctionPropertiesInfo)) == 0;
- }
+ bool operator==(const FunctionPropertiesInfo &FPI) const;
bool operator!=(const FunctionPropertiesInfo &FPI) const {
return !(*this == FPI);
@@ -137,6 +140,19 @@ class FunctionPropertiesInfo {
int64_t CallReturnsVectorPointerCount = 0;
int64_t CallWithManyArgumentsCount = 0;
int64_t CallWithPointerArgumentCount = 0;
+
+ const ir2vec::Embedding &getFunctionEmbedding() const {
+return FunctionEmbedding;
+ }
+
+ const std::optional &getIR2VecVocab() const {
+return IR2VecVocab;
+ }
+
+ // Helper intended to be useful for unittests
+ void setFunctionEmbeddingForTest(const ir2vec::Embedding &Embedding) {
+FunctionEmbedding = Embedding;
+ }
};
// Analysis pass
@@ -192,7 +208,7 @@ class FunctionPropertiesUpdater {
DominatorTree &getUpdatedDominatorTree(FunctionAnalysisManager &FAM) const;
- DenseSet Successors;
+ DenseSet Successors, CallUsers;
// Edges we might potentially need to remove from the dominator tree.
SmallVector DomTreeUpdates;
diff --git a/llvm/include/llvm/Analysis/IR2Vec.h
b/llvm/include/llvm/Analysis/IR2Vec.h
index 3a6f47ded8ca4..9acffb996283c 100644
--- a/llvm/include/llvm/Analysis/IR2Vec.h
+++ b/llvm/include/llvm/Analysis/IR2Vec.h
@@ -239,7 +239,7 @@ class IR2VecVocabAnalysis : public
AnalysisInfoMixin {
public:
static AnalysisKey Key;
IR2VecVocabAnalysis() = default;
- explicit IR2VecVocabAnalysis(ir2vec::Vocab &&Vocab);
+ explicit IR2VecVocabAnalysis(ir2vec::Vocab Vocab);
using Result = IR2VecVocabResult;
Result run(Module &M, ModuleAnalysisManager &MAM);
};
diff --git a/llvm/include/llvm/Analysis/InlineAdvisor.h
b/llvm/include/llvm/Analysis/InlineAdvisor.h
index 9d15136e81d10..d2cad4717cbdb 100644
--- a/llvm/include/llvm/Analysis/InlineAdvisor.h
+++ b/llvm/include/llvm/Analysis/InlineAdvisor.h
@@ -331,6 +331,9 @@ class InlineAdvisorAnalysis : public
AnalysisInfoMixin {
};
Result run(Module &M, ModuleAnalysisManager &MAM) { return Result(M, MAM); }
+
+private:
+ static bool initializeIR2VecVocab(Module &M, ModuleAnalysisManager &MAM);
};
/// Printer pass for the InlineAdvisorAnalysis results.
diff --git a/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
b/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
index 961d5091bf9f3..91d3378565fc5 100644
--- a/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
+++ b/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
@@ -142,6 +142,10 @@ enum class FeatureIndex : size_t {
INLINE_FEATURE_ITERATOR(POPULATE_INDICES)
#undef POPULATE_INDICES
+// IR2Vec embeddings
+ callee_embedding,
+ caller_embedding,
+
NumberOfFeatures
};
// clang-format on
@@ -154,7 +158,7 @@ inlineCostFeatureToMlFeature(InlineCostFeatu
[llvm-branch-commits] [llvm] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
https://github.com/svkeerthy updated
https://github.com/llvm/llvm-project/pull/143479
>From 6085399a3d002b78a093d951c6a9b6c5bb3fb243 Mon Sep 17 00:00:00 2001
From: svkeerthy
Date: Tue, 10 Jun 2025 05:40:38 +
Subject: [PATCH] [MLIniner][IR2Vec] Integrating IR2Vec with MLInliner
---
.../Analysis/FunctionPropertiesAnalysis.h | 26 ++-
llvm/include/llvm/Analysis/IR2Vec.h | 2 +-
llvm/include/llvm/Analysis/InlineAdvisor.h| 3 +
.../llvm/Analysis/InlineModelFeatureMaps.h| 6 +-
llvm/include/llvm/Analysis/MLInlineAdvisor.h | 1 +
.../Analysis/FunctionPropertiesAnalysis.cpp | 115 ++-
llvm/lib/Analysis/IR2Vec.cpp | 4 +-
llvm/lib/Analysis/InlineAdvisor.cpp | 29 +++
llvm/lib/Analysis/MLInlineAdvisor.cpp | 34 +++-
.../FunctionPropertiesAnalysisTest.cpp| 179 +++---
10 files changed, 361 insertions(+), 38 deletions(-)
diff --git a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
index babb6d9d6cf0c..06dbfc35a5294 100644
--- a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
+++ b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
@@ -15,6 +15,7 @@
#define LLVM_ANALYSIS_FUNCTIONPROPERTIESANALYSIS_H
#include "llvm/ADT/DenseSet.h"
+#include "llvm/Analysis/IR2Vec.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Support/Compiler.h"
@@ -32,17 +33,19 @@ class FunctionPropertiesInfo {
void updateAggregateStats(const Function &F, const LoopInfo &LI);
void reIncludeBB(const BasicBlock &BB);
+ ir2vec::Embedding FunctionEmbedding = ir2vec::Embedding(0.0);
+ std::optional IR2VecVocab;
+
public:
LLVM_ABI static FunctionPropertiesInfo
getFunctionPropertiesInfo(const Function &F, const DominatorTree &DT,
-const LoopInfo &LI);
+const LoopInfo &LI,
+const IR2VecVocabResult *VocabResult);
LLVM_ABI static FunctionPropertiesInfo
getFunctionPropertiesInfo(Function &F, FunctionAnalysisManager &FAM);
- bool operator==(const FunctionPropertiesInfo &FPI) const {
-return std::memcmp(this, &FPI, sizeof(FunctionPropertiesInfo)) == 0;
- }
+ bool operator==(const FunctionPropertiesInfo &FPI) const;
bool operator!=(const FunctionPropertiesInfo &FPI) const {
return !(*this == FPI);
@@ -137,6 +140,19 @@ class FunctionPropertiesInfo {
int64_t CallReturnsVectorPointerCount = 0;
int64_t CallWithManyArgumentsCount = 0;
int64_t CallWithPointerArgumentCount = 0;
+
+ const ir2vec::Embedding &getFunctionEmbedding() const {
+return FunctionEmbedding;
+ }
+
+ const std::optional &getIR2VecVocab() const {
+return IR2VecVocab;
+ }
+
+ // Helper intended to be useful for unittests
+ void setFunctionEmbeddingForTest(const ir2vec::Embedding &Embedding) {
+FunctionEmbedding = Embedding;
+ }
};
// Analysis pass
@@ -192,7 +208,7 @@ class FunctionPropertiesUpdater {
DominatorTree &getUpdatedDominatorTree(FunctionAnalysisManager &FAM) const;
- DenseSet Successors;
+ DenseSet Successors, CallUsers;
// Edges we might potentially need to remove from the dominator tree.
SmallVector DomTreeUpdates;
diff --git a/llvm/include/llvm/Analysis/IR2Vec.h
b/llvm/include/llvm/Analysis/IR2Vec.h
index 3a6f47ded8ca4..9acffb996283c 100644
--- a/llvm/include/llvm/Analysis/IR2Vec.h
+++ b/llvm/include/llvm/Analysis/IR2Vec.h
@@ -239,7 +239,7 @@ class IR2VecVocabAnalysis : public
AnalysisInfoMixin {
public:
static AnalysisKey Key;
IR2VecVocabAnalysis() = default;
- explicit IR2VecVocabAnalysis(ir2vec::Vocab &&Vocab);
+ explicit IR2VecVocabAnalysis(ir2vec::Vocab Vocab);
using Result = IR2VecVocabResult;
Result run(Module &M, ModuleAnalysisManager &MAM);
};
diff --git a/llvm/include/llvm/Analysis/InlineAdvisor.h
b/llvm/include/llvm/Analysis/InlineAdvisor.h
index 9d15136e81d10..d2cad4717cbdb 100644
--- a/llvm/include/llvm/Analysis/InlineAdvisor.h
+++ b/llvm/include/llvm/Analysis/InlineAdvisor.h
@@ -331,6 +331,9 @@ class InlineAdvisorAnalysis : public
AnalysisInfoMixin {
};
Result run(Module &M, ModuleAnalysisManager &MAM) { return Result(M, MAM); }
+
+private:
+ static bool initializeIR2VecVocab(Module &M, ModuleAnalysisManager &MAM);
};
/// Printer pass for the InlineAdvisorAnalysis results.
diff --git a/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
b/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
index 961d5091bf9f3..91d3378565fc5 100644
--- a/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
+++ b/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
@@ -142,6 +142,10 @@ enum class FeatureIndex : size_t {
INLINE_FEATURE_ITERATOR(POPULATE_INDICES)
#undef POPULATE_INDICES
+// IR2Vec embeddings
+ callee_embedding,
+ caller_embedding,
+
NumberOfFeatures
};
// clang-format on
@@ -154,7 +158,7 @@ inlineCostFeatureToMlFeature(InlineCostFeatu
[llvm-branch-commits] [llvm] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
https://github.com/svkeerthy updated
https://github.com/llvm/llvm-project/pull/143479
>From 6085399a3d002b78a093d951c6a9b6c5bb3fb243 Mon Sep 17 00:00:00 2001
From: svkeerthy
Date: Tue, 10 Jun 2025 05:40:38 +
Subject: [PATCH] [MLIniner][IR2Vec] Integrating IR2Vec with MLInliner
---
.../Analysis/FunctionPropertiesAnalysis.h | 26 ++-
llvm/include/llvm/Analysis/IR2Vec.h | 2 +-
llvm/include/llvm/Analysis/InlineAdvisor.h| 3 +
.../llvm/Analysis/InlineModelFeatureMaps.h| 6 +-
llvm/include/llvm/Analysis/MLInlineAdvisor.h | 1 +
.../Analysis/FunctionPropertiesAnalysis.cpp | 115 ++-
llvm/lib/Analysis/IR2Vec.cpp | 4 +-
llvm/lib/Analysis/InlineAdvisor.cpp | 29 +++
llvm/lib/Analysis/MLInlineAdvisor.cpp | 34 +++-
.../FunctionPropertiesAnalysisTest.cpp| 179 +++---
10 files changed, 361 insertions(+), 38 deletions(-)
diff --git a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
index babb6d9d6cf0c..06dbfc35a5294 100644
--- a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
+++ b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
@@ -15,6 +15,7 @@
#define LLVM_ANALYSIS_FUNCTIONPROPERTIESANALYSIS_H
#include "llvm/ADT/DenseSet.h"
+#include "llvm/Analysis/IR2Vec.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Support/Compiler.h"
@@ -32,17 +33,19 @@ class FunctionPropertiesInfo {
void updateAggregateStats(const Function &F, const LoopInfo &LI);
void reIncludeBB(const BasicBlock &BB);
+ ir2vec::Embedding FunctionEmbedding = ir2vec::Embedding(0.0);
+ std::optional IR2VecVocab;
+
public:
LLVM_ABI static FunctionPropertiesInfo
getFunctionPropertiesInfo(const Function &F, const DominatorTree &DT,
-const LoopInfo &LI);
+const LoopInfo &LI,
+const IR2VecVocabResult *VocabResult);
LLVM_ABI static FunctionPropertiesInfo
getFunctionPropertiesInfo(Function &F, FunctionAnalysisManager &FAM);
- bool operator==(const FunctionPropertiesInfo &FPI) const {
-return std::memcmp(this, &FPI, sizeof(FunctionPropertiesInfo)) == 0;
- }
+ bool operator==(const FunctionPropertiesInfo &FPI) const;
bool operator!=(const FunctionPropertiesInfo &FPI) const {
return !(*this == FPI);
@@ -137,6 +140,19 @@ class FunctionPropertiesInfo {
int64_t CallReturnsVectorPointerCount = 0;
int64_t CallWithManyArgumentsCount = 0;
int64_t CallWithPointerArgumentCount = 0;
+
+ const ir2vec::Embedding &getFunctionEmbedding() const {
+return FunctionEmbedding;
+ }
+
+ const std::optional &getIR2VecVocab() const {
+return IR2VecVocab;
+ }
+
+ // Helper intended to be useful for unittests
+ void setFunctionEmbeddingForTest(const ir2vec::Embedding &Embedding) {
+FunctionEmbedding = Embedding;
+ }
};
// Analysis pass
@@ -192,7 +208,7 @@ class FunctionPropertiesUpdater {
DominatorTree &getUpdatedDominatorTree(FunctionAnalysisManager &FAM) const;
- DenseSet Successors;
+ DenseSet Successors, CallUsers;
// Edges we might potentially need to remove from the dominator tree.
SmallVector DomTreeUpdates;
diff --git a/llvm/include/llvm/Analysis/IR2Vec.h
b/llvm/include/llvm/Analysis/IR2Vec.h
index 3a6f47ded8ca4..9acffb996283c 100644
--- a/llvm/include/llvm/Analysis/IR2Vec.h
+++ b/llvm/include/llvm/Analysis/IR2Vec.h
@@ -239,7 +239,7 @@ class IR2VecVocabAnalysis : public
AnalysisInfoMixin {
public:
static AnalysisKey Key;
IR2VecVocabAnalysis() = default;
- explicit IR2VecVocabAnalysis(ir2vec::Vocab &&Vocab);
+ explicit IR2VecVocabAnalysis(ir2vec::Vocab Vocab);
using Result = IR2VecVocabResult;
Result run(Module &M, ModuleAnalysisManager &MAM);
};
diff --git a/llvm/include/llvm/Analysis/InlineAdvisor.h
b/llvm/include/llvm/Analysis/InlineAdvisor.h
index 9d15136e81d10..d2cad4717cbdb 100644
--- a/llvm/include/llvm/Analysis/InlineAdvisor.h
+++ b/llvm/include/llvm/Analysis/InlineAdvisor.h
@@ -331,6 +331,9 @@ class InlineAdvisorAnalysis : public
AnalysisInfoMixin {
};
Result run(Module &M, ModuleAnalysisManager &MAM) { return Result(M, MAM); }
+
+private:
+ static bool initializeIR2VecVocab(Module &M, ModuleAnalysisManager &MAM);
};
/// Printer pass for the InlineAdvisorAnalysis results.
diff --git a/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
b/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
index 961d5091bf9f3..91d3378565fc5 100644
--- a/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
+++ b/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h
@@ -142,6 +142,10 @@ enum class FeatureIndex : size_t {
INLINE_FEATURE_ITERATOR(POPULATE_INDICES)
#undef POPULATE_INDICES
+// IR2Vec embeddings
+ callee_embedding,
+ caller_embedding,
+
NumberOfFeatures
};
// clang-format on
@@ -154,7 +158,7 @@ inlineCostFeatureToMlFeature(InlineCostFeatu
[llvm-branch-commits] [llvm] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
https://github.com/mtrofin edited https://github.com/llvm/llvm-project/pull/143479 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
@@ -294,8 +294,8 @@ Error IR2VecVocabAnalysis::readVocabulary() {
return Error::success();
}
-IR2VecVocabAnalysis::IR2VecVocabAnalysis(Vocab &&Vocabulary)
-: Vocabulary(std::move(Vocabulary)) {}
+IR2VecVocabAnalysis::IR2VecVocabAnalysis(Vocab Vocabulary)
+: Vocabulary(Vocabulary) {}
mtrofin wrote:
why?
can this change be made in a precursor PR?
https://github.com/llvm/llvm-project/pull/143479
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
@@ -199,6 +199,29 @@ void FunctionPropertiesInfo::updateForBB(const BasicBlock
&BB,
#undef CHECK_OPERAND
}
}
+
+ if (IR2VecVocab) {
+// We instantiate the IR2Vec embedder each time, as having an unique
+// pointer to the embedder as member of the class would make it
+// non-copyable. Instantiating the embedder in itself is not costly.
+auto EmbOrErr = ir2vec::Embedder::create(IR2VecKind::Symbolic,
mtrofin wrote:
separate patch, but we can do away with `create` returning Error, right?
https://github.com/llvm/llvm-project/pull/143479
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
@@ -186,6 +186,20 @@ MLInlineAdvisor::MLInlineAdvisor(
EdgeCount += getLocalCalls(KVP.first->getFunction());
}
NodeCount = AllNodes.size();
+
+ if (auto IR2VecVocabResult = MAM.getCachedResult(M)) {
+if (!IR2VecVocabResult->isValid()) {
+ M.getContext().emitError("IR2VecVocabAnalysis is not valid");
+ return;
+}
+// Add the IR2Vec features to the feature map
+auto IR2VecDim = IR2VecVocabResult->getDimension();
+FeatureMap.push_back(
+TensorSpec::createSpec("callee_embedding", {IR2VecDim}));
+FeatureMap.push_back(
+TensorSpec::createSpec("caller_embedding", {IR2VecDim}));
+UseIR2Vec = true;
mtrofin wrote:
nit: if it makes sense, you could have `const UseIR2Vec` and init it in the
ctor based on `MAM.getCachedResult`. Then here, if the result isn't valid,
splat the error.
main value is readability - the bool flag would say it's set once.
https://github.com/llvm/llvm-project/pull/143479
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
https://github.com/svkeerthy edited https://github.com/llvm/llvm-project/pull/143479 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
