Skip to content

Commit 3d41ac3

Browse files
authored
[Refactor] Replace std::tie with structured bindings (#12610)
* [Refactor] Replace std::tie with structured bindings With C++17 enabled in #12337, using structured bindings to replace cases where `std::tie` is used to define local variables. * Added missing header for <optional> * Silenced unused variable warnings after structured bindings This is a bug in gcc version 7, resolved in gcc 8. While gcc version 7 is used for CI, we'll need to silence unused variable warnings resulting from using only part of a structured binding. More information: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81767
1 parent 648a29a commit 3d41ac3

35 files changed

+105
-185
lines changed

src/auto_scheduler/auto_schedule.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ TVM_REGISTER_GLOBAL("auto_scheduler.TuningOptions")
7878

7979
TVM_REGISTER_GLOBAL("auto_scheduler.AutoSchedule")
8080
.set_body_typed([](SearchPolicy search_policy, TuningOptions tuning_options) {
81-
te::Schedule sch;
82-
Array<te::Tensor> return_tensors;
83-
std::tie(sch, return_tensors) = AutoSchedule(search_policy, tuning_options);
81+
auto [sch, return_tensors] = AutoSchedule(search_policy, tuning_options);
8482
return Array<ObjectRef>{sch, return_tensors};
8583
});
8684
} // namespace auto_scheduler

