[CODEGEN] Now using atomic_rmw code path for atomic_xchg (#222)
This commit is contained in:
@@ -922,30 +922,9 @@ void generator::visit_atomic_cas_inst(ir::atomic_cas_inst* cas) {
|
||||
vals_[cas][{}] = load(atom_ptr);
|
||||
add_barrier();
|
||||
}
|
||||
/**
|
||||
* \brief Code Generation for `atomic_exch`
|
||||
*/
|
||||
void generator::visit_atomic_exch_inst(ir::atomic_exch_inst* xchg) {
|
||||
BasicBlock *current = builder_->GetInsertBlock();
|
||||
Module *module = current->getModule();
|
||||
Value *rmw_ptr = vals_[xchg->get_operand(0)][{}];
|
||||
Value *rmw_val = vals_[xchg->get_operand(1)][{}];
|
||||
Value *tid = tgt_->get_local_id(module, *builder_, 0);
|
||||
Value *pred = icmp_eq(tid, i32(0));
|
||||
BasicBlock *tid_0_bb = BasicBlock::Create(*ctx_, "tid_0", current->getParent());
|
||||
BasicBlock *tid_0_done_bb = BasicBlock::Create(*ctx_, "tid_0_done", current->getParent());
|
||||
tgt_->add_memfence(module, *builder_);
|
||||
add_barrier();
|
||||
cond_br(pred, tid_0_bb, tid_0_done_bb);
|
||||
builder_->SetInsertPoint(tid_0_bb);
|
||||
atomic_rmw(AtomicRMWInst::Xchg, rmw_ptr, rmw_val, AtomicOrdering::Monotonic, SyncScope::System);
|
||||
br(tid_0_done_bb);
|
||||
builder_->SetInsertPoint(tid_0_done_bb);
|
||||
tgt_->add_memfence(module, *builder_);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Code Generation for `atomic_add`
|
||||
* \brief Code Generation for `atomic_rmw`
|
||||
*/
|
||||
void generator::visit_atomic_rmw_inst(ir::atomic_rmw_inst *atom) {
|
||||
ir::value* ptr = atom->get_operand(0);
|
||||
@@ -1000,6 +979,7 @@ void generator::visit_atomic_rmw_inst(ir::atomic_rmw_inst *atom) {
|
||||
case tt::UMin: name = "min", s_ty = "u"; break;
|
||||
case tt::UMax: name = "max", s_ty = "u"; break;
|
||||
case tt::FAdd: name = "add", s_ty = "f"; break;
|
||||
case tt::Xchg: name = "exch", s_ty = "b"; break;
|
||||
}
|
||||
std::string s_vec = vec == 2 ? "x2" : "";
|
||||
std::string mod = nbits == 32 ? "" : ".noftz";
|
||||
|
@@ -325,10 +325,6 @@ value *builder::create_atomic_cas(value *ptr, value *cmp, value *val){
|
||||
return insert(atomic_cas_inst::create(ptr, cmp, val));
|
||||
}
|
||||
|
||||
value *builder::create_atomic_exch(value *ptr, value *val){
|
||||
return insert(atomic_exch_inst::create(ptr, val));
|
||||
}
|
||||
|
||||
value *builder::create_atomic_rmw(ir::atomic_rmw_op_t op, value *ptr, value *val, value *msk){
|
||||
return insert(atomic_rmw_inst::create(op, ptr, val, msk));
|
||||
}
|
||||
|
@@ -534,10 +534,6 @@ ir::value *dispatch::atomic_cas(ir::value* ptr, ir::value *cmp, ir::value *val,
|
||||
return builder->create_atomic_cas(ptr, cmp, val);
|
||||
}
|
||||
|
||||
ir::value *dispatch::atomic_xchg(ir::value* ptr, ir::value *val, ir::builder *builder){
|
||||
return builder->create_atomic_exch(ptr, val);
|
||||
}
|
||||
|
||||
void atom_red_typechecking(ir::value*& ptr, ir::value *&val, ir::value *&mask, ir::builder *builder){
|
||||
if(!ptr->get_type()->get_scalar_ty()->is_pointer_ty())
|
||||
throw semantic_error("Pointer argument of store instruction is " + ptr->get_type()->repr());
|
||||
@@ -615,6 +611,12 @@ ir::value *dispatch::atomic_xor(ir::value* ptr, ir::value *val, ir::value *mask,
|
||||
return builder->create_atomic_rmw(ir::atomic_rmw_op_t::Xor, ptr, val, mask);
|
||||
}
|
||||
|
||||
ir::value *dispatch::atomic_xchg(ir::value* ptr, ir::value *val, ir::value *mask, ir::builder *builder){
|
||||
atom_red_typechecking(ptr, val, mask, builder);
|
||||
ir::type* sca_ty = val->get_type()->get_scalar_ty();
|
||||
return builder->create_atomic_rmw(ir::atomic_rmw_op_t::Xchg, ptr, val, mask);
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Linear Algebra
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
@@ -757,18 +757,6 @@ instruction* atomic_cas_inst::create(value *ptr, value *cmp, value *val, const s
|
||||
return new atomic_cas_inst(ptr, cmp, val, name, next);
|
||||
}
|
||||
|
||||
// atomic exch
|
||||
|
||||
atomic_exch_inst::atomic_exch_inst(value *ptr, value *val, const std::string &name, instruction *next)
|
||||
: atomic_inst(ptr->get_type()->get_pointer_element_ty(), INST_ATOMIC_EXCH, 2, name, next) {
|
||||
set_operand(0, ptr);
|
||||
set_operand(1, val);
|
||||
}
|
||||
|
||||
instruction* atomic_exch_inst::create(value *ptr, value *val, const std::string &name, instruction *next) {
|
||||
return new atomic_exch_inst(ptr, val, name, next);
|
||||
}
|
||||
|
||||
|
||||
// exp
|
||||
|
||||
|
Reference in New Issue
Block a user