Commit ac004e74 authored by Kevin Modzelewski's avatar Kevin Modzelewski

rangify the codebase

parent 4fa5406f
...@@ -66,18 +66,18 @@ typename BBAnalyzer<T>::AllMap computeFixedPoint(CFG* cfg, const BBAnalyzer<T> & ...@@ -66,18 +66,18 @@ typename BBAnalyzer<T>::AllMap computeFixedPoint(CFG* cfg, const BBAnalyzer<T> &
} }
Map &next = states[next_block]; Map &next = states[next_block];
for (typename Map::iterator it = ending.begin(), end = ending.end(); it != end; ++it) { for (auto p : ending) {
if (next.count(it->first) == 0) { if (next.count(p.first) == 0) {
changed = true; changed = true;
if (initial) { if (initial) {
next[it->first] = it->second; next[p.first] = p.second;
} else { } else {
next[it->first] = analyzer.mergeBlank(it->second); next[p.first] = analyzer.mergeBlank(p.second);
} }
} else { } else {
T &next_elt = next[it->first]; T &next_elt = next[p.first];
T new_elt = analyzer.merge(it->second, next_elt); T new_elt = analyzer.merge(p.second, next_elt);
if (next_elt != new_elt) { if (next_elt != new_elt) {
next_elt = new_elt; next_elt = new_elt;
changed = true; changed = true;
...@@ -85,13 +85,13 @@ typename BBAnalyzer<T>::AllMap computeFixedPoint(CFG* cfg, const BBAnalyzer<T> & ...@@ -85,13 +85,13 @@ typename BBAnalyzer<T>::AllMap computeFixedPoint(CFG* cfg, const BBAnalyzer<T> &
} }
} }
for (typename Map::iterator it = next.begin(), end = ending.end(); it != end; ++it) { for (auto p : ending) {
if (ending.count(it->first)) if (ending.count(p.first))
continue; continue;
T next_elt = analyzer.mergeBlank(it->second); T next_elt = analyzer.mergeBlank(p.second);
if (next_elt != it->second) { if (next_elt != p.second) {
next[it->first] = next_elt; next[p.first] = next_elt;
changed = true; changed = true;
} }
} }
......
...@@ -240,18 +240,17 @@ void DefinednessBBAnalyzer::processBB(Map &starting, CFGBlock *block) const { ...@@ -240,18 +240,17 @@ void DefinednessBBAnalyzer::processBB(Map &starting, CFGBlock *block) const {
DefinednessAnalysis::DefinednessAnalysis(AST_arguments *args, CFG* cfg, ScopeInfo *scope_info) : scope_info(scope_info) { DefinednessAnalysis::DefinednessAnalysis(AST_arguments *args, CFG* cfg, ScopeInfo *scope_info) : scope_info(scope_info) {
results = computeFixedPoint(cfg, DefinednessBBAnalyzer(args), false); results = computeFixedPoint(cfg, DefinednessBBAnalyzer(args), false);
for (std::unordered_map<CFGBlock*, std::unordered_map<std::string, DefinitionLevel> >::iterator for (auto p : results) {
it = results.begin(), end = results.end(); it != end; ++it) {
RequiredSet required; RequiredSet required;
for (std::unordered_map<std::string, DefinitionLevel>::iterator it2 = it->second.begin(), end2 = it->second.end(); for (std::unordered_map<std::string, DefinitionLevel>::iterator it2 = p.second.begin(), end2 = p.second.end();
it2 != end2; ++it2) { it2 != end2; ++it2) {
if (scope_info->refersToGlobal(it2->first)) if (scope_info->refersToGlobal(it2->first))
continue; continue;
//printf("%d %s %d\n", it->first->idx, it2->first.c_str(), it2->second); //printf("%d %s %d\n", p.first->idx, it2->first.c_str(), it2->second);
required.insert(it2->first); required.insert(it2->first);
} }
defined.insert(make_pair(it->first, required)); defined.insert(make_pair(p.first, required));
} }
} }
...@@ -278,9 +277,9 @@ PhiAnalysis::PhiAnalysis(AST_arguments* args, CFG* cfg, LivenessAnalysis *livene ...@@ -278,9 +277,9 @@ PhiAnalysis::PhiAnalysis(AST_arguments* args, CFG* cfg, LivenessAnalysis *livene
const RequiredSet& defined = definedness.getDefinedNamesAt(block); const RequiredSet& defined = definedness.getDefinedNamesAt(block);
if (defined.size()) if (defined.size())
assert(block->predecessors.size()); assert(block->predecessors.size());
for (RequiredSet::const_iterator it = defined.begin(), end = defined.end(); it != end; ++it) { for (auto s : defined) {
if (liveness->isLiveAtEnd(*it, block->predecessors[0])) { if (liveness->isLiveAtEnd(s, block->predecessors[0])) {
required.insert(*it); required.insert(s);
} }
} }
......
...@@ -256,9 +256,8 @@ static std::vector<ScopingAnalysis::ScopeNameUsage*> sortNameUsages(ScopingAnaly ...@@ -256,9 +256,8 @@ static std::vector<ScopingAnalysis::ScopeNameUsage*> sortNameUsages(ScopingAnaly
std::vector<ScopingAnalysis::ScopeNameUsage*> rtn; std::vector<ScopingAnalysis::ScopeNameUsage*> rtn;
std::unordered_set<ScopingAnalysis::ScopeNameUsage*> added; std::unordered_set<ScopingAnalysis::ScopeNameUsage*> added;
for (ScopingAnalysis::NameUsageMap::iterator it = usages->begin(), end = usages->end(); for (auto p : *usages) {
it != end; ++it) { ScopingAnalysis::ScopeNameUsage *usage = p.second;
ScopingAnalysis::ScopeNameUsage *usage = it->second;
std::vector<ScopingAnalysis::ScopeNameUsage*> traversed; std::vector<ScopingAnalysis::ScopeNameUsage*> traversed;
...@@ -282,9 +281,8 @@ void ScopingAnalysis::processNameUsages(ScopingAnalysis::NameUsageMap* usages) { ...@@ -282,9 +281,8 @@ void ScopingAnalysis::processNameUsages(ScopingAnalysis::NameUsageMap* usages) {
typedef ScopeNameUsage::StrSet StrSet; typedef ScopeNameUsage::StrSet StrSet;
// Resolve name lookups: // Resolve name lookups:
for (ScopingAnalysis::NameUsageMap::iterator it = usages->begin(), end = usages->end(); for (auto p : *usages) {
it != end; ++it) { ScopeNameUsage *usage = p.second;
ScopeNameUsage *usage = it->second;
for (StrSet::iterator it2 = usage->read.begin(), end2 = usage->read.end(); for (StrSet::iterator it2 = usage->read.begin(), end2 = usage->read.end();
it2 != end2; ++it2) { it2 != end2; ++it2) {
if (usage->forced_globals.count(*it2)) if (usage->forced_globals.count(*it2))
......
...@@ -566,9 +566,9 @@ class PropagatingTypeAnalysis : public TypeAnalysis { ...@@ -566,9 +566,9 @@ class PropagatingTypeAnalysis : public TypeAnalysis {
if (VERBOSITY("types") >= 2) { if (VERBOSITY("types") >= 2) {
printf("before:\n"); printf("before:\n");
TypeMap &starting = starting_types[block_id]; TypeMap &starting = starting_types[block_id];
for (TypeMap::iterator it = starting.begin(), end = starting.end(); it != end; ++it) { for (auto p : starting) {
ASSERT(it->second, "%s", it->first.c_str()); ASSERT(p.second, "%s", p.first.c_str());
printf("%s: %s\n", it->first.c_str(), it->second->debugName().c_str()); printf("%s: %s\n", p.first.c_str(), p.second->debugName().c_str());
} }
} }
...@@ -577,14 +577,14 @@ class PropagatingTypeAnalysis : public TypeAnalysis { ...@@ -577,14 +577,14 @@ class PropagatingTypeAnalysis : public TypeAnalysis {
if (VERBOSITY("types") >= 2) { if (VERBOSITY("types") >= 2) {
printf("before (after):\n"); printf("before (after):\n");
TypeMap &starting = starting_types[block_id]; TypeMap &starting = starting_types[block_id];
for (TypeMap::iterator it = starting.begin(), end = starting.end(); it != end; ++it) { for (auto p : starting) {
ASSERT(it->second, "%s", it->first.c_str()); ASSERT(p.second, "%s", p.first.c_str());
printf("%s: %s\n", it->first.c_str(), it->second->debugName().c_str()); printf("%s: %s\n", p.first.c_str(), p.second->debugName().c_str());
} }
printf("after:\n"); printf("after:\n");
for (TypeMap::iterator it = ending.begin(), end = ending.end(); it != end; ++it) { for (auto p : ending) {
ASSERT(it->second, "%s", it->first.c_str()); ASSERT(p.second, "%s", p.first.c_str());
printf("%s: %s\n", it->first.c_str(), it->second->debugName().c_str()); printf("%s: %s\n", p.first.c_str(), p.second->debugName().c_str());
} }
} }
...@@ -604,9 +604,9 @@ class PropagatingTypeAnalysis : public TypeAnalysis { ...@@ -604,9 +604,9 @@ class PropagatingTypeAnalysis : public TypeAnalysis {
CFGBlock *b = cfg->blocks[i]; CFGBlock *b = cfg->blocks[i];
TypeMap &starting = starting_types[i]; TypeMap &starting = starting_types[i];
for (TypeMap::iterator it = starting.begin(), end = starting.end(); it != end; ++it) { for (auto p : starting) {
ASSERT(it->second, "%s", it->first.c_str()); ASSERT(p.second, "%s", p.first.c_str());
printf("%s: %s\n", it->first.c_str(), it->second->debugName().c_str()); printf("%s: %s\n", p.first.c_str(), p.second->debugName().c_str());
} }
} }
} }
......
...@@ -42,9 +42,8 @@ void ICInvalidator::addDependent(ICSlotInfo* entry_info) { ...@@ -42,9 +42,8 @@ void ICInvalidator::addDependent(ICSlotInfo* entry_info) {
void ICInvalidator::invalidateAll() { void ICInvalidator::invalidateAll() {
cur_version++; cur_version++;
for (std::unordered_set<ICSlotInfo*>::iterator it = dependents.begin(), end = dependents.end(); for (ICSlotInfo* slot : dependents) {
it != end; ++it) { slot->clear();
(*it)->clear();
} }
dependents.clear(); dependents.clear();
} }
......
...@@ -47,17 +47,16 @@ void FunctionAddressRegistry::dumpPerfMap() { ...@@ -47,17 +47,16 @@ void FunctionAddressRegistry::dumpPerfMap() {
char buf[80]; char buf[80];
snprintf(buf, 80, "/tmp/perf-%d.map", getpid()); snprintf(buf, 80, "/tmp/perf-%d.map", getpid());
FILE *f = fopen(buf, "w"); FILE *f = fopen(buf, "w");
for (FuncMap::iterator it = functions.begin(), end = functions.end(); for (auto p : functions) {
it != end; ++it) { const FuncInfo& info = p.second;
const FuncInfo& info = it->second; fprintf(f, "%lx %x %s\n", (uintptr_t)p.first, info.length, info.name.c_str());
fprintf(f, "%lx %x %s\n", (uintptr_t)it->first, info.length, info.name.c_str());
if (info.length > 0) { if (info.length > 0) {
fprintf(index_f, "%lx %s\n", (uintptr_t)it->first, info.name.c_str()); fprintf(index_f, "%lx %s\n", (uintptr_t)p.first, info.name.c_str());
FILE *data_f = fopen((out_path + "/" + info.name).c_str(), "wb"); FILE *data_f = fopen((out_path + "/" + info.name).c_str(), "wb");
int written = fwrite((void*)it->first, 1, info.length, data_f); int written = fwrite((void*)p.first, 1, info.length, data_f);
assert(written == info.length); assert(written == info.length);
fclose(data_f); fclose(data_f);
} }
......
This diff is collapsed.
...@@ -78,16 +78,17 @@ GuardList::ExprTypeGuard::ExprTypeGuard(CFGBlock *cfg_block, llvm::BranchInst* b ...@@ -78,16 +78,17 @@ GuardList::ExprTypeGuard::ExprTypeGuard(CFGBlock *cfg_block, llvm::BranchInst* b
cfg_block(cfg_block), branch(branch), ast_node(ast_node) { cfg_block(cfg_block), branch(branch), ast_node(ast_node) {
DupCache cache; DupCache cache;
this->val = val->dup(cache); this->val = val->dup(cache);
for (SymbolTable::const_iterator it = st.begin(), end = st.end(); it != end; ++it) {
this->st[it->first] = it->second->dup(cache); for (auto p : st) {
this->st[p.first] = p.second->dup(cache);
} }
} }
GuardList::BlockEntryGuard::BlockEntryGuard(CFGBlock *cfg_block, llvm::BranchInst* branch, const SymbolTable &symbol_table) : GuardList::BlockEntryGuard::BlockEntryGuard(CFGBlock *cfg_block, llvm::BranchInst* branch, const SymbolTable &symbol_table) :
cfg_block(cfg_block), branch(branch) { cfg_block(cfg_block), branch(branch) {
DupCache cache; DupCache cache;
for (SymbolTable::const_iterator it = symbol_table.begin(), end = symbol_table.end(); it != end; ++it) { for (auto p : symbol_table) {
this->symbol_table[it->first] = it->second->dup(cache); this->symbol_table[p.first] = p.second->dup(cache);
} }
} }
...@@ -925,34 +926,34 @@ class IRGeneratorImpl : public IRGenerator { ...@@ -925,34 +926,34 @@ class IRGeneratorImpl : public IRGenerator {
llvm::BasicBlock *ramp_block = llvm::BasicBlock::Create(g.context, "deopt_ramp", irstate->getLLVMFunction()); 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()); llvm::BasicBlock *join_block = llvm::BasicBlock::Create(g.context, "deopt_join", irstate->getLLVMFunction());
SymbolTable joined_st; SymbolTable joined_st;
for (SymbolTable::iterator it = guard->st.begin(), end = guard->st.end(); it != end; ++it) { for (auto p : guard->st) {
//if (VERBOSITY("irgen") >= 1) printf("merging %s\n", it->first.c_str()); //if (VERBOSITY("irgen") >= 1) printf("merging %s\n", p.first.c_str());
CompilerVariable *curval = symbol_table[it->first]; CompilerVariable *curval = symbol_table[p.first];
// I'm not sure this is necessary or even correct: // I'm not sure this is necessary or even correct:
//ASSERT(curval->getVrefs() == it->second->getVrefs(), "%s %d %d", it->first.c_str(), curval->getVrefs(), it->second->getVrefs()); //ASSERT(curval->getVrefs() == p.second->getVrefs(), "%s %d %d", p.first.c_str(), curval->getVrefs(), p.second->getVrefs());
ConcreteCompilerType *merged_type = curval->getConcreteType(); ConcreteCompilerType *merged_type = curval->getConcreteType();
emitter.getBuilder()->SetInsertPoint(ramp_block); emitter.getBuilder()->SetInsertPoint(ramp_block);
ConcreteCompilerVariable* converted1 = it->second->makeConverted(emitter, merged_type); ConcreteCompilerVariable* converted1 = p.second->makeConverted(emitter, merged_type);
it->second->decvref(emitter); // for makeconverted p.second->decvref(emitter); // for makeconverted
//guard->st[it->first] = converted; //guard->st[p.first] = converted;
//it->second->decvref(emitter); // for the replaced version //p.second->decvref(emitter); // for the replaced version
emitter.getBuilder()->SetInsertPoint(curblock); emitter.getBuilder()->SetInsertPoint(curblock);
ConcreteCompilerVariable* converted2 = curval->makeConverted(emitter, merged_type); ConcreteCompilerVariable* converted2 = curval->makeConverted(emitter, merged_type);
curval->decvref(emitter); // for makeconverted curval->decvref(emitter); // for makeconverted
//symbol_table[it->first] = converted; //symbol_table[p.first] = converted;
//curval->decvref(emitter); // for the replaced version //curval->decvref(emitter); // for the replaced version
if (converted1->getValue() == converted2->getValue()) { if (converted1->getValue() == converted2->getValue()) {
joined_st[it->first] = new ConcreteCompilerVariable(merged_type, converted1->getValue(), true); joined_st[p.first] = new ConcreteCompilerVariable(merged_type, converted1->getValue(), true);
} else { } else {
emitter.getBuilder()->SetInsertPoint(join_block); emitter.getBuilder()->SetInsertPoint(join_block);
llvm::PHINode* phi = emitter.getBuilder()->CreatePHI(merged_type->llvmType(), 2, it->first); llvm::PHINode* phi = emitter.getBuilder()->CreatePHI(merged_type->llvmType(), 2, p.first);
phi->addIncoming(converted1->getValue(), ramp_block); phi->addIncoming(converted1->getValue(), ramp_block);
phi->addIncoming(converted2->getValue(), curblock); phi->addIncoming(converted2->getValue(), curblock);
joined_st[it->first] = new ConcreteCompilerVariable(merged_type, phi, true); joined_st[p.first] = new ConcreteCompilerVariable(merged_type, phi, true);
} }
// TODO free dead Variable objects! // TODO free dead Variable objects!
...@@ -1374,17 +1375,18 @@ class IRGeneratorImpl : public IRGenerator { ...@@ -1374,17 +1375,18 @@ class IRGeneratorImpl : public IRGenerator {
} }
} }
int i = 0; int arg_num = -1;
for (SortedSymbolTable::iterator it = sorted_symbol_table.begin(), end = sorted_symbol_table.end(); it != end; ++it, ++i) { for (auto p : sorted_symbol_table) {
arg_num++;
// I don't think this can fail, but if it can we should filter out dead symbols before // I don't think this can fail, but if it can we should filter out dead symbols before
// passing them on: // passing them on:
ASSERT(startswith(it->first, "!is_defined") || irstate->getSourceInfo()->liveness->isLiveAtEnd(it->first, myblock), "%d %s", myblock->idx, it->first.c_str()); ASSERT(startswith(p.first, "!is_defined") || irstate->getSourceInfo()->liveness->isLiveAtEnd(p.first, myblock), "%d %s", myblock->idx, p.first.c_str());
// This line can never get hit right now since we unnecessarily force every variable to be concrete // This line can never get hit right now since we unnecessarily force every variable to be concrete
// for a loop, since we generate all potential phis: // for a loop, since we generate all potential phis:
ASSERT(it->second->getType() == it->second->getConcreteType(), "trying to pass through %s\n", it->second->getType()->debugName().c_str()); ASSERT(p.second->getType() == p.second->getConcreteType(), "trying to pass through %s\n", p.second->getType()->debugName().c_str());
ConcreteCompilerVariable* var = it->second->makeConverted(emitter, it->second->getConcreteType()); ConcreteCompilerVariable* var = p.second->makeConverted(emitter, p.second->getConcreteType());
converted_args.push_back(var); converted_args.push_back(var);
assert(var->getType() != BOXED_INT && "should probably unbox it, but why is it boxed in the first place?"); assert(var->getType() != BOXED_INT && "should probably unbox it, but why is it boxed in the first place?");
...@@ -1392,16 +1394,16 @@ class IRGeneratorImpl : public IRGenerator { ...@@ -1392,16 +1394,16 @@ class IRGeneratorImpl : public IRGenerator {
// This line can never get hit right now for the same reason that the variables must already be concrete, // This line can never get hit right now for the same reason that the variables must already be concrete,
// because we're over-generating phis. // because we're over-generating phis.
ASSERT(var->isGrabbed(), "%s", it->first.c_str()); ASSERT(var->isGrabbed(), "%s", p.first.c_str());
//var->ensureGrabbed(emitter); //var->ensureGrabbed(emitter);
llvm::Value* val = var->getValue(); llvm::Value* val = var->getValue();
if (i < 3) { if (arg_num < 3) {
llvm_args.push_back(val); llvm_args.push_back(val);
llvm_arg_types.push_back(val->getType()); llvm_arg_types.push_back(val->getType());
} else { } else {
llvm::Value* ptr = emitter.getBuilder()->CreateConstGEP1_32(arg_array, i-3); llvm::Value* ptr = emitter.getBuilder()->CreateConstGEP1_32(arg_array, arg_num-3);
if (var->getType() == INT) { if (var->getType() == INT) {
val = emitter.getBuilder()->CreateIntToPtr(val, g.llvm_value_type_ptr); val = emitter.getBuilder()->CreateIntToPtr(val, g.llvm_value_type_ptr);
...@@ -1415,7 +1417,7 @@ class IRGeneratorImpl : public IRGenerator { ...@@ -1415,7 +1417,7 @@ class IRGeneratorImpl : public IRGenerator {
emitter.getBuilder()->CreateStore(val, ptr); emitter.getBuilder()->CreateStore(val, ptr);
} }
ConcreteCompilerType* &t = exit->entry->args[it->first]; ConcreteCompilerType* &t = exit->entry->args[p.first];
if (t == NULL) if (t == NULL)
t = var->getType(); t = var->getType();
else else
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#include <map> #include <map>
#include "llvm/ADT/iterator_range.h"
#include "core/types.h" #include "core/types.h"
namespace llvm { namespace llvm {
...@@ -114,15 +116,14 @@ class GuardList { ...@@ -114,15 +116,14 @@ class GuardList {
private: private:
std::unordered_map<AST_expr*, ExprTypeGuard*> expr_type_guards; std::unordered_map<AST_expr*, ExprTypeGuard*> expr_type_guards;
std::unordered_map<CFGBlock*, std::vector<BlockEntryGuard*> > block_begin_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: public:
typedef std::unordered_map<AST_expr*, ExprTypeGuard*>::iterator expr_type_guard_iterator; llvm::iterator_range<expr_type_guard_iterator> exprGuards() {
typedef std::unordered_map<AST_expr*, ExprTypeGuard*>::const_iterator expr_type_guard_const_iterator; return llvm::iterator_range<expr_type_guard_iterator>(expr_type_guards.begin(), expr_type_guards.end());
expr_type_guard_iterator after_begin() {
return expr_type_guards.begin();
}
expr_type_guard_iterator after_end() {
return expr_type_guards.end();
} }
void getBlocksWithGuards(std::unordered_set<CFGBlock*> &add_to) { void getBlocksWithGuards(std::unordered_set<CFGBlock*> &add_to) {
......
...@@ -256,16 +256,18 @@ Box* interpretFunction(llvm::Function *f, int nargs, Box* arg1, Box* arg2, Box* ...@@ -256,16 +256,18 @@ Box* interpretFunction(llvm::Function *f, int nargs, Box* arg1, Box* arg2, Box*
interpreter_roots[frame_ptr] = &symbols; interpreter_roots[frame_ptr] = &symbols;
UnregisterHelper helper(frame_ptr); UnregisterHelper helper(frame_ptr);
int i = 0; int arg_num = -1;
for (llvm::Function::arg_iterator AI = f->arg_begin(), end = f->arg_end(); AI != end; AI++, i++) { for (llvm::Argument& arg : f->args()) {
if (i == 0) symbols.insert(std::make_pair(static_cast<llvm::Value*>(&(*AI)), Val(arg1))); arg_num++;
else if (i == 1) symbols.insert(std::make_pair(static_cast<llvm::Value*>(&(*AI)), Val(arg2)));
else if (i == 2) symbols.insert(std::make_pair(static_cast<llvm::Value*>(&(*AI)), Val(arg3))); if (arg_num == 0) symbols.insert(std::make_pair(static_cast<llvm::Value*>(&arg), Val(arg1)));
else if (arg_num == 1) symbols.insert(std::make_pair(static_cast<llvm::Value*>(&arg), Val(arg2)));
else if (arg_num == 2) symbols.insert(std::make_pair(static_cast<llvm::Value*>(&arg), Val(arg3)));
else { else {
assert(i == 3); assert(arg_num == 3);
assert(f->getArgumentList().size() == 4); assert(f->getArgumentList().size() == 4);
assert(f->getArgumentList().back().getType() == g.llvm_value_type_ptr->getPointerTo()); assert(f->getArgumentList().back().getType() == g.llvm_value_type_ptr->getPointerTo());
symbols.insert(std::make_pair(static_cast<llvm::Value*>(&(*AI)), Val((int64_t)args))); symbols.insert(std::make_pair(static_cast<llvm::Value*>(&arg), Val((int64_t)args)));
//printf("loading %%4 with %p\n", (void*)args); //printf("loading %%4 with %p\n", (void*)args);
break; break;
} }
...@@ -276,16 +278,18 @@ Box* interpretFunction(llvm::Function *f, int nargs, Box* arg1, Box* arg2, Box* ...@@ -276,16 +278,18 @@ Box* interpretFunction(llvm::Function *f, int nargs, Box* arg1, Box* arg2, Box*
while (true) { while (true) {
for (llvm::BasicBlock::iterator it = curblock->begin(), end = curblock->end(); it != end; ++it) { for (llvm::Instruction &_inst : *curblock) {
llvm::Instruction *inst = &_inst;
if (VERBOSITY("interpreter") >= 2) { if (VERBOSITY("interpreter") >= 2) {
printf("executing in %s: ", f->getName().data()); printf("executing in %s: ", f->getName().data());
fflush(stdout); fflush(stdout);
it->dump(); inst->dump();
//f->dump(); //f->dump();
} }
#define SET(v) set(symbols, it, (v)) #define SET(v) set(symbols, inst, (v))
if (llvm::LoadInst *li = llvm::dyn_cast<llvm::LoadInst>(it)) { if (llvm::LoadInst *li = llvm::dyn_cast<llvm::LoadInst>(inst)) {
llvm::Value *ptr = li->getOperand(0); llvm::Value *ptr = li->getOperand(0);
Val v = fetch(ptr, dl, symbols); Val v = fetch(ptr, dl, symbols);
//printf("loading from %p\n", v.o); //printf("loading from %p\n", v.o);
...@@ -302,7 +306,7 @@ Box* interpretFunction(llvm::Function *f, int nargs, Box* arg1, Box* arg2, Box* ...@@ -302,7 +306,7 @@ Box* interpretFunction(llvm::Function *f, int nargs, Box* arg1, Box* arg2, Box*
li->dump(); li->dump();
RELEASE_ASSERT(0, ""); RELEASE_ASSERT(0, "");
} }
} else if (llvm::StoreInst *si = llvm::dyn_cast<llvm::StoreInst>(it)) { } else if (llvm::StoreInst *si = llvm::dyn_cast<llvm::StoreInst>(inst)) {
llvm::Value *val = si->getOperand(0); llvm::Value *val = si->getOperand(0);
llvm::Value *ptr = si->getOperand(1); llvm::Value *ptr = si->getOperand(1);
Val v = fetch(val, dl, symbols); Val v = fetch(val, dl, symbols);
...@@ -320,7 +324,7 @@ Box* interpretFunction(llvm::Function *f, int nargs, Box* arg1, Box* arg2, Box* ...@@ -320,7 +324,7 @@ Box* interpretFunction(llvm::Function *f, int nargs, Box* arg1, Box* arg2, Box*
si->dump(); si->dump();
RELEASE_ASSERT(0, ""); RELEASE_ASSERT(0, "");
} }
} else if (llvm::CmpInst *ci = llvm::dyn_cast<llvm::CmpInst>(it)) { } else if (llvm::CmpInst *ci = llvm::dyn_cast<llvm::CmpInst>(inst)) {
assert(ci->getType() == g.i1); assert(ci->getType() == g.i1);
Val a0 = fetch(ci->getOperand(0), dl, symbols); Val a0 = fetch(ci->getOperand(0), dl, symbols);
...@@ -368,7 +372,7 @@ Box* interpretFunction(llvm::Function *f, int nargs, Box* arg1, Box* arg2, Box* ...@@ -368,7 +372,7 @@ Box* interpretFunction(llvm::Function *f, int nargs, Box* arg1, Box* arg2, Box*
RELEASE_ASSERT(0, ""); RELEASE_ASSERT(0, "");
} }
continue; continue;
} else if (llvm::BinaryOperator *bo = llvm::dyn_cast<llvm::BinaryOperator>(it)) { } else if (llvm::BinaryOperator *bo = llvm::dyn_cast<llvm::BinaryOperator>(inst)) {
if (bo->getOperand(0)->getType() == g.i64 || bo->getOperand(0)->getType() == g.i1) { if (bo->getOperand(0)->getType() == g.i64 || bo->getOperand(0)->getType() == g.i1) {
//assert(bo->getOperand(0)->getType() == g.i64); //assert(bo->getOperand(0)->getType() == g.i64);
//assert(bo->getOperand(1)->getType() == g.i64); //assert(bo->getOperand(1)->getType() == g.i64);
...@@ -432,7 +436,7 @@ Box* interpretFunction(llvm::Function *f, int nargs, Box* arg1, Box* arg2, Box* ...@@ -432,7 +436,7 @@ Box* interpretFunction(llvm::Function *f, int nargs, Box* arg1, Box* arg2, Box*
bo->dump(); bo->dump();
RELEASE_ASSERT(0, ""); RELEASE_ASSERT(0, "");
} }
} else if (llvm::GetElementPtrInst *gep = llvm::dyn_cast<llvm::GetElementPtrInst>(it)) { } else if (llvm::GetElementPtrInst *gep = llvm::dyn_cast<llvm::GetElementPtrInst>(inst)) {
int64_t base = fetch(gep->getPointerOperand(), dl, symbols).n; int64_t base = fetch(gep->getPointerOperand(), dl, symbols).n;
llvm::User::value_op_iterator begin = gep->value_op_begin(); llvm::User::value_op_iterator begin = gep->value_op_begin();
...@@ -444,26 +448,26 @@ Box* interpretFunction(llvm::Function *f, int nargs, Box* arg1, Box* arg2, Box* ...@@ -444,26 +448,26 @@ Box* interpretFunction(llvm::Function *f, int nargs, Box* arg1, Box* arg2, Box*
//printf("offset for inst: %ld (base is %lx)\n", offset, base); //printf("offset for inst: %ld (base is %lx)\n", offset, base);
SET(base + offset); SET(base + offset);
continue; continue;
} else if (llvm::AllocaInst *al = llvm::dyn_cast<llvm::AllocaInst>(it)) { } else if (llvm::AllocaInst *al = llvm::dyn_cast<llvm::AllocaInst>(inst)) {
int size = fetch(al->getArraySize(), dl, symbols).n * width(al->getAllocatedType(), dl); int size = fetch(al->getArraySize(), dl, symbols).n * width(al->getAllocatedType(), dl);
void* ptr = alloca(size); void* ptr = alloca(size);
//void* ptr = malloc(size); //void* ptr = malloc(size);
//printf("alloca()'d at %p\n", ptr); //printf("alloca()'d at %p\n", ptr);
SET((int64_t)ptr); SET((int64_t)ptr);
continue; continue;
} else if (llvm::SIToFPInst *si = llvm::dyn_cast<llvm::SIToFPInst>(it)) { } else if (llvm::SIToFPInst *si = llvm::dyn_cast<llvm::SIToFPInst>(inst)) {
assert(width(si->getOperand(0), dl) == 8); assert(width(si->getOperand(0), dl) == 8);
SET((double)fetch(si->getOperand(0), dl, symbols).n); SET((double)fetch(si->getOperand(0), dl, symbols).n);
continue; continue;
} else if (llvm::BitCastInst *bc = llvm::dyn_cast<llvm::BitCastInst>(it)) { } else if (llvm::BitCastInst *bc = llvm::dyn_cast<llvm::BitCastInst>(inst)) {
assert(width(bc->getOperand(0), dl) == 8); assert(width(bc->getOperand(0), dl) == 8);
SET(fetch(bc->getOperand(0), dl, symbols)); SET(fetch(bc->getOperand(0), dl, symbols));
continue; continue;
} else if (llvm::IntToPtrInst *bc = llvm::dyn_cast<llvm::IntToPtrInst>(it)) { } else if (llvm::IntToPtrInst *bc = llvm::dyn_cast<llvm::IntToPtrInst>(inst)) {
assert(width(bc->getOperand(0), dl) == 8); assert(width(bc->getOperand(0), dl) == 8);
SET(fetch(bc->getOperand(0), dl, symbols)); SET(fetch(bc->getOperand(0), dl, symbols));
continue; continue;
} else if (llvm::CallInst *ci = llvm::dyn_cast<llvm::CallInst>(it)) { } else if (llvm::CallInst *ci = llvm::dyn_cast<llvm::CallInst>(inst)) {
void* f; void* f;
int arg_start; int arg_start;
if (ci->getCalledFunction() && (ci->getCalledFunction()->getName() == "llvm.experimental.patchpoint.void" || ci->getCalledFunction()->getName() == "llvm.experimental.patchpoint.i64")) { if (ci->getCalledFunction() && (ci->getCalledFunction()->getName() == "llvm.experimental.patchpoint.void" || ci->getCalledFunction()->getName() == "llvm.experimental.patchpoint.i64")) {
...@@ -568,7 +572,7 @@ Box* interpretFunction(llvm::Function *f, int nargs, Box* arg1, Box* arg2, Box* ...@@ -568,7 +572,7 @@ Box* interpretFunction(llvm::Function *f, int nargs, Box* arg1, Box* arg2, Box*
r = reinterpret_cast<int64_t (*)(int64_t, int64_t, int64_t, int64_t, int64_t, int64_t, int64_t, int64_t)>(f)(args[0].n, args[1].n, args[2].n, args[3].n, args[4].n, args[5].n, args[6].n, args[7].n); r = reinterpret_cast<int64_t (*)(int64_t, int64_t, int64_t, int64_t, int64_t, int64_t, int64_t, int64_t)>(f)(args[0].n, args[1].n, args[2].n, args[3].n, args[4].n, args[5].n, args[6].n, args[7].n);
break; break;
default: default:
it->dump(); inst->dump();
RELEASE_ASSERT(0, "%d", mask); RELEASE_ASSERT(0, "%d", mask);
break; break;
} }
...@@ -580,7 +584,7 @@ Box* interpretFunction(llvm::Function *f, int nargs, Box* arg1, Box* arg2, Box* ...@@ -580,7 +584,7 @@ Box* interpretFunction(llvm::Function *f, int nargs, Box* arg1, Box* arg2, Box*
_t.restart("to interpret", 10000000); _t.restart("to interpret", 10000000);
#endif #endif
continue; continue;
} else if (llvm::SelectInst *si = llvm::dyn_cast<llvm::SelectInst>(it)) { } else if (llvm::SelectInst *si = llvm::dyn_cast<llvm::SelectInst>(inst)) {
Val test = fetch(si->getCondition(), dl, symbols); Val test = fetch(si->getCondition(), dl, symbols);
Val vt = fetch(si->getTrueValue(), dl, symbols); Val vt = fetch(si->getTrueValue(), dl, symbols);
Val vf = fetch(si->getFalseValue(), dl, symbols); Val vf = fetch(si->getFalseValue(), dl, symbols);
...@@ -589,11 +593,11 @@ Box* interpretFunction(llvm::Function *f, int nargs, Box* arg1, Box* arg2, Box* ...@@ -589,11 +593,11 @@ Box* interpretFunction(llvm::Function *f, int nargs, Box* arg1, Box* arg2, Box*
else else
SET(vf); SET(vf);
continue; continue;
} else if (llvm::PHINode *phi = llvm::dyn_cast<llvm::PHINode>(it)) { } else if (llvm::PHINode *phi = llvm::dyn_cast<llvm::PHINode>(inst)) {
assert(prevblock); assert(prevblock);
SET(fetch(phi->getIncomingValueForBlock(prevblock), dl, symbols)); SET(fetch(phi->getIncomingValueForBlock(prevblock), dl, symbols));
continue; continue;
} else if (llvm::BranchInst *br = llvm::dyn_cast<llvm::BranchInst>(it)) { } else if (llvm::BranchInst *br = llvm::dyn_cast<llvm::BranchInst>(inst)) {
prevblock = curblock; prevblock = curblock;
if (br->isConditional()) { if (br->isConditional()) {
Val t = fetch(br->getCondition(), dl, symbols); Val t = fetch(br->getCondition(), dl, symbols);
...@@ -609,7 +613,7 @@ Box* interpretFunction(llvm::Function *f, int nargs, Box* arg1, Box* arg2, Box* ...@@ -609,7 +613,7 @@ Box* interpretFunction(llvm::Function *f, int nargs, Box* arg1, Box* arg2, Box*
//printf("jumped to %s\n", curblock->getName().data()); //printf("jumped to %s\n", curblock->getName().data());
//} //}
break; break;
} else if (llvm::ReturnInst *ret = llvm::dyn_cast<llvm::ReturnInst>(it)) { } else if (llvm::ReturnInst *ret = llvm::dyn_cast<llvm::ReturnInst>(inst)) {
llvm::Value* r = ret->getReturnValue(); llvm::Value* r = ret->getReturnValue();
#ifdef TIME_INTERPRETS #ifdef TIME_INTERPRETS
...@@ -625,7 +629,7 @@ Box* interpretFunction(llvm::Function *f, int nargs, Box* arg1, Box* arg2, Box* ...@@ -625,7 +629,7 @@ Box* interpretFunction(llvm::Function *f, int nargs, Box* arg1, Box* arg2, Box*
} }
it->dump(); inst->dump();
RELEASE_ASSERT(1, ""); RELEASE_ASSERT(1, "");
} }
} }
......
...@@ -144,6 +144,7 @@ class DeadAllocsPass : public FunctionPass { ...@@ -144,6 +144,7 @@ class DeadAllocsPass : public FunctionPass {
if (GetElementPtrInst *gep = dyn_cast<GetElementPtrInst>(derived)) { if (GetElementPtrInst *gep = dyn_cast<GetElementPtrInst>(derived)) {
std::vector<Value*> indices; std::vector<Value*> indices;
// No range version of this for now:
for (GetElementPtrInst::op_iterator it = gep->idx_begin(), end = gep->idx_end(); it != end; ++it) { for (GetElementPtrInst::op_iterator it = gep->idx_begin(), end = gep->idx_end(); it != end; ++it) {
indices.push_back(it->get()); indices.push_back(it->get());
} }
...@@ -291,6 +292,7 @@ class DeadAllocsPass : public FunctionPass { ...@@ -291,6 +292,7 @@ class DeadAllocsPass : public FunctionPass {
// Extract a Value corresponding to the value of this pointer, potentially traversing the CFG. // Extract a Value corresponding to the value of this pointer, potentially traversing the CFG.
// Starts looking a the end of this BB and working backwards. // Starts looking a the end of this BB and working backwards.
Value* getLoadValFrom(Value* ptr, BasicBlock* bb, std::unordered_map<BasicBlock*, Value*> &seen, ChainInfo &chain) { Value* getLoadValFrom(Value* ptr, BasicBlock* bb, std::unordered_map<BasicBlock*, Value*> &seen, ChainInfo &chain) {
// No range version of this for now:
for (auto it = bb->rbegin(), end = bb->rend(); it != end; ++it) { for (auto it = bb->rbegin(), end = bb->rend(); it != end; ++it) {
Value* v = extractLoadValue(ptr, &*it, chain); Value* v = extractLoadValue(ptr, &*it, chain);
if (v == NULL) if (v == NULL)
...@@ -318,6 +320,7 @@ class DeadAllocsPass : public FunctionPass { ...@@ -318,6 +320,7 @@ class DeadAllocsPass : public FunctionPass {
if (VERBOSITY() >= 2) errs() << "Added phi " << *phi << " in " << bb->getName() << '\n'; if (VERBOSITY() >= 2) errs() << "Added phi " << *phi << " in " << bb->getName() << '\n';
int num_predecessors = 0; int num_predecessors = 0;
// No range version of this for now:
for (auto prev_bb = pred_begin(bb), end = pred_end(bb); prev_bb != end; ++prev_bb) { for (auto prev_bb = pred_begin(bb), end = pred_end(bb); prev_bb != end; ++prev_bb) {
num_predecessors++; num_predecessors++;
......
...@@ -175,18 +175,19 @@ class MyInliningPass : public llvm::FunctionPass { ...@@ -175,18 +175,19 @@ class MyInliningPass : public llvm::FunctionPass {
// Keep this section as a release_assert since the code-to-be-inlined, as well as the inlining // Keep this section as a release_assert since the code-to-be-inlined, as well as the inlining
// decisions, can be different in release mode: // decisions, can be different in release mode:
int op_idx = 0; int op_idx = -1;
for (llvm::Function::arg_iterator it = f->arg_begin(), end = f->arg_end(); it != end; ++it, ++op_idx) { for (llvm::Argument& arg : f->args()) {
++op_idx;
llvm::Type* op_type =call->getOperand(op_idx)->getType(); llvm::Type* op_type =call->getOperand(op_idx)->getType();
if (it->getType() != op_type) { if (arg.getType() != op_type) {
llvm::errs() << f->getName() << " has arg " << op_idx << " mismatched!\n"; llvm::errs() << f->getName() << " has arg " << op_idx << " mismatched!\n";
llvm::errs() << "Given "; llvm::errs() << "Given ";
op_type->dump(); op_type->dump();
llvm::errs() << " but underlying function expected "; llvm::errs() << " but underlying function expected ";
it->getType()->dump(); arg.getType()->dump();
llvm::errs() << '\n'; llvm::errs() << '\n';
} }
RELEASE_ASSERT(it->getType() == call->getOperand(op_idx)->getType(), ""); RELEASE_ASSERT(arg.getType() == call->getOperand(op_idx)->getType(), "");
} }
assert(!f->isDeclaration()); assert(!f->isDeclaration());
......
...@@ -104,9 +104,8 @@ void processStackmap(StackMap* stackmap) { ...@@ -104,9 +104,8 @@ void processStackmap(StackMap* stackmap) {
registerCompiledPatchpoint(start_addr, pp, StackInfo({stack_size, has_scratch, pp->numScratchBytes(), scratch_rbp_offset}), std::move(live_outs)); registerCompiledPatchpoint(start_addr, pp, StackInfo({stack_size, has_scratch, pp->numScratchBytes(), scratch_rbp_offset}), std::move(live_outs));
} }
for (std::unordered_map<int64_t, PatchpointSetupInfo*>::iterator it = for (const std::pair<int64_t, PatchpointSetupInfo*> &p : new_patchpoints_by_id) {
new_patchpoints_by_id.begin(), end = new_patchpoints_by_id.end(); it != end; ++it) { delete p.second;
delete it->second;
} }
new_patchpoints_by_id.clear(); new_patchpoints_by_id.clear();
} }
......
...@@ -45,8 +45,8 @@ void Stats::dump() { ...@@ -45,8 +45,8 @@ void Stats::dump() {
printf("Stats:\n"); printf("Stats:\n");
std::vector<std::pair<std::string, int> > pairs; std::vector<std::pair<std::string, int> > pairs;
for (std::unordered_map<int, std::string>::iterator it = names->begin(), end = names->end(); it != end; ++it) { for (auto p : *names) {
pairs.push_back(make_pair(it->second, it->first)); pairs.push_back(make_pair(p.second, p.first));
} }
std::sort(pairs.begin(), pairs.end()); std::sort(pairs.begin(), pairs.end());
......
...@@ -27,15 +27,15 @@ Box* dictRepr(BoxedDict* self) { ...@@ -27,15 +27,15 @@ Box* dictRepr(BoxedDict* self) {
std::vector<char> chars; std::vector<char> chars;
chars.push_back('{'); chars.push_back('{');
bool first = true; bool first = true;
for (BoxedDict::PyDict::iterator it = self->d.begin(), end = self->d.end(); it != end; ++it) { for (auto p : self->d) {
if (!first) { if (!first) {
chars.push_back(','); chars.push_back(',');
chars.push_back(' '); chars.push_back(' ');
} }
first = false; first = false;
BoxedString *k = repr(it->first); BoxedString *k = repr(p.first);
BoxedString *v = repr(it->second); BoxedString *v = repr(p.second);
chars.insert(chars.end(), k->s.begin(), k->s.end()); chars.insert(chars.end(), k->s.begin(), k->s.end());
chars.push_back(':'); chars.push_back(':');
chars.push_back(' '); chars.push_back(' ');
...@@ -48,10 +48,10 @@ Box* dictRepr(BoxedDict* self) { ...@@ -48,10 +48,10 @@ Box* dictRepr(BoxedDict* self) {
Box* dictItems(BoxedDict* self) { Box* dictItems(BoxedDict* self) {
BoxedList* rtn = new BoxedList(); BoxedList* rtn = new BoxedList();
for (BoxedDict::PyDict::const_iterator it = self->d.begin(), end = self->d.end(); it != end; ++it) { for (auto p : self->d) {
std::vector<Box*> elts; std::vector<Box*> elts;
elts.push_back(it->first); elts.push_back(p.first);
elts.push_back(it->second); elts.push_back(p.second);
BoxedTuple *t = new BoxedTuple(elts); BoxedTuple *t = new BoxedTuple(elts);
listAppendInternal(rtn, t); listAppendInternal(rtn, t);
} }
...@@ -61,16 +61,16 @@ Box* dictItems(BoxedDict* self) { ...@@ -61,16 +61,16 @@ Box* dictItems(BoxedDict* self) {
Box* dictValues(BoxedDict* self) { Box* dictValues(BoxedDict* self) {
BoxedList* rtn = new BoxedList(); BoxedList* rtn = new BoxedList();
for (BoxedDict::PyDict::const_iterator it = self->d.begin(), end = self->d.end(); it != end; ++it) { for (auto p : self->d) {
listAppendInternal(rtn, it->second); listAppendInternal(rtn, p.second);
} }
return rtn; return rtn;
} }
Box* dictKeys(BoxedDict* self) { Box* dictKeys(BoxedDict* self) {
BoxedList* rtn = new BoxedList(); BoxedList* rtn = new BoxedList();
for (BoxedDict::PyDict::const_iterator it = self->d.begin(), end = self->d.end(); it != end; ++it) { for (auto p : self->d) {
listAppendInternal(rtn, it->first); listAppendInternal(rtn, p.first);
} }
return rtn; return rtn;
} }
......
...@@ -92,8 +92,8 @@ void gc_teardown() { ...@@ -92,8 +92,8 @@ void gc_teardown() {
#ifdef DEBUG_GC #ifdef DEBUG_GC
AliveSet *alive = getAlive(); AliveSet *alive = getAlive();
assert(nallocs == alive->size()); assert(nallocs == alive->size());
for (AliveSet::iterator it = alive->begin(), end = alive->end(); it != end; ++it) { for (void* p : alive) {
printf("%p\n", *it); printf("%p\n", p);
} }
#endif #endif
// This will scan through the heap and alert us about things that // This will scan through the heap and alert us about things that
......
...@@ -419,9 +419,8 @@ void HCBox::setattr(const std::string& attr, Box* val, SetattrRewriteArgs *rewri ...@@ -419,9 +419,8 @@ void HCBox::setattr(const std::string& attr, Box* val, SetattrRewriteArgs *rewri
// TODO need to make sure we don't need to rearrange the attributes // TODO need to make sure we don't need to rearrange the attributes
assert(new_hcls->attr_offsets[attr] == numattrs); assert(new_hcls->attr_offsets[attr] == numattrs);
#ifndef NDEBUG #ifndef NDEBUG
for (std::unordered_map<std::string, int>::iterator it = hcls->attr_offsets.begin(), end = hcls->attr_offsets.end(); for (auto p : hcls->attr_offsets) {
it != end; ++it) { assert(new_hcls->attr_offsets[p.first] == p.second);
assert(new_hcls->attr_offsets[it->first] == it->second);
} }
#endif #endif
......
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