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

ISSUE #21 #22 #23 RESOLVED #37

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions ISSUE 21,22,23/ISSUE 21/load_store_analysis/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.18)
project(LoadStoreAnalysisPass)

find_package(LLVM REQUIRED CONFIG)

add_definitions(${LLVM_DEFINITIONS})
include_directories(${LLVM_INCLUDE_DIRS})

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_library(LoadStoreAnalysisPass MODULE LoadStoreAnalysisPass.cpp)
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include "llvm/Pass.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Instructions.h"
#include "llvm/Support/raw_ostream.h"

using namespace llvm;

namespace {
// Add this before the LoadStoreAnalysisPass struct definition
struct MemoryAccessInfo {
enum AccessPattern {
DirectLoad,
DirectStore,
PointerArithmetic,
NestedStructures,
Unknown
};

AccessPattern pattern;
Instruction *inst;

MemoryAccessInfo(AccessPattern pattern, Instruction *inst)
: pattern(pattern), inst(inst) {}
};
// Define the pass class
struct LoadStoreAnalysisPass : public FunctionPass {
static char ID;

LoadStoreAnalysisPass() : FunctionPass(ID) {}

bool runOnFunction(Function &F) override {
errs() << "Function: " << F.getName() << '\n';

for (auto &BB : F) {
for (auto &I : BB) {
if (I.getOpcode() == Instruction::Load) {
errs() << "Found a load instruction: " << I << '\n';
MemoryAccessInfo info(MemoryAccessInfo::DirectLoad, &I);
// TODO: Process the load instruction with the access info
} else if (I.getOpcode() == Instruction::Store) {
errs() << "Found a store instruction: " << I << '\n';
MemoryAccessInfo info(MemoryAccessInfo::DirectStore, &I);
// TODO: Process the store instruction with the access info
}
}
}

return false;
}
};
}

char LoadStoreAnalysisPass::ID = 0;

// Register the pass with the LLVM Pass Manager
static RegisterPass<LoadStoreAnalysisPass> X(
"loadstoreanalysis", "Load/Store Analysis Pass",
false /* Only looks at CFG */,
false /* Analysis Pass */);

Loading