[fir][NFC] Move fir.select_type builder to cpp file

Move the big builder out of the td file to the cpp file.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D110820
This commit is contained in:
Valentin Clement 2021-10-01 09:19:17 +02:00
parent b04dd35f0e
commit a149b103ca
No known key found for this signature in database
GPG Key ID: 086D54783C928776
2 changed files with 32 additions and 28 deletions

View File

@ -720,34 +720,7 @@ def fir_SelectTypeOp : fir_SwitchTerminatorOp<"select_type"> {
"llvm::ArrayRef<mlir::Attribute>":$typeOperands,
"llvm::ArrayRef<mlir::Block *>":$destinations,
CArg<"llvm::ArrayRef<mlir::ValueRange>", "{}">:$destOperands,
CArg<"llvm::ArrayRef<mlir::NamedAttribute>", "{}">:$attributes),
[{
$_state.addOperands(selector);
$_state.addAttribute(getCasesAttr(),
$_builder.getArrayAttr(typeOperands));
const auto count = destinations.size();
for (auto d : destinations)
$_state.addSuccessors(d);
const auto opCount = destOperands.size();
llvm::SmallVector<int32_t, 8> argOffs;
int32_t sumArgs = 0;
for (std::remove_const_t<decltype(count)> i = 0; i != count; ++i) {
if (i < opCount) {
$_state.addOperands(destOperands[i]);
const auto argSz = destOperands[i].size();
argOffs.push_back(argSz);
sumArgs += argSz;
} else {
argOffs.push_back(0);
}
}
$_state.addAttribute(getOperandSegmentSizeAttr(),
$_builder.getI32VectorAttr({1, 0, sumArgs}));
$_state.addAttribute(getTargetOffsetAttr(),
$_builder.getI32VectorAttr(argOffs));
$_state.addAttributes(attributes);
}]
>];
CArg<"llvm::ArrayRef<mlir::NamedAttribute>", "{}">:$attributes)>];
let parser = "return parseSelectType(parser, result);";

View File

@ -2671,6 +2671,37 @@ static mlir::LogicalResult verify(fir::SelectTypeOp &op) {
return mlir::success();
}
void fir::SelectTypeOp::build(mlir::OpBuilder &builder,
mlir::OperationState &result,
mlir::Value selector,
llvm::ArrayRef<mlir::Attribute> typeOperands,
llvm::ArrayRef<mlir::Block *> destinations,
llvm::ArrayRef<mlir::ValueRange> destOperands,
llvm::ArrayRef<mlir::NamedAttribute> attributes) {
result.addOperands(selector);
result.addAttribute(getCasesAttr(), builder.getArrayAttr(typeOperands));
const auto count = destinations.size();
for (mlir::Block *dest : destinations)
result.addSuccessors(dest);
const auto opCount = destOperands.size();
llvm::SmallVector<int32_t> argOffs;
int32_t sumArgs = 0;
for (std::remove_const_t<decltype(count)> i = 0; i != count; ++i) {
if (i < opCount) {
result.addOperands(destOperands[i]);
const auto argSz = destOperands[i].size();
argOffs.push_back(argSz);
sumArgs += argSz;
} else {
argOffs.push_back(0);
}
}
result.addAttribute(getOperandSegmentSizeAttr(),
builder.getI32VectorAttr({1, 0, sumArgs}));
result.addAttribute(getTargetOffsetAttr(), builder.getI32VectorAttr(argOffs));
result.addAttributes(attributes);
}
//===----------------------------------------------------------------------===//
// ShapeOp
//===----------------------------------------------------------------------===//