Author: void Date: Sat Jan 26 03:03:52 2008 New Revision: 46398 URL: http://llvm.org/viewvc/llvm-project?rev=46398&view=rev Log: If there's no instructions being emitted on X86 for a function, emit a nop. Emit the nop directly for PPC.
Added: llvm/trunk/test/CodeGen/X86/2008-01-25-EmptyFunction.ll Modified: llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp llvm/trunk/lib/Target/X86/X86ATTAsmPrinter.cpp Modified: llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp?rev=46398&r1=46397&r2=46398&view=diff ============================================================================== --- llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp (original) +++ llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp Sat Jan 26 03:03:52 2008 @@ -819,12 +819,8 @@ // be associated with. We emit a noop in this situation. MachineFunction::iterator I = MF.begin(); - if (++I == MF.end()) { - MachineBasicBlock &MBB = MF.front(); - - if (MBB.begin() == MBB.end()) - BuildMI(MBB, MBB.end(), TM.getInstrInfo()->get(PPC::NOP)); - } + if (++I == MF.end() && MF.front().empty()) + O << "\tnop\n"; // Print out code for the function. for (MachineFunction::const_iterator I = MF.begin(), E = MF.end(); Modified: llvm/trunk/lib/Target/X86/X86ATTAsmPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ATTAsmPrinter.cpp?rev=46398&r1=46397&r2=46398&view=diff ============================================================================== --- llvm/trunk/lib/Target/X86/X86ATTAsmPrinter.cpp (original) +++ llvm/trunk/lib/Target/X86/X86ATTAsmPrinter.cpp Sat Jan 26 03:03:52 2008 @@ -165,6 +165,16 @@ DW.BeginFunction(&MF); } + if (Subtarget->isTargetDarwin()) { + // If the function is empty, then we need to emit *something*. Otherwise, + // the function's label might be associated with something that it wasn't + // meant to be associated with. We emit a noop in this situation. + MachineFunction::iterator I = MF.begin(); + + if (++I == MF.end() && MF.front().empty()) + O << "\tnop\n"; + } + // Print out code for the function. for (MachineFunction::const_iterator I = MF.begin(), E = MF.end(); I != E; ++I) { @@ -173,8 +183,8 @@ printBasicBlockLabel(I, true); O << '\n'; } - for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end(); - II != E; ++II) { + for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end(); + II != IE; ++II) { // Print the assembly for the instruction. O << "\t"; printMachineInstruction(II); Added: llvm/trunk/test/CodeGen/X86/2008-01-25-EmptyFunction.ll URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/2008-01-25-EmptyFunction.ll?rev=46398&view=auto ============================================================================== --- llvm/trunk/test/CodeGen/X86/2008-01-25-EmptyFunction.ll (added) +++ llvm/trunk/test/CodeGen/X86/2008-01-25-EmptyFunction.ll Sat Jan 26 03:03:52 2008 @@ -0,0 +1,6 @@ +; RUN: llvm-as < %s | llc -march=x86 | grep nop + +define void @bork() noreturn nounwind { +entry: + unreachable +} _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits