Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Apr 26, 2022
1 parent 27de735 commit 884f4f8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
31 changes: 18 additions & 13 deletions taichi/analysis/gen_offline_cache_key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ enum class ExternalFuncType : std::uint8_t {

class ASTSerializer : public IRVisitor {
public:
ASTSerializer(Program *prog, ExpressionPrinter *expr_printer, std::ostream *os)
: prog_(prog), os_(os), expr_printer_(expr_printer) {
ASTSerializer(Program *prog,
ExpressionPrinter *expr_printer,
std::ostream *os)
: prog_(prog), os_(os), expr_printer_(expr_printer) {
this->allow_undefined_visitor = true;
expr_printer_->set_ostream(os);
}
Expand Down Expand Up @@ -95,7 +97,8 @@ class ASTSerializer : public IRVisitor {
emit(stmt->op_type);
emit(stmt->snode);
std::size_t count = stmt->indices.size();
if (stmt->val.expr) ++count;
if (stmt->val.expr)
++count;
emit(count);
for (const auto &i : stmt->indices.exprs) {
emit(i);
Expand Down Expand Up @@ -184,7 +187,8 @@ class ASTSerializer : public IRVisitor {
}

void visit(FrontendExternalFuncStmt *stmt) override {
// Note: The result of serializing FrontendExternalFuncStmt is not parsable now
// Note: The result of serializing FrontendExternalFuncStmt is not parsable
// now
emit(StmtOpCode::FrontendExternalFuncStmt);
if (stmt->so_func != nullptr) {
emit(ExternalFuncType::SO);
Expand All @@ -201,7 +205,8 @@ class ASTSerializer : public IRVisitor {
}

static void run(Program *prog, IRNode *ast, std::ostream *os) {
// Temporary: using ExpressionOfflineCacheKeyGenerator, which will be refactored
// Temporary: using ExpressionOfflineCacheKeyGenerator, which will be
// refactored
ExpressionOfflineCacheKeyGenerator generator(prog);
ASTSerializer serializer(prog, &generator, os);
ast->accept(&serializer);
Expand All @@ -221,10 +226,10 @@ class ASTSerializer : public IRVisitor {
for (auto &[func, visited] : real_funcs_) {
if (!visited) {
visited = true;
func->ir->accept(this); // Maybe add new func
func->ir->accept(this); // Maybe add new func
}
}
} while(real_funcs_.size() > last_size);
} while (real_funcs_.size() > last_size);
this->set_ostream(curr_os);
expr_printer_->set_ostream(curr_os);
emit(static_cast<std::size_t>(real_funcs_.size()));
Expand All @@ -243,7 +248,7 @@ class ASTSerializer : public IRVisitor {
emit_bytes(string_pool_.data(), string_pool_.size());
}

template<typename T>
template <typename T>
void emit_pod(const T &val) {
static_assert(std::is_pod<T>::value);
TI_ASSERT(os_);
Expand All @@ -255,7 +260,7 @@ class ASTSerializer : public IRVisitor {
os_->write(bytes, len);
}

template<typename K, typename V>
template <typename K, typename V>
void emit(const std::unordered_map<K, V> &map) {
emit(static_cast<std::size_t>(map.size()));
for (const auto &[k, v] : map) {
Expand All @@ -264,13 +269,13 @@ class ASTSerializer : public IRVisitor {
}
}

template<typename T1, typename T2>
template <typename T1, typename T2>
void emit(const std::pair<T1, T2> &pair) {
emit(pair.first);
emit(pair.second);
}

template<typename K, typename V>
template <typename K, typename V>
void emit(const std::map<K, V> &map) {
emit(static_cast<std::size_t>(map.size()));
for (const auto &[k, v] : map) {
Expand Down Expand Up @@ -421,8 +426,8 @@ class ASTSerializer : public IRVisitor {
Program *prog_{nullptr};
std::ostream *os_{nullptr};
ExpressionPrinter *expr_printer_{nullptr};
std::unordered_set<SNode*> snode_tree_roots_;
std::unordered_map<Function*, bool> real_funcs_;
std::unordered_set<SNode *> snode_tree_roots_;
std::unordered_map<Function *, bool> real_funcs_;
std::vector<char> string_pool_;
};

Expand Down
3 changes: 1 addition & 2 deletions taichi/analysis/offline_cache_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ std::string get_hashed_offline_cache_key(CompileConfig *config,
std::string kernel_ast_string;
if (kernel) {
std::ostringstream oss;
gen_offline_cache_key(kernel->program, kernel->ir.get(),
&oss);
gen_offline_cache_key(kernel->program, kernel->ir.get(), &oss);
kernel_ast_string = oss.str();
}

Expand Down
2 changes: 1 addition & 1 deletion taichi/inc/frontend_statements.inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ PER_STATEMENT(FrontendEvalStmt)
PER_STATEMENT(FrontendSNodeOpStmt) // activate, deactivate, append, clear
PER_STATEMENT(FrontendAssertStmt)
PER_STATEMENT(FrontendFuncDefStmt)
PER_STATEMENT(FrontendReturnStmt)
PER_STATEMENT(FrontendReturnStmt)

0 comments on commit 884f4f8

Please sign in to comment.