llir-opt
0.0.1
Low-Level Post-Link Optimiser for OCaml and C
|
10 #include <llvm/Pass.h>
11 #include <llvm/IR/DataLayout.h>
12 #include <llvm/MC/MCStreamer.h>
13 #include <llvm/MC/MCObjectFileInfo.h>
14 #include <llvm/Target/TargetMachine.h>
15 #include <llvm/CodeGen/MachineFunctionPass.h>
16 #include <llvm/CodeGen/TargetSubtargetInfo.h>
18 #include "core/adt/hash.h"
19 #include "core/annot.h"
54 const llvm::MCObjectFileInfo *objInfo,
55 const llvm::DataLayout &layout,
78 bool runOnModule(llvm::Module &M)
override;
80 void getAnalysisUsage(llvm::AnalysisUsage &AU)
const override;
86 llvm::MCSymbol *Label;
92 std::set<uint16_t> Live;
94 std::vector<size_t> Allocs;
96 std::vector<llvm::MCSymbol *> Debug;
102 llvm::MCSymbol *Label;
106 RootInfo(llvm::MCSymbol *label, int64_t offset)
107 : Label(label), Offset(offset)
117 bool operator==(
const DebugKey &that)
const {
118 return Debug == that.Debug;
123 struct DebugKeyHash {
124 size_t operator() (
const DebugKey &key)
const {
126 for (
const auto &debug : key.Debug) {
127 ::hash_combine(hash, std::hash<int64_t>{}(debug.Location));
128 ::hash_combine(hash, std::hash<std::string>{}(debug.File));
129 ::hash_combine(hash, std::hash<std::string>{}(debug.Definition));
137 llvm::MCSymbol *Definition;
143 llvm::MCSymbol *Symbol;
144 std::vector<DebugInfo> Debug;
148 struct DefinitionInfo {
149 llvm::MCSymbol *Symbol;
150 llvm::MCSymbol *File;
151 std::string Definition;
155 void LowerFrame(
const FrameInfo &frame);
157 llvm::MCSymbol *LowerSymbol(
const std::string_view name);
161 llvm::MCSymbol *RecordDefinition(
162 const std::string &file,
163 const std::string &def
166 llvm::MCSymbol *RecordFile(
const std::string &file);
168 void EmitDiff(llvm::MCSymbol *symbol,
unsigned size = 4);
170 void EmitOffset(llvm::MCSymbol *symbol, int64_t off);
188 std::unordered_map<DebugKey, DebugInfos, DebugKeyHash>
debug_;
191 std::pair<std::string, std::string>,
195 std::unordered_map<std::string, llvm::MCSymbol *>
files_;
virtual llvm::StringRef GetRegisterName(unsigned reg)=0
Returns the name of a register.
std::vector< DebugInfo > DebugInfos
Debug information bundle.
Definition: annot.h:231
std::vector< RootInfo > roots_
List of root frames.
Definition: annot_printer.h:186
virtual llvm::Register GetStackPointer()=0
Returns the stack pointer of the target.
bool shared_
Flag to indicate whether a shared library is emitted.
Definition: annot_printer.h:197
Definition: isel_mapping.h:22
std::unordered_map< std::pair< std::string, std::string >, DefinitionInfo > defs_
Mapping from definitions to labels.
Definition: annot_printer.h:193
virtual unsigned GetImplicitStackSize() const =0
Returns the implicit stack size, besides the frame adjustment.
Definition: annot_printer.h:47
std::vector< FrameInfo > frames_
List of frames to emit information for.
Definition: annot_printer.h:184
std::unordered_map< DebugKey, DebugInfos, DebugKeyHash > debug_
Mapping of debug objects.
Definition: annot_printer.h:188
virtual std::optional< unsigned > GetRegisterIndex(llvm::Register reg)=0
Returns the GC index of a register.
const llvm::MCObjectFileInfo * objInfo_
Object-file specific information.
Definition: annot_printer.h:180
std::unordered_map< std::string, llvm::MCSymbol * > files_
Mapping from file names to labels.
Definition: annot_printer.h:195
llvm::MCStreamer * os_
Streamer to emit output to.
Definition: annot_printer.h:178
const ISelMapping & mapping_
Instruction selector pass containing info for annotations.
Definition: annot_printer.h:174
AnnotPrinter(char &ID, llvm::MCContext *ctx, llvm::MCStreamer *os, const llvm::MCObjectFileInfo *objInfo, const llvm::DataLayout &layout, const ISelMapping &mapping, bool shared)
Initialises the pass which prints data sections.
Definition: annot_printer.cpp:40
const llvm::DataLayout layout_
Data layout.
Definition: annot_printer.h:182
llvm::MCContext * ctx_
LLVM context.
Definition: annot_printer.h:176
virtual int64_t GetFrameOffset(const llvm::MachineInstr &MI) const
Return the offset to apply to a label.
Definition: annot_printer.h:71