Skip to content

Commit 4dffc8a

Browse files
committed
Reorder fields in callgraph section.
1 parent 7df84eb commit 4dffc8a

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

llvm/docs/CallGraphSection.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ Each record in the `.callgraph` section has the following binary layout:
1313
| Function Entry PC | `uintptr_t` | 32/64 | The address of the function's entry point. |
1414
| Function Type ID | `uint64_t` | 64 | The type ID of the function. This field is non-zero if the function is a potential indirect call target and its type is known. |
1515
| Number of Unique Direct Callees | `ULEB128` | Variable | The number of unique direct call destinations from this function. This field is only present if there is at least one direct callee. |
16-
| Number of Unique Indirect Target Type IDs| `ULEB128` | Variable | The number of unique indirect call target type IDs. This field is only present if there is at least one indirect target type ID. |
1716
| Direct Callees Array | `uintptr_t[]` | Variable | An array of unique direct callee entry point addresses. |
17+
| Number of Unique Indirect Target Type IDs| `ULEB128` | Variable | The number of unique indirect call target type IDs. This field is only present if there is at least one indirect target type ID. |
1818
| Indirect Target Type IDs Array | `uint64_t[]` | Variable | An array of unique indirect call target type IDs. |

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,11 +1713,11 @@ void AsmPrinter::emitCallGraphSection(const MachineFunction &MF,
17131713
// c. LSB bit 2 is set to 1 if there are indirect callees.
17141714
// d. Rest of the 5 bits in Flags are reserved for any future use.
17151715
// 3) Function entry PC.
1716-
// 4) FunctionTypeID if the function is indirect target and its type id is
1717-
// known, otherwise it is set to 0.
1716+
// 4) FunctionTypeID if the function is indirect target and its type id
1717+
// is known, otherwise it is set to 0.
17181718
// 5) Number of unique direct callees, if at least one exists.
1719-
// 6) Number of unique indirect target type IDs, if at least one exists.
1720-
// 7) For each unique direct callee, the callee's PC.
1719+
// 6) For each unique direct callee, the callee's PC.
1720+
// 7) Number of unique indirect target type IDs, if at least one exists.
17211721
// 8) Each unique indirect target type id.
17221722
OutStreamer->emitInt8(CallGraphSectionFormatVersion::V_0);
17231723
OutStreamer->emitInt8(Flags);
@@ -1728,16 +1728,18 @@ void AsmPrinter::emitCallGraphSection(const MachineFunction &MF,
17281728
else
17291729
OutStreamer->emitInt64(0);
17301730

1731-
if (DirectCallees.size() > 0)
1731+
if (DirectCallees.size() > 0) {
17321732
OutStreamer->emitULEB128IntValue(DirectCallees.size());
1733-
if (IndirectCalleeTypeIDs.size() > 0)
1733+
for (const auto &CalleeSymbol : DirectCallees)
1734+
OutStreamer->emitSymbolValue(CalleeSymbol, TM.getProgramPointerSize());
1735+
FuncCGInfo.DirectCallees.clear();
1736+
}
1737+
if (IndirectCalleeTypeIDs.size() > 0) {
17341738
OutStreamer->emitULEB128IntValue(IndirectCalleeTypeIDs.size());
1735-
for (const auto &CalleeSymbol : DirectCallees)
1736-
OutStreamer->emitSymbolValue(CalleeSymbol, TM.getProgramPointerSize());
1737-
FuncCGInfo.DirectCallees.clear();
1738-
for (const auto &CalleeTypeId : IndirectCalleeTypeIDs)
1739-
OutStreamer->emitInt64(CalleeTypeId);
1740-
FuncCGInfo.IndirectCalleeTypeIDs.clear();
1739+
for (const auto &CalleeTypeId : IndirectCalleeTypeIDs)
1740+
OutStreamer->emitInt64(CalleeTypeId);
1741+
FuncCGInfo.IndirectCalleeTypeIDs.clear();
1742+
}
17411743
// End of emitting call graph section contents.
17421744
OutStreamer->popSection();
17431745
}

llvm/test/CodeGen/X86/call-graph-section-assembly.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ entry:
4747
; CHECK-NEXT: .quad 0
4848
;; Number of unique direct callees.
4949
; CHECK-NEXT: .byte 3
50-
;; Number of unique indirect target type IDs.
51-
; CHECK-NEXT: .byte 3
5250
;; Direct callees.
5351
; CHECK-NEXT: .quad direct_foo
5452
; CHECK-NEXT: .quad direct_bar
5553
; CHECK-NEXT: .quad direct_baz
54+
;; Number of unique indirect target type IDs.
55+
; CHECK-NEXT: .byte 3
5656
;; Indirect type IDs.
5757
; CHECK-NEXT: .quad 4524972987496481828
5858
; CHECK-NEXT: .quad 3498816979441845844

0 commit comments

Comments
 (0)