diff --git a/mlir/lib/Pass/PassRegistry.cpp b/mlir/lib/Pass/PassRegistry.cpp --- a/mlir/lib/Pass/PassRegistry.cpp +++ b/mlir/lib/Pass/PassRegistry.cpp @@ -588,6 +588,9 @@ pipeline.back().options = text.substr(0, close); text = text.substr(close + 1); + // Consume space characters that an user might add for readeability. + text = text.ltrim(); + // Skip checking for '(' because nested pipelines cannot have options. } else if (sep == '(') { text = text.substr(1); @@ -607,6 +610,8 @@ "parentheses while parsing pipeline"); pipelineStack.pop_back(); + // Consume space characters that an user might add for readeability. + text = text.ltrim(); } // Check if we've finished parsing. diff --git a/mlir/test/python/pass_manager.py b/mlir/test/python/pass_manager.py --- a/mlir/test/python/pass_manager.py +++ b/mlir/test/python/pass_manager.py @@ -59,6 +59,18 @@ log("Roundtrip: ", pm) run(testParseSuccess) +# Verify successful round-trip. +# CHECK-LABEL: TEST: testParseSpacedPipeline +def testParseSpacedPipeline(): + with Context(): + # A registered pass should parse successfully even if has extras spaces for readability + pm = PassManager.parse("""builtin.module( + func.func( print-op-stats{ json=false } ) + )""") + # CHECK: Roundtrip: builtin.module(func.func(print-op-stats{json=false})) + log("Roundtrip: ", pm) +run(testParseSpacedPipeline) + # Verify failure on unregistered pass. # CHECK-LABEL: TEST: testParseFail def testParseFail():