Skip to content

Commit 5a1f607

Browse files
committed
Apply clang-tidy fixes for readability-container-size-empty for MLIR (NFC)
Reviewed By: rriddle, Mogball Differential Revision: https://reviews.llvm.org/D116252
1 parent f0fff1d commit 5a1f607

File tree

10 files changed

+19
-19
lines changed

10 files changed

+19
-19
lines changed

mlir/lib/Analysis/Utils.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ void ComputationSliceState::dump() const {
151151
/// if both the src and the dst loops don't have the same bounds. Returns
152152
/// llvm::None if none of the above can be proven.
153153
Optional<bool> ComputationSliceState::isSliceMaximalFastCheck() const {
154-
assert(lbs.size() == ubs.size() && lbs.size() && ivs.size() &&
154+
assert(lbs.size() == ubs.size() && !lbs.empty() && !ivs.empty() &&
155155
"Unexpected number of lbs, ubs and ivs in slice");
156156

157157
for (unsigned i = 0, end = lbs.size(); i < end; ++i) {

mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ static void printOperandAndTypeList(OpAsmPrinter &p, OperandRange operands) {
105105
/// Print data variables corresponding to a data-sharing clause `name`
106106
static void printDataVars(OpAsmPrinter &p, OperandRange operands,
107107
StringRef name) {
108-
if (operands.size()) {
108+
if (!operands.empty()) {
109109
p << name;
110110
printOperandAndTypeList(p, operands);
111111
}
@@ -390,7 +390,7 @@ static void printReductionVarList(OpAsmPrinter &p,
390390
static LogicalResult verifyReductionVarList(Operation *op,
391391
Optional<ArrayAttr> reductions,
392392
OperandRange reductionVars) {
393-
if (reductionVars.size() != 0) {
393+
if (!reductionVars.empty()) {
394394
if (!reductions || reductions->size() != reductionVars.size())
395395
return op->emitOpError()
396396
<< "expected as many reduction symbol references "
@@ -863,7 +863,7 @@ static ParseResult parseClauses(OpAsmParser &parser, OperationState &result,
863863
schedule[0] = llvm::toUpper(schedule[0]);
864864
auto attr = parser.getBuilder().getStringAttr(schedule);
865865
result.addAttribute("schedule_val", attr);
866-
if (modifiers.size() > 0) {
866+
if (!modifiers.empty()) {
867867
auto mod = parser.getBuilder().getStringAttr(modifiers[0]);
868868
result.addAttribute("schedule_modifier", mod);
869869
// Only SIMD attribute is allowed here!
@@ -1072,7 +1072,7 @@ static void printWsLoopOp(OpAsmPrinter &p, WsLoopOp op) {
10721072
printDataVars(p, op.firstprivate_vars(), "firstprivate");
10731073
printDataVars(p, op.lastprivate_vars(), "lastprivate");
10741074

1075-
if (op.linear_vars().size())
1075+
if (!op.linear_vars().empty())
10761076
printLinearClause(p, op.linear_vars(), op.linear_step_vars());
10771077

10781078
if (auto sched = op.schedule_val())

mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ getElementType(Type type, Attribute indices,
669669
emitErrorFn("expected a 32-bit integer array attribute for 'indices'");
670670
return nullptr;
671671
}
672-
if (!indicesArrayAttr.size()) {
672+
if (indicesArrayAttr.empty()) {
673673
emitErrorFn("expected at least one index for spv.CompositeExtract");
674674
return nullptr;
675675
}
@@ -1929,7 +1929,7 @@ static void print(spirv::ExecutionModeOp execModeOp, OpAsmPrinter &printer) {
19291929
printer << " \"" << stringifyExecutionMode(execModeOp.execution_mode())
19301930
<< "\"";
19311931
auto values = execModeOp.values();
1932-
if (!values.size())
1932+
if (values.empty())
19331933
return;
19341934
printer << ", ";
19351935
llvm::interleaveComma(values, printer, [&](Attribute a) {

mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ unsigned Merger::mapSet(Kind kind, unsigned s0, Value v) {
137137

138138
unsigned Merger::optimizeSet(unsigned s0) {
139139
unsigned s = addSet();
140-
assert(latSets[s0].size() != 0);
140+
assert(!latSets[s0].empty());
141141
unsigned p0 = latSets[s0][0];
142142
for (unsigned p1 : latSets[s0]) {
143143
bool add = true;

mlir/lib/Dialect/Vector/VectorMultiDimReductionTransforms.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,12 @@ class ReduceMultiDimReductionRank
141141
// 2. Compute flattened parallel and reduction sizes.
142142
int flattenedParallelDim = 0;
143143
int flattenedReductionDim = 0;
144-
if (parallelShapes.size() > 0) {
144+
if (!parallelShapes.empty()) {
145145
flattenedParallelDim = 1;
146146
for (auto d : parallelShapes)
147147
flattenedParallelDim *= d;
148148
}
149-
if (reductionShapes.size() > 0) {
149+
if (!reductionShapes.empty()) {
150150
flattenedReductionDim = 1;
151151
for (auto d : reductionShapes)
152152
flattenedReductionDim *= d;

mlir/lib/Dialect/Vector/VectorOps.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,13 @@ static ParseResult parseReductionOp(OpAsmParser &parser,
340340
parser.parseComma() || parser.parseOperandList(operandsInfo) ||
341341
parser.parseColonType(redType) ||
342342
parser.parseKeywordType("into", resType) ||
343-
(operandsInfo.size() > 0 &&
343+
(!operandsInfo.empty() &&
344344
parser.resolveOperand(operandsInfo[0], redType, result.operands)) ||
345345
(operandsInfo.size() > 1 &&
346346
parser.resolveOperand(operandsInfo[1], resType, result.operands)) ||
347347
parser.addTypeToList(resType, result.types))
348348
return failure();
349-
if (operandsInfo.size() < 1 || operandsInfo.size() > 2)
349+
if (operandsInfo.empty() || operandsInfo.size() > 2)
350350
return parser.emitError(parser.getNameLoc(),
351351
"unsupported number of operands");
352352
return success();
@@ -546,7 +546,7 @@ static LogicalResult verifyOutputShape(
546546
}
547547

548548
// Verify 'expectedResultDims'.
549-
if (expectedResultDims.size() == 0) {
549+
if (expectedResultDims.empty()) {
550550
// No batch or free dimension implies a scalar result.
551551
if (resType.isa<VectorType>() || accType.isa<VectorType>())
552552
return op.emitOpError("invalid accumulator/result vector shape");

mlir/lib/Reducer/ReductionNode.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ ArrayRef<ReductionNode *> ReductionNode::generateNewVariants() {
6161
// If we haven't created new variant, then we can create varients by removing
6262
// each of them respectively. For example, given {{1, 3}, {4, 9}}, we can
6363
// produce variants with range {{1, 3}} and {{4, 9}}.
64-
if (variants.size() == 0 && getRanges().size() > 1) {
64+
if (variants.empty() && getRanges().size() > 1) {
6565
for (const Range &range : getRanges()) {
6666
std::vector<Range> subRanges = getRanges();
6767
llvm::erase_value(subRanges, range);

mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ convertOmpSections(Operation &opInst, llvm::IRBuilderBase &builder,
591591
// No sections within omp.sections operation - skip generation. This situation
592592
// is only possible if there is only a terminator operation inside the
593593
// sections operation
594-
if (sectionCBs.size() == 0)
594+
if (sectionCBs.empty())
595595
return success();
596596

597597
assert(isa<omp::SectionOp>(*sectionsOp.region().op_begin()));

mlir/test/lib/Dialect/Affine/TestAffineDataCopy.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void TestAffineDataCopy::runOnFunction() {
5959
// Gather all AffineForOps by loop depth.
6060
std::vector<SmallVector<AffineForOp, 2>> depthToLoops;
6161
gatherLoops(getFunction(), depthToLoops);
62-
assert(depthToLoops.size() && "Loop nest not found");
62+
assert(!depthToLoops.empty() && "Loop nest not found");
6363

6464
// Only support tests with a single loop nest and a single innermost loop
6565
// for now.

mlir/tools/mlir-tblgen/DirectiveCommonGen.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,18 @@ using llvm::RecordKeeper;
4242
static bool emitDecls(const RecordKeeper &recordKeeper, raw_ostream &os) {
4343
const auto &directiveLanguages =
4444
recordKeeper.getAllDerivedDefinitions("DirectiveLanguage");
45-
assert(directiveLanguages.size() != 0 && "DirectiveLanguage missing.");
45+
assert(!directiveLanguages.empty() && "DirectiveLanguage missing.");
4646

4747
const auto &clauses = recordKeeper.getAllDerivedDefinitions("Clause");
4848

4949
for (const auto &r : clauses) {
5050
Clause c{r};
5151
const auto &clauseVals = c.getClauseVals();
52-
if (clauseVals.size() <= 0)
52+
if (clauseVals.empty())
5353
continue;
5454

5555
const auto enumName = c.getEnumName();
56-
assert(enumName.size() != 0 && "enumClauseValue field not set.");
56+
assert(!enumName.empty() && "enumClauseValue field not set.");
5757

5858
std::vector<std::string> cvDefs;
5959
for (const auto &cv : clauseVals) {

0 commit comments

Comments
 (0)