llvm.org GIT mirror llvm / 04e94f7
[GVN, OptDiag] Include the value that is forwarded in load elimination [recommitting after the fix in r288307] 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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288380 91177308-0d34-0410-b5e6-96231b3b80d8 Adam Nemet 3 years ago
5 changed file(s) with 49 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
222222 namespace ore {
223223 using NV = DiagnosticInfoOptimizationBase::Argument;
224224 using setIsVerbose = DiagnosticInfoOptimizationBase::setIsVerbose;
225 using setExtraArgs = DiagnosticInfoOptimizationBase::setExtraArgs;
225226 }
226227
227228 /// OptimizationRemarkEmitter legacy analysis pass
381381 /// \brief Used to set IsVerbose via the stream interface.
382382 struct setIsVerbose {};
383383
384 /// \brief When an instance of this is inserted into the stream, the arguments
385 /// following will not appear in the remark printed in the compiler output
386 /// (-Rpass) but only in the optimization record file
387 /// (-fsave-optimization-record).
388 struct setExtraArgs {};
389
384390 /// \brief Used in the streaming interface as the general argument type. It
385391 /// internally converts everything into a key-value pair.
386392 struct Argument {
451457 DiagnosticInfoOptimizationBase &operator<<(StringRef S);
452458 DiagnosticInfoOptimizationBase &operator<<(Argument A);
453459 DiagnosticInfoOptimizationBase &operator<<(setIsVerbose V);
460 DiagnosticInfoOptimizationBase &operator<<(setExtraArgs EA);
454461
455462 /// \see DiagnosticInfo::print.
456463 void print(DiagnosticPrinter &DP) const override;
499506
500507 /// The remark is expected to be noisy.
501508 bool IsVerbose = false;
509
510 /// \brief If positive, the index of the first argument that only appear in
511 /// the optimization records and not in the remark printed in the compiler
512 /// output.
513 int FirstExtraArgIndex = -1;
502514
503515 friend struct yaml::MappingTraits;
504516 };
169169 getLocation(&Filename, &Line, &Column);
170170 return (Filename + ":" + Twine(Line) + ":" + Twine(Column)).str();
171171 }
172
172173 DiagnosticInfoOptimizationBase::Argument::Argument(StringRef Key, Value *V)
173 : Key(Key), Val(GlobalValue::getRealLinkageName(V->getName())) {
174 : Key(Key) {
174175 if (auto *F = dyn_cast(V)) {
175176 if (DISubprogram *SP = F->getSubprogram())
176177 DLoc = DebugLoc::get(SP->getScopeLine(), 0, SP);
177178 }
178179 else if (auto *I = dyn_cast(V))
179180 DLoc = I->getDebugLoc();
181
182 // Only include names that correspond to user variables. FIXME: we should use
183 // debug info if available to get the name of the user variable.
184 if (isa(V) || isa(V))
185 Val = GlobalValue::getRealLinkageName(V->getName());
186 else if (isa(V)) {
187 raw_string_ostream OS(Val);
188 V->printAsOperand(OS, /*PrintType=*/false);
189 } else if (auto *I = dyn_cast(V))
190 Val = I->getOpcodeName();
180191 }
181192
182193 DiagnosticInfoOptimizationBase::Argument::Argument(StringRef Key, Type *T)
358369 return *this;
359370 }
360371
372 DiagnosticInfoOptimizationBase &DiagnosticInfoOptimizationBase::
373 operator<<(setExtraArgs EA) {
374 FirstExtraArgIndex = Args.size();
375 return *this;
376 }
377
361378 std::string DiagnosticInfoOptimizationBase::getMsg() const {
362379 std::string Str;
363380 raw_string_ostream OS(Str);
364 for (const DiagnosticInfoOptimizationBase::Argument &Arg : Args)
381 for (const DiagnosticInfoOptimizationBase::Argument &Arg :
382 make_range(Args.begin(), FirstExtraArgIndex == -1
383 ? Args.end()
384 : Args.begin() + FirstExtraArgIndex))
365385 OS << Arg.Val;
366386 return OS.str();
367387 }
15901590 return true;
15911591 }
15921592
1593 static void reportLoadElim(LoadInst *LI, OptimizationRemarkEmitter *ORE) {
1593 static void reportLoadElim(LoadInst *LI, Value *AvailableValue,
1594 OptimizationRemarkEmitter *ORE) {
1595 using namespace ore;
15941596 ORE->emit(OptimizationRemark(DEBUG_TYPE, "LoadElim", LI)
1595 << "load of type " << ore::NV("Type", LI->getType())
1596 << " eliminated");
1597 << "load of type " << NV("Type", LI->getType()) << " eliminated"
1598 << setExtraArgs() << " in favor of "
1599 << NV("InfavorOfValue", AvailableValue));
15971600 }
15981601
15991602 /// Attempt to eliminate a load whose dependencies are
16661669 MD->invalidateCachedPointerInfo(V);
16671670 markInstructionForDeletion(LI);
16681671 ++NumGVNLoad;
1669 reportLoadElim(LI, ORE);
1672 reportLoadElim(LI, V, ORE);
16701673 return true;
16711674 }
16721675
18131816 patchAndReplaceAllUsesWith(L, AvailableValue);
18141817 markInstructionForDeletion(L);
18151818 ++NumGVNLoad;
1816 reportLoadElim(L, ORE);
1819 reportLoadElim(L, AvailableValue, ORE);
18171820 // Tell MDA to rexamine the reused pointer since we might have more
18181821 // information after forwarding it.
18191822 if (MD && AvailableValue->getType()->getScalarType()->isPointerTy())
1414 ; YAML-NEXT: - String: 'load of type '
1515 ; YAML-NEXT: - Type: i32
1616 ; YAML-NEXT: - String: ' eliminated'
17 ; YAML-NEXT: - String: ' in favor of '
18 ; YAML-NEXT: - InfavorOfValue: i
1719 ; YAML-NEXT: ...
1820 ; YAML-NEXT: --- !Passed
1921 ; YAML-NEXT: Pass: gvn
2325 ; YAML-NEXT: - String: 'load of type '
2426 ; YAML-NEXT: - Type: i32
2527 ; YAML-NEXT: - String: ' eliminated'
28 ; YAML-NEXT: - String: ' in favor of '
29 ; YAML-NEXT: - InfavorOfValue: '4'
2630 ; YAML-NEXT: ...
2731 ; YAML-NEXT: --- !Passed
2832 ; YAML-NEXT: Pass: gvn
3236 ; YAML-NEXT: - String: 'load of type '
3337 ; YAML-NEXT: - Type: i32
3438 ; YAML-NEXT: - String: ' eliminated'
39 ; YAML-NEXT: - String: ' in favor of '
40 ; YAML-NEXT: - InfavorOfValue: load
3541 ; YAML-NEXT: ...
3642
3743