Skip to content

Commit 3801916

Browse files
author
git apple-llvm automerger
committed
Merge commit 'dd378739d731' from llvm.org/master into apple/main
2 parents 7fd7078 + dd37873 commit 3801916

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

mlir/lib/Transforms/Bufferize.cpp

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ BufferizeTypeConverter::BufferizeTypeConverter() {
2020
// Keep all types unchanged.
2121
addConversion([](Type type) { return type; });
2222
// Convert RankedTensorType to MemRefType.
23-
addConversion([](RankedTensorType type) {
24-
return (Type)MemRefType::get(type.getShape(), type.getElementType());
23+
addConversion([](RankedTensorType type) -> Type {
24+
return MemRefType::get(type.getShape(), type.getElementType());
2525
});
2626
// Convert UnrankedTensorType to UnrankedMemRefType.
27-
addConversion([](UnrankedTensorType type) {
28-
return (Type)UnrankedMemRefType::get(type.getElementType(), 0);
27+
addConversion([](UnrankedTensorType type) -> Type {
28+
return UnrankedMemRefType::get(type.getElementType(), 0);
2929
});
3030
}
3131

@@ -35,8 +35,8 @@ BufferizeTypeConverter::BufferizeTypeConverter() {
3535
void BufferizeTypeConverter::tryDecomposeValue(
3636
OpBuilder &builder, Location loc, Type type, Value value,
3737
SmallVectorImpl<Value> &results) {
38-
for (auto conversion : decomposeValueConversions)
39-
if (conversion(builder, loc, type, value, results) != llvm::None)
38+
for (auto &conversion : decomposeValueConversions)
39+
if (conversion(builder, loc, type, value, results))
4040
return;
4141
results.push_back(value);
4242
}
@@ -45,20 +45,18 @@ void BufferizeTypeConverter::tryDecomposeValue(
4545
/// functions. If it is unable to do so, the original type is returned.
4646
void BufferizeTypeConverter::tryDecomposeType(Type type,
4747
SmallVectorImpl<Type> &types) {
48-
for (auto conversion : decomposeTypeConversions)
49-
if (conversion(type, types) != llvm::None)
48+
for (auto &conversion : decomposeTypeConversions)
49+
if (conversion(type, types))
5050
return;
5151
types.push_back(type);
5252
}
5353

5454
/// This method returns ResultConversionKind for the input type.
5555
BufferizeTypeConverter::ResultConversionKind
5656
BufferizeTypeConverter::getResultConversionKind(Type origin, Type converted) {
57-
for (auto conversion : resultTypeConversions) {
58-
auto res = conversion(origin, converted);
59-
if (res != llvm::None)
57+
for (auto &conversion : resultTypeConversions)
58+
if (auto res = conversion(origin, converted))
6059
return res.getValue();
61-
}
6260
return KeepAsFunctionResult;
6361
}
6462

@@ -90,11 +88,12 @@ LogicalResult BufferizeFuncOpConverter::matchAndRewrite(
9088
for (auto origin : originTypes) {
9189
Type converted = converter.convertType(origin);
9290
auto kind = converter.getResultConversionKind(origin, converted);
93-
if (kind == BufferizeTypeConverter::AppendToArgumentsList)
91+
if (kind == BufferizeTypeConverter::AppendToArgumentsList) {
9492
conversion.addInputs(converted);
95-
else
96-
// kind = BufferizeTypeConverter::KeepAsFunctionResult
93+
} else {
94+
assert(kind == BufferizeTypeConverter::KeepAsFunctionResult);
9795
newResultTypes.push_back(converted);
96+
}
9897
}
9998
}
10099

@@ -140,21 +139,19 @@ class CallOpResultMapping {
140139
SmallVector<std::pair<unsigned, Value>, 2> res(toValuesMapping.begin(),
141140
toValuesMapping.end());
142141
// Replace the indices with the actual values.
143-
llvm::for_each(
144-
toIndicesMapping, [&](const std::pair<unsigned, unsigned> &entry) {
145-
assert(entry.second < valuesToReplaceIndices.size() &&
146-
"The value index is out of range.");
147-
res.push_back({entry.first, valuesToReplaceIndices[entry.second]});
148-
});
142+
for (const std::pair<unsigned, unsigned> &entry : toIndicesMapping) {
143+
assert(entry.second < valuesToReplaceIndices.size() &&
144+
"The value index is out of range.");
145+
res.push_back({entry.first, valuesToReplaceIndices[entry.second]});
146+
}
149147
// Sort the values based on their adding orders.
150148
llvm::sort(res, [](const std::pair<unsigned, Value> &v1,
151149
const std::pair<unsigned, Value> &v2) {
152150
return v1.first < v2.first;
153151
});
154152
// Fill the values.
155-
llvm::for_each(res, [&](const std::pair<unsigned, Value> &entry) {
153+
for (const std::pair<unsigned, Value> &entry : res)
156154
values.push_back(entry.second);
157-
});
158155
}
159156

160157
private:
@@ -187,8 +184,8 @@ LogicalResult BufferizeCallOpConverter::matchAndRewrite(
187184
// values if a decompose callback function has been provided by the user.
188185
for (auto operand : operands) {
189186
SmallVector<Value, 2> values;
190-
this->converter.tryDecomposeValue(builder, loc, operand.getType(), operand,
191-
values);
187+
converter.tryDecomposeValue(builder, loc, operand.getType(), operand,
188+
values);
192189
newOperands.append(values.begin(), values.end());
193190
}
194191

0 commit comments

Comments
 (0)