[llvm] r219177 - gold plugin: Remap function arguments when creating a replacement function.
Rafael Espindola
rafael.espindola at gmail.com
Mon Oct 6 17:47:38 PDT 2014
Author: rafael
Date: Mon Oct 6 19:47:38 2014
New Revision: 219177
URL: http://llvm.org/viewvc/llvm-project?rev=219177&view=rev
Log:
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.
Modified:
llvm/trunk/test/tools/gold/Inputs/comdat.ll
llvm/trunk/test/tools/gold/comdat.ll
llvm/trunk/tools/gold/gold-plugin.cpp
Modified: llvm/trunk/test/tools/gold/Inputs/comdat.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/gold/Inputs/comdat.ll?rev=219177&r1=219176&r2=219177&view=diff
==============================================================================
--- llvm/trunk/test/tools/gold/Inputs/comdat.ll (original)
+++ llvm/trunk/test/tools/gold/Inputs/comdat.ll Mon Oct 6 19:47:38 2014
@@ -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
- at r22 = global i32()* @f1
+ at r22 = global i32(i8*)* @f1
@a21 = alias i32* @v1
@a22 = alias bitcast (i32* @v1 to i16*)
- at a23 = alias i32()* @f1
- at a24 = alias bitcast (i32()* @f1 to i16*)
+ at a23 = alias i32(i8*)* @f1
+ at a24 = alias bitcast (i32(i8*)* @f1 to i16*)
@a25 = alias i16* @a24
Modified: llvm/trunk/test/tools/gold/comdat.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/gold/comdat.ll?rev=219177&r1=219176&r2=219177&view=diff
==============================================================================
--- llvm/trunk/test/tools/gold/comdat.ll (original)
+++ llvm/trunk/test/tools/gold/comdat.ll Mon Oct 6 19:47:38 2014
@@ -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
- at r12 = global i32 ()* @f1
+ at r12 = global i32 (i8*)* @f1
@a11 = alias i32* @v1
@a12 = alias bitcast (i32* @v1 to i16*)
- at a13 = alias i32 ()* @f1
- at a14 = alias bitcast (i32 ()* @f1 to i16*)
+ at a13 = alias i32 (i8*)* @f1
+ at 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
Modified: llvm/trunk/tools/gold/gold-plugin.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/gold/gold-plugin.cpp?rev=219177&r1=219176&r2=219177&view=diff
==============================================================================
--- llvm/trunk/tools/gold/gold-plugin.cpp (original)
+++ llvm/trunk/tools/gold/gold-plugin.cpp Mon Oct 6 19:47:38 2014
@@ -493,7 +493,21 @@ static GlobalObject *makeInternalReplace
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 {
More information about the llvm-commits
mailing list