[llvm] [JITLink][AArch32] Add TableGen Backend for Instr Encodings (PR #76996)
Stefan Gränitz via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 8 05:11:40 PST 2024
================
@@ -164,17 +164,77 @@ struct HalfWords {
const uint16_t Lo; // Second halfword
};
+enum InstrName {
+
+#define GET_INSTR(name, opcode, opcode_mask, imm_mask, reg_mask) name,
+
+#include "llvm/ExecutionEngine/JITLink/JITLinkAArch32.inc"
+#undef GET_INSTR
+ INSTR_COUNT,
+ NONE = INSTR_COUNT,
+};
+
+constexpr InstrName getInstrFromJITLinkEdgeKind(Edge::Kind Kind) {
+ switch (Kind) {
+ case Arm_Call:
+ return InstrName::NONE;
+ case aarch32::Arm_Jump24:
+ return InstrName::NONE;
+ case aarch32::Arm_MovwAbsNC:
+ return InstrName::MOVi16;
+ case aarch32::Arm_MovtAbs:
+ return InstrName::MOVTi16;
+ case aarch32::Thumb_Call:
+ return InstrName::NONE;
+ case aarch32::Thumb_Jump24:
+ return InstrName::NONE;
+ case aarch32::Thumb_MovwAbsNC:
+ case aarch32::Thumb_MovwPrelNC:
+ return InstrName::t2MOVi16;
+ case aarch32::Thumb_MovtAbs:
+ case aarch32::Thumb_MovtPrel:
+ return InstrName::t2MOVTi16;
+ default:
+ return InstrName::NONE;
+ }
+}
+
+struct InstrInfo {
+ uint32_t Opcode;
+ uint32_t OpcodeMask;
+ uint32_t ImmMask;
+ uint32_t RegMask;
+};
+
+static constexpr InstrInfo InstrTable[INSTR_COUNT] = {
+#define GET_INSTR(name, opcode, opcode_mask, imm_mask, reg_mask) \
+ {opcode, opcode_mask, imm_mask, reg_mask},
+#include "llvm/ExecutionEngine/JITLink/JITLinkAArch32.inc"
+#undef GET_INSTR
+};
+
/// FixupInfo base class is required for dynamic lookups.
struct FixupInfoBase {
static const FixupInfoBase *getDynFixupInfo(Edge::Kind K);
virtual ~FixupInfoBase() {}
};
-/// FixupInfo checks for Arm edge kinds work on 32-bit words
-struct FixupInfoArm : public FixupInfoBase {
+struct FixupInfoArmBase : public FixupInfoBase {
bool (*checkOpcode)(uint32_t Wd) = nullptr;
};
+/// FixupInfo checks for Arm edge kinds work on 32-bit words
+template <EdgeKind_aarch32 Kind> struct FixupInfoArm : public FixupInfoArmBase {
+ static constexpr uint32_t Opcode =
+ InstrTable[getInstrFromJITLinkEdgeKind(Kind)].Opcode;
----------------
weliveindetail wrote:
Can we turn these into something like `getTableGenInfoArm(Kind).Opcode`? Then `getInstrFromJITLinkEdgeKind()` could become an implementation detail and for Thumb we can also convert to `HalfWords` in there.
https://github.com/llvm/llvm-project/pull/76996
More information about the llvm-commits
mailing list