[llvm] [CGData] Declare command line options in TableGen, one struct per library (PR #226087)

Alexis Engelke via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 24 02:37:31 PDT 2026


================
@@ -0,0 +1,16 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+include "llvm/Option/OptParser.td"
+
+def TestLibraryOptions : OptionsStruct;
+
+defm Enable : BoolField<"lib-enable", "false", "A bool">;
+defm Count : ValueField<"lib-count", "unsigned", "3", "An unsigned">;
+defm Ratio : ValueField<"lib-ratio", "double", "0.5", "A double">;
+defm Path : ValueField<"lib-path", "std::string", "\"p\"", "A string">;
----------------
aengelke wrote:

I dislike using data types that require ctors/dtors in option structs and I'd prefer the possibility of using StringRef/ArrayRef instead of std::string/std::vector. This will allow constexpr initialization of default values (they will require relocations, but at least no ctor/dtor and no malloc for non-empty default values) and reduce the size of the option structs. C++20 makes string/vector constexpr, but only for empty values, so that doesn't help.

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


More information about the llvm-commits mailing list