Running clang-format on alloy.

All except x64_sequences, which needs work.
This commit is contained in:
Ben Vanik
2014-07-10 20:20:00 -07:00
parent 0158380cfc
commit 7daa85179c
139 changed files with 6925 additions and 6998 deletions

View File

@@ -11,9 +11,8 @@
#include <alloy/hir/instr.h>
using namespace alloy;
using namespace alloy::hir;
namespace alloy {
namespace hir {
void Block::AssertNoCycles() {
Instr* hare = instr_head;
@@ -37,3 +36,6 @@ void Block::AssertNoCycles() {
}
}
}
} // namespace hir
} // namespace alloy

View File

@@ -14,7 +14,6 @@
XEDECLARECLASS1(llvm, BitVector);
namespace alloy {
namespace hir {
@@ -23,14 +22,14 @@ class HIRBuilder;
class Instr;
class Label;
class Edge {
public:
public:
enum EdgeFlags {
UNCONDITIONAL = (1 << 0),
DOMINATES = (1 << 1),
};
public:
public:
Edge* outgoing_next;
Edge* outgoing_prev;
Edge* incoming_next;
@@ -42,9 +41,8 @@ public:
uint32_t flags;
};
class Block {
public:
public:
Arena* arena;
Block* next;
@@ -65,9 +63,7 @@ public:
void AssertNoCycles();
};
} // namespace hir
} // namespace alloy
#endif // ALLOY_HIR_BLOCK_H_

File diff suppressed because it is too large Load Diff

View File

@@ -17,17 +17,15 @@
#include <alloy/hir/opcodes.h>
#include <alloy/hir/value.h>
namespace alloy {
namespace hir {
enum FunctionAttributes {
FUNCTION_ATTRIB_INLINE = (1 << 1),
FUNCTION_ATTRIB_INLINE = (1 << 1),
};
class HIRBuilder {
public:
public:
HIRBuilder();
virtual ~HIRBuilder();
@@ -86,10 +84,8 @@ public:
void Branch(Label* label, uint32_t branch_flags = 0);
void Branch(Block* block, uint32_t branch_flags = 0);
void BranchTrue(Value* cond, Label* label,
uint32_t branch_flags = 0);
void BranchFalse(Value* cond, Label* label,
uint32_t branch_flags = 0);
void BranchTrue(Value* cond, Label* label, uint32_t branch_flags = 0);
void BranchFalse(Value* cond, Label* label, uint32_t branch_flags = 0);
// phi type_name, Block* b1, Value* v1, Block* b2, Value* v2, etc
@@ -162,13 +158,12 @@ public:
uint32_t arithmetic_flags = 0);
Value* VectorAdd(Value* value1, Value* value2, TypeName part_type,
uint32_t arithmetic_flags = 0);
Value* Sub(Value* value1, Value* value2,
uint32_t arithmetic_flags = 0);
Value* Sub(Value* value1, Value* value2, uint32_t arithmetic_flags = 0);
Value* Mul(Value* value1, Value* value2, uint32_t arithmetic_flags = 0);
Value* MulHi(Value* value1, Value* value2, uint32_t arithmetic_flags = 0);
Value* Div(Value* value1, Value* value2, uint32_t arithmetic_flags = 0);
Value* MulAdd(Value* value1, Value* value2, Value* value3); // (1 * 2) + 3
Value* MulSub(Value* value1, Value* value2, Value* value3); // (1 * 2) - 3
Value* MulAdd(Value* value1, Value* value2, Value* value3); // (1 * 2) + 3
Value* MulSub(Value* value1, Value* value2, Value* value3); // (1 * 2) - 3
Value* Neg(Value* value);
Value* Abs(Value* value);
Value* Sqrt(Value* value);
@@ -208,48 +203,44 @@ public:
Value* Pack(Value* value, uint32_t pack_flags = 0);
Value* Unpack(Value* value, uint32_t pack_flags = 0);
Value* CompareExchange(Value* address,
Value* compare_value, Value* exchange_value);
Value* CompareExchange(Value* address, Value* compare_value,
Value* exchange_value);
Value* AtomicExchange(Value* address, Value* new_value);
Value* AtomicAdd(Value* address, Value* value);
Value* AtomicSub(Value* address, Value* value);
protected:
protected:
void DumpValue(StringBuffer* str, Value* value);
void DumpOp(
StringBuffer* str, OpcodeSignatureType sig_type, Instr::Op* op);
void DumpOp(StringBuffer* str, OpcodeSignatureType sig_type, Instr::Op* op);
Value* AllocValue(TypeName type = INT64_TYPE);
Value* CloneValue(Value* source);
private:
private:
Block* AppendBlock();
void EndBlock();
bool IsUnconditionalJump(Instr* instr);
Instr* AppendInstr(const OpcodeInfo& opcode, uint16_t flags,
Value* dest = 0);
Instr* AppendInstr(const OpcodeInfo& opcode, uint16_t flags, Value* dest = 0);
Value* CompareXX(const OpcodeInfo& opcode, Value* value1, Value* value2);
Value* VectorCompareXX(
const OpcodeInfo& opcode, Value* value1, Value* value2, TypeName part_type);
Value* VectorCompareXX(const OpcodeInfo& opcode, Value* value1, Value* value2,
TypeName part_type);
protected:
Arena* arena_;
protected:
Arena* arena_;
uint32_t attributes_;
uint32_t attributes_;
uint32_t next_label_id_;
uint32_t next_value_ordinal_;
uint32_t next_label_id_;
uint32_t next_value_ordinal_;
std::vector<Value*> locals_;
Block* block_head_;
Block* block_tail_;
Block* current_block_;
Block* block_head_;
Block* block_tail_;
Block* current_block_;
};
} // namespace hir
} // namespace alloy
#endif // ALLOY_HIR_HIR_BUILDER_H_

View File

