Alien-LibJIT
view release on metacpan or search on metacpan
libjit/jit/jit-internal.h view on Meta::CPAN
{
unsigned int elem_size;
unsigned int elems_per_block;
unsigned int elems_in_last;
jit_pool_block_t blocks;
void *free_list;
} jit_memory_pool;
/*
* Initialize a memory pool.
*/
void _jit_memory_pool_init(jit_memory_pool *pool, unsigned int elem_size);
#define jit_memory_pool_init(pool,type) \
_jit_memory_pool_init((pool), sizeof(type))
/*
* Free the contents of a memory pool.
*/
void _jit_memory_pool_free(jit_memory_pool *pool, jit_meta_free_func func);
#define jit_memory_pool_free(pool,func) _jit_memory_pool_free((pool), (func))
/*
* Allocate an item from a memory pool.
*/
void *_jit_memory_pool_alloc(jit_memory_pool *pool);
#define jit_memory_pool_alloc(pool,type) \
((type *)_jit_memory_pool_alloc((pool)))
/*
* Deallocate an item back to a memory pool.
*/
void _jit_memory_pool_dealloc(jit_memory_pool *pool, void *item);
#define jit_memory_pool_dealloc(pool,item) \
(_jit_memory_pool_dealloc((pool), (item)))
/*
* Storage for metadata.
*/
struct _jit_meta
{
int type;
void *data;
jit_meta_free_func free_data;
jit_meta_t next;
jit_function_t pool_owner;
};
/*
* Control flow graph edge.
*/
typedef struct _jit_edge *_jit_edge_t;
struct _jit_edge
{
/* Source node of the edge */
jit_block_t src;
/* Destination node of the edge */
jit_block_t dst;
/* Edge flags */
int flags;
};
#define _JIT_EDGE_FALLTHRU 0
#define _JIT_EDGE_BRANCH 1
#define _JIT_EDGE_RETURN 2
#define _JIT_EDGE_EXCEPT 3
/*
* Internal structure of a basic block.
*/
struct _jit_block
{
jit_function_t func;
jit_label_t label;
/* List of all instructions in this block */
jit_insn_t insns;
int num_insns;
int max_insns;
/* Next and previous blocks in the function's linear block list */
jit_block_t next;
jit_block_t prev;
/* Edges to successor blocks in control flow graph */
_jit_edge_t *succs;
int num_succs;
/* Edges to predecessor blocks in control flow graph */
_jit_edge_t *preds;
int num_preds;
/* Control flow flags */
unsigned visited : 1;
unsigned ends_in_dead : 1;
unsigned address_of : 1;
/* Metadata */
jit_meta_t meta;
/* Code generation data */
void *address;
void *fixup_list;
void *fixup_absolute_list;
};
/*
* Internal structure of a value.
*/
struct _jit_value
{
jit_block_t block;
jit_type_t type;
unsigned is_temporary : 1;
unsigned is_local : 1;
unsigned is_volatile : 1;
unsigned is_addressable : 1;
unsigned is_constant : 1;
unsigned is_nint_constant : 1;
unsigned is_parameter : 1;
unsigned is_reg_parameter : 1;
unsigned has_address : 1;
unsigned free_address : 1;
unsigned in_register : 1;
unsigned in_frame : 1;
unsigned in_global_register : 1;
unsigned live : 1;
unsigned next_use : 1;
unsigned has_frame_offset : 1;
unsigned global_candidate : 1;
unsigned has_global_register : 1;
short reg;
short global_reg;
jit_nint address;
jit_nint frame_offset;
jit_nuint usage_count;
int index;
};
#define JIT_INVALID_FRAME_OFFSET ((jit_nint)0x7FFFFFFF)
/*
* Free the structures that are associated with a value.
*/
void _jit_value_free(void *value);
/*
* Add references to all of the parameter values in a function.
* This is used when the initialization block is split during a
* "jit_insn_move_blocks_to_start" instruction.
*/
void _jit_value_ref_params(jit_function_t func);
/*
* Internal structure of an instruction.
*/
struct _jit_insn
{
short opcode;
short flags;
jit_value_t dest;
jit_value_t value1;
jit_value_t value2;
};
/*
* Instruction flags.
*/
#define JIT_INSN_DEST_LIVE 0x0001
#define JIT_INSN_DEST_NEXT_USE 0x0002
#define JIT_INSN_VALUE1_LIVE 0x0004
#define JIT_INSN_VALUE1_NEXT_USE 0x0008
#define JIT_INSN_VALUE2_LIVE 0x0010
#define JIT_INSN_VALUE2_NEXT_USE 0x0020
#define JIT_INSN_LIVENESS_FLAGS 0x003F
#define JIT_INSN_DEST_IS_LABEL 0x0040
#define JIT_INSN_DEST_IS_FUNCTION 0x0080
#define JIT_INSN_DEST_IS_NATIVE 0x0100
#define JIT_INSN_DEST_OTHER_FLAGS 0x01C0
#define JIT_INSN_VALUE1_IS_NAME 0x0200
#define JIT_INSN_VALUE1_IS_LABEL 0x0400
#define JIT_INSN_VALUE1_OTHER_FLAGS 0x0600
#define JIT_INSN_VALUE2_IS_SIGNATURE 0x0800
#define JIT_INSN_VALUE2_OTHER_FLAGS 0x0800
#define JIT_INSN_DEST_IS_VALUE 0x1000
/*
* Information about each label associated with a function.
*
* Multiple labels may belong to the same basic block. Such labels are
* linked into list.
*/
typedef struct _jit_label_info _jit_label_info_t;
struct _jit_label_info
{
/* Block the label assigned to */
jit_block_t block;
/* Next label that might belong to the same block */
jit_label_t alias;
/* Label flags */
int flags;
};
#define JIT_LABEL_ADDRESS_OF 0x0001
/*
* Information that is associated with a function for building
* the instructions and values. This structure can be discarded
* once the function has been fully compiled.
*/
typedef struct _jit_builder *jit_builder_t;
struct _jit_builder
{
/* Entry point for the function (and the head of the block list) */
jit_block_t entry_block;
/* Exit point for the function (and the tail of the block list) */
jit_block_t exit_block;
/* The position to insert initialization blocks */
jit_block_t init_block;
/* The current block that is being constructed */
jit_block_t current_block;
/* The list of deleted blocks */
jit_block_t deleted_blocks;
/* Blocks sorted in order required by an optimization pass */
jit_block_t *block_order;
int num_block_order;
/* The next block label to be allocated */
jit_label_t next_label;
/* Mapping from label numbers to blocks */
_jit_label_info_t *label_info;
jit_label_t max_label_info;
/* Exception handling definitions for the function */
jit_value_t setjmp_value;
jit_value_t thrown_exception;
jit_value_t thrown_pc;
jit_label_t catcher_label;
jit_value_t eh_frame_info;
/* Flag that is set to indicate that this function is not a leaf */
unsigned non_leaf : 1;
/* Flag that indicates if we've seen code that may throw an exception */
unsigned may_throw : 1;
/* Flag that indicates if the function has an ordinary return */
unsigned ordinary_return : 1;
/* Flag that indicates that the current function contains a tail call */
unsigned has_tail_call : 1;
/* Generate position-independent code */
unsigned position_independent : 1;
libjit/jit/jit-internal.h view on Meta::CPAN
struct jit_jmp_buf *setjmp_head;
};
/*
* Initialize the block list for a function.
*/
int _jit_block_init(jit_function_t func);
/*
* Free all blocks that are associated with a function.
*/
void _jit_block_free(jit_function_t func);
/*
* Build control flow graph edges for all blocks associated with a
* function.
*/
void _jit_block_build_cfg(jit_function_t func);
/*
* Eliminate useless control flow between blocks in a function.
*/
void _jit_block_clean_cfg(jit_function_t func);
/*
* Compute block postorder for control flow graph depth first traversal.
*/
int _jit_block_compute_postorder(jit_function_t func);
/*
* Create a new block and associate it with a function.
*/
jit_block_t _jit_block_create(jit_function_t func);
/*
* Destroy a block.
*/
void _jit_block_destroy(jit_block_t block);
/*
* Detach blocks from their current position in a function.
*/
void _jit_block_detach(jit_block_t first, jit_block_t last);
/*
* Attach blocks to a function after a specific position.
*/
void _jit_block_attach_after(jit_block_t block, jit_block_t first, jit_block_t last);
/*
* Attach blocks to a function before a specific position.
*/
void _jit_block_attach_before(jit_block_t block, jit_block_t first, jit_block_t last);
/*
* Record the label mapping for a block.
*/
int _jit_block_record_label(jit_block_t block, jit_label_t label);
/*
* Record the label flags.
*/
int _jit_block_record_label_flags(jit_function_t func, jit_label_t label, int flags);
/*
* Add an instruction to a block.
*/
jit_insn_t _jit_block_add_insn(jit_block_t block);
/*
* Get the last instruction in a block. NULL if the block is empty.
*/
jit_insn_t _jit_block_get_last(jit_block_t block);
/*
* The block goes just before the function end possibly excluding
* some empty blocks.
*/
int _jit_block_is_final(jit_block_t block);
/*
* Free one element in a metadata list.
*/
void _jit_meta_free_one(void *meta);
/*
* Determine if a NULL pointer check is redundant. The specified
* iterator is assumed to be positioned one place beyond the
* "check_null" instruction that we are testing.
*/
int _jit_insn_check_is_redundant(const jit_insn_iter_t *iter);
/*
* Get the correct opcode to use for a "load" instruction,
* starting at a particular opcode base. We assume that the
* instructions are laid out as "sbyte", "ubyte", "short",
* "ushort", "int", "long", "float32", "float64", "nfloat",
* and "struct".
*/
int _jit_load_opcode(int base_opcode, jit_type_t type,
jit_value_t value, int no_temps);
/*
* Get the correct opcode to use for a "store" instruction.
* We assume that the instructions are laid out as "byte",
* "short", "int", "long", "float32", "float64", "nfloat",
* and "struct".
*/
int _jit_store_opcode(int base_opcode, int small_base, jit_type_t type);
/*
* Function that is called upon each breakpoint location.
*/
void _jit_debugger_hook(jit_function_t func, jit_nint data1, jit_nint data2);
/*
* Internal structure of a type descriptor.
*/
struct jit_component
{
jit_type_t type;
jit_nuint offset;
char *name;
};
struct _jit_type
{
unsigned int ref_count;
int kind : 19;
int abi : 8;
int is_fixed : 1;
int layout_flags : 4;
jit_nuint size;
jit_nuint alignment;
jit_type_t sub_type;
unsigned int num_components;
struct jit_component components[1];
};
struct jit_tagged_type
{
struct _jit_type type;
void *data;
jit_meta_free_func free_func;
};
/*
* Pre-defined type descriptors.
*/
extern struct _jit_type const _jit_type_void_def;
extern struct _jit_type const _jit_type_sbyte_def;
extern struct _jit_type const _jit_type_ubyte_def;
extern struct _jit_type const _jit_type_short_def;
extern struct _jit_type const _jit_type_ushort_def;
extern struct _jit_type const _jit_type_int_def;
extern struct _jit_type const _jit_type_uint_def;
extern struct _jit_type const _jit_type_nint_def;
extern struct _jit_type const _jit_type_nuint_def;
extern struct _jit_type const _jit_type_long_def;
extern struct _jit_type const _jit_type_ulong_def;
extern struct _jit_type const _jit_type_float32_def;
extern struct _jit_type const _jit_type_float64_def;
extern struct _jit_type const _jit_type_nfloat_def;
extern struct _jit_type const _jit_type_void_ptr_def;
/*
* Intrinsic signatures.
*
* Naming convention is return type folowed by an underscore and the
* argument types.
*
* jit_int -> i (lower case I)
* jit_uint -> I
* jit_long -> l (lower case L)
* jit_ulong -> L
* jit_float32 -> f
* jit_float64 -> d
* jit_nflloat -> D
*
* pointer -> p followed by the type
*
* Special signatures are conv and conv_ovf for type conversions without
* and with overflow checks.
*/
typedef enum
{
JIT_SIG_NONE = 0,
JIT_SIG_i_i = 1,
JIT_SIG_i_ii = 2,
JIT_SIG_i_piii = 3,
JIT_SIG_i_iI = 4,
JIT_SIG_i_II = 5,
JIT_SIG_I_I = 6,
JIT_SIG_I_II = 7,
JIT_SIG_i_pIII = 8,
JIT_SIG_l_l = 9,
JIT_SIG_l_ll = 10,
JIT_SIG_i_plll = 11,
JIT_SIG_i_l = 12,
JIT_SIG_i_ll = 13,
JIT_SIG_l_lI = 14,
JIT_SIG_L_L = 15,
JIT_SIG_L_LL = 16,
JIT_SIG_i_pLLL = 17,
JIT_SIG_i_LL = 18,
JIT_SIG_L_LI = 19,
JIT_SIG_f_f = 20,
JIT_SIG_f_ff = 21,
JIT_SIG_i_f = 22,
JIT_SIG_i_ff = 23,
JIT_SIG_d_d = 24,
JIT_SIG_d_dd = 25,
JIT_SIG_i_d = 26,
JIT_SIG_i_dd = 27,
JIT_SIG_D_D = 28,
JIT_SIG_D_DD = 29,
JIT_SIG_i_D = 30,
JIT_SIG_i_DD = 31,
JIT_SIG_conv = 32,
JIT_SIG_conv_ovf= 33
} _jit_intrinsic_signature;
/*
* Flags for the intrinsic info.
*/
#define _JIT_INTRINSIC_FLAG_NONE 0x0000
#define _JIT_INTRINSIC_FLAG_BRANCH 0x8000
#define _JIT_INTRINSIC_FLAG_BRANCH_UNARY 0xC000
#define _JIT_INTRINSIC_FLAG_NOT 0x4000
#define _JIT_INTRINSIC_FLAG_MASK 0xC000
/*
* Additional intrinsic flags for the unary branches.
*/
#define _JIT_INTRINSIC_FLAG_IFALSE 0x0000
#define _JIT_INTRINSIC_FLAG_ITRUE 0x0001
#define _JIT_INTRINSIC_FLAG_LFALSE 0x0002
#define _JIT_INTRINSIC_FLAG_LTRUE 0x0003
/*
* Description for the implementation of an opcode by an intrinsic.
*/
typedef struct _jit_intrinsic_info _jit_intrinsic_info_t;
struct _jit_intrinsic_info
{
jit_short flags;
jit_short signature;
void *intrinsic;
};
extern _jit_intrinsic_info_t const _jit_intrinsics[JIT_OP_NUM_OPCODES];
/*
* Apply an opcode to one or two constant values.
* Returns the constant result value on success and NULL otherwise.
* NOTE: dest_type MUST be either the correct destination type for the
* opcode or a tagged type of the correct destination type.
*/
jit_value_t
_jit_opcode_apply(jit_function_t func, jit_uint opcode, jit_type_t dest_type,
jit_value_t value1, jit_value_t value2);
/*
* Extra call flags for internal use.
*/
#define JIT_CALL_NATIVE (1 << 14)
#ifdef JIT_USE_SIGNALS
/*
* Initialize the signal handlers.
*/
void _jit_signal_init(void);
#endif
#ifdef __cplusplus
};
#endif
#endif /* _JIT_INTERNAL_H */
( run in 0.943 second using v1.01-cache-2.11-cpan-796a6f069b2 )