Skip to content

Commit 9859fb6

Browse files
Addressing review comments
1 parent a0130ea commit 9859fb6

File tree

2 files changed

+55
-120
lines changed

2 files changed

+55
-120
lines changed

llvm/tools/llvm-exegesis/lib/RISCV/Target.cpp

Lines changed: 43 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
#include "RISCVInstrInfo.h"
1515

1616
// include computeAvailableFeatures and computeRequiredFeatures.
17-
#define GET_COMPUTE_FEATURES
1817
#define GET_AVAILABLE_OPCODE_CHECKER
1918
#include "RISCVGenInstrInfo.inc"
20-
#undef GET_COMPUTE_FEATURES
2119

2220
#include "llvm/CodeGen/MachineInstrBuilder.h"
2321

@@ -28,61 +26,6 @@ namespace exegesis {
2826

2927
namespace {
3028

31-
class ExegesisRISCVTarget : public ExegesisTarget {
32-
public:
33-
ExegesisRISCVTarget();
34-
35-
MCRegister findRegisterByName(const StringRef RegName) const override;
36-
37-
bool matchesArch(Triple::ArchType Arch) const override;
38-
39-
std::vector<MCInst> setRegTo(const MCSubtargetInfo &STI, unsigned Reg,
40-
const APInt &Value) const override;
41-
42-
unsigned getDefaultLoopCounterRegister(const Triple &) const override;
43-
44-
void decrementLoopCounterAndJump(MachineBasicBlock &MBB,
45-
MachineBasicBlock &TargetMBB,
46-
const MCInstrInfo &MII,
47-
unsigned LoopRegister) const override;
48-
49-
unsigned getScratchMemoryRegister(const Triple &TT) const override;
50-
51-
void fillMemoryOperands(InstructionTemplate &IT, unsigned Reg,
52-
unsigned Offset) const override;
53-
54-
ArrayRef<unsigned> getUnavailableRegisters() const override;
55-
56-
Error randomizeTargetMCOperand(const Instruction &Instr, const Variable &Var,
57-
MCOperand &AssignedValue,
58-
const BitVector &ForbiddenRegs) const override;
59-
60-
std::vector<InstructionTemplate>
61-
generateInstructionVariants(const Instruction &Instr,
62-
unsigned MaxConfigsPerOpcode) const override;
63-
};
64-
65-
ExegesisRISCVTarget::ExegesisRISCVTarget()
66-
: ExegesisTarget(ArrayRef<CpuAndPfmCounters>{},
67-
RISCV_MC::isOpcodeAvailable) {}
68-
69-
#define GET_REGISTER_MATCHER
70-
#include "RISCVGenAsmMatcher.inc"
71-
72-
MCRegister
73-
ExegesisRISCVTarget::findRegisterByName(const StringRef RegName) const {
74-
MCRegister Reg;
75-
if ((Reg = MatchRegisterName(RegName)))
76-
return Reg;
77-
if ((Reg = MatchRegisterAltName(RegName)))
78-
return Reg;
79-
return RISCV::NoRegister;
80-
}
81-
82-
bool ExegesisRISCVTarget::matchesArch(Triple::ArchType Arch) const {
83-
return Arch == Triple::riscv32 || Arch == Triple::riscv64;
84-
}
85-
8629
// Stores constant value to a general-purpose (integer) register.
8730
static std::vector<MCInst> loadIntReg(const MCSubtargetInfo &STI, unsigned Reg,
8831
const APInt &Value) {
@@ -156,6 +99,49 @@ static bool isVectorRegList(unsigned Reg) {
15699
RISCV::VRN8M1RegClass.contains(Reg);
157100
}
158101

102+
class ExegesisRISCVTarget : public ExegesisTarget {
103+
public:
104+
ExegesisRISCVTarget();
105+
106+
bool matchesArch(Triple::ArchType Arch) const override;
107+
108+
std::vector<MCInst> setRegTo(const MCSubtargetInfo &STI, unsigned Reg,
109+
const APInt &Value) const override;
110+
111+
unsigned getDefaultLoopCounterRegister(const Triple &) const override;
112+
113+
void decrementLoopCounterAndJump(MachineBasicBlock &MBB,
114+
MachineBasicBlock &TargetMBB,
115+
const MCInstrInfo &MII,
116+
unsigned LoopRegister) const override;
117+
118+
unsigned getScratchMemoryRegister(const Triple &TT) const override;
119+
120+
void fillMemoryOperands(InstructionTemplate &IT, unsigned Reg,
121+
unsigned Offset) const override;
122+
123+
ArrayRef<unsigned> getUnavailableRegisters() const override;
124+
125+
Error randomizeTargetMCOperand(const Instruction &Instr, const Variable &Var,
126+
MCOperand &AssignedValue,
127+
const BitVector &ForbiddenRegs) const override;
128+
129+
std::vector<InstructionTemplate>
130+
generateInstructionVariants(const Instruction &Instr,
131+
unsigned MaxConfigsPerOpcode) const override;
132+
};
133+
134+
ExegesisRISCVTarget::ExegesisRISCVTarget()
135+
: ExegesisTarget(ArrayRef<CpuAndPfmCounters>{},
136+
RISCV_MC::isOpcodeAvailable) {}
137+
138+
#define GET_REGISTER_MATCHER
139+
#include "RISCVGenAsmMatcher.inc"
140+
141+
bool ExegesisRISCVTarget::matchesArch(Triple::ArchType Arch) const {
142+
return Arch == Triple::riscv32 || Arch == Triple::riscv64;
143+
}
144+
159145
std::vector<MCInst> ExegesisRISCVTarget::setRegTo(const MCSubtargetInfo &STI,
160146
unsigned Reg,
161147
const APInt &Value) const {

llvm/tools/llvm-exegesis/llvm-exegesis.cpp

Lines changed: 12 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,15 @@
5050
namespace llvm {
5151
namespace exegesis {
5252

53-
struct OpcodeNameParser
54-
: public cl::parser<std::vector<std::pair<StringRef, StringRef>>> {
55-
OpcodeNameParser(cl::Option &O)
56-
: cl::parser<std::vector<std::pair<StringRef, StringRef>>>(O) {}
57-
bool parse(cl::Option &O, StringRef ArgName, const StringRef ArgValue,
58-
std::vector<std::pair<StringRef, StringRef>> &Val);
59-
};
60-
6153
static cl::opt<int> OpcodeIndex(
6254
"opcode-index",
6355
cl::desc("opcode to measure, by index, or -1 to measure all opcodes"),
6456
cl::cat(BenchmarkOptions), cl::init(0));
6557

66-
static cl::opt<std::vector<std::pair<StringRef, StringRef>>, false,
67-
OpcodeNameParser>
58+
static cl::opt<std::string>
6859
OpcodeNames("opcode-name",
69-
cl::desc("comma-separated list of opcodes to measure, "
70-
"each item is either opcode name ('OP') "
71-
"or opcode range ('OP1..OP2', ends are inclusive)"),
72-
cl::cat(BenchmarkOptions),
73-
cl::init(std::vector<std::pair<StringRef, StringRef>>()));
60+
cl::desc("comma-separated list of opcodes to measure, by name"),
61+
cl::cat(BenchmarkOptions), cl::init(""));
7462

7563
static cl::opt<std::string> SnippetsFile("snippets-file",
7664
cl::desc("code snippets to measure"),
@@ -328,27 +316,6 @@ static bool isIgnoredOpcode(const LLVMState &State, unsigned Opcode) {
328316
return getIgnoredOpcodeReasonOrNull(State, Opcode) != nullptr;
329317
}
330318

331-
bool OpcodeNameParser::parse(
332-
cl::Option &O, StringRef ArgName, const StringRef OpcodeNames,
333-
std::vector<std::pair<StringRef, StringRef>> &Val) {
334-
SmallVector<StringRef, 2> Pieces;
335-
StringRef(OpcodeNames)
336-
.split(Pieces, ",", /*MaxSplit=*/-1, /*KeepEmpty=*/false);
337-
for (const StringRef &OpcodeName : Pieces) {
338-
size_t DotDotPos = OpcodeName.find("..");
339-
if (DotDotPos == StringRef::npos) {
340-
Val.emplace_back(OpcodeName, OpcodeName);
341-
continue;
342-
}
343-
StringRef BeginOpcodeName = OpcodeName.substr(0, DotDotPos);
344-
StringRef EndOpcodeName = OpcodeName.substr(DotDotPos + 2);
345-
Val.emplace_back(BeginOpcodeName, EndOpcodeName);
346-
}
347-
if (Val.empty())
348-
return O.error("No matching opcode names");
349-
return false;
350-
}
351-
352319
// Checks that only one of OpcodeNames, OpcodeIndex or SnippetsFile is provided,
353320
// and returns the opcode indices or {} if snippets should be read from
354321
// `SnippetsFile`.
@@ -388,34 +355,16 @@ static std::vector<unsigned> getOpcodesOrDie(const LLVMState &State) {
388355
return 0u;
389356
};
390357

358+
SmallVector<StringRef, 2> Pieces;
359+
StringRef(OpcodeNames.getValue())
360+
.split(Pieces, ",", /* MaxSplit */ -1, /* KeepEmpty */ false);
391361
std::vector<unsigned> Result;
392-
for (const std::pair<StringRef, StringRef> &OpcodeName : OpcodeNames) {
393-
if (OpcodeName.first == OpcodeName.second) {
394-
if (unsigned Opcode = ResolveName(OpcodeName.first)) {
395-
Result.push_back(Opcode);
396-
continue;
397-
} else {
398-
ExitWithError(Twine("unknown opcode ").concat(OpcodeName.first));
399-
}
400-
} else {
401-
StringRef BeginOpcodeName = OpcodeName.first;
402-
unsigned BeginOpcode =
403-
BeginOpcodeName.empty() ? 1 : ResolveName(BeginOpcodeName);
404-
if (BeginOpcode == 0) {
405-
ExitWithError(Twine("unknown opcode ").concat(BeginOpcodeName));
406-
}
407-
StringRef EndOpcodeName = OpcodeName.second;
408-
unsigned EndOpcode = EndOpcodeName.empty()
409-
? State.getInstrInfo().getNumOpcodes() - 1
410-
: ResolveName(EndOpcodeName);
411-
if (EndOpcode == 0) {
412-
ExitWithError(Twine("unknown opcode ").concat(EndOpcodeName));
413-
}
414-
for (unsigned I = BeginOpcode; I <= EndOpcode; ++I) {
415-
if (!isIgnoredOpcode(State, I))
416-
Result.push_back(I);
417-
}
418-
}
362+
Result.reserve(Pieces.size());
363+
for (const StringRef &OpcodeName : Pieces) {
364+
if (unsigned Opcode = ResolveName(OpcodeName))
365+
Result.push_back(Opcode);
366+
else
367+
ExitWithError(Twine("unknown opcode ").concat(OpcodeName));
419368
}
420369
return Result;
421370
}

0 commit comments

Comments
 (0)