Skip to content

Commit 3a8fc34

Browse files
committed
resolve nits before adding more tests
1 parent 668dfb2 commit 3a8fc34

File tree

3 files changed

+19
-33
lines changed

3 files changed

+19
-33
lines changed

mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ static ParseResult parseOneOpBundle(
253253
SmallVector<SmallVector<OpAsmParser::UnresolvedOperand>> &opBundleOperands,
254254
SmallVector<SmallVector<Type>> &opBundleOperandTypes,
255255
SmallVector<std::string> &opBundleTags) {
256-
auto currentParserLoc = p.getCurrentLocation();
256+
SMLoc currentParserLoc = p.getCurrentLocation();
257257
SmallVector<OpAsmParser::UnresolvedOperand> operands;
258258
SmallVector<Type> types;
259259
std::string tag;
@@ -1189,18 +1189,12 @@ LogicalResult verifyCallOpVarCalleeType(OpTy callOp) {
11891189
template <typename OpType>
11901190
static LogicalResult verifyOperandBundles(OpType &op) {
11911191
OperandRangeRange opBundleOperands = op.getOpBundleOperands();
1192-
std::optional<ArrayRef<std::string>> opBundleTags = op.getOpBundleTags();
1192+
ArrayRef<std::string> opBundleTags = op.getOpBundleTags();
11931193

1194-
if (!opBundleTags.has_value()) {
1195-
if (!opBundleOperands.empty())
1196-
return op.emitError("expected operand bundle tags");
1197-
return success();
1198-
}
1199-
1200-
if (opBundleTags->size() != opBundleOperands.size())
1194+
if (opBundleTags.size() != opBundleOperands.size())
12011195
return op.emitError("expected ")
12021196
<< opBundleOperands.size()
1203-
<< " operand bundle tags, but actually got " << opBundleTags->size();
1197+
<< " operand bundle tags, but actually got " << opBundleTags.size();
12041198

12051199
return success();
12061200
}
@@ -1405,12 +1399,9 @@ static ParseResult resolveOpBundleOperands(
14051399
ArrayRef<SmallVector<OpAsmParser::UnresolvedOperand>> opBundleOperands,
14061400
ArrayRef<SmallVector<Type>> opBundleOperandTypes,
14071401
StringAttr opBundleSizesAttrName) {
1408-
assert(opBundleOperands.size() == opBundleOperandTypes.size() &&
1409-
"operand bundle operand groups and type groups should match");
1410-
14111402
unsigned opBundleIndex = 0;
14121403
for (const auto &[operands, types] :
1413-
llvm::zip(opBundleOperands, opBundleOperandTypes)) {
1404+
llvm::zip_equal(opBundleOperands, opBundleOperandTypes)) {
14141405
if (operands.size() != types.size())
14151406
return parser.emitError(loc, "expected ")
14161407
<< operands.size()
@@ -1422,9 +1413,8 @@ static ParseResult resolveOpBundleOperands(
14221413

14231414
SmallVector<int32_t> opBundleSizes;
14241415
opBundleSizes.reserve(opBundleOperands.size());
1425-
for (const auto &operands : opBundleOperands) {
1416+
for (const auto &operands : opBundleOperands)
14261417
opBundleSizes.push_back(operands.size());
1427-
}
14281418

14291419
state.addAttribute(
14301420
opBundleSizesAttrName,
@@ -1436,10 +1426,8 @@ static ParseResult resolveOpBundleOperands(
14361426
// <operation> ::= `llvm.call` (cconv)? (tailcallkind)? (function-id | ssa-use)
14371427
// `(` ssa-use-list `)`
14381428
// ( `vararg(` var-callee-type `)` )?
1439-
// ( `bundlearg(` ssa-use-list-list `)` )?
1440-
// ( `bundletags(` str-elements-attr `) )
1429+
// ( `[` op-bundles-list `]` )?
14411430
// attribute-dict? `:` (type `,`)? function-type
1442-
// (`,` `bundletype(` type-list-list `)`)?
14431431
ParseResult CallOp::parse(OpAsmParser &parser, OperationState &result) {
14441432
SymbolRefAttr funcAttr;
14451433
TypeAttr varCalleeType;
@@ -1487,10 +1475,10 @@ ParseResult CallOp::parse(OpAsmParser &parser, OperationState &result) {
14871475
return failure();
14881476
}
14891477

1490-
auto opBundlesLoc = parser.getCurrentLocation();
1491-
if (auto result = parseOpBundles(parser, opBundleOperands,
1492-
opBundleOperandTypes, opBundleTags);
1493-
result.has_value() && failed(*result))
1478+
SMLoc opBundlesLoc = parser.getCurrentLocation();
1479+
if (std::optional<ParseResult> result = parseOpBundles(
1480+
parser, opBundleOperands, opBundleOperandTypes, opBundleTags);
1481+
result && failed(*result))
14941482
return failure();
14951483
if (!opBundleTags.empty())
14961484
result.getOrAddProperties<CallOp::Properties>().op_bundle_tags =
@@ -1657,10 +1645,8 @@ void InvokeOp::print(OpAsmPrinter &p) {
16571645
// `to` bb-id (`[` ssa-use-and-type-list `]`)?
16581646
// `unwind` bb-id (`[` ssa-use-and-type-list `]`)?
16591647
// ( `vararg(` var-callee-type `)` )?
1660-
// ( `bundlearg(` ssa-use-list-list `)` )?
1661-
// ( `bundletags(` str-elements-attr `) )
1648+
// ( `[` op-bundles-list `]` )?
16621649
// attribute-dict? `:` (type `,`)? function-type
1663-
// (`,` `bundletype(` type-list-list `)`)?
16641650
ParseResult InvokeOp::parse(OpAsmParser &parser, OperationState &result) {
16651651
SmallVector<OpAsmParser::UnresolvedOperand, 8> operands;
16661652
SymbolRefAttr funcAttr;
@@ -1708,10 +1694,10 @@ ParseResult InvokeOp::parse(OpAsmParser &parser, OperationState &result) {
17081694
return failure();
17091695
}
17101696

1711-
auto opBundlesLoc = parser.getCurrentLocation();
1712-
if (auto result = parseOpBundles(parser, opBundleOperands,
1713-
opBundleOperandTypes, opBundleTags);
1714-
result.has_value() && failed(*result))
1697+
SMLoc opBundlesLoc = parser.getCurrentLocation();
1698+
if (std::optional<ParseResult> result = parseOpBundles(
1699+
parser, opBundleOperands, opBundleOperandTypes, opBundleTags);
1700+
result && failed(*result))
17151701
return failure();
17161702
if (!opBundleTags.empty())
17171703
result.getOrAddProperties<InvokeOp::Properties>().op_bundle_tags =

mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ convertOperandBundle(OperandRange bundleOperands, StringRef bundleTag,
107107
LLVM::ModuleTranslation &moduleTranslation) {
108108
std::vector<llvm::Value *> operands;
109109
operands.reserve(bundleOperands.size());
110-
for (auto bundleArg : bundleOperands)
110+
for (Value bundleArg : bundleOperands)
111111
operands.push_back(moduleTranslation.lookupValue(bundleArg));
112112
return llvm::OperandBundleDef(bundleTag.str(), std::move(operands));
113113
}
@@ -131,7 +131,7 @@ static SmallVector<llvm::OperandBundleDef>
131131
convertOperandBundles(OperandRangeRange bundleOperands,
132132
std::optional<ArrayRef<std::string>> bundleTags,
133133
LLVM::ModuleTranslation &moduleTranslation) {
134-
if (!bundleTags.has_value())
134+
if (!bundleTags)
135135
bundleTags.emplace();
136136
return convertOperandBundles(bundleOperands, *bundleTags, moduleTranslation);
137137
}

mlir/test/Dialect/LLVMIR/invalid.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1662,6 +1662,6 @@ llvm.func @foo()
16621662
llvm.func @wrong_number_of_bundle_types() {
16631663
%0 = llvm.mlir.constant(0 : i32) : i32
16641664
// expected-error@+1 {{expected 1 types for operand bundle operands for operand bundle #0, but actually got 2}}
1665-
llvm.call @foo() ["tag"(%0 : i32, i32)] : () -> () bundletype((i32, i32))
1665+
llvm.call @foo() ["tag"(%0 : i32, i32)] : () -> ()
16661666
llvm.return
16671667
}

0 commit comments

Comments
 (0)