Skip to content

Commit 90242ca

Browse files
committed
Revert "[CodeGen] emit CG profile for COFF object file"
This reverts commit 91aed9b, it is causing link errors.
1 parent 89c1e35 commit 90242ca

File tree

5 files changed

+53
-116
lines changed

5 files changed

+53
-116
lines changed

llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
3535
protected:
3636
MCSymbolRefExpr::VariantKind PLTRelativeVariantKind =
3737
MCSymbolRefExpr::VK_None;
38+
const TargetMachine *TM = nullptr;
3839

3940
public:
4041
TargetLoweringObjectFileELF() = default;

llvm/include/llvm/Target/TargetLoweringObjectFile.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ class TargetLoweringObjectFile : public MCObjectFileInfo {
6161
/// This section contains the static destructor pointer list.
6262
MCSection *StaticDtorSection = nullptr;
6363

64-
const TargetMachine *TM = nullptr;
65-
6664
public:
6765
TargetLoweringObjectFile() = default;
6866
TargetLoweringObjectFile(const TargetLoweringObjectFile &) = delete;
@@ -83,9 +81,6 @@ class TargetLoweringObjectFile : public MCObjectFileInfo {
8381
/// Emit the module-level metadata that the platform cares about.
8482
virtual void emitModuleMetadata(MCStreamer &Streamer, Module &M) const {}
8583

86-
/// Emit Call Graph Profile metadata.
87-
virtual void emitCGProfile(MCStreamer &Streamer, Module &M) const;
88-
8984
/// Get the module-level metadata that the platform cares about.
9085
virtual void getModuleMetadata(Module &M) {}
9186

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ static void GetObjCImageInfo(Module &M, unsigned &Version, unsigned &Flags,
107107
void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx,
108108
const TargetMachine &TgtM) {
109109
TargetLoweringObjectFile::Initialize(Ctx, TgtM);
110+
TM = &TgtM;
110111

111112
CodeModel::Model CM = TgtM.getCodeModel();
112113
InitializeELF(TgtM.Options.UseInitArray);
@@ -323,7 +324,46 @@ void TargetLoweringObjectFileELF::emitModuleMetadata(MCStreamer &Streamer,
323324
Streamer.AddBlankLine();
324325
}
325326

326-
emitCGProfile(Streamer, M);
327+
SmallVector<Module::ModuleFlagEntry, 8> ModuleFlags;
328+
M.getModuleFlagsMetadata(ModuleFlags);
329+
330+
MDNode *CFGProfile = nullptr;
331+
332+
for (const auto &MFE : ModuleFlags) {
333+
StringRef Key = MFE.Key->getString();
334+
if (Key == "CG Profile") {
335+
CFGProfile = cast<MDNode>(MFE.Val);
336+
break;
337+
}
338+
}
339+
340+
if (!CFGProfile)
341+
return;
342+
343+
auto GetSym = [this](const MDOperand &MDO) -> MCSymbol * {
344+
if (!MDO)
345+
return nullptr;
346+
auto V = cast<ValueAsMetadata>(MDO);
347+
const Function *F = cast<Function>(V->getValue());
348+
return TM->getSymbol(F);
349+
};
350+
351+
for (const auto &Edge : CFGProfile->operands()) {
352+
MDNode *E = cast<MDNode>(Edge);
353+
const MCSymbol *From = GetSym(E->getOperand(0));
354+
const MCSymbol *To = GetSym(E->getOperand(1));
355+
// Skip null functions. This can happen if functions are dead stripped after
356+
// the CGProfile pass has been run.
357+
if (!From || !To)
358+
continue;
359+
uint64_t Count = cast<ConstantAsMetadata>(E->getOperand(2))
360+
->getValue()
361+
->getUniqueInteger()
362+
.getZExtValue();
363+
Streamer.emitCGProfileEntry(
364+
MCSymbolRefExpr::create(From, MCSymbolRefExpr::VK_None, C),
365+
MCSymbolRefExpr::create(To, MCSymbolRefExpr::VK_None, C), Count);
366+
}
327367
}
328368

329369
MCSymbol *TargetLoweringObjectFileELF::getCFIPersonalitySymbol(
@@ -1558,20 +1598,18 @@ void TargetLoweringObjectFileCOFF::emitModuleMetadata(MCStreamer &Streamer,
15581598
StringRef Section;
15591599

15601600
GetObjCImageInfo(M, Version, Flags, Section);
1561-
if (!Section.empty()) {
1562-
auto &C = getContext();
1563-
auto *S = C.getCOFFSection(Section,
1564-
COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
1565-
COFF::IMAGE_SCN_MEM_READ,
1566-
SectionKind::getReadOnly());
1567-
Streamer.SwitchSection(S);
1568-
Streamer.emitLabel(C.getOrCreateSymbol(StringRef("OBJC_IMAGE_INFO")));
1569-
Streamer.emitInt32(Version);
1570-
Streamer.emitInt32(Flags);
1571-
Streamer.AddBlankLine();
1572-
}
1601+
if (Section.empty())
1602+
return;
15731603

1574-
emitCGProfile(Streamer, M);
1604+
auto &C = getContext();
1605+
auto *S = C.getCOFFSection(
1606+
Section, COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
1607+
SectionKind::getReadOnly());
1608+
Streamer.SwitchSection(S);
1609+
Streamer.emitLabel(C.getOrCreateSymbol(StringRef("OBJC_IMAGE_INFO")));
1610+
Streamer.emitInt32(Version);
1611+
Streamer.emitInt32(Flags);
1612+
Streamer.AddBlankLine();
15751613
}
15761614

15771615
void TargetLoweringObjectFileCOFF::emitLinkerDirectives(

llvm/lib/Target/TargetLoweringObjectFile.cpp

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ void TargetLoweringObjectFile::Initialize(MCContext &ctx,
4949
// Reset various EH DWARF encodings.
5050
PersonalityEncoding = LSDAEncoding = TTypeEncoding = dwarf::DW_EH_PE_absptr;
5151
CallSiteEncoding = dwarf::DW_EH_PE_uleb128;
52-
53-
this->TM = &TM;
5452
}
5553

5654
TargetLoweringObjectFile::~TargetLoweringObjectFile() {
@@ -138,50 +136,6 @@ void TargetLoweringObjectFile::emitPersonalityValue(MCStreamer &Streamer,
138136
const MCSymbol *Sym) const {
139137
}
140138

141-
void TargetLoweringObjectFile::emitCGProfile(MCStreamer &Streamer,
142-
Module &M) const {
143-
MCContext &C = getContext();
144-
SmallVector<Module::ModuleFlagEntry, 8> ModuleFlags;
145-
M.getModuleFlagsMetadata(ModuleFlags);
146-
147-
MDNode *CFGProfile = nullptr;
148-
149-
for (const auto &MFE : ModuleFlags) {
150-
StringRef Key = MFE.Key->getString();
151-
if (Key == "CG Profile") {
152-
CFGProfile = cast<MDNode>(MFE.Val);
153-
break;
154-
}
155-
}
156-
157-
if (!CFGProfile)
158-
return;
159-
160-
auto GetSym = [this](const MDOperand &MDO) -> MCSymbol * {
161-
if (!MDO)
162-
return nullptr;
163-
auto *V = cast<ValueAsMetadata>(MDO);
164-
const Function *F = cast<Function>(V->getValue());
165-
return TM->getSymbol(F);
166-
};
167-
168-
for (const auto &Edge : CFGProfile->operands()) {
169-
MDNode *E = cast<MDNode>(Edge);
170-
const MCSymbol *From = GetSym(E->getOperand(0));
171-
const MCSymbol *To = GetSym(E->getOperand(1));
172-
// Skip null functions. This can happen if functions are dead stripped after
173-
// the CGProfile pass has been run.
174-
if (!From || !To)
175-
continue;
176-
uint64_t Count = cast<ConstantAsMetadata>(E->getOperand(2))
177-
->getValue()
178-
->getUniqueInteger()
179-
.getZExtValue();
180-
Streamer.emitCGProfileEntry(
181-
MCSymbolRefExpr::create(From, MCSymbolRefExpr::VK_None, C),
182-
MCSymbolRefExpr::create(To, MCSymbolRefExpr::VK_None, C), Count);
183-
}
184-
}
185139

186140
/// getKindForGlobal - This is a top-level target-independent classifier for
187141
/// a global object. Given a global variable and information from the TM, this

llvm/test/MC/COFF/cgprofile.ll

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)