[llvm] r338357 - [ARM] Allow automatically deducing the thumb instruction size for .inst
Martin Storsjo via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 31 02:27:08 PDT 2018
Author: mstorsjo
Date: Tue Jul 31 02:27:07 2018
New Revision: 338357
URL: http://llvm.org/viewvc/llvm-project?rev=338357&view=rev
Log:
[ARM] Allow automatically deducing the thumb instruction size for .inst
This matches GAS, that allows unsuffixed .inst for thumb.
Differential Revision: https://reviews.llvm.org/D49937
Added:
llvm/trunk/test/MC/ARM/inst-thumb-suffixes-auto.s
Modified:
llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
llvm/trunk/test/MC/ARM/inst-thumb-suffixes.s
Modified: llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp?rev=338357&r1=338356&r2=338357&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp (original)
+++ llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp Tue Jul 31 02:27:07 2018
@@ -10012,8 +10012,8 @@ bool ARMAsmParser::parseDirectiveInst(SM
case 'w':
break;
default:
- return Error(Loc, "cannot determine Thumb instruction size, "
- "use inst.n/inst.w instead");
+ Width = 0;
+ break;
}
} else {
if (Suffix)
@@ -10029,6 +10029,7 @@ bool ARMAsmParser::parseDirectiveInst(SM
return Error(Loc, "expected constant expression");
}
+ char CurSuffix = Suffix;
switch (Width) {
case 2:
if (Value->getValue() > 0xffff)
@@ -10039,11 +10040,21 @@ bool ARMAsmParser::parseDirectiveInst(SM
return Error(Loc, StringRef(Suffix ? "inst.w" : "inst") +
" operand is too big");
break;
+ case 0:
+ // Thumb mode, no width indicated. Guess from the opcode, if possible.
+ if (Value->getValue() < 0xe800)
+ CurSuffix = 'n';
+ else if (Value->getValue() >= 0xe8000000)
+ CurSuffix = 'w';
+ else
+ return Error(Loc, "cannot determine Thumb instruction size, "
+ "use inst.n/inst.w instead");
+ break;
default:
llvm_unreachable("only supported widths are 2 and 4");
}
- getTargetStreamer().emitInst(Value->getValue(), Suffix);
+ getTargetStreamer().emitInst(Value->getValue(), CurSuffix);
return false;
};
Added: llvm/trunk/test/MC/ARM/inst-thumb-suffixes-auto.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/inst-thumb-suffixes-auto.s?rev=338357&view=auto
==============================================================================
--- llvm/trunk/test/MC/ARM/inst-thumb-suffixes-auto.s (added)
+++ llvm/trunk/test/MC/ARM/inst-thumb-suffixes-auto.s Tue Jul 31 02:27:07 2018
@@ -0,0 +1,16 @@
+@ RUN: llvm-mc %s -triple armv7-linux-gnueabi -filetype asm -o - \
+@ RUN: | FileCheck %s
+@ RUN: llvm-mc %s -triple armebv7-linux-gnueabi -filetype asm -o - \
+@ RUN: | FileCheck %s
+
+ .syntax unified
+ .thumb
+
+ .align 2
+ .global inst_n
+ .type inst_n,%function
+inst_n:
+ @ bx lr, mov.w r0, #42
+ .inst 0x4770, 0xf04f002a
+@ CHECK: .inst.n 0x4770
+@ CHECK: .inst.w 0xf04f002a
Modified: llvm/trunk/test/MC/ARM/inst-thumb-suffixes.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/inst-thumb-suffixes.s?rev=338357&r1=338356&r2=338357&view=diff
==============================================================================
--- llvm/trunk/test/MC/ARM/inst-thumb-suffixes.s (original)
+++ llvm/trunk/test/MC/ARM/inst-thumb-suffixes.s Tue Jul 31 02:27:07 2018
@@ -8,6 +8,6 @@
.global suffixes_required_in_thumb
.type suffixes_required_in_thumb,%function
suffixes_required_in_thumb:
- .inst 0x0000
+ .inst 0xff00
@ CHECK-ERROR: cannot determine Thumb instruction size, use inst.n/inst.w instead
More information about the llvm-commits
mailing list