Skip to content

[MLIR][Presburger] Fix style violations in ff80414 (NFC) #76720

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 12, 2024

Conversation

iambrj
Copy link
Member

@iambrj iambrj commented Jan 2, 2024

Use preincrement not postincrement; use Identifier::getIds not getVarKindOffset

@llvmbot
Copy link
Member

llvmbot commented Jan 2, 2024

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-presburger

Author: Bharathi Ramana Joshi (iambrj)

Changes

Use preincrement not postincrement; use Identifier::getIds not getVarKindOffset


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

1 Files Affected:

  • (modified) mlir/lib/Analysis/Presburger/PresburgerSpace.cpp (+8-13)
diff --git a/mlir/lib/Analysis/Presburger/PresburgerSpace.cpp b/mlir/lib/Analysis/Presburger/PresburgerSpace.cpp
index a6f9af83b97738..f80df52fb82908 100644
--- a/mlir/lib/Analysis/Presburger/PresburgerSpace.cpp
+++ b/mlir/lib/Analysis/Presburger/PresburgerSpace.cpp
@@ -299,30 +299,25 @@ void PresburgerSpace::mergeAndAlignSymbols(PresburgerSpace &other) {
          "Both spaces need to have identifers to merge & align");
 
   // First merge & align identifiers into `other` from `this`.
-  unsigned kindBeginOffset = other.getVarKindOffset(VarKind::Symbol);
   unsigned i = 0;
-  for (const Identifier *identifier =
-           identifiers.begin() + getVarKindOffset(VarKind::Symbol);
-       identifier != identifiers.begin() + getVarKindEnd(VarKind::Symbol);
-       identifier++) {
+  for (const Identifier identifier : getIds(VarKind::Symbol)) {
     // If the identifier exists in `other`, then align it; otherwise insert it
     // assuming it is a new identifier. Search in `other` starting at position
     // `i` since the left of `i` is aligned.
-    auto *findEnd =
-        other.identifiers.begin() + other.getVarKindEnd(VarKind::Symbol);
-    auto *itr = std::find(other.identifiers.begin() + kindBeginOffset + i,
-                          findEnd, *identifier);
+    auto *findBegin = other.getIds(VarKind::Symbol).begin() + i;
+    auto *findEnd = other.getIds(VarKind::Symbol).end();
+    auto *itr = std::find(findBegin, findEnd, identifier);
     if (itr != findEnd) {
-      std::iter_swap(other.identifiers.begin() + kindBeginOffset + i, itr);
+      std::swap(findBegin, itr);
     } else {
       other.insertVar(VarKind::Symbol, i);
-      other.getId(VarKind::Symbol, i) = *identifier;
+      other.getId(VarKind::Symbol, i) = identifier;
     }
-    i++;
+    ++i;
   }
 
   // Finally add identifiers that are in `other`, but not in `this` to `this`.
-  for (unsigned e = other.getNumVarKind(VarKind::Symbol); i < e; i++) {
+  for (unsigned e = other.getNumVarKind(VarKind::Symbol); i < e; ++i) {
     insertVar(VarKind::Symbol, i);
     getId(VarKind::Symbol, i) = other.getId(VarKind::Symbol, i);
   }

Copy link
Contributor

@tobiasgrosser tobiasgrosser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This certainly looks a lot better. Lets see what @Groverkss and @Superty have to add.

Copy link
Member

@Groverkss Groverkss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Groverkss Groverkss merged commit c39926e into llvm:main Jan 12, 2024
justinfargnoli pushed a commit to justinfargnoli/llvm-project that referenced this pull request Jan 28, 2024
Use preincrement not postincrement; use `Identifier::getIds` not
`getVarKindOffset`
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.

4 participants