Page MenuHomePhabricator

add 2 functions to the ALiasAnalysis interface (getAddressesDistance + ModRefSameBuffer)
Needs ReviewPublic

Authored by atheel.ma on May 15 2018, 1:43 AM.

Details

Summary

bool ModRefSameBuffer: returns if 2 Locations Mod/Ref same buff (same block in memory)
getAddressesDistance : returns the distance between 2 Locations if there are modifying the same block in memory and distance can be calculated

Diff Detail

Repository
rL LLVM

Event Timeline

atheel.ma created this revision.May 15 2018, 1:43 AM

Can you please comment on how you intend to implement the interface and how you'd like to use it?

atheel.ma added a comment.EditedMay 15 2018, 9:18 AM

Hi,
its very similar to the BasicAliasAnalysis aliasCheck() functions,
the declerations for the private function is:

BuffUseResult BasicAAResult::ModRefSameBufferCheck(
    const Value *V1, uint64_t V1Size, AAMDNodes V1AAInfo, int64_t ptr1Offset,
	const Value *V2, uint64_t V2Size, AAMDNodes V2AAInfo, int64_t ptr2Offset,
	Optional<int64_t> &LocDistance, const Value *O1, const Value *O2) { ... }

were ptr1Offset is "MMOa->getPointerInfo().Offset"

inside I will try to get to the GEP of the 2 memory operands this will tell me if its the same buffer (memory block)
I may pass throw PHI and SELECT nodes like in aliasCheck(),
after i will have 2 GEP I will calculate the distance using:

int64_t GEP1BaseOffset =
          DecompGEP1.StructOffset + DecompGEP1.OtherOffset + ptr1Offset;
      int64_t GEP2BaseOffset =
          DecompGEP2.StructOffset + DecompGEP2.OtherOffset + ptr2Offset;
      LocDistance = GEP2BaseOffset - GEP1BaseOffset;

and I will save it inside a cache like aliasCache...

I have implemented it and test it on my Core and it works for most cases...
it helps for detecting "Bank conflicts", when two memory instructions Mod/Ref from the same memory block, I can check if its also in the same bank if I have the distance between them and the size of each one of them...

the 2 functions I have added is generic and maybe other users will use it for something else...
If you also see how useful it is I will add a new patch with a first implementation (on BasicAliasAnalysis)

for being more clear, the call for the private function would be:

Optional<int64_t>
BasicAAResult::getAddressesDistance(const MemoryLocation &LocA,
	int64_t ptr1Offset, const MemoryLocation &LocB, int64_t ptr2Offset) {
  // LocA-LocB
  Optional<int64_t> LocDistance;
  BuffUseResult sameBuff =
      ModRefSameBufferCheck(LocA.Ptr, LocA.Size, LocA.AATags, ptr1Offset, 
		  LocB.Ptr, LocB.Size, LocB.AATags, ptr2Offset, LocDistance);

	return LocDistance;
}

Would be good if you can also add an implementation of this API (in a dependent patch).
I'm not entirely clear on the use yet, e.g. "BuffUseResult sameBuff" in your example is never used. An actual implementation would help with understanding and reviewing.

asbirlea resigned from this revision.Sep 15 2021, 12:28 PM

Considered obsolete. Readd if active.