[llvm] r199023 - ARM IAS: support emitting constant values in target expressions
Saleem Abdulrasool
compnerd at compnerd.org
Sat Jan 11 15:03:48 PST 2014
Author: compnerd
Date: Sat Jan 11 17:03:48 2014
New Revision: 199023
URL: http://llvm.org/viewvc/llvm-project?rev=199023&view=rev
Log:
ARM IAS: support emitting constant values in target expressions
A 32-bit immediate value can be formed from a constant expression and loaded
into a register. Add support to emit this into an object file. Because this
value is a constant, a relocation must *not* be produced for it.
Modified:
llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMCCodeEmitter.cpp
llvm/trunk/test/MC/ARM/target-expressions.s
Modified: llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMCCodeEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMCCodeEmitter.cpp?rev=199023&r1=199022&r2=199023&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMCCodeEmitter.cpp (original)
+++ llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMCCodeEmitter.cpp Sat Jan 11 17:03:48 2014
@@ -26,6 +26,7 @@
#include "llvm/MC/MCInstrInfo.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/MC/MCSubtargetInfo.h"
+#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
@@ -912,6 +913,20 @@ ARMMCCodeEmitter::getHiLo16ImmOpValue(co
const ARMMCExpr *ARM16Expr = cast<ARMMCExpr>(E);
E = ARM16Expr->getSubExpr();
+ if (const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(E)) {
+ const int64_t Value = MCE->getValue();
+ if (Value > UINT32_MAX)
+ report_fatal_error("constant value truncated (limited to 32-bit)");
+
+ switch (ARM16Expr->getKind()) {
+ case ARMMCExpr::VK_ARM_HI16:
+ return (int32_t(Value) & 0xffff0000) >> 16;
+ case ARMMCExpr::VK_ARM_LO16:
+ return (int32_t(Value) & 0x0000ffff);
+ default: llvm_unreachable("Unsupported ARMFixup");
+ }
+ }
+
switch (ARM16Expr->getKind()) {
default: llvm_unreachable("Unsupported ARMFixup");
case ARMMCExpr::VK_ARM_HI16:
Modified: llvm/trunk/test/MC/ARM/target-expressions.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/target-expressions.s?rev=199023&r1=199022&r2=199023&view=diff
==============================================================================
--- llvm/trunk/test/MC/ARM/target-expressions.s (original)
+++ llvm/trunk/test/MC/ARM/target-expressions.s Sat Jan 11 17:03:48 2014
@@ -1,4 +1,6 @@
@ RUN: llvm-mc -triple armv7-eabi -filetype asm -o - %s | FileCheck %s
+@ RUN: llvm-mc -triple armv7-eabi -filetype obj -o - %s | llvm-readobj -r \
+@ RUN: | FileCheck -check-prefix CHECK-RELOCATIONS %s
.syntax unified
@@ -6,6 +8,9 @@
function:
bx lr
+ .global external
+ .type external,%function
+
.set deadbeat, 0xdeadbea7
.type test,%function
@@ -28,6 +33,18 @@ test:
movw r5, #:lower16:0xD1510D6E
movt r5, #:upper16:0xD1510D6E
+ movw r0, :lower16:external
+ movt r0, :upper16:external
+
+ movw r1, #:lower16:external
+ movt r1, #:upper16:external
+
+ movw r2, #:lower16:(16 + 16)
+ movt r2, #:upper16:(16 + 16)
+
+ movw r3, :lower16:(16 + 16)
+ movt r3, :upper16:(16 + 16)
+
@ CHECK-LABEL: test:
@ CHECK: movw r0, :lower16:function
@ CHECK: movt r0, :upper16:function
@@ -41,4 +58,23 @@ test:
@ CHECK: movt r4, :upper16:(3511749998)
@ CHECK: movw r5, :lower16:(3511749998)
@ CHECK: movt r5, :upper16:(3511749998)
+@ CHECK: movw r0, :lower16:external
+@ CHECK: movt r0, :upper16:external
+@ CHECK: movw r1, :lower16:external
+@ CHECK: movt r1, :upper16:external
+@ CHECK: movw r2, :lower16:(32)
+@ CHECK: movt r2, :upper16:(32)
+@ CHECK: movw r3, :lower16:(32)
+@ CHECK: movt r3, :upper16:(32)
+
+@ CHECK-RELOCATIONS: Relocations [
+@ CHECK-RELOCATIONS: 0x4 R_ARM_MOVW_ABS_NC function 0x0
+@ CHECK-RELOCATIONS: 0x8 R_ARM_MOVT_ABS function 0x0
+@ CHECK-RELOCATIONS: 0xC R_ARM_MOVW_ABS_NC function 0x0
+@ CHECK-RELOCATIONS: 0x10 R_ARM_MOVT_ABS function 0x0
+@ CHECK-RELOCATIONS: 0x34 R_ARM_MOVW_ABS_NC external 0x0
+@ CHECK-RELOCATIONS: 0x38 R_ARM_MOVT_ABS external 0x0
+@ CHECK-RELOCATIONS: 0x3C R_ARM_MOVW_ABS_NC external 0x0
+@ CHECK-RELOCATIONS: 0x40 R_ARM_MOVT_ABS external 0x0
+@ CHECK-RELOCATIONS: ]
More information about the llvm-commits
mailing list