[PATCH] D101045: [IR][Verifier] Allow alloca outside alloca address space

Andy Wingo via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 22 04:12:25 PDT 2021


wingo created this revision.
wingo added a reviewer: tlively.
Herald added subscribers: dexonsmith, sunfish, hiraditya.
wingo requested review of this revision.
Herald added subscribers: llvm-commits, aheejin.
Herald added a project: LLVM.

The WebAssembly target has a class of values that can't be written to
the stack, but would like to allow function-local variables to be
modelled using the usual alloca approach.  These allocations will be
lowered to off-stack automatic-duration storage locations during
instruction selection.  For this strategy to work, we need to relax the
restriction on alloca IR instructions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101045

Files:
  llvm/lib/IR/Verifier.cpp
  llvm/test/Assembler/datalayout-alloca-addrspace-mismatch-0.ll
  llvm/test/Assembler/datalayout-alloca-addrspace-mismatch-1.ll
  llvm/test/Assembler/datalayout-alloca-addrspace-mismatch-2.ll
  llvm/test/Verifier/alloca-alternate-addrspace-valid.ll


Index: llvm/test/Verifier/alloca-alternate-addrspace-valid.ll
===================================================================
--- /dev/null
+++ llvm/test/Verifier/alloca-alternate-addrspace-valid.ll
@@ -0,0 +1,22 @@
+; RUN: llvm-as %s -o /dev/null
+
+; Should assemble without error.
+
+target datalayout = "A1"
+
+define void @use_alloca0() {
+  %alloca_scalar_no_align = alloca i32, addrspace(2)
+  ret void
+}
+
+define void @use_alloca1() {
+  %alloca_scalar_no_align = alloca i32, align 4, addrspace(2)
+  ret void
+}
+
+define void @use_alloca2() {
+  %alloca_scalar_no_align = alloca i32, align 4, addrspace(2), !foo !0
+  ret void
+}
+
+!0 = !{}
Index: llvm/test/Assembler/datalayout-alloca-addrspace-mismatch-2.ll
===================================================================
--- llvm/test/Assembler/datalayout-alloca-addrspace-mismatch-2.ll
+++ /dev/null
@@ -1,13 +0,0 @@
-; RUN: not llvm-as < %s 2>&1 | FileCheck %s
-
-target datalayout = "A1"
-
-; CHECK: Allocation instruction pointer not in the stack address space!
-; CHECK-NEXT:  %alloca_scalar_no_align = alloca i32, align 4, addrspace(2), !foo !0
-
-define void @use_alloca() {
-  %alloca_scalar_no_align = alloca i32, align 4, addrspace(2), !foo !0
-  ret void
-}
-
-!0 = !{}
Index: llvm/test/Assembler/datalayout-alloca-addrspace-mismatch-1.ll
===================================================================
--- llvm/test/Assembler/datalayout-alloca-addrspace-mismatch-1.ll
+++ /dev/null
@@ -1,11 +0,0 @@
-; RUN: not llvm-as < %s 2>&1 | FileCheck %s
-
-target datalayout = "A1"
-
-; CHECK: Allocation instruction pointer not in the stack address space!
-; CHECK-NEXT:  %alloca_scalar_no_align = alloca i32, align 4, addrspace(2)
-
-define void @use_alloca() {
-  %alloca_scalar_no_align = alloca i32, align 4, addrspace(2)
-  ret void
-}
Index: llvm/test/Assembler/datalayout-alloca-addrspace-mismatch-0.ll
===================================================================
--- llvm/test/Assembler/datalayout-alloca-addrspace-mismatch-0.ll
+++ /dev/null
@@ -1,11 +0,0 @@
-; RUN: not llvm-as < %s 2>&1 | FileCheck %s
-
-target datalayout = "A1"
-
-; CHECK: Allocation instruction pointer not in the stack address space!
-; CHECK-NEXT:  %alloca_scalar_no_align = alloca i32, align 4, addrspace(2)
-
-define void @use_alloca() {
-  %alloca_scalar_no_align = alloca i32, addrspace(2)
-  ret void
-}
Index: llvm/lib/IR/Verifier.cpp
===================================================================
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -3801,11 +3801,6 @@
 
 void Verifier::visitAllocaInst(AllocaInst &AI) {
   SmallPtrSet<Type*, 4> Visited;
-  PointerType *PTy = AI.getType();
-  // TODO: Relax this restriction?
-  Assert(PTy->getAddressSpace() == DL.getAllocaAddrSpace(),
-         "Allocation instruction pointer not in the stack address space!",
-         &AI);
   Assert(AI.getAllocatedType()->isSized(&Visited),
          "Cannot allocate unsized type", &AI);
   Assert(AI.getArraySize()->getType()->isIntegerTy(),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101045.339555.patch
Type: text/x-patch
Size: 3027 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210422/9e557a08/attachment.bin>


More information about the llvm-commits mailing list