[PATCH] D29925: Implement intrinsic mangling for literal struct types.Fixes PR 31921

Daniel Berlin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 13 21:44:20 PST 2017


dberlin created this revision.
Herald added a subscriber: sanjoy.

Predicateinfo requires an ugly workaround to try to avoid literal
struct types due to the intrinsic mangling not being implemented.
This workaround actually does not work in all cases (you can hit the
assert by bootstrapping with -print-predicateinfo), and can't be made
to work without DFS'ing the type (IE copying getMangledStr and using a
version that detects if it would crash).

Rather than do that, i just implemented the mangling.  It seems
simple, since they are unified structurally.

Looking at the overloaded-mangling testcase we have, it actually turns
out the gc intrinsics will *also* crash if you try to use a literal
struct.  Thus, the testcase added fails before this patch, and works
after, without needing to resort to predicateinfo.


https://reviews.llvm.org/D29925

Files:
  lib/IR/Function.cpp
  test/CodeGen/Generic/overloaded-intrinsic-name.ll


Index: test/CodeGen/Generic/overloaded-intrinsic-name.ll
===================================================================
--- test/CodeGen/Generic/overloaded-intrinsic-name.ll
+++ test/CodeGen/Generic/overloaded-intrinsic-name.ll
@@ -48,10 +48,17 @@
        ret %struct.test* %v-new
 }
 
+; literal struct
+define {i64, i64}* @test_literal_struct({i64, i64}* %v) gc "statepoint-example" {
+       %tok = call token (i64, i32, i1 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i1f(i64 0, i32 0, i1 ()* @return_i1, i32 0, i32 0, i32 0, i32 0, {i64, i64} *%v)
+       %v-new = call {i64, i64}* @llvm.experimental.gc.relocate.p0si64i64.test(token %tok,  i32 7, i32 7)
+       ret {i64, i64}* %v-new
+}
 declare zeroext i1 @return_i1()
 declare token @llvm.experimental.gc.statepoint.p0f_i1f(i64, i32, i1 ()*, i32, i32, ...)
 declare i32* @llvm.experimental.gc.relocate.p0i32(token, i32, i32)
 declare float* @llvm.experimental.gc.relocate.p0f32(token, i32, i32)
 declare [3 x i32]* @llvm.experimental.gc.relocate.p0a3i32(token, i32, i32)
 declare <3 x i32>* @llvm.experimental.gc.relocate.p0v3i32(token, i32, i32)
 declare %struct.test* @llvm.experimental.gc.relocate.p0struct.test(token, i32, i32)
+declare {i64, i64}* @llvm.experimental.gc.relocate.p0si64i64.test(token, i32, i32)
Index: lib/IR/Function.cpp
===================================================================
--- lib/IR/Function.cpp
+++ lib/IR/Function.cpp
@@ -533,10 +533,15 @@
   } else if (ArrayType* ATyp = dyn_cast<ArrayType>(Ty)) {
     Result += "a" + llvm::utostr(ATyp->getNumElements()) +
       getMangledTypeStr(ATyp->getElementType());
-  } else if (StructType* STyp = dyn_cast<StructType>(Ty)) {
-    assert(!STyp->isLiteral() && "TODO: implement literal types");
-    Result += STyp->getName();
-  } else if (FunctionType* FT = dyn_cast<FunctionType>(Ty)) {
+  } else if (StructType *STyp = dyn_cast<StructType>(Ty)) {
+    if (!STyp->isLiteral()) {
+      Result += STyp->getName();
+    } else {
+      Result += "s";
+      for (size_t i = 0; i < STyp->getNumElements(); ++i)
+        Result += getMangledTypeStr(STyp->getElementType(i));
+    }
+  } else if (FunctionType *FT = dyn_cast<FunctionType>(Ty)) {
     Result += "f_" + getMangledTypeStr(FT->getReturnType());
     for (size_t i = 0; i < FT->getNumParams(); i++)
       Result += getMangledTypeStr(FT->getParamType(i));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29925.88303.patch
Type: text/x-patch
Size: 2376 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170214/45b945ce/attachment.bin>


More information about the llvm-commits mailing list