Skip to content
Snippets Groups Projects
Commit 3537ea42 authored by Mick Jordan's avatar Mick Jordan
Browse files

rffi: Truffle_LLVM fixes

parent c0a2be8a
Branches
No related tags found
No related merge requests found
...@@ -31,11 +31,11 @@ import com.oracle.truffle.r.runtime.rng.user.UserRNG; ...@@ -31,11 +31,11 @@ import com.oracle.truffle.r.runtime.rng.user.UserRNG;
* with {@code double *}. * with {@code double *}.
* *
* N.B. When {@code libR} is not completely in LLVM mode (as now), we have to look up the symbols * N.B. When {@code libR} is not completely in LLVM mode (as now), we have to look up the symbols
* using an explicitly created {@link TruffleLLVM_DLL.LLVM_Handle}and not go via generic lookup in * using an explicitly created {@link TruffleLLVM_DLL.LLVM_Handle} and not go via generic lookup in
* {@link DLL} as that would use a {@link JNI_DLL} handle. * {@link DLL} as that would use a {@link JNI_DLL} handle.
*/ */
public class TruffleLLVM_CAccess { public class TruffleLLVM_CAccess {
private static final TruffleLLVM_DLL.LLVM_Handle handle = new TruffleLLVM_DLL.LLVM_Handle("libR"); private static final TruffleLLVM_DLL.LLVM_Handle handle = new TruffleLLVM_DLL.LLVM_Handle("libR", null);
public enum Function { public enum Function {
READ_POINTER_INT, READ_POINTER_INT,
......
...@@ -40,6 +40,7 @@ import com.oracle.truffle.r.runtime.data.RNull; ...@@ -40,6 +40,7 @@ import com.oracle.truffle.r.runtime.data.RNull;
import com.oracle.truffle.r.runtime.ffi.CallRFFI; import com.oracle.truffle.r.runtime.ffi.CallRFFI;
import com.oracle.truffle.r.runtime.ffi.DLL.SymbolHandle; import com.oracle.truffle.r.runtime.ffi.DLL.SymbolHandle;
import com.oracle.truffle.r.runtime.ffi.NativeCallInfo; import com.oracle.truffle.r.runtime.ffi.NativeCallInfo;
import com.oracle.truffle.r.runtime.ffi.RFFIFactory;
import com.oracle.truffle.r.runtime.ffi.RFFIVariables; import com.oracle.truffle.r.runtime.ffi.RFFIVariables;
import com.oracle.truffle.r.runtime.ffi.jni.JNI_Call; import com.oracle.truffle.r.runtime.ffi.jni.JNI_Call;
import com.oracle.truffle.r.runtime.ffi.jni.JNI_Call.JNI_CallRFFINode; import com.oracle.truffle.r.runtime.ffi.jni.JNI_Call.JNI_CallRFFINode;
...@@ -55,7 +56,6 @@ class TruffleLLVM_Call implements CallRFFI { ...@@ -55,7 +56,6 @@ class TruffleLLVM_Call implements CallRFFI {
new JNI_Call(); new JNI_Call();
truffleCall = this; truffleCall = this;
truffleCallTruffleObject = JavaInterop.asTruffleObject(truffleCall); truffleCallTruffleObject = JavaInterop.asTruffleObject(truffleCall);
TruffleLLVM_PkgInit.initialize();
truffleCallHelper = TruffleLLVM_UpCallsRFFIImpl.initialize(); truffleCallHelper = TruffleLLVM_UpCallsRFFIImpl.initialize();
} }
...@@ -66,6 +66,7 @@ class TruffleLLVM_Call implements CallRFFI { ...@@ -66,6 +66,7 @@ class TruffleLLVM_Call implements CallRFFI {
@Override @Override
public ContextState initialize(RContext contextA) { public ContextState initialize(RContext contextA) {
this.context = contextA; this.context = contextA;
RFFIFactory.getRFFI().getCallRFFI();
context.addExportedSymbol("_fastr_rffi_call", truffleCallTruffleObject); context.addExportedSymbol("_fastr_rffi_call", truffleCallTruffleObject);
context.addExportedSymbol("_fastr_rffi_callhelper", truffleCallHelper); context.addExportedSymbol("_fastr_rffi_callhelper", truffleCallHelper);
return this; return this;
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
package com.oracle.truffle.r.engine.interop.ffi.llvm; package com.oracle.truffle.r.engine.interop.ffi.llvm;
import java.nio.file.FileSystems; import java.nio.file.FileSystems;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -35,6 +36,7 @@ import com.oracle.truffle.r.runtime.Utils; ...@@ -35,6 +36,7 @@ import com.oracle.truffle.r.runtime.Utils;
import com.oracle.truffle.r.runtime.context.RContext; import com.oracle.truffle.r.runtime.context.RContext;
import com.oracle.truffle.r.runtime.context.RContext.ContextState; import com.oracle.truffle.r.runtime.context.RContext.ContextState;
import com.oracle.truffle.r.runtime.ffi.DLL; import com.oracle.truffle.r.runtime.ffi.DLL;
import com.oracle.truffle.r.runtime.ffi.DLL.DLLInfo;
import com.oracle.truffle.r.runtime.ffi.DLL.SymbolHandle; import com.oracle.truffle.r.runtime.ffi.DLL.SymbolHandle;
import com.oracle.truffle.r.runtime.ffi.DLLRFFI; import com.oracle.truffle.r.runtime.ffi.DLLRFFI;
import com.oracle.truffle.r.runtime.ffi.NativeCallInfo; import com.oracle.truffle.r.runtime.ffi.NativeCallInfo;
...@@ -111,7 +113,7 @@ class TruffleLLVM_DLL extends JNI_DLL implements DLLRFFI { ...@@ -111,7 +113,7 @@ class TruffleLLVM_DLL extends JNI_DLL implements DLLRFFI {
} }
} }
class ContextStateImpl implements RContext.ContextState { static class ContextStateImpl implements RContext.ContextState {
/** /**
* A map from function name to its {@link ParseStatus}, allowing fast determination whether * A map from function name to its {@link ParseStatus}, allowing fast determination whether
* parsing is required in a call, see {@link #ensureParsed}. N.B. parsing happens at the * parsing is required in a call, see {@link #ensureParsed}. N.B. parsing happens at the
...@@ -128,9 +130,21 @@ class TruffleLLVM_DLL extends JNI_DLL implements DLLRFFI { ...@@ -128,9 +130,21 @@ class TruffleLLVM_DLL extends JNI_DLL implements DLLRFFI {
*/ */
@Override @Override
public ContextState initialize(RContext context) { public ContextState initialize(RContext context) {
for (LLVM_IR ir : libRModules) { for (LLVM_IR ir : truffleDLL.libRModules) {
addExportsToMap(this, "libR", ir, (name) -> name.endsWith("_llvm")); addExportsToMap(this, "libR", ir, (name) -> name.endsWith("_llvm"));
} }
if (context.getKind() == RContext.ContextKind.SHARE_PARENT_RW) {
// must propagate all LLVM library exports
ArrayList<DLLInfo> loadedDLLs = DLL.getLoadedDLLs();
for (DLLInfo dllInfo : loadedDLLs) {
if (dllInfo.handle instanceof LLVM_Handle) {
LLVM_Handle llvmHandle = (LLVM_Handle) dllInfo.handle;
for (LLVM_IR ir : llvmHandle.irs) {
addExportsToMap(this, llvmHandle.libName, ir, (name) -> true);
}
}
}
}
return this; return this;
} }
...@@ -150,7 +164,7 @@ class TruffleLLVM_DLL extends JNI_DLL implements DLLRFFI { ...@@ -150,7 +164,7 @@ class TruffleLLVM_DLL extends JNI_DLL implements DLLRFFI {
} }
static ContextStateImpl newContextState() { static ContextStateImpl newContextState() {
return truffleDLL.new ContextStateImpl(); return new ContextStateImpl();
} }
static boolean isBlacklisted(String libName) { static boolean isBlacklisted(String libName) {
...@@ -170,9 +184,11 @@ class TruffleLLVM_DLL extends JNI_DLL implements DLLRFFI { ...@@ -170,9 +184,11 @@ class TruffleLLVM_DLL extends JNI_DLL implements DLLRFFI {
static class LLVM_Handle { static class LLVM_Handle {
private final String libName; private final String libName;
private final LLVM_IR[] irs;
LLVM_Handle(String libName) { LLVM_Handle(String libName, LLVM_IR[] irs) {
this.libName = libName; this.libName = libName;
this.irs = irs;
} }
} }
...@@ -207,7 +223,7 @@ class TruffleLLVM_DLL extends JNI_DLL implements DLLRFFI { ...@@ -207,7 +223,7 @@ class TruffleLLVM_DLL extends JNI_DLL implements DLLRFFI {
LLVM_IR ir = irs[i]; LLVM_IR ir = irs[i];
addExportsToMap(contextState, libName, ir, (name) -> true); addExportsToMap(contextState, libName, ir, (name) -> true);
} }
return new LLVM_Handle(libName); return new LLVM_Handle(libName, irs);
} }
} catch (Exception ex) { } catch (Exception ex) {
return null; return null;
......
...@@ -45,6 +45,7 @@ class TruffleLLVM_PkgInit { ...@@ -45,6 +45,7 @@ class TruffleLLVM_PkgInit {
static class ContextStateImpl implements RContext.ContextState { static class ContextStateImpl implements RContext.ContextState {
@Override @Override
public ContextState initialize(RContext context) { public ContextState initialize(RContext context) {
TruffleLLVM_PkgInit.initialize();
context.addExportedSymbol("_fastr_rffi_pkginit", trufflePkgInitTruffleObject); context.addExportedSymbol("_fastr_rffi_pkginit", trufflePkgInitTruffleObject);
return this; return this;
} }
...@@ -58,7 +59,7 @@ class TruffleLLVM_PkgInit { ...@@ -58,7 +59,7 @@ class TruffleLLVM_PkgInit {
return new ContextStateImpl(); return new ContextStateImpl();
} }
static TruffleLLVM_PkgInit initialize() { private static TruffleLLVM_PkgInit initialize() {
if (trufflePkgInit == null) { if (trufflePkgInit == null) {
trufflePkgInit = new TruffleLLVM_PkgInit(); trufflePkgInit = new TruffleLLVM_PkgInit();
trufflePkgInitTruffleObject = JavaInterop.asTruffleObject(trufflePkgInit); trufflePkgInitTruffleObject = JavaInterop.asTruffleObject(trufflePkgInit);
......
...@@ -34,8 +34,10 @@ class TruffleLLVM_RFFIContextState implements ContextState { ...@@ -34,8 +34,10 @@ class TruffleLLVM_RFFIContextState implements ContextState {
TruffleLLVM_PkgInit.ContextStateImpl pkgInitState; TruffleLLVM_PkgInit.ContextStateImpl pkgInitState;
TruffleLLVM_Call.ContextStateImpl callState; TruffleLLVM_Call.ContextStateImpl callState;
TruffleLLVM_Stats.ContextStateImpl statsState; TruffleLLVM_Stats.ContextStateImpl statsState;
private final ContextState jniContextState;
TruffleLLVM_RFFIContextState() { TruffleLLVM_RFFIContextState(ContextState jniContextState) {
this.jniContextState = jniContextState;
dllState = TruffleLLVM_DLL.newContextState(); dllState = TruffleLLVM_DLL.newContextState();
pkgInitState = TruffleLLVM_PkgInit.newContextState(); pkgInitState = TruffleLLVM_PkgInit.newContextState();
callState = TruffleLLVM_Call.newContextState(); callState = TruffleLLVM_Call.newContextState();
...@@ -52,6 +54,7 @@ class TruffleLLVM_RFFIContextState implements ContextState { ...@@ -52,6 +54,7 @@ class TruffleLLVM_RFFIContextState implements ContextState {
@Override @Override
public ContextState initialize(RContext context) { public ContextState initialize(RContext context) {
jniContextState.initialize(context);
dllState.initialize(context); dllState.initialize(context);
pkgInitState.initialize(context); pkgInitState.initialize(context);
callState.initialize(context); callState.initialize(context);
......
...@@ -37,14 +37,9 @@ import com.oracle.truffle.r.runtime.ffi.jni.JNI_RFFIFactory; ...@@ -37,14 +37,9 @@ import com.oracle.truffle.r.runtime.ffi.jni.JNI_RFFIFactory;
*/ */
public class TruffleLLVM_RFFIFactory extends JNI_RFFIFactory implements RFFI { public class TruffleLLVM_RFFIFactory extends JNI_RFFIFactory implements RFFI {
@Override
protected void initialize(boolean runtime) {
super.initialize(runtime);
}
@Override @Override
public ContextState newContextState() { public ContextState newContextState() {
return new TruffleLLVM_RFFIContextState(); return new TruffleLLVM_RFFIContextState(super.newContextState());
} }
private CRFFI cRFFI; private CRFFI cRFFI;
......
...@@ -80,7 +80,7 @@ public enum RFFIVariables { ...@@ -80,7 +80,7 @@ public enum RFFIVariables {
R_BlankString(RDataFactory.createStringVectorFromScalar("")), R_BlankString(RDataFactory.createStringVectorFromScalar("")),
R_TrueValue(RRuntime.LOGICAL_TRUE), R_TrueValue(RRuntime.LOGICAL_TRUE),
R_FalseValue(RRuntime.LOGICAL_FALSE), R_FalseValue(RRuntime.LOGICAL_FALSE),
R_LogicalNAValue(RRuntime.LOGICAL_NA); // updated with setInteractive R_LogicalNAValue(RRuntime.LOGICAL_NA);
private Object value; private Object value;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment