Skip to content

Commit a2578e9

Browse files
committed
Revert "Reland [CodeGen] emit CG profile for COFF object file"
This reverts commit 506b617. This still causes link errors, see https://crbug.com/1130780.
1 parent 1598595 commit a2578e9

File tree

5 files changed

+53
-118
lines changed

5 files changed

+53
-118
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
@@ -108,6 +108,7 @@ static void GetObjCImageInfo(Module &M, unsigned &Version, unsigned &Flags,
108108
void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx,
109109
const TargetMachine &TgtM) {
110110
TargetLoweringObjectFile::Initialize(Ctx, TgtM);
111+
TM = &TgtM;
111112

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

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

330370
MCSymbol *TargetLoweringObjectFileELF::getCFIPersonalitySymbol(
@@ -1559,20 +1599,18 @@ void TargetLoweringObjectFileCOFF::emitModuleMetadata(MCStreamer &Streamer,
15591599
StringRef Section;
15601600

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

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

15781616
void TargetLoweringObjectFileCOFF::emitLinkerDirectives(

llvm/lib/Target/TargetLoweringObjectFile.cpp

Lines changed: 0 additions & 48 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,52 +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-
if (F->hasDLLImportStorageClass())
166-
return nullptr;
167-
return TM->getSymbol(F);
168-
};
169-
170-
for (const auto &Edge : CFGProfile->operands()) {
171-
MDNode *E = cast<MDNode>(Edge);
172-
const MCSymbol *From = GetSym(E->getOperand(0));
173-
const MCSymbol *To = GetSym(E->getOperand(1));
174-
// Skip null functions. This can happen if functions are dead stripped after
175-
// the CGProfile pass has been run.
176-
if (!From || !To)
177-
continue;
178-
uint64_t Count = cast<ConstantAsMetadata>(E->getOperand(2))
179-
->getValue()
180-
->getUniqueInteger()
181-
.getZExtValue();
182-
Streamer.emitCGProfileEntry(
183-
MCSymbolRefExpr::create(From, MCSymbolRefExpr::VK_None, C),
184-
MCSymbolRefExpr::create(To, MCSymbolRefExpr::VK_None, C), Count);
185-
}
186-
}
187139

188140
/// getKindForGlobal - This is a top-level target-independent classifier for
189141
/// 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)