Identify memory regions

I am working on an architecture that uses scratchpad memory. So I am planning to implement a pass that inserts data transfer instructions(custom) before the computation. Look at the below example where the fun() needs A, B, C arrays. Before invoking fun(), I have the move these arrays to the scratchpad. How do I identify the memory region accessed by these arrays? Any pointers would be helpful.

void fun(int *A, int *B, int *C, int start, int end){
        for (int i = start; i < end; ++i)
		[i] = A[i] + B[i];

void test(){
	int start, end;
	int *A, *B, *C;
	// Intialize variables

	// TODO: 
	//	 1. Identify the memory region accessed by A, B and C
	//   2. Move the accessed regions to scratchpad memory
	fun(A, B, C, start, end);

Clang supports address spaces.

#define DAX __attribute__((address_space(256)))
#define NODAX __attribute__((address_space(255)))

void DAX *  pmem_map_file(const char *path, size_t len, int flags, mode_t mode,
                    size_t *mapped_lenp, int *is_pmemp);

void pmem_flush(const void DAX *addr, size_t len);

It is commonly used for GPUs. They have to address the same problems that you are facing.

Worth pointing out that for LLVM backend address space, the common pattern is to have a corresponding attribute built into Clang. For reasons which I don’t remember, folks weren’t too keen on using the generic address_space attribute for this.