llvm.org GIT mirror llvm / 3009eea
[ARM] Tidy-up condition-code support functions Move condition code support functions to Utils and remove code duplication. Reviewed by: @fhahn, @asb Differential Revision: https://reviews.llvm.org/D37179 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@311860 91177308-0d34-0410-b5e6-96231b3b80d8 Javed Absar 2 years ago
3 changed file(s) with 89 addition(s) and 102 deletion(s). Raw diff Collapse all Expand all
33383338 const AsmToken &Tok = Parser.getTok();
33393339 if (!Tok.is(AsmToken::Identifier))
33403340 return MatchOperand_NoMatch;
3341 unsigned CC = StringSwitch(Tok.getString().lower())
3342 .Case("eq", ARMCC::EQ)
3343 .Case("ne", ARMCC::NE)
3344 .Case("hs", ARMCC::HS)
3345 .Case("cs", ARMCC::HS)
3346 .Case("lo", ARMCC::LO)
3347 .Case("cc", ARMCC::LO)
3348 .Case("mi", ARMCC::MI)
3349 .Case("pl", ARMCC::PL)
3350 .Case("vs", ARMCC::VS)
3351 .Case("vc", ARMCC::VC)
3352 .Case("hi", ARMCC::HI)
3353 .Case("ls", ARMCC::LS)
3354 .Case("ge", ARMCC::GE)
3355 .Case("lt", ARMCC::LT)
3356 .Case("gt", ARMCC::GT)
3357 .Case("le", ARMCC::LE)
3358 .Case("al", ARMCC::AL)
3359 .Default(~0U);
3341 unsigned CC = ARMCondCodeFromString(Tok.getString());
33603342 if (CC == ~0U)
33613343 return MatchOperand_NoMatch;
33623344 Parser.Lex(); // Eat the token.
53395321 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
53405322 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
53415323 Mnemonic != "sbcs" && Mnemonic != "rscs") {
5342 unsigned CC = StringSwitch(Mnemonic.substr(Mnemonic.size()-2))
5343 .Case("eq", ARMCC::EQ)
5344 .Case("ne", ARMCC::NE)
5345 .Case("hs", ARMCC::HS)
5346 .Case("cs", ARMCC::HS)
5347 .Case("lo", ARMCC::LO)
5348 .Case("cc", ARMCC::LO)
5349 .Case("mi", ARMCC::MI)
5350 .Case("pl", ARMCC::PL)
5351 .Case("vs", ARMCC::VS)
5352 .Case("vc", ARMCC::VC)
5353 .Case("hi", ARMCC::HI)
5354 .Case("ls", ARMCC::LS)
5355 .Case("ge", ARMCC::GE)
5356 .Case("lt", ARMCC::LT)
5357 .Case("gt", ARMCC::GT)
5358 .Case("le", ARMCC::LE)
5359 .Case("al", ARMCC::AL)
5360 .Default(~0U);
5324 unsigned CC = ARMCondCodeFromString(Mnemonic.substr(Mnemonic.size()-2));
53615325 if (CC != ~0U) {
53625326 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
53635327 PredicationCode = CC;
1818
1919 #include "ARMMCTargetDesc.h"
2020 #include "llvm/Support/ErrorHandling.h"
21 #include "Utils/ARMBaseInfo.h"
2122
2223 namespace llvm {
23
24 // Enums corresponding to ARM condition codes
25 namespace ARMCC {
26 // The CondCodes constants map directly to the 4-bit encoding of the
27 // condition field for predicated instructions.
28 enum CondCodes { // Meaning (integer) Meaning (floating-point)
29 EQ, // Equal Equal
30 NE, // Not equal Not equal, or unordered
31 HS, // Carry set >, ==, or unordered
32 LO, // Carry clear Less than
33 MI, // Minus, negative Less than
34 PL, // Plus, positive or zero >, ==, or unordered
35 VS, // Overflow Unordered
36 VC, // No overflow Not unordered
37 HI, // Unsigned higher Greater than, or unordered
38 LS, // Unsigned lower or same Less than or equal
39 GE, // Greater than or equal Greater than or equal
40 LT, // Less than Less than, or unordered
41 GT, // Greater than Greater than
42 LE, // Less than or equal <, ==, or unordered
43 AL // Always (unconditional) Always (unconditional)
44 };
45
46 inline static CondCodes getOppositeCondition(CondCodes CC) {
47 switch (CC) {
48 default: llvm_unreachable("Unknown condition code");
49 case EQ: return NE;
50 case NE: return EQ;
51 case HS: return LO;
52 case LO: return HS;
53 case MI: return PL;
54 case PL: return MI;
55 case VS: return VC;
56 case VC: return VS;
57 case HI: return LS;
58 case LS: return HI;
59 case GE: return LT;
60 case LT: return GE;
61 case GT: return LE;
62 case LE: return GT;
63 }
64 }
65 } // namespace ARMCC
66
67 inline static const char *ARMCondCodeToString(ARMCC::CondCodes CC) {
68 switch (CC) {
69 case ARMCC::EQ: return "eq";
70 case ARMCC::NE: return "ne";
71 case ARMCC::HS: return "hs";
72 case ARMCC::LO: return "lo";
73 case ARMCC::MI: return "mi";
74 case ARMCC::PL: return "pl";
75 case ARMCC::VS: return "vs";
76 case ARMCC::VC: return "vc";
77 case ARMCC::HI: return "hi";
78 case ARMCC::LS: return "ls";
79 case ARMCC::GE: return "ge";
80 case ARMCC::LT: return "lt";
81 case ARMCC::GT: return "gt";
82 case ARMCC::LE: return "le";
83 case ARMCC::AL: return "al";
84 }
85 llvm_unreachable("Unknown condition code");
86 }
8724
8825 namespace ARM_PROC {
8926 enum IMod {
2222 #include "MCTargetDesc/ARMMCTargetDesc.h"
2323
2424 namespace llvm {
25
26 // Enums corresponding to ARM condition codes
27 namespace ARMCC {
28 // The CondCodes constants map directly to the 4-bit encoding of the
29 // condition field for predicated instructions.
30 enum CondCodes { // Meaning (integer) Meaning (floating-point)
31 EQ, // Equal Equal
32 NE, // Not equal Not equal, or unordered
33 HS, // Carry set >, ==, or unordered
34 LO, // Carry clear Less than
35 MI, // Minus, negative Less than
36 PL, // Plus, positive or zero >, ==, or unordered
37 VS, // Overflow Unordered
38 VC, // No overflow Not unordered
39 HI, // Unsigned higher Greater than, or unordered
40 LS, // Unsigned lower or same Less than or equal
41 GE, // Greater than or equal Greater than or equal
42 LT, // Less than Less than, or unordered
43 GT, // Greater than Greater than
44 LE, // Less than or equal <, ==, or unordered
45 AL // Always (unconditional) Always (unconditional)
46 };
47
48 inline static CondCodes getOppositeCondition(CondCodes CC) {
49 switch (CC) {
50 default: llvm_unreachable("Unknown condition code");
51 case EQ: return NE;
52 case NE: return EQ;
53 case HS: return LO;
54 case LO: return HS;
55 case MI: return PL;
56 case PL: return MI;
57 case VS: return VC;
58 case VC: return VS;
59 case HI: return LS;
60 case LS: return HI;
61 case GE: return LT;
62 case LT: return GE;
63 case GT: return LE;
64 case LE: return GT;
65 }
66 }
67 } // end namespace ARMCC
68
69 inline static const char *ARMCondCodeToString(ARMCC::CondCodes CC) {
70 switch (CC) {
71 case ARMCC::EQ: return "eq";
72 case ARMCC::NE: return "ne";
73 case ARMCC::HS: return "hs";
74 case ARMCC::LO: return "lo";
75 case ARMCC::MI: return "mi";
76 case ARMCC::PL: return "pl";
77 case ARMCC::VS: return "vs";
78 case ARMCC::VC: return "vc";
79 case ARMCC::HI: return "hi";
80 case ARMCC::LS: return "ls";
81 case ARMCC::GE: return "ge";
82 case ARMCC::LT: return "lt";
83 case ARMCC::GT: return "gt";
84 case ARMCC::LE: return "le";
85 case ARMCC::AL: return "al";
86 }
87 llvm_unreachable("Unknown condition code");
88 }
89
90 inline static unsigned ARMCondCodeFromString(StringRef CC) {
91 return StringSwitch(CC.lower())
92 .Case("eq", ARMCC::EQ)
93 .Case("ne", ARMCC::NE)
94 .Case("hs", ARMCC::HS)
95 .Case("cs", ARMCC::HS)
96 .Case("lo", ARMCC::LO)
97 .Case("cc", ARMCC::LO)
98 .Case("mi", ARMCC::MI)
99 .Case("pl", ARMCC::PL)
100 .Case("vs", ARMCC::VS)
101 .Case("vc", ARMCC::VC)
102 .Case("hi", ARMCC::HI)
103 .Case("ls", ARMCC::LS)
104 .Case("ge", ARMCC::GE)
105 .Case("lt", ARMCC::LT)
106 .Case("gt", ARMCC::GT)
107 .Case("le", ARMCC::LE)
108 .Case("al", ARMCC::AL)
109 .Default(~0U);
110 }
25111
26112 // System Registers
27113 namespace ARMSysReg {