google/autofdo

AutoFDO can not be built with LLVM trunk (LLVM-18)

foxtran opened this issue · 0 comments

I have tried to reproduce optimisation clang with Propeller.

I used that script, which I found in this repo: https://github.com/google/autofdo/blob/master/propeller_optimize_clang.sh

This script uses llvm trunk. Unfortunately, there is some changes in LLVM trunk that break compilation of https://github.com/google/autofdo/blob/master/llvm_profile_writer.cc:

/dev/shm/ger/propeller_optimize_clang.dir/trunk_llvm_install/bin/clang++ -DHAVE_LLVM=1 -DLLVM_GETELFFILE_RET_REFERENCE=1 -DLLVM_VERSION_MAJOR=18 -DLLVM_VERSION_MINOR=0 -I/dev/shm/ger/propeller_optimize_clang.dir/trunk_llvm_install/include -I/dev/shm/ger/propeller_optimize_clang.dir/create_llvm_prof_build/autofdo -I/dev/shm/ger/propeller_optimize_clang.dir/create_llvm_prof_build/autofdo/third_party/glog/src -I/dev/shm/ger/propeller_optimize_clang.dir/create_llvm_prof_build/autofdo/third_party/abseil -I/dev/shm/ger/propeller_optimize_clang.dir/create_llvm_prof_build/autofdo/third_party/perf_data_converter/src -I/dev/shm/ger/propeller_optimize_clang.dir/create_llvm_prof_build/autofdo/third_party/perf_data_converter/src/quipper -I/dev/shm/ger/propeller_optimize_clang.dir/create_llvm_prof_build/build -I/dev/shm/ger/propeller_optimize_clang.dir/create_llvm_prof_build/build/third_party/glog -I/dev/shm/ger/propeller_optimize_clang.dir/create_llvm_prof_build/autofdo/third_party/googletest/googlemock/include -I/dev/shm/ger/propeller_optimize_clang.dir/create_llvm_prof_build/autofdo/util/regexp -I/dev/shm/ger/propeller_optimize_clang.dir/create_llvm_prof_build/autofdo/libprotobuf -I/dev/shm/ger/propeller_optimize_clang.dir/create_llvm_prof_build/autofdo/util -isystem /dev/shm/ger/propeller_optimize_clang.dir/create_llvm_prof_build/autofdo/third_party/googletest/googletest/include -isystem /dev/shm/ger/propeller_optimize_clang.dir/create_llvm_prof_build/autofdo/third_party/googletest/googletest -std=gnu++17 -MD -MT CMakeFiles/llvm_profile_writer_test.dir/llvm_profile_writer_test.cc.o -MF CMakeFiles/llvm_profile_writer_test.dir/llvm_profile_writer_test.cc.o.d -o CMakeFiles/llvm_profile_writer_test.dir/llvm_profile_writer_test.cc.o -c /dev/shm/ger/propeller_optimize_clang.dir/create_llvm_prof_build/autofdo/llvm_profile_writer_test.cc
In file included from /dev/shm/ger/propeller_optimize_clang.dir/create_llvm_prof_build/autofdo/llvm_profile_writer_test.cc:1:
In file included from /dev/shm/ger/propeller_optimize_clang.dir/create_llvm_prof_build/autofdo/llvm_profile_writer.h:7:
/dev/shm/ger/propeller_optimize_clang.dir/create_llvm_prof_build/autofdo/profile_writer.h:164:8: warning: 'VisitCallsite' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
  164 |   void VisitCallsite(const Callsite &callsite) {
      |        ^
/dev/shm/ger/propeller_optimize_clang.dir/create_llvm_prof_build/autofdo/profile_writer.h:130:16: note: overridden virtual function is here
  130 |   virtual void VisitCallsite(const Callsite &offset) {}
      |                ^
/dev/shm/ger/propeller_optimize_clang.dir/create_llvm_prof_build/autofdo/llvm_profile_writer_test.cc:84:26: error: no member named 'lookup' in 'std::unordered_map<llvm::sampleprof::FunctionId, unsigned long>'
   84 |   ASSERT_EQ(call_targets.lookup("_Z3fooi"), 3336);
      |             ~~~~~~~~~~~~ ^
/dev/shm/ger/propeller_optimize_clang.dir/create_llvm_prof_build/autofdo/third_party/googletest/googletest/include/gtest/gtest.h:1897:47: note: expanded from macro 'ASSERT_EQ'
 1897 | #define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2)
      |                                               ^~~~
/dev/shm/ger/propeller_optimize_clang.dir/create_llvm_prof_build/autofdo/third_party/googletest/googletest/include/gtest/gtest.h:1881:63: note: expanded from macro 'GTEST_ASSERT_EQ'
 1881 |   ASSERT_PRED_FORMAT2(::testing::internal::EqHelper::Compare, val1, val2)
      |                                                               ^~~~
/dev/shm/ger/propeller_optimize_clang.dir/create_llvm_prof_build/autofdo/third_party/googletest/googletest/include/gtest/gtest_pred_impl.h:148:36: note: expanded from macro 'ASSERT_PRED_FORMAT2'
  148 |   GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_FATAL_FAILURE_)
      |                                    ^~
