Skip to content

Commit a1c3cc5

Browse files
authored
[CIR][Builder][NFC] Refactor getPointerTo considering AddressSpaceAttr (#746)
After switching to a separate address space attribute in CIR, we need better helper methods in CIR builder. This PR provides: * two versions of `getPointerTo`, consuming `LangAS` or `AddressSpaceAttr`. * an extra helper method `getAddrSpaceAttr(LangAS)` that is used by `getPointerTo(LangAS)` and other potential use cases (mainly about address space cast in the future). Calls to `getPointerTo` without addrspace will invoke the version consuming `AddressSpaceAttr` and return a type with null addrspace attribute, which should be exactly what we expect for CIRBuilder.
1 parent b7ff719 commit a1c3cc5

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h

+12-6
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,19 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
7575
return mlir::cir::IntType::get(getContext(), N, true);
7676
}
7777

78-
mlir::cir::PointerType
79-
getPointerTo(mlir::Type ty, clang::LangAS langAS = clang::LangAS::Default) {
80-
mlir::cir::AddressSpaceAttr addrSpaceAttr;
81-
if (langAS != clang::LangAS::Default)
82-
addrSpaceAttr = mlir::cir::AddressSpaceAttr::get(getContext(), langAS);
78+
mlir::cir::AddressSpaceAttr getAddrSpaceAttr(clang::LangAS langAS) {
79+
if (langAS == clang::LangAS::Default)
80+
return {};
81+
return mlir::cir::AddressSpaceAttr::get(getContext(), langAS);
82+
}
83+
84+
mlir::cir::PointerType getPointerTo(mlir::Type ty,
85+
mlir::cir::AddressSpaceAttr cirAS = {}) {
86+
return mlir::cir::PointerType::get(getContext(), ty, cirAS);
87+
}
8388

84-
return mlir::cir::PointerType::get(getContext(), ty, addrSpaceAttr);
89+
mlir::cir::PointerType getPointerTo(mlir::Type ty, clang::LangAS langAS) {
90+
return getPointerTo(ty, getAddrSpaceAttr(langAS));
8591
}
8692

8793
mlir::cir::PointerType

0 commit comments

Comments
 (0)