Search in sources :

Example 11 with LLVMBasicBlockRef

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

the class LLVMHelperFunctions method buildIntToObjectFunction.

private LLVMValueRef buildIntToObjectFunction(boolean compressed) {
    String funcName = compressed ? INT_TO_COMPRESSED_OBJECT_FUNCTION_NAME : INT_TO_OBJECT_FUNCTION_NAME;
    LLVMValueRef func = builder.addFunction(funcName, builder.functionType(builder.objectType(compressed), builder.wordType()));
    LLVMIRBuilder.setLinkage(func, LinkageType.LinkOnce);
    builder.setFunctionAttribute(func, Attribute.AlwaysInline);
    builder.setFunctionAttribute(func, Attribute.GCLeafFunction);
    LLVMBasicBlockRef block = builder.appendBasicBlock(func, "main");
    builder.positionAtEnd(block);
    LLVMValueRef arg = LLVMIRBuilder.getParam(func, 0);
    LLVMValueRef ref = builder.buildLLVMIntToPtr(arg, builder.objectType(compressed));
    builder.buildRet(ref);
    return func;
}
Also used : LLVMBasicBlockRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMBasicBlockRef) LLVMValueRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMValueRef)

Example 12 with LLVMBasicBlockRef

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

the class LLVMHelperFunctions method buildLoadObjectFromUntrackedPointerFunction.

private LLVMValueRef buildLoadObjectFromUntrackedPointerFunction(boolean compressed) {
    String funcName = compressed ? LOAD_COMPRESSED_OBJECT_FROM_UNTRACKED_POINTER_FUNCTION_NAME : LOAD_OBJECT_FROM_UNTRACKED_POINTER_FUNCTION_NAME;
    LLVMValueRef func = builder.addFunction(funcName, builder.functionType(builder.objectType(compressed), builder.rawPointerType()));
    LLVMIRBuilder.setLinkage(func, LinkageType.LinkOnce);
    builder.setFunctionAttribute(func, Attribute.AlwaysInline);
    builder.setFunctionAttribute(func, Attribute.GCLeafFunction);
    LLVMBasicBlockRef block = builder.appendBasicBlock(func, "main");
    builder.positionAtEnd(block);
    LLVMValueRef address = LLVMIRBuilder.getParam(func, 0);
    LLVMValueRef castedAddress = builder.buildBitcast(address, builder.pointerType(builder.objectType(compressed), false, false));
    LLVMValueRef loadedValue = builder.buildLoad(castedAddress);
    builder.buildRet(loadedValue);
    return func;
}
Also used : LLVMBasicBlockRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMBasicBlockRef) LLVMValueRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMValueRef)

Example 13 with LLVMBasicBlockRef

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

the class LLVMHelperFunctions method buildObjectsCmpxchgFunction.

private LLVMValueRef buildObjectsCmpxchgFunction(boolean compressed, MemoryOrderMode memoryOrder, boolean returnsValue) {
    String funcName = compressed ? returnsValue ? COMPRESSED_OBJECTS_VALUE_CMPXCHG_FUNCTION_NAME : COMPRESSED_OBJECTS_LOGIC_CMPXCHG_FUNCTION_NAME : returnsValue ? OBJECTS_VALUE_CMPXCHG_FUNCTION_NAME : OBJECTS_LOGIC_CMPXCHG_FUNCTION_NAME;
    LLVMTypeRef exchangeType = builder.objectType(compressed);
    LLVMValueRef func = builder.addFunction(funcName, builder.functionType(returnsValue ? exchangeType : builder.booleanType(), builder.pointerType(exchangeType, true, false), exchangeType, exchangeType));
    LLVMIRBuilder.setLinkage(func, LinkageType.LinkOnce);
    builder.setFunctionAttribute(func, Attribute.AlwaysInline);
    builder.setFunctionAttribute(func, Attribute.GCLeafFunction);
    LLVMBasicBlockRef block = builder.appendBasicBlock(func, "main");
    builder.positionAtEnd(block);
    LLVMValueRef addr = LLVMIRBuilder.getParam(func, 0);
    LLVMValueRef expected = LLVMIRBuilder.getParam(func, 1);
    LLVMValueRef newVal = LLVMIRBuilder.getParam(func, 2);
    LLVMValueRef result = builder.buildAtomicCmpXchg(addr, expected, newVal, memoryOrder, returnsValue);
    builder.buildRet(result);
    return func;
}
Also used : LLVMBasicBlockRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMBasicBlockRef) LLVMValueRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMValueRef) LLVMTypeRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMTypeRef)

