use of com.oracle.truffle.llvm.runtime.except.LLVMParserException in project graal by oracle.
the class ParserDriver method verifyBitcodeSource.
private void verifyBitcodeSource(Source source, DataLayout targetDataLayout, TargetTriple targetTriple) {
if (targetDataLayout.getByteOrder() != ByteOrder.LITTLE_ENDIAN) {
throw new LLVMParserException("Byte order " + targetDataLayout.getByteOrder() + " of file " + source.getPath() + " is not supported");
}
boolean verifyBitcode = context.getEnv().getOptions().get(SulongEngineOption.VERIFY_BITCODE);
TargetTriple defaultTargetTriple = language.getDefaultTargetTriple();
if (defaultTargetTriple == null && !context.isInternalLibraryPath(Paths.get(source.getPath()))) {
// some internal libraries (libsulong++) might be loaded before libsulong
throw new IllegalStateException("No default target triple.");
}
if (defaultTargetTriple != null && targetTriple != null && !defaultTargetTriple.matches(targetTriple)) {
TruffleLogger logger = TruffleLogger.getLogger(LLVMLanguage.ID, "BitcodeVerifier");
String exceptionMessage = "Mismatching target triple (expected " + defaultTargetTriple + ", got " + targetTriple + ')';
logger.severe(exceptionMessage);
logger.severe("Source " + source.getPath());
logger.severe("See https://www.graalvm.org/reference-manual/llvm/Compiling/ for more details");
logger.severe("To silence this message, set --log." + logger.getName() + ".level=OFF");
if (verifyBitcode) {
logger.severe("To make this error non-fatal, set --" + SulongEngineOption.VERIFY_BITCODE_NAME + "=false");
throw new LLVMParserException(exceptionMessage);
}
}
}
use of com.oracle.truffle.llvm.runtime.except.LLVMParserException in project graal by oracle.
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 TypeArrayBuilder argTypes = new TypeArrayBuilder(argumentCount);
int argIndex = 0;
// stack pointer
argNodes[argIndex] = nodeFactory.createGetStackFromFrame();
argTypes.set(argIndex, new PointerType(null));
argIndex++;
if (targetType instanceof StructureType) {
argTypes.set(argIndex, new PointerType(targetType));
argNodes[argIndex] = nodeFactory.createGetUniqueStackSpace(targetType, uniquesRegion);
argIndex++;
}
// realArgumentCount = argumentCount - varArgCount
int realArgumentCount = call.getCallTarget().getType() instanceof FunctionType ? ((FunctionType) call.getCallTarget().getType()).getNumberOfArguments() : argumentCount;
final SymbolImpl target = call.getCallTarget();
for (int i = call.getArgumentCount() - 1; i >= 0; i--) {
argNodes[argIndex + i] = resolveOptimized(call.getArgument(i), i, target, call.getArguments());
argTypes.set(argIndex + i, call.getArgument(i).getType());
boolean isVarArg = i >= realArgumentCount;
final AttributesGroup paramAttr = call.getParameterAttributesGroup(i);
if (isByValue(paramAttr)) {
argNodes[argIndex + i] = capsuleAddressByValue(argNodes[argIndex + i], argTypes.get(argIndex + i), paramAttr);
} else if (isVarArg && isArrayByValue(argTypes.get(argIndex + i), argNodes[argIndex + i])) {
argNodes[argIndex + i] = capsuleArrayByValue(argNodes[argIndex + i], argTypes.get(argIndex + i));
}
}
LLVMExpressionNode result = nodeFactory.createLLVMBuiltin(target, argNodes, argTypes, argCount);
if (call.getOperandBundle() != null && !(result instanceof LLVMAssume)) {
throw new LLVMParserException("Unsupported operand bundle on call of " + target.toString());
}
SourceInstrumentationStrategy intent = SourceInstrumentationStrategy.ONLY_FIRST_STATEMENT_ON_LOCATION;
if (result == null) {
if (target instanceof InlineAsmConstant) {
final InlineAsmConstant inlineAsmConstant = (InlineAsmConstant) target;
result = createInlineAssemblerNode(inlineAsmConstant, argNodes, argTypes, targetType);
} else {
LLVMExpressionNode function = symbols.resolve(target);
result = CommonNodeFactory.createFunctionCall(function, argNodes, new FunctionType(targetType, argTypes, false));
// the callNode needs to be instrumentable so that the debugger can see the CallTag.
// If it did not provide a source location, the debugger may not be able to show the
// node on the call stack or offer stepping into the call.
intent = SourceInstrumentationStrategy.FORCED;
}
}
// the SourceSection references the call, not the return value assignment
createFrameWrite(result, call, intent);
}
use of com.oracle.truffle.llvm.runtime.except.LLVMParserException in project graal by oracle.
the class CommonNodeFactory method createNestedElementPointerNode.
public static LLVMExpressionNode createNestedElementPointerNode(NodeFactory nodeFactory, DataLayout dataLayout, LLVMExpressionNode[] indexNodes, Long[] indexConstants, Type[] indexTypes, LLVMExpressionNode curAddress, Type curType) {
try {
ElementPointerFactory factory = new ElementPointerFactory(nodeFactory, curAddress, curType);
for (int i = 0; i < indexNodes.length; i++) {
Type indexType = indexTypes[i];
Long indexInteger = indexConstants[i];
if (indexInteger == null) {
// the index is determined at runtime
if (factory.currentType instanceof StructureType) {
// according to http://llvm.org/docs/LangRef.html#getelementptr-instruction
throw new LLVMParserException("Indices on structs must be constant integers!");
}
AggregateType aggregate = (AggregateType) factory.currentType;
long indexedTypeLength = aggregate.getOffsetOf(1, dataLayout);
factory.currentType = aggregate.getElementType(1);
factory.addIndex(indexedTypeLength, indexNodes[i], indexType);
} else {
// the index is a constant integer
AggregateType aggregate = (AggregateType) factory.currentType;
long addressOffset = aggregate.getOffsetOf(indexInteger, dataLayout);
factory.currentType = aggregate.getElementType(indexInteger);
// address computed by getelementptr even if it is the same as the basepointer
if (addressOffset != 0 || i == indexNodes.length - 1) {
LLVMExpressionNode indexNode;
if (indexType == PrimitiveType.I32) {
indexNode = CommonNodeFactory.createLiteral(1, PrimitiveType.I32);
} else if (indexType == PrimitiveType.I64) {
indexNode = CommonNodeFactory.createLiteral(1L, PrimitiveType.I64);
} else {
throw new AssertionError(indexType);
}
factory.addIndex(addressOffset, indexNode, indexType);
}
}
}
return factory.currentAddress;
} catch (TypeOverflowException e) {
return Type.handleOverflowExpression(e);
}
}
use of com.oracle.truffle.llvm.runtime.except.LLVMParserException in project graal by oracle.
the class BasicNodeFactory method getCompareOp.
private static CompareOperator getCompareOp(LLVMExpressionNode expr) {
LLVMMetaLiteralNode meta = (LLVMMetaLiteralNode) expr;
String op = (String) meta.getMetadata();
switch(op) {
case "oeq":
return CompareOperator.FP_ORDERED_EQUAL;
case "ogt":
return CompareOperator.FP_ORDERED_GREATER_THAN;
case "oge":
return CompareOperator.FP_ORDERED_GREATER_OR_EQUAL;
case "olt":
return CompareOperator.FP_ORDERED_LESS_THAN;
case "ole":
return CompareOperator.FP_ORDERED_LESS_OR_EQUAL;
case "one":
return CompareOperator.FP_ORDERED_NOT_EQUAL;
case "ord":
return CompareOperator.FP_ORDERED;
case "ueq":
return CompareOperator.FP_UNORDERED_EQUAL;
case "ugt":
return CompareOperator.FP_UNORDERED_GREATER_THAN;
case "uge":
return CompareOperator.FP_UNORDERED_GREATER_OR_EQUAL;
case "ult":
return CompareOperator.FP_UNORDERED_LESS_THAN;
case "ule":
return CompareOperator.FP_UNORDERED_LESS_OR_EQUAL;
case "une":
return CompareOperator.FP_UNORDERED_NOT_EQUAL;
case "uno":
return CompareOperator.FP_UNORDERED;
default:
throw new LLVMParserException("unsupported fp compare op: " + op);
}
}
use of com.oracle.truffle.llvm.runtime.except.LLVMParserException in project graal by oracle.
the class ParameterAttributes method decodeGroupCodeEntry.
private void decodeGroupCodeEntry(RecordBuffer buffer) {
final long groupId = buffer.read();
final long paramIdx = buffer.read();
AttributesGroup group = new AttributesGroup(groupId, paramIdx);
attributes.add(group);
while (buffer.remaining() > 0) {
int type = buffer.readInt();
switch(type) {
case WELL_KNOWN_ATTRIBUTE_KIND:
{
Attribute.Kind attr = Attribute.Kind.decode(buffer.read());
group.addAttribute(new Attribute.KnownAttribute(attr));
break;
}
case WELL_KNOWN_INTEGER_ATTRIBUTE_KIND:
{
Attribute.Kind attr = Attribute.Kind.decode(buffer.read());
group.addAttribute(new Attribute.KnownIntegerValueAttribute(attr, buffer.read()));
break;
}
case STRING_ATTRIBUTE_KIND:
{
String strAttr = readString(buffer);
group.addAttribute(new Attribute.StringAttribute(strAttr));
break;
}
case STRING_VALUE_ATTRIBUTE_KIND:
{
String strAttr = readString(buffer);
String strVal = readString(buffer);
group.addAttribute(new Attribute.StringValueAttribute(strAttr, strVal));
break;
}
case BYVAL_ATTRIBUTE_KIND:
{
Attribute.Kind attr = Attribute.Kind.decode(buffer.read());
if (attr == Attribute.Kind.BYVAL) {
group.addAttribute(new Attribute.KnownAttribute(Attribute.Kind.BYVAL));
}
break;
}
case TYPED_BYVAL_ATTRIBUTE_KIND:
{
Attribute.Kind attr = Attribute.Kind.decode(buffer.read());
if (attr == Attribute.Kind.BYVAL) {
final Type valueType = types.get(buffer.read());
group.addAttribute(new Attribute.KnownTypedAttribute(Attribute.Kind.BYVAL, valueType));
} else if (attr == Attribute.Kind.SRET) {
final Type retType = types.get(buffer.read());
group.addAttribute(new Attribute.KnownTypedAttribute(Attribute.Kind.SRET, retType));
}
break;
}
default:
throw new LLVMParserException("Unexpected code of attribute group: " + type);
}
}
}
Aggregations