1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

BlockExtractor: Don’t delete functions directly

Blocks may have function calls, so don’t erase functions
directly to avoid erasing a function that has a user.

llvm-svn: 327340
This commit is contained in:
Volkan Keles 2018-03-12 22:28:18 +00:00
parent db7886716e
commit e71a34b01d
3 changed files with 18 additions and 3 deletions

View File

@ -161,8 +161,9 @@ bool BlockExtractor::runOnModule(Module &M) {
// Erase the functions.
if (EraseFunctions || BlockExtractorEraseFuncs) {
for (Function *F : Functions) {
DEBUG(dbgs() << "BlockExtractor: Deleting " << F->getName() << "\n");
F->eraseFromParent();
DEBUG(dbgs() << "BlockExtractor: Trying to delete " << F->getName()
<< "\n");
F->deleteBody();
}
// Set linkage as ExternalLinkage to avoid erasing unreachable functions.
for (Function &F : M)

View File

@ -6,7 +6,7 @@
; CHECK-NO-ERASE: @foo(
; CHECK-NO-ERASE: @foo_bb9(
; CHECK-NO-ERASE: @foo_bb20(
; CHECK-ERASE-NOT: @foo(
; CHECK-ERASE: declare i32 @foo(
; CHECK-ERASE: @foo_bb9(
; CHECK-ERASE: @foo_bb20(
define i32 @foo(i32 %arg, i32 %arg1) {

View File

@ -1,6 +1,19 @@
; RUN: llvm-extract -S -bb foo:bb4 %s | FileCheck %s
; CHECK: declare void @bar()
define void @bar() {
bb:
ret void
}
; CHECK-NOT: @unused()
define void @unused() {
bb:
ret void
}
; CHECK: @foo_bb4
; CHECK: call void @bar()
; CHECK: %tmp5
define i32 @foo(i32 %arg) {
bb:
@ -12,6 +25,7 @@ bb:
br i1 %tmp3, label %bb4, label %bb7
bb4: ; preds = %bb
call void @bar()
%tmp5 = load i32, i32* %tmp1, align 4
%tmp6 = add nsw i32 %tmp5, 1
store i32 %tmp6, i32* %tmp1, align 4