diff options
author | Dehao Chen <dehao@google.com> | 2016-10-18 20:42:47 +0000 |
---|---|---|
committer | Dehao Chen <dehao@google.com> | 2016-10-18 20:42:47 +0000 |
commit | 302b69c9406b1c690db2e8faaf0a2211dfd46879 (patch) | |
tree | 580f38a5f827e7b9ee3b540edfc028671421347c /llvm/lib/IR/Function.cpp | |
parent | 4dd6c68d67c25af4617238c1308f6aa6caa6e82c (diff) | |
download | bcm5719-llvm-302b69c9406b1c690db2e8faaf0a2211dfd46879.tar.gz bcm5719-llvm-302b69c9406b1c690db2e8faaf0a2211dfd46879.zip |
Use profile info to set function section prefix to group hot/cold functions.
Summary:
The original implementation is in r261607, which was reverted in r269726 to accomendate the ProfileSummaryInfo analysis pass. The new implementation:
1. add a new metadata for function section prefix
2. query against ProfileSummaryInfo in CGP to set the correct section prefix for each function
3. output the section prefix set by CGP
Reviewers: davidxl, eraman
Subscribers: vsk, llvm-commits
Differential Revision: https://reviews.llvm.org/D24989
llvm-svn: 284533
Diffstat (limited to 'llvm/lib/IR/Function.cpp')
-rw-r--r-- | llvm/lib/IR/Function.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp index f9f33fef452..e1b4d4af457 100644 --- a/llvm/lib/IR/Function.cpp +++ b/llvm/lib/IR/Function.cpp @@ -1274,3 +1274,20 @@ Optional<uint64_t> Function::getEntryCount() const { } return None; } + +void Function::setSectionPrefix(StringRef Prefix) { + MDBuilder MDB(getContext()); + setMetadata(LLVMContext::MD_section_prefix, + MDB.createFunctionSectionPrefix(Prefix)); +} + +Optional<StringRef> Function::getSectionPrefix() const { + if (MDNode *MD = getMetadata(LLVMContext::MD_section_prefix)) { + assert(dyn_cast<MDString>(MD->getOperand(0)) + ->getString() + .equals("function_section_prefix") && + "Metadata not match"); + return dyn_cast<MDString>(MD->getOperand(1))->getString(); + } + return None; +} |