Index: lib/Target/NVPTX/NVPTXTargetMachine.cpp =================================================================== --- lib/Target/NVPTX/NVPTXTargetMachine.cpp +++ lib/Target/NVPTX/NVPTXTargetMachine.cpp @@ -76,6 +76,11 @@ initializeNVPTXLowerAggrCopiesPass(PR); } +static cl::opt NVPTXEnableReflect( + "nvptx-enable-reflect", cl::init(false), cl::Hidden, + cl::desc("Run NVVM reflection pass before other standard passes, " + "disabled by default")); + static std::string computeDataLayout(bool is64Bit) { std::string Ret = "e"; @@ -176,6 +181,8 @@ disablePass(&MachineCopyPropagationID); disablePass(&TailDuplicateID); + if (NVPTXEnableReflect) + addPass(createNVVMReflectPass()); addPass(createNVPTXImageOptimizerPass()); addPass(createNVPTXAssignValidGlobalNamesPass()); addPass(createGenericToNVVMPass()); Index: test/CodeGen/NVPTX/nvptx-enable-reflect.ll =================================================================== --- /dev/null +++ test/CodeGen/NVPTX/nvptx-enable-reflect.ll @@ -0,0 +1,10 @@ +; RUN: llc < %s -march=nvptx -debug-pass=Structure -o /dev/null 2>&1 \ +; RUN: | FileCheck %s --check-prefix=ALL --check-prefix=NOREFLECT +; RUN: llc < %s -march=nvptx -debug-pass=Structure -o /dev/null -nvptx-enable-reflect 2>&1 \ +; RUN: | FileCheck %s --check-prefix=ALL --check-prefix=REFLECT + +; ALL: Pass Arguments +; ALL: ModulePass Manager +; REFLECT-NEXT: Replace occurrences of __nvvm_reflect +; NOREFLECT-NOT: Replace occurrences of __nvvm_reflect +; ALL-NEXT: FunctionPass Manager