simple constexpr

This commit is contained in:
Philippe Tillet
2019-08-05 13:06:56 -07:00
parent d869d9a924
commit 899b2b72e1
9 changed files with 96 additions and 21 deletions

View File

@@ -148,10 +148,20 @@ DEFINE_UNARY_FLOAT(fneg)
value* builder::create_insert_nuwnswb_binop(binary_operator::op_t op, value *lhs,
value *rhs, const std::string &name,
bool has_nuw, bool has_nsw) {
binary_operator* result = insert(binary_operator::create(op, lhs, rhs), name);
if (has_nuw) result->set_has_no_unsigned_wrap();
if (has_nsw) result->set_has_no_signed_wrap();
return result;
if(auto *clhs = dynamic_cast<constant_int*>(lhs)){
if(auto *crhs = dynamic_cast<constant_int*>(rhs)){
constant_expression* result = constant_expression::create(op, clhs, crhs);
if (has_nuw) result->set_has_no_unsigned_wrap();
if (has_nsw) result->set_has_no_signed_wrap();
return result;
}
}
else {
binary_operator* result = insert(binary_operator::create(op, lhs, rhs), name);
if (has_nuw) result->set_has_no_unsigned_wrap();
if (has_nsw) result->set_has_no_signed_wrap();
return result;
}
}
#define DEFINE_NOWRAP_BINARY(SUFFIX, OPCODE)\
@@ -161,7 +171,7 @@ value* builder::create_insert_nuwnswb_binop(binary_operator::op_t op, value *lhs
#define DEFINE_BINARY_INT(SUFFIX, OPCODE)\
value *builder::create_ ## SUFFIX(value *lhs, value *rhs, const std::string &name){\
return insert(binary_operator::create(OPCODE, lhs, rhs), name);\
return create_insert_nuwnswb_binop(OPCODE, lhs, rhs, name, false, false);\
}
#define DEFINE_UNARY_INT(SUFFIX)\