[llvm] [SandboxVec][DAG] Build actual dependencies (PR #111094)

Sriraman Tallam via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 7 23:17:03 PDT 2024


================
@@ -50,29 +51,137 @@ MemDGNodeIntervalBuilder::make(const Interval<Instruction> &Instrs,
                              cast<MemDGNode>(DAG.getNode(MemBotI)));
 }
 
+DependencyGraph::DependencyType
+DependencyGraph::getRoughDepType(Instruction *FromI, Instruction *ToI) {
+  if (FromI->mayWriteToMemory()) {
+    if (ToI->mayReadFromMemory())
+      return DependencyType::RAW;
+    if (ToI->mayWriteToMemory())
+      return DependencyType::WAW;
+  }
+  if (FromI->mayReadFromMemory()) {
+    if (ToI->mayWriteToMemory())
+      return DependencyType::WAR;
+    if (ToI->mayReadFromMemory())
+      return DependencyType::RAR;
+  }
----------------
tmsri wrote:

Why not else-if in the second outer if for FromI?

Why is ToI checked first for Read in the first-if and for write in the second, any implicit ordering?  If ToI is not mem read/write this code will still go through all the checks?  Can it both read and write memory, if so can we make it simpler, something along these lines where write takes precedence?

```
enum  AccessType {
   NONE,
   READ,
   WRITE,
}  FromMemType = NONE;

// If it could both read and write, write takes precedence
if (FromI->mayWriteToMemory()) 
  FromMemType = AccessType::WRITE;
else if  (FromI->mayReadFromMemory())
  FromMemType = AccessType::READ;

if (FromMemType  != NONE) {
   // Check Write First
    if (ToI->mayWriteToMemory())
       return FromMemType == AccessType::READ ? WAR : WAW;
    if (ToI->mayReadFromMemory())
       return FromMemType == AccessType::READ ? RAR : RAW;  
}



https://github.com/llvm/llvm-project/pull/111094


More information about the llvm-commits mailing list