LLVM: lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
29#include
30#include
31#include
32#include
33
34using namespace llvm;
35
36namespace {
37
39public:
40 void beginAssembly(Module &M, GCModuleInfo &Info, AsmPrinter &AP) override;
41 void finishAssembly(Module &M, GCModuleInfo &Info, AsmPrinter &AP) override;
42};
43
44}
45
46static GCMetadataPrinterRegistry::Add
47 Y("ocaml", "ocaml 3.10-compatible collector");
48
50
52 const std::string &MId = M.getModuleIdentifier();
53
54 std::string SymName;
55 SymName += "caml";
56 size_t Letter = SymName.size();
57 SymName.append(MId.begin(), llvm::find(MId, '.'));
58 SymName += "__";
59 SymName += Id;
60
61
62 SymName[Letter] = toupper(SymName[Letter]);
63
66
68
71}
72
77
80}
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98void OcamlGCMetadataPrinter::finishAssembly(Module &M, GCModuleInfo &Info,
99 AsmPrinter &AP) {
100 unsigned IntPtrSize = M.getDataLayout().getPointerSize();
101
104
107
108
109 AP.OutStreamer->emitIntValue(0, IntPtrSize);
110
113
114 int NumDescriptors = 0;
115 for (std::unique_ptr &FI :
117 if (FI->getStrategy().getName() != getStrategy().getName())
118
119 continue;
120 NumDescriptors += FI->size();
121 }
122
123 if (NumDescriptors >= 1 << 16) {
124
126 }
129
130 for (std::unique_ptr &FI :
132 if (FI->getStrategy().getName() != getStrategy().getName())
133
134 continue;
135
136 uint64_t FrameSize = FI->getFrameSize();
137 if (FrameSize >= 1 << 16) {
138
140 "' is too large for the ocaml GC! "
141 "Frame size " +
142 Twine(FrameSize) +
143 ">= 65536.\n"
144 "(" +
145 Twine(reinterpret_cast<uintptr_t>(FI.get())) + ")");
146 }
147
148 AP.OutStreamer->AddComment("live roots for " +
149 Twine(FI->getFunction().getName()));
151
153 ++J) {
154 size_t LiveCount = FI->live_size(J);
155 if (LiveCount >= 1 << 16) {
156
158 "' is too large for the ocaml GC! "
159 "Live root count " +
160 Twine(LiveCount) + " >= 65536.");
161 }
162
163 AP.OutStreamer->emitSymbolValue(J->Label, IntPtrSize);
166
168 KE = FI->live_end(J);
169 K != KE; ++K) {
170 if (K->StackOffset >= 1 << 16) {
171
173 "GC root stack offset is outside of fixed stack frame and out "
174 "of range for ocaml GC!");
175 }
177 }
178
180 }
181 }
182}
Analysis containing CSE Info
Module.h This file contains the declarations for the Module class.
Machine Check Debug Module
static void EmitCamlGlobal(const Module &M, AsmPrinter &AP, const char *Id)
Definition OcamlGCPrinter.cpp:51
static StringRef getName(Value *V)
This file defines the SmallString class.
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
This class is intended to be used as a driving class for all asm writers.
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
void emitAlignment(Align Alignment, const GlobalObject *GV=nullptr, unsigned MaxBytesToEmit=0) const
Emit an alignment directive to the specified power of two boundary.
MCContext & OutContext
This is the context for the output file that we are streaming.
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
void emitInt16(int Value) const
Emit a short directive and value.
std::vector< GCRoot >::const_iterator live_iterator
std::vector< GCPoint >::iterator iterator
An analysis pass which caches information about the entire Module.
LLVM_ABI MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
MCSection * getTextSection() const
MCSection * getDataSection() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
LLVM_ABI void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV, bool CannotUsePrivateLabel) const
Print the appropriate prefix and the specified global variable's name.
A Module instance is used to store all the information related to an LLVM module.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
This is an optimization pass for GlobalISel generic memory operations.
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
LLVM_ABI void linkOcamlGCPrinter()
Creates an ocaml-compatible metadata printer.
Definition OcamlGCPrinter.cpp:49
@ MCSA_Global
.type _foo, @gnu_unique_object