首页 > 其他 > 详细

LLVM程序分析日记之MemorySSA

时间:2021-02-21 23:34:41      阅读:82      评论:0      收藏:0      [点我收藏+]

Introduction

LLVM MemorySSA使我们能够便捷地推断各种内存操作之间的交互。它旨在替代 MemoryDependenceAnalysis大多数(即使不是全部)用例。在较高的层次上,MemorySSA是提供一种基于SSA的内存表单,并带有def-use和use-def链,这使用户能够快速找到内存操作的may-def和may-use。注意,LLVM的MemorySSA是intra-procedure的。

关于MemorySSA的详细介绍可以在[1][2]中找到。

Code

llvm::MemorySSA *MSSA = &getAnalysis<MemorySSAWrapperPass>(F).getMSSA();
llvm::StoreInst *SI = ...;
MemoryAccess *storeMA = MSSA->getMemoryAccess(SI);
const llvm::Instruction *immediate_access_inst = nullptr;
for (const llvm::Insturction *I = getNextNonDebugInstruction(SI); I; I = getNextNonDebugInstruction(I)) {
  MemoryAccess *ma = MSSA->getMemoryAccess(I);
  if (ma) {
    MemoryUseOrDef *ud = dyn_cast<MemoryUseOrDef>(ma);
    if (ud && ud->getDefiningAccess() == storeMA) {
      immediate_access_inst = ud->getMemoryInst();
      break;
    }
  }
}

上述代码对于给定的一个llvm::StoreInst, 找到其后续指令中最近的,操作(读/写)与StoreInst同一块内存的指令。

Reference

[1] Novillo D , Canada R H . Memory SSA- A Unified Approach for Sparsely Representing Memory Operations[J]. Proc of the Gcc Developers Summit, 2006.
[2] https://www.llvm.org/docs/MemorySSA.html

LLVM程序分析日记之MemorySSA

原文:https://www.cnblogs.com/bjchan9an/p/14427567.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!