|
| 1 | + |
| 2 | +#ifndef SAPFOR_RESTRICTIONARGUMENTSPASS_H |
| 3 | +#define SAPFOR_RESTRICTIONARGUMENTSPASS_H |
| 4 | + |
| 5 | +#include <llvm/Pass.h> |
| 6 | +#include <bcl/utility.h> |
| 7 | +#include "tsar/Analysis/Memory/Passes.h" |
| 8 | +#include <llvm/IR/Instructions.h> |
| 9 | +#include <llvm/IR/Type.h> |
| 10 | + |
| 11 | +namespace llvm { |
| 12 | + |
| 13 | + class RestrictionArgumentsPass : public ModulePass, private bcl::Uncopyable { |
| 14 | + public: |
| 15 | + static char ID; |
| 16 | + |
| 17 | + RestrictionArgumentsPass() : ModulePass(ID) { |
| 18 | + initializeRestrictionArgumentsPassPass(*PassRegistry::getPassRegistry()); |
| 19 | + } |
| 20 | + |
| 21 | + bool runOnModule(llvm::Module& M) override; |
| 22 | + |
| 23 | + void getAnalysisUsage(AnalysisUsage& AU) const override; |
| 24 | + }; |
| 25 | + |
| 26 | +} |
| 27 | + |
| 28 | +namespace tsar { |
| 29 | + |
| 30 | + typedef llvm::DenseSet<llvm::Value*> MemorySources; |
| 31 | + |
| 32 | + struct FunctionCallWithMemorySources { |
| 33 | + llvm::CallInst* mCallI; |
| 34 | + llvm::DenseMap<int, MemorySources> mArgumentMemorySources; |
| 35 | + |
| 36 | + FunctionCallWithMemorySources() : |
| 37 | + mCallI(nullptr), |
| 38 | + mArgumentMemorySources(llvm::DenseMap<int, MemorySources>()) {} |
| 39 | + |
| 40 | + explicit FunctionCallWithMemorySources(llvm::CallInst* CallI) : |
| 41 | + mCallI(CallI), |
| 42 | + mArgumentMemorySources(llvm::DenseMap<int, MemorySources>()) {} |
| 43 | + }; |
| 44 | + |
| 45 | + struct ValueWithMemorySources { |
| 46 | + llvm::Value* mV; |
| 47 | + MemorySources mMemorySources; |
| 48 | + |
| 49 | + explicit ValueWithMemorySources(llvm::Value* V) : |
| 50 | + mV(V) {} |
| 51 | + |
| 52 | + ValueWithMemorySources(llvm::Value* V, llvm::Value* MemorySource) : |
| 53 | + mV(V) { |
| 54 | + mMemorySources.insert(MemorySource); |
| 55 | + } |
| 56 | + |
| 57 | + ValueWithMemorySources(llvm::Value* V, MemorySources Sources) : |
| 58 | + mV(V) { |
| 59 | + mMemorySources.insert(Sources.begin(), Sources.end()); |
| 60 | + } |
| 61 | + }; |
| 62 | + |
| 63 | + struct FunctionResultArgumentsMemoryDependencies { |
| 64 | + llvm::DenseSet<int> mInfluencingArgumentsIndexes; |
| 65 | + // Indicates is returned value always points to the unique memory |
| 66 | + bool mIsRestrict; |
| 67 | + |
| 68 | + FunctionResultArgumentsMemoryDependencies() : |
| 69 | + mIsRestrict(false) {} |
| 70 | + }; |
| 71 | + |
| 72 | + struct FunctionArgumentRestrictCalls { |
| 73 | + int mArgumentIndex; |
| 74 | + llvm::DenseSet<llvm::CallInst*> mRestrictCalls; |
| 75 | + bool mAllFunctionCallsRestrict; |
| 76 | + |
| 77 | + FunctionArgumentRestrictCalls(int index) : |
| 78 | + mArgumentIndex(index), |
| 79 | + mAllFunctionCallsRestrict(false) {} |
| 80 | + }; |
| 81 | + |
| 82 | + struct FunctionCallsInfo { |
| 83 | + llvm::Function* mFunction; |
| 84 | + llvm::DenseMap<int, FunctionArgumentRestrictCalls> mRestrictCallsByArguments; |
| 85 | + }; |
| 86 | + |
| 87 | + //typedef llvm::DenseSet<int> FunctionResultArgumentsMemoryDependencies; |
| 88 | + |
| 89 | +} |
| 90 | + |
| 91 | + |
| 92 | + |
| 93 | +#endif //SAPFOR_RESTRICTIONARGUMENTSPASS_H |
0 commit comments