Extracting the int value of a function argument

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 always fail with this approach. My functions never have a body. I first have to create a block and then I can walk over the arguments.

  mlir::Block *entryBlock = builder.createBlock(
      &fun.getBody(), {}, parameterTypes, parameterLocation);

  entryBlock->getArguments();

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);

Yes, the size of the memref is not known before compiling. I want to create a memref whose size is determined by the function parameter(%arg0).

  auto dynamicBufferType =
      MemRefType::get(ShapedType::kDynamic, firstArgType);

A dynamic memref does not seem to be able to be related to the function parameter.

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.