use of com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode in project sulong by graalvm.
the class BasicNodeFactory method createStructureConstantNode.
@Override
public LLVMExpressionNode createStructureConstantNode(LLVMParserRuntime runtime, Type structType, boolean packed, Type[] types, LLVMExpressionNode[] constants) {
int[] offsets = new int[types.length];
LLVMStoreNode[] nodes = new LLVMStoreNode[types.length];
int currentOffset = 0;
LLVMExpressionNode alloc = createAlloca(runtime, structType);
for (int i = 0; i < types.length; i++) {
Type resolvedType = types[i];
if (!packed) {
currentOffset += runtime.getContext().getBytePadding(currentOffset, resolvedType);
}
offsets[i] = currentOffset;
int byteSize = runtime.getContext().getByteSize(resolvedType);
nodes[i] = createMemoryStore(runtime, resolvedType);
currentOffset += byteSize;
}
return StructLiteralNodeGen.create(offsets, nodes, constants, alloc);
}
use of com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode in project sulong by graalvm.
the class BasicNodeFactory method createArrayLiteral.
@Override
public LLVMExpressionNode createArrayLiteral(LLVMParserRuntime runtime, List<LLVMExpressionNode> arrayValues, ArrayType arrayType) {
assert arrayType.getNumberOfElements() == arrayValues.size();
LLVMExpressionNode arrayAlloc = createAlloca(runtime, arrayType);
int nrElements = arrayValues.size();
Type elementType = arrayType.getElementType();
int elementSize = runtime.getContext().getByteSize(elementType);
if (elementSize == 0) {
throw new AssertionError(elementType + " has size of 0!");
}
if (elementType instanceof PrimitiveType) {
switch(((PrimitiveType) elementType).getPrimitiveKind()) {
case I8:
return LLVMI8ArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
case I16:
return LLVMI16ArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
case I32:
return LLVMI32ArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
case I64:
return LLVMI64ArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
case FLOAT:
return LLVMFloatArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
case DOUBLE:
return LLVMDoubleArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
case X86_FP80:
return LLVM80BitFloatArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
default:
throw new AssertionError(elementType);
}
} else if (Type.isFunctionOrFunctionPointer(elementType)) {
return LLVMFunctionArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
} else if (elementType instanceof PointerType) {
return LLVMAddressArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
} else if (elementType instanceof ArrayType || elementType instanceof StructureType) {
return LLVMStructArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), createMemMove(), elementSize, arrayAlloc);
}
throw new AssertionError(elementType);
}
use of com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode in project sulong by graalvm.
the class LLVMBitcodeFunctionVisitor method visit.
@Override
public void visit(InstructionBlock block) {
List<Phi> blockPhis = phis.get(block);
ArrayList<LLVMLivenessAnalysis.NullerInformation> blockNullerInfos = liveness.getNullableWithinBlock()[block.getBlockIndex()];
LLVMBitcodeInstructionVisitor visitor = new LLVMBitcodeInstructionVisitor(frame, blockPhis, nodeFactory, argCount, symbols, runtime, blockNullerInfos, function.getSourceFunction(), notNullable, dbgInfoHandler);
if (initDebugValues) {
for (SourceVariable variable : function.getSourceFunction().getVariables()) {
final LLVMExpressionNode initNode = dbgInfoHandler.createInitializer(variable);
if (initNode != null) {
visitor.addInstructionUnchecked(initNode);
}
}
initDebugValues = false;
}
for (int i = 0; i < block.getInstructionCount(); i++) {
Instruction instruction = block.getInstruction(i);
visitor.setInstructionIndex(i);
instruction.accept(visitor);
}
blocks.add(nodeFactory.createBasicBlockNode(runtime, visitor.getInstructions(), visitor.getControlFlowNode(), block.getBlockIndex(), block.getName()));
}
use of com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode 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.nodes.api.LLVMExpressionNode in project sulong by graalvm.
the class LLVMBitcodeInstructionVisitor method visit.
@Override
public void visit(CompareExchangeInstruction cmpxchg) {
final LLVMExpressionNode ptrNode = symbols.resolve(cmpxchg.getPtr());
final LLVMExpressionNode cmpNode = symbols.resolve(cmpxchg.getCmp());
final LLVMExpressionNode newNode = symbols.resolve(cmpxchg.getReplace());
final Type elementType = cmpxchg.getCmp().getType();
createFrameWrite(nodeFactory.createCompareExchangeInstruction(runtime, cmpxchg.getType(), elementType, ptrNode, cmpNode, newNode), cmpxchg);
}
Aggregations