[llvm] [llvm-mca] Account for AcquireAtCycles in llvm-mca (PR #80742)

Michael Maitland via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 27 08:54:22 PST 2024


================
@@ -89,11 +89,11 @@ static void initializeUsedResources(InstrDesc &ID,
       AllInOrderResources &= (PR.BufferSize <= 1);
     }
 
-    CycleSegment RCy(0, PRE->ReleaseAtCycle, false);
+    CycleSegment RCy(PRE->AcquireAtCycle, PRE->ReleaseAtCycle, false);
----------------
michaelmaitland wrote:

This code here made me wonder if we are accounting for AcquireAtCycle correctly. 

The `NumCyclesUsed` class may only represent the total number of cycles used, without saying anything about when the resource is acquired or released. `CycleSegment` class looks like it is the one who is responsible for taking this information into account. After looking into it, I found that although this information is being tracked, it is not being used as needed:

In `ResourceManager::issueInstruction`, we say `BusyResources[Pipe] += CS.size()`, which is a map from pipe to how many cycles are left before the pipe is usable again. The problem is that the this map data structure does not model the fact that a resource can be free from issue cycle until acquire at cycle. My thought is to add another map that tracks this data, and in conjunction with `BusyResources` we can tell the full story.

The other part that needs some fixing is that `reserveResource` is called in `issueInstruction`. We need to model that a resource may not need to be reserved on instruction issue, but on acquire at cycles after instruction issue. It may be a good idea to move the call to `reserveResource` from `ResourceManager::issueInstruction` to `ResourceManager::cycleEvent`.

I will take a look into this once I get some bandwidth. I am leaving this comment here and marking this PR as needs changes in the meantime.

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


More information about the llvm-commits mailing list