This is my first patch for LLVM, so I selected reviewers based on the information of git blame as well as those on the CC list of the related bug. I am new to cmake so I will appreciate if experts review my changes in the cmake files carefully.
Motivation for this change
Intrinsics.h needs from the TableGen'erated file Intrinsics.gen only the list of Intrinsics ID enumerators, however it used to #include all of Intrinsics.gen. The latter by now is over 3MiB, while its fragment that is relevant to Intrinsics.h is less than 350KiB.
Solution:
Intrinsics.gen is post-processed into a new file Intrinsics.ids. Post-processing is performed by a new utility extract_ifdef_block. I explored the following alternative solutions before selecting this one as the most optimal one:
- Make TableGen produce Intrinsics.ids directly (e.g. through a new mode -gen-intrinsics-ids) Cons:
- As a continuation of the work on bug#11951 I will need to extract an extra couple of sections from Intrinsics.gen into files of their own. Adding more options to TableGen would unnecessarily pollute its API.
- Use the standard preprocessor. Cons:
- Issues in CMake with making it work on different platforms
- The standard preprocessor implicitly includes compiler support header files (e.g. /usr/include/stdc-predef.h for gcc) and pollutes the output with the following lines:
- 1 "include/llvm/IR/Intrinsics.gen"
- 1 "<command-line>"
- 1 "/usr/include/stdc-predef.h" 1 3 4
- 1 "<command-line>" 2
- 1 "include/llvm/IR/Intrinsics.gen"
- 19 "include/llvm/IR/Intrinsics.gen"
Moreover, if the preprocessor is instructed to preserve the comments (so that the intrinsics enum ids are accompanied by the intrinsics names) then the comments from the compiler support files show up too. All this garbage may be a little confusing if anyone needs to look into Intrinsics.ids.
extract_ifdef_block is a rudimentary pre-processor that filters from the input the mentioned #ifdef/#endif block. There are actually two implementations (if the LLVM build system allowed using python or perl during the build proper step, I would create just one version in one of those languages):
- utils/Misc/extract_ifdef_block.sh: bash version, serving the autoconf build
- utils/Misc/extract_ifdef_block.cpp: produces a binary executable target for the CMake build