llvm.org GIT mirror llvm / 588af2f
Add support for having different alignment for objects on call frames. The x86-64 ABI states that objects passed on the stack have 8 byte alignment. Implement that. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41768 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 13 years ago
5 changed file(s) with 57 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
3737 INTEGER_ALIGN = 'i', ///< Integer type alignment
3838 VECTOR_ALIGN = 'v', ///< Vector type alignment
3939 FLOAT_ALIGN = 'f', ///< Floating point type alignment
40 AGGREGATE_ALIGN = 'a' ///< Aggregate alignment
40 AGGREGATE_ALIGN = 'a', ///< Aggregate alignment
41 STACK_ALIGN = 's' ///< Stack objects alignment
4142 };
4243 /// Target alignment element.
4344 ///
165166 /// specified type.
166167 unsigned char getABITypeAlignment(const Type *Ty) const;
167168
169 /// getCallFrameTypeAlignment - Return the minimum ABI-required alignment
170 /// for the specified type when it is part of a call frame.
171 unsigned char getCallFrameTypeAlignment(const Type *Ty) const;
172
173
168174 /// getPrefTypeAlignment - Return the preferred stack/global alignment for
169175 /// the specified type.
170176 unsigned char getPrefTypeAlignment(const Type *Ty) const;
38693869 Flags |= ISD::ParamFlags::ByVal;
38703870 const PointerType *Ty = cast(I->getType());
38713871 const StructType *STy = cast(Ty->getElementType());
3872 unsigned StructAlign = Log2_32(getTargetData()->getABITypeAlignment(STy));
3872 unsigned StructAlign =
3873 Log2_32(getTargetData()->getCallFrameTypeAlignment(STy));
38733874 unsigned StructSize = getTargetData()->getTypeSize(STy);
38743875 Flags |= (StructAlign << ISD::ParamFlags::ByValAlignOffs);
38753876 Flags |= (StructSize << ISD::ParamFlags::ByValSizeOffs);
39983999 Flags |= ISD::ParamFlags::ByVal;
39994000 const PointerType *Ty = cast(Args[i].Ty);
40004001 const StructType *STy = cast(Ty->getElementType());
4001 unsigned StructAlign = Log2_32(getTargetData()->getABITypeAlignment(STy));
4002 unsigned StructAlign =
4003 Log2_32(getTargetData()->getCallFrameTypeAlignment(STy));
40024004 unsigned StructSize = getTargetData()->getTypeSize(STy);
40034005 Flags |= (StructAlign << ISD::ParamFlags::ByValAlignOffs);
40044006 Flags |= (StructSize << ISD::ParamFlags::ByValSizeOffs);
181181 setAlignment(VECTOR_ALIGN, 8, 8, 64); // v2i32
182182 setAlignment(VECTOR_ALIGN, 16, 16, 128); // v16i8, v8i16, v4i32, ...
183183 setAlignment(AGGREGATE_ALIGN, 0, 8, 0); // struct, union, class, ...
184
184 setAlignment(STACK_ALIGN, 0, 8, 0); // objects on the stack
185
185186 while (!temp.empty()) {
186187 std::string token = getToken(temp, "-");
187188 std::string arg0 = getToken(token, ":");
203204 case 'i':
204205 case 'v':
205206 case 'f':
206 case 'a': {
207 AlignTypeEnum align_type =
208 (*p == 'i' ? INTEGER_ALIGN : (*p == 'f' ? FLOAT_ALIGN :
209 (*p == 'v' ? VECTOR_ALIGN : AGGREGATE_ALIGN)));
207 case 'a':
208 case 's': {
209 AlignTypeEnum align_type;
210 switch(*p) {
211 case 'i': align_type = INTEGER_ALIGN; break;
212 case 'v': align_type = VECTOR_ALIGN; break;
213 case 'f': align_type = FLOAT_ALIGN; break;
214 case 'a': align_type = AGGREGATE_ALIGN; break;
215 case 's': align_type = STACK_ALIGN; break;
216 }
210217 uint32_t size = (uint32_t) atoi(++p);
211218 unsigned char abi_align = atoi(getToken(token, ":").c_str()) / 8;
212219 unsigned char pref_align = atoi(getToken(token, ":").c_str()) / 8;
528535 return getAlignment(Ty, true);
529536 }
530537
538 unsigned char TargetData::getCallFrameTypeAlignment(const Type *Ty) const {
539 for (unsigned i = 0, e = Alignments.size(); i != e; ++i)
540 if (Alignments[i].AlignType == STACK_ALIGN)
541 return Alignments[i].ABIAlign;
542
543 return getABITypeAlignment(Ty);
544 }
545
531546 unsigned char TargetData::getPrefTypeAlignment(const Type *Ty) const {
532547 return getAlignment(Ty, false);
533548 }
145145 std::string getDataLayout() const {
146146 const char *p;
147147 if (is64Bit())
148 p = "e-p:64:64-f64:64:64-i64:64:64-f80:128:128";
148 p = "e-p:64:64-s:64-f64:64:64-i64:64:64-f80:128:128";
149149 else {
150150 if (isTargetDarwin())
151151 p = "e-p:32:32-f64:32:64-i64:32:64-f80:128:128";
0 ; RUN: llvm-as < %s | llc -march=x86-64 | grep rep.movsl | count 2
1
2 %struct.s = type { i32, i32, i32, i32, i32, i32 }
3
4 define void @g(i32 %a1, i32 %a2, i32 %a3, i32 %a4, i32 %a5, i32 %a6) {
5 entry:
6 %d = alloca %struct.s, align 16
7 %tmp = getelementptr %struct.s* %d, i32 0, i32 0
8 store i32 %a1, i32* %tmp, align 16
9 %tmp2 = getelementptr %struct.s* %d, i32 0, i32 1
10 store i32 %a2, i32* %tmp2, align 16
11 %tmp4 = getelementptr %struct.s* %d, i32 0, i32 2
12 store i32 %a3, i32* %tmp4, align 16
13 %tmp6 = getelementptr %struct.s* %d, i32 0, i32 3
14 store i32 %a4, i32* %tmp6, align 16
15 %tmp8 = getelementptr %struct.s* %d, i32 0, i32 4
16 store i32 %a5, i32* %tmp8, align 16
17 %tmp10 = getelementptr %struct.s* %d, i32 0, i32 5
18 store i32 %a6, i32* %tmp10, align 16
19 call void @f( %struct.s* %d byval)
20 call void @f( %struct.s* %d byval)
21 ret void
22 }
23
24 declare void @f(%struct.s* byval)