|
36 | 36 | #include "llvm/BinaryFormat/COFF.h"
|
37 | 37 | #include "llvm/BinaryFormat/Dwarf.h"
|
38 | 38 | #include "llvm/BinaryFormat/ELF.h"
|
| 39 | +#include "llvm/Bitcode/BitcodeWriter.h" |
39 | 40 | #include "llvm/CodeGen/GCMetadata.h"
|
40 | 41 | #include "llvm/CodeGen/GCMetadataPrinter.h"
|
41 | 42 | #include "llvm/CodeGen/MachineBasicBlock.h"
|
@@ -141,6 +142,10 @@ static cl::opt<bool>
|
141 | 142 | DisableDebugInfoPrinting("disable-debug-info-print", cl::Hidden,
|
142 | 143 | cl::desc("Disable debug info printing"));
|
143 | 144 |
|
| 145 | +static cl::opt<bool> |
| 146 | + EmbedBitcodeFinal("embed-bitcode-final", cl::NotHidden, |
| 147 | + cl::desc("Embed final IR as bitcode after all optimisations and transformations have run.")); |
| 148 | + |
144 | 149 | const char DWARFGroupName[] = "dwarf";
|
145 | 150 | const char DWARFGroupDescription[] = "DWARF Emission";
|
146 | 151 | const char DbgTimerName[] = "emit";
|
@@ -1778,6 +1783,18 @@ void AsmPrinter::emitRemarksSection(remarks::RemarkStreamer &RS) {
|
1778 | 1783 | }
|
1779 | 1784 |
|
1780 | 1785 | bool AsmPrinter::doFinalization(Module &M) {
|
| 1786 | + // The `embed-bitcode` flag serialises the IR after only architecture |
| 1787 | + // agnostic optimisations have been run, but then proceeds to apply other |
| 1788 | + // optimisations and transformations afterwards. Sometimes this final version |
| 1789 | + // is precisely what we are interested in. The `embed-bitcode-final` flag |
| 1790 | + // waits until all optimisations/transformations have been run before |
| 1791 | + // embedding the IR. |
| 1792 | + if (EmbedBitcodeFinal) |
| 1793 | + llvm::EmbedBitcodeInModule(M, llvm::MemoryBufferRef(), |
| 1794 | + /*EmbedBitcode*/ true, |
| 1795 | + /*EmbedCmdline*/ false, |
| 1796 | + /*CmdArgs*/ std::vector<uint8_t>()); |
| 1797 | + |
1781 | 1798 | // Set the MachineFunction to nullptr so that we can catch attempted
|
1782 | 1799 | // accesses to MF specific features at the module level and so that
|
1783 | 1800 | // we can conditionalize accesses based on whether or not it is nullptr.
|
|
0 commit comments