Skip to content

Commit f4778a3

Browse files
committed
Use MachineJumpTableInfo directly for alignment and position independent.
1 parent a356b83 commit f4778a3

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

llvm/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,10 +500,15 @@ bool RISCVInstructionSelector::select(MachineInstr &MI) {
500500
}
501501
case TargetOpcode::G_BRJT: {
502502
// FIXME: Move to legalization?
503-
unsigned EntrySize =
504-
MF.getJumpTableInfo()->getEntrySize(MF.getDataLayout());
503+
const MachineJumpTableInfo *MJTI = MF.getJumpTableInfo();
504+
unsigned EntrySize = MJTI->getEntrySize(MF.getDataLayout());
505505
assert((EntrySize == 4 || (Subtarget->is64Bit() && EntrySize == 8)) &&
506506
"Unsupported jump-table entry size");
507+
assert(
508+
(MJTI->getEntryKind() == MachineJumpTableInfo::EK_LabelDifference32 ||
509+
MJTI->getEntryKind() == MachineJumpTableInfo::EK_Custom32 ||
510+
MJTI->getEntryKind() == MachineJumpTableInfo::EK_BlockAddress) &&
511+
"Unexpected jump-table entry kind");
507512

508513
auto SLL =
509514
MIB.buildInstr(RISCV::SLLI, {&RISCV::GPRRegClass}, {MI.getOperand(2)})
@@ -523,11 +528,11 @@ bool RISCVInstructionSelector::select(MachineInstr &MI) {
523528
.addImm(0)
524529
.addMemOperand(MF.getMachineMemOperand(
525530
MachinePointerInfo::getJumpTable(MF), MachineMemOperand::MOLoad,
526-
EntrySize, Align(EntrySize)));
531+
EntrySize, Align(MJTI->getEntryAlignment(MF.getDataLayout()))));
527532
if (!Dest.constrainAllUses(TII, TRI, RBI))
528533
return false;
529534

530-
if (MF.getTarget().isPositionIndependent()) {
535+
if (MJTI->getEntryKind() == MachineJumpTableInfo::EK_LabelDifference32) {
531536
Dest = MIB.buildInstr(RISCV::ADD, {&RISCV::GPRRegClass},
532537
{Dest.getReg(0), MI.getOperand(0)});
533538
if (!Dest.constrainAllUses(TII, TRI, RBI))

0 commit comments

Comments
 (0)