[PATCH] D119431: [C API] Add LLVMWriteThinLTOBitcodeToMemoryBuffer to C API

Ayke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 10 05:24:55 PST 2022


aykevl updated this revision to Diff 407495.
aykevl added a comment.

- fix


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119431/new/

https://reviews.llvm.org/D119431

Files:
  llvm/bindings/go/llvm/bitwriter.go
  llvm/include/llvm-c/BitWriter.h
  llvm/lib/Bitcode/Writer/BitWriter.cpp


Index: llvm/lib/Bitcode/Writer/BitWriter.cpp
===================================================================
--- llvm/lib/Bitcode/Writer/BitWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitWriter.cpp
@@ -8,10 +8,12 @@
 
 #include "llvm-c/BitWriter.h"
 #include "llvm/Bitcode/BitcodeWriter.h"
+#include "llvm/IR/LegacyPassManager.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Transforms/IPO.h"
 using namespace llvm;
 
 
@@ -47,3 +49,12 @@
   WriteBitcodeToFile(*unwrap(M), OS);
   return wrap(MemoryBuffer::getMemBufferCopy(OS.str()).release());
 }
+
+LLVMMemoryBufferRef LLVMWriteThinLTOBitcodeToMemoryBuffer(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());
+}
Index: llvm/include/llvm-c/BitWriter.h
===================================================================
--- llvm/include/llvm-c/BitWriter.h
+++ llvm/include/llvm-c/BitWriter.h
@@ -47,6 +47,9 @@
 /** Writes a module to a new memory buffer and returns it. */
 LLVMMemoryBufferRef LLVMWriteBitcodeToMemoryBuffer(LLVMModuleRef M);
 
+/** Writes a module with ThinLTO summary to a new memory buffer and returns it. */
+LLVMMemoryBufferRef LLVMWriteThinLTOBitcodeToMemoryBuffer(LLVMModuleRef M);
+
 /**
  * @}
  */
Index: llvm/bindings/go/llvm/bitwriter.go
===================================================================
--- llvm/bindings/go/llvm/bitwriter.go
+++ llvm/bindings/go/llvm/bitwriter.go
@@ -35,4 +35,9 @@
 	return MemoryBuffer{mb}
 }
 
+func WriteThinLTOBitcodeToMemoryBuffer(m Module) MemoryBuffer {
+	mb := C.LLVMWriteThinLTOBitcodeToMemoryBuffer(m.C)
+	return MemoryBuffer{mb}
+}
+
 // TODO(nsf): Figure out way how to make it work with io.Writer


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119431.407495.patch
Type: text/x-patch
Size: 1958 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220210/0351f816/attachment.bin>


More information about the llvm-commits mailing list