Skip to content

Commit 805ddff

Browse files
committed
replace isU*Imm() and isS*Imm() with generic template definition
1 parent 205aef9 commit 805ddff

File tree

2 files changed

+43
-44
lines changed

2 files changed

+43
-44
lines changed

llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -349,32 +349,30 @@ struct PPCOperand : public MCParsedAsmOperand {
349349
bool isImm() const override {
350350
return Kind == Immediate || Kind == Expression;
351351
}
352-
bool isU1Imm() const { return Kind == Immediate && isUInt<1>(getImm()); }
353-
bool isU2Imm() const { return Kind == Immediate && isUInt<2>(getImm()); }
354-
bool isU3Imm() const { return Kind == Immediate && isUInt<3>(getImm()); }
355-
bool isU4Imm() const { return Kind == Immediate && isUInt<4>(getImm()); }
356-
bool isU5Imm() const { return Kind == Immediate && isUInt<5>(getImm()); }
357-
bool isS5Imm() const { return Kind == Immediate && isInt<5>(getImm()); }
358-
bool isU6Imm() const { return Kind == Immediate && isUInt<6>(getImm()); }
359-
bool isU6ImmX2() const { return Kind == Immediate &&
360-
isUInt<6>(getImm()) &&
361-
(getImm() & 1) == 0; }
362-
bool isU7Imm() const { return Kind == Immediate && isUInt<7>(getImm()); }
363-
bool isU7ImmX4() const { return Kind == Immediate &&
364-
isUInt<7>(getImm()) &&
365-
(getImm() & 3) == 0; }
366-
bool isU8Imm() const { return Kind == Immediate && isUInt<8>(getImm()); }
367-
bool isU8ImmX8() const { return Kind == Immediate &&
368-
isUInt<8>(getImm()) &&
369-
(getImm() & 7) == 0; }
370-
371-
bool isU10Imm() const { return Kind == Immediate && isUInt<10>(getImm()); }
372-
bool isU12Imm() const { return Kind == Immediate && isUInt<12>(getImm()); }
352+
353+
template <uint64_t N> bool isUImm() const {
354+
return Kind == Immediate && isUInt<N>(getImm());
355+
}
356+
template <uint64_t N> bool isSImm() const {
357+
return Kind == Immediate && isInt<N>(getImm());
358+
}
359+
bool isU6ImmX2() const { return isUImm<6>() && (getImm() & 1) == 0; }
360+
bool isU7ImmX4() const { return isUImm<7>() && (getImm() & 3) == 0; }
361+
bool isU8ImmX8() const { return isUImm<8>() && (getImm() & 7) == 0; }
362+
373363
bool isU16Imm() const { return isExtImm<16>(/*Signed*/ false, 1); }
374364
bool isS16Imm() const { return isExtImm<16>(/*Signed*/ true, 1); }
375365
bool isS16ImmX4() const { return isExtImm<16>(/*Signed*/ true, 4); }
376366
bool isS16ImmX16() const { return isExtImm<16>(/*Signed*/ true, 16); }
377367
bool isS17Imm() const { return isExtImm<17>(/*Signed*/ true, 1); }
368+
bool isS34Imm() const {
369+
// Once the PC-Rel ABI is finalized, evaluate whether a 34-bit
370+
// ContextImmediate is needed.
371+
return Kind == Expression || isSImm<34>();
372+
}
373+
bool isS34ImmX16() const {
374+
return Kind == Expression || (isSImm<34>() && (getImm() & 15) == 0);
375+
}
378376

379377
bool isHashImmX8() const {
380378
// The Hash Imm form is used for instructions that check or store a hash.
@@ -384,16 +382,6 @@ struct PPCOperand : public MCParsedAsmOperand {
384382
(getImm() & 7) == 0);
385383
}
386384

387-
bool isS34ImmX16() const {
388-
return Kind == Expression ||
389-
(Kind == Immediate && isInt<34>(getImm()) && (getImm() & 15) == 0);
390-
}
391-
bool isS34Imm() const {
392-
// Once the PC-Rel ABI is finalized, evaluate whether a 34-bit
393-
// ContextImmediate is needed.
394-
return Kind == Expression || (Kind == Immediate && isInt<34>(getImm()));
395-
}
396-
397385
bool isTLSReg() const { return Kind == TLSRegister; }
398386
bool isDirectBr() const {
399387
if (Kind == Expression)
@@ -1637,7 +1625,7 @@ bool PPCAsmParser::parseInstruction(ParseInstructionInfo &Info, StringRef Name,
16371625
if (Operands.size() != 5)
16381626
return false;
16391627
PPCOperand &EHOp = (PPCOperand &)*Operands[4];
1640-
if (EHOp.isU1Imm() && EHOp.getImm() == 0)
1628+
if (EHOp.isUImm<1>() && EHOp.getImm() == 0)
16411629
Operands.pop_back();
16421630
}
16431631

@@ -1817,7 +1805,7 @@ unsigned PPCAsmParser::validateTargetOperandClass(MCParsedAsmOperand &AsmOp,
18171805
}
18181806

18191807
PPCOperand &Op = static_cast<PPCOperand &>(AsmOp);
1820-
if (Op.isU3Imm() && Op.getImm() == ImmVal)
1808+
if (Op.isUImm<3>() && Op.getImm() == ImmVal)
18211809
return Match_Success;
18221810

18231811
return Match_InvalidOperand;

llvm/lib/Target/PowerPC/PPCRegisterInfo.td

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,8 @@ def spe4rc : RegisterOperand<GPRC> {
615615
}
616616

617617
def PPCU1ImmAsmOperand : AsmOperandClass {
618-
let Name = "U1Imm"; let PredicateMethod = "isU1Imm";
618+
let Name = "U1Imm";
619+
let PredicateMethod = "isUImm<1>";
619620
let RenderMethod = "addImmOperands";
620621
}
621622
def u1imm : Operand<i32> {
@@ -626,7 +627,8 @@ def u1imm : Operand<i32> {
626627
}
627628

628629
def PPCU2ImmAsmOperand : AsmOperandClass {
629-
let Name = "U2Imm"; let PredicateMethod = "isU2Imm";
630+
let Name = "U2Imm";
631+
let PredicateMethod = "isUImm<2>";
630632
let RenderMethod = "addImmOperands";
631633
}
632634
def u2imm : Operand<i32> {
@@ -647,7 +649,8 @@ def atimm : Operand<i32> {
647649
}
648650

649651
def PPCU3ImmAsmOperand : AsmOperandClass {
650-
let Name = "U3Imm"; let PredicateMethod = "isU3Imm";
652+
let Name = "U3Imm";
653+
let PredicateMethod = "isUImm<3>";
651654
let RenderMethod = "addImmOperands";
652655
}
653656
def u3imm : Operand<i32> {
@@ -658,7 +661,8 @@ def u3imm : Operand<i32> {
658661
}
659662

660663
def PPCU4ImmAsmOperand : AsmOperandClass {
661-
let Name = "U4Imm"; let PredicateMethod = "isU4Imm";
664+
let Name = "U4Imm";
665+
let PredicateMethod = "isUImm<4>";
662666
let RenderMethod = "addImmOperands";
663667
}
664668
def u4imm : Operand<i32> {
@@ -668,7 +672,8 @@ def u4imm : Operand<i32> {
668672
let OperandType = "OPERAND_IMMEDIATE";
669673
}
670674
def PPCS5ImmAsmOperand : AsmOperandClass {
671-
let Name = "S5Imm"; let PredicateMethod = "isS5Imm";
675+
let Name = "S5Imm";
676+
let PredicateMethod = "isSImm<5>";
672677
let RenderMethod = "addImmOperands";
673678
}
674679
def s5imm : Operand<i32> {
@@ -678,7 +683,8 @@ def s5imm : Operand<i32> {
678683
let OperandType = "OPERAND_IMMEDIATE";
679684
}
680685
def PPCU5ImmAsmOperand : AsmOperandClass {
681-
let Name = "U5Imm"; let PredicateMethod = "isU5Imm";
686+
let Name = "U5Imm";
687+
let PredicateMethod = "isUImm<5>";
682688
let RenderMethod = "addImmOperands";
683689
}
684690
def u5imm : Operand<i32> {
@@ -688,7 +694,8 @@ def u5imm : Operand<i32> {
688694
let OperandType = "OPERAND_IMMEDIATE";
689695
}
690696
def PPCU6ImmAsmOperand : AsmOperandClass {
691-
let Name = "U6Imm"; let PredicateMethod = "isU6Imm";
697+
let Name = "U6Imm";
698+
let PredicateMethod = "isUImm<6>";
692699
let RenderMethod = "addImmOperands";
693700
}
694701
def u6imm : Operand<i32> {
@@ -698,7 +705,8 @@ def u6imm : Operand<i32> {
698705
let OperandType = "OPERAND_IMMEDIATE";
699706
}
700707
def PPCU7ImmAsmOperand : AsmOperandClass {
701-
let Name = "U7Imm"; let PredicateMethod = "isU7Imm";
708+
let Name = "U7Imm";
709+
let PredicateMethod = "isUImm<7>";
702710
let RenderMethod = "addImmOperands";
703711
}
704712
def u7imm : Operand<i32> {
@@ -708,7 +716,8 @@ def u7imm : Operand<i32> {
708716
let OperandType = "OPERAND_IMMEDIATE";
709717
}
710718
def PPCU8ImmAsmOperand : AsmOperandClass {
711-
let Name = "U8Imm"; let PredicateMethod = "isU8Imm";
719+
let Name = "U8Imm";
720+
let PredicateMethod = "isUImm<8>";
712721
let RenderMethod = "addImmOperands";
713722
}
714723
def u8imm : Operand<i32> {
@@ -718,7 +727,8 @@ def u8imm : Operand<i32> {
718727
let OperandType = "OPERAND_IMMEDIATE";
719728
}
720729
def PPCU10ImmAsmOperand : AsmOperandClass {
721-
let Name = "U10Imm"; let PredicateMethod = "isU10Imm";
730+
let Name = "U10Imm";
731+
let PredicateMethod = "isUImm<10>";
722732
let RenderMethod = "addImmOperands";
723733
}
724734
def u10imm : Operand<i32> {
@@ -728,7 +738,8 @@ def u10imm : Operand<i32> {
728738
let OperandType = "OPERAND_IMMEDIATE";
729739
}
730740
def PPCU12ImmAsmOperand : AsmOperandClass {
731-
let Name = "U12Imm"; let PredicateMethod = "isU12Imm";
741+
let Name = "U12Imm";
742+
let PredicateMethod = "isUImm<12>";
732743
let RenderMethod = "addImmOperands";
733744
}
734745
def u12imm : Operand<i32> {

0 commit comments

Comments
 (0)