namespace fir {
/// Return the integer value of a arith::ConstantOp.
inline std::int64_t toInt(mlir::arith::ConstantOp cop) {
- return cop.value().cast<mlir::IntegerAttr>().getValue().getSExtValue();
+ return cop.getValue().cast<mlir::IntegerAttr>().getValue().getSExtValue();
}
} // namespace fir
def fir_Dialect : Dialect {
let name = "fir";
let cppNamespace = "::fir";
+ let emitAccessorPrefix = kEmitAccessorPrefix_Both;
}
#endif // FORTRAN_DIALECT_FIR_DIALECT
unsigned numShapeOperands() { return shape().size(); }
operand_range getShapeOperands() { return shape(); }
static mlir::Type getRefTy(mlir::Type ty);
- mlir::Type getInType() { return in_type(); }
}];
}
unsigned numShapeOperands() { return shape().size(); }
operand_range getShapeOperands() { return shape(); }
static mlir::Type getRefTy(mlir::Type ty);
- mlir::Type getInType() { return in_type(); }
}];
}
}
// The selector is the value being tested to determine the destination
- mlir::Value getSelector() { return selector(); }
mlir::Value getSelector(llvm::ArrayRef<mlir::Value> operands) {
return operands[0];
}
let verifier = "return ::verify(*this);";
let extraClassDeclaration = [{
- mlir::Value getShape() { return shape(); }
- mlir::Value getSlice() { return slice(); }
bool hasLenParams() { return !typeparams().empty(); }
unsigned numLenParams() { return typeparams().size(); }
}];
[{ return build($_builder, $_state, resultType, ref, coor,
mlir::TypeAttr::get(ref.getType())); }]>,
];
-
- let extraClassDeclaration = [{
- /// Get the type of the base object.
- mlir::Type getBaseType() { return baseType(); }
- }];
}
def fir_ExtractValueOp : fir_OneResultOp<"extract_value", [NoSideEffect]> {
}];
let verifier = "return ::verify(*this);";
-
- let extraClassDeclaration = [{
- std::vector<mlir::Value> getExtents() {
- return {extents().begin(), extents().end()};
- }
- }];
}
def fir_ShapeShiftOp : fir_Op<"shape_shift", [NoSideEffect]> {
}];
let verifier = "return ::verify(*this);";
-
- let extraClassDeclaration = [{
- std::vector<mlir::Value> getOrigins() {
- return {origins().begin(), origins().end()};
- }
- }];
}
def fir_SliceOp : fir_Op<"slice", [NoSideEffect, AttrSizedOperandSegments]> {
let extraClassDeclaration = [{
static constexpr llvm::StringRef fieldAttrName() { return "field_id"; }
static constexpr llvm::StringRef typeAttrName() { return "on_type"; }
- mlir::Type getOnType() {
- return (*this)->getAttrOfType<TypeAttr>(typeAttrName()).getValue();
- }
}];
}
];
let extraClassDeclaration = [{
- static constexpr llvm::StringRef getFinalValueAttrName() {
+ static constexpr llvm::StringRef getFinalValueAttrNameStr() {
return "finalValue";
}
mlir::Block *getBody() { return ®ion().front(); }
}]>];
let extraClassDeclaration = [{
- static constexpr StringRef getCalleeAttrName() { return "callee"; }
+ static constexpr StringRef getCalleeAttrNameStr() { return "callee"; }
mlir::FunctionType getFunctionType();
static constexpr llvm::StringRef passArgAttrName() {
return "pass_arg_pos";
}
- static constexpr llvm::StringRef getMethodAttrName() { return "method"; }
+ static constexpr llvm::StringRef getMethodAttrNameStr() { return "method"; }
unsigned passArgPos();
}];
}
let builders = [OpBuilder<(ins "mlir::TypeAttr":$inty)>];
let verifier = "return ::verify(*this);";
-
- let extraClassDeclaration = [{
- mlir::Type getInType() {
- // get the type that the type descriptor describes
- return (*this)->getAttrOfType<mlir::TypeAttr>("in_type").getValue();
- }
- }];
}
def fir_NoReassocOp : fir_OneResultOp<"no_reassoc",
];
let extraClassDeclaration = [{
- static constexpr llvm::StringRef symbolAttrName() { return "symref"; }
- static constexpr llvm::StringRef getConstantAttrName() {
+ static constexpr llvm::StringRef symbolAttrNameStr() { return "symref"; }
+ static constexpr llvm::StringRef getConstantAttrNameStr() {
return "constant";
}
static constexpr llvm::StringRef linkageAttrName() { return "linkName"; }
/// the variable's initial value.
void appendInitialValue(mlir::Operation *op);
- /// A GlobalOp has one region.
- mlir::Region &getRegion() { return (*this)->getRegion(0); }
-
/// A GlobalOp has one block.
mlir::Block &getBlock() { return getRegion().front(); }
/// Append a dispatch table entry to the table.
void appendTableEntry(mlir::Operation *op);
- mlir::Region &getRegion() {
- return (*this)->getRegion(0);
- }
-
mlir::Block &getBlock() {
return getRegion().front();
}
let printer = "::print(p, *this);";
let extraClassDeclaration = [{
- static constexpr llvm::StringRef getMethodAttrName() { return "method"; }
- static constexpr llvm::StringRef getProcAttrName() { return "proc"; }
+ static constexpr llvm::StringRef getMethodAttrNameStr() { return "method"; }
+ static constexpr llvm::StringRef getProcAttrNameStr() { return "proc"; }
}];
}
namespace fir {
/// Return the integer value of a arith::ConstantOp.
inline std::int64_t toInt(mlir::arith::ConstantOp cop) {
- return cop.value().cast<mlir::IntegerAttr>().getValue().getSExtValue();
+ return cop.getValue().cast<mlir::IntegerAttr>().getValue().getSExtValue();
}
} // namespace fir
if (auto *shapeOp = shapeVal.getDefiningOp()) {
if (auto shOp = mlir::dyn_cast<fir::ShapeShiftOp>(shapeOp))
return shOp.getOrigins();
- if (auto shOp = mlir::dyn_cast<fir::ShiftOp>(shapeOp))
- return shOp.getOrigins();
+ if (auto shOp = mlir::dyn_cast<fir::ShiftOp>(shapeOp)) {
+ auto operands = shOp.getOrigins();
+ return {operands.begin(), operands.end()};
+ }
}
return {};
}
mlir::Type vecType = mlir::VectorType::get(
insertOp.getType().getShape(), constant.getType());
auto denseAttr = mlir::DenseElementsAttr::get(
- vecType.cast<ShapedType>(), constant.value());
+ vecType.cast<ShapedType>(), constant.getValue());
rewriter.setInsertionPointAfter(insertOp);
rewriter.replaceOpWithNewOp<mlir::arith::ConstantOp>(
insertOp, seqTyAttr, denseAttr);
std::vector<mlir::Value> fir::ArrayLoadOp::getExtents() {
if (auto sh = shape())
if (auto *op = sh.getDefiningOp()) {
- if (auto shOp = dyn_cast<fir::ShapeOp>(op))
- return shOp.getExtents();
+ if (auto shOp = dyn_cast<fir::ShapeOp>(op)) {
+ auto extents = shOp.getExtents();
+ return {extents.begin(), extents.end()};
+ }
return cast<fir::ShapeShiftOp>(op).getExtents();
}
return {};
void fir::CallOp::build(mlir::OpBuilder &builder, mlir::OperationState &result,
mlir::FuncOp callee, mlir::ValueRange operands) {
result.addOperands(operands);
- result.addAttribute(getCalleeAttrName(), SymbolRefAttr::get(callee));
+ result.addAttribute(getCalleeAttrNameStr(), SymbolRefAttr::get(callee));
result.addTypes(callee.getType().getResults());
}
mlir::ValueRange operands) {
result.addOperands(operands);
if (callee)
- result.addAttribute(getCalleeAttrName(), callee);
+ result.addAttribute(getCalleeAttrNameStr(), callee);
result.addTypes(results);
}
llvm::StringRef calleeName;
if (failed(parser.parseOptionalKeyword(&calleeName))) {
mlir::StringAttr calleeAttr;
- if (parser.parseAttribute(calleeAttr, fir::DispatchOp::getMethodAttrName(),
+ if (parser.parseAttribute(calleeAttr,
+ fir::DispatchOp::getMethodAttrNameStr(),
result.attributes))
return mlir::failure();
} else {
- result.addAttribute(fir::DispatchOp::getMethodAttrName(),
+ result.addAttribute(fir::DispatchOp::getMethodAttrNameStr(),
parser.getBuilder().getStringAttr(calleeName));
}
if (parser.parseOperandList(operands, mlir::OpAsmParser::Delimiter::Paren) ||
}
static void print(mlir::OpAsmPrinter &p, fir::DispatchOp &op) {
- p << ' ' << op.getOperation()->getAttr(fir::DispatchOp::getMethodAttrName())
- << '(';
+ p << ' ' << op.getMethodAttr() << '(';
p.printOperand(op.object());
if (!op.args().empty()) {
p << ", ";
// Parse the name as a symbol reference attribute.
mlir::SymbolRefAttr nameAttr;
- if (parser.parseAttribute(nameAttr, fir::GlobalOp::symbolAttrName(),
+ if (parser.parseAttribute(nameAttr, fir::GlobalOp::symbolAttrNameStr(),
result.attributes))
return mlir::failure();
result.addAttribute(mlir::SymbolTable::getSymbolAttrName(),
if (op.linkName().hasValue())
p << ' ' << op.linkName().getValue();
p << ' ';
- p.printAttributeWithoutType(
- op.getOperation()->getAttr(fir::GlobalOp::symbolAttrName()));
+ p.printAttributeWithoutType(op.getSymrefAttr());
if (auto val = op.getValueOrNull())
p << '(' << val << ')';
- if (op.getOperation()->getAttr(fir::GlobalOp::getConstantAttrName()))
+ if (op.getOperation()->getAttr(fir::GlobalOp::getConstantAttrNameStr()))
p << " constant";
p << " : ";
p.printType(op.getType());
result.addAttribute(typeAttrName(result.name), mlir::TypeAttr::get(type));
result.addAttribute(mlir::SymbolTable::getSymbolAttrName(),
builder.getStringAttr(name));
- result.addAttribute(symbolAttrName(),
+ result.addAttribute(symbolAttrNameStr(),
SymbolRefAttr::get(builder.getContext(), name));
if (isConstant)
result.addAttribute(constantAttrName(result.name), builder.getUnitAttr());
!isZero(insval2.coor()[0]))
return mlir::failure();
auto eai =
- dyn_cast_or_null<fir::ExtractValueOp>(binf.lhs().getDefiningOp());
+ dyn_cast_or_null<fir::ExtractValueOp>(binf.getLhs().getDefiningOp());
auto ebi =
- dyn_cast_or_null<fir::ExtractValueOp>(binf.rhs().getDefiningOp());
+ dyn_cast_or_null<fir::ExtractValueOp>(binf.getRhs().getDefiningOp());
auto ear =
- dyn_cast_or_null<fir::ExtractValueOp>(binf2.lhs().getDefiningOp());
+ dyn_cast_or_null<fir::ExtractValueOp>(binf2.getLhs().getDefiningOp());
auto ebr =
- dyn_cast_or_null<fir::ExtractValueOp>(binf2.rhs().getDefiningOp());
+ dyn_cast_or_null<fir::ExtractValueOp>(binf2.getRhs().getDefiningOp());
if (!eai || !ebi || !ear || !ebr || ear.adt() != eai.adt() ||
ebr.adt() != ebi.adt() || eai.coor().size() != 1 ||
!isOne(eai.coor()[0]) || ebi.coor().size() != 1 ||
result.addOperands({lb, ub, step, iterate});
if (finalCountValue) {
result.addTypes(builder.getIndexType());
- result.addAttribute(getFinalValueAttrName(), builder.getUnitAttr());
+ result.addAttribute(getFinalValueAttrNameStr(), builder.getUnitAttr());
}
result.addTypes(iterate.getType());
result.addOperands(iterArgs);
llvm::SmallVector<mlir::Type> argTypes;
// Induction variable (hidden)
if (prependCount)
- result.addAttribute(IterWhileOp::getFinalValueAttrName(),
+ result.addAttribute(IterWhileOp::getFinalValueAttrNameStr(),
builder.getUnitAttr());
else
argTypes.push_back(indexType);
p << " -> (" << op.getResultTypes() << ')';
}
p.printOptionalAttrDictWithKeyword(op->getAttrs(),
- {IterWhileOp::getFinalValueAttrName()});
+ {op.getFinalValueAttrNameStr()});
p.printRegion(op.region(), /*printEntryBlockArgs=*/false,
/*printBlockTerminators=*/true);
}
// allow `methodName` or `"methodName"`
if (failed(parser.parseOptionalKeyword(&methodName))) {
mlir::StringAttr methodAttr;
- if (parser.parseAttribute(methodAttr, fir::DTEntryOp::getMethodAttrName(),
+ if (parser.parseAttribute(methodAttr,
+ fir::DTEntryOp::getMethodAttrNameStr(),
result.attributes))
return mlir::failure();
} else {
- result.addAttribute(fir::DTEntryOp::getMethodAttrName(),
+ result.addAttribute(fir::DTEntryOp::getMethodAttrNameStr(),
parser.getBuilder().getStringAttr(methodName));
}
mlir::SymbolRefAttr calleeAttr;
if (parser.parseComma() ||
- parser.parseAttribute(calleeAttr, fir::DTEntryOp::getProcAttrName(),
+ parser.parseAttribute(calleeAttr, fir::DTEntryOp::getProcAttrNameStr(),
result.attributes))
return mlir::failure();
return mlir::success();
}
static void print(mlir::OpAsmPrinter &p, fir::DTEntryOp &op) {
- p << ' ' << op.getOperation()->getAttr(fir::DTEntryOp::getMethodAttrName())
- << ", " << op.getOperation()->getAttr(fir::DTEntryOp::getProcAttrName());
+ p << ' ' << op.getMethodAttr() << ", " << op.getProcAttr();
}
//===----------------------------------------------------------------------===//
static Optional<int64_t> constantIntegerLike(const mlir::Value value) {
if (auto definition = value.getDefiningOp<mlir::arith::ConstantOp>())
- if (auto stepAttr = definition.value().dyn_cast<IntegerAttr>())
+ if (auto stepAttr = definition.getValue().dyn_cast<IntegerAttr>())
return stepAttr.getInt();
return {};
}
accesses.push_back(owner);
appendToQueue(update.getResult(1));
} else if (auto br = mlir::dyn_cast<mlir::BranchOp>(owner)) {
- branchOp(br.getDest(), br.destOperands());
+ branchOp(br.getDest(), br.getDestOperands());
} else if (auto br = mlir::dyn_cast<mlir::CondBranchOp>(owner)) {
branchOp(br.getTrueDest(), br.getTrueOperands());
branchOp(br.getFalseDest(), br.getFalseOperands());
EXPECT_TRUE(mlir::isa<arith::SubIOp>(loop.upperBound().getDefiningOp()));
auto subOp = dyn_cast<arith::SubIOp>(loop.upperBound().getDefiningOp());
EXPECT_EQ(c10, subOp.lhs());
- checkConstantValue(subOp.rhs(), 1);
- checkConstantValue(loop.step(), 1);
+ checkConstantValue(subOp.getRhs(), 1);
+ checkConstantValue(loop.getStep(), 1);
}
TEST_F(DoLoopHelperTest, createLoopWithLowerAndUpperBound) {
firBuilder.getUnknownLoc(), firBuilder.getIndexType(), 20);
auto loop =
helper.createLoop(lb, ub, [&](fir::FirOpBuilder &, mlir::Value index) {});
- checkConstantValue(loop.lowerBound(), 1);
- checkConstantValue(loop.upperBound(), 20);
- checkConstantValue(loop.step(), 1);
+ checkConstantValue(loop.getLowerBound(), 1);
+ checkConstantValue(loop.getUpperBound(), 20);
+ checkConstantValue(loop.getStep(), 1);
}
TEST_F(DoLoopHelperTest, createLoopWithStep) {
firBuilder.getUnknownLoc(), firBuilder.getIndexType(), 2);
auto loop = helper.createLoop(
lb, ub, step, [&](fir::FirOpBuilder &, mlir::Value index) {});
- checkConstantValue(loop.lowerBound(), 1);
- checkConstantValue(loop.upperBound(), 20);
- checkConstantValue(loop.step(), 2);
+ checkConstantValue(loop.getLowerBound(), 1);
+ checkConstantValue(loop.getUpperBound(), 20);
+ checkConstantValue(loop.getStep(), 2);
}
auto loc = builder.getUnknownLoc();
auto cdt = createCondition(builder);
auto ifBuilder = builder.genIfThen(loc, cdt);
- EXPECT_FALSE(ifBuilder.getIfOp().thenRegion().empty());
- EXPECT_TRUE(ifBuilder.getIfOp().elseRegion().empty());
+ EXPECT_FALSE(ifBuilder.getIfOp().getThenRegion().empty());
+ EXPECT_TRUE(ifBuilder.getIfOp().getElseRegion().empty());
}
TEST_F(FIRBuilderTest, genIfThenElse) {
auto loc = builder.getUnknownLoc();
auto cdt = createCondition(builder);
auto ifBuilder = builder.genIfThenElse(loc, cdt);
- EXPECT_FALSE(ifBuilder.getIfOp().thenRegion().empty());
- EXPECT_FALSE(ifBuilder.getIfOp().elseRegion().empty());
+ EXPECT_FALSE(ifBuilder.getIfOp().getThenRegion().empty());
+ EXPECT_FALSE(ifBuilder.getIfOp().getElseRegion().empty());
}
TEST_F(FIRBuilderTest, genIfWithThen) {
auto loc = builder.getUnknownLoc();
auto cdt = createCondition(builder);
auto ifBuilder = builder.genIfOp(loc, {}, cdt, false);
- EXPECT_FALSE(ifBuilder.getIfOp().thenRegion().empty());
- EXPECT_TRUE(ifBuilder.getIfOp().elseRegion().empty());
+ EXPECT_FALSE(ifBuilder.getIfOp().getThenRegion().empty());
+ EXPECT_TRUE(ifBuilder.getIfOp().getElseRegion().empty());
}
TEST_F(FIRBuilderTest, genIfWithThenAndElse) {
auto loc = builder.getUnknownLoc();
auto cdt = createCondition(builder);
auto ifBuilder = builder.genIfOp(loc, {}, cdt, true);
- EXPECT_FALSE(ifBuilder.getIfOp().thenRegion().empty());
- EXPECT_FALSE(ifBuilder.getIfOp().elseRegion().empty());
+ EXPECT_FALSE(ifBuilder.getIfOp().getThenRegion().empty());
+ EXPECT_FALSE(ifBuilder.getIfOp().getElseRegion().empty());
}
//===----------------------------------------------------------------------===//
auto res = builder.genIsNotNull(loc, dummyValue);
EXPECT_TRUE(mlir::isa<arith::CmpIOp>(res.getDefiningOp()));
auto cmpOp = dyn_cast<arith::CmpIOp>(res.getDefiningOp());
- EXPECT_EQ(arith::CmpIPredicate::ne, cmpOp.predicate());
+ EXPECT_EQ(arith::CmpIPredicate::ne, cmpOp.getPredicate());
}
TEST_F(FIRBuilderTest, genIsNull) {
auto res = builder.genIsNull(loc, dummyValue);
EXPECT_TRUE(mlir::isa<arith::CmpIOp>(res.getDefiningOp()));
auto cmpOp = dyn_cast<arith::CmpIOp>(res.getDefiningOp());
- EXPECT_EQ(arith::CmpIPredicate::eq, cmpOp.predicate());
+ EXPECT_EQ(arith::CmpIPredicate::eq, cmpOp.getPredicate());
}
TEST_F(FIRBuilderTest, createZeroConstant) {
EXPECT_TRUE(mlir::isa<arith::ConstantOp>(cst.getDefiningOp()));
auto cstOp = dyn_cast<arith::ConstantOp>(cst.getDefiningOp());
EXPECT_EQ(realTy, cstOp.getType());
- EXPECT_EQ(0u, cstOp.value().cast<FloatAttr>().getValue().convertToDouble());
+ EXPECT_EQ(
+ 0u, cstOp.getValue().cast<FloatAttr>().getValue().convertToDouble());
}
TEST_F(FIRBuilderTest, createBool) {
mlir::Value cmp = selectOp.condition();
EXPECT_TRUE(mlir::isa<mlir::arith::CmpFOp>(cmp.getDefiningOp()));
auto cmpOp = mlir::dyn_cast<mlir::arith::CmpFOp>(cmp.getDefiningOp());
- EXPECT_EQ(s, cmpOp.lhs());
+ EXPECT_EQ(s, cmpOp.getLhs());
}
TEST_F(RuntimeCallTest, genNearestTest) {