mirror of
https://github.com/danog/ir.git
synced 2025-01-22 05:31:32 +01:00
Merge pull request #20 from weltling/fixups_00
fixups: Minor improvements to ir.h, ir_builder.h and ir_init
This commit is contained in:
commit
52ab3439d1
8
ir.c
8
ir.c
@ -282,19 +282,19 @@ void ir_truncate(ir_ctx *ctx)
|
||||
ctx->ir_base = buf + ctx->consts_limit;
|
||||
}
|
||||
|
||||
void ir_init(ir_ctx *ctx, ir_ref consts_limit, ir_ref insns_limit)
|
||||
void ir_init(ir_ctx *ctx, uint32_t flags, ir_ref consts_limit, ir_ref insns_limit)
|
||||
{
|
||||
ir_insn *buf;
|
||||
|
||||
IR_ASSERT(consts_limit >= -(IR_TRUE - 1));
|
||||
IR_ASSERT(insns_limit >= IR_UNUSED + 1);
|
||||
IR_ASSERT(consts_limit >= IR_CONSTS_LIMIT_MIN);
|
||||
IR_ASSERT(insns_limit >= IR_INSNS_LIMIT_MIN);
|
||||
|
||||
ctx->insns_count = IR_UNUSED + 1;
|
||||
ctx->insns_limit = insns_limit;
|
||||
ctx->consts_count = -(IR_TRUE - 1);
|
||||
ctx->consts_limit = consts_limit;
|
||||
ctx->fold_cse_limit = IR_UNUSED + 1;
|
||||
ctx->flags = 0;
|
||||
ctx->flags = flags;
|
||||
|
||||
ctx->binding = NULL;
|
||||
|
||||
|
25
ir.h
25
ir.h
@ -8,6 +8,10 @@
|
||||
#ifndef IR_H
|
||||
#define IR_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
@ -343,6 +347,9 @@ typedef int32_t ir_ref;
|
||||
#define IR_TRUE (-3)
|
||||
#define IR_LAST_FOLDABLE_OP IR_COPY
|
||||
|
||||
#define IR_CONSTS_LIMIT_MIN (-(IR_TRUE - 1))
|
||||
#define IR_INSNS_LIMIT_MIN (IR_UNUSED + 1)
|
||||
|
||||
/* IR Constant Value */
|
||||
#ifndef IR_64
|
||||
# define ADDR_MEMBER uintptr_t addr;
|
||||
@ -452,9 +459,9 @@ void ir_strtab_apply(ir_strtab *strtab, ir_strtab_apply_t func);
|
||||
void ir_strtab_free(ir_strtab *strtab);
|
||||
|
||||
/* IR Context Flags */
|
||||
#define IR_FUNCTION (1<<0)
|
||||
#define IR_FASTCALL_FUNC (1<<1)
|
||||
#define IR_SKIP_PROLOGUE (1<<2)
|
||||
#define IR_FUNCTION (1<<0) /* Generate a function. */
|
||||
#define IR_FASTCALL_FUNC (1<<1) /* Generate a function with fastcall calling convention, x86 32-bit only. */
|
||||
#define IR_SKIP_PROLOGUE (1<<2) /* Don't generate function prologue. */
|
||||
#define IR_USE_FRAME_POINTER (1<<3)
|
||||
#define IR_PREALLOCATED_STACK (1<<4)
|
||||
#define IR_HAS_ALLOCA (1<<5)
|
||||
@ -505,10 +512,10 @@ typedef void (*ir_snapshot_create_t)(ir_ctx *ctx, ir_ref addr);
|
||||
struct _ir_ctx {
|
||||
ir_insn *ir_base; /* two directional array - instructions grow down, constants grow up */
|
||||
ir_ref insns_count;
|
||||
ir_ref insns_limit;
|
||||
ir_ref insns_limit; /* initial instructions count */
|
||||
ir_ref consts_count;
|
||||
ir_ref consts_limit;
|
||||
uint32_t flags;
|
||||
ir_ref consts_limit; /* initial constants count */
|
||||
uint32_t flags; /* IR context flags */
|
||||
ir_ref fold_cse_limit;
|
||||
ir_insn fold_insn;
|
||||
ir_hashtab *binding;
|
||||
@ -550,7 +557,7 @@ struct _ir_ctx {
|
||||
};
|
||||
|
||||
/* Basic IR Construction API (implementation in ir.c) */
|
||||
void ir_init(ir_ctx *ctx, ir_ref consts_limit, ir_ref insns_limit);
|
||||
void ir_init(ir_ctx *ctx, uint32_t flags, ir_ref consts_limit, ir_ref insns_limit);
|
||||
void ir_free(ir_ctx *ctx);
|
||||
void ir_truncate(ir_ctx *ctx);
|
||||
|
||||
@ -756,4 +763,8 @@ int ir_mem_protect(void *ptr, size_t size);
|
||||
int ir_mem_unprotect(void *ptr, size_t size);
|
||||
int ir_mem_flush(void *ptr, size_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* IR_H */
|
||||
|
@ -8,6 +8,10 @@
|
||||
#ifndef IR_BUILDER_H
|
||||
#define IR_BUILDER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* _ir_CTX may be redefined by the user */
|
||||
#define _ir_CTX ctx
|
||||
|
||||
@ -589,4 +593,8 @@ ir_ref _ir_SNAPSHOT(ir_ctx *ctx, ir_ref n);
|
||||
void _ir_SNAPSHOT_SET_OP(ir_ctx *ctx, ir_ref snapshot, ir_ref pos, ir_ref val);
|
||||
ir_ref _ir_EXITCALL(ir_ctx *ctx, ir_ref func);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* IR_BUILDER_H */
|
||||
|
3
ir_gcm.c
3
ir_gcm.c
@ -658,9 +658,8 @@ restart:
|
||||
|
||||
ir_mem_free(_prev);
|
||||
|
||||
ir_init(&new_ctx, consts_count, insns_count);
|
||||
ir_init(&new_ctx, ctx->flags, consts_count, insns_count);
|
||||
new_ctx.insns_count = insns_count;
|
||||
new_ctx.flags = ctx->flags;
|
||||
new_ctx.spill_base = ctx->spill_base;
|
||||
new_ctx.fixed_stack_red_zone = ctx->fixed_stack_red_zone;
|
||||
new_ctx.fixed_stack_frame_size = ctx->fixed_stack_frame_size;
|
||||
|
11
ir_main.c
11
ir_main.c
@ -381,19 +381,18 @@ int main(int argc, char **argv)
|
||||
|
||||
ir_loader_init();
|
||||
|
||||
ir_init(&ctx, 256, 1024);
|
||||
ctx.flags |= IR_FUNCTION;
|
||||
ctx.flags |= mflags;
|
||||
uint32_t flags = IR_FUNCTION | mflags;
|
||||
|
||||
if (opt_level > 0) {
|
||||
ctx.flags |= IR_OPT_FOLDING | IR_OPT_CFG | IR_OPT_CODEGEN;
|
||||
flags |= IR_OPT_FOLDING | IR_OPT_CFG | IR_OPT_CODEGEN;
|
||||
}
|
||||
if (emit_c) {
|
||||
ctx.flags |= IR_GEN_C;
|
||||
flags |= IR_GEN_C;
|
||||
}
|
||||
if (dump_asm || run) {
|
||||
ctx.flags |= IR_GEN_NATIVE;
|
||||
flags |= IR_GEN_NATIVE;
|
||||
}
|
||||
ir_init(&ctx, flags, 256, 1024);
|
||||
ctx.fixed_regset = ~debug_regset;
|
||||
|
||||
if (!ir_load(&ctx, f)) {
|
||||
|
@ -134,12 +134,11 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
ir_init(&ctx, 256, 1024);
|
||||
ctx.flags |= IR_FUNCTION;
|
||||
ctx.flags |= mflags;
|
||||
uint32_t flags = IR_FUNCTION | mflags;
|
||||
if (opt_level > 0) {
|
||||
ctx.flags |= IR_OPT_FOLDING | IR_OPT_CFG | IR_OPT_CODEGEN;
|
||||
flags |= IR_OPT_FOLDING | IR_OPT_CFG | IR_OPT_CODEGEN;
|
||||
}
|
||||
ir_init(&ctx, flags, 256, 1024);
|
||||
ctx.fixed_regset = ~debug_regset;
|
||||
gen_mandelbrot(&ctx);
|
||||
// ir_save(&ctx, stderr);
|
||||
|
Loading…
x
Reference in New Issue
Block a user