[Mlir-commits] [mlir] [mlir] Add support for parsing nested PassPipelineOptions (PR #101118)

River Riddle llvmlistbot at llvm.org
Tue Jul 30 09:22:45 PDT 2024


================
@@ -159,13 +160,36 @@ const PassPipelineInfo *mlir::PassPipelineInfo::lookup(StringRef pipelineArg) {
 // PassOptions
 //===----------------------------------------------------------------------===//
 
+/// Extract an argument from 'options' and update it to point after the arg.
+/// Returns the cleaned argument string.
+static StringRef extractArgAndUpdateOptions(StringRef &options,
+                                            size_t argSize) {
+  StringRef str = options.take_front(argSize).trim();
+  options = options.drop_front(argSize).ltrim();
+  // Handle escape sequences
+  if (str.size() > 2) {
+    const auto escapePairs = {std::make_pair('\'', '\''),
+                              std::make_pair('"', '"'),
+                              std::make_pair('{', '}')};
+    for (const auto &escape : escapePairs) {
+      if (str.front() == escape.first && str.back() == escape.second) {
+        // Drop the escape characters and trim.
+        str = str.drop_front().drop_back().trim();
+        // Don't process additional escape sequences.
+        break;
+      }
+    }
+  }
+  return str;
----------------
River707 wrote:

```suggestion
  if (str.size() <= 2)
    return str;
    
  // Handle escape sequences
  const auto escapePairs = {std::make_pair('\'', '\''),
                            std::make_pair('"', '"'),
                            std::make_pair('{', '}')};
  for (const auto &escape : escapePairs) {
    if (str.front() == escape.first && str.back() == escape.second) {
      // Drop the escape characters and trim.
      str = str.drop_front().drop_back().trim();
      // Don't process additional escape sequences.
      break;
    }
  }
  return str;
```

I know this is the same as before, but can you flip to early exit?

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


More information about the Mlir-commits mailing list