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;
31class Instruction;
32
33/// In SandboxIR the Module is mainly used to access the list of global objects.
34class Module {
35 llvm::Module &LLVMM;
36 Context &Ctx;
37 IRBuilder<ConstantFolder> LLVMIRBuilder;
38
39 Module(llvm::Module &LLVMM, Context &Ctx)
40 : LLVMM(LLVMM), Ctx(Ctx), LLVMIRBuilder(LLVMM) {}
41 friend class Context; // For constructor.
42
43 auto &getLLVMIRBuilder() { return LLVMIRBuilder; }
44 friend class Instruction; // For getLLVMIRBuilder().
45
46public:
47 Context &getContext() const { return Ctx; }
48
50
51 const DataLayout &getDataLayout() const { return LLVMM.getDataLayout(); }
52
53 /// Get the target triple which is a string describing the target host.
54 const Triple &getTargetTriple() const { return LLVMM.getTargetTriple(); }
55
56 const std::string &getSourceFileName() const {
57 return LLVMM.getSourceFileName();
58 }
59
60 /// Look up the specified global variable in the module symbol table. If it
61 /// does not exist, return null. If AllowInternal is set to true, this
62 /// function will return types that have InternalLinkage. By default, these
63 /// types are not returned.
65 bool AllowInternal) const;
67 return getGlobalVariable(Name, /*AllowInternal=*/false);
68 }
69 /// Return the global variable in the module with the specified name, of
70 /// arbitrary type. This method returns null if a global with the specified
71 /// name is not found.
73 return getGlobalVariable(Name, true);
74 }
75
76 // TODO: missing getOrInsertGlobal().
77
78 /// Return the global alias in the module with the specified name, of
79 /// arbitrary type. This method returns null if a global with the specified
80 /// name is not found.
82
83 /// Return the global ifunc in the module with the specified name, of
84 /// arbitrary type. This method returns null if a global with the specified
85 /// name is not found.
87
88 // TODO: Missing removeGlobalVariable() eraseGlobalVariable(),
89 // insertGlobalVariable()
90
91 // TODO: Missing global_begin(), global_end(), globals().
92
93 // TODO: Missing many other functions.
94
95#ifndef NDEBUG
96 void dumpOS(raw_ostream &OS) const;
97 LLVM_DUMP_METHOD void dump() const;
98#endif // NDEBUG
99};
100
101} // namespace sandboxir
102} // namespace llvm
103
104#endif // LLVM_SANDBOXIR_MODULE_H
#define LLVM_ABI
Definition Compiler.h:211
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:690
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:2909
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
A sandboxir::User with operands, opcode and linked with previous/next instructions in an instruction ...
Definition Instruction.h:43
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:54
const DataLayout & getDataLayout() const
Definition Module.h:51
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:72
GlobalVariable * getGlobalVariable(StringRef Name) const
Definition Module.h:66
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Definition Module.h:44
Context & getContext() const
Definition Module.h:47
LLVM_DUMP_METHOD void dump() const
friend class Context
Definition Module.h:41
const std::string & getSourceFileName() const
Definition Module.h:56
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.