神奇的LLVM与llvmlite之JIT编译。

发布时间 2023-07-12 10:02:47作者: abaelhe

https://releases.llvm.org/11.0.0/docs/LangRef.html

llvmlite Documentation, Release 0.41.0dev0-64-gbbb88a7-dirty 3.2 User guide
3.2.1 IR layer—llvmlite.ir The llvmlite.ir module contains classes and utilities to build the LLVM IR(intermediate representation) of native functions.

The provided APIs may sometimes look like LLVM’s C++ APIs, but they never call into LLVM, unless otherwise noted. Instead, they construct a pure Python representation of the IR.
To use this module, you should be familiar with the concepts in the LLVM Language Reference.

Types
• Atomic types • Aggregate types • Other types

All values used in an LLVM module are explicitly typed. All types derive from a common base class Type. You can instantiate most of them directly. Once instantiated, a type should be considered immutable.
class llvmlite.ir.Type The base class for all types. Never instantiate it directly. Types have the following methods in common: • as_pointer(addrspace=0) Return a PointerType pointing to this type. The optional addrspace integer allows you to choose a non-default address space—the meaning is platform dependent.
• get_abi_size(target_data) Get the ABI size of this type, in bytes, according to the target_data—an llvmlite.binding. TargetData instance.
• get_abi_alignment(target_data) Get the ABI alignment of this type, in bytes, according to the target_data—an llvmlite.binding. TargetData instance. NOTE: get_abi_size() and get_abi_alignment() call into the LLVM C++ API to get the requested information.
call(value) A convenience method to create a Constant of this type with the given value:

int32 = ir.IntType(32) >>> c = int32(42) >>> c
<ir.Constant type='i32' value=42> >>> print(c) i32 42