Commit 464c98e7 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #969 from kmod/unboxed3

Reenable unboxed values
parents 40c4e710 96555a1e
...@@ -57,15 +57,13 @@ ConcreteCompilerType* NullTypeAnalysis::getTypeAtBlockEnd(InternedString name, C ...@@ -57,15 +57,13 @@ ConcreteCompilerType* NullTypeAnalysis::getTypeAtBlockEnd(InternedString name, C
// Note: the behavior of this function must match irgenerator.cpp::unboxVar() // Note: the behavior of this function must match irgenerator.cpp::unboxVar()
static ConcreteCompilerType* unboxedType(ConcreteCompilerType* t) { static CompilerType* unboxedType(ConcreteCompilerType* t) {
if (t == BOXED_BOOL) if (t == BOXED_BOOL)
return BOOL; return BOOL;
#if ENABLE_UNBOXED_VALUES
if (t == BOXED_INT) if (t == BOXED_INT)
return INT; return INT;
if (t == BOXED_FLOAT) if (t == BOXED_FLOAT)
return FLOAT; return FLOAT;
#endif
return t; return t;
} }
...@@ -117,17 +115,17 @@ private: ...@@ -117,17 +115,17 @@ private:
assert(speculation != TypeAnalysis::NONE); assert(speculation != TypeAnalysis::NONE);
if (speculated_cls != NULL && speculated_cls->is_constant) { if (speculated_cls != NULL && speculated_cls->is_constant) {
ConcreteCompilerType* speculated_type = unboxedType(typeFromClass(speculated_cls)); CompilerType* speculated_type = unboxedType(typeFromClass(speculated_cls));
if (!old_type->canConvertTo(speculated_type)) {
if (VERBOSITY() >= 2) { if (VERBOSITY() >= 2) {
printf("in propagator, speculating that %s would actually be %s, at ", old_type->debugName().c_str(), printf("in propagator, speculating that %s would actually be %s, at ",
speculated_type->debugName().c_str()); old_type->debugName().c_str(), speculated_type->debugName().c_str());
fflush(stdout); fflush(stdout);
print_ast(node); print_ast(node);
llvm::outs().flush(); llvm::outs().flush();
printf("\n"); printf("\n");
} }
if (!old_type->canConvertTo(speculated_type)) {
type_speculations[node] = speculated_cls; type_speculations[node] = speculated_cls;
return speculated_type; return speculated_type;
} }
...@@ -147,6 +145,7 @@ private: ...@@ -147,6 +145,7 @@ private:
} }
expr_types[node] = rtn; expr_types[node] = rtn;
assert(rtn->isUsable());
return rtn; return rtn;
} }
...@@ -163,10 +162,12 @@ private: ...@@ -163,10 +162,12 @@ private:
} }
expr_types[node] = rtn; expr_types[node] = rtn;
assert(rtn->isUsable());
return rtn; return rtn;
} }
void _doSet(InternedString target, CompilerType* t) { void _doSet(InternedString target, CompilerType* t) {
assert(t->isUsable());
if (t) if (t)
sym_table[target] = t; sym_table[target] = t;
} }
...@@ -196,7 +197,7 @@ private: ...@@ -196,7 +197,7 @@ private:
} }
} }
void* visit_ellipsis(AST_Ellipsis* node) override { return ELLIPSIS; } void* visit_ellipsis(AST_Ellipsis* node) override { return typeFromClass(ellipsis_cls); }
void* visit_attribute(AST_Attribute* node) override { void* visit_attribute(AST_Attribute* node) override {
CompilerType* t = getType(node->value); CompilerType* t = getType(node->value);
......
This diff is collapsed.
...@@ -47,7 +47,7 @@ public: ...@@ -47,7 +47,7 @@ public:
virtual std::string debugName() = 0; virtual std::string debugName() = 0;
virtual ConcreteCompilerType* getConcreteType() = 0; virtual ConcreteCompilerType* getConcreteType() = 0;
virtual ConcreteCompilerType* getBoxType() = 0; virtual ConcreteCompilerType* getBoxType() = 0;
virtual bool canConvertTo(ConcreteCompilerType* other_type) = 0; virtual bool canConvertTo(CompilerType* other_type) = 0;
virtual CompilerType* getattrType(BoxedString* attr, bool cls_only) = 0; virtual CompilerType* getattrType(BoxedString* attr, bool cls_only) = 0;
virtual CompilerType* getPystonIterType(); virtual CompilerType* getPystonIterType();
virtual Result hasattr(BoxedString* attr); virtual Result hasattr(BoxedString* attr);
...@@ -58,6 +58,13 @@ public: ...@@ -58,6 +58,13 @@ public:
virtual Box* deserializeFromFrame(const FrameVals& vals) = 0; virtual Box* deserializeFromFrame(const FrameVals& vals) = 0;
virtual int numFrameArgs() = 0; virtual int numFrameArgs() = 0;
virtual std::vector<CompilerType*> unpackTypes(int num_into); virtual std::vector<CompilerType*> unpackTypes(int num_into);
// Some types are not "usable" even if they are "concrete". Concrete means that it's possible to
// represent the value as an llvm::Value*; usable means that we are allowed to use it as a variable's
// type. Some concrete types are not usable; for example unboxed ints are concrete (can be represented
// as an i64) but are not usable, since we need to use the form that remembers what it gets boxed to.
virtual CompilerType* getUsableType() { return this; }
bool isUsable() { return this == getUsableType(); }
}; };
typedef std::unordered_map<CompilerVariable*, CompilerVariable*> DupCache; typedef std::unordered_map<CompilerVariable*, CompilerVariable*> DupCache;
...@@ -94,7 +101,7 @@ public: ...@@ -94,7 +101,7 @@ public:
printf("grab not defined for %s\n", debugName().c_str()); printf("grab not defined for %s\n", debugName().c_str());
abort(); abort();
} }
bool canConvertTo(ConcreteCompilerType* other_type) override { bool canConvertTo(CompilerType* other_type) override {
printf("canConvertTo not defined for %s\n", debugName().c_str()); printf("canConvertTo not defined for %s\n", debugName().c_str());
abort(); abort();
} }
...@@ -102,13 +109,12 @@ public: ...@@ -102,13 +109,12 @@ public:
printf("makeConverted not defined for %s\n", debugName().c_str()); printf("makeConverted not defined for %s\n", debugName().c_str());
abort(); abort();
} }
virtual ConcreteCompilerVariable* nonzero(IREmitter& emitter, const OpInfo& info, VAR* var) { virtual CompilerVariable* nonzero(IREmitter& emitter, const OpInfo& info, VAR* var) {
printf("nonzero not defined for %s\n", debugName().c_str()); printf("nonzero not defined for %s\n", debugName().c_str());
abort(); abort();
} }
virtual ConcreteCompilerVariable* unaryop(IREmitter& emitter, const OpInfo& info, VAR* var, virtual CompilerVariable* unaryop(IREmitter& emitter, const OpInfo& info, VAR* var, AST_TYPE::AST_TYPE op_type);
AST_TYPE::AST_TYPE op_type); virtual CompilerVariable* hasnext(IREmitter& emitter, const OpInfo& info, VAR* var) {
virtual ConcreteCompilerVariable* hasnext(IREmitter& emitter, const OpInfo& info, VAR* var) {
printf("hasnext not defined for %s\n", debugName().c_str()); printf("hasnext not defined for %s\n", debugName().c_str());
abort(); abort();
} }
...@@ -139,7 +145,7 @@ public: ...@@ -139,7 +145,7 @@ public:
printf("call not defined for %s\n", debugName().c_str()); printf("call not defined for %s\n", debugName().c_str());
abort(); abort();
} }
virtual ConcreteCompilerVariable* len(IREmitter& emitter, const OpInfo& info, VAR* var) { virtual CompilerVariable* len(IREmitter& emitter, const OpInfo& info, VAR* var) {
printf("len not defined for %s\n", debugName().c_str()); printf("len not defined for %s\n", debugName().c_str());
abort(); abort();
} }
...@@ -202,7 +208,7 @@ public: ...@@ -202,7 +208,7 @@ public:
CompilerVariable* dup(ConcreteCompilerVariable* v, DupCache& cache) override; CompilerVariable* dup(ConcreteCompilerVariable* v, DupCache& cache) override;
ConcreteCompilerType* getConcreteType() override { return this; } ConcreteCompilerType* getConcreteType() override { return this; }
bool canConvertTo(ConcreteCompilerType* other_type) override { return other_type == this || other_type == UNKNOWN; } bool canConvertTo(CompilerType* other_type) override { return other_type == this || other_type == UNKNOWN; }
ConcreteCompilerVariable* makeConverted(IREmitter& emitter, ConcreteCompilerVariable* var, ConcreteCompilerVariable* makeConverted(IREmitter& emitter, ConcreteCompilerVariable* var,
ConcreteCompilerType* other_type) override; ConcreteCompilerType* other_type) override;
void serializeToFrame(VAR* var, std::vector<llvm::Value*>& stackmap_args) override; void serializeToFrame(VAR* var, std::vector<llvm::Value*>& stackmap_args) override;
...@@ -261,14 +267,14 @@ public: ...@@ -261,14 +267,14 @@ public:
virtual CompilerType* getType() = 0; virtual CompilerType* getType() = 0;
virtual ConcreteCompilerType* getConcreteType() = 0; virtual ConcreteCompilerType* getConcreteType() = 0;
virtual ConcreteCompilerType* getBoxType() = 0; virtual ConcreteCompilerType* getBoxType() = 0;
virtual bool canConvertTo(ConcreteCompilerType* other_type) = 0; virtual bool canConvertTo(CompilerType* other_type) = 0;
virtual ConcreteCompilerVariable* makeConverted(IREmitter& emitter, ConcreteCompilerType* other_type) = 0; virtual ConcreteCompilerVariable* makeConverted(IREmitter& emitter, ConcreteCompilerType* other_type) = 0;
virtual llvm::Value* makeClassCheck(IREmitter& emitter, BoxedClass* cls) = 0; virtual llvm::Value* makeClassCheck(IREmitter& emitter, BoxedClass* cls) = 0;
virtual BoxedClass* guaranteedClass() = 0; virtual BoxedClass* guaranteedClass() = 0;
virtual ConcreteCompilerVariable* nonzero(IREmitter& emitter, const OpInfo& info) = 0; virtual CompilerVariable* nonzero(IREmitter& emitter, const OpInfo& info) = 0;
virtual ConcreteCompilerVariable* unaryop(IREmitter& emitter, const OpInfo& info, AST_TYPE::AST_TYPE op_type) = 0; virtual CompilerVariable* unaryop(IREmitter& emitter, const OpInfo& info, AST_TYPE::AST_TYPE op_type) = 0;
virtual ConcreteCompilerVariable* hasnext(IREmitter& emitter, const OpInfo& info) = 0; virtual CompilerVariable* hasnext(IREmitter& emitter, const OpInfo& info) = 0;
virtual CompilerVariable* getattr(IREmitter& emitter, const OpInfo& info, BoxedString* attr, bool cls_only) = 0; virtual CompilerVariable* getattr(IREmitter& emitter, const OpInfo& info, BoxedString* attr, bool cls_only) = 0;
virtual void setattr(IREmitter& emitter, const OpInfo& info, BoxedString* attr, CompilerVariable* v) = 0; virtual void setattr(IREmitter& emitter, const OpInfo& info, BoxedString* attr, CompilerVariable* v) = 0;
virtual void delattr(IREmitter& emitter, const OpInfo& info, BoxedString* attr) = 0; virtual void delattr(IREmitter& emitter, const OpInfo& info, BoxedString* attr) = 0;
...@@ -278,7 +284,7 @@ public: ...@@ -278,7 +284,7 @@ public:
virtual CompilerVariable* call(IREmitter& emitter, const OpInfo& info, struct ArgPassSpec argspec, virtual CompilerVariable* call(IREmitter& emitter, const OpInfo& info, struct ArgPassSpec argspec,
const std::vector<CompilerVariable*>& args, const std::vector<CompilerVariable*>& args,
const std::vector<BoxedString*>* keyword_names) = 0; const std::vector<BoxedString*>* keyword_names) = 0;
virtual ConcreteCompilerVariable* len(IREmitter& emitter, const OpInfo& info) = 0; virtual CompilerVariable* len(IREmitter& emitter, const OpInfo& info) = 0;
virtual CompilerVariable* getitem(IREmitter& emitter, const OpInfo& info, CompilerVariable*) = 0; virtual CompilerVariable* getitem(IREmitter& emitter, const OpInfo& info, CompilerVariable*) = 0;
virtual CompilerVariable* getPystonIter(IREmitter& emitter, const OpInfo& info) = 0; virtual CompilerVariable* getPystonIter(IREmitter& emitter, const OpInfo& info) = 0;
virtual CompilerVariable* binexp(IREmitter& emitter, const OpInfo& info, CompilerVariable* rhs, virtual CompilerVariable* binexp(IREmitter& emitter, const OpInfo& info, CompilerVariable* rhs,
...@@ -330,19 +336,19 @@ public: ...@@ -330,19 +336,19 @@ public:
return rtn; return rtn;
} }
bool canConvertTo(ConcreteCompilerType* other_type) override { return type->canConvertTo(other_type); } bool canConvertTo(CompilerType* other_type) override { return type->canConvertTo(other_type); }
ConcreteCompilerVariable* makeConverted(IREmitter& emitter, ConcreteCompilerType* other_type) override { ConcreteCompilerVariable* makeConverted(IREmitter& emitter, ConcreteCompilerType* other_type) override {
ConcreteCompilerVariable* rtn = type->makeConverted(emitter, this, other_type); ConcreteCompilerVariable* rtn = type->makeConverted(emitter, this, other_type);
ASSERT(rtn->getType() == other_type, "%s", type->debugName().c_str()); ASSERT(rtn->getType() == other_type, "%s", type->debugName().c_str());
return rtn; return rtn;
} }
ConcreteCompilerVariable* nonzero(IREmitter& emitter, const OpInfo& info) override { CompilerVariable* nonzero(IREmitter& emitter, const OpInfo& info) override {
return type->nonzero(emitter, info, this); return type->nonzero(emitter, info, this);
} }
ConcreteCompilerVariable* unaryop(IREmitter& emitter, const OpInfo& info, AST_TYPE::AST_TYPE op_type) override { CompilerVariable* unaryop(IREmitter& emitter, const OpInfo& info, AST_TYPE::AST_TYPE op_type) override {
return type->unaryop(emitter, info, this, op_type); return type->unaryop(emitter, info, this, op_type);
} }
ConcreteCompilerVariable* hasnext(IREmitter& emitter, const OpInfo& info) override { CompilerVariable* hasnext(IREmitter& emitter, const OpInfo& info) override {
return type->hasnext(emitter, info, this); return type->hasnext(emitter, info, this);
} }
CompilerVariable* getattr(IREmitter& emitter, const OpInfo& info, BoxedString* attr, bool cls_only) override { CompilerVariable* getattr(IREmitter& emitter, const OpInfo& info, BoxedString* attr, bool cls_only) override {
...@@ -366,9 +372,7 @@ public: ...@@ -366,9 +372,7 @@ public:
const std::vector<BoxedString*>* keyword_names) override { const std::vector<BoxedString*>* keyword_names) override {
return type->call(emitter, info, this, argspec, args, keyword_names); return type->call(emitter, info, this, argspec, args, keyword_names);
} }
ConcreteCompilerVariable* len(IREmitter& emitter, const OpInfo& info) override { CompilerVariable* len(IREmitter& emitter, const OpInfo& info) override { return type->len(emitter, info, this); }
return type->len(emitter, info, this);
}
CompilerVariable* getitem(IREmitter& emitter, const OpInfo& info, CompilerVariable* slice) override { CompilerVariable* getitem(IREmitter& emitter, const OpInfo& info, CompilerVariable* slice) override {
return type->getitem(emitter, info, this, slice); return type->getitem(emitter, info, this, slice);
} }
...@@ -407,9 +411,20 @@ public: ...@@ -407,9 +411,20 @@ public:
// Emit the test for whether one variable 'is' another one. // Emit the test for whether one variable 'is' another one.
ConcreteCompilerVariable* doIs(IREmitter& emitter, CompilerVariable* lhs, CompilerVariable* rhs, bool negate); ConcreteCompilerVariable* doIs(IREmitter& emitter, CompilerVariable* lhs, CompilerVariable* rhs, bool negate);
// These functions all return an INT variable, from either an unboxed representation (makeInt) or
// a boxed representation (makeUnboxedInt)
CompilerVariable* makeInt(int64_t);
CompilerVariable* makeInt(llvm::Value*);
CompilerVariable* makeUnboxedInt(IREmitter&, ConcreteCompilerVariable*);
CompilerVariable* makeUnboxedInt(IREmitter&, llvm::Value*);
// Same for floats:
CompilerVariable* makeFloat(llvm::Value*);
CompilerVariable* makeFloat(double);
CompilerVariable* makeUnboxedFloat(IREmitter&, ConcreteCompilerVariable*);
CompilerVariable* makeUnboxedFloat(IREmitter&, llvm::Value*);
ConcreteCompilerVariable* makeBool(bool); ConcreteCompilerVariable* makeBool(bool);
ConcreteCompilerVariable* makeInt(int64_t);
ConcreteCompilerVariable* makeFloat(double);
ConcreteCompilerVariable* makeLong(Box*); ConcreteCompilerVariable* makeLong(Box*);
ConcreteCompilerVariable* makePureImaginary(Box*); ConcreteCompilerVariable* makePureImaginary(Box*);
CompilerVariable* makeStr(BoxedString*); CompilerVariable* makeStr(BoxedString*);
...@@ -447,7 +462,7 @@ CompilerVariable* _ValuedCompilerType<V>::contains(IREmitter& emitter, const OpI ...@@ -447,7 +462,7 @@ CompilerVariable* _ValuedCompilerType<V>::contains(IREmitter& emitter, const OpI
} }
template <typename V> template <typename V>
ConcreteCompilerVariable* _ValuedCompilerType<V>::unaryop(IREmitter& emitter, const OpInfo& info, VAR* var, CompilerVariable* _ValuedCompilerType<V>::unaryop(IREmitter& emitter, const OpInfo& info, VAR* var,
AST_TYPE::AST_TYPE op_type) { AST_TYPE::AST_TYPE op_type) {
ConcreteCompilerVariable* converted = makeConverted(emitter, var, getBoxType()); ConcreteCompilerVariable* converted = makeConverted(emitter, var, getBoxType());
auto r = UNKNOWN->unaryop(emitter, info, converted, op_type); auto r = UNKNOWN->unaryop(emitter, info, converted, op_type);
......
...@@ -799,7 +799,7 @@ private: ...@@ -799,7 +799,7 @@ private:
assert(node->args.size() == 1); assert(node->args.size() == 1);
CompilerVariable* obj = evalExpr(node->args[0], unw_info); CompilerVariable* obj = evalExpr(node->args[0], unw_info);
ConcreteCompilerVariable* rtn = obj->nonzero(emitter, getOpInfoForNode(node, unw_info)); CompilerVariable* rtn = obj->nonzero(emitter, getOpInfoForNode(node, unw_info));
obj->decvref(emitter); obj->decvref(emitter);
return rtn; return rtn;
} }
...@@ -807,7 +807,7 @@ private: ...@@ -807,7 +807,7 @@ private:
assert(node->args.size() == 1); assert(node->args.size() == 1);
CompilerVariable* obj = evalExpr(node->args[0], unw_info); CompilerVariable* obj = evalExpr(node->args[0], unw_info);
ConcreteCompilerVariable* rtn = obj->hasnext(emitter, getOpInfoForNode(node, unw_info)); CompilerVariable* rtn = obj->hasnext(emitter, getOpInfoForNode(node, unw_info));
obj->decvref(emitter); obj->decvref(emitter);
return rtn; return rtn;
} }
...@@ -1348,18 +1348,18 @@ private: ...@@ -1348,18 +1348,18 @@ private:
CompilerVariable* operand = evalExpr(node->operand, unw_info); CompilerVariable* operand = evalExpr(node->operand, unw_info);
if (node->op_type == AST_TYPE::Not) { if (node->op_type == AST_TYPE::Not) {
ConcreteCompilerVariable* rtn = operand->nonzero(emitter, getOpInfoForNode(node, unw_info)); CompilerVariable* rtn = operand->nonzero(emitter, getOpInfoForNode(node, unw_info));
operand->decvref(emitter); operand->decvref(emitter);
assert(rtn->getType() == BOOL); assert(rtn->getType() == BOOL);
llvm::Value* v = i1FromBool(emitter, rtn); llvm::Value* v = i1FromBool(emitter, static_cast<ConcreteCompilerVariable*>(rtn));
assert(v->getType() == g.i1); assert(v->getType() == g.i1);
llvm::Value* negated = emitter.getBuilder()->CreateNot(v); llvm::Value* negated = emitter.getBuilder()->CreateNot(v);
rtn->decvref(emitter); rtn->decvref(emitter);
return boolFromI1(emitter, negated); return boolFromI1(emitter, negated);
} else { } else {
ConcreteCompilerVariable* rtn = operand->unaryop(emitter, getOpInfoForNode(node, unw_info), node->op_type); CompilerVariable* rtn = operand->unaryop(emitter, getOpInfoForNode(node, unw_info), node->op_type);
operand->decvref(emitter); operand->decvref(emitter);
return rtn; return rtn;
} }
...@@ -1517,19 +1517,13 @@ private: ...@@ -1517,19 +1517,13 @@ private:
} }
// Note: the behavior of this function must match type_analysis.cpp:unboxedType() // Note: the behavior of this function must match type_analysis.cpp:unboxedType()
ConcreteCompilerVariable* unboxVar(ConcreteCompilerType* t, llvm::Value* v, bool grabbed) { CompilerVariable* unboxVar(ConcreteCompilerType* t, llvm::Value* v, bool grabbed) {
#if ENABLE_UNBOXED_VALUES
if (t == BOXED_INT) { if (t == BOXED_INT) {
llvm::Value* unboxed = emitter.getBuilder()->CreateCall(g.funcs.unboxInt, v); return makeUnboxedInt(emitter, v);
ConcreteCompilerVariable* rtn = new ConcreteCompilerVariable(INT, unboxed, true);
return rtn;
} }
if (t == BOXED_FLOAT) { if (t == BOXED_FLOAT) {
llvm::Value* unboxed = emitter.getBuilder()->CreateCall(g.funcs.unboxFloat, v); return makeUnboxedFloat(emitter, v);
ConcreteCompilerVariable* rtn = new ConcreteCompilerVariable(FLOAT, unboxed, true);
return rtn;
} }
#endif
if (t == BOXED_BOOL) { if (t == BOXED_BOOL) {
llvm::Value* unboxed = emitter.getBuilder()->CreateCall(g.funcs.unboxBool, v); llvm::Value* unboxed = emitter.getBuilder()->CreateCall(g.funcs.unboxBool, v);
return boolFromI1(emitter, unboxed); return boolFromI1(emitter, unboxed);
...@@ -1548,7 +1542,7 @@ private: ...@@ -1548,7 +1542,7 @@ private:
ConcreteCompilerType* speculated_type = typeFromClass(speculated_class); ConcreteCompilerType* speculated_type = typeFromClass(speculated_class);
if (VERBOSITY("irgen") >= 2) { if (VERBOSITY("irgen") >= 2) {
printf("Speculating that %s is actually %s, at ", rtn->getConcreteType()->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_ast(node); print_ast(node);
...@@ -1580,6 +1574,7 @@ private: ...@@ -1580,6 +1574,7 @@ private:
} }
assert(rtn); assert(rtn);
assert(rtn->getType()->isUsable());
return rtn; return rtn;
} }
...@@ -1728,6 +1723,7 @@ private: ...@@ -1728,6 +1723,7 @@ private:
void _doSet(InternedString name, CompilerVariable* val, const UnwindInfo& unw_info) { void _doSet(InternedString name, CompilerVariable* val, const UnwindInfo& unw_info) {
assert(name.s() != "None"); assert(name.s() != "None");
assert(name.s() != FRAME_INFO_PTR_NAME); assert(name.s() != FRAME_INFO_PTR_NAME);
assert(val->getType()->isUsable());
auto scope_info = irstate->getScopeInfo(); auto scope_info = irstate->getScopeInfo();
ScopeInfo::VarScopeType vst = scope_info->getScopeTypeOfName(name); ScopeInfo::VarScopeType vst = scope_info->getScopeTypeOfName(name);
...@@ -2210,11 +2206,9 @@ private: ...@@ -2210,11 +2206,9 @@ private:
ConcreteCompilerVariable* var = p.second->makeConverted(emitter, p.second->getConcreteType()); ConcreteCompilerVariable* var = p.second->makeConverted(emitter, p.second->getConcreteType());
converted_args.push_back(var); converted_args.push_back(var);
#if ENABLE_UNBOXED_VALUES assert(var->getType() != BOXED_INT);
assert(var->getType() != BOXED_INT && "should probably unbox it, but why is it boxed in the first place?");
assert(var->getType() != BOXED_FLOAT assert(var->getType() != BOXED_FLOAT
&& "should probably unbox it, but why is it boxed in the first place?"); && "should probably unbox it, but why is it boxed in the first place?");
#endif
// This line can never get hit right now for the same reason that the variables must already be // This line can never get hit right now for the same reason that the variables must already be
// concrete, // concrete,
...@@ -2438,13 +2432,13 @@ private: ...@@ -2438,13 +2432,13 @@ private:
void loadArgument(InternedString name, ConcreteCompilerType* t, llvm::Value* v, const UnwindInfo& unw_info) { void loadArgument(InternedString name, ConcreteCompilerType* t, llvm::Value* v, const UnwindInfo& unw_info) {
assert(name.s() != FRAME_INFO_PTR_NAME); assert(name.s() != FRAME_INFO_PTR_NAME);
ConcreteCompilerVariable* var = unboxVar(t, v, false); CompilerVariable* var = unboxVar(t, v, false);
_doSet(name, var, unw_info); _doSet(name, var, unw_info);
var->decvref(emitter); var->decvref(emitter);
} }
void loadArgument(AST_expr* name, ConcreteCompilerType* t, llvm::Value* v, const UnwindInfo& unw_info) { void loadArgument(AST_expr* name, ConcreteCompilerType* t, llvm::Value* v, const UnwindInfo& unw_info) {
ConcreteCompilerVariable* var = unboxVar(t, v, false); CompilerVariable* var = unboxVar(t, v, false);
_doSet(name, var, unw_info); _doSet(name, var, unw_info);
var->decvref(emitter); var->decvref(emitter);
} }
...@@ -2467,6 +2461,7 @@ private: ...@@ -2467,6 +2461,7 @@ private:
std::map<InternedString, CompilerVariable*> sorted_symbol_table(symbol_table.begin(), symbol_table.end()); std::map<InternedString, CompilerVariable*> sorted_symbol_table(symbol_table.begin(), symbol_table.end());
for (const auto& p : sorted_symbol_table) { for (const auto& p : sorted_symbol_table) {
assert(p.first.s() != FRAME_INFO_PTR_NAME); assert(p.first.s() != FRAME_INFO_PTR_NAME);
assert(p.second->getType()->isUsable());
if (allowableFakeEndingSymbol(p.first)) if (allowableFakeEndingSymbol(p.first))
continue; continue;
...@@ -2483,6 +2478,7 @@ private: ...@@ -2483,6 +2478,7 @@ private:
} else if (irstate->getPhis()->isRequiredAfter(p.first, myblock)) { } else if (irstate->getPhis()->isRequiredAfter(p.first, myblock)) {
assert(scope_info->getScopeTypeOfName(p.first) != ScopeInfo::VarScopeType::GLOBAL); assert(scope_info->getScopeTypeOfName(p.first) != ScopeInfo::VarScopeType::GLOBAL);
ConcreteCompilerType* phi_type = types->getTypeAtBlockEnd(p.first, myblock); ConcreteCompilerType* phi_type = types->getTypeAtBlockEnd(p.first, myblock);
assert(phi_type->isUsable());
// printf("Converting %s from %s to %s\n", p.first.c_str(), // printf("Converting %s from %s to %s\n", p.first.c_str(),
// p.second->getType()->debugName().c_str(), phi_type->debugName().c_str()); // p.second->getType()->debugName().c_str(), phi_type->debugName().c_str());
// printf("have to convert %s from %s to %s\n", p.first.c_str(), // printf("have to convert %s from %s to %s\n", p.first.c_str(),
...@@ -2533,6 +2529,7 @@ private: ...@@ -2533,6 +2529,7 @@ private:
} else { } else {
// printf("no st entry, setting undefined\n"); // printf("no st entry, setting undefined\n");
ConcreteCompilerType* phi_type = types->getTypeAtBlockEnd(*it, myblock); ConcreteCompilerType* phi_type = types->getTypeAtBlockEnd(*it, myblock);
assert(phi_type->isUsable());
cur = new ConcreteCompilerVariable(phi_type, llvm::UndefValue::get(phi_type->llvmType()), true); cur = new ConcreteCompilerVariable(phi_type, llvm::UndefValue::get(phi_type->llvmType()), true);
_setFake(defined_name, makeBool(0)); _setFake(defined_name, makeBool(0));
} }
...@@ -2553,7 +2550,7 @@ public: ...@@ -2553,7 +2550,7 @@ public:
pp->addFrameVar(PASSED_GLOBALS_NAME, UNKNOWN); pp->addFrameVar(PASSED_GLOBALS_NAME, UNKNOWN);
} }
assert(INT->llvmType() == g.i64); assert(UNBOXED_INT->llvmType() == g.i64);
if (ENABLE_JIT_OBJECT_CACHE) { if (ENABLE_JIT_OBJECT_CACHE) {
llvm::Value* v; llvm::Value* v;
if (current_stmt) if (current_stmt)
...@@ -2565,7 +2562,7 @@ public: ...@@ -2565,7 +2562,7 @@ public:
stackmap_args.push_back(getConstantInt((uint64_t)current_stmt, g.i64)); stackmap_args.push_back(getConstantInt((uint64_t)current_stmt, g.i64));
} }
pp->addFrameVar("!current_stmt", INT); pp->addFrameVar("!current_stmt", UNBOXED_INT);
if (ENABLE_FRAME_INTROSPECTION) { if (ENABLE_FRAME_INTROSPECTION) {
// TODO: don't need to use a sorted symbol table if we're explicitly recording the names! // TODO: don't need to use a sorted symbol table if we're explicitly recording the names!
...@@ -2600,6 +2597,10 @@ public: ...@@ -2600,6 +2597,10 @@ public:
// This should have been consumed: // This should have been consumed:
assert(incoming_exc_state.empty()); assert(incoming_exc_state.empty());
for (auto&& p : symbol_table) {
ASSERT(p.second->getType()->isUsable(), "%s", p.first.c_str());
}
if (myblock->successors.size() == 0) { if (myblock->successors.size() == 0) {
for (auto& p : *st) { for (auto& p : *st) {
p.second->decvref(emitter); p.second->decvref(emitter);
...@@ -2645,6 +2646,7 @@ public: ...@@ -2645,6 +2646,7 @@ public:
} else { } else {
ending_type = types->getTypeAtBlockEnd(it->first, myblock); ending_type = types->getTypeAtBlockEnd(it->first, myblock);
} }
assert(ending_type->isUsable());
//(*phi_st)[it->first] = it->second->makeConverted(emitter, it->second->getConcreteType()); //(*phi_st)[it->first] = it->second->makeConverted(emitter, it->second->getConcreteType());
// printf("%s %p %d\n", it->first.c_str(), it->second, it->second->getVrefs()); // printf("%s %p %d\n", it->first.c_str(), it->second, it->second->getVrefs());
(*phi_st)[it->first] = it->second->split(emitter)->makeConverted(emitter, ending_type); (*phi_st)[it->first] = it->second->split(emitter)->makeConverted(emitter, ending_type);
...@@ -2661,10 +2663,9 @@ public: ...@@ -2661,10 +2663,9 @@ public:
assert(name.s() != FRAME_INFO_PTR_NAME); assert(name.s() != FRAME_INFO_PTR_NAME);
ASSERT(irstate->getScopeInfo()->getScopeTypeOfName(name) != ScopeInfo::VarScopeType::GLOBAL, "%s", ASSERT(irstate->getScopeInfo()->getScopeTypeOfName(name) != ScopeInfo::VarScopeType::GLOBAL, "%s",
name.c_str()); name.c_str());
#if ENABLE_UNBOXED_VALUES
assert(var->getType() != BOXED_INT); ASSERT(var->getType()->isUsable(), "%s", name.c_str());
assert(var->getType() != BOXED_FLOAT);
#endif
CompilerVariable*& cur = symbol_table[name]; CompilerVariable*& cur = symbol_table[name];
assert(cur == NULL); assert(cur == NULL);
cur = var; cur = var;
...@@ -2675,7 +2676,9 @@ public: ...@@ -2675,7 +2676,9 @@ public:
DupCache cache; DupCache cache;
for (SymbolTable::iterator it = st->begin(); it != st->end(); ++it) { for (SymbolTable::iterator it = st->begin(); it != st->end(); ++it) {
// printf("Copying in %s: %p, %d\n", it->first.c_str(), it->second, it->second->getVrefs()); // printf("Copying in %s: %p, %d\n", it->first.c_str(), it->second, it->second->getVrefs());
// printf("Copying in %s, a %s\n", it->first.c_str(), it->second->getType()->debugName().c_str());
symbol_table[it->first] = it->second->dup(cache); symbol_table[it->first] = it->second->dup(cache);
assert(symbol_table[it->first]->getType()->isUsable());
// printf("got: %p, %d\n", symbol_table[it->first], symbol_table[it->first]->getVrefs()); // printf("got: %p, %d\n", symbol_table[it->first], symbol_table[it->first]->getVrefs());
} }
} }
......
...@@ -51,12 +51,6 @@ extern bool ENABLE_ICS, ENABLE_ICGENERICS, ENABLE_ICGETITEMS, ENABLE_ICSETITEMS, ...@@ -51,12 +51,6 @@ extern bool ENABLE_ICS, ENABLE_ICGENERICS, ENABLE_ICGETITEMS, ENABLE_ICSETITEMS,
extern bool BOOLS_AS_I64; extern bool BOOLS_AS_I64;
#define ENABLE_SAMPLING_PROFILER 0 #define ENABLE_SAMPLING_PROFILER 0
// Our current implementation of unbox values has some minor compatibility issues, where it can
// change the apparent id() / is-equality of a boxed value (by inserting extra unbox+box pairs).
// I think it can be rescued (we need the unboxed compilertype to remember the boxed value),
// but for now it's just turned off with this flag.
#define ENABLE_UNBOXED_VALUES 0
} }
} }
......
...@@ -93,10 +93,10 @@ template <class V> class ValuedCompilerType; ...@@ -93,10 +93,10 @@ template <class V> class ValuedCompilerType;
typedef ValuedCompilerType<llvm::Value*> ConcreteCompilerType; typedef ValuedCompilerType<llvm::Value*> ConcreteCompilerType;
ConcreteCompilerType* typeFromClass(BoxedClass*); ConcreteCompilerType* typeFromClass(BoxedClass*);
extern ConcreteCompilerType* INT, *BOXED_INT, *LONG, *FLOAT, *BOXED_FLOAT, *UNKNOWN, *BOOL, *STR, *NONE, *LIST, *SLICE,*ELLIPSIS, extern ConcreteCompilerType* UNBOXED_INT, *BOXED_INT, *LONG, *UNBOXED_FLOAT, *BOXED_FLOAT, *UNKNOWN, *BOOL, *STR, *NONE,
*MODULE, *DICT, *BOOL, *BOXED_BOOL, *BOXED_TUPLE, *SET, *FROZENSET, *CLOSURE, *GENERATOR, *BOXED_COMPLEX, *LIST, *SLICE, *MODULE, *DICT, *BOOL, *BOXED_BOOL, *BOXED_TUPLE, *SET, *FROZENSET, *CLOSURE, *GENERATOR,
*FRAME_INFO; *BOXED_COMPLEX, *FRAME_INFO;
extern CompilerType* UNDEF; extern CompilerType* UNDEF, *INT, *FLOAT;
class CompilerVariable; class CompilerVariable;
template <class V> class ValuedCompilerVariable; template <class V> class ValuedCompilerVariable;
......
...@@ -1524,12 +1524,16 @@ Box* builtinFormat(Box* value, Box* format_spec) { ...@@ -1524,12 +1524,16 @@ Box* builtinFormat(Box* value, Box* format_spec) {
return res; return res;
} }
extern "C" {
BoxedClass* ellipsis_cls;
}
void setupBuiltins() { void setupBuiltins() {
builtins_module = createModule(boxString("__builtin__"), NULL, builtins_module = createModule(boxString("__builtin__"), NULL,
"Built-in functions, exceptions, and other objects.\n\nNoteworthy: None is " "Built-in functions, exceptions, and other objects.\n\nNoteworthy: None is "
"the `nil' object; Ellipsis represents `...' in slices."); "the `nil' object; Ellipsis represents `...' in slices.");
BoxedClass* ellipsis_cls = BoxedClass::create(type_cls, object_cls, NULL, 0, 0, sizeof(Box), false, "ellipsis"); ellipsis_cls = BoxedClass::create(type_cls, object_cls, NULL, 0, 0, sizeof(Box), false, "ellipsis");
ellipsis_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)ellipsisRepr, STR, 1))); ellipsis_cls->giveAttr("__repr__", new BoxedFunction(boxRTFunction((void*)ellipsisRepr, STR, 1)));
Ellipsis = new (ellipsis_cls) Box(); Ellipsis = new (ellipsis_cls) Box();
assert(Ellipsis->cls); assert(Ellipsis->cls);
......
...@@ -270,7 +270,7 @@ void setupXrange() { ...@@ -270,7 +270,7 @@ void setupXrange() {
"__iter__", new BoxedFunction(boxRTFunction((void*)xrangeIterIter, typeFromClass(xrange_iterator_cls), 1))); "__iter__", new BoxedFunction(boxRTFunction((void*)xrangeIterIter, typeFromClass(xrange_iterator_cls), 1)));
xrange_iterator_cls->giveAttr("__hasnext__", new BoxedFunction(hasnext)); xrange_iterator_cls->giveAttr("__hasnext__", new BoxedFunction(hasnext));
CLFunction* next = boxRTFunction((void*)BoxedXrangeIterator::xrangeIteratorNextUnboxed, INT, 1); CLFunction* next = boxRTFunction((void*)BoxedXrangeIterator::xrangeIteratorNextUnboxed, UNBOXED_INT, 1);
addRTFunction(next, (void*)BoxedXrangeIterator::xrangeIteratorNext, BOXED_INT); addRTFunction(next, (void*)BoxedXrangeIterator::xrangeIteratorNext, BOXED_INT);
xrange_iterator_cls->giveAttr("next", new BoxedFunction(next)); xrange_iterator_cls->giveAttr("next", new BoxedFunction(next));
......
...@@ -42,6 +42,14 @@ def f4(a, b): ...@@ -42,6 +42,14 @@ def f4(a, b):
for i in xrange(11000): for i in xrange(11000):
f4(1000, 1000) f4(1000, 1000)
def f6():
for i in xrange(11000):
a = b = 1000
if True:
pass
f4(a, b)
f6()
# This applies to other data types as well. (maybe should call this test file something else) # This applies to other data types as well. (maybe should call this test file something else)
def ident(x): def ident(x):
...@@ -49,7 +57,7 @@ def ident(x): ...@@ -49,7 +57,7 @@ def ident(x):
def f5(): def f5():
t = (1, 2, 3) t = (1, 2, 3)
print ident(t) is t assert ident(t) is t
for i in xrange(10): for i in xrange(10):
f5() f5()
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