[llvm-commits] [llvm] r137723 - in /llvm/trunk: lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp test/MC/ARM/nop-armv4-padding.s test/MC/ARM/nop-armv6t2-padding.s test/MC/ARM/nop-thumb-padding.s test/MC/ARM/nop-thumb2-padding.s
Jim Grosbach
grosbach at apple.com
Tue Aug 16 10:06:20 PDT 2011
Author: grosbach
Date: Tue Aug 16 12:06:20 2011
New Revision: 137723
URL: http://llvm.org/viewvc/llvm-project?rev=137723&view=rev
Log:
ARM .align NOP padding uses different encoding pre-ARMv6.
Patch by Kristof Beyls and James Malloy.
Added:
llvm/trunk/test/MC/ARM/nop-armv4-padding.s
llvm/trunk/test/MC/ARM/nop-armv6t2-padding.s
llvm/trunk/test/MC/ARM/nop-thumb-padding.s
llvm/trunk/test/MC/ARM/nop-thumb2-padding.s
Modified:
llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
Modified: llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp?rev=137723&r1=137722&r2=137723&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp (original)
+++ llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp Tue Aug 16 12:06:20 2011
@@ -7,6 +7,7 @@
//
//===----------------------------------------------------------------------===//
+#include "MCTargetDesc/ARMMCTargetDesc.h"
#include "MCTargetDesc/ARMBaseInfo.h"
#include "MCTargetDesc/ARMFixupKinds.h"
#include "MCTargetDesc/ARMAddressingModes.h"
@@ -20,6 +21,7 @@
#include "llvm/MC/MCSectionELF.h"
#include "llvm/MC/MCSectionMachO.h"
#include "llvm/MC/MCAsmBackend.h"
+#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/Object/MachOFormat.h"
#include "llvm/Support/ELF.h"
#include "llvm/Support/ErrorHandling.h"
@@ -35,12 +37,23 @@
};
class ARMAsmBackend : public MCAsmBackend {
+ const MCSubtargetInfo* STI;
bool isThumbMode; // Currently emitting Thumb code.
public:
- ARMAsmBackend(const Target &T) : MCAsmBackend(), isThumbMode(false) {}
+ ARMAsmBackend(const Target &T, const StringRef TT)
+ : MCAsmBackend(), STI(ARM_MC::createARMMCSubtargetInfo(TT, "", "")),
+ isThumbMode(false) {}
+
+ ~ARMAsmBackend() {
+ delete STI;
+ }
unsigned getNumFixupKinds() const { return ARM::NumTargetFixupKinds; }
+ bool hasNOP() const {
+ return (STI->getFeatureBits() & ARM::HasV6T2Ops) != 0;
+ }
+
const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const {
const static MCFixupKindInfo Infos[ARM::NumTargetFixupKinds] = {
// This table *must* be in the order that the fixup_* kinds are defined in
@@ -122,20 +135,28 @@
}
bool ARMAsmBackend::WriteNopData(uint64_t Count, MCObjectWriter *OW) const {
+ const uint16_t Thumb1_16bitNopEncoding = 0x46c0; // using MOV r8,r8
+ const uint16_t Thumb2_16bitNopEncoding = 0xbf00; // NOP
+ const uint32_t ARMv4_NopEncoding = 0xe1a0000; // using MOV r0,r0
+ const uint32_t ARMv6T2_NopEncoding = 0xe3207800; // NOP
if (isThumb()) {
- // FIXME: 0xbf00 is the ARMv7 value. For v6 and before, we'll need to
- // use 0x46c0 (which is a 'mov r8, r8' insn).
+ const uint16_t nopEncoding = hasNOP() ? Thumb2_16bitNopEncoding
+ : Thumb1_16bitNopEncoding;
uint64_t NumNops = Count / 2;
for (uint64_t i = 0; i != NumNops; ++i)
- OW->Write16(0xbf00);
+ OW->Write16(nopEncoding);
if (Count & 1)
OW->Write8(0);
return true;
}
// ARM mode
+ const uint32_t nopEncoding = hasNOP() ? ARMv6T2_NopEncoding
+ : ARMv4_NopEncoding;
uint64_t NumNops = Count / 4;
for (uint64_t i = 0; i != NumNops; ++i)
- OW->Write32(0xe1a00000);
+ OW->Write32(nopEncoding);
+ // FIXME: should this function return false when unable to write exactly
+ // 'Count' bytes with NOP encodings?
switch (Count % 4) {
default: break; // No leftover bytes to write
case 1: OW->Write8(0); break;
@@ -381,8 +402,9 @@
class ELFARMAsmBackend : public ARMAsmBackend {
public:
Triple::OSType OSType;
- ELFARMAsmBackend(const Target &T, Triple::OSType _OSType)
- : ARMAsmBackend(T), OSType(_OSType) { }
+ ELFARMAsmBackend(const Target &T, const StringRef TT,
+ Triple::OSType _OSType)
+ : ARMAsmBackend(T, TT), OSType(_OSType) { }
void ApplyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
uint64_t Value) const;
@@ -413,8 +435,9 @@
class DarwinARMAsmBackend : public ARMAsmBackend {
public:
const object::mach::CPUSubtypeARM Subtype;
- DarwinARMAsmBackend(const Target &T, object::mach::CPUSubtypeARM st)
- : ARMAsmBackend(T), Subtype(st) { }
+ DarwinARMAsmBackend(const Target &T, const StringRef TT,
+ object::mach::CPUSubtypeARM st)
+ : ARMAsmBackend(T, TT), Subtype(st) { }
MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
return createARMMachObjectWriter(OS, /*Is64Bit=*/false,
@@ -497,18 +520,18 @@
if (TheTriple.isOSDarwin()) {
if (TheTriple.getArchName() == "armv4t" ||
TheTriple.getArchName() == "thumbv4t")
- return new DarwinARMAsmBackend(T, object::mach::CSARM_V4T);
+ return new DarwinARMAsmBackend(T, TT, object::mach::CSARM_V4T);
else if (TheTriple.getArchName() == "armv5e" ||
TheTriple.getArchName() == "thumbv5e")
- return new DarwinARMAsmBackend(T, object::mach::CSARM_V5TEJ);
+ return new DarwinARMAsmBackend(T, TT, object::mach::CSARM_V5TEJ);
else if (TheTriple.getArchName() == "armv6" ||
TheTriple.getArchName() == "thumbv6")
- return new DarwinARMAsmBackend(T, object::mach::CSARM_V6);
- return new DarwinARMAsmBackend(T, object::mach::CSARM_V7);
+ return new DarwinARMAsmBackend(T, TT, object::mach::CSARM_V6);
+ return new DarwinARMAsmBackend(T, TT, object::mach::CSARM_V7);
}
if (TheTriple.isOSWindows())
assert(0 && "Windows not supported on ARM");
- return new ELFARMAsmBackend(T, Triple(TT).getOS());
+ return new ELFARMAsmBackend(T, TT, Triple(TT).getOS());
}
Added: llvm/trunk/test/MC/ARM/nop-armv4-padding.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/nop-armv4-padding.s?rev=137723&view=auto
==============================================================================
--- llvm/trunk/test/MC/ARM/nop-armv4-padding.s (added)
+++ llvm/trunk/test/MC/ARM/nop-armv4-padding.s Tue Aug 16 12:06:20 2011
@@ -0,0 +1,10 @@
+@ RUN: llvm-mc -triple armv4-apple-darwin %s -filetype=obj -o %t.obj
+@ RUN: macho-dump --dump-section-data < %t.obj > %t.dump
+@ RUN: FileCheck %s < %t.dump
+
+x:
+ add r0, r1, r2
+ .align 4
+ add r0, r1, r2
+
+@ CHECK: ('_section_data', '020081e0 00001a0e 00001a0e 00001a0e 020081e0')
Added: llvm/trunk/test/MC/ARM/nop-armv6t2-padding.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/nop-armv6t2-padding.s?rev=137723&view=auto
==============================================================================
--- llvm/trunk/test/MC/ARM/nop-armv6t2-padding.s (added)
+++ llvm/trunk/test/MC/ARM/nop-armv6t2-padding.s Tue Aug 16 12:06:20 2011
@@ -0,0 +1,10 @@
+@ RUN: llvm-mc -triple armv6t2-apple-darwin %s -filetype=obj -o %t.obj
+@ RUN: macho-dump --dump-section-data < %t.obj > %t.dump
+@ RUN: FileCheck %s < %t.dump
+
+x:
+ add r0, r1, r2
+ .align 4
+ add r0, r1, r2
+
+@ CHECK: ('_section_data', '020081e0 007820e3 007820e3 007820e3 020081e0')
Added: llvm/trunk/test/MC/ARM/nop-thumb-padding.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/nop-thumb-padding.s?rev=137723&view=auto
==============================================================================
--- llvm/trunk/test/MC/ARM/nop-thumb-padding.s (added)
+++ llvm/trunk/test/MC/ARM/nop-thumb-padding.s Tue Aug 16 12:06:20 2011
@@ -0,0 +1,12 @@
+@ RUN: llvm-mc -triple armv6-apple-darwin %s -filetype=obj -o %t.obj
+@ RUN: macho-dump --dump-section-data < %t.obj > %t.dump
+@ RUN: FileCheck %s < %t.dump
+
+.thumb_func x
+.code 16
+x:
+ add r0, r1, r2
+ .align 4
+ add r0, r1, r2
+
+@ CHECK: ('_section_data', '8818c046 c046c046 c046c046 c046c046 8818')
Added: llvm/trunk/test/MC/ARM/nop-thumb2-padding.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/nop-thumb2-padding.s?rev=137723&view=auto
==============================================================================
--- llvm/trunk/test/MC/ARM/nop-thumb2-padding.s (added)
+++ llvm/trunk/test/MC/ARM/nop-thumb2-padding.s Tue Aug 16 12:06:20 2011
@@ -0,0 +1,12 @@
+@ RUN: llvm-mc -triple armv7-apple-darwin %s -filetype=obj -o %t.obj
+@ RUN: macho-dump --dump-section-data < %t.obj > %t.dump
+@ RUN: FileCheck %s < %t.dump
+
+.thumb_func x
+.code 16
+x:
+ add r0, r1, r2
+ .align 4
+ add r0, r1, r2
+
+@ CHECK: ('_section_data', '881800bf 00bf00bf 00bf00bf 00bf00bf 8818')
More information about the llvm-commits
mailing list