Skip to content

Commit 8e8692a

Browse files
[Exegesis][RISCV] Add RISCV support for llvm-exegesis (llvm#120467)
This patch also makes following amendments to core exegesis: * Added distinction between regular registers aliasing check and registers used as memory address in instruction. * Added scratch memory space pointer register. * General exegesis options were amended: * mattr - new option to pass a list of enabled target features Llvm-exegesis RISCV port is a result of team effort. Below everyone involved listed. Co-authored-by: Konstantin Vladimirov <[email protected]> Co-authored-by: Dmitrii Petrov <[email protected]> Co-authored-by: Dmitry Bushev <[email protected]> Co-authored-by: Mark Goncharov <[email protected]> Co-authored-by: Anastasiya Chernikova <[email protected]> Original pr: llvm#89047 --------- Co-authored-by: Kazu Hirata <[email protected]>
1 parent 26f5d1e commit 8e8692a

File tree

12 files changed

+480
-29
lines changed

12 files changed

+480
-29
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# RUN: llvm-exegesis -mode=latency -mtriple=riscv64-unknown-linux-gnu --mcpu=generic --benchmark-phase=assemble-measured-code -opcode-name=AMOAND_D -mattr="+a" | FileCheck --check-prefix=AMOAND_D %s
2+
3+
AMOAND_D: ---
4+
AMOAND_D-NEXT: mode: latency
5+
AMOAND_D-NEXT: key:
6+
AMOAND_D-NEXT: instructions:
7+
AMOAND_D-NEXT: - 'AMOAND_D [[RE01:X[0-9]+]] X10 [[RE01:X[0-9]+]]'
8+
AMOAND_D-NEXT: config: ''
9+
AMOAND_D-NEXT: register_initial_values:
10+
AMOAND_D-NEXT: - '[[RE01:X[0-9]+]]=0x0'
11+
AMOAND_D-DAG: ...
12+
13+
# RUN: llvm-exegesis -mode=latency -mtriple=riscv64-unknown-linux-gnu --mcpu=generic --benchmark-phase=assemble-measured-code -opcode-name=AMOADD_W -mattr="+a" | FileCheck --check-prefix=AMOADD_W %s
14+
15+
AMOADD_W: ---
16+
AMOADD_W-NEXT: mode: latency
17+
AMOADD_W-NEXT: key:
18+
AMOADD_W-NEXT: instructions:
19+
AMOADD_W-NEXT: - 'AMOADD_W [[RE02:X[0-9]+]] X10 [[RE02:X[0-9]+]]'
20+
AMOADD_W-NEXT: config: ''
21+
AMOADD_W-NEXT: register_initial_values:
22+
AMOADD_W-NEXT: - '[[RE02:X[0-9]+]]=0x0'
23+
AMOADD_W-DAG: ...
24+
25+
# RUN: llvm-exegesis -mode=latency -mtriple=riscv64-unknown-linux-gnu --mcpu=generic --benchmark-phase=assemble-measured-code -opcode-name=AMOMAXU_D -mattr="+a" | FileCheck --check-prefix=AMOMAXU_D %s
26+
27+
AMOMAXU_D: ---
28+
AMOMAXU_D-NEXT: mode: latency
29+
AMOMAXU_D-NEXT: key:
30+
AMOMAXU_D-NEXT: instructions:
31+
AMOMAXU_D-NEXT: - 'AMOMAXU_D [[RE03:X[0-9]+]] X10 [[RE03:X[0-9]+]]'
32+
AMOMAXU_D-NEXT: config: ''
33+
AMOMAXU_D-NEXT: register_initial_values:
34+
AMOMAXU_D-NEXT: - '[[RE03:X[0-9]+]]=0x0'
35+
AMOMAXU_D-DAG: ...
36+
37+
# RUN: llvm-exegesis -mode=latency -mtriple=riscv64-unknown-linux-gnu --mcpu=generic --benchmark-phase=assemble-measured-code -opcode-name=AMOMIN_W -mattr="+a" | FileCheck --check-prefix=AMOMIN_W %s
38+
39+
AMOMIN_W: ---
40+
AMOMIN_W-NEXT: mode: latency
41+
AMOMIN_W-NEXT: key:
42+
AMOMIN_W-NEXT: instructions:
43+
AMOMIN_W-NEXT: - 'AMOMIN_W [[RE04:X[0-9]+]] X10 [[RE04:X[0-9]+]]'
44+
AMOMIN_W-NEXT: config: ''
45+
AMOMIN_W-NEXT: register_initial_values:
46+
AMOMIN_W-NEXT: - '[[RE04:X[0-9]+]]=0x0'
47+
AMOMIN_W-DAG: ...
48+
49+
# RUN: llvm-exegesis -mode=latency -mtriple=riscv64-unknown-linux-gnu --mcpu=generic --benchmark-phase=assemble-measured-code -opcode-name=AMOXOR_D -mattr="+a" | FileCheck --check-prefix=AMOXOR_D %s
50+
51+
AMOXOR_D: ---
52+
AMOXOR_D-NEXT: mode: latency
53+
AMOXOR_D-NEXT: key:
54+
AMOXOR_D-NEXT: instructions:
55+
AMOXOR_D-NEXT: - 'AMOXOR_D [[RE05:X[0-9]+]] X10 [[RE05:X[0-9]+]]'
56+
AMOXOR_D-NEXT: config: ''
57+
AMOXOR_D-NEXT: register_initial_values:
58+
AMOXOR_D-NEXT: - '[[RE05:X[0-9]+]]=0x0'
59+
AMOXOR_D-DAG: ...
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# RUN: llvm-exegesis -mode=latency -mtriple=riscv64-unknown-linux-gnu --mcpu=generic --benchmark-phase=assemble-measured-code -opcode-name=C_ADDI -mattr=+c | FileCheck --check-prefix=C_ADDI %s
2+
3+
C_ADDI: ---
4+
C_ADDI-NEXT: mode: latency
5+
C_ADDI-NEXT: key:
6+
C_ADDI-NEXT: instructions:
7+
C_ADDI-NEXT: - 'C_ADDI [[REG01:X[0-9]+]] [[RE02:X[0-9]+]] [[IMM0:i_0x[0-9]+]]'
8+
9+
# RUN: llvm-exegesis -mode=latency -mtriple=riscv64-unknown-linux-gnu --mcpu=generic --benchmark-phase=assemble-measured-code -opcode-name=C_ADDIW -mattr=+c | FileCheck --check-prefix=C_ADDIW %s
10+
11+
C_ADDIW: ---
12+
C_ADDIW-NEXT: mode: latency
13+
C_ADDIW-NEXT: key:
14+
C_ADDIW-NEXT: instructions:
15+
C_ADDIW-NEXT: - 'C_ADDIW [[REG11:X[0-9]+]] [[RE12:X[0-9]+]] [[IMM1:i_0x[0-9]+]]'
16+
17+
# RUN: llvm-exegesis -mode=latency -mtriple=riscv64-unknown-linux-gnu --mcpu=generic --benchmark-phase=assemble-measured-code -opcode-name=C_ANDI -mattr=+c | FileCheck --check-prefix=C_ANDI %s
18+
19+
C_ANDI: ---
20+
C_ANDI-NEXT: mode: latency
21+
C_ANDI-NEXT: key:
22+
C_ANDI-NEXT: instructions:
23+
C_ANDI-NEXT: - 'C_ANDI [[REG31:X[0-9]+]] [[REG32:X[0-9]+]] [[IMM3:i_0x[0-9]+]]'
24+
25+
# RUN: llvm-exegesis -mode=latency -mtriple=riscv64-unknown-linux-gnu --mcpu=generic --benchmark-phase=assemble-measured-code -opcode-name=C_SLLI -mattr=+c | FileCheck --check-prefix=C_SLLI %s
26+
27+
C_SLLI: ---
28+
C_SLLI-NEXT: mode: latency
29+
C_SLLI-NEXT: key:
30+
C_SLLI-NEXT: instructions:
31+
C_SLLI-NEXT: - 'C_SLLI [[REG81:X[0-9]+]] [[REG82:X[0-9]+]] [[IMM8:i_0x[0-9]+]]'
32+
33+
# RUN: llvm-exegesis -mode=latency -mtriple=riscv64-unknown-linux-gnu --mcpu=generic --benchmark-phase=assemble-measured-code -opcode-name=C_SRAI -mattr=+c | FileCheck --check-prefix=C_SRAI %s
34+
35+
C_SRAI: ---
36+
C_SRAI-NEXT: mode: latency
37+
C_SRAI-NEXT: key:
38+
C_SRAI-NEXT: instructions:
39+
C_SRAI-NEXT: - 'C_SRAI [[REG91:X[0-9]+]] [[REG92:X[0-9]+]] [[IMM9:i_0x[0-9]+]]'
40+
41+
# RUN: llvm-exegesis -mode=latency -mtriple=riscv64-unknown-linux-gnu --mcpu=generic --benchmark-phase=assemble-measured-code -opcode-name=C_SRLI -mattr=+c | FileCheck --check-prefix=C_SRLI %s
42+
43+
C_SRLI: ---
44+
C_SRLI-NEXT: mode: latency
45+
C_SRLI-NEXT: key:
46+
C_SRLI-NEXT: instructions:
47+
C_SRLI-NEXT: - 'C_SRLI [[REG101:X[0-9]+]] [[REG102:X[0-9]+]] [[IMM10:i_0x[0-9]+]]'
48+
C_SRLI-DAG: ...
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# RUN: llvm-exegesis -mtriple=riscv64-unknown-linux-gnu --mcpu=generic -mode=latency --benchmark-phase=assemble-measured-code -mattr=+d -opcode-name=FADD_D | FileCheck %s
2+
3+
CHECK: ---
4+
CHECK-NEXT: mode: latency
5+
CHECK-NEXT: key:
6+
CHECK-NEXT: instructions:
7+
CHECK-NEXT: - 'FADD_D [[REG1:F[0-9]+_D]] [[REG2:F[0-9]+_D]] [[REG3:F[0-9]+_D]] i_0x7'
8+
CHECK-NEXT: config: ''
9+
CHECK-NEXT: register_initial_values:
10+
CHECK-DAG: - '[[REG1]]=0x0'
11+
CHECK-DAG: ...
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if not ("RISCV" in config.root.targets):
2+
# We need support for RISCV.
3+
config.unsupported = True

llvm/tools/llvm-exegesis/lib/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ endif()
1212
if (LLVM_TARGETS_TO_BUILD MATCHES "Mips")
1313
list(APPEND LLVM_EXEGESIS_TARGETS "Mips")
1414
endif()
15+
if(LLVM_TARGETS_TO_BUILD MATCHES "RISCV")
16+
list(APPEND LLVM_EXEGESIS_TARGETS "RISCV")
17+
endif()
1518

1619
set(LLVM_EXEGESIS_TARGETS ${LLVM_EXEGESIS_TARGETS} PARENT_SCOPE)
1720

llvm/tools/llvm-exegesis/lib/MCInstrDescView.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,12 @@ Instruction::Instruction(const MCInstrDesc *Description, StringRef Name,
9595
const BitVector *ImplDefRegs,
9696
const BitVector *ImplUseRegs,
9797
const BitVector *AllDefRegs,
98-
const BitVector *AllUseRegs)
98+
const BitVector *AllUseRegs,
99+
const BitVector *NonMemoryRegs)
99100
: Description(*Description), Name(Name), Operands(std::move(Operands)),
100101
Variables(std::move(Variables)), ImplDefRegs(*ImplDefRegs),
101102
ImplUseRegs(*ImplUseRegs), AllDefRegs(*AllDefRegs),
102-
AllUseRegs(*AllUseRegs) {}
103+
AllUseRegs(*AllUseRegs), NonMemoryRegs(*NonMemoryRegs) {}
103104

