summaryrefslogtreecommitdiff
path: root/lib/CodeGen/CodeGenPGO.cpp
diff options
context:
space:
mode:
authorJustin Bogner <mail@justinbogner.com>2014-03-12 18:14:32 +0000
committerJustin Bogner <mail@justinbogner.com>2014-03-12 18:14:32 +0000
commit4142aa7cc7146ae947ddcd0500afc4ea274275d5 (patch)
tree6cd832414e3058689ce0467532accb8b05a3621c /lib/CodeGen/CodeGenPGO.cpp
parent4b11d767d52c819894f705353ffb401e71354818 (diff)
downloadclang-4142aa7cc7146ae947ddcd0500afc4ea274275d5.tar.gz
clang-4142aa7cc7146ae947ddcd0500afc4ea274275d5.tar.bz2
clang-4142aa7cc7146ae947ddcd0500afc4ea274275d5.tar.xz
CodeGen: Move hot/cold logic out of PGOProfileData
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203689 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CodeGenPGO.cpp')
-rw-r--r--lib/CodeGen/CodeGenPGO.cpp51
1 files changed, 18 insertions, 33 deletions
diff --git a/lib/CodeGen/CodeGenPGO.cpp b/lib/CodeGen/CodeGenPGO.cpp
index ed92de6e6d..3206daa76a 100644
--- a/lib/CodeGen/CodeGenPGO.cpp
+++ b/lib/CodeGen/CodeGenPGO.cpp
@@ -99,32 +99,6 @@ PGOProfileData::PGOProfileData(CodeGenModule &CGM, std::string Path)
MaxFunctionCount = MaxCount;
}
-/// Return true if a function is hot. If we know nothing about the function,
-/// return false.
-bool PGOProfileData::isHotFunction(StringRef FuncName) {
- llvm::StringMap<uint64_t>::const_iterator CountIter =
- FunctionCounts.find(FuncName);
- // If we know nothing about the function, return false.
- if (CountIter == FunctionCounts.end())
- return false;
- // FIXME: functions with >= 30% of the maximal function count are
- // treated as hot. This number is from preliminary tuning on SPEC.
- return CountIter->getValue() >= (uint64_t)(0.3 * (double)MaxFunctionCount);
-}
-
-/// Return true if a function is cold. If we know nothing about the function,
-/// return false.
-bool PGOProfileData::isColdFunction(StringRef FuncName) {
- llvm::StringMap<uint64_t>::const_iterator CountIter =
- FunctionCounts.find(FuncName);
- // If we know nothing about the function, return false.
- if (CountIter == FunctionCounts.end())
- return false;
- // FIXME: functions with <= 1% of the maximal function count are treated as
- // cold. This number is from preliminary tuning on SPEC.
- return CountIter->getValue() <= (uint64_t)(0.01 * (double)MaxFunctionCount);
-}
-
bool PGOProfileData::getFunctionCounts(StringRef FuncName,
std::vector<uint64_t> &Counts) {
// Find the relevant section of the pgo-data file.
@@ -796,13 +770,7 @@ void CodeGenPGO::assignRegionCounters(const Decl *D, llvm::Function *Fn) {
if (PGOData) {
loadRegionCounts(PGOData);
computeRegionCounts(D);
-
- // Turn on InlineHint attribute for hot functions.
- if (PGOData->isHotFunction(getFuncName()))
- Fn->addFnAttr(llvm::Attribute::InlineHint);
- // Turn on Cold attribute for cold functions.
- else if (PGOData->isColdFunction(getFuncName()))
- Fn->addFnAttr(llvm::Attribute::Cold);
+ applyFunctionAttributes(PGOData, Fn);
}
}
@@ -829,6 +797,23 @@ void CodeGenPGO::computeRegionCounts(const Decl *D) {
Walker.VisitBlockDecl(BD);
}
+void CodeGenPGO::applyFunctionAttributes(PGOProfileData *PGOData,
+ llvm::Function *Fn) {
+ if (!haveRegionCounts())
+ return;
+
+ uint64_t MaxFunctionCount = PGOData->getMaximumFunctionCount();
+ uint64_t FunctionCount = getRegionCount(0);
+ if (FunctionCount >= (uint64_t)(0.3 * (double)MaxFunctionCount))
+ // Turn on InlineHint attribute for hot functions.
+ // FIXME: 30% is from preliminary tuning on SPEC, it may not be optimal.
+ Fn->addFnAttr(llvm::Attribute::InlineHint);
+ else if (FunctionCount <= (uint64_t)(0.01 * (double)MaxFunctionCount))
+ // Turn on Cold attribute for cold functions.
+ // FIXME: 1% is from preliminary tuning on SPEC, it may not be optimal.
+ Fn->addFnAttr(llvm::Attribute::Cold);
+}
+
void CodeGenPGO::emitCounterVariables() {
llvm::LLVMContext &Ctx = CGM.getLLVMContext();
llvm::ArrayType *CounterTy = llvm::ArrayType::get(llvm::Type::getInt64Ty(Ctx),