Skip to content

Commit 18b37bb

Browse files
Skylion007pytorchmergebot
authored andcommitted
Clang-Tidy: Improve tensorexpr headers with additional std::moves (pytorch#91572)
Splitting pytorch#91559 into smaller pieces Pull Request resolved: pytorch#91572 Approved by: https://github.com/ezyang
1 parent 3d17728 commit 18b37bb

20 files changed

+178
-147
lines changed

c10/core/WrapDimMinimal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ T _maybe_wrap_dim(T dim, T dim_post_expr, bool wrap_scalar = true) {
2424
return dim;
2525
}
2626
// Check edge-cases out-of-line (wrapping scalars and out-of-bounds errors)
27-
return c10::detail::maybe_wrap_dim_slow<T>(dim, dim_post_expr, wrap_scalar);
27+
return c10::detail::maybe_wrap_dim_slow<T>(
28+
std::move(dim), std::move(dim_post_expr), wrap_scalar);
2829
}
2930

3031
inline int64_t maybe_wrap_dim(

torch/csrc/jit/api/object.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include <c10/util/Optional.h>
66
#include <torch/csrc/jit/api/method.h>
77

8+
#include <utility>
9+
810
namespace torch {
911
namespace jit {
1012

@@ -130,7 +132,8 @@ struct TORCH_API Object {
130132
if (prop.setter) {
131133
setter = Method(_ivalue(), prop.setter);
132134
}
133-
return Property{prop.name, Method(_ivalue(), prop.getter), setter};
135+
return Property{
136+
prop.name, Method(_ivalue(), prop.getter), std::move(setter)};
134137
}
135138
}
136139
AT_ERROR("Property '", name, "' is not defined.");
@@ -142,7 +145,8 @@ struct TORCH_API Object {
142145
if (prop.setter) {
143146
setter = Method(_ivalue(), prop.setter);
144147
}
145-
return Property{prop.name, Method(_ivalue(), prop.getter), setter};
148+
return Property{
149+
prop.name, Method(_ivalue(), prop.getter), std::move(setter)};
146150
});
147151
}
148152

