[PATCH] LLVM CFL Alias Analysis -- Algorithm

Sanjoy Das sanjoy at playingwithpointers.com
Tue Jul 29 20:19:48 PDT 2014


Few comments inline.

================
Comment at: lib/Analysis/CFLAliasAnalysis.cpp:48
@@ +47,3 @@
+// Try to go from a Value* to a Function*. Never returns nullptr.
+static Optional<Function *> valueToFunction(Value *);
+
----------------
This might be better named as `parentFunctionOfValue`.  `valueToFunction` sounds a lot like it just does `dyn_cast<Function>(va)`.

================
Comment at: lib/Analysis/CFLAliasAnalysis.cpp:56
@@ +55,3 @@
+template <typename Inst>
+static bool getPossibleTargets(Inst *, SmallVectorImpl<Function *> *);
+
----------------
Can this use the `CallSite` class?

================
Comment at: lib/Analysis/CFLAliasAnalysis.cpp:303
@@ +302,3 @@
+  // TODO: Maybe just split the same code into two methods.
+  template <typename Inst> Optional<bool> visitCallLikeInst(Inst &inst) {
+    SmallVector<Function *, 4> targets;
----------------
It may be possible to use `CallSite` here too.

================
Comment at: lib/Analysis/CFLAliasAnalysis.cpp:339
@@ +338,3 @@
+  // and load from.
+  Optional<bool> visitExtractElementInst(ExtractElementInst &inst) {
+    auto *ptr = inst.getVectorOperand();
----------------
Are you sure this is correct?  In the comment on `enum class EdgeWeight` you have:

```
  // The edge used when our edge goes from a value to a handle that may have
  // contained it at some point. Examples:
  // %b = load %a              (%a Reference %b)
  // %b = extractelement %a, 0 (%a Reference %b)
  Reference
```

but here

```
Optional<bool> visitExtractElementInst(ExtractElementInst &inst) {
  // inst :: %b = extractelementinst %a, 0
  auto *ptr = inst.getVectorOperand();   // ptr = %a
  auto *val = &inst;   // val = %b
  // new edge = (val -> ptr, Reference) => (%b Reference %a)
  output->push_back({val, ptr, EdgeWeight::Reference, false});
  return true;
}
```

I may be totally missing something though, so please feel free to assert the correctness of this function without a specific reason -- I'll rebuild my understand then. :)

http://reviews.llvm.org/D4551






More information about the llvm-commits mailing list