[PATCH] D92493: IR] Add hot to function attributes and use hot/cold attribute in function section prefix/suffix

Rong Xu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 2 09:46:10 PST 2020


xur created this revision.
xur added a reviewer: davidxl.
Herald added subscribers: dexonsmith, wenlei, jdoerfert, pengfei, hiraditya.
Herald added a project: LLVM.
xur requested review of this revision.

Clang FE currently has hot/cold function attribute. But we only have cold
function attribute in LLVM IR.

This patch adds support of hot function attribute to LLVM IR.
This attribute will be used in setting function section prefix/suffix.
Currently .hot and .unlikely suffix only are added in PGO (Sample PGO)
compilation (through isFunctionHotInCallGraph and isFunctionColdInCallGraph).

This patch changes the behavior. The new behavior is:
(1) If the user annotates a function as hot or isFunctionHotInCallGraph
is true, this function will be marked as hot.
(2) If the user annotates a function as cold or isFunctionColdInCallGraph
is true, this function will be marked as cold.

The changes are:
(1) user annotated function will used in setting function section prefix/suffix.
(2) hot attribute overwrites profile count based hotness.
(3) profile count based hotness overwrite user annotated cold attribute.

The intention for these changes is to provide the user a way to mark
certain function as hot in cases where training input is hard to cover all
the hot functions.

One thing that we might also need to change is we set cold attribute
in PGO instrumentation. This code is before isFunctionColdInCallGraph and
not use PSI. With this patch, we may mark more cold functions.
I did not change this part because cold attribute is used many downstream
optimizations other than setting function section prefix/suffix.


https://reviews.llvm.org/D92493

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/attributes.c
  llvm/include/llvm/Bitcode/LLVMBitCodes.h
  llvm/include/llvm/IR/Attributes.td
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/CodeGen/CodeGenPrepare.cpp
  llvm/lib/IR/Attributes.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
  llvm/test/CodeGen/X86/hot-unlikely-section-prefix.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92493.308998.patch
Type: text/x-patch
Size: 10876 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201202/272f2175/attachment.bin>


More information about the llvm-commits mailing list