Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit ae7bdef

Browse files
pftbestarielb1
authored andcommitted
[MSP430] Fix data layout string.
Summary: Without this patch some types have incorrect size and/or alignment according to the MSP430 EABI. Reviewers: asl, awygle Reviewed By: asl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D34561 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306159 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 56462c5 commit ae7bdef

File tree

3 files changed

+64
-3
lines changed

3 files changed

+64
-3
lines changed

lib/Target/MSP430/MSP430TargetMachine.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,20 @@ static Reloc::Model getEffectiveRelocModel(Optional<Reloc::Model> RM) {
3232
return *RM;
3333
}
3434

35+
static std::string computeDataLayout(const Triple &TT, StringRef CPU,
36+
const TargetOptions &Options) {
37+
return "e-m:e-p:16:16-i32:16-i64:16-f32:16-f64:16-a:8-n8:16-S16";
38+
}
39+
3540
MSP430TargetMachine::MSP430TargetMachine(const Target &T, const Triple &TT,
3641
StringRef CPU, StringRef FS,
3742
const TargetOptions &Options,
3843
Optional<Reloc::Model> RM,
3944
CodeModel::Model CM,
4045
CodeGenOpt::Level OL)
41-
: LLVMTargetMachine(T, "e-m:e-p:16:16-i32:16:32-a:16-n8:16", TT, CPU, FS,
46+
: LLVMTargetMachine(T, computeDataLayout(TT, CPU, Options), TT, CPU, FS,
4247
Options, getEffectiveRelocModel(RM), CM, OL),
4348
TLOF(make_unique<TargetLoweringObjectFileELF>()),
44-
// FIXME: Check DataLayout string.
4549
Subtarget(TT, CPU, FS, *this) {
4650
initAsmInfo();
4751
}

test/CodeGen/MSP430/Inst16mm.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ entry:
6464
%0 = load i16, i16* %retval ; <i16> [#uses=1]
6565
ret i16 %0
6666
; CHECK-LABEL: mov2:
67-
; CHECK: mov.w 2(r1), 6(r1)
6867
; CHECK: mov.w 0(r1), 4(r1)
68+
; CHECK: mov.w 2(r1), 6(r1)
6969
}

test/CodeGen/MSP430/struct_layout.ll

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
; RUN: llc < %s | FileCheck %s
2+
3+
target triple = "msp430"
4+
5+
%struct.X = type { i8 }
6+
7+
; CHECK-LABEL: @foo
8+
; CHECK: sub.w #4, r1
9+
; CHECK: mov.b #1, 3(r1)
10+
define void @foo() {
11+
%1 = alloca %struct.X
12+
%2 = alloca %struct.X
13+
%3 = alloca %struct.X
14+
%4 = getelementptr inbounds %struct.X, %struct.X* %1, i32 0, i32 0
15+
store i8 1, i8* %4
16+
%5 = getelementptr inbounds %struct.X, %struct.X* %2, i32 0, i32 0
17+
store i8 1, i8* %5
18+
%6 = getelementptr inbounds %struct.X, %struct.X* %3, i32 0, i32 0
19+
store i8 1, i8* %6
20+
ret void
21+
}
22+
23+
; CHECK-LABEL: @bar
24+
; CHECK: sub.w #4, r1
25+
; CHECK: mov.b #1, 3(r1)
26+
define void @bar() {
27+
%1 = alloca [3 x %struct.X]
28+
%2 = getelementptr inbounds [3 x %struct.X], [3 x %struct.X]* %1, i16 0, i16 0
29+
%3 = getelementptr inbounds %struct.X, %struct.X* %2, i32 0, i32 0
30+
store i8 1, i8* %3
31+
%4 = getelementptr inbounds [3 x %struct.X], [3 x %struct.X]* %1, i16 0, i16 1
32+
%5 = getelementptr inbounds %struct.X, %struct.X* %4, i32 0, i32 0
33+
store i8 1, i8* %5
34+
%6 = getelementptr inbounds [3 x %struct.X], [3 x %struct.X]* %1, i16 0, i16 2
35+
%7 = getelementptr inbounds %struct.X, %struct.X* %6, i32 0, i32 0
36+
store i8 1, i8* %7
37+
ret void
38+
}
39+
40+
%struct.Y = type { i8, i16 }
41+
42+
; CHECK-LABEL: @baz
43+
; CHECK: sub.w #8, r1
44+
; CHECK: mov.w #2, 6(r1)
45+
define void @baz() {
46+
%1 = alloca %struct.Y, align 2
47+
%2 = alloca %struct.Y, align 2
48+
%3 = getelementptr inbounds %struct.Y, %struct.Y* %1, i32 0, i32 0
49+
store i8 1, i8* %3, align 2
50+
%4 = getelementptr inbounds %struct.Y, %struct.Y* %1, i32 0, i32 1
51+
store i16 2, i16* %4, align 2
52+
%5 = getelementptr inbounds %struct.Y, %struct.Y* %2, i32 0, i32 0
53+
store i8 1, i8* %5, align 2
54+
%6 = getelementptr inbounds %struct.Y, %struct.Y* %2, i32 0, i32 1
55+
store i16 2, i16* %6, align 2
56+
ret void
57+
}

0 commit comments

Comments
 (0)