Skip to content

Commit a901f39

Browse files
Thomas Symallatsymalla-AMD
authored andcommitted
Add support for typed pointers with the builtin PointerType.
In some scenarios, we want to use typed pointers even if LLVM is moving to opaque pointers. Dialects currently only supports opaque pointers in its builtin. With this change, we simply return an i8* when evaluating a builtin pointer type return value or operand. This translates to an opaque pointer as well. The client that creates the operations is responsible for handling the pointers correctly (e. g. not using opaque pointers in a typed pointer scenario).
1 parent c9d028d commit a901f39

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

include/llvm-dialects/Dialect/Dialect.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ def I64 : TgConstant<(IntegerType 64)>, Type;
169169

170170
def PointerType : BuiltinType {
171171
let arguments = (args type:$self, AttrI32:$address_space);
172-
let evaluate = "::llvm::PointerType::get($_context, $address_space)";
172+
// Supports both typed and opaque pointers.
173+
let evaluate = "::llvm::PointerType::get(::llvm::Type::getInt8Ty($_context), $address_space)";
173174
let check = "$self->isPointerTy()";
174175
let capture = ["$self->getPointerAddressSpace()"];
175176
}

test/example/generated/ExampleDialect.cpp.inc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,9 +1478,9 @@ initial
14781478
::llvm::Type * const resultType = getResult()->getType();
14791479
(void)resultType;
14801480

1481-
if (::llvm::PointerType::get(context, 0) != ptrType) {
1481+
if (::llvm::PointerType::get(::llvm::Type::getInt8Ty(context), 0) != ptrType) {
14821482
errs << " unexpected value of $ptr:\n";
1483-
errs << " expected: " << printable(::llvm::PointerType::get(context, 0)) << '\n';
1483+
errs << " expected: " << printable(::llvm::PointerType::get(::llvm::Type::getInt8Ty(context), 0)) << '\n';
14841484
errs << " actual: " << printable(ptrType) << '\n';
14851485

14861486
return false;
@@ -1570,9 +1570,9 @@ initial
15701570
::llvm::Type * const resultType = getResult()->getType();
15711571
(void)resultType;
15721572

1573-
if (::llvm::PointerType::get(context, 0) != ptrType) {
1573+
if (::llvm::PointerType::get(::llvm::Type::getInt8Ty(context), 0) != ptrType) {
15741574
errs << " unexpected value of $ptr:\n";
1575-
errs << " expected: " << printable(::llvm::PointerType::get(context, 0)) << '\n';
1575+
errs << " expected: " << printable(::llvm::PointerType::get(::llvm::Type::getInt8Ty(context), 0)) << '\n';
15761576
errs << " actual: " << printable(ptrType) << '\n';
15771577

15781578
return false;
@@ -1662,9 +1662,9 @@ initial
16621662
::llvm::Type * const resultType = getResult()->getType();
16631663
(void)resultType;
16641664

1665-
if (::llvm::PointerType::get(context, 0) != ptrType) {
1665+
if (::llvm::PointerType::get(::llvm::Type::getInt8Ty(context), 0) != ptrType) {
16661666
errs << " unexpected value of $ptr:\n";
1667-
errs << " expected: " << printable(::llvm::PointerType::get(context, 0)) << '\n';
1667+
errs << " expected: " << printable(::llvm::PointerType::get(::llvm::Type::getInt8Ty(context), 0)) << '\n';
16681668
errs << " actual: " << printable(ptrType) << '\n';
16691669

16701670
return false;

0 commit comments

Comments
 (0)