[llvm] a6bd224 - [ExecutionEngine] Support TargetExtType in Interpreter

Bing1 Yu via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 7 18:25:17 PDT 2023


Author: Wenju He
Date: 2023-06-08T09:25:08+08:00
New Revision: a6bd2241b86148939db37d4a9427e0f0f876b501

URL: https://github.com/llvm/llvm-project/commit/a6bd2241b86148939db37d4a9427e0f0f876b501
DIFF: https://github.com/llvm/llvm-project/commit/a6bd2241b86148939db37d4a9427e0f0f876b501.diff

LOG: [ExecutionEngine] Support TargetExtType in Interpreter

When llvm Interpreter is used to execute bitcode, it shall be able to handle TargetExtType.

Reviewed By: jcranmer-intel

Differential Revision: https://reviews.llvm.org/D148283

Added: 
    llvm/test/ExecutionEngine/test-interp-target-ext-type.ll

Modified: 
    llvm/lib/ExecutionEngine/ExecutionEngine.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ExecutionEngine/ExecutionEngine.cpp b/llvm/lib/ExecutionEngine/ExecutionEngine.cpp
index 3afc41fd9df02..768d845013372 100644
--- a/llvm/lib/ExecutionEngine/ExecutionEngine.cpp
+++ b/llvm/lib/ExecutionEngine/ExecutionEngine.cpp
@@ -878,6 +878,12 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
     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 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
 
 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::StoreValueToMemory(const GenericValue &Val,
 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()) {

diff  --git a/llvm/test/ExecutionEngine/test-interp-target-ext-type.ll b/llvm/test/ExecutionEngine/test-interp-target-ext-type.ll
new file mode 100644
index 0000000000000..8abc618e35e77
--- /dev/null
+++ b/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
+}


        


More information about the llvm-commits mailing list