UQ-PAC / BASIL

Apache License 2.0
8 stars 0 forks source link

Adding Memory Region Analysis results to IR #63

Open l-kent opened 1 year ago

l-kent commented 1 year ago

We want to add the results from the Memory Region Analysis to the intermediate representation. This means replacing all references to 'mem' in the IR with new variables representing discrete memory regions, derived from the memory region analysis. Each memory load and store should only have a single memory region associated with it - if the analysis says there are multiple regions, those regions need to be universally merged (in terms of the IR, anyway) to only have a single memory variable represent them. However, we want to keep stack regions distinct from other regions, so if there is a case where a memory access could potentially be either a stack access or a non-stack access, we should not merge the regions and instead create new blocks to represent both possibilities. I'm realising now we probably need to add non-deterministic branching to the IR for this case?

We want to keep track of which memory regions are stacks, so we probably need a flag for that in the Memory class.

ailrst commented 1 year ago
l-kent commented 1 year ago

Ideally the MRA will be able to replace that entirely, but an option does make sense for the time being

yousifpatti commented 1 year ago

Hey I started looking at this and I was able to replace memLoads and memStores with stack identifier using MRA. I was abe to replace the memLoads with values if only a single one is given from VSA.

However, I have also used OR to combine values in a case where a memLoad could lead to multiple values (is this correct?). I am not sure what you mean by "universally merged to only have a single memory variable represent them" as I am not sure how you would merge the values without using BVOR for all of them.

Here is the PR for this: #74

l-kent commented 1 year ago

What I mean is merging regions - if an access is ambiguous and could possibly be multiple regions according to the MRA & VSA, it's necessary to merge those regions into a single region for the purposes of the IR.

l-kent commented 1 year ago

To be clearer, the idea is to replace the mem variable for all accesses (MemoryLoads and MemoryStores) with a new Memory variable that represents the memory region. If an access could point to multiple regions, then you need to merge all those possible regions together for the purposes of the IR and represent them with a single Memory variable wherever any of those regions would be mentioned.

For example, if there is a MemoryStore that could be to the regions region1 or region2, then you need to merge region1 and region2 and represent them both with a new Memory variable region1_region2 (the names I've chosen are arbitrary) that is used in that MemoryStore. If there is a separate MemoryLoad that is only to region1, then you need to use the Memory region1_region2 for it as well.

As discussed yesterday, we don't want to replace MemoryLoads with static values from the VSA at the moment.

I hope that all makes sense.