diff options
author | Sergei Barannikov <barannikov88@gmail.com> | 2024-08-14 15:02:47 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-14 15:02:47 +0300 |
commit | 6cf3e7d06706fe79e87d1816c92b074416b5f8f8 (patch) | |
tree | 8f9d911249025f00bd39ffd36a830ed61d6d3489 /llvm/lib/IR | |
parent | 6de04e6fe8b1520ef3e4073ff222e623b7dc9cb9 (diff) | |
download | llvm-6cf3e7d06706fe79e87d1816c92b074416b5f8f8.zip llvm-6cf3e7d06706fe79e87d1816c92b074416b5f8f8.tar.gz llvm-6cf3e7d06706fe79e87d1816c92b074416b5f8f8.tar.bz2 |
[DataLayout] Use member initialization (NFC) (#103712)
This also adds a default constructor and a few uses of it.
Diffstat (limited to 'llvm/lib/IR')
-rw-r--r-- | llvm/lib/IR/DataLayout.cpp | 59 | ||||
-rw-r--r-- | llvm/lib/IR/Module.cpp | 2 |
2 files changed, 31 insertions, 30 deletions
diff --git a/llvm/lib/IR/DataLayout.cpp b/llvm/lib/IR/DataLayout.cpp index c10b302..530979c 100644 --- a/llvm/lib/IR/DataLayout.cpp +++ b/llvm/lib/IR/DataLayout.cpp @@ -198,37 +198,38 @@ const char *DataLayout::getManglingComponent(const Triple &T) { return "-m:e"; } -static const std::pair<AlignTypeEnum, LayoutAlignElem> DefaultAlignments[] = { - {INTEGER_ALIGN, {1, Align(1), Align(1)}}, // i1 - {INTEGER_ALIGN, {8, Align(1), Align(1)}}, // i8 - {INTEGER_ALIGN, {16, Align(2), Align(2)}}, // i16 - {INTEGER_ALIGN, {32, Align(4), Align(4)}}, // i32 - {INTEGER_ALIGN, {64, Align(4), Align(8)}}, // i64 - {FLOAT_ALIGN, {16, Align(2), Align(2)}}, // half, bfloat - {FLOAT_ALIGN, {32, Align(4), Align(4)}}, // float - {FLOAT_ALIGN, {64, Align(8), Align(8)}}, // double - {FLOAT_ALIGN, {128, Align(16), Align(16)}}, // ppcf128, quad, ... - {VECTOR_ALIGN, {64, Align(8), Align(8)}}, // v2i32, v1i64, ... - {VECTOR_ALIGN, {128, Align(16), Align(16)}}, // v16i8, v8i16, v4i32, ... +// Default primitive type specifications. +// NOTE: These arrays must be sorted by type bit width. +constexpr LayoutAlignElem DefaultIntSpecs[] = { + {1, Align::Constant<1>(), Align::Constant<1>()}, // i1:8:8 + {8, Align::Constant<1>(), Align::Constant<1>()}, // i8:8:8 + {16, Align::Constant<2>(), Align::Constant<2>()}, // i16:16:16 + {32, Align::Constant<4>(), Align::Constant<4>()}, // i32:32:32 + {64, Align::Constant<4>(), Align::Constant<8>()}, // i64:32:64 +}; +constexpr LayoutAlignElem DefaultFloatSpecs[] = { + {16, Align::Constant<2>(), Align::Constant<2>()}, // f16:16:16 + {32, Align::Constant<4>(), Align::Constant<4>()}, // f32:32:32 + {64, Align::Constant<8>(), Align::Constant<8>()}, // f64:64:64 + {128, Align::Constant<16>(), Align::Constant<16>()}, // f128:128:128 +}; +constexpr LayoutAlignElem DefaultVectorSpecs[] = { + {64, Align::Constant<8>(), Align::Constant<8>()}, // v64:64:64 + {128, Align::Constant<16>(), Align::Constant<16>()}, // v128:128:128 }; -DataLayout::DataLayout(StringRef LayoutString) { - BigEndian = false; - AllocaAddrSpace = 0; - ProgramAddrSpace = 0; - DefaultGlobalsAddrSpace = 0; - TheFunctionPtrAlignType = FunctionPtrAlignType::Independent; - ManglingMode = MM_None; - - // Default alignments - for (const auto &[Kind, Layout] : DefaultAlignments) { - if (Error Err = setAlignment(Kind, Layout.ABIAlign, Layout.PrefAlign, - Layout.TypeBitWidth)) - report_fatal_error(std::move(Err)); - } - if (Error Err = setPointerAlignmentInBits(0, Align(8), Align(8), 64, 64)) - report_fatal_error(std::move(Err)); +// Default pointer type specifications. +constexpr PointerAlignElem DefaultPointerSpecs[] = { + {0, 64, Align::Constant<8>(), Align::Constant<8>(), 64} // p0:64:64:64:64 +}; + +DataLayout::DataLayout() + : IntAlignments(ArrayRef(DefaultIntSpecs)), + FloatAlignments(ArrayRef(DefaultFloatSpecs)), + VectorAlignments(ArrayRef(DefaultVectorSpecs)), + Pointers(ArrayRef(DefaultPointerSpecs)) {} +DataLayout::DataLayout(StringRef LayoutString) : DataLayout() { if (Error Err = parseSpecifier(LayoutString)) report_fatal_error(std::move(Err)); } @@ -277,7 +278,7 @@ bool DataLayout::operator==(const DataLayout &Other) const { } Expected<DataLayout> DataLayout::parse(StringRef LayoutDescription) { - DataLayout Layout(""); + DataLayout Layout; if (Error Err = Layout.parseSpecifier(LayoutDescription)) return std::move(Err); return Layout; diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp index 7ba5b27..704bc8d 100644 --- a/llvm/lib/IR/Module.cpp +++ b/llvm/lib/IR/Module.cpp @@ -73,7 +73,7 @@ template class llvm::SymbolTableListTraits<GlobalIFunc>; Module::Module(StringRef MID, LLVMContext &C) : Context(C), ValSymTab(std::make_unique<ValueSymbolTable>(-1)), - ModuleID(std::string(MID)), SourceFileName(std::string(MID)), DL(""), + ModuleID(std::string(MID)), SourceFileName(std::string(MID)), IsNewDbgInfoFormat(UseNewDbgInfoFormat) { Context.addModule(this); } |