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

rename ConstantVRegInfo to CodeConstants

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