104105
std::unique_ptr<Instruction>
105106
Instruction::create(const MCInstrInfo &InstrInfo,
@@ -166,6 +167,8 @@ Instruction::create(const MCInstrInfo &InstrInfo,
166167
BitVector ImplUseRegs = RATC.emptyRegisters();
167168
BitVector AllDefRegs = RATC.emptyRegisters();
168169
BitVector AllUseRegs = RATC.emptyRegisters();
170+
BitVector NonMemoryRegs = RATC.emptyRegisters();
171+
169172
for (const auto &Op : Operands) {
170173
if (Op.isReg()) {
171174
const auto &AliasingBits = Op.getRegisterAliasing().aliasedBits();
@@ -177,6 +180,8 @@ Instruction::create(const MCInstrInfo &InstrInfo,
177180
ImplDefRegs |= AliasingBits;
178181
if (Op.isUse() && Op.isImplicit())
179182
ImplUseRegs |= AliasingBits;
183+
if (Op.isUse() && !Op.isMemory())
184+
NonMemoryRegs |= AliasingBits;
180185
}
181186
}
182187
// Can't use make_unique because constructor is private.
@@ -185,7 +190,8 @@ Instruction::create(const MCInstrInfo &InstrInfo,
185190
std::move(Variables), BVC.getUnique(std::move(ImplDefRegs)),
186191
BVC.getUnique(std::move(ImplUseRegs)),
187192
BVC.getUnique(std::move(AllDefRegs)),
188-
BVC.getUnique(std::move(AllUseRegs))));
193+
BVC.getUnique(std::move(AllUseRegs)),
194+
BVC.getUnique(std::move(NonMemoryRegs))));
189195
}
190196

