| Justin Holewinski | 30d56a7 | 2014-04-09 15:39:15 +0000 | [diff] [blame] | 1 | //===-- NVPTXMachineFunctionInfo.h - NVPTX-specific Function Info --------===// |
| 2 | // |
| Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| Justin Holewinski | 30d56a7 | 2014-04-09 15:39:15 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This class is attached to a MachineFunction instance and tracks target- |
| 10 | // dependent information |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 14 | #ifndef LLVM_LIB_TARGET_NVPTX_NVPTXMACHINEFUNCTIONINFO_H |
| 15 | #define LLVM_LIB_TARGET_NVPTX_NVPTXMACHINEFUNCTIONINFO_H |
| 16 | |
| Justin Holewinski | 30d56a7 | 2014-04-09 15:39:15 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/MachineFunction.h" |
| 18 | |
| 19 | namespace llvm { |
| 20 | class NVPTXMachineFunctionInfo : public MachineFunctionInfo { |
| 21 | private: |
| 22 | /// Stores a mapping from index to symbol name for removing image handles |
| 23 | /// on Fermi. |
| 24 | SmallVector<std::string, 8> ImageHandleList; |
| 25 | |
| 26 | public: |
| 27 | NVPTXMachineFunctionInfo(MachineFunction &MF) {} |
| 28 | |
| 29 | /// Returns the index for the symbol \p Symbol. If the symbol was previously, |
| 30 | /// added, the same index is returned. Otherwise, the symbol is added and the |
| 31 | /// new index is returned. |
| 32 | unsigned getImageHandleSymbolIndex(const char *Symbol) { |
| 33 | // Is the symbol already present? |
| 34 | for (unsigned i = 0, e = ImageHandleList.size(); i != e; ++i) |
| 35 | if (ImageHandleList[i] == std::string(Symbol)) |
| 36 | return i; |
| 37 | // Nope, insert it |
| 38 | ImageHandleList.push_back(Symbol); |
| 39 | return ImageHandleList.size()-1; |
| 40 | } |
| 41 | |
| 42 | /// Returns the symbol name at the given index. |
| 43 | const char *getImageHandleSymbol(unsigned Idx) const { |
| 44 | assert(ImageHandleList.size() > Idx && "Bad index"); |
| 45 | return ImageHandleList[Idx].c_str(); |
| 46 | } |
| 47 | }; |
| Alexander Kornienko | f00654e | 2015-06-23 09:49:53 +0000 | [diff] [blame] | 48 | } |
| Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 49 | |
| 50 | #endif |