src/auto_scheduler/compute_dag.cc

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,10 +1325,9 @@ State ComputeDAG::InferBound(const State& state) const {
13251325

13261326
Array<te::Stage> stages;
13271327
StageToAxesMap stage_to_axes;
1328-
te::Schedule sch;
1329-
Array<te::Tensor> tensors;
13301328
// Replay steps to tvm::Schedule
1331-
std::tie(sch, tensors) = ApplySteps(pstate->transform_steps, &stages, &stage_to_axes);
1329+
auto [sch, tensors] = ApplySteps(pstate->transform_steps, &stages, &stage_to_axes);
1330+
(void)tensors; // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81767
13321331
sch = sch.normalize_for_feature_extraction();
13331332
// Get bound information from TVM schedule
13341333
Map<IterVar, Range> bounds = te::InferBound(sch);
@@ -1382,9 +1381,8 @@ Array<State> ComputeDAG::InferBound(const Array<State>& states) const {
13821381
}
13831382

13841383
ComputeDAG ComputeDAG::ReplayAndGetDAG(const Array<Step>& transform_steps) const {
1385-
te::Schedule sch;
1386-
Array<te::Tensor> old_tensors;
1387-
std::tie(sch, old_tensors) = ApplySteps(transform_steps);
1384+
auto [sch, old_tensors] = ApplySteps(transform_steps);
1385+
(void)old_tensors; // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81767
13881386
return ComputeDAG(sch);
13891387
}
13901388

@@ -1481,11 +1479,8 @@ TVM_REGISTER_GLOBAL("auto_scheduler.ComputeDAG")
14811479

14821480
TVM_REGISTER_GLOBAL("auto_scheduler.ComputeDAGApplyStepsFromState")
14831481
.set_body_typed([](const ComputeDAG& dag, const State& state, int layout_rewrite) {
1484-
te::Schedule sch;
1485-
Array<te::Tensor> return_tensors;
1486-
std::tie(sch, return_tensors) =
1487-
dag.ApplySteps(state->transform_steps, nullptr, nullptr,
1488-
static_cast<LayoutRewriteOption>(layout_rewrite));
1482+
auto [sch, return_tensors] = dag.ApplySteps(state->transform_steps, nullptr, nullptr,
1483+
static_cast<LayoutRewriteOption>(layout_rewrite));
14891484
return Array<ObjectRef>{sch, return_tensors};
14901485
});
14911486

src/auto_scheduler/feature.cc

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -952,9 +952,7 @@ class PerStoreFeatureExtractor : public StmtExprVisitor {
952952
unique_lines = std::max(unique_lines, 1.0f);
953953
}
954954

955-
ReuseType reuse_type;
956-
float reuse_dis_iter, reuse_dis_bytes, reuse_ct;
957-
std::tie(reuse_type, reuse_dis_iter, reuse_dis_bytes, reuse_ct) =
955+
auto [reuse_type, reuse_dis_iter, reuse_dis_bytes, reuse_ct] =
958956
ComputeReuse(t, acc.indices, for_loop_stack_, for_touch_regions_, ana_);
959957

960958
acc_feas.emplace_back();
@@ -1356,10 +1354,7 @@ void GetPerStoreFeatureName(int max_n_bufs, std::vector<std::string>* ret) {
13561354

13571355
void GetPerStoreFeaturesWorkerFunc(const SearchTask& task, const State& state, int max_n_bufs,
13581356
std::vector<float>* feature, std::atomic<int>* error_ct) {
1359-
te::Schedule sch;
1360-
Array<te::Tensor> tensors;
1361-
1362-
std::tie(sch, tensors) = task->compute_dag.ApplySteps(state->transform_steps);
1357+
auto [sch, tensors] = task->compute_dag.ApplySteps(state->transform_steps);
13631358

13641359
// When inlining, replace const matrices with const values.
13651360
// Produces wrong IR, but good enough for feature extraction, and

src/auto_scheduler/search_policy/search_policy.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,7 @@ TVM_REGISTER_GLOBAL("auto_scheduler.SearchPolicyRunCallbacks")
106106

107107
TVM_REGISTER_GLOBAL("auto_scheduler.SearchPolicyContinueSearchOneRound")
108108
.set_body_typed([](SearchPolicy policy, int num_measure, ProgramMeasurer measurer) {
109-
Array<MeasureInput> inputs;
110-
Array<MeasureResult> results;
111-
std::tie(inputs, results) = policy->ContinueSearchOneRound(num_measure, measurer);
109+
auto [inputs, results] = policy->ContinueSearchOneRound(num_measure, measurer);
112110
return Array<ObjectRef>{inputs, results};
113111
});
114112

src/auto_scheduler/search_policy/sketch_policy_rules.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,7 @@ SketchGenerationRule::ConditionKind RuleCrossThreadReduction::MeetCondition(
343343
const auto& op = state->stages[stage_id]->op;
344344
if (op->IsInstance<te::ComputeOpNode>()) {
345345
// Compute the product of lengths of all space iters and all reduce iters
346-
int cum_space_len, cum_reduce_len;
347-
std::tie(cum_space_len, cum_reduce_len) =
346+
auto [cum_space_len, cum_reduce_len] =
348347
GetCumulativeSpaceAndReductionLength(state->stages[stage_id]);
349348

350349
if (NeedsMultilevelTiling(policy.search_task, state, stage_id)) {

src/ir/instrument.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,7 @@ String RenderPassProfiles() {
288288
os << std::fixed;
289289

290290
while (profiles.size() > 0) {
291-
size_t depth;
292-
PassProfile::Duration parent_duration;
293-
PassProfile* profile;
294-
std::tie(depth, parent_duration, profile) = profiles.top();
291+
auto [depth, parent_duration, profile] = profiles.top();
295292
profiles.pop();
296293

297294
// indent depth

src/meta_schedule/database/json_database.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ class JSONDatabaseNode : public DatabaseNode {
115115

116116
Workload CommitWorkload(const IRModule& mod) {
117117
// Try to insert `mod` into `workloads_`
118-
decltype(this->workloads2idx_)::iterator it;
119-
bool inserted = false;
120-
std::tie(it, inserted) =
118+
auto [it, inserted] =
121119
this->workloads2idx_.emplace(Workload(mod, tvm::StructuralHash()(mod)), -1);
122120
Workload workload = it->first;
123121
// If `mod` is new in `workloads2idx_`, append it to the workload file

src/meta_schedule/mutator/mutate_compute_location.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,7 @@ std::vector<MutateComputeLocationNode::Candidate> MutateComputeLocationNode::Fin
8686
int old_decision = Downcast<Integer>(decision)->value;
8787

8888
// Step 2. Collect all the compute_at locations.
89-
Array<tir::StmtSRef> location_srefs;
90-
std::vector<int> location_indices;
91-
std::tie(location_srefs, location_indices) = CollectComputeLocation(sch->state(), block_sref);
89+
auto [location_srefs, location_indices] = CollectComputeLocation(sch->state(), block_sref);
9290
// Step 3. Remove the old decision.
9391
auto it = std::find(location_indices.begin(), location_indices.end(), old_decision);
9492
if (it != location_indices.end()) {

src/meta_schedule/schedule_rule/cross_thread_reduction.cc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,11 @@ class CrossThreadReductionNode : public ScheduleRuleNode {
6464
// Step 2. Check the opportunity for block fusion. We say "fusible", if we can compute-at the
6565
// block to its consumers. We want to fuse as much as possible because it results in
6666
// significantly faster schedule.
67-
bool fusible = false;
6867
// `target_loop` is the loop position where the input block will be computed at.
69-
tir::LoopRV target_loop{nullptr};
7068
// `target_block` is the consumer block that we want to compute-at the input block to.
71-
tir::BlockRV target_block{nullptr};
7269
// `tgt_block_innermost_loop` is the innermost loop outside the target block.
73-
tir::LoopRV tgt_block_innermost_loop{nullptr};
7470

75-
std::tie(fusible, target_loop, target_block, tgt_block_innermost_loop) =
71+
auto [fusible, target_loop, target_block, tgt_block_innermost_loop] =
7672
GetComputeTargetLoopAndBlock(tmp_sch, block_rv);
7773

7874
// Step 3. Try block fusion.

src/meta_schedule/space_generator/post_order_apply.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,7 @@ class PostOrderApplyNode : public SpaceGeneratorNode {
140140
result.clear();
141141
while (!stack.empty()) {
142142
// get the stack.top()
143-
tir::Schedule sch;
144-
Array<tir::BlockRV> blocks;
145-
std::tie(sch, blocks) = stack.back();
143+
auto [sch, blocks] = stack.back();
146144
stack.pop_back();
147145
// if all blocks are visited
148146
if (blocks.empty()) {

0 commit comments

Comments
 (0)