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 LLVMIRBuilder.disableGEPCanonicalization();
42 }
43 friend class Context; // For constructor.
44
45 auto &getLLVMIRBuilder() { return LLVMIRBuilder; }
46 friend class Instruction; // For getLLVMIRBuilder().
47
48public:
49 Context &getContext() const { return Ctx; }
50
52
53 const DataLayout &getDataLayout() const { return LLVMM.getDataLayout(); }
54
55 /// Get the target triple which is a string describing the target host.
56 const Triple &getTargetTriple() const { return LLVMM.getTargetTriple(); }
57
58 const std::string &getSourceFileName() const {
59 return LLVMM.getSourceFileName();
60 }
61
62 /// Look up the specified global variable in the module symbol table. If it
63 /// does not exist, return null. If AllowInternal is set to true, this
64 /// function will return types that have InternalLinkage. By default, these
65 /// types are not returned.
67 bool AllowInternal) const;
69 return getGlobalVariable(Name, /*AllowInternal=*/false);
70 }
71 /// Return the global variable 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 return getGlobalVariable(Name, true);
76 }
77
78 // TODO: missing getOrInsertGlobal().
79
80 /// Return the global alias in the module with the specified name, of
81 /// arbitrary type. This method returns null if a global with the specified
82 /// name is not found.
84
85 /// Return the global ifunc in the module with the specified name, of
86 /// arbitrary type. This method returns null if a global with the specified
87 /// name is not found.
89
90 // TODO: Missing removeGlobalVariable() eraseGlobalVariable(),
91 // insertGlobalVariable()
92
93 // TODO: Missing global_begin(), global_end(), globals().
94
95 // TODO: Missing many other functions.
96
97#ifndef NDEBUG
98 void dumpOS(raw_ostream &OS) const;
99 LLVM_DUMP_METHOD void dump() const;
100#endif // NDEBUG
101};
102
103} // namespace sandboxir
104} // namespace llvm
105
106#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:2987
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:56
const DataLayout & getDataLayout() const
Definition Module.h:53
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:74
GlobalVariable * getGlobalVariable(StringRef Name) const
Definition Module.h:68
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Definition Module.h:46
Context & getContext() const
Definition Module.h:49
LLVM_DUMP_METHOD void dump() const
friend class Context
Definition Module.h:43
const std::string & getSourceFileName() const
Definition Module.h:58
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:48
This is an optimization pass for GlobalISel generic memory operations.