GPURuntimeDebugPrinter: Printer pointer values (except if they are strings)
authorTobias Grosser <tobias@grosser.es>
Fri, 17 Jul 2015 13:57:57 +0000 (13:57 +0000)
committerTobias Grosser <tobias@grosser.es>
Fri, 17 Jul 2015 13:57:57 +0000 (13:57 +0000)
Only pointer values in constant address space are assumed to be strings. For
all other pointers their address is printed.

llvm-svn: 242524

polly/lib/CodeGen/RuntimeDebugBuilder.cpp

index f8503d4..c9ae10a 100644 (file)
@@ -130,14 +130,19 @@ void RuntimeDebugBuilder::createGPUVAPrinter(PollyIRBuilder &Builder,
         Ty = Builder.getInt64Ty();
         Val = Builder.CreateSExt(Val, Ty);
       }
+    } else if (auto PtTy = dyn_cast<PointerType>(Ty)) {
+      if (PtTy->getAddressSpace() == 4) {
+        // Pointers in constant address space are printed as strings
+        Val = Builder.CreateGEP(Val, Builder.getInt64(0));
+        auto F = RuntimeDebugBuilder::getAddressSpaceCast(Builder, 4, 0);
+        Val = Builder.CreateCall(F, Val);
+        Ty = Val->getType();
+      } else {
+        Val = Builder.CreatePtrToInt(Val, Builder.getInt64Ty());
+        Ty = Val->getType();
+      }
     } else {
-      // If it is not a number, it must be a string type.
-      Val = Builder.CreateGEP(Val, Builder.getInt64(0));
-      assert((Val->getType() == Builder.getInt8PtrTy(4)) &&
-             "Expected i8 ptr placed in constant address space");
-      auto F = RuntimeDebugBuilder::getAddressSpaceCast(Builder, 4, 0);
-      Val = Builder.CreateCall(F, Val);
-      Ty = Val->getType();
+      llvm_unreachable("Unknown type");
     }
 
     Ptr = Builder.CreatePointerBitCastOrAddrSpaceCast(Ptr, Ty->getPointerTo(5));