Skip to content

Commit 57ab708

Browse files
committed
Try to resolve symbol differences early, and if successful create a plain
data fragment. This reduces the time to assemble the test in 8711 from 60s to 54s. llvm-svn: 120767
1 parent f0b36a3 commit 57ab708

14 files changed

+144
-88
lines changed

llvm/include/llvm/MC/MCDwarf.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ namespace llvm {
209209
// This emits the Dwarf file and the line tables.
210210
//
211211
static void Emit(MCStreamer *MCOS, const MCSection *DwarfLineSection,
212-
MCSectionData *DLS, int PointerSize,
213212
const MCSection *TextSection = NULL);
214213
};
215214

llvm/include/llvm/MC/MCExpr.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
namespace llvm {
1717
class MCAsmInfo;
1818
class MCAsmLayout;
19+
class MCAssembler;
1920
class MCContext;
2021
class MCSymbol;
2122
class MCValue;
@@ -43,7 +44,8 @@ class MCExpr {
4344
protected:
4445
explicit MCExpr(ExprKind _Kind) : Kind(_Kind) {}
4546

46-
bool EvaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout,
47+
bool EvaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
48+
const MCAsmLayout *Layout,
4749
bool InSet) const;
4850
public:
4951
/// @name Accessors
@@ -69,7 +71,11 @@ class MCExpr {
6971
/// values. If not given, then only non-symbolic expressions will be
7072
/// evaluated.
7173
/// @result - True on success.
72-
bool EvaluateAsAbsolute(int64_t &Res, const MCAsmLayout *Layout = 0) const;
74+
bool EvaluateAsAbsolute(int64_t &Res) const;
75+
bool EvaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm) const;
76+
bool EvaluateAsAbsolute(int64_t &Res, const MCAsmLayout *Layout) const;
77+
bool EvaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
78+
const MCAsmLayout *Layout) const;
7379

7480
/// EvaluateAsRelocatable - Try to evaluate the expression to a relocatable
7581
/// value, i.e. an expression of the fixed form (a - b + constant).

llvm/include/llvm/MC/MCObjectStreamer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ class MCObjectStreamer : public MCStreamer {
6969
virtual void EmitInstruction(const MCInst &Inst);
7070
virtual void EmitInstToFragment(const MCInst &Inst);
7171
virtual void EmitValueToOffset(const MCExpr *Offset, unsigned char Value);
72+
virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
73+
const MCSymbol *LastLabel,
74+
const MCSymbol *Label);
7275
virtual void Finish();
7376

7477
/// @}

llvm/include/llvm/MC/MCStreamer.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,13 @@ namespace llvm {
351351
unsigned Isa,
352352
unsigned Discriminator);
353353

354+
virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
355+
const MCSymbol *LastLabel,
356+
const MCSymbol *Label) = 0;
357+
358+
void EmitDwarfSetLineAddr(int64_t LineDelta, const MCSymbol *Label,
359+
int PointerSize);
360+
354361
virtual bool EmitCFIStartProc();
355362
virtual bool EmitCFIEndProc();
356363
virtual bool EmitCFIDefCfaOffset(int64_t Offset);

llvm/lib/MC/MCAsmStreamer.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ class MCAsmStreamer : public MCStreamer {
121121

122122
virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
123123
virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
124+
virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
125+
const MCSymbol *LastLabel,
126+
const MCSymbol *Label);
124127

125128
virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute);
126129

@@ -298,6 +301,12 @@ void MCAsmStreamer::EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {
298301
EmitEOL();
299302
}
300303

