Skip to content

Commit e826b2e

Browse files
MaskRayyuxuanchen1997
authored andcommitted
MCAssembler: Move CGProfile to MCObjectWriter
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251155
1 parent 44fda99 commit e826b2e

File tree

8 files changed

+29
-32
lines changed

8 files changed

+29
-32
lines changed

llvm/include/llvm/MC/MCAssembler.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -236,24 +236,10 @@ class MCAssembler {
236236
return make_pointee_range(Symbols);
237237
}
238238

239-
/// @}
240-
/// \name Linker Option List Access
241-
/// @{
242-
243239
std::vector<std::vector<std::string>> &getLinkerOptions() {
244240
return LinkerOptions;
245241
}
246242

247-
struct CGProfileEntry {
248-
const MCSymbolRefExpr *From;
249-
const MCSymbolRefExpr *To;
250-
uint64_t Count;
251-
};
252-
std::vector<CGProfileEntry> CGProfile;
253-
/// @}
254-
/// \name Backend Data Access
255-
/// @{
256-
257243
bool registerSection(MCSection &Section);
258244
bool registerSymbol(const MCSymbol &Symbol);
259245

@@ -262,8 +248,6 @@ class MCAssembler {
262248
void writeFragmentPadding(raw_ostream &OS, const MCEncodedFragment &F,
263249
uint64_t FSize) const;
264250

265-
/// @}
266-
267251
void dump() const;
268252
};
269253

