| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
#ifndef LLVM_IR_MODULESLOTTRACKER_H |
| 10 |
#define LLVM_IR_MODULESLOTTRACKER_H |
| 11 |
|
| 12 |
#include <functional> |
| 13 |
#include <memory> |
| 14 |
#include <utility> |
| 15 |
#include <vector> |
| 16 |
|
| 17 |
namespace llvm { |
| 18 |
|
| 19 |
class Module; |
| 20 |
class Function; |
| 21 |
class SlotTracker; |
| 22 |
class Value; |
| 23 |
class MDNode; |
| 24 |
|
| 25 |
|
| 26 |
class AbstractSlotTrackerStorage { |
| 27 |
public: |
| 28 |
virtual ~AbstractSlotTrackerStorage(); |
| 29 |
|
| 30 |
virtual unsigned getNextMetadataSlot() = 0; |
| 31 |
|
| 32 |
virtual void createMetadataSlot(const MDNode *) = 0; |
| 33 |
virtual int getMetadataSlot(const MDNode *) = 0; |
| 34 |
}; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
class ModuleSlotTracker { |
| 45 |
|
| 46 |
std::unique_ptr<SlotTracker> MachineStorage; |
| 47 |
bool ShouldCreateStorage = false; |
| 48 |
bool ShouldInitializeAllMetadata = false; |
| 49 |
|
| 50 |
const Module *M = nullptr; |
| 51 |
const Function *F = nullptr; |
| 52 |
SlotTracker *Machine = nullptr; |
| 53 |
|
| 54 |
std::function<void(AbstractSlotTrackerStorage *, const Module *, bool)> |
| 55 |
ProcessModuleHookFn; |
| 56 |
std::function<void(AbstractSlotTrackerStorage *, const Function *, bool)> |
| 57 |
ProcessFunctionHookFn; |
| 58 |
|
| 59 |
public: |
| 60 |
|
| 61 |
ModuleSlotTracker(SlotTracker &Machine, const Module *M, |
| 62 |
const Function *F = nullptr); |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
explicit ModuleSlotTracker(const Module *M, |
| 72 |
bool ShouldInitializeAllMetadata = true); |
| 73 |
|
| 74 |
|
| 75 |
virtual ~ModuleSlotTracker(); |
| 76 |
|
| 77 |
|
| 78 |
SlotTracker *getMachine(); |
| 79 |
|
| 80 |
const Module *getModule() const { return M; } |
| 81 |
const Function *getCurrentFunction() const { return F; } |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
void incorporateFunction(const Function &F); |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
int getLocalSlot(const Value *V); |
| 95 |
|
| 96 |
void setProcessHook( |
| 97 |
std::function<void(AbstractSlotTrackerStorage *, const Module *, bool)>); |
| 98 |
void setProcessHook(std::function<void(AbstractSlotTrackerStorage *, |
| 99 |
const Function *, bool)>); |
| 100 |
|
| 101 |
using MachineMDNodeListType = |
| 102 |
std::vector<std::pair<unsigned, const MDNode *>>; |
| 103 |
|
| 104 |
void collectMDNodes(MachineMDNodeListType &L, unsigned LB, unsigned UB) const; |
| 105 |
}; |
| 106 |
|
| 107 |
} |
| 108 |
|
| 109 |
#endif |