[llvm] [llvm-mca] Add optional identifier field to mca::Instruction (PR #97867)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 5 16:16:27 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-tools-llvm-mca

Author: Chinmay Deshpande (chinmaydd)

<details>
<summary>Changes</summary>

While using llvm-mca as a library (in MCA Daemon), we've been having trouble uniquely identifying instructions that go through the pipeline. Inspired by the discussion [here](https://github.com/llvm/llvm-project/pull/92849#discussion_r1621376233), I believe it may make sense to add an optional identifier to each `mca::Instruction`. 

A possible instance of use could be the `InstrBuilder` incrementing the `Identifier` by 1 after each instruction is created. I'm happy to add that too.

---
Full diff: https://github.com/llvm/llvm-project/pull/97867.diff


1 Files Affected:

- (modified) llvm/include/llvm/MCA/Instruction.h (+5) 


``````````diff
diff --git a/llvm/include/llvm/MCA/Instruction.h b/llvm/include/llvm/MCA/Instruction.h
index e48a70164bec6..09822e43a827d 100644
--- a/llvm/include/llvm/MCA/Instruction.h
+++ b/llvm/include/llvm/MCA/Instruction.h
@@ -643,6 +643,8 @@ class Instruction : public InstructionBase {
   // True if this instruction has been optimized at register renaming stage.
   bool IsEliminated;
 
+  std::optional<uint64_t> Identifier;
+
 public:
   Instruction(const InstrDesc &D, const unsigned Opcode)
       : InstructionBase(D, Opcode), Stage(IS_INVALID),
@@ -690,6 +692,9 @@ class Instruction : public InstructionBase {
   bool isRetired() const { return Stage == IS_RETIRED; }
   bool isEliminated() const { return IsEliminated; }
 
+  std::optional<uint64_t> getIdentifier() const { return Identifier; }
+  void setIdentifier(uint64_t Id) { Identifier = Id; }
+
   // Forces a transition from state IS_DISPATCHED to state IS_EXECUTED.
   void forceExecuted();
   void setEliminated() { IsEliminated = true; }

``````````

</details>


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


More information about the llvm-commits mailing list