use of com.oracle.truffle.llvm.runtime.types.PointerType in project sulong by graalvm.
the class Types method record.
@Override
public void record(long id, long[] args) {
TypesRecord record = TypesRecord.decode(id);
Type type;
switch(record) {
case NUMBER_OF_ENTRIES:
table = new Type[(int) args[0]];
return;
case VOID:
type = VoidType.INSTANCE;
break;
case FLOAT:
type = PrimitiveType.FLOAT;
break;
case DOUBLE:
type = PrimitiveType.DOUBLE;
break;
case LABEL:
type = MetaType.LABEL;
break;
case OPAQUE:
if (structName != null) {
type = new OpaqueType(LLVMIdentifier.toLocalIdentifier(structName));
structName = null;
module.addGlobalType(type);
} else {
type = new OpaqueType();
}
break;
case INTEGER:
type = Type.getIntegerType((int) args[0]);
break;
case POINTER:
{
final PointerType pointerType = new PointerType(null);
setType((int) args[0], pointerType::setPointeeType);
type = pointerType;
break;
}
case FUNCTION_OLD:
{
final FunctionType functionType = new FunctionType(null, toTypes(args, 3, args.length), args[0] != 0);
setType((int) args[2], functionType::setReturnType);
type = functionType;
break;
}
case HALF:
type = PrimitiveType.HALF;
break;
case ARRAY:
{
final ArrayType arrayType = new ArrayType(null, (int) args[0]);
setType((int) args[1], arrayType::setElementType);
type = arrayType;
break;
}
case VECTOR:
{
final VectorType vectorType = new VectorType(null, (int) args[0]);
setType((int) args[1], vectorType::setElementType);
type = vectorType;
break;
}
case X86_FP80:
type = PrimitiveType.X86_FP80;
break;
case FP128:
type = PrimitiveType.F128;
break;
case PPC_FP128:
type = PrimitiveType.PPC_FP128;
break;
case METADATA:
type = MetaType.METADATA;
break;
case X86_MMX:
type = MetaType.X86MMX;
break;
case STRUCT_NAME:
{
structName = Records.toString(args);
return;
}
case STRUCT_ANON:
case STRUCT_NAMED:
{
final boolean isPacked = args[0] != 0;
final Type[] members = toTypes(args, 1, args.length);
if (structName != null) {
type = new StructureType(LLVMIdentifier.toTypeIdentifier(structName), isPacked, members);
structName = null;
module.addGlobalType(type);
} else {
type = new StructureType(isPacked, members);
}
break;
}
case FUNCTION:
{
final FunctionType functionType = new FunctionType(null, toTypes(args, 2, args.length), args[0] != 0);
setType((int) args[1], functionType::setReturnType);
type = functionType;
break;
}
case TOKEN:
type = MetaType.TOKEN;
break;
default:
type = MetaType.UNKNOWN;
break;
}
if (table[size] != null) {
((UnresolvedType) table[size]).dependent.accept(type);
}
table[size++] = type;
}
use of com.oracle.truffle.llvm.runtime.types.PointerType in project sulong by graalvm.
the class AsmFactory method addFrameSlot.
void addFrameSlot(String reg, Type type) {
if (!registers.contains(reg)) {
registers.add(reg);
FrameSlotKind kind;
if (type instanceof PrimitiveType) {
PrimitiveKind primitiveKind = ((PrimitiveType) type).getPrimitiveKind();
switch(primitiveKind) {
case I8:
kind = FrameSlotKind.Byte;
break;
case I32:
kind = FrameSlotKind.Int;
break;
case I64:
kind = FrameSlotKind.Long;
break;
default:
kind = FrameSlotKind.Illegal;
break;
}
} else if (type instanceof PointerType) {
kind = FrameSlotKind.Object;
} else {
kind = FrameSlotKind.Illegal;
}
this.frameDescriptor.addFrameSlot(reg, type, kind);
}
}
use of com.oracle.truffle.llvm.runtime.types.PointerType in project sulong by graalvm.
the class AsmFactory method createUnaryOperationImplicitSize.
void createUnaryOperationImplicitSize(String operation, AsmOperand operand) {
LLVMExpressionNode out;
AsmOperand dst = operand;
assert operand != null;
assert operation.length() > 0;
Type dstType = getType(operand);
PrimitiveType.PrimitiveKind dstPrimitiveType = (dstType instanceof PrimitiveType) ? ((PrimitiveType) dstType).getPrimitiveKind() : null;
switch(operation) {
case "seta":
case "setnbe":
out = LLVMAMD64SetaNodeGen.create(getFlag(LLVMAMD64Flags.CF), getFlag(LLVMAMD64Flags.ZF));
dstType = PrimitiveType.I8;
break;
case "setae":
case "setnb":
case "setnc":
out = LLVMAMD64SetzNodeGen.create(getFlag(LLVMAMD64Flags.CF));
dstType = PrimitiveType.I8;
break;
case "setb":
case "setc":
case "setnae":
out = LLVMAMD64SetnzNodeGen.create(getFlag(LLVMAMD64Flags.CF));
dstType = PrimitiveType.I8;
break;
case "setbe":
out = LLVMAMD64SetorNodeGen.create(getFlag(LLVMAMD64Flags.CF), getFlag(LLVMAMD64Flags.ZF));
dstType = PrimitiveType.I8;
break;
case "sete":
case "setz":
out = LLVMAMD64SetzNodeGen.create(getFlag(LLVMAMD64Flags.ZF));
dstType = PrimitiveType.I8;
break;
case "setg":
case "setnle":
out = LLVMAMD64SetgNodeGen.create(getFlag(LLVMAMD64Flags.ZF), getFlag(LLVMAMD64Flags.SF), getFlag(LLVMAMD64Flags.OF));
dstType = PrimitiveType.I8;
break;
case "setge":
case "setnl":
out = LLVMAMD64SeteqNodeGen.create(getFlag(LLVMAMD64Flags.SF), getFlag(LLVMAMD64Flags.OF));
dstType = PrimitiveType.I8;
break;
case "setl":
case "setnge":
out = LLVMAMD64SetneNodeGen.create(getFlag(LLVMAMD64Flags.SF), getFlag(LLVMAMD64Flags.OF));
dstType = PrimitiveType.I8;
break;
case "setle":
case "setng":
out = LLVMAMD64SetleNodeGen.create(getFlag(LLVMAMD64Flags.ZF), getFlag(LLVMAMD64Flags.SF), getFlag(LLVMAMD64Flags.OF));
dstType = PrimitiveType.I8;
break;
case "setna":
out = LLVMAMD64SetorNodeGen.create(getFlag(LLVMAMD64Flags.CF), getFlag(LLVMAMD64Flags.ZF));
dstType = PrimitiveType.I8;
break;
case "setne":
case "setnz":
out = LLVMAMD64SetzNodeGen.create(getFlag(LLVMAMD64Flags.ZF));
dstType = PrimitiveType.I8;
break;
case "setno":
out = LLVMAMD64SetzNodeGen.create(getFlag(LLVMAMD64Flags.OF));
dstType = PrimitiveType.I8;
break;
case "setnp":
case "setpo":
out = LLVMAMD64SetzNodeGen.create(getFlag(LLVMAMD64Flags.PF));
dstType = PrimitiveType.I8;
break;
case "setns":
out = LLVMAMD64SetzNodeGen.create(getFlag(LLVMAMD64Flags.SF));
dstType = PrimitiveType.I8;
break;
case "seto":
out = LLVMAMD64SetnzNodeGen.create(getFlag(LLVMAMD64Flags.OF));
dstType = PrimitiveType.I8;
break;
case "setp":
case "setpe":
out = LLVMAMD64SetnzNodeGen.create(getFlag(LLVMAMD64Flags.PF));
dstType = PrimitiveType.I8;
break;
case "sets":
out = LLVMAMD64SetnzNodeGen.create(getFlag(LLVMAMD64Flags.SF));
dstType = PrimitiveType.I8;
break;
case "rdrand":
if (dstType instanceof PrimitiveType) {
switch(dstPrimitiveType) {
case I16:
out = LLVMAMD64RdRandwNodeGen.create(getFlagWrite(LLVMAMD64Flags.CF));
break;
case I32:
out = LLVMAMD64RdRandlNodeGen.create(getFlagWrite(LLVMAMD64Flags.CF));
break;
case I64:
out = LLVMAMD64RdRandqNodeGen.create(getFlagWrite(LLVMAMD64Flags.CF));
break;
default:
throw new AsmParseException("invalid operand size: " + dstPrimitiveType);
}
} else {
throw new AsmParseException("invalid operand type: " + dstType);
}
break;
case "rdseed":
if (dstType instanceof PrimitiveType) {
switch(dstPrimitiveType) {
case I16:
out = LLVMAMD64RdSeedwNodeGen.create(getFlagWrite(LLVMAMD64Flags.CF));
break;
case I32:
out = LLVMAMD64RdSeedlNodeGen.create(getFlagWrite(LLVMAMD64Flags.CF));
break;
case I64:
out = LLVMAMD64RdSeedqNodeGen.create(getFlagWrite(LLVMAMD64Flags.CF));
break;
default:
throw new AsmParseException("invalid operand size: " + dstPrimitiveType);
}
} else {
throw new AsmParseException("invalid operand type: " + dstType);
}
break;
case "pop":
// default size: I64
if (dstType == null) {
dstType = PrimitiveType.I64;
dstPrimitiveType = PrimitiveKind.I64;
}
if (dstType instanceof PrimitiveType) {
switch(dstPrimitiveType) {
case I16:
out = LLVMAMD64PopwNodeGen.create();
break;
case I32:
out = LLVMAMD64PoplNodeGen.create();
break;
case I64:
out = LLVMAMD64PopqNodeGen.create();
break;
default:
throw new AsmParseException("invalid operand size: " + dstPrimitiveType);
}
} else if (dstType instanceof PointerType) {
PointerType ptr = (PointerType) dstType;
dstType = ptr.getPointeeType();
if (dstType instanceof PrimitiveType) {
switch(((PrimitiveType) dstType).getPrimitiveKind()) {
case I16:
out = LLVMAMD64PopwNodeGen.create();
break;
case I32:
out = LLVMAMD64PoplNodeGen.create();
break;
case I64:
out = LLVMAMD64PopqNodeGen.create();
break;
default:
throw new AsmParseException("invalid operand size: " + dstPrimitiveType);
}
} else {
throw new AsmParseException("invalid operand type: " + dstType);
}
} else {
throw new AsmParseException("invalid operand type: " + dstType);
}
break;
case "push":
// default size: I64
if (dstType == null) {
dstType = PrimitiveType.I64;
dstPrimitiveType = PrimitiveKind.I64;
}
if (dstType instanceof PrimitiveType) {
LLVMExpressionNode src = getOperandLoad(dstType, operand);
switch(dstPrimitiveType) {
case I16:
statements.add(LLVMAMD64PushwNodeGen.create(src));
return;
case I32:
statements.add(LLVMAMD64PushlNodeGen.create(src));
return;
case I64:
statements.add(LLVMAMD64PushqNodeGen.create(src));
return;
default:
throw new AsmParseException("invalid operand size: " + dstPrimitiveType);
}
} else if (dstType instanceof PointerType) {
PointerType ptr = (PointerType) dstType;
dstType = ptr.getPointeeType();
LLVMExpressionNode src = getOperandLoad(dstType, operand);
if (dstType instanceof PrimitiveType) {
switch(((PrimitiveType) dstType).getPrimitiveKind()) {
case I16:
statements.add(LLVMAMD64PushwNodeGen.create(src));
return;
case I32:
statements.add(LLVMAMD64PushlNodeGen.create(src));
return;
case I64:
statements.add(LLVMAMD64PushqNodeGen.create(src));
return;
default:
throw new AsmParseException("invalid operand size: " + dstPrimitiveType);
}
} else {
throw new AsmParseException("invalid operand type: " + dstType);
}
} else {
throw new AsmParseException("invalid operand type: " + dstType);
}
case "bswap":
if (dstType instanceof PrimitiveType) {
LLVMExpressionNode src = getOperandLoad(dstType, operand);
switch(dstPrimitiveType) {
case I32:
statements.add(LLVMAMD64BswaplNodeGen.create(src));
return;
case I64:
statements.add(LLVMAMD64BswapqNodeGen.create(src));
return;
default:
throw new AsmParseException("invalid operand size: " + dstPrimitiveType);
}
} else {
throw new AsmParseException("invalid operand type: " + dstType);
}
default:
statements.add(new LLVMUnsupportedInlineAssemblerNode(sourceLocation, "Unsupported operation: " + operation));
return;
}
if (dstType == null) {
throw new IllegalArgumentException("unknown operand width");
}
LLVMExpressionNode write = getOperandStore(dstType, dst, out);
statements.add(write);
}
use of com.oracle.truffle.llvm.runtime.types.PointerType in project sulong by graalvm.
the class AsmFactory method getTarget.
private LLVMAMD64Target getTarget(Type type, AsmOperand operand) {
if (operand instanceof AsmRegisterOperand) {
AsmRegisterOperand op = (AsmRegisterOperand) operand;
FrameSlot frame = getRegisterSlot(op.getBaseRegister());
int shift = op.getShift();
assert type == op.getType();
switch(((PrimitiveType) op.getType()).getPrimitiveKind()) {
case I8:
return new LLVMAMD64Target(frame, shift);
case I16:
case I32:
case I64:
return new LLVMAMD64Target(frame);
default:
throw new AsmParseException("unsupported operand type: " + op.getType());
}
} else if (operand instanceof AsmArgumentOperand) {
AsmArgumentOperand op = (AsmArgumentOperand) operand;
Argument info = argInfo.get(op.getIndex());
if (info.isMemory()) {
LLVMExpressionNode address = info.getAddress();
if (type instanceof PointerType) {
return new LLVMAMD64Target(address);
}
switch(((PrimitiveType) type).getPrimitiveKind()) {
case I8:
case I16:
case I32:
case I64:
return new LLVMAMD64Target(address);
default:
throw new AsmParseException("unsupported operand type: " + type);
}
} else if (info.isRegister()) {
FrameSlot frame = getRegisterSlot(info.getRegister());
if (type instanceof PointerType || info.getType() instanceof PointerType) {
return new LLVMAMD64Target(frame);
}
switch(((PrimitiveType) type).getPrimitiveKind()) {
case I8:
case I16:
case I32:
case I64:
return new LLVMAMD64Target(frame);
default:
throw new AsmParseException("unsupported operand type: " + type);
}
} else {
throw new AssertionError("this should not happen; " + info);
}
}
throw new AsmParseException("unsupported operand type: " + operand);
}
use of com.oracle.truffle.llvm.runtime.types.PointerType in project sulong by graalvm.
the class AsmFactory method createBinaryOperationImplicitSize.
void createBinaryOperationImplicitSize(String operation, AsmOperand a, AsmOperand b) {
AsmOperand dst = b;
AsmOperand src = a;
assert a != null && b != null;
Type dstType = getType(b, a);
PrimitiveType.PrimitiveKind dstPrimitiveType = (dstType instanceof PrimitiveType) ? ((PrimitiveType) dstType).getPrimitiveKind() : null;
LLVMExpressionNode out;
switch(operation) {
case "lea":
out = getOperandAddress(dstType, src);
if (isLeaPointer(src)) {
dstType = new PointerType(dstType);
}
break;
case "xor":
if (dstType instanceof PrimitiveType) {
LLVMExpressionNode srcA = getOperandLoad(dstType, a);
LLVMExpressionNode srcB = getOperandLoad(dstType, b);
switch(dstPrimitiveType) {
case I8:
out = LLVMAMD64XorbNodeGen.create(srcA, srcB);
break;
case I16:
out = LLVMAMD64XorwNodeGen.create(srcA, srcB);
break;
case I32:
out = LLVMAMD64XorlNodeGen.create(srcA, srcB);
break;
case I64:
out = LLVMAMD64XorqNodeGen.create(srcA, srcB);
break;
default:
throw new AsmParseException("invalid operand type: " + dstType);
}
} else {
throw new AsmParseException("invalid operand type: " + dstType);
}
break;
case "mov":
if (dstType instanceof PrimitiveType) {
LLVMExpressionNode srcA = getOperandLoad(dstType, a);
out = srcA;
} else if (dstType instanceof PointerType) {
LLVMExpressionNode srcA = getOperandLoad(dstType, a);
out = srcA;
} else {
throw new AsmParseException("invalid operand type: " + dstType);
}
break;
case "bsr":
if (dstType instanceof PrimitiveType) {
LLVMExpressionNode srcA = getOperandLoad(dstType, a);
LLVMExpressionNode srcB = getOperandLoad(dstType, b);
switch(dstPrimitiveType) {
case I16:
out = LLVMAMD64BsrwNodeGen.create(getFlagWrite(LLVMAMD64Flags.ZF), srcA, srcB);
break;
case I32:
out = LLVMAMD64BsrlNodeGen.create(getFlagWrite(LLVMAMD64Flags.ZF), srcA, srcB);
break;
case I64:
out = LLVMAMD64BsrqNodeGen.create(getFlagWrite(LLVMAMD64Flags.ZF), srcA, srcB);
break;
default:
throw new AsmParseException("invalid operand type: " + dstType);
}
} else {
throw new AsmParseException("invalid operand type: " + dstType);
}
break;
case "bsf":
if (dstType instanceof PrimitiveType) {
LLVMExpressionNode srcA = getOperandLoad(dstType, a);
LLVMExpressionNode srcB = getOperandLoad(dstType, b);
switch(dstPrimitiveType) {
case I16:
out = LLVMAMD64BsfwNodeGen.create(getFlagWrite(LLVMAMD64Flags.ZF), srcA, srcB);
break;
case I32:
out = LLVMAMD64BsflNodeGen.create(getFlagWrite(LLVMAMD64Flags.ZF), srcA, srcB);
break;
case I64:
out = LLVMAMD64BsfqNodeGen.create(getFlagWrite(LLVMAMD64Flags.ZF), srcA, srcB);
break;
default:
throw new AsmParseException("invalid operand type: " + dstType);
}
} else {
throw new AsmParseException("invalid operand type: " + dstType);
}
break;
case "xchg":
{
if (dstType instanceof PrimitiveType) {
XchgOperands operands = new XchgOperands(a, b, dstType);
switch(dstPrimitiveType) {
case I8:
out = LLVMAMD64XchgbNodeGen.create(operands.dst, operands.srcA, operands.srcB);
break;
case I16:
out = LLVMAMD64XchgwNodeGen.create(operands.dst, operands.srcA, operands.srcB);
break;
case I32:
out = LLVMAMD64XchglNodeGen.create(operands.dst, operands.srcA, operands.srcB);
break;
case I64:
out = LLVMAMD64XchgqNodeGen.create(operands.dst, operands.srcA, operands.srcB);
break;
default:
throw new AsmParseException("invalid operand type: " + dstType);
}
statements.add(out);
return;
} else {
throw new AsmParseException("invalid operand type: " + dstType);
}
}
case "cmpxchg":
{
if (dstType instanceof PointerType) {
// treat pointers as I64
dstPrimitiveType = PrimitiveKind.I64;
}
if (dstType instanceof PrimitiveType || dstType instanceof PointerType) {
LLVMExpressionNode srcA = getOperandLoad(dstType, a);
LLVMExpressionNode srcB = getOperandLoad(dstType, b);
LLVMAMD64WriteValueNode dst1 = getStore(dstType, b);
LLVMAMD64WriteValueNode dst2;
LLVMExpressionNode accumulator;
if (dstType instanceof PointerType) {
dst2 = getRegisterStore("rax");
accumulator = getOperandLoad(new PointerType(PrimitiveType.I8), new AsmRegisterOperand("rax"));
out = LLVMAMD64CmpXchgqNodeGen.create(getUpdateCPAZSOFlagsNode(), dst1, dst2, accumulator, srcA, srcB);
} else {
switch(dstPrimitiveType) {
case I8:
dst2 = getRegisterStore("al");
accumulator = getOperandLoad(PrimitiveType.I8, new AsmRegisterOperand("al"));
out = LLVMAMD64CmpXchgbNodeGen.create(getUpdateCPAZSOFlagsNode(), dst1, dst2, accumulator, srcA, srcB);
break;
case I16:
dst2 = getRegisterStore("ax");
accumulator = getOperandLoad(PrimitiveType.I16, new AsmRegisterOperand("ax"));
out = LLVMAMD64CmpXchgwNodeGen.create(getUpdateCPAZSOFlagsNode(), dst1, dst2, accumulator, srcA, srcB);
break;
case I32:
dst2 = getRegisterStore("eax");
accumulator = getOperandLoad(PrimitiveType.I32, new AsmRegisterOperand("eax"));
out = LLVMAMD64CmpXchglNodeGen.create(getUpdateCPAZSOFlagsNode(), dst1, dst2, accumulator, srcA, srcB);
break;
case I64:
dst2 = getRegisterStore("rax");
accumulator = getOperandLoad(PrimitiveType.I64, new AsmRegisterOperand("rax"));
out = LLVMAMD64CmpXchgqNodeGen.create(getUpdateCPAZSOFlagsNode(), dst1, dst2, accumulator, srcA, srcB);
break;
default:
throw new AsmParseException("invalid operand type: " + dstType);
}
}
statements.add(out);
return;
} else {
throw new AsmParseException("invalid operand type: " + dstType);
}
}
case "and":
if (dstType instanceof PrimitiveType) {
LLVMExpressionNode srcA = getOperandLoad(dstType, a);
LLVMExpressionNode srcB = getOperandLoad(dstType, b);
switch(dstPrimitiveType) {
case I8:
out = LLVMAMD64AndbNodeGen.create(getUpdatePZSFlagsNode(), srcA, srcB);
break;
case I16:
out = LLVMAMD64AndwNodeGen.create(getUpdatePZSFlagsNode(), srcA, srcB);
break;
case I32:
out = LLVMAMD64AndlNodeGen.create(getUpdatePZSFlagsNode(), srcA, srcB);
break;
case I64:
out = LLVMAMD64AndqNodeGen.create(getUpdatePZSFlagsNode(), srcA, srcB);
break;
default:
throw new AsmParseException("invalid operand type: " + dstType);
}
} else {
throw new AsmParseException("invalid operand type: " + dstType);
}
break;
case "or":
if (dstType instanceof PrimitiveType) {
LLVMExpressionNode srcA = getOperandLoad(dstType, a);
LLVMExpressionNode srcB = getOperandLoad(dstType, b);
switch(dstPrimitiveType) {
case I8:
out = LLVMAMD64OrbNodeGen.create(srcA, srcB);
break;
case I16:
out = LLVMAMD64OrwNodeGen.create(srcA, srcB);
break;
case I32:
out = LLVMAMD64OrlNodeGen.create(srcA, srcB);
break;
case I64:
out = LLVMAMD64OrqNodeGen.create(srcA, srcB);
break;
default:
throw new AsmParseException("invalid operand type: " + dstType);
}
} else {
throw new AsmParseException("invalid operand type: " + dstType);
}
break;
default:
statements.add(new LLVMUnsupportedInlineAssemblerNode(sourceLocation, "Unsupported operation: " + operation));
return;
}
LLVMExpressionNode write = getOperandStore(dstType, dst, out);
statements.add(write);
}
Aggregations