[llvm] r308524 - [TRE] Move to the new OptRemark API.
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 19 14:13:22 PDT 2017
Author: davide
Date: Wed Jul 19 14:13:22 2017
New Revision: 308524
URL: http://llvm.org/viewvc/llvm-project?rev=308524&view=rev
Log:
[TRE] Move to the new OptRemark API.
Fixes PR33788.
Differential Revision: https://reviews.llvm.org/D35570
Added:
llvm/trunk/test/Transforms/TailCallElim/opt-remarks.ll
Modified:
llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp
llvm/trunk/test/Other/new-pm-defaults.ll
llvm/trunk/test/Other/new-pm-thinlto-defaults.ll
Modified: llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp?rev=308524&r1=308523&r2=308524&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp Wed Jul 19 14:13:22 2017
@@ -60,6 +60,7 @@
#include "llvm/Analysis/InlineCost.h"
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Analysis/Loads.h"
+#include "llvm/Analysis/OptimizationDiagnosticInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/CallSite.h"
@@ -177,7 +178,8 @@ struct AllocaDerivedValueTracker {
};
}
-static bool markTails(Function &F, bool &AllCallsAreTailCalls) {
+static bool markTails(Function &F, bool &AllCallsAreTailCalls,
+ OptimizationRemarkEmitter *ORE) {
if (F.callsFunctionThatReturnsTwice())
return false;
AllCallsAreTailCalls = true;
@@ -252,9 +254,9 @@ static bool markTails(Function &F, bool
break;
}
if (SafeToTail) {
- emitOptimizationRemark(
- F.getContext(), "tailcallelim", F, CI->getDebugLoc(),
- "marked this readnone call a tail call candidate");
+ using namespace ore;
+ ORE->emit(OptimizationRemark(DEBUG_TYPE, "tailcall-readnone", CI)
+ << "marked as tail call candidate (readnone)");
CI->setTailCall();
Modified = true;
continue;
@@ -299,9 +301,8 @@ static bool markTails(Function &F, bool
if (Visited[CI->getParent()] != ESCAPED) {
// If the escape point was part way through the block, calls after the
// escape point wouldn't have been put into DeferredTails.
- emitOptimizationRemark(F.getContext(), "tailcallelim", F,
- CI->getDebugLoc(),
- "marked this call a tail call candidate");
+ ORE->emit(OptimizationRemark(DEBUG_TYPE, "tailcall", CI)
+ << "marked as tail call candidate");
CI->setTailCall();
Modified = true;
} else {
@@ -491,7 +492,8 @@ static bool eliminateRecursiveTailCall(C
BasicBlock *&OldEntry,
bool &TailCallsAreMarkedTail,
SmallVectorImpl<PHINode *> &ArgumentPHIs,
- AliasAnalysis *AA) {
+ AliasAnalysis *AA,
+ OptimizationRemarkEmitter *ORE) {
// If we are introducing accumulator recursion to eliminate operations after
// the call instruction that are both associative and commutative, the initial
// value for the accumulator is placed in this variable. If this value is set
@@ -551,8 +553,9 @@ static bool eliminateRecursiveTailCall(C
BasicBlock *BB = Ret->getParent();
Function *F = BB->getParent();
- emitOptimizationRemark(F->getContext(), "tailcallelim", *F, CI->getDebugLoc(),
- "transforming tail recursion to loop");
+ using namespace ore;
+ ORE->emit(OptimizationRemark(DEBUG_TYPE, "tailcall-recursion", CI)
+ << "transforming tail recursion into loop");
// OK! We can transform this tail call. If this is the first one found,
// create the new entry block, allowing us to branch back to the old entry.
@@ -666,13 +669,11 @@ static bool eliminateRecursiveTailCall(C
return true;
}
-static bool foldReturnAndProcessPred(BasicBlock *BB, ReturnInst *Ret,
- BasicBlock *&OldEntry,
- bool &TailCallsAreMarkedTail,
- SmallVectorImpl<PHINode *> &ArgumentPHIs,
- bool CannotTailCallElimCallsMarkedTail,
- const TargetTransformInfo *TTI,
- AliasAnalysis *AA) {
+static bool foldReturnAndProcessPred(
+ BasicBlock *BB, ReturnInst *Ret, BasicBlock *&OldEntry,
+ bool &TailCallsAreMarkedTail, SmallVectorImpl<PHINode *> &ArgumentPHIs,
+ bool CannotTailCallElimCallsMarkedTail, const TargetTransformInfo *TTI,
+ AliasAnalysis *AA, OptimizationRemarkEmitter *ORE) {
bool Change = false;
// Make sure this block is a trivial return block.
@@ -708,7 +709,7 @@ static bool foldReturnAndProcessPred(Bas
BB->eraseFromParent();
eliminateRecursiveTailCall(CI, RI, OldEntry, TailCallsAreMarkedTail,
- ArgumentPHIs, AA);
+ ArgumentPHIs, AA, ORE);
++NumRetDuped;
Change = true;
}
@@ -722,23 +723,25 @@ static bool processReturningBlock(Return
SmallVectorImpl<PHINode *> &ArgumentPHIs,
bool CannotTailCallElimCallsMarkedTail,
const TargetTransformInfo *TTI,
- AliasAnalysis *AA) {
+ AliasAnalysis *AA,
+ OptimizationRemarkEmitter *ORE) {
CallInst *CI = findTRECandidate(Ret, CannotTailCallElimCallsMarkedTail, TTI);
if (!CI)
return false;
return eliminateRecursiveTailCall(CI, Ret, OldEntry, TailCallsAreMarkedTail,
- ArgumentPHIs, AA);
+ ArgumentPHIs, AA, ORE);
}
static bool eliminateTailRecursion(Function &F, const TargetTransformInfo *TTI,
- AliasAnalysis *AA) {
+ AliasAnalysis *AA,
+ OptimizationRemarkEmitter *ORE) {
if (F.getFnAttribute("disable-tail-calls").getValueAsString() == "true")
return false;
bool MadeChange = false;
bool AllCallsAreTailCalls = false;
- MadeChange |= markTails(F, AllCallsAreTailCalls);
+ MadeChange |= markTails(F, AllCallsAreTailCalls, ORE);
if (!AllCallsAreTailCalls)
return MadeChange;
@@ -765,13 +768,13 @@ static bool eliminateTailRecursion(Funct
for (Function::iterator BBI = F.begin(), E = F.end(); BBI != E; /*in loop*/) {
BasicBlock *BB = &*BBI++; // foldReturnAndProcessPred may delete BB.
if (ReturnInst *Ret = dyn_cast<ReturnInst>(BB->getTerminator())) {
- bool Change =
- processReturningBlock(Ret, OldEntry, TailCallsAreMarkedTail,
- ArgumentPHIs, !CanTRETailMarkedCall, TTI, AA);
+ bool Change = processReturningBlock(Ret, OldEntry, TailCallsAreMarkedTail,
+ ArgumentPHIs, !CanTRETailMarkedCall,
+ TTI, AA, ORE);
if (!Change && BB->getFirstNonPHIOrDbg() == Ret)
Change = foldReturnAndProcessPred(BB, Ret, OldEntry,
TailCallsAreMarkedTail, ArgumentPHIs,
- !CanTRETailMarkedCall, TTI, AA);
+ !CanTRETailMarkedCall, TTI, AA, ORE);
MadeChange |= Change;
}
}
@@ -802,6 +805,7 @@ struct TailCallElim : public FunctionPas
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequired<TargetTransformInfoWrapperPass>();
AU.addRequired<AAResultsWrapperPass>();
+ AU.addRequired<OptimizationRemarkEmitterWrapperPass>();
AU.addPreserved<GlobalsAAWrapperPass>();
}
@@ -811,7 +815,8 @@ struct TailCallElim : public FunctionPas
return eliminateTailRecursion(
F, &getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F),
- &getAnalysis<AAResultsWrapperPass>().getAAResults());
+ &getAnalysis<AAResultsWrapperPass>().getAAResults(),
+ &getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE());
}
};
}
@@ -820,6 +825,7 @@ char TailCallElim::ID = 0;
INITIALIZE_PASS_BEGIN(TailCallElim, "tailcallelim", "Tail Call Elimination",
false, false)
INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
+INITIALIZE_PASS_DEPENDENCY(OptimizationRemarkEmitterWrapperPass)
INITIALIZE_PASS_END(TailCallElim, "tailcallelim", "Tail Call Elimination",
false, false)
@@ -833,8 +839,9 @@ PreservedAnalyses TailCallElimPass::run(
TargetTransformInfo &TTI = AM.getResult<TargetIRAnalysis>(F);
AliasAnalysis &AA = AM.getResult<AAManager>(F);
+ auto &ORE = AM.getResult<OptimizationRemarkEmitterAnalysis>(F);
- bool Changed = eliminateTailRecursion(F, &TTI, &AA);
+ bool Changed = eliminateTailRecursion(F, &TTI, &AA, &ORE);
if (!Changed)
return PreservedAnalyses::all();
Modified: llvm/trunk/test/Other/new-pm-defaults.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/new-pm-defaults.ll?rev=308524&r1=308523&r2=308524&view=diff
==============================================================================
--- llvm/trunk/test/Other/new-pm-defaults.ll (original)
+++ llvm/trunk/test/Other/new-pm-defaults.ll Wed Jul 19 14:13:22 2017
@@ -118,10 +118,10 @@
; CHECK-O3-NEXT: Running pass: LibCallsShrinkWrapPass
; CHECK-EP-PEEPHOLE-NEXT: Running pass: NoOpFunctionPass
; CHECK-O-NEXT: Running pass: TailCallElimPass
+; CHECK-O-NEXT: Running analysis: OptimizationRemarkEmitterAnalysis
; CHECK-O-NEXT: Running pass: SimplifyCFGPass
; CHECK-O-NEXT: Running pass: ReassociatePass
; CHECK-O-NEXT: Running pass: RequireAnalysisPass<{{.*}}OptimizationRemarkEmitterAnalysis
-; CHECK-O-NEXT: Running analysis: OptimizationRemarkEmitterAnalysis
; CHECK-O-NEXT: Running pass: FunctionToLoopPassAdaptor<{{.*}}LoopStandardAnalysisResults{{.*}}>
; CHECK-O-NEXT: Running analysis: LoopAnalysis
; CHECK-O-NEXT: Running analysis: ScalarEvolutionAnalysis
Modified: llvm/trunk/test/Other/new-pm-thinlto-defaults.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/new-pm-thinlto-defaults.ll?rev=308524&r1=308523&r2=308524&view=diff
==============================================================================
--- llvm/trunk/test/Other/new-pm-thinlto-defaults.ll (original)
+++ llvm/trunk/test/Other/new-pm-thinlto-defaults.ll Wed Jul 19 14:13:22 2017
@@ -101,10 +101,10 @@
; CHECK-O2-NEXT: Running pass: LibCallsShrinkWrapPass
; CHECK-O3-NEXT: Running pass: LibCallsShrinkWrapPass
; CHECK-O-NEXT: Running pass: TailCallElimPass
+; CHECK-O-NEXT: Running analysis: OptimizationRemarkEmitterAnalysis
; CHECK-O-NEXT: Running pass: SimplifyCFGPass
; CHECK-O-NEXT: Running pass: ReassociatePass
; CHECK-O-NEXT: Running pass: RequireAnalysisPass<{{.*}}OptimizationRemarkEmitterAnalysis
-; CHECK-O-NEXT: Running analysis: OptimizationRemarkEmitterAnalysis
; CHECK-O-NEXT: Running pass: FunctionToLoopPassAdaptor<{{.*}}LoopStandardAnalysisResults{{.*}}>
; CHECK-O-NEXT: Running analysis: LoopAnalysis
; CHECK-O-NEXT: Running analysis: ScalarEvolutionAnalysis
Added: llvm/trunk/test/Transforms/TailCallElim/opt-remarks.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/TailCallElim/opt-remarks.ll?rev=308524&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/TailCallElim/opt-remarks.ll (added)
+++ llvm/trunk/test/Transforms/TailCallElim/opt-remarks.ll Wed Jul 19 14:13:22 2017
@@ -0,0 +1,25 @@
+; RUN: opt %s -tailcallelim -pass-remarks=tailcallelim -o /dev/null 2>&1 | FileCheck %s
+; 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: marked as tail call candidate
+define void @patatino() {
+ call void @tinky(), !dbg !8
+ ret void
+}
+
+declare void @tinky()
+
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4}
+!llvm.ident = !{!5}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: NoDebug, 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 "}
+!6 = distinct !DISubprogram(name: "success", scope: !1, file: !1, line: 1, type: !7, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !2)
+!7 = !DISubroutineType(types: !2)
+!8 = !DILocation(line: 2, column: 20, scope: !6)
More information about the llvm-commits
mailing list