Skip to content

Commit 63087aa

Browse files
authored
Sort IntrinsicOp and intrinsic_op_names arrays (#9156)
Sort `IntrinsicOp` and `intrinsic_op_names` arrays and enforce sorting using `keep-sorted` markers.
1 parent 3b679be commit 63087aa

2 files changed

Lines changed: 11 additions & 55 deletions

File tree

src/IR.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,8 @@ Expr Call::make(const Function &func, const std::vector<Expr> &args, int idx) {
607607

608608
namespace {
609609

610-
const char *const intrinsic_op_names[] = {
610+
constexpr const char *intrinsic_op_names[] = {
611+
// keep-sorted start
611612
"abs",
612613
"absd",
613614
"add_image_checks_marker",
@@ -629,6 +630,7 @@ const char *const intrinsic_op_names[] = {
629630
"dynamic_shuffle",
630631
"extract_bits",
631632
"extract_mask_element",
633+
"get_runtime_vscale",
632634
"get_user_context",
633635
"gpu_thread_barrier",
634636
"halving_add",
@@ -665,8 +667,8 @@ const char *const intrinsic_op_names[] = {
665667
"rounding_shift_left",
666668
"rounding_shift_right",
667669
"saturating_add",
668-
"saturating_sub",
669670
"saturating_cast",
671+
"saturating_sub",
670672
"scatter_gather",
671673
"select_mask",
672674
"shift_left",
@@ -704,10 +706,10 @@ const char *const intrinsic_op_names[] = {
704706
"widening_shift_left",
705707
"widening_shift_right",
706708
"widening_sub",
707-
"get_runtime_vscale",
709+
// keep-sorted end
708710
};
709711

710-
static_assert(sizeof(intrinsic_op_names) / sizeof(intrinsic_op_names[0]) == Call::IntrinsicOpCount,
712+
static_assert(std::size(intrinsic_op_names) == Call::IntrinsicOpCount,
711713
"intrinsic_op_names needs attention");
712714

713715
} // namespace

src/IR.h

Lines changed: 5 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -605,156 +605,122 @@ struct Call : public ExprNode<Call> {
605605
// Please keep this list sorted alphabetically; the specific enum values
606606
// are *not* guaranteed to be stable across time.
607607
enum IntrinsicOp {
608+
// keep-sorted start sticky_comments=yes
608609
abs,
609-
610610
// Absolute difference between two values. absd(a, b) = abs(a - b), but
611611
// without overflow issues for integer types.
612612
absd,
613-
614613
// Marks the point where assertions on input images should be inserted
615614
add_image_checks_marker,
616-
617615
alloca,
618616
bitwise_and,
619617
bitwise_not,
620618
bitwise_or,
621619
bitwise_xor,
622-
623620
// Converts a boolean to a mask. Scalar bools become -1 (all bits set) when true,
624621
// 0 when false. Vector bools are converted to proper vector masks.
625622
bool_to_mask,
626-
627623
// Bundle multiple exprs together temporarily for analysis (e.g. CSE)
628624
bundle,
629-
630625
// Takes a sequence of (condition, function) pairs, and calls the first
631626
// function for which the associated condition is true. Caches this
632627
// choice and directly calls the associated function on all subsequent
633628
// uses. Args to the containing function are passed through to the
634629
// callee. Used to implement multi-target switching.
635630
call_cached_indirect_function,
636-
637631
// Casts a mask (boolean vector) to a different bit width
638632
cast_mask,
639-
640633
// Concatenate bits of the args, with least significant bits as the
641634
// first arg (i.e. little-endian)
642635
concat_bits,
643636
count_leading_zeros,
644637
count_trailing_zeros,
645638
debug_to_file,
646-
647639
// Declares that a box region of an allocation has been touched (used by bounds inference)
648640
declare_box_touched,
649-
650641
div_round_to_zero,
651-
652642
// A shuffle operation with runtime-varying indices.
653643
dynamic_shuffle,
654-
655644
// Extract some contiguous slice of bits from the argument starting at
656645
// the nth bit, counting from the least significant bit, with the number
657646
// of bits determined by the return type.
658647
extract_bits,
659-
660648
// Extracts a single element from a mask vector
661649
extract_mask_element,
662-
650+
// Returns the runtime value of ARM SVE vscale (the vector length multiplier)
651+
get_runtime_vscale,
663652
get_user_context,
664653
gpu_thread_barrier,
665654
halving_add,
666655
halving_sub,
667-
668656
// Hexagon HVX gather/scatter operations for indirect memory access
669657
hvx_gather,
670658
hvx_scatter,
671659
hvx_scatter_acc,
672660
hvx_scatter_release,
673-
674661
if_then_else,
675-
676662
// Vectorized if-then-else that operates on mask types
677663
if_then_else_mask,
678664
image_load,
679665
image_store,
680666
lerp,
681-
682667
// Loop partitioning hints used to help identify the 'steady state' of
683668
// loops. likely marks an if condition expression as likely to be true,
684669
// or marks the side of a min or max node which dominates in the steady
685670
// state. likely_if_innermost only applies the hint if this is the
686671
// innermost loop.
687672
likely,
688673
likely_if_innermost,
689-
690674
// Loads a member from a typed struct (used for halide_buffer_t and
691675
// related structures)
692676
load_typed_struct_member,
693-
694677
make_struct,
695-
696678
// Marks an expression to be memoized (computed once and cached)
697679
memoize_expr,
698-
699680
mod_round_to_zero,
700681
mul_shift_right,
701682
mux,
702683
popcount,
703684
prefetch,
704-
705685
// Marks the point where profiling should start counting pipeline instances
706686
// (used to exclude bounds queries from profiling)
707687
profiling_enable_instance_marker,
708-
709688
// Promises that a value is clamped to the given range. This allows the compiler
710689
// to optimize based on this assumption. promise_clamped is safe (adds a runtime check),
711690
// unsafe_promise_clamped skips the check.
712691
promise_clamped,
713-
714692
random,
715-
716693
// Registers a destructor function to be called when an object goes out
717694
// of scope. Used internally in codegen.
718695
register_destructor,
719-
720696
// Runtime assertions. require checks the condition and errors if false.
721697
// require_mask is the vectorized version that operates on masks.
722698
require,
723699
require_mask,
724-
725700
// Evaluates both arguments but returns the second one. Used to sequence side effects.
726701
return_second,
727-
728702
// Round a floating point value to nearest integer, with ties going to even
729703
round,
730-
731704
rounding_halving_add,
732705
rounding_mul_shift_right,
733706
rounding_shift_left,
734707
rounding_shift_right,
735708
saturating_add,
736-
saturating_sub,
737709
saturating_cast,
738-
710+
saturating_sub,
739711
// Used to implement scatter and gather (see IROperator.h)
740712
scatter_gather,
741-
742713
// Vectorized select that operates on mask types (similar to if_then_else_mask)
743714
select_mask,
744-
745715
shift_left,
746716
shift_right,
747-
748717
// Represents a signed integer overflow that occurred. Used to mark overflow points
749718
// rather than producing undefined behavior.
750719
signed_integer_overflow,
751-
752720
size_of_halide_buffer_t,
753-
754721
// Marks the point in lowering where the outermost skip stages checks
755722
// should be introduced.
756723
skip_stages_marker,
757-
758724
// Takes a realization name and a loop variable. Declares that values of
759725
// the realization that were stored on earlier loop iterations of the
760726
// given loop are potentially loaded in this loop iteration somewhere
@@ -763,10 +729,8 @@ struct Call : public ExprNode<Call> {
763729
// nodes. Communicates to storage folding that sliding window took
764730
// place.
765731
sliding_window_marker,
766-
767732
// Compute (arg[0] + arg[1]) / 2, assuming arg[0] < arg[1].
768733
sorted_avg,
769-
770734
// strict floating point ops. These are floating point ops that we would
771735
// like to optimize around (or let llvm optimize around) by treating
772736
// them as reals and ignoring the existence of nan and inf. Using these
@@ -782,45 +746,35 @@ struct Call : public ExprNode<Call> {
782746
strict_min,
783747
strict_mul,
784748
strict_sub,
785-
786749
// Convert a list of Exprs to a string
787750
stringify,
788-
789751
// Query properties of the compiled-for target (resolved at compile-time)
790752
target_arch_is,
791753
target_bits,
792754
target_has_feature,
793755
target_natural_vector_size,
794756
target_os_is,
795-
796757
// An undef is a magic value where storing it has no observable effect.
797758
undef,
798-
799759
// Mark a code path as unreachable so that it can be dead-code eliminated.
800760
unreachable,
801-
802761
// Promise an expression is bounded. Not checked. Injected by the
803762
// compiler itself during lowering when an early pass needs to
804763
// communicate boundedness to a later pass.
805764
unsafe_promise_clamped,
806-
807765
// One-sided variants of widening_add, widening_mul, and widening_sub.
808766
// arg[0] + widen(arg[1])
809767
widen_right_add,
810768
// arg[0] * widen(arg[1])
811769
widen_right_mul,
812770
// arg[0] - widen(arg[1])
813771
widen_right_sub,
814-
815772
widening_add,
816773
widening_mul,
817774
widening_shift_left,
818775
widening_shift_right,
819776
widening_sub,
820-
821-
// Returns the runtime value of ARM SVE vscale (the vector length multiplier)
822-
get_runtime_vscale,
823-
777+
// keep-sorted end
824778
IntrinsicOpCount // Sentinel: keep last.
825779
};
826780

0 commit comments

Comments
 (0)