[all-commits] [llvm/llvm-project] 614a8c: [MC][NFC] Allow MCInstrAnalysis to store state (#6...

Job Noorman via All-commits all-commits at lists.llvm.org
Thu Oct 19 23:09:14 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 614a8cbfd155b706688cfca0101f8d99988a9871
      https://github.com/llvm/llvm-project/commit/614a8cbfd155b706688cfca0101f8d99988a9871
  Author: Job Noorman <jnoorman at igalia.com>
  Date:   2023-10-20 (Fri, 20 Oct 2023)

  Changed paths:
    M llvm/include/llvm/MC/MCInstrAnalysis.h
    M llvm/tools/llvm-objdump/llvm-objdump.cpp

  Log Message:
  -----------
  [MC][NFC] Allow MCInstrAnalysis to store state (#65479)

Currently, all the analysis functions provided by `MCInstrAnalysis` work
on a single instruction. On some targets, this limits the kind of
instructions that can be successfully analyzed as common constructs may
need multiple instructions.

For example, a typical call sequence on RISC-V uses a auipc+jalr pair.
In order to analyse the jalr inside `evaluateBranch`, information about
the corresponding auipc is needed. Similarly, AArch64 uses adrp+ldr
pairs to access globals.

This patch proposes to add state to `MCInstrAnalysis` to support these
use cases. Two new virtual methods are added:
- `updateState`: takes an instruction and its address. This methods
should be called by clients on every instruction and allows targets to
store whatever information they need to analyse future instructions.
- `resetState`: clears the state whenever it becomes irrelevant. Clients
could call this, for example, when starting to disassemble a new
function.

Note that the default implementations do nothing so this patch is NFC.
No actual state is stored inside `MCInstrAnalysis`; deciding the
structure of the state is left to the targets.

This patch also modifies llvm-objdump to use the new interface.

This patch is an alternative to
[D116677](https://reviews.llvm.org/D116677) and the idea of storing
state in `MCInstrAnalysis` was first discussed there.




More information about the All-commits mailing list