use of com.oracle.truffle.llvm.runtime.types.Type 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.types.Type in project sulong by graalvm.
the class BasicNodeFactory method createInlineAssemblerExpression.
@Override
public LLVMExpressionNode createInlineAssemblerExpression(LLVMParserRuntime runtime, String asmExpression, String asmFlags, LLVMExpressionNode[] args, Type[] argTypes, Type retType, LLVMSourceLocation sourceSection) {
Type[] retTypes = null;
int[] retOffsets = null;
if (retType instanceof StructureType) {
// multiple out values
assert args[1] instanceof LLVMAllocaConstInstruction;
LLVMAllocaConstInstruction alloca = (LLVMAllocaConstInstruction) args[1];
retTypes = alloca.getTypes();
retOffsets = alloca.getOffsets();
}
Parser asmParser = new Parser(runtime.getLanguage(), sourceSection, asmExpression, asmFlags, argTypes, retType, retTypes, retOffsets);
LLVMInlineAssemblyRootNode assemblyRoot = asmParser.Parse();
LLVMFunctionDescriptor asm = LLVMFunctionDescriptor.createDescriptor(runtime.getContext(), runtime.getLibrary(), "<asm>", new FunctionType(MetaType.UNKNOWN, new Type[0], false), -1);
asm.declareInSulong(Truffle.getRuntime().createCallTarget(assemblyRoot), false);
LLVMFunctionLiteralNode asmFunction = LLVMFunctionLiteralNodeGen.create(asm);
return new LLVMCallNode(new FunctionType(MetaType.UNKNOWN, argTypes, false), asmFunction, args, sourceSection);
}
use of com.oracle.truffle.llvm.runtime.types.Type 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.Type 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);
}
use of com.oracle.truffle.llvm.runtime.types.Type in project sulong by graalvm.
the class LLVMBitcodeInstructionVisitor method convertToPhiWriteNodes.
private LLVMExpressionNode[] convertToPhiWriteNodes(ArrayList<Phi>[] phisPerSuccessor) {
if (phisPerSuccessor.length == 0) {
return LLVMExpressionNode.NO_EXPRESSIONS;
}
LLVMExpressionNode[] result = new LLVMExpressionNode[phisPerSuccessor.length];
for (int i = 0; i < result.length; i++) {
LLVMExpressionNode[] from = new LLVMExpressionNode[phisPerSuccessor[i].size()];
FrameSlot[] to = new FrameSlot[phisPerSuccessor[i].size()];
Type[] types = new Type[phisPerSuccessor[i].size()];
for (int j = 0; j < phisPerSuccessor[i].size(); j++) {
Phi phi = phisPerSuccessor[i].get(j);
to[j] = getSlot(phi.getPhiValue().getName());
from[j] = symbols.resolve(phi.getValue());
types[j] = phi.getValue().getType();
}
result[i] = nodeFactory.createPhi(runtime, from, to, types);
}
return result;
}
Aggregations