summaryrefslogtreecommitdiffstats
path: root/clang
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
commit4c9c45c060e7597f035582de0f05e1a01e841d65 (patch)
tree824303c2ec1183cd7a4350271e783ff52a2b69ba /clang
parenta44acc78caf6a722a77d1c4db6b4b77307a7af26 (diff)
downloadbcm5719-llvm-4c9c45c060e7597f035582de0f05e1a01e841d65.tar.gz
bcm5719-llvm-4c9c45c060e7597f035582de0f05e1a01e841d65.zip
CodeGen: Move hot/cold logic out of PGOProfileData
llvm-svn: 203689
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/CodeGen/CodeGenPGO.cpp51
-rw-r--r--clang/lib/CodeGen/CodeGenPGO.h9
2 files changed, 21 insertions, 39 deletions
diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp
index ed92de6e6dc..3206daa76a6 100644
--- a/clang/lib/CodeGen/CodeGenPGO.cpp
+++ b/clang/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),
diff --git a/clang/lib/CodeGen/CodeGenPGO.h b/clang/lib/CodeGen/CodeGenPGO.h
index 7ee1b27573b..51d59cf9a9b 100644
--- a/clang/lib/CodeGen/CodeGenPGO.h
+++ b/clang/lib/CodeGen/CodeGenPGO.h
@@ -43,12 +43,8 @@ public:
/// Fill Counts with the profile data for the given function name. Returns
/// false on success.
bool getFunctionCounts(StringRef FuncName, std::vector<uint64_t> &Counts);
- /// Return true if a function is hot. If we know nothing about the function,
- /// return false.
- bool isHotFunction(StringRef FuncName);
- /// Return true if a function is cold. If we know nothing about the function,
- /// return false.
- bool isColdFunction(StringRef FuncName);
+ /// Return the maximum of all known function counts.
+ uint64_t getMaximumFunctionCount() { return MaxFunctionCount; }
};
/// Per-function PGO state. This class should generally not be used directly,
@@ -140,6 +136,7 @@ private:
void setFuncName(llvm::Function *Fn);
void mapRegionCounters(const Decl *D);
void computeRegionCounts(const Decl *D);
+ void applyFunctionAttributes(PGOProfileData *PGOData, llvm::Function *Fn);
void loadRegionCounts(PGOProfileData *PGOData);
void emitCounterVariables();
OpenPOWER on IntegriCloud