@@ -198,37 +198,38 @@ const char *DataLayout::getManglingComponent(const Triple &T) {
198198 return " -m:e" ;
199199}
200200
201- static const std::pair<AlignTypeEnum, LayoutAlignElem> DefaultAlignments[] = {
202- {INTEGER_ALIGN, {1 , Align (1 ), Align (1 )}}, // i1
203- {INTEGER_ALIGN, {8 , Align (1 ), Align (1 )}}, // i8
204- {INTEGER_ALIGN, {16 , Align (2 ), Align (2 )}}, // i16
205- {INTEGER_ALIGN, {32 , Align (4 ), Align (4 )}}, // i32
206- {INTEGER_ALIGN, {64 , Align (4 ), Align (8 )}}, // i64
207- {FLOAT_ALIGN, {16 , Align (2 ), Align (2 )}}, // half, bfloat
208- {FLOAT_ALIGN, {32 , Align (4 ), Align (4 )}}, // float
209- {FLOAT_ALIGN, {64 , Align (8 ), Align (8 )}}, // double
210- {FLOAT_ALIGN, {128 , Align (16 ), Align (16 )}}, // ppcf128, quad, ...
211- {VECTOR_ALIGN, {64 , Align (8 ), Align (8 )}}, // v2i32, v1i64, ...
212- {VECTOR_ALIGN, {128 , Align (16 ), Align (16 )}}, // v16i8, v8i16, v4i32, ...
201+ // Default primitive type specifications.
202+ // NOTE: These arrays must be sorted by type bit width.
203+ constexpr LayoutAlignElem DefaultIntSpecs[] = {
204+ {1 , Align::Constant<1 >(), Align::Constant<1 >()}, // i1:8:8
205+ {8 , Align::Constant<1 >(), Align::Constant<1 >()}, // i8:8:8
206+ {16 , Align::Constant<2 >(), Align::Constant<2 >()}, // i16:16:16
207+ {32 , Align::Constant<4 >(), Align::Constant<4 >()}, // i32:32:32
208+ {64 , Align::Constant<4 >(), Align::Constant<8 >()}, // i64:32:64
209+ };
210+ constexpr LayoutAlignElem DefaultFloatSpecs[] = {
211+ {16 , Align::Constant<2 >(), Align::Constant<2 >()}, // f16:16:16
212+ {32 , Align::Constant<4 >(), Align::Constant<4 >()}, // f32:32:32
213+ {64 , Align::Constant<8 >(), Align::Constant<8 >()}, // f64:64:64
214+ {128 , Align::Constant<16 >(), Align::Constant<16 >()}, // f128:128:128
215+ };
216+ constexpr LayoutAlignElem DefaultVectorSpecs[] = {
217+ {64 , Align::Constant<8 >(), Align::Constant<8 >()}, // v64:64:64
218+ {128 , Align::Constant<16 >(), Align::Constant<16 >()}, // v128:128:128
213219};
214220
215- DataLayout::DataLayout (StringRef LayoutString) {
216- BigEndian = false ;
217- AllocaAddrSpace = 0 ;
218- ProgramAddrSpace = 0 ;
219- DefaultGlobalsAddrSpace = 0 ;
220- TheFunctionPtrAlignType = FunctionPtrAlignType::Independent;
221- ManglingMode = MM_None;
222-
223- // Default alignments
224- for (const auto &[Kind, Layout] : DefaultAlignments) {
225- if (Error Err = setAlignment (Kind, Layout.ABIAlign , Layout.PrefAlign ,
226- Layout.TypeBitWidth ))
227- report_fatal_error (std::move (Err));
228- }
229- if (Error Err = setPointerAlignmentInBits (0 , Align (8 ), Align (8 ), 64 , 64 ))
230- report_fatal_error (std::move (Err));
221+ // Default pointer type specifications.
222+ constexpr PointerAlignElem DefaultPointerSpecs[] = {
223+ {0 , 64 , Align::Constant<8 >(), Align::Constant<8 >(), 64 } // p0:64:64:64:64
224+ };
225+
226+ DataLayout::DataLayout ()
227+ : IntAlignments(ArrayRef(DefaultIntSpecs)),
228+ FloatAlignments(ArrayRef(DefaultFloatSpecs)),
229+ VectorAlignments(ArrayRef(DefaultVectorSpecs)),
230+ Pointers(ArrayRef(DefaultPointerSpecs)) {}
231231
232+ DataLayout::DataLayout (StringRef LayoutString) : DataLayout() {
232233 if (Error Err = parseSpecifier (LayoutString))
233234 report_fatal_error (std::move (Err));
234235}
@@ -277,7 +278,7 @@ bool DataLayout::operator==(const DataLayout &Other) const {
277278}
278279
279280Expected<DataLayout> DataLayout::parse (StringRef LayoutDescription) {
280- DataLayout Layout ( " " ) ;
281+ DataLayout Layout;
281282 if (Error Err = Layout.parseSpecifier (LayoutDescription))
282283 return std::move (Err);
283284 return Layout;
0 commit comments