Skip to content

Commit b3d2c50

Browse files
[plugins,llvm] Use ADDI/C.LI instead of AUIPC
1 parent 776944e commit b3d2c50

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

icemu/plugins/replay_cache_plugin/ReplayCache.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,21 +150,21 @@ class ReplayCacheIntrinsics : public HookCode {
150150
bool checkInstruction(insn_t insn) {
151151
const auto rvinsn = (riscv_insn)insn->id;
152152
switch (rvinsn) {
153-
case RISCV_INS_AUIPC: {
153+
case RISCV_INS_C_LI: {
154154
// Extract the operands
155155
const auto rd = insn->detail->riscv.operands[0];
156-
const auto imm20 = insn->detail->riscv.operands[1];
156+
const auto imm = insn->detail->riscv.operands[1];
157157
assert(rd.type == RISCV_OP_REG);
158-
assert(imm20.type == RISCV_OP_IMM);
158+
assert(imm.type == RISCV_OP_IMM);
159159

160160
// Process in case rd is x31 (t6)
161161
if (rd.reg == RISCV_REG_X31) {
162162
// Read the immediate value
163-
const auto imm1_value = imm20.imm;
164-
p_debug << printLeader() << " AUIPC x31, " << imm1_value << ": ";
163+
const auto imm_value = imm.imm;
164+
p_debug << printLeader() << " C.LI x31, " << imm_value << ": ";
165165

166166
bool was_cache_instr = false;
167-
switch (imm1_value) {
167+
switch (imm_value) {
168168
case 0: p_debug << "start region" << std::endl;
169169
// Store the PC for verification
170170
last_region_register_value = getRegisterValue(_Arch::Register::REG_PC);
@@ -186,10 +186,10 @@ class ReplayCacheIntrinsics : public HookCode {
186186
power_failure_generator.failNext();
187187
break;
188188
default:
189-
assert(false && "AUIPC immediate for region register not recognized");
189+
assert(false && "C.LI immediate for region register not recognized");
190190
break;
191191
}
192-
// Adjust for any effects that this special AUIPC instruction might have had
192+
// Adjust for any effects that this special instruction might have had
193193
setRegisterValue(_Arch::Register::REG_X31, last_region_register_value);
194194
if (was_cache_instr)
195195
return true;

llvm/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# CLion build files
2+
/llvm-*/llvm/cmake-build-*
3+
4+
# Downloaded files
15
/llvm-*-bin
26
/llvm-*-ref
37
/.download_llvm*

llvm/llvm-16.0.2/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ BitVector RISCVRegisterInfo::getReservedRegs(const MachineFunction &MF) const {
9898
markSuperRegs(Reserved, RISCV::X4); // tp
9999
if (TFI->hasFP(MF))
100100
markSuperRegs(Reserved, RISCV::X8); // fp
101-
markSuperRegs(Reserved, RISCV::X31); // ReplayCache region register
102101
// Reserve the base register if we need to realign the stack and allocate
103102
// variable-sized objects at runtime.
104103
if (TFI->hasBP(MF))

llvm/llvm-16.0.2/llvm/lib/Target/RISCV/RISCVSubtarget.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ RISCVSubtarget::RISCVSubtarget(const Triple &TT, StringRef CPU,
8585
InstrInfo(*this), RegInfo(getHwMode()), TLInfo(TM, *this) {
8686
if (RISCV::isX18ReservedByDefault(TT))
8787
UserReservedRegister.set(RISCV::X18);
88+
UserReservedRegister.set(RISCV::X31); // ReplayCache region register
8889

8990
CallLoweringInfo.reset(new RISCVCallLowering(*getTargetLowering()));
9091
Legalizer.reset(new RISCVLegalizerInfo(*this));

0 commit comments

Comments
 (0)