Skip to content
Merged
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
2 changes: 1 addition & 1 deletion external/rsh
3 changes: 2 additions & 1 deletion rcp/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ RSH_HOME ?= $(ROOT_DIR)/../external/rsh/client/rsh
R_HOME ?= $(ROOT_DIR)/../external/rsh/external/R
# Which R to use
R := $(R_HOME)/bin/R
RSCRIPT := $(R_HOME)/bin/Rscript

define ensure_microbenchmark_installed
if ! $(R) --slave --no-restore -e 'if (!requireNamespace("microbenchmark", quietly=TRUE)) quit(status=1)' >/dev/null 2>&1; then \
if ! $(RSCRIPT) --vanilla -e 'if (!requireNamespace("microbenchmark", quietly=TRUE)) quit(status=1)' >/dev/null 2>&1; then \
echo "Error: R package 'microbenchmark' is not installed. Run 'make setup' from the repository root." >&2; \
exit 1; \
fi
Expand Down
3 changes: 3 additions & 0 deletions rcp/inst/benchmarks/run-benchmarks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ run_one() {
echo " [$count/$TOTAL] $name ... OK"
else
echo " [$count/$TOTAL] $name ... FAIL"
echo "--- $name output ---"
cat "$OUTPUT/$name.log"
echo "--- end $name output ---"
fi
) 9>"$LOCKFILE"

Expand Down
26 changes: 17 additions & 9 deletions rcp/src/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,6 @@ static struct StencilProfileInfo
stencil_profile_info[sizeof(OPCODES_NAMES) / sizeof(*OPCODES_NAMES)];
#endif

#define UNPROTECT_SAFE(ptr) \
do \
{ \
assert(R_PPStack[R_PPStackTop - 1] == ptr); \
UNPROTECT(1); \
} while (0)

// Used as a hint where to map address space close to R internals to allow
// relative addressing
#define R_INTERNALS_ADDRESS (&Rf_ScalarInteger)
Expand Down Expand Up @@ -389,7 +382,8 @@ static void prepare_shared_memory()
PROTECT(R_MakeExternalPtr(mem_shared, R_NilValue, R_NilValue));
R_PreserveObject(mem_shared_sexp);
UNPROTECT(1); // mem_shared_sexp
R_RegisterCFinalizerEx(mem_shared_sexp, &R_RcpSharedFree, TRUE);
// We do not free structures if R is shutting down, there will be memory leaks.
R_RegisterCFinalizerEx(mem_shared_sexp, &R_RcpSharedFree, FALSE);
}

#ifdef STEPFOR_SPECIALIZE
Expand Down Expand Up @@ -2095,7 +2089,8 @@ static SEXP copy_patch_bc(SEXP bcode, int recursive, CompilationStats *stats,
SEXP ptr = R_MakeExternalPtr(res_ptr, Rsh_ClosureBodyTag, prot);
UNPROTECT_SAFE(prot); // prot
PROTECT(ptr);
R_RegisterCFinalizerEx(ptr, &rcp_finalizer, TRUE);
// We do not free structures if R is shutting down, there will be memory leaks.
R_RegisterCFinalizerEx(ptr, &rcp_finalizer, FALSE);
UNPROTECT_SAFE(ptr); // ptr
Comment thread
MatejKocourek marked this conversation as resolved.
return ptr;
}
Expand Down Expand Up @@ -3149,6 +3144,19 @@ void __attribute__((used)) rcp_print_stack_val(void *p)
}
}

void __attribute__((used)) rcp_print_stack_val_unbox(void *p)
{
if (!p)
{
Rprintf("Stack value is NULL\n");
return;
}
R_bcstack_t v = *(R_bcstack_t *)p;
val_unbox_inplace(&v, 1, 1, 1);

rcp_print_stack_val(&v);
}

