LLVM 20.0.0git
Module.h
Go to the documentation of this file.
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 <string>
15
16namespace llvm {
17
18class DataLayout;
19
20namespace sandboxir {
21
22class Context;
23class Function;
24class GlobalVariable;
25class Type;
26class Constant;
27class GlobalAlias;
28class GlobalIFunc;
29
30/// In SandboxIR the Module is mainly used to access the list of global objects.
31class Module {
32 llvm::Module &LLVMM;
33 Context &Ctx;
34
35 Module(llvm::Module &LLVMM, Context &Ctx) : LLVMM(LLVMM), Ctx(Ctx) {}
36 friend class Context; // For constructor.
37
38public:
39 Context &getContext() const { return Ctx; }
40
42
43 const DataLayout &getDataLayout() const { return LLVMM.getDataLayout(); }
44
45 const std::string &getSourceFileName() const {
46 return LLVMM.getSourceFileName();
47 }
48
49 /// Look up the specified global variable in the module symbol table. If it
50 /// does not exist, return null. If AllowInternal is set to true, this
51 /// function will return types that have InternalLinkage. By default, these
52 /// types are not returned.
53 GlobalVariable *getGlobalVariable(StringRef Name, bool AllowInternal) const;
55 return getGlobalVariable(Name, /*AllowInternal=*/false);
56 }
57 /// Return the global variable in the module with the specified name, of
58 /// arbitrary type. This method returns null if a global with the specified
59 /// name is not found.
61 return getGlobalVariable(Name, true);
62 }
63
64 // TODO: missing getOrInsertGlobal().
65
66 /// Return the global alias in the module with the specified name, of
67 /// arbitrary type. This method returns null if a global with the specified
68 /// name is not found.
70
71 /// Return the global ifunc in the module with the specified name, of
72 /// arbitrary type. This method returns null if a global with the specified
73 /// name is not found.
75
76 // TODO: Missing removeGlobalVariable() eraseGlobalVariable(),
77 // insertGlobalVariable()
78
79 // TODO: Missing global_begin(), global_end(), globals().
80
81 // TODO: Missing many other functions.
82
83#ifndef NDEBUG
84 void dumpOS(raw_ostream &OS) const;
85 LLVM_DUMP_METHOD void dump() const;
86#endif // NDEBUG
87};
88
89} // namespace sandboxir
90} // namespace llvm
91
92#endif // LLVM_SANDBOXIR_MODULE_H
RelocType Type
Definition: COFFYAML.cpp:410
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:622
std::string Name
Module.h This file contains the declarations for the Module class.
This file contains some templates that are useful if you are working with the STL at all.
raw_pwrite_stream & OS
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
const std::string & getSourceFileName() const
Get the module's original source file name.
Definition: Module.h:279
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition: Module.h:294
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
In SandboxIR the Module is mainly used to access the list of global objects.
Definition: Module.h:31
GlobalAlias * getNamedAlias(StringRef Name) const
Return the global alias in the module with the specified name, of arbitrary type.
const DataLayout & getDataLayout() const
Definition: Module.h:43
void dumpOS(raw_ostream &OS) const
Definition: Module.cpp:37
GlobalVariable * getNamedGlobal(StringRef Name) const
Return the global variable in the module with the specified name, of arbitrary type.
Definition: Module.h:60
GlobalVariable * getGlobalVariable(StringRef Name) const
Definition: Module.h:54
GlobalVariable * getGlobalVariable(StringRef Name, bool AllowInternal) const
Look up the specified global variable in the module symbol table.
Context & getContext() const
Definition: Module.h:39
GlobalIFunc * getNamedIFunc(StringRef Name) const
Return the global ifunc in the module with the specified name, of arbitrary type.
LLVM_DUMP_METHOD void dump() const
Function * getFunction(StringRef Name) const
const std::string & getSourceFileName() const
Definition: Module.h:45
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18