Commit 222f5a70 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Cleanup: delete vestiges of old expr guarding system

parent a8ff0670
......@@ -1198,9 +1198,6 @@ CompiledFunction* doCompile(SourceInfo* source, ParamNames* param_names, const O
// Worklist guard_worklist;
guards.getBlocksWithGuards(deopt_full_blocks);
for (const auto& p : guards.exprGuards()) {
deopt_partial_blocks.insert(p.second->cfg_block);
}
computeBlockSetClosure(deopt_full_blocks, deopt_partial_blocks);
......@@ -1219,10 +1216,6 @@ CompiledFunction* doCompile(SourceInfo* source, ParamNames* param_names, const O
}
guards.assertGotPatched();
for (const auto& p : guards.exprGuards()) {
delete p.second;
}
delete types;
if (VERBOSITY("irgen") >= 1) {
......
......@@ -105,17 +105,6 @@ ScopeInfo* IRGenState::getScopeInfoForNode(AST* node) {
return source->scoping->getScopeInfoForNode(node);
}
GuardList::ExprTypeGuard::ExprTypeGuard(CFGBlock* cfg_block, llvm::BranchInst* branch, AST_expr* ast_node,
CompilerVariable* val, const SymbolTable& st)
: cfg_block(cfg_block), branch(branch), ast_node(ast_node) {
DupCache cache;
this->val = val->dup(cache);
for (const auto& p : st) {
this->st[p.first] = p.second->dup(cache);
}
}
GuardList::BlockEntryGuard::BlockEntryGuard(CFGBlock* cfg_block, llvm::BranchInst* branch,
const SymbolTable& symbol_table)
: cfg_block(cfg_block), branch(branch) {
......@@ -1277,102 +1266,6 @@ private:
}
}
// In-guarding:
GuardList::ExprTypeGuard* guard = in_guards.getNodeTypeGuard(node);
if (guard != NULL) {
if (VERBOSITY("irgen") >= 1) {
printf("merging guard after ");
PrintVisitor printer;
node->accept(&printer);
printf("; is_partial=%d\n", state == PARTIAL);
}
if (state == PARTIAL) {
guard->branch->setSuccessor(1, curblock);
symbol_table = SymbolTable(guard->st);
assert(guard->val);
state = RUNNING;
return guard->val;
} else {
assert(state == RUNNING);
compareKeyset(&symbol_table, &guard->st);
assert(symbol_table.size() == guard->st.size());
llvm::BasicBlock* ramp_block
= llvm::BasicBlock::Create(g.context, "deopt_ramp", irstate->getLLVMFunction());
llvm::BasicBlock* join_block
= llvm::BasicBlock::Create(g.context, "deopt_join", irstate->getLLVMFunction());
SymbolTable joined_st;
for (const auto& p : guard->st) {
// if (VERBOSITY("irgen") >= 1) printf("merging %s\n", p.first.c_str());
CompilerVariable* curval = symbol_table[p.first];
// I'm not sure this is necessary or even correct:
// ASSERT(curval->getVrefs() == p.second->getVrefs(), "%s %d %d", p.first.c_str(),
// curval->getVrefs(), p.second->getVrefs());
ConcreteCompilerType* merged_type = curval->getConcreteType();
emitter.getBuilder()->SetInsertPoint(ramp_block);
ConcreteCompilerVariable* converted1 = p.second->makeConverted(emitter, merged_type);
p.second->decvref(emitter); // for makeconverted
// guard->st[p.first] = converted;
// p.second->decvref(emitter); // for the replaced version
emitter.getBuilder()->SetInsertPoint(curblock);
ConcreteCompilerVariable* converted2 = curval->makeConverted(emitter, merged_type);
curval->decvref(emitter); // for makeconverted
// symbol_table[p.first] = converted;
// curval->decvref(emitter); // for the replaced version
if (converted1->getValue() == converted2->getValue()) {
joined_st[p.first] = new ConcreteCompilerVariable(merged_type, converted1->getValue(), true);
} else {
emitter.getBuilder()->SetInsertPoint(join_block);
llvm::PHINode* phi = emitter.getBuilder()->CreatePHI(merged_type->llvmType(), 2, p.first.str());
phi->addIncoming(converted1->getValue(), ramp_block);
phi->addIncoming(converted2->getValue(), curblock);
joined_st[p.first] = new ConcreteCompilerVariable(merged_type, phi, true);
}
// TODO free dead Variable objects!
}
symbol_table = joined_st;
emitter.getBuilder()->SetInsertPoint(curblock);
emitter.getBuilder()->CreateBr(join_block);
emitter.getBuilder()->SetInsertPoint(ramp_block);
emitter.getBuilder()->CreateBr(join_block);
guard->branch->setSuccessor(1, ramp_block);
{
ConcreteCompilerType* this_merged_type = rtn->getConcreteType();
emitter.getBuilder()->SetInsertPoint(ramp_block);
ConcreteCompilerVariable* converted_guard_rtn
= guard->val->makeConverted(emitter, this_merged_type);
guard->val->decvref(emitter);
emitter.getBuilder()->SetInsertPoint(curblock);
ConcreteCompilerVariable* converted_rtn = rtn->makeConverted(emitter, this_merged_type);
rtn->decvref(emitter);
emitter.getBuilder()->SetInsertPoint(join_block);
llvm::PHINode* this_phi = emitter.getBuilder()->CreatePHI(this_merged_type->llvmType(), 2);
this_phi->addIncoming(converted_rtn->getValue(), curblock);
this_phi->addIncoming(converted_guard_rtn->getValue(), ramp_block);
rtn = new ConcreteCompilerVariable(this_merged_type, this_phi, true);
// TODO free dead Variable objects!
}
curblock = join_block;
emitter.getBuilder()->SetInsertPoint(curblock);
}
}
assert(rtn || state == PARTIAL);
return rtn;
......
......@@ -100,17 +100,6 @@ public:
class GuardList {
public:
struct ExprTypeGuard {
CFGBlock* cfg_block;
llvm::BranchInst* branch;
AST_expr* ast_node;
CompilerVariable* val;
SymbolTable st;
ExprTypeGuard(CFGBlock* cfg_block, llvm::BranchInst* branch, AST_expr* ast_node, CompilerVariable* val,
const SymbolTable& st);
};
struct BlockEntryGuard {
CFGBlock* cfg_block;
llvm::BranchInst* branch;
......@@ -120,18 +109,9 @@ public:
};
private:
std::unordered_map<AST_expr*, ExprTypeGuard*> expr_type_guards;
std::unordered_map<CFGBlock*, std::vector<BlockEntryGuard*>> block_begin_guards;
// typedef std::unordered_map<AST_expr*, ExprTypeGuard*>::iterator expr_type_guard_iterator;
// typedef std::unordered_map<AST_expr*, ExprTypeGuard*>::const_iterator expr_type_guard_const_iterator;
typedef decltype(expr_type_guards)::iterator expr_type_guard_iterator;
typedef decltype(expr_type_guards)::const_iterator expr_type_guard_const_iterator;
public:
llvm::iterator_range<expr_type_guard_iterator> exprGuards() {
return llvm::iterator_range<expr_type_guard_iterator>(expr_type_guards.begin(), expr_type_guards.end());
}
void getBlocksWithGuards(std::unordered_set<CFGBlock*>& add_to) {
for (const auto& p : block_begin_guards) {
add_to.insert(p.first);
......@@ -145,29 +125,10 @@ public:
assert(g->branch->getSuccessor(0) != g->branch->getSuccessor(1));
}
}
for (const auto& p : expr_type_guards) {
assert(p.second->branch->getSuccessor(0) != p.second->branch->getSuccessor(1));
}
#endif
}
ExprTypeGuard* getNodeTypeGuard(AST_expr* node) const {
expr_type_guard_const_iterator it = expr_type_guards.find(node);
if (it == expr_type_guards.end())
return NULL;
return it->second;
}
bool isEmpty() const { return expr_type_guards.size() == 0 && block_begin_guards.size() == 0; }
void addExprTypeGuard(CFGBlock* cfg_block, llvm::BranchInst* branch, AST_expr* ast_node, CompilerVariable* val,
const SymbolTable& st) {
abort();
ExprTypeGuard*& g = expr_type_guards[ast_node];
assert(g == NULL);
g = new ExprTypeGuard(cfg_block, branch, ast_node, val, st);
}
bool isEmpty() const { return block_begin_guards.size() == 0; }
void registerGuardForBlockEntry(CFGBlock* cfg_block, llvm::BranchInst* branch, const SymbolTable& st) {
// printf("Adding guard for block %p, in %p\n", cfg_block, this);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment