Skip to content

Commit acda3af

Browse files
committed
Update IR
IR commit: 18a3192604d9475cee833c6f94079d31015a9754
1 parent 4c6e08d commit acda3af

File tree

14 files changed

+726
-89
lines changed

14 files changed

+726
-89
lines changed

ext/opcache/jit/ir/ir.c

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ void ir_print_const(const ir_ctx *ctx, const ir_insn *insn, FILE *f, bool quoted
201201
#define ir_op_flag_s3 (ir_op_flag_s | 3 | (3 << IR_OP_FLAG_OPERANDS_SHIFT))
202202
#define ir_op_flag_x1 (IR_OP_FLAG_CONTROL|IR_OP_FLAG_MEM|IR_OP_FLAG_MEM_CALL | 1 | (1 << IR_OP_FLAG_OPERANDS_SHIFT))
203203
#define ir_op_flag_x2 (IR_OP_FLAG_CONTROL|IR_OP_FLAG_MEM|IR_OP_FLAG_MEM_CALL | 2 | (2 << IR_OP_FLAG_OPERANDS_SHIFT))
204+
#define ir_op_flag_x3 (IR_OP_FLAG_CONTROL|IR_OP_FLAG_MEM|IR_OP_FLAG_MEM_CALL | 3 | (3 << IR_OP_FLAG_OPERANDS_SHIFT))
204205
#define ir_op_flag_xN (IR_OP_FLAG_CONTROL|IR_OP_FLAG_MEM|IR_OP_FLAG_MEM_CALL | IR_OP_FLAG_VAR_INPUTS)
205206
#define ir_op_flag_a2 (IR_OP_FLAG_CONTROL|IR_OP_FLAG_MEM|IR_OP_FLAG_MEM_ALLOC | 2 | (2 << IR_OP_FLAG_OPERANDS_SHIFT))
206207

@@ -433,8 +434,10 @@ static IR_NEVER_INLINE ir_ref ir_const_ex(ir_ctx *ctx, ir_val val, uint8_t type,
433434
while (ref) {
434435
insn = &ctx->ir_base[ref];
435436
if (UNEXPECTED(insn->val.u64 >= val.u64)) {
436-
if (insn->val.u64 == val.u64 && insn->optx == optx) {
437-
return ref;
437+
if (insn->val.u64 == val.u64) {
438+
if (insn->optx == optx) {
439+
return ref;
440+
}
438441
} else {
439442
break;
440443
}
@@ -779,7 +782,7 @@ ir_ref ir_folding(ir_ctx *ctx, uint32_t opt, ir_ref op1, ir_ref op2, ir_ref op3,
779782
} while (1);
780783

781784
ir_fold_restart:
782-
if (!(ctx->flags & IR_OPT_IN_SCCP)) {
785+
if (!(ctx->flags2 & IR_OPT_IN_SCCP)) {
783786
op1_insn = ctx->ir_base + op1;
784787
op2_insn = ctx->ir_base + op2;
785788
op3_insn = ctx->ir_base + op3;
@@ -792,7 +795,7 @@ ir_ref ir_folding(ir_ctx *ctx, uint32_t opt, ir_ref op1, ir_ref op2, ir_ref op3,
792795
return IR_FOLD_DO_RESTART;
793796
}
794797
ir_fold_cse:
795-
if (!(ctx->flags & IR_OPT_IN_SCCP)) {
798+
if (!(ctx->flags2 & IR_OPT_IN_SCCP)) {
796799
/* Local CSE */
797800
ref = _ir_fold_cse(ctx, opt, op1, op2, op3);
798801
if (ref) {
@@ -816,7 +819,7 @@ ir_ref ir_folding(ir_ctx *ctx, uint32_t opt, ir_ref op1, ir_ref op2, ir_ref op3,
816819
return ref;
817820
}
818821
ir_fold_emit:
819-
if (!(ctx->flags & IR_OPT_IN_SCCP)) {
822+
if (!(ctx->flags2 & IR_OPT_IN_SCCP)) {
820823
return ir_emit(ctx, opt, op1, op2, op3);
821824
} else {
822825
ctx->fold_insn.optx = opt;
@@ -826,14 +829,14 @@ ir_ref ir_folding(ir_ctx *ctx, uint32_t opt, ir_ref op1, ir_ref op2, ir_ref op3,
826829
return IR_FOLD_DO_EMIT;
827830
}
828831
ir_fold_copy:
829-
if (!(ctx->flags & IR_OPT_IN_SCCP)) {
832+
if (!(ctx->flags2 & IR_OPT_IN_SCCP)) {
830833
return ref;
831834
} else {
832835
ctx->fold_insn.op1 = ref;
833836
return IR_FOLD_DO_COPY;
834837
}
835838
ir_fold_const:
836-
if (!(ctx->flags & IR_OPT_IN_SCCP)) {
839+
if (!(ctx->flags2 & IR_OPT_IN_SCCP)) {
837840
return ir_const(ctx, val, IR_OPT_TYPE(opt));
838841
} else {
839842
ctx->fold_insn.type = IR_OPT_TYPE(opt);
@@ -2320,3 +2323,27 @@ void _ir_STORE(ir_ctx *ctx, ir_ref addr, ir_ref val)
23202323
}
23212324
ctx->control = ir_emit3(ctx, IR_STORE, ctx->control, addr, val);
23222325
}
2326+
2327+
void _ir_VA_START(ir_ctx *ctx, ir_ref list)
2328+
{
2329+
IR_ASSERT(ctx->control);
2330+
ctx->control = ir_emit2(ctx, IR_VA_START, ctx->control, list);
2331+
}
2332+
2333+
void _ir_VA_END(ir_ctx *ctx, ir_ref list)
2334+
{
2335+
IR_ASSERT(ctx->control);
2336+
ctx->control = ir_emit2(ctx, IR_VA_END, ctx->control, list);
2337+
}
2338+
2339+
void _ir_VA_COPY(ir_ctx *ctx, ir_ref dst, ir_ref src)
2340+
{
2341+
IR_ASSERT(ctx->control);
2342+
ctx->control = ir_emit3(ctx, IR_VA_COPY, ctx->control, dst, src);
2343+
}
2344+
2345+
ir_ref _ir_VA_ARG(ir_ctx *ctx, ir_type type, ir_ref list)
2346+
{
2347+
IR_ASSERT(ctx->control);
2348+
return ctx->control = ir_emit2(ctx, IR_OPT(IR_VA_ARG, type), ctx->control, list);
2349+
}

ext/opcache/jit/ir/ir.h

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,18 @@ typedef enum _ir_type {
136136
IR_LAST_TYPE
137137
} ir_type;
138138

139+
#ifdef IR_64
140+
# define IR_SIZE_T IR_U64
141+
# define IR_SSIZE_T IR_I64
142+
# define IR_UINTPTR_T IR_U64
143+
# define IR_INTPTR_T IR_I64
144+
#else
145+
# define IR_SIZE_T IR_U32
146+
# define IR_SSIZE_T IR_I32
147+
# define IR_UINTPTR_T IR_U32
148+
# define IR_INTPTR_T IR_I32
149+
#endif
150+
139151
/* List of IR opcodes
140152
* ==================
141153
*
@@ -252,6 +264,9 @@ typedef enum _ir_type {
252264
_(ROL, d2, def, def, ___) /* rotate left */ \
253265
_(ROR, d2, def, def, ___) /* rotate right */ \
254266
_(BSWAP, d1, def, ___, ___) /* byte swap */ \
267+
_(CTPOP, d1, def, ___, ___) /* count population */ \
268+
_(CTLZ, d1, def, ___, ___) /* count leading zeros */ \
269+
_(CTTZ, d1, def, ___, ___) /* count trailing zeros */ \
255270
\
256271
/* branch-less conditional ops */ \
257272
_(MIN, d2C, def, def, ___) /* min(op1, op2) */ \
@@ -262,6 +277,7 @@ typedef enum _ir_type {
262277
_(PHI, pN, reg, def, def) /* SSA Phi function */ \
263278
_(COPY, d1X1, def, opt, ___) /* COPY (last foldable op) */ \
264279
_(PI, p2, reg, def, ___) /* e-SSA Pi constraint ??? */ \
280+
_(FRAME_ADDR, d0, ___, ___, ___) /* function frame address */ \
265281
/* (USE, RENAME) */ \
266282
\
267283
/* data ops */ \
@@ -290,6 +306,12 @@ typedef enum _ir_type {
290306
_(TRAP, x1, src, ___, ___) /* DebugBreak */ \
291307
/* memory reference ops (A, H, U, S, TMP, STR, NEW, X, V) ??? */ \
292308
\
309+
/* va_args */ \
310+
_(VA_START, x2, src, def, ___) /* va_start(va_list) */ \
311+
_(VA_END, x2, src, def, ___) /* va_end(va_list) */ \
312+
_(VA_COPY, x3, src, def, def) /* va_copy(dst, stc) */ \
313+
_(VA_ARG, x2, src, def, ___) /* va_arg(va_list) */ \
314+
\
293315
/* guards */ \
294316
_(GUARD, c3, src, def, def) /* IF without second successor */ \
295317
_(GUARD_NOT , c3, src, def, def) /* IF without second successor */ \
@@ -399,6 +421,7 @@ typedef union _ir_val {
399421
#define IR_CONST_EMIT (1<<0)
400422
#define IR_CONST_FASTCALL_FUNC (1<<1)
401423
#define IR_CONST_VARARG_FUNC (1<<2)
424+
#define IR_CONST_BUILTIN_FUNC (1<<3)
402425

403426
/* IR Instruction */
404427
typedef struct _ir_insn {
@@ -473,38 +496,18 @@ void ir_strtab_free(ir_strtab *strtab);
473496
#define IR_SKIP_PROLOGUE (1<<6) /* Don't generate function prologue. */
474497
#define IR_USE_FRAME_POINTER (1<<7)
475498
#define IR_PREALLOCATED_STACK (1<<8)
476-
#define IR_HAS_ALLOCA (1<<9)
477-
#define IR_HAS_CALLS (1<<10)
478-
#define IR_NO_STACK_COMBINE (1<<11)
479-
#define IR_START_BR_TARGET (1<<12)
480-
#define IR_ENTRY_BR_TARGET (1<<13)
481-
#define IR_GEN_ENDBR (1<<14)
482-
#define IR_MERGE_EMPTY_ENTRIES (1<<15)
483-
484-
#define IR_CFG_HAS_LOOPS (1<<16)
485-
#define IR_IRREDUCIBLE_CFG (1<<17)
499+
#define IR_NO_STACK_COMBINE (1<<9)
500+
#define IR_START_BR_TARGET (1<<10)
501+
#define IR_ENTRY_BR_TARGET (1<<11)
502+
#define IR_GEN_ENDBR (1<<12)
503+
#define IR_MERGE_EMPTY_ENTRIES (1<<13)
486504

487505
#define IR_OPT_FOLDING (1<<18)
488506
#define IR_OPT_CFG (1<<19) /* merge BBs, by remove END->BEGIN nodes during CFG construction */
489507
#define IR_OPT_CODEGEN (1<<20)
490-
#define IR_OPT_IN_SCCP (1<<21)
491-
#define IR_LINEAR (1<<22)
492508
#define IR_GEN_NATIVE (1<<23)
493509
#define IR_GEN_CODE (1<<24) /* C or LLVM */
494510

495-
/* Temporary: SCCP -> CFG */
496-
#define IR_SCCP_DONE (1<<25)
497-
498-
/* Temporary: Dominators -> Loops */
499-
#define IR_NO_LOOPS (1<<25)
500-
501-
/* Temporary: Live Ranges */
502-
#define IR_LR_HAVE_DESSA_MOVES (1<<25)
503-
504-
/* Temporary: Register Allocator */
505-
#define IR_RA_HAVE_SPLITS (1<<25)
506-
#define IR_RA_HAVE_SPILLS (1<<26)
507-
508511
/* debug related */
509512
#ifdef IR_DEBUG
510513
# define IR_DEBUG_SCCP (1<<27)
@@ -537,6 +540,7 @@ struct _ir_ctx {
537540
ir_ref consts_count; /* number of constants stored in constants buffer */
538541
ir_ref consts_limit; /* size of allocated constants buffer (it's extended when overflow) */
539542
uint32_t flags; /* IR context flags (see IR_* defines above) */
543+
uint32_t flags2; /* IR context provate flags (see IR_* defines in ir_private.h) */
540544
ir_type ret_type; /* Function return type */
541545
uint32_t mflags; /* CPU specific flags (see IR_X86_... macros below) */
542546
int32_t status; /* non-zero error code (see IR_ERROR_... macros), app may use negative codes */
@@ -766,6 +770,7 @@ struct _ir_loader {
766770
uint32_t flags, ir_type ret_type, uint32_t params_count, ir_type *param_types);
767771
bool (*sym_dcl) (ir_loader *loader, const char *name, uint32_t flags, size_t size, bool has_data);
768772
bool (*sym_data) (ir_loader *loader, ir_type type, uint32_t count, const void *data);
773+
bool (*sym_data_ref) (ir_loader *loader, ir_op op, const char *ref);
769774
bool (*sym_data_end) (ir_loader *loader);
770775
bool (*func_init) (ir_loader *loader, ir_ctx *ctx, const char *name);
771776
bool (*func_process) (ir_loader *loader, ir_ctx *ctx, const char *name);
@@ -816,6 +821,7 @@ int ir_patch(const void *code, size_t size, uint32_t jmp_table_size, const void
816821
# define IR_X86_SSE42 (1<<4)
817822
# define IR_X86_AVX (1<<5)
818823
# define IR_X86_AVX2 (1<<6)
824+
# define IR_X86_BMI1 (1<<7)
819825
#endif
820826

821827
uint32_t ir_cpuinfo(void);

0 commit comments

Comments
 (0)