This is an archive of the discontinued LLVM Phabricator instance.

[NFC][Bitstream] Improve the dumpability of bitstream/bitcode headers
ClosedPublic

Authored by woodruffw on Aug 19 2021, 7:20 PM.

Details

Summary

The LLVMBitCodes.h header contains various enums that are updated whenever LLVM's bitcode fundamentally changes. It would be nice to track these changes in a semi-automated way, so that external tools that attempt to parse LLVM's bitstream and bitcode can remain in sync.

Before this change, LLVMBitCodes.h had a single dependency -- it needed the FIRST_APPLICATION_BLOCKID enum value from BitCodes.h. BitCodes.h, in turn, had a whole tree of include dependencies that boiled down to llvm-config.h, meaning that it was impossible to dump the AST of either file without having a partial or full LLVM build tree already present.

To eliminate that requirement, this patch introduces a new leaf-only header, BitCodeEnums.h, which includes the "core" enums originally in BitCodes.h. LLVMBitCodes.h and BitCodes.h both include this new header in turn, preserving the current header relationships while allowing LLVMBitCodes.h to be dumped fully independently with a command like this (run from the repository root):

clang -fsyntax-only -x c++ -Illvm/include -Xclang -ast-dump=json -Xclang -ast-dump-filter -Xclang llvm::bitc::BlockIDs llvm/include/llvm/Bitcode/LLVMBitCodes.h

I recognize that this is a pretty unusual change and perhaps not a guarantee that the LLVM authors would like to make in the general case (i.e., that individual files within LLVM can have their AST dumped with minimal dependencies). However, I believe the criticality/limited scope of the file(s) in this patch warrants an exception. Please let me know if there's any other information I can provide, or anything else I can do to improve this patch!

Diff Detail

Event Timeline

woodruffw requested review of this revision.Aug 19 2021, 7:20 PM
woodruffw created this revision.
woodruffw retitled this revision from Improve the dumpability of bitstream/bitcode headers to [Bitstream] Improve the dumpability of bitstream/bitcode headers.Aug 19 2021, 7:21 PM
woodruffw updated this revision to Diff 367697.Aug 19 2021, 7:53 PM

Fixed namespaces.

woodruffw updated this revision to Diff 367934.Aug 20 2021, 6:19 PM

Fix the header guard style.

woodruffw retitled this revision from [Bitstream] Improve the dumpability of bitstream/bitcode headers to [Bitstream] Improve the dumpability of bitstream/bitcode headers [NFC].Aug 21 2021, 1:22 PM
woodruffw updated this revision to Diff 367970.Aug 21 2021, 1:30 PM

Fix the header guards, again.

Gentle ping for review on this.

Another gentle ping for review.

xgupta added a subscriber: xgupta.

I recognize that this is a pretty unusual change and perhaps not a guarantee that the LLVM authors would like to make in the general case (i.e., that individual files within LLVM can have their AST dumped with minimal dependencies). However, I believe the criticality/limited scope of the file(s) in this patch warrants an exception.

of course, these kinds of patches are very welcome and Definitely deserve a review.

I don't see any particular issue with refactoring this way, but I'm wondering why you need to be able to dump the AST in order to track changes to the file and values?

I don't see any particular issue with refactoring this way, but I'm wondering why you need to be able to dump the AST in order to track changes to the file and values?

I'll admit that it's a selfish use case :-) -- I've been reimplementing bits of LLVM's core (bitstream parsing, bitcode mapping, &c) in Rust as a learning exercise: https://github.com/woodruffw/mollusc

As part of that, I wanted to challenge myself to write a bit of CI harnessing to track key LLVM enums -- my thinking was that I could check for changes to LLVM's head, and then open an automated issue on my end whenever one of the enums changes upstream.

Gentle ping for review here.

Herald added a project: Restricted Project. · View Herald TranscriptMar 15 2022, 6:14 PM
woodruffw updated this revision to Diff 415656.Mar 15 2022, 6:22 PM
woodruffw retitled this revision from [Bitstream] Improve the dumpability of bitstream/bitcode headers [NFC] to [NFC][Bitstream] Improve the dumpability of bitstream/bitcode headers.

Rebased diff.

This revision is now accepted and ready to land.Mar 15 2022, 8:37 PM
woodruffw updated this revision to Diff 418737.Mar 28 2022, 5:11 PM

Gentle ping for re-app/merge.

Gentle ping for re-app/merge.

It is already approved, can you clarify?

Gentle ping for re-app/merge.

If you don't have commit access and you need someone to commit and push this for you, please ask it explicitly :)

If you don't have commit access and you need someone to commit and push this for you, please ask it explicitly :)

Sorry for the confusion! In that case, please commit and push once you feel this is ready!

This revision was landed with ongoing or failed builds.Apr 5 2022, 3:10 PM
This revision was automatically updated to reflect the committed changes.