[llvm-commits] [llvm] r102400 - in /llvm/trunk: include/llvm/Target/TargetInstrInfo.h lib/CodeGen/AsmPrinter/AsmPrinter.cpp lib/Target/X86/X86InstrInfo.cpp lib/Target/X86/X86InstrInfo.h test/CodeGen/PowerPC/2008-01-25-EmptyFunction.ll test/CodeGen/X86/2008-01-25-EmptyFunction.ll
Chris Lattner
sabre at nondot.org
Mon Apr 26 16:37:21 PDT 2010
Author: lattner
Date: Mon Apr 26 18:37:21 2010
New Revision: 102400
URL: http://llvm.org/viewvc/llvm-project?rev=102400&view=rev
Log:
on darwin empty functions need to codegen into something of non-zero length,
otherwise labels get incorrectly merged. We handled this by emitting a
".byte 0", but this isn't correct on thumb/arm targets where the text segment
needs to be a multiple of 2/4 bytes. Handle this by emitting a noop. This
is more gross than it should be because arm/ppc are not fully mc'ized yet.
This fixes rdar://7908505
Modified:
llvm/trunk/include/llvm/Target/TargetInstrInfo.h
llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/trunk/lib/Target/X86/X86InstrInfo.cpp
llvm/trunk/lib/Target/X86/X86InstrInfo.h
llvm/trunk/test/CodeGen/PowerPC/2008-01-25-EmptyFunction.ll
llvm/trunk/test/CodeGen/X86/2008-01-25-EmptyFunction.ll
Modified: llvm/trunk/include/llvm/Target/TargetInstrInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetInstrInfo.h?rev=102400&r1=102399&r2=102400&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetInstrInfo.h (original)
+++ llvm/trunk/include/llvm/Target/TargetInstrInfo.h Mon Apr 26 18:37:21 2010
@@ -24,6 +24,7 @@
class MCAsmInfo;
class MachineMemOperand;
class MDNode;
+class MCInst;
class SDNode;
class SelectionDAG;
class TargetRegisterClass;
@@ -490,6 +491,13 @@
virtual void insertNoop(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MI) const;
+
+ /// getNoopForMachoTarget - Return the noop instruction to use for a noop.
+ virtual void getNoopForMachoTarget(MCInst &NopInst) const {
+ // Default to just using 'nop' string.
+ }
+
+
/// isPredicated - Returns true if the instruction is already predicated.
///
virtual bool isPredicated(const MachineInstr *MI) const {
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=102400&r1=102399&r2=102400&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Mon Apr 26 18:37:21 2010
@@ -585,9 +585,15 @@
// 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 0 byte.
- if (MAI->hasSubsectionsViaSymbols() && !HasAnyRealCode)
- OutStreamer.EmitIntValue(0, 1, 0/*addrspace*/);
+ // labels from collapsing together. Just emit a noop.
+ if (MAI->hasSubsectionsViaSymbols() && !HasAnyRealCode) {
+ MCInst Noop;
+ TM.getInstrInfo()->getNoopForMachoTarget(Noop);
+ if (Noop.getOpcode())
+ OutStreamer.EmitInstruction(Noop);
+ else // Target not mc-ized yet.
+ OutStreamer.EmitRawText(StringRef("\tnop\n"));
+ }
// Emit target-specific gunk after the function body.
EmitFunctionBodyEnd();
Modified: llvm/trunk/lib/Target/X86/X86InstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86InstrInfo.cpp?rev=102400&r1=102399&r2=102400&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86InstrInfo.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86InstrInfo.cpp Mon Apr 26 18:37:21 2010
@@ -27,6 +27,7 @@
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/LiveVariables.h"
#include "llvm/CodeGen/PseudoSourceValue.h"
+#include "llvm/MC/MCInst.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
@@ -3766,3 +3767,9 @@
assert(table && "Cannot change domain");
MI->setDesc(get(table[Domain-1]));
}
+
+/// getNoopForMachoTarget - Return the noop instruction to use for a noop.
+void X86InstrInfo::getNoopForMachoTarget(MCInst &NopInst) const {
+ NopInst.setOpcode(X86::NOOP);
+}
+
Modified: llvm/trunk/lib/Target/X86/X86InstrInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86InstrInfo.h?rev=102400&r1=102399&r2=102400&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86InstrInfo.h (original)
+++ llvm/trunk/lib/Target/X86/X86InstrInfo.h Mon Apr 26 18:37:21 2010
@@ -693,6 +693,8 @@
int64_t Offset1, int64_t Offset2,
unsigned NumLoads) const;
+ virtual void getNoopForMachoTarget(MCInst &NopInst) const;
+
virtual
bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
Modified: llvm/trunk/test/CodeGen/PowerPC/2008-01-25-EmptyFunction.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/PowerPC/2008-01-25-EmptyFunction.ll?rev=102400&r1=102399&r2=102400&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/PowerPC/2008-01-25-EmptyFunction.ll (original)
+++ llvm/trunk/test/CodeGen/PowerPC/2008-01-25-EmptyFunction.ll Mon Apr 26 18:37:21 2010
@@ -1,4 +1,4 @@
-; RUN: llc < %s -march=ppc32 | grep .byte
+; RUN: llc < %s -march=ppc32 | grep nop
target triple = "powerpc-apple-darwin8"
Modified: 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=102400&r1=102399&r2=102400&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/2008-01-25-EmptyFunction.ll (original)
+++ llvm/trunk/test/CodeGen/X86/2008-01-25-EmptyFunction.ll Mon Apr 26 18:37:21 2010
@@ -1,4 +1,4 @@
-; RUN: llc < %s -march=x86 | grep {.byte 0}
+; RUN: llc < %s -march=x86 | grep nop
target triple = "i686-apple-darwin8"
More information about the llvm-commits
mailing list