Commit 614a8cb
authored
[MC][NFC] Allow MCInstrAnalysis to store state (llvm#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.1 parent b2d3c7b commit 614a8cb
File tree
2 files changed
+31
-5
lines changed- llvm
- include/llvm/MC
- tools/llvm-objdump
2 files changed
+31
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
40 | 55 | | |
41 | 56 | | |
42 | 57 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
860 | 860 | | |
861 | 861 | | |
862 | 862 | | |
863 | | - | |
| 863 | + | |
864 | 864 | | |
865 | 865 | | |
866 | 866 | | |
| |||
1283 | 1283 | | |
1284 | 1284 | | |
1285 | 1285 | | |
1286 | | - | |
1287 | | - | |
1288 | | - | |
1289 | | - | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
1290 | 1292 | | |
1291 | 1293 | | |
1292 | 1294 | | |
1293 | 1295 | | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
1294 | 1299 | | |
1295 | 1300 | | |
1296 | 1301 | | |
| |||
1316 | 1321 | | |
1317 | 1322 | | |
1318 | 1323 | | |
| 1324 | + | |
1319 | 1325 | | |
1320 | 1326 | | |
1321 | 1327 | | |
| |||
1967 | 1973 | | |
1968 | 1974 | | |
1969 | 1975 | | |
| 1976 | + | |
| 1977 | + | |
| 1978 | + | |
1970 | 1979 | | |
1971 | 1980 | | |
1972 | 1981 | | |
| |||
2183 | 2192 | | |
2184 | 2193 | | |
2185 | 2194 | | |
| 2195 | + | |
| 2196 | + | |
2186 | 2197 | | |
2187 | 2198 | | |
2188 | 2199 | | |
| |||
0 commit comments