<commit_before>/**
 * @file irarch.c
 * @date 28.9.2004
 * @author <NAME>
 * @brief Machine dependent firm optimizations.
 *
 * $Id$
 */
#include <stdlib.h>
#include <assert.h>

#include "irnode_t.h"
#include "irgraph_t.h"
#include "irmode_t.h"
#include "iropt_t.h"
#include "ircons_t.h"
#include "irgmod.h"
#include "irvrfy.h"
#include "tv_t.h"
#include "dbginfo_t.h"
#include "iropt_dbg.h"
#include "irflag_t.h"
#include "irhooks.h"
#include "ircons.h"
#include "irarch.h"
#include "irreflect.h"

#undef DEB

#define MAX_BITSTR 64

/* when we need verifying */
#ifdef NDEBUG
# define IRN_VRFY_IRG(res, irg)
#else
# define IRN_VRFY_IRG(res, irg)  irn_vrfy_irg(res, irg)
#endif

/** The params got from the factory in arch_dep_init(...). */
static const arch_dep_params_t *params = NULL;

/** The bit mask, which optimizations to apply. */
static arch_dep_opts_t opts;

/* we need this new pseudo op */
static ir_op *op_Mulh = NULL;

/**
 * construct a Mulh: Mulh(a,b) = (a * b) >> w, w is the with in bits of a, b
 */
static ir_node *
new_rd_Mulh (dbg_info *db, ir_graph *irg, ir_node *block,
       ir_node *op1, ir_node *op2, ir_mode *mode)
{
  ir_node *in[2];
  ir_node *res;

  if (! op_Mulh) {
    rflct_sig_t *sig;
    int mulh_opc = get_next_ir_opcode();

    op_Mulh = new_ir_op(mulh_opc, "Mulh",  op_pin_state_floats, irop_flag_commutative, oparity_binary, 0, 0);
    sig = rflct_signature_allocate(1, 3);
    rflct_signature_set_arg(sig, 0, 0, "Res", RFLCT_MC(Int), 0, 0);
    rflct_signature_set_arg(sig, 1, 0, "Block", RFLCT_MC(BB), 0, 0);
    rflct_signature_set_arg(sig, 1, 1, "Op 0", RFLCT_MC(Int), 0, 0);
    rflct_signature_set_arg(sig, 1, 2, "Op 1", RFLCT_MC(Int), 0, 0);

    rflct_new_opcode(mulh_opc, "Mulh", false);
    rflct_opcode_add_signature(mulh_opc, sig);

  }

  in[0] = op1;
  in[1] = op2;
  res = new_ir_node(db, irg, block, op_Mulh, mode, 2, in);
  res = optimize_node(res);
  IRN_VRFY_IRG(res, irg);
  return res;
}

ir_op *get_op_Mulh(void)  { return op_Mulh; }

void arch_dep_init(arch_dep_params_factory_t factory)
{
  opts = arch_dep_none;

  if (factory != NULL)
    params = factory();

  if (params && (opts & (arch_dep_div_by_const|arch_dep_mod_by_const))) {
    if (! op_Mulh) {
      /* create the Mulh operation */
      op_Mulh = new_ir_op(get_next_ir_opcode(), "Mulh",  op_pin_state_floats, irop_flag_commutative, oparity_binary, 0, 0);
    }
  }
}

void arch_dep_set_opts(arch_dep_opts_t the_opts) {
  opts = the_opts;
}

/* check, whether a mode allows a Mulh instruction */
static int allow_Mulh(ir_mode *mode)
{
  if (get_mode_size_bits(mode) > params->max_bits_for_mulh)
    return 0;
  return (mode_is_signed(mode) && params->allow_mulhs) || (!mode_is_signed(mode) && params->allow_mulhu);
}<commit_msg>always build the mulh op in init<commit_after>/**
 * @file irarch.c
 * @date 28.9.2004
 * @author <NAME>
 * @brief Machine dependent firm optimizations.
 *
 * $Id$
 */
#include <stdlib.h>
#include <assert.h>

#include "irnode_t.h"
#include "irgraph_t.h"
#include "irmode_t.h"
#include "iropt_t.h"
#include "ircons_t.h"
#include "irgmod.h"
#include "irvrfy.h"
#include "tv_t.h"
#include "dbginfo_t.h"
#include "iropt_dbg.h"
#include "irflag_t.h"
#include "irhooks.h"
#include "ircons.h"
#include "irarch.h"
#include "irreflect.h"

#undef DEB

#define MAX_BITSTR 64

/* when we need verifying */
#ifdef NDEBUG
# define IRN_VRFY_IRG(res, irg)
#else
# define IRN_VRFY_IRG(res, irg)  irn_vrfy_irg(res, irg)
#endif

/** The params got from the factory in arch_dep_init(...). */
static const arch_dep_params_t *params = NULL;

/** The bit mask, which optimizations to apply. */
static arch_dep_opts_t opts;

/* we need this new pseudo op */
static ir_op *op_Mulh = NULL;

/**
 * construct a Mulh: Mulh(a,b) = (a * b) >> w, w is the with in bits of a, b
 */
static ir_node *
new_rd_Mulh (dbg_info *db, ir_graph *irg, ir_node *block,
       ir_node *op1, ir_node *op2, ir_mode *mode)
{
  ir_node *in[2];
  ir_node *res;

  in[0] = op1;
  in[1] = op2;
  res = new_ir_node(db, irg, block, op_Mulh, mode, 2, in);
  res = optimize_node(res);
  IRN_VRFY_IRG(res, irg);
  return res;
}

ir_op *get_op_Mulh(void)  { return op_Mulh; }

void arch_dep_init(arch_dep_params_factory_t factory)
{
  opts = arch_dep_none;

  if (factory != NULL)
    params = factory();

  if (! op_Mulh) {
    rflct_sig_t *sig;
    int mulh_opc = get_next_ir_opcode();

    /* create the Mulh operation */
    op_Mulh = new_ir_op(mulh_opc, "Mulh",  op_pin_state_floats, irop_flag_commutative, oparity_binary, 0, 0, NULL);
    sig = rflct_signature_allocate(1, 3);
    rflct_signature_set_arg(sig, 0, 0, "Res", RFLCT_MC(Int), 0, 0);
    rflct_signature_set_arg(sig, 1, 0, "Block", RFLCT_MC(BB), 0, 0);
    rflct_signature_set_arg(sig, 1, 1, "Op 0", RFLCT_MC(Int), 0, 0);
    rflct_signature_set_arg(sig, 1, 2, "Op 1", RFLCT_MC(Int), 0, 0);

    rflct_new_opcode(mulh_opc, "Mulh", false);
    rflct_opcode_add_signature(mulh_opc, sig);
  }
}

void arch_dep_set_opts(arch_dep_opts_t the_opts) {
  opts = the_opts;
}

/* check, whether a mode allows a Mulh instruction */
static int allow_Mulh(ir_mode *mode)
{
  if (get_mode_size_bits(mode) > params->max_bits_for_mulh)
    return 0;
  return (mode_is_signed(mode) && params->allow_mulhs) || (!mode_is_signed(mode) && params->allow_mulhu);
}
{'fraction_non_alphanumeric': 0.14511873350923482, 'fraction_numerical': 0.015454202789295138, 'mean_word_length': 4.322968906720161, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6667534', 'n_tokens_mistral': 2388, 'n_tokens_neox': 2302, 'n_words': 525}