+/* this function is often called with current_ir_graph unset */
+static ir_node *
+new_bd_Unknown(ir_mode *m)
+{
+ ir_node *res;
+ ir_graph *irg = current_ir_graph;
+
+ res = new_ir_node(NULL, irg, get_irg_start_block(irg), op_Unknown, m, 0, NULL);
+ res = optimize_node(res);
+ return res;
+} /* new_bd_Unknown */
+
+static ir_node *
+new_bd_CallBegin(dbg_info *db, ir_node *block, ir_node *call)
+{
+ ir_node *in[1];
+ ir_node *res;
+ ir_graph *irg = current_ir_graph;
+
+ in[0] = get_Call_ptr(call);
+ res = new_ir_node(db, irg, block, op_CallBegin, mode_T, 1, in);
+ /* res->attr.callbegin.irg = irg; */
+ res->attr.callbegin.call = call;
+ res = optimize_node(res);
+ IRN_VRFY_IRG(res, irg);
+ return res;
+} /* new_bd_CallBegin */
+
+static ir_node *
+new_bd_EndReg(dbg_info *db, ir_node *block)
+{
+ ir_node *res;
+ ir_graph *irg = current_ir_graph;
+
+ res = new_ir_node(db, irg, block, op_EndReg, mode_T, -1, NULL);
+ set_irg_end_reg(irg, res);
+ IRN_VRFY_IRG(res, irg);
+ return res;
+} /* new_bd_EndReg */
+
+static ir_node *
+new_bd_EndExcept(dbg_info *db, ir_node *block)
+{
+ ir_node *res;
+ ir_graph *irg = current_ir_graph;
+
+ res = new_ir_node(db, irg, block, op_EndExcept, mode_T, -1, NULL);
+ set_irg_end_except(irg, res);
+ IRN_VRFY_IRG (res, irg);
+ return res;
+} /* new_bd_EndExcept */
+
+static ir_node *
+new_bd_Break(dbg_info *db, ir_node *block)
+{
+ ir_node *res;
+ ir_graph *irg = current_ir_graph;
+
+ res = new_ir_node(db, irg, block, op_Break, mode_X, 0, NULL);
+ res = optimize_node(res);
+ IRN_VRFY_IRG(res, irg);
+ return res;
+} /* new_bd_Break */
+
+static ir_node *
+new_bd_Filter(dbg_info *db, ir_node *block, ir_node *arg, ir_mode *mode,
+ long proj)
+{
+ ir_node *res;
+ ir_graph *irg = current_ir_graph;
+
+ res = new_ir_node(db, irg, block, op_Filter, mode, 1, &arg);
+ res->attr.filter.proj = proj;
+ res->attr.filter.in_cg = NULL;
+ res->attr.filter.backedge = NULL;
+
+ assert(res);
+ assert(get_Proj_pred(res));
+ assert(get_nodes_block(get_Proj_pred(res)));
+
+ res = optimize_node(res);
+ IRN_VRFY_IRG(res, irg);
+ return res;
+} /* new_bd_Filter */
+
+static ir_node *
+new_bd_Mux(dbg_info *db, ir_node *block,
+ ir_node *sel, ir_node *ir_false, ir_node *ir_true, ir_mode *mode)
+{
+ ir_node *in[3];
+ ir_node *res;
+ ir_graph *irg = current_ir_graph;
+
+ in[0] = sel;
+ in[1] = ir_false;
+ in[2] = ir_true;
+
+ res = new_ir_node(db, irg, block, op_Mux, mode, 3, in);
+ assert(res);
+
+ res = optimize_node(res);
+ IRN_VRFY_IRG(res, irg);
+ return res;
+} /* new_bd_Mux */
+
+static ir_node *
+new_bd_Psi(dbg_info *db, ir_node *block,
+ int arity, ir_node *cond[], ir_node *vals[], ir_mode *mode)
+{
+ ir_node **in;
+ ir_node *res;
+ ir_graph *irg = current_ir_graph;
+ int i;
+
+ NEW_ARR_A(ir_node *, in, 2 * arity + 1);
+
+ for (i = 0; i < arity; ++i) {
+ in[2 * i] = cond[i];
+ in[2 * i + 1] = vals[i];
+ }
+ in[2 * i] = vals[i];
+
+ res = new_ir_node(db, irg, block, op_Psi, mode, 2 * arity + 1, in);
+ assert(res);
+
+ res = optimize_node(res);
+ IRN_VRFY_IRG(res, irg);
+ return res;
+} /* new_bd_Psi */
+
+static ir_node *
+new_bd_CopyB(dbg_info *db, ir_node *block,
+ ir_node *store, ir_node *dst, ir_node *src, ir_type *data_type)
+{
+ ir_node *in[3];
+ ir_node *res;
+ ir_graph *irg = current_ir_graph;
+
+ in[0] = store;
+ in[1] = dst;
+ in[2] = src;
+
+ res = new_ir_node(db, irg, block, op_CopyB, mode_T, 3, in);
+
+ res->attr.copyb.exc.pin_state = op_pin_state_pinned;
+ res->attr.copyb.data_type = data_type;
+ res = optimize_node(res);
+ IRN_VRFY_IRG(res, irg);
+ return res;
+} /* new_bd_CopyB */
+
+static ir_node *
+new_bd_InstOf(dbg_info *db, ir_node *block, ir_node *store,
+ ir_node *objptr, ir_type *type)
+{
+ ir_node *in[2];
+ ir_node *res;
+ ir_graph *irg = current_ir_graph;
+
+ in[0] = store;
+ in[1] = objptr;
+ res = new_ir_node(db, irg, block, op_Sel, mode_T, 2, in);
+ res->attr.instof.type = type;
+ res = optimize_node(res);
+ IRN_VRFY_IRG(res, irg);
+ return res;
+} /* new_bd_InstOf */
+
+static ir_node *
+new_bd_Raise(dbg_info *db, ir_node *block, ir_node *store, ir_node *obj)
+{
+ ir_node *in[2];
+ ir_node *res;
+ ir_graph *irg = current_ir_graph;
+
+ in[0] = store;
+ in[1] = obj;
+ res = new_ir_node(db, irg, block, op_Raise, mode_T, 2, in);
+ res = optimize_node(res);
+ IRN_VRFY_IRG(res, irg);
+ return res;
+} /* new_bd_Raise */
+
+static ir_node *
+new_bd_Bound(dbg_info *db, ir_node *block,
+ ir_node *store, ir_node *idx, ir_node *lower, ir_node *upper)
+{
+ ir_node *in[4];
+ ir_node *res;
+ ir_graph *irg = current_ir_graph;
+
+ in[0] = store;
+ in[1] = idx;
+ in[2] = lower;
+ in[3] = upper;
+ res = new_ir_node(db, irg, block, op_Bound, mode_T, 4, in);
+ res->attr.bound.exc.pin_state = op_pin_state_pinned;
+ res = optimize_node(res);
+ IRN_VRFY_IRG(res, irg);
+ return res;
+} /* new_bd_Bound */
+
+static ir_node *
+new_bd_Pin(dbg_info *db, ir_node *block, ir_node *node)
+{
+ ir_node *res;
+ ir_graph *irg = current_ir_graph;
+
+ res = new_ir_node(db, irg, block, op_Pin, get_irn_mode(node), 1, &node);
+ res = optimize_node(res);
+ IRN_VRFY_IRG(res, irg);
+ return res;
+} /* new_bd_Pin */
+
+/* --------------------------------------------- */
+/* private interfaces, for professional use only */
+/* --------------------------------------------- */
+
+/* Constructs a Block with a fixed number of predecessors.
+ Does not set current_block. Can not be used with automatic
+ Phi node construction. */
+ir_node *
+new_rd_Block(dbg_info *db, ir_graph *irg, int arity, ir_node **in)
+{
+ ir_graph *rem = current_ir_graph;
+ ir_node *res;
+
+ current_ir_graph = irg;
+ res = new_bd_Block(db, arity, in);
+ current_ir_graph = rem;
+
+ return res;
+} /* new_rd_Block */
+
+ir_node *
+new_rd_Start(dbg_info *db, ir_graph *irg, ir_node *block)
+{
+ ir_graph *rem = current_ir_graph;
+ ir_node *res;
+
+ current_ir_graph = irg;
+ res = new_bd_Start(db, block);
+ current_ir_graph = rem;
+
+ return res;
+} /* new_rd_Start */
+
+ir_node *
+new_rd_End(dbg_info *db, ir_graph *irg, ir_node *block)
+{
+ ir_node *res;
+ ir_graph *rem = current_ir_graph;
+
+ current_ir_graph = rem;
+ res = new_bd_End(db, block);
+ current_ir_graph = rem;
+
+ return res;
+} /* new_rd_End */
+
+/* Creates a Phi node with all predecessors. Calling this constructor
+ is only allowed if the corresponding block is mature. */
+ir_node *
+new_rd_Phi(dbg_info *db, ir_graph *irg, ir_node *block, int arity, ir_node **in, ir_mode *mode)
+{
+ ir_node *res;
+ ir_graph *rem = current_ir_graph;
+
+ current_ir_graph = irg;
+ res = new_bd_Phi(db, block,arity, in, mode);
+ current_ir_graph = rem;
+
+ return res;
+} /* new_rd_Phi */
+
+ir_node *
+new_rd_Const_type(dbg_info *db, ir_graph *irg, ir_node *block, ir_mode *mode, tarval *con, ir_type *tp)
+{
+ ir_node *res;
+ ir_graph *rem = current_ir_graph;
+
+ current_ir_graph = irg;
+ res = new_bd_Const_type(db, block, mode, con, tp);
+ current_ir_graph = rem;
+
+ return res;
+} /* new_rd_Const_type */
+
+ir_node *
+new_rd_Const(dbg_info *db, ir_graph *irg, ir_node *block, ir_mode *mode, tarval *con)
+{
+ ir_node *res;
+ ir_graph *rem = current_ir_graph;
+
+ current_ir_graph = irg;
+ res = new_bd_Const_type(db, block, mode, con, firm_unknown_type);
+ current_ir_graph = rem;
+
+ return res;
+} /* new_rd_Const */
+
+ir_node *
+new_rd_Const_long(dbg_info *db, ir_graph *irg, ir_node *block, ir_mode *mode, long value)
+{
+ return new_rd_Const(db, irg, block, mode, new_tarval_from_long(value, mode));
+} /* new_rd_Const_long */
+
+ir_node *
+new_rd_Id(dbg_info *db, ir_graph *irg, ir_node *block, ir_node *val, ir_mode *mode)
+{
+ ir_node *res;
+ ir_graph *rem = current_ir_graph;
+
+ current_ir_graph = irg;
+ res = new_bd_Id(db, block, val, mode);
+ current_ir_graph = rem;
+
+ return res;
+} /* new_rd_Id */
+
+ir_node *
+new_rd_Proj(dbg_info *db, ir_graph *irg, ir_node *block, ir_node *arg, ir_mode *mode,
+ long proj)
+{
+ ir_node *res;
+ ir_graph *rem = current_ir_graph;
+
+ current_ir_graph = irg;
+ res = new_bd_Proj(db, block, arg, mode, proj);
+ current_ir_graph = rem;
+
+ return res;
+} /* new_rd_Proj */
+
+ir_node *
+new_rd_defaultProj(dbg_info *db, ir_graph *irg, ir_node *block, ir_node *arg,
+ long max_proj)
+{
+ ir_node *res;
+ ir_graph *rem = current_ir_graph;
+
+ current_ir_graph = irg;
+ res = new_bd_defaultProj(db, block, arg, max_proj);
+ current_ir_graph = rem;
+
+ return res;
+} /* new_rd_defaultProj */
+
+ir_node *
+new_rd_Conv(dbg_info *db, ir_graph *irg, ir_node *block, ir_node *op, ir_mode *mode)
+{
+ ir_node *res;
+ ir_graph *rem = current_ir_graph;
+
+ current_ir_graph = irg;
+ res = new_bd_Conv(db, block, op, mode, 0);
+ current_ir_graph = rem;
+
+ return res;
+} /* new_rd_Conv */
+
+ir_node *
+new_rd_Cast(dbg_info *db, ir_graph *irg, ir_node *block, ir_node *op, ir_type *to_tp)
+{
+ ir_node *res;
+ ir_graph *rem = current_ir_graph;
+
+ current_ir_graph = irg;
+ res = new_bd_Cast(db, block, op, to_tp);
+ current_ir_graph = rem;
+
+ return res;
+} /* new_rd_Cast */
+
+ir_node *
+new_rd_Tuple(dbg_info *db, ir_graph *irg, ir_node *block, int arity, ir_node **in)
+{
+ ir_node *res;
+ ir_graph *rem = current_ir_graph;
+
+ current_ir_graph = irg;
+ res = new_bd_Tuple(db, block, arity, in);
+ current_ir_graph = rem;
+
+ return res;
+} /* new_rd_Tuple */
+
+NEW_RD_BINOP(Add)
+NEW_RD_BINOP(Sub)
+NEW_RD_UNOP(Minus)
+NEW_RD_BINOP(Mul)
+NEW_RD_DIVOP(Quot)
+NEW_RD_DIVOP(DivMod)
+NEW_RD_DIVOP(Div)
+NEW_RD_DIVOP(Mod)
+NEW_RD_BINOP(And)
+NEW_RD_BINOP(Or)
+NEW_RD_BINOP(Eor)
+NEW_RD_UNOP(Not)
+NEW_RD_BINOP(Shl)
+NEW_RD_BINOP(Shr)
+NEW_RD_BINOP(Shrs)
+NEW_RD_BINOP(Rot)
+NEW_RD_UNOP(Abs)
+NEW_RD_BINOP(Carry)
+NEW_RD_BINOP(Borrow)
+
+ir_node *
+new_rd_Cmp(dbg_info *db, ir_graph *irg, ir_node *block,
+ ir_node *op1, ir_node *op2)
+{
+ ir_node *res;
+ ir_graph *rem = current_ir_graph;
+
+ current_ir_graph = irg;
+ res = new_bd_Cmp(db, block, op1, op2);
+ current_ir_graph = rem;
+
+ return res;
+} /* new_rd_Cmp */
+
+ir_node *
+new_rd_Jmp(dbg_info *db, ir_graph *irg, ir_node *block)
+{
+ ir_node *res;
+ ir_graph *rem = current_ir_graph;
+
+ current_ir_graph = irg;
+ res = new_bd_Jmp(db, block);
+ current_ir_graph = rem;
+
+ return res;
+} /* new_rd_Jmp */
+
+ir_node *
+new_rd_IJmp(dbg_info *db, ir_graph *irg, ir_node *block, ir_node *tgt)
+{
+ ir_node *res;
+ ir_graph *rem = current_ir_graph;
+
+ current_ir_graph = irg;
+ res = new_bd_IJmp(db, block, tgt);
+ current_ir_graph = rem;
+