JIT hackery. Not quite working.
This commit is contained in:
@@ -420,6 +420,7 @@ Value* HIRBuilder::AllocValue(TypeName type) {
|
||||
value->def = NULL;
|
||||
value->use_head = NULL;
|
||||
value->tag = NULL;
|
||||
value->reg = -1;
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -432,6 +433,7 @@ Value* HIRBuilder::CloneValue(Value* source) {
|
||||
value->def = NULL;
|
||||
value->use_head = NULL;
|
||||
value->tag = NULL;
|
||||
value->reg = -1;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,19 @@ void Instr::set_src3(Value* value) {
|
||||
src3_use = value ? value->AddUse(block->arena, this) : NULL;
|
||||
}
|
||||
|
||||
bool Instr::Match(SignatureType dest_req,
|
||||
SignatureType src1_req,
|
||||
SignatureType src2_req,
|
||||
SignatureType src3_req) const {
|
||||
#define TO_SIG_TYPE(v) \
|
||||
(v ? (v->IsConstant() ? SignatureType((v->type + 1) | SIG_TYPE_C) : SignatureType(v->type + 1)) : SIG_TYPE_X)
|
||||
return
|
||||
((dest_req == SIG_TYPE_IGNORE) || (dest_req == TO_SIG_TYPE(dest))) &&
|
||||
((src1_req == SIG_TYPE_IGNORE) || (src1_req == TO_SIG_TYPE(src1.value))) &&
|
||||
((src2_req == SIG_TYPE_IGNORE) || (src2_req == TO_SIG_TYPE(src2.value))) &&
|
||||
((src3_req == SIG_TYPE_IGNORE) || (src3_req == TO_SIG_TYPE(src3.value)));
|
||||
}
|
||||
|
||||
void Instr::Replace(const OpcodeInfo* opcode, uint16_t flags) {
|
||||
this->opcode = opcode;
|
||||
this->flags = flags;
|
||||
|
||||
@@ -24,6 +24,25 @@ namespace hir {
|
||||
class Block;
|
||||
class Label;
|
||||
|
||||
enum SignatureType {
|
||||
SIG_TYPE_X = 0,
|
||||
SIG_TYPE_I8 = 1,
|
||||
SIG_TYPE_I16 = 2,
|
||||
SIG_TYPE_I32 = 3,
|
||||
SIG_TYPE_I64 = 4,
|
||||
SIG_TYPE_F32 = 5,
|
||||
SIG_TYPE_F64 = 6,
|
||||
SIG_TYPE_V128 = 7,
|
||||
SIG_TYPE_C = (1 << 3),
|
||||
SIG_TYPE_I8C = SIG_TYPE_C | SIG_TYPE_I8,
|
||||
SIG_TYPE_I16C = SIG_TYPE_C | SIG_TYPE_I16,
|
||||
SIG_TYPE_I32C = SIG_TYPE_C | SIG_TYPE_I32,
|
||||
SIG_TYPE_I64C = SIG_TYPE_C | SIG_TYPE_I64,
|
||||
SIG_TYPE_F32C = SIG_TYPE_C | SIG_TYPE_F32,
|
||||
SIG_TYPE_F64C = SIG_TYPE_C | SIG_TYPE_F64,
|
||||
SIG_TYPE_V128C = SIG_TYPE_C | SIG_TYPE_V128,
|
||||
SIG_TYPE_IGNORE = 0xFF,
|
||||
};
|
||||
|
||||
class Instr {
|
||||
public:
|
||||
@@ -33,6 +52,7 @@ public:
|
||||
|
||||
const OpcodeInfo* opcode;
|
||||
uint16_t flags;
|
||||
uint16_t ordinal;
|
||||
|
||||
typedef union {
|
||||
runtime::FunctionInfo* symbol_info;
|
||||
@@ -54,6 +74,11 @@ public:
|
||||
void set_src2(Value* value);
|
||||
void set_src3(Value* value);
|
||||
|
||||
bool Match(SignatureType dest = SIG_TYPE_X,
|
||||
SignatureType src1 = SIG_TYPE_X,
|
||||
SignatureType src2 = SIG_TYPE_X,
|
||||
SignatureType src3 = SIG_TYPE_X) const;
|
||||
|
||||
void Replace(const OpcodeInfo* opcode, uint16_t flags);
|
||||
void Remove();
|
||||
};
|
||||
|
||||
@@ -36,6 +36,23 @@ void Value::RemoveUse(Use* use) {
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t Value::AsUint32() {
|
||||
XEASSERT(IsConstant());
|
||||
switch (type) {
|
||||
case INT8_TYPE:
|
||||
return constant.i8;
|
||||
case INT16_TYPE:
|
||||
return constant.i16;
|
||||
case INT32_TYPE:
|
||||
return constant.i32;
|
||||
case INT64_TYPE:
|
||||
return (uint32_t)constant.i64;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t Value::AsUint64() {
|
||||
XEASSERT(IsConstant());
|
||||
switch (type) {
|
||||
|
||||
@@ -21,17 +21,22 @@ class Instr;
|
||||
|
||||
|
||||
enum TypeName {
|
||||
INT8_TYPE,
|
||||
INT16_TYPE,
|
||||
INT32_TYPE,
|
||||
INT64_TYPE,
|
||||
FLOAT32_TYPE,
|
||||
FLOAT64_TYPE,
|
||||
VEC128_TYPE,
|
||||
// Many tables rely on this ordering.
|
||||
INT8_TYPE = 0,
|
||||
INT16_TYPE = 1,
|
||||
INT32_TYPE = 2,
|
||||
INT64_TYPE = 3,
|
||||
FLOAT32_TYPE = 4,
|
||||
FLOAT64_TYPE = 5,
|
||||
VEC128_TYPE = 6,
|
||||
|
||||
MAX_TYPENAME,
|
||||
};
|
||||
|
||||
static bool IsIntType(TypeName type_name) {
|
||||
return type_name < 4;
|
||||
}
|
||||
|
||||
enum ValueFlags {
|
||||
VALUE_IS_CONSTANT = (1 << 1),
|
||||
};
|
||||
@@ -59,7 +64,7 @@ public:
|
||||
TypeName type;
|
||||
|
||||
uint32_t flags;
|
||||
uint32_t reserved;
|
||||
uint32_t reg;
|
||||
ConstantValue constant;
|
||||
|
||||
Instr* def;
|
||||
@@ -174,6 +179,7 @@ public:
|
||||
(other->flags & VALUE_IS_CONSTANT) &&
|
||||
constant.i64 != other->constant.i64;
|
||||
}
|
||||
uint32_t AsUint32();
|
||||
uint64_t AsUint64();
|
||||
|
||||
void Cast(TypeName target_type);
|
||||
|
||||
Reference in New Issue
Block a user