Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposing BB level representations #129

Merged
merged 15 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ jobs:
- name: make
run: cd build && make -j8
- name: Run-tests
run: cd build && ulimit -s unlimited && make check
run: cd build && ulimit -s unlimited && make check_ir2vec
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ If you're a C++ developer and require low-level control, optimization, or integr

This process would generate `ir2vec` binary under `build/bin` directory, `libIR2Vec.a` and `libIR2Vec.so` under `build/lib` directory.

To ensure the correctness, run `make check`
To ensure the correctness, run `make check_ir2vec`



Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ if(NOT LLVM_IR2VEC)

add_subdirectory(test-suite)

add_custom_target(check
add_custom_target(check_ir2vec
COMMAND python3 test-lit.py -a .
COMMENT "Running LIT based test-suite"
WORKING_DIRECTORY ./test-suite
Expand Down
3 changes: 2 additions & 1 deletion src/FlowAware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include <functional>
#include <regex>
#include <string>

using namespace llvm;
using namespace IR2Vec;
Expand Down Expand Up @@ -534,7 +535,7 @@ Vector IR2Vec_FA::func2Vec(Function &F,
bbVector.begin(), std::plus<double>());
}
}

bbVecMap[b] = bbVector;
IR2VEC_DEBUG(outs() << "-------------------------------------------\n");
for (auto i : bbVector) {
if ((i <= 0.0001 && i > 0) || (i < 0 && i >= -0.0001)) {
Expand Down
5 changes: 5 additions & 0 deletions src/Symbolic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ Vector IR2Vec_Symbolic::func2Vec(Function &F,
std::transform(funcVector.begin(), funcVector.end(),
weightedBBVector.begin(), funcVector.begin(),
std::plus<double>());
bbVecMap[b] = weightedBBVector;
}

funcStack.pop_back();
Expand All @@ -130,6 +131,10 @@ Vector IR2Vec_Symbolic::func2Vec(Function &F,

Vector IR2Vec_Symbolic::bb2Vec(BasicBlock &B,
SmallVector<Function *, 15> &funcStack) {
auto It = bbVecMap.find(&B);
if (It != bbVecMap.end()) {
return It->second;
}
Vector bbVector(DIM, 0);

for (auto &I : B) {
Expand Down
6 changes: 6 additions & 0 deletions src/include/FlowAware.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class IR2Vec_FA {

llvm::SmallMapVector<const llvm::Instruction *, IR2Vec::Vector, 128>
instVecMap;
llvm::SmallMapVector<const llvm::BasicBlock *, IR2Vec::Vector, 16> bbVecMap;
llvm::SmallMapVector<const llvm::Function *, IR2Vec::Vector, 16> funcVecMap;

llvm::SmallMapVector<const llvm::Function *,
Expand Down Expand Up @@ -183,6 +184,11 @@ class IR2Vec_FA {
return instVecMap;
}

llvm::SmallMapVector<const llvm::BasicBlock *, IR2Vec::Vector, 16>
getBBVecMap() {
return bbVecMap;
}

llvm::SmallMapVector<const llvm::Function *, IR2Vec::Vector, 16>
getFuncVecMap() {
return funcVecMap;
Expand Down
9 changes: 9 additions & 0 deletions src/include/IR2Vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Embeddings {
float WA = 0.2, float WT = 0.5);

llvm::SmallMapVector<const llvm::Instruction *, Vector, 128> instVecMap;
llvm::SmallMapVector<const llvm::BasicBlock *, IR2Vec::Vector, 16> bbVecMap;
llvm::SmallMapVector<const llvm::Function *, Vector, 16> funcVecMap;
Vector pgmVector;
std::map<std::string, IR2Vec::Vector> vocabulary;
Expand Down Expand Up @@ -56,6 +57,14 @@ class Embeddings {
return instVecMap;
}

// Returns a map containing basic block and the corresponding vector
// representations for a given module corresponding to the IR2VecMode and
// other configurations that is set in constructor
llvm::SmallMapVector<const llvm::BasicBlock *, IR2Vec::Vector, 16>
getBBVecMap() {
return bbVecMap;
}

// Returns a map containing functions and the corresponding vector
// representations for a given module corresponding to the IR2VecMode and
// other configurations that is set in constructor
Expand Down
6 changes: 6 additions & 0 deletions src/include/Symbolic.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class IR2Vec_Symbolic {
llvm::SmallVector<llvm::Function *, 15> &funcStack);
std::string res;
llvm::SmallMapVector<const llvm::Function *, IR2Vec::Vector, 16> funcVecMap;
llvm::SmallMapVector<const llvm::BasicBlock *, IR2Vec::Vector, 16> bbVecMap;
llvm::SmallMapVector<const llvm::Instruction *, IR2Vec::Vector, 128>
instVecMap;

Expand All @@ -52,6 +53,11 @@ class IR2Vec_Symbolic {
return instVecMap;
}

llvm::SmallMapVector<const llvm::BasicBlock *, IR2Vec::Vector, 16>
getBBVecMap() {
return bbVecMap;
}

llvm::SmallMapVector<const llvm::Function *, IR2Vec::Vector, 16>
getFuncVecMap() {
return funcVecMap;
Expand Down
4 changes: 4 additions & 0 deletions src/libIR2Vec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,26 @@ int IR2Vec::Embeddings::generateEncodings(llvm::Module &M,
FA.generateFlowAwareEncodingsForFunction(o, funcName);
instVecMap = FA.getInstVecMap();
funcVecMap = FA.getFuncVecMap();
bbVecMap = FA.getBBVecMap();
} else if (mode == IR2Vec::IR2VecMode::FlowAware) {
IR2Vec_FA FA(M, vocabulary);
FA.generateFlowAwareEncodings(o);
instVecMap = FA.getInstVecMap();
funcVecMap = FA.getFuncVecMap();
bbVecMap = FA.getBBVecMap();
pgmVector = FA.getProgramVector();
} else if (mode == IR2Vec::IR2VecMode::Symbolic && !funcName.empty()) {
IR2Vec_Symbolic SYM(M, vocabulary);
SYM.generateSymbolicEncodingsForFunction(0, funcName);
instVecMap = SYM.getInstVecMap();
funcVecMap = SYM.getFuncVecMap();
bbVecMap = SYM.getBBVecMap();
} else if (mode == IR2Vec::IR2VecMode::Symbolic) {
IR2Vec_Symbolic SYM(M, vocabulary);
SYM.generateSymbolicEncodings(o);
instVecMap = SYM.getInstVecMap();
funcVecMap = SYM.getFuncVecMap();
bbVecMap = SYM.getBBVecMap();
pgmVector = SYM.getProgramVector();
}

Expand Down
Loading