|
11 | 11 | //===----------------------------------------------------------------------===// |
12 | 12 |
|
13 | 13 | #include "clang/CIR/Dialect/OpenACC/CIROpenACCTypeInterfaces.h" |
| 14 | +#include "clang/CIR/Dialect/IR/CIRDialect.h" |
14 | 15 |
|
15 | 16 | namespace cir::acc { |
16 | 17 |
|
| 18 | +mlir::Type getBaseType(mlir::Value varPtr) { |
| 19 | + mlir::Operation *op = varPtr.getDefiningOp(); |
| 20 | + assert(op && "Expected a defining operation"); |
| 21 | + |
| 22 | + // This is the variable definition we're looking for. |
| 23 | + if (auto allocaOp = mlir::dyn_cast<cir::AllocaOp>(*op)) |
| 24 | + return allocaOp.getAllocaType(); |
| 25 | + |
| 26 | + // Look through casts to the source pointer. |
| 27 | + if (auto castOp = mlir::dyn_cast<cir::CastOp>(*op)) |
| 28 | + return getBaseType(castOp.getSrc()); |
| 29 | + |
| 30 | + // Follow the source of ptr strides. |
| 31 | + if (auto ptrStrideOp = mlir::dyn_cast<cir::PtrStrideOp>(*op)) |
| 32 | + return getBaseType(ptrStrideOp.getBase()); |
| 33 | + |
| 34 | + if (auto getMemberOp = mlir::dyn_cast<cir::GetMemberOp>(*op)) |
| 35 | + return getBaseType(getMemberOp.getAddr()); |
| 36 | + |
| 37 | + return mlir::cast<cir::PointerType>(varPtr.getType()).getPointee(); |
| 38 | +} |
| 39 | + |
17 | 40 | template <> |
18 | 41 | mlir::acc::VariableTypeCategory |
19 | 42 | OpenACCPointerLikeModel<cir::PointerType>::getPointeeTypeCategory( |
20 | 43 | mlir::Type pointer, mlir::TypedValue<mlir::acc::PointerLikeType> varPtr, |
21 | 44 | mlir::Type varType) const { |
22 | | - mlir::Type eleTy = mlir::cast<cir::PointerType>(pointer).getPointee(); |
| 45 | + mlir::Type eleTy = getBaseType(varPtr); |
23 | 46 |
|
24 | 47 | if (auto mappableTy = mlir::dyn_cast<mlir::acc::MappableType>(eleTy)) |
25 | 48 | return mappableTy.getTypeCategory(varPtr); |
|
0 commit comments