This is an archive of the discontinued LLVM Phabricator instance.

[OptDiag] Split code region out of DiagnosticInfoOptimizationBase
ClosedPublic

Authored by anemet on Jan 22 2017, 9:47 PM.

Details

Summary

Code region is the only part of this class that is IR-specific. Code
region is moved down in the inheritance tree to a new derived class,
called DiagnosticInfoIROptimization.

All the existing remarks are derived from this new class now.

This allows the new MIR pass-remark classes to be derived from
DiagnosticInfoOptimizationBase.

Also because we keep the name DiagnosticInfoOptimizationBase, the clang
parts don't need any adjustment.

Diff Detail

Repository
rL LLVM

Event Timeline

anemet created this revision.Jan 22 2017, 9:47 PM
MatzeB accepted this revision.Jan 23 2017, 9:44 AM

LGTM. Straightforward so not much to say except nitpicking about comments and names.

include/llvm/Analysis/OptimizationDiagnosticInfo.h
71–73 ↗(On Diff #85319)

Probably no need to justify the choice of class here.

Instead I wish the documentation comment would tell me what the function actually does instead of just telling me it is the new way to emit things.

include/llvm/IR/DiagnosticInfo.h
381 ↗(On Diff #85319)

Why not call this DiagnosticInfoOptimization to make it a bit shorter and call the new thing DiagnosticInfoIROptimization/DiagnosticInfoMIROptimization (the fact that it is a Base class or Common is not that important that it needs to go into the name IMO).

478 ↗(On Diff #85319)

... used by (or in) IR passes

lib/Analysis/OptimizationDiagnosticInfo.cpp
152 ↗(On Diff #85319)

Could use a reference instead of a pointer.

157 ↗(On Diff #85319)

dito.

This revision is now accepted and ready to land.Jan 23 2017, 9:44 AM
anemet marked 4 inline comments as done.Jan 23 2017, 10:33 AM

Thanks, Matthias!

include/llvm/IR/DiagnosticInfo.h
381 ↗(On Diff #85319)

Good suggestion. Let me rename DiagnosticInfoOptimizationBase to DiagnosticInfoIROptimization in a prequel to this and rebase.

anemet marked an inline comment as not done.Jan 24 2017, 4:52 PM
anemet added inline comments.
lib/Analysis/OptimizationDiagnosticInfo.cpp
157 ↗(On Diff #85319)

Actually, this one needs to be a pointer because << requires an lvalue so we can't pass a temporary (&P).

anemet updated this revision to Diff 85659.Jan 24 2017, 5:01 PM
anemet marked an inline comment as not done.

The main thing is the renaming here proposed by Matthias.

I've actually kept the original name DiagnosticInfoOptimizationBase for the
IR-agnostic class (i.e. no code-region). This is nice because 99% of the
clients work because they weren't using code region. This includes clang so
there is no cross-repo renaming.

The other names are as suggested by Matthias.

Will also update the title and description of the review because it's
confusing now.

anemet retitled this revision from [OptDiag] Move everything but code region into a new base class for DiagnosticInfoOptimizationBase to [OptDiag] Split code region out of DiagnosticInfoOptimizationBase.Jan 24 2017, 5:02 PM
anemet edited the summary of this revision. (Show Details)

Still good to go.

lib/Analysis/OptimizationDiagnosticInfo.cpp
157 ↗(On Diff #85319)

I am pretty sure this is equivalent and taking the address of a reference variable does produce a pointer that can still be used when the reference variable is out of scope (as long as the referenced object is still around which is the case here):

auto &P = const_cast<DiagnosticInfoOptimizationBase&>(OptDiagBase);
*out << &P;

Thanks.

lib/Analysis/OptimizationDiagnosticInfo.cpp
157 ↗(On Diff #85319)

I am pretty it's not ;) since that is what I tried. &P is an rvalue for a pointer type so we can't take a reference of it.

Here is the actual error message:

../lib/Analysis/OptimizationDiagnosticInfo.cpp:161:10: error: invalid operands to binary expression ('yaml::Output' and 'llvm::DiagnosticInfoOptimizationBase *')
    *Out << &P;
    ~~~~ ^  ~~
../include/llvm/Support/YAMLTraits.h:1473:1: note: candidate function [with T = llvm::DiagnosticInfoOptimizationBase *] not viable: no known conversion from 'llvm::DiagnosticInfoOptimizationBase *' to 'llvm::DiagnosticInfoOptimizationBase *&' for 2nd argument

Arguably, operator<< should take a reference not a pointer. I forgot why I used a pointer here.

MatzeB added inline comments.Jan 25 2017, 11:07 AM
lib/Analysis/OptimizationDiagnosticInfo.cpp
157 ↗(On Diff #85319)

operator<< needs an lvalue?!? Oh well, that is for another patch to clenaup/ complain about then.

This revision was automatically updated to reflect the committed changes.