[TailCallElim] Preserve DT and PDT
Summary:
Previously, in the NewPM pipeline, TailCallElim recalculates the DomTree when it modifies any instruction in the Function.
For example,
```
CallInst *CI = dyn_cast<CallInst>(&I);
...
CI->setTailCall();
Modified = true;
...
if (!Modified || ...)
return PreservedAnalyses::all();
```
After applying this patch, the DomTree only recalculates if needed (plus an extra insertEdge() + an extra deleteEdge() call).
When optimizing SQLite with `-passes="default<O3>"` pipeline of the newPM, the number of DomTree recalculation decreases by 6.2%, the number of nodes visited by DFS decreases by 2.9%. The time used by DomTree will decrease approximately 1%~2.5% after applying the patch.
Statistics:
```
Before the patch:
23010 dom-tree-stats - Number of DomTree recalculations
489264 dom-tree-stats - Number of nodes visited by DFS -- DomTree
After the patch:
21581 dom-tree-stats - Number of DomTree recalculations
475088 dom-tree-stats - Number of nodes visited by DFS -- DomTree
```
Reviewers: kuhar, dmgreen, brzycki, grosser, davide
Reviewed By: kuhar, brzycki
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D49982
llvm-svn: 338954
2018-08-04 16:13:47 +08:00
; RUN: opt %s -tailcallelim -verify-dom-info -pass-remarks=tailcallelim -o /dev/null 2>&1 | FileCheck %s
2017-07-20 05:39:51 +08:00
; RUN: opt %s -o /dev/null -passes='require<opt-remark-emit>,tailcallelim' -pass-remarks=tailcallelim 2>&1 | FileCheck %s
; CHECK: /home/davide/pat.c:2:20: transforming tail recursion into loop
define i32 @fib ( i32 %n ) nounwind ssp {
entry:
%cmp = icmp slt i32 %n , 2
br i1 %cmp , label %if.then , label %if.end
if.then: ; preds = %entry
br label %return
if.end: ; preds = %entry
%sub = add nsw i32 %n , -2
%call = call i32 @fib ( i32 %sub )
%sub3 = add nsw i32 %n , -1
%call4 = call i32 @fib ( i32 %sub3 ) , !dbg !8
%add = add nsw i32 %call , %call4
br label %return
return: ; preds = %if.end, %if.then
%retval.0 = phi i32 [ 1 , %if.then ] , [ %add , %if.end ]
ret i32 %retval.0
}
!llvm.dbg.cu = ! { !0 }
!llvm.module.flags = ! { !3 , !4 }
!llvm.ident = ! { !5 }
!0 = distinct !DICompileUnit ( language: D W _ L A N G _ C 99 , file: !1 , producer: "clang version 3.9.0 " , isOptimized: true , runtimeVersion: 0 , emissionKind: N o D e b u g , enums: !2 )
!1 = !DIFile ( filename: "/home/davide/pat.c" , directory: "/tmp" )
!2 = ! { }
!3 = ! { i32 2 , !"Debug Info Version" , i32 3 }
!4 = ! { i32 1 , !"PIC Level" , i32 2 }
!5 = ! { !"clang version 3.9.0 " }
[DebugInfo] Add DILabel metadata and intrinsic llvm.dbg.label.
In order to set breakpoints on labels and list source code around
labels, we need collect debug information for labels, i.e., label
name, the function label belong, line number in the file, and the
address label located. In order to keep these information in LLVM
IR and to allow backend to generate debug information correctly.
We create a new kind of metadata for labels, DILabel. The format
of DILabel is
!DILabel(scope: !1, name: "foo", file: !2, line: 3)
We hope to keep debug information as much as possible even the
code is optimized. So, we create a new kind of intrinsic for label
metadata to avoid the metadata is eliminated with basic block.
The intrinsic will keep existing if we keep it from optimized out.
The format of the intrinsic is
llvm.dbg.label(metadata !1)
It has only one argument, that is the DILabel metadata. The
intrinsic will follow the label immediately. Backend could get the
label metadata through the intrinsic's parameter.
We also create DIBuilder API for labels to be used by Frontend.
Frontend could use createLabel() to allocate DILabel objects, and use
insertLabel() to insert llvm.dbg.label intrinsic in LLVM IR.
Differential Revision: https://reviews.llvm.org/D45024
Patch by Hsiangkai Wang.
llvm-svn: 331841
2018-05-09 10:40:45 +08:00
!6 = distinct !DISubprogram ( name: "success" , scope: !1 , file: !1 , line: 1 , type: !7 , isLocal: false , isDefinition: true , scopeLine: 1 , flags: D I F l a g P r o t o t y p e d , isOptimized: true , unit: !0 , retainedNodes: !2 )
2017-07-20 05:39:51 +08:00
!7 = !DISubroutineType ( types: !2 )
!8 = !DILocation ( line: 2 , column: 20 , scope: !6 )