Skip to content

Commit

Permalink
Remove temporary variables for loads
Browse files Browse the repository at this point in the history
  • Loading branch information
frabert committed Aug 26, 2022
1 parent 01cf2fc commit 706c7da
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 65 deletions.
2 changes: 0 additions & 2 deletions include/rellic/BC/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,4 @@ void RemoveInsertValues(llvm::Module &module);
// Converts by value array arguments and wraps them into a struct, so that
// semantics are preserved in C
void ConvertArrayArguments(llvm::Module &module);

void FindRedundantLoads(llvm::Module &module);
} // namespace rellic
4 changes: 0 additions & 4 deletions lib/AST/IRToASTVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1313,11 +1313,7 @@ void IRToASTVisitor::VisitFunctionDecl(llvm::Function &func) {
fdecl->addDecl(var);
} else if (inst.hasNUsesOrMore(2) ||
(inst.hasNUsesOrMore(1) && llvm::isa<llvm::CallInst>(inst)) ||
llvm::isa<llvm::LoadInst>(inst) ||
llvm::isa<llvm::PHINode>(inst)) {
if (inst.getMetadata("rellic.notemp")) {
continue;
}
if (!inst.getType()->isVoidTy()) {
auto GetPrefix{[&](llvm::Instruction *inst) {
if (llvm::isa<llvm::CallInst>(inst)) {
Expand Down
57 changes: 0 additions & 57 deletions lib/BC/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,61 +437,4 @@ void ConvertArrayArguments(llvm::Module &m) {
CHECK(VerifyModule(&m)) << "Transformation broke module correctness";
}

static void FindRedundantLoads(llvm::Function &func) {
auto HasStoreBeforeUse = [&](llvm::Value *ptr, llvm::User *user,
llvm::LoadInst *load) {
std::unordered_set<llvm::BasicBlock *> visited_blocks;
std::vector<llvm::Instruction *> work_list;
auto inst{llvm::cast<llvm::Instruction>(user)};
work_list.push_back(inst);
while (!work_list.empty()) {
inst = work_list.back();
work_list.pop_back();
auto bb{inst->getParent()};
visited_blocks.insert(bb);

while (inst) {
if (auto store = llvm::dyn_cast<llvm::StoreInst>(inst)) {
if (store->getPointerOperand() == ptr) {
return true;
}
}
if (inst == load) {
return false;
}
inst = inst->getPrevNode();
}
for (auto pred : llvm::predecessors(bb)) {
if (!visited_blocks.count(pred)) {
work_list.push_back(pred->getTerminator());
}
}
}

return false;
};

for (auto &inst : llvm::instructions(func)) {
if (auto load = llvm::dyn_cast<llvm::LoadInst>(&inst)) {
for (auto &use : load->uses()) {
auto ptr{load->getPointerOperand()};
if (!llvm::isa<llvm::AllocaInst>(ptr)) {
continue;
}
if (HasStoreBeforeUse(ptr, use.getUser(), load)) {
continue;
}
load->setMetadata("rellic.notemp",
llvm::MDNode::get(func.getContext(), {}));
}
}
}
}

void FindRedundantLoads(llvm::Module &module) {
for (auto &func : module.functions()) {
FindRedundantLoads(func);
}
}

} // namespace rellic
1 change: 0 additions & 1 deletion lib/Decompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ Result<DecompilationResult, DecompilationError> Decompile(

ConvertArrayArguments(*module);
RemoveInsertValues(*module);
FindRedundantLoads(*module);

InitOptPasses();
rellic::DebugInfoCollector dic;
Expand Down
1 change: 0 additions & 1 deletion tools/xref/Xref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ static void LoadModule(const httplib::Request& req, httplib::Response& res) {
return;
}
session.Module = std::unique_ptr<llvm::Module>(mod);
rellic::FindRedundantLoads(*session.Module);
llvm::json::Object msg{{"message", "Ok."}};
SendJSON(res, msg);
res.status = 200;
Expand Down

0 comments on commit 706c7da

Please sign in to comment.