MLIR 23.0.0git
Utils.h
Go to the documentation of this file.
1//===- Utils.h - MPI dialect --------------------------------------*- C++-*-==//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef MLIR_DIALECT_MPI_IR_UTILS_H_
9#define MLIR_DIALECT_MPI_IR_UTILS_H_
10
15
16namespace mlir {
17namespace mpi {
18template <typename OpT>
19LogicalResult FoldToDLTIConst(OpT op, const char *key,
21 auto comm = op.getComm();
22 if (!comm.template getDefiningOp<mlir::mpi::CommWorldOp>())
23 return mlir::failure();
24
25 // Try to get DLTI attribute for MPI:comm_world_rank
26 // If found, set worldRank to the value of the attribute.
27 auto dltiAttr = dlti::query(op, {key}, false);
28 if (failed(dltiAttr))
29 return mlir::failure();
30 if (!isa<IntegerAttr>(dltiAttr.value()))
31 return op->emitError() << "Expected an integer attribute for " << key;
32 Value res = arith::ConstantOp::create(
33 b, op.getLoc(), b.getI32Type(),
34 b.getI32IntegerAttr(cast<IntegerAttr>(dltiAttr.value()).getInt()));
35 if (Value retVal = op.getRetval())
36 b.replaceOp(op, {retVal, res});
37 else
38 b.replaceOp(op, res);
39 return mlir::success();
40}
41} // namespace mpi
42} // namespace mlir
43
44#endif // MLIR_DIALECT_MPI_IR_UTILS_H_
b
Return true if permutation is a valid permutation of the outer_dims_perm (case OuterOrInnerPerm::Oute...
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
FailureOr< Attribute > query(Operation *op, ArrayRef< DataLayoutEntryKey > keys, bool emitError=false)
Perform a DLTI-query at op, recursively querying each key of keys on query interface-implementing att...
Definition DLTI.cpp:537
LogicalResult FoldToDLTIConst(OpT op, const char *key, mlir::PatternRewriter &b)
Definition Utils.h:19
Include the generated interface declarations.