Skip to content

Commit 997717a

Browse files
committed
Move the implementation logic to AsmPrinter.
1 parent f473eb5 commit 997717a

File tree

4 files changed

+26
-30
lines changed

4 files changed

+26
-30
lines changed

llvm/include/llvm/CodeGen/AsmPrinter.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ class LLVM_ABI AsmPrinter : public MachineFunctionPass {
135135
/// default, this is equal to CurrentFnSym.
136136
MCSymbol *CurrentFnSymForSize = nullptr;
137137

138+
/// Vector of symbols marking the position of callsites in each basic block.
139+
/// The callsite symbols of each block are stored in the order they appear
140+
/// in that block.
141+
DenseMap<const MachineBasicBlock *, SmallVector<MCSymbol *, 1>>
142+
CurrentFnCallsiteSymbols;
143+
138144
/// Provides the profile information for constants.
139145
const StaticDataProfileInfo *SDPI = nullptr;
140146

@@ -295,6 +301,10 @@ class LLVM_ABI AsmPrinter : public MachineFunctionPass {
295301
/// to emit them as well, return the whole set.
296302
ArrayRef<MCSymbol *> getAddrLabelSymbolToEmit(const BasicBlock *BB);
297303

304+
/// Creates a new symbol to be used for the beginning of a callsite at th
305+
/// specified basic block.
306+
MCSymbol *createCallsiteSymbol(const MachineBasicBlock &MBB);
307+
298308
/// If the specified function has had any references to address-taken blocks
299309
/// generated, but the block got deleted, return the symbol now so we can
300310
/// emit it. This prevents emitting a reference to a symbol that has no
@@ -426,7 +436,7 @@ class LLVM_ABI AsmPrinter : public MachineFunctionPass {
426436

427437
void emitStackUsage(const MachineFunction &MF);
428438

429-
void emitBBAddrMapSection(const MachineFunction &MF, bool HasCalls);
439+
void emitBBAddrMapSection(const MachineFunction &MF);
430440

431441
void emitKCFITrapEntry(const MachineFunction &MF, const MCSymbol *Symbol);
432442
virtual void emitKCFITypeId(const MachineFunction &MF);

llvm/include/llvm/CodeGen/MachineBasicBlock.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,6 @@ class MachineBasicBlock
242242
/// calculate the size of the basic block, or the BB section ending with it.
243243
mutable MCSymbol *CachedEndMCSymbol = nullptr;
244244

245-
/// Vector of symbols marking the position of callsites in the basic
246-
/// block, stored in the order they appear in the basic block.
247-
mutable SmallVector<MCSymbol *, 1> CallsiteSymbols;
248-
249245
// Intrusive list support
250246
MachineBasicBlock() = default;
251247

@@ -329,12 +325,6 @@ class MachineBasicBlock
329325
/// its label be emitted.
330326
void setLabelMustBeEmitted() { LabelMustBeEmitted = true; }
331327

332-
/// Returns the symbols marking callsites in the order they appear in the
333-
/// basic block.
334-
const SmallVectorImpl<MCSymbol *> &getCallsiteSymbols() const {
335-
return CallsiteSymbols;
336-
}
337-
338328
/// Return the MachineFunction containing this basic block.
339329
const MachineFunction *getParent() const { return xParent; }
340330
MachineFunction *getParent() { return xParent; }

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,11 +1428,11 @@ getBBAddrMapFeature(const MachineFunction &MF, int NumMBBSectionRanges,
14281428
HasCalls};
14291429
}
14301430

1431-
void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF,
1432-
bool HasCalls) {
1431+
void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
14331432
MCSection *BBAddrMapSection =
14341433
getObjFileLowering().getBBAddrMapSection(*MF.getSection());
14351434
assert(BBAddrMapSection && ".llvm_bb_addr_map section is not initialized.");
1435+
bool HasCalls = !CurrentFnCallsiteSymbols.empty();
14361436

14371437
const MCSymbol *FunctionSymbol = getFunctionBegin();
14381438

@@ -1498,7 +1498,7 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF,
14981498
const MCSymbol *CurrentLabel = MBBSymbol;
14991499
if (HasCalls) {
15001500
const SmallVectorImpl<MCSymbol *> &CallsiteSymbols =
1501-
MBB.getCallsiteSymbols();
1501+
CurrentFnCallsiteSymbols.lookup(&MBB);
15021502
OutStreamer->AddComment("number of callsites");
15031503
OutStreamer->emitULEB128IntValue(CallsiteSymbols.size());
15041504
for (const MCSymbol *CallsiteSymbol : CallsiteSymbols) {
@@ -1815,7 +1815,6 @@ void AsmPrinter::emitFunctionBody() {
18151815

18161816
// Print out code for the function.
18171817
bool HasAnyRealCode = false;
1818-
bool HasCalls = false;
18191818
int NumInstsInFunction = 0;
18201819
bool IsEHa = MMI->getModule()->getModuleFlag("eh-asynch");
18211820

@@ -1842,11 +1841,8 @@ void AsmPrinter::emitFunctionBody() {
18421841
!MI.isDebugInstr()) {
18431842
HasAnyRealCode = true;
18441843
}
1845-
if (MI.isCall()) {
1846-
HasCalls = true;
1847-
if (MF->getTarget().Options.BBAddrMap)
1848-
OutStreamer->emitLabel(MBB.createCallsiteSymbol());
1849-
}
1844+
if (MI.isCall() && MF->getTarget().Options.BBAddrMap)
1845+
OutStreamer->emitLabel(createCallsiteSymbol(MBB));
18501846

18511847
// If there is a pre-instruction symbol, emit a label for it here.
18521848
if (MCSymbol *S = MI.getPreInstrSymbol())
@@ -2133,7 +2129,7 @@ void AsmPrinter::emitFunctionBody() {
21332129
// BB labels are requested for this function. Skip empty functions.
21342130
if (HasAnyRealCode) {
21352131
if (MF->getTarget().Options.BBAddrMap)
2136-
emitBBAddrMapSection(*MF, HasCalls);
2132+
emitBBAddrMapSection(*MF);
21372133
else if (PgoAnalysisMapFeatures.getBits() != 0)
21382134
MF->getContext().reportWarning(
21392135
SMLoc(), "pgo-analysis-map is enabled for function " + MF->getName() +
@@ -2794,6 +2790,14 @@ MCSymbol *AsmPrinter::getMBBExceptionSym(const MachineBasicBlock &MBB) {
27942790
return Res.first->second;
27952791
}
27962792

2793+
MCSymbol *AsmPrinter::createCallsiteSymbol(const MachineBasicBlock &MBB) {
2794+
MCContext &Ctx = MF->getContext();
2795+
MCSymbol *Sym = Ctx.createTempSymbol("BB" + Twine(MF->getFunctionNumber()) +
2796+
"_" + Twine(MBB.getNumber()) + "_CS");
2797+
CurrentFnCallsiteSymbols[&MBB].push_back(Sym);
2798+
return Sym;
2799+
}
2800+
27972801
void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
27982802
this->MF = &MF;
27992803
const Function &F = MF.getFunction();
@@ -2828,6 +2832,7 @@ void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
28282832
CurrentFnBegin = nullptr;
28292833
CurrentFnBeginLocal = nullptr;
28302834
CurrentSectionBeginSym = nullptr;
2835+
CurrentFnCallsiteSymbols.clear();
28312836
MBBSectionRanges.clear();
28322837
MBBSectionExceptionSyms.clear();
28332838
bool NeedsLocalForSize = MAI->needsLocalForSize();

llvm/lib/CodeGen/MachineBasicBlock.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,6 @@ MCSymbol *MachineBasicBlock::getEndSymbol() const {
112112
return CachedEndMCSymbol;
113113
}
114114

115-
MCSymbol *MachineBasicBlock::createCallsiteSymbol() const {
116-
const MachineFunction *MF = getParent();
117-
MCContext &Ctx = MF->getContext();
118-
CallsiteSymbols.push_back(
119-
Ctx.createTempSymbol("BB" + Twine(MF->getFunctionNumber()) + "_" +
120-
Twine(getNumber()) + "_CS"));
121-
return CallsiteSymbols.back();
122-
}
123-
124115
raw_ostream &llvm::operator<<(raw_ostream &OS, const MachineBasicBlock &MBB) {
125116
MBB.print(OS);
126117
return OS;

0 commit comments

Comments
 (0)