Skip to content

Commit ee4aad4

Browse files
committed
Add ThinLTO summary support
1 parent 4fa2ab2 commit ee4aad4

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

backports.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11

22
#include "backports.h"
33
#include "llvm/IR/Instructions.h"
4+
#include "llvm/IR/LegacyPassManager.h"
5+
#include "llvm/IR/Module.h"
6+
#include "llvm/Support/MemoryBuffer.h"
7+
#include "llvm/Transforms/IPO.h"
48
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
59
#include "llvm/Transforms/Coroutines.h"
610
#include "llvm-c/DebugInfo.h"
@@ -62,3 +66,13 @@ LLVMMetadataRef LLVMGoDIBuilderCreateCompileUnit(
6266
SplitNameLen, Kind, DWOId, SplitDebugInlining, DebugInfoForProfiling);
6367
#endif
6468
}
69+
70+
// See https://reviews.llvm.org/D119431
71+
LLVMMemoryBufferRef LLVMGoWriteThinLTOBitcodeToMemoryBuffer(LLVMModuleRef M) {
72+
std::string Data;
73+
llvm::raw_string_ostream OS(Data);
74+
llvm::legacy::PassManager PM;
75+
PM.add(createWriteThinLTOBitcodePass(OS));
76+
PM.run(*llvm::unwrap(M));
77+
return llvm::wrap(llvm::MemoryBuffer::getMemBufferCopy(OS.str()).release());
78+
}

backports.h

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ LLVMMetadataRef LLVMGoDIBuilderCreateCompileUnit(
2626
LLVMBool DebugInfoForProfiling, const char *SysRoot, size_t SysRootLen,
2727
const char *SDK, size_t SDKLen);
2828

29+
LLVMMemoryBufferRef LLVMGoWriteThinLTOBitcodeToMemoryBuffer(LLVMModuleRef M);
30+
2931
#ifdef __cplusplus
3032
}
3133
#endif /* defined(__cplusplus) */

bitwriter.go

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ package llvm
1414

1515
/*
1616
#include "llvm-c/BitWriter.h"
17+
#include "backports.h"
1718
#include <stdlib.h>
1819
*/
1920
import "C"
@@ -35,4 +36,9 @@ func WriteBitcodeToMemoryBuffer(m Module) MemoryBuffer {
3536
return MemoryBuffer{mb}
3637
}
3738

39+
func WriteThinLTOBitcodeToMemoryBuffer(m Module) MemoryBuffer {
40+
mb := C.LLVMGoWriteThinLTOBitcodeToMemoryBuffer(m.C)
41+
return MemoryBuffer{mb}
42+
}
43+
3844
// TODO(nsf): Figure out way how to make it work with io.Writer

0 commit comments

Comments
 (0)