My function entry looks like this (%arg0: i32, %arg1: memref<?xi32>)
Block &entryBlock = func.getBody().front();
Value firstArg = entryBlock.getArgument(0);
I want to get the int value of %arg0 and create a memory space for it. MemRefType inputMemType = MemRefType::get({size}, firstArgType);
But size needs to be an int value and I have no way of extracting the int value of %arg0.
I am very confused by what you’re trying to achieve right now: you’re trying to build a memref type with a compile time constant size for the dimension, but at the same time you’re trying to get it from the function argument which is a dynamic value. Something is inconsistent here.
What you may want is a dynamic memref (the size is not known at compile time):
auto dynamicBufferType =
MemRefType::get(ShapedType::kDynamic, firstArgType);
This would be based on the operation you use to create the memref, not the type, e.g. if you use memref.alloc it would look something like memref.alloc(%arg0) : memref<?xi32>
This isn’t gonna be encoded in the type system: the type system does not support directly dependent types (I think this is what you’re looking for here?)
However as @troggo mentioned, you can allocate a memref with the function argument as size, the type itself will erase this size information though.