diff options
author | Jim Grosbach <grosbach@apple.com> | 2010-12-08 01:16:55 +0000 |
---|---|---|
committer | Jim Grosbach <grosbach@apple.com> | 2010-12-08 01:16:55 +0000 |
commit | 5be6d2af38c29e3653998978345220974cc40c01 (patch) | |
tree | 6c08f8d9129cbaef8c42c7e2219174b6e78f0f46 | |
parent | 1b19dc1d8b7594434ea9a157bfe2ae68eabf9f05 (diff) | |
download | llvm-5be6d2af38c29e3653998978345220974cc40c01.tar.gz llvm-5be6d2af38c29e3653998978345220974cc40c01.tar.bz2 llvm-5be6d2af38c29e3653998978345220974cc40c01.tar.xz |
Let target asm backends see assembler flags as they go by. Use that to handle
thumb vs. arm mode differences in WriteNopData().
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121219 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/Target/TargetAsmBackend.h | 5 | ||||
-rw-r--r-- | lib/MC/MCMachOStreamer.cpp | 3 | ||||
-rw-r--r-- | lib/Target/ARM/ARMAsmBackend.cpp | 33 |
3 files changed, 36 insertions, 5 deletions
diff --git a/include/llvm/Target/TargetAsmBackend.h b/include/llvm/Target/TargetAsmBackend.h index ba34472690..4805e1966f 100644 --- a/include/llvm/Target/TargetAsmBackend.h +++ b/include/llvm/Target/TargetAsmBackend.h @@ -10,6 +10,7 @@ #ifndef LLVM_TARGET_TARGETASMBACKEND_H #define LLVM_TARGET_TARGETASMBACKEND_H +#include "llvm/MC/MCDirectives.h" #include "llvm/Support/DataTypes.h" namespace llvm { @@ -109,6 +110,10 @@ public: /// /// \return - True on success. virtual bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const = 0; + + /// HandleAssemblerFlag - Handle any target-specific assembler flags. + /// By default, do nothing. + virtual void HandleAssemblerFlag(MCAssemblerFlag Flag) {} }; } // End llvm namespace diff --git a/lib/MC/MCMachOStreamer.cpp b/lib/MC/MCMachOStreamer.cpp index 6f36001037..47060234b3 100644 --- a/lib/MC/MCMachOStreamer.cpp +++ b/lib/MC/MCMachOStreamer.cpp @@ -124,6 +124,9 @@ void MCMachOStreamer::EmitLabel(MCSymbol *Symbol) { } void MCMachOStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) { + // Let the target do whatever target specific stuff it needs to do. + getAssembler().getBackend().HandleAssemblerFlag(Flag); + // Do any generic stuff we need to do. switch (Flag) { case MCAF_SyntaxUnified: return; // no-op here. case MCAF_Code16: return; // no-op here. diff --git a/lib/Target/ARM/ARMAsmBackend.cpp b/lib/Target/ARM/ARMAsmBackend.cpp index 0bf6dd6e13..90b181e2cb 100644 --- a/lib/Target/ARM/ARMAsmBackend.cpp +++ b/lib/Target/ARM/ARMAsmBackend.cpp @@ -12,6 +12,7 @@ #include "ARMFixupKinds.h" #include "llvm/ADT/Twine.h" #include "llvm/MC/MCAssembler.h" +#include "llvm/MC/MCDirectives.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCObjectFormat.h" #include "llvm/MC/MCObjectWriter.h" @@ -27,6 +28,7 @@ using namespace llvm; namespace { class ARMAsmBackend : public TargetAsmBackend { + bool isThumbMode; // Currently emitting Thumb code. public: ARMAsmBackend(const Target &T) : TargetAsmBackend() {} @@ -36,9 +38,21 @@ public: bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const; - unsigned getPointerSize() const { - return 4; + void HandleAssemblerFlag(MCAssemblerFlag Flag) { + switch (Flag) { + default: break; + case MCAF_Code16: + setIsThumb(true); + break; + case MCAF_Code32: + setIsThumb(false); + break; + } } + + unsigned getPointerSize() const { return 4; } + bool isThumb() const { return isThumbMode; } + void setIsThumb(bool it) { isThumbMode = it; } }; } // end anonymous namespace @@ -53,10 +67,19 @@ void ARMAsmBackend::RelaxInstruction(const MCInst &Inst, MCInst &Res) const { } bool ARMAsmBackend::WriteNopData(uint64_t Count, MCObjectWriter *OW) const { - // FIXME: Zero fill for now. That's not right, but at least will get the - // section size right. + if (isThumb()) { + assert (((Count & 1) == 0) && "Unaligned Nop data fragment!"); + // FIXME: 0xbf00 is the ARMv7 value. For v6 and before, we'll need to + // use 0x46c0 (which is a 'mov r8, r8' insn). + Count /= 2; + for (uint64_t i = 0; i != Count; ++i) + OW->Write16(0xbf00); + return true; + } + // ARM mode + Count /= 4; for (uint64_t i = 0; i != Count; ++i) - OW->Write8(0); + OW->Write32(0xe1a00000); return true; } |