Commit 21ac70f4 authored by Marius Wachtler's avatar Marius Wachtler

rename ConstantVRegInfo to CodeConstants

parent ff6ca0d4
...@@ -89,17 +89,17 @@ private: ...@@ -89,17 +89,17 @@ private:
ExprTypeMap& expr_types; ExprTypeMap& expr_types;
TypeSpeculations& type_speculations; TypeSpeculations& type_speculations;
TypeAnalysis::SpeculationLevel speculation; TypeAnalysis::SpeculationLevel speculation;
const ConstantVRegInfo& constant_vregs; const CodeConstants& code_constants;
BasicBlockTypePropagator(CFGBlock* block, TypeMap& initial, ExprTypeMap& expr_types, BasicBlockTypePropagator(CFGBlock* block, TypeMap& initial, ExprTypeMap& expr_types,
TypeSpeculations& type_speculations, TypeAnalysis::SpeculationLevel speculation, TypeSpeculations& type_speculations, TypeAnalysis::SpeculationLevel speculation,
const ConstantVRegInfo& constant_vregs) const CodeConstants& code_constants)
: block(block), : block(block),
sym_table(initial), sym_table(initial),
expr_types(expr_types), expr_types(expr_types),
type_speculations(type_speculations), type_speculations(type_speculations),
speculation(speculation), speculation(speculation),
constant_vregs(constant_vregs) {} code_constants(code_constants) {}
void run() { void run() {
for (int i = 0; i < block->body.size(); i++) { for (int i = 0; i < block->body.size(); i++) {
...@@ -118,7 +118,7 @@ private: ...@@ -118,7 +118,7 @@ private:
printf("in propagator, speculating that %s would actually be %s, at ", printf("in propagator, speculating that %s would actually be %s, at ",
old_type->debugName().c_str(), speculated_type->debugName().c_str()); old_type->debugName().c_str(), speculated_type->debugName().c_str());
fflush(stdout); fflush(stdout);
print_bst(node, constant_vregs); print_bst(node, code_constants);
llvm::outs().flush(); llvm::outs().flush();
printf("\n"); printf("\n");
} }
...@@ -131,7 +131,7 @@ private: ...@@ -131,7 +131,7 @@ private:
} }
CompilerType* getConstantType(int vreg) { CompilerType* getConstantType(int vreg) {
Box* o = constant_vregs.getConstant(vreg); Box* o = code_constants.getConstant(vreg);
if (o->cls == int_cls) if (o->cls == int_cls)
return INT; return INT;
else if (o->cls == float_cls) else if (o->cls == float_cls)
...@@ -284,7 +284,7 @@ private: ...@@ -284,7 +284,7 @@ private:
if (VERBOSITY() >= 2 && func == UNDEF) { if (VERBOSITY() >= 2 && func == UNDEF) {
printf("Think %s.%s is undefined, at %d\n", t->debugName().c_str(), node->attr.c_str(), node->lineno); printf("Think %s.%s is undefined, at %d\n", t->debugName().c_str(), node->attr.c_str(), node->lineno);
print_bst(node, constant_vregs); print_bst(node, code_constants);
printf("\n"); printf("\n");
} }
...@@ -297,7 +297,7 @@ private: ...@@ -297,7 +297,7 @@ private:
if (VERBOSITY() >= 2 && func == UNDEF) { if (VERBOSITY() >= 2 && func == UNDEF) {
printf("Think %s.%s is undefined, at %d\n", t->debugName().c_str(), node->attr.c_str(), node->lineno); printf("Think %s.%s is undefined, at %d\n", t->debugName().c_str(), node->attr.c_str(), node->lineno);
print_bst(node, constant_vregs); print_bst(node, code_constants);
printf("\n"); printf("\n");
} }
...@@ -399,7 +399,7 @@ private: ...@@ -399,7 +399,7 @@ private:
if (VERBOSITY() >= 2 && rtn == UNDEF) { if (VERBOSITY() >= 2 && rtn == UNDEF) {
printf("Think %s.%s is undefined, at %d\n", t->debugName().c_str(), node->attr.c_str(), node->lineno); printf("Think %s.%s is undefined, at %d\n", t->debugName().c_str(), node->attr.c_str(), node->lineno);
print_bst(node, constant_vregs); print_bst(node, code_constants);
printf("\n"); printf("\n");
} }
_doSet(node->vreg_dst, rtn); _doSet(node->vreg_dst, rtn);
...@@ -551,9 +551,9 @@ private: ...@@ -551,9 +551,9 @@ private:
public: public:
static TypeMap propagate(CFGBlock* block, const TypeMap& starting, ExprTypeMap& expr_types, static TypeMap propagate(CFGBlock* block, const TypeMap& starting, ExprTypeMap& expr_types,
TypeSpeculations& type_speculations, TypeAnalysis::SpeculationLevel speculation, TypeSpeculations& type_speculations, TypeAnalysis::SpeculationLevel speculation,
const ConstantVRegInfo& constant_vregs) { const CodeConstants& code_constants) {
TypeMap ending = starting; TypeMap ending = starting;
BasicBlockTypePropagator(block, ending, expr_types, type_speculations, speculation, constant_vregs).run(); BasicBlockTypePropagator(block, ending, expr_types, type_speculations, speculation, code_constants).run();
return ending; return ending;
} }
}; };
...@@ -632,7 +632,7 @@ public: ...@@ -632,7 +632,7 @@ public:
} }
static PropagatingTypeAnalysis* doAnalysis(SpeculationLevel speculation, TypeMap&& initial_types, static PropagatingTypeAnalysis* doAnalysis(SpeculationLevel speculation, TypeMap&& initial_types,
CFGBlock* initial_block, const ConstantVRegInfo& constant_vregs) { CFGBlock* initial_block, const CodeConstants& code_constants) {
Timer _t("PropagatingTypeAnalysis::doAnalysis()"); Timer _t("PropagatingTypeAnalysis::doAnalysis()");
CFG* cfg = initial_block->cfg; CFG* cfg = initial_block->cfg;
...@@ -673,7 +673,7 @@ public: ...@@ -673,7 +673,7 @@ public:
} }
TypeMap ending = BasicBlockTypePropagator::propagate(block, starting_types.find(block)->second, expr_types, TypeMap ending = BasicBlockTypePropagator::propagate(block, starting_types.find(block)->second, expr_types,
type_speculations, speculation, constant_vregs); type_speculations, speculation, code_constants);
if (VERBOSITY("types") >= 3) { if (VERBOSITY("types") >= 3) {
printf("before (after):\n"); printf("before (after):\n");
...@@ -730,7 +730,7 @@ public: ...@@ -730,7 +730,7 @@ public:
// public entry point: // public entry point:
TypeAnalysis* doTypeAnalysis(CFG* cfg, const ParamNames& arg_names, const std::vector<ConcreteCompilerType*>& arg_types, TypeAnalysis* doTypeAnalysis(CFG* cfg, const ParamNames& arg_names, const std::vector<ConcreteCompilerType*>& arg_types,
EffortLevel effort, TypeAnalysis::SpeculationLevel speculation, EffortLevel effort, TypeAnalysis::SpeculationLevel speculation,
const ConstantVRegInfo& constant_vregs) { const CodeConstants& code_constants) {
// if (effort == EffortLevel::INTERPRETED) { // if (effort == EffortLevel::INTERPRETED) {
// return new NullTypeAnalysis(); // return new NullTypeAnalysis();
//} //}
...@@ -750,11 +750,11 @@ TypeAnalysis* doTypeAnalysis(CFG* cfg, const ParamNames& arg_names, const std::v ...@@ -750,11 +750,11 @@ TypeAnalysis* doTypeAnalysis(CFG* cfg, const ParamNames& arg_names, const std::v
assert(i == arg_types.size()); assert(i == arg_types.size());
return PropagatingTypeAnalysis::doAnalysis(speculation, std::move(initial_types), cfg->getStartingBlock(), return PropagatingTypeAnalysis::doAnalysis(speculation, std::move(initial_types), cfg->getStartingBlock(),
constant_vregs); code_constants);
} }
TypeAnalysis* doTypeAnalysis(const OSREntryDescriptor* entry_descriptor, EffortLevel effort, TypeAnalysis* doTypeAnalysis(const OSREntryDescriptor* entry_descriptor, EffortLevel effort,
TypeAnalysis::SpeculationLevel speculation, const ConstantVRegInfo& constant_vregs) { TypeAnalysis::SpeculationLevel speculation, const CodeConstants& code_constants) {
auto cfg = entry_descriptor->code->source->cfg; auto cfg = entry_descriptor->code->source->cfg;
auto&& vreg_info = cfg->getVRegInfo(); auto&& vreg_info = cfg->getVRegInfo();
TypeMap initial_types(vreg_info.getTotalNumOfVRegs()); TypeMap initial_types(vreg_info.getTotalNumOfVRegs());
...@@ -764,6 +764,6 @@ TypeAnalysis* doTypeAnalysis(const OSREntryDescriptor* entry_descriptor, EffortL ...@@ -764,6 +764,6 @@ TypeAnalysis* doTypeAnalysis(const OSREntryDescriptor* entry_descriptor, EffortL
} }
return PropagatingTypeAnalysis::doAnalysis(speculation, std::move(initial_types), return PropagatingTypeAnalysis::doAnalysis(speculation, std::move(initial_types),
entry_descriptor->backedge->target, constant_vregs); entry_descriptor->backedge->target, code_constants);
} }
} }
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
namespace pyston { namespace pyston {
class CFGBlock; class CFGBlock;
class ConstantVRegInfo; class CodeConstants;
class BoxedClass; class BoxedClass;
class BST_stmt_with_dest; class BST_stmt_with_dest;
class OSREntryDescriptor; class OSREntryDescriptor;
...@@ -45,9 +45,9 @@ public: ...@@ -45,9 +45,9 @@ public:
TypeAnalysis* doTypeAnalysis(CFG* cfg, const ParamNames& param_names, TypeAnalysis* doTypeAnalysis(CFG* cfg, const ParamNames& param_names,
const std::vector<ConcreteCompilerType*>& arg_types, EffortLevel effort, const std::vector<ConcreteCompilerType*>& arg_types, EffortLevel effort,
TypeAnalysis::SpeculationLevel speculation, const ConstantVRegInfo& constant_vregs); TypeAnalysis::SpeculationLevel speculation, const CodeConstants& code_constants);
TypeAnalysis* doTypeAnalysis(const OSREntryDescriptor* entry_descriptor, EffortLevel effort, TypeAnalysis* doTypeAnalysis(const OSREntryDescriptor* entry_descriptor, EffortLevel effort,
TypeAnalysis::SpeculationLevel speculation, const ConstantVRegInfo& constant_vregs); TypeAnalysis::SpeculationLevel speculation, const CodeConstants& code_constants);
} }
#endif #endif
...@@ -181,7 +181,7 @@ public: ...@@ -181,7 +181,7 @@ public:
BoxedClosure* getPassedClosure() { return frame_info.passed_closure; } BoxedClosure* getPassedClosure() { return frame_info.passed_closure; }
Box** getVRegs() { return vregs; } Box** getVRegs() { return vregs; }
const ScopingResults& getScopeInfo() { return scope_info; } const ScopingResults& getScopeInfo() { return scope_info; }
const ConstantVRegInfo& getConstantVRegInfo() { return getCode()->constant_vregs; } const CodeConstants& getCodeConstants() { return getCode()->code_constants; }
void addSymbol(int vreg, Box* value, bool allow_duplicates); void addSymbol(int vreg, Box* value, bool allow_duplicates);
void setGenerator(Box* gen); void setGenerator(Box* gen);
...@@ -900,7 +900,7 @@ Value ASTInterpreter::visit_stmt(BST_stmt* node) { ...@@ -900,7 +900,7 @@ Value ASTInterpreter::visit_stmt(BST_stmt* node) {
if (0) { if (0) {
printf("%20s % 2d ", getCode()->name->c_str(), current_block->idx); printf("%20s % 2d ", getCode()->name->c_str(), current_block->idx);
print_bst(node, getConstantVRegInfo()); print_bst(node, getCodeConstants());
printf("\n"); printf("\n");
} }
...@@ -1528,7 +1528,7 @@ Value ASTInterpreter::visit_set(BST_Set* node) { ...@@ -1528,7 +1528,7 @@ Value ASTInterpreter::visit_set(BST_Set* node) {
Value ASTInterpreter::getVReg(int vreg, bool is_kill) { Value ASTInterpreter::getVReg(int vreg, bool is_kill) {
assert(vreg != VREG_UNDEFINED); assert(vreg != VREG_UNDEFINED);
if (vreg < 0) { if (vreg < 0) {
Box* o = getConstantVRegInfo().getConstant(vreg); Box* o = getCodeConstants().getConstant(vreg);
return Value(incref(o), jit ? jit->imm(o)->setType(RefType::BORROWED) : NULL); return Value(incref(o), jit ? jit->imm(o)->setType(RefType::BORROWED) : NULL);
} }
...@@ -1564,10 +1564,10 @@ Value ASTInterpreter::getVReg(int vreg, bool is_kill) { ...@@ -1564,10 +1564,10 @@ Value ASTInterpreter::getVReg(int vreg, bool is_kill) {
} }
current_block->print(getConstantVRegInfo()); current_block->print(getCodeConstants());
printf("vreg: %d num cross: %d\n", vreg, getVRegInfo().getNumOfCrossBlockVRegs()); printf("vreg: %d num cross: %d\n", vreg, getVRegInfo().getNumOfCrossBlockVRegs());
printf("\n\n"); printf("\n\n");
current_block->cfg->print(getConstantVRegInfo()); current_block->cfg->print(getCodeConstants());
assert(0); assert(0);
return Value(); return Value();
......
...@@ -1027,7 +1027,7 @@ std::pair<CompiledFunction*, llvm::Function*> doCompile(BoxedCode* code, SourceI ...@@ -1027,7 +1027,7 @@ std::pair<CompiledFunction*, llvm::Function*> doCompile(BoxedCode* code, SourceI
assert((entry_descriptor != NULL) + (spec != NULL) == 1); assert((entry_descriptor != NULL) + (spec != NULL) == 1);
if (VERBOSITY("irgen") >= 2) if (VERBOSITY("irgen") >= 2)
source->cfg->print(code->constant_vregs); source->cfg->print(code->code_constants);
assert(g.cur_module == NULL); assert(g.cur_module == NULL);
...@@ -1101,10 +1101,10 @@ std::pair<CompiledFunction*, llvm::Function*> doCompile(BoxedCode* code, SourceI ...@@ -1101,10 +1101,10 @@ std::pair<CompiledFunction*, llvm::Function*> doCompile(BoxedCode* code, SourceI
speculation_level = TypeAnalysis::SOME; speculation_level = TypeAnalysis::SOME;
TypeAnalysis* types; TypeAnalysis* types;
if (entry_descriptor) if (entry_descriptor)
types = doTypeAnalysis(entry_descriptor, effort, speculation_level, code->constant_vregs); types = doTypeAnalysis(entry_descriptor, effort, speculation_level, code->code_constants);
else else
types = doTypeAnalysis(source->cfg, *param_names, spec->arg_types, effort, speculation_level, types = doTypeAnalysis(source->cfg, *param_names, spec->arg_types, effort, speculation_level,
code->constant_vregs); code->code_constants);
_t2.split(); _t2.split();
......
...@@ -1225,7 +1225,7 @@ private: ...@@ -1225,7 +1225,7 @@ private:
CompilerVariable* evalVReg(int vreg, bool is_kill = true) { CompilerVariable* evalVReg(int vreg, bool is_kill = true) {
assert(vreg != VREG_UNDEFINED); assert(vreg != VREG_UNDEFINED);
if (vreg < 0) { if (vreg < 0) {
Box* o = irstate->getCode()->constant_vregs.getConstant(vreg); Box* o = irstate->getCode()->code_constants.getConstant(vreg);
if (o->cls == int_cls) { if (o->cls == int_cls) {
return makeInt(((BoxedInt*)o)->n); return makeInt(((BoxedInt*)o)->n);
} else if (o->cls == float_cls) { } else if (o->cls == float_cls) {
...@@ -1612,7 +1612,7 @@ private: ...@@ -1612,7 +1612,7 @@ private:
printf("Speculating that %s is actually %s, at ", rtn->getType()->debugName().c_str(), printf("Speculating that %s is actually %s, at ", rtn->getType()->debugName().c_str(),
speculated_type->debugName().c_str()); speculated_type->debugName().c_str());
fflush(stdout); fflush(stdout);
print_bst(node, irstate->getCode()->constant_vregs); print_bst(node, irstate->getCode()->code_constants);
llvm::outs().flush(); llvm::outs().flush();
printf("\n"); printf("\n");
} }
...@@ -1624,7 +1624,7 @@ private: ...@@ -1624,7 +1624,7 @@ private:
auto source = irstate->getSourceInfo(); auto source = irstate->getSourceInfo();
printf("On %s:%d, function %s:\n", irstate->getCode()->filename->c_str(), printf("On %s:%d, function %s:\n", irstate->getCode()->filename->c_str(),
irstate->getCode()->firstlineno, irstate->getCode()->name->c_str()); irstate->getCode()->firstlineno, irstate->getCode()->name->c_str());
irstate->getSourceInfo()->cfg->print(irstate->getCode()->constant_vregs); irstate->getSourceInfo()->cfg->print(irstate->getCode()->code_constants);
} }
RELEASE_ASSERT(!rtn->canConvertTo(speculated_type), "%s %s", rtn->getType()->debugName().c_str(), RELEASE_ASSERT(!rtn->canConvertTo(speculated_type), "%s %s", rtn->getType()->debugName().c_str(),
speculated_type->debugName().c_str()); speculated_type->debugName().c_str());
......
...@@ -754,8 +754,8 @@ void BST_MakeSlice::accept_stmt(StmtVisitor* v) { ...@@ -754,8 +754,8 @@ void BST_MakeSlice::accept_stmt(StmtVisitor* v) {
return v->visit_makeslice(this); return v->visit_makeslice(this);
} }
void print_bst(BST_stmt* bst, const ConstantVRegInfo& constant_vregs) { void print_bst(BST_stmt* bst, const CodeConstants& code_constants) {
PrintVisitor v(constant_vregs, 0, llvm::outs()); PrintVisitor v(code_constants, 0, llvm::outs());
bst->accept(&v); bst->accept(&v);
v.flush(); v.flush();
} }
...@@ -771,7 +771,7 @@ bool PrintVisitor::visit_vreg(int* vreg, bool is_dst) { ...@@ -771,7 +771,7 @@ bool PrintVisitor::visit_vreg(int* vreg, bool is_dst) {
if (*vreg != VREG_UNDEFINED) { if (*vreg != VREG_UNDEFINED) {
stream << "%" << *vreg; stream << "%" << *vreg;
if (*vreg < 0) if (*vreg < 0)
stream << "|" << autoDecref(repr(constant_vregs.getConstant(*vreg)))->s() << "|"; stream << "|" << autoDecref(repr(code_constants.getConstant(*vreg)))->s() << "|";
} else } else
stream << "%undef"; stream << "%undef";
......
...@@ -906,20 +906,20 @@ public: ...@@ -906,20 +906,20 @@ public:
virtual void visit_yield(BST_Yield* node) { RELEASE_ASSERT(0, ""); } virtual void visit_yield(BST_Yield* node) { RELEASE_ASSERT(0, ""); }
}; };
class ConstantVRegInfo; class CodeConstants;
void print_bst(BST_stmt* bst, const ConstantVRegInfo& constant_vregs); void print_bst(BST_stmt* bst, const CodeConstants& code_constants);
class PrintVisitor : public BSTVisitor { class PrintVisitor : public BSTVisitor {
private: private:
llvm::raw_ostream& stream; llvm::raw_ostream& stream;
const ConstantVRegInfo& constant_vregs; const CodeConstants& code_constants;
int indent; int indent;
void printIndent(); void printIndent();
void printOp(AST_TYPE::AST_TYPE op_type); void printOp(AST_TYPE::AST_TYPE op_type);
public: public:
PrintVisitor(const ConstantVRegInfo& constant_vregs, int indent, llvm::raw_ostream& stream) PrintVisitor(const CodeConstants& code_constants, int indent, llvm::raw_ostream& stream)
: BSTVisitor(false /* visit child CFG */), stream(stream), constant_vregs(constant_vregs), indent(indent) {} : BSTVisitor(false /* visit child CFG */), stream(stream), code_constants(code_constants), indent(indent) {}
virtual ~PrintVisitor() {} virtual ~PrintVisitor() {}
void flush() { stream.flush(); } void flush() { stream.flush(); }
......
...@@ -185,7 +185,7 @@ void CFGBlock::unconnectFrom(CFGBlock* successor) { ...@@ -185,7 +185,7 @@ void CFGBlock::unconnectFrom(CFGBlock* successor) {
successor->predecessors.end()); successor->predecessors.end());
} }
void CFGBlock::print(const ConstantVRegInfo& constant_vregs, llvm::raw_ostream& stream) { void CFGBlock::print(const CodeConstants& code_constants, llvm::raw_ostream& stream) {
stream << "Block " << idx; stream << "Block " << idx;
if (info) if (info)
stream << " '" << info << "'"; stream << " '" << info << "'";
...@@ -200,7 +200,7 @@ void CFGBlock::print(const ConstantVRegInfo& constant_vregs, llvm::raw_ostream& ...@@ -200,7 +200,7 @@ void CFGBlock::print(const ConstantVRegInfo& constant_vregs, llvm::raw_ostream&
} }
stream << "\n"; stream << "\n";
PrintVisitor pv(constant_vregs, 4, stream); PrintVisitor pv(code_constants, 4, stream);
for (int j = 0; j < body.size(); j++) { for (int j = 0; j < body.size(); j++) {
stream << " "; stream << " ";
body[j]->accept(&pv); body[j]->accept(&pv);
...@@ -246,10 +246,10 @@ public: ...@@ -246,10 +246,10 @@ public:
AST* orig_node); AST* orig_node);
}; };
static std::pair<CFG*, ConstantVRegInfo> computeCFG(llvm::ArrayRef<AST_stmt*> body, AST_TYPE::AST_TYPE ast_type, static std::pair<CFG*, CodeConstants> computeCFG(llvm::ArrayRef<AST_stmt*> body, AST_TYPE::AST_TYPE ast_type,
int lineno, AST_arguments* args, BoxedString* filename, int lineno, AST_arguments* args, BoxedString* filename,
SourceInfo* source, const ParamNames& param_names, SourceInfo* source, const ParamNames& param_names, ScopeInfo* scoping,
ScopeInfo* scoping, ModuleCFGProcessor* cfgizer); ModuleCFGProcessor* cfgizer);
// This keeps track of the result of an instruction it's either a name, const or undefined. // This keeps track of the result of an instruction it's either a name, const or undefined.
struct TmpValue { struct TmpValue {
...@@ -363,11 +363,11 @@ private: ...@@ -363,11 +363,11 @@ private:
std::vector<ContInfo> continuations; std::vector<ContInfo> continuations;
std::vector<ExcBlockInfo> exc_handlers; std::vector<ExcBlockInfo> exc_handlers;
llvm::DenseMap<Box*, int> consts; llvm::DenseMap<Box*, int> consts;
ConstantVRegInfo constant_vregs; CodeConstants code_constants;
unsigned int next_var_index = 0; unsigned int next_var_index = 0;
friend std::pair<CFG*, ConstantVRegInfo> computeCFG(llvm::ArrayRef<AST_stmt*> body, AST_TYPE::AST_TYPE ast_type, friend std::pair<CFG*, CodeConstants> computeCFG(llvm::ArrayRef<AST_stmt*> body, AST_TYPE::AST_TYPE ast_type,
int lineno, AST_arguments* args, BoxedString* filename, int lineno, AST_arguments* args, BoxedString* filename,
SourceInfo* source, const ParamNames& param_names, SourceInfo* source, const ParamNames& param_names,
ScopeInfo* scoping, ModuleCFGProcessor* cfgizer); ScopeInfo* scoping, ModuleCFGProcessor* cfgizer);
...@@ -513,7 +513,7 @@ private: ...@@ -513,7 +513,7 @@ private:
auto it = consts.find(o); auto it = consts.find(o);
if (it != consts.end()) if (it != consts.end())
return it->second; return it->second;
int vreg = constant_vregs.addConstant(o); int vreg = code_constants.createVRegEntryForConstant(o);
consts[o] = vreg; consts[o] = vreg;
return vreg; return vreg;
} }
...@@ -2855,11 +2855,11 @@ public: ...@@ -2855,11 +2855,11 @@ public:
} }
}; };
void CFG::print(const ConstantVRegInfo& constant_vregs, llvm::raw_ostream& stream) { void CFG::print(const CodeConstants& code_constants, llvm::raw_ostream& stream) {
stream << "CFG:\n"; stream << "CFG:\n";
stream << blocks.size() << " blocks\n"; stream << blocks.size() << " blocks\n";
for (int i = 0; i < blocks.size(); i++) for (int i = 0; i < blocks.size(); i++)
blocks[i]->print(constant_vregs, stream); blocks[i]->print(code_constants, stream);
stream.flush(); stream.flush();
} }
...@@ -3047,10 +3047,10 @@ void VRegInfo::assignVRegs(CFG* cfg, const ParamNames& param_names, llvm::DenseM ...@@ -3047,10 +3047,10 @@ void VRegInfo::assignVRegs(CFG* cfg, const ParamNames& param_names, llvm::DenseM
} }
static std::pair<CFG*, ConstantVRegInfo> computeCFG(llvm::ArrayRef<AST_stmt*> body, AST_TYPE::AST_TYPE ast_type, static std::pair<CFG*, CodeConstants> computeCFG(llvm::ArrayRef<AST_stmt*> body, AST_TYPE::AST_TYPE ast_type,
int lineno, AST_arguments* args, BoxedString* filename, int lineno, AST_arguments* args, BoxedString* filename,
SourceInfo* source, const ParamNames& param_names, SourceInfo* source, const ParamNames& param_names, ScopeInfo* scoping,
ScopeInfo* scoping, ModuleCFGProcessor* cfgizer) { ModuleCFGProcessor* cfgizer) {
STAT_TIMER(t0, "us_timer_computecfg", 0); STAT_TIMER(t0, "us_timer_computecfg", 0);
CFG* rtn = new CFG(); CFG* rtn = new CFG();
...@@ -3139,7 +3139,7 @@ static std::pair<CFG*, ConstantVRegInfo> computeCFG(llvm::ArrayRef<AST_stmt*> bo ...@@ -3139,7 +3139,7 @@ static std::pair<CFG*, ConstantVRegInfo> computeCFG(llvm::ArrayRef<AST_stmt*> bo
if (VERBOSITY("cfg") >= 3) { if (VERBOSITY("cfg") >= 3) {
printf("Before cfg checking and transformations:\n"); printf("Before cfg checking and transformations:\n");
rtn->print(visitor.constant_vregs); rtn->print(visitor.code_constants);
} }
#ifndef NDEBUG #ifndef NDEBUG
...@@ -3167,7 +3167,7 @@ static std::pair<CFG*, ConstantVRegInfo> computeCFG(llvm::ArrayRef<AST_stmt*> bo ...@@ -3167,7 +3167,7 @@ static std::pair<CFG*, ConstantVRegInfo> computeCFG(llvm::ArrayRef<AST_stmt*> bo
if (b->predecessors.size() == 0) { if (b->predecessors.size() == 0) {
if (b != rtn->getStartingBlock()) { if (b != rtn->getStartingBlock()) {
rtn->print(visitor.constant_vregs); rtn->print(visitor.code_constants);
} }
ASSERT(b == rtn->getStartingBlock(), "%d", b->idx); ASSERT(b == rtn->getStartingBlock(), "%d", b->idx);
} }
...@@ -3222,13 +3222,13 @@ static std::pair<CFG*, ConstantVRegInfo> computeCFG(llvm::ArrayRef<AST_stmt*> bo ...@@ -3222,13 +3222,13 @@ static std::pair<CFG*, ConstantVRegInfo> computeCFG(llvm::ArrayRef<AST_stmt*> bo
deduped[e]++; deduped[e]++;
if (deduped[e] == 2) { if (deduped[e] == 2) {
printf("Duplicated: "); printf("Duplicated: ");
print_bst(e, visitor.constant_vregs); print_bst(e, visitor.code_constants);
printf("\n"); printf("\n");
no_dups = false; no_dups = false;
} }
} }
if (!no_dups) if (!no_dups)
rtn->print(visitor.constant_vregs); rtn->print(visitor.code_constants);
assert(no_dups); assert(no_dups);
// Uncomment this for some heavy checking to make sure that we don't forget // Uncomment this for some heavy checking to make sure that we don't forget
...@@ -3331,10 +3331,10 @@ static std::pair<CFG*, ConstantVRegInfo> computeCFG(llvm::ArrayRef<AST_stmt*> bo ...@@ -3331,10 +3331,10 @@ static std::pair<CFG*, ConstantVRegInfo> computeCFG(llvm::ArrayRef<AST_stmt*> bo
if (VERBOSITY("cfg") >= 2) { if (VERBOSITY("cfg") >= 2) {
printf("Final cfg:\n"); printf("Final cfg:\n");
rtn->print(visitor.constant_vregs, llvm::outs()); rtn->print(visitor.code_constants, llvm::outs());
} }
return std::make_pair(rtn, visitor.constant_vregs); return std::make_pair(rtn, visitor.code_constants);
} }
...@@ -3381,17 +3381,17 @@ BoxedCode* ModuleCFGProcessor::runRecursively(llvm::ArrayRef<AST_stmt*> body, Bo ...@@ -3381,17 +3381,17 @@ BoxedCode* ModuleCFGProcessor::runRecursively(llvm::ArrayRef<AST_stmt*> body, Bo
for (auto e : param_names.allArgsAsName()) for (auto e : param_names.allArgsAsName())
fillScopingInfo(e, scope_info); fillScopingInfo(e, scope_info);
ConstantVRegInfo constant_vregs; CodeConstants code_constants;
std::tie(si->cfg, constant_vregs) std::tie(si->cfg, code_constants)
= computeCFG(body, ast_type, lineno, args, fn, si.get(), param_names, scope_info, this); = computeCFG(body, ast_type, lineno, args, fn, si.get(), param_names, scope_info, this);
BoxedCode* code; BoxedCode* code;
if (args) if (args)
code = new BoxedCode(args->args.size(), args->vararg, args->kwarg, lineno, std::move(si), code = new BoxedCode(args->args.size(), args->vararg, args->kwarg, lineno, std::move(si),
std::move(constant_vregs), std::move(param_names), fn, name, std::move(code_constants), std::move(param_names), fn, name,
autoDecref(getDocString(body))); autoDecref(getDocString(body)));
else else
code = new BoxedCode(0, false, false, lineno, std::move(si), std::move(constant_vregs), std::move(param_names), code = new BoxedCode(0, false, false, lineno, std::move(si), std::move(code_constants), std::move(param_names),
fn, name, autoDecref(getDocString(body))); fn, name, autoDecref(getDocString(body)));
return code; return code;
...@@ -3403,7 +3403,7 @@ BoxedCode* computeAllCFGs(AST* ast, bool globals_from_module, FutureFlags future ...@@ -3403,7 +3403,7 @@ BoxedCode* computeAllCFGs(AST* ast, bool globals_from_module, FutureFlags future
.runRecursively(ast->getBody(), ast->getName(), ast->lineno, nullptr, ast); .runRecursively(ast->getBody(), ast->getName(), ast->lineno, nullptr, ast);
} }
void printCFG(CFG* cfg, const ConstantVRegInfo& constant_vregs) { void printCFG(CFG* cfg, const CodeConstants& code_constants) {
cfg->print(constant_vregs); cfg->print(code_constants);
} }
} }
...@@ -88,7 +88,7 @@ public: ...@@ -88,7 +88,7 @@ public:
void unconnectFrom(CFGBlock* successor); void unconnectFrom(CFGBlock* successor);
void push_back(BST_stmt* node) { body.push_back(node); } void push_back(BST_stmt* node) { body.push_back(node); }
void print(const ConstantVRegInfo& constant_vregs, llvm::raw_ostream& stream = llvm::outs()); void print(const CodeConstants& code_constants, llvm::raw_ostream& stream = llvm::outs());
}; };
// the vregs are split into three parts. // the vregs are split into three parts.
...@@ -210,7 +210,7 @@ public: ...@@ -210,7 +210,7 @@ public:
blocks.push_back(block); blocks.push_back(block);
} }
void print(const ConstantVRegInfo& constant_vregs, llvm::raw_ostream& stream = llvm::outs()); void print(const CodeConstants& code_constants, llvm::raw_ostream& stream = llvm::outs());
}; };
class VRegSet { class VRegSet {
...@@ -331,7 +331,7 @@ public: ...@@ -331,7 +331,7 @@ public:
BoxedCode* computeAllCFGs(AST* ast, bool globals_from_module, FutureFlags future_flags, BoxedString* fn, BoxedCode* computeAllCFGs(AST* ast, bool globals_from_module, FutureFlags future_flags, BoxedString* fn,
BoxedModule* bm); BoxedModule* bm);
void printCFG(CFG* cfg, const ConstantVRegInfo& constant_vregs); void printCFG(CFG* cfg, const CodeConstants& code_constants);
} }
#endif #endif
...@@ -113,10 +113,10 @@ void BoxedCode::dealloc(Box* b) noexcept { ...@@ -113,10 +113,10 @@ void BoxedCode::dealloc(Box* b) noexcept {
} }
BoxedCode::BoxedCode(int num_args, bool takes_varargs, bool takes_kwargs, int firstlineno, BoxedCode::BoxedCode(int num_args, bool takes_varargs, bool takes_kwargs, int firstlineno,
std::unique_ptr<SourceInfo> source, ConstantVRegInfo constant_vregs, ParamNames param_names, std::unique_ptr<SourceInfo> source, CodeConstants code_constants, ParamNames param_names,
BoxedString* filename, BoxedString* name, Box* doc) BoxedString* filename, BoxedString* name, Box* doc)
: source(std::move(source)), : source(std::move(source)),
constant_vregs(std::move(constant_vregs)), code_constants(std::move(code_constants)),
filename(incref(filename)), filename(incref(filename)),
name(incref(name)), name(incref(name)),
firstlineno(firstlineno), firstlineno(firstlineno),
......
...@@ -1070,17 +1070,17 @@ public: ...@@ -1070,17 +1070,17 @@ public:
}; };
static_assert(sizeof(BoxedDict) == sizeof(PyDictObject), ""); static_assert(sizeof(BoxedDict) == sizeof(PyDictObject), "");
class ConstantVRegInfo { class CodeConstants {
private: private:
std::vector<Box*> constants; std::vector<Box*> constants;
public: public:
ConstantVRegInfo(){}; CodeConstants() {}
Box* getConstant(int vreg) const { return constants[-(vreg + 1)]; } Box* getConstant(int vreg) const { return constants[-(vreg + 1)]; }
// returns the vreg num for the constant (which is a negative number) // returns the vreg num for the constant (which is a negative number)
int addConstant(Box* o) { int createVRegEntryForConstant(Box* o) {
constants.push_back(o); constants.push_back(o);
return -constants.size(); return -constants.size();
} }
...@@ -1096,7 +1096,7 @@ public: ...@@ -1096,7 +1096,7 @@ public:
class BoxedCode : public Box { class BoxedCode : public Box {
public: public:
std::unique_ptr<SourceInfo> source; // source can be NULL for functions defined in the C/C++ runtime std::unique_ptr<SourceInfo> source; // source can be NULL for functions defined in the C/C++ runtime
const ConstantVRegInfo BORROWED(constant_vregs); // keeps track of all constants inside the bytecode const CodeConstants BORROWED(code_constants); // keeps track of all constants inside the bytecode
BoxedString* filename = nullptr; BoxedString* filename = nullptr;
BoxedString* name = nullptr; BoxedString* name = nullptr;
...@@ -1135,8 +1135,7 @@ public: ...@@ -1135,8 +1135,7 @@ public:
// Constructor for Python code objects: // Constructor for Python code objects:
BoxedCode(int num_args, bool takes_varargs, bool takes_kwargs, int firstlineno, std::unique_ptr<SourceInfo> source, BoxedCode(int num_args, bool takes_varargs, bool takes_kwargs, int firstlineno, std::unique_ptr<SourceInfo> source,
ConstantVRegInfo constant_vregs, ParamNames param_names, BoxedString* filename, BoxedString* name, CodeConstants code_constants, ParamNames param_names, BoxedString* filename, BoxedString* name, Box* doc);
Box* doc);
// Constructor for code objects created by the runtime: // Constructor for code objects created by the runtime:
BoxedCode(int num_args, bool takes_varargs, bool takes_kwargs, const char* name, const char* doc = "", BoxedCode(int num_args, bool takes_varargs, bool takes_kwargs, const char* name, const char* doc = "",
......
...@@ -254,7 +254,7 @@ extern "C" void dumpEx(void* p, int levels) { ...@@ -254,7 +254,7 @@ extern "C" void dumpEx(void* p, int levels) {
printf("Defined at %s:%d\n", code->filename->c_str(), code->firstlineno); printf("Defined at %s:%d\n", code->filename->c_str(), code->firstlineno);
if (code->source->cfg && levels > 0) { if (code->source->cfg && levels > 0) {
code->source->cfg->print(code->constant_vregs); code->source->cfg->print(code->code_constants);
} }
} else { } else {
printf("A builtin function\n"); printf("A builtin function\n");
......
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