@@ -11,9 +11,8 @@
#include <alloy/hir/block.h>
using namespace alloy;
using namespace alloy::hir;
namespace alloy {
namespace hir {
void Instr::set_src1(Value* value) {
if (src1.value == value) {
@@ -114,3 +113,6 @@ void Instr::Remove() {
block->instr_tail = prev;
}
}
} // namespace hir
} // namespace alloy

View File

@@ -14,9 +14,11 @@
#include <alloy/hir/opcodes.h>
#include <alloy/hir/value.h>
namespace alloy { namespace runtime { class FunctionInfo; } }
namespace alloy {
namespace runtime {
class FunctionInfo;
} // namespace runtime
} // namespace alloy
namespace alloy {
namespace hir {
@@ -25,26 +27,26 @@ class Block;
class Label;
class Instr {
public:
Block* block;
Instr* next;
Instr* prev;
public:
Block* block;
Instr* next;
Instr* prev;
const OpcodeInfo* opcode;
uint16_t flags;
uint32_t ordinal;
uint16_t flags;
uint32_t ordinal;
typedef union {
runtime::FunctionInfo* symbol_info;
Label* label;
Value* value;
uint64_t offset;
Label* label;
Value* value;
uint64_t offset;
} Op;
Value* dest;
Op src1;
Op src2;
Op src3;
Value* dest;
Op src1;
Op src2;
Op src3;
Value::Use* src1_use;
Value::Use* src2_use;
@@ -59,9 +61,7 @@ public:
void Remove();
};
} // namespace hir
} // namespace alloy
#endif // ALLOY_HIR_INSTR_H_

View File

@@ -12,28 +12,24 @@
#include <alloy/core.h>
namespace alloy {
namespace hir {
class Block;
class Label {
public:
public:
Block* block;
Label* next;
Label* prev;
uint32_t id;
char* name;
uint32_t id;
char* name;
void* tag;
void* tag;
};
} // namespace hir
} // namespace alloy
#endif // ALLOY_HIR_LABEL_H_

View File

@@ -9,15 +9,13 @@
#include <alloy/hir/opcodes.h>
using namespace alloy;
using namespace alloy::hir;
namespace alloy {
namespace hir {
#define DEFINE_OPCODE(num, name, sig, flags) \
static const OpcodeInfo num##_info = { flags, sig, name, num, };
static const OpcodeInfo num##_info = { \
flags, sig, name, num, \
};
#include <alloy/hir/opcodes.inl>
#undef DEFINE_OPCODE

View File

@@ -12,17 +12,15 @@
#include <alloy/core.h>
namespace alloy {
namespace hir {
enum CallFlags {
CALL_TAIL = (1 << 1),
CALL_POSSIBLE_RETURN = (1 << 2),
CALL_TAIL = (1 << 1),
CALL_POSSIBLE_RETURN = (1 << 2),
};
enum BranchFlags {
BRANCH_LIKELY = (1 << 1),
BRANCH_LIKELY = (1 << 1),
BRANCH_UNLIKELY = (1 << 2),
};
enum RoundMode {
@@ -33,20 +31,20 @@ enum RoundMode {
ROUND_TO_POSITIVE_INFINITY,
};
enum LoadFlags {
LOAD_NO_ALIAS = (1 << 1),
LOAD_ALIGNED = (1 << 2),
LOAD_UNALIGNED = (1 << 3),
LOAD_VOLATILE = (1 << 4),
LOAD_NO_ALIAS = (1 << 1),
LOAD_ALIGNED = (1 << 2),
LOAD_UNALIGNED = (1 << 3),
LOAD_VOLATILE = (1 << 4),
};
enum StoreFlags {
STORE_NO_ALIAS = (1 << 1),
STORE_ALIGNED = (1 << 2),
STORE_NO_ALIAS = (1 << 1),
STORE_ALIGNED = (1 << 2),
STORE_UNALIGNED = (1 << 3),
STORE_VOLATILE = (1 << 4),
STORE_VOLATILE = (1 << 4),
};
enum PrefetchFlags {
PREFETCH_LOAD = (1 << 1),
PREFETCH_STORE = (1 << 2),
PREFETCH_LOAD = (1 << 1),
PREFETCH_STORE = (1 << 2),
};
enum ArithmeticFlags {
ARITHMETIC_SET_CARRY = (1 << 1),
@@ -56,11 +54,8 @@ enum ArithmeticFlags {
enum Permutes {
PERMUTE_XY_ZW = 0x00010405,
};
#define SWIZZLE_MASK(x, y, z, w) ( \
(((x) & 0x3) << 6) | \
(((y) & 0x3) << 4) | \
(((z) & 0x3) << 2) | \
(((w) & 0x3)))
#define SWIZZLE_MASK(x, y, z, w) \
((((x)&0x3) << 6) | (((y)&0x3) << 4) | (((z)&0x3) << 2) | (((w)&0x3)))
enum Swizzles {
SWIZZLE_XYZW_TO_XYZW = SWIZZLE_MASK(0, 1, 2, 3),
SWIZZLE_XYZW_TO_YZWX = SWIZZLE_MASK(1, 2, 3, 0),
@@ -78,19 +73,14 @@ enum PackType {
PACK_TYPE_S16_IN_32_HI = 7,
};
enum Opcode {
OPCODE_COMMENT,
OPCODE_NOP,
OPCODE_SOURCE_OFFSET,
OPCODE_DEBUG_BREAK,
OPCODE_DEBUG_BREAK_TRUE,
OPCODE_TRAP,
OPCODE_TRAP_TRUE,
OPCODE_CALL,
OPCODE_CALL_TRUE,
OPCODE_CALL_INDIRECT,
@@ -99,11 +89,9 @@ enum Opcode {
OPCODE_RETURN,
OPCODE_RETURN_TRUE,
OPCODE_SET_RETURN_ADDRESS,
OPCODE_BRANCH,
OPCODE_BRANCH_TRUE,
OPCODE_BRANCH_FALSE,
OPCODE_ASSIGN,
OPCODE_CAST,
OPCODE_ZERO_EXTEND,
@@ -113,22 +101,16 @@ enum Opcode {
OPCODE_ROUND,
OPCODE_VECTOR_CONVERT_I2F,
OPCODE_VECTOR_CONVERT_F2I,
OPCODE_LOAD_VECTOR_SHL,
OPCODE_LOAD_VECTOR_SHR,
OPCODE_LOAD_CLOCK,
OPCODE_LOAD_LOCAL,
OPCODE_STORE_LOCAL,
OPCODE_LOAD_CONTEXT,
OPCODE_STORE_CONTEXT,
OPCODE_LOAD,
OPCODE_STORE,
OPCODE_PREFETCH,
OPCODE_MAX,
OPCODE_MIN,
OPCODE_SELECT,
@@ -152,13 +134,12 @@ enum Opcode {
OPCODE_VECTOR_COMPARE_SGE,
OPCODE_VECTOR_COMPARE_UGT,
OPCODE_VECTOR_COMPARE_UGE,
OPCODE_ADD,
OPCODE_ADD_CARRY,
OPCODE_VECTOR_ADD,
OPCODE_SUB,
OPCODE_MUL,
OPCODE_MUL_HI, // TODO(benvanik): remove this and add INT128 type.
OPCODE_MUL_HI, // TODO(benvanik): remove this and add INT128 type.
OPCODE_DIV,
OPCODE_MUL_ADD,
OPCODE_MUL_SUB,
@@ -170,7 +151,6 @@ enum Opcode {
OPCODE_LOG2,
OPCODE_DOT_PRODUCT_3,
OPCODE_DOT_PRODUCT_4,
OPCODE_AND,
OPCODE_OR,
OPCODE_XOR,
@@ -191,22 +171,20 @@ enum Opcode {
OPCODE_SWIZZLE,
OPCODE_PACK,
OPCODE_UNPACK,
OPCODE_COMPARE_EXCHANGE,
OPCODE_ATOMIC_EXCHANGE,
OPCODE_ATOMIC_ADD,
OPCODE_ATOMIC_SUB,
__OPCODE_MAX_VALUE, // Keep at end.
__OPCODE_MAX_VALUE, // Keep at end.
};
enum OpcodeFlags {
OPCODE_FLAG_BRANCH = (1 << 1),
OPCODE_FLAG_MEMORY = (1 << 2),
OPCODE_FLAG_BRANCH = (1 << 1),
OPCODE_FLAG_MEMORY = (1 << 2),
OPCODE_FLAG_COMMUNATIVE = (1 << 3),
OPCODE_FLAG_VOLATILE = (1 << 4),
OPCODE_FLAG_IGNORE = (1 << 5),
OPCODE_FLAG_HIDE = (1 << 6),
OPCODE_FLAG_VOLATILE = (1 << 4),
OPCODE_FLAG_IGNORE = (1 << 5),
OPCODE_FLAG_HIDE = (1 << 6),
OPCODE_FLAG_PAIRED_PREV = (1 << 7),
};
@@ -220,26 +198,38 @@ enum OpcodeSignatureType {
};
enum OpcodeSignature {
OPCODE_SIG_X = (OPCODE_SIG_TYPE_X),
OPCODE_SIG_X_L = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_L << 3),
OPCODE_SIG_X_O = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_O << 3),
OPCODE_SIG_X_O_V = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_O << 3) | (OPCODE_SIG_TYPE_V << 6),
OPCODE_SIG_X_S = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_S << 3),
OPCODE_SIG_X_V = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_V << 3),
OPCODE_SIG_X_V_L = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_L << 6),
OPCODE_SIG_X_V_L_L = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_L << 6) | (OPCODE_SIG_TYPE_L << 9),
OPCODE_SIG_X_V_O = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_O << 6),
OPCODE_SIG_X_V_S = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_S << 6),
OPCODE_SIG_X_V_V = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_V << 6),
OPCODE_SIG_X_V_V_V = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_V << 6) | (OPCODE_SIG_TYPE_V << 9),
OPCODE_SIG_V = (OPCODE_SIG_TYPE_V),
OPCODE_SIG_V_O = (OPCODE_SIG_TYPE_V) | (OPCODE_SIG_TYPE_O << 3),
OPCODE_SIG_V_V = (OPCODE_SIG_TYPE_V) | (OPCODE_SIG_TYPE_V << 3),
OPCODE_SIG_V_V_O = (OPCODE_SIG_TYPE_V) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_O << 6),
OPCODE_SIG_V_V_O_V = (OPCODE_SIG_TYPE_V) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_O << 6) | (OPCODE_SIG_TYPE_V << 9),
OPCODE_SIG_V_V_V = (OPCODE_SIG_TYPE_V) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_V << 6),
OPCODE_SIG_V_V_V_O = (OPCODE_SIG_TYPE_V) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_V << 6) | (OPCODE_SIG_TYPE_O << 9),
OPCODE_SIG_V_V_V_V = (OPCODE_SIG_TYPE_V) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_V << 6) | (OPCODE_SIG_TYPE_V << 9),
OPCODE_SIG_X = (OPCODE_SIG_TYPE_X),
OPCODE_SIG_X_L = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_L << 3),
OPCODE_SIG_X_O = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_O << 3),
OPCODE_SIG_X_O_V =
(OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_O << 3) | (OPCODE_SIG_TYPE_V << 6),
OPCODE_SIG_X_S = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_S << 3),
OPCODE_SIG_X_V = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_V << 3),
OPCODE_SIG_X_V_L =
(OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_L << 6),
OPCODE_SIG_X_V_L_L = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_V << 3) |
(OPCODE_SIG_TYPE_L << 6) | (OPCODE_SIG_TYPE_L << 9),
OPCODE_SIG_X_V_O =
(OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_O << 6),
OPCODE_SIG_X_V_S =
(OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_S << 6),
OPCODE_SIG_X_V_V =
(OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_V << 6),
OPCODE_SIG_X_V_V_V = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_V << 3) |
(OPCODE_SIG_TYPE_V << 6) | (OPCODE_SIG_TYPE_V << 9),
OPCODE_SIG_V = (OPCODE_SIG_TYPE_V),
OPCODE_SIG_V_O = (OPCODE_SIG_TYPE_V) | (OPCODE_SIG_TYPE_O << 3),
OPCODE_SIG_V_V = (OPCODE_SIG_TYPE_V) | (OPCODE_SIG_TYPE_V << 3),
OPCODE_SIG_V_V_O =
(OPCODE_SIG_TYPE_V) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_O << 6),
OPCODE_SIG_V_V_O_V = (OPCODE_SIG_TYPE_V) | (OPCODE_SIG_TYPE_V << 3) |
(OPCODE_SIG_TYPE_O << 6) | (OPCODE_SIG_TYPE_V << 9),
OPCODE_SIG_V_V_V =
(OPCODE_SIG_TYPE_V) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_V << 6),
OPCODE_SIG_V_V_V_O = (OPCODE_SIG_TYPE_V) | (OPCODE_SIG_TYPE_V << 3) |
(OPCODE_SIG_TYPE_V << 6) | (OPCODE_SIG_TYPE_O << 9),
OPCODE_SIG_V_V_V_V = (OPCODE_SIG_TYPE_V) | (OPCODE_SIG_TYPE_V << 3) |
(OPCODE_SIG_TYPE_V << 6) | (OPCODE_SIG_TYPE_V << 9),
};
#define GET_OPCODE_SIG_TYPE_DEST(sig) (OpcodeSignatureType)(sig & 0x7)
@@ -248,21 +238,17 @@ enum OpcodeSignature {
#define GET_OPCODE_SIG_TYPE_SRC3(sig) (OpcodeSignatureType)((sig >> 9) & 0x7)
typedef struct {
uint32_t flags;
uint32_t signature;
uint32_t flags;
uint32_t signature;
const char* name;
Opcode num;
Opcode num;
} OpcodeInfo;
#define DEFINE_OPCODE(num, name, sig, flags) \
extern const OpcodeInfo num##_info;
#define DEFINE_OPCODE(num, name, sig, flags) extern const OpcodeInfo num##_info;
#include <alloy/hir/opcodes.inl>
#undef DEFINE_OPCODE
} // namespace hir
} // namespace alloy
#endif // ALLOY_HIR_OPCODES_H_

