[llvm] Refactored verbosity flag in mlgo-utils to common location #107898 (PR #128541)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 24 09:47:53 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlgo
Author: Ali Raeisdanaei (aliraeisdanaei)
<details>
<summary>Changes</summary>
add common lib file to setup arguments for parser #<!-- -->107898
This is my first pull request to LLVM, so I would appreciate your feedback :)
---
Full diff: https://github.com/llvm/llvm-project/pull/128541.diff
3 Files Affected:
- (modified) llvm/utils/mlgo-utils/mlgo/corpus/combine_training_corpus.py (+2-9)
- (modified) llvm/utils/mlgo-utils/mlgo/corpus/extract_ir.py (+2-10)
- (added) llvm/utils/mlgo-utils/mlgo/corpus/parser_setup_lib.py (+21)
``````````diff
diff --git a/llvm/utils/mlgo-utils/mlgo/corpus/combine_training_corpus.py b/llvm/utils/mlgo-utils/mlgo/corpus/combine_training_corpus.py
index 90cf51cad75ed..5b56e49e5abee 100644
--- a/llvm/utils/mlgo-utils/mlgo/corpus/combine_training_corpus.py
+++ b/llvm/utils/mlgo-utils/mlgo/corpus/combine_training_corpus.py
@@ -27,6 +27,7 @@
import logging
from mlgo.corpus import combine_training_corpus_lib
+from mlgo.corpus import parser_setup_lib
def parse_args_and_run():
@@ -36,15 +37,7 @@ def parse_args_and_run():
parser.add_argument(
"--root_dir", type=str, help="The root dir of module paths to combine."
)
- # TODO(#107898): Refactor this into a common location.
- parser.add_argument(
- "--verbosity",
- type=str,
- help="The verbosity level to use for logging",
- default="INFO",
- nargs="?",
- choices=["DEBUG", "INFO", "WARNING", "ERROR"],
- )
+ parser_setup_lib.add_verbosity_arguments(parser)
args = parser.parse_args()
main(args)
diff --git a/llvm/utils/mlgo-utils/mlgo/corpus/extract_ir.py b/llvm/utils/mlgo-utils/mlgo/corpus/extract_ir.py
index 5edb429241d0c..2b54d47b03d5d 100644
--- a/llvm/utils/mlgo-utils/mlgo/corpus/extract_ir.py
+++ b/llvm/utils/mlgo-utils/mlgo/corpus/extract_ir.py
@@ -28,7 +28,7 @@
import logging
from mlgo.corpus import extract_ir_lib
-
+from mlgo.corpus import parser_setup_lib
def parse_args_and_run():
parser = argparse.ArgumentParser(
@@ -111,15 +111,7 @@ def parse_args_and_run():
default=".llvmbc",
nargs="?",
)
- # TODO(#107898): Refactor this into a common location.
- parser.add_argument(
- "--verbosity",
- type=str,
- help="The verbosity level to use for logging",
- default="INFO",
- nargs="?",
- choices=["DEBUG", "INFO", "WARNING", "ERROR"],
- )
+ parser_setup_lib.add_verbosity_arguments(parser)
args = parser.parse_args()
main(args)
diff --git a/llvm/utils/mlgo-utils/mlgo/corpus/parser_setup_lib.py b/llvm/utils/mlgo-utils/mlgo/corpus/parser_setup_lib.py
new file mode 100644
index 0000000000000..238bae3cd1e46
--- /dev/null
+++ b/llvm/utils/mlgo-utils/mlgo/corpus/parser_setup_lib.py
@@ -0,0 +1,21 @@
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+"""Library functions for setting up common parser arguments"""
+
+from argparse import ArgumentParser
+
+def add_verbosity_arguments(parser: ArgumentParser) -> None:
+ """Adds the arguments for verbosity to the ArgumentParser
+
+ Arguments:
+ parser -- the argument parser being modified with verbosity arguments
+ """
+ parser.add_argument(
+ "--verbosity",
+ type=str,
+ help="The verbosity level to use for logging",
+ default="INFO",
+ nargs="?",
+ choices=["DEBUG", "INFO", "WARNING", "ERROR"],
+ )
\ No newline at end of file
``````````
</details>
https://github.com/llvm/llvm-project/pull/128541
More information about the llvm-commits
mailing list