Search in sources :

Example 1 with Symbol

use of com.oracle.truffle.llvm.runtime.types.symbols.Symbol 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;
}
Also used : FunctionDeclaration(com.oracle.truffle.llvm.parser.model.functions.FunctionDeclaration) LLVMSymbol(com.oracle.truffle.llvm.runtime.LLVMSymbol) Symbol(com.oracle.truffle.llvm.runtime.types.symbols.Symbol) CastConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.CastConstant) LLVMIntrinsicProvider(com.oracle.truffle.llvm.runtime.LLVMIntrinsicProvider)

Aggregations

FunctionDeclaration (com.oracle.truffle.llvm.parser.model.functions.FunctionDeclaration)1 CastConstant (com.oracle.truffle.llvm.parser.model.symbols.constants.CastConstant)1 LLVMIntrinsicProvider (com.oracle.truffle.llvm.runtime.LLVMIntrinsicProvider)1 LLVMSymbol (com.oracle.truffle.llvm.runtime.LLVMSymbol)1 Symbol (com.oracle.truffle.llvm.runtime.types.symbols.Symbol)1