Search in sources :

Example 16 with LLVMTypeRef

use of com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMTypeRef in project graal by oracle.

the class LLVMUtils method dumpTypes.

public static String dumpTypes(String prefix, LLVMTypeRef... types) {
    StringBuilder builder = new StringBuilder(prefix);
    for (LLVMTypeRef type : types) {
        builder.append(" ");
        builder.append(LLVM.LLVMPrintTypeToString(type).getString());
    }
    return builder.toString();
}
Also used : LLVMTypeRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMTypeRef)

Example 17 with LLVMTypeRef

use of com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMTypeRef in project graal by oracle.

the class LLVMGenerator method getLLVMFunctionArgTypes.

private LLVMTypeRef[] getLLVMFunctionArgTypes(ResolvedJavaMethod method, boolean forMainFunction) {
    ResolvedJavaType receiver = method.hasReceiver() ? method.getDeclaringClass() : null;
    JavaType[] javaParameterTypes = method.getSignature().toParameterTypes(receiver);
    LLVMTypeRef[] parameterTypes = Arrays.stream(javaParameterTypes).map(type -> getLLVMStackType(getTypeKind(type.resolve(null), forMainFunction))).toArray(LLVMTypeRef[]::new);
    LLVMTypeRef[] newParameterTypes = parameterTypes;
    if (!isEntryPoint(method) && SpecialRegister.count() > 0) {
        newParameterTypes = new LLVMTypeRef[SpecialRegister.count() + parameterTypes.length];
        for (SpecialRegister reg : SpecialRegister.registers()) {
            newParameterTypes[reg.index] = builder.wordType();
        }
        System.arraycopy(parameterTypes, 0, newParameterTypes, SpecialRegister.count(), parameterTypes.length);
    }
    return newParameterTypes;
}
Also used : SubstrateCallingConvention(com.oracle.svm.core.graal.code.SubstrateCallingConvention) Arrays(java.util.Arrays) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) GuardedAnnotationAccess(org.graalvm.util.GuardedAnnotationAccess) SubstrateOptions(com.oracle.svm.core.SubstrateOptions) ReflectionUtil(com.oracle.svm.util.ReflectionUtil) LIRGenerationResult(org.graalvm.compiler.lir.gen.LIRGenerationResult) CEntryPointData(com.oracle.svm.hosted.code.CEntryPointData) LinkageType(com.oracle.svm.core.graal.llvm.util.LLVMIRBuilder.LinkageType) LLVMKind(com.oracle.svm.core.graal.llvm.util.LLVMUtils.LLVMKind) CodeGenProviders(org.graalvm.compiler.core.common.spi.CodeGenProviders) Map(java.util.Map) LLVMUtils.dumpValues(com.oracle.svm.core.graal.llvm.util.LLVMUtils.dumpValues) LLVMIRBuilder.isFloatType(com.oracle.svm.core.graal.llvm.util.LLVMIRBuilder.isFloatType) LLVMIRBuilder.isVectorType(com.oracle.svm.core.graal.llvm.util.LLVMIRBuilder.isVectorType) LIRKindTool(org.graalvm.compiler.core.common.spi.LIRKindTool) WriteHeapBaseNode(com.oracle.svm.core.graal.nodes.WriteHeapBaseNode) LLVMUtils.getVal(com.oracle.svm.core.graal.llvm.util.LLVMUtils.getVal) SubstrateLIRGenerator(com.oracle.svm.core.graal.code.SubstrateLIRGenerator) MemoryOrderMode(org.graalvm.compiler.core.common.memory.MemoryOrderMode) Stamp(org.graalvm.compiler.core.common.type.Stamp) LLVMStackSlot(com.oracle.svm.core.graal.llvm.util.LLVMUtils.LLVMStackSlot) WriteCurrentVMThreadNode(com.oracle.svm.core.graal.nodes.WriteCurrentVMThreadNode) TargetDescription(jdk.vm.ci.code.TargetDescription) PlatformKind(jdk.vm.ci.meta.PlatformKind) JavaType(jdk.vm.ci.meta.JavaType) CompressEncoding(org.graalvm.compiler.core.common.CompressEncoding) SnippetRuntime(com.oracle.svm.core.snippets.SnippetRuntime) CodeCacheProvider(jdk.vm.ci.code.CodeCacheProvider) LLVMIRBuilder.isDoubleType(com.oracle.svm.core.graal.llvm.util.LLVMIRBuilder.isDoubleType) CEnum(org.graalvm.nativeimage.c.constant.CEnum) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) AbstractBlockBase(org.graalvm.compiler.core.common.cfg.AbstractBlockBase) LIRFrameState(org.graalvm.compiler.lir.LIRFrameState) LLVMVariable(com.oracle.svm.core.graal.llvm.util.LLVMUtils.LLVMVariable) LLVMTypeRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMTypeRef) GCStrategy(com.oracle.svm.core.graal.llvm.util.LLVMIRBuilder.GCStrategy) ReferenceAccess(com.oracle.svm.core.heap.ReferenceAccess) Register(jdk.vm.ci.code.Register) ArrayList(java.util.ArrayList) SubstrateCallingConventionType(com.oracle.svm.core.graal.code.SubstrateCallingConventionType) LLVMBasicBlockRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMBasicBlockRef) GraalError.shouldNotReachHere(org.graalvm.compiler.debug.GraalError.shouldNotReachHere) CompilationResult(org.graalvm.compiler.code.CompilationResult) MemoryBarriers(jdk.vm.ci.code.MemoryBarriers) VirtualStackSlot(org.graalvm.compiler.lir.VirtualStackSlot) SubstrateDataBuilder(com.oracle.svm.core.graal.code.SubstrateDataBuilder) FloatConvert(org.graalvm.compiler.core.common.calc.FloatConvert) Attribute(com.oracle.svm.core.graal.llvm.util.LLVMIRBuilder.Attribute) AtomicLong(java.util.concurrent.atomic.AtomicLong) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) DataSectionReference(jdk.vm.ci.code.site.DataSectionReference) Block(org.graalvm.compiler.nodes.cfg.Block) FrameAccess(com.oracle.svm.core.FrameAccess) CallingConvention(jdk.vm.ci.code.CallingConvention) LLVMStackMapInfo(com.oracle.svm.core.graal.llvm.util.LLVMStackMapInfo) Providers(org.graalvm.compiler.phases.util.Providers) LLVMUtils.dumpTypes(com.oracle.svm.core.graal.llvm.util.LLVMUtils.dumpTypes) LLVMTargetSpecific(com.oracle.svm.core.graal.llvm.util.LLVMTargetSpecific) Constant(jdk.vm.ci.meta.Constant) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions) BiFunction(java.util.function.BiFunction) IllegalStamp(org.graalvm.compiler.core.common.type.IllegalStamp) LIRInstruction(org.graalvm.compiler.lir.LIRInstruction) LLVMVersionChecker(com.oracle.svm.core.graal.llvm.LLVMFeature.LLVMVersionChecker) InlineAssemblyConstraint(com.oracle.svm.core.graal.llvm.util.LLVMIRBuilder.InlineAssemblyConstraint) LabelRef(org.graalvm.compiler.lir.LabelRef) StampFactory(org.graalvm.compiler.core.common.type.StampFactory) JavaKind(jdk.vm.ci.meta.JavaKind) LLVMUtils(com.oracle.svm.core.graal.llvm.util.LLVMUtils) ForeignCallsProvider(org.graalvm.compiler.core.common.spi.ForeignCallsProvider) DebugInfo(jdk.vm.ci.code.DebugInfo) RawPointerStamp(org.graalvm.compiler.core.common.type.RawPointerStamp) Location(com.oracle.svm.core.graal.llvm.util.LLVMIRBuilder.InlineAssemblyConstraint.Location) SubstrateRegisterConfig(com.oracle.svm.core.graal.meta.SubstrateRegisterConfig) NumUtil(org.graalvm.compiler.core.common.NumUtil) LLVMExceptionUnwind(com.oracle.svm.core.graal.llvm.runtime.LLVMExceptionUnwind) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) ForeignCallLinkage(org.graalvm.compiler.core.common.spi.ForeignCallLinkage) Type(com.oracle.svm.core.graal.llvm.util.LLVMIRBuilder.InlineAssemblyConstraint.Type) LLVMUtils.getType(com.oracle.svm.core.graal.llvm.util.LLVMUtils.getType) VMError(com.oracle.svm.core.util.VMError) JavaConstant(jdk.vm.ci.meta.JavaConstant) ValueNode(org.graalvm.compiler.nodes.ValueNode) List(java.util.List) GraalError.unimplemented(org.graalvm.compiler.debug.GraalError.unimplemented) Value(jdk.vm.ci.meta.Value) GraalError(org.graalvm.compiler.debug.GraalError) StackSlot(jdk.vm.ci.code.StackSlot) ArithmeticLIRGeneratorTool(org.graalvm.compiler.lir.gen.ArithmeticLIRGeneratorTool) ValueKind(jdk.vm.ci.meta.ValueKind) LLVMValueWrapper(com.oracle.svm.core.graal.llvm.util.LLVMUtils.LLVMValueWrapper) LLVMIRBuilder(com.oracle.svm.core.graal.llvm.util.LLVMIRBuilder) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) NarrowOopStamp(org.graalvm.compiler.nodes.type.NarrowOopStamp) LLVMIntrinsicGenerator(com.oracle.svm.core.graal.llvm.replacements.LLVMIntrinsicGenerator) HashMap(java.util.HashMap) SubstrateObjectConstant(com.oracle.svm.core.meta.SubstrateObjectConstant) LLVMConstant(com.oracle.svm.core.graal.llvm.util.LLVMUtils.LLVMConstant) LLVMIRBuilder.typeOf(com.oracle.svm.core.graal.llvm.util.LLVMIRBuilder.typeOf) ReservedRegisters(com.oracle.svm.core.ReservedRegisters) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) HostedType(com.oracle.svm.hosted.meta.HostedType) Condition(org.graalvm.compiler.core.common.calc.Condition) Variable(org.graalvm.compiler.lir.Variable) MoveFactory(org.graalvm.compiler.lir.gen.MoveFactory) LIRKind(org.graalvm.compiler.core.common.LIRKind) SubstrateUtil(com.oracle.svm.core.SubstrateUtil) LLVMValueRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMValueRef) RegisterValue(jdk.vm.ci.code.RegisterValue) LLVMIRBuilder.isIntegerType(com.oracle.svm.core.graal.llvm.util.LLVMIRBuilder.isIntegerType) InfopointReason(jdk.vm.ci.code.site.InfopointReason) JavaVersionUtil(org.graalvm.compiler.serviceprovider.JavaVersionUtil) Node(org.graalvm.compiler.graph.Node) LIRGeneratorTool(org.graalvm.compiler.lir.gen.LIRGeneratorTool) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) LLVMPendingSpecialRegisterRead(com.oracle.svm.core.graal.llvm.util.LLVMUtils.LLVMPendingSpecialRegisterRead) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) LLVMTypeRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMTypeRef) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 18 with LLVMTypeRef

