mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2026-04-23 22:23:00 +00:00
Fix a lot of confusion around inserting nops on empty functions.
On MachO, and MachO only, we cannot have a truly empty function since that breaks the linker logic for atomizing the section. When we are emitting a frame pointer, the presence of an unreachable will create a cfi instruction pointing past the last instruction. This is perfectly fine. The FDE information encodes the pc range it applies to. If some tool cannot handle this, we should explicitly say which bug we are working around and only work around it when it is actually relevant (not for ELF for example). Given the unreachable we could omit the .cfi_def_cfa_register, but then again, we could also omit the entire function prologue if we wanted to. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217801 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -731,12 +731,10 @@ void AsmPrinter::EmitFunctionBody() {
|
||||
|
||||
// Print out code for the function.
|
||||
bool HasAnyRealCode = false;
|
||||
const MachineInstr *LastMI = nullptr;
|
||||
for (auto &MBB : *MF) {
|
||||
// Print a label for the basic block.
|
||||
EmitBasicBlockStart(MBB);
|
||||
for (auto &MI : MBB) {
|
||||
LastMI = &MI;
|
||||
|
||||
// Print the assembly for the instruction.
|
||||
if (!MI.isPosition() && !MI.isImplicitDef() && !MI.isKill() &&
|
||||
@@ -797,24 +795,14 @@ void AsmPrinter::EmitFunctionBody() {
|
||||
EmitBasicBlockEnd(MBB);
|
||||
}
|
||||
|
||||
// If the last instruction was a prolog label, then we have a situation where
|
||||
// we emitted a prolog but no function body. This results in the ending prolog
|
||||
// label equaling the end of function label and an invalid "row" in the
|
||||
// FDE. We need to emit a noop in this situation so that the FDE's rows are
|
||||
// valid.
|
||||
bool RequiresNoop = LastMI && LastMI->isCFIInstruction();
|
||||
|
||||
// If the function is empty and the object file uses .subsections_via_symbols,
|
||||
// then we need to emit *something* to the function body to prevent the
|
||||
// labels from collapsing together. Just emit a noop.
|
||||
if ((MAI->hasSubsectionsViaSymbols() && !HasAnyRealCode) || RequiresNoop) {
|
||||
if ((MAI->hasSubsectionsViaSymbols() && !HasAnyRealCode)) {
|
||||
MCInst Noop;
|
||||
TM.getSubtargetImpl()->getInstrInfo()->getNoopForMachoTarget(Noop);
|
||||
if (Noop.getOpcode()) {
|
||||
OutStreamer.AddComment("avoids zero-length function");
|
||||
OutStreamer.EmitInstruction(Noop, getSubtargetInfo());
|
||||
} else // Target not mc-ized yet.
|
||||
OutStreamer.EmitRawText(StringRef("\tnop\n"));
|
||||
OutStreamer.AddComment("avoids zero-length function");
|
||||
OutStreamer.EmitInstruction(Noop, getSubtargetInfo());
|
||||
}
|
||||
|
||||
const Function *F = MF->getFunction();
|
||||
|
||||
Reference in New Issue
Block a user