use of com.oracle.truffle.llvm.runtime.types.PointerType in project sulong by graalvm.
the class LLVMBitcodeInstructionVisitor method visit.
@Override
public void visit(VoidCallInstruction call) {
// stackpointer
final int argumentCount = call.getArgumentCount() + 1;
final LLVMExpressionNode[] args = new LLVMExpressionNode[argumentCount];
final Type[] argsType = new Type[argumentCount];
int argIndex = 0;
args[argIndex] = nodeFactory.createFrameRead(runtime, PointerType.VOID, getStackSlot());
argsType[argIndex] = new PointerType(null);
argIndex++;
for (int i = 0; i < call.getArgumentCount(); i++) {
args[argIndex] = symbols.resolve(call.getArgument(i));
argsType[argIndex] = call.getArgument(i).getType();
final AttributesGroup paramAttr = call.getParameterAttributesGroup(i);
if (isByValue(paramAttr)) {
args[argIndex] = capsuleAddressByValue(args[argIndex], argsType[argIndex], paramAttr);
}
argIndex++;
}
final LLVMSourceLocation source = sourceFunction.getSourceLocation(call);
final SymbolImpl target = call.getCallTarget();
LLVMExpressionNode node = nodeFactory.createLLVMBuiltin(runtime, target, args, argCount, source);
if (node == null) {
if (target instanceof InlineAsmConstant) {
final InlineAsmConstant inlineAsmConstant = (InlineAsmConstant) target;
node = createInlineAssemblerNode(inlineAsmConstant, args, argsType, call.getType(), source);
} else {
final LLVMExpressionNode function = symbols.resolve(target);
final FunctionType functionType = new FunctionType(call.getType(), argsType, false);
node = nodeFactory.createFunctionCall(runtime, function, args, functionType, source);
}
}
addInstruction(node);
}
use of com.oracle.truffle.llvm.runtime.types.PointerType in project sulong by graalvm.
the class Function method createLoad.
private void createLoad(long[] args) {
int i = 0;
final int src = getIndex(args[i++]);
final Type srcType;
if (scope.isValueForwardRef(src)) {
srcType = types.get(args[i++]);
} else {
srcType = scope.getValueType(src);
}
final Type opType;
if (i + LOAD_ARGS_EXPECTED_AFTER_TYPE == args.length) {
opType = types.get(args[i++]);
} else {
opType = ((PointerType) srcType).getPointeeType();
}
final int align = getAlign(args[i++]);
final boolean isVolatile = args[i] != 0;
emit(LoadInstruction.fromSymbols(scope.getSymbols(), opType, src, align, isVolatile));
}
use of com.oracle.truffle.llvm.runtime.types.PointerType in project sulong by graalvm.
the class Function method createInvoke.
private void createInvoke(long[] args) {
int i = 0;
final AttributesCodeEntry paramAttr = paramAttributes.getCodeEntry(args[i++]);
final long ccInfo = args[i++];
final InstructionBlock normalSuccessor = function.getBlock(args[i++]);
final InstructionBlock unwindSuccessor = function.getBlock(args[i++]);
FunctionType functionType = null;
if (((ccInfo >> INVOKE_HASEXPLICITFUNCTIONTYPE_SHIFT) & 1) != 0) {
functionType = (FunctionType) types.get(args[i++]);
}
final int target = getIndex(args[i++]);
final Type calleeType;
if (scope.isValueForwardRef(target)) {
calleeType = types.get(args[i++]);
} else {
calleeType = scope.getValueType(target);
}
if (functionType == null) {
if (calleeType instanceof PointerType) {
functionType = (FunctionType) ((PointerType) calleeType).getPointeeType();
} else if (calleeType instanceof FunctionType) {
functionType = (FunctionType) calleeType;
} else {
throw new AssertionError("Cannot find Type of invoked function: " + calleeType.toString());
}
}
int[] arguments = new int[args.length - i];
int skipped = 0;
int j = 0;
while (j < functionType.getArgumentTypes().length && i < args.length) {
arguments[j++] = getIndex(args[i++]);
}
while (i < args.length) {
int index = getIndex(args[i++]);
arguments[j++] = index;
if (scope.isValueForwardRef(index)) {
i++;
skipped++;
}
}
if (skipped > 0) {
arguments = Arrays.copyOf(arguments, arguments.length - skipped);
}
final Type returnType = functionType.getReturnType();
if (returnType == VoidType.INSTANCE) {
emit(VoidInvokeInstruction.fromSymbols(scope, target, arguments, normalSuccessor, unwindSuccessor, paramAttr));
} else {
emit(InvokeInstruction.fromSymbols(scope, returnType, target, arguments, normalSuccessor, unwindSuccessor, paramAttr));
}
isLastBlockTerminated = true;
}
use of com.oracle.truffle.llvm.runtime.types.PointerType in project sulong by graalvm.
the class Function method createGetElementPointerOld.
private void createGetElementPointerOld(long[] args, boolean isInbounds) {
int i = 0;
int pointer = getIndex(args[i++]);
Type base;
if (scope.isValueForwardRef(pointer)) {
base = types.get(args[i++]);
} else {
base = scope.getValueType(pointer);
}
List<Integer> indices = getIndices(args, i);
Type type = new PointerType(getElementPointerType(base, indices));
emit(GetElementPointerInstruction.fromSymbols(scope.getSymbols(), type, pointer, indices, isInbounds));
}
use of com.oracle.truffle.llvm.runtime.types.PointerType in project sulong by graalvm.
the class Function method createAlloca.
private void createAlloca(long[] args) {
int i = 0;
final long typeRecord = args[i++];
// type of count
i++;
final int count = getIndexAbsolute(args[i++]);
final long alignRecord = args[i];
final int align = getAlign(alignRecord & ~ALLOCA_FLAGSMASK);
Type type = types.get(typeRecord);
if ((alignRecord & ALLOCA_EXPLICITTYPEMASK) != 0L) {
type = new PointerType(type);
} else if (!(type instanceof PointerType)) {
throw new AssertionError("Alloca must have PointerType!");
}
emit(AllocateInstruction.fromSymbols(scope.getSymbols(), type, count, align));
}
Aggregations