llvm/include/llvm/MC/MCObjectWriter.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ class MCObjectWriter {
3939
std::vector<const MCSymbol *> AddrsigSyms;
4040
bool EmitAddrsigSection = false;
4141

42+
struct CGProfileEntry {
43+
const MCSymbolRefExpr *From;
44+
const MCSymbolRefExpr *To;
45+
uint64_t Count;
46+
};
47+
SmallVector<CGProfileEntry, 0> CGProfile;
48+
4249
MCObjectWriter() = default;
4350

4451
public:
@@ -105,6 +112,7 @@ class MCObjectWriter {
105112
void addAddrsigSymbol(const MCSymbol *Sym) { AddrsigSyms.push_back(Sym); }
106113

107114
std::vector<const MCSymbol *> &getAddrsigSyms() { return AddrsigSyms; }
115+
SmallVector<CGProfileEntry, 0> &getCGProfile() { return CGProfile; }
108116

109117
/// Write the object file and returns the number of bytes written.
110118
///

llvm/lib/MC/MCELFStreamer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ void MCELFStreamer::emitValueToAlignment(Align Alignment, int64_t Value,
347347
void MCELFStreamer::emitCGProfileEntry(const MCSymbolRefExpr *From,
348348
const MCSymbolRefExpr *To,
349349
uint64_t Count) {
350-
getAssembler().CGProfile.push_back({From, To, Count});
350+
getWriter().getCGProfile().push_back({From, To, Count});
351351
}
352352

353353
void MCELFStreamer::emitIdent(StringRef IdentString) {
@@ -476,16 +476,16 @@ void MCELFStreamer::finalizeCGProfileEntry(const MCSymbolRefExpr *&SRE,
476476
}
477477

478478
void MCELFStreamer::finalizeCGProfile() {
479-
MCAssembler &Asm = getAssembler();
480-
if (Asm.CGProfile.empty())
479+
ELFObjectWriter &W = getWriter();
480+
if (W.getCGProfile().empty())
481481
return;
482482
MCSection *CGProfile = getAssembler().getContext().getELFSection(
483483
".llvm.call-graph-profile", ELF::SHT_LLVM_CALL_GRAPH_PROFILE,
484484
ELF::SHF_EXCLUDE, /*sizeof(Elf_CGProfile_Impl<>)=*/8);
485485
pushSection();
486486
switchSection(CGProfile);
487487
uint64_t Offset = 0;
488-
for (MCAssembler::CGProfileEntry &E : Asm.CGProfile) {
488+
for (auto &E : W.getCGProfile()) {
489489
finalizeCGProfileEntry(E.From, Offset);
490490
finalizeCGProfileEntry(E.To, Offset);
491491
emitIntValue(E.Count, sizeof(uint64_t));

llvm/lib/MC/MCMachOStreamer.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class MCMachOStreamer : public MCObjectStreamer {
123123
void emitCGProfileEntry(const MCSymbolRefExpr *From,
124124
const MCSymbolRefExpr *To, uint64_t Count) override {
125125
if (!From->getSymbol().isTemporary() && !To->getSymbol().isTemporary())
126-
getAssembler().CGProfile.push_back({From, To, Count});
126+
getWriter().getCGProfile().push_back({From, To, Count});
127127
}
128128

129129
void finishImpl() override;
@@ -506,9 +506,10 @@ void MCMachOStreamer::finalizeCGProfileEntry(const MCSymbolRefExpr *&SRE) {
506506

507507
void MCMachOStreamer::finalizeCGProfile() {
508508
MCAssembler &Asm = getAssembler();
509-
if (Asm.CGProfile.empty())
509+
MCObjectWriter &W = getWriter();
510+
if (W.getCGProfile().empty())
510511
return;
511-
for (MCAssembler::CGProfileEntry &E : Asm.CGProfile) {
512+
for (auto &E : W.getCGProfile()) {
512513
finalizeCGProfileEntry(E.From);
513514
finalizeCGProfileEntry(E.To);
514515
}
@@ -520,7 +521,7 @@ void MCMachOStreamer::finalizeCGProfile() {
520521
changeSection(CGProfileSection);
521522
// For each entry, reserve space for 2 32-bit indices and a 64-bit count.
522523
size_t SectionBytes =
523-
Asm.CGProfile.size() * (2 * sizeof(uint32_t) + sizeof(uint64_t));
524+
W.getCGProfile().size() * (2 * sizeof(uint32_t) + sizeof(uint64_t));
524525
cast<MCDataFragment>(*CGProfileSection->begin())
525526
.getContents()
526527
.resize(SectionBytes);

llvm/lib/MC/MCObjectWriter.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ using namespace llvm;
1919

2020
MCObjectWriter::~MCObjectWriter() = default;
2121

22-
void MCObjectWriter::reset() { FileNames.clear(); }
22+
void MCObjectWriter::reset() {
23+
FileNames.clear();
24+
AddrsigSyms.clear();
25+
CGProfile.clear();
26+
}
2327

2428
bool MCObjectWriter::isSymbolRefDifferenceFullyResolved(
2529
const MCAssembler &Asm, const MCSymbolRefExpr *A, const MCSymbolRefExpr *B,

llvm/lib/MC/MCWinCOFFStreamer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ void MCWinCOFFStreamer::emitCGProfileEntry(const MCSymbolRefExpr *From,
360360
uint64_t Count) {
361361
// Ignore temporary symbols for now.
362362
if (!From->getSymbol().isTemporary() && !To->getSymbol().isTemporary())
363-
getAssembler().CGProfile.push_back({From, To, Count});
363+
getWriter().getCGProfile().push_back({From, To, Count});
364364
}
365365

366366
void MCWinCOFFStreamer::finalizeCGProfileEntry(const MCSymbolRefExpr *&SRE) {
@@ -376,8 +376,8 @@ void MCWinCOFFStreamer::finishImpl() {
376376
switchSection(Asm.getContext().getCOFFSection(".llvm_addrsig",
377377
COFF::IMAGE_SCN_LNK_REMOVE));
378378
}
379-
if (!Asm.CGProfile.empty()) {
380-
for (MCAssembler::CGProfileEntry &E : Asm.CGProfile) {
379+
if (!Asm.getWriter().getCGProfile().empty()) {
380+
for (auto &E : Asm.getWriter().getCGProfile()) {
381381
finalizeCGProfileEntry(E.From);
382382
finalizeCGProfileEntry(E.To);
383383
}

llvm/lib/MC/MachObjectWriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,13 +791,13 @@ uint64_t MachObjectWriter::writeObject(MCAssembler &Asm) {
791791
computeSymbolTable(Asm, LocalSymbolData, ExternalSymbolData,
792792
UndefinedSymbolData);
793793

794-
if (!Asm.CGProfile.empty()) {
794+
if (!CGProfile.empty()) {
795795
MCSection *CGProfileSection = Asm.getContext().getMachOSection(
796796
"__LLVM", "__cg_profile", 0, SectionKind::getMetadata());
797797
auto &Frag = cast<MCDataFragment>(*CGProfileSection->begin());
798798
Frag.getContents().clear();
799799
raw_svector_ostream OS(Frag.getContents());
800-
for (const MCAssembler::CGProfileEntry &CGPE : Asm.CGProfile) {
800+
for (const MCObjectWriter::CGProfileEntry &CGPE : CGProfile) {
801801
uint32_t FromIndex = CGPE.From->getSymbol().getIndex();
802802
uint32_t ToIndex = CGPE.To->getSymbol().getIndex();
803803
support::endian::write(OS, FromIndex, W.Endian);

llvm/lib/MC/WinCOFFObjectWriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,12 +1084,12 @@ uint64_t WinCOFFWriter::writeObject(MCAssembler &Asm) {
10841084
}
10851085

10861086
// Create the contents of the .llvm.call-graph-profile section.
1087-
if (Mode != DwoOnly && !Asm.CGProfile.empty()) {
1087+
if (Mode != DwoOnly && !OWriter.getCGProfile().empty()) {
10881088
auto *Sec = Asm.getContext().getCOFFSection(
10891089
".llvm.call-graph-profile", COFF::IMAGE_SCN_LNK_REMOVE);
10901090
auto *Frag = cast<MCDataFragment>(Sec->curFragList()->Head);
10911091
raw_svector_ostream OS(Frag->getContents());
1092-
for (const MCAssembler::CGProfileEntry &CGPE : Asm.CGProfile) {
1092+
for (const auto &CGPE : OWriter.getCGProfile()) {
10931093
uint32_t FromIndex = CGPE.From->getSymbol().getIndex();
10941094
uint32_t ToIndex = CGPE.To->getSymbol().getIndex();
10951095
support::endian::write(OS, FromIndex, W.Endian);

0 commit comments

Comments
 (0)