Skip to content

Commit

Permalink
[refactor] Remove redundant codegen of BitExtractStmt
Browse files Browse the repository at this point in the history
  • Loading branch information
strongoier committed Sep 22, 2022
1 parent 79f2a6a commit b32a8f5
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 37 deletions.
6 changes: 0 additions & 6 deletions taichi/codegen/cc/codegen_cc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,6 @@ class CCTransformer : public IRVisitor {
stmt->tb);
}

void visit(BitExtractStmt *stmt) override {
emit("{} = (({} >> {}) & ((1 << {}) - 1));",
define_var("Ti_i32", stmt->raw_name()), stmt->input->raw_name(),
stmt->bit_begin, stmt->bit_end - stmt->bit_begin);
}

std::string define_var(std::string const &type, std::string const &name) {
if (C90_COMPAT) {
emit_header("{} {};", type, name);
Expand Down
7 changes: 0 additions & 7 deletions taichi/codegen/llvm/codegen_llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1572,13 +1572,6 @@ void TaskCodeGenLLVM::visit(GetRootStmt *stmt) {
0));
}

void TaskCodeGenLLVM::visit(BitExtractStmt *stmt) {
int mask = (1u << (stmt->bit_end - stmt->bit_begin)) - 1;
llvm_val[stmt] = builder->CreateAnd(
builder->CreateLShr(llvm_val[stmt->input], stmt->bit_begin),
tlctx->get_constant(mask));
}

void TaskCodeGenLLVM::visit(LinearizeStmt *stmt) {
llvm::Value *val = tlctx->get_constant(0);
for (int i = 0; i < (int)stmt->inputs.size(); i++) {
Expand Down
2 changes: 0 additions & 2 deletions taichi/codegen/llvm/codegen_llvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,6 @@ class TaskCodeGenLLVM : public IRVisitor, public LLVMModuleBuilder {

void visit(GetRootStmt *stmt) override;

void visit(BitExtractStmt *stmt) override;

void visit(LinearizeStmt *stmt) override;

void visit(IntegerOffsetStmt *stmt) override;
Expand Down
6 changes: 0 additions & 6 deletions taichi/codegen/metal/codegen_metal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,6 @@ class KernelCodegenImpl : public IRVisitor {
emit(R"(auto {} = {};)", stmt->raw_name(), val);
}

void visit(BitExtractStmt *stmt) override {
emit(R"(auto {} = (({} >> {}) & ((1 << {}) - 1));)", stmt->raw_name(),
stmt->input->raw_name(), stmt->bit_begin,
stmt->bit_end - stmt->bit_begin);
}

void visit(SNodeLookupStmt *stmt) override {
const auto *sn = stmt->snode;
std::string parent;
Expand Down
16 changes: 0 additions & 16 deletions taichi/codegen/spirv/spirv_codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,22 +460,6 @@ class TaskCodegen : public IRVisitor {
ir_->register_value(stmt->raw_name(), val);
}

void visit(BitExtractStmt *stmt) override {
spirv::Value input_val = ir_->query_value(stmt->input->raw_name());
auto stype = input_val.stype;
spirv::Value tmp0 = ir_->int_immediate_number(stype, stmt->bit_begin);
spirv::Value tmp1 =
ir_->int_immediate_number(stype, stmt->bit_end - stmt->bit_begin);
spirv::Value tmp2 =
ir_->make_value(spv::OpShiftRightArithmetic, stype, input_val, tmp0);
spirv::Value tmp3 =
ir_->make_value(spv::OpShiftLeftLogical, stype,
ir_->int_immediate_number(stype, 1), tmp1);
spirv::Value tmp4 = ir_->sub(tmp3, ir_->int_immediate_number(stype, 1));
spirv::Value val = ir_->make_value(spv::OpBitwiseAnd, stype, tmp2, tmp4);
ir_->register_value(stmt->raw_name(), val);
}

void visit(LoopIndexStmt *stmt) override {
const auto stmt_name = stmt->raw_name();
if (stmt->loop->is<OffloadedStmt>()) {
Expand Down

0 comments on commit b32a8f5

Please sign in to comment.