[llvm] ec08f03 - [OpaquePtr] Mangle intrinsics with opaque pointers arguments

Zequan Wu via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 23 10:52:26 PDT 2021


Author: Zequan Wu
Date: 2021-06-23T10:52:13-07:00
New Revision: ec08f03be3942d4ae6694d0f7a9b490fe3cbba9b

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

LOG: [OpaquePtr] Mangle intrinsics with opaque pointers arguments

Mangling intrinsics with opaque pointer arguments using "op"+{address space}.

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

Added: 
    

Modified: 
    llvm/lib/IR/Function.cpp
    llvm/test/Verifier/opaque-ptr.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp
index 8f1148d461eb..07c603fd98a6 100644
--- a/llvm/lib/IR/Function.cpp
+++ b/llvm/lib/IR/Function.cpp
@@ -775,10 +775,13 @@ void Function::recalculateIntrinsicID() {
 /// indicating that extra care must be taken to ensure a unique name.
 static std::string getMangledTypeStr(Type *Ty, bool &HasUnnamedType) {
   std::string Result;
-  if (PointerType* PTyp = dyn_cast<PointerType>(Ty)) {
-    Result += "p" + utostr(PTyp->getAddressSpace()) +
-              getMangledTypeStr(PTyp->getElementType(), HasUnnamedType);
-  } else if (ArrayType* ATyp = dyn_cast<ArrayType>(Ty)) {
+  if (PointerType *PTyp = dyn_cast<PointerType>(Ty)) {
+    Result += "p" + utostr(PTyp->getAddressSpace());
+    // Opaque pointer doesn't have pointee type information, so we just mangle
+    // address space for opaque pointer.
+    if (!PTyp->isOpaque())
+      Result += getMangledTypeStr(PTyp->getElementType(), HasUnnamedType);
+  } else if (ArrayType *ATyp = dyn_cast<ArrayType>(Ty)) {
     Result += "a" + utostr(ATyp->getNumElements()) +
               getMangledTypeStr(ATyp->getElementType(), HasUnnamedType);
   } else if (StructType *STyp = dyn_cast<StructType>(Ty)) {
@@ -803,7 +806,7 @@ static std::string getMangledTypeStr(Type *Ty, bool &HasUnnamedType) {
       Result += "vararg";
     // Ensure nested function types are distinguishable.
     Result += "f";
-  } else if (VectorType* VTy = dyn_cast<VectorType>(Ty)) {
+  } else if (VectorType *VTy = dyn_cast<VectorType>(Ty)) {
     ElementCount EC = VTy->getElementCount();
     if (EC.isScalable())
       Result += "nx";

diff  --git a/llvm/test/Verifier/opaque-ptr.ll b/llvm/test/Verifier/opaque-ptr.ll
index 322544471a56..3cdcb306a944 100644
--- a/llvm/test/Verifier/opaque-ptr.ll
+++ b/llvm/test/Verifier/opaque-ptr.ll
@@ -23,3 +23,14 @@ define void @atomicrmw(ptr %a, i32 %i) {
     %b = atomicrmw add ptr %a, i32 %i acquire
     ret void
 }
+
+define void @opaque_mangle(ptr %a) {
+    call void @llvm.lifetime.start.p0(i64 8, ptr %a)
+    call void @llvm.lifetime.end.p0(i64 8, ptr %a)
+    ret void
+}
+
+; CHECK: @llvm.lifetime.start.p0
+; CHECK: @llvm.lifetime.end.p0
+declare void @llvm.lifetime.start.p0(i64, ptr nocapture)
+declare void @llvm.lifetime.end.p0(i64, ptr nocapture)


        


More information about the llvm-commits mailing list