1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00

gold plugin: Remap function arguments when creating a replacement function.

When creating an internal function replacement for use in an alias we were
not remapping the argument uses in the instructions to point to the new
arguments.

llvm-svn: 219177
This commit is contained in:
Rafael Espindola 2014-10-07 00:47:38 +00:00
parent c49d88c9db
commit cc59b6926d
3 changed files with 32 additions and 16 deletions

View File

@ -1,19 +1,20 @@
$c2 = comdat any
@v1 = weak_odr global i32 41, comdat $c2
define weak_odr i32 @f1() comdat $c2 {
define weak_odr i32 @f1(i8* %this) comdat $c2 {
bb20:
store i8* %this, i8** null
br label %bb21
bb21:
ret i32 41
}
@r21 = global i32* @v1
@r22 = global i32()* @f1
@r22 = global i32(i8*)* @f1
@a21 = alias i32* @v1
@a22 = alias bitcast (i32* @v1 to i16*)
@a23 = alias i32()* @f1
@a24 = alias bitcast (i32()* @f1 to i16*)
@a23 = alias i32(i8*)* @f1
@a24 = alias bitcast (i32(i8*)* @f1 to i16*)
@a25 = alias i16* @a24

View File

@ -7,7 +7,7 @@
$c1 = comdat any
@v1 = weak_odr global i32 42, comdat $c1
define weak_odr i32 @f1() comdat $c1 {
define weak_odr i32 @f1(i8*) comdat $c1 {
bb10:
br label %bb11
bb11:
@ -15,13 +15,13 @@ bb11:
}
@r11 = global i32* @v1
@r12 = global i32 ()* @f1
@r12 = global i32 (i8*)* @f1
@a11 = alias i32* @v1
@a12 = alias bitcast (i32* @v1 to i16*)
@a13 = alias i32 ()* @f1
@a14 = alias bitcast (i32 ()* @f1 to i16*)
@a13 = alias i32 (i8*)* @f1
@a14 = alias bitcast (i32 (i8*)* @f1 to i16*)
@a15 = alias i16* @a14
; CHECK: $c1 = comdat any
@ -30,34 +30,35 @@ bb11:
; CHECK: @v1 = weak_odr global i32 42, comdat $c1
; CHECK: @r11 = global i32* @v1{{$}}
; CHECK: @r12 = global i32 ()* @f1{{$}}
; CHECK: @r12 = global i32 (i8*)* @f1{{$}}
; CHECK: @r21 = global i32* @v1{{$}}
; CHECK: @r22 = global i32 ()* @f1{{$}}
; CHECK: @r22 = global i32 (i8*)* @f1{{$}}
; CHECK: @v11 = internal global i32 41, comdat $c2
; CHECK: @a11 = alias i32* @v1{{$}}
; CHECK: @a12 = alias bitcast (i32* @v1 to i16*)
; CHECK: @a13 = alias i32 ()* @f1{{$}}
; CHECK: @a14 = alias bitcast (i32 ()* @f1 to i16*)
; CHECK: @a13 = alias i32 (i8*)* @f1{{$}}
; CHECK: @a14 = alias bitcast (i32 (i8*)* @f1 to i16*)
; CHECK: @a21 = alias i32* @v11{{$}}
; CHECK: @a22 = alias bitcast (i32* @v11 to i16*)
; CHECK: @a23 = alias i32 ()* @f12{{$}}
; CHECK: @a24 = alias bitcast (i32 ()* @f12 to i16*)
; CHECK: @a23 = alias i32 (i8*)* @f12{{$}}
; CHECK: @a24 = alias bitcast (i32 (i8*)* @f12 to i16*)
; CHECK: define weak_odr i32 @f1() comdat $c1 {
; CHECK: define weak_odr i32 @f1(i8*) comdat $c1 {
; CHECK-NEXT: bb10:
; CHECK-NEXT: br label %bb11{{$}}
; CHECK: bb11:
; CHECK-NEXT: ret i32 42
; CHECK-NEXT: }
; CHECK: define internal i32 @f12() comdat $c2 {
; CHECK: define internal i32 @f12(i8* %this) comdat $c2 {
; CHECK-NEXT: bb20:
; CHECK-NEXT: store i8* %this, i8** null
; CHECK-NEXT: br label %bb21
; CHECK: bb21:
; CHECK-NEXT: ret i32 41

View File

@ -493,7 +493,21 @@ static GlobalObject *makeInternalReplacement(GlobalObject *GO) {
if (auto *F = dyn_cast<Function>(GO)) {
auto *NewF = Function::Create(
F->getFunctionType(), GlobalValue::InternalLinkage, F->getName(), M);
ValueToValueMapTy VM;
Function::arg_iterator NewI = NewF->arg_begin();
for (auto &Arg : F->args()) {
NewI->setName(Arg.getName());
VM[&Arg] = NewI;
++NewI;
}
NewF->getBasicBlockList().splice(NewF->end(), F->getBasicBlockList());
for (auto &BB : *NewF) {
for (auto &Inst : BB)
RemapInstruction(&Inst, VM, RF_IgnoreMissingEntries);
}
Ret = NewF;
F->deleteBody();
} else {