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