Skip to content

Commit 8d5d68f

Browse files
committed
getMangledTypeStr: clarify how it mangles types, and add tests
"Write a set of tests that show how name mangling is done for overloaded intrinsics." These happen to use gc.relocates to exercise the codepath in question, but is not a GC specific test. Patch by: [email protected] Differential Revision: http://reviews.llvm.org/D6915 llvm-svn: 226056
1 parent a50a89a commit 8d5d68f

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

llvm/lib/IR/Function.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,10 @@ unsigned Function::lookupIntrinsicID() const {
455455
/// which can't be confused with it's prefix. This ensures we don't have
456456
/// collisions between two unrelated function types. Otherwise, you might
457457
/// parse ffXX as f(fXX) or f(fX)X. (X is a placeholder for any other type.)
458+
/// Manglings of integers, floats, and vectors ('i', 'f', and 'v' prefix in most
459+
/// cases) fall back to the MVT codepath, where they could be mangled to
460+
/// 'x86mmx', for example; matching on derived types is not sufficient to mangle
461+
/// everything.
458462
static std::string getMangledTypeStr(Type* Ty) {
459463
std::string Result;
460464
if (PointerType* PTyp = dyn_cast<PointerType>(Ty)) {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
; RUN: opt -verify -S < %s
2+
3+
; Tests the name mangling performed by the codepath following
4+
; getMangledTypeStr(). Only tests that code with the various manglings
5+
; run fine: doesn't actually test the mangling with the type of the
6+
; arguments. Meant to serve as an example-document on how the user
7+
; should do name manglings.
8+
9+
; Exercise the most general case, llvm_anyptr_type, using gc.relocate
10+
; and gc.statepoint. Note that it has nothing to do with gc.*
11+
; functions specifically: any function that accepts llvm_anyptr_type
12+
; will serve the purpose.
13+
14+
; function and integer
15+
define i32* @test_iAny(i32* %v) {
16+
%tok = call i32 (i1 ()*, i32, i32, ...)* @llvm.experimental.gc.statepoint.p0f_i1f(i1 ()* @return_i1, i32 0, i32 0, i32 0, i32* %v)
17+
%v-new = call i32* @llvm.experimental.gc.relocate.p0i32(i32 %tok, i32 4, i32 4)
18+
ret i32* %v-new
19+
}
20+
21+
; float
22+
define float* @test_fAny(float* %v) {
23+
%tok = call i32 (i1 ()*, i32, i32, ...)* @llvm.experimental.gc.statepoint.p0f_i1f(i1 ()* @return_i1, i32 0, i32 0, i32 0, float* %v)
24+
%v-new = call float* @llvm.experimental.gc.relocate.p0f32(i32 %tok, i32 4, i32 4)
25+
ret float* %v-new
26+
}
27+
28+
; array of integers
29+
define [3 x i32]* @test_aAny([3 x i32]* %v) {
30+
%tok = call i32 (i1 ()*, i32, i32, ...)* @llvm.experimental.gc.statepoint.p0f_i1f(i1 ()* @return_i1, i32 0, i32 0, i32 0, [3 x i32]* %v)
31+
%v-new = call [3 x i32]* @llvm.experimental.gc.relocate.p0a3i32(i32 %tok, i32 4, i32 4)
32+
ret [3 x i32]* %v-new
33+
}
34+
35+
; vector of integers
36+
define <3 x i32>* @test_vAny(<3 x i32>* %v) {
37+
%tok = call i32 (i1 ()*, i32, i32, ...)* @llvm.experimental.gc.statepoint.p0f_i1f(i1 ()* @return_i1, i32 0, i32 0, i32 0, <3 x i32>* %v)
38+
%v-new = call <3 x i32>* @llvm.experimental.gc.relocate.p0v3i32(i32 %tok, i32 4, i32 4)
39+
ret <3 x i32>* %v-new
40+
}
41+
42+
declare zeroext i1 @return_i1()
43+
declare i32 @llvm.experimental.gc.statepoint.p0f_i1f(i1 ()*, i32, i32, ...)
44+
declare i32* @llvm.experimental.gc.relocate.p0i32(i32, i32, i32)
45+
declare float* @llvm.experimental.gc.relocate.p0f32(i32, i32, i32)
46+
declare [3 x i32]* @llvm.experimental.gc.relocate.p0a3i32(i32, i32, i32)
47+
declare <3 x i32>* @llvm.experimental.gc.relocate.p0v3i32(i32, i32, i32)

0 commit comments

Comments
 (0)