-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Jump table annotations for Linux #112606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Jump table annotations for Linux #112606
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -162,6 +162,10 @@ static cl::opt<bool> EmitJumpTableSizesSection( | |
| cl::desc("Emit a section containing jump table addresses and sizes"), | ||
| cl::Hidden, cl::init(false)); | ||
|
|
||
| static cl::opt<bool> AnnotateJumpTables("annotate-jump-tables", | ||
| cl::desc("Annotate jump tables"), | ||
| cl::Hidden, cl::init(false)); | ||
|
Comment on lines
+165
to
+167
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK I'll look into that. Suggestions welcome on useful examples.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fc018eb was exactly this. Perhaps we can add a new (That way we have |
||
|
|
||
| STATISTIC(EmittedInsts, "Number of machine instrs printed"); | ||
|
|
||
| char AsmPrinter::ID = 0; | ||
|
|
@@ -1528,6 +1532,25 @@ void AsmPrinter::emitPseudoProbe(const MachineInstr &MI) { | |
| } | ||
| } | ||
|
|
||
| void AsmPrinter::emitJumpTableAnnotation(const MachineFunction &MF, | ||
| const MachineInstr &MI) { | ||
| if (!AnnotateJumpTables || !TM.getTargetTriple().isOSBinFormatELF()) | ||
| return; | ||
|
|
||
| MCSymbol *JTISymbol = GetJTISymbol(MI.getOperand(0).getImm()); | ||
| MCSymbol *ProvenanceLabel = OutContext.createTempSymbol("jtp"); | ||
|
|
||
| const MCExpr *OffsetExpr = | ||
| MCSymbolRefExpr::create(ProvenanceLabel, OutContext); | ||
| const MCExpr *JTISymbolExpr = | ||
| MCSymbolRefExpr::create(JTISymbol, OutContext); | ||
|
|
||
| OutStreamer->emitRelocDirective(*OffsetExpr, "BFD_RELOC_NONE", | ||
| JTISymbolExpr, SMLoc(), | ||
| *OutContext.getSubtargetInfo()); | ||
| OutStreamer->emitLabel(ProvenanceLabel); | ||
| } | ||
|
|
||
| void AsmPrinter::emitStackSizeSection(const MachineFunction &MF) { | ||
| if (!MF.getTarget().Options.EmitStackSizeSection) | ||
| return; | ||
|
|
@@ -1849,8 +1872,7 @@ void AsmPrinter::emitFunctionBody() { | |
| OutStreamer->emitRawComment("MEMBARRIER"); | ||
| break; | ||
| case TargetOpcode::JUMP_TABLE_DEBUG_INFO: | ||
| // This instruction is only used to note jump table debug info, it's | ||
| // purely meta information. | ||
| emitJumpTableAnnotation(*MF, MI); | ||
| break; | ||
| case TargetOpcode::INIT_UNDEF: | ||
| // This is only used to influence register allocation behavior, no | ||
|
|
@@ -2821,6 +2843,25 @@ void AsmPrinter::emitJumpTableInfo() { | |
| // label differences will be evaluated at write time. | ||
| for (const MachineBasicBlock *MBB : JTBBs) | ||
| emitJumpTableEntry(MJTI, MBB, JTI); | ||
|
|
||
| if (AnnotateJumpTables && TM.getTargetTriple().isOSBinFormatELF()) { | ||
| // Create a temp symbol for the end of the jump table. | ||
| MCSymbol *JTIEndSymbol = createTempSymbol("jt_end"); | ||
| OutStreamer->emitLabel(JTIEndSymbol); | ||
|
|
||
| const MCExpr *JTISymbolExpr = | ||
| MCSymbolRefExpr::create(JTISymbol, OutContext); | ||
|
|
||
| MCSymbol *JTISymbolForSize = OutContext.getOrCreateSymbol( | ||
| "$JTI" + Twine(MF->getFunctionNumber()) + "_" + Twine(JTI)); | ||
| OutStreamer->emitAssignment(JTISymbolForSize, JTISymbolExpr); | ||
| OutStreamer->emitSymbolAttribute(JTISymbolForSize, MCSA_ELF_TypeObject); | ||
|
|
||
| const MCExpr *SizeExp = MCBinaryExpr::createSub( | ||
| MCSymbolRefExpr::create(JTIEndSymbol, OutContext), JTISymbolExpr, | ||
| OutContext); | ||
| OutStreamer->emitELFSize(JTISymbolForSize, SizeExp); | ||
| } | ||
| } | ||
|
|
||
| if (EmitJumpTableSizesSection) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it need to be virtual if you're only providing one definition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that a rhetorical question?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes (sorry, I could have phrased it differently).
As an example, if you look at the below method declaration for
emitGlobalVariable, you'll find a definition for it in the base classAsmPrinter, but overrides are provided in various derived classes (AMDGPUAsmPrinter,ARMAsmPrinter,NVPTXAsmPrinter,PPCAsmPrinter, andWebAssemblyAsmPrinter).Since you're not changing the functionality for any of the derived classes (i.e. no
overrides) and only providing a definition for the base class, then you should not declare this method asvirtual. That should avoid needing to traverse the vtable to call this method.