[llvm] [Offload] Add framework for math conformance tests (PR #149242)

Joseph Huber via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 29 05:18:24 PDT 2025


================
@@ -0,0 +1,94 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains the definition of custom command-line argument parsers
+/// using llvm::cl.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef MATHTEST_COMMANDLINE_HPP
+#define MATHTEST_COMMANDLINE_HPP
+
+#include "mathtest/TestConfig.hpp"
+
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/CommandLine.h"
+
+#include <string>
+
+namespace llvm {
+namespace cl {
+
+struct TestConfigsArg {
+  enum class Mode { Default, All, Explicit } Mode = Mode::Default;
+  llvm::SmallVector<mathtest::TestConfig, 4> Explicit;
+};
+
+template <> class parser<TestConfigsArg> : public basic_parser<TestConfigsArg> {
+public:
+  parser(Option &O) : basic_parser<TestConfigsArg>(O) {}
+
+  static bool isAllowed(const mathtest::TestConfig &Config) {
+    static const llvm::SmallVector<mathtest::TestConfig, 4> &AllTestConfigs =
+        mathtest::getAllTestConfigs();
+
+    return llvm::is_contained(AllTestConfigs, Config);
+  }
+
+  bool parse(Option &O, StringRef ArgName, StringRef ArgValue,
+             TestConfigsArg &Val) {
+    ArgValue = ArgValue.trim();
+    if (ArgValue.empty())
+      return O.error(
+          "Expected '" + getValueName() +
+          "', but got an empty string. Omit the flag to use defaults");
+
+    if (ArgValue.equals_insensitive("all")) {
+      Val.Mode = TestConfigsArg::Mode::All;
+      return false;
+    }
+
+    llvm::SmallVector<StringRef, 8> Pairs;
+    ArgValue.split(Pairs, ',', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
+
+    Val.Mode = TestConfigsArg::Mode::Explicit;
+    Val.Explicit.clear();
+
+    for (StringRef Pair : Pairs) {
+      size_t Pos = Pair.find(':');
+      if (Pos == StringRef::npos)
+        return O.error("Expected '<provider>:<platform>', got '" + Pair + "'");
+
+      StringRef Provider = Pair.take_front(Pos);
+      StringRef Platform = Pair.drop_front(Pos + 1);
----------------
jhuber6 wrote:

You can just do Pair.split(':').first.

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


More information about the llvm-commits mailing list