}
};
+inline bool unescapableTemp(Temp *t, Function *f)
+{
+ switch (t->kind) {
+ case Temp::Formal:
+ case Temp::ScopedFormal:
+ case Temp::ScopedLocal:
+ return false;
+ case Temp::Local:
+ return !f->variablesCanEscape();
+ default:
+ return true;
+ }
+}
+
inline Temp *unescapableTemp(Expr *e, Function *f)
{
Temp *t = e->asTemp();
if (!t)
return 0;
- switch (t->kind) {
- case Temp::VirtualRegister:
- return t;
- case Temp::Local:
- return f->variablesCanEscape() ? 0 : t;
- default:
- return 0;
- }
+ return unescapableTemp(t, f) ? t : 0;
}
class BasicBlockSet
Function *function;
bool isCollectable(Temp *t) const
{
- switch (t->kind) {
- case Temp::Formal:
- case Temp::ScopedFormal:
- case Temp::ScopedLocal:
- return false;
- case Temp::Local:
- return !function->variablesCanEscape();
- case Temp::VirtualRegister:
- return true;
- default:
- // PhysicalRegister and StackSlot can only get inserted later.
- Q_ASSERT(!"Invalid temp kind!");
- return false;
- }
+ Q_ASSERT(t->kind != Temp::PhysicalRegister && t->kind != Temp::StackSlot);
+ return unescapableTemp(t, function);
}
public:
bool isRenamable(Temp *t) const
{
- switch (t->kind) {
- case Temp::Formal:
- case Temp::ScopedFormal:
- case Temp::ScopedLocal:
- return false;
- case Temp::Local:
- return !function->variablesCanEscape();
- case Temp::VirtualRegister:
- return true;
- default:
- Q_ASSERT(!"Invalid temp kind!");
- return false;
- }
+ Q_ASSERT(t->kind != Temp::PhysicalRegister && t->kind != Temp::StackSlot);
+ return unescapableTemp(t, function);
}
struct TodoAction {
Stmt *_stmt;
bool isCollectible(Temp *t) const {
- switch (t->kind) {
- case Temp::Formal:
- case Temp::ScopedFormal:
- case Temp::ScopedLocal:
- return false;
- case Temp::Local:
- return !function->variablesCanEscape();
- case Temp::VirtualRegister:
- return true;
- default:
- Q_UNREACHABLE();
- return false;
- }
+ Q_ASSERT(t->kind != Temp::PhysicalRegister && t->kind != Temp::StackSlot);
+ return unescapableTemp(t, function);
}
void addUse(Temp *t) {
bool isCollectable(Temp *t) const
{
- switch (t->kind) {
- case Temp::Formal:
- case Temp::ScopedFormal:
- case Temp::ScopedLocal:
- return false;
- case Temp::Local:
- return !function->variablesCanEscape();
- default:
- return true;
- }
+ return unescapableTemp(t, function);
}
protected:
}
bool isAlwaysVar(Temp *t) {
- switch (t->kind) {
- case Temp::Formal:
- case Temp::ScopedFormal:
- case Temp::ScopedLocal:
- t->type = VarType;
- return true;
- case Temp::Local:
- if (function->variablesCanEscape()) {
- t->type = VarType;
- return true;
- }
- return false;
- default:
+ if (unescapableTemp(t, function))
return false;
- }
+ t->type = VarType;
+ return true;
}
void setType(Expr *e, DiscoveredType ty) {
virtual void visitRegExp(RegExp *) {}
virtual void visitName(Name *) {}
virtual void visitTemp(Temp *e) {
- switch (e->kind) {
- case Temp::Local:
- if (!function->variablesCanEscape())
- inputs.append(*e);
- break;
-
- case Temp::VirtualRegister:
+ if (unescapableTemp(e, function))
inputs.append(*e);
- break;
-
- default:
- break;
- }
}
virtual void visitClosure(Closure *) {}
virtual void visitConvert(Convert *e) { e->expr->accept(this); }
virtual void visitMove(Move *s) {
s->source->accept(this);
if (Temp *t = s->target->asTemp()) {
- if ((t->kind == Temp::Local && !function->variablesCanEscape()) || t->kind == Temp::VirtualRegister)
+ if (unescapableTemp(t, function))
outputs.append(*t);
else
s->target->accept(this);