Skip to content

Commit 99fb5bf

Browse files
committed
arcv: apex: Add subcode operand to APEX RTX instructions.
This patch extends "riscv_expand_builtin_direct" to optionally accept and attach a subcode operand for APEX builtins. A new "has_subcode_p" flag determines whether a constant RTL operand for the subcode should be added to the operand list. The subcode is used to extract the instruction name from "arcv_apex_builtins" once a pattern is selected in the machine description (see "arcv_apex_get_insn_name (rtx op)"). Also updates "riscv_check_builtin_call" and "riscv_resolve_overloaded_builtin" to handle the new "RISCV_BUILTIN_APEX" class. Signed-off-by: Luis Silva <[email protected]>
1 parent e91b1cc commit 99fb5bf

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

gcc/config/riscv/riscv-builtins.cc

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,8 @@ riscv_expand_builtin_insn (enum insn_code icode, unsigned int n_ops,
389389

390390
static rtx
391391
riscv_expand_builtin_direct (enum insn_code icode, rtx target, tree exp,
392-
bool has_target_p)
392+
bool has_target_p, unsigned int subcode,
393+
bool has_subcode_p)
393394
{
394395
struct expand_operand ops[MAX_RECOG_OPERANDS];
395396

@@ -398,6 +399,14 @@ riscv_expand_builtin_direct (enum insn_code icode, rtx target, tree exp,
398399
if (has_target_p)
399400
create_output_operand (&ops[opno++], target, TYPE_MODE (TREE_TYPE (exp)));
400401

402+
if (has_subcode_p)
403+
{
404+
/* Create an RTL constant for the APEX subcode. */
405+
rtx const_rtx = GEN_INT (subcode);
406+
/* Add the subcode as an additional input operand to the RTL expression. */
407+
create_input_operand (&ops[opno++], const_rtx, SImode);
408+
}
409+
401410
/* Map the arguments to the other operands. */
402411
gcc_assert (opno + call_expr_nargs (exp)
403412
== insn_data[icode].n_generator_args);
@@ -449,16 +458,34 @@ riscv_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
449458
{
450459
case RISCV_BUILTIN_VECTOR:
451460
return riscv_vector::expand_builtin (subcode, exp, target);
461+
case RISCV_BUILTIN_APEX: {
462+
const struct arcv_apex_builtin_description *d
463+
= &arcv_apex_builtins[subcode];
464+
465+
switch (d->builtin_type)
466+
{
467+
case RISCV_BUILTIN_DIRECT:
468+
return riscv_expand_builtin_direct (d->icode, target, exp, true,
469+
subcode, true);
470+
471+
case RISCV_BUILTIN_DIRECT_NO_TARGET:
472+
return riscv_expand_builtin_direct (d->icode, target, exp, false,
473+
subcode, true);
474+
}
475+
break;
476+
}
452477
case RISCV_BUILTIN_GENERAL: {
453478
const struct riscv_builtin_description *d = &riscv_builtins[subcode];
454479

455480
switch (d->builtin_type)
456481
{
457482
case RISCV_BUILTIN_DIRECT:
458-
return riscv_expand_builtin_direct (d->icode, target, exp, true);
483+
return riscv_expand_builtin_direct (d->icode, target, exp, true,
484+
subcode, false);
459485

460486
case RISCV_BUILTIN_DIRECT_NO_TARGET:
461-
return riscv_expand_builtin_direct (d->icode, target, exp, false);
487+
return riscv_expand_builtin_direct (d->icode, target, exp, false,
488+
subcode, false);
462489
}
463490
}
464491
}

gcc/config/riscv/riscv-c.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,9 @@ riscv_check_builtin_call (location_t loc, vec<location_t> arg_loc, tree fndecl,
524524
case RISCV_BUILTIN_VECTOR:
525525
return riscv_vector::check_builtin_call (loc, arg_loc, subcode,
526526
fndecl, nargs, args);
527+
528+
case RISCV_BUILTIN_APEX:
529+
return true;
527530
}
528531
gcc_unreachable ();
529532
}
@@ -551,6 +554,8 @@ riscv_resolve_overloaded_builtin (unsigned int uncast_location, tree fndecl,
551554
new_fndecl = riscv_vector::resolve_overloaded_builtin (loc, subcode,
552555
fndecl, arglist);
553556
break;
557+
case RISCV_BUILTIN_APEX:
558+
break;
554559
default:
555560
gcc_unreachable ();
556561
}

0 commit comments

Comments
 (0)