-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[NFC][MC][ARM] Reorder decoder functions N/N #158767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
You can test this locally with the following command:git-clang-format --diff origin/main HEAD --extensions cpp -- llvm/lib/Target/ARM/Disassembler/ARMDisassembler.cpp
View the diff from clang-format here.diff --git a/llvm/lib/Target/ARM/Disassembler/ARMDisassembler.cpp b/llvm/lib/Target/ARM/Disassembler/ARMDisassembler.cpp
index 8b5e9ba3c..a8c5ec962 100644
--- a/llvm/lib/Target/ARM/Disassembler/ARMDisassembler.cpp
+++ b/llvm/lib/Target/ARM/Disassembler/ARMDisassembler.cpp
@@ -3212,18 +3212,18 @@ static DecodeStatus DecodeT2AddrModeImm8(MCInst &Inst, unsigned Val,
// Some instructions always use an additive offset.
switch (Inst.getOpcode()) {
- case ARM::t2LDRT:
- case ARM::t2LDRBT:
- case ARM::t2LDRHT:
- case ARM::t2LDRSBT:
- case ARM::t2LDRSHT:
- case ARM::t2STRT:
- case ARM::t2STRBT:
- case ARM::t2STRHT:
- imm |= 0x100;
- break;
- default:
- break;
+ case ARM::t2LDRT:
+ case ARM::t2LDRBT:
+ case ARM::t2LDRHT:
+ case ARM::t2LDRSBT:
+ case ARM::t2LDRSHT:
+ case ARM::t2STRT:
+ case ARM::t2STRBT:
+ case ARM::t2STRHT:
+ imm |= 0x100;
+ break;
+ default:
+ break;
}
if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
|
@llvm/pr-subscribers-backend-arm Author: Rahul Joshi (jurahul) ChangesMove Work on #156560 : Reorder ARM disassembler decode functions to eliminate forward declarations Full diff: https://github.com/llvm/llvm-project/pull/158767.diff 1 Files Affected:
diff --git a/llvm/lib/Target/ARM/Disassembler/ARMDisassembler.cpp b/llvm/lib/Target/ARM/Disassembler/ARMDisassembler.cpp
index 1d19bc89ccf92..8b5e9ba3c6d1e 100644
--- a/llvm/lib/Target/ARM/Disassembler/ARMDisassembler.cpp
+++ b/llvm/lib/Target/ARM/Disassembler/ARMDisassembler.cpp
@@ -159,12 +159,6 @@ class ARMDisassembler : public MCDisassembler {
} // end anonymous namespace
-// Forward declare these because the autogenerated code will reference them.
-// Definitions are further down.
-static DecodeStatus DecodeT2AddrModeImm8(MCInst &Inst, unsigned Val,
- uint64_t Address,
- const MCDisassembler *Decoder);
-
typedef DecodeStatus OperandDecoder(MCInst &Inst, unsigned Val,
uint64_t Address,
const MCDisassembler *Decoder);
@@ -3181,6 +3175,65 @@ static DecodeStatus DecodeT2LoadShift(MCInst &Inst, unsigned Insn,
return S;
}
+static DecodeStatus DecodeT2Imm8(MCInst &Inst, unsigned Val, uint64_t Address,
+ const MCDisassembler *Decoder) {
+ int imm = Val & 0xFF;
+ if (Val == 0)
+ imm = INT32_MIN;
+ else if (!(Val & 0x100))
+ imm *= -1;
+ Inst.addOperand(MCOperand::createImm(imm));
+
+ return MCDisassembler::Success;
+}
+
+static DecodeStatus DecodeT2AddrModeImm8(MCInst &Inst, unsigned Val,
+ uint64_t Address,
+ const MCDisassembler *Decoder) {
+ DecodeStatus S = MCDisassembler::Success;
+
+ unsigned Rn = fieldFromInstruction(Val, 9, 4);
+ unsigned imm = fieldFromInstruction(Val, 0, 9);
+
+ // Thumb stores cannot use PC as dest register.
+ switch (Inst.getOpcode()) {
+ case ARM::t2STRT:
+ case ARM::t2STRBT:
+ case ARM::t2STRHT:
+ case ARM::t2STRi8:
+ case ARM::t2STRHi8:
+ case ARM::t2STRBi8:
+ if (Rn == 15)
+ return MCDisassembler::Fail;
+ break;
+ default:
+ break;
+ }
+
+ // Some instructions always use an additive offset.
+ switch (Inst.getOpcode()) {
+ case ARM::t2LDRT:
+ case ARM::t2LDRBT:
+ case ARM::t2LDRHT:
+ case ARM::t2LDRSBT:
+ case ARM::t2LDRSHT:
+ case ARM::t2STRT:
+ case ARM::t2STRBT:
+ case ARM::t2STRHT:
+ imm |= 0x100;
+ break;
+ default:
+ break;
+ }
+
+ if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
+ return MCDisassembler::Fail;
+ if (!Check(S, DecodeT2Imm8(Inst, imm, Address, Decoder)))
+ return MCDisassembler::Fail;
+
+ return S;
+}
+
static DecodeStatus DecodeT2LoadImm8(MCInst &Inst, unsigned Insn,
uint64_t Address,
const MCDisassembler *Decoder) {
@@ -3490,18 +3543,6 @@ static DecodeStatus DecodeT2AddrModeImm0_1020s4(MCInst &Inst, unsigned Val,
return S;
}
-static DecodeStatus DecodeT2Imm8(MCInst &Inst, unsigned Val, uint64_t Address,
- const MCDisassembler *Decoder) {
- int imm = Val & 0xFF;
- if (Val == 0)
- imm = INT32_MIN;
- else if (!(Val & 0x100))
- imm *= -1;
- Inst.addOperand(MCOperand::createImm(imm));
-
- return MCDisassembler::Success;
-}
-
template <int shift>
static DecodeStatus DecodeT2Imm7(MCInst &Inst, unsigned Val, uint64_t Address,
const MCDisassembler *Decoder) {
@@ -3517,53 +3558,6 @@ static DecodeStatus DecodeT2Imm7(MCInst &Inst, unsigned Val, uint64_t Address,
return MCDisassembler::Success;
}
-static DecodeStatus DecodeT2AddrModeImm8(MCInst &Inst, unsigned Val,
- uint64_t Address,
- const MCDisassembler *Decoder) {
- DecodeStatus S = MCDisassembler::Success;
-
- unsigned Rn = fieldFromInstruction(Val, 9, 4);
- unsigned imm = fieldFromInstruction(Val, 0, 9);
-
- // Thumb stores cannot use PC as dest register.
- switch (Inst.getOpcode()) {
- case ARM::t2STRT:
- case ARM::t2STRBT:
- case ARM::t2STRHT:
- case ARM::t2STRi8:
- case ARM::t2STRHi8:
- case ARM::t2STRBi8:
- if (Rn == 15)
- return MCDisassembler::Fail;
- break;
- default:
- break;
- }
-
- // Some instructions always use an additive offset.
- switch (Inst.getOpcode()) {
- case ARM::t2LDRT:
- case ARM::t2LDRBT:
- case ARM::t2LDRHT:
- case ARM::t2LDRSBT:
- case ARM::t2LDRSHT:
- case ARM::t2STRT:
- case ARM::t2STRBT:
- case ARM::t2STRHT:
- imm |= 0x100;
- break;
- default:
- break;
- }
-
- if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
- return MCDisassembler::Fail;
- if (!Check(S, DecodeT2Imm8(Inst, imm, Address, Decoder)))
- return MCDisassembler::Fail;
-
- return S;
-}
-
template <int shift>
static DecodeStatus DecodeTAddrModeImm7(MCInst &Inst, unsigned Val,
uint64_t Address,
|
@davemgreen @ostannard gentle ping. This is the last one of this nature and I can then close the LLVM issue as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice. LGTM.
Move
DecodeT2AddrModeImm8
andDecodeT2Imm8
definition before its first use and eliminate the last remaining forward declarations of decode functions.Work on #156560 : Reorder ARM disassembler decode functions to eliminate forward declarations