//===-- NVPTXAssignValidGlobalNames.cpp - Assign valid names to globals ---===// // // 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 // //===----------------------------------------------------------------------===// // // Clean up the names of global variables in the module to not contain symbols // that are invalid in PTX. // // Currently NVPTX, like other backends, relies on generic symbol name // sanitizing done by MC. However, the ptxas assembler is more stringent and // disallows some additional characters in symbol names. This pass makes sure // such names do not reach MC at all. // //===----------------------------------------------------------------------===// #include "NVPTX.h" #include "llvm/ADT/StringExtras.h" #include "llvm/IR/Function.h" #include "llvm/IR/GlobalVariable.h" #include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/Module.h" #include "llvm/Support/raw_ostream.h" #include <string> usingnamespacellvm; namespace { /// NVPTXAssignValidGlobalNames class NVPTXAssignValidGlobalNames : public ModulePass { … }; } char NVPTXAssignValidGlobalNames::ID = …; namespace llvm { void initializeNVPTXAssignValidGlobalNamesPass(PassRegistry &); } INITIALIZE_PASS(…) bool NVPTXAssignValidGlobalNames::runOnModule(Module &M) { … } std::string NVPTXAssignValidGlobalNames::cleanUpName(StringRef Name) { … } ModulePass *llvm::createNVPTXAssignValidGlobalNamesPass() { … }