191197
const Operand &Instruction::getPrimaryOperand(const Variable &Var) const {
@@ -240,6 +246,12 @@ bool Instruction::hasAliasingRegisters(
240246
ForbiddenRegisters);
241247
}
242248

249+
bool Instruction::hasAliasingNotMemoryRegisters(
250+
const BitVector &ForbiddenRegisters) const {
251+
return anyCommonExcludingForbidden(AllDefRegs, NonMemoryRegs,
252+
ForbiddenRegisters);
253+
}
254+
243255
bool Instruction::hasOneUseOrOneDef() const {
244256
return AllDefRegs.count() || AllUseRegs.count();
245257
}

llvm/tools/llvm-exegesis/lib/MCInstrDescView.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ struct Instruction {
133133
// aliasing Use and Def registers.
134134
bool hasAliasingRegisters(const BitVector &ForbiddenRegisters) const;
135135

136+
// Whether this instruction is self aliasing through some registers.
137+
// Repeating this instruction may execute sequentially by picking aliasing
138+
// Def and Not Memory Use registers. It may also execute in parallel by
139+
// picking non aliasing Def and Not Memory Use registers.
140+
bool hasAliasingNotMemoryRegisters(const BitVector &ForbiddenRegisters) const;
141+
136142
// Whether this instruction's registers alias with OtherInstr's registers.
137143
bool hasAliasingRegistersThrough(const Instruction &OtherInstr,
138144
const BitVector &ForbiddenRegisters) const;
@@ -160,12 +166,15 @@ struct Instruction {
160166
const BitVector &ImplUseRegs; // The set of aliased implicit use registers.
161167
const BitVector &AllDefRegs; // The set of all aliased def registers.
162168
const BitVector &AllUseRegs; // The set of all aliased use registers.
169+
// The set of all aliased not memory use registers.
170+
const BitVector &NonMemoryRegs;
171+
163172
private:
164173
Instruction(const MCInstrDesc *Description, StringRef Name,
165174
SmallVector<Operand, 8> Operands,
166175
SmallVector<Variable, 4> Variables, const BitVector *ImplDefRegs,
167176
const BitVector *ImplUseRegs, const BitVector *AllDefRegs,
168-
const BitVector *AllUseRegs);
177+
const BitVector *AllUseRegs, const BitVector *NonMemoryRegs);
169178
};
170179

171180
// Instructions are expensive to instantiate. This class provides a cache of
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
include_directories(
2+
${LLVM_MAIN_SRC_DIR}/lib/Target/RISCV
3+
${LLVM_BINARY_DIR}/lib/Target/RISCV
4+
)
5+
6+
set(LLVM_LINK_COMPONENTS
7+
CodeGen
8+
RISCV
9+
Exegesis
10+
Core
11+
Support
12+
)
13+
14+
add_llvm_library(LLVMExegesisRISCV
15+
DISABLE_LLVM_LINK_LLVM_DYLIB
16+
STATIC
17+
Target.cpp
18+
19+
DEPENDS
20+
intrinsics_gen
21+
RISCVCommonTableGen
22+
)

0 commit comments

Comments
 (0)