LLVM 24.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/IRBuilder.h"
14#include "llvm/IR/Module.h"
16#include <string>
17
18namespace llvm {
19
20class DataLayout;
21
22namespace sandboxir {
23
24class Context;
25class Function;
26class GlobalVariable;
27class Type;
28class Constant;
29class GlobalAlias;
30class GlobalIFunc;
31
32/// In SandboxIR the Module is mainly used to access the list of global objects.
33class Module {
34 llvm::Module &LLVMM;
35 Context &Ctx;
36 IRBuilder<ConstantFolder> LLVMIRBuilder;
37
38 Module(llvm::Module &LLVMM, Context &Ctx)
39 : LLVMM(LLVMM), Ctx(Ctx), LLVMIRBuilder(LLVMM) {}
40 friend class Context; // For constructor.
41
42public:
43 Context &getContext() const { return Ctx; }
44
46
47 const DataLayout &getDataLayout() const { return LLVMM.getDataLayout(); }
48
49 /// Get the target triple which is a string describing the target host.
50 const Triple &getTargetTriple() const { return LLVMM.getTargetTriple(); }
51
52 const std::string &getSourceFileName() const {
53 return LLVMM.getSourceFileName();
54 }
55
56 auto &getLLVMIRBuilder() { return LLVMIRBuilder; }
57
58 /// Look up the specified global variable in the module symbol table. If it
59 /// does not exist, return null. If AllowInternal is set to true, this
60 /// function will return types that have InternalLinkage. By default, these
61 /// types are not returned.
63 bool AllowInternal) const;
65 return getGlobalVariable(Name, /*AllowInternal=*/false);
66 }
67 /// Return the global variable in the module with the specified name, of
68 /// arbitrary type. This method returns null if a global with the specified
69 /// name is not found.
71 return getGlobalVariable(Name, true);
72 }
73
74 // TODO: missing getOrInsertGlobal().
75
76 /// Return the global alias in the module with the specified name, of
77 /// arbitrary type. This method returns null if a global with the specified
78 /// name is not found.
80
81 /// Return the global ifunc in the module with the specified name, of
82 /// arbitrary type. This method returns null if a global with the specified
83 /// name is not found.
85
86 // TODO: Missing removeGlobalVariable() eraseGlobalVariable(),
87 // insertGlobalVariable()
88
89 // TODO: Missing global_begin(), global_end(), globals().
90
91 // TODO: Missing many other functions.
92
93#ifndef NDEBUG
94 void dumpOS(raw_ostream &OS) const;
95 LLVM_DUMP_METHOD void dump() const;
96#endif // NDEBUG
97};
98
99} // namespace sandboxir
100} // namespace llvm
101
102#endif // LLVM_SANDBOXIR_MODULE_H
#define LLVM_ABI
Definition Compiler.h:215
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:686
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.
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition IRBuilder.h:2918
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
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 Triple & getTargetTriple() const
Get the target triple which is a string describing the target host.
Definition Module.h:50
const DataLayout & getDataLayout() const
Definition Module.h:47
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:70
GlobalVariable * getGlobalVariable(StringRef Name) const
Definition Module.h:64
Context & getContext() const
Definition Module.h:43
LLVM_DUMP_METHOD void dump() const
friend class Context
Definition Module.h:40
const std::string & getSourceFileName() const
Definition Module.h:52
LLVM_ABI Function * getFunction(StringRef Name) const
auto & getLLVMIRBuilder()
Definition Module.h:56
Just like llvm::Type these are immutable, unique, never get freed and can only be created via static ...
Definition Type.h:49
This is an optimization pass for GlobalISel generic memory operations.