use of com.oracle.truffle.llvm.runtime.types.StructureType in project sulong by graalvm.
the class LLVMBitcodeInstructionVisitor method visit.
@Override
public void visit(ExtractValueInstruction extract) {
if (!(extract.getAggregate().getType() instanceof ArrayType || extract.getAggregate().getType() instanceof StructureType || extract.getAggregate().getType() instanceof PointerType)) {
throw new IllegalStateException("\'extractvalue\' can only extract elements of arrays and structs!");
}
final LLVMExpressionNode baseAddress = symbols.resolve(extract.getAggregate());
final Type baseType = extract.getAggregate().getType();
final int targetIndex = extract.getIndex();
final Type resultType = extract.getType();
LLVMExpressionNode targetAddress = baseAddress;
final AggregateType aggregateType = (AggregateType) baseType;
long offset = runtime.getContext().getIndexOffset(targetIndex, aggregateType);
final Type targetType = aggregateType.getElementType(targetIndex);
if (targetType != null && !((targetType instanceof StructureType) && (((StructureType) targetType).isPacked()))) {
offset += runtime.getContext().getBytePadding(offset, targetType);
}
if (offset != 0) {
final LLVMExpressionNode oneLiteralNode = nodeFactory.createLiteral(runtime, 1, PrimitiveType.I32);
targetAddress = nodeFactory.createTypedElementPointer(runtime, targetAddress, oneLiteralNode, offset, extract.getType());
}
final LLVMExpressionNode result = nodeFactory.createExtractValue(runtime, resultType, targetAddress);
createFrameWrite(result, extract);
}
use of com.oracle.truffle.llvm.runtime.types.StructureType in project sulong by graalvm.
the class LLVMBitcodeInstructionVisitor method visit.
@Override
public void visit(InsertValueInstruction insert) {
if (!(insert.getAggregate().getType() instanceof StructureType || insert.getAggregate().getType() instanceof ArrayType)) {
throw new IllegalStateException("\'insertvalue\' can only insert values into arrays and structs!");
}
final AggregateType sourceType = (AggregateType) insert.getAggregate().getType();
final LLVMExpressionNode sourceAggregate = symbols.resolve(insert.getAggregate());
final LLVMExpressionNode valueToInsert = symbols.resolve(insert.getValue());
final Type valueType = insert.getValue().getType();
final int targetIndex = insert.getIndex();
final LLVMExpressionNode resultAggregate = nodeFactory.createAlloca(runtime, sourceType);
final long offset = runtime.getContext().getIndexOffset(targetIndex, sourceType);
final LLVMExpressionNode result = nodeFactory.createInsertValue(runtime, resultAggregate, sourceAggregate, runtime.getContext().getByteSize(sourceType), offset, valueToInsert, valueType);
createFrameWrite(result, insert);
}
use of com.oracle.truffle.llvm.runtime.types.StructureType in project sulong by graalvm.
the class LLVMBitcodeInstructionVisitor method visit.
@Override
public void visit(CallInstruction call) {
final Type targetType = call.getType();
int argumentCount = getArgumentCount(call.getArgumentCount(), targetType);
final LLVMExpressionNode[] argNodes = new LLVMExpressionNode[argumentCount];
final Type[] argTypes = new Type[argumentCount];
int argIndex = 0;
// stack pointer
argNodes[argIndex] = nodeFactory.createFrameRead(runtime, PointerType.VOID, getStackSlot());
argTypes[argIndex] = new PointerType(null);
argIndex++;
if (targetType instanceof StructureType) {
argTypes[argIndex] = new PointerType(targetType);
argNodes[argIndex] = nodeFactory.createAlloca(runtime, targetType);
argIndex++;
}
for (int i = 0; argIndex < argumentCount; i++) {
argNodes[argIndex] = symbols.resolve(call.getArgument(i));
argTypes[argIndex] = call.getArgument(i).getType();
final AttributesGroup paramAttr = call.getParameterAttributesGroup(i);
if (isByValue(paramAttr)) {
argNodes[argIndex] = capsuleAddressByValue(argNodes[argIndex], argTypes[argIndex], paramAttr);
}
argIndex++;
}
final LLVMSourceLocation source = sourceFunction.getSourceLocation(call);
final SymbolImpl target = call.getCallTarget();
LLVMExpressionNode result = nodeFactory.createLLVMBuiltin(runtime, target, argNodes, argCount, source);
if (result == null) {
if (target instanceof InlineAsmConstant) {
final InlineAsmConstant inlineAsmConstant = (InlineAsmConstant) target;
result = createInlineAssemblerNode(inlineAsmConstant, argNodes, argTypes, targetType, source);
} else {
LLVMExpressionNode function = symbols.resolve(target);
result = nodeFactory.createFunctionCall(runtime, function, argNodes, new FunctionType(targetType, argTypes, false), source);
}
}
// the SourceSection references the call, not the return value assignment
createFrameWrite(result, call, null);
}
use of com.oracle.truffle.llvm.runtime.types.StructureType in project sulong by graalvm.
the class LLVMParserRuntime method createGlobalInitialization.
private LLVMExpressionNode createGlobalInitialization(LLVMSymbolReadResolver symbolResolver, GlobalValueSymbol global) {
if (global == null || global.getValue() == null) {
return null;
}
LLVMExpressionNode constant = symbolResolver.resolve(global.getValue());
if (constant != null) {
final Type type = ((PointerType) global.getType()).getPointeeType();
final int size = getContext().getByteSize(type);
final LLVMExpressionNode globalVarAddress = getGlobalVariable(symbolResolver, global);
if (size != 0) {
final LLVMExpressionNode store;
if (type instanceof ArrayType || type instanceof StructureType) {
store = nodeFactory.createStore(this, globalVarAddress, constant, type, null);
} else {
final Type t = global.getValue().getType();
store = nodeFactory.createStore(this, globalVarAddress, constant, t, null);
}
return store;
}
}
return null;
}
use of com.oracle.truffle.llvm.runtime.types.StructureType in project sulong by graalvm.
the class LazyToTruffleConverterImpl method copyArgumentsToFrame.
private List<LLVMExpressionNode> copyArgumentsToFrame(FrameDescriptor frame) {
List<FunctionParameter> parameters = method.getParameters();
List<LLVMExpressionNode> formalParamInits = new ArrayList<>();
LLVMExpressionNode stackPointerNode = nodeFactory.createFunctionArgNode(0, PrimitiveType.I64);
formalParamInits.add(nodeFactory.createFrameWrite(runtime, PointerType.VOID, stackPointerNode, frame.findFrameSlot(LLVMStack.FRAME_ID), null));
int argIndex = 1;
if (method.getType().getReturnType() instanceof StructureType) {
argIndex++;
}
for (FunctionParameter parameter : parameters) {
LLVMExpressionNode parameterNode = nodeFactory.createFunctionArgNode(argIndex++, parameter.getType());
FrameSlot slot = frame.findFrameSlot(parameter.getName());
if (isStructByValue(parameter)) {
Type type = ((PointerType) parameter.getType()).getPointeeType();
formalParamInits.add(nodeFactory.createFrameWrite(runtime, parameter.getType(), nodeFactory.createCopyStructByValue(runtime, type, parameterNode), slot, null));
} else {
formalParamInits.add(nodeFactory.createFrameWrite(runtime, parameter.getType(), parameterNode, slot, null));
}
}
return formalParamInits;
}
Aggregations