This is an archive of the discontinued LLVM Phabricator instance.

[Propeller] Use a bit-field struct for the metdata fields of BBEntry.
ClosedPublic

Authored by rahmanl on Apr 14 2023, 11:45 AM.

Details

Summary

This patch encapsulates the encoding and decoding logic of basic block metadata into the Metadata struct, and also reduces the decoded size of SHT_LLVM_BB_ADDR_MAP section.

The patch would've looked more readable if we could use designated initializer, but that is a c++20 feature.

Diff Detail

Event Timeline

rahmanl created this revision.Apr 14 2023, 11:45 AM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: hiraditya. · View Herald Transcript
rahmanl updated this revision to Diff 513696.Apr 14 2023, 11:46 AM

clang-format.

rahmanl updated this revision to Diff 514420.Apr 17 2023, 2:46 PM

Rebase and add comments.

rahmanl updated this revision to Diff 514422.Apr 17 2023, 2:47 PM

clang-format.

rahmanl updated this revision to Diff 514423.Apr 17 2023, 2:49 PM

clang-format.

rahmanl updated this revision to Diff 514668.Apr 18 2023, 9:43 AM

Remove old accessors.

rahmanl published this revision for review.Apr 18 2023, 9:49 AM
rahmanl edited the summary of this revision. (Show Details)
rahmanl added a reviewer: dhoekwater.
Herald added a project: Restricted Project. · View Herald TranscriptApr 18 2023, 9:50 AM
rahmanl updated this revision to Diff 514712.Apr 18 2023, 12:26 PM

Use a bitwise equality operator, since memcmp won't work when padding is involved.

rahmanl updated this revision to Diff 514713.Apr 18 2023, 12:26 PM

clang-format.

rahmanl updated this revision to Diff 514714.Apr 18 2023, 12:28 PM
  • cleanup.
jhenderson added inline comments.Apr 19 2023, 12:11 AM
llvm/include/llvm/Object/ELFTypes.h
853

Nit: use static_cast<unsigned>

855

Nit: blank line after method.

857

Could you add some simple unit tests for the encode/decode methods, please? They should be trivial to write, but I think would just help ensure there are no surprises. I think it would be sufficient to cover all 4 fields set individually, and also all fields set and no fields set.

863

FWIW, I'd find it more readable if you declared the struct, and then declared the member on a separate line i.e:

struct Metadata {
  ...
};

Metadata MD;
865–868

I'm not sure these should be moved. Typically, the constructor comes before other methods, from what I've seen, and it would reduce the size of the diff.

rahmanl updated this revision to Diff 516463.Apr 24 2023, 10:44 AM
rahmanl marked 5 inline comments as done.

Add unittest for encoding and decoding.

rahmanl updated this revision to Diff 516464.Apr 24 2023, 10:44 AM

clang-format.

rahmanl updated this revision to Diff 516467.Apr 24 2023, 10:46 AM
  • clang-format.
jhenderson added inline comments.Apr 25 2023, 12:24 AM
llvm/include/llvm/Object/ELFTypes.h
807–811

Nit: I'd add blank lines either side of this method.

813

Thinking about it, it's probably more appropriate for this to return a fixed width type (i.e. uint32_t) and similarly for the casts to cast to that.

Strictly speaking, I don't think there's any guarantee that unsigned is 4 bytes in size, plus it expresses the intent a little better in my opinion.

821

As above, uint32_t would be more appropriate here.

llvm/unittests/Object/ELFTypesTest.cpp
67

It might be interesting to show what happens when you provide decode with a value that includes bits that aren't related to any of the properties. For example, 0xffffffff.

74

What's the reason for these two being static? It's not modifiable, so I don't think it benefits anything, since it's already function-local.

75

These two loops should use size_t since that's what size returns.

rahmanl updated this revision to Diff 518011.Apr 28 2023, 12:01 PM
rahmanl marked 6 inline comments as done.
  • Add error handling for invalid encoding.
  • Add llvm-readobj test.
rahmanl added inline comments.Apr 28 2023, 12:02 PM
llvm/unittests/Object/ELFTypesTest.cpp
67

Good point. I added a check to enforce 1-to-1 encoding.

@jhenderson Thanks for reviewing. Please let me know if I have addressed your comments.

rahmanl updated this revision to Diff 520747.May 9 2023, 10:33 AM
  • clang-format.
rahmanl updated this revision to Diff 520754.May 9 2023, 10:40 AM
  • Add error handling for invalid encoding.
  • Add llvm-readobj test.

@jhenderson Another friendly ping.

jhenderson accepted this revision.May 10 2023, 12:18 AM

Apologies for the delay: high priority "regular" work, combined with time off of various descriptions means my reviewing has mostly taken a back seat. LGTM.

llvm/lib/Object/ELF.cpp
747–748

Comment needs updating.

This revision is now accepted and ready to land.May 10 2023, 12:18 AM
rahmanl updated this revision to Diff 521381.May 11 2023, 11:19 AM
rahmanl marked an inline comment as done.

Update the comment.

Thank you for the review.

This revision was landed with ongoing or failed builds.May 11 2023, 11:21 AM
This revision was automatically updated to reflect the committed changes.