[PATCH] D148283: [ExecutionEngine] Support TargetExtType in Interpreter

Wenju He via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 6 18:38:23 PDT 2023


wenju updated this revision to Diff 529119.
wenju added a comment.

add test of global and poison value, add comment of 'It is safe to treat TargetExtType as its layout type'


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148283/new/

https://reviews.llvm.org/D148283

Files:
  llvm/lib/ExecutionEngine/ExecutionEngine.cpp
  llvm/test/ExecutionEngine/test-interp-target-ext-type.ll


Index: llvm/test/ExecutionEngine/test-interp-target-ext-type.ll
===================================================================
--- /dev/null
+++ llvm/test/ExecutionEngine/test-interp-target-ext-type.ll
@@ -0,0 +1,16 @@
+; RUN: %lli -jit-kind=mcjit -force-interpreter=true %s > /dev/null
+
+; Check interpreter isn't crashing in handling target extension type.
+
+ at g = global target("spirv.Event") zeroinitializer, align 8
+
+define i32 @main() {
+  %event = alloca target("spirv.Event"), align 8
+  store target("spirv.Event") zeroinitializer, ptr %event, align 8
+  %e = load target("spirv.Event"), ptr %event, align 8
+
+  store target("spirv.Event") poison, ptr @g, align 8
+  %e2 = load target("spirv.Event"), ptr @g, align 8
+
+  ret i32 0
+}
Index: llvm/lib/ExecutionEngine/ExecutionEngine.cpp
===================================================================
--- llvm/lib/ExecutionEngine/ExecutionEngine.cpp
+++ llvm/lib/ExecutionEngine/ExecutionEngine.cpp
@@ -878,6 +878,12 @@
     report_fatal_error(OS.str());
   }
 
+  if (auto *TETy = dyn_cast<TargetExtType>(C->getType())) {
+    assert(TETy->hasProperty(TargetExtType::HasZeroInit) && C->isNullValue() &&
+           "TargetExtType only supports null constant value");
+    C = Constant::getNullValue(TETy->getLayoutType());
+  }
+
   // Otherwise, we have a simple constant.
   GenericValue Result;
   switch (C->getType()->getTypeID()) {
@@ -1017,6 +1023,11 @@
 
 void ExecutionEngine::StoreValueToMemory(const GenericValue &Val,
                                          GenericValue *Ptr, Type *Ty) {
+  // It is safe to treat TargetExtType as its layout type since the underlying
+  // bits are only copied and are not inspected.
+  if (auto *TETy = dyn_cast<TargetExtType>(Ty))
+    Ty = TETy->getLayoutType();
+
   const unsigned StoreBytes = getDataLayout().getTypeStoreSize(Ty);
 
   switch (Ty->getTypeID()) {
@@ -1068,6 +1079,9 @@
 void ExecutionEngine::LoadValueFromMemory(GenericValue &Result,
                                           GenericValue *Ptr,
                                           Type *Ty) {
+  if (auto *TETy = dyn_cast<TargetExtType>(Ty))
+    Ty = TETy->getLayoutType();
+
   const unsigned LoadBytes = getDataLayout().getTypeStoreSize(Ty);
 
   switch (Ty->getTypeID()) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148283.529119.patch
Type: text/x-patch
Size: 2279 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230607/ecd56c51/attachment.bin>


More information about the llvm-commits mailing list