Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyichao committed Jul 8, 2017
1 parent 8135b09 commit 16eeea4
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/llvm-alloc-opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "julia_internal.h"

#include <map>
#include <set>

using namespace llvm;

Expand Down Expand Up @@ -89,7 +90,8 @@ struct AllocOpt : public FunctionPass {

bool doInitialization(Module &m) override;
bool runOnFunction(Function &F) override;
bool checkInst(Instruction *I, CheckInstStack &stack, bool &ignore_tag);
bool checkInst(Instruction *I, CheckInstStack &stack, std::set<Instruction*> &uses,
bool &ignore_tag);
void replaceUsesWith(Instruction *orig_i, Instruction *new_i);
void lowerAlloc(CallInst *I, size_t sz);
};
Expand Down Expand Up @@ -151,12 +153,14 @@ bool AllocOpt::doInitialization(Module &M)
return true;
}

bool AllocOpt::checkInst(Instruction *I, CheckInstStack &stack, bool &ignore_tag)
bool AllocOpt::checkInst(Instruction *I, CheckInstStack &stack, std::set<Instruction*> &uses,
bool &ignore_tag)
{
if (I->user_empty())
return true;
CheckInstFrame cur{I, 0, I->user_begin(), I->user_end()};
stack.clear();
uses.clear();

// Recursion
auto push_inst = [&] (Instruction *inst) {
Expand Down Expand Up @@ -224,6 +228,7 @@ bool AllocOpt::checkInst(Instruction *I, CheckInstStack &stack, bool &ignore_tag
return false;
if (!check_inst(inst))
return false;
uses.insert(inst);
if (cur.user_it == cur.user_end) {
if (stack.empty())
return true;
Expand Down Expand Up @@ -355,10 +360,11 @@ bool AllocOpt::runOnFunction(Function &F)
auto &entry = F.getEntryBlock();
auto first = &entry.front();
CheckInstStack check_stack;
std::set<Instruction*> uses;
for (auto it: allocs) {
bool ignore_tag = true;
auto orig = it.first;
if (optimize && checkInst(orig, check_stack, ignore_tag)) {
if (optimize && checkInst(orig, check_stack, uses, ignore_tag)) {
// The allocation does not escape or get used in a phi node so none of the derived
// SSA from it are live when we run the allocation again.
// It is now safe to promote the allocation to an entry block alloca.
Expand Down

0 comments on commit 16eeea4

Please sign in to comment.