Skip to content

Commit e5639b3

Browse files
committed
Fix more clang-tidy cleanups in mlir/ (NFC)
1 parent dcb3e80 commit e5639b3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+122
-122
lines changed

mlir/lib/Analysis/DataFlowAnalysis.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -756,13 +756,13 @@ void ForwardDataFlowSolver::join(Operation *owner, AbstractLatticeElement &to,
756756
// AbstractLatticeElement
757757
//===----------------------------------------------------------------------===//
758758

759-
AbstractLatticeElement::~AbstractLatticeElement() {}
759+
AbstractLatticeElement::~AbstractLatticeElement() = default;
760760

761761
//===----------------------------------------------------------------------===//
762762
// ForwardDataFlowAnalysisBase
763763
//===----------------------------------------------------------------------===//
764764

765-
ForwardDataFlowAnalysisBase::~ForwardDataFlowAnalysisBase() {}
765+
ForwardDataFlowAnalysisBase::~ForwardDataFlowAnalysisBase() = default;
766766

767767
AbstractLatticeElement &
768768
ForwardDataFlowAnalysisBase::getLatticeElement(Value value) {

mlir/lib/Analysis/Liveness.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct BlockInfoBuilder {
2727
using ValueSetT = Liveness::ValueSetT;
2828

2929
/// Constructs an empty block builder.
30-
BlockInfoBuilder() : block(nullptr) {}
30+
BlockInfoBuilder() {}
3131

3232
/// Fills the block builder with initial liveness information.
3333
BlockInfoBuilder(Block *block) : block(block) {
@@ -104,7 +104,7 @@ struct BlockInfoBuilder {
104104
}
105105

106106
/// The current block.
107-
Block *block;
107+
Block *block{nullptr};
108108

109109
/// The set of all live in values.
110110
ValueSetT inValues;

mlir/lib/Analysis/LoopAnalysis.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ static bool isAccessIndexInvariant(Value iv, Value index) {
182182

183183
DenseSet<Value> mlir::getInvariantAccesses(Value iv, ArrayRef<Value> indices) {
184184
DenseSet<Value> res;
185-
for (unsigned idx = 0, n = indices.size(); idx < n; ++idx) {
186-
auto val = indices[idx];
185+
for (auto val : indices) {
187186
if (isAccessIndexInvariant(iv, val)) {
188187
res.insert(val);
189188
}

mlir/lib/Analysis/Utils.cpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -817,15 +817,15 @@ mlir::computeSliceUnion(ArrayRef<Operation *> opsA, ArrayRef<Operation *> opsB,
817817
FlatAffineValueConstraints sliceUnionCst;
818818
assert(sliceUnionCst.getNumDimAndSymbolIds() == 0);
819819
std::vector<std::pair<Operation *, Operation *>> dependentOpPairs;
820-
for (unsigned i = 0, numOpsA = opsA.size(); i < numOpsA; ++i) {
821-
MemRefAccess srcAccess(opsA[i]);
822-
for (unsigned j = 0, numOpsB = opsB.size(); j < numOpsB; ++j) {
823-
MemRefAccess dstAccess(opsB[j]);
820+
for (auto i : opsA) {
821+
MemRefAccess srcAccess(i);
822+
for (auto j : opsB) {
823+
MemRefAccess dstAccess(j);
824824
if (srcAccess.memref != dstAccess.memref)
825825
continue;
826826
// Check if 'loopDepth' exceeds nesting depth of src/dst ops.
827-
if ((!isBackwardSlice && loopDepth > getNestingDepth(opsA[i])) ||
828-
(isBackwardSlice && loopDepth > getNestingDepth(opsB[j]))) {
827+
if ((!isBackwardSlice && loopDepth > getNestingDepth(i)) ||
828+
(isBackwardSlice && loopDepth > getNestingDepth(j))) {
829829
LLVM_DEBUG(llvm::dbgs() << "Invalid loop depth\n");
830830
return SliceComputationResult::GenericFailure;
831831
}
@@ -844,13 +844,12 @@ mlir::computeSliceUnion(ArrayRef<Operation *> opsA, ArrayRef<Operation *> opsB,
844844
}
845845
if (result.value == DependenceResult::NoDependence)
846846
continue;
847-
dependentOpPairs.push_back({opsA[i], opsB[j]});
847+
dependentOpPairs.emplace_back(i, j);
848848

849849
// Compute slice bounds for 'srcAccess' and 'dstAccess'.
850850
ComputationSliceState tmpSliceState;
851-
mlir::getComputationSliceState(opsA[i], opsB[j], &dependenceConstraints,
852-
loopDepth, isBackwardSlice,
853-
&tmpSliceState);
851+
mlir::getComputationSliceState(i, j, &dependenceConstraints, loopDepth,
852+
isBackwardSlice, &tmpSliceState);
854853

855854
if (sliceUnionCst.getNumDimAndSymbolIds() == 0) {
856855
// Initialize 'sliceUnionCst' with the bounds computed in previous step.

mlir/lib/Bindings/Python/IRAffine.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ void mlir::python::populateIRAffine(py::module &m) {
676676
std::vector<PyAffineMap> res;
677677
res.reserve(compressed.size());
678678
for (auto m : compressed)
679-
res.push_back(PyAffineMap(context->getRef(), m));
679+
res.emplace_back(context->getRef(), m);
680680
return res;
681681
})
682682
.def_property_readonly(

mlir/lib/Bindings/Python/IRAttributes.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,8 @@ class PyDenseElementsAttribute
524524
mlirIntegerTypeIsSigned(elementType)) {
525525
// i32
526526
return bufferInfo<int32_t>(shapedType);
527-
} else if (mlirIntegerTypeIsUnsigned(elementType)) {
527+
}
528+
if (mlirIntegerTypeIsUnsigned(elementType)) {
528529
// unsigned i32
529530
return bufferInfo<uint32_t>(shapedType);
530531
}
@@ -534,7 +535,8 @@ class PyDenseElementsAttribute
534535
mlirIntegerTypeIsSigned(elementType)) {
535536
// i64
536537
return bufferInfo<int64_t>(shapedType);
537-
} else if (mlirIntegerTypeIsUnsigned(elementType)) {
538+
}
539+
if (mlirIntegerTypeIsUnsigned(elementType)) {
538540
// unsigned i64
539541
return bufferInfo<uint64_t>(shapedType);
540542
}
@@ -544,7 +546,8 @@ class PyDenseElementsAttribute
544546
mlirIntegerTypeIsSigned(elementType)) {
545547
// i8
546548
return bufferInfo<int8_t>(shapedType);
547-
} else if (mlirIntegerTypeIsUnsigned(elementType)) {
549+
}
550+
if (mlirIntegerTypeIsUnsigned(elementType)) {
548551
// unsigned i8
549552
return bufferInfo<uint8_t>(shapedType);
550553
}
@@ -554,7 +557,8 @@ class PyDenseElementsAttribute
554557
mlirIntegerTypeIsSigned(elementType)) {
555558
// i16
556559
return bufferInfo<int16_t>(shapedType);
557-
} else if (mlirIntegerTypeIsUnsigned(elementType)) {
560+
}
561+
if (mlirIntegerTypeIsUnsigned(elementType)) {
558562
// unsigned i16
559563
return bufferInfo<uint16_t>(shapedType);
560564
}

mlir/lib/Bindings/Python/IRInterfaces.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@ class PyInferTypeOpInterface
175175
auto *data = static_cast<AppendResultsCallbackData *>(userData);
176176
data->inferredTypes.reserve(data->inferredTypes.size() + nTypes);
177177
for (intptr_t i = 0; i < nTypes; ++i) {
178-
data->inferredTypes.push_back(
179-
PyType(data->pyMlirContext.getRef(), types[i]));
178+
data->inferredTypes.emplace_back(data->pyMlirContext.getRef(), types[i]);
180179
}
181180
}
182181

mlir/lib/Bindings/Python/IRModule.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ PyGlobals::PyGlobals() {
2929
instance = this;
3030
// The default search path include {mlir.}dialects, where {mlir.} is the
3131
// package prefix configured at compile time.
32-
dialectSearchPrefixes.push_back(MAKE_MLIR_PYTHON_QUALNAME("dialects"));
32+
dialectSearchPrefixes.emplace_back(MAKE_MLIR_PYTHON_QUALNAME("dialects"));
3333
}
3434

3535
PyGlobals::~PyGlobals() { instance = nullptr; }

mlir/lib/CAPI/IR/Diagnostics.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ MlirDiagnosticHandlerID mlirContextAttachDiagnosticHandler(
5757
MlirContext context, MlirDiagnosticHandler handler, void *userData,
5858
void (*deleteUserData)(void *)) {
5959
assert(handler && "unexpected null diagnostic handler");
60-
if (deleteUserData == NULL)
60+
if (deleteUserData == nullptr)
6161
deleteUserData = deleteUserDataNoop;
6262
std::shared_ptr<void> sharedUserData(userData, deleteUserData);
6363
DiagnosticEngine::HandlerID id =

mlir/lib/Conversion/PDLToPDLInterp/Predicate.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ using namespace mlir::pdl_to_pdl_interp;
1515
// Positions
1616
//===----------------------------------------------------------------------===//
1717

18-
Position::~Position() {}
18+
Position::~Position() = default;
1919

2020
/// Returns the depth of the first ancestor operation position.
2121
unsigned Position::getOperationDepth() const {

mlir/lib/Dialect/Affine/IR/AffineValueMap.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,4 @@ ArrayRef<Value> AffineValueMap::getOperands() const {
9999

100100
AffineMap AffineValueMap::getAffineMap() const { return map.getAffineMap(); }
101101

102-
AffineValueMap::~AffineValueMap() {}
102+
AffineValueMap::~AffineValueMap() = default;

mlir/lib/Dialect/Affine/Transforms/AffineParallelize.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void AffineParallelize::runOnFunction() {
5656
f.walk<WalkOrder::PreOrder>([&](AffineForOp loop) {
5757
SmallVector<LoopReduction> reductions;
5858
if (isLoopParallel(loop, parallelReductions ? &reductions : nullptr))
59-
parallelizableLoops.push_back({loop, std::move(reductions)});
59+
parallelizableLoops.emplace_back(loop, std::move(reductions));
6060
});
6161

6262
for (const ParallelizationCandidate &candidate : parallelizableLoops) {

mlir/lib/Dialect/Affine/Transforms/LoopUnroll.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ struct LoopUnroll : public AffineLoopUnrollBase<LoopUnroll> {
4141

4242
LoopUnroll() : getUnrollFactor(nullptr) {}
4343
LoopUnroll(const LoopUnroll &other)
44-
: AffineLoopUnrollBase<LoopUnroll>(other),
45-
getUnrollFactor(other.getUnrollFactor) {}
44+
45+
= default;
4646
explicit LoopUnroll(
4747
Optional<unsigned> unrollFactor = None, bool unrollUpToFactor = false,
4848
bool unrollFull = false,

mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,7 @@ getMatchedAffineLoopsRec(NestedMatch match, unsigned currentLevel,
14941494
// Add a new empty level to the output if it doesn't exist already.
14951495
assert(currentLevel <= loops.size() && "Unexpected currentLevel");
14961496
if (currentLevel == loops.size())
1497-
loops.push_back(SmallVector<AffineForOp, 2>());
1497+
loops.emplace_back();
14981498

14991499
// Add current match and recursively visit its children.
15001500
loops[currentLevel].push_back(cast<AffineForOp>(match.getMatchedOperation()));
@@ -1631,7 +1631,7 @@ static void computeIntersectionBuckets(
16311631
// it.
16321632
if (!intersects) {
16331633
bucketRoots.push_back(matchRoot);
1634-
intersectionBuckets.push_back(SmallVector<NestedMatch, 8>());
1634+
intersectionBuckets.emplace_back();
16351635
intersectionBuckets.back().push_back(match);
16361636
}
16371637
}

mlir/lib/Dialect/Linalg/Transforms/ComprehensiveBufferizePass.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace {
3333
struct LinalgComprehensiveModuleBufferize
3434
: public LinalgComprehensiveModuleBufferizeBase<
3535
LinalgComprehensiveModuleBufferize> {
36-
LinalgComprehensiveModuleBufferize() {}
36+
LinalgComprehensiveModuleBufferize() = default;
3737

3838
LinalgComprehensiveModuleBufferize(
3939
const LinalgComprehensiveModuleBufferize &p) {}

mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ Attribute SparseTensorEncodingAttr::parse(AsmParser &parser, Type type) {
6161
"expected an array for dimension level types");
6262
return {};
6363
}
64-
for (unsigned i = 0, e = arrayAttr.size(); i < e; i++) {
65-
auto strAttr = arrayAttr[i].dyn_cast<StringAttr>();
64+
for (auto i : arrayAttr) {
65+
auto strAttr = i.dyn_cast<StringAttr>();
6666
if (!strAttr) {
6767
parser.emitError(parser.getNameLoc(),
6868
"expected a string value in dimension level types");

mlir/lib/Dialect/Tosa/Transforms/TosaOptimization.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ struct DepthwiseConv2DIsMul : public OpRewritePattern<tosa::DepthwiseConv2DOp> {
215215

216216
class TosaOptimization : public PassWrapper<TosaOptimization, FunctionPass> {
217217
public:
218-
explicit TosaOptimization() {}
218+
explicit TosaOptimization() = default;
219219
void runOnFunction() override;
220220

221221
StringRef getArgument() const final { return PASS_NAME; }

mlir/lib/Dialect/Vector/VectorOps.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ getDimMap(ArrayRef<AffineMap> indexingMaps, ArrayAttr iteratorTypes,
702702
int64_t lhsDim = getResultIndex(indexingMaps[0], targetExpr);
703703
int64_t rhsDim = getResultIndex(indexingMaps[1], targetExpr);
704704
if (lhsDim >= 0 && rhsDim >= 0)
705-
dimMap.push_back({lhsDim, rhsDim});
705+
dimMap.emplace_back(lhsDim, rhsDim);
706706
}
707707
return dimMap;
708708
}

mlir/lib/ExecutionEngine/AsyncRuntime.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ extern "C" int64_t mlirAsyncRuntimeAddTokenToGroup(AsyncToken *token,
289289
// then, and re-ackquire the lock.
290290
group->addRef();
291291

292-
token->awaiters.push_back([group, onTokenReady]() {
292+
token->awaiters.emplace_back([group, onTokenReady]() {
293293
// Make sure that `dropRef` does not destroy the mutex owned by the lock.
294294
{
295295
std::unique_lock<std::mutex> lockGroup(group->mu);
@@ -408,7 +408,7 @@ extern "C" void mlirAsyncRuntimeAwaitTokenAndExecute(AsyncToken *token,
408408
lock.unlock();
409409
execute();
410410
} else {
411-
token->awaiters.push_back([execute]() { execute(); });
411+
token->awaiters.emplace_back([execute]() { execute(); });
412412
}
413413
}
414414

@@ -421,7 +421,7 @@ extern "C" void mlirAsyncRuntimeAwaitValueAndExecute(AsyncValue *value,
421421
lock.unlock();
422422
execute();
423423
} else {
424-
value->awaiters.push_back([execute]() { execute(); });
424+
value->awaiters.emplace_back([execute]() { execute(); });
425425
}
426426
}
427427

@@ -434,7 +434,7 @@ extern "C" void mlirAsyncRuntimeAwaitAllInGroupAndExecute(AsyncGroup *group,
434434
lock.unlock();
435435
execute();
436436
} else {
437-
group->awaiters.push_back([execute]() { execute(); });
437+
group->awaiters.emplace_back([execute]() { execute(); });
438438
}
439439
}
440440

mlir/lib/ExecutionEngine/CRunnerUtils.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ extern "C" void print_flops(double flops) {
109109
extern "C" double rtclock() {
110110
#ifndef _WIN32
111111
struct timeval tp;
112-
int stat = gettimeofday(&tp, NULL);
112+
int stat = gettimeofday(&tp, nullptr);
113113
if (stat != 0)
114114
fprintf(stderr, "Error returning time from gettimeofday: %d\n", stat);
115115
return (tp.tv_sec + tp.tv_usec * 1.0e-6);

mlir/lib/ExecutionEngine/SparseTensorUtils.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ class SparseTensorStorageBase {
217217
/// Finishes insertion.
218218
virtual void endInsert() = 0;
219219

220-
virtual ~SparseTensorStorageBase() {}
220+
virtual ~SparseTensorStorageBase() = default;
221221

222222
private:
223223
void fatal(const char *tp) {
@@ -277,7 +277,7 @@ class SparseTensorStorage : public SparseTensorStorageBase {
277277
}
278278
}
279279

280-
virtual ~SparseTensorStorage() {}
280+
virtual ~SparseTensorStorage() = default;
281281

282282
/// Get the rank of the tensor.
283283
uint64_t getRank() const { return sizes.size(); }
@@ -574,7 +574,7 @@ static void readMMEHeader(FILE *file, char *filename, char *line,
574574
exit(1);
575575
}
576576
// Skip comments.
577-
while (1) {
577+
while (true) {
578578
if (!fgets(line, kColWidth, file)) {
579579
fprintf(stderr, "Cannot find data in %s\n", filename);
580580
exit(1);
@@ -598,7 +598,7 @@ static void readMMEHeader(FILE *file, char *filename, char *line,
598598
static void readExtFROSTTHeader(FILE *file, char *filename, char *line,
599599
uint64_t *idata) {
600600
// Skip comments.
601-
while (1) {
601+
while (true) {
602602
if (!fgets(line, kColWidth, file)) {
603603
fprintf(stderr, "Cannot find data in %s\n", filename);
604604
exit(1);

mlir/lib/IR/AsmPrinter.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,23 @@ void OperationName::dump() const { print(llvm::errs()); }
5454
// AsmParser
5555
//===--------------------------------------------------------------------===//
5656

57-
AsmParser::~AsmParser() {}
58-
DialectAsmParser::~DialectAsmParser() {}
59-
OpAsmParser::~OpAsmParser() {}
57+
AsmParser::~AsmParser() = default;
58+
DialectAsmParser::~DialectAsmParser() = default;
59+
OpAsmParser::~OpAsmParser() = default;
6060

6161
MLIRContext *AsmParser::getContext() const { return getBuilder().getContext(); }
6262

6363
//===----------------------------------------------------------------------===//
6464
// DialectAsmPrinter
6565
//===----------------------------------------------------------------------===//
6666

67-
DialectAsmPrinter::~DialectAsmPrinter() {}
67+
DialectAsmPrinter::~DialectAsmPrinter() = default;
6868

6969
//===----------------------------------------------------------------------===//
7070
// OpAsmPrinter
7171
//===----------------------------------------------------------------------===//
7272

73-
OpAsmPrinter::~OpAsmPrinter() {}
73+
OpAsmPrinter::~OpAsmPrinter() = default;
7474

7575
void OpAsmPrinter::printFunctionalType(Operation *op) {
7676
auto &os = getStream();
@@ -1221,7 +1221,7 @@ class AsmStateImpl {
12211221
AsmState::AsmState(Operation *op, const OpPrintingFlags &printerFlags,
12221222
LocationMap *locationMap)
12231223
: impl(std::make_unique<AsmStateImpl>(op, printerFlags, locationMap)) {}
1224-
AsmState::~AsmState() {}
1224+
AsmState::~AsmState() = default;
12251225

12261226
//===----------------------------------------------------------------------===//
12271227
// AsmPrinter::Impl
@@ -2116,7 +2116,7 @@ void AsmPrinter::Impl::printDialectType(Type type) {
21162116
// AsmPrinter
21172117
//===--------------------------------------------------------------------===//
21182118

2119-
AsmPrinter::~AsmPrinter() {}
2119+
AsmPrinter::~AsmPrinter() = default;
21202120

21212121
raw_ostream &AsmPrinter::getStream() const {
21222122
assert(impl && "expected AsmPrinter::getStream to be overriden");

mlir/lib/IR/Builders.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ AffineMap Builder::getShiftedAffineMap(AffineMap map, int64_t shift) {
342342
// OpBuilder
343343
//===----------------------------------------------------------------------===//
344344

345-
OpBuilder::Listener::~Listener() {}
345+
OpBuilder::Listener::~Listener() = default;
346346

347347
/// Insert the given operation at the current insertion point and return it.
348348
Operation *OpBuilder::insert(Operation *op) {

0 commit comments

Comments
 (0)