[Mlir-commits] [mlir] [MLIR][NVVM] Add `cmd-options` to pass flags to the downstream compiler (PR #127457)

Durgadoss R llvmlistbot at llvm.org
Mon Feb 17 01:58:37 PST 2025


================
@@ -321,6 +321,25 @@ std::optional<std::string> NVPTXSerializer::findTool(StringRef tool) {
   return std::nullopt;
 }
 
+/// Adds optional command-line arguments to existing arguments.
+template <typename T>
+static void setOptionalCommandlineArguments(NVVMTargetAttr target,
+                                            SmallVectorImpl<T> &ptxasArgs) {
+  if (!target.hasCmdOptions())
+    return;
+
+  std::optional<mlir::NamedAttribute> cmdOptions = target.getCmdOptions();
+  for (Attribute attr : cast<ArrayAttr>(cmdOptions->getValue())) {
+    if (auto strAttr = dyn_cast<StringAttr>(attr)) {
+      if constexpr (std::is_same_v<T, StringRef>) {
+        ptxasArgs.push_back(strAttr.getValue());
+      } else if constexpr (std::is_same_v<T, const char *>) {
+        ptxasArgs.push_back(strAttr.getValue().data());
+      }
----------------
durga4github wrote:

For my understanding:
Why do we handle it as both StringRef and a const char * ?

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


More information about the Mlir-commits mailing list