65 lines · cpp
1//===-- CGOps.cpp -- FIR codegen operations -------------------------------===//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-exception6//7//===----------------------------------------------------------------------===//8//9// Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/10//11//===----------------------------------------------------------------------===//12 13#include "flang/Optimizer/Dialect/FIRCG/CGOps.h"14#include "flang/Optimizer/Dialect/FIRDialect.h"15#include "flang/Optimizer/Dialect/FIROps.h"16#include "flang/Optimizer/Dialect/FIRType.h"17 18/// FIR codegen dialect constructor.19fir::FIRCodeGenDialect::FIRCodeGenDialect(mlir::MLIRContext *ctx)20 : mlir::Dialect("fircg", ctx, mlir::TypeID::get<FIRCodeGenDialect>()) {21 addOperations<22#define GET_OP_LIST23#include "flang/Optimizer/Dialect/FIRCG/CGOps.cpp.inc"24 >();25}26 27// anchor the class vtable to this compilation unit28fir::FIRCodeGenDialect::~FIRCodeGenDialect() {29 // do nothing30}31 32#define GET_OP_CLASSES33#include "flang/Optimizer/Dialect/FIRCG/CGOps.cpp.inc"34 35unsigned fir::cg::XEmboxOp::getOutRank() {36 if (getSlice().empty())37 return getRank();38 auto outRank = fir::SliceOp::getOutputRank(getSlice());39 assert(outRank >= 1);40 return outRank;41}42 43unsigned fir::cg::XReboxOp::getOutRank() {44 if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(45 fir::dyn_cast_ptrOrBoxEleTy(getType())))46 return seqTy.getDimension();47 return 0;48}49 50unsigned fir::cg::XReboxOp::getRank() {51 if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(52 fir::dyn_cast_ptrOrBoxEleTy(getBox().getType())))53 return seqTy.getDimension();54 return 0;55}56 57unsigned fir::cg::XArrayCoorOp::getRank() {58 auto memrefTy = getMemref().getType();59 if (mlir::isa<fir::BaseBoxType>(memrefTy))60 if (auto seqty = mlir::dyn_cast<fir::SequenceType>(61 fir::dyn_cast_ptrOrBoxEleTy(memrefTy)))62 return seqty.getDimension();63 return getShape().size();64}65