diff options
author | Xinliang David Li <davidxl@google.com> | 2015-12-21 20:41:20 +0000 |
---|---|---|
committer | Xinliang David Li <davidxl@google.com> | 2015-12-21 20:41:20 +0000 |
commit | 6c494cd0df0704a7795428e87cb38399f4230be8 (patch) | |
tree | 60f945b8c47aaf5d9ea1618c829fff4b2f28010e /llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp | |
parent | 0c97988e54d08cf84c1da9301fa4495384a9fbc0 (diff) | |
download | llvm-6c494cd0df0704a7795428e87cb38399f4230be8.zip llvm-6c494cd0df0704a7795428e87cb38399f4230be8.tar.gz llvm-6c494cd0df0704a7795428e87cb38399f4230be8.tar.bz2 |
[PGO] Fix profile var comdat generation problem with COFF
When targeting COFF, it is required that a comdat section to
have a global obj with the same name as the comdat (except for
comdats with select kind to be associative). This fix makes
sure that the comdat is keyed on the data variable for COFF.
Also improved test coverage for this.
llvm-svn: 256193
Diffstat (limited to 'llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp')
-rw-r--r-- | llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp index 57ed2f7..0c0b54f 100644 --- a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp +++ b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp @@ -279,6 +279,16 @@ static inline bool shouldRecordFunctionAddr(Function *F) { return F->hasAddressTaken(); } +static inline Comdat *getOrCreateProfileComdat(Module &M, + InstrProfIncrementInst *Inc) { + // COFF format requires a COMDAT section to have a key symbol with the same + // name. + StringRef ComdatPrefix = (Triple(M.getTargetTriple()).isOSBinFormatCOFF() + ? getInstrProfDataVarPrefix() + : getInstrProfComdatPrefix()); + return M.getOrInsertComdat(StringRef(getVarName(Inc, ComdatPrefix))); +} + GlobalVariable * InstrProfiling::getOrCreateRegionCounters(InstrProfIncrementInst *Inc) { GlobalVariable *NamePtr = Inc->getName(); @@ -297,8 +307,7 @@ InstrProfiling::getOrCreateRegionCounters(InstrProfIncrementInst *Inc) { Function *Fn = Inc->getParent()->getParent(); Comdat *ProfileVarsComdat = nullptr; if (Fn->hasComdat()) - ProfileVarsComdat = M->getOrInsertComdat( - StringRef(getVarName(Inc, getInstrProfComdatPrefix()))); + ProfileVarsComdat = getOrCreateProfileComdat(*M, Inc); NamePtr->setSection(getNameSection()); NamePtr->setAlignment(1); NamePtr->setComdat(ProfileVarsComdat); |