@@ -258,6 +258,94 @@ LLVM 22 introduces a source-language naming API change in debug info and bumps t
258258- ` DIBuilder.cpp ` : removed the ` #if LLVM_VERSION_MAJOR >= 22 ` conditional; the LLVM 22+ API is now the only code path.
259259- ` cmake/LLVM.cmake ` : the version discovery loop and the minimum-version guard now enforce LLVM >= 22.
260260
261+ ## v9.1.0 — Basic code generation
262+
263+ v9.1.0 adds a substantial set of new APIs for compiling LLVM IR to native code.
264+
265+ ** At a glance**
266+
267+ - Adds basic code generation: compile a module to an object file or an in-memory buffer.
268+ - Adds ` ModulePassManager ` and ` FunctionPassManager ` wrappers over LLVM's new PassBuilder infrastructure.
269+ - Adds ` CallingConv ` namespace with all calling convention IDs.
270+ - Adds ` Reloc ` , ` CodeModel ` , ` CodeGenOpt ` , and ` CodeGenFileType ` enum namespaces.
271+ - Adds ` OptimizationLevel ` and ` ThinOrFullLTOPhase ` enum namespaces.
272+ - Extends ` Function ` with ` getCallingConv() ` and ` setCallingConv(cc) ` .
273+ - Extends ` StructType.create ` with an optional ` isPacked ` boolean parameter.
274+ - Extends ` APInt ` constructor to accept a ` bigint ` value in addition to ` number ` .
275+ - Extends ` Target.createTargetMachine ` with optional ` reloc ` , ` codeModel ` , ` optLevel ` , and ` jit ` parameters.
276+
277+ ** Code generation**
278+
279+ Initialize target backends first, then use ` TargetMachine.emitToFile ` or ` TargetMachine.emitToBuffer ` :
280+
281+ ``` typescript
282+ import llvm from ' llvm-bindings' ;
283+
284+ llvm .InitializeAllTargetInfos ();
285+ llvm .InitializeAllTargets ();
286+ llvm .InitializeAllTargetMCs ();
287+ llvm .InitializeAllAsmPrinters ();
288+
289+ const target = llvm .TargetRegistry .lookupTarget (' x86_64' )! ;
290+ const machine = target .createTargetMachine (
291+ ' x86_64-unknown-unknown' ,
292+ ' generic' ,
293+ ' ' ,
294+ llvm .Reloc .PIC_ ,
295+ llvm .CodeModel .Small ,
296+ llvm .CodeGenOpt .Default ,
297+ );
298+
299+ // ... build your module ...
300+ const myModule: llvm .Module = /* ... */ ;
301+ myModule .setDataLayout (machine .createDataLayout ());
302+
303+ // Emit to an object file on disk
304+ machine .emitToFile (myModule , ' /tmp/out.o' , llvm .CodeGenFileType .Object );
305+
306+ // Or emit to an in-memory Buffer
307+ const buf: Buffer = machine .emitToBuffer (myModule , llvm .CodeGenFileType .Object );
308+ ```
309+
310+ ** Pass manager**
311+
312+ ` ModulePassManager ` wraps LLVM's new PassBuilder pipeline. Pass the desired ` OptimizationLevel ` to its constructor:
313+
314+ ``` typescript
315+ const mpm = new llvm .ModulePassManager (llvm .OptimizationLevel .O2 );
316+ mpm .run (myModule );
317+ ```
318+
319+ ` FunctionPassManager ` is obtained via ` ModulePassManager.createFunctionPassManager ` and can be composed back into the module pipeline:
320+
321+ ``` typescript
322+ const fpm = mpm .createFunctionPassManager (llvm .ThinOrFullLTOPhase .None );
323+ // fpm.addSROAPass();
324+ // fpm.addEarlyCSEPass();
325+ // fpm.addInstCombinePass();
326+ mpm .addFunctionPasses (fpm );
327+ ```
328+
329+ ** Calling conventions**
330+
331+ ``` typescript
332+ func .setCallingConv (llvm .CallingConv .Fast );
333+ console .log (func .getCallingConv ()); // 8
334+ ```
335+
336+ ** Packed structs**
337+
338+ ``` typescript
339+ const packed = llvm .StructType .create (context , [i8 , i32 ], ' PackedPoint' , true );
340+ console .log (packed .isPacked ()); // true
341+ ```
342+
343+ ** BigInt support for APInt**
344+
345+ ``` typescript
346+ const big = new llvm .APInt (64 , 9007199254740993n ); // value > Number.MAX_SAFE_INTEGER
347+ ```
348+
261349## Compatibility
262350
263351| llvm-bindings versions | compatible LLVM versions |
@@ -275,6 +363,7 @@ LLVM 22 introduces a source-language naming API change in debug info and bumps t
275363| (@designliquido/llvm-bindings ) 7.0.x | 20.1.x |
276364| (@designliquido/llvm-bindings ) 8.0.x | 21.1.x |
277365| (@designliquido/llvm-bindings ) 9.0.x | 22.1.x |
366+ | (@designliquido/llvm-bindings ) 9.1.x | 22.1.x |
278367
279368## Acknowledgments
280369
0 commit comments