[llvm] r346255 - [CodeExtractor] Erase use-without-def debug intrinsics in parent func
Vedant Kumar via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 6 11:05:53 PST 2018
Author: vedantk
Date: Tue Nov 6 11:05:53 2018
New Revision: 346255
URL: http://llvm.org/viewvc/llvm-project?rev=346255&view=rev
Log:
[CodeExtractor] Erase use-without-def debug intrinsics in parent func
When CodeExtractor moves instructions to a new function, debug
intrinsics referring to those instructions within the parent function
become invalid.
This results in the same verifier failure which motivated r344545, about
function-local metadata being used in the wrong function.
Added:
llvm/trunk/test/Transforms/HotColdSplit/delete-use-without-def-dbg-val.ll
Modified:
llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp
Modified: llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp?rev=346255&r1=346254&r2=346255&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp Tue Nov 6 11:05:53 2018
@@ -57,6 +57,7 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
+#include "llvm/Transforms/Utils/Local.h"
#include <cassert>
#include <cstdint>
#include <iterator>
@@ -1305,12 +1306,20 @@ Function *CodeExtractor::extractCodeRegi
// for the new function.
for (BasicBlock &BB : *newFunction) {
auto BlockIt = BB.begin();
+ // Remove debug info intrinsics from the new function.
while (BlockIt != BB.end()) {
Instruction *Inst = &*BlockIt;
++BlockIt;
if (isa<DbgInfoIntrinsic>(Inst))
Inst->eraseFromParent();
}
+ // Remove debug info intrinsics which refer to values in the new function
+ // from the old function.
+ SmallVector<DbgVariableIntrinsic *, 4> DbgUsers;
+ for (Instruction &I : BB)
+ findDbgUsers(DbgUsers, &I);
+ for (DbgVariableIntrinsic *DVI : DbgUsers)
+ DVI->eraseFromParent();
}
LLVM_DEBUG(if (verifyFunction(*newFunction))
Added: llvm/trunk/test/Transforms/HotColdSplit/delete-use-without-def-dbg-val.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/HotColdSplit/delete-use-without-def-dbg-val.ll?rev=346255&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/HotColdSplit/delete-use-without-def-dbg-val.ll (added)
+++ llvm/trunk/test/Transforms/HotColdSplit/delete-use-without-def-dbg-val.ll Tue Nov 6 11:05:53 2018
@@ -0,0 +1,53 @@
+; RUN: opt -hotcoldsplit -S < %s | FileCheck %s
+
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.14.0"
+
+; CHECK-LABEL: define {{.*}}@foo(
+; CHECK-NOT: call {{.*}}llvm.dbg.value
+
+; CHECK-LABEL: define {{.*}}@foo.cold
+; CHECK-NOT: call {{.*}}llvm.dbg.value
+
+define void @foo() !dbg !6 {
+entry:
+ br i1 undef, label %if.then, label %if.end
+
+if.then: ; preds = %entry
+ br label %cleanup
+
+if.end: ; preds = %entry
+ ; We expect this block to be outlined. That kills the definition of %var.
+ %var = add i32 0, 0, !dbg !11
+ call void @sink()
+ call void @sink()
+ call void @sink()
+ br label %cleanup
+
+cleanup:
+ ; This dbg.value should be deleted after outlining, otherwise the verifier
+ ; complains about function-local metadata being used outside of a function.
+ call void @llvm.dbg.value(metadata i32 %var, metadata !9, metadata !DIExpression()), !dbg !11
+ ret void
+}
+
+declare void @llvm.dbg.value(metadata, metadata, metadata)
+
+declare void @sink() cold
+
+!llvm.dbg.cu = !{!0}
+!llvm.debugify = !{!3, !4}
+!llvm.module.flags = !{!5}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
+!1 = !DIFile(filename: "<stdin>", directory: "/")
+!2 = !{}
+!3 = !{i32 7}
+!4 = !{i32 1}
+!5 = !{i32 2, !"Debug Info Version", i32 3}
+!6 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: null, file: !1, line: 1, type: !7, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: true, unit: !0, retainedNodes: !8)
+!7 = !DISubroutineType(types: !2)
+!8 = !{!9}
+!9 = !DILocalVariable(name: "1", scope: !6, file: !1, line: 1, type: !10)
+!10 = !DIBasicType(name: "ty32", size: 32, encoding: DW_ATE_unsigned)
+!11 = !DILocation(line: 1, column: 1, scope: !6)
More information about the llvm-commits
mailing list