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