[Mlir-commits] [mlir] 5a1f607 - Apply clang-tidy fixes for readability-container-size-empty for MLIR (NFC)
Mehdi Amini
llvmlistbot at llvm.org
Sat Jan 1 17:58:52 PST 2022
Author: Mehdi Amini
Date: 2022-01-02T01:56:38Z
New Revision: 5a1f6077ec2b0eb9c1a314967f789026d015bdb1
URL: https://github.com/llvm/llvm-project/commit/5a1f6077ec2b0eb9c1a314967f789026d015bdb1
DIFF: https://github.com/llvm/llvm-project/commit/5a1f6077ec2b0eb9c1a314967f789026d015bdb1.diff
LOG: Apply clang-tidy fixes for readability-container-size-empty for MLIR (NFC)
Reviewed By: rriddle, Mogball
Differential Revision: https://reviews.llvm.org/D116252
Added:
Modified:
mlir/lib/Analysis/Utils.cpp
mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp
mlir/lib/Dialect/Vector/VectorMultiDimReductionTransforms.cpp
mlir/lib/Dialect/Vector/VectorOps.cpp
mlir/lib/Reducer/ReductionNode.cpp
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
mlir/test/lib/Dialect/Affine/TestAffineDataCopy.cpp
mlir/tools/mlir-tblgen/DirectiveCommonGen.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Analysis/Utils.cpp b/mlir/lib/Analysis/Utils.cpp
index e6fe34996359e..432aeecde2db6 100644
--- a/mlir/lib/Analysis/Utils.cpp
+++ b/mlir/lib/Analysis/Utils.cpp
@@ -151,7 +151,7 @@ void ComputationSliceState::dump() const {
/// if both the src and the dst loops don't have the same bounds. Returns
/// llvm::None if none of the above can be proven.
Optional<bool> ComputationSliceState::isSliceMaximalFastCheck() const {
- assert(lbs.size() == ubs.size() && lbs.size() && ivs.size() &&
+ assert(lbs.size() == ubs.size() && !lbs.empty() && !ivs.empty() &&
"Unexpected number of lbs, ubs and ivs in slice");
for (unsigned i = 0, end = lbs.size(); i < end; ++i) {
diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
index e1d2dcadff8ad..0b4346ddd08d1 100644
--- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -105,7 +105,7 @@ static void printOperandAndTypeList(OpAsmPrinter &p, OperandRange operands) {
/// Print data variables corresponding to a data-sharing clause `name`
static void printDataVars(OpAsmPrinter &p, OperandRange operands,
StringRef name) {
- if (operands.size()) {
+ if (!operands.empty()) {
p << name;
printOperandAndTypeList(p, operands);
}
@@ -390,7 +390,7 @@ static void printReductionVarList(OpAsmPrinter &p,
static LogicalResult verifyReductionVarList(Operation *op,
Optional<ArrayAttr> reductions,
OperandRange reductionVars) {
- if (reductionVars.size() != 0) {
+ if (!reductionVars.empty()) {
if (!reductions || reductions->size() != reductionVars.size())
return op->emitOpError()
<< "expected as many reduction symbol references "
@@ -863,7 +863,7 @@ static ParseResult parseClauses(OpAsmParser &parser, OperationState &result,
schedule[0] = llvm::toUpper(schedule[0]);
auto attr = parser.getBuilder().getStringAttr(schedule);
result.addAttribute("schedule_val", attr);
- if (modifiers.size() > 0) {
+ if (!modifiers.empty()) {
auto mod = parser.getBuilder().getStringAttr(modifiers[0]);
result.addAttribute("schedule_modifier", mod);
// Only SIMD attribute is allowed here!
@@ -1072,7 +1072,7 @@ static void printWsLoopOp(OpAsmPrinter &p, WsLoopOp op) {
printDataVars(p, op.firstprivate_vars(), "firstprivate");
printDataVars(p, op.lastprivate_vars(), "lastprivate");
- if (op.linear_vars().size())
+ if (!op.linear_vars().empty())
printLinearClause(p, op.linear_vars(), op.linear_step_vars());
if (auto sched = op.schedule_val())
diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
index 8090b235cc46e..f85cc03b104ee 100644
--- a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
+++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
@@ -669,7 +669,7 @@ getElementType(Type type, Attribute indices,
emitErrorFn("expected a 32-bit integer array attribute for 'indices'");
return nullptr;
}
- if (!indicesArrayAttr.size()) {
+ if (indicesArrayAttr.empty()) {
emitErrorFn("expected at least one index for spv.CompositeExtract");
return nullptr;
}
@@ -1929,7 +1929,7 @@ static void print(spirv::ExecutionModeOp execModeOp, OpAsmPrinter &printer) {
printer << " \"" << stringifyExecutionMode(execModeOp.execution_mode())
<< "\"";
auto values = execModeOp.values();
- if (!values.size())
+ if (values.empty())
return;
printer << ", ";
llvm::interleaveComma(values, printer, [&](Attribute a) {
diff --git a/mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp b/mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp
index a863a9cd8e01f..9163aabd3c816 100644
--- a/mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp
+++ b/mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp
@@ -137,7 +137,7 @@ unsigned Merger::mapSet(Kind kind, unsigned s0, Value v) {
unsigned Merger::optimizeSet(unsigned s0) {
unsigned s = addSet();
- assert(latSets[s0].size() != 0);
+ assert(!latSets[s0].empty());
unsigned p0 = latSets[s0][0];
for (unsigned p1 : latSets[s0]) {
bool add = true;
diff --git a/mlir/lib/Dialect/Vector/VectorMultiDimReductionTransforms.cpp b/mlir/lib/Dialect/Vector/VectorMultiDimReductionTransforms.cpp
index f012bf486bdf4..9a1ca53074d01 100644
--- a/mlir/lib/Dialect/Vector/VectorMultiDimReductionTransforms.cpp
+++ b/mlir/lib/Dialect/Vector/VectorMultiDimReductionTransforms.cpp
@@ -141,12 +141,12 @@ class ReduceMultiDimReductionRank
// 2. Compute flattened parallel and reduction sizes.
int flattenedParallelDim = 0;
int flattenedReductionDim = 0;
- if (parallelShapes.size() > 0) {
+ if (!parallelShapes.empty()) {
flattenedParallelDim = 1;
for (auto d : parallelShapes)
flattenedParallelDim *= d;
}
- if (reductionShapes.size() > 0) {
+ if (!reductionShapes.empty()) {
flattenedReductionDim = 1;
for (auto d : reductionShapes)
flattenedReductionDim *= d;
diff --git a/mlir/lib/Dialect/Vector/VectorOps.cpp b/mlir/lib/Dialect/Vector/VectorOps.cpp
index 60c0aac1a4bea..fa608113b079a 100644
--- a/mlir/lib/Dialect/Vector/VectorOps.cpp
+++ b/mlir/lib/Dialect/Vector/VectorOps.cpp
@@ -340,13 +340,13 @@ static ParseResult parseReductionOp(OpAsmParser &parser,
parser.parseComma() || parser.parseOperandList(operandsInfo) ||
parser.parseColonType(redType) ||
parser.parseKeywordType("into", resType) ||
- (operandsInfo.size() > 0 &&
+ (!operandsInfo.empty() &&
parser.resolveOperand(operandsInfo[0], redType, result.operands)) ||
(operandsInfo.size() > 1 &&
parser.resolveOperand(operandsInfo[1], resType, result.operands)) ||
parser.addTypeToList(resType, result.types))
return failure();
- if (operandsInfo.size() < 1 || operandsInfo.size() > 2)
+ if (operandsInfo.empty() || operandsInfo.size() > 2)
return parser.emitError(parser.getNameLoc(),
"unsupported number of operands");
return success();
@@ -546,7 +546,7 @@ static LogicalResult verifyOutputShape(
}
// Verify 'expectedResultDims'.
- if (expectedResultDims.size() == 0) {
+ if (expectedResultDims.empty()) {
// No batch or free dimension implies a scalar result.
if (resType.isa<VectorType>() || accType.isa<VectorType>())
return op.emitOpError("invalid accumulator/result vector shape");
diff --git a/mlir/lib/Reducer/ReductionNode.cpp b/mlir/lib/Reducer/ReductionNode.cpp
index 2aa551ed8338b..9f0f461d676e7 100644
--- a/mlir/lib/Reducer/ReductionNode.cpp
+++ b/mlir/lib/Reducer/ReductionNode.cpp
@@ -61,7 +61,7 @@ ArrayRef<ReductionNode *> ReductionNode::generateNewVariants() {
// If we haven't created new variant, then we can create varients by removing
// each of them respectively. For example, given {{1, 3}, {4, 9}}, we can
// produce variants with range {{1, 3}} and {{4, 9}}.
- if (variants.size() == 0 && getRanges().size() > 1) {
+ if (variants.empty() && getRanges().size() > 1) {
for (const Range &range : getRanges()) {
std::vector<Range> subRanges = getRanges();
llvm::erase_value(subRanges, range);
diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index 581065f7cd0a7..7a3eca3e32d14 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -591,7 +591,7 @@ convertOmpSections(Operation &opInst, llvm::IRBuilderBase &builder,
// No sections within omp.sections operation - skip generation. This situation
// is only possible if there is only a terminator operation inside the
// sections operation
- if (sectionCBs.size() == 0)
+ if (sectionCBs.empty())
return success();
assert(isa<omp::SectionOp>(*sectionsOp.region().op_begin()));
diff --git a/mlir/test/lib/Dialect/Affine/TestAffineDataCopy.cpp b/mlir/test/lib/Dialect/Affine/TestAffineDataCopy.cpp
index e28b0c38f0ff0..edb2fb39b179e 100644
--- a/mlir/test/lib/Dialect/Affine/TestAffineDataCopy.cpp
+++ b/mlir/test/lib/Dialect/Affine/TestAffineDataCopy.cpp
@@ -59,7 +59,7 @@ void TestAffineDataCopy::runOnFunction() {
// Gather all AffineForOps by loop depth.
std::vector<SmallVector<AffineForOp, 2>> depthToLoops;
gatherLoops(getFunction(), depthToLoops);
- assert(depthToLoops.size() && "Loop nest not found");
+ assert(!depthToLoops.empty() && "Loop nest not found");
// Only support tests with a single loop nest and a single innermost loop
// for now.
diff --git a/mlir/tools/mlir-tblgen/DirectiveCommonGen.cpp b/mlir/tools/mlir-tblgen/DirectiveCommonGen.cpp
index 7cca598cc6ec1..718f7070f3bc5 100644
--- a/mlir/tools/mlir-tblgen/DirectiveCommonGen.cpp
+++ b/mlir/tools/mlir-tblgen/DirectiveCommonGen.cpp
@@ -42,18 +42,18 @@ using llvm::RecordKeeper;
static bool emitDecls(const RecordKeeper &recordKeeper, raw_ostream &os) {
const auto &directiveLanguages =
recordKeeper.getAllDerivedDefinitions("DirectiveLanguage");
- assert(directiveLanguages.size() != 0 && "DirectiveLanguage missing.");
+ assert(!directiveLanguages.empty() && "DirectiveLanguage missing.");
const auto &clauses = recordKeeper.getAllDerivedDefinitions("Clause");
for (const auto &r : clauses) {
Clause c{r};
const auto &clauseVals = c.getClauseVals();
- if (clauseVals.size() <= 0)
+ if (clauseVals.empty())
continue;
const auto enumName = c.getEnumName();
- assert(enumName.size() != 0 && "enumClauseValue field not set.");
+ assert(!enumName.empty() && "enumClauseValue field not set.");
std::vector<std::string> cvDefs;
for (const auto &cv : clauseVals) {
More information about the Mlir-commits
mailing list