use of com.oracle.truffle.llvm.runtime.LLVMIntrinsicProvider in project graal by oracle.
the class InitializeExternalNode method execute.
/*
* (PLi): Need to be careful of native functions/globals that are not in the nfi context (i.e.
* __xstat). Ideally they will be added to the symbol table as unresolved/undefined
* functions/globals.
*/
public void execute(LLVMContext context, LLVMScopeChain localScope, LLVMDLOpen.RTLDFlags rtldFlags) {
LLVMScopeChain globalScope = context.getGlobalScopeChain();
LLVMIntrinsicProvider intrinsicProvider = getLanguage().getCapability(LLVMIntrinsicProvider.class);
NativeContextExtension nativeContextExtension = getNativeContextExtension(context);
for (int i = 0; i < globals.length; i++) {
LLVMGlobal global = globals[i];
LLVMPointer pointer = allocExternalSymbol.execute(localScope, globalScope, intrinsicProvider, nativeContextExtension, context, rtldFlags, global);
if (pointer == null) {
continue;
}
context.initializeSymbol(globals[i], pointer);
}
for (int i = 0; i < functions.length; i++) {
LLVMFunction function = functions[i];
LLVMPointer pointer = allocExternalSymbol.execute(localScope, globalScope, intrinsicProvider, nativeContextExtension, context, rtldFlags, function);
if (pointer == null) {
continue;
}
context.initializeSymbol(functions[i], pointer);
}
}
use of com.oracle.truffle.llvm.runtime.LLVMIntrinsicProvider in project graal by oracle.
the class BasicNodeFactory method createLLVMBuiltin.
@Override
public LLVMExpressionNode createLLVMBuiltin(Symbol target, LLVMExpressionNode[] args, Type.TypeArrayBuilder argsTypes, int callerArgumentCount) {
Symbol actualTarget = target;
if (actualTarget instanceof CastConstant && ((CastConstant) actualTarget).getValue() instanceof FunctionDeclaration) {
/*
* This branch solves the following scenario, in which a builtin is bitcast before its
* invocation:
*
* %1 = call i32 bitcast (i32 (...)* @polyglot_get_arg_count to i32 ()*)() #2, !dbg !18
*
* Otherwise the builtin would be handled as a normal function.
*/
actualTarget = ((CastConstant) actualTarget).getValue();
}
if (actualTarget instanceof FunctionDeclaration) {
FunctionDeclaration declaration = (FunctionDeclaration) actualTarget;
String name = declaration.getName();
/*
* These "llvm." builtins are *not* function intrinsics. Builtins replace statements
* that look like function calls but are actually LLVM intrinsics. An example is
* llvm.stackpointer. Also, it is not possible to retrieve the functionpointer of such
* pseudo-call-targets.
*
* These builtins shall not be used for regular function intrinsification!
*/
if (name.startsWith("llvm.experimental.constrained.")) {
return getConstrainedFPBuiltin(declaration, args);
} else if (name.startsWith("llvm.")) {
return getLLVMBuiltin(declaration, args, callerArgumentCount);
} else if (name.startsWith("__builtin_")) {
return getGccBuiltin(declaration, args);
} else if (name.equals("polyglot_get_arg")) {
// it must therefore not be hidden behind a call target
return LLVMTruffleGetArgNodeGen.create(args[1]);
} else if (name.equals("polyglot_get_arg_count")) {
// it must therefore not be hidden behind a call target
return LLVMTruffleGetArgCountNodeGen.create();
} else {
// Inline Sulong intrinsics directly at their call site, to avoid the overhead of a
// call node and extra argument nodes.
LLVMIntrinsicProvider intrinsicProvider = language.getCapability(LLVMIntrinsicProvider.class);
if (intrinsicProvider.isIntrinsified(name)) {
/*
* Note that getRawTypeArray has a side effect, so we can't rely on the implicit
* null return of generateIntrinsicNode if the function is not intrinsified.
*/
return intrinsicProvider.generateIntrinsicNode(name, args, Type.getRawTypeArray(argsTypes), this);
}
}
}
return null;
}
Aggregations