Skip to content

Commit

Permalink
Add ThinLTO summary support
Browse files Browse the repository at this point in the history
  • Loading branch information
aykevl committed Feb 11, 2022
1 parent 4fa2ab2 commit ee4aad4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions backports.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@

#include "backports.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#include "llvm/Transforms/Coroutines.h"
#include "llvm-c/DebugInfo.h"
Expand Down Expand Up @@ -62,3 +66,13 @@ LLVMMetadataRef LLVMGoDIBuilderCreateCompileUnit(
SplitNameLen, Kind, DWOId, SplitDebugInlining, DebugInfoForProfiling);
#endif
}

// See https://reviews.llvm.org/D119431
LLVMMemoryBufferRef LLVMGoWriteThinLTOBitcodeToMemoryBuffer(LLVMModuleRef M) {
std::string Data;
llvm::raw_string_ostream OS(Data);
llvm::legacy::PassManager PM;
PM.add(createWriteThinLTOBitcodePass(OS));
PM.run(*llvm::unwrap(M));
return llvm::wrap(llvm::MemoryBuffer::getMemBufferCopy(OS.str()).release());
}
2 changes: 2 additions & 0 deletions backports.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ LLVMMetadataRef LLVMGoDIBuilderCreateCompileUnit(
LLVMBool DebugInfoForProfiling, const char *SysRoot, size_t SysRootLen,
const char *SDK, size_t SDKLen);

LLVMMemoryBufferRef LLVMGoWriteThinLTOBitcodeToMemoryBuffer(LLVMModuleRef M);

#ifdef __cplusplus
}
#endif /* defined(__cplusplus) */
6 changes: 6 additions & 0 deletions bitwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ package llvm

/*
#include "llvm-c/BitWriter.h"
#include "backports.h"
#include <stdlib.h>
*/
import "C"
Expand All @@ -35,4 +36,9 @@ func WriteBitcodeToMemoryBuffer(m Module) MemoryBuffer {
return MemoryBuffer{mb}
}

func WriteThinLTOBitcodeToMemoryBuffer(m Module) MemoryBuffer {
mb := C.LLVMGoWriteThinLTOBitcodeToMemoryBuffer(m.C)
return MemoryBuffer{mb}
}

// TODO(nsf): Figure out way how to make it work with io.Writer

0 comments on commit ee4aad4

Please sign in to comment.