Search in sources :

Example 6 with LLVMValueRef

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

the class LLVMGenerator method buildInlineJump.

/* Inline assembly */
private void buildInlineJump(LLVMValueRef address) {
    LLVMTypeRef inlineAsmType = builder.functionType(builder.voidType(), builder.rawPointerType());
    String asmSnippet = LLVMTargetSpecific.get().getJumpInlineAsm();
    InlineAssemblyConstraint inputConstraint = new InlineAssemblyConstraint(Type.Input, Location.register());
    LLVMValueRef jump = builder.buildInlineAsm(inlineAsmType, asmSnippet, true, false, inputConstraint);
    LLVMValueRef call = builder.buildCall(jump, address);
    builder.setCallSiteAttribute(call, Attribute.GCLeafFunction);
}
Also used : LLVMValueRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMValueRef) InlineAssemblyConstraint(com.oracle.svm.core.graal.llvm.util.LLVMIRBuilder.InlineAssemblyConstraint) LLVMTypeRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMTypeRef)

Example 7 with LLVMValueRef

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

the class LLVMGenerator method emitConditionalMove.

@Override
public Variable emitConditionalMove(PlatformKind cmpKind, Value leftVal, Value rightVal, Condition cond, boolean unorderedIsTrue, Value trueVal, Value falseVal) {
    LLVMValueRef condition = builder.buildCompare(cond, getVal(leftVal), getVal(rightVal), unorderedIsTrue);
    LLVMValueRef select;
    LLVMValueRef trueValue = getVal(trueVal);
    LLVMValueRef falseValue = getVal(falseVal);
    if (LLVMVersionChecker.useExplicitSelects() && LLVMIRBuilder.isObjectType(typeOf(trueValue))) {
        select = buildExplicitSelect(condition, trueValue, falseValue);
    } else {
        select = builder.buildSelect(condition, trueValue, falseValue);
    }
    return new LLVMVariable(select);
}
Also used : LLVMVariable(com.oracle.svm.core.graal.llvm.util.LLVMUtils.LLVMVariable) LLVMValueRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMValueRef)

Example 8 with LLVMValueRef

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

the class LLVMGenerator method buildCmpxchg.

private LLVMValueRef buildCmpxchg(LLVMValueRef address, LLVMValueRef expectedValue, LLVMValueRef newValue, MemoryOrderMode memoryOrder, boolean returnValue) {
    LLVMTypeRef expectedType = LLVMIRBuilder.typeOf(expectedValue);
    LLVMTypeRef newType = LLVMIRBuilder.typeOf(newValue);
    assert LLVMIRBuilder.compatibleTypes(expectedType, newType) : dumpValues("invalid cmpxchg arguments", expectedValue, newValue);
    boolean trackedAddress = LLVMIRBuilder.isObjectType(typeOf(address));
    LLVMValueRef castedAddress;
    if (!trackedAddress && LLVMIRBuilder.isObjectType(expectedType)) {
        castedAddress = builder.buildAddrSpaceCast(address, builder.pointerType(expectedType, true, false));
    } else {
        castedAddress = builder.buildBitcast(address, builder.pointerType(expectedType, trackedAddress, false));
    }
    boolean convertResult = LLVMIRBuilder.isFloatType(expectedType) || LLVMIRBuilder.isDoubleType(expectedType);
    LLVMValueRef castedExpectedValue = expectedValue;
    LLVMValueRef castedNewValue = newValue;
    if (convertResult) {
        LLVMTypeRef cmpxchgType = LLVMIRBuilder.isFloatType(expectedType) ? builder.intType() : builder.longType();
        castedExpectedValue = builder.buildFPToSI(expectedValue, cmpxchgType);
        castedNewValue = builder.buildFPToSI(newValue, cmpxchgType);
    }
    LLVMValueRef result = builder.buildCmpxchg(castedAddress, castedExpectedValue, castedNewValue, memoryOrder, returnValue);
    if (returnValue && convertResult) {
        return builder.buildSIToFP(result, expectedType);
    } else {
        return result;
    }
}
Also used : LLVMValueRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMValueRef) LLVMTypeRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMTypeRef)

Example 9 with LLVMValueRef

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

the class LLVMGenerator method emitReturn.

