From cc56f12f132e898856aa5e42a4b99a2778d1baf8 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 8 Nov 2022 11:32:46 +0300 Subject: [PATCH] Add LICENSE and copyright notices --- LICENSE | 21 +++++++++++++++++++++ gen_ir_fold_hash.c | 9 +++++++++ ir-test.php | 6 ++++++ ir.c | 16 ++++++++++++++++ ir.g | 23 +++++++++++++++++++---- ir.h | 7 +++++++ ir_aarch64.dasc | 7 +++++++ ir_aarch64.h | 7 +++++++ ir_cfg.c | 7 +++++++ ir_check.c | 8 +++++++- ir_disasm.c | 7 +++++++ ir_dump.c | 7 +++++++ ir_elf.h | 7 +++++++ ir_emit.c | 7 +++++++ ir_emit_c.c | 7 +++++++ ir_fold.h | 9 +++++++++ ir_gcm.c | 14 ++++++++++---- ir_gdb.c | 8 ++++++-- ir_load.c | 12 +++++++++++- ir_main.c | 7 +++++++ ir_patch.c | 10 +++++++++- ir_perf.c | 30 ++++++++++++++++-------------- ir_php.h | 7 +++++++ ir_private.h | 7 +++++++ ir_ra.c | 28 ++++++++++++++++------------ ir_save.c | 7 +++++++ ir_sccp.c | 17 +++++++++++------ ir_strtab.c | 7 +++++++ ir_test.c | 7 +++++++ ir_x86.dasc | 7 +++++++ ir_x86.h | 7 +++++++ 31 files changed, 285 insertions(+), 45 deletions(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c43a12a --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zend by Perforce + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/gen_ir_fold_hash.c b/gen_ir_fold_hash.c index d9b0697..f85b8d9 100644 --- a/gen_ir_fold_hash.c +++ b/gen_ir_fold_hash.c @@ -1,3 +1,12 @@ +/* + * IR - Lightweight JIT Compilation Framework + * (Folding engine generator) + * Copyright (C) 2022 Zend by Perforce. + * Authors: Dmitry Stogov + * + * Based on Mike Pall's implementation for LuaJIT. + */ + #include "ir.h" #include diff --git a/ir-test.php b/ir-test.php index 6569215..8fece6a 100644 --- a/ir-test.php +++ b/ir-test.php @@ -1,4 +1,10 @@ + */ function parse_test($test, &$name, &$code, &$expect, &$args, &$target) { $text = @file_get_contents($test); diff --git a/ir.c b/ir.c index cee1482..1836b06 100644 --- a/ir.c +++ b/ir.c @@ -1,3 +1,19 @@ +/* + * IR - Lightweight JIT Compilation Framework + * (IR construction, folding, utilities) + * Copyright (C) 2022 Zend by Perforce. + * Authors: Dmitry Stogov + * + * The logical IR representation is based on Cliff Click's Sea of Nodes. + * See: C. Click, M. Paleczny. “A Simple Graph-Based Intermediate + * Representation” In ACM SIGPLAN Workshop on Intermediate Representations + * (IR '95), pages 35-49, Jan. 1995. + * + * The phisical IR representation is based on Mike Pall's LuaJIT IR. + * See: M. Pall. “LuaJIT 2.0 intellectual property disclosure and research + * opportunities” November 2009 http://lua-users.org/lists/lua-l/2009-11/msg00089.html + */ + #ifndef _GNU_SOURCE # define _GNU_SOURCE #endif diff --git a/ir.g b/ir.g index a8e5754..3a9c583 100644 --- a/ir.g +++ b/ir.g @@ -1,7 +1,12 @@ /* -To generate ir_load.c use llk : -php llk.php ir.g -*/ + * IR - Lightweight JIT Compilation Framework + * (IR loader) + * Copyright (C) 2022 Zend by Perforce. + * Authors: Dmitry Stogov + * + * To generate ir_load.c use llk : + * php llk.php ir.g + */ %start ir %case-sensetive true @@ -11,7 +16,17 @@ php llk.php ir.g %indent "\t" %{ -/* This file is generated from "ir.g". Do not edit! */ +/* + * IR - Lightweight JIT Compilation Framework + * (IR loader) + * Copyright (C) 2005-2022 Zend by Perforce. + * Authors: Dmitry Stogov + * + * This file is generated from "ir.g". Do not edit! + * + * To generate ir_load.c use llk : + * php llk.php ir.g + */ #include "ir.h" #include "ir_private.h" diff --git a/ir.h b/ir.h index 2477d78..e2cae64 100644 --- a/ir.h +++ b/ir.h @@ -1,3 +1,10 @@ +/* + * IR - Lightweight JIT Compilation Framework + * (Public API) + * Copyright (C) 2022 Zend by Perforce. + * Authors: Dmitry Stogov + */ + #ifndef IR_H #define IR_H diff --git a/ir_aarch64.dasc b/ir_aarch64.dasc index d3e8bae..d78f18a 100644 --- a/ir_aarch64.dasc +++ b/ir_aarch64.dasc @@ -1,3 +1,10 @@ +/* + * IR - Lightweight JIT Compilation Framework + * (Aarch64 native code generator based on DynAsm) + * Copyright (C) 2022 Zend by Perforce. + * Authors: Dmitry Stogov + */ + |.arch arm64 |.actionlist dasm_actions diff --git a/ir_aarch64.h b/ir_aarch64.h index cc8662e..2db735c 100644 --- a/ir_aarch64.h +++ b/ir_aarch64.h @@ -1,3 +1,10 @@ +/* + * IR - Lightweight JIT Compilation Framework + * (Aarch64 CPU specific definitions) + * Copyright (C) 2022 Zend by Perforce. + * Authors: Dmitry Stogov + */ + #ifndef IR_AARCH64_H #define IR_AARCH64_H diff --git a/ir_cfg.c b/ir_cfg.c index d4c9d95..9dfbf1f 100644 --- a/ir_cfg.c +++ b/ir_cfg.c @@ -1,3 +1,10 @@ +/* + * IR - Lightweight JIT Compilation Framework + * (CFG - Control Flow Graph) + * Copyright (C) 2022 Zend by Perforce. + * Authors: Dmitry Stogov + */ + #include "ir.h" #include "ir_private.h" diff --git a/ir_check.c b/ir_check.c index bc2d428..a33cd66 100644 --- a/ir_check.c +++ b/ir_check.c @@ -1,3 +1,10 @@ +/* + * IR - Lightweight JIT Compilation Framework + * (IR verification) + * Copyright (C) 2022 Zend by Perforce. + * Authors: Dmitry Stogov + */ + #include "ir.h" #include "ir_private.h" @@ -35,7 +42,6 @@ void ir_consistency_check(void) bool ir_check(ir_ctx *ctx) { - //TODO: ir_ref i, j, n, *p, use; ir_insn *insn, *use_insn; uint32_t flags; diff --git a/ir_disasm.c b/ir_disasm.c index 89ee50f..e399919 100644 --- a/ir_disasm.c +++ b/ir_disasm.c @@ -1,3 +1,10 @@ +/* + * IR - Lightweight JIT Compilation Framework + * (Disassembler based on libcapstone) + * Copyright (C) 2022 Zend by Perforce. + * Authors: Dmitry Stogov + */ + #ifndef _GNU_SOURCE # define _GNU_SOURCE #endif diff --git a/ir_dump.c b/ir_dump.c index e0418d5..fbb4194 100644 --- a/ir_dump.c +++ b/ir_dump.c @@ -1,3 +1,10 @@ +/* + * IR - Lightweight JIT Compilation Framework + * (debug dumps) + * Copyright (C) 2022 Zend by Perforce. + * Authors: Dmitry Stogov + */ + #include "ir.h" #include "ir_private.h" diff --git a/ir_elf.h b/ir_elf.h index cd8270d..961789a 100644 --- a/ir_elf.h +++ b/ir_elf.h @@ -1,3 +1,10 @@ +/* + * IR - Lightweight JIT Compilation Framework + * (ELF header definitions) + * Copyright (C) 2022 Zend by Perforce. + * Authors: Dmitry Stogov + */ + #ifndef IR_ELF #define IR_ELF diff --git a/ir_emit.c b/ir_emit.c index cc05784..7f2a8d6 100644 --- a/ir_emit.c +++ b/ir_emit.c @@ -1,3 +1,10 @@ +/* + * IR - Lightweight JIT Compilation Framework + * (Native code generator based on DynAsm) + * Copyright (C) 2022 Zend by Perforce. + * Authors: Dmitry Stogov + */ + #include "ir.h" #if defined(IR_TARGET_X86) || defined(IR_TARGET_X64) diff --git a/ir_emit_c.c b/ir_emit_c.c index 2ab8f86..e90a469 100644 --- a/ir_emit_c.c +++ b/ir_emit_c.c @@ -1,3 +1,10 @@ +/* + * IR - Lightweight JIT Compilation Framework + * (C code generator) + * Copyright (C) 2022 Zend by Perforce. + * Authors: Dmitry Stogov + */ + #include "ir.h" #include "ir_private.h" diff --git a/ir_fold.h b/ir_fold.h index c262ea4..f2086c0 100644 --- a/ir_fold.h +++ b/ir_fold.h @@ -1,3 +1,12 @@ +/* + * IR - Lightweight JIT Compilation Framework + * (Folding engine rules) + * Copyright (C) 2022 Zend by Perforce. + * Authors: Dmitry Stogov + * + * Based on Mike Pall's implementation for LuaJIT. + */ + /* Constant Folding */ IR_FOLD(EQ(C_BOOL, C_BOOL)) IR_FOLD(EQ(C_U8, C_U8)) diff --git a/ir_gcm.c b/ir_gcm.c index 9367e3e..fb29657 100644 --- a/ir_gcm.c +++ b/ir_gcm.c @@ -1,10 +1,16 @@ +/* + * IR - Lightweight JIT Compilation Framework + * (GCM - Global Code Motion and Scheduler) + * Copyright (C) 2022 Zend by Perforce. + * Authors: Dmitry Stogov + * + * The GCM algorithm is based on Cliff Click's publication + * See: C. Click. "Global code motion, global value numbering" Submitted to PLDI‘95. + */ + #include "ir.h" #include "ir_private.h" -/* GCM - Global Code Motion - * - * C. Click. "Global code motion, global value numbering" Submitted to PLDI ‘95. - */ static void ir_gcm_schedule_early(ir_ctx *ctx, uint32_t *_blocks, ir_ref ref) { ir_ref j, n, *p; diff --git a/ir_gdb.c b/ir_gdb.c index 38a199c..a231f56 100644 --- a/ir_gdb.c +++ b/ir_gdb.c @@ -1,6 +1,10 @@ /* - * Based on Mike Pall's implementation of GDB interface for LuaJIT. - * LuaJIT -- a Just-In-Time Compiler for Lua. http://luajit.org/ + * IR - Lightweight JIT Compilation Framework + * (GDB interface) + * Copyright (C) 2022 Zend by Perforce. + * Authors: Dmitry Stogov + * + * Based on Mike Pall's implementation of GDB interface for LuaJIT. */ #include diff --git a/ir_load.c b/ir_load.c index 1d0407a..ba991c4 100644 --- a/ir_load.c +++ b/ir_load.c @@ -1,4 +1,14 @@ -/* This file is generated from "ir.g". Do not edit! */ +/* + * IR - Lightweight JIT Compilation Framework + * (IR loader) + * Copyright (C) 2005-2022 Zend by Perforce. + * Authors: Dmitry Stogov + * + * This file is generated from "ir.g". Do not edit! + * + * To generate ir_load.c use llk : + * php llk.php ir.g + */ #include "ir.h" #include "ir_private.h" diff --git a/ir_main.c b/ir_main.c index 7fad022..007eb94 100644 --- a/ir_main.c +++ b/ir_main.c @@ -1,3 +1,10 @@ +/* + * IR - Lightweight JIT Compilation Framework + * (IR CLI driver) + * Copyright (C) 2022 Zend by Perforce. + * Authors: Dmitry Stogov + */ + #include "ir.h" #include #include diff --git a/ir_patch.c b/ir_patch.c index f3944a7..aacda06 100644 --- a/ir_patch.c +++ b/ir_patch.c @@ -1,8 +1,16 @@ +/* + * IR - Lightweight JIT Compilation Framework + * (Native code patcher) + * Copyright (C) 2022 Zend by Perforce. + * Authors: Dmitry Stogov + * + * Based on Mike Pall's implementation for LuaJIT. + */ + #include "ir.h" #include "ir_private.h" #if defined(IR_TARGET_X86) || defined(IR_TARGET_X64) -/* This taken from LuaJIT. Thanks to Mike Pall. */ static uint32_t _asm_x86_inslen(const uint8_t* p) { static const uint8_t map_op1[256] = { diff --git a/ir_perf.c b/ir_perf.c index 839927e..7255624 100644 --- a/ir_perf.c +++ b/ir_perf.c @@ -1,3 +1,19 @@ +/* + * IR - Lightweight JIT Compilation Framework + * (Linux perf interface) + * Copyright (C) 2022 Zend by Perforce. + * Authors: Dmitry Stogov + * + * 1) Profile using perf-.map + * perf record ./prog + * perf report + * + * 2) Profile using jit-.dump + * perf record -k 1 ./prog + * perf inject -j -i perf.data -o perf.data.jitted + * perf report -i perf.data.jitted + */ + #include #include #include @@ -29,20 +45,6 @@ extern unsigned int thr_self(void); #include "ir.h" #include "ir_elf.h" -/* - * 1) Profile using perf-.map - * - * perf record ./prog - * perf report - * - * 2) Profile using jit-.dump - * - * perf record -k 1 ./prog - * perf inject -j -i perf.data -o perf.data.jitted - * perf report -i perf.data.jitted - * - */ - #define IR_PERF_JITDUMP_HEADER_MAGIC 0x4A695444 #define IR_PERF_JITDUMP_HEADER_VERSION 1 diff --git a/ir_php.h b/ir_php.h index 74feb14..57bb061 100644 --- a/ir_php.h +++ b/ir_php.h @@ -1,3 +1,10 @@ +/* + * IR - Lightweight JIT Compilation Framework + * (IR/PHP integration) + * Copyright (C) 2022 Zend by Perforce. + * Authors: Dmitry Stogov + */ + #ifndef IR_PHP_H #define IR_PHP_H diff --git a/ir_private.h b/ir_private.h index 0a90f14..711a4bf 100644 --- a/ir_private.h +++ b/ir_private.h @@ -1,3 +1,10 @@ +/* + * IR - Lightweight JIT Compilation Framework + * (Common data structures and non public definitions) + * Copyright (C) 2022 Zend by Perforce. + * Authors: Dmitry Stogov + */ + #ifndef IR_PRIVATE_H #define IR_PRIVATE_H #include diff --git a/ir_ra.c b/ir_ra.c index 6c1ffdd..d649523 100644 --- a/ir_ra.c +++ b/ir_ra.c @@ -1,3 +1,15 @@ +/* + * IR - Lightweight JIT Compilation Framework + * (RA - Register Allocation, Liveness, Coalescing, SSA Deconstruction) + * Copyright (C) 2022 Zend by Perforce. + * Authors: Dmitry Stogov + * + * See: "Linear Scan Register Allocation on SSA Form", Christian Wimmer and + * Michael Franz, CGO'10 (2010) + * See: "Optimized Interval Splitting in a Linear Scan Register Allocator", + * Christian Wimmer VEE'10 (2005) + */ + #ifndef _GNU_SOURCE # define _GNU_SOURCE #endif @@ -34,8 +46,6 @@ bool ir_reg_is_int(int32_t reg) return reg >= IR_REG_GP_FIRST && reg <= IR_REG_GP_LAST; } -/* RA - Register Allocation, Liveness, Coalescing and SSA Resolution */ - int ir_assign_virtual_registers(ir_ctx *ctx) { uint32_t *vregs; @@ -79,11 +89,8 @@ int ir_assign_virtual_registers(ir_ctx *ctx) return 1; } -/* Lifetime intervals construction - * - * See "Linear Scan Register Allocation on SSA Form", Christian Wimmer and - * Michael Franz, CGO'10 (2010), Figure 4. - */ +/* Lifetime intervals construction */ + static void ir_add_local_var(ir_ctx *ctx, int v, uint8_t type) { ir_live_interval *ival = ctx->live_intervals[v]; @@ -1220,11 +1227,8 @@ int ir_gen_dessa_moves(ir_ctx *ctx, int b, emit_copy_t emit_copy) return 1; } -/* Linear Scan Register Allocation - * - * See "Optimized Interval Splitting in a Linear Scan Register Allocator", - * Christian Wimmer VEE'10 (2005), Figure 2. - */ +/* Linear Scan Register Allocation */ + #ifdef IR_DEBUG # define IR_LOG_LSRA(action, ival, comment) do { \ if (ctx->flags & IR_DEBUG_RA) { \ diff --git a/ir_save.c b/ir_save.c index b2a72bc..1224abe 100644 --- a/ir_save.c +++ b/ir_save.c @@ -1,3 +1,10 @@ +/* + * IR - Lightweight JIT Compilation Framework + * (IR saver) + * Copyright (C) 2022 Zend by Perforce. + * Authors: Dmitry Stogov + */ + #include "ir.h" #include "ir_private.h" diff --git a/ir_sccp.c b/ir_sccp.c index 970ff88..4cb002a 100644 --- a/ir_sccp.c +++ b/ir_sccp.c @@ -1,3 +1,14 @@ +/* + * IR - Lightweight JIT Compilation Framework + * (SCCP - Sparse Conditional Constant Propagation) + * Copyright (C) 2022 Zend by Perforce. + * Authors: Dmitry Stogov + * + * The SCCP algorithm is based on M. N. Wegman and F. K. Zadeck publication + * See: M. N. Wegman and F. K. Zadeck. "Constant propagation with conditional branches" + * ACM Transactions on Programming Languages and Systems, 13(2):181-210, April 1991 + */ + #include "ir.h" #include "ir_private.h" @@ -5,12 +16,6 @@ # pragma GCC diagnostic ignored "-Warray-bounds" #endif -/* SCCP - Sparse Conditional Constant Propagation + Copy Propagation - * - * M. N. Wegman and F. K. Zadeck. "Constant propagation with conditional branches" - * ACM Transactions on Programming Languages and Systems, 13(2):181-210, April 1991 - */ - #define IR_TOP IR_UNUSED #define IR_BOTTOM IR_LAST_OP diff --git a/ir_strtab.c b/ir_strtab.c index c6c6d1d..44d1642 100644 --- a/ir_strtab.c +++ b/ir_strtab.c @@ -1,3 +1,10 @@ +/* + * IR - Lightweight JIT Compilation Framework + * (String table) + * Copyright (C) 2022 Zend by Perforce. + * Authors: Dmitry Stogov + */ + #include "ir.h" #include "ir_private.h" diff --git a/ir_test.c b/ir_test.c index d829d07..00c4063 100644 --- a/ir_test.c +++ b/ir_test.c @@ -1,3 +1,10 @@ +/* + * IR - Lightweight JIT Compilation Framework + * (Mandelbrot example) + * Copyright (C) 2022 Zend by Perforce. + * Authors: Dmitry Stogov + */ + #include "ir.h" #include #include diff --git a/ir_x86.dasc b/ir_x86.dasc index e2459dd..c463b80 100644 --- a/ir_x86.dasc +++ b/ir_x86.dasc @@ -1,3 +1,10 @@ +/* + * IR - Lightweight JIT Compilation Framework + * (x86/x86_64 native code generator based on DynAsm) + * Copyright (C) 2022 Zend by Perforce. + * Authors: Dmitry Stogov + */ + |.if X64 |.arch x64 |.else diff --git a/ir_x86.h b/ir_x86.h index 93618ab..ab22844 100644 --- a/ir_x86.h +++ b/ir_x86.h @@ -1,3 +1,10 @@ +/* + * IR - Lightweight JIT Compilation Framework + * (x86/x86_64 CPU soecific definitions) + * Copyright (C) 2022 Zend by Perforce. + * Authors: Dmitry Stogov + */ + #ifndef IR_X86_H #define IR_X86_H