Skip to content

Commit

Permalink
Revert "Reland [CodeGen] emit CG profile for COFF object file"
Browse files Browse the repository at this point in the history
This reverts commit 506b617.

This still causes link errors, see https://crbug.com/1130780.
  • Loading branch information
aeubanks committed Sep 28, 2020
1 parent 1598595 commit a2578e9
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 118 deletions.
1 change: 1 addition & 0 deletions llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
Expand Up @@ -35,6 +35,7 @@ class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
protected:
MCSymbolRefExpr::VariantKind PLTRelativeVariantKind =
MCSymbolRefExpr::VK_None;
const TargetMachine *TM = nullptr;

public:
TargetLoweringObjectFileELF() = default;
Expand Down
5 changes: 0 additions & 5 deletions llvm/include/llvm/Target/TargetLoweringObjectFile.h
Expand Up @@ -61,8 +61,6 @@ class TargetLoweringObjectFile : public MCObjectFileInfo {
/// This section contains the static destructor pointer list.
MCSection *StaticDtorSection = nullptr;

const TargetMachine *TM = nullptr;

public:
TargetLoweringObjectFile() = default;
TargetLoweringObjectFile(const TargetLoweringObjectFile &) = delete;
Expand All @@ -83,9 +81,6 @@ class TargetLoweringObjectFile : public MCObjectFileInfo {
/// Emit the module-level metadata that the platform cares about.
virtual void emitModuleMetadata(MCStreamer &Streamer, Module &M) const {}

/// Emit Call Graph Profile metadata.
virtual void emitCGProfile(MCStreamer &Streamer, Module &M) const;

/// Get the module-level metadata that the platform cares about.
virtual void getModuleMetadata(Module &M) {}

Expand Down
66 changes: 52 additions & 14 deletions llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
Expand Up @@ -108,6 +108,7 @@ static void GetObjCImageInfo(Module &M, unsigned &Version, unsigned &Flags,
void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx,
const TargetMachine &TgtM) {
TargetLoweringObjectFile::Initialize(Ctx, TgtM);
TM = &TgtM;

CodeModel::Model CM = TgtM.getCodeModel();
InitializeELF(TgtM.Options.UseInitArray);
Expand Down Expand Up @@ -324,7 +325,46 @@ void TargetLoweringObjectFileELF::emitModuleMetadata(MCStreamer &Streamer,
Streamer.AddBlankLine();
}

emitCGProfile(Streamer, M);
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);
}
}

MCSymbol *TargetLoweringObjectFileELF::getCFIPersonalitySymbol(
Expand Down Expand Up @@ -1559,20 +1599,18 @@ void TargetLoweringObjectFileCOFF::emitModuleMetadata(MCStreamer &Streamer,
StringRef Section;

GetObjCImageInfo(M, Version, Flags, Section);
if (!Section.empty()) {
auto &C = getContext();
auto *S = C.getCOFFSection(Section,
COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getReadOnly());
Streamer.SwitchSection(S);
Streamer.emitLabel(C.getOrCreateSymbol(StringRef("OBJC_IMAGE_INFO")));
Streamer.emitInt32(Version);
Streamer.emitInt32(Flags);
Streamer.AddBlankLine();
}
if (Section.empty())
return;

emitCGProfile(Streamer, M);
auto &C = getContext();
auto *S = C.getCOFFSection(
Section, COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
SectionKind::getReadOnly());
Streamer.SwitchSection(S);
Streamer.emitLabel(C.getOrCreateSymbol(StringRef("OBJC_IMAGE_INFO")));
Streamer.emitInt32(Version);
Streamer.emitInt32(Flags);
Streamer.AddBlankLine();
}

void TargetLoweringObjectFileCOFF::emitLinkerDirectives(
Expand Down
48 changes: 0 additions & 48 deletions llvm/lib/Target/TargetLoweringObjectFile.cpp
Expand Up @@ -49,8 +49,6 @@ 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() {
Expand Down Expand Up @@ -138,52 +136,6 @@ 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());
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);
}
}

/// getKindForGlobal - This is a top-level target-independent classifier for
/// a global object. Given a global variable and information from the TM, this
Expand Down
51 changes: 0 additions & 51 deletions llvm/test/MC/COFF/cgprofile.ll

This file was deleted.

0 comments on commit a2578e9

Please sign in to comment.