2012-03-12 60 views
1

如何檢查基本塊中是否有數組訪問?在基本塊中查找數組訪問

例如,我想在以下示例中找到[i]。

例如:

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

你確定你需要這個在LLVM的水平,而不是鏘水平?即如果你正在分析C代碼,你最好看看AST Clang生成 – 2012-03-12 18:01:48

回答

1

陣列的訪問通過getelementptr指令建模。 所以,你可以用類似遍歷基本塊:

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

雖然數組訪問並不是GEP建模的唯一事物。指針解除也是。所以是結構成員訪問。所以你在這裏需要小心 – 2012-03-12 14:04:03

+0

沒問題,但問題很模糊,所以這至少是一個好的開始! – joey 2012-03-12 15:10:59

+0

另請參閱:http://stackoverflow.com/questions/9682705/identify-array-type-in​​-ir – 2012-03-13 13:35:06