Skip to content

Commit d9a0ec6

Browse files
committed
fix command line options
1 parent 8e95772 commit d9a0ec6

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

llvm/lib/Target/NVPTX/NVVMReflect.cpp

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ INITIALIZE_PASS(NVVMReflect, "nvvm-reflect",
8686
// are the last to be added to the VarMap, and therefore will take precedence over initial
8787
// values (i.e. __CUDA_FTZ from module medadata and __CUDA_ARCH from SmVersion).
8888
static cl::list<std::string>
89-
ReflectList("nvvm-reflect-add", cl::value_desc("name=<int>"), cl::Hidden,
89+
ReflectList("nvvm-reflect-list", cl::value_desc("name=<int>"), cl::Hidden,
90+
cl::CommaSeparated,
9091
cl::desc("list of comma-separated key=value pairs"),
9192
cl::ValueRequired);
9293

@@ -101,28 +102,17 @@ void NVVMReflect::setVarMap(Module &M) {
101102
M.getModuleFlag("nvvm-reflect-ftz")))
102103
VarMap["__CUDA_FTZ"] = Flag->getSExtValue();
103104

104-
/// The command line can look as follows :
105-
/// -nvvm-reflect-add a=1,b=2 -nvvm-reflect-add c=3,d=0 -nvvm-reflect-add e=2
106-
/// The strings "a=1,b=2", "c=3,d=0", "e=2" are available in the
107-
/// ReflectList vector. First, each of ReflectList[i] is 'split'
108-
/// using "," as the delimiter. Then each of this part is split
109-
/// using "=" as the delimiter.
110105
for (StringRef Option : ReflectList) {
111106
LLVM_DEBUG(dbgs() << "ReflectOption : " << Option << "\n");
112-
while (!Option.empty()) {
113-
auto Split = Option.split(',');
114-
StringRef NameVal = Split.first;
115-
Option = Split.second;
116-
117-
auto NameValPair = NameVal.split('=');
118-
assert(!NameValPair.first.empty() && !NameValPair.second.empty() &&
119-
"name=val expected");
120-
121-
int Val;
122-
if (!to_integer(NameValPair.second.trim(), Val, 10))
123-
report_fatal_error("integer value expected");
124-
VarMap[NameValPair.first] = Val;
125-
}
107+
auto [Name, Val] = Option.split('=');
108+
if (Name.empty())
109+
report_fatal_error("Empty name in nvvm-reflect-list option '" + Option + "'");
110+
if (Val.empty())
111+
report_fatal_error("Missing value in nvvm-reflect- option '" + Option + "'");
112+
int ValInt;
113+
if (!to_integer(Val.trim(), ValInt, 10))
114+
report_fatal_error("integer value expected in nvvm-reflect-list option '" + Option + "'");
115+
VarMap[Name] = ValInt;
126116
}
127117
}
128118

llvm/test/CodeGen/NVPTX/nvvm-reflect-options.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ declare i32 @__nvvm_reflect(ptr)
55
@ftz = private unnamed_addr addrspace(1) constant [11 x i8] c"__CUDA_FTZ\00"
66
@arch = private unnamed_addr addrspace(1) constant [12 x i8] c"__CUDA_ARCH\00"
77

8-
; RUN: opt -passes=nvvm-reflect -mtriple=nvptx-nvidia-cuda -nvvm-reflect-add=__CUDA_FTZ=1,__CUDA_ARCH=350 %s -S | FileCheck %s --check-prefix=CHECK-FTZ1-ARCH350
9-
; RUN: opt -passes=nvvm-reflect -mtriple=nvptx-nvidia-cuda -nvvm-reflect-add=__CUDA_FTZ=0 -nvvm-reflect-add=__CUDA_ARCH=520 %s -S | FileCheck %s --check-prefix=CHECK-FTZ0-ARCH520
8+
; RUN: opt -passes=nvvm-reflect -mtriple=nvptx-nvidia-cuda -nvvm-reflect-list=__CUDA_FTZ=1,__CUDA_ARCH=350 %s -S | FileCheck %s --check-prefix=CHECK-FTZ1-ARCH350
9+
; RUN: opt -passes=nvvm-reflect -mtriple=nvptx-nvidia-cuda -nvvm-reflect-list=__CUDA_FTZ=0 -nvvm-reflect-list=__CUDA_ARCH=520 %s -S | FileCheck %s --check-prefix=CHECK-FTZ0-ARCH520
1010

1111
; Verify that if we have module metadata that sets __CUDA_FTZ=1, that gets overridden by the command line arguments
1212

1313
; RUN: cat %s > %t.options
1414
; RUN: echo '!llvm.module.flags = !{!0}' >> %t.options
1515
; RUN: echo '!0 = !{i32 4, !"nvvm-reflect-ftz", i32 1}' >> %t.options
16-
; RUN: opt -passes=nvvm-reflect -mtriple=nvptx-nvidia-cuda -nvvm-reflect-add=__CUDA_FTZ=0,__CUDA_ARCH=520 %t.options -S | FileCheck %s --check-prefix=CHECK-FTZ0-ARCH520
16+
; RUN: opt -passes=nvvm-reflect -mtriple=nvptx-nvidia-cuda -nvvm-reflect-list=__CUDA_FTZ=0,__CUDA_ARCH=520 %t.options -S | FileCheck %s --check-prefix=CHECK-FTZ0-ARCH520
1717

1818
define i32 @options() {
1919
%1 = call i32 @__nvvm_reflect(ptr addrspacecast (ptr addrspace(1) @ftz to ptr))

0 commit comments

Comments
 (0)