diff options
| author | Adam Nemet <anemet@apple.com> | 2016-11-28 17:45:34 +0000 |
|---|---|---|
| committer | Adam Nemet <anemet@apple.com> | 2016-11-28 17:45:34 +0000 |
| commit | a415a9bde6569ef9bd7f5f1053c802124a2e8d5e (patch) | |
| tree | d87cf3b9b72bb6beaeb4be13b93356f696b48fd2 /llvm/lib | |
| parent | e5112b14b9657a28c82dba921a6f57fa18559772 (diff) | |
| download | bcm5719-llvm-a415a9bde6569ef9bd7f5f1053c802124a2e8d5e.tar.gz bcm5719-llvm-a415a9bde6569ef9bd7f5f1053c802124a2e8d5e.zip | |
[GVN, OptDiag] Include the value that is forwarded in load elimination
This requires some changes to the opt-diag API. Hal and I have
discussed this at the Dev Meeting and came up with a streaming delimiter
(setExtraArgs) to solve this.
Arguments after this delimiter are only included in the optimization
records and not in the remarks printed in the compiler output. (Note,
how in the test the content of the YAML file changes but the remarks on
the compiler output don't.)
This implements the green GVN message with a bug fix at line
http://lab.llvm.org:8080/artifacts/opt-view_test-suite/build/SingleSource/Benchmarks/Dhrystone/CMakeFiles/dry.dir/html/_org_test-suite_SingleSource_Benchmarks_Dhrystone_dry.c.html#L446
The fix is that now we properly include the constant value in the
message: "load of type i32 eliminated in favor of 7"
Differential Revision: https://reviews.llvm.org/D26489
llvm-svn: 288047
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/IR/DiagnosticInfo.cpp | 24 | ||||
| -rw-r--r-- | llvm/lib/Transforms/Scalar/GVN.cpp | 13 |
2 files changed, 30 insertions, 7 deletions
diff --git a/llvm/lib/IR/DiagnosticInfo.cpp b/llvm/lib/IR/DiagnosticInfo.cpp index 6a3fdcff233..ea71fde26e0 100644 --- a/llvm/lib/IR/DiagnosticInfo.cpp +++ b/llvm/lib/IR/DiagnosticInfo.cpp @@ -170,14 +170,25 @@ const std::string DiagnosticInfoWithDebugLocBase::getLocationStr() const { getLocation(&Filename, &Line, &Column); return (Filename + ":" + Twine(Line) + ":" + Twine(Column)).str(); } + DiagnosticInfoOptimizationBase::Argument::Argument(StringRef Key, Value *V) - : Key(Key), Val(GlobalValue::getRealLinkageName(V->getName())) { + : Key(Key) { if (auto *F = dyn_cast<Function>(V)) { if (DISubprogram *SP = F->getSubprogram()) DLoc = DebugLoc::get(SP->getScopeLine(), 0, SP); } else if (auto *I = dyn_cast<Instruction>(V)) DLoc = I->getDebugLoc(); + + // Only include names that correspond to user variables. FIXME: we should use + // debug info if available to get the name of the user variable. + if (isa<llvm::Argument>(V) || isa<GlobalValue>(V)) + Val = GlobalValue::getRealLinkageName(V->getName()); + else if (isa<Constant>(V)) { + raw_string_ostream OS(Val); + V->printAsOperand(OS, /*PrintType=*/false); + } else if (auto *I = dyn_cast<Instruction>(V)) + Val = I->getOpcodeName(); } DiagnosticInfoOptimizationBase::Argument::Argument(StringRef Key, Type *T) @@ -359,10 +370,19 @@ operator<<(setIsVerbose V) { return *this; } +DiagnosticInfoOptimizationBase &DiagnosticInfoOptimizationBase:: +operator<<(setExtraArgs EA) { + FirstExtraArgIndex = Args.size(); + return *this; +} + std::string DiagnosticInfoOptimizationBase::getMsg() const { std::string Str; raw_string_ostream OS(Str); - for (const DiagnosticInfoOptimizationBase::Argument &Arg : Args) + for (const DiagnosticInfoOptimizationBase::Argument &Arg : + make_range(Args.begin(), FirstExtraArgIndex == -1 + ? Args.end() + : Args.begin() + FirstExtraArgIndex)) OS << Arg.Val; return OS.str(); } diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp index 83a7efe14e9..4f66c5d1314 100644 --- a/llvm/lib/Transforms/Scalar/GVN.cpp +++ b/llvm/lib/Transforms/Scalar/GVN.cpp @@ -1590,10 +1590,13 @@ bool GVN::PerformLoadPRE(LoadInst *LI, AvailValInBlkVect &ValuesPerBlock, return true; } -static void reportLoadElim(LoadInst *LI, OptimizationRemarkEmitter *ORE) { +static void reportLoadElim(LoadInst *LI, Value *AvailableValue, + OptimizationRemarkEmitter *ORE) { + using namespace ore; ORE->emit(OptimizationRemark(DEBUG_TYPE, "LoadElim", LI) - << "load of type " << ore::NV("Type", LI->getType()) - << " eliminated"); + << "load of type " << NV("Type", LI->getType()) << " eliminated" + << setExtraArgs() << " in favor of " + << NV("InfavorOfValue", AvailableValue)); } /// Attempt to eliminate a load whose dependencies are @@ -1666,7 +1669,7 @@ bool GVN::processNonLocalLoad(LoadInst *LI) { MD->invalidateCachedPointerInfo(V); markInstructionForDeletion(LI); ++NumGVNLoad; - reportLoadElim(LI, ORE); + reportLoadElim(LI, V, ORE); return true; } @@ -1813,7 +1816,7 @@ bool GVN::processLoad(LoadInst *L) { patchAndReplaceAllUsesWith(L, AvailableValue); markInstructionForDeletion(L); ++NumGVNLoad; - reportLoadElim(L, ORE); + reportLoadElim(L, AvailableValue, ORE); // Tell MDA to rexamine the reused pointer since we might have more // information after forwarding it. if (MD && AvailableValue->getType()->getScalarType()->isPointerTy()) |