SEXP rcp_init(void)
{
refresh_near_memory_ptr(0);
Expand Down
21 changes: 10 additions & 11 deletions rcp/src/stencils/stencils.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,10 @@ static inline uint64_t rdtsc(void)
#define PROFILING_END(opcode) ((void)0)
#endif

#define RET_T Value

// Macros to define stencil functions
#define RCP_STENCIL_FUNCTION(name) __attribute__((noinline)) STENCIL_ATTRIBUTES SEXP name(Value *restrict stack, rcpEval_locals *restrict locals)
#define RCP_STENCIL_FUNCTION(name) __attribute__((noinline)) STENCIL_ATTRIBUTES RET_T name(Value *restrict stack, rcpEval_locals *restrict locals)
#define RCP_OP_EX(op, ex) RCP_STENCIL_FUNCTION(_RCP_##op##_OP_##ex)
#define RCP_STENCIL(op) RCP_STENCIL_FUNCTION(_RCP_##op##_OP)

Expand Down Expand Up @@ -139,13 +141,13 @@ static inline uint64_t rdtsc(void)
#define RCP_OP(...) EXPAND(GET_MACRO(__VA_ARGS__, RCP_OP_TEMPLATE_JUMP, RCP_OP_TEMPLATE_CONTINUE)(__VA_ARGS__))

/* PATCHING SYMBOLS */
extern STENCIL_ATTRIBUTES SEXP _RCP_EXEC_NEXT(Value *stack, rcpEval_locals *locals);
extern STENCIL_ATTRIBUTES RET_T _RCP_EXEC_NEXT(Value *stack, rcpEval_locals *locals);
#define NEXT return _RCP_EXEC_NEXT(stack, locals)

extern STENCIL_ATTRIBUTES SEXP _RCP_EXEC_IMM0(Value *stack, rcpEval_locals *locals);
extern STENCIL_ATTRIBUTES SEXP _RCP_EXEC_IMM1(Value *stack, rcpEval_locals *locals);
extern STENCIL_ATTRIBUTES SEXP _RCP_EXEC_IMM2(Value *stack, rcpEval_locals *locals);
extern STENCIL_ATTRIBUTES SEXP _RCP_EXEC_IMM3(Value *stack, rcpEval_locals *locals);
extern STENCIL_ATTRIBUTES RET_T _RCP_EXEC_IMM0(Value *stack, rcpEval_locals *locals);
extern STENCIL_ATTRIBUTES RET_T _RCP_EXEC_IMM1(Value *stack, rcpEval_locals *locals);
extern STENCIL_ATTRIBUTES RET_T _RCP_EXEC_IMM2(Value *stack, rcpEval_locals *locals);
extern STENCIL_ATTRIBUTES RET_T _RCP_EXEC_IMM3(Value *stack, rcpEval_locals *locals);
#define GOTO_IMM(i) return _RCP_EXEC_IMM##i(stack, locals)
//__attribute__((musttail))
//[[gnu::musttail]]
Expand Down Expand Up @@ -194,7 +196,7 @@ extern const void *const _RCP_EXECUTABLE[];
#define GETEXECUTABLE() (const void *const)&_RCP_EXECUTABLE
#define GOTO_VAL(i) \
{ \
STENCIL_ATTRIBUTES SEXP (*call)(Value * stack, rcpEval_locals * locals) = (const void *const)(((uint8_t *)GETEXECUTABLE()) + i); \
STENCIL_ATTRIBUTES RET_T (*call)(Value * stack, rcpEval_locals * locals) = (const void *const)(((uint8_t *)GETEXECUTABLE()) + i); \
return call(stack, locals); \
}

Expand Down Expand Up @@ -326,11 +328,8 @@ RCP_STENCIL_FUNCTION(_RCP_EXIT_HOOK)
NEXT;
}


RCP_OP(RETURN,
,
PUSH_VAL(1);
return Rsh_Return(stack);)
return *(stack - 1);)

RCP_OP(GOTO,
,
Expand Down
2 changes: 1 addition & 1 deletion rcp/tests/benchmarks/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ all: test
test:
@$(call ensure_microbenchmark_installed)
@RSH_HOME=$(RSH_HOME) R_HOME=$(R_HOME) ../../inst/benchmarks/run-benchmarks.sh
@$(R) --slave --no-restore -f ../../inst/benchmarks/benchmark-compiler.R --args $(RSH_HOME)/inst/benchmarks
@$(RSCRIPT) --vanilla ../../inst/benchmarks/benchmark-compiler.R $(RSH_HOME)/inst/benchmarks

clean:
@true
2 changes: 1 addition & 1 deletion rcp/tests/exceptions/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ all: test

test:
@echo "Running exception unwinding test..."
@$(R) --vanilla --quiet < test.R || exit 1
@$(RSCRIPT) --vanilla test.R || exit 1

clean:
@rm -f *.Rout .RData
6 changes: 3 additions & 3 deletions rcp/tests/gdb-jit/gdb-next/test.gdb
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ next

# Line 2 (LDCONST) - stepped over GETVAR
echo Stack Top after GETVAR (should be 10):\n
call rcp_print_stack_val((void*)((char*)stack - 16))
call rcp_print_stack_val_unbox((void*)((char*)stack - 16))
next

# Line 3 (ADD) - stepped over LDCONST
echo Stack Top after LDCONST (should be 1):\n
call rcp_print_stack_val((void*)((char*)stack - 16))
call rcp_print_stack_val_unbox((void*)((char*)stack - 16))
next

# Line 4 (RETURN) - stepped over ADD
echo Stack Top after ADD (should be 11):\n
call rcp_print_stack_val((void*)((char*)stack - 16))
call rcp_print_stack_val_unbox((void*)((char*)stack - 16))

quit
2 changes: 1 addition & 1 deletion rcp/tests/smoketest/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ all: test
test:
@for test in $(TESTS); do \
echo "Running $$test..."; \
$(R) --vanilla --quiet < $$test || exit 1; \
$(RSCRIPT) --vanilla $$test || exit 1; \
done

clean:
Expand Down
2 changes: 1 addition & 1 deletion rcp/tests/types/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ all: test
test:
@for test in $(TESTS); do \
echo "Running $$test..."; \
$(R) --vanilla --quiet < $$test || exit 1; \
$(RSCRIPT) --vanilla $$test || exit 1; \
done

clean:
Expand Down
Loading