[llvm] r322481 - [AArch64][AsmParser] Cleanup isSImm7s4, isSImm7s8, (etc) functions.
Sander de Smalen via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 15 04:47:17 PST 2018
Author: s.desmalen
Date: Mon Jan 15 04:47:17 2018
New Revision: 322481
URL: http://llvm.org/viewvc/llvm-project?rev=322481&view=rev
Log:
[AArch64][AsmParser] Cleanup isSImm7s4, isSImm7s8, (etc) functions.
Reviewers: fhahn, rengolin, t.p.northover, echristo, olista01, samparker
Reviewed By: fhahn, samparker
Subscribers: samparker, aemerson, javed.absar, kristof.beyls, llvm-commits
Differential Revision: https://reviews.llvm.org/D41899
Modified:
llvm/trunk/lib/Target/AArch64/AArch64InstrFormats.td
llvm/trunk/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
Modified: llvm/trunk/lib/Target/AArch64/AArch64InstrFormats.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64InstrFormats.td?rev=322481&r1=322480&r2=322481&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64InstrFormats.td (original)
+++ llvm/trunk/lib/Target/AArch64/AArch64InstrFormats.td Mon Jan 15 04:47:17 2018
@@ -193,6 +193,7 @@ def SIMDImmType10Operand : AsmOperandCla
def SImm10s8Operand : AsmOperandClass {
let Name = "SImm10s8";
let DiagnosticType = "InvalidMemoryIndexedSImm10";
+ let PredicateMethod = "isSImmScaled<10, 8>";
}
//===----------------------------------------------------------------------===//
@@ -221,19 +222,23 @@ def adrlabel : Operand<i64> {
let ParserMatchClass = AdrOperand;
}
+class SImmOperand<int width> : AsmOperandClass {
+ let Name = "SImm" # width;
+ let DiagnosticType = "InvalidMemoryIndexedSImm" # width;
+ let RenderMethod = "addImmOperands";
+ let PredicateMethod = "isSImm<" # width # ">";
+}
+
def simm10Scaled : Operand<i64> {
let ParserMatchClass = SImm10s8Operand;
let DecoderMethod = "DecodeSImm<10>";
let PrintMethod = "printImmScale<8>";
}
-// simm9 predicate - True if the immediate is in the range [-256, 255].
-def SImm9Operand : AsmOperandClass {
- let Name = "SImm9";
- let DiagnosticType = "InvalidMemoryIndexedSImm9";
-}
+def SImm9Operand : SImmOperand<9>;
def simm9 : Operand<i64>, ImmLeaf<i64, [{ return Imm >= -256 && Imm < 256; }]> {
let ParserMatchClass = SImm9Operand;
+ let DecoderMethod = "DecodeSImm<9>";
}
// simm7sN predicate - True if the immediate is a multiple of N in the range
@@ -241,6 +246,7 @@ def simm9 : Operand<i64>, ImmLeaf<i64, [
class SImm7Scaled<int Scale> : AsmOperandClass {
let Name = "SImm7s" # Scale;
let DiagnosticType = "InvalidMemoryIndexed" # Scale # "SImm7";
+ let PredicateMethod = "isSImmScaled<7, " # Scale # ">";
}
def SImm7s4Operand : SImm7Scaled<4>;
Modified: llvm/trunk/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp?rev=322481&r1=322480&r2=322481&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp Mon Jan 15 04:47:17 2018
@@ -470,50 +470,22 @@ public:
bool isImm() const override { return Kind == k_Immediate; }
bool isMem() const override { return false; }
- bool isSImm9() const {
- if (!isImm())
- return false;
- const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
- if (!MCE)
- return false;
- int64_t Val = MCE->getValue();
- return (Val >= -256 && Val < 256);
- }
- bool isSImm10s8() const {
- if (!isImm())
- return false;
- const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
- if (!MCE)
- return false;
- int64_t Val = MCE->getValue();
- return (Val >= -4096 && Val < 4089 && (Val & 7) == 0);
- }
- bool isSImm7s4() const {
- if (!isImm())
- return false;
- const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
- if (!MCE)
- return false;
- int64_t Val = MCE->getValue();
- return (Val >= -256 && Val <= 252 && (Val & 3) == 0);
- }
- bool isSImm7s8() const {
- if (!isImm())
- return false;
- const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
- if (!MCE)
- return false;
- int64_t Val = MCE->getValue();
- return (Val >= -512 && Val <= 504 && (Val & 7) == 0);
- }
- bool isSImm7s16() const {
+
+ template <int Width> bool isSImm() const { return isSImmScaled<Width, 1>(); }
+
+ template <int Bits, int Scale> bool isSImmScaled() const {
if (!isImm())
return false;
const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(getImm());
if (!MCE)
return false;
+
+ int64_t Shift = Bits - 1;
+ int64_t MinVal = (int64_t(1) << Shift) * -Scale;
+ int64_t MaxVal = ((int64_t(1) << Shift) - 1) * Scale;
+
int64_t Val = MCE->getValue();
- return (Val >= -1024 && Val <= 1008 && (Val & 15) == 0);
+ return Val >= MinVal && Val <= MaxVal && (Val % Scale) == 0;
}
bool isSymbolicUImm12Offset(const MCExpr *Expr, unsigned Scale) const {
@@ -1081,7 +1053,7 @@ public:
// ambiguity in the matcher.
template<int Width>
bool isSImm9OffsetFB() const {
- return isSImm9() && !isUImm12Offset<Width / 8>();
+ return isSImm<9>() && !isUImm12Offset<Width / 8>();
}
bool isAdrpLabel() const {
More information about the llvm-commits
mailing list