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