torch/csrc/jit/frontend/source_range.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ struct TORCH_API Source {
300300
// A SourceRange is a reference to subset of a Source, specified by `start` and
301301
// `end` byte offsets into the source text.
302302
struct TORCH_API SourceRange {
303-
SourceRange(std::shared_ptr<Source> source_view_, size_t start_, size_t end_)
304-
: source_view_(std::move(source_view_)), start_(start_), end_(end_) {
303+
SourceRange(std::shared_ptr<Source> source_view, size_t start_, size_t end_)
304+
: source_view_(std::move(source_view)), start_(start_), end_(end_) {
305305
if (source_view_) {
306306
start_iter_ = source_view_->text_str().iter_for_pos(start_);
307307
}

torch/csrc/jit/frontend/tree_views.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <functional>
99
#include <iostream>
1010
#include <string>
11+
#include <utility>
1112

1213
namespace torch {
1314
namespace jit {
@@ -358,8 +359,8 @@ struct Param : public TreeView {
358359
bool kwarg_only) {
359360
TreeRef kwarg_only_tree =
360361
Compound::create(kwarg_only ? TK_TRUE : TK_FALSE, range, {});
361-
return Param(
362-
Compound::create(TK_PARAM, range, {ident, type, def, kwarg_only_tree}));
362+
return Param(Compound::create(
363+
TK_PARAM, range, {ident, type, def, std::move(kwarg_only_tree)}));
363364
}
364365
Ident ident() const {
365366
return Ident(subtree(0));

torch/csrc/jit/python/pybind_utils.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ inline InferredType tryToInferType(py::handle input) {
341341
auto enum_type = py::cast<TypePtr>(
342342
py::module::import("torch.jit.annotations")
343343
.attr("try_ann_to_type")(enum_class, SourceRange()));
344-
return InferredType(enum_type);
344+
return InferredType(std::move(enum_type));
345345
}
346346

347347
py::bool_ isClass =
@@ -387,7 +387,7 @@ inline InferredType tryToInferType(py::handle input) {
387387
auto class_type = py::cast<ClassTypePtr>(script_class);
388388

389389
if (class_type && !class_type->is_module()) {
390-
return InferredType(class_type);
390+
return InferredType(std::move(class_type));
391391
}
392392
}
393393
}
@@ -432,7 +432,7 @@ inline InferredType tryToInferContainerType(py::handle input) {
432432
return type_match.reason();
433433
}
434434
}
435-
return InferredType(TupleType::create(element_types));
435+
return InferredType(TupleType::create(std::move(element_types)));
436436
} else if (PyDict_Check(input.ptr())) {
437437
// Check to make sure we can generate useful input/output types
438438
auto dict = py::cast<py::dict>(input);
@@ -478,7 +478,8 @@ inline InferredType tryToInferContainerType(py::handle input) {
478478
key_type = *unified_key;
479479
value_type = *unified_value;
480480
}
481-
return InferredType(DictType::create(key_type, value_type));
481+
return InferredType(
482+
DictType::create(std::move(key_type), std::move(value_type)));
482483
} else if (PyList_Check(input.ptr())) {
483484
auto list = py::cast<py::list>(input);
484485
size_t len = py::len(list);
@@ -581,7 +582,7 @@ inline IValue createGenericList(py::handle obj, const TypePtr& elem_type) {
581582
for (auto elem : obj) {
582583
elems.push_back(toIValue(elem, elem_type));
583584
}
584-
return IValue(std::move(elems));
585+
return IValue(elems);
585586
}
586587

587588
inline IValue createGenericDict(
@@ -594,7 +595,7 @@ inline IValue createGenericDict(
594595
elems.insert(
595596
toIValue(entry.first, key_type), toIValue(entry.second, value_type));
596597
}
597-
return IValue(std::move(elems));
598+
return IValue(elems);
598599
}
599600

600601
template <class T>

torch/csrc/jit/runtime/operator.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,10 @@ struct TORCH_API Operator {
231231
std::vector<Argument> returns,
232232
AliasAnalysisKind alias_analysis) {
233233
auto result = FunctionSchema(
234-
name,
235-
overload_name,
236-
arguments,
237-
returns,
234+
std::move(name),
235+
std::move(overload_name),
236+
std::move(arguments),
237+
std::move(returns),
238238
/*is_vararg*/ false,
239239
/*is_varret*/ false);
240240
result.setAliasAnalysis(alias_analysis);

torch/csrc/jit/serialization/pickler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ inline void setTensorMetadata(
348348
auto key = *pair.key().toString();
349349
metadata[key] = pair.value().toBool();
350350
}
351-
setTensorMetadata(t, metadata);
351+
setTensorMetadata(t, std::move(metadata));
352352
}
353353

354354
} // namespace jit

torch/csrc/jit/tensorexpr/analysis.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class HasRand : public IRVisitor {
2525
if (v->op_type() == IntrinsicsOp::kRand) {
2626
has_rand_ = true;
2727
} else {
28-
IRVisitor::visit(v);
28+
IRVisitor::visit(std::move(v));
2929
}
3030
}
3131
StmtPtr stmt_;
@@ -61,7 +61,7 @@ class VarFinder : public IRVisitor {
6161
public:
6262
void visit(VarPtr v) override {
6363
vars_.insert(v);
64-
IRVisitor::visit(v);
64+
IRVisitor::visit(std::move(v));
6565
}
6666

6767
static std::unordered_set<VarPtr> find(StmtPtr s) {
@@ -88,7 +88,7 @@ class BufFinder : public IRVisitor {
8888
public:
8989
void visit(BufPtr v) override {
9090
bufs_.insert(v);
91-
IRVisitor::visit(v);
91+
IRVisitor::visit(std::move(v));
9292
}
9393

9494
static std::unordered_set<BufPtr> find(StmtPtr s) {
@@ -122,7 +122,7 @@ class WritesToBuf : public IRVisitor {
122122
}
123123

124124
static std::vector<StmtPtr> find(StmtPtr s, BufPtr b) {
125-
WritesToBuf finder(b);
125+
WritesToBuf finder(std::move(b));
126126
s->accept(&finder);
127127
return finder.writes();
128128
}
@@ -154,14 +154,14 @@ class StmtsReadingBuf : public IRVisitor {
154154
}
155155

156156
static std::vector<StmtPtr> find(StmtPtr s, BufPtr b) {
157-
StmtsReadingBuf finder(b);
157+
StmtsReadingBuf finder(std::move(b));
158158
s->accept(&finder);
159159
return finder.reads();
160160
}
161161

162162
private:
163163
bool readsBuffer(StmtPtr s) {
164-
auto loads = NodeFinder<Load>::find(s);
164+
auto loads = NodeFinder<Load>::find(std::move(s));
165165
for (const auto& l : loads) {
166166
if (l->buf() == target_) {
167167
return true;
@@ -203,7 +203,7 @@ class ExternalAllocBufFinder : public IRVisitor {
203203
void visit(ExternalCallWithAllocPtr v) override {
204204
const auto& bufs_out = v->buf_out_args();
205205
bufs_.insert(bufs_out.begin(), bufs_out.end());
206-
IRVisitor::visit(v);
206+
IRVisitor::visit(std::move(v));
207207
}
208208

209209
static std::unordered_set<BufPtr> find(StmtPtr s) {
@@ -232,7 +232,7 @@ class ModifiesVarChecker : public IRVisitor {
232232
ModifiesVarChecker(VarPtr v) : var_(std::move(v)) {}
233233

234234
static bool check(StmtPtr s, VarPtr v) {
235-
ModifiesVarChecker checker(v);
235+
ModifiesVarChecker checker(std::move(v));
236236
s->accept(&checker);
237237
return checker.found();
238238
}
@@ -247,31 +247,31 @@ class ModifiesVarChecker : public IRVisitor {
247247
found_ = true;
248248
return;
249249
}
250-
IRVisitor::visit(v);
250+
IRVisitor::visit(std::move(v));
251251
}
252252

253253
void visit(AtomicAddPtr v) override {
254254
if (v->buf()->base_handle() == var_) {
255255
found_ = true;
256256
return;
257257
}
258-
IRVisitor::visit(v);
258+
IRVisitor::visit(std::move(v));
259259
}
260260

261261
void visit(LetPtr v) override {
262262
if (v->var() == var_) {
263263
found_ = true;
264264
return;
265265
}
266-
IRVisitor::visit(v);
266+
IRVisitor::visit(std::move(v));
267267
}
268268

269269
void visit(ForPtr v) override {
270270
if (v->var() == var_) {
271271
found_ = true;
272272
return;
273273
}
274-
IRVisitor::visit(v);
274+
IRVisitor::visit(std::move(v));
275275
}
276276

277277
VarPtr var_;
@@ -286,13 +286,13 @@ class BufLiveRange : public IRVisitor {
286286
BufLiveRange(BufPtr b) : buf_(std::move(b)) {}
287287

288288
static std::tuple<int32_t, int32_t> liveRange(StmtPtr s, BufPtr b) {
289-
BlockPtr block = to<Block>(s);
289+
BlockPtr block = to<Block>(std::move(s));
290290
// We Only analze buffer live ranges for block stmts.
291291
if (!block) {
292292
return std::make_tuple(0, 0);
293293
}
294294

295-
BufLiveRange analyzer(b);
295+
BufLiveRange analyzer(std::move(b));
296296
block->accept(&analyzer);
297297
return analyzer.getLiveRange();
298298
}
@@ -317,7 +317,7 @@ class BufLiveRange : public IRVisitor {
317317
}
318318
}
319319
}
320-
auto loads3 = NodeFinder<ExternalCallWithAlloc>::find(s);
320+
auto loads3 = NodeFinder<ExternalCallWithAlloc>::find(std::move(s));
321321
for (const auto& l : loads3) {
322322
for (const auto& lb : l->buf_args()) {
323323
if (lb == buf_) {
@@ -341,7 +341,7 @@ class BufLiveRange : public IRVisitor {
341341
return true;
342342
}
343343
}
344-
auto writes3 = NodeFinder<ExternalCallWithAlloc>::find(s);
344+
auto writes3 = NodeFinder<ExternalCallWithAlloc>::find(std::move(s));
345345
for (const auto& w : writes3) {
346346
for (const auto& wb : w->buf_out_args()) {
347347
if (wb == buf_) {
@@ -353,7 +353,7 @@ class BufLiveRange : public IRVisitor {
353353
}
354354

355355
void findAccAndUpdateLiveRange(StmtPtr s) {
356-
bool has_reads = hasBufReads(s), has_writes = hasBufWrites(s);
356+
bool has_reads = hasBufReads(s), has_writes = hasBufWrites(std::move(s));
357357
if (has_reads || has_writes) {
358358
if (begin_ == -1) {
359359
begin_ = curr_index_;

torch/csrc/jit/tensorexpr/block_codegen.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <string>
44
#include <unordered_map>
55
#include <unordered_set>
6+
#include <utility>
67

78
#include <ATen/ATen.h>
89
#include <torch/csrc/jit/resource_guard.h>
@@ -43,7 +44,7 @@ class BlockAnalysis : public IRVisitor {
4344
std::string getInputName(BufPtr buf) const;
4445

4546
std::string getFlatInputName(BufPtr buf) const {
46-
return getInputName(buf) + "_flat";
47+
return getInputName(std::move(buf)) + "_flat";
4748
}
4849

4950
std::unordered_map<std::string, BufPtr> getBufferMap() const {

torch/csrc/jit/tensorexpr/codegen.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ class TORCH_API ExtCallMemoryReuse : public IRMutator {
125125

126126
class CodeGen::BufferArg {
127127
public:
128-
BufferArg(Tensor tensor) : buf_(tensor.buf()) {}
128+
BufferArg(const Tensor& tensor) : buf_(tensor.buf()) {}
129129
BufferArg(const VarHandle& var) : var_(var.node()), isVar_(true) {}
130130
BufferArg(const BufHandle& buf) : buf_(buf.node()) {}
131-
BufferArg(const BufPtr& buf) : buf_(buf) {}
131+
BufferArg(BufPtr buf) : buf_(std::move(buf)) {}
132132

133133
VarPtr var() const {
134134
return isVar_ ? var_ : buf_->base_handle();

torch/csrc/jit/tensorexpr/eval.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <cstring>
55
#include <type_traits>
66
#include <unordered_map>
7+
#include <utility>
78
#include <vector>
89

910
#include <c10/macros/Macros.h>
@@ -329,7 +330,7 @@ inline StmtPtr Substitute(StmtPtr stmt, const VarMapping& var_mapping) {
329330
// ones, and `VarMapping` input has variables as the key.
330331
inline ExprPtr SubstituteInClone(ExprPtr expr, const VarMapping& var_mapping) {
331332
VarSubMutator var_sub(var_mapping);
332-
return Expr::clone(expr)->accept_mutator(&var_sub);
333+
return Expr::clone(std::move(expr))->accept_mutator(&var_sub);
333334
}
334335

335336
// Creates a clone of the input statement and substitutes the given vars with
@@ -338,7 +339,7 @@ inline ExprPtr SubstituteInClone(ExprPtr expr, const VarMapping& var_mapping) {
338339
// ones, and `VarMapping` input has variables as the key.
339340
inline StmtPtr SubstituteInClone(StmtPtr stmt, const VarMapping& var_mapping) {
340341
VarSubMutator var_sub(var_mapping);
341-
return Stmt::clone(stmt)->accept_mutator(&var_sub);
342+
return Stmt::clone(std::move(stmt))->accept_mutator(&var_sub);
342343
}
343344

344345
} // namespace tensorexpr

0 commit comments

Comments
 (0)