[PATCH] D110522: Add build option to specify profdata type

Yi Kong via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 26 23:59:45 PDT 2021


kongyi created this revision.
Herald added a subscriber: mgorny.
kongyi requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

There is an option to generate IR profile for LLVM but no way to actually use it. Add an option to choose which type of profdata is given, and default to frontend profile if option is not set to maintain the current behaviour.


https://reviews.llvm.org/D110522

Files:
  llvm/cmake/modules/HandleLLVMOptions.cmake


Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===================================================================
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -1037,18 +1037,36 @@
     CMAKE_SHARED_LINKER_FLAGS)
 endif()
 
+set(LLVM_PROFDATA_TYPE OFF CACHE STRING "The type of PGO profile used to build LLVM and tools. May be specified as IR or Frontend")
+mark_as_advanced(LLVM_PROFDATA_TYPE)
+string(TOUPPER "${LLVM_PROFDATA_TYPE}" uppercase_LLVM_PROFDATA_TYPE)
 if(LLVM_PROFDATA_FILE AND EXISTS ${LLVM_PROFDATA_FILE})
-  if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
-    append("-fprofile-instr-use=\"${LLVM_PROFDATA_FILE}\""
-      CMAKE_CXX_FLAGS
-      CMAKE_C_FLAGS)
-    if(NOT LINKER_IS_LLD_LINK)
-      append("-fprofile-instr-use=\"${LLVM_PROFDATA_FILE}\""
-        CMAKE_EXE_LINKER_FLAGS
-        CMAKE_SHARED_LINKER_FLAGS)
+  if (uppercase_LLVM_PROFDATA_TYPE STREQUAL "IR")
+    if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
+      append("-fprofile-use=\"${LLVM_PROFDATA_FILE}\""
+        CMAKE_CXX_FLAGS
+        CMAKE_C_FLAGS)
+      if(NOT LINKER_IS_LLD_LINK)
+        append("-fprofile-use=\"${LLVM_PROFDATA_FILE}\""
+          CMAKE_EXE_LINKER_FLAGS
+          CMAKE_SHARED_LINKER_FLAGS)
+      endif()
+    else()
+      message(FATAL_ERROR "LLVM_PROFDATA_FILE can only be specified when compiling with clang")
     endif()
   else()
-    message(FATAL_ERROR "LLVM_PROFDATA_FILE can only be specified when compiling with clang")
+    if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
+      append("-fprofile-instr-use=\"${LLVM_PROFDATA_FILE}\""
+        CMAKE_CXX_FLAGS
+        CMAKE_C_FLAGS)
+      if(NOT LINKER_IS_LLD_LINK)
+        append("-fprofile-instr-use=\"${LLVM_PROFDATA_FILE}\""
+          CMAKE_EXE_LINKER_FLAGS
+          CMAKE_SHARED_LINKER_FLAGS)
+      endif()
+    else()
+      message(FATAL_ERROR "LLVM_PROFDATA_FILE can only be specified when compiling with clang")
+    endif()
   endif()
 endif()
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110522.375155.patch
Type: text/x-patch
Size: 2006 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210927/b650cda4/attachment.bin>


More information about the llvm-commits mailing list