use of com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup in project sulong by graalvm.
the class FunctionDefinition method createParameter.
public FunctionParameter createParameter(Type t) {
final AttributesGroup attrGroup = paramAttr.getParameterAttributesGroup(parameters.size());
final FunctionParameter parameter = new FunctionParameter(t, attrGroup);
parameters.add(parameter);
return parameter;
}
use of com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup in project sulong by graalvm.
the class LLVMBitcodeInstructionVisitor method visit.
@Override
public void visit(InvokeInstruction 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;
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++, argIndex++) {
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);
}
}
final SymbolImpl target = call.getCallTarget();
int regularIndex = call.normalSuccessor().getBlockIndex();
int unwindIndex = call.unwindSuccessor().getBlockIndex();
List<FrameSlot> normalTo = new ArrayList<>();
List<FrameSlot> unwindTo = new ArrayList<>();
List<Type> normalType = new ArrayList<>();
List<Type> unwindType = new ArrayList<>();
List<LLVMExpressionNode> normalValue = new ArrayList<>();
List<LLVMExpressionNode> unwindValue = new ArrayList<>();
if (blockPhis != null) {
for (Phi phi : blockPhis) {
FrameSlot slot = getSlot(phi.getPhiValue().getName());
LLVMExpressionNode value = symbols.resolve(phi.getValue());
if (call.normalSuccessor() == phi.getBlock()) {
normalTo.add(slot);
normalType.add(phi.getValue().getType());
normalValue.add(value);
} else {
unwindTo.add(slot);
unwindType.add(phi.getValue().getType());
unwindValue.add(value);
}
}
}
LLVMExpressionNode normalPhi = nodeFactory.createPhi(runtime, normalValue.toArray(new LLVMExpressionNode[normalValue.size()]), normalTo.toArray(new FrameSlot[normalTo.size()]), normalType.toArray(Type.EMPTY_ARRAY));
LLVMExpressionNode unwindPhi = nodeFactory.createPhi(runtime, unwindValue.toArray(new LLVMExpressionNode[unwindValue.size()]), unwindTo.toArray(new FrameSlot[unwindTo.size()]), unwindType.toArray(Type.EMPTY_ARRAY));
final LLVMSourceLocation source = sourceFunction.getSourceLocation(call);
LLVMExpressionNode function = nodeFactory.createLLVMBuiltin(runtime, target, argNodes, argCount, null);
if (function == null) {
function = symbols.resolve(target);
}
LLVMControlFlowNode result = nodeFactory.createFunctionInvoke(runtime, getSlot(call.getName()), function, argNodes, new FunctionType(targetType, argTypes, false), regularIndex, unwindIndex, normalPhi, unwindPhi, source);
setControlFlowNode(result);
}
use of com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup 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.parser.model.attributes.AttributesGroup in project sulong by graalvm.
the class ParameterAttributes method decodeGroupCodeEntry.
private void decodeGroupCodeEntry(long[] args) {
int i = 0;
final long groupId = args[i++];
final long paramIdx = args[i++];
AttributesGroup group = new AttributesGroup(groupId, paramIdx);
attributes.add(group);
while (i < args.length) {
long type = args[i++];
switch((int) type) {
case WELL_KNOWN_ATTRIBUTE_KIND:
{
Attribute.Kind attr = Attribute.Kind.decode(args[i++]);
group.addAttribute(new Attribute.KnownAttribute(attr));
break;
}
case WELL_KNOWN_INTEGER_ATTRIBUTE_KIND:
{
Attribute.Kind attr = Attribute.Kind.decode(args[i++]);
group.addAttribute(new Attribute.KnownIntegerValueAttribute(attr, (int) args[i++]));
break;
}
case STRING_ATTRIBUTE_KIND:
{
StringBuilder strAttr = new StringBuilder();
i = readString(i, args, strAttr);
group.addAttribute(new Attribute.StringAttribute(strAttr.toString()));
break;
}
case STRING_VALUE_ATTRIBUTE_KIND:
{
StringBuilder strAttr = new StringBuilder();
i = readString(i, args, strAttr);
StringBuilder strVal = new StringBuilder();
i = readString(i, args, strVal);
group.addAttribute(new Attribute.StringValueAttribute(strAttr.toString(), strVal.toString()));
break;
}
default:
throw new RuntimeException("unexpected type: " + type);
}
}
}
use of com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup in project sulong by graalvm.
the class ParameterAttributes method decodeOldCodeEntry.
private void decodeOldCodeEntry(long[] args) {
final List<AttributesGroup> attrGroup = new ArrayList<>();
for (int i = 0; i < args.length; i += 2) {
attrGroup.add(decodeOldGroupCodeEntry(args[i], args[i + 1]));
}
parameterCodeEntry.add(new AttributesCodeEntry(attrGroup));
}
Aggregations