Skip to content

Commit 9f5f98d

Browse files
committed
Define pointer layout for AVR program address space
AVR uses separate address spaces for data (0) and program (1) memory, however pointer layout is only defined for address space 0 in the data layout string. The `p[n]` directive defines pointer layouts where `n` defaults to `0`. When pointer layout is unspecified it defaults to `p[n]:64:64:64`. AVR uses 16-bit pointers for both data and program memory (e.g. for function pointers).
1 parent 18dd299 commit 9f5f98d

File tree

7 files changed

+8
-7
lines changed

7 files changed

+8
-7
lines changed

clang/lib/Basic/Targets/AVR.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ class LLVM_LIBRARY_VISIBILITY AVRTargetInfo : public TargetInfo {
5757
Int16Type = SignedInt;
5858
Char32Type = UnsignedLong;
5959
SigAtomicType = SignedChar;
60-
resetDataLayout("e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8");
60+
resetDataLayout(
61+
"e-P1-p0:16:8-p1:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8");
6162
}
6263

6364
void getTargetDefines(const LangOptions &Opts,

llvm/lib/Target/AVR/AVRTargetMachine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
namespace llvm {
2828

2929
static const char *AVRDataLayout =
30-
"e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8";
30+
"e-P1-p0:16:8-p1:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8";
3131

3232
/// Processes a CPU name.
3333
static StringRef getCPU(StringRef CPU) {

llvm/test/CodeGen/AVR/block-address-is-in-progmem-space.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
; This would cause a load of uninitialized memory, not even
1212
; touching the program's machine code as otherwise desired.
1313

14-
target datalayout = "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8"
14+
target datalayout = "e-P1-p0:16:8-p1:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8"
1515

1616
; CHECK-LABEL: load_with_no_forward_reference
1717
define i8 @load_with_no_forward_reference(i8 %a, i8 %b) {

llvm/test/CodeGen/AVR/shift-expand.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
; amount to a loop. These loops avoid generating a (non-existing) builtin such
66
; as __ashlsi3.
77

8-
target datalayout = "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8"
8+
target datalayout = "e-P1-p0:16:8-p1:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8"
99
target triple = "avr"
1010

1111
define i16 @shl16(i16 %value, i16 %amount) addrspace(1) {

llvm/test/Transforms/ArgumentPromotion/nonzero-address-spaces.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
; ArgumentPromotion should preserve the default function address space
55
; from the data layout.
66

7-
target datalayout = "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8"
7+
target datalayout = "e-P1-p0:16:8-p1:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8"
88

99
@g = common global i32 0, align 4
1010

llvm/test/Transforms/Attributor/ArgumentPromotion/nonzero-address-spaces.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
; ArgumentPromotion should preserve the default function address space
66
; from the data layout.
77

8-
target datalayout = "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8"
8+
target datalayout = "e-P1-p0:16:8-p1:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8"
99

1010
@g = common global i32 0, align 4
1111

llvm/test/Transforms/DeadArgElim/nonzero-address-spaces.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
; DeadArgumentElimination should respect the function address space
44
; in the data layout.
55

6-
target datalayout = "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8"
6+
target datalayout = "e-P1-p0:16:8-p1:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8"
77

88
; CHECK: define internal i32 @foo() addrspace(1)
99
define internal i32 @foo(i32 %x) #0 {

0 commit comments

Comments
 (0)