xref: /freebsd-src/contrib/llvm-project/llvm/lib/Target/NVPTX/NVPTXMachineFunctionInfo.h (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
10b57cec5SDimitry Andric //===-- NVPTXMachineFunctionInfo.h - NVPTX-specific Function Info  --------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This class is attached to a MachineFunction instance and tracks target-
100b57cec5SDimitry Andric // dependent information
110b57cec5SDimitry Andric //
120b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
130b57cec5SDimitry Andric 
140b57cec5SDimitry Andric #ifndef LLVM_LIB_TARGET_NVPTX_NVPTXMACHINEFUNCTIONINFO_H
150b57cec5SDimitry Andric #define LLVM_LIB_TARGET_NVPTX_NVPTXMACHINEFUNCTIONINFO_H
160b57cec5SDimitry Andric 
170b57cec5SDimitry Andric #include "llvm/CodeGen/MachineFunction.h"
180b57cec5SDimitry Andric 
190b57cec5SDimitry Andric namespace llvm {
200b57cec5SDimitry Andric class NVPTXMachineFunctionInfo : public MachineFunctionInfo {
210b57cec5SDimitry Andric private:
220b57cec5SDimitry Andric   /// Stores a mapping from index to symbol name for removing image handles
230b57cec5SDimitry Andric   /// on Fermi.
240b57cec5SDimitry Andric   SmallVector<std::string, 8> ImageHandleList;
250b57cec5SDimitry Andric 
260b57cec5SDimitry Andric public:
NVPTXMachineFunctionInfo(const Function & F,const TargetSubtargetInfo * STI)27*bdd1243dSDimitry Andric   NVPTXMachineFunctionInfo(const Function &F, const TargetSubtargetInfo *STI) {}
280b57cec5SDimitry Andric 
2981ad6265SDimitry Andric   MachineFunctionInfo *
clone(BumpPtrAllocator & Allocator,MachineFunction & DestMF,const DenseMap<MachineBasicBlock *,MachineBasicBlock * > & Src2DstMBB)3081ad6265SDimitry Andric   clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF,
3181ad6265SDimitry Andric         const DenseMap<MachineBasicBlock *, MachineBasicBlock *> &Src2DstMBB)
3281ad6265SDimitry Andric       const override {
3381ad6265SDimitry Andric     return DestMF.cloneInfo<NVPTXMachineFunctionInfo>(*this);
3481ad6265SDimitry Andric   }
3581ad6265SDimitry Andric 
360b57cec5SDimitry Andric   /// Returns the index for the symbol \p Symbol. If the symbol was previously,
370b57cec5SDimitry Andric   /// added, the same index is returned. Otherwise, the symbol is added and the
380b57cec5SDimitry Andric   /// new index is returned.
getImageHandleSymbolIndex(const char * Symbol)390b57cec5SDimitry Andric   unsigned getImageHandleSymbolIndex(const char *Symbol) {
400b57cec5SDimitry Andric     // Is the symbol already present?
410b57cec5SDimitry Andric     for (unsigned i = 0, e = ImageHandleList.size(); i != e; ++i)
420b57cec5SDimitry Andric       if (ImageHandleList[i] == std::string(Symbol))
430b57cec5SDimitry Andric         return i;
440b57cec5SDimitry Andric     // Nope, insert it
450b57cec5SDimitry Andric     ImageHandleList.push_back(Symbol);
460b57cec5SDimitry Andric     return ImageHandleList.size()-1;
470b57cec5SDimitry Andric   }
480b57cec5SDimitry Andric 
490b57cec5SDimitry Andric   /// Returns the symbol name at the given index.
getImageHandleSymbol(unsigned Idx)500b57cec5SDimitry Andric   const char *getImageHandleSymbol(unsigned Idx) const {
510b57cec5SDimitry Andric     assert(ImageHandleList.size() > Idx && "Bad index");
520b57cec5SDimitry Andric     return ImageHandleList[Idx].c_str();
530b57cec5SDimitry Andric   }
540b57cec5SDimitry Andric };
550b57cec5SDimitry Andric }
560b57cec5SDimitry Andric 
570b57cec5SDimitry Andric #endif
58