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);
}
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);
}
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;
}
}
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);
}
}
}
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);
}
Aggregations