use of com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMTypeRef in project graal by oracle.

the class LLVMGenerator method createJNIWrapper.

/*
     * Calling a native function from Java code requires filling the JavaFrameAnchor with the return
     * address of the call. This wrapper allows this by creating an intermediary call frame from
     * which the return address can be accessed. The parameters to this wrapper are the anchor, the
     * native callee, and the arguments to the callee.
     */
LLVMValueRef createJNIWrapper(LLVMValueRef callee, boolean nativeABI, int numArgs, int anchorIPOffset) {
    LLVMTypeRef calleeType = LLVMIRBuilder.getElementType(LLVMIRBuilder.typeOf(callee));
    String wrapperName = JNI_WRAPPER_BASE_NAME + LLVMIRBuilder.intrinsicType(calleeType) + (nativeABI ? "_native" : "");
    LLVMValueRef transitionWrapper = builder.getNamedFunction(wrapperName);
    if (transitionWrapper == null) {
        try (LLVMIRBuilder tempBuilder = new LLVMIRBuilder(builder)) {
            LLVMTypeRef wrapperType = prependArgumentTypes(calleeType, nativeABI ? 0 : SpecialRegister.count(), tempBuilder.rawPointerType(), LLVMIRBuilder.typeOf(callee));
            transitionWrapper = tempBuilder.addFunction(wrapperName, wrapperType);
            LLVMIRBuilder.setLinkage(transitionWrapper, LinkageType.LinkOnce);
            tempBuilder.setGarbageCollector(transitionWrapper, GCStrategy.CompressedPointers);
            tempBuilder.setFunctionAttribute(transitionWrapper, Attribute.NoInline);
            LLVMBasicBlockRef block = tempBuilder.appendBasicBlock(transitionWrapper, "main");
            tempBuilder.positionAtEnd(block);
            LLVMValueRef anchor = LLVMIRBuilder.getParam(transitionWrapper, 0 + (nativeABI ? 0 : SpecialRegister.count()));
            LLVMValueRef lastIPAddr = tempBuilder.buildGEP(anchor, tempBuilder.constantInt(anchorIPOffset));
            LLVMValueRef callIP = tempBuilder.buildReturnAddress(tempBuilder.constantInt(0));
            LLVMValueRef castedLastIPAddr = tempBuilder.buildBitcast(lastIPAddr, tempBuilder.pointerType(tempBuilder.rawPointerType()));
            tempBuilder.buildStore(callIP, castedLastIPAddr);
            LLVMValueRef[] args = new LLVMValueRef[numArgs];
            for (int i = 0; i < numArgs; ++i) {
                if (!nativeABI && i < SpecialRegister.count()) {
                    args[i] = LLVMIRBuilder.getParam(transitionWrapper, i);
                } else {
                    args[i] = LLVMIRBuilder.getParam(transitionWrapper, i + 2);
                }
            }
            LLVMValueRef target = LLVMIRBuilder.getParam(transitionWrapper, 1 + (nativeABI ? 0 : SpecialRegister.count()));
            LLVMValueRef ret = tempBuilder.buildCall(target, args);
            tempBuilder.setCallSiteAttribute(ret, Attribute.GCLeafFunction);
            if (LLVMIRBuilder.isVoidType(LLVMIRBuilder.getReturnType(calleeType))) {
                tempBuilder.buildRetVoid();
            } else {
                tempBuilder.buildRet(ret);
            }
        }
    }
    return transitionWrapper;
}
Also used : LLVMBasicBlockRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMBasicBlockRef) LLVMIRBuilder(com.oracle.svm.core.graal.llvm.util.LLVMIRBuilder) LLVMValueRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMValueRef) LLVMTypeRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMTypeRef) InlineAssemblyConstraint(com.oracle.svm.core.graal.llvm.util.LLVMIRBuilder.InlineAssemblyConstraint)

