Skip to content

Commit 816ea84

Browse files
Vasileios KalintirisVasileios Kalintiris
Vasileios Kalintiris
authored and
Vasileios Kalintiris
committedApr 17, 2015
[mips][FastISel] Implement FastMaterializeAlloca in Mips fast-isel.
Summary: Implement the method FastMaterializeAlloca in Mips fast-isel Based on a patch by Reed Kotler. Test Plan: Passes test-suite at O0/O2 for mips32 r1/r2 fastalloca.ll Reviewers: dsanders, rkotler Subscribers: rfuhler, llvm-commits Differential Revision: http://reviews.llvm.org/D6742 llvm-svn: 235213
1 parent 2be05ee commit 816ea84

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
 

‎llvm/lib/Target/Mips/MipsFastISel.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ class MipsFastISel final : public FastISel {
187187
UnsupportedFPMode = Subtarget->isFP64bit();
188188
}
189189

190+
unsigned fastMaterializeAlloca(const AllocaInst *AI) override;
190191
unsigned fastMaterializeConstant(const Constant *C) override;
191192
bool fastSelectInstruction(const Instruction *I) override;
192193

@@ -253,6 +254,25 @@ unsigned MipsFastISel::emitLogicalOp(unsigned ISDOpc, MVT RetVT,
253254
return ResultReg;
254255
}
255256

257+
unsigned MipsFastISel::fastMaterializeAlloca(const AllocaInst *AI) {
258+
assert(TLI.getValueType(AI->getType(), true) == MVT::i32 &&
259+
"Alloca should always return a pointer.");
260+
261+
DenseMap<const AllocaInst *, int>::iterator SI =
262+
FuncInfo.StaticAllocaMap.find(AI);
263+
264+
if (SI != FuncInfo.StaticAllocaMap.end()) {
265+
unsigned ResultReg = createResultReg(&Mips::GPR32RegClass);
266+
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Mips::LEA_ADDiu),
267+
ResultReg)
268+
.addFrameIndex(SI->second)
269+
.addImm(0);
270+
return ResultReg;
271+
}
272+
273+
return 0;
274+
}
275+
256276
unsigned MipsFastISel::materializeInt(const Constant *C, MVT VT) {
257277
if (VT != MVT::i32 && VT != MVT::i16 && VT != MVT::i8 && VT != MVT::i1)
258278
return 0;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
; RUN: llc -march=mipsel -relocation-model=pic -O0 -mips-fast-isel -fast-isel-abort=1 -mcpu=mips32r2 \
2+
; RUN: < %s | FileCheck %s
3+
4+
%struct.x = type { i32 }
5+
6+
@i = common global i32 0, align 4
7+
8+
define i32 @foobar(i32 signext %x) {
9+
entry:
10+
; CHECK-LABEL: foobar:
11+
%retval = alloca i32, align 4
12+
%x.addr = alloca i32, align 4
13+
%a = alloca %struct.x, align 4
14+
%c = alloca %struct.x*, align 4
15+
store i32 %x, i32* %x.addr, align 4
16+
%x1 = getelementptr inbounds %struct.x, %struct.x* %a, i32 0, i32 0
17+
%0 = load i32, i32* %x.addr, align 4
18+
store i32 %0, i32* %x1, align 4
19+
store %struct.x* %a, %struct.x** %c, align 4
20+
%1 = load %struct.x*, %struct.x** %c, align 4
21+
%x2 = getelementptr inbounds %struct.x, %struct.x* %1, i32 0, i32 0
22+
%2 = load i32, i32* %x2, align 4
23+
store i32 %2, i32* @i, align 4
24+
%3 = load i32, i32* %retval
25+
; CHECK-DAG: lw $[[I_ADDR:[0-9]+]], %got(i)($[[REG_GP:[0-9]+]])
26+
; CHECK-DAG: addiu $[[A_ADDR:[0-9]+]], $sp, 8
27+
; CHECK-DAG: sw $[[A_ADDR]], [[A_ADDR_FI:[0-9]+]]($sp)
28+
; CHECK-DAG: lw $[[A_ADDR2:[0-9]+]], [[A_ADDR_FI]]($sp)
29+
; CHECK-DAG: lw $[[A_X:[0-9]+]], 0($[[A_ADDR2]])
30+
; CHECK-DAG: sw $[[A_X]], 0($[[I_ADDR]])
31+
ret i32 %3
32+
}

0 commit comments

Comments
 (0)
Please sign in to comment.