[PATCH] D84833: Implement indirect branch generation in position independent code for the RISC-V target
msizanoen1 via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 29 04:04:56 PDT 2020
msizanoen1 created this revision.
msizanoen1 added a reviewer: lenary.
msizanoen1 created this object with edit policy "Only User: msizanoen1 (msizanoen1)".
msizanoen1 added a project: LLVM.
Herald added subscribers: llvm-commits, luismarques, apazos, sameer.abuasal, pzheng, s.egerton, Jim, jocewei, PkmX, rkruppe, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, hiraditya.
msizanoen1 requested review of this revision.
Herald added a subscriber: MaskRay.
msizanoen1 changed the edit policy from "Only User: msizanoen1 (msizanoen1)" to "Subscribers".
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D84833
Files:
llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
Index: llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
+++ llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
@@ -386,9 +386,6 @@
MachineRegisterInfo &MRI = MF->getRegInfo();
const auto &TM = static_cast<const RISCVTargetMachine &>(MF->getTarget());
- if (TM.isPositionIndependent())
- report_fatal_error("Unable to insert indirect branch");
-
if (!isInt<32>(BrOffset))
report_fatal_error(
"Branch offsets outside of the signed 32-bit range not supported");
@@ -398,16 +395,29 @@
// uses the same workaround).
Register ScratchReg = MRI.createVirtualRegister(&RISCV::GPRRegClass);
auto II = MBB.end();
+ unsigned Scav;
+
+ if (TM.isPositionIndependent()) {
+ MBB.setLabelMustBeEmitted();
+ MachineInstr &AuipcMI = *BuildMI(MBB, II, DL, get(RISCV::AUIPC), ScratchReg)
+ .addMBB(&DestBB, RISCVII::MO_PCREL_HI);
+ BuildMI(MBB, II, DL, get(RISCV::PseudoBRIND))
+ .addReg(ScratchReg, RegState::Kill)
+ .addMBB(&MBB, RISCVII::MO_PCREL_LO);
+ RS->enterBasicBlockEnd(MBB);
+ Scav = RS->scavengeRegisterBackwards(RISCV::GPRRegClass,
+ AuipcMI.getIterator(), false, 0);
+ } else {
+ MachineInstr &LuiMI = *BuildMI(MBB, II, DL, get(RISCV::LUI), ScratchReg)
+ .addMBB(&DestBB, RISCVII::MO_HI);
+ BuildMI(MBB, II, DL, get(RISCV::PseudoBRIND))
+ .addReg(ScratchReg, RegState::Kill)
+ .addMBB(&DestBB, RISCVII::MO_LO);
+ RS->enterBasicBlockEnd(MBB);
+ Scav = RS->scavengeRegisterBackwards(RISCV::GPRRegClass,
+ LuiMI.getIterator(), false, 0);
+ }
- MachineInstr &LuiMI = *BuildMI(MBB, II, DL, get(RISCV::LUI), ScratchReg)
- .addMBB(&DestBB, RISCVII::MO_HI);
- BuildMI(MBB, II, DL, get(RISCV::PseudoBRIND))
- .addReg(ScratchReg, RegState::Kill)
- .addMBB(&DestBB, RISCVII::MO_LO);
-
- RS->enterBasicBlockEnd(MBB);
- unsigned Scav = RS->scavengeRegisterBackwards(RISCV::GPRRegClass,
- LuiMI.getIterator(), false, 0);
MRI.replaceRegWith(ScratchReg, Scav);
MRI.clearVirtRegs();
RS->setRegUsed(Scav);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84833.281496.patch
Type: text/x-patch
Size: 2315 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200729/42c33599/attachment.bin>
More information about the llvm-commits
mailing list