Skip to content

Commit

Permalink
[Attributor] Fixup block addresses after rewriting function signature
Browse files Browse the repository at this point in the history
Reviewers: jdoerfert, sstefan1, uenoku

Reviewed By: jdoerfert

Subscribers: hiraditya, uenoku, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D79801
  • Loading branch information
sndmitriev committed May 12, 2020
1 parent 6c29073 commit 32f5ee8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
8 changes: 8 additions & 0 deletions llvm/lib/Transforms/IPO/Attributor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,14 @@ ChangeStatus Attributor::rewriteFunctionSignatures(
NewFn->getBasicBlockList().splice(NewFn->begin(),
OldFn->getBasicBlockList());

// Fixup block addresses to reference new function.
SmallVector<BlockAddress *, 8u> BlockAddresses;
for (User *U : OldFn->users())
if (auto *BA = dyn_cast<BlockAddress>(U))
BlockAddresses.push_back(BA);
for (auto *BA : BlockAddresses)
BA->replaceAllUsesWith(BlockAddress::get(NewFn, BA->getBasicBlock()));

// Set of all "call-like" instructions that invoke the old function mapped
// to their new replacements.
SmallVector<std::pair<CallBase *, CallBase *>, 8> CallSitePairs;
Expand Down
33 changes: 33 additions & 0 deletions llvm/test/Transforms/Attributor/misc_crash.ll
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,36 @@ ret_bb:
%2 = load i32, i32* @var2
ret i32 %2
}

define void @func4() {
; CHECK-LABEL: define {{[^@]+}}@func4
; CHECK-NEXT: call void @func5()
; CHECK-NEXT: ret void
;
call void @func5(i32 0)
ret void
}

define internal void @func5(i32 %0) {
; CHECK-LABEL: define {{[^@]+}}@func5
; CHECK-NEXT: [[TMP1:%.*]] = alloca i8*
; CHECK-NEXT: br label %block
; CHECK: block:
; CHECK-NEXT: store i8* blockaddress(@func5, %block), i8** [[TMP1]]
; CHECK-NEXT: [[TMP2:%.*]] = load i8*, i8** [[TMP1]]
; CHECK-NEXT: call void @func6(i8* [[TMP2]])
; CHECK-NEXT: ret void
;
%tmp = alloca i8*
br label %block

block:
store i8* blockaddress(@func5, %block), i8** %tmp
%addr = load i8*, i8** %tmp
call void @func6(i8* %addr)
ret void
}

; CHECK-LABEL: declare {{[^@]+}}@func6
; CHECK-SAME: (i8*)
declare void @func6(i8*)

0 comments on commit 32f5ee8

Please sign in to comment.