View File

@@ -13,23 +13,19 @@
#include <alloy/tracing/tracing.h>
#include <alloy/tracing/event_type.h>
namespace alloy {
namespace hir {
const uint32_t ALLOY_HIR = alloy::tracing::EventType::ALLOY_HIR;
class EventType {
public:
public:
enum {
ALLOY_HIR_FOO = ALLOY_HIR | (0),
ALLOY_HIR_FOO = ALLOY_HIR | (0),
};
};
} // namespace hir
} // namespace alloy
#endif // ALLOY_HIR_TRACING_H_

View File

@@ -9,9 +9,8 @@
#include <alloy/hir/value.h>
using namespace alloy;
using namespace alloy::hir;
namespace alloy {
namespace hir {
Value::Use* Value::AddUse(Arena* arena, Instr* instr) {
Use* use = arena->Alloc<Use>();
@@ -39,34 +38,34 @@ 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;
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) {
case INT8_TYPE:
return constant.i8;
case INT16_TYPE:
return constant.i16;
case INT32_TYPE:
return constant.i32;
case INT64_TYPE:
return constant.i64;
default:
XEASSERTALWAYS();
return 0;
case INT8_TYPE:
return constant.i8;
case INT16_TYPE:
return constant.i16;
case INT32_TYPE:
return constant.i32;
case INT64_TYPE:
return constant.i64;
default:
XEASSERTALWAYS();
return 0;
}
}
@@ -77,87 +76,6 @@ void Value::Cast(TypeName target_type) {
void Value::ZeroExtend(TypeName target_type) {
switch (type) {
case INT8_TYPE:
type = target_type;
constant.i64 = constant.i64 & 0xFF;
return;
case INT16_TYPE:
type = target_type;
constant.i64 = constant.i64 & 0xFFFF;
return;
case INT32_TYPE:
type = target_type;
constant.i64 = constant.i64 & 0xFFFFFFFF;
return;
}
// Unsupported types.
XEASSERTALWAYS();
}
void Value::SignExtend(TypeName target_type) {
switch (type) {
case INT8_TYPE:
type = target_type;
switch (target_type) {
case INT16_TYPE:
constant.i16 = constant.i8;
break;
case INT32_TYPE:
constant.i32 = constant.i8;
break;
case INT64_TYPE:
constant.i64 = constant.i8;
break;
}
return;
case INT16_TYPE:
type = target_type;
switch (target_type) {
case INT32_TYPE:
constant.i32 = constant.i16;
break;
case INT64_TYPE:
constant.i64 = constant.i16;
break;
}
return;
case INT32_TYPE:
type = target_type;
switch (target_type) {
case INT64_TYPE:
constant.i64 = constant.i32;
break;
}
return;
}
// Unsupported types.
XEASSERTALWAYS();
}
void Value::Truncate(TypeName target_type) {
switch (type) {
case INT16_TYPE:
switch (target_type) {
case INT8_TYPE:
type = target_type;
constant.i64 = constant.i64 & 0xFF;
return;
}
break;
case INT32_TYPE:
switch (target_type) {
case INT8_TYPE:
type = target_type;
constant.i64 = constant.i64 & 0xFF;
return;
case INT16_TYPE:
type = target_type;
constant.i64 = constant.i64 & 0xFFFF;
return;
}
break;
case INT64_TYPE:
switch (target_type) {
case INT8_TYPE:
type = target_type;
constant.i64 = constant.i64 & 0xFF;
@@ -170,8 +88,89 @@ void Value::Truncate(TypeName target_type) {
type = target_type;
constant.i64 = constant.i64 & 0xFFFFFFFF;
return;
}
break;
}
// Unsupported types.
XEASSERTALWAYS();
}
void Value::SignExtend(TypeName target_type) {
switch (type) {
case INT8_TYPE:
type = target_type;
switch (target_type) {
case INT16_TYPE:
constant.i16 = constant.i8;
break;
case INT32_TYPE:
constant.i32 = constant.i8;
break;
case INT64_TYPE:
constant.i64 = constant.i8;
break;
}
return;
case INT16_TYPE:
type = target_type;
switch (target_type) {
case INT32_TYPE:
constant.i32 = constant.i16;
break;
case INT64_TYPE:
constant.i64 = constant.i16;
break;
}
return;
case INT32_TYPE:
type = target_type;
switch (target_type) {
case INT64_TYPE:
constant.i64 = constant.i32;
break;
}
return;
}
// Unsupported types.
XEASSERTALWAYS();
}
void Value::Truncate(TypeName target_type) {
switch (type) {
case INT16_TYPE:
switch (target_type) {
case INT8_TYPE:
type = target_type;
constant.i64 = constant.i64 & 0xFF;
return;
}
break;
case INT32_TYPE:
switch (target_type) {
case INT8_TYPE:
type = target_type;
constant.i64 = constant.i64 & 0xFF;
return;
case INT16_TYPE:
type = target_type;
constant.i64 = constant.i64 & 0xFFFF;
return;
}
break;
case INT64_TYPE:
switch (target_type) {
case INT8_TYPE:
type = target_type;
constant.i64 = constant.i64 & 0xFF;
return;
case INT16_TYPE:
type = target_type;
constant.i64 = constant.i64 & 0xFFFF;
return;
case INT32_TYPE:
type = target_type;
constant.i64 = constant.i64 & 0xFFFFFFFF;
return;
}
break;
}
// Unsupported types.
XEASSERTALWAYS();
@@ -188,70 +187,70 @@ void Value::Round(RoundMode round_mode) {
}
bool Value::Add(Value* other) {
#define CHECK_DID_CARRY(v1, v2) (((uint64_t)v2) > ~((uint64_t)v1))
#define ADD_DID_CARRY(a, b) CHECK_DID_CARRY(a, b)
#define CHECK_DID_CARRY(v1, v2) (((uint64_t)v2) > ~((uint64_t)v1))
#define ADD_DID_CARRY(a, b) CHECK_DID_CARRY(a, b)
XEASSERT(type == other->type);
bool did_carry = false;
switch (type) {
case INT8_TYPE:
did_carry = ADD_DID_CARRY(constant.i8, other->constant.i8);
constant.i8 += other->constant.i8;
break;
case INT16_TYPE:
did_carry = ADD_DID_CARRY(constant.i16, other->constant.i16);
constant.i16 += other->constant.i16;
break;
case INT32_TYPE:
did_carry = ADD_DID_CARRY(constant.i32, other->constant.i32);
constant.i32 += other->constant.i32;
break;
case INT64_TYPE:
did_carry = ADD_DID_CARRY(constant.i64, other->constant.i64);
constant.i64 += other->constant.i64;
break;
case FLOAT32_TYPE:
constant.f32 += other->constant.f32;
break;
case FLOAT64_TYPE:
constant.f64 += other->constant.f64;
break;
default:
XEASSERTALWAYS();
break;
case INT8_TYPE:
did_carry = ADD_DID_CARRY(constant.i8, other->constant.i8);
constant.i8 += other->constant.i8;
break;
case INT16_TYPE:
did_carry = ADD_DID_CARRY(constant.i16, other->constant.i16);
constant.i16 += other->constant.i16;
break;
case INT32_TYPE:
did_carry = ADD_DID_CARRY(constant.i32, other->constant.i32);
constant.i32 += other->constant.i32;
break;
case INT64_TYPE:
did_carry = ADD_DID_CARRY(constant.i64, other->constant.i64);
constant.i64 += other->constant.i64;
break;
case FLOAT32_TYPE:
constant.f32 += other->constant.f32;
break;
case FLOAT64_TYPE:
constant.f64 += other->constant.f64;
break;
default:
XEASSERTALWAYS();
break;
}
return did_carry;
}
bool Value::Sub(Value* other) {
#define SUB_DID_CARRY(a, b) (b > a)
#define SUB_DID_CARRY(a, b) (b > a)
XEASSERT(type == other->type);
bool did_carry = false;
switch (type) {
case INT8_TYPE:
did_carry = SUB_DID_CARRY(constant.i8, other->constant.i8);
constant.i8 -= other->constant.i8;
break;
case INT16_TYPE:
did_carry = SUB_DID_CARRY(constant.i16, other->constant.i16);
constant.i16 -= other->constant.i16;
break;
case INT32_TYPE:
did_carry = SUB_DID_CARRY(constant.i32, other->constant.i32);
constant.i32 -= other->constant.i32;
break;
case INT64_TYPE:
did_carry = SUB_DID_CARRY(constant.i64, other->constant.i64);
constant.i64 -= other->constant.i64;
break;
case FLOAT32_TYPE:
constant.f32 -= other->constant.f32;
break;
case FLOAT64_TYPE:
constant.f64 -= other->constant.f64;
break;
default:
XEASSERTALWAYS();
break;
case INT8_TYPE:
did_carry = SUB_DID_CARRY(constant.i8, other->constant.i8);
constant.i8 -= other->constant.i8;
break;
case INT16_TYPE:
did_carry = SUB_DID_CARRY(constant.i16, other->constant.i16);
constant.i16 -= other->constant.i16;
break;
case INT32_TYPE:
did_carry = SUB_DID_CARRY(constant.i32, other->constant.i32);
constant.i32 -= other->constant.i32;
break;
case INT64_TYPE:
did_carry = SUB_DID_CARRY(constant.i64, other->constant.i64);
constant.i64 -= other->constant.i64;
break;
case FLOAT32_TYPE:
constant.f32 -= other->constant.f32;
break;
case FLOAT64_TYPE:
constant.f64 -= other->constant.f64;
break;
default:
XEASSERTALWAYS();
break;
}
return did_carry;
}
@@ -259,54 +258,54 @@ bool Value::Sub(Value* other) {
void Value::Mul(Value* other) {
XEASSERT(type == other->type);
switch (type) {
case INT8_TYPE:
constant.i8 *= other->constant.i8;
break;
case INT16_TYPE:
constant.i16 *= other->constant.i16;
break;
case INT32_TYPE:
constant.i32 *= other->constant.i32;
break;
case INT64_TYPE:
constant.i64 *= other->constant.i64;
break;
case FLOAT32_TYPE:
constant.f32 *= other->constant.f32;
break;
case FLOAT64_TYPE:
constant.f64 *= other->constant.f64;
break;
default:
XEASSERTALWAYS();
break;
case INT8_TYPE:
constant.i8 *= other->constant.i8;
break;
case INT16_TYPE:
constant.i16 *= other->constant.i16;
break;
case INT32_TYPE:
constant.i32 *= other->constant.i32;
break;
case INT64_TYPE:
constant.i64 *= other->constant.i64;
break;
case FLOAT32_TYPE:
constant.f32 *= other->constant.f32;
break;
case FLOAT64_TYPE:
constant.f64 *= other->constant.f64;
break;
default:
XEASSERTALWAYS();
break;
}
}
void Value::Div(Value* other) {
XEASSERT(type == other->type);
switch (type) {
case INT8_TYPE:
constant.i8 /= other->constant.i8;
break;
case INT16_TYPE:
constant.i16 /= other->constant.i16;
break;
case INT32_TYPE:
constant.i32 /= other->constant.i32;
break;
case INT64_TYPE:
constant.i64 /= other->constant.i64;
break;
case FLOAT32_TYPE:
constant.f32 /= other->constant.f32;
break;
case FLOAT64_TYPE:
constant.f64 /= other->constant.f64;
break;
default:
XEASSERTALWAYS();
break;
case INT8_TYPE:
constant.i8 /= other->constant.i8;
break;
case INT16_TYPE:
constant.i16 /= other->constant.i16;
break;
case INT32_TYPE:
constant.i32 /= other->constant.i32;
break;
case INT64_TYPE:
constant.i64 /= other->constant.i64;
break;
case FLOAT32_TYPE:
constant.f32 /= other->constant.f32;
break;
case FLOAT64_TYPE:
constant.f64 /= other->constant.f64;
break;
default:
XEASSERTALWAYS();
break;
}
}
@@ -322,276 +321,276 @@ void Value::MulSub(Value* dest, Value* value1, Value* value2, Value* value3) {
void Value::Neg() {
switch (type) {
case INT8_TYPE:
constant.i8 = -constant.i8;
break;
case INT16_TYPE:
constant.i16 = -constant.i16;
break;
case INT32_TYPE:
constant.i32 = -constant.i32;
break;
case INT64_TYPE:
constant.i64 = -constant.i64;
break;
case FLOAT32_TYPE:
constant.f32 = -constant.f32;
break;
case FLOAT64_TYPE:
constant.f64 = -constant.f64;
break;
default:
XEASSERTALWAYS();
break;
case INT8_TYPE:
constant.i8 = -constant.i8;
break;
case INT16_TYPE:
constant.i16 = -constant.i16;
break;
case INT32_TYPE:
constant.i32 = -constant.i32;
break;
case INT64_TYPE:
constant.i64 = -constant.i64;
break;
case FLOAT32_TYPE:
constant.f32 = -constant.f32;
break;
case FLOAT64_TYPE:
constant.f64 = -constant.f64;
break;
default:
XEASSERTALWAYS();
break;
}
}
void Value::Abs() {
switch (type) {
case INT8_TYPE:
constant.i8 = abs(constant.i8);
break;
case INT16_TYPE:
constant.i16 = abs(constant.i16);
break;
case INT32_TYPE:
constant.i32 = abs(constant.i32);
break;
case INT64_TYPE:
constant.i64 = abs(constant.i64);
break;
case FLOAT32_TYPE:
constant.f32 = abs(constant.f32);
break;
case FLOAT64_TYPE:
constant.f64 = abs(constant.f64);
break;
default:
XEASSERTALWAYS();
break;
case INT8_TYPE:
constant.i8 = abs(constant.i8);
break;
case INT16_TYPE:
constant.i16 = abs(constant.i16);
break;
case INT32_TYPE:
constant.i32 = abs(constant.i32);
break;
case INT64_TYPE:
constant.i64 = abs(constant.i64);
break;
case FLOAT32_TYPE:
constant.f32 = abs(constant.f32);
break;
case FLOAT64_TYPE:
constant.f64 = abs(constant.f64);
break;
default:
XEASSERTALWAYS();
break;
}
}
void Value::Sqrt() {
switch (type) {
case FLOAT32_TYPE:
constant.f32 = 1.0f / sqrtf(constant.f32);
break;
case FLOAT64_TYPE:
constant.f64 = 1.0 / sqrt(constant.f64);
break;
default:
XEASSERTALWAYS();
break;
case FLOAT32_TYPE:
constant.f32 = 1.0f / sqrtf(constant.f32);
break;
case FLOAT64_TYPE:
constant.f64 = 1.0 / sqrt(constant.f64);
break;
default:
XEASSERTALWAYS();
break;
}
}
void Value::RSqrt() {
switch (type) {
case FLOAT32_TYPE:
constant.f32 = sqrt(constant.f32);
break;
case FLOAT64_TYPE:
constant.f64 = sqrt(constant.f64);
break;
default:
XEASSERTALWAYS();
break;
case FLOAT32_TYPE:
constant.f32 = sqrt(constant.f32);
break;
case FLOAT64_TYPE:
constant.f64 = sqrt(constant.f64);
break;
default:
XEASSERTALWAYS();
break;
}
}
void Value::And(Value* other) {
XEASSERT(type == other->type);
switch (type) {
case INT8_TYPE:
constant.i8 &= other->constant.i8;
break;
case INT16_TYPE:
constant.i16 &= other->constant.i16;
break;
case INT32_TYPE:
constant.i32 &= other->constant.i32;
break;
case INT64_TYPE:
constant.i64 &= other->constant.i64;
break;
default:
XEASSERTALWAYS();
break;
case INT8_TYPE:
constant.i8 &= other->constant.i8;
break;
case INT16_TYPE:
constant.i16 &= other->constant.i16;
break;
case INT32_TYPE:
constant.i32 &= other->constant.i32;
break;
case INT64_TYPE:
constant.i64 &= other->constant.i64;
break;
default:
XEASSERTALWAYS();
break;
}
}
void Value::Or(Value* other) {
XEASSERT(type == other->type);
switch (type) {
case INT8_TYPE:
constant.i8 |= other->constant.i8;
break;
case INT16_TYPE:
constant.i16 |= other->constant.i16;
break;
case INT32_TYPE:
constant.i32 |= other->constant.i32;
break;
case INT64_TYPE:
constant.i64 |= other->constant.i64;
break;
default:
XEASSERTALWAYS();
break;
case INT8_TYPE:
constant.i8 |= other->constant.i8;
break;
case INT16_TYPE:
constant.i16 |= other->constant.i16;
break;
case INT32_TYPE:
constant.i32 |= other->constant.i32;
break;
case INT64_TYPE:
constant.i64 |= other->constant.i64;
break;
default:
XEASSERTALWAYS();
break;
}
}
void Value::Xor(Value* other) {
XEASSERT(type == other->type);
switch (type) {
case INT8_TYPE:
constant.i8 ^= other->constant.i8;
break;
case INT16_TYPE:
constant.i16 ^= other->constant.i16;
break;
case INT32_TYPE:
constant.i32 ^= other->constant.i32;
break;
case INT64_TYPE:
constant.i64 ^= other->constant.i64;
break;
default:
XEASSERTALWAYS();
break;
case INT8_TYPE:
constant.i8 ^= other->constant.i8;
break;
case INT16_TYPE:
constant.i16 ^= other->constant.i16;
break;
case INT32_TYPE:
constant.i32 ^= other->constant.i32;
break;
case INT64_TYPE:
constant.i64 ^= other->constant.i64;
break;
default:
XEASSERTALWAYS();
break;
}
}
void Value::Not() {
switch (type) {
case INT8_TYPE:
constant.i8 = ~constant.i8;
break;
case INT16_TYPE:
constant.i16 = ~constant.i16;
break;
case INT32_TYPE:
constant.i32 = ~constant.i32;
break;
case INT64_TYPE:
constant.i64 = ~constant.i64;
break;
case VEC128_TYPE:
constant.v128.low = ~constant.v128.low;
constant.v128.high = ~constant.v128.high;
break;
default:
XEASSERTALWAYS();
break;
case INT8_TYPE:
constant.i8 = ~constant.i8;
break;
case INT16_TYPE:
constant.i16 = ~constant.i16;
break;
case INT32_TYPE:
constant.i32 = ~constant.i32;
break;
case INT64_TYPE:
constant.i64 = ~constant.i64;
break;
case VEC128_TYPE:
constant.v128.low = ~constant.v128.low;
constant.v128.high = ~constant.v128.high;
break;
default:
XEASSERTALWAYS();
break;
}
}
void Value::Shl(Value* other) {
XEASSERT(other->type == INT8_TYPE);
switch (type) {
case INT8_TYPE:
constant.i8 <<= other->constant.i8;
break;
case INT16_TYPE:
constant.i16 <<= other->constant.i8;
break;
case INT32_TYPE:
constant.i32 <<= other->constant.i8;
break;
case INT64_TYPE:
constant.i64 <<= other->constant.i8;
break;
default:
XEASSERTALWAYS();
break;
case INT8_TYPE:
constant.i8 <<= other->constant.i8;
break;
case INT16_TYPE:
constant.i16 <<= other->constant.i8;
break;
case INT32_TYPE:
constant.i32 <<= other->constant.i8;
break;
case INT64_TYPE:
constant.i64 <<= other->constant.i8;
break;
default:
XEASSERTALWAYS();
break;
}
}
void Value::Shr(Value* other) {
XEASSERT(other->type == INT8_TYPE);
switch (type) {
case INT8_TYPE:
constant.i8 = (uint8_t)constant.i8 >> other->constant.i8;
break;
case INT16_TYPE:
constant.i16 = (uint16_t)constant.i16 >> other->constant.i8;
break;
case INT32_TYPE:
constant.i32 = (uint32_t)constant.i32 >> other->constant.i8;
break;
case INT64_TYPE:
constant.i64 = (uint16_t)constant.i64 >> other->constant.i8;
break;
default:
XEASSERTALWAYS();
break;
case INT8_TYPE:
constant.i8 = (uint8_t)constant.i8 >> other->constant.i8;
break;
case INT16_TYPE:
constant.i16 = (uint16_t)constant.i16 >> other->constant.i8;
break;
case INT32_TYPE:
constant.i32 = (uint32_t)constant.i32 >> other->constant.i8;
break;
case INT64_TYPE:
constant.i64 = (uint16_t)constant.i64 >> other->constant.i8;
break;
default:
XEASSERTALWAYS();
break;
}
}
void Value::Sha(Value* other) {
XEASSERT(other->type == INT8_TYPE);
switch (type) {
case INT8_TYPE:
constant.i8 = constant.i8 >> other->constant.i8;
break;
case INT16_TYPE:
constant.i16 = constant.i16 >> other->constant.i8;
break;
case INT32_TYPE:
constant.i32 = constant.i32 >> other->constant.i8;
break;
case INT64_TYPE:
constant.i64 = constant.i64 >> other->constant.i8;
break;
default:
XEASSERTALWAYS();
break;
case INT8_TYPE:
constant.i8 = constant.i8 >> other->constant.i8;
break;
case INT16_TYPE:
constant.i16 = constant.i16 >> other->constant.i8;
break;
case INT32_TYPE:
constant.i32 = constant.i32 >> other->constant.i8;
break;
case INT64_TYPE:
constant.i64 = constant.i64 >> other->constant.i8;
break;
default:
XEASSERTALWAYS();
break;
}
}
void Value::ByteSwap() {
switch (type) {
case INT8_TYPE:
constant.i8 = constant.i8;
break;
case INT16_TYPE:
constant.i16 = XESWAP16(constant.i16);
break;
case INT32_TYPE:
constant.i32 = XESWAP32(constant.i32);
break;
case INT64_TYPE:
constant.i64 = XESWAP64(constant.i64);
break;
case VEC128_TYPE:
for (int n = 0; n < 4; n++) {
constant.v128.i4[n] = XESWAP32(constant.v128.i4[n]);
}
break;
default:
XEASSERTALWAYS();
break;
case INT8_TYPE:
constant.i8 = constant.i8;
break;
case INT16_TYPE:
constant.i16 = XESWAP16(constant.i16);
break;
case INT32_TYPE:
constant.i32 = XESWAP32(constant.i32);
break;
case INT64_TYPE:
constant.i64 = XESWAP64(constant.i64);
break;
case VEC128_TYPE:
for (int n = 0; n < 4; n++) {
constant.v128.i4[n] = XESWAP32(constant.v128.i4[n]);
}
break;
default:
XEASSERTALWAYS();
break;
}
}
void Value::CountLeadingZeros(const Value* other) {
switch (other->type) {
case INT8_TYPE:
constant.i8 = static_cast<uint8_t>(__lzcnt16(other->constant.i8) - 8);
break;
case INT16_TYPE:
constant.i8 = static_cast<uint8_t>(__lzcnt16(other->constant.i16));
break;
case INT32_TYPE:
constant.i8 = static_cast<uint8_t>(__lzcnt(other->constant.i32));
break;
case INT64_TYPE:
constant.i8 = static_cast<uint8_t>(__lzcnt64(other->constant.i64));
break;
default:
XEASSERTALWAYS();
break;
case INT8_TYPE:
constant.i8 = static_cast<uint8_t>(__lzcnt16(other->constant.i8) - 8);
break;
case INT16_TYPE:
constant.i8 = static_cast<uint8_t>(__lzcnt16(other->constant.i16));
break;
case INT32_TYPE:
constant.i8 = static_cast<uint8_t>(__lzcnt(other->constant.i32));
break;
case INT64_TYPE:
constant.i8 = static_cast<uint8_t>(__lzcnt64(other->constant.i64));
break;
default:
XEASSERTALWAYS();
break;
}
}
@@ -600,3 +599,6 @@ bool Value::Compare(Opcode opcode, Value* other) {
XEASSERTALWAYS();
return false;
}
} // namespace hir
} // namespace alloy

View File

@@ -14,58 +14,51 @@
#include <alloy/backend/machine_info.h>
#include <alloy/hir/opcodes.h>
namespace alloy {
namespace hir {
class Instr;
enum TypeName {
// 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,
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 <= INT64_TYPE;
}
static bool IsIntType(TypeName type_name) { return type_name <= INT64_TYPE; }
static bool IsFloatType(TypeName type_name) {
return type_name == FLOAT32_TYPE || type_name == FLOAT64_TYPE;
}
static bool IsVecType(TypeName type_name) {
return type_name == VEC128_TYPE;
}
static bool IsVecType(TypeName type_name) { return type_name == VEC128_TYPE; }
static size_t GetTypeSize(TypeName type_name) {
switch (type_name) {
case INT8_TYPE:
return 1;
case INT16_TYPE:
return 2;
case INT32_TYPE:
return 4;
case INT64_TYPE:
return 8;
case FLOAT32_TYPE:
return 4;
case FLOAT64_TYPE:
return 8;
default:
case VEC128_TYPE:
return 16;
case INT8_TYPE:
return 1;
case INT16_TYPE:
return 2;
case INT32_TYPE:
return 4;
case INT64_TYPE:
return 8;
case FLOAT32_TYPE:
return 4;
case FLOAT64_TYPE:
return 8;
default:
case VEC128_TYPE:
return 16;
}
}
enum ValueFlags {
VALUE_IS_CONSTANT = (1 << 1),
VALUE_IS_ALLOCATED = (1 << 2), // Used by backends. Do not set.
VALUE_IS_CONSTANT = (1 << 1),
VALUE_IS_ALLOCATED = (1 << 2), // Used by backends. Do not set.
};
struct RegAssignment {
@@ -74,23 +67,23 @@ struct RegAssignment {
};
class Value {
public:
public:
typedef struct Use_s {
Instr* instr;
Use_s* prev;
Use_s* next;
Instr* instr;
Use_s* prev;
Use_s* next;
} Use;
typedef union {
int8_t i8;
int16_t i16;
int32_t i32;
int64_t i64;
float f32;
double f64;
vec128_t v128;
int8_t i8;
int16_t i16;
int32_t i32;
int64_t i64;
float f32;
double f64;
vec128_t v128;
} ConstantValue;
public:
public:
uint32_t ordinal;
TypeName type;
@@ -98,14 +91,14 @@ public:
RegAssignment reg;
ConstantValue constant;
Instr* def;
Use* use_head;
Instr* def;
Use* use_head;
// NOTE: for performance reasons this is not maintained during construction.
Instr* last_use;
Value* local_slot;
Instr* last_use;
Value* local_slot;
// TODO(benvanik): remove to shrink size.
void* tag;
void* tag;
Use* AddUse(Arena* arena, Instr* instr);
void RemoveUse(Use* use);
@@ -184,9 +177,7 @@ public:
constant.v128 = other->constant.v128;
}
inline bool IsConstant() const {
return !!(flags & VALUE_IS_CONSTANT);
}
inline bool IsConstant() const { return !!(flags & VALUE_IS_CONSTANT); }
bool IsConstantTrue() const {
if (type == VEC128_TYPE) {
XEASSERTALWAYS();
@@ -201,8 +192,8 @@ public:
}
bool IsConstantZero() const {
if (type == VEC128_TYPE) {
return (flags & VALUE_IS_CONSTANT) &&
!constant.v128.low && !constant.v128.high;
return (flags & VALUE_IS_CONSTANT) && !constant.v128.low &&
!constant.v128.high;
}
return (flags & VALUE_IS_CONSTANT) && !constant.i64;
}
@@ -210,160 +201,174 @@ public:
if (type == VEC128_TYPE) {
XEASSERTALWAYS();
}
return (flags & VALUE_IS_CONSTANT) &&
(other->flags & VALUE_IS_CONSTANT) &&
return (flags & VALUE_IS_CONSTANT) && (other->flags & VALUE_IS_CONSTANT) &&
constant.i64 == other->constant.i64;
}
bool IsConstantNE(Value* other) const {
if (type == VEC128_TYPE) {
XEASSERTALWAYS();
}
return (flags & VALUE_IS_CONSTANT) &&
(other->flags & VALUE_IS_CONSTANT) &&
return (flags & VALUE_IS_CONSTANT) && (other->flags & VALUE_IS_CONSTANT) &&
constant.i64 != other->constant.i64;
}
bool IsConstantSLT(Value* other) const {
XEASSERT(flags & VALUE_IS_CONSTANT && other->flags & VALUE_IS_CONSTANT);
switch (type) {
case INT8_TYPE:
return constant.i8 < other->constant.i8;
case INT16_TYPE:
return constant.i16 < other->constant.i16;
case INT32_TYPE:
return constant.i32 < other->constant.i32;
case INT64_TYPE:
return constant.i64 < other->constant.i64;
case FLOAT32_TYPE:
return constant.f32 < other->constant.f32;
case FLOAT64_TYPE:
return constant.f64 < other->constant.f64;
default: XEASSERTALWAYS(); return false;
case INT8_TYPE:
return constant.i8 < other->constant.i8;
case INT16_TYPE:
return constant.i16 < other->constant.i16;
case INT32_TYPE:
return constant.i32 < other->constant.i32;
case INT64_TYPE:
return constant.i64 < other->constant.i64;
case FLOAT32_TYPE:
return constant.f32 < other->constant.f32;
case FLOAT64_TYPE:
return constant.f64 < other->constant.f64;
default:
XEASSERTALWAYS();
return false;
}
}
bool IsConstantSLE(Value* other) const {
XEASSERT(flags & VALUE_IS_CONSTANT && other->flags & VALUE_IS_CONSTANT);
switch (type) {
case INT8_TYPE:
return constant.i8 <= other->constant.i8;
case INT16_TYPE:
return constant.i16 <= other->constant.i16;
case INT32_TYPE:
return constant.i32 <= other->constant.i32;
case INT64_TYPE:
return constant.i64 <= other->constant.i64;
case FLOAT32_TYPE:
return constant.f32 <= other->constant.f32;
case FLOAT64_TYPE:
return constant.f64 <= other->constant.f64;
default: XEASSERTALWAYS(); return false;
case INT8_TYPE:
return constant.i8 <= other->constant.i8;
case INT16_TYPE:
return constant.i16 <= other->constant.i16;
case INT32_TYPE:
return constant.i32 <= other->constant.i32;
case INT64_TYPE:
return constant.i64 <= other->constant.i64;
case FLOAT32_TYPE:
return constant.f32 <= other->constant.f32;
case FLOAT64_TYPE:
return constant.f64 <= other->constant.f64;
default:
XEASSERTALWAYS();
return false;
}
}
bool IsConstantSGT(Value* other) const {
XEASSERT(flags & VALUE_IS_CONSTANT && other->flags & VALUE_IS_CONSTANT);
switch (type) {
case INT8_TYPE:
return constant.i8 > other->constant.i8;
case INT16_TYPE:
return constant.i16 > other->constant.i16;
case INT32_TYPE:
return constant.i32 > other->constant.i32;
case INT64_TYPE:
return constant.i64 > other->constant.i64;
case FLOAT32_TYPE:
return constant.f32 > other->constant.f32;
case FLOAT64_TYPE:
return constant.f64 > other->constant.f64;
default: XEASSERTALWAYS(); return false;
case INT8_TYPE:
return constant.i8 > other->constant.i8;
case INT16_TYPE:
return constant.i16 > other->constant.i16;
case INT32_TYPE:
return constant.i32 > other->constant.i32;
case INT64_TYPE:
return constant.i64 > other->constant.i64;
case FLOAT32_TYPE:
return constant.f32 > other->constant.f32;
case FLOAT64_TYPE:
return constant.f64 > other->constant.f64;
default:
XEASSERTALWAYS();
return false;
}
}
bool IsConstantSGE(Value* other) const {
XEASSERT(flags & VALUE_IS_CONSTANT && other->flags & VALUE_IS_CONSTANT);
switch (type) {
case INT8_TYPE:
return constant.i8 >= other->constant.i8;
case INT16_TYPE:
return constant.i16 >= other->constant.i16;
case INT32_TYPE:
return constant.i32 >= other->constant.i32;
case INT64_TYPE:
return constant.i64 >= other->constant.i64;
case FLOAT32_TYPE:
return constant.f32 >= other->constant.f32;
case FLOAT64_TYPE:
return constant.f64 >= other->constant.f64;
default: XEASSERTALWAYS(); return false;
case INT8_TYPE:
return constant.i8 >= other->constant.i8;
case INT16_TYPE:
return constant.i16 >= other->constant.i16;
case INT32_TYPE:
return constant.i32 >= other->constant.i32;
case INT64_TYPE:
return constant.i64 >= other->constant.i64;
case FLOAT32_TYPE:
return constant.f32 >= other->constant.f32;
case FLOAT64_TYPE:
return constant.f64 >= other->constant.f64;
default:
XEASSERTALWAYS();
return false;
}
}
bool IsConstantULT(Value* other) const {
XEASSERT(flags & VALUE_IS_CONSTANT && other->flags & VALUE_IS_CONSTANT);
switch (type) {
case INT8_TYPE:
return (uint8_t)constant.i8 < (uint8_t)other->constant.i8;
case INT16_TYPE:
return (uint16_t)constant.i16 < (uint16_t)other->constant.i16;
case INT32_TYPE:
return (uint32_t)constant.i32 < (uint32_t)other->constant.i32;
case INT64_TYPE:
return (uint64_t)constant.i64 < (uint64_t)other->constant.i64;
case FLOAT32_TYPE:
return constant.f32 < other->constant.f32;
case FLOAT64_TYPE:
return constant.f64 < other->constant.f64;
default: XEASSERTALWAYS(); return false;
case INT8_TYPE:
return (uint8_t)constant.i8 < (uint8_t)other->constant.i8;
case INT16_TYPE:
return (uint16_t)constant.i16 < (uint16_t)other->constant.i16;
case INT32_TYPE:
return (uint32_t)constant.i32 < (uint32_t)other->constant.i32;
case INT64_TYPE:
return (uint64_t)constant.i64 < (uint64_t)other->constant.i64;
case FLOAT32_TYPE:
return constant.f32 < other->constant.f32;
case FLOAT64_TYPE:
return constant.f64 < other->constant.f64;
default:
XEASSERTALWAYS();
return false;
}
}
bool IsConstantULE(Value* other) const {
XEASSERT(flags & VALUE_IS_CONSTANT && other->flags & VALUE_IS_CONSTANT);
switch (type) {
case INT8_TYPE:
return (uint8_t)constant.i8 <= (uint8_t)other->constant.i8;
case INT16_TYPE:
return (uint16_t)constant.i16 <= (uint16_t)other->constant.i16;
case INT32_TYPE:
return (uint32_t)constant.i32 <= (uint32_t)other->constant.i32;
case INT64_TYPE:
return (uint64_t)constant.i64 <= (uint64_t)other->constant.i64;
case FLOAT32_TYPE:
return constant.f32 <= other->constant.f32;
case FLOAT64_TYPE:
return constant.f64 <= other->constant.f64;
default: XEASSERTALWAYS(); return false;
case INT8_TYPE:
return (uint8_t)constant.i8 <= (uint8_t)other->constant.i8;
case INT16_TYPE:
return (uint16_t)constant.i16 <= (uint16_t)other->constant.i16;
case INT32_TYPE:
return (uint32_t)constant.i32 <= (uint32_t)other->constant.i32;
case INT64_TYPE:
return (uint64_t)constant.i64 <= (uint64_t)other->constant.i64;
case FLOAT32_TYPE:
return constant.f32 <= other->constant.f32;
case FLOAT64_TYPE:
return constant.f64 <= other->constant.f64;
default:
XEASSERTALWAYS();
return false;
}
}
bool IsConstantUGT(Value* other) const {
XEASSERT(flags & VALUE_IS_CONSTANT && other->flags & VALUE_IS_CONSTANT);
switch (type) {
case INT8_TYPE:
return (uint8_t)constant.i8 > (uint8_t)other->constant.i8;
case INT16_TYPE:
return (uint16_t)constant.i16 > (uint16_t)other->constant.i16;
case INT32_TYPE:
return (uint32_t)constant.i32 > (uint32_t)other->constant.i32;
case INT64_TYPE:
return (uint64_t)constant.i64 > (uint64_t)other->constant.i64;
case FLOAT32_TYPE:
return constant.f32 > other->constant.f32;
case FLOAT64_TYPE:
return constant.f64 > other->constant.f64;
default: XEASSERTALWAYS(); return false;
case INT8_TYPE:
return (uint8_t)constant.i8 > (uint8_t)other->constant.i8;
case INT16_TYPE:
return (uint16_t)constant.i16 > (uint16_t)other->constant.i16;
case INT32_TYPE:
return (uint32_t)constant.i32 > (uint32_t)other->constant.i32;
case INT64_TYPE:
return (uint64_t)constant.i64 > (uint64_t)other->constant.i64;
case FLOAT32_TYPE:
return constant.f32 > other->constant.f32;
case FLOAT64_TYPE:
return constant.f64 > other->constant.f64;
default:
XEASSERTALWAYS();
return false;
}
}
bool IsConstantUGE(Value* other) const {
XEASSERT(flags & VALUE_IS_CONSTANT && other->flags & VALUE_IS_CONSTANT);
switch (type) {
case INT8_TYPE:
return (uint8_t)constant.i8 >= (uint8_t)other->constant.i8;
case INT16_TYPE:
return (uint16_t)constant.i16 >= (uint16_t)other->constant.i16;
case INT32_TYPE:
return (uint32_t)constant.i32 >= (uint32_t)other->constant.i32;
case INT64_TYPE:
return (uint64_t)constant.i64 >= (uint64_t)other->constant.i64;
case FLOAT32_TYPE:
return constant.f32 >= other->constant.f32;
case FLOAT64_TYPE:
return constant.f64 >= other->constant.f64;
default: XEASSERTALWAYS(); return false;
case INT8_TYPE:
return (uint8_t)constant.i8 >= (uint8_t)other->constant.i8;
case INT16_TYPE:
return (uint16_t)constant.i16 >= (uint16_t)other->constant.i16;
case INT32_TYPE:
return (uint32_t)constant.i32 >= (uint32_t)other->constant.i32;
case INT64_TYPE:
return (uint64_t)constant.i64 >= (uint64_t)other->constant.i64;
case FLOAT32_TYPE:
return constant.f32 >= other->constant.f32;
case FLOAT64_TYPE:
return constant.f64 >= other->constant.f64;
default:
XEASSERTALWAYS();
return false;
}
}
uint32_t AsUint32();
@@ -397,9 +402,7 @@ public:
bool Compare(Opcode opcode, Value* other);
};
} // namespace hir
} // namespace alloy
#endif // ALLOY_HIR_VALUE_H_