Search in sources :

Example 1 with CastConstant

use of com.oracle.truffle.llvm.parser.model.symbols.constants.CastConstant in project graal by oracle.

the class LLVMParser method defineAlias.

private void defineAlias(String aliasName, boolean isAliasExported, SymbolImpl value, DataLayout targetDataLayout) {
    if (value instanceof FunctionSymbol) {
        FunctionSymbol function = (FunctionSymbol) value;
        defineAlias(function.getName(), aliasName, isAliasExported);
    } else if (value instanceof GlobalVariable) {
        GlobalVariable global = (GlobalVariable) value;
        defineAlias(global.getName(), aliasName, isAliasExported);
    } else if (value instanceof GlobalAlias) {
        GlobalAlias target = (GlobalAlias) value;
        defineAlias(target, targetDataLayout);
        defineAlias(target.getName(), aliasName, isAliasExported);
    } else if (value instanceof CastConstant) {
        // TODO (chaeubl): this is not perfectly accurate as we are loosing the type cast
        CastConstant cast = (CastConstant) value;
        defineAlias(aliasName, isAliasExported, cast.getValue(), targetDataLayout);
    } else if (value instanceof GetElementPointerConstant) {
        GetElementPointerConstant elementPointerConstant = (GetElementPointerConstant) value;
        defineExpressionSymbol(aliasName, isAliasExported, elementPointerConstant, targetDataLayout);
    } else {
        throw new LLVMLinkerException("Unknown alias type: " + value.getClass());
    }
}
Also used : GlobalVariable(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalVariable) FunctionSymbol(com.oracle.truffle.llvm.parser.model.functions.FunctionSymbol) GetElementPointerConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.GetElementPointerConstant) GlobalAlias(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalAlias) CastConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.CastConstant) LLVMLinkerException(com.oracle.truffle.llvm.runtime.except.LLVMLinkerException)

Example 2 with CastConstant

use of com.oracle.truffle.llvm.parser.model.symbols.constants.CastConstant 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

CastConstant (com.oracle.truffle.llvm.parser.model.symbols.constants.CastConstant)2 FunctionDeclaration (com.oracle.truffle.llvm.parser.model.functions.FunctionDeclaration)1 FunctionSymbol (com.oracle.truffle.llvm.parser.model.functions.FunctionSymbol)1 GetElementPointerConstant (com.oracle.truffle.llvm.parser.model.symbols.constants.GetElementPointerConstant)1 GlobalAlias (com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalAlias)1 GlobalVariable (com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalVariable)1 LLVMIntrinsicProvider (com.oracle.truffle.llvm.runtime.LLVMIntrinsicProvider)1 LLVMSymbol (com.oracle.truffle.llvm.runtime.LLVMSymbol)1 LLVMLinkerException (com.oracle.truffle.llvm.runtime.except.LLVMLinkerException)1 Symbol (com.oracle.truffle.llvm.runtime.types.symbols.Symbol)1