304+
void MCAsmStreamer::EmitDwarfAdvanceLineAddr(int64_t LineDelta,
305+
const MCSymbol *LastLabel,
306+
const MCSymbol *Label) {
307+
EmitDwarfSetLineAddr(LineDelta, Label, PointerSize);
308+
}
309+
301310
void MCAsmStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
302311
MCSymbolAttr Attribute) {
303312
switch (Attribute) {
@@ -885,10 +894,9 @@ void MCAsmStreamer::EmitRawText(StringRef String) {
885894

886895
void MCAsmStreamer::Finish() {
887896
// Dump out the dwarf file & directory tables and line tables.
888-
if (getContext().hasDwarfFiles() && TLOF) {
889-
MCDwarfFileTable::Emit(this, TLOF->getDwarfLineSection(), NULL,
890-
PointerSize, TLOF->getTextSection());
891-
}
897+
if (getContext().hasDwarfFiles() && TLOF)
898+
MCDwarfFileTable::Emit(this, TLOF->getDwarfLineSection(),
899+
TLOF->getTextSection());
892900
}
893901

894902
MCStreamer *llvm::createAsmStreamer(MCContext &Context,

llvm/lib/MC/MCDwarf.cpp

Lines changed: 5 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -117,31 +117,14 @@ static inline const MCExpr *MakeStartMinusEndExpr(MCStreamer *MCOS,
117117
return Res3;
118118
}
119119

120-
//
121-
// This emits an "absolute" address used in the start of a dwarf line number
122-
// table. This will result in a relocatation entry for the address.
123-
//
124-
static inline void EmitDwarfSetAddress(MCStreamer *MCOS,
125-
MCSymbol *Symbol,
126-
int PointerSize) {
127-
MCOS->EmitIntValue(dwarf::DW_LNS_extended_op, 1);
128-
129-
MCOS->EmitULEB128IntValue(PointerSize + 1);
130-
131-
MCOS->EmitIntValue(dwarf::DW_LNE_set_address, 1);
132-
MCOS->EmitSymbolValue(Symbol, PointerSize);
133-
}
134-
135120
//
136121
// This emits the Dwarf line table for the specified section from the entries
137122
// in the LineSection.
138123
//
139124
static inline void EmitDwarfLineTable(MCStreamer *MCOS,
140125
const MCSection *Section,
141126
const MCLineSection *LineSection,
142-
const MCSection *DwarfLineSection,
143-
MCSectionData *DLS,
144-
int PointerSize) {
127+
const MCSection *DwarfLineSection) {
145128
unsigned FileNum = 1;
146129
unsigned LastLine = 1;
147130
unsigned Column = 0;
@@ -186,19 +169,7 @@ static inline void EmitDwarfLineTable(MCStreamer *MCOS,
186169
// At this point we want to emit/create the sequence to encode the delta in
187170
// line numbers and the increment of the address from the previous Label
188171
// and the current Label.
189-
if (LastLabel == NULL || DLS == NULL) {
190-
// emit the sequence to set the address
191-
EmitDwarfSetAddress(MCOS, Label, PointerSize);
192-
// emit the sequence for the LineDelta (from 1) and a zero address delta.
193-
MCDwarfLineAddr::Emit(MCOS, LineDelta, 0);
194-
}
195-
else {
196-
// Create an expression for the address delta from the LastLabel and
197-
// this Label (plus 0).
198-
const MCExpr *AddrDelta = MakeStartMinusEndExpr(MCOS, LastLabel, Label,0);
199-
// Create a Dwarf Line fragment for the LineDelta and AddrDelta.
200-
new MCDwarfLineAddrFragment(LineDelta, *AddrDelta, DLS);
201-
}
172+
MCOS->EmitDwarfAdvanceLineAddr(LineDelta, LastLabel, Label);
202173

203174
LastLine = it->getLine();
204175
LastLabel = Label;
@@ -220,28 +191,14 @@ static inline void EmitDwarfLineTable(MCStreamer *MCOS,
220191
// Switch back the the dwarf line section.
221192
MCOS->SwitchSection(DwarfLineSection);
222193

223-
if (DLS == NULL) {
224-
// emit the sequence to set the address
225-
EmitDwarfSetAddress(MCOS, SectionEnd, PointerSize);
226-
// emit the sequence for the LineDelta (from 1) and a zero address delta.
227-
MCDwarfLineAddr::Emit(MCOS, INT64_MAX, 0);
228-
} else {
229-
// Create an expression for the address delta from the LastLabel and this
230-
// SectionEnd label.
231-
const MCExpr *AddrDelta = MakeStartMinusEndExpr(MCOS, LastLabel, SectionEnd,
232-
0);
233-
// Create a Dwarf Line fragment for the LineDelta and AddrDelta.
234-
new MCDwarfLineAddrFragment(INT64_MAX, *AddrDelta, DLS);
235-
}
194+
MCOS->EmitDwarfAdvanceLineAddr(INT64_MAX, LastLabel, SectionEnd);
236195
}
237196

238197
//
239198
// This emits the Dwarf file and the line tables.
240199
//
241200
void MCDwarfFileTable::Emit(MCStreamer *MCOS,
242201
const MCSection *DwarfLineSection,
243-
MCSectionData *DLS,
244-
int PointerSize,
245202
const MCSection *TextSection) {
246203
// Switch to the section where the table will be emitted into.
247204
MCOS->SwitchSection(DwarfLineSection);
@@ -332,8 +289,7 @@ void MCDwarfFileTable::Emit(MCStreamer *MCOS,
332289
++it) {
333290
const MCSection *Sec = *it;
334291
const MCLineSection *Line = MCLineSections.lookup(Sec);
335-
EmitDwarfLineTable(MCOS, Sec, Line, DwarfLineSection, DLS,
336-
PointerSize);
292+
EmitDwarfLineTable(MCOS, Sec, Line, DwarfLineSection);
337293

338294
// Now delete the MCLineSections that were created in MCLineEntry::Make()
339295
// and used to emit the line table.
@@ -351,10 +307,7 @@ void MCDwarfFileTable::Emit(MCStreamer *MCOS,
351307
// Switch back the the dwarf line section.
352308
MCOS->SwitchSection(DwarfLineSection);
353309

354-
// emit the sequence to set the address
355-
EmitDwarfSetAddress(MCOS, SectionEnd, PointerSize);
356-
// emit the sequence for the LineDelta (from 1) and a zero address delta.
357-
MCDwarfLineAddr::Emit(MCOS, INT64_MAX, 0);
310+
MCOS->EmitDwarfAdvanceLineAddr(INT64_MAX, NULL, SectionEnd);
358311
}
359312

360313
// This is the end of the section, so set the value of the symbol at the end

llvm/lib/MC/MCELFStreamer.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,10 +484,7 @@ void MCELFStreamer::Finish() {
484484
const MCSection *DwarfLineSection =
485485
getContext().getELFSection(".debug_line", 0, 0,
486486
SectionKind::getDataRelLocal());
487-
MCSectionData &DLS =
488-
getAssembler().getOrCreateSectionData(*DwarfLineSection);
489-
int PointerSize = getAssembler().getBackend().getPointerSize();
490-
MCDwarfFileTable::Emit(this, DwarfLineSection, &DLS, PointerSize);
487+
MCDwarfFileTable::Emit(this, DwarfLineSection);
491488
}
492489

493490
for (std::vector<LocalCommon>::const_iterator i = LocalCommons.begin(),

llvm/lib/MC/MCExpr.cpp

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,24 @@ void MCTargetExpr::Anchor() {}
237237

238238
/* *** */
239239

240-
bool MCExpr::EvaluateAsAbsolute(int64_t &Res, const MCAsmLayout *Layout) const {
240+
bool MCExpr::EvaluateAsAbsolute(int64_t &Res) const {
241+
return EvaluateAsAbsolute(Res, 0, 0);
242+
}
243+
244+
bool MCExpr::EvaluateAsAbsolute(int64_t &Res,
245+
const MCAsmLayout *Layout) const {
246+
if (Layout)
247+
return EvaluateAsAbsolute(Res, &Layout->getAssembler(), Layout);
248+
else
249+
return EvaluateAsAbsolute(Res, 0, 0);
250+
}
251+
252+
bool MCExpr::EvaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm) const {
253+
return EvaluateAsAbsolute(Res, Asm, 0);
254+
}
255+
256+
bool MCExpr::EvaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
257+
const MCAsmLayout *Layout) const {
241258
MCValue Value;
242259

243260
// Fast path constants.
@@ -246,7 +263,8 @@ bool MCExpr::EvaluateAsAbsolute(int64_t &Res, const MCAsmLayout *Layout) const {
246263
return true;
247264
}
248265

249-
if (!EvaluateAsRelocatable(Value, Layout) || !Value.isAbsolute()) {
266+
if (!EvaluateAsRelocatableImpl(Value, Asm, Layout, false) ||
267+
!Value.isAbsolute()) {
250268
// EvaluateAsAbsolute is defined to return the "current value" of
251269
// the expression if we are given a Layout object, even in cases
252270
// when the value is not fixed.
@@ -268,7 +286,9 @@ bool MCExpr::EvaluateAsAbsolute(int64_t &Res, const MCAsmLayout *Layout) const {
268286
return true;
269287
}
270288

271-
static bool EvaluateSymbolicAdd(const MCAsmLayout *Layout, bool InSet,
289+
static bool EvaluateSymbolicAdd(const MCAsmLayout *Layout,
290+
const MCAssembler *Asm,
291+
bool InSet,
272292
const MCValue &LHS,const MCSymbolRefExpr *RHS_A,
273293
const MCSymbolRefExpr *RHS_B, int64_t RHS_Cst,
274294
MCValue &Res) {
@@ -291,14 +311,15 @@ static bool EvaluateSymbolicAdd(const MCAsmLayout *Layout, bool InSet,
291311
// Absolutize symbol differences between defined symbols when we have a
292312
// layout object and the target requests it.
293313

294-
if (Layout && A && B) {
314+
assert(!(Layout && !Asm));
315+
316+
if ((Layout || Asm) && A && B) {
295317
const MCSymbol &SA = A->getSymbol();
296318
const MCSymbol &SB = B->getSymbol();
297-
const MCAssembler &Asm = Layout->getAssembler();
298-
const MCObjectFormat &F = Asm.getBackend().getObjectFormat();
319+
const MCObjectFormat &F = Asm->getBackend().getObjectFormat();
299320
if (SA.isDefined() && SB.isDefined() && F.isAbsolute(InSet, SA, SB)) {
300-
MCSymbolData &AD = Asm.getSymbolData(A->getSymbol());
301-
MCSymbolData &BD = Asm.getSymbolData(B->getSymbol());
321+
MCSymbolData &AD = Asm->getSymbolData(A->getSymbol());
322+
MCSymbolData &BD = Asm->getSymbolData(B->getSymbol());
302323

303324
if (AD.getFragment() == BD.getFragment()) {
304325
Res = MCValue::get(+ AD.getOffset()
@@ -308,25 +329,31 @@ static bool EvaluateSymbolicAdd(const MCAsmLayout *Layout, bool InSet,
308329
return true;
309330
}
310331

311-
Res = MCValue::get(+ Layout->getSymbolAddress(&AD)
312-
- Layout->getSymbolAddress(&BD)
313-
+ LHS.getConstant()
314-
+ RHS_Cst);
315-
return true;
332+
if (Layout) {
333+
Res = MCValue::get(+ Layout->getSymbolAddress(&AD)
334+
- Layout->getSymbolAddress(&BD)
335+
+ LHS.getConstant()
336+
+ RHS_Cst);
337+
return true;
338+
}
316339
}
317340
}
318341

319-
320342
Res = MCValue::get(A, B, LHS.getConstant() + RHS_Cst);
321343
return true;
322344
}
323345

324346
bool MCExpr::EvaluateAsRelocatable(MCValue &Res,
325347
const MCAsmLayout *Layout) const {
326-
return EvaluateAsRelocatableImpl(Res, Layout, false);
348+
if (Layout)
349+
return EvaluateAsRelocatableImpl(Res, &Layout->getAssembler(), Layout,
350+
false);
351+
else
352+
return EvaluateAsRelocatableImpl(Res, 0, 0, false);
327353
}
328354

329355
bool MCExpr::EvaluateAsRelocatableImpl(MCValue &Res,
356+
const MCAssembler *Asm,
330357
const MCAsmLayout *Layout,
331358
bool InSet) const {
332359
++stats::MCExprEvaluate;
@@ -345,7 +372,8 @@ bool MCExpr::EvaluateAsRelocatableImpl(MCValue &Res,
345372

346373
// Evaluate recursively if this is a variable.
347374
if (Sym.isVariable() && SRE->getKind() == MCSymbolRefExpr::VK_None) {
348-
bool Ret = Sym.getVariableValue()->EvaluateAsRelocatableImpl(Res, Layout,
375+
bool Ret = Sym.getVariableValue()->EvaluateAsRelocatableImpl(Res, Asm,
376+
Layout,
349377
true);
350378
// If we failed to simplify this to a constant, let the target
351379
// handle it.
@@ -361,7 +389,8 @@ bool MCExpr::EvaluateAsRelocatableImpl(MCValue &Res,
361389
const MCUnaryExpr *AUE = cast<MCUnaryExpr>(this);
362390
MCValue Value;
363391

364-
if (!AUE->getSubExpr()->EvaluateAsRelocatableImpl(Value, Layout, InSet))
392+
if (!AUE->getSubExpr()->EvaluateAsRelocatableImpl(Value, Asm, Layout,
393+
InSet))
365394
return false;
366395

367396
switch (AUE->getOpcode()) {
@@ -394,8 +423,10 @@ bool MCExpr::EvaluateAsRelocatableImpl(MCValue &Res,
394423
const MCBinaryExpr *ABE = cast<MCBinaryExpr>(this);
395424
MCValue LHSValue, RHSValue;
396425

397-
if (!ABE->getLHS()->EvaluateAsRelocatableImpl(LHSValue, Layout, InSet) ||
398-
!ABE->getRHS()->EvaluateAsRelocatableImpl(RHSValue, Layout, InSet))
426+
if (!ABE->getLHS()->EvaluateAsRelocatableImpl(LHSValue, Asm, Layout,
427+
InSet) ||
428+
!ABE->getRHS()->EvaluateAsRelocatableImpl(RHSValue, Asm, Layout,
429+
InSet))
399430
return false;
400431

401432
// We only support a few operations on non-constant expressions, handle
@@ -406,13 +437,13 @@ bool MCExpr::EvaluateAsRelocatableImpl(MCValue &Res,
406437
return false;
407438
case MCBinaryExpr::Sub:
408439
// Negate RHS and add.
409-
return EvaluateSymbolicAdd(Layout, InSet, LHSValue,
440+
return EvaluateSymbolicAdd(Layout, Asm, InSet, LHSValue,
410441
RHSValue.getSymB(), RHSValue.getSymA(),
411442
-RHSValue.getConstant(),
412443
Res);
413444

414445
case MCBinaryExpr::Add:
415-
return EvaluateSymbolicAdd(Layout, InSet, LHSValue,
446+
return EvaluateSymbolicAdd(Layout, Asm, InSet, LHSValue,
416447
RHSValue.getSymA(), RHSValue.getSymB(),
417448
RHSValue.getConstant(),
418449
Res);

llvm/lib/MC/MCLoggingStreamer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ class MCLoggingStreamer : public MCStreamer {
8484
return Child->EmitWeakReference(Alias, Symbol);
8585
}
8686

87+
virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
88+
const MCSymbol *LastLabel,
89+
const MCSymbol *Label) {
90+
LogCall("EmitDwarfAdvanceLineAddr");
91+
return Child->EmitDwarfAdvanceLineAddr(LineDelta, LastLabel, Label);
92+
}
93+
8794
virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) {
8895
LogCall("EmitSymbolAttribute");
8996
return Child->EmitSymbolAttribute(Symbol, Attribute);

llvm/lib/MC/MCMachOStreamer.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,7 @@ void MCMachOStreamer::Finish() {
357357
"__debug_line",
358358
MCSectionMachO::S_ATTR_DEBUG,
359359
0, SectionKind::getDataRelLocal());
360-
MCSectionData &DLS =
361-
getAssembler().getOrCreateSectionData(*DwarfLineSection);
362-
int PointerSize = getAssembler().getBackend().getPointerSize();
363-
MCDwarfFileTable::Emit(this, DwarfLineSection, &DLS, PointerSize);
360+
MCDwarfFileTable::Emit(this, DwarfLineSection);
364361
}
365362

366363
// We have to set the fragment atom associations so we can relax properly for

0 commit comments

Comments
 (0)