openbsd-ports/devel/llvm/patches/patch-lib_CodeGen_AsmPrinter_AsmPrinter_cpp
2022-03-10 00:04:05 +00:00

69 lines
2.7 KiB
Plaintext

- Use int3 trap padding between functions instead of trapsleds with a leading jump.
- Emit trap alignment between basic blocks that are unreachable via
fallthrough. Avoids unnecessary jmp instructions in the middle
of functions and makes disassembly nicer to read.
Index: lib/CodeGen/AsmPrinter/AsmPrinter.cpp
--- lib/CodeGen/AsmPrinter/AsmPrinter.cpp.orig
+++ lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -745,7 +745,7 @@ void AsmPrinter::emitFunctionHeader() {
emitLinkage(&F, CurrentFnSym);
if (MAI->hasFunctionAlignment())
- emitAlignment(MF->getAlignment(), &F);
+ emitTrapAlignment(MF->getAlignment(), &F);
if (MAI->hasDotTypeDotSizeDirective())
OutStreamer->emitSymbolAttribute(CurrentFnSym, MCSA_ELF_TypeFunction);
@@ -2462,6 +2462,30 @@ void AsmPrinter::emitAlignment(Align Alignment, const
}
//===----------------------------------------------------------------------===//
+/// emitTrapAlignment - Emit an alignment directive to the specified power of
+/// two boundary, but call emitTrapToAlignment to fill with Trap instructions
+/// if the Target implements emitTrapToAlignment.
+void AsmPrinter::emitTrapAlignment(Align Alignment, const GlobalObject *GV) const {
+ if (GV)
+ Alignment = getGVAlignment(GV, GV->getParent()->getDataLayout(), Alignment);
+
+ if (Alignment == Align(1)) return; // 1-byte aligned: no need to emit alignment.
+
+ emitTrapToAlignment(Alignment);
+}
+
+//===----------------------------------------------------------------------===//
+/// emitTrapToAlignment - Emit an alignment directive to the specified power
+/// of two boundary. This default implementation calls EmitCodeAlignment on
+/// the OutStreamer, but can be overridden by Target implementations.
+void AsmPrinter::emitTrapToAlignment(Align Alignment) const {
+ if (Alignment == Align(1)) return;
+ OutStreamer->emitCodeAlignment(Alignment.value());
+}
+
+
+
+//===----------------------------------------------------------------------===//
// Constant emission.
//===----------------------------------------------------------------------===//
@@ -3246,10 +3270,17 @@ void AsmPrinter::emitBasicBlockStart(const MachineBasi
}
}
+ bool isReachableViaFallthrough =
+ std::find(MBB.pred_begin(), MBB.pred_end(), MBB.getPrevNode()) !=
+ MBB.pred_end();
// Emit an alignment directive for this block, if needed.
const Align Alignment = MBB.getAlignment();
- if (Alignment != Align(1))
- emitAlignment(Alignment);
+ if (Alignment != Align(1)) {
+ if (isReachableViaFallthrough)
+ emitAlignment(Alignment);
+ else
+ emitTrapAlignment(Alignment);
+ }
// Switch to a new section if this basic block must begin a section. The
// entry block is always placed in the function section and is handled