Use unique_ptr in ir::context_impl (#462)

Co-authored-by: Philippe Tillet <Phil.Tillet@gmail.com>
This commit is contained in:
daadaada
2022-02-25 08:07:10 +08:00
committed by GitHub
parent 98ed7db8c1
commit d9dd97492f
4 changed files with 24 additions and 28 deletions

View File

@@ -47,10 +47,10 @@ constant_int *constant_int::get(type *ty, uint64_t value) {
if (!ty->is_integer_ty())
throw std::runtime_error("Cannot create constant_int with non integer ty");
context_impl *impl = ty->get_context().p_impl.get();
constant_int *& cst = impl->int_constants_[std::make_pair(ty, value)];
if(cst == nullptr)
cst = new constant_int(ty, value);
return cst;
std::unique_ptr<constant_int> &cst = impl->int_constants_[std::make_pair(ty, value)];
if(!cst)
cst.reset(new constant_int(ty, value));
return cst.get();
}
@@ -73,10 +73,10 @@ constant *constant_fp::get_zero_value_for_negation(type *ty) {
constant *constant_fp::get(type *ty, double v){
context_impl *impl = ty->get_context().p_impl.get();
constant_fp *&result = impl->fp_constants_[std::make_pair(ty, v)];
std::unique_ptr<constant_fp> &result = impl->fp_constants_[std::make_pair(ty, v)];
if(!result)
result = new constant_fp(ty, v);
return result;
result.reset(new constant_fp(ty, v));
return result.get();
}
@@ -86,10 +86,10 @@ undef_value::undef_value(type *ty)
undef_value *undef_value::get(type *ty) {
context_impl *impl = ty->get_context().p_impl.get();
undef_value *&result = impl->uv_constants_[ty];
std::unique_ptr<undef_value> &result = impl->uv_constants_[ty];
if(!result)
result = new undef_value(ty);
return result;
result.reset(new undef_value(ty));
return result.get();
}
/* global value */

View File

@@ -167,10 +167,10 @@ pointer_type* pointer_type::get(type *elt_ty, unsigned address_space){
assert(is_valid_elt_ty(elt_ty) && "Invalid type for pointer element!");
// look-up
context_impl *impl = elt_ty->get_context().p_impl.get();
pointer_type *&entry = impl->ptr_tys[std::make_pair(elt_ty, address_space)];
std::unique_ptr<pointer_type> &entry = impl->ptr_tys[std::make_pair(elt_ty, address_space)];
if(!entry)
entry = new pointer_type(elt_ty, address_space);
return entry;
entry.reset(new pointer_type(elt_ty, address_space));
return entry.get();
}
//===----------------------------------------------------------------------===//
@@ -217,10 +217,10 @@ block_type* block_type::get(type *elt_ty, const block_shapes_t &shapes) {
assert(is_valid_elt_ty(elt_ty) && "Invalid type for tile element!");
// look-up
context_impl *impl = elt_ty->get_context().p_impl.get();
block_type *&entry = impl->block_tys[std::make_pair(elt_ty, shapes)];
std::unique_ptr<block_type> &entry = impl->block_tys[std::make_pair(elt_ty, shapes)];
if(!entry)
entry = new block_type(elt_ty, shapes);
return entry;
entry.reset(new block_type(elt_ty, shapes));
return entry.get();
}
block_type* block_type::get_same_shapes(type *ty, type *ref){