1*ed35a92cSVlad Serebrennikov //===------ SemaHexagon.cpp ------ Hexagon target-specific routines -------===//
2*ed35a92cSVlad Serebrennikov //
3*ed35a92cSVlad Serebrennikov // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*ed35a92cSVlad Serebrennikov // See https://llvm.org/LICENSE.txt for license information.
5*ed35a92cSVlad Serebrennikov // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*ed35a92cSVlad Serebrennikov //
7*ed35a92cSVlad Serebrennikov //===----------------------------------------------------------------------===//
8*ed35a92cSVlad Serebrennikov //
9*ed35a92cSVlad Serebrennikov // This file implements semantic analysis functions specific to Hexagon.
10*ed35a92cSVlad Serebrennikov //
11*ed35a92cSVlad Serebrennikov //===----------------------------------------------------------------------===//
12*ed35a92cSVlad Serebrennikov
13*ed35a92cSVlad Serebrennikov #include "clang/Sema/SemaHexagon.h"
14*ed35a92cSVlad Serebrennikov #include "clang/Basic/TargetBuiltins.h"
15*ed35a92cSVlad Serebrennikov #include "clang/Sema/Sema.h"
16*ed35a92cSVlad Serebrennikov #include "llvm/ADT/STLExtras.h"
17*ed35a92cSVlad Serebrennikov #include <cstdint>
18*ed35a92cSVlad Serebrennikov #include <iterator>
19*ed35a92cSVlad Serebrennikov
20*ed35a92cSVlad Serebrennikov namespace clang {
21*ed35a92cSVlad Serebrennikov
SemaHexagon(Sema & S)22*ed35a92cSVlad Serebrennikov SemaHexagon::SemaHexagon(Sema &S) : SemaBase(S) {}
23*ed35a92cSVlad Serebrennikov
CheckHexagonBuiltinArgument(unsigned BuiltinID,CallExpr * TheCall)24*ed35a92cSVlad Serebrennikov bool SemaHexagon::CheckHexagonBuiltinArgument(unsigned BuiltinID,
25*ed35a92cSVlad Serebrennikov CallExpr *TheCall) {
26*ed35a92cSVlad Serebrennikov struct ArgInfo {
27*ed35a92cSVlad Serebrennikov uint8_t OpNum;
28*ed35a92cSVlad Serebrennikov bool IsSigned;
29*ed35a92cSVlad Serebrennikov uint8_t BitWidth;
30*ed35a92cSVlad Serebrennikov uint8_t Align;
31*ed35a92cSVlad Serebrennikov };
32*ed35a92cSVlad Serebrennikov struct BuiltinInfo {
33*ed35a92cSVlad Serebrennikov unsigned BuiltinID;
34*ed35a92cSVlad Serebrennikov ArgInfo Infos[2];
35*ed35a92cSVlad Serebrennikov };
36*ed35a92cSVlad Serebrennikov
37*ed35a92cSVlad Serebrennikov static BuiltinInfo Infos[] = {
38*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_circ_ldd, {{ 3, true, 4, 3 }} },
39*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_circ_ldw, {{ 3, true, 4, 2 }} },
40*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_circ_ldh, {{ 3, true, 4, 1 }} },
41*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_circ_lduh, {{ 3, true, 4, 1 }} },
42*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_circ_ldb, {{ 3, true, 4, 0 }} },
43*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_circ_ldub, {{ 3, true, 4, 0 }} },
44*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_circ_std, {{ 3, true, 4, 3 }} },
45*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_circ_stw, {{ 3, true, 4, 2 }} },
46*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_circ_sth, {{ 3, true, 4, 1 }} },
47*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_circ_sthhi, {{ 3, true, 4, 1 }} },
48*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_circ_stb, {{ 3, true, 4, 0 }} },
49*ed35a92cSVlad Serebrennikov
50*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_L2_loadrub_pci, {{ 1, true, 4, 0 }} },
51*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_L2_loadrb_pci, {{ 1, true, 4, 0 }} },
52*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_L2_loadruh_pci, {{ 1, true, 4, 1 }} },
53*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_L2_loadrh_pci, {{ 1, true, 4, 1 }} },
54*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_L2_loadri_pci, {{ 1, true, 4, 2 }} },
55*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_L2_loadrd_pci, {{ 1, true, 4, 3 }} },
56*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_storerb_pci, {{ 1, true, 4, 0 }} },
57*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_storerh_pci, {{ 1, true, 4, 1 }} },
58*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_storerf_pci, {{ 1, true, 4, 1 }} },
59*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_storeri_pci, {{ 1, true, 4, 2 }} },
60*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_storerd_pci, {{ 1, true, 4, 3 }} },
61*ed35a92cSVlad Serebrennikov
62*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_A2_combineii, {{ 1, true, 8, 0 }} },
63*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_A2_tfrih, {{ 1, false, 16, 0 }} },
64*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_A2_tfril, {{ 1, false, 16, 0 }} },
65*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_A2_tfrpi, {{ 0, true, 8, 0 }} },
66*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_A4_bitspliti, {{ 1, false, 5, 0 }} },
67*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_A4_cmpbeqi, {{ 1, false, 8, 0 }} },
68*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_A4_cmpbgti, {{ 1, true, 8, 0 }} },
69*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_A4_cround_ri, {{ 1, false, 5, 0 }} },
70*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_A4_round_ri, {{ 1, false, 5, 0 }} },
71*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_A4_round_ri_sat, {{ 1, false, 5, 0 }} },
72*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_A4_vcmpbeqi, {{ 1, false, 8, 0 }} },
73*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_A4_vcmpbgti, {{ 1, true, 8, 0 }} },
74*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_A4_vcmpbgtui, {{ 1, false, 7, 0 }} },
75*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_A4_vcmpheqi, {{ 1, true, 8, 0 }} },
76*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_A4_vcmphgti, {{ 1, true, 8, 0 }} },
77*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_A4_vcmphgtui, {{ 1, false, 7, 0 }} },
78*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_A4_vcmpweqi, {{ 1, true, 8, 0 }} },
79*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_A4_vcmpwgti, {{ 1, true, 8, 0 }} },
80*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_A4_vcmpwgtui, {{ 1, false, 7, 0 }} },
81*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_C2_bitsclri, {{ 1, false, 6, 0 }} },
82*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_C2_muxii, {{ 2, true, 8, 0 }} },
83*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_C4_nbitsclri, {{ 1, false, 6, 0 }} },
84*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_F2_dfclass, {{ 1, false, 5, 0 }} },
85*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_F2_dfimm_n, {{ 0, false, 10, 0 }} },
86*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_F2_dfimm_p, {{ 0, false, 10, 0 }} },
87*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_F2_sfclass, {{ 1, false, 5, 0 }} },
88*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_F2_sfimm_n, {{ 0, false, 10, 0 }} },
89*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_F2_sfimm_p, {{ 0, false, 10, 0 }} },
90*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_M4_mpyri_addi, {{ 2, false, 6, 0 }} },
91*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_M4_mpyri_addr_u2, {{ 1, false, 6, 2 }} },
92*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_addasl_rrri, {{ 2, false, 3, 0 }} },
93*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_asl_i_p_acc, {{ 2, false, 6, 0 }} },
94*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_asl_i_p_and, {{ 2, false, 6, 0 }} },
95*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_asl_i_p, {{ 1, false, 6, 0 }} },
96*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_asl_i_p_nac, {{ 2, false, 6, 0 }} },
97*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_asl_i_p_or, {{ 2, false, 6, 0 }} },
98*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_asl_i_p_xacc, {{ 2, false, 6, 0 }} },
99*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_asl_i_r_acc, {{ 2, false, 5, 0 }} },
100*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_asl_i_r_and, {{ 2, false, 5, 0 }} },
101*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_asl_i_r, {{ 1, false, 5, 0 }} },
102*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_asl_i_r_nac, {{ 2, false, 5, 0 }} },
103*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_asl_i_r_or, {{ 2, false, 5, 0 }} },
104*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_asl_i_r_sat, {{ 1, false, 5, 0 }} },
105*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_asl_i_r_xacc, {{ 2, false, 5, 0 }} },
106*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_asl_i_vh, {{ 1, false, 4, 0 }} },
107*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_asl_i_vw, {{ 1, false, 5, 0 }} },
108*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_asr_i_p_acc, {{ 2, false, 6, 0 }} },
109*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_asr_i_p_and, {{ 2, false, 6, 0 }} },
110*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_asr_i_p, {{ 1, false, 6, 0 }} },
111*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_asr_i_p_nac, {{ 2, false, 6, 0 }} },
112*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_asr_i_p_or, {{ 2, false, 6, 0 }} },
113*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_asr_i_p_rnd_goodsyntax,
114*ed35a92cSVlad Serebrennikov {{ 1, false, 6, 0 }} },
115*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_asr_i_p_rnd, {{ 1, false, 6, 0 }} },
116*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_asr_i_r_acc, {{ 2, false, 5, 0 }} },
117*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_asr_i_r_and, {{ 2, false, 5, 0 }} },
118*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_asr_i_r, {{ 1, false, 5, 0 }} },
119*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_asr_i_r_nac, {{ 2, false, 5, 0 }} },
120*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_asr_i_r_or, {{ 2, false, 5, 0 }} },
121*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_asr_i_r_rnd_goodsyntax,
122*ed35a92cSVlad Serebrennikov {{ 1, false, 5, 0 }} },
123*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_asr_i_r_rnd, {{ 1, false, 5, 0 }} },
124*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_asr_i_svw_trun, {{ 1, false, 5, 0 }} },
125*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_asr_i_vh, {{ 1, false, 4, 0 }} },
126*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_asr_i_vw, {{ 1, false, 5, 0 }} },
127*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_clrbit_i, {{ 1, false, 5, 0 }} },
128*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_extractu, {{ 1, false, 5, 0 },
129*ed35a92cSVlad Serebrennikov { 2, false, 5, 0 }} },
130*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_extractup, {{ 1, false, 6, 0 },
131*ed35a92cSVlad Serebrennikov { 2, false, 6, 0 }} },
132*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_insert, {{ 2, false, 5, 0 },
133*ed35a92cSVlad Serebrennikov { 3, false, 5, 0 }} },
134*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_insertp, {{ 2, false, 6, 0 },
135*ed35a92cSVlad Serebrennikov { 3, false, 6, 0 }} },
136*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_p_acc, {{ 2, false, 6, 0 }} },
137*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_p_and, {{ 2, false, 6, 0 }} },
138*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_p, {{ 1, false, 6, 0 }} },
139*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_p_nac, {{ 2, false, 6, 0 }} },
140*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_p_or, {{ 2, false, 6, 0 }} },
141*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_p_xacc, {{ 2, false, 6, 0 }} },
142*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_r_acc, {{ 2, false, 5, 0 }} },
143*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_r_and, {{ 2, false, 5, 0 }} },
144*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_r, {{ 1, false, 5, 0 }} },
145*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_r_nac, {{ 2, false, 5, 0 }} },
146*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_r_or, {{ 2, false, 5, 0 }} },
147*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_r_xacc, {{ 2, false, 5, 0 }} },
148*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_vh, {{ 1, false, 4, 0 }} },
149*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_vw, {{ 1, false, 5, 0 }} },
150*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_setbit_i, {{ 1, false, 5, 0 }} },
151*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_tableidxb_goodsyntax,
152*ed35a92cSVlad Serebrennikov {{ 2, false, 4, 0 },
153*ed35a92cSVlad Serebrennikov { 3, false, 5, 0 }} },
154*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_tableidxd_goodsyntax,
155*ed35a92cSVlad Serebrennikov {{ 2, false, 4, 0 },
156*ed35a92cSVlad Serebrennikov { 3, false, 5, 0 }} },
157*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_tableidxh_goodsyntax,
158*ed35a92cSVlad Serebrennikov {{ 2, false, 4, 0 },
159*ed35a92cSVlad Serebrennikov { 3, false, 5, 0 }} },
160*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_tableidxw_goodsyntax,
161*ed35a92cSVlad Serebrennikov {{ 2, false, 4, 0 },
162*ed35a92cSVlad Serebrennikov { 3, false, 5, 0 }} },
163*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_togglebit_i, {{ 1, false, 5, 0 }} },
164*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_tstbit_i, {{ 1, false, 5, 0 }} },
165*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_valignib, {{ 2, false, 3, 0 }} },
166*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S2_vspliceib, {{ 2, false, 3, 0 }} },
167*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S4_addi_asl_ri, {{ 2, false, 5, 0 }} },
168*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S4_addi_lsr_ri, {{ 2, false, 5, 0 }} },
169*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S4_andi_asl_ri, {{ 2, false, 5, 0 }} },
170*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S4_andi_lsr_ri, {{ 2, false, 5, 0 }} },
171*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S4_clbaddi, {{ 1, true , 6, 0 }} },
172*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S4_clbpaddi, {{ 1, true, 6, 0 }} },
173*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S4_extract, {{ 1, false, 5, 0 },
174*ed35a92cSVlad Serebrennikov { 2, false, 5, 0 }} },
175*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S4_extractp, {{ 1, false, 6, 0 },
176*ed35a92cSVlad Serebrennikov { 2, false, 6, 0 }} },
177*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S4_lsli, {{ 0, true, 6, 0 }} },
178*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S4_ntstbit_i, {{ 1, false, 5, 0 }} },
179*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S4_ori_asl_ri, {{ 2, false, 5, 0 }} },
180*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S4_ori_lsr_ri, {{ 2, false, 5, 0 }} },
181*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S4_subi_asl_ri, {{ 2, false, 5, 0 }} },
182*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S4_subi_lsr_ri, {{ 2, false, 5, 0 }} },
183*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S4_vrcrotate_acc, {{ 3, false, 2, 0 }} },
184*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S4_vrcrotate, {{ 2, false, 2, 0 }} },
185*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S5_asrhub_rnd_sat_goodsyntax,
186*ed35a92cSVlad Serebrennikov {{ 1, false, 4, 0 }} },
187*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S5_asrhub_sat, {{ 1, false, 4, 0 }} },
188*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S5_vasrhrnd_goodsyntax,
189*ed35a92cSVlad Serebrennikov {{ 1, false, 4, 0 }} },
190*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S6_rol_i_p, {{ 1, false, 6, 0 }} },
191*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S6_rol_i_p_acc, {{ 2, false, 6, 0 }} },
192*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S6_rol_i_p_and, {{ 2, false, 6, 0 }} },
193*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S6_rol_i_p_nac, {{ 2, false, 6, 0 }} },
194*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S6_rol_i_p_or, {{ 2, false, 6, 0 }} },
195*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S6_rol_i_p_xacc, {{ 2, false, 6, 0 }} },
196*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S6_rol_i_r, {{ 1, false, 5, 0 }} },
197*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S6_rol_i_r_acc, {{ 2, false, 5, 0 }} },
198*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S6_rol_i_r_and, {{ 2, false, 5, 0 }} },
199*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S6_rol_i_r_nac, {{ 2, false, 5, 0 }} },
200*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S6_rol_i_r_or, {{ 2, false, 5, 0 }} },
201*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_S6_rol_i_r_xacc, {{ 2, false, 5, 0 }} },
202*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_V6_valignbi, {{ 2, false, 3, 0 }} },
203*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_V6_valignbi_128B, {{ 2, false, 3, 0 }} },
204*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_V6_vlalignbi, {{ 2, false, 3, 0 }} },
205*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_V6_vlalignbi_128B, {{ 2, false, 3, 0 }} },
206*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_V6_vrmpybusi, {{ 2, false, 1, 0 }} },
207*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_V6_vrmpybusi_128B, {{ 2, false, 1, 0 }} },
208*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_V6_vrmpybusi_acc, {{ 3, false, 1, 0 }} },
209*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_V6_vrmpybusi_acc_128B,
210*ed35a92cSVlad Serebrennikov {{ 3, false, 1, 0 }} },
211*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_V6_vrmpyubi, {{ 2, false, 1, 0 }} },
212*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_V6_vrmpyubi_128B, {{ 2, false, 1, 0 }} },
213*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_V6_vrmpyubi_acc, {{ 3, false, 1, 0 }} },
214*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_V6_vrmpyubi_acc_128B,
215*ed35a92cSVlad Serebrennikov {{ 3, false, 1, 0 }} },
216*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_V6_vrsadubi, {{ 2, false, 1, 0 }} },
217*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_V6_vrsadubi_128B, {{ 2, false, 1, 0 }} },
218*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_V6_vrsadubi_acc, {{ 3, false, 1, 0 }} },
219*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_V6_vrsadubi_acc_128B,
220*ed35a92cSVlad Serebrennikov {{ 3, false, 1, 0 }} },
221*ed35a92cSVlad Serebrennikov
222*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_V6_v6mpyhubs10, {{ 2, false, 2, 0 }} },
223*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_V6_v6mpyhubs10_128B,
224*ed35a92cSVlad Serebrennikov {{ 2, false, 2, 0 }} },
225*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_V6_v6mpyhubs10_vxx,
226*ed35a92cSVlad Serebrennikov {{ 3, false, 2, 0 }} },
227*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_V6_v6mpyhubs10_vxx_128B,
228*ed35a92cSVlad Serebrennikov {{ 3, false, 2, 0 }} },
229*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_V6_v6mpyvubs10, {{ 2, false, 2, 0 }} },
230*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_V6_v6mpyvubs10_128B,
231*ed35a92cSVlad Serebrennikov {{ 2, false, 2, 0 }} },
232*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_V6_v6mpyvubs10_vxx,
233*ed35a92cSVlad Serebrennikov {{ 3, false, 2, 0 }} },
234*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_V6_v6mpyvubs10_vxx_128B,
235*ed35a92cSVlad Serebrennikov {{ 3, false, 2, 0 }} },
236*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_V6_vlutvvbi, {{ 2, false, 3, 0 }} },
237*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_V6_vlutvvbi_128B, {{ 2, false, 3, 0 }} },
238*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_V6_vlutvvb_oracci, {{ 3, false, 3, 0 }} },
239*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_V6_vlutvvb_oracci_128B,
240*ed35a92cSVlad Serebrennikov {{ 3, false, 3, 0 }} },
241*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_V6_vlutvwhi, {{ 2, false, 3, 0 }} },
242*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_V6_vlutvwhi_128B, {{ 2, false, 3, 0 }} },
243*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_V6_vlutvwh_oracci, {{ 3, false, 3, 0 }} },
244*ed35a92cSVlad Serebrennikov { Hexagon::BI__builtin_HEXAGON_V6_vlutvwh_oracci_128B,
245*ed35a92cSVlad Serebrennikov {{ 3, false, 3, 0 }} },
246*ed35a92cSVlad Serebrennikov };
247*ed35a92cSVlad Serebrennikov
248*ed35a92cSVlad Serebrennikov // Use a dynamically initialized static to sort the table exactly once on
249*ed35a92cSVlad Serebrennikov // first run.
250*ed35a92cSVlad Serebrennikov static const bool SortOnce =
251*ed35a92cSVlad Serebrennikov (llvm::sort(Infos,
252*ed35a92cSVlad Serebrennikov [](const BuiltinInfo &LHS, const BuiltinInfo &RHS) {
253*ed35a92cSVlad Serebrennikov return LHS.BuiltinID < RHS.BuiltinID;
254*ed35a92cSVlad Serebrennikov }),
255*ed35a92cSVlad Serebrennikov true);
256*ed35a92cSVlad Serebrennikov (void)SortOnce;
257*ed35a92cSVlad Serebrennikov
258*ed35a92cSVlad Serebrennikov const BuiltinInfo *F = llvm::partition_point(
259*ed35a92cSVlad Serebrennikov Infos, [=](const BuiltinInfo &BI) { return BI.BuiltinID < BuiltinID; });
260*ed35a92cSVlad Serebrennikov if (F == std::end(Infos) || F->BuiltinID != BuiltinID)
261*ed35a92cSVlad Serebrennikov return false;
262*ed35a92cSVlad Serebrennikov
263*ed35a92cSVlad Serebrennikov bool Error = false;
264*ed35a92cSVlad Serebrennikov
265*ed35a92cSVlad Serebrennikov for (const ArgInfo &A : F->Infos) {
266*ed35a92cSVlad Serebrennikov // Ignore empty ArgInfo elements.
267*ed35a92cSVlad Serebrennikov if (A.BitWidth == 0)
268*ed35a92cSVlad Serebrennikov continue;
269*ed35a92cSVlad Serebrennikov
270*ed35a92cSVlad Serebrennikov int32_t Min = A.IsSigned ? -(1 << (A.BitWidth - 1)) : 0;
271*ed35a92cSVlad Serebrennikov int32_t Max = (1 << (A.IsSigned ? A.BitWidth - 1 : A.BitWidth)) - 1;
272*ed35a92cSVlad Serebrennikov if (!A.Align) {
273*ed35a92cSVlad Serebrennikov Error |= SemaRef.BuiltinConstantArgRange(TheCall, A.OpNum, Min, Max);
274*ed35a92cSVlad Serebrennikov } else {
275*ed35a92cSVlad Serebrennikov unsigned M = 1 << A.Align;
276*ed35a92cSVlad Serebrennikov Min *= M;
277*ed35a92cSVlad Serebrennikov Max *= M;
278*ed35a92cSVlad Serebrennikov Error |= SemaRef.BuiltinConstantArgRange(TheCall, A.OpNum, Min, Max);
279*ed35a92cSVlad Serebrennikov Error |= SemaRef.BuiltinConstantArgMultiple(TheCall, A.OpNum, M);
280*ed35a92cSVlad Serebrennikov }
281*ed35a92cSVlad Serebrennikov }
282*ed35a92cSVlad Serebrennikov return Error;
283*ed35a92cSVlad Serebrennikov }
284*ed35a92cSVlad Serebrennikov
CheckHexagonBuiltinFunctionCall(unsigned BuiltinID,CallExpr * TheCall)285*ed35a92cSVlad Serebrennikov bool SemaHexagon::CheckHexagonBuiltinFunctionCall(unsigned BuiltinID,
286*ed35a92cSVlad Serebrennikov CallExpr *TheCall) {
287*ed35a92cSVlad Serebrennikov return CheckHexagonBuiltinArgument(BuiltinID, TheCall);
288*ed35a92cSVlad Serebrennikov }
289*ed35a92cSVlad Serebrennikov
290*ed35a92cSVlad Serebrennikov } // namespace clang
291