LLVM 22.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"
15#include <string>
16
17namespace llvm {
18
19class DataLayout;
20
21namespace sandboxir {
22
23class Context;
24class Function;
25class GlobalVariable;
26class Type;
27class Constant;
28class GlobalAlias;
29class GlobalIFunc;
30
31/// In SandboxIR the Module is mainly used to access the list of global objects.
32class Module {
33 llvm::Module &LLVMM;
34 Context &Ctx;
35
36 Module(llvm::Module &LLVMM, Context &Ctx) : LLVMM(LLVMM), Ctx(Ctx) {}
37 friend class Context; // For constructor.
38
39public:
40 Context &getContext() const { return Ctx; }
41
43
44 const DataLayout &getDataLayout() const { return LLVMM.getDataLayout(); }
45
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.
55 bool AllowInternal) 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.
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.
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.
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
RelocType Type
Definition: COFFYAML.cpp:410
#define LLVM_ABI
Definition: Compiler.h:213
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:638
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:67
const std::string & getSourceFileName() const
Get the module's original source file name.
Definition: Module.h:263
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition: Module.h:278
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
In SandboxIR the Module is mainly used to access the list of global objects.
Definition: Module.h:32
LLVM_ABI GlobalIFunc * getNamedIFunc(StringRef Name) const
Return the global ifunc in the module with the specified name, of arbitrary type.
LLVM_ABI 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:44
LLVM_ABI GlobalVariable * getGlobalVariable(StringRef Name, bool AllowInternal) const
Look up the specified global variable in the module symbol table.
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:62
GlobalVariable * getGlobalVariable(StringRef Name) const
Definition: Module.h:56
Context & getContext() const
Definition: Module.h:40
LLVM_DUMP_METHOD void dump() const
const std::string & getSourceFileName() const
Definition: Module.h:46
LLVM_ABI Function * getFunction(StringRef Name) const
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18