use of com.oracle.truffle.llvm.runtime.types.Type in project sulong by graalvm.
the class LLVMBitcodeInstructionVisitor method capsuleAddressByValue.
private LLVMExpressionNode capsuleAddressByValue(LLVMExpressionNode child, Type type, AttributesGroup paramAttr) {
final Type pointee = ((PointerType) type).getPointeeType();
final int size = runtime.getContext().getByteSize(pointee);
int alignment = runtime.getContext().getByteAlignment(pointee);
for (Attribute attr : paramAttr.getAttributes()) {
if (attr instanceof Attribute.KnownIntegerValueAttribute && ((Attribute.KnownIntegerValueAttribute) attr).getAttr() == Attribute.Kind.ALIGN) {
alignment = ((Attribute.KnownIntegerValueAttribute) attr).getValue();
}
}
return nodeFactory.createVarArgCompoundValue(runtime, size, alignment, child);
}
use of com.oracle.truffle.llvm.runtime.types.Type in project sulong by graalvm.
the class LLVMBitcodeInstructionVisitor method visit.
@Override
public void visit(ShuffleVectorInstruction shuffle) {
final LLVMExpressionNode vector1 = symbols.resolve(shuffle.getVector1());
final LLVMExpressionNode vector2 = symbols.resolve(shuffle.getVector2());
final LLVMExpressionNode mask = symbols.resolve(shuffle.getMask());
final Type type = shuffle.getType();
final LLVMExpressionNode result = nodeFactory.createShuffleVector(runtime, type, vector1, vector2, mask);
createFrameWrite(result, shuffle);
}
use of com.oracle.truffle.llvm.runtime.types.Type 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.Type in project sulong by graalvm.
the class LLVMBitcodeInstructionVisitor method visit.
@Override
public void visit(BinaryOperationInstruction operation) {
LLVMExpressionNode lhs = symbols.resolve(operation.getLHS());
LLVMExpressionNode rhs = symbols.resolve(operation.getRHS());
final Type type = operation.getType();
final LLVMArithmeticInstructionType opA = LLVMBitcodeTypeHelper.toArithmeticInstructionType(operation.getOperator());
if (opA != null) {
final LLVMExpressionNode result = nodeFactory.createArithmeticOperation(runtime, lhs, rhs, opA, type, operation.getFlags());
createFrameWrite(result, operation);
return;
}
final LLVMLogicalInstructionKind opL = LLVMBitcodeTypeHelper.toLogicalInstructionType(operation.getOperator());
if (opL != null) {
final LLVMExpressionNode result = nodeFactory.createLogicalOperation(runtime, lhs, rhs, opL, type, operation.getFlags());
createFrameWrite(result, operation);
return;
}
throw new RuntimeException("Missed a binary operator");
}
use of com.oracle.truffle.llvm.runtime.types.Type in project sulong by graalvm.
the class LLVMBitcodeInstructionVisitor method visit.
@Override
public void visit(AllocateInstruction allocate) {
final Type type = allocate.getPointeeType();
int alignment;
if (allocate.getAlign() == 0) {
alignment = runtime.getContext().getByteAlignment(type);
} else {
alignment = 1 << (allocate.getAlign() - 1);
}
if (alignment == 0) {
alignment = LLVMStack.NO_ALIGNMENT_REQUIREMENTS;
}
final SymbolImpl count = allocate.getCount();
final LLVMExpressionNode result;
if (count instanceof NullConstant) {
result = nodeFactory.createAlloca(runtime, type, alignment);
} else if (count instanceof IntegerConstant) {
long numElements = (int) ((IntegerConstant) count).getValue();
if (numElements == 1) {
result = nodeFactory.createAlloca(runtime, type, alignment);
} else {
assert numElements == (int) numElements;
ArrayType arrayType = new ArrayType(type, (int) numElements);
result = nodeFactory.createAlloca(runtime, arrayType, alignment);
}
} else {
LLVMExpressionNode num = symbols.resolve(count);
result = nodeFactory.createAllocaArray(runtime, type, num, alignment);
}
// we never want to step on allocations, only to actual assignments in the source
createFrameWrite(result, allocate, null);
}
Aggregations