For identity layout (verified on line 672), stride*size gives the correct number of elements (stride is 'product(size[1..n-1])').
getMemrefDescriptorSizes is not the right API here, you would first need to extract the dynamic sizes from the struct.
Ah, this is subtle. Can you leave a comment so I understand this next time round, as well? Especially as the meaning of isSupportedMemRefType is not obvious here.