Add LICENSE and copyright notices

This commit is contained in:
Dmitry Stogov 2022-11-08 11:32:46 +03:00
parent 2ff0617db6
commit cc56f12f13
31 changed files with 285 additions and 45 deletions

21
LICENSE Normal file
View File

@ -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.

View File

@ -1,3 +1,12 @@
/*
* IR - Lightweight JIT Compilation Framework
* (Folding engine generator)
* Copyright (C) 2022 Zend by Perforce.
* Authors: Dmitry Stogov <dmitry@php.net>
*
* Based on Mike Pall's implementation for LuaJIT.
*/
#include "ir.h" #include "ir.h"
#include <string.h> #include <string.h>

View File

@ -1,4 +1,10 @@
<?php <?php
/*
* IR - Lightweight JIT Compilation Framework
* (Test driver)
* Copyright (C) 2022 Zend by Perforce.
* Authors: Dmitry Stogov <dmitry@php.net>
*/
function parse_test($test, &$name, &$code, &$expect, &$args, &$target) { function parse_test($test, &$name, &$code, &$expect, &$args, &$target) {
$text = @file_get_contents($test); $text = @file_get_contents($test);

16
ir.c
View File

@ -1,3 +1,19 @@
/*
* IR - Lightweight JIT Compilation Framework
* (IR construction, folding, utilities)
* Copyright (C) 2022 Zend by Perforce.
* Authors: Dmitry Stogov <dmitry@php.net>
*
* 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 #ifndef _GNU_SOURCE
# define _GNU_SOURCE # define _GNU_SOURCE
#endif #endif

23
ir.g
View File

@ -1,7 +1,12 @@
/* /*
To generate ir_load.c use llk <https://github.com/dstogov/llk>: * IR - Lightweight JIT Compilation Framework
php llk.php ir.g * (IR loader)
*/ * Copyright (C) 2022 Zend by Perforce.
* Authors: Dmitry Stogov <dmitry@php.net>
*
* To generate ir_load.c use llk <https://github.com/dstogov/llk>:
* php llk.php ir.g
*/
%start ir %start ir
%case-sensetive true %case-sensetive true
@ -11,7 +16,17 @@ php llk.php ir.g
%indent "\t" %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 <dmitry@php.net>
*
* This file is generated from "ir.g". Do not edit!
*
* To generate ir_load.c use llk <https://github.com/dstogov/llk>:
* php llk.php ir.g
*/
#include "ir.h" #include "ir.h"
#include "ir_private.h" #include "ir_private.h"

7
ir.h
View File

@ -1,3 +1,10 @@
/*
* IR - Lightweight JIT Compilation Framework
* (Public API)
* Copyright (C) 2022 Zend by Perforce.
* Authors: Dmitry Stogov <dmitry@php.net>
*/
#ifndef IR_H #ifndef IR_H
#define IR_H #define IR_H

View File

@ -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 <dmitry@php.net>
*/
|.arch arm64 |.arch arm64
|.actionlist dasm_actions |.actionlist dasm_actions

View File

@ -1,3 +1,10 @@
/*
* IR - Lightweight JIT Compilation Framework
* (Aarch64 CPU specific definitions)
* Copyright (C) 2022 Zend by Perforce.
* Authors: Dmitry Stogov <dmitry@php.net>
*/
#ifndef IR_AARCH64_H #ifndef IR_AARCH64_H
#define IR_AARCH64_H #define IR_AARCH64_H

View File

@ -1,3 +1,10 @@
/*
* IR - Lightweight JIT Compilation Framework
* (CFG - Control Flow Graph)
* Copyright (C) 2022 Zend by Perforce.
* Authors: Dmitry Stogov <dmitry@php.net>
*/
#include "ir.h" #include "ir.h"
#include "ir_private.h" #include "ir_private.h"

View File

@ -1,3 +1,10 @@
/*
* IR - Lightweight JIT Compilation Framework
* (IR verification)
* Copyright (C) 2022 Zend by Perforce.
* Authors: Dmitry Stogov <dmitry@php.net>
*/
#include "ir.h" #include "ir.h"
#include "ir_private.h" #include "ir_private.h"
@ -35,7 +42,6 @@ void ir_consistency_check(void)
bool ir_check(ir_ctx *ctx) bool ir_check(ir_ctx *ctx)
{ {
//TODO:
ir_ref i, j, n, *p, use; ir_ref i, j, n, *p, use;
ir_insn *insn, *use_insn; ir_insn *insn, *use_insn;
uint32_t flags; uint32_t flags;

View File

@ -1,3 +1,10 @@
/*
* IR - Lightweight JIT Compilation Framework
* (Disassembler based on libcapstone)
* Copyright (C) 2022 Zend by Perforce.
* Authors: Dmitry Stogov <dmitry@php.net>
*/
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
# define _GNU_SOURCE # define _GNU_SOURCE
#endif #endif

View File

@ -1,3 +1,10 @@
/*
* IR - Lightweight JIT Compilation Framework
* (debug dumps)
* Copyright (C) 2022 Zend by Perforce.
* Authors: Dmitry Stogov <dmitry@php.net>
*/
#include "ir.h" #include "ir.h"
#include "ir_private.h" #include "ir_private.h"

View File

@ -1,3 +1,10 @@
/*
* IR - Lightweight JIT Compilation Framework
* (ELF header definitions)
* Copyright (C) 2022 Zend by Perforce.
* Authors: Dmitry Stogov <dmitry@php.net>
*/
#ifndef IR_ELF #ifndef IR_ELF
#define IR_ELF #define IR_ELF

View File

@ -1,3 +1,10 @@
/*
* IR - Lightweight JIT Compilation Framework
* (Native code generator based on DynAsm)
* Copyright (C) 2022 Zend by Perforce.
* Authors: Dmitry Stogov <dmitry@php.net>
*/
#include "ir.h" #include "ir.h"
#if defined(IR_TARGET_X86) || defined(IR_TARGET_X64) #if defined(IR_TARGET_X86) || defined(IR_TARGET_X64)

View File

@ -1,3 +1,10 @@
/*
* IR - Lightweight JIT Compilation Framework
* (C code generator)
* Copyright (C) 2022 Zend by Perforce.
* Authors: Dmitry Stogov <dmitry@php.net>
*/
#include "ir.h" #include "ir.h"
#include "ir_private.h" #include "ir_private.h"

View File

@ -1,3 +1,12 @@
/*
* IR - Lightweight JIT Compilation Framework
* (Folding engine rules)
* Copyright (C) 2022 Zend by Perforce.
* Authors: Dmitry Stogov <dmitry@php.net>
*
* Based on Mike Pall's implementation for LuaJIT.
*/
/* Constant Folding */ /* Constant Folding */
IR_FOLD(EQ(C_BOOL, C_BOOL)) IR_FOLD(EQ(C_BOOL, C_BOOL))
IR_FOLD(EQ(C_U8, C_U8)) IR_FOLD(EQ(C_U8, C_U8))

View File

@ -1,10 +1,16 @@
/*
* IR - Lightweight JIT Compilation Framework
* (GCM - Global Code Motion and Scheduler)
* Copyright (C) 2022 Zend by Perforce.
* Authors: Dmitry Stogov <dmitry@php.net>
*
* The GCM algorithm is based on Cliff Click's publication
* See: C. Click. "Global code motion, global value numbering" Submitted to PLDI95.
*/
#include "ir.h" #include "ir.h"
#include "ir_private.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) static void ir_gcm_schedule_early(ir_ctx *ctx, uint32_t *_blocks, ir_ref ref)
{ {
ir_ref j, n, *p; ir_ref j, n, *p;

View File

@ -1,6 +1,10 @@
/* /*
* Based on Mike Pall's implementation of GDB interface for LuaJIT. * IR - Lightweight JIT Compilation Framework
* LuaJIT -- a Just-In-Time Compiler for Lua. http://luajit.org/ * (GDB interface)
* Copyright (C) 2022 Zend by Perforce.
* Authors: Dmitry Stogov <dmitry@php.net>
*
* Based on Mike Pall's implementation of GDB interface for LuaJIT.
*/ */
#include <stdlib.h> #include <stdlib.h>

View File

@ -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 <dmitry@php.net>
*
* This file is generated from "ir.g". Do not edit!
*
* To generate ir_load.c use llk <https://github.com/dstogov/llk>:
* php llk.php ir.g
*/
#include "ir.h" #include "ir.h"
#include "ir_private.h" #include "ir_private.h"

View File

@ -1,3 +1,10 @@
/*
* IR - Lightweight JIT Compilation Framework
* (IR CLI driver)
* Copyright (C) 2022 Zend by Perforce.
* Authors: Dmitry Stogov <dmitry@php.net>
*/
#include "ir.h" #include "ir.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>

View File

@ -1,8 +1,16 @@
/*
* IR - Lightweight JIT Compilation Framework
* (Native code patcher)
* Copyright (C) 2022 Zend by Perforce.
* Authors: Dmitry Stogov <dmitry@php.net>
*
* Based on Mike Pall's implementation for LuaJIT.
*/
#include "ir.h" #include "ir.h"
#include "ir_private.h" #include "ir_private.h"
#if defined(IR_TARGET_X86) || defined(IR_TARGET_X64) #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 uint32_t _asm_x86_inslen(const uint8_t* p)
{ {
static const uint8_t map_op1[256] = { static const uint8_t map_op1[256] = {

View File

@ -1,3 +1,19 @@
/*
* IR - Lightweight JIT Compilation Framework
* (Linux perf interface)
* Copyright (C) 2022 Zend by Perforce.
* Authors: Dmitry Stogov <dmitry@php.net>
*
* 1) Profile using perf-<pid>.map
* perf record ./prog
* perf report
*
* 2) Profile using jit-<pid>.dump
* perf record -k 1 ./prog
* perf inject -j -i perf.data -o perf.data.jitted
* perf report -i perf.data.jitted
*/
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
@ -29,20 +45,6 @@ extern unsigned int thr_self(void);
#include "ir.h" #include "ir.h"
#include "ir_elf.h" #include "ir_elf.h"
/*
* 1) Profile using perf-<pid>.map
*
* perf record ./prog
* perf report
*
* 2) Profile using jit-<pid>.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_MAGIC 0x4A695444
#define IR_PERF_JITDUMP_HEADER_VERSION 1 #define IR_PERF_JITDUMP_HEADER_VERSION 1

View File

@ -1,3 +1,10 @@
/*
* IR - Lightweight JIT Compilation Framework
* (IR/PHP integration)
* Copyright (C) 2022 Zend by Perforce.
* Authors: Dmitry Stogov <dmitry@php.net>
*/
#ifndef IR_PHP_H #ifndef IR_PHP_H
#define IR_PHP_H #define IR_PHP_H

View File

@ -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 <dmitry@php.net>
*/
#ifndef IR_PRIVATE_H #ifndef IR_PRIVATE_H
#define IR_PRIVATE_H #define IR_PRIVATE_H
#include <string.h> #include <string.h>

28
ir_ra.c
View File

@ -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 <dmitry@php.net>
*
* 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 #ifndef _GNU_SOURCE
# define _GNU_SOURCE # define _GNU_SOURCE
#endif #endif
@ -34,8 +46,6 @@ bool ir_reg_is_int(int32_t reg)
return reg >= IR_REG_GP_FIRST && reg <= IR_REG_GP_LAST; 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) int ir_assign_virtual_registers(ir_ctx *ctx)
{ {
uint32_t *vregs; uint32_t *vregs;
@ -79,11 +89,8 @@ int ir_assign_virtual_registers(ir_ctx *ctx)
return 1; return 1;
} }
/* Lifetime intervals construction /* Lifetime intervals construction */
*
* See "Linear Scan Register Allocation on SSA Form", Christian Wimmer and
* Michael Franz, CGO'10 (2010), Figure 4.
*/
static void ir_add_local_var(ir_ctx *ctx, int v, uint8_t type) static void ir_add_local_var(ir_ctx *ctx, int v, uint8_t type)
{ {
ir_live_interval *ival = ctx->live_intervals[v]; 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; return 1;
} }
/* Linear Scan Register Allocation /* Linear Scan Register Allocation */
*
* See "Optimized Interval Splitting in a Linear Scan Register Allocator",
* Christian Wimmer VEE'10 (2005), Figure 2.
*/
#ifdef IR_DEBUG #ifdef IR_DEBUG
# define IR_LOG_LSRA(action, ival, comment) do { \ # define IR_LOG_LSRA(action, ival, comment) do { \
if (ctx->flags & IR_DEBUG_RA) { \ if (ctx->flags & IR_DEBUG_RA) { \

View File

@ -1,3 +1,10 @@
/*
* IR - Lightweight JIT Compilation Framework
* (IR saver)
* Copyright (C) 2022 Zend by Perforce.
* Authors: Dmitry Stogov <dmitry@php.net>
*/
#include "ir.h" #include "ir.h"
#include "ir_private.h" #include "ir_private.h"

View File

@ -1,3 +1,14 @@
/*
* IR - Lightweight JIT Compilation Framework
* (SCCP - Sparse Conditional Constant Propagation)
* Copyright (C) 2022 Zend by Perforce.
* Authors: Dmitry Stogov <dmitry@php.net>
*
* 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.h"
#include "ir_private.h" #include "ir_private.h"
@ -5,12 +16,6 @@
# pragma GCC diagnostic ignored "-Warray-bounds" # pragma GCC diagnostic ignored "-Warray-bounds"
#endif #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_TOP IR_UNUSED
#define IR_BOTTOM IR_LAST_OP #define IR_BOTTOM IR_LAST_OP

View File

@ -1,3 +1,10 @@
/*
* IR - Lightweight JIT Compilation Framework
* (String table)
* Copyright (C) 2022 Zend by Perforce.
* Authors: Dmitry Stogov <dmitry@php.net>
*/
#include "ir.h" #include "ir.h"
#include "ir_private.h" #include "ir_private.h"

View File

@ -1,3 +1,10 @@
/*
* IR - Lightweight JIT Compilation Framework
* (Mandelbrot example)
* Copyright (C) 2022 Zend by Perforce.
* Authors: Dmitry Stogov <dmitry@php.net>
*/
#include "ir.h" #include "ir.h"
#include <sys/time.h> #include <sys/time.h>
#include <stdlib.h> #include <stdlib.h>

View File

@ -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 <dmitry@php.net>
*/
|.if X64 |.if X64
|.arch x64 |.arch x64
|.else |.else

View File

@ -1,3 +1,10 @@
/*
* IR - Lightweight JIT Compilation Framework
* (x86/x86_64 CPU soecific definitions)
* Copyright (C) 2022 Zend by Perforce.
* Authors: Dmitry Stogov <dmitry@php.net>
*/
#ifndef IR_X86_H #ifndef IR_X86_H
#define IR_X86_H #define IR_X86_H