Skip to content

Commit e39668d

Browse files
authored
[fir] Move verifier of AllocaOp and AllocMemOp tothe .cpp file
1 parent b729d8a commit e39668d

File tree

2 files changed

+30
-26
lines changed

2 files changed

+30
-26
lines changed

flang/include/flang/Optimizer/Dialect/FIROps.td

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -151,19 +151,7 @@ def fir_AllocaOp : fir_Op<"alloca", [AttrSizedOperandSegments,
151151
CArg<"mlir::ValueRange", "{}">:$shape,
152152
CArg<"llvm::ArrayRef<mlir::NamedAttribute>", "{}">:$attributes)>];
153153

154-
let verifier = [{
155-
llvm::SmallVector<llvm::StringRef> visited;
156-
if (verifyInType(getInType(), visited, numShapeOperands()))
157-
return emitOpError("invalid type for allocation");
158-
if (verifyTypeParamCount(getInType(), numLenParams()))
159-
return emitOpError("LEN params do not correspond to type");
160-
mlir::Type outType = getType();
161-
if (!outType.isa<fir::ReferenceType>())
162-
return emitOpError("must be a !fir.ref type");
163-
if (fir::isa_unknown_size_box(fir::dyn_cast_ptrEleTy(outType)))
164-
return emitOpError("cannot allocate !fir.box of unknown rank or type");
165-
return mlir::success();
166-
}];
154+
let verifier = [{ return ::verify(*this); }];
167155

168156
let extraClassDeclaration = [{
169157
mlir::Type getAllocatedType();
@@ -220,19 +208,7 @@ def fir_AllocMemOp : fir_Op<"allocmem",
220208
CArg<"mlir::ValueRange", "{}">:$shape,
221209
CArg<"llvm::ArrayRef<mlir::NamedAttribute>", "{}">:$attributes)>];
222210

223-
let verifier = [{
224-
llvm::SmallVector<llvm::StringRef> visited;
225-
if (verifyInType(getInType(), visited, numShapeOperands()))
226-
return emitOpError("invalid type for allocation");
227-
if (verifyTypeParamCount(getInType(), numLenParams()))
228-
return emitOpError("LEN params do not correspond to type");
229-
mlir::Type outType = getType();
230-
if (!outType.dyn_cast<fir::HeapType>())
231-
return emitOpError("must be a !fir.heap type");
232-
if (fir::isa_unknown_size_box(fir::dyn_cast_ptrEleTy(outType)))
233-
return emitOpError("cannot allocate !fir.box of unknown rank or type");
234-
return mlir::success();
235-
}];
211+
let verifier = [{ return ::verify(*this); }];
236212

237213
let extraClassDeclaration = [{
238214
mlir::Type getAllocatedType();

flang/lib/Optimizer/Dialect/FIROps.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,20 @@ void fir::AllocaOp::build(mlir::OpBuilder &builder,
202202
result.addAttributes(attributes);
203203
}
204204

205+
static mlir::LogicalResult verify(fir::AllocaOp &op) {
206+
llvm::SmallVector<llvm::StringRef> visited;
207+
if (verifyInType(op.getInType(), visited, op.numShapeOperands()))
208+
return op.emitOpError("invalid type for allocation");
209+
if (verifyTypeParamCount(op.getInType(), op.numLenParams()))
210+
return op.emitOpError("LEN params do not correspond to type");
211+
mlir::Type outType = op.getType();
212+
if (!outType.isa<fir::ReferenceType>())
213+
return op.emitOpError("must be a !fir.ref type");
214+
if (fir::isa_unknown_size_box(fir::dyn_cast_ptrEleTy(outType)))
215+
return op.emitOpError("cannot allocate !fir.box of unknown rank or type");
216+
return mlir::success();
217+
}
218+
205219
//===----------------------------------------------------------------------===//
206220
// AllocMemOp
207221
//===----------------------------------------------------------------------===//
@@ -267,6 +281,20 @@ void fir::AllocMemOp::build(mlir::OpBuilder &builder,
267281
result.addAttributes(attributes);
268282
}
269283

284+
static mlir::LogicalResult verify(fir::AllocMemOp &op) {
285+
llvm::SmallVector<llvm::StringRef> visited;
286+
if (verifyInType(op.getInType(), visited, op.numShapeOperands()))
287+
return op.emitOpError("invalid type for allocation");
288+
if (verifyTypeParamCount(op.getInType(), op.numLenParams()))
289+
return op.emitOpError("LEN params do not correspond to type");
290+
mlir::Type outType = op.getType();
291+
if (!outType.dyn_cast<fir::HeapType>())
292+
return op.emitOpError("must be a !fir.heap type");
293+
if (fir::isa_unknown_size_box(fir::dyn_cast_ptrEleTy(outType)))
294+
return op.emitOpError("cannot allocate !fir.box of unknown rank or type");
295+
return mlir::success();
296+
}
297+
270298
//===----------------------------------------------------------------------===//
271299
// ArrayCoorOp
272300
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)