Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IR based JIT #2

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 37 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
# Copyright (c) 2015, 2016 Grigory Rechistov. All rights reserved.
#

CFLAGS=-std=c11 -O2 -Wextra -Werror -gdwarf-3
CFLAGS=-std=c11 -O0 -g -Wextra -Werror -gdwarf-3
LDFLAGS = -lm

COMMON_SRC = common.c
COMMON_OBJ := $(COMMON_SRC:.c=.o)
COMMON_HEADERS = common.h

ALL = switched threaded predecoded subroutined threaded-cached tailrecursive asmopt translated native
ALL = switched threaded predecoded subroutined threaded-cached tailrecursive asmopt translated native \
jited_ir jited_ir_stack jited_ir_var jited_ir_ssa

# Must be the first target for the magic below to work
all: $(ALL)
Expand Down Expand Up @@ -43,46 +44,46 @@ $(ALL): $(COMMON_OBJ)
# Note that some of them use customized CFLAGS

switched: switched.o
$(CC) $^ -lm -o $@
$(CC) $^ $(LDFLAGS) -o $@

threaded: CFLAGS += -fno-gcse -fno-function-cse -fno-thread-jumps -fno-cse-follow-jumps -fno-crossjumping -fno-cse-skip-blocks -fomit-frame-pointer
threaded: threaded.o
$(CC) $^ -lm -o $@
$(CC) $^ $(LDFLAGS) -o $@

predecoded: predecoded.o
$(CC) $^ -lm -o $@
$(CC) $^ $(LDFLAGS) -o $@

tailrecursive: CFLAGS += -foptimize-sibling-calls
tailrecursive: tailrecursive.o
$(CC) $^ -lm -o $@
$(CC) $^ $(LDFLAGS) -o $@

asmoptll: asmoptll.o
$(CC) -g -pg -c $< -o $@

asmopt: CFLAGS += -foptimize-sibling-calls
asmopt: asmoptll.o asmopt.o
$(CC) -g -pg $^ -lm -o $@
$(CC) -g -pg $^ $(LDFLAGS) -o $@

prof:
gprof -b asmopt gmon.out

threaded-cached: CFLAGS += -fno-gcse -fno-thread-jumps -fno-cse-follow-jumps -fno-crossjumping -fno-cse-skip-blocks -fomit-frame-pointer
threaded-cached: threaded-cached.o
$(CC) $^ -lm -o $@
$(CC) $^ $(LDFLAGS) -o $@

subroutined: subroutined.o
$(CC) $^ -lm -o $@
$(CC) $^ $(LDFLAGS) -o $@

translated: CFLAGS += -std=gnu11
translated: translated.o
$(CC) $^ -lm -o $@
$(CC) $^ $(LDFLAGS) -o $@

translated-inline: CFLAGS += -std=gnu11
translated-inline: translated-inline.o
$(CC) $^ -lm -o $@
$(CC) $^ $(LDFLAGS) -o $@

native: native.o
$(CC) $^ -lm -o $@
$(CC) $^ $(LDFLAGS) -o $@

########################
### Maintainance targets
Expand Down Expand Up @@ -110,3 +111,27 @@ threaded-notune: threaded.o
# This will crash with stack overflow
tailrecursive-noopt: CFLAGS += -O0 -fno-optimize-sibling-calls
tailrecursive-noopt: tailrecursive.o

jited_ir.o: jited_ir.c
$(CC) $(DEPFLAGS) $(CFLAGS) $(CPPFLAGS) -c $<

jited_ir: jited_ir.o
$(CC) $^ -lir -lcapstone $(LDFLAGS) -o $@

jited_ir_stack.o: jited_ir.c
$(CC) $(DEPFLAGS) $(CFLAGS) $(CPPFLAGS) -DJIT_RESOLVE_STACK -o $@ -c $<

jited_ir_stack: jited_ir_stack.o
$(CC) $^ -lir -lcapstone $(LDFLAGS) -o $@

jited_ir_var.o: jited_ir.c
$(CC) $(DEPFLAGS) $(CFLAGS) $(CPPFLAGS) -DJIT_RESOLVE_STACK -DJIT_USE_VARS -o $@ -c $<

jited_ir_var: jited_ir_var.o
$(CC) $^ -lir -lcapstone $(LDFLAGS) -o $@

jited_ir_ssa.o: jited_ir.c
$(CC) $(DEPFLAGS) $(CFLAGS) $(CPPFLAGS) -DJIT_RESOLVE_STACK -DJIT_USE_SSA -o $@ -c $<

jited_ir_ssa: jited_ir_ssa.o
$(CC) $^ -lir -lcapstone $(LDFLAGS) -o $@
4 changes: 4 additions & 0 deletions common.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */

#include "common.h"

int debug = 0;

/* Program to print all prime numbers < 10000 */
const Instr_t Primes[PROGRAM_SIZE] = {
Instr_Push, 100000, // nmax (maximal number to test)
Expand Down Expand Up @@ -198,6 +200,8 @@ uint64_t parse_args(int argc, char** argv) {
for (int i = 1; i < argc; ++i) {
if (!strcmp(argv[i], "--help"))
report_usage_and_exit(argv[0], 0);
if (!strcmp(argv[i], "--debug"))
debug = 1;
else if (!strncmp(argv[i], steplimit_opt, strlen(steplimit_opt))) {
char *endptr = NULL;
steplimit = strtoll(argv[i] + strlen(steplimit_opt), &endptr, 10);
Expand Down
2 changes: 2 additions & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
#ifndef COMMON_H_
#define COMMON_H_

extern int debug;

/* Instruction Set Architecture:
opcodes and arguments for individual instructions.
Those marked with "imm" use the next machine word
Expand Down
Loading