Skip to content

Commit bfa6ca8

Browse files
committed
Fix interior pointer handling
1 parent 6edf90c commit bfa6ca8

File tree

4 files changed

+285
-51
lines changed

4 files changed

+285
-51
lines changed

clang/lib/CIR/Dialect/OpenACC/CIROpenACCTypeInterfaces.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,38 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "clang/CIR/Dialect/OpenACC/CIROpenACCTypeInterfaces.h"
14+
#include "clang/CIR/Dialect/IR/CIRDialect.h"
1415

1516
namespace cir::acc {
1617

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+
1740
template <>
1841
mlir::acc::VariableTypeCategory
1942
OpenACCPointerLikeModel<cir::PointerType>::getPointeeTypeCategory(
2043
mlir::Type pointer, mlir::TypedValue<mlir::acc::PointerLikeType> varPtr,
2144
mlir::Type varType) const {
22-
mlir::Type eleTy = mlir::cast<cir::PointerType>(pointer).getPointee();
45+
mlir::Type eleTy = getBaseType(varPtr);
2346

2447
if (auto mappableTy = mlir::dyn_cast<mlir::acc::MappableType>(eleTy))
2548
return mappableTy.getTypeCategory(varPtr);

clang/lib/CIR/Dialect/OpenACC/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ add_clang_library(CIROpenACCSupport
77

88
LINK_LIBS PUBLIC
99
MLIRIR
10+
MLIRCIR
11+
MLIROpenACCDialect
1012
)

clang/unittests/CIR/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
add_clang_unittest(CIRUnitTests
1+
set(MLIR_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/../mlir/include )
2+
set(MLIR_TABLEGEN_OUTPUT_DIR ${CMAKE_BINARY_DIR}/tools/mlir/include)
3+
include_directories(SYSTEM ${MLIR_INCLUDE_DIR})
4+
include_directories(${MLIR_TABLEGEN_OUTPUT_DIR})
5+
6+
add_distinct_clang_unittest(CIRUnitTests
27
PointerLikeTest.cpp
38
LLVM_COMPONENTS
49
Core

0 commit comments

Comments
 (0)