/dev/shm/ger/propeller_optimize_clang.dir/create_llvm_prof_build/autofdo/third_party/googletest/googletest/include/gtest/gtest_pred_impl.h:134:39: note: expanded from macro 'GTEST_PRED_FORMAT2_'
  134 |   GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), on_failure)
      |                                       ^~
/dev/shm/ger/propeller_optimize_clang.dir/create_llvm_prof_build/autofdo/third_party/googletest/googletest/include/gtest/gtest_pred_impl.h:79:52: note: expanded from macro 'GTEST_ASSERT_'
   79 |   if (const ::testing::AssertionResult gtest_ar = (expression)) \
      |                                                    ^~~~~~~~~~
/dev/shm/ger/propeller_optimize_clang.dir/create_llvm_prof_build/autofdo/llvm_profile_writer_test.cc:85:26: error: no member named 'lookup' in 'std::unordered_map<llvm::sampleprof::FunctionId, unsigned long>'
   85 |   ASSERT_EQ(call_targets.lookup("_Z3bari"), 8045);
      |             ~~~~~~~~~~~~ ^
/dev/shm/ger/propeller_optimize_clang.dir/create_llvm_prof_build/autofdo/third_party/googletest/googletest/include/gtest/gtest.h:1897:47: note: expanded from macro 'ASSERT_EQ'
 1897 | #define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2)
      |                                               ^~~~
/dev/shm/ger/propeller_optimize_clang.dir/create_llvm_prof_build/autofdo/third_party/googletest/googletest/include/gtest/gtest.h:1881:63: note: expanded from macro 'GTEST_ASSERT_EQ'
 1881 |   ASSERT_PRED_FORMAT2(::testing::internal::EqHelper::Compare, val1, val2)
      |                                                               ^~~~
/dev/shm/ger/propeller_optimize_clang.dir/create_llvm_prof_build/autofdo/third_party/googletest/googletest/include/gtest/gtest_pred_impl.h:148:36: note: expanded from macro 'ASSERT_PRED_FORMAT2'
  148 |   GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_FATAL_FAILURE_)
      |                                    ^~
/dev/shm/ger/propeller_optimize_clang.dir/create_llvm_prof_build/autofdo/third_party/googletest/googletest/include/gtest/gtest_pred_impl.h:134:39: note: expanded from macro 'GTEST_PRED_FORMAT2_'
  134 |   GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), on_failure)
      |                                       ^~
/dev/shm/ger/propeller_optimize_clang.dir/create_llvm_prof_build/autofdo/third_party/googletest/googletest/include/gtest/gtest_pred_impl.h:79:52: note: expanded from macro 'GTEST_ASSERT_'
   79 |   if (const ::testing::AssertionResult gtest_ar = (expression)) \
      |                                                    ^~~~~~~~~~
1 warning and 2 errors generated.

I did not research which commit breaks autofdo build, but, at least, with llvm-17 autofdo works yet.

So, I used the following patch to compile autofdo with llvm-17:

--- propeller_optimize_clang.sh.orig	2023-10-26 16:54:07.550679311 +0900
+++ propeller_optimize_clang.sh	2023-10-26 16:54:58.961428839 +0900
@@ -30,7 +30,7 @@ PATH_TO_TRUNK_LLVM_BUILD=${BASE_PROPELLE
 PATH_TO_TRUNK_LLVM_INSTALL=${BASE_PROPELLER_CLANG_DIR}/trunk_llvm_install
 # Build Trunk LLVM
 mkdir -p ${PATH_TO_LLVM_SOURCES} && cd ${PATH_TO_LLVM_SOURCES}
-git clone git@github.com:llvm/llvm-project.git
+git clone -b release/17.x --single-branch git@github.com:llvm/llvm-project.git
 mkdir -p ${PATH_TO_TRUNK_LLVM_BUILD} && cd ${PATH_TO_TRUNK_LLVM_BUILD}
 cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=X86 \
       -DCMAKE_INSTALL_PREFIX="${PATH_TO_TRUNK_LLVM_INSTALL}" \