diff options
Diffstat (limited to 'llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp')
-rw-r--r-- | llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 86 |
1 files changed, 2 insertions, 84 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 6cbf21d..b4d88fcb 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -114,7 +114,6 @@ TargetLoweringObjectFileELF::TargetLoweringObjectFileELF() void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx, const TargetMachine &TgtM) { TargetLoweringObjectFile::Initialize(Ctx, TgtM); - TM = &TgtM; CodeModel::Model CM = TgtM.getCodeModel(); InitializeELF(TgtM.Options.UseInitArray); @@ -354,46 +353,7 @@ void TargetLoweringObjectFileELF::emitModuleMetadata(MCStreamer &Streamer, Streamer.AddBlankLine(); } - 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()->stripPointerCasts()); - 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); - } + emitCGProfileMetadata(Streamer, M); } MCSymbol *TargetLoweringObjectFileELF::getCFIPersonalitySymbol( @@ -1696,49 +1656,7 @@ void TargetLoweringObjectFileCOFF::emitModuleMetadata(MCStreamer &Streamer, Streamer.AddBlankLine(); } - auto &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()); - if (F->hasDLLImportStorageClass()) - return nullptr; - 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); - } + emitCGProfileMetadata(Streamer, M); } void TargetLoweringObjectFileCOFF::emitLinkerDirectives( |