Skip to content

Commit e91e508

Browse files
MaskRayyuxuanchen1997
authored andcommitted
[MC] Move LOHContainer to MachObjectwriter
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251228
1 parent 933c35d commit e91e508

File tree

5 files changed

+9
-18
lines changed

5 files changed

+9
-18
lines changed

llvm/include/llvm/MC/MCAssembler.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "llvm/BinaryFormat/MachO.h"
1919
#include "llvm/MC/MCDirectives.h"
2020
#include "llvm/MC/MCDwarf.h"
21-
#include "llvm/MC/MCLinkerOptimizationHint.h"
2221
#include "llvm/MC/MCSymbol.h"
2322
#include "llvm/Support/SMLoc.h"
2423
#include "llvm/Support/VersionTuple.h"
@@ -122,10 +121,6 @@ class MCAssembler {
122121
// which flags to be set.
123122
unsigned ELFHeaderEFlags = 0;
124123

125-
/// Used to communicate Linker Optimization Hint information between
126-
/// the Streamer and the .o writer
127-
MCLOHContainer LOHContainer;
128-
129124
VersionInfoType VersionInfo;
130125
VersionInfoType DarwinTargetVariantVersionInfo;
131126

@@ -341,14 +336,6 @@ class MCAssembler {
341336
return LinkerOptions;
342337
}
343338

344-
// FIXME: This is a total hack, this should not be here. Once things are
345-
// factored so that the streamer has direct access to the .o writer, it can
346-
// disappear.
347-
MCLOHContainer &getLOHContainer() { return LOHContainer; }
348-
const MCLOHContainer &getLOHContainer() const {
349-
return const_cast<MCAssembler *>(this)->getLOHContainer();
350-
}
351-
352339
struct CGProfileEntry {
353340
const MCSymbolRefExpr *From;
354341
const MCSymbolRefExpr *To;

llvm/include/llvm/MC/MCMachObjectWriter.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "llvm/ADT/StringRef.h"
1414
#include "llvm/BinaryFormat/MachO.h"
1515
#include "llvm/MC/MCExpr.h"
16+
#include "llvm/MC/MCLinkerOptimizationHint.h"
1617
#include "llvm/MC/MCObjectWriter.h"
1718
#include "llvm/MC/MCSection.h"
1819
#include "llvm/MC/StringTableBuilder.h"
@@ -140,6 +141,9 @@ class MachObjectWriter : public MCObjectWriter {
140141

141142
/// @}
142143

144+
// Used to communicate Linker Optimization Hint information.
145+
MCLOHContainer LOHContainer;
146+
143147
MachSymbolData *findSymbolData(const MCSymbol &Sym);
144148

145149
void writeWithPadding(StringRef Str, uint64_t Size);
@@ -177,6 +181,7 @@ class MachObjectWriter : public MCObjectWriter {
177181
return SectionOrder;
178182
}
179183
SectionAddrMap &getSectionAddressMap() { return SectionAddress; }
184+
MCLOHContainer &getLOHContainer() { return LOHContainer; }
180185

181186
uint64_t getSectionAddress(const MCSection *Sec) const {
182187
return SectionAddress.lookup(Sec);

llvm/lib/MC/MCAssembler.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ void MCAssembler::reset() {
102102
ThumbFuncs.clear();
103103
BundleAlignSize = 0;
104104
ELFHeaderEFlags = 0;
105-
LOHContainer.reset();
106105
VersionInfo.Major = 0;
107106
VersionInfo.SDKVersion = VersionTuple();
108107
DarwinTargetVariantVersionInfo.Major = 0;
@@ -115,7 +114,6 @@ void MCAssembler::reset() {
115114
getEmitterPtr()->reset();
116115
if (getWriterPtr())
117116
getWriterPtr()->reset();
118-
getLOHContainer().reset();
119117
}
120118

121119
bool MCAssembler::registerSection(MCSection &Section) {

llvm/lib/MC/MCMachOStreamer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class MCMachOStreamer : public MCObjectStreamer {
118118
}
119119

120120
void emitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) override {
121-
getAssembler().getLOHContainer().addDirective(Kind, Args);
121+
getWriter().getLOHContainer().addDirective(Kind, Args);
122122
}
123123
void emitCGProfileEntry(const MCSymbolRefExpr *From,
124124
const MCSymbolRefExpr *To, uint64_t Count) override {

llvm/lib/MC/MachObjectWriter.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ void MachObjectWriter::reset() {
5555
LocalSymbolData.clear();
5656
ExternalSymbolData.clear();
5757
UndefinedSymbolData.clear();
58+
LOHContainer.reset();
5859
MCObjectWriter::reset();
5960
}
6061

@@ -839,7 +840,7 @@ uint64_t MachObjectWriter::writeObject(MCAssembler &Asm) {
839840
}
840841

841842
// Add the loh load command size, if used.
842-
uint64_t LOHRawSize = Asm.getLOHContainer().getEmitSize(Asm, *this);
843+
uint64_t LOHRawSize = LOHContainer.getEmitSize(Asm, *this);
843844
uint64_t LOHSize = alignTo(LOHRawSize, is64Bit() ? 8 : 4);
844845
if (LOHSize) {
845846
++NumLoadCommands;
@@ -1063,7 +1064,7 @@ uint64_t MachObjectWriter::writeObject(MCAssembler &Asm) {
10631064
#ifndef NDEBUG
10641065
unsigned Start = W.OS.tell();
10651066
#endif
1066-
Asm.getLOHContainer().emit(Asm, *this);
1067+
LOHContainer.emit(Asm, *this);
10671068
// Pad to a multiple of the pointer size.
10681069
W.OS.write_zeros(
10691070
offsetToAlignment(LOHRawSize, is64Bit() ? Align(8) : Align(4)));

0 commit comments

Comments
 (0)