Adarsh Konchady
Adarsh Konchady

Reputation: 2737

Find array accesses in a basic block

How can I check whether there are array accesses in a basic block?

For example, I want to find a[i] in the following example.

Eg:

           for(i=0;i<n;i++)
                  a[i]=a[i+1]+i;

Upvotes: 1

Views: 316

Answers (1)

joey
joey

Reputation: 578

Array accesses are modeled by getelementptr instructions. So you could iterate over the Basic Block with something like:

for (BasicBlock::iterator i = blk->begin(), e = blk->end(); i != e; ++i) {
  if(isa<GetElementPtrInst>(i)) {
    // process it here
  }
}

Upvotes: 1

Related Questions