private MidExp SimplifyExpImpl(MidAttributeFetch exp, SimplifyEnv env) { return(_exps.AttributeFetch( exp.Range, exp.Obj, exp.Attribute)); }
private MidExp SimplifyLabelExpImpl( MidLabelExp labelExp, MidLetExp letExp, SimplifyEnv env) { // As long as the label doesn't occur in the // bound expression, we can move it outside // of the label's bounds. if (!UsesLabel(letExp.Exp, labelExp.Label)) { MidExp result = new MidLetExp( letExp.Range, letExp.Var, letExp.Exp, new MidLabelExp( labelExp.Range, labelExp.Label, letExp.Body, labelExp.Type)); result = SimplifyExp(result, env); return(result); } return(labelExp); }
private MidExp SimplifyExpImpl(MidAttributeRef val, SimplifyEnv env) { if (val.IsLazy) { return(_exps.AttributeRef(val.Range, val.Decl)); } return(val); }
private MidExp SimplifyExpImpl(MidLetExp exp, SimplifyEnv env) { if (exp.Exp is MidVal) { // The variable is just being bound to a simple // value, so substitute it away: var innerEnv = new SimplifyEnv(env); innerEnv.Insert(exp.Var, (MidVal)exp.Exp); return(SimplifyExp(exp.Body, innerEnv)); } if (exp.Exp is MidBreakExp) { // Well, we can't possibly get to the rest of the // expression, right? return(exp.Exp); } if (exp.Body is MidVarRef) { var midVarRef = (MidVarRef)exp.Body; if (midVarRef.Var == exp.Var) { return(exp.Exp); } } if (exp.Exp is MidPath) { var midPath = (MidPath)exp.Exp; // Try to substitute this path into // any down-stream field references... var midLet = exp; while (midLet != null) { midLet.Exp = TryFoldPath(exp.Var, midLet.Exp, midPath); midLet.Body = TryFoldPath(exp.Var, midLet.Body, midPath); midLet = midLet.Body as MidLetExp; } } if (!UsesVar(exp.Body, exp.Var) && !MightHaveSideEffects(exp.Exp)) { // \todo: Should be able to DCE the let expression away, // but to do that we need to be sure it doesn't have // any side-effects... :( return(exp.Body); } return(exp); }
private MidExp SimplifyLabelExpImpl( MidLabelExp labelExp, MidExp exp, SimplifyEnv env) { if (!UsesLabel(exp, labelExp.Label)) { return(exp); } return(labelExp); }
private MidExp SimplifyLabelExpImpl( MidLabelExp labelExp, MidBreakExp breakExp, SimplifyEnv env) { if (labelExp.Label == breakExp.Label) { return(breakExp.Value); } return(labelExp); }
private MidExp SimplifyExp(MidExp exp, SimplifyEnv env) { if (exp == null) { return(null); } var transform = new MidTransform( null, // no pre-transform (e) => SimplifyExpImpl((dynamic)e, env)); return(transform.Transform(exp)); }
public SimplifyEnv( SimplifyEnv parent) { _parent = parent; }
private MidExp SimplifyExpImpl(MidAttributeRef val, SimplifyEnv env) { if (val.IsLazy) { return _exps.AttributeRef(val.Range, val.Decl); } return val; }
private MidExp SimplifyExpImpl(MidLabelExp exp, SimplifyEnv env) { return(SimplifyLabelExpImpl(exp, (dynamic)exp.Body, env)); }
private MidExp SimplifyExpImpl(MidVarRef val, SimplifyEnv env) { return(env.Lookup(val)); }
private MidExp SimplifyExpImpl(MidAttributeFetch exp, SimplifyEnv env) { return _exps.AttributeFetch( exp.Range, exp.Obj, exp.Attribute); }
private MidExp SimplifyExpImpl(MidVarRef val, SimplifyEnv env) { return env.Lookup(val); }
private MidExp SimplifyExpImpl(MidExp exp, SimplifyEnv env) { return(exp); }
private MidExp SimplifyExpImpl(MidExp exp, SimplifyEnv env) { return exp; }
private MidExp SimplifyLabelExpImpl( MidLabelExp labelExp, MidExp exp, SimplifyEnv env) { if (!UsesLabel(exp, labelExp.Label)) return exp; return labelExp; }
private MidExp SimplifyLabelExpImpl( MidLabelExp labelExp, MidBreakExp breakExp, SimplifyEnv env) { if (labelExp.Label == breakExp.Label) { return breakExp.Value; } return labelExp; }
private MidExp SimplifyLabelExpImpl( MidLabelExp labelExp, MidLetExp letExp, SimplifyEnv env) { // As long as the label doesn't occur in the // bound expression, we can move it outside // of the label's bounds. if (!UsesLabel(letExp.Exp, labelExp.Label)) { MidExp result = new MidLetExp( letExp.Range, letExp.Var, letExp.Exp, new MidLabelExp( labelExp.Range, labelExp.Label, letExp.Body, labelExp.Type)); result = SimplifyExp(result, env); return result; } return labelExp; }
private MidExp SimplifyExpImpl(MidLetExp exp, SimplifyEnv env) { if (exp.Exp is MidVal) { // The variable is just being bound to a simple // value, so substitute it away: var innerEnv = new SimplifyEnv(env); innerEnv.Insert(exp.Var, (MidVal) exp.Exp); return SimplifyExp(exp.Body, innerEnv); } if (exp.Exp is MidBreakExp) { // Well, we can't possibly get to the rest of the // expression, right? return exp.Exp; } if (exp.Body is MidVarRef) { var midVarRef = (MidVarRef)exp.Body; if (midVarRef.Var == exp.Var) return exp.Exp; } if (exp.Exp is MidPath) { var midPath = (MidPath)exp.Exp; // Try to substitute this path into // any down-stream field references... var midLet = exp; while (midLet != null) { midLet.Exp = TryFoldPath(exp.Var, midLet.Exp, midPath); midLet.Body = TryFoldPath(exp.Var, midLet.Body, midPath); midLet = midLet.Body as MidLetExp; } } if (!UsesVar(exp.Body, exp.Var) && !MightHaveSideEffects(exp.Exp)) { // \todo: Should be able to DCE the let expression away, // but to do that we need to be sure it doesn't have // any side-effects... :( return exp.Body; } return exp; }
private MidExp SimplifyExpImpl(MidLabelExp exp, SimplifyEnv env) { return SimplifyLabelExpImpl(exp, (dynamic) exp.Body, env); }
private MidExp SimplifyExp(MidExp exp, SimplifyEnv env) { if (exp == null) return null; var transform = new MidTransform( null, // no pre-transform (e) => SimplifyExpImpl((dynamic)e, env)); return transform.Transform(exp); }