[llvm] [DataLayout] Refactor parsing of i/f/v/a specifications (PR #104699)
Sergei Barannikov via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 18 06:01:32 PDT 2024
================
@@ -376,6 +376,86 @@ static Error getAddrSpace(StringRef R, unsigned &AddrSpace) {
return Error::success();
}
+Error DataLayout::parsePrimitiveSpec(StringRef Spec) {
+ // [ifv]<size>:<abi>[:<pref>]
+ SmallVector<StringRef, 3> Components;
+ char Specifier = Spec.front();
+ assert(Specifier == 'i' || Specifier == 'f' || Specifier == 'v');
+ Spec.drop_front().split(Components, ':');
+
+ if (Components.size() < 2 || Components.size() > 3)
+ return createSpecFormatError(Twine(Specifier) + "<size>:<abi>[:<pref>]");
+
+ // Size. Required, cannot be zero.
+ unsigned BitWidth;
+ if (Error Err = parseSize(Components[0], BitWidth))
+ return Err;
+
+ // ABI alignment. Required, cannot be zero.
+ Align ABIAlign;
+ if (Error Err = parseAlignment(Components[1], ABIAlign, "ABI"))
+ return Err;
+
+ if (Specifier == 'i' && BitWidth == 8 && ABIAlign != 1)
+ return createStringError("i8 must be 8-bit aligned");
+
+ // Preferred alignment. Optional, defaults to the ABI alignment.
+ // Can be zero, meaning use one byte alignment.
----------------
s-barannikov wrote:
I'd like to, here and elsewhere. Need to update LangRef though, which currently doesn't impose any restrictions on alignments. I'll create a candidate PR soon.
https://github.com/llvm/llvm-project/pull/104699
More information about the llvm-commits
mailing list