Example 14 with LLVMBasicBlockRef

use of com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMBasicBlockRef 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 15 with LLVMBasicBlockRef

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

the class LLVMGenerator method createJNITrampoline.

void createJNITrampoline(RegisterValue threadArg, int threadIsolateOffset, RegisterValue methodIdArg, int methodObjEntryPointOffset) {
    builder.setFunctionAttribute(Attribute.Naked);
    LLVMBasicBlockRef block = builder.appendBasicBlock("main");
    builder.positionAtEnd(block);
    long startPatchpointId = LLVMGenerator.nextPatchpointId.getAndIncrement();
    builder.buildStackmap(builder.constantLong(startPatchpointId));
    compilationResult.recordInfopoint(NumUtil.safeToInt(startPatchpointId), null, InfopointReason.METHOD_START);
    LLVMValueRef jumpAddressAddress;
    if (SubstrateOptions.SpawnIsolates.getValue()) {
        LLVMValueRef thread = buildInlineGetRegister(threadArg.getRegister().name);
        LLVMValueRef heapBaseAddress = builder.buildGEP(builder.buildIntToPtr(thread, builder.rawPointerType()), builder.constantInt(threadIsolateOffset));
        LLVMValueRef heapBase = builder.buildLoad(heapBaseAddress, builder.rawPointerType());
        LLVMValueRef methodId = buildInlineGetRegister(methodIdArg.getRegister().name);
        LLVMValueRef methodBase = builder.buildGEP(builder.buildIntToPtr(heapBase, builder.rawPointerType()), builder.buildPtrToInt(methodId));
        jumpAddressAddress = builder.buildGEP(methodBase, builder.constantInt(methodObjEntryPointOffset));
    } else {
        LLVMValueRef methodBase = buildInlineGetRegister(methodIdArg.getRegister().name);
        jumpAddressAddress = builder.buildGEP(builder.buildIntToPtr(methodBase, builder.rawPointerType()), builder.constantInt(methodObjEntryPointOffset));
    }
    LLVMValueRef jumpAddress = builder.buildLoad(jumpAddressAddress, builder.rawPointerType());
    buildInlineJump(jumpAddress);
    builder.buildUnreachable();
}
Also used : LLVMBasicBlockRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMBasicBlockRef) LLVMValueRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMValueRef)

Aggregations

LLVMBasicBlockRef (com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMBasicBlockRef)20 LLVMValueRef (com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMValueRef)17 Safepoint (com.oracle.svm.core.thread.Safepoint)4 LLVMTypeRef (com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMTypeRef)3 SpecialRegister (com.oracle.svm.core.graal.llvm.LLVMGenerator.SpecialRegister)2 InlineAssemblyConstraint (com.oracle.svm.core.graal.llvm.util.LLVMIRBuilder.InlineAssemblyConstraint)2 InvokeWithExceptionNode (org.graalvm.compiler.nodes.InvokeWithExceptionNode)2 ValuePhiNode (org.graalvm.compiler.nodes.ValuePhiNode)2 Block (org.graalvm.compiler.nodes.cfg.Block)2 ForeignCallNode (org.graalvm.compiler.nodes.extended.ForeignCallNode)2 ForeignCallWithExceptionNode (org.graalvm.compiler.nodes.extended.ForeignCallWithExceptionNode)2 TypeSwitchNode (org.graalvm.compiler.nodes.java.TypeSwitchNode)2 LLVMAddressValue (com.oracle.svm.core.graal.llvm.lowering.LLVMAddressLowering.LLVMAddressValue)1 LLVMIRBuilder (com.oracle.svm.core.graal.llvm.util.LLVMIRBuilder)1 LLVMPendingSpecialRegisterRead (com.oracle.svm.core.graal.llvm.util.LLVMUtils.LLVMPendingSpecialRegisterRead)1 CGlobalDataLoadAddressNode (com.oracle.svm.core.graal.nodes.CGlobalDataLoadAddressNode)1 SafepointCheckNode (com.oracle.svm.core.nodes.SafepointCheckNode)1 ArrayList (java.util.ArrayList)1 RegisterValue (jdk.vm.ci.code.RegisterValue)1 JavaConstant (jdk.vm.ci.meta.JavaConstant)1