llvm.org GIT mirror llvm / bb5b3f3
Add a natural stack alignment field to TargetData, and prevent InstCombine from promoting allocas to preferred alignments that exceed the natural alignment. This avoids some potentially expensive dynamic stack realignments. The natural stack alignment is set in target data strings via the "S<size>" option. Size is in bits and must be a multiple of 8. The natural stack alignment defaults to "unspecified" (represented by a zero value), and the "unspecified" value does not prevent any alignment promotions. Target maintainers that care about avoiding promotions should explicitly add the "S<size>" option to their target data strings. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141599 91177308-0d34-0410-b5e6-96231b3b80d8 Lang Hames 8 years ago
8 changed file(s) with 45 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
13181318 the bits with the least significance have the lowest address
13191319 location.
13201320
1321
Ssize
1322
Specifies the natural alignment of the stack in bits. Alignment promotion
1323 of stack variables is limited to the natural stack alignment to avoid
1324 dynamic stack realignment. The stack alignment must be a multiple of
1325 8-bits, and currently defaults to 128 bits if unspecified.
1326
13211327
p:size:abi:pref
13221328
This specifies the size of a pointer and its abi and
13231329 preferred alignments. All sizes are in bits. Specifying
6969 unsigned PointerMemSize; ///< Pointer size in bytes
7070 unsigned PointerABIAlign; ///< Pointer ABI alignment
7171 unsigned PointerPrefAlign; ///< Pointer preferred alignment
72 unsigned StackNaturalAlign; ///< Stack natural alignment
7273
7374 SmallVector LegalIntWidths; ///< Legal Integers.
7475
160161
161162 bool isIllegalInteger(unsigned Width) const {
162163 return !isLegalInteger(Width);
164 }
165
166 /// Returns true if the given alignment exceeds the natural stack alignment.
167 bool exceedsNaturalStackAlignment(unsigned Align) const {
168 return (StackNaturalAlign != 0) && (Align > StackNaturalAlign);
163169 }
164170
165171 /// fitsInLegalInteger - This function returns true if the specified type fits
5252 : ARMBaseTargetMachine(T, TT, CPU, FS, RM, CM), InstrInfo(Subtarget),
5353 DataLayout(Subtarget.isAPCS_ABI() ?
5454 std::string("e-p:32:32-f64:32:64-i64:32:64-"
55 "v128:32:128-v64:32:64-n32") :
55 "v128:32:128-v64:32:64-n32-S32") :
56 Subtarget.isAAPCS_ABI() ?
5657 std::string("e-p:32:32-f64:64:64-i64:64:64-"
57 "v128:64:128-v64:64:64-n32")),
58 "v128:64:128-v64:64:64-n32-S64") :
59 std::string("e-p:32:32-f64:64:64-i64:64:64-"
60 "v128:64:128-v64:64:64-n32-S32")),
5861 ELFWriterInfo(*this),
5962 TLInfo(*this),
6063 TSInfo(*this),
7477 DataLayout(Subtarget.isAPCS_ABI() ?
7578 std::string("e-p:32:32-f64:32:64-i64:32:64-"
7679 "i16:16:32-i8:8:32-i1:8:32-"
77 "v128:32:128-v64:32:64-a:0:32-n32") :
80 "v128:32:128-v64:32:64-a:0:32-n32-S32") :
81 Subtarget.isAAPCS_ABI() ?
7882 std::string("e-p:32:32-f64:64:64-i64:64:64-"
7983 "i16:16:32-i8:8:32-i1:8:32-"
80 "v128:64:128-v64:64:64-a:0:32-n32")),
84 "v128:64:128-v64:64:64-a:0:32-n32-S64") :
85 std::string("e-p:32:32-f64:64:64-i64:64:64-"
86 "i16:16:32-i8:8:32-i1:8:32-"
87 "v128:64:128-v64:64:64-a:0:32-n32-S32")),
8188 ELFWriterInfo(*this),
8289 TLInfo(*this),
8390 TSInfo(*this),
138138 PointerMemSize = 8;
139139 PointerABIAlign = 8;
140140 PointerPrefAlign = PointerABIAlign;
141 StackNaturalAlign = 0;
141142
142143 // Default alignments
143144 setAlignment(INTEGER_ALIGN, 1, 1, 1); // i1
217218 Token = Split.second;
218219 } while (!Specifier.empty() || !Token.empty());
219220 break;
220
221 case 'S': // Stack natural alignment.
222 StackNaturalAlign = getInt(Specifier.substr(1));
223 StackNaturalAlign /= 8;
224 // FIXME: Should we really be truncating these alingments and
225 // sizes silently?
226 break;
221227 default:
222228 break;
223229 }
371377
372378 OS << (LittleEndian ? "e" : "E")
373379 << "-p:" << PointerMemSize*8 << ':' << PointerABIAlign*8
374 << ':' << PointerPrefAlign*8;
380 << ':' << PointerPrefAlign*8
381 << "-S" << StackNaturalAlign*8;
382
375383 for (unsigned i = 0, e = Alignments.size(); i != e; ++i) {
376384 const TargetAlignElem &AI = Alignments[i];
377385 OS << '-' << (char)AI.AlignType << AI.TypeBitWidth << ':'
861861
862862 This IR (from PR6194):
863863
864 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
864 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
865865 target triple = "x86_64-apple-darwin10.0.0"
866866
867867 %0 = type { double, double }
12161216
12171217 Take the following:
12181218
1219 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
1219 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-S128"
12201220 target triple = "i386-apple-darwin8"
12211221 @in_exit.4870.b = internal global i1 false ; [#uses=2]
12221222 define fastcc void @abort_gzip() noreturn nounwind {
3333 Reloc::Model RM, CodeModel::Model CM)
3434 : X86TargetMachine(T, TT, CPU, FS, RM, CM, false),
3535 DataLayout(getSubtargetImpl()->isTargetDarwin() ?
36 "e-p:32:32-f64:32:64-i64:32:64-f80:128:128-f128:128:128-n8:16:32" :
36 "e-p:32:32-f64:32:64-i64:32:64-f80:128:128-f128:128:128-n8:16:32-S128" :
3737 (getSubtargetImpl()->isTargetCygMing() ||
3838 getSubtargetImpl()->isTargetWindows()) ?
39 "e-p:32:32-f64:64:64-i64:64:64-f80:32:32-f128:128:128-n8:16:32" :
40 "e-p:32:32-f64:32:64-i64:32:64-f80:32:32-f128:128:128-n8:16:32"),
39 "e-p:32:32-f64:64:64-i64:64:64-f80:32:32-f128:128:128-n8:16:32-S32" :
40 "e-p:32:32-f64:32:64-i64:32:64-f80:32:32-f128:128:128-n8:16:32-S32"),
4141 InstrInfo(*this),
4242 TSInfo(*this),
4343 TLInfo(*this),
4949 StringRef CPU, StringRef FS,
5050 Reloc::Model RM, CodeModel::Model CM)
5151 : X86TargetMachine(T, TT, CPU, FS, RM, CM, true),
52 DataLayout("e-p:64:64-s:64-f64:64:64-i64:64:64-f80:128:128-f128:128:128-n8:16:32:64"),
52 DataLayout("e-p:64:64-s:64-f64:64:64-i64:64:64-f80:128:128-f128:128:128-n8:16:32:64-S128"),
5353 InstrInfo(*this),
5454 TSInfo(*this),
5555 TLInfo(*this),
720720 /// their preferred alignment from the beginning.
721721 ///
722722 static unsigned enforceKnownAlignment(Value *V, unsigned Align,
723 unsigned PrefAlign) {
723 unsigned PrefAlign, const TargetData *TD) {
724724 V = V->stripPointerCasts();
725725
726726 if (AllocaInst *AI = dyn_cast(V)) {
727 // If the preferred alignment is greater than the natural stack alignment
728 // then don't round up. This avoids dynamic stack realignment.
729 if (TD && TD->exceedsNaturalStackAlignment(PrefAlign))
730 return Align;
727731 // If there is a requested alignment and if this is an alloca, round up.
728732 if (AI->getAlignment() >= PrefAlign)
729733 return AI->getAlignment();
774778 Align = std::min(Align, +Value::MaximumAlignment);
775779
776780 if (PrefAlign > Align)
777 Align = enforceKnownAlignment(V, Align, PrefAlign);
781 Align = enforceKnownAlignment(V, Align, PrefAlign, TD);
778782
779783 // We don't need to make any adjustment.
780784 return Align;