Skip to content

Commit 83e9643

Browse files
committed
[TSAR, Analysis] Add pass for Restrict Arguments analysis.
1 parent 3ac4e77 commit 83e9643

File tree

17 files changed

+973
-2
lines changed

17 files changed

+973
-2
lines changed

include/tsar/Analysis/Memory/Passes.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ ImmutablePass *createGlobalDefinedMemoryStorage();
191191
/// analysis.
192192
void initializeGlobalDefinedMemoryWrapperPass(PassRegistry &Registry);
193193

194+
/// Initialize a pass to perform iterprocedural analysis of restrict arguments
195+
void initializeRestrictionArgumentsPassPass(PassRegistry& Registry);
196+
197+
/// Create a pass to perform iterprocedural analysis of restrict arguments
198+
ModulePass* createRestrictionArgumentsPass();
199+
194200
/// Create analysis server.
195201
ModulePass *createDIMemoryAnalysisServer();
196202

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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

lib/Analysis/Memory/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ set(ANALYSIS_SOURCES Passes.cpp DependenceAnalysis.cpp PrivateAnalysis.cpp
44
EstimateMemory.cpp DefinedMemory.cpp LiveMemory.cpp AliasTreePrinter.cpp
55
DIAliasTreePrinter.cpp DIMemoryLocation.cpp DFMemoryLocation.cpp
66
Delinearization.cpp ServerUtils.cpp ClonedDIMemoryMatcher.cpp
7-
GlobalLiveMemory.cpp GlobalDefinedMemory.cpp DIClientServerInfo.cpp
8-
DIMemoryAnalysisServer.cpp DIArrayAccess.cpp)
7+
GlobalLiveMemory.cpp GlobalDefinedMemory.cpp RestrictionArgumentsPass.cpp
8+
DIClientServerInfo.cpp DIMemoryAnalysisServer.cpp DIArrayAccess.cpp)
99

1010
if(MSVC_IDE)
1111
file(GLOB_RECURSE ANALYSIS_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}

lib/Analysis/Memory/Passes.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,5 @@ void llvm::initializeMemoryAnalysis(PassRegistry &Registry) {
4646
initializeGlobalDefinedMemoryPass(Registry);
4747
initializeGlobalLiveMemoryPass(Registry);
4848
initializeDIArrayAccessWrapperPass(Registry);
49+
initializeRestrictionArgumentsPassPass(Registry);
4950
}

0 commit comments

Comments
 (0)