diff options
author | Zequan Wu <zequanwu@google.com> | 2020-09-16 19:05:51 -0700 |
---|---|---|
committer | Zequan Wu <zequanwu@google.com> | 2020-09-18 10:57:54 -0700 |
commit | 91aed9bf975f1e4346cc8f4bdefc98436386ced2 (patch) | |
tree | 776f8209ad059a9d321f56e7087588b63a42c131 /llvm/lib/Target/TargetLoweringObjectFile.cpp | |
parent | d419e34c4d7e9e0b2b3f99b77246e57a03b2459b (diff) | |
download | llvm-91aed9bf975f1e4346cc8f4bdefc98436386ced2.zip llvm-91aed9bf975f1e4346cc8f4bdefc98436386ced2.tar.gz llvm-91aed9bf975f1e4346cc8f4bdefc98436386ced2.tar.bz2 |
[CodeGen] emit CG profile for COFF object file
I forgot to add emission of CG profile for COFF object file, when adding the support (https://reviews.llvm.org/D81775)
Differential Revision: https://reviews.llvm.org/D87811
Diffstat (limited to 'llvm/lib/Target/TargetLoweringObjectFile.cpp')
-rw-r--r-- | llvm/lib/Target/TargetLoweringObjectFile.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/llvm/lib/Target/TargetLoweringObjectFile.cpp b/llvm/lib/Target/TargetLoweringObjectFile.cpp index eea0aee..0e45c70 100644 --- a/llvm/lib/Target/TargetLoweringObjectFile.cpp +++ b/llvm/lib/Target/TargetLoweringObjectFile.cpp @@ -49,6 +49,8 @@ void TargetLoweringObjectFile::Initialize(MCContext &ctx, // Reset various EH DWARF encodings. PersonalityEncoding = LSDAEncoding = TTypeEncoding = dwarf::DW_EH_PE_absptr; CallSiteEncoding = dwarf::DW_EH_PE_uleb128; + + this->TM = &TM; } TargetLoweringObjectFile::~TargetLoweringObjectFile() { @@ -136,6 +138,50 @@ void TargetLoweringObjectFile::emitPersonalityValue(MCStreamer &Streamer, const MCSymbol *Sym) const { } +void TargetLoweringObjectFile::emitCGProfile(MCStreamer &Streamer, + Module &M) const { + MCContext &C = getContext(); + SmallVector<Module::ModuleFlagEntry, 8> ModuleFlags; + M.getModuleFlagsMetadata(ModuleFlags); + + MDNode *CFGProfile = nullptr; + + for (const auto &MFE : ModuleFlags) { + StringRef Key = MFE.Key->getString(); + if (Key == "CG Profile") { + CFGProfile = cast<MDNode>(MFE.Val); + break; + } + } + + if (!CFGProfile) + return; + + auto GetSym = [this](const MDOperand &MDO) -> MCSymbol * { + if (!MDO) + return nullptr; + auto *V = cast<ValueAsMetadata>(MDO); + const Function *F = cast<Function>(V->getValue()); + return TM->getSymbol(F); + }; + + for (const auto &Edge : CFGProfile->operands()) { + MDNode *E = cast<MDNode>(Edge); + const MCSymbol *From = GetSym(E->getOperand(0)); + const MCSymbol *To = GetSym(E->getOperand(1)); + // Skip null functions. This can happen if functions are dead stripped after + // the CGProfile pass has been run. + if (!From || !To) + continue; + uint64_t Count = cast<ConstantAsMetadata>(E->getOperand(2)) + ->getValue() + ->getUniqueInteger() + .getZExtValue(); + Streamer.emitCGProfileEntry( + MCSymbolRefExpr::create(From, MCSymbolRefExpr::VK_None, C), + MCSymbolRefExpr::create(To, MCSymbolRefExpr::VK_None, C), Count); + } +} /// getKindForGlobal - This is a top-level target-independent classifier for /// a global object. Given a global variable and information from the TM, this |