[llvm] [IR] Verify parameters of TargetExtTypes (PR #105084)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 20 09:32:41 PDT 2024
https://github.com/jayfoad created https://github.com/llvm/llvm-project/pull/105084
This just adds a place in the IR verifier to verify that TargetExtTypes
are well formed. As a start it checks that target("aarch64.svcount")
has no (type or integer) parameters.
>From 187040b9eb334ca4f2cf5ca3cc7f5d96f619e71b Mon Sep 17 00:00:00 2001
From: Jay Foad <jay.foad at amd.com>
Date: Tue, 20 Aug 2024 17:30:05 +0100
Subject: [PATCH] [IR] Verify parameters of TargetExtTypes
This just adds a place in the IR verifier to verify that TargetExtTypes
are well formed. As a start it checks that target("aarch64.svcount")
has no (type or integer) parameters.
---
llvm/lib/IR/Verifier.cpp | 17 ++++++++++++++++-
llvm/test/Verifier/target-types.ll | 8 ++++++++
2 files changed, 24 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/Verifier/target-types.ll
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 4e097b732cc2cb..e79e4e6a9b52fc 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -492,6 +492,7 @@ class Verifier : public InstVisitor<Verifier>, VerifierSupport {
enum class AreDebugLocsAllowed { No, Yes };
// Verification methods...
+ void visitTargetExtType(TargetExtType *Ty);
void visitGlobalValue(const GlobalValue &GV);
void visitGlobalVariable(const GlobalVariable &GV);
void visitGlobalAlias(const GlobalAlias &GA);
@@ -723,6 +724,16 @@ static void forEachUser(const Value *User,
}
}
+void Verifier::visitTargetExtType(TargetExtType *TTy) {
+ StringRef Name = TTy->getName();
+
+ // Opaque types in the AArch64 name space.
+ if (Name == "aarch64.svcount") {
+ Check(TTy->getNumTypeParameters() == 0 && TTy->getNumIntParameters() == 0,
+ "Target type should have no parameters", TTy);
+ }
+}
+
void Verifier::visitGlobalValue(const GlobalValue &GV) {
Check(!GV.isDeclaration() || GV.hasValidDeclarationLinkage(),
"Global is external, but doesn't have external or weak linkage!", &GV);
@@ -908,10 +919,12 @@ void Verifier::visitGlobalVariable(const GlobalVariable &GV) {
// Check if it's a target extension type that disallows being used as a
// global.
- if (auto *TTy = dyn_cast<TargetExtType>(GV.getValueType()))
+ if (auto *TTy = dyn_cast<TargetExtType>(GV.getValueType())) {
Check(TTy->hasProperty(TargetExtType::CanBeGlobal),
"Global @" + GV.getName() + " has illegal target extension type",
TTy);
+ visitTargetExtType(TTy);
+ }
if (!GV.hasInitializer()) {
visitGlobalValue(GV);
@@ -4285,6 +4298,8 @@ void Verifier::visitAllocaInst(AllocaInst &AI) {
SmallPtrSet<Type*, 4> Visited;
Check(AI.getAllocatedType()->isSized(&Visited),
"Cannot allocate unsized type", &AI);
+ if (auto *TTy = dyn_cast<TargetExtType>(AI.getAllocatedType()))
+ visitTargetExtType(TTy);
Check(AI.getArraySize()->getType()->isIntegerTy(),
"Alloca array size must have integer type", &AI);
if (MaybeAlign A = AI.getAlign()) {
diff --git a/llvm/test/Verifier/target-types.ll b/llvm/test/Verifier/target-types.ll
new file mode 100644
index 00000000000000..da4cdaf55eee49
--- /dev/null
+++ b/llvm/test/Verifier/target-types.ll
@@ -0,0 +1,8 @@
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
+
+; CHECK: Target type should have no parameters
+; CHECK-NEXT: target("aarch64.svcount", i32, 0)
+define void @test_alloca_svcount_ptr_int() {
+ %ptr = alloca target("aarch64.svcount", i32, 0)
+ ret void
+}
More information about the llvm-commits
mailing list