Constant Propagation

ߤޤ뼰:
	̤INTCONSTȤʤ׻
	̤FLOATCONSTȤʤ׻
	(ADD|SUB (ADD|SUB (FRAME|STATIC) (INTCONST a)) (INTCONST b))
		->
	(ADD|SUB (FRAME|STATIC) (INTCONST a+-b))

ߤ̤
	ߤ̤ľ֤
	bottomʤnonconst֤
	topʤnull֤

	ƥΡɤνǤϡnullǤbottomǤʤз̤ˤΤޤޤ
	ƱΡɤshareʤˤʤΤǡɽ¸Ϥʤ

	meet(PHIؿ)Ǥ
		null (top)Ƥ٤Ʊʤ̤Ϥ
		nonconst(bottom)ޤޤƤƤnonconst


Sparse Simple Constant Propagation

٤Ƥμ׻롣
η̡top(undefined)ʳͤˤʤäREGѿꥹL롣
while (LǤʤ) {
  r = Lļ
  r ѤƤ뼰Ʒ׻롣մؿʤmeetԤ
  ηѲREGѿꥹL
}


Sparse Conditional Constant Propagation

ե饰
    ܥ֥åȤexecutable flag
    edgeexecutable flag
¸٤ַ regѿȡJUMPC/JUMPNμ
׻뤿Ӥheap񤹤뤬ȤꤢϵˤʤȤˤ롣

edgeνE
SSAѿνS
E = {entryblockؤedge}  <-- ¤Ϥdestination blockǤ褤
ǡedge eexecutableȤsource blockΥꥹȤȤɽƤ

for (;;) {
  if (E != empty) {
    b = take(E);
    for all phi p in b
      visitPhi(p);
    if (!b.executable) {
      b.executable = true;
      for all expr x in b
        visitExpr(x);
    }
  }
  else if (S != empty) {
    s = take(S);
    for all sѤƤlir tree xˤĤ
      xմؿʤvisitPhi(x);
      Ǥʤ(̤μʤ)ν°֥åbexecutableʤ
        visitExpr(x)
  }
  else break;
}

«塢֤롣


visitExpr(LirNode x) {
  symbolicexec(x);
  if ((set (reg s) subtree)ʤ) {
    newval = symbolicExec(subtree);
    if (values[s] != newval) {
      values[s] = newval;
      S += s;
    }
  }
  else if (JUMPC or JUMPN) {
    newval = symbolicExec(subtree);
    if (values[x] != newval) {
      values[x] = newval;
      B = ˼¹Բǽˤʤäդsuccessor;
      for all b in B {
        E += b;
        execPath[currentBlock.id] += b;
    }
  }
}



visitPhi(LirNode x) {

}



FlowWorkList = entryBlockؤ;
while (FlowWorkListǤʤ || SSAWorkListǤʤ) {
  if (FlowWorkListǤʤ) {
    edge = FlowWorkListļ
    if (!edge.executable) {
      edge.executable = true;
      blk = edge.toblk;
      visitPhi(blk);
      if (first visit of blk)
        visitExpr(blk);
      if (successor is only one)
        FlowWorkList += blk.successor;
  }
  if (SSAWorkListǤʤ) {
    s = takeone(SSAWorkList);
    visitPhi(s);
  }
}


	