This is an archive of the discontinued LLVM Phabricator instance.

[Remarks] Emit variable info in auto-init remarks
ClosedPublic

Authored by thegameg on Mar 1 2021, 2:01 PM.

Details

Summary

This enhances the auto-init remark with information about the variable
that is auto-initialized.

This is based of debug info if available, or alloca names (mostly for
development purposes).

auto-init.c:4:7: remark: Call to memset inserted by -ftrivial-auto-var-init. Memory operation size: 4096 bytes.Variables: var (4096 bytes). [-Rpass-missed=annotation-remarks]
  int var[1024];
      ^

This allows to see things like partial initialization of a variable that
the optimizer won't be able to completely remove.

Diff Detail

Event Timeline

thegameg created this revision.Mar 1 2021, 2:01 PM
thegameg requested review of this revision.Mar 1 2021, 2:01 PM
Herald added a project: Restricted Project. ยท View Herald TranscriptMar 1 2021, 2:01 PM
fhahn added inline comments.Mar 2 2021, 9:30 AM
llvm/include/llvm/Transforms/Utils/AutoInitRemark.h
66

This just stores references to existing strings, right? Could it just be a StringRef?

70

might be helpful to have a quick comment describing what those do?

llvm/lib/Transforms/Utils/AutoInitRemark.cpp
158

nit: most code in LLVM seems to use regular () for constructors.

llvm/test/Transforms/Util/trivial-auto-var-init-call.ll
293

Not sure I missed a test case, but is there one with multiple variables?

paquette added inline comments.Mar 2 2021, 9:39 AM
llvm/lib/Transforms/Utils/AutoInitRemark.cpp
42

Might as well merge the ifs to save a line.

164

Do we want to return if FoundDI == true, but Result is empty? Is it possible to get more information from the alloca case even if FoundDI == true?

199

Why uint32_t?

thegameg updated this revision to Diff 327530.Mar 2 2021, 11:24 AM
thegameg marked 4 inline comments as done.

Address comments + comments in header.

llvm/lib/Transforms/Utils/AutoInitRemark.cpp
158

I use it mostly so I don't have to add a constructor, but I can add one if needed.

199

๐Ÿคท๐Ÿปโ€โ™‚๏ธ

llvm/test/Transforms/Util/trivial-auto-var-init-call.ll
293

From known_call_with_size_alloca_phi to the end of the file they should all be with multiple variables.

fhahn accepted this revision.Mar 2 2021, 2:34 PM

LGTM, thanks! It might be good to wait a bit with committing, in case Jessica has additional comments.

This revision is now accepted and ready to land.Mar 2 2021, 2:34 PM
paquette accepted this revision.Mar 4 2021, 12:40 PM

LGTM!

This revision was landed with ongoing or failed builds.Mar 4 2021, 12:51 PM
This revision was automatically updated to reflect the committed changes.