Skip to content

Commit dfd1c30

Browse files
committed
lint: resolve clang-tidy errors
1 parent 6b9dd88 commit dfd1c30

File tree

10 files changed

+38
-30
lines changed

10 files changed

+38
-30
lines changed

.clang-tidy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
---
22
InheritParentConfig: true
3+
ExtraArgs: ['-v']
34
FormatStyle: file
45
UseColor: true
56
WarningsAsErrors: '*'
6-
HeaderFilterRegex: '^(?!.*(3rdparty|build)).*$'
7+
ExcludeHeaderFilterRegex: '^(3rdparty|tvm)/.*$'
78

89
# NOTE: there must be no spaces before the '-', so put the comma last.
910
Checks: >-

src/layout/utils.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Array<IterSplitExpr> DivideUnusedIterators(const Array<PrimExpr> &exprs,
134134
for (const IterVar &iter : input_iters) {
135135
IterMark iv_mark;
136136
for (const IterMark &mark : collector.visited_) {
137-
if (mark->source.as<Var>()->same_as(iter->var)) {
137+
if (mark->source.as<Var>()->same_as(iter->var)) { // NOLINT(*)
138138
iv_mark = mark;
139139
break;
140140
}

src/runtime/runtime.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ template <typename T> static std::string ArrayToStr(const T *ptr, size_t n) {
2020
for (size_t i = 0; i < n; i++) {
2121
if (i > 0)
2222
ss << ", ";
23-
ss << ptr[i];
23+
ss << ptr[i]; // NOLINT(clang-analyzer-security.ArrayBound)
2424
}
2525
ss << "]";
2626
return ss.str();

src/target/codegen_webgpu.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ CodeGenTileLangWebGPU::AddFunction(const PrimFunc &f, bool skip_readonly_decl) {
218218
this->decl_stream << "\nstruct " << type_pod_args << " {\n";
219219

220220
for (size_t i = 0; i < pod_args.size(); ++i) {
221-
Var v = pod_args[i];
221+
const Var &v = pod_args[i];
222222
ICHECK(!v.dtype().is_handle());
223223
std::string vid = AllocVarID(v.get());
224224

src/transform/layout_inference.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@ class BufferUseDefCollector : public IRVisitorWithAnalyzer {
131131
ICHECK(dst_layout_opt.has_value())
132132
<< "Failed to cast layout to Fragment for buffer " << buffer
133133
<< ", layout type is " << layout->GetTypeKey();
134-
auto dst_layout = dst_layout_opt.value();
134+
const auto &dst_layout = dst_layout_opt.value();
135135
auto src_layout_opt = layout_map[buffer].as<Fragment>();
136136
ICHECK(src_layout_opt.has_value())
137137
<< "Failed to cast layout_map[buffer] to Fragment for buffer "
138138
<< buffer << ", layout type is "
139139
<< layout_map[buffer]->GetTypeKey();
140-
auto src_layout = src_layout_opt.value();
140+
const auto &src_layout = src_layout_opt.value();
141141
ICHECK(dst_layout->InputDim() == src_layout->InputDim());
142142
Array<PrimExpr> indices;
143143
indices.reserve(dst_layout->InputDim());
@@ -398,7 +398,7 @@ class BufferUseDefCollector : public IRVisitorWithAnalyzer {
398398
<< call->args[1]->GetTypeKey();
399399
return std::nullopt;
400400
}
401-
auto var = var_opt.value();
401+
const auto &var = var_opt.value();
402402
return buffer_data_to_buffer_[var];
403403
} else if (call->op.same_as(RegionOp::Get())) {
404404
return call->args[0].as<BufferLoadNode>()->buffer;

src/transform/layout_reducer.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class ReducerLayoutAnnotator : public IRMutatorWithAnalyzer {
209209

210210
auto opt_buffer = var_to_buffer_.Get(reducer_var);
211211
ICHECK(opt_buffer);
212-
auto buffer = opt_buffer.value();
212+
const auto &buffer = opt_buffer.value();
213213
Fragment f;
214214
if (info->rep == ReducerRepType::ALL) {
215215
f = Fragment(buffer->shape, {}, ReplicationPlaceholder(),

src/transform/lower_thread_allreduce.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,9 @@ class ThreadAllreduceBuilder final : public StmtExprMutator {
496496
if (reduce_extent == 1) {
497497
// special case, no reduction is needed.
498498
std::vector<Stmt> stores;
499+
stores.reserve(size);
499500
for (size_t i = 0; i < size; ++i) {
500-
stores.push_back(BufferStore(buffers[i], values[i], {0}));
501+
stores.emplace_back(BufferStore(buffers[i], values[i], {0}));
501502
}
502503
return SeqStmt::Flatten(stores);
503504
}
@@ -604,7 +605,7 @@ class ThreadAllreduceBuilder final : public StmtExprMutator {
604605
// Load reduction values, no synchronization needed.
605606
Array<PrimExpr> a, b;
606607
for (int i = 0; i < n_buffers; ++i) {
607-
Buffer shared_buf = shared_bufs[i];
608+
const Buffer &shared_buf = shared_bufs[i];
608609
BufferLoad val(shared_buf, zero_indices);
609610
ICHECK_EQ(val->dtype, dtypes[i]);
610611
a.push_back(val);
@@ -623,7 +624,7 @@ class ThreadAllreduceBuilder final : public StmtExprMutator {
623624
// branch with a warp sync call inside.
624625
PrimExpr other = WarpShuffle(builtin::tvm_warp_shuffle_down(),
625626
mask_buffer, val, offset);
626-
Buffer local_buf = local_bufs[i];
627+
const Buffer &local_buf = local_bufs[i];
627628
Stmt s = BufferStore(local_buf, other, zero_indices);
628629
seq->push_back(s);
629630

@@ -639,7 +640,7 @@ class ThreadAllreduceBuilder final : public StmtExprMutator {
639640
std::vector<Stmt> stores;
640641
stores.reserve(n_buffers);
641642
for (int i = 0; i < n_buffers; ++i) {
642-
Buffer buf = shared_bufs[i];
643+
const Buffer &buf = shared_bufs[i];
643644
stores.push_back(BufferStore(buf, ret[i], zero_indices));
644645
}
645646

src/transform/make_packed_api.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ tvm::transform::Pass MakePackedAPI() {
477477
Map<GlobalVar, String> packed_func_methods;
478478
for (const auto &[gvar, base_func] : mod->functions) {
479479
if (auto opt = base_func.as<PrimFunc>()) {
480-
auto prim_func = opt.value();
480+
const auto &prim_func = opt.value();
481481
if (auto global_symbol = RequiresPackedAPI(prim_func)) {
482482
packed_func_methods.Set(gvar, global_symbol.value());
483483
}

src/transform/storage_access.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ void TileLangStorageAccessVisitor::VisitStmt_(const ForNode *op) {
209209
bool IsThreadInvariant(const PrimExpr &cond) {
210210
if (auto call = cond.as<CallNode>()) {
211211
if (auto opt_call_op = call->op.as<Op>()) {
212-
auto call_op = opt_call_op.value();
212+
const auto &call_op = opt_call_op.value();
213213
if (call_op.same_as(builtin::tvm_thread_invariant())) {
214214
return true;
215215
}

src/transform/warp_specialized_rewriter.cc

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -530,10 +530,11 @@ class GroupOpRewriter : public StmtExprMutator {
530530
block_stmt.push_back(block->body);
531531
cur_id++;
532532
}
533-
new_body.push_back(MakeGroupBlock(block_stmt.size() == 1
534-
? block_stmt[0]
535-
: SeqStmt(std::move(block_stmt)),
536-
annotations));
533+
new_body.push_back(MakeGroupBlock(
534+
block_stmt.size() == 1 ? block_stmt[0]
535+
// NOLINTNEXTLINE(performance-move-const-arg)
536+
: SeqStmt(std::move(block_stmt)),
537+
annotations));
537538
}
538539
Array<Integer> order_anno;
539540
Array<Integer> stage_anno;
@@ -697,10 +698,12 @@ class WSCodeEmitter : public StmtMutator {
697698
continue;
698699
if (marker_.GetRole(op->seq[i]) == Role::kBoth) {
699700
block_stmt.push_back(seq_transformed[i]);
700-
new_body.push_back(MakeGroupBlock(
701-
block_stmt.size() == 1 ? block_stmt[0]
702-
: SeqStmt(std::move(block_stmt)),
703-
annotations));
701+
new_body.push_back(
702+
MakeGroupBlock(block_stmt.size() == 1
703+
? block_stmt[0]
704+
// NOLINTNEXTLINE(performance-move-const-arg)
705+
: SeqStmt(std::move(block_stmt)),
706+
annotations));
704707
continue;
705708
}
706709
}
@@ -734,10 +737,12 @@ class WSCodeEmitter : public StmtMutator {
734737
}
735738
}
736739
collector.Clear();
737-
new_body.push_back(MakeGroupBlock(
738-
block_stmt.size() == 1 ? block_stmt[0]
739-
: SeqStmt(std::move(block_stmt)),
740-
annotations));
740+
new_body.push_back(
741+
MakeGroupBlock(block_stmt.size() == 1
742+
? block_stmt[0]
743+
// NOLINTNEXTLINE(performance-move-const-arg)
744+
: SeqStmt(std::move(block_stmt)),
745+
annotations));
741746
}
742747
}
743748
} else { // consumer case
@@ -766,10 +771,11 @@ class WSCodeEmitter : public StmtMutator {
766771
}
767772
}
768773
}
769-
new_body.push_back(MakeGroupBlock(block_stmt.size() == 1
770-
? block_stmt[0]
771-
: SeqStmt(std::move(block_stmt)),
772-
annotations));
774+
new_body.push_back(MakeGroupBlock(
775+
block_stmt.size() == 1 ? block_stmt[0]
776+
// NOLINTNEXTLINE(performance-move-const-arg)
777+
: SeqStmt(std::move(block_stmt)),
778+
annotations));
773779
}
774780
// Filter out the producer stmts
775781
int cur_id = 0;

0 commit comments

Comments
 (0)