|
| 1 | +//===----------------------------------------------------------------------===// |
| 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 | +// |
| 9 | +// Implementation of external dialect interfaces for CIR. |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#include "clang/CIR/Dialect/OpenACC/CIROpenACCTypeInterfaces.h" |
| 14 | +#include "clang/CIR/Dialect/IR/CIRDialect.h" |
| 15 | +#include "clang/CIR/Dialect/IR/CIRTypes.h" |
| 16 | + |
| 17 | +namespace cir::acc { |
| 18 | + |
| 19 | +mlir::Type getBaseType(mlir::Value varPtr) { |
| 20 | + mlir::Operation *op = varPtr.getDefiningOp(); |
| 21 | + assert(op && "Expected a defining operation"); |
| 22 | + |
| 23 | + // This is the variable definition we're looking for. |
| 24 | + if (auto allocaOp = mlir::dyn_cast<cir::AllocaOp>(*op)) |
| 25 | + return allocaOp.getAllocaType(); |
| 26 | + |
| 27 | + // Look through casts to the source pointer. |
| 28 | + if (auto castOp = mlir::dyn_cast<cir::CastOp>(*op)) |
| 29 | + return getBaseType(castOp.getSrc()); |
| 30 | + |
| 31 | + // Follow the source of ptr strides. |
| 32 | + if (auto ptrStrideOp = mlir::dyn_cast<cir::PtrStrideOp>(*op)) |
| 33 | + return getBaseType(ptrStrideOp.getBase()); |
| 34 | + |
| 35 | + if (auto getMemberOp = mlir::dyn_cast<cir::GetMemberOp>(*op)) |
| 36 | + return getBaseType(getMemberOp.getAddr()); |
| 37 | + |
| 38 | + return mlir::cast<cir::PointerType>(varPtr.getType()).getPointee(); |
| 39 | +} |
| 40 | + |
| 41 | +template <> |
| 42 | +mlir::acc::VariableTypeCategory |
| 43 | +OpenACCPointerLikeModel<cir::PointerType>::getPointeeTypeCategory( |
| 44 | + mlir::Type pointer, mlir::TypedValue<mlir::acc::PointerLikeType> varPtr, |
| 45 | + mlir::Type varType) const { |
| 46 | + mlir::Type eleTy = getBaseType(varPtr); |
| 47 | + |
| 48 | + if (auto mappableTy = mlir::dyn_cast<mlir::acc::MappableType>(eleTy)) |
| 49 | + return mappableTy.getTypeCategory(varPtr); |
| 50 | + |
| 51 | + if (isAnyIntegerOrFloatingPointType(eleTy) || |
| 52 | + mlir::isa<cir::BoolType>(eleTy) || mlir::isa<cir::PointerType>(eleTy)) |
| 53 | + return mlir::acc::VariableTypeCategory::scalar; |
| 54 | + if (mlir::isa<cir::ArrayType>(eleTy)) |
| 55 | + return mlir::acc::VariableTypeCategory::array; |
| 56 | + if (mlir::isa<cir::RecordType>(eleTy)) |
| 57 | + return mlir::acc::VariableTypeCategory::composite; |
| 58 | + if (mlir::isa<cir::FuncType>(eleTy) || mlir::isa<cir::VectorType>(eleTy)) |
| 59 | + return mlir::acc::VariableTypeCategory::nonscalar; |
| 60 | + |
| 61 | + // Without further checking, this type cannot be categorized. |
| 62 | + return mlir::acc::VariableTypeCategory::uncategorized; |
| 63 | +} |
| 64 | + |
| 65 | +} // namespace cir::acc |
0 commit comments