xref: /freebsd/contrib/llvm-project/llvm/include/llvm/SandboxIR/Module.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 //===- Module.h -------------------------------------------------*- C++ -*-===//
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 #ifndef LLVM_SANDBOXIR_MODULE_H
10 #define LLVM_SANDBOXIR_MODULE_H
11 
12 #include "llvm/ADT/STLExtras.h"
13 #include "llvm/IR/Module.h"
14 #include "llvm/Support/Compiler.h"
15 #include <string>
16 
17 namespace llvm {
18 
19 class DataLayout;
20 
21 namespace sandboxir {
22 
23 class Context;
24 class Function;
25 class GlobalVariable;
26 class Type;
27 class Constant;
28 class GlobalAlias;
29 class GlobalIFunc;
30 
31 /// In SandboxIR the Module is mainly used to access the list of global objects.
32 class Module {
33   llvm::Module &LLVMM;
34   Context &Ctx;
35 
Module(llvm::Module & LLVMM,Context & Ctx)36   Module(llvm::Module &LLVMM, Context &Ctx) : LLVMM(LLVMM), Ctx(Ctx) {}
37   friend class Context; // For constructor.
38 
39 public:
getContext()40   Context &getContext() const { return Ctx; }
41 
42   LLVM_ABI Function *getFunction(StringRef Name) const;
43 
getDataLayout()44   const DataLayout &getDataLayout() const { return LLVMM.getDataLayout(); }
45 
getSourceFileName()46   const std::string &getSourceFileName() const {
47     return LLVMM.getSourceFileName();
48   }
49 
50   /// Look up the specified global variable in the module symbol table. If it
51   /// does not exist, return null. If AllowInternal is set to true, this
52   /// function will return types that have InternalLinkage. By default, these
53   /// types are not returned.
54   LLVM_ABI GlobalVariable *getGlobalVariable(StringRef Name,
55                                              bool AllowInternal) const;
getGlobalVariable(StringRef Name)56   GlobalVariable *getGlobalVariable(StringRef Name) const {
57     return getGlobalVariable(Name, /*AllowInternal=*/false);
58   }
59   /// Return the global variable in the module with the specified name, of
60   /// arbitrary type. This method returns null if a global with the specified
61   /// name is not found.
getNamedGlobal(StringRef Name)62   GlobalVariable *getNamedGlobal(StringRef Name) const {
63     return getGlobalVariable(Name, true);
64   }
65 
66   // TODO: missing getOrInsertGlobal().
67 
68   /// Return the global alias in the module with the specified name, of
69   /// arbitrary type. This method returns null if a global with the specified
70   /// name is not found.
71   LLVM_ABI GlobalAlias *getNamedAlias(StringRef Name) const;
72 
73   /// Return the global ifunc in the module with the specified name, of
74   /// arbitrary type. This method returns null if a global with the specified
75   /// name is not found.
76   LLVM_ABI GlobalIFunc *getNamedIFunc(StringRef Name) const;
77 
78   // TODO: Missing removeGlobalVariable() eraseGlobalVariable(),
79   // insertGlobalVariable()
80 
81   // TODO: Missing global_begin(), global_end(), globals().
82 
83   // TODO: Missing many other functions.
84 
85 #ifndef NDEBUG
86   void dumpOS(raw_ostream &OS) const;
87   LLVM_DUMP_METHOD void dump() const;
88 #endif // NDEBUG
89 };
90 
91 } // namespace sandboxir
92 } // namespace llvm
93 
94 #endif // LLVM_SANDBOXIR_MODULE_H
95