Alex
Alex

Reputation: 360

llvm dependencies alloca-load

I have some problems of finding dependencies. I want to get the corresponding Alloca from every Load (corresponding from the point of view of the variable used, meaning that the Load is using a variable based/dependent on the Alloca or Allocas).

Hence, I have a chain like : Alloca -> Load(1) -> ... -> Computation where the variable might be changed -> Store(new_var) -> ... -> Load(n)

"Computation where the variable is changed" means that : I might have Alloca(a), c=a+7000*b[32], Load(c).

First, I tried to use methods from AliasAnalysis class. The plan was the following: after I get all the must-aliases, I categorize them into 2 :

  1. category A : aliases with allocas
  2. category B: aliases without allocas

For category A, is straight ahead for what I need. For category B, I check if there is an instruction where the variable is used also from an instruction from the aliases of category A. If it is, it is ok.

For some methods I cannot use Alloca, so I try to find dependencies among Loads (I have all the Load instructions in an array loadInstrArray) and then check if some Load use the same variable as an Alloca.

But the following gave me no result at all (and they should, I have dependencies in my target test code - meaning that Load j is used multiple times in my code, so the pointers should be must-alias) :

  1. if( AA.isMustAlias(Loci,Locj) ) - no results
  2. if( AA.alias(Loci,Locj) ) - wrong results, like "LOAD %2 = load i32* %j, align 4 IS DEPENDENT ON %3 = load i32* %c, align 4"

where j is totally independent from c

3". if( AA.getModRefInfo(allocaInstrArray[j],Loci) ) - no results

where Loci is AliasAnalysis::Location from a Load, allocaInstrArray is an array with all allocas

Second, I tried to use methods from DependencyAnalysis class.

  1. if (DA.depends(loadInstrArray[i],loadInstrArray[j],false)) - no results

Third, I tried methods from MemoryDependenceAnalysis class - the existing pass http://llvm.org/docs/doxygen/html/MemDepPrinter_8cpp_source.html .

  1. I have wrong results, like : %1 = load i32* %j, align 4 IS Clobber FROM: store i32 0, i32* %c, align 4
  2. then I tried to get only DEF (not clobber), since I only need to see the correspondent Alloca for every Load. I don't have any results for Loads. I also checked with getDef() method, Loads being dependent on themselves.
  3. I have to mention that I commented line 00131, since I had an unsolved segfault and not the parameters are the problem.

What do you think I should focus on, what approach is better to take into account and what to eliminate?

Thank you a lot for your time !

Upvotes: 1

Views: 510

Answers (2)

user2022455
user2022455

Reputation:

In addition, you should check if all the time the ICMP operands are referring to a Load instruction. If not, seek recursive for Load instructions from both ICMP operands (0 and 1). There might be other intermediate operations between Loads and ICMP.

Upvotes: 1

Alex
Alex

Reputation: 360

Use getOperand(0)/getOperand(1) of the ICMP instructions. If there is isa<LoadInst> valid, then cast them to LoadInst. getPointerOperand() will get the Value* that is the actual variable which is searched. Do the same procedure between Load instructions and Alloca instructions. getOperand(0) applied on Load gives the corresponding Alloca instruction. Link the two results together, by checking the dependencies. The result of doing it manually passes the tests.

Upvotes: 0

Related Questions