use of com.oracle.svm.core.graal.llvm.util.LLVMUtils.LLVMValueWrapper 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;
}
Aggregations