Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RISCV][GlobalISel] Select G_FRAME_INDEX #68254

Merged
merged 6 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions llvm/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,14 @@ bool RISCVInstructionSelector::select(MachineInstr &MI) {
}
case TargetOpcode::G_SEXT_INREG:
return selectSExtInreg(MI, MIB);
case TargetOpcode::G_FRAME_INDEX: {
// TODO: We may want to replace this code with the SelectionDAG patterns,
// which fail to get imported because it uses FrameAddrRegImm, which is a
// ComplexPattern
MI.setDesc(TII.get(RISCV::ADDI));
MI.addOperand(MachineOperand::CreateImm(0));
return constrainSelectedInstRegOperands(MI, TII, TRI, RBI);
}
case TargetOpcode::G_SELECT:
return selectSelect(MI, MIB, MRI);
default:
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/RISCV/GISel/RISCVRegisterBankInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
case TargetOpcode::G_STORE:
break;
case TargetOpcode::G_CONSTANT:
case TargetOpcode::G_FRAME_INDEX:
case TargetOpcode::G_GLOBAL_VALUE:
case TargetOpcode::G_BRCOND:
OperandsMapping = getOperandsMapping({GPRValueMapping, nullptr});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -mtriple=riscv32 -run-pass=instruction-select %s -o - \
# RUN: | FileCheck %s
--- |
define ptr @frame_index() {
entry:
%x = alloca i32, align 4
ret ptr %x
}

...
---
name: frame_index
legalized: true
regBankSelected: true
registers:
- { id: 0, class: gprb, preferred-register: '' }
stack:
- { id: 0, name: x, type: default, offset: 0, size: 4, alignment: 4,
stack-id: default, callee-saved-register: '', callee-saved-restored: true,
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
body: |
bb.1.entry:
; CHECK-LABEL: name: frame_index
; CHECK: [[ADDI:%[0-9]+]]:gpr = ADDI %stack.0.x, 0
; CHECK-NEXT: $x10 = COPY [[ADDI]]
; CHECK-NEXT: PseudoRET implicit $x10
%0:gprb(p0) = G_FRAME_INDEX %stack.0.x
$x10 = COPY %0(p0)
PseudoRET implicit $x10

...
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -mtriple=riscv64 -run-pass=instruction-select %s -o - \
# RUN: | FileCheck %s
--- |
define ptr @frame_index() {
entry:
%x = alloca i32, align 4
ret ptr %x
}

...
---
name: frame_index
legalized: true
regBankSelected: true
registers:
- { id: 0, class: gprb, preferred-register: '' }
stack:
- { id: 0, name: x, type: default, offset: 0, size: 4, alignment: 4,
stack-id: default, callee-saved-register: '', callee-saved-restored: true,
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
body: |
bb.1.entry:
; CHECK-LABEL: name: frame_index
; CHECK: [[ADDI:%[0-9]+]]:gpr = ADDI %stack.0.x, 0
; CHECK-NEXT: $x10 = COPY [[ADDI]]
; CHECK-NEXT: PseudoRET implicit $x10
%0:gprb(p0) = G_FRAME_INDEX %stack.0.x
$x10 = COPY %0(p0)
PseudoRET implicit $x10

...
33 changes: 33 additions & 0 deletions llvm/test/CodeGen/RISCV/GlobalISel/regbankselect/frame-index.mir
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -mtriple=riscv32 -run-pass=regbankselect %s -o - \
# RUN: | FileCheck %s
# RUN: llc -mtriple=riscv64 -run-pass=regbankselect %s -o - \
# RUN: | FileCheck %s
--- |
define ptr @frame_index() {
entry:
%x = alloca i32, align 4
ret ptr %x
}

...
---
name: frame_index
legalized: true
registers:
- { id: 0, class: _, preferred-register: '' }
stack:
- { id: 0, name: x, type: default, offset: 0, size: 4, alignment: 4,
stack-id: default, callee-saved-register: '', callee-saved-restored: true,
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
body: |
bb.1.entry:
; CHECK-LABEL: name: frame_index
; CHECK: [[FRAME_INDEX:%[0-9]+]]:gprb(p0) = G_FRAME_INDEX %stack.0.x
; CHECK-NEXT: $x10 = COPY [[FRAME_INDEX]](p0)
; CHECK-NEXT: PseudoRET implicit $x10
%0:_(p0) = G_FRAME_INDEX %stack.0.x
$x10 = COPY %0(p0)
PseudoRET implicit $x10

...