Example 19 with LLVMTypeRef

use of com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMTypeRef in project graal by oracle.

the class NodeLLVMBuilder method setResult.

@Override
public Value setResult(ValueNode node, Value operand) {
    LLVMValueWrapper llvmOperand;
    boolean typeOverride = false;
    if (operand instanceof LLVMValueWrapper) {
        llvmOperand = (LLVMValueWrapper) operand;
    } else if (operand instanceof ConstantValue) {
        /* This only happens when emitting null or illegal object constants */
        PlatformKind kind = operand.getPlatformKind();
        if (kind instanceof LLVMKind) {
            llvmOperand = new LLVMVariable(builder.constantNull(((LLVMKind) kind).get()));
        } else {
            assert kind == ValueKind.Illegal.getPlatformKind();
            llvmOperand = new LLVMVariable(builder.getUndef());
        }
    } else if (operand instanceof LLVMAddressValue) {
        LLVMAddressValue addressValue = (LLVMAddressValue) operand;
        Value wrappedBase = addressValue.getBase();
        Value index = addressValue.getIndex();
        if (wrappedBase instanceof LLVMPendingSpecialRegisterRead) {
            LLVMPendingSpecialRegisterRead pendingRead = (LLVMPendingSpecialRegisterRead) wrappedBase;
            if (index != null && index != Value.ILLEGAL) {
                pendingRead = new LLVMPendingSpecialRegisterRead(pendingRead, LLVMUtils.getVal(addressValue.getIndex()));
            }
            llvmOperand = pendingRead;
        } else {
            LLVMValueRef base = LLVMUtils.getVal(wrappedBase);
            LLVMTypeRef baseType = LLVMIRBuilder.typeOf(base);
            if (LLVMIRBuilder.isWordType(baseType)) {
                base = builder.buildIntToPtr(base, builder.rawPointerType());
            } else if (LLVMIRBuilder.isObjectType(baseType)) {
                typeOverride = true;
            } else {
                throw shouldNotReachHere(LLVMUtils.dumpValues("unsupported base for address", base));
            }
            LLVMValueRef intermediate;
            if (index == null || index == Value.ILLEGAL) {
                intermediate = base;
            } else {
                intermediate = builder.buildGEP(base, LLVMUtils.getVal(index));
            }
            llvmOperand = new LLVMVariable(intermediate);
        }
    } else if (operand instanceof RegisterValue) {
        RegisterValue registerValue = (RegisterValue) operand;
        llvmOperand = (LLVMValueWrapper) gen.emitReadRegister(registerValue.getRegister(), registerValue.getValueKind());
    } else {
        throw shouldNotReachHere("unknown operand: " + operand.toString());
    }
    assert typeOverride || LLVMIRBuilder.compatibleTypes(getLLVMType(node), LLVMIRBuilder.typeOf(llvmOperand.get())) : LLVMUtils.dumpValues("value type doesn't match node stamp (" + node.stamp(NodeView.DEFAULT).toString() + ")", llvmOperand.get());
    gen.getDebugInfoPrinter().setValueName(llvmOperand, node);
    valueMap.put(node, llvmOperand);
    return operand;
}
Also used : LLVMVariable(com.oracle.svm.core.graal.llvm.util.LLVMUtils.LLVMVariable) RegisterValue(jdk.vm.ci.code.RegisterValue) LLVMAddressValue(com.oracle.svm.core.graal.llvm.lowering.LLVMAddressLowering.LLVMAddressValue) LLVMPendingSpecialRegisterRead(com.oracle.svm.core.graal.llvm.util.LLVMUtils.LLVMPendingSpecialRegisterRead) LLVMValueWrapper(com.oracle.svm.core.graal.llvm.util.LLVMUtils.LLVMValueWrapper) ConstantValue(org.graalvm.compiler.lir.ConstantValue) LLVMAddressValue(com.oracle.svm.core.graal.llvm.lowering.LLVMAddressLowering.LLVMAddressValue) Value(jdk.vm.ci.meta.Value) RegisterValue(jdk.vm.ci.code.RegisterValue) LLVMValueRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMValueRef) PlatformKind(jdk.vm.ci.meta.PlatformKind) LLVMTypeRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMTypeRef) ConstantValue(org.graalvm.compiler.lir.ConstantValue) LLVMKind(com.oracle.svm.core.graal.llvm.util.LLVMUtils.LLVMKind)

