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/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 /// Get the target triple which is a string describing the target host.
47 const Triple &getTargetTriple() const { return LLVMM.getTargetTriple(); }
48
49 const std::string &getSourceFileName() const {
50 return LLVMM.getSourceFileName();
51 }
52
53 /// Look up the specified global variable in the module symbol table. If it
54 /// does not exist, return null. If AllowInternal is set to true, this
55 /// function will return types that have InternalLinkage. By default, these
56 /// types are not returned.
58 bool AllowInternal) const;
60 return getGlobalVariable(Name, /*AllowInternal=*/false);
61 }
62 /// Return the global variable in the module with the specified name, of
63 /// arbitrary type. This method returns null if a global with the specified
64 /// name is not found.
66 return getGlobalVariable(Name, true);
67 }
68
69 // TODO: missing getOrInsertGlobal().
70
71 /// Return the global alias 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 /// Return the global ifunc 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 // TODO: Missing removeGlobalVariable() eraseGlobalVariable(),
82 // insertGlobalVariable()
83
84 // TODO: Missing global_begin(), global_end(), globals().
85
86 // TODO: Missing many other functions.
87
88#ifndef NDEBUG
89 void dumpOS(raw_ostream &OS) const;
90 LLVM_DUMP_METHOD void dump() const;
91#endif // NDEBUG
92};
93
94} // namespace sandboxir
95} // namespace llvm
96
97#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:683
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
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:47
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:65
GlobalVariable * getGlobalVariable(StringRef Name) const
Definition Module.h:59
Context & getContext() const
Definition Module.h:40
LLVM_DUMP_METHOD void dump() const
friend class Context
Definition Module.h:37
const std::string & getSourceFileName() const
Definition Module.h:49
LLVM_ABI Function * getFunction(StringRef Name) const
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.