Skip to content

[llvm-exegesis] Remove implicit conversions of MCRegister to unsigned. NFC #123223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 16, 2025

Conversation

topperc
Copy link
Collaborator

@topperc topperc commented Jan 16, 2025

-Use MCRegister::id() for BitVector index.
-Replace std::unordered_set with std::set<MCRegister.
There are other std::sets for Register. None for MCRegister before this.
I'm assuming we can have operator<(MCRegister, MCRegister). This avoids
needing to add std::hash.
-Use MCRegister::isValid() to avoid comparing to 0.

…. NFC

-Use MCRegister::id() for BitVector index.
-Replace std::unordered_set<unsigned> with std::set<MCRegister.
 There are other std::sets for Register. None for MCRegister before this.
 I'm assuming we can have operator<(MCRegister, MCRegister). This avoids
 needing to add std::hash<MCRegister>.
-Use MCRegister::isValid() to avoid comparing to 0.
@llvmbot
Copy link
Member

llvmbot commented Jan 16, 2025

@llvm/pr-subscribers-tools-llvm-exegesis

Author: Craig Topper (topperc)

Changes

-Use MCRegister::id() for BitVector index.
-Replace std::unordered_set<unsigned> with std::set<MCRegister.
There are other std::sets for Register. None for MCRegister before this.
I'm assuming we can have operator<(MCRegister, MCRegister). This avoids
needing to add std::hash<MCRegister>.
-Use MCRegister::isValid() to avoid comparing to 0.


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

1 Files Affected:

  • (modified) llvm/unittests/tools/llvm-exegesis/X86/SnippetGeneratorTest.cpp (+7-7)
diff --git a/llvm/unittests/tools/llvm-exegesis/X86/SnippetGeneratorTest.cpp b/llvm/unittests/tools/llvm-exegesis/X86/SnippetGeneratorTest.cpp
index bf110c8ad76bb8..60c726212062dd 100644
--- a/llvm/unittests/tools/llvm-exegesis/X86/SnippetGeneratorTest.cpp
+++ b/llvm/unittests/tools/llvm-exegesis/X86/SnippetGeneratorTest.cpp
@@ -183,7 +183,7 @@ TEST_F(X86SerialSnippetGeneratorTest,
     ASSERT_THAT(IT.getVariableValues(), SizeIs(3));
     for (const auto &Var : IT.getVariableValues()) {
       if (Var.isReg()) {
-        EXPECT_FALSE(ForbiddenRegisters[Var.getReg()]);
+        EXPECT_FALSE(ForbiddenRegisters[Var.getReg().id()]);
       }
     }
   }
@@ -288,8 +288,8 @@ TEST_F(X86ParallelSnippetGeneratorTest, ReadAfterWrite_CMOV32rr) {
     EXPECT_THAT(CT.Info, HasSubstr("avoiding Read-After-Write issue"));
     EXPECT_THAT(CT.Execution, ExecutionMode::UNKNOWN);
     ASSERT_GT(CT.Instructions.size(), 1U);
-    std::unordered_set<unsigned> AllDefRegisters;
-    std::unordered_set<unsigned> AllUseRegisters;
+    std::set<MCRegister> AllDefRegisters;
+    std::set<MCRegister> AllUseRegisters;
     for (const auto &IT : CT.Instructions) {
       ASSERT_THAT(IT.getVariableValues(), SizeIs(3));
       AllDefRegisters.insert(IT.getVariableValues()[0].getReg());
@@ -328,8 +328,8 @@ TEST_F(X86ParallelSnippetGeneratorTest, ReadAfterWrite_VFMADD132PDr) {
     EXPECT_THAT(CT.Info, HasSubstr("avoiding Read-After-Write issue"));
     EXPECT_THAT(CT.Execution, ExecutionMode::UNKNOWN);
     ASSERT_GT(CT.Instructions.size(), 1U);
-    std::unordered_set<unsigned> AllDefRegisters;
-    std::unordered_set<unsigned> AllUseRegisters;
+    std::set<MCRegister> AllDefRegisters;
+    std::set<MCRegister> AllUseRegisters;
     for (const auto &IT : CT.Instructions) {
       ASSERT_THAT(IT.getVariableValues(), SizeIs(3));
       AllDefRegisters.insert(IT.getVariableValues()[0].getReg());
@@ -412,9 +412,9 @@ TEST_F(X86ParallelSnippetGeneratorTest, MemoryUse) {
     EXPECT_THAT(IT.getOpcode(), Opcode);
     ASSERT_THAT(IT.getVariableValues(), SizeIs(6));
     EXPECT_EQ(IT.getVariableValues()[2].getImm(), 1);
-    EXPECT_EQ(IT.getVariableValues()[3].getReg(), 0u);
+    EXPECT_FALSE(IT.getVariableValues()[3].getReg().isValid());
     EXPECT_EQ(IT.getVariableValues()[4].getImm(), 0);
-    EXPECT_EQ(IT.getVariableValues()[5].getReg(), 0u);
+    EXPECT_FALSE(IT.getVariableValues()[5].getReg().isValid());
   }
 }
 

@topperc topperc merged commit 3173a4f into llvm:main Jan 16, 2025
8 of 9 checks passed
@topperc topperc deleted the pr/exegesis-unit branch January 16, 2025 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants