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