Skip to content

Commit 11c50dc

Browse files
committed
Pass subtargetinfo as function argument
Follows up on discussion from linked pull request that has been closed. Essentially, not having a target specific factory method
1 parent 5e1cf12 commit 11c50dc

File tree

4 files changed

+13
-17
lines changed

4 files changed

+13
-17
lines changed

llvm/include/llvm/MC/MCInstrAnalysis.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/MC/MCInstrDesc.h"
2020
#include "llvm/MC/MCInstrInfo.h"
2121
#include "llvm/MC/MCRegisterInfo.h"
22+
#include "llvm/MC/MCSubtargetInfo.h"
2223
#include "llvm/Support/Compiler.h"
2324
#include <cstdint>
2425
#include <vector>
@@ -185,7 +186,7 @@ class LLVM_ABI MCInstrAnalysis {
185186
/// Given an instruction that accesses a memory address, try to compute
186187
/// the target address. Return true on success, and the address in \p Target.
187188
virtual bool evaluateInstruction(const MCInst &Inst, uint64_t Addr,
188-
uint64_t Size, uint64_t &Target) const;
189+
uint64_t Size, uint64_t &Target, const MCSubtargetInfo &STI) const;
189190

190191
/// Given an instruction tries to get the address of a memory operand. Returns
191192
/// the address on success.

llvm/lib/MC/MCInstrAnalysis.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ bool MCInstrAnalysis::evaluateBranch(const MCInst & /*Inst*/, uint64_t /*Addr*/,
3232

3333
bool MCInstrAnalysis::evaluateInstruction(const MCInst &Inst, uint64_t Addr,
3434
uint64_t Size,
35-
uint64_t &Target) const {
35+
uint64_t &Target,
36+
const MCSubtargetInfo &STI) const {
3637
return false;
3738
}
3839

llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCTargetDesc.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ namespace {
131131
class RISCVMCInstrAnalysis : public MCInstrAnalysis {
132132
int64_t GPRState[31] = {};
133133
std::bitset<31> GPRValidMask;
134-
unsigned int ArchRegWidth;
135134

136135
static bool isGPR(MCRegister Reg) {
137136
return Reg >= RISCV::X0 && Reg <= RISCV::X31;
@@ -168,8 +167,8 @@ class RISCVMCInstrAnalysis : public MCInstrAnalysis {
168167
}
169168

170169
public:
171-
explicit RISCVMCInstrAnalysis(const MCInstrInfo *Info, unsigned int ArchRegWidth)
172-
: MCInstrAnalysis(Info), ArchRegWidth(ArchRegWidth) {}
170+
explicit RISCVMCInstrAnalysis(const MCInstrInfo *Info)
171+
: MCInstrAnalysis(Info) {}
173172

174173
void resetState() override { GPRValidMask.reset(); }
175174

@@ -245,7 +244,8 @@ class RISCVMCInstrAnalysis : public MCInstrAnalysis {
245244
}
246245

247246
bool evaluateInstruction(const MCInst &Inst, uint64_t Addr, uint64_t Size,
248-
uint64_t &Target) const override {
247+
uint64_t &Target, const MCSubtargetInfo &STI) const override {
248+
unsigned int ArchRegWidth = STI.getTargetTriple().getArchPointerBitWidth();
249249
switch(Inst.getOpcode()) {
250250
default:
251251
return false;
@@ -420,12 +420,8 @@ class RISCVMCInstrAnalysis : public MCInstrAnalysis {
420420

421421
} // end anonymous namespace
422422

423-
static MCInstrAnalysis *createRISCV32InstrAnalysis(const MCInstrInfo *Info) {
424-
return new RISCVMCInstrAnalysis(Info, 32);
425-
}
426-
427-
static MCInstrAnalysis *createRISCV64InstrAnalysis(const MCInstrInfo *Info) {
428-
return new RISCVMCInstrAnalysis(Info, 64);
423+
static MCInstrAnalysis *createRISCVInstrAnalysis(const MCInstrInfo *Info) {
424+
return new RISCVMCInstrAnalysis(Info);
429425
}
430426

431427
extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeRISCVTargetMC() {
@@ -446,9 +442,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeRISCVTargetMC() {
446442
// Register the null target streamer.
447443
TargetRegistry::RegisterNullTargetStreamer(*T,
448444
createRISCVNullTargetStreamer);
445+
TargetRegistry::RegisterMCInstrAnalysis(*T,
446+
createRISCVInstrAnalysis);
449447
}
450-
TargetRegistry::RegisterMCInstrAnalysis(getTheRISCV32Target(),
451-
createRISCV32InstrAnalysis);
452-
TargetRegistry::RegisterMCInstrAnalysis(getTheRISCV64Target(),
453-
createRISCV64InstrAnalysis);
454448
}

llvm/tools/llvm-objdump/llvm-objdump.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2358,7 +2358,7 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
23582358
bool PrintTarget = DT->InstrAnalysis->evaluateBranch(
23592359
Inst, SectionAddr + Index, Size, Target) ||
23602360
DT->InstrAnalysis->evaluateInstruction(
2361-
Inst, SectionAddr + Index, Size, Target);
2361+
Inst, SectionAddr + Index, Size, Target, *DT->SubtargetInfo);
23622362
if (!PrintTarget) {
23632363
if (std::optional<uint64_t> MaybeTarget =
23642364
DT->InstrAnalysis->evaluateMemoryOperandAddress(

0 commit comments

Comments
 (0)