Skip to content

Commit 7a21ee3

Browse files
committed
[RISCV][GlobalISel] Select G_FRAME_INDEX
1 parent da9f908 commit 7a21ee3

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,18 @@ bool RISCVInstructionSelector::select(MachineInstr &MI) {
239239
}
240240
case TargetOpcode::G_SEXT_INREG:
241241
return selectSExtInreg(MI, MIB);
242+
case TargetOpcode::G_FRAME_INDEX: {
243+
// FIXME: We want to replace this with tablegen code that matches for
244+
// FrameAddrRegImm
245+
Register DstReg = MI.getOperand(0).getReg();
246+
247+
if (!MRI.getType(DstReg).isPointer())
248+
return false;
249+
250+
MI.setDesc(TII.get(RISCV::ADDI));
251+
MI.addOperand(MachineOperand::CreateImm(0));
252+
return constrainSelectedInstRegOperands(MI, TII, TRI, RBI);
253+
}
242254
default:
243255
return false;
244256
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
127127
case TargetOpcode::G_STORE:
128128
break;
129129
case TargetOpcode::G_CONSTANT:
130+
case TargetOpcode::G_FRAME_INDEX:
130131
case TargetOpcode::G_GLOBAL_VALUE:
131132
case TargetOpcode::G_BRCOND:
132133
OperandsMapping = getOperandsMapping({GPRValueMapping, nullptr});
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2+
# RUN: llc -mtriple=riscv32 -run-pass=instruction-select %s -o - \
3+
# RUN: | FileCheck %s
4+
--- |
5+
define ptr @frame_index() {
6+
entry:
7+
%x = alloca i32, align 4
8+
ret ptr %x
9+
}
10+
11+
...
12+
---
13+
name: frame_index
14+
legalized: true
15+
regBankSelected: true
16+
registers:
17+
- { id: 0, class: gprb, preferred-register: '' }
18+
stack:
19+
- { id: 0, name: x, type: default, offset: 0, size: 4, alignment: 4,
20+
stack-id: default, callee-saved-register: '', callee-saved-restored: true,
21+
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
22+
body: |
23+
bb.1.entry:
24+
; CHECK-LABEL: name: frame_index
25+
; CHECK: [[ADDI:%[0-9]+]]:gpr = ADDI %stack.0.x, 0
26+
; CHECK-NEXT: $x10 = COPY [[ADDI]]
27+
; CHECK-NEXT: PseudoRET implicit $x10
28+
%0:gprb(p0) = G_FRAME_INDEX %stack.0.x
29+
$x10 = COPY %0(p0)
30+
PseudoRET implicit $x10
31+
32+
...
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2+
# RUN: llc -mtriple=riscv64 -run-pass=instruction-select %s -o - \
3+
# RUN: | FileCheck %s
4+
--- |
5+
define ptr @frame_index() {
6+
entry:
7+
%x = alloca i32, align 4
8+
ret ptr %x
9+
}
10+
11+
...
12+
---
13+
name: frame_index
14+
legalized: true
15+
regBankSelected: true
16+
registers:
17+
- { id: 0, class: gprb, preferred-register: '' }
18+
stack:
19+
- { id: 0, name: x, type: default, offset: 0, size: 4, alignment: 4,
20+
stack-id: default, callee-saved-register: '', callee-saved-restored: true,
21+
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
22+
body: |
23+
bb.1.entry:
24+
; CHECK-LABEL: name: frame_index
25+
; CHECK: [[ADDI:%[0-9]+]]:gpr = ADDI %stack.0.x, 0
26+
; CHECK-NEXT: $x10 = COPY [[ADDI]]
27+
; CHECK-NEXT: PseudoRET implicit $x10
28+
%0:gprb(p0) = G_FRAME_INDEX %stack.0.x
29+
$x10 = COPY %0(p0)
30+
PseudoRET implicit $x10
31+
32+
...

0 commit comments

Comments
 (0)