1//===-- NVPTXMachineFunctionInfo.h - NVPTX-specific Function Info --------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This class is attached to a MachineFunction instance and tracks target-
10// dependent information
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_LIB_TARGET_NVPTX_NVPTXMACHINEFUNCTIONINFO_H
15#define LLVM_LIB_TARGET_NVPTX_NVPTXMACHINEFUNCTIONINFO_H
16
17#include "llvm/ADT/StringRef.h"
18#include "llvm/CodeGen/MachineFunction.h"
19#include <map>
20
21namespace llvm {
22class CallBase;
23
24class NVPTXMachineFunctionInfo : public MachineFunctionInfo {
25private:
26 /// Stores a mapping from index to symbol name for image handles that are
27 /// replaced with image references
28 SmallVector<std::string, 8> ImageHandleList;
29
30 /// Stores a mapping from a unique call-site id to the call instruction that
31 /// needs an indirect-call prototype emitted.
32 std::map<unsigned, const CallBase *> CallPrototypes;
33
34public:
35 NVPTXMachineFunctionInfo(const Function &F, const TargetSubtargetInfo *STI) {}
36
37 MachineFunctionInfo *
38 clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF,
39 const DenseMap<MachineBasicBlock *, MachineBasicBlock *> &Src2DstMBB)
40 const override {
41 return DestMF.cloneInfo<NVPTXMachineFunctionInfo>(Old: *this);
42 }
43
44 /// Returns the index for the symbol \p Symbol. If the symbol was previously,
45 /// added, the same index is returned. Otherwise, the symbol is added and the
46 /// new index is returned.
47 unsigned getImageHandleSymbolIndex(StringRef Symbol) {
48 // Is the symbol already present?
49 for (unsigned i = 0, e = ImageHandleList.size(); i != e; ++i)
50 if (ImageHandleList[i] == Symbol)
51 return i;
52 // Nope, insert it
53 ImageHandleList.push_back(Elt: Symbol.str());
54 return ImageHandleList.size()-1;
55 }
56
57 /// Check if the symbol has a mapping. Having a mapping means the handle is
58 /// replaced with a reference
59 bool checkImageHandleSymbol(StringRef Symbol) const {
60 return llvm::is_contained(Range: ImageHandleList, Element: Symbol);
61 }
62
63 void addCallPrototype(unsigned Id, const CallBase *CB) {
64 CallPrototypes.try_emplace(k: Id, args&: CB);
65 }
66
67 const std::map<unsigned, const CallBase *> &getCallPrototypes() const {
68 return CallPrototypes;
69 }
70};
71}
72
73#endif
74