Skip to content

Commit b76c9ad

Browse files
committed
Cleanup callsite label generation function
1 parent f3abc2f commit b76c9ad

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

llvm/include/llvm/CodeGen/AsmPrinter.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,10 @@ class LLVM_ABI AsmPrinter : public MachineFunctionPass {
388388

389389
/// Generate and emit labels for callees of all callsites which will
390390
/// be used to populate the .callgraph section.
391-
void
392-
emitCalleeLabels(FunctionInfo &FuncInfo,
393-
const MachineFunction::CallSiteInfoMap &CallSitesInfoMap,
394-
const MachineInstr &MI);
391+
void emitCallsiteLabelsForCallgraph(
392+
FunctionInfo &FuncInfo,
393+
const MachineFunction::CallSiteInfoMap &CallSitesInfoMap,
394+
const MachineInstr &MI);
395395

396396
//===------------------------------------------------------------------===//
397397
// XRay instrumentation implementation.

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,16 +1875,14 @@ static StringRef getMIMnemonic(const MachineInstr &MI, MCStreamer &Streamer) {
18751875
return Name;
18761876
}
18771877

1878-
void AsmPrinter::emitCalleeLabels(
1878+
void AsmPrinter::emitCallsiteLabelsForCallgraph(
18791879
FunctionInfo &FuncInfo,
18801880
const MachineFunction::CallSiteInfoMap &CallSitesInfoMap,
18811881
const MachineInstr &MI) {
1882-
// Only indirect calls have type identifiers set.
1883-
const auto &CallSiteInfo = CallSitesInfoMap.find(&MI);
1884-
1885-
// Handle direct callsite info
1886-
if (CallSiteInfo == CallSitesInfoMap.end()) {
1887-
const MachineOperand &CalleeOperand = MI.getOperand(0);
1882+
assert(MI.isCall() && "Callsite labels are meant for call instruction only.");
1883+
const MachineOperand &CalleeOperand = MI.getOperand(0);
1884+
if (CalleeOperand.isGlobal() || CalleeOperand.isSymbol()) {
1885+
// Handle direct calls.
18881886
MCSymbol *CalleeSymbol = nullptr;
18891887
switch (CalleeOperand.getType()) {
18901888
case llvm::MachineOperand::MO_GlobalAddress:
@@ -1894,20 +1892,22 @@ void AsmPrinter::emitCalleeLabels(
18941892
CalleeSymbol = GetExternalSymbolSymbol(CalleeOperand.getSymbolName());
18951893
break;
18961894
default:
1897-
llvm_unreachable("Expect only direct call instructions to be handled.");
1895+
llvm_unreachable(
1896+
"Expected to only handle direct call instructions here.");
18981897
}
18991898
MCSymbol *S = MF->getContext().createTempSymbol();
19001899
OutStreamer->emitLabel(S);
19011900
FuncInfo.DirectCallSiteLabels.emplace_back(S, CalleeSymbol);
1902-
return;
1903-
}
1904-
1905-
// Handle indirect callsite info.
1906-
for (ConstantInt *CalleeTypeId : CallSiteInfo->second.CalleeTypeIds) {
1907-
MCSymbol *S = MF->getContext().createTempSymbol();
1908-
OutStreamer->emitLabel(S);
1909-
uint64_t CalleeTypeIdVal = CalleeTypeId->getZExtValue();
1910-
FuncInfo.CallSiteLabels.emplace_back(CalleeTypeIdVal, S);
1901+
} else {
1902+
// Handle indirect callsite info.
1903+
// Only indirect calls have type identifiers set.
1904+
const auto &CallSiteInfo = CallSitesInfoMap.find(&MI);
1905+
for (ConstantInt *CalleeTypeId : CallSiteInfo->second.CalleeTypeIds) {
1906+
MCSymbol *S = MF->getContext().createTempSymbol();
1907+
OutStreamer->emitLabel(S);
1908+
uint64_t CalleeTypeIdVal = CalleeTypeId->getZExtValue();
1909+
FuncInfo.CallSiteLabels.emplace_back(CalleeTypeIdVal, S);
1910+
}
19111911
}
19121912
}
19131913

@@ -2093,7 +2093,7 @@ void AsmPrinter::emitFunctionBody() {
20932093
}
20942094

20952095
if (TM.Options.EmitCallGraphSection && MI.isCall())
2096-
emitCalleeLabels(FuncInfo, CallSitesInfoMap, MI);
2096+
emitCallsiteLabelsForCallgraph(FuncInfo, CallSitesInfoMap, MI);
20972097

20982098
// If there is a post-instruction symbol, emit a label for it here.
20992099
if (MCSymbol *S = MI.getPostInstrSymbol())

0 commit comments

Comments
 (0)