[llvm] [mlgo] Allow passing pre-emitc-ed models (PR #227941)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 30 20:47:30 PDT 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions h,inc,cpp -- llvm/lib/Analysis/models/inline-oz-test-model.inc llvm/lib/Analysis/models/regalloc-eviction-test-model.inc llvm/include/llvm/Analysis/Utils/MLGOUtils.h llvm/lib/Analysis/MLInlineAdvisor.cpp llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp llvm/unittests/Analysis/MLGOUtilsTest.cpp --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/lib/Analysis/models/inline-oz-test-model.inc b/llvm/lib/Analysis/models/inline-oz-test-model.inc
index 68dd73138..62a204f8e 100644
--- a/llvm/lib/Analysis/models/inline-oz-test-model.inc
+++ b/llvm/lib/Analysis/models/inline-oz-test-model.inc
@@ -2,50 +2,93 @@
#include <string>
static const int64_t __constant_xi64 = 1;
class Model {
- public:
- int64_t* fieldName0;
- int64_t* fieldName1;
- int64_t* fieldName2;
- int64_t* fieldName3;
- int64_t* fieldName4;
- int64_t* fieldName5;
- int64_t* fieldName6;
- int64_t* fieldName7;
- int64_t* fieldName8;
- int64_t* fieldName9;
- int64_t* fieldName10;
- int64_t* fieldName11;
- int64_t* fieldName12;
- int64_t* fieldName13;
- int64_t* fieldName14;
- int64_t* fieldName15;
- int64_t* fieldName16;
- int64_t* fieldName17;
- int64_t* fieldName18;
- int64_t* fieldName19;
- int64_t* fieldName20;
- int64_t* fieldName21;
- int64_t* fieldName22;
- int64_t* fieldName23;
- int64_t* fieldName24;
- int64_t* fieldName25;
- int64_t* fieldName26;
- int32_t* fieldName27;
- int64_t* fieldName28;
- int64_t* fieldName29;
- int64_t* fieldName30;
- int64_t* fieldName31;
- int64_t* fieldName32;
- int64_t* fieldName33;
- int64_t* fieldName34;
- int64_t* fieldName35;
- int64_t* fieldName36;
- float* fieldName37;
- int64_t* fieldName38;
- float* fieldName39;
- const std::map<std::string, char*> reflectionMap = { { "callsite_cost", reinterpret_cast<char*>(&fieldName0) }, { "is_multiple_blocks", reinterpret_cast<char*>(&fieldName1) }, { "caller_conditionally_executed_blocks", reinterpret_cast<char*>(&fieldName2) }, { "cold_cc_penalty", reinterpret_cast<char*>(&fieldName3) }, { "callee_conditionally_executed_blocks", reinterpret_cast<char*>(&fieldName4) }, { "callee_users", reinterpret_cast<char*>(&fieldName5) }, { "callee_basic_block_count", reinterpret_cast<char*>(&fieldName6) }, { "nr_ctant_params", reinterpret_cast<char*>(&fieldName7) }, { "load_relative_intrinsic", reinterpret_cast<char*>(&fieldName8) }, { "jump_table_penalty", reinterpret_cast<char*>(&fieldName9) }, { "unsimplified_common_instructions", reinterpret_cast<char*>(&fieldName10) }, { "indirect_call_penalty", reinterpret_cast<char*>(&fieldName11) }, { "load_elimination", reinterpret_cast<char*>(&fieldName12) }, { "is_caller_avail_external", reinterpret_cast<char*>(&fieldName13) }, { "call_penalty", reinterpret_cast<char*>(&fieldName14) }, { "cost_estimate", reinterpret_cast<char*>(&fieldName15) }, { "case_cluster_penalty", reinterpret_cast<char*>(&fieldName16) }, { "node_count", reinterpret_cast<char*>(&fieldName17) }, { "call_argument_setup", reinterpret_cast<char*>(&fieldName18) }, { "sroa_savings", reinterpret_cast<char*>(&fieldName19) }, { "lowered_call_arg_setup", reinterpret_cast<char*>(&fieldName20) }, { "threshold", reinterpret_cast<char*>(&fieldName21) }, { "dead_blocks", reinterpret_cast<char*>(&fieldName22) }, { "constant_args", reinterpret_cast<char*>(&fieldName23) }, { "sroa_losses", reinterpret_cast<char*>(&fieldName24) }, { "simplified_instructions", reinterpret_cast<char*>(&fieldName25) }, { "num_loops", reinterpret_cast<char*>(&fieldName26) }, { "step_type", reinterpret_cast<char*>(&fieldName27) }, { "edge_count", reinterpret_cast<char*>(&fieldName28) }, { "is_callee_avail_external", reinterpret_cast<char*>(&fieldName29) }, { "nested_inlines", reinterpret_cast<char*>(&fieldName30) }, { "caller_basic_block_count", reinterpret_cast<char*>(&fieldName31) }, { "last_call_to_static_bonus", reinterpret_cast<char*>(&fieldName32) }, { "nested_inline_cost_estimate", reinterpret_cast<char*>(&fieldName33) }, { "callsite_height", reinterpret_cast<char*>(&fieldName34) }, { "constant_offset_ptr_args", reinterpret_cast<char*>(&fieldName35) }, { "switch_penalty", reinterpret_cast<char*>(&fieldName36) }, { "discount", reinterpret_cast<char*>(&fieldName37) }, { "caller_users", reinterpret_cast<char*>(&fieldName38) }, { "reward", reinterpret_cast<char*>(&fieldName39) } };
- char* getBufferForName(std::string v1) {
- char* v2 = reflectionMap.at(v1);
+public:
+ int64_t *fieldName0;
+ int64_t *fieldName1;
+ int64_t *fieldName2;
+ int64_t *fieldName3;
+ int64_t *fieldName4;
+ int64_t *fieldName5;
+ int64_t *fieldName6;
+ int64_t *fieldName7;
+ int64_t *fieldName8;
+ int64_t *fieldName9;
+ int64_t *fieldName10;
+ int64_t *fieldName11;
+ int64_t *fieldName12;
+ int64_t *fieldName13;
+ int64_t *fieldName14;
+ int64_t *fieldName15;
+ int64_t *fieldName16;
+ int64_t *fieldName17;
+ int64_t *fieldName18;
+ int64_t *fieldName19;
+ int64_t *fieldName20;
+ int64_t *fieldName21;
+ int64_t *fieldName22;
+ int64_t *fieldName23;
+ int64_t *fieldName24;
+ int64_t *fieldName25;
+ int64_t *fieldName26;
+ int32_t *fieldName27;
+ int64_t *fieldName28;
+ int64_t *fieldName29;
+ int64_t *fieldName30;
+ int64_t *fieldName31;
+ int64_t *fieldName32;
+ int64_t *fieldName33;
+ int64_t *fieldName34;
+ int64_t *fieldName35;
+ int64_t *fieldName36;
+ float *fieldName37;
+ int64_t *fieldName38;
+ float *fieldName39;
+ const std::map<std::string, char *> reflectionMap = {
+ {"callsite_cost", reinterpret_cast<char *>(&fieldName0)},
+ {"is_multiple_blocks", reinterpret_cast<char *>(&fieldName1)},
+ {"caller_conditionally_executed_blocks",
+ reinterpret_cast<char *>(&fieldName2)},
+ {"cold_cc_penalty", reinterpret_cast<char *>(&fieldName3)},
+ {"callee_conditionally_executed_blocks",
+ reinterpret_cast<char *>(&fieldName4)},
+ {"callee_users", reinterpret_cast<char *>(&fieldName5)},
+ {"callee_basic_block_count", reinterpret_cast<char *>(&fieldName6)},
+ {"nr_ctant_params", reinterpret_cast<char *>(&fieldName7)},
+ {"load_relative_intrinsic", reinterpret_cast<char *>(&fieldName8)},
+ {"jump_table_penalty", reinterpret_cast<char *>(&fieldName9)},
+ {"unsimplified_common_instructions",
+ reinterpret_cast<char *>(&fieldName10)},
+ {"indirect_call_penalty", reinterpret_cast<char *>(&fieldName11)},
+ {"load_elimination", reinterpret_cast<char *>(&fieldName12)},
+ {"is_caller_avail_external", reinterpret_cast<char *>(&fieldName13)},
+ {"call_penalty", reinterpret_cast<char *>(&fieldName14)},
+ {"cost_estimate", reinterpret_cast<char *>(&fieldName15)},
+ {"case_cluster_penalty", reinterpret_cast<char *>(&fieldName16)},
+ {"node_count", reinterpret_cast<char *>(&fieldName17)},
+ {"call_argument_setup", reinterpret_cast<char *>(&fieldName18)},
+ {"sroa_savings", reinterpret_cast<char *>(&fieldName19)},
+ {"lowered_call_arg_setup", reinterpret_cast<char *>(&fieldName20)},
+ {"threshold", reinterpret_cast<char *>(&fieldName21)},
+ {"dead_blocks", reinterpret_cast<char *>(&fieldName22)},
+ {"constant_args", reinterpret_cast<char *>(&fieldName23)},
+ {"sroa_losses", reinterpret_cast<char *>(&fieldName24)},
+ {"simplified_instructions", reinterpret_cast<char *>(&fieldName25)},
+ {"num_loops", reinterpret_cast<char *>(&fieldName26)},
+ {"step_type", reinterpret_cast<char *>(&fieldName27)},
+ {"edge_count", reinterpret_cast<char *>(&fieldName28)},
+ {"is_callee_avail_external", reinterpret_cast<char *>(&fieldName29)},
+ {"nested_inlines", reinterpret_cast<char *>(&fieldName30)},
+ {"caller_basic_block_count", reinterpret_cast<char *>(&fieldName31)},
+ {"last_call_to_static_bonus", reinterpret_cast<char *>(&fieldName32)},
+ {"nested_inline_cost_estimate", reinterpret_cast<char *>(&fieldName33)},
+ {"callsite_height", reinterpret_cast<char *>(&fieldName34)},
+ {"constant_offset_ptr_args", reinterpret_cast<char *>(&fieldName35)},
+ {"switch_penalty", reinterpret_cast<char *>(&fieldName36)},
+ {"discount", reinterpret_cast<char *>(&fieldName37)},
+ {"caller_users", reinterpret_cast<char *>(&fieldName38)},
+ {"reward", reinterpret_cast<char *>(&fieldName39)}};
+ char *getBufferForName(std::string v1) {
+ char *v2 = reflectionMap.at(v1);
return v2;
}
int64_t operator()() {
@@ -53,4 +96,3 @@ class Model {
return v1;
}
};
-
diff --git a/llvm/lib/Analysis/models/regalloc-eviction-test-model.inc b/llvm/lib/Analysis/models/regalloc-eviction-test-model.inc
index 0f4d5f975..dff437188 100644
--- a/llvm/lib/Analysis/models/regalloc-eviction-test-model.inc
+++ b/llvm/lib/Analysis/models/regalloc-eviction-test-model.inc
@@ -1,11 +1,12 @@
#include <map>
#include <string>
class Model {
- public:
+public:
int64_t fieldName0[33];
- const std::map<std::string, char*> reflectionMap = { { "mask", reinterpret_cast<char*>(&fieldName0) } };
- char* getBufferForName(std::string v1) {
- char* v2 = reflectionMap.at(v1);
+ const std::map<std::string, char *> reflectionMap = {
+ {"mask", reinterpret_cast<char *>(&fieldName0)}};
+ char *getBufferForName(std::string v1) {
+ char *v2 = reflectionMap.at(v1);
return v2;
}
int64_t operator()() {
@@ -18,23 +19,23 @@ class Model {
int32_t v7[33];
for (size_t i8 = v4; i8 < v3; i8 += v2) {
int64_t v9 = fieldName0[i8];
- uint64_t v10 = (uint64_t) v9;
- uint32_t v11 = (uint32_t) v10;
- int32_t v12 = (int32_t) v11;
+ uint64_t v10 = (uint64_t)v9;
+ uint32_t v11 = (uint32_t)v10;
+ int32_t v12 = (int32_t)v11;
v7[i8] = v12;
}
int64_t v13;
- int64_t* v14 = &v13;
+ int64_t *v14 = &v13;
v14[v1] = v6;
int32_t v15;
- int32_t* v16 = &v15;
+ int32_t *v16 = &v15;
v16[v1] = v5;
for (size_t i17 = v4; i17 < v3; i17 += v2) {
int32_t v18 = v7[i17];
int64_t v19 = v14[v1];
int32_t v20 = v16[v1];
- ptrdiff_t v21 = (ptrdiff_t) i17;
- int64_t v22 = (int64_t) v21;
+ ptrdiff_t v21 = (ptrdiff_t)i17;
+ int64_t v22 = (int64_t)v21;
bool v23 = v18 > v20;
bool v24 = v18 > v20;
int32_t v25 = v24 ? v18 : v20;
@@ -46,4 +47,3 @@ class Model {
return v27;
}
};
-
diff --git a/llvm/unittests/Analysis/MLGOUtilsTest.cpp b/llvm/unittests/Analysis/MLGOUtilsTest.cpp
index 44b67d7a9..8122c251a 100644
--- a/llvm/unittests/Analysis/MLGOUtilsTest.cpp
+++ b/llvm/unittests/Analysis/MLGOUtilsTest.cpp
@@ -158,11 +158,8 @@ TEST(MLGOUtilsTest, CreateReleaseModeModelRunnerAOTFallback) {
TensorSpec::createSpec<int64_t>("b", {1})};
TensorSpec OutputSpec = TensorSpec::createSpec<int64_t>("result", {1});
- auto DummyEmitCFactory =
- [](LLVMContext &,
- const std::vector<TensorSpec> &) -> std::unique_ptr<MLModelRunner> {
- return nullptr;
- };
+ auto DummyEmitCFactory = [](LLVMContext &, const std::vector<TensorSpec> &)
+ -> std::unique_ptr<MLModelRunner> { return nullptr; };
auto Runner = createReleaseModeModelRunner<MockAOTModel>(
Ctx, Inputs, "result", "", OutputSpec, DummyEmitCFactory);
``````````
</details>
https://github.com/llvm/llvm-project/pull/227941
More information about the llvm-commits
mailing list