[all-commits] [llvm/llvm-project] d0dcbb: [LLDB][RISCV][NFC] Rewrite instruction in algebrai...

Emmmer via All-commits all-commits at lists.llvm.org
Wed Oct 5 04:45:50 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: d0dcbb9b026af47378ad0603a45663fad9d8e9c2
      https://github.com/llvm/llvm-project/commit/d0dcbb9b026af47378ad0603a45663fad9d8e9c2
  Author: Emmmer <yjhdandan at 163.com>
  Date:   2022-10-05 (Wed, 05 Oct 2022)

  Changed paths:
    M lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.cpp
    M lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.h
    A lldb/source/Plugins/Instruction/RISCV/RISCVInstructions.h
    M lldb/unittests/Instruction/RISCV/TestRISCVEmulator.cpp

  Log Message:
  -----------
  [LLDB][RISCV][NFC] Rewrite instruction in algebraic datatype

The old approach (dedicated ExecXXX for each instruction) is not flexible and results in duplicated code when RVC kicks in.

According to the spec, every compressed instruction can be decoded to a non-compressed one. So we can lower compressed instructions to instructions we already had, which requires a decoupling between the decoder and executor.

This patch:
- use llvm::Optional and its combinators AMAP.
- use template constraints on common instruction.
- make instructions strongly-typed (no uint32_t everywhere bc it is error-prone and burdens the developer when lowering the RVC) with the help of algebraic datatype (std::variant).

Note:
(NFC) because this is more of a refactoring in preparation for RVC.

Reviewed By: DavidSpickett

Differential Revision: https://reviews.llvm.org/D135015




More information about the All-commits mailing list