[Mlir-commits] [mlir] [mlir][emitc] Add EmitC index types (PR #93155)

Corentin Ferry llvmlistbot at llvm.org
Wed May 29 01:21:23 PDT 2024


================
@@ -1570,6 +1570,10 @@ LogicalResult CppEmitter::emitType(Location loc, Type type) {
   }
   if (auto iType = dyn_cast<IndexType>(type))
     return (os << "size_t"), success();
+  if (auto sType = dyn_cast<emitc::SizeTType>(type))
+    return (os << "size_t"), success();
+  if (auto sType = dyn_cast<emitc::SignedSizeTType>(type))
+    return (os << "ssize_t"), success();
----------------
cferry-AMD wrote:

So here's what I did in the end: we'll keep `size_t`, `ssize_t` in EmitC with this note that `ssize_t` goes out of C99. We also add `ptrdiff_t` as a data type, and conversion functions to go back and forth between types with different signedness and same bitwidth.

This enables passes to make abstraction of which data type is actually used (and just have a data type that accurately represents `index`), while also providing them with explicit C-world data types they can use (e.g. a pass will want to explicitly use `size_t` if they're calling `sizeof`).

https://github.com/llvm/llvm-project/pull/93155


More information about the Mlir-commits mailing list