@Override
public void emitReturn(JavaKind javaKind, Value input) {
    if (javaKind == JavaKind.Void) {
        debugInfoPrinter.printRetVoid();
        if (isEntryPoint) {
            builder.buildRetVoid();
        } else {
            LLVMTypeRef[] retTypes = new LLVMTypeRef[SpecialRegister.count()];
            LLVMValueRef[] retValues = new LLVMValueRef[SpecialRegister.count()];
            for (SpecialRegister reg : SpecialRegister.registers()) {
                retTypes[reg.index] = builder.wordType();
                retValues[reg.index] = getSpecialRegisterValue(reg);
            }
            LLVMValueRef retStruct = builder.constantNull(builder.structType(retTypes));
            for (int i = 0; i < retValues.length; ++i) {
                retStruct = builder.buildInsertValue(retStruct, i, retValues[i]);
            }
            builder.buildRet(retStruct);
        }
    } else {
        debugInfoPrinter.printRet(javaKind, input);
        LLVMValueRef retVal = getVal(input);
        if (javaKind == JavaKind.Int) {
            assert LLVMIRBuilder.isIntegerType(typeOf(retVal));
            retVal = arithmetic.emitIntegerConvert(retVal, builder.intType());
        } else if (returnsEnum && javaKind == FrameAccess.getWordKind()) {
            /*
                 * An enum value is represented by a long in the function body, but is returned as
                 * an object (CEnum values are returned as an int)
                 */
            LLVMValueRef result;
            if (returnsCEnum) {
                result = builder.buildTrunc(retVal, JavaKind.Int.getBitCount());
            } else {
                result = builder.buildIntToPtr(retVal, builder.objectType(false));
            }
            retVal = result;
        }
        if (isEntryPoint) {
            builder.buildRet(retVal);
        } else {
            LLVMTypeRef[] retTypes = new LLVMTypeRef[SpecialRegister.count() + 1];
            LLVMValueRef[] retValues = new LLVMValueRef[SpecialRegister.count() + 1];
            for (SpecialRegister reg : SpecialRegister.registers()) {
                retTypes[reg.index] = builder.wordType();
                retValues[reg.index] = getSpecialRegisterValue(reg);
            }
            retTypes[SpecialRegister.count()] = LLVMIRBuilder.typeOf(retVal);
            retValues[SpecialRegister.count()] = retVal;
            LLVMValueRef retStruct = builder.constantNull(builder.structType(retTypes));
            for (int i = 0; i < retValues.length; ++i) {
                retStruct = builder.buildInsertValue(retStruct, i, retValues[i]);
            }
            builder.buildRet(retStruct);
        }
    }
}
Also used : 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 10 with LLVMValueRef

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

the class NodeLLVMBuilder method emitIf.

/* Control flow nodes */
@Override
public void emitIf(IfNode i) {
    LLVMValueRef condition = emitCondition(i.condition());
    LLVMBasicBlockRef thenBlock = gen.getBlock(i.trueSuccessor());
    LLVMBasicBlockRef elseBlock = gen.getBlock(i.falseSuccessor());
    LLVMValueRef instr = builder.buildIf(condition, thenBlock, elseBlock);
    int trueProbability = expandProbability(i.getTrueSuccessorProbability());
    int falseProbability = expandProbability(1 - i.getTrueSuccessorProbability());
    LLVMValueRef branchWeights = builder.branchWeights(builder.constantInt(trueProbability), builder.constantInt(falseProbability));
    builder.setMetadata(instr, "prof", branchWeights);
}
Also used : LLVMBasicBlockRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMBasicBlockRef) LLVMValueRef(com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMValueRef) Safepoint(com.oracle.svm.core.thread.Safepoint)

Aggregations

LLVMValueRef (com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMValueRef)51 LLVMBasicBlockRef (com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMBasicBlockRef)17 LLVMTypeRef (com.oracle.svm.shadowed.org.bytedeco.llvm.LLVM.LLVMTypeRef)14 LLVMVariable (com.oracle.svm.core.graal.llvm.util.LLVMUtils.LLVMVariable)9 InlineAssemblyConstraint (com.oracle.svm.core.graal.llvm.util.LLVMIRBuilder.InlineAssemblyConstraint)7 Safepoint (com.oracle.svm.core.thread.Safepoint)4 SpecialRegister (com.oracle.svm.core.graal.llvm.LLVMGenerator.SpecialRegister)3 SubstrateCallingConventionType (com.oracle.svm.core.graal.code.SubstrateCallingConventionType)2 LLVMKind (com.oracle.svm.core.graal.llvm.util.LLVMUtils.LLVMKind)2 LLVMPendingSpecialRegisterRead (com.oracle.svm.core.graal.llvm.util.LLVMUtils.LLVMPendingSpecialRegisterRead)2 SafepointCheckNode (com.oracle.svm.core.nodes.SafepointCheckNode)2 DebugInfo (jdk.vm.ci.code.DebugInfo)2 RegisterValue (jdk.vm.ci.code.RegisterValue)2 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)2 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 Value (jdk.vm.ci.meta.Value)2 DirectCallTargetNode (org.graalvm.compiler.nodes.DirectCallTargetNode)2 IndirectCallTargetNode (org.graalvm.compiler.nodes.IndirectCallTargetNode)2 InvokeWithExceptionNode (org.graalvm.compiler.nodes.InvokeWithExceptionNode)2 LogicConstantNode (org.graalvm.compiler.nodes.LogicConstantNode)2