Example 20 with LLVMTypeRef

use of com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMTypeRef in project graal by oracle.

the class LLVMGenerator method emitMove.

@Override
public void emitMove(AllocatableValue dst, Value src) {
    LLVMValueRef source = getVal(src);
    LLVMTypeRef sourceType = typeOf(source);
    LLVMTypeRef destType = ((LLVMKind) dst.getPlatformKind()).get();
    /* Floating word cast */
    if (LLVMIRBuilder.isObjectType(destType) && LLVMIRBuilder.isWordType(sourceType)) {
        source = builder.buildIntToPtr(source, destType);
    } else if (LLVMIRBuilder.isWordType(destType) && LLVMIRBuilder.isObjectType(sourceType)) {
        source = builder.buildPtrToInt(source);
    }
    ((LLVMVariable) dst).set(source);
}
Also used : LLVMVariable(com.oracle.svm.core.graal.llvm.util.LLVMUtils.LLVMVariable) LLVMValueRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMValueRef) LLVMTypeRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMTypeRef) LLVMKind(com.oracle.svm.core.graal.llvm.util.LLVMUtils.LLVMKind)

Aggregations

LLVMTypeRef (com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMTypeRef)25 LLVMValueRef (com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMValueRef)15 InlineAssemblyConstraint (com.oracle.svm.core.graal.llvm.util.LLVMIRBuilder.InlineAssemblyConstraint)5 LLVMBasicBlockRef (com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMBasicBlockRef)4 LLVMKind (com.oracle.svm.core.graal.llvm.util.LLVMUtils.LLVMKind)3 LLVMPendingSpecialRegisterRead (com.oracle.svm.core.graal.llvm.util.LLVMUtils.LLVMPendingSpecialRegisterRead)3 LLVMVariable (com.oracle.svm.core.graal.llvm.util.LLVMUtils.LLVMVariable)3 RegisterValue (jdk.vm.ci.code.RegisterValue)3 Value (jdk.vm.ci.meta.Value)3 ValueNode (org.graalvm.compiler.nodes.ValueNode)3 SpecialRegister (com.oracle.svm.core.graal.llvm.LLVMGenerator.SpecialRegister)2 LLVMIRBuilder (com.oracle.svm.core.graal.llvm.util.LLVMIRBuilder)2 LLVMValueWrapper (com.oracle.svm.core.graal.llvm.util.LLVMUtils.LLVMValueWrapper)2 DebugInfo (jdk.vm.ci.code.DebugInfo)2 PlatformKind (jdk.vm.ci.meta.PlatformKind)2 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 LIRFrameState (org.graalvm.compiler.lir.LIRFrameState)2 FrameAccess (com.oracle.svm.core.FrameAccess)1 ReservedRegisters (com.oracle.svm.core.ReservedRegisters)1 SubstrateOptions (com.oracle.svm.core.SubstrateOptions)1