[llvm] [IR] Check parameters of target extension types on construction (PR #107268)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 5 03:47:23 PDT 2024
================
@@ -792,28 +793,51 @@ TargetExtType::TargetExtType(LLVMContext &C, StringRef Name,
TargetExtType *TargetExtType::get(LLVMContext &C, StringRef Name,
ArrayRef<Type *> Types,
ArrayRef<unsigned> Ints) {
+ return cantFail(getOrError(C, Name, Types, Ints));
+}
+
+Expected<TargetExtType *> TargetExtType::getOrError(LLVMContext &C,
+ StringRef Name,
+ ArrayRef<Type *> Types,
+ ArrayRef<unsigned> Ints) {
const TargetExtTypeKeyInfo::KeyTy Key(Name, Types, Ints);
TargetExtType *TT;
// Since we only want to allocate a fresh target type in case none is found
// and we don't want to perform two lookups (one for checking if existent and
// one for inserting the newly allocated one), here we instead lookup based on
// Key and update the reference to the target type in-place to a newly
// allocated one if not found.
- auto Insertion = C.pImpl->TargetExtTypes.insert_as(nullptr, Key);
- if (Insertion.second) {
+ auto [Iter, Inserted] = C.pImpl->TargetExtTypes.insert_as(nullptr, Key);
+ if (Inserted) {
// The target type was not found. Allocate one and update TargetExtTypes
// in-place.
TT = (TargetExtType *)C.pImpl->Alloc.Allocate(
sizeof(TargetExtType) + sizeof(Type *) * Types.size() +
sizeof(unsigned) * Ints.size(),
alignof(TargetExtType));
new (TT) TargetExtType(C, Name, Types, Ints);
- *Insertion.first = TT;
- } else {
- // The target type was found. Just return it.
- TT = *Insertion.first;
+ *Iter = TT;
+ return checkParams(TT);
}
- return TT;
+
+ // The target type was found. Just return it.
+ return *Iter;
+}
+
+Expected<TargetExtType *> TargetExtType::checkParams(TargetExtType *TTy) {
+ // Opaque types in the AArch64 name space.
+ if (TTy->Name == "aarch64.svcount" &&
+ (TTy->getNumTypeParameters() != 0 || TTy->getNumIntParameters() != 0))
+ return createStringError(
+ "Target type aarch64.svcount should have no parameters");
----------------
jayfoad wrote:
Maybe "Target _extension_ type ..." would be more correct, though I see "target type" is already reasonably common in the code base.
https://github.com/llvm/llvm-project/pull/107268
More information about the llvm-commits
mailing list