Commit cefce6a5 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Rip out the vestiges of the old vref-counting system

parent c9b0d8f9
......@@ -117,9 +117,7 @@ public:
static CompilerVariable* makeIM(CompilerVariable* obj, CompilerVariable* func, CompilerVariable* im_class) {
CompilerVariable* rtn = new ValuedCompilerVariable<RawInstanceMethod*>(
InstanceMethodType::get(obj->getType(), func->getType()), new RawInstanceMethod(obj, func, im_class), true);
obj->incvref();
func->incvref();
InstanceMethodType::get(obj->getType(), func->getType()), new RawInstanceMethod(obj, func, im_class));
return rtn;
}
......@@ -136,14 +134,6 @@ public:
return "instanceMethod(" + obj_type->debugName() + " ; " + function_type->debugName() + ")";
}
void drop(IREmitter& emitter, VAR* var) override {
checkVar(var);
RawInstanceMethod* val = var->getValue();
val->obj->decvref(emitter);
val->func->decvref(emitter);
delete val;
}
CompilerVariable* call(IREmitter& emitter, const OpInfo& info, ValuedCompilerVariable<RawInstanceMethod*>* var,
ArgPassSpec argspec, const std::vector<CompilerVariable*>& args,
const std::vector<BoxedString*>* keyword_names) override {
......@@ -172,10 +162,7 @@ public:
llvm::Value* boxed = emitter.getBuilder()->CreateCall3(g.funcs.boxInstanceMethod, obj->getValue(),
func->getValue(), im_class->getValue());
obj->decvref(emitter);
func->decvref(emitter);
return new ConcreteCompilerVariable(other_type, boxed, true);
return new ConcreteCompilerVariable(other_type, boxed);
}
CompilerVariable* dup(VAR* var, DupCache& cache) override {
checkVar(var);
......@@ -185,9 +172,7 @@ public:
RawInstanceMethod* im = var->getValue();
RawInstanceMethod* new_im
= new RawInstanceMethod(im->obj->dup(cache), im->func->dup(cache), im->im_class->dup(cache));
rtn = new VAR(this, new_im, var->isGrabbed());
while (rtn->getVrefs() < var->getVrefs())
rtn->incvref();
rtn = new VAR(this, new_im);
}
return rtn;
}
......@@ -209,7 +194,6 @@ std::unordered_map<std::pair<CompilerType*, CompilerType*>, InstanceMethodType*>
ConcreteCompilerVariable* ConcreteCompilerType::makeConverted(IREmitter& emitter, ConcreteCompilerVariable* var,
ConcreteCompilerType* other_type) {
if (other_type == this) {
var->incvref();
return var;
}
printf("makeConverted not defined for %s\n", debugName().c_str());
......@@ -218,9 +202,7 @@ ConcreteCompilerVariable* ConcreteCompilerType::makeConverted(IREmitter& emitter
CompilerVariable* ConcreteCompilerType::dup(ConcreteCompilerVariable* v, DupCache& cache) {
auto& rtn = cache[v];
if (rtn == NULL) {
rtn = new ConcreteCompilerVariable(this, v->getValue(), v->isGrabbed());
while (rtn->getVrefs() < v->getVrefs())
rtn->incvref();
rtn = new ConcreteCompilerVariable(this, v->getValue());
}
return rtn;
}
......@@ -231,9 +213,6 @@ public:
std::string debugName() override { return "AnyBox"; }
void drop(IREmitter& emitter, VAR* var) override { emitter.getGC()->dropPointer(emitter, var->getValue()); }
void grab(IREmitter& emitter, VAR* var) override { emitter.getGC()->grabPointer(emitter, var->getValue()); }
bool isFitBy(BoxedClass* c) override { return true; }
CompilerVariable* getattr(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var, BoxedString* attr,
......@@ -270,7 +249,6 @@ public:
} else {
emitter.createCall3(info.unw_info, g.funcs.setattr, var->getValue(), ptr, converted->getValue());
}
converted->decvref(emitter);
}
void delattr(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var, BoxedString* attr) override {
......@@ -317,7 +295,6 @@ public:
ConcreteCompilerVariable* makeConverted(IREmitter& emitter, ConcreteCompilerVariable* var,
ConcreteCompilerType* other_type) override {
if (other_type == this) {
var->incvref();
return var;
}
fprintf(stderr, "Can't convert unknown to %s...\n", other_type->debugName().c_str());
......@@ -363,7 +340,7 @@ public:
emitter.checkAndPropagateCapiException(info.unw_info, r, getNullPtr(g.llvm_value_type_ptr));
return new ConcreteCompilerVariable(static_cast<ConcreteCompilerType*>(return_type), r, true);
return new ConcreteCompilerVariable(static_cast<ConcreteCompilerType*>(return_type), r);
}
}
......@@ -389,12 +366,11 @@ public:
target_exception_style == CAPI ? g.funcs.getitem_capi : g.funcs.getitem,
var->getValue(), converted_slice->getValue(), target_exception_style);
}
converted_slice->decvref(emitter);
if (target_exception_style == CAPI)
emitter.checkAndPropagateCapiException(info.unw_info, rtn, getNullPtr(g.llvm_value_type_ptr));
return new ConcreteCompilerVariable(UNKNOWN, rtn, true);
return new ConcreteCompilerVariable(UNKNOWN, rtn);
}
CompilerVariable* getPystonIter(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var) override {
......@@ -407,7 +383,6 @@ public:
// If the type analysis could determine the iter type is a valid pyston iter (has 'hasnext') we are finished.
CompilerType* iter_type = var->getType()->getPystonIterType();
if (iter_type != UNKNOWN) {
iter_call->decvref(emitter);
return converted_iter_call;
}
......@@ -444,10 +419,7 @@ public:
phi->addIncoming(value_has_iter, value_has_iter_bb);
phi->addIncoming(value_no_iter, value_no_iter_bb);
converted_iter_call->decvref(emitter);
iter_call->decvref(emitter);
return new ConcreteCompilerVariable(UNKNOWN, phi, true);
return new ConcreteCompilerVariable(UNKNOWN, phi);
}
CompilerVariable* binexp(IREmitter& emitter, const OpInfo& info, VAR* var, CompilerVariable* rhs,
......@@ -485,15 +457,13 @@ public:
getConstantInt(op_type, g.i32));
}
converted_rhs->decvref(emitter);
if (op_type == AST_TYPE::In || op_type == AST_TYPE::NotIn || op_type == AST_TYPE::Is
|| op_type == AST_TYPE::IsNot) {
llvm::Value* unboxed = emitter.getBuilder()->CreateCall(g.funcs.unboxBool, rtn);
return boolFromI1(emitter, unboxed);
}
return new ConcreteCompilerVariable(UNKNOWN, rtn, true);
return new ConcreteCompilerVariable(UNKNOWN, rtn);
}
CompilerVariable* contains(IREmitter& emitter, const OpInfo& info, VAR* var, CompilerVariable* lhs) override {
......@@ -516,7 +486,7 @@ public:
llvm::Value* val = emitter.getBuilder()->CreateLoad(ptr);
assert(val->getType() == g.llvm_value_type_ptr);
rtn.push_back(new ConcreteCompilerVariable(UNKNOWN, val, true));
rtn.push_back(new ConcreteCompilerVariable(UNKNOWN, val));
}
return rtn;
}
......@@ -569,7 +539,7 @@ CompilerVariable* UnknownType::getattr(IREmitter& emitter, const OpInfo& info, C
if (target_exception_style == CAPI)
emitter.checkAndPropagateCapiException(info.unw_info, rtn_val, getNullPtr(g.llvm_value_type_ptr));
return new ConcreteCompilerVariable(UNKNOWN, rtn_val, true);
return new ConcreteCompilerVariable(UNKNOWN, rtn_val);
}
static ConcreteCompilerVariable* _call(IREmitter& emitter, const OpInfo& info, llvm::Value* func,
......@@ -669,17 +639,13 @@ static ConcreteCompilerVariable* _call(IREmitter& emitter, const OpInfo& info, l
rtn = emitter.createCall(info.unw_info, func, llvm_args, target_exception_style);
}
for (int i = 0; i < args.size(); i++) {
converted_args[i]->decvref(emitter);
}
assert(rtn->getType() == rtn_type->llvmType());
if (target_exception_style == CAPI) {
emitter.checkAndPropagateCapiException(info.unw_info, rtn, getNullPtr(g.llvm_value_type_ptr));
}
return new ConcreteCompilerVariable(rtn_type, rtn, true);
return new ConcreteCompilerVariable(rtn_type, rtn);
}
CompilerVariable* UnknownType::call(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var,
......@@ -787,9 +753,7 @@ ConcreteCompilerVariable* UnknownType::unaryop(IREmitter& emitter, const OpInfo&
getConstantInt(op_type, g.i32));
}
converted->decvref(emitter);
return new ConcreteCompilerVariable(UNKNOWN, rtn, true);
return new ConcreteCompilerVariable(UNKNOWN, rtn);
}
ConcreteCompilerVariable* UnknownType::hasnext(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var) {
......@@ -848,9 +812,7 @@ CompilerVariable* makeFunction(IREmitter& emitter, FunctionMetadata* f, Compiler
std::vector<llvm::Value*>{ embedRelocatablePtr(f, g.llvm_functionmetadata_type_ptr), closure_v, globals,
scratch, getConstantInt(defaults.size(), g.i64) });
if (convertedClosure)
convertedClosure->decvref(emitter);
return new ConcreteCompilerVariable(typeFromClass(function_cls), boxed, true);
return new ConcreteCompilerVariable(typeFromClass(function_cls), boxed);
}
class AbstractFunctionType : public CompilerType {
......@@ -965,22 +927,12 @@ public:
// Subclasses need to implement:
// _makeConverted
// _dup
// _drop
// _numFrameArgs
// _serializeToFrame
// _deserializeFromFrame
typedef UnboxedVal<T> Unboxed;
typedef typename ValuedCompilerType<std::shared_ptr<UnboxedVal<T>>>::VAR VAR;
void drop(IREmitter& emitter, VAR* var) override final {
auto v = var->getValue();
if (v->boxed)
v->boxed->decvref(emitter);
static_cast<D*>(this)->_drop(emitter, v->val);
}
void grab(IREmitter& emitter, VAR* var) override final { RELEASE_ASSERT(0, ""); }
void assertMatches(std::shared_ptr<Unboxed> val) override final {
static_cast<D*>(this)->_assertMatches(val->val);
assert(!val->boxed || val->boxed->getType() == static_cast<D*>(this)->getBoxType());
......@@ -999,9 +951,7 @@ public:
auto val
= std::make_shared<Unboxed>(std::move(val_duped), static_cast<ConcreteCompilerVariable*>(box_duped));
rtn = new VAR(this, val, var->isGrabbed());
while (rtn->getVrefs() < var->getVrefs())
rtn->incvref();
rtn = new VAR(this, val);
}
return rtn;
}
......@@ -1032,7 +982,6 @@ public:
return boxed->makeConverted(emitter, other_type);
}
boxed->incvref();
return boxed;
}
......@@ -1082,8 +1031,6 @@ class IntType : public UnboxedType<llvm::Value*, IntType> {
public:
IntType() {}
void _drop(IREmitter& emitter, llvm::Value* v) {}
llvm::Value* _dup(llvm::Value* v, DupCache& cache) { return v; }
void _assertMatches(llvm::Value* v) { assert(v->getType() == g.i64); }
......@@ -1145,7 +1092,6 @@ public:
const std::vector<BoxedString*>* keyword_names) override {
ConcreteCompilerVariable* converted = var->makeConverted(emitter, BOXED_INT);
CompilerVariable* rtn = converted->callattr(emitter, info, attr, flags, args, keyword_names);
converted->decvref(emitter);
return rtn;
}
......@@ -1153,7 +1099,6 @@ public:
bool cls_only) override {
ConcreteCompilerVariable* converted = var->makeConverted(emitter, BOXED_INT);
CompilerVariable* rtn = converted->getattr(emitter, info, attr, cls_only);
converted->decvref(emitter);
return rtn;
}
......@@ -1180,13 +1125,12 @@ public:
} else {
boxed = emitter.getBuilder()->CreateCall(g.funcs.boxInt, unboxed);
}
return new ConcreteCompilerVariable(other_type, boxed, true);
return new ConcreteCompilerVariable(other_type, boxed);
}
CompilerVariable* getitem(IREmitter& emitter, const OpInfo& info, VAR* var, CompilerVariable* slice) override {
ConcreteCompilerVariable* converted = var->makeConverted(emitter, BOXED_INT);
CompilerVariable* rtn = converted->getitem(emitter, info, slice);
converted->decvref(emitter);
return rtn;
}
......@@ -1218,7 +1162,6 @@ public:
ConcreteCompilerVariable* converted = var->makeConverted(emitter, BOXED_INT);
auto rtn = converted->unaryop(emitter, info, op_type);
converted->decvref(emitter);
return rtn;
}
......@@ -1238,7 +1181,6 @@ public:
ConcreteCompilerVariable* converted = var->makeConverted(emitter, BOXED_INT);
CompilerVariable* rtn = converted->binexp(emitter, info, rhs, op_type, exp_type);
converted->decvref(emitter);
return rtn;
}
......@@ -1326,7 +1268,7 @@ public:
llvm::CallSite call
= emitter.createCall(info.unw_info, g.funcs.raiseNotIterableError, embedConstantPtr("int", g.i8_ptr));
call.setDoesNotReturn();
return new ConcreteCompilerVariable(BOOL, llvm::UndefValue::get(BOOL->llvmType()), true);
return new ConcreteCompilerVariable(BOOL, llvm::UndefValue::get(BOOL->llvmType()));
}
ConcreteCompilerType* getBoxType() override { return BOXED_INT; }
......@@ -1350,7 +1292,7 @@ CompilerType* INT = &_INT;
CompilerVariable* makeInt(llvm::Value* n) {
assert(n->getType() == g.i64);
return new IntType::VAR(&_INT, std::make_shared<IntType::Unboxed>(n, nullptr), true);
return new IntType::VAR(&_INT, std::make_shared<IntType::Unboxed>(n, nullptr));
}
CompilerVariable* makeInt(int64_t n) {
......@@ -1360,12 +1302,12 @@ CompilerVariable* makeInt(int64_t n) {
CompilerVariable* makeUnboxedInt(IREmitter& emitter, ConcreteCompilerVariable* v) {
assert(v->getType() == BOXED_INT);
llvm::Value* unboxed = emitter.getBuilder()->CreateCall(g.funcs.unboxInt, v->getValue());
return new IntType::VAR(&_INT, std::make_shared<IntType::Unboxed>(unboxed, v), true);
return new IntType::VAR(&_INT, std::make_shared<IntType::Unboxed>(unboxed, v));
}
CompilerVariable* makeUnboxedInt(IREmitter& emitter, llvm::Value* v) {
assert(v->getType() == g.llvm_value_type_ptr);
return makeUnboxedInt(emitter, new ConcreteCompilerVariable(BOXED_INT, v, false));
return makeUnboxedInt(emitter, new ConcreteCompilerVariable(BOXED_INT, v));
}
class FloatType : public UnboxedType<llvm::Value*, FloatType> {
......@@ -1374,10 +1316,6 @@ public:
std::string debugName() override { return "float"; }
void _drop(IREmitter& emitter, llvm::Value* v) {
// pass
}
void _assertMatches(llvm::Value* v) { assert(v->getType() == g.double_); }
llvm::Value* _dup(llvm::Value* v, DupCache& cache) { return v; }
......@@ -1420,7 +1358,6 @@ public:
bool cls_only) override {
ConcreteCompilerVariable* converted = var->makeConverted(emitter, BOXED_FLOAT);
CompilerVariable* rtn = converted->getattr(emitter, info, attr, cls_only);
converted->decvref(emitter);
return rtn;
}
......@@ -1429,7 +1366,6 @@ public:
const std::vector<BoxedString*>* keyword_names) override {
ConcreteCompilerVariable* converted = var->makeConverted(emitter, BOXED_FLOAT);
CompilerVariable* rtn = converted->callattr(emitter, info, attr, flags, args, keyword_names);
converted->decvref(emitter);
return rtn;
}
......@@ -1458,7 +1394,7 @@ public:
} else {
boxed = emitter.getBuilder()->CreateCall(g.funcs.boxFloat, unboxed);
}
return new ConcreteCompilerVariable(other_type, boxed, true);
return new ConcreteCompilerVariable(other_type, boxed);
}
ConcreteCompilerVariable* nonzero(IREmitter& emitter, const OpInfo& info, VAR* var) override {
......@@ -1470,14 +1406,12 @@ public:
CompilerVariable* unaryop(IREmitter& emitter, const OpInfo& info, VAR* var, AST_TYPE::AST_TYPE op_type) override {
ConcreteCompilerVariable* converted = var->makeConverted(emitter, BOXED_FLOAT);
auto rtn = converted->unaryop(emitter, info, op_type);
converted->decvref(emitter);
return rtn;
}
CompilerVariable* getitem(IREmitter& emitter, const OpInfo& info, VAR* var, CompilerVariable* slice) override {
ConcreteCompilerVariable* converted = var->makeConverted(emitter, BOXED_FLOAT);
CompilerVariable* rtn = converted->getitem(emitter, info, slice);
converted->decvref(emitter);
return rtn;
}
......@@ -1488,7 +1422,6 @@ public:
if (rhs->getType() != INT && rhs->getType() != FLOAT) {
ConcreteCompilerVariable* converted = var->makeConverted(emitter, BOXED_FLOAT);
CompilerVariable* rtn = converted->binexp(emitter, info, rhs, op_type, exp_type);
converted->decvref(emitter);
return rtn;
}
......@@ -1585,7 +1518,6 @@ public:
// TODO duplication with top of function, other functions, etc
ConcreteCompilerVariable* converted = var->makeConverted(emitter, BOXED_FLOAT);
CompilerVariable* rtn = converted->binexp(emitter, info, rhs, op_type, exp_type);
converted->decvref(emitter);
return rtn;
}
......@@ -1593,7 +1525,7 @@ public:
llvm::CallSite call
= emitter.createCall(info.unw_info, g.funcs.raiseNotIterableError, embedConstantPtr("float", g.i8_ptr));
call.setDoesNotReturn();
return new ConcreteCompilerVariable(BOOL, llvm::UndefValue::get(BOOL->llvmType()), true);
return new ConcreteCompilerVariable(BOOL, llvm::UndefValue::get(BOOL->llvmType()));
}
ConcreteCompilerType* getBoxType() override { return BOXED_FLOAT; }
......@@ -1633,7 +1565,7 @@ ConcreteCompilerType* UNBOXED_FLOAT = new PhonyUnboxedType(llvm::Type::getDouble
CompilerVariable* makeFloat(llvm::Value* n) {
assert(n->getType() == g.double_);
return new FloatType::VAR(&_FLOAT, std::make_shared<FloatType::Unboxed>(n, nullptr), true);
return new FloatType::VAR(&_FLOAT, std::make_shared<FloatType::Unboxed>(n, nullptr));
}
CompilerVariable* makeFloat(double n) {
......@@ -1643,21 +1575,21 @@ CompilerVariable* makeFloat(double n) {
CompilerVariable* makeUnboxedFloat(IREmitter& emitter, ConcreteCompilerVariable* v) {
assert(v->getType() == BOXED_FLOAT);
llvm::Value* unboxed = emitter.getBuilder()->CreateCall(g.funcs.unboxFloat, v->getValue());
return new FloatType::VAR(&_FLOAT, std::make_shared<FloatType::Unboxed>(unboxed, v), true);
return new FloatType::VAR(&_FLOAT, std::make_shared<FloatType::Unboxed>(unboxed, v));
}
CompilerVariable* makeUnboxedFloat(IREmitter& emitter, llvm::Value* v) {
assert(v->getType() == g.llvm_value_type_ptr);
return makeUnboxedFloat(emitter, new ConcreteCompilerVariable(BOXED_FLOAT, v, false));
return makeUnboxedFloat(emitter, new ConcreteCompilerVariable(BOXED_FLOAT, v));
}
ConcreteCompilerVariable* makeLong(Box* v) {
return new ConcreteCompilerVariable(LONG, embedRelocatablePtr(v, g.llvm_value_type_ptr), true);
return new ConcreteCompilerVariable(LONG, embedRelocatablePtr(v, g.llvm_value_type_ptr));
}
ConcreteCompilerVariable* makePureImaginary(Box* v) {
return new ConcreteCompilerVariable(BOXED_COMPLEX, embedRelocatablePtr(v, g.llvm_value_type_ptr), true);
return new ConcreteCompilerVariable(BOXED_COMPLEX, embedRelocatablePtr(v, g.llvm_value_type_ptr));
}
class KnownClassobjType : public ValuedCompilerType<BoxedClass*> {
......@@ -1726,17 +1658,12 @@ public:
ConcreteCompilerVariable* makeConverted(IREmitter& emitter, ConcreteCompilerVariable* var,
ConcreteCompilerType* other_type) override {
if (other_type == this) {
var->incvref();
return var;
}
ASSERT(other_type == UNKNOWN, "%s", other_type->debugName().c_str());
return new ConcreteCompilerVariable(UNKNOWN, var->getValue(), false);
// return (new ConcreteCompilerVariable(UNKNOWN, var->getValue(), false))->split(emitter);
return new ConcreteCompilerVariable(UNKNOWN, var->getValue());
}
void drop(IREmitter& emitter, VAR* var) override { emitter.getGC()->dropPointer(emitter, var->getValue()); }
void grab(IREmitter& emitter, VAR* var) override { emitter.getGC()->grabPointer(emitter, var->getValue()); }
bool isFitBy(BoxedClass* c) override {
// I don't think it's ok to accept subclasses
return c == cls;
......@@ -1795,11 +1722,11 @@ public:
ASSERT(rtattr, "%s.%s", debugName().c_str(), attr->data());
if (rtattr->cls == function_cls) {
CompilerVariable* clattr = new ConcreteCompilerVariable(
typeFromClass(function_cls), embedRelocatablePtr(rtattr, g.llvm_value_type_ptr), false);
typeFromClass(function_cls), embedRelocatablePtr(rtattr, g.llvm_value_type_ptr));
return InstanceMethodType::makeIM(
var, clattr,
new ConcreteCompilerVariable(UNKNOWN, embedRelocatablePtr(cls, g.llvm_value_type_ptr), false));
new ConcreteCompilerVariable(UNKNOWN, embedRelocatablePtr(cls, g.llvm_value_type_ptr)));
}
}
......@@ -1821,7 +1748,6 @@ public:
const std::vector<BoxedString*>* keyword_names) override {
ConcreteCompilerVariable* converted = var->makeConverted(emitter, UNKNOWN);
CompilerVariable* rtn = converted->call(emitter, info, argspec, args, keyword_names);
converted->decvref(emitter);
return rtn;
}
......@@ -1949,7 +1875,7 @@ public:
else
llvm_value = getNullPtr(g.llvm_value_type_ptr);
new_args.push_back(new ConcreteCompilerVariable(UNKNOWN, llvm_value, true));
new_args.push_back(new ConcreteCompilerVariable(UNKNOWN, llvm_value));
}
std::vector<llvm::Value*> other_args;
......@@ -1993,7 +1919,6 @@ public:
ConcreteCompilerVariable* converted = var->makeConverted(emitter, UNKNOWN);
CompilerVariable* rtn = converted->callattr(emitter, info, attr, flags, args, keyword_names);
converted->decvref(emitter);
return rtn;
}
......@@ -2021,20 +1946,17 @@ public:
// Kind of hacky, but just call into getitem like normal. except...
auto r = UNKNOWN->binexp(emitter, info, var, converted_rhs, op_type, exp_type);
r->decvref(emitter);
// ... return the undef value, since that matches what the type analyzer thought we would do.
return called_constant;
}
if (called_constant) {
converted_rhs->decvref(emitter);
return called_constant;
}
}
}
auto rtn = UNKNOWN->binexp(emitter, info, var, converted_rhs, op_type, exp_type);
converted_rhs->decvref(emitter);
return rtn;
}
......@@ -2087,7 +2009,7 @@ public:
var->getValue(), start, stop);
emitter.checkAndPropagateCapiException(info.unw_info, r, getNullPtr(g.llvm_value_type_ptr));
return new ConcreteCompilerVariable(static_cast<ConcreteCompilerType*>(return_type), r, true);
return new ConcreteCompilerVariable(static_cast<ConcreteCompilerType*>(return_type), r);
}
}
}
......@@ -2106,7 +2028,6 @@ public:
// Kind of hacky, but just call into getitem like normal. except...
auto r = UNKNOWN->getitem(emitter, info, var, slice);
r->decvref(emitter);
// ... return the undef value, since that matches what the type analyzer thought we would do.
return called_constant;
}
......@@ -2227,9 +2148,6 @@ public:
ConcreteCompilerType* getConcreteType() override { return this; }
ConcreteCompilerType* getBoxType() override { return this; }
void drop(IREmitter& emitter, VAR* var) override {}
void grab(IREmitter& emitter, VAR* var) override {}
Box* deserializeFromFrame(const FrameVals& vals) override {
assert(vals.size() == 1);
return reinterpret_cast<Box*>(vals[0]);
......@@ -2245,13 +2163,6 @@ public:
ConcreteCompilerType* getConcreteType() override { return this; }
ConcreteCompilerType* getBoxType() override { return GENERATOR; }
void drop(IREmitter& emitter, VAR* var) override {
// pass
}
void grab(IREmitter& emitter, VAR* var) override {
// pass
}
Box* deserializeFromFrame(const FrameVals& vals) override {
assert(vals.size() == numFrameArgs());
return reinterpret_cast<Box*>(vals[0]);
......@@ -2267,13 +2178,6 @@ public:
ConcreteCompilerType* getConcreteType() override { return this; }
ConcreteCompilerType* getBoxType() override { return FRAME_INFO; }
void drop(IREmitter& emitter, VAR* var) override {
// pass
}
void grab(IREmitter& emitter, VAR* var) override {
// pass
}
Box* deserializeFromFrame(const FrameVals& vals) override {
RELEASE_ASSERT(false, "should not be called"); // This function shouldn't be called.
}
......@@ -2290,18 +2194,10 @@ public:
ConcreteCompilerType* getBoxType() override { return STR; }
void drop(IREmitter& emitter, VAR* var) override {
// pass
}
void grab(IREmitter& emitter, VAR* var) override {
// pass
}
ConcreteCompilerVariable* makeConverted(IREmitter& emitter, VAR* var, ConcreteCompilerType* other_type) override {
assert(other_type == STR || other_type == UNKNOWN);
llvm::Value* boxed = embedRelocatablePtr(var->getValue(), g.llvm_value_type_ptr);
return new ConcreteCompilerVariable(other_type, boxed, true);
return new ConcreteCompilerVariable(other_type, boxed);
}
bool canConvertTo(CompilerType* other) override { return (other == STR || other == UNKNOWN); }
......@@ -2310,7 +2206,6 @@ public:
bool cls_only) override {
ConcreteCompilerVariable* converted = var->makeConverted(emitter, STR);
CompilerVariable* rtn = converted->getattr(emitter, info, attr, cls_only);
converted->decvref(emitter);
return rtn;
}
......@@ -2319,14 +2214,12 @@ public:
const std::vector<BoxedString*>* keyword_names) override {
ConcreteCompilerVariable* converted = var->makeConverted(emitter, STR);
CompilerVariable* rtn = converted->callattr(emitter, info, attr, flags, args, keyword_names);
converted->decvref(emitter);
return rtn;
}
CompilerVariable* getitem(IREmitter& emitter, const OpInfo& info, VAR* var, CompilerVariable* slice) override {
ConcreteCompilerVariable* converted = var->makeConverted(emitter, STR);
CompilerVariable* rtn = converted->getitem(emitter, info, slice);
converted->decvref(emitter);
return rtn;
}
......@@ -2334,14 +2227,12 @@ public:
AST_TYPE::AST_TYPE op_type, BinExpType exp_type) override {
ConcreteCompilerVariable* converted = var->makeConverted(emitter, STR);
CompilerVariable* rtn = converted->binexp(emitter, info, rhs, op_type, exp_type);
converted->decvref(emitter);
return rtn;
}
CompilerVariable* contains(IREmitter& emitter, const OpInfo& info, VAR* var, CompilerVariable* lhs) override {
ConcreteCompilerVariable* converted = var->makeConverted(emitter, STR);
CompilerVariable* rtn = converted->contains(emitter, info, lhs);
converted->decvref(emitter);
return rtn;
}
......@@ -2353,9 +2244,7 @@ public:
CompilerVariable*& rtn = cache[var];
if (rtn == NULL) {
rtn = new VAR(this, var->getValue(), var->isGrabbed());
while (rtn->getVrefs() < var->getVrefs())
rtn->incvref();
rtn = new VAR(this, var->getValue());
}
return rtn;
}
......@@ -2385,7 +2274,7 @@ public:
static ValuedCompilerType<BoxedString*>* STR_CONSTANT = new StrConstantType();
CompilerVariable* makeStr(BoxedString* s) {
return new ValuedCompilerVariable<BoxedString*>(STR_CONSTANT, s, true);
return new ValuedCompilerVariable<BoxedString*>(STR_CONSTANT, s);
}
ConcreteCompilerType* typeFromClass(BoxedClass* c) {
......@@ -2405,15 +2294,7 @@ public:
bool isFitBy(BoxedClass* c) override { return false; }
void drop(IREmitter& emitter, VAR* var) override {
// pass
}
void grab(IREmitter& emitter, VAR* var) override {
// pass
}
ConcreteCompilerVariable* nonzero(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var) override {
var->incvref();
return var;
}
......@@ -2424,7 +2305,6 @@ public:
ConcreteCompilerVariable* makeConverted(IREmitter& emitter, ConcreteCompilerVariable* var,
ConcreteCompilerType* other_type) override {
if (other_type == BOOL) {
var->incvref();
return var;
}
......@@ -2432,7 +2312,7 @@ public:
llvm::Value* boxed = emitter.getBuilder()->CreateSelect(i1FromBool(emitter, var),
embedConstantPtr(True, g.llvm_value_type_ptr),
embedConstantPtr(False, g.llvm_value_type_ptr));
return new ConcreteCompilerVariable(other_type, boxed, true);
return new ConcreteCompilerVariable(other_type, boxed);
}
CompilerType* getattrType(BoxedString* attr, bool cls_only) override {
......@@ -2443,7 +2323,6 @@ public:
bool cls_only) override {
ConcreteCompilerVariable* converted = var->makeConverted(emitter, BOXED_BOOL);
CompilerVariable* rtn = converted->getattr(emitter, info, attr, cls_only);
converted->decvref(emitter);
return rtn;
}
......@@ -2452,7 +2331,6 @@ public:
const std::vector<BoxedString*>* keyword_names) override {
ConcreteCompilerVariable* converted = var->makeConverted(emitter, BOXED_BOOL);
CompilerVariable* rtn = converted->callattr(emitter, info, attr, flags, args, keyword_names);
converted->decvref(emitter);
return rtn;
}
......@@ -2460,7 +2338,6 @@ public:
AST_TYPE::AST_TYPE op_type, BinExpType exp_type) override {
ConcreteCompilerVariable* converted = var->makeConverted(emitter, UNKNOWN);
CompilerVariable* rtn = converted->binexp(emitter, info, rhs, op_type, exp_type);
converted->decvref(emitter);
return rtn;
}
......@@ -2468,7 +2345,7 @@ public:
llvm::CallSite call
= emitter.createCall(info.unw_info, g.funcs.raiseNotIterableError, embedConstantPtr("bool", g.i8_ptr));
call.setDoesNotReturn();
return new ConcreteCompilerVariable(BOOL, llvm::UndefValue::get(BOOL->llvmType()), true);
return new ConcreteCompilerVariable(BOOL, llvm::UndefValue::get(BOOL->llvmType()));
}
ConcreteCompilerType* getBoxType() override { return BOXED_BOOL; }
......@@ -2482,7 +2359,7 @@ public:
};
ConcreteCompilerType* BOOL = new BoolType();
ConcreteCompilerVariable* makeBool(bool b) {
return new ConcreteCompilerVariable(BOOL, llvm::ConstantInt::get(BOOL->llvmType(), b, false), true);
return new ConcreteCompilerVariable(BOOL, llvm::ConstantInt::get(BOOL->llvmType(), b, false));
}
ConcreteCompilerVariable* doIs(IREmitter& emitter, CompilerVariable* lhs, CompilerVariable* rhs, bool negate) {
......@@ -2496,9 +2373,6 @@ ConcreteCompilerVariable* doIs(IREmitter& emitter, CompilerVariable* lhs, Compil
else
cmp = emitter.getBuilder()->CreateICmpNE(converted_left->getValue(), converted_right->getValue());
converted_left->decvref(emitter);
converted_right->decvref(emitter);
return boolFromI1(emitter, cmp);
}
......@@ -2533,12 +2407,6 @@ public:
std::string debugName() override { return name; }
void _drop(IREmitter& emitter, const VEC& val) {
for (int i = 0; i < val.size(); i++) {
val[i]->decvref(emitter);
}
}
VEC _dup(const VEC& orig_elts, DupCache& cache) {
std::vector<CompilerVariable*> elts;
......@@ -2576,10 +2444,7 @@ public:
llvm::Value* rtn = emitter.getBuilder()->CreateCall2(g.funcs.createTuple, nelts, scratch);
for (int i = 0; i < converted_args.size(); i++) {
converted_args[i]->decvref(emitter);
}
return new ConcreteCompilerVariable(other_type, rtn, true);
return new ConcreteCompilerVariable(other_type, rtn);
}
ConcreteCompilerType* getBoxType() override { return BOXED_TUPLE; }
......@@ -2597,11 +2462,9 @@ public:
const VEC* elts = &v->val;
if (i >= 0 && i < elts->size()) {
CompilerVariable* rtn = (*elts)[i];
rtn->incvref();
return rtn;
} else if (i < 0 && -i <= elts->size()) {
CompilerVariable* rtn = (*elts)[elts->size() + i];
rtn->incvref();
return rtn;
} else {
ExceptionStyle target_exception_style = info.preferredExceptionStyle();
......@@ -2623,7 +2486,6 @@ public:
ConcreteCompilerVariable* converted = var->makeConverted(emitter, BOXED_TUPLE);
CompilerVariable* rtn = converted->getitem(emitter, info, slice);
converted->decvref(emitter);
return rtn;
}
......@@ -2639,7 +2501,6 @@ public:
AST_TYPE::AST_TYPE op_type, BinExpType exp_type) override {
ConcreteCompilerVariable* converted = var->makeConverted(emitter, UNKNOWN);
CompilerVariable* rtn = converted->binexp(emitter, info, rhs, op_type, exp_type);
converted->decvref(emitter);
return rtn;
}
......@@ -2690,8 +2551,6 @@ public:
phi->addIncoming(p.second, p.first);
}
converted_lhs->decvref(emitter);
return boolFromI1(emitter, phi);
}
......@@ -2739,10 +2598,6 @@ public:
return ValuedCompilerType::unpack(emitter, info, var, num_into);
}
// Not sure if this is right:
for (auto e : var->getValue()->val)
e->incvref();
return var->getValue()->val;
}
......@@ -2762,22 +2617,18 @@ CompilerType* makeTupleType(const std::vector<CompilerType*>& elt_types) {
CompilerVariable* makeTuple(const std::vector<CompilerVariable*>& elts) {
std::vector<CompilerType*> elt_types;
for (int i = 0; i < elts.size(); i++) {
elts[i]->incvref();
elt_types.push_back(elts[i]->getType());
}
TupleType* type = TupleType::make(elt_types);
auto alloc_var = std::make_shared<TupleType::Unboxed>(elts, nullptr);
return new TupleType::VAR(type, alloc_var, true);
return new TupleType::VAR(type, alloc_var);
}
class UnboxedSliceType : public ValuedCompilerType<UnboxedSlice> {
public:
std::string debugName() override { return "slice"; }
void drop(IREmitter& emitter, VAR* var) override {}
void grab(IREmitter& emitter, VAR* var) override {}
void assertMatches(UnboxedSlice slice) {}
int numFrameArgs() override { RELEASE_ASSERT(0, "unboxed slice should never get serialized"); }
......@@ -2811,16 +2662,13 @@ public:
args.push_back(cstep->getValue());
llvm::Value* rtn = emitter.getBuilder()->CreateCall(g.funcs.createSlice, args);
cstart->decvref(emitter);
cstop->decvref(emitter);
cstep->decvref(emitter);
return new ConcreteCompilerVariable(SLICE, rtn, true);
return new ConcreteCompilerVariable(SLICE, rtn);
}
} _UNBOXED_SLICE;
CompilerType* UNBOXED_SLICE = &_UNBOXED_SLICE;
CompilerVariable* makeSlice(CompilerVariable* start, CompilerVariable* stop, CompilerVariable* step) {
return new UnboxedSliceType::VAR(&_UNBOXED_SLICE, UnboxedSlice{ start, stop, step }, true);
return new UnboxedSliceType::VAR(&_UNBOXED_SLICE, UnboxedSlice{ start, stop, step });
}
UnboxedSlice extractSlice(CompilerVariable* slice) {
......@@ -2830,7 +2678,7 @@ UnboxedSlice extractSlice(CompilerVariable* slice) {
ConcreteCompilerVariable* getNone() {
llvm::Constant* none = embedRelocatablePtr(None, g.llvm_value_type_ptr, "cNone");
return new ConcreteCompilerVariable(typeFromClass(none_cls), none, false);
return new ConcreteCompilerVariable(typeFromClass(none_cls), none);
}
class UndefType : public ConcreteCompilerType {
......@@ -2848,21 +2696,17 @@ public:
const std::vector<BoxedString*>* keyword_names) override {
return undefVariable();
}
void drop(IREmitter& emitter, VAR* var) override {}
void grab(IREmitter& emitter, VAR* var) override {}
CompilerVariable* dup(VAR* v, DupCache& cache) override {
// TODO copied from UnknownType
auto& rtn = cache[v];
if (rtn == NULL) {
rtn = new VAR(this, v->getValue(), v->isGrabbed());
while (rtn->getVrefs() < v->getVrefs())
rtn->incvref();
rtn = new VAR(this, v->getValue());
}
return rtn;
}
ConcreteCompilerVariable* makeConverted(IREmitter& emitter, VAR* var, ConcreteCompilerType* other_type) override {
llvm::Value* v = llvm::UndefValue::get(other_type->llvmType());
return new ConcreteCompilerVariable(other_type, v, true);
return new ConcreteCompilerVariable(other_type, v);
}
CompilerVariable* getattr(IREmitter& emitter, const OpInfo& info, VAR* var, BoxedString* attr,
bool cls_only) override {
......@@ -2881,7 +2725,7 @@ public:
}
ConcreteCompilerVariable* nonzero(IREmitter& emitter, const OpInfo& info, VAR* var) override {
return new ConcreteCompilerVariable(BOOL, llvm::UndefValue::get(BOOL->llvmType()), true);
return new ConcreteCompilerVariable(BOOL, llvm::UndefValue::get(BOOL->llvmType()));
}
CompilerVariable* binexp(IREmitter& emitter, const OpInfo& info, VAR* var, CompilerVariable* rhs,
......@@ -2916,7 +2760,7 @@ public:
CompilerType* UNDEF = &_UNDEF;
ConcreteCompilerVariable* undefVariable() {
return new ConcreteCompilerVariable(&_UNDEF, llvm::UndefValue::get(_UNDEF.llvmType()), true);
return new ConcreteCompilerVariable(&_UNDEF, llvm::UndefValue::get(_UNDEF.llvmType()));
}
ConcreteCompilerVariable* boolFromI1(IREmitter& emitter, llvm::Value* v) {
......@@ -2924,9 +2768,9 @@ ConcreteCompilerVariable* boolFromI1(IREmitter& emitter, llvm::Value* v) {
assert(v->getType() == g.i1);
assert(BOOL->llvmType() == g.i64);
llvm::Value* v2 = emitter.getBuilder()->CreateZExt(v, BOOL->llvmType());
return new ConcreteCompilerVariable(BOOL, v2, true);
return new ConcreteCompilerVariable(BOOL, v2);
} else {
return new ConcreteCompilerVariable(BOOL, v, true);
return new ConcreteCompilerVariable(BOOL, v);
}
}
......
......@@ -93,14 +93,6 @@ public:
printf("getBoxType not defined for %s\n", debugName().c_str());
abort();
}
virtual void drop(IREmitter& emmitter, VAR* var) {
printf("drop not defined for %s\n", debugName().c_str());
abort();
}
virtual void grab(IREmitter& emmitter, VAR* var) {
printf("grab not defined for %s\n", debugName().c_str());
abort();
}
bool canConvertTo(CompilerType* other_type) override {
printf("canConvertTo not defined for %s\n", debugName().c_str());
abort();
......@@ -216,52 +208,10 @@ public:
};
class CompilerVariable {
private:
int vrefs;
bool grabbed;
protected:
virtual void drop(IREmitter& emitter) = 0;
virtual void grab(IREmitter& emmitter) = 0;
public:
CompilerVariable(bool grabbed) : vrefs(1), grabbed(grabbed) {}
CompilerVariable() {}
virtual ~CompilerVariable() {}
bool isGrabbed() { return grabbed; }
void incvref() {
assert(vrefs);
vrefs++;
}
void decvrefNodrop() {
assert(vrefs > 0 && vrefs < (1 << 20));
// It'd be nice to print out the type of the variable, but this is all happening
// after the object got deleted so it's pretty precarious, and the getType()
// debugging call will probably segfault:
// ASSERT(vrefs, "%s", getType()->debugName().c_str());
vrefs--;
if (vrefs == 0) {
delete this;
}
}
void decvref(IREmitter& emitter) {
ASSERT(vrefs > 0 && vrefs < (1 << 20), "%d", vrefs);
// ASSERT(vrefs, "%s", getType()->debugName().c_str());
vrefs--;
if (vrefs == 0) {
if (grabbed)
drop(emitter);
delete this;
}
}
int getVrefs() { return vrefs; }
void ensureGrabbed(IREmitter& emitter) {
if (!grabbed) {
grab(emitter);
grabbed = true;
}
}
virtual CompilerVariable* split(IREmitter& emitter) = 0;
virtual CompilerVariable* dup(DupCache& cache) = 0;
virtual CompilerType* getType() = 0;
......@@ -302,12 +252,8 @@ private:
T* type;
V value;
protected:
void drop(IREmitter& emitter) override { type->drop(emitter, this); }
void grab(IREmitter& emitter) override { type->grab(emitter, this); }
public:
ValuedCompilerVariable(T* type, V value, bool grabbed) : CompilerVariable(grabbed), type(type), value(value) {
ValuedCompilerVariable(T* type, V value) : CompilerVariable(), type(type), value(value) {
#ifndef NDEBUG
type->assertMatches(value);
#endif
......@@ -318,21 +264,9 @@ public:
ConcreteCompilerType* getConcreteType() override { return type->getConcreteType(); }
ConcreteCompilerType* getBoxType() override { return type->getBoxType(); }
ValuedCompilerVariable<V>* split(IREmitter& emitter) override {
ValuedCompilerVariable<V>* rtn;
if (getVrefs() == 1) {
rtn = this;
} else {
rtn = new ValuedCompilerVariable<V>(type, value, false);
this->decvref(emitter);
}
rtn->ensureGrabbed(emitter);
return rtn;
}
CompilerVariable* dup(DupCache& cache) override {
CompilerVariable* rtn = type->dup(this, cache);
ASSERT(rtn->getVrefs() == getVrefs(), "%d %s", rtn->getVrefs(), type->debugName().c_str());
return rtn;
}
......@@ -402,12 +336,6 @@ public:
}
};
// template <>
// inline ConcreteCompilerVariable::ValuedCompilerVariable(ConcreteCompilerType *type, llvm::Value* value, bool grabbed)
// : CompilerVariable(grabbed), type(type), value(value) {
// assert(value->getType() == type->llvmType());
//}
// Emit the test for whether one variable 'is' another one.
ConcreteCompilerVariable* doIs(IREmitter& emitter, CompilerVariable* lhs, CompilerVariable* rhs, bool negate);
......@@ -457,7 +385,6 @@ template <typename V>
CompilerVariable* _ValuedCompilerType<V>::getPystonIter(IREmitter& emitter, const OpInfo& info, VAR* var) {
ConcreteCompilerVariable* converted = makeConverted(emitter, var, getBoxType());
auto r = UNKNOWN->getPystonIter(emitter, info, converted);
converted->decvref(emitter);
return r;
}
......@@ -466,7 +393,6 @@ CompilerVariable* _ValuedCompilerType<V>::contains(IREmitter& emitter, const OpI
CompilerVariable* rhs) {
ConcreteCompilerVariable* converted = makeConverted(emitter, var, getBoxType());
auto r = UNKNOWN->contains(emitter, info, converted, rhs);
converted->decvref(emitter);
return r;
}
......@@ -475,7 +401,6 @@ CompilerVariable* _ValuedCompilerType<V>::unaryop(IREmitter& emitter, const OpIn
AST_TYPE::AST_TYPE op_type) {
ConcreteCompilerVariable* converted = makeConverted(emitter, var, getBoxType());
auto r = UNKNOWN->unaryop(emitter, info, converted, op_type);
converted->decvref(emitter);
return r;
}
......@@ -486,7 +411,6 @@ std::vector<CompilerVariable*> _ValuedCompilerType<V>::unpack(IREmitter& emitter
ConcreteCompilerVariable* converted = makeConverted(emitter, var, UNKNOWN);
auto r = UNKNOWN->unpack(emitter, info, converted, num_into);
converted->decvref(emitter);
return r;
}
......
......@@ -452,7 +452,7 @@ static void emitBBs(IRGenState* irstate, TypeAnalysis* types, const OSREntryDesc
ConcreteCompilerType* phi_type;
phi_type = getTypeAtBlockStart(types, p.first, target_block);
ConcreteCompilerVariable* var = new ConcreteCompilerVariable(p.second, from_arg, true);
ConcreteCompilerVariable* var = new ConcreteCompilerVariable(p.second, from_arg);
(*initial_syms)[p.first] = var;
// It's possible to OSR into a version of the function with a higher speculation level;
......@@ -477,7 +477,7 @@ static void emitBBs(IRGenState* irstate, TypeAnalysis* types, const OSREntryDesc
if (VERBOSITY("irgen") >= 2)
v->setName("prev_" + p.first.s());
(*osr_syms)[p.first] = new ConcreteCompilerVariable(phi_type, v, true);
(*osr_syms)[p.first] = new ConcreteCompilerVariable(phi_type, v);
}
entry_emitter->getBuilder()->CreateBr(osr_unbox_block);
......@@ -624,7 +624,7 @@ static void emitBBs(IRGenState* irstate, TypeAnalysis* types, const OSREntryDesc
llvm::PHINode* phi = emitter->getBuilder()->CreatePHI(analyzed_type->llvmType(),
block->predecessors.size() + 1, p.first.s());
ConcreteCompilerVariable* var = new ConcreteCompilerVariable(analyzed_type, phi, true);
ConcreteCompilerVariable* var = new ConcreteCompilerVariable(analyzed_type, phi);
generator->giveLocalSymbol(p.first, var);
(*phis)[p.first] = std::make_pair(analyzed_type, phi);
}
......@@ -661,7 +661,7 @@ static void emitBBs(IRGenState* irstate, TypeAnalysis* types, const OSREntryDesc
ConcreteCompilerType* type = getTypeAtBlockStart(types, s, block);
llvm::PHINode* phi
= emitter->getBuilder()->CreatePHI(type->llvmType(), block->predecessors.size(), s.s());
ConcreteCompilerVariable* var = new ConcreteCompilerVariable(type, phi, true);
ConcreteCompilerVariable* var = new ConcreteCompilerVariable(type, phi);
generator->giveLocalSymbol(s, var);
(*phis)[s] = std::make_pair(type, phi);
......@@ -761,7 +761,7 @@ static void emitBBs(IRGenState* irstate, TypeAnalysis* types, const OSREntryDesc
llvm::PHINode* phi = emitter->getBuilder()->CreatePHI(cv->getType()->llvmType(),
block->predecessors.size(), name.s());
// emitter->getBuilder()->CreateCall(g.funcs.dump, phi);
ConcreteCompilerVariable* var = new ConcreteCompilerVariable(cv->getType(), phi, true);
ConcreteCompilerVariable* var = new ConcreteCompilerVariable(cv->getType(), phi);
generator->giveLocalSymbol(name, var);
(*phis)[name] = std::make_pair(cv->getType(), phi);
......@@ -851,7 +851,6 @@ static void emitBBs(IRGenState* irstate, TypeAnalysis* types, const OSREntryDesc
ConcreteCompilerVariable* v = (*phi_ending_symbol_tables[bpred])[it->first];
assert(v);
assert(v->isGrabbed());
// Make sure they all prepared for the same type:
ASSERT(it->second.first == v->getType(), "%d %d: %s %s %s", b->idx, bpred->idx, it->first.c_str(),
......@@ -864,7 +863,6 @@ static void emitBBs(IRGenState* irstate, TypeAnalysis* types, const OSREntryDesc
if (this_is_osr_entry) {
ConcreteCompilerVariable* v = (*osr_syms)[it->first];
assert(v);
assert(v->isGrabbed());
ASSERT(it->second.first == v->getType(), "");
llvm_phi->addIncoming(v->getValue(), osr_unbox_block_end);
......@@ -880,14 +878,6 @@ static void emitBBs(IRGenState* irstate, TypeAnalysis* types, const OSREntryDesc
if (ending_symbol_tables[b] == NULL)
continue;
for (SymbolTable::iterator it = ending_symbol_tables[b]->begin(); it != ending_symbol_tables[b]->end(); ++it) {
it->second->decvrefNodrop();
}
for (ConcreteSymbolTable::iterator it = phi_ending_symbol_tables[b]->begin();
it != phi_ending_symbol_tables[b]->end(); ++it) {
it->second->decvrefNodrop();
}
delete phi_ending_symbol_tables[b];
delete ending_symbol_tables[b];
delete created_phis[b];
}
......
......@@ -645,14 +645,12 @@ private:
CompilerVariable* value = evalExpr(node->value, unw_info);
CompilerVariable* rtn = value->getattr(emitter, getOpInfoForNode(node, unw_info), node->attr.getBox(), false);
value->decvref(emitter);
return rtn;
}
CompilerVariable* evalClsAttribute(AST_ClsAttribute* node, const UnwindInfo& unw_info) {
CompilerVariable* value = evalExpr(node->value, unw_info);
CompilerVariable* rtn = value->getattr(emitter, getOpInfoForNode(node, unw_info), node->attr.getBox(), true);
value->decvref(emitter);
return rtn;
}
......@@ -665,8 +663,6 @@ private:
ConcreteCompilerVariable* converted_obj = obj->makeConverted(emitter, obj->getBoxType());
ConcreteCompilerVariable* converted_cls = cls->makeConverted(emitter, cls->getBoxType());
obj->decvref(emitter);
cls->decvref(emitter);
llvm::Value* v = emitter.createCall(unw_info, g.funcs.exceptionMatches,
{ converted_obj->getValue(), converted_cls->getValue() });
......@@ -696,9 +692,9 @@ private:
phi_exc_value->addIncoming(e.exc_value->getValue(), e.from_block);
phi_exc_tb->addIncoming(e.exc_tb->getValue(), e.from_block);
}
exc_type = new ConcreteCompilerVariable(UNKNOWN, phi_exc_type, true);
exc_value = new ConcreteCompilerVariable(UNKNOWN, phi_exc_value, true);
exc_tb = new ConcreteCompilerVariable(UNKNOWN, phi_exc_tb, true);
exc_type = new ConcreteCompilerVariable(UNKNOWN, phi_exc_type);
exc_value = new ConcreteCompilerVariable(UNKNOWN, phi_exc_value);
exc_tb = new ConcreteCompilerVariable(UNKNOWN, phi_exc_tb);
}
} else {
// There can be no incoming exception if the irgenerator was able to prove that
......@@ -717,13 +713,12 @@ private:
return makeTuple({ exc_type, exc_value, exc_tb });
}
case AST_LangPrimitive::LOCALS: {
return new ConcreteCompilerVariable(UNKNOWN, irstate->getBoxedLocalsVar(), true);
return new ConcreteCompilerVariable(UNKNOWN, irstate->getBoxedLocalsVar());
}
case AST_LangPrimitive::GET_ITER: {
assert(node->args.size() == 1);
CompilerVariable* obj = evalExpr(node->args[0], unw_info);
auto rtn = obj->getPystonIter(emitter, getOpInfoForNode(node, unw_info));
obj->decvref(emitter);
return rtn;
}
case AST_LangPrimitive::IMPORT_FROM: {
......@@ -733,7 +728,6 @@ private:
CompilerVariable* module = evalExpr(node->args[0], unw_info);
ConcreteCompilerVariable* converted_module = module->makeConverted(emitter, module->getBoxType());
module->decvref(emitter);
auto ast_str = ast_cast<AST_Str>(node->args[1]);
assert(ast_str->str_type == AST_Str::STR);
......@@ -746,9 +740,7 @@ private:
llvm::Value* r
= emitter.createCall2(unw_info, g.funcs.importFrom, converted_module->getValue(), name_arg);
CompilerVariable* v = new ConcreteCompilerVariable(UNKNOWN, r, true);
converted_module->decvref(emitter);
CompilerVariable* v = new ConcreteCompilerVariable(UNKNOWN, r);
return v;
}
case AST_LangPrimitive::IMPORT_STAR: {
......@@ -760,13 +752,10 @@ private:
CompilerVariable* module = evalExpr(node->args[0], unw_info);
ConcreteCompilerVariable* converted_module = module->makeConverted(emitter, module->getBoxType());
module->decvref(emitter);
llvm::Value* r = emitter.createCall2(unw_info, g.funcs.importStar, converted_module->getValue(),
irstate->getGlobals());
CompilerVariable* v = new ConcreteCompilerVariable(UNKNOWN, r, true);
converted_module->decvref(emitter);
CompilerVariable* v = new ConcreteCompilerVariable(UNKNOWN, r);
return v;
}
case AST_LangPrimitive::IMPORT_NAME: {
......@@ -780,7 +769,6 @@ private:
// TODO this could be a constant Box* too
CompilerVariable* froms = evalExpr(node->args[1], unw_info);
ConcreteCompilerVariable* converted_froms = froms->makeConverted(emitter, froms->getBoxType());
froms->decvref(emitter);
auto ast_str = ast_cast<AST_Str>(node->args[2]);
assert(ast_str->str_type == AST_Str::STR);
......@@ -790,9 +778,7 @@ private:
{ getConstantInt(level, g.i32), converted_froms->getValue(),
embedRelocatablePtr(module_name.c_str(), g.i8_ptr),
getConstantInt(module_name.size(), g.i64) });
ConcreteCompilerVariable* v = new ConcreteCompilerVariable(UNKNOWN, imported, true);
converted_froms->decvref(emitter);
ConcreteCompilerVariable* v = new ConcreteCompilerVariable(UNKNOWN, imported);
return v;
}
case AST_LangPrimitive::NONE: {
......@@ -803,7 +789,6 @@ private:
CompilerVariable* obj = evalExpr(node->args[0], unw_info);
CompilerVariable* rtn = obj->nonzero(emitter, getOpInfoForNode(node, unw_info));
obj->decvref(emitter);
return rtn;
}
case AST_LangPrimitive::HASNEXT: {
......@@ -811,7 +796,6 @@ private:
CompilerVariable* obj = evalExpr(node->args[0], unw_info);
CompilerVariable* rtn = obj->hasnext(emitter, getOpInfoForNode(node, unw_info));
obj->decvref(emitter);
return rtn;
}
case AST_LangPrimitive::SET_EXC_INFO: {
......@@ -828,14 +812,11 @@ private:
ConcreteCompilerVariable* converted_type = type->makeConverted(emitter, UNKNOWN);
builder->CreateStore(converted_type->getValue(), builder->CreateConstInBoundsGEP2_32(exc_info, 0, 0));
converted_type->decvref(emitter);
ConcreteCompilerVariable* converted_value = value->makeConverted(emitter, UNKNOWN);
builder->CreateStore(converted_value->getValue(), builder->CreateConstInBoundsGEP2_32(exc_info, 0, 1));
converted_value->decvref(emitter);
ConcreteCompilerVariable* converted_traceback = traceback->makeConverted(emitter, UNKNOWN);
builder->CreateStore(converted_traceback->getValue(),
builder->CreateConstInBoundsGEP2_32(exc_info, 0, 2));
converted_traceback->decvref(emitter);
return getNone();
}
......@@ -899,8 +880,6 @@ private:
assert(node->op_type != AST_TYPE::Is && node->op_type != AST_TYPE::IsNot && "not tested yet");
CompilerVariable* rtn = this->_evalBinExp(node, left, right, node->op_type, BinOp, unw_info);
left->decvref(emitter);
right->decvref(emitter);
return rtn;
}
......@@ -911,8 +890,6 @@ private:
assert(node->op_type != AST_TYPE::Is && node->op_type != AST_TYPE::IsNot && "not tested yet");
CompilerVariable* rtn = this->_evalBinExp(node, left, right, node->op_type, AugBinOp, unw_info);
left->decvref(emitter);
right->decvref(emitter);
return rtn;
}
......@@ -930,8 +907,6 @@ private:
}
CompilerVariable* rtn = _evalBinExp(node, left, right, node->ops[0], Compare, unw_info);
left->decvref(emitter);
right->decvref(emitter);
return rtn;
}
......@@ -992,17 +967,12 @@ private:
rtn = func->call(emitter, getOpInfoForNode(node, unw_info), argspec, args, keyword_names);
}
func->decvref(emitter);
for (int i = 0; i < args.size(); i++) {
args[i]->decvref(emitter);
}
return rtn;
}
CompilerVariable* evalDict(AST_Dict* node, const UnwindInfo& unw_info) {
llvm::Value* v = emitter.getBuilder()->CreateCall(g.funcs.createDict);
ConcreteCompilerVariable* rtn = new ConcreteCompilerVariable(DICT, v, true);
ConcreteCompilerVariable* rtn = new ConcreteCompilerVariable(DICT, v);
if (node->keys.size()) {
static BoxedString* setitem_str = getStaticString("__setitem__");
CompilerVariable* setitem = rtn->getattr(emitter, getEmptyOpInfo(unw_info), setitem_str, true);
......@@ -1017,12 +987,7 @@ private:
args.push_back(value);
// TODO should use callattr
CompilerVariable* rtn = setitem->call(emitter, getEmptyOpInfo(unw_info), ArgPassSpec(2), args, NULL);
rtn->decvref(emitter);
key->decvref(emitter);
value->decvref(emitter);
}
setitem->decvref(emitter);
}
return rtn;
}
......@@ -1044,7 +1009,6 @@ private:
std::vector<AST_stmt*> body = { expr };
CompilerVariable* func = _createFunction(node, unw_info, node->args, body);
ConcreteCompilerVariable* converted = func->makeConverted(emitter, func->getBoxType());
func->decvref(emitter);
return converted;
}
......@@ -1058,7 +1022,7 @@ private:
}
llvm::Value* v = emitter.getBuilder()->CreateCall(g.funcs.createList);
ConcreteCompilerVariable* rtn = new ConcreteCompilerVariable(LIST, v, true);
ConcreteCompilerVariable* rtn = new ConcreteCompilerVariable(LIST, v);
llvm::Value* f = g.funcs.listAppendInternal;
llvm::Value* bitcast = emitter.getBuilder()->CreateBitCast(
......@@ -1068,10 +1032,8 @@ private:
for (int i = 0; i < node->elts.size(); i++) {
CompilerVariable* elt = elts[i];
ConcreteCompilerVariable* converted = elt->makeConverted(emitter, elt->getBoxType());
elt->decvref(emitter);
emitter.createCall2(unw_info, f, bitcast, converted->getValue());
converted->decvref(emitter);
}
return rtn;
}
......@@ -1079,7 +1041,7 @@ private:
ConcreteCompilerVariable* getEllipsis() {
llvm::Constant* ellipsis = embedRelocatablePtr(Ellipsis, g.llvm_value_type_ptr, "cEllipsis");
auto ellipsis_cls = Ellipsis->cls;
return new ConcreteCompilerVariable(typeFromClass(ellipsis_cls), ellipsis, false);
return new ConcreteCompilerVariable(typeFromClass(ellipsis_cls), ellipsis);
}
llvm::Constant* embedParentModulePtr() {
......@@ -1101,11 +1063,11 @@ private:
llvm::Value* uncasted = emitter.createIC(pp, (void*)pyston::getGlobal, llvm_args, unw_info);
llvm::Value* r = emitter.getBuilder()->CreateIntToPtr(uncasted, g.llvm_value_type_ptr);
return new ConcreteCompilerVariable(UNKNOWN, r, true);
return new ConcreteCompilerVariable(UNKNOWN, r);
} else {
llvm::Value* r = emitter.createCall2(unw_info, g.funcs.getGlobal, irstate->getGlobals(),
embedRelocatablePtr(node->id.getBox(), g.llvm_boxedstring_type_ptr));
return new ConcreteCompilerVariable(UNKNOWN, r, true);
return new ConcreteCompilerVariable(UNKNOWN, r);
}
}
......@@ -1135,7 +1097,6 @@ private:
// Where the parent lookup is done `deref_info.num_parents_from_passed_closure` times
CompilerVariable* closure = symbol_table[internString(PASSED_CLOSURE_NAME)];
llvm::Value* closureValue = closure->makeConverted(emitter, CLOSURE)->getValue();
closure->decvref(emitter);
for (int i = 0; i < deref_info.num_parents_from_passed_closure; i++) {
closureValue = emitter.getBuilder()->CreateLoad(getClosureParentGep(emitter, closureValue));
}
......@@ -1167,13 +1128,13 @@ private:
curblock = success_bb;
emitter.getBuilder()->SetInsertPoint(curblock);
return new ConcreteCompilerVariable(UNKNOWN, lookupResult, true);
return new ConcreteCompilerVariable(UNKNOWN, lookupResult);
} else if (vst == ScopeInfo::VarScopeType::NAME) {
llvm::Value* boxedLocals = irstate->getBoxedLocalsVar();
llvm::Value* attr = embedRelocatablePtr(node->id.getBox(), g.llvm_boxedstring_type_ptr);
llvm::Value* module = irstate->getGlobals();
llvm::Value* r = emitter.createCall3(unw_info, g.funcs.boxedLocalsGet, boxedLocals, attr, module);
return new ConcreteCompilerVariable(UNKNOWN, r, true);
return new ConcreteCompilerVariable(UNKNOWN, r);
} else {
// vst is one of {FAST, CLOSURE}
if (symbol_table.find(node->id) == symbol_table.end()) {
......@@ -1204,8 +1165,6 @@ private:
CompilerVariable* rtn = symbol_table[node->id];
if (is_kill)
symbol_table.erase(node->id);
else
rtn->incvref();
return rtn;
}
}
......@@ -1227,14 +1186,12 @@ private:
CompilerVariable* evalRepr(AST_Repr* node, const UnwindInfo& unw_info) {
CompilerVariable* var = evalExpr(node->value, unw_info);
ConcreteCompilerVariable* cvar = var->makeConverted(emitter, var->getBoxType());
var->decvref(emitter);
std::vector<llvm::Value*> args{ cvar->getValue() };
llvm::Value* rtn = emitter.createCall(unw_info, g.funcs.repr, args);
cvar->decvref(emitter);
rtn = emitter.getBuilder()->CreateBitCast(rtn, g.llvm_value_type_ptr);
return new ConcreteCompilerVariable(STR, rtn, true);
return new ConcreteCompilerVariable(STR, rtn);
}
CompilerVariable* evalSet(AST_Set* node, const UnwindInfo& unw_info) {
......@@ -1245,7 +1202,7 @@ private:
}
llvm::Value* v = emitter.getBuilder()->CreateCall(g.funcs.createSet);
ConcreteCompilerVariable* rtn = new ConcreteCompilerVariable(SET, v, true);
ConcreteCompilerVariable* rtn = new ConcreteCompilerVariable(SET, v);
static BoxedString* add_str = getStaticString("add");
......@@ -1254,8 +1211,6 @@ private:
CallattrFlags flags = {.cls_only = true, .null_on_nonexistent = false, .argspec = ArgPassSpec(1) };
CompilerVariable* r
= rtn->callattr(emitter, getOpInfoForNode(node, unw_info), add_str, flags, { elt }, NULL);
r->decvref(emitter);
elt->decvref(emitter);
}
return rtn;
......@@ -1276,11 +1231,7 @@ private:
elts.push_back(evalSlice(e, unw_info));
}
// TODO makeTuple should probably just transfer the vref, but I want to keep things consistent
CompilerVariable* rtn = makeTuple(elts);
for (auto* e : elts) {
e->decvref(emitter);
}
return rtn;
}
......@@ -1290,12 +1241,12 @@ private:
= embedRelocatablePtr(irstate->getSourceInfo()->parent_module->getStringConstant(node->str_data, true),
g.llvm_value_type_ptr);
return new ConcreteCompilerVariable(STR, rtn, true);
return new ConcreteCompilerVariable(STR, rtn);
} else if (node->str_type == AST_Str::UNICODE) {
llvm::Value* rtn = embedRelocatablePtr(
irstate->getSourceInfo()->parent_module->getUnicodeConstant(node->str_data), g.llvm_value_type_ptr);
return new ConcreteCompilerVariable(typeFromClass(unicode_cls), rtn, true);
return new ConcreteCompilerVariable(typeFromClass(unicode_cls), rtn);
} else {
RELEASE_ASSERT(0, "%d", node->str_type);
}
......@@ -1306,8 +1257,6 @@ private:
CompilerVariable* slice = evalSlice(node->slice, unw_info);
CompilerVariable* rtn = value->getitem(emitter, getOpInfoForNode(node, unw_info), slice);
value->decvref(emitter);
slice->decvref(emitter);
return rtn;
}
......@@ -1318,11 +1267,7 @@ private:
elts.push_back(value);
}
// TODO makeTuple should probably just transfer the vref, but I want to keep things consistent
CompilerVariable* rtn = makeTuple(elts);
for (int i = 0; i < node->elts.size(); i++) {
elts[i]->decvref(emitter);
}
return rtn;
}
......@@ -1331,18 +1276,15 @@ private:
if (node->op_type == AST_TYPE::Not) {
CompilerVariable* rtn = operand->nonzero(emitter, getOpInfoForNode(node, unw_info));
operand->decvref(emitter);
assert(rtn->getType() == BOOL);
llvm::Value* v = i1FromBool(emitter, static_cast<ConcreteCompilerVariable*>(rtn));
assert(v->getType() == g.i1);
llvm::Value* negated = emitter.getBuilder()->CreateNot(v);
rtn->decvref(emitter);
return boolFromI1(emitter, negated);
} else {
CompilerVariable* rtn = operand->unaryop(emitter, getOpInfoForNode(node, unw_info), node->op_type);
operand->decvref(emitter);
return rtn;
}
}
......@@ -1355,14 +1297,11 @@ private:
CompilerVariable* value = node->value ? evalExpr(node->value, unw_info) : getNone();
ConcreteCompilerVariable* convertedValue = value->makeConverted(emitter, value->getBoxType());
value->decvref(emitter);
llvm::Value* rtn
= emitter.createCall2(unw_info, g.funcs.yield, convertedGenerator->getValue(), convertedValue->getValue());
convertedGenerator->decvref(emitter);
convertedValue->decvref(emitter);
return new ConcreteCompilerVariable(UNKNOWN, rtn, true);
return new ConcreteCompilerVariable(UNKNOWN, rtn);
}
CompilerVariable* evalMakeClass(AST_MakeClass* mkclass, const UnwindInfo& unw_info) {
......@@ -1378,12 +1317,7 @@ private:
}
CompilerVariable* _bases_tuple = makeTuple(bases);
for (auto b : bases) {
b->decvref(emitter);
}
ConcreteCompilerVariable* bases_tuple = _bases_tuple->makeConverted(emitter, _bases_tuple->getBoxType());
_bases_tuple->decvref(emitter);
std::vector<CompilerVariable*> decorators;
for (auto d : node->decorator_list) {
......@@ -1413,24 +1347,19 @@ private:
CompilerVariable* attr_dict = func->call(emitter, getEmptyOpInfo(unw_info), ArgPassSpec(0), {}, NULL);
func->decvref(emitter);
ConcreteCompilerVariable* converted_attr_dict = attr_dict->makeConverted(emitter, attr_dict->getBoxType());
attr_dict->decvref(emitter);
llvm::Value* classobj = emitter.createCall3(
unw_info, g.funcs.createUserClass, embedRelocatablePtr(node->name.getBox(), g.llvm_boxedstring_type_ptr),
bases_tuple->getValue(), converted_attr_dict->getValue());
// Note: createuserClass is free to manufacture non-class objects
CompilerVariable* cls = new ConcreteCompilerVariable(UNKNOWN, classobj, true);
CompilerVariable* cls = new ConcreteCompilerVariable(UNKNOWN, classobj);
for (int i = decorators.size() - 1; i >= 0; i--) {
cls = decorators[i]->call(emitter, getOpInfoForNode(node, unw_info), ArgPassSpec(1), { cls }, NULL);
decorators[i]->decvref(emitter);
}
// do we need to decvref this?
return cls;
}
......@@ -1442,7 +1371,6 @@ private:
for (auto d : args->defaults) {
CompilerVariable* e = evalExpr(d, unw_info);
ConcreteCompilerVariable* converted = e->makeConverted(emitter, e->getBoxType());
e->decvref(emitter);
defaults.push_back(converted);
}
......@@ -1474,10 +1402,6 @@ private:
CompilerVariable* func = makeFunction(emitter, md, created_closure, irstate->getGlobalsIfCustom(), defaults);
for (auto d : defaults) {
d->decvref(emitter);
}
return func;
}
......@@ -1492,14 +1416,13 @@ private:
for (int i = decorators.size() - 1; i >= 0; i--) {
func = decorators[i]->call(emitter, getOpInfoForNode(node, unw_info), ArgPassSpec(1), { func }, NULL);
decorators[i]->decvref(emitter);
}
return func;
}
// Note: the behavior of this function must match type_analysis.cpp:unboxedType()
CompilerVariable* unboxVar(ConcreteCompilerType* t, llvm::Value* v, bool grabbed) {
CompilerVariable* unboxVar(ConcreteCompilerType* t, llvm::Value* v) {
if (t == BOXED_INT) {
return makeUnboxedInt(emitter, v);
}
......@@ -1510,7 +1433,7 @@ private:
llvm::Value* unboxed = emitter.getBuilder()->CreateCall(g.funcs.unboxBool, v);
return boolFromI1(emitter, unboxed);
}
return new ConcreteCompilerVariable(t, v, grabbed);
return new ConcreteCompilerVariable(t, v);
}
template <typename AstType>
......@@ -1546,13 +1469,12 @@ private:
#endif
ConcreteCompilerVariable* old_rtn = rtn->makeConverted(emitter, UNKNOWN);
rtn->decvref(emitter);
llvm::Value* guard_check = old_rtn->makeClassCheck(emitter, speculated_class);
assert(guard_check->getType() == g.i1);
createExprTypeGuard(guard_check, node, old_rtn->getValue(), unw_info.current_stmt);
rtn = unboxVar(speculated_type, old_rtn->getValue(), true);
rtn = unboxVar(speculated_type, old_rtn->getValue());
}
assert(rtn);
......@@ -1714,15 +1636,13 @@ private:
if (vst == ScopeInfo::VarScopeType::GLOBAL) {
if (irstate->getSourceInfo()->scoping->areGlobalsFromModule()) {
auto parent_module = llvm::ConstantExpr::getPointerCast(embedParentModulePtr(), g.llvm_value_type_ptr);
ConcreteCompilerVariable* module = new ConcreteCompilerVariable(MODULE, parent_module, false);
ConcreteCompilerVariable* module = new ConcreteCompilerVariable(MODULE, parent_module);
module->setattr(emitter, getEmptyOpInfo(unw_info), name.getBox(), val);
module->decvref(emitter);
} else {
auto converted = val->makeConverted(emitter, val->getBoxType());
emitter.createCall3(unw_info, g.funcs.setGlobal, irstate->getGlobals(),
embedRelocatablePtr(name.getBox(), g.llvm_boxedstring_type_ptr),
converted->getValue());
converted->decvref(emitter);
}
} else if (vst == ScopeInfo::VarScopeType::NAME) {
// TODO inefficient
......@@ -1734,11 +1654,7 @@ private:
// FAST or CLOSURE
CompilerVariable*& prev = symbol_table[name];
if (prev != NULL) {
prev->decvref(emitter);
}
prev = val;
val->incvref();
// Clear out the is_defined name since it is now definitely defined:
assert(!isIsDefinedName(name.s()));
......@@ -1751,7 +1667,6 @@ private:
// This is basically `closure->elts[offset] = val;`
CompilerVariable* closure = symbol_table[internString(CREATED_CLOSURE_NAME)];
llvm::Value* closureValue = closure->makeConverted(emitter, CLOSURE)->getValue();
closure->decvref(emitter);
llvm::Value* gep = getClosureElementGep(emitter, closureValue, offset);
emitter.getBuilder()->CreateStore(val->makeConverted(emitter, UNKNOWN)->getValue(), gep);
}
......@@ -1761,7 +1676,6 @@ private:
void _doSetattr(AST_Attribute* target, CompilerVariable* val, const UnwindInfo& unw_info) {
CompilerVariable* t = evalExpr(target->value, unw_info);
t->setattr(emitter, getEmptyOpInfo(unw_info), target->attr.getBox(), val);
t->decvref(emitter);
}
void _doSetitem(AST_Subscript* target, CompilerVariable* val, const UnwindInfo& unw_info) {
......@@ -1770,8 +1684,6 @@ private:
ConcreteCompilerVariable* converted_target = tget->makeConverted(emitter, tget->getBoxType());
ConcreteCompilerVariable* converted_slice = slice->makeConverted(emitter, slice->getBoxType());
tget->decvref(emitter);
slice->decvref(emitter);
ConcreteCompilerVariable* converted_val = val->makeConverted(emitter, val->getBoxType());
......@@ -1792,10 +1704,6 @@ private:
emitter.createCall3(unw_info, g.funcs.setitem, converted_target->getValue(), converted_slice->getValue(),
converted_val->getValue());
}
converted_target->decvref(emitter);
converted_slice->decvref(emitter);
converted_val->decvref(emitter);
}
void _doUnpackTuple(AST_Tuple* target, CompilerVariable* val, const UnwindInfo& unw_info) {
......@@ -1813,7 +1721,6 @@ private:
for (int i = 0; i < ntargets; i++) {
CompilerVariable* thisval = unpacked[i];
_doSet(target->elts[i], thisval, unw_info);
thisval->decvref(emitter);
}
}
......@@ -1857,7 +1764,6 @@ private:
if (node->msg) {
CompilerVariable* msg = evalExpr(node->msg, unw_info);
converted_msg = msg->makeConverted(emitter, msg->getBoxType());
msg->decvref(emitter);
llvm_args.push_back(converted_msg->getValue());
} else {
llvm_args.push_back(getNullPtr(g.llvm_value_type_ptr));
......@@ -1872,7 +1778,6 @@ private:
for (int i = 0; i < node->targets.size(); i++) {
_doSet(node->targets[i], val, unw_info);
}
val->decvref(emitter);
}
void doDelete(AST_Delete* node, const UnwindInfo& unw_info) {
......@@ -1901,8 +1806,6 @@ private:
ConcreteCompilerVariable* converted_target = tget->makeConverted(emitter, tget->getBoxType());
ConcreteCompilerVariable* converted_slice = slice->makeConverted(emitter, slice->getBoxType());
tget->decvref(emitter);
slice->decvref(emitter);
bool do_patchpoint = ENABLE_ICDELITEMS;
if (do_patchpoint) {
......@@ -1916,9 +1819,6 @@ private:
} else {
emitter.createCall2(unw_info, g.funcs.delitem, converted_target->getValue(), converted_slice->getValue());
}
converted_target->decvref(emitter);
converted_slice->decvref(emitter);
}
void _doDelAttr(AST_Attribute* node, const UnwindInfo& unw_info) {
......@@ -1974,13 +1874,11 @@ private:
void doExec(AST_Exec* node, const UnwindInfo& unw_info) {
CompilerVariable* body = evalExpr(node->body, unw_info);
llvm::Value* vbody = body->makeConverted(emitter, body->getBoxType())->getValue();
body->decvref(emitter);
llvm::Value* vglobals;
if (node->globals) {
CompilerVariable* globals = evalExpr(node->globals, unw_info);
vglobals = globals->makeConverted(emitter, globals->getBoxType())->getValue();
globals->decvref(emitter);
} else {
vglobals = getNullPtr(g.llvm_value_type_ptr);
}
......@@ -1989,7 +1887,6 @@ private:
if (node->locals) {
CompilerVariable* locals = evalExpr(node->locals, unw_info);
vlocals = locals->makeConverted(emitter, locals->getBoxType())->getValue();
locals->decvref(emitter);
} else {
vlocals = getNullPtr(g.llvm_value_type_ptr);
}
......@@ -2004,10 +1901,9 @@ private:
if (node->dest) {
auto d = evalExpr(node->dest, unw_info);
dest = d->makeConverted(emitter, d->getBoxType());
d->decvref(emitter);
} else {
llvm::Value* sys_stdout_val = emitter.createCall(unw_info, g.funcs.getSysStdout);
dest = new ConcreteCompilerVariable(UNKNOWN, sys_stdout_val, true);
dest = new ConcreteCompilerVariable(UNKNOWN, sys_stdout_val);
// TODO: speculate that sys.stdout is a file?
}
assert(dest);
......@@ -2018,16 +1914,12 @@ private:
if (node->values.size() == 1) {
CompilerVariable* var = evalExpr(node->values[0], unw_info);
converted = var->makeConverted(emitter, var->getBoxType());
var->decvref(emitter);
} else {
converted = new ConcreteCompilerVariable(UNKNOWN, getNullPtr(g.llvm_value_type_ptr), true);
converted = new ConcreteCompilerVariable(UNKNOWN, getNullPtr(g.llvm_value_type_ptr));
}
emitter.createCall3(unw_info, g.funcs.printHelper, dest->getValue(), converted->getValue(),
getConstantInt(node->nl, g.i1));
dest->decvref(emitter);
converted->decvref(emitter);
}
void doReturn(AST_Return* node, const UnwindInfo& unw_info) {
......@@ -2041,30 +1933,16 @@ private:
}
assert(val);
// If we ask the return variable to become UNKNOWN (the typical return type),
// it will be forced to split a copy of itself and incref.
// But often the return variable will already be in the right shape, so in
// that case asking it to convert to itself ends up just being an incvref
// and doesn't end up emitting an incref+decref pair.
// This could also be handled by casting from the CompilerVariable to
// ConcreteCompilerVariable, but this way feels a little more robust to me.
ConcreteCompilerType* opt_rtn_type = irstate->getReturnType();
if (irstate->getReturnType()->llvmType() == val->getConcreteType()->llvmType())
opt_rtn_type = val->getConcreteType();
ConcreteCompilerVariable* rtn = val->makeConverted(emitter, opt_rtn_type);
rtn->ensureGrabbed(emitter);
val->decvref(emitter);
for (auto& p : symbol_table) {
p.second->decvref(emitter);
}
symbol_table.clear();
endBlock(DEAD);
// This is tripping in test/tests/return_selfreferential.py. kmod says it should be removed.
// ASSERT(rtn->getVrefs() == 1, "%d", rtn->getVrefs());
assert(rtn->getValue());
emitter.getBuilder()->CreateRet(rtn->getValue());
}
......@@ -2094,8 +1972,6 @@ private:
void doExpr(AST_Expr* node, const UnwindInfo& unw_info) {
CompilerVariable* var = evalExpr(node->value, unw_info);
var->decvref(emitter);
}
void doOSRExit(llvm::BasicBlock* normal_target, AST_Jump* osr_key) {
......@@ -2137,11 +2013,11 @@ private:
SortedSymbolTable sorted_symbol_table(symbol_table.begin(), symbol_table.end());
sorted_symbol_table[internString(FRAME_INFO_PTR_NAME)]
= new ConcreteCompilerVariable(FRAME_INFO, irstate->getFrameInfoVar(), true);
= new ConcreteCompilerVariable(FRAME_INFO, irstate->getFrameInfoVar());
if (!irstate->getSourceInfo()->scoping->areGlobalsFromModule()) {
sorted_symbol_table[internString(PASSED_GLOBALS_NAME)]
= new ConcreteCompilerVariable(UNKNOWN, irstate->getGlobals(), true);
= new ConcreteCompilerVariable(UNKNOWN, irstate->getGlobals());
}
// For OSR calls, we use the same calling convention as in some other places; namely,
......@@ -2192,12 +2068,6 @@ private:
assert(var->getType() != BOXED_FLOAT
&& "should probably unbox it, but why is it boxed in the first place?");
// 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.
ASSERT(var->isGrabbed(), "%s", p.first.c_str());
// var->ensureGrabbed(emitter);
llvm::Value* val = var->getValue();
if (arg_num < 3) {
......@@ -2260,10 +2130,6 @@ private:
emitter.getBuilder()->CreateCall(l_free, malloc_save);
}
for (int i = 0; i < converted_args.size(); i++) {
converted_args[i]->decvref(emitter);
}
emitter.getBuilder()->CreateRet(rtn);
emitter.getBuilder()->SetInsertPoint(starting_block);
......@@ -2317,7 +2183,6 @@ private:
if (a) {
CompilerVariable* v = evalExpr(a, unw_info);
ConcreteCompilerVariable* converted = v->makeConverted(emitter, v->getBoxType());
v->decvref(emitter);
args.push_back(converted->getValue());
} else {
args.push_back(embedRelocatablePtr(None, g.llvm_value_type_ptr, "cNone"));
......@@ -2414,15 +2279,13 @@ private:
void loadArgument(InternedString name, ConcreteCompilerType* t, llvm::Value* v, const UnwindInfo& unw_info) {
assert(name.s() != FRAME_INFO_PTR_NAME);
CompilerVariable* var = unboxVar(t, v, false);
CompilerVariable* var = unboxVar(t, v);
_doSet(name, var, unw_info);
var->decvref(emitter);
}
void loadArgument(AST_expr* name, ConcreteCompilerType* t, llvm::Value* v, const UnwindInfo& unw_info) {
CompilerVariable* var = unboxVar(t, v, false);
CompilerVariable* var = unboxVar(t, v);
_doSet(name, var, unw_info);
var->decvref(emitter);
}
bool allowableFakeEndingSymbol(InternedString name) {
......@@ -2451,10 +2314,6 @@ private:
// symbol table? '%s'", p.first.c_str());
if (!irstate->getLiveness()->isLiveAtEnd(p.first, myblock)) {
// printf("%s dead at end of %d; grabbed = %d, %d vrefs\n", p.first.c_str(), myblock->idx,
// p.second->isGrabbed(), p.second->getVrefs());
p.second->decvref(emitter);
symbol_table.erase(getIsDefinedName(p.first));
symbol_table.erase(p.first);
} else if (irstate->getPhis()->isRequiredAfter(p.first, myblock)) {
......@@ -2466,8 +2325,7 @@ private:
// printf("have to convert %s from %s to %s\n", p.first.c_str(),
// p.second->getType()->debugName().c_str(), phi_type->debugName().c_str());
ConcreteCompilerVariable* v = p.second->makeConverted(emitter, phi_type);
p.second->decvref(emitter);
symbol_table[p.first] = v->split(emitter);
symbol_table[p.first] = v;
} else {
#ifndef NDEBUG
if (myblock->successors.size()) {
......@@ -2512,7 +2370,7 @@ private:
// printf("no st entry, setting undefined\n");
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()));
_setFake(defined_name, makeBool(0));
}
}
......@@ -2567,10 +2425,6 @@ public:
EndingState getEndingSymbolTable() override {
assert(state == FINISHED || state == DEAD);
// for (SymbolTable::iterator it = symbol_table.begin(); it != symbol_table.end(); ++it) {
// printf("%s %p %d\n", it->first.c_str(), it->second, it->second->getVrefs());
//}
SourceInfo* source = irstate->getSourceInfo();
SymbolTable* st = new SymbolTable(symbol_table);
......@@ -2584,9 +2438,6 @@ public:
}
if (myblock->successors.size() == 0) {
for (auto& p : *st) {
p.second->decvref(emitter);
}
st->clear();
symbol_table.clear();
return EndingState(st, phi_st, curblock, outgoing_exc_state);
......@@ -2610,8 +2461,6 @@ public:
// We're going to sort out which symbols need to go in phi_st and which belong inst.
for (SymbolTable::iterator it = st->begin(); it != st->end();) {
if (allowableFakeEndingSymbol(it->first) || irstate->getPhis()->isRequiredAfter(it->first, myblock)) {
ASSERT(it->second->isGrabbed(), "%s", it->first.c_str());
assert(it->second->getVrefs() == 1);
// this conversion should have already happened... should refactor this.
ConcreteCompilerType* ending_type;
if (isIsDefinedName(it->first.s())) {
......@@ -2630,8 +2479,7 @@ public:
}
assert(ending_type->isUsable());
//(*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());
(*phi_st)[it->first] = it->second->split(emitter)->makeConverted(emitter, ending_type);
(*phi_st)[it->first] = it->second->makeConverted(emitter, ending_type);
it = st->erase(it);
} else {
++it;
......@@ -2657,11 +2505,9 @@ public:
assert(st);
DupCache cache;
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, a %s\n", it->first.c_str(), it->second->getType()->debugName().c_str());
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());
}
}
......@@ -2686,7 +2532,7 @@ public:
if (scope_info->takesClosure()) {
passed_closure = AI;
symbol_table[internString(PASSED_CLOSURE_NAME)]
= new ConcreteCompilerVariable(getPassedClosureType(), AI, true);
= new ConcreteCompilerVariable(getPassedClosureType(), AI);
++AI;
}
......@@ -2697,11 +2543,11 @@ public:
llvm::Value* new_closure = emitter.getBuilder()->CreateCall2(
g.funcs.createClosure, passed_closure, getConstantInt(scope_info->getClosureSize(), g.i64));
symbol_table[internString(CREATED_CLOSURE_NAME)]
= new ConcreteCompilerVariable(getCreatedClosureType(), new_closure, true);
= new ConcreteCompilerVariable(getCreatedClosureType(), new_closure);
}
if (irstate->getSourceInfo()->is_generator) {
symbol_table[internString(PASSED_GENERATOR_NAME)] = new ConcreteCompilerVariable(GENERATOR, AI, true);
symbol_table[internString(PASSED_GENERATOR_NAME)] = new ConcreteCompilerVariable(GENERATOR, AI);
++AI;
}
......@@ -2857,9 +2703,9 @@ public:
llvm::Value* exc_traceback = emitter.getBuilder()->CreateLoad(exc_traceback_ptr);
addOutgoingExceptionState(
IRGenerator::ExceptionState(capi_exc_dest, new ConcreteCompilerVariable(UNKNOWN, exc_type, true),
new ConcreteCompilerVariable(UNKNOWN, exc_value, true),
new ConcreteCompilerVariable(UNKNOWN, exc_traceback, true)));
IRGenerator::ExceptionState(capi_exc_dest, new ConcreteCompilerVariable(UNKNOWN, exc_type),
new ConcreteCompilerVariable(UNKNOWN, exc_value),
new ConcreteCompilerVariable(UNKNOWN, exc_traceback)));
emitter.getBuilder()->CreateBr(final_dest);
}
......@@ -2916,9 +2762,9 @@ public:
if (final_dest) {
// Catch the exception and forward to final_dest:
addOutgoingExceptionState(ExceptionState(cxx_exc_dest,
new ConcreteCompilerVariable(UNKNOWN, exc_type, true),
new ConcreteCompilerVariable(UNKNOWN, exc_value, true),
new ConcreteCompilerVariable(UNKNOWN, exc_traceback, true)));
new ConcreteCompilerVariable(UNKNOWN, exc_type),
new ConcreteCompilerVariable(UNKNOWN, exc_value),
new ConcreteCompilerVariable(UNKNOWN, exc_traceback)));
builder->CreateBr(final_dest);
} else {
......
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