text: /*
     +----------------------------------------------------------------------+
     | HipHop for PHP                                                       |
     +----------------------------------------------------------------------+
     | Copyright (c) 2010-2013 Facebook, Inc. (http://www.facebook.com)     |
     +----------------------------------------------------------------------+
     | This source file is subject to version 3.01 of the PHP license,      |
     | that is bundled with this package in the file LICENSE, and is        |
     | available through the world-wide-web at the following url:           |
     | http://www.php.net/license/3_01.txt                                  |
     | If you did not receive a copy of the PHP license and are unable to   |
     | obtain it through the world-wide-web, please send a note to          |
     | license@php.net so we can mail you a copy immediately.               |
     +----------------------------------------------------------------------+
  */
  
  #include "hphp/runtime/vm/jit/ir-factory.h"
  
  #include "hphp/runtime/vm/jit/block.h"
  
  namespace HPHP {  namespace JIT {
  
  IRInstruction* IRFactory::defLabel(unsigned numDst, BCMarker marker) {
    IRInstruction inst(DefLabel, marker);
    IRInstruction* label = cloneInstruction(&inst);
    if (numDst > 0) {
      SSATmp* dsts = (SSATmp*) m_arena.alloc(numDst * sizeof(SSATmp));
      for (unsigned i = 0; i < numDst; ++i) {
        new (&dsts[i]) SSATmp(m_nextOpndId++, label);
      }
      label->setDsts(numDst, dsts);
    }
    return label;
  }
  
  Block* IRFactory::defBlock(const Func* func) {
    return new (m_arena) Block(m_nextBlockId++, func);
  }
  
  IRInstruction* IRFactory::mov(SSATmp* dst, SSATmp* src, BCMarker marker) {
    IRInstruction* inst = gen(Mov, marker, dst->type(), src);
    dst->setInstruction(inst);
    inst->setDst(dst);
    return inst;
  }
  
  SSATmp* IRFactory::findConst(ConstData& cdata, Type ctype) {
    IRInstruction inst(DefConst, BCMarker());
    inst.setExtra(&cdata);
    inst.setTypeParam(ctype);
    if (SSATmp* tmp = m_constTable.lookup(&inst)) {
      assert(tmp->type().equals(ctype));
      return tmp;
    }
    return m_constTable.insert(cloneInstruction(&inst)->dst());
  }
  
  }}
  