summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorChad Rosier <mcrosier@apple.com>2012-07-13 23:57:43 +0000
committerChad Rosier <mcrosier@apple.com>2012-07-13 23:57:43 +0000
commitcc40ea7f9a26192b9a377569e2798c635765f53c (patch)
treedfd3c50e13e8e20905728fd5f40270597da72bf7 /clang
parent1c5431af8138b6c1b847eae76aae66e60fa31e52 (diff)
downloadbcm5719-llvm-cc40ea7f9a26192b9a377569e2798c635765f53c.tar.gz
bcm5719-llvm-cc40ea7f9a26192b9a377569e2798c635765f53c.zip
Add a per target max vector alignment field (e.g., 32-byte alignment for x86 due to
AVX). Currently, if no aligned attribute is specified the alignment of a vector is inferred from its size. Thus, very large vectors will be over-aligned with no benefit. Target owners should set this target max. llvm-svn: 160209
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/Basic/TargetInfo.h4
-rw-r--r--clang/lib/AST/ASTContext.cpp4
-rw-r--r--clang/lib/Basic/TargetInfo.cpp1
-rw-r--r--clang/lib/Basic/Targets.cpp2
-rw-r--r--clang/test/CodeGen/vector-alignment.c38
5 files changed, 49 insertions, 0 deletions
diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h
index 125496a3604..54d49e6fa55 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -80,6 +80,7 @@ protected:
unsigned char LongLongWidth, LongLongAlign;
unsigned char SuitableAlign;
unsigned char MaxAtomicPromoteWidth, MaxAtomicInlineWidth;
+ unsigned short MaxVectorAlign;
const char *DescriptionString;
const char *UserLabelPrefix;
const char *MCountName;
@@ -308,6 +309,9 @@ public:
/// inlined given the supported features of the given target.
unsigned getMaxAtomicInlineWidth() const { return MaxAtomicInlineWidth; }
+ /// \brief Return the maximum vector alignment supported for the given target.
+ unsigned getMaxVectorAlign() const { return MaxVectorAlign; }
+
/// \brief Return the size of intmax_t and uintmax_t for this target, in bits.
unsigned getIntMaxTWidth() const {
return getTypeWidth(IntMaxType);
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index a9681d86697..b0351d69adb 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1047,6 +1047,10 @@ ASTContext::getTypeInfoImpl(const Type *T) const {
Align = llvm::NextPowerOf2(Align);
Width = llvm::RoundUpToAlignment(Width, Align);
}
+ // Adjust the alignment based on the target max.
+ uint64_t TargetVectorAlign = Target->getMaxVectorAlign();
+ if (TargetVectorAlign && TargetVectorAlign < Align)
+ Align = TargetVectorAlign;
break;
}
diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index 8c49486b0dc..db5941a5d92 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -47,6 +47,7 @@ TargetInfo::TargetInfo(const std::string &T) : Triple(T) {
LargeArrayMinWidth = 0;
LargeArrayAlign = 0;
MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 0;
+ MaxVectorAlign = 0;
SizeType = UnsignedLong;
PtrDiffType = SignedLong;
IntMaxType = SignedLongLong;
diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 3df59c35d12..193241361da 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -2448,6 +2448,7 @@ public:
LongDoubleWidth = 128;
LongDoubleAlign = 128;
SuitableAlign = 128;
+ MaxVectorAlign = 256;
SizeType = UnsignedLong;
IntPtrType = SignedLong;
DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
@@ -2755,6 +2756,7 @@ public:
DarwinX86_64TargetInfo(const std::string& triple)
: DarwinTargetInfo<X86_64TargetInfo>(triple) {
Int64Type = SignedLongLong;
+ MaxVectorAlign = 256;
}
};
} // end anonymous namespace
diff --git a/clang/test/CodeGen/vector-alignment.c b/clang/test/CodeGen/vector-alignment.c
new file mode 100644
index 00000000000..92d1ae73f9e
--- /dev/null
+++ b/clang/test/CodeGen/vector-alignment.c
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -w -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s
+// rdar://11759609
+
+// At or below target max alignment with no aligned attribute should align based
+// on the size of vector.
+double __attribute__((vector_size(16))) v1;
+// CHECK: @v1 {{.*}}, align 16
+double __attribute__((vector_size(32))) v2;
+// CHECK: @v2 {{.*}}, align 32
+
+// Alignment above target max alignment with no aligned attribute should align
+// based on the target max.
+double __attribute__((vector_size(64))) v3;
+// CHECK: @v3 {{.*}}, align 32
+double __attribute__((vector_size(1024))) v4;
+// CHECK: @v4 {{.*}}, align 32
+
+// Aliged attribute should always override.
+double __attribute__((vector_size(16), aligned(16))) v5;
+// CHECK: @v5 {{.*}}, align 16
+double __attribute__((vector_size(16), aligned(64))) v6;
+// CHECK: @v6 {{.*}}, align 64
+double __attribute__((vector_size(32), aligned(16))) v7;
+// CHECK: @v7 {{.*}}, align 16
+double __attribute__((vector_size(32), aligned(64))) v8;
+// CHECK: @v8 {{.*}}, align 64
+
+// Check non-power of 2 widths.
+double __attribute__((vector_size(24))) v9;
+// CHECK: @v9 {{.*}}, align 32
+double __attribute__((vector_size(40))) v10;
+// CHECK: @v10 {{.*}}, align 32
+
+// Check non-power of 2 widths with aligned attribute.
+double __attribute__((vector_size(24), aligned(64))) v11;
+// CHECK: @v11 {{.*}}, align 64
+double __attribute__((vector_size(80), aligned(16))) v12;
+// CHECK: @v12 {{.*}}, align 16
OpenPOWER on IntegriCloud