Skip to content
6 changes: 6 additions & 0 deletions include/tsar/Analysis/Memory/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ ImmutablePass *createGlobalDefinedMemoryStorage();
/// analysis.
void initializeGlobalDefinedMemoryWrapperPass(PassRegistry &Registry);

/// Initialize a pass to perform iterprocedural analysis of restrict arguments
void initializeRestrictionArgumentsPassPass(PassRegistry& Registry);

/// Create a pass to perform iterprocedural analysis of restrict arguments
ModulePass* createRestrictionArgumentsPass();

/// Create analysis server.
ModulePass *createDIMemoryAnalysisServer();

Expand Down
88 changes: 88 additions & 0 deletions include/tsar/Analysis/Memory/RestrictionArgumentsPass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@

#ifndef SAPFOR_RESTRICTIONARGUMENTSPASS_H
#define SAPFOR_RESTRICTIONARGUMENTSPASS_H

#include <llvm/Pass.h>
#include <bcl/utility.h>
#include "tsar/Analysis/Memory/Passes.h"
#include <llvm/IR/Instructions.h>
#include <llvm/IR/Type.h>

namespace llvm {

class RestrictionArgumentsPass : public ModulePass, private bcl::Uncopyable {
public:
static char ID;

RestrictionArgumentsPass() : ModulePass(ID) {
initializeRestrictionArgumentsPassPass(*PassRegistry::getPassRegistry());
}

bool runOnModule(llvm::Module& M) override;

void getAnalysisUsage(AnalysisUsage& AU) const override;
};
}


namespace tsar {

typedef std::set<llvm::Value*> MemorySources;

struct FunctionCallWithMemorySources {
llvm::CallInst* mCallI;
llvm::DenseMap<int, MemorySources> mArgumentMemorySources;

FunctionCallWithMemorySources() :
mCallI(nullptr),
mArgumentMemorySources(llvm::DenseMap<int, MemorySources>()) {}

explicit FunctionCallWithMemorySources(llvm::CallInst* CallI) :
mCallI(CallI),
mArgumentMemorySources(llvm::DenseMap<int, MemorySources>()) {}
};

struct ValueWithMemorySources {
llvm::Value* mV;
MemorySources mMemorySources;

explicit ValueWithMemorySources(llvm::Value* V) :
mV(V) {}

ValueWithMemorySources(llvm::Value* V, llvm::Value* MemorySource) :
mV(V) {
mMemorySources.insert(MemorySource);
}

ValueWithMemorySources(llvm::Value* V, MemorySources Sources) :
mV(V) {
mMemorySources.insert(Sources.begin(), Sources.end());
}
};

struct FunctionResultArgumentsMemoryDependencies {
llvm::DenseSet<int> mInfluencingArgumentsIndexes;
// Indicates is returned value always points to the unique memory
bool mIsRestrict;

FunctionResultArgumentsMemoryDependencies() :
mIsRestrict(false) {}
};

struct FunctionArgumentRestrictCalls {
int mArgumentIndex;
llvm::DenseSet<llvm::CallInst*> mRestrictCalls;
bool mAllFunctionCallsRestrict;

FunctionArgumentRestrictCalls(int index) :
mArgumentIndex(index),
mAllFunctionCallsRestrict(false) {}
};

struct FunctionCallsInfo {
llvm::Function* mFunction;
llvm::DenseMap<int, FunctionArgumentRestrictCalls> mRestrictCallsByArguments;
};
}

#endif //SAPFOR_RESTRICTIONARGUMENTSPASS_H
3 changes: 2 additions & 1 deletion lib/Analysis/Memory/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ set(ANALYSIS_SOURCES Passes.cpp DependenceAnalysis.cpp PrivateAnalysis.cpp
DIAliasTreePrinter.cpp DIMemoryLocation.cpp DFMemoryLocation.cpp
Delinearization.cpp ServerUtils.cpp ClonedDIMemoryMatcher.cpp
GlobalLiveMemory.cpp GlobalDefinedMemory.cpp DIClientServerInfo.cpp
DIMemoryAnalysisServer.cpp DIArrayAccess.cpp AllocasModRef.cpp)
DIMemoryAnalysisServer.cpp DIArrayAccess.cpp AllocasModRef.cpp
RestrictionArgumentsPass.cpp)

if(MSVC_IDE)
file(GLOB_RECURSE ANALYSIS_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
Expand Down
1 change: 1 addition & 0 deletions lib/Analysis/Memory/Passes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ void llvm::initializeMemoryAnalysis(PassRegistry &Registry) {
initializeGlobalLiveMemoryPass(Registry);
initializeDIArrayAccessWrapperPass(Registry);
initializeAllocasAAWrapperPassPass(Registry);
initializeRestrictionArgumentsPassPass(Registry);
}
Loading