aboutsummaryrefslogtreecommitdiff
path: root/gcc/config/cil32/cil32.c
blob: 08fbbef2a1f38a15729bc3660195572f32964278 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
/* Definitions for GCC.  Part of the machine description for cil32.

   Copyright (C) 2006-2009 Free Software Foundation, Inc.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2, or (at your option) any later
version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING.  If not, write to the Free
Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.

Authors:
   Andrea Bona
   Andrea Ornstein
   Erven Rohou
   Roberto Costa

Contact information at STMicroelectronics:
Andrea C. Ornstein      <andrea.ornstein@st.com>
Contact information at INRIA:
Erven Rohou             <erven.rohou@inria.fr>
*/

#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "rtl.h"
#include "regs.h"
#include "hard-reg-set.h"
#include "real.h"
#include "insn-config.h"
#include "conditions.h"
#include "insn-attr.h"
#include "flags.h"
#include "tree.h"
#include "expr.h"
#include "except.h"
#include "function.h"
#include "toplev.h"
#include "recog.h"
#include "reload.h"
#include "tm_p.h"
#include "debug.h"
#include "output.h"
#include "target.h"
#include "target-def.h"
#include "ggc.h"
#include "optabs.h"
#include "langhooks.h"

#include "cil32-protos.h"
#include "cil-builtins.h"
#include "cil-types.h"
#include "cil-refs.h"
#include "emit-cil.h"

static struct machine_function *cil_init_machine_status (void);
static hashval_t cil_basic_block_hash (const void *);
static int cil_basic_block_eq (const void *, const void *);

static tree cil32_handle_function_attribute (tree *, tree, tree, int, bool *);
static void cil32_file_start (void);
static void cil32_file_end (void);
static void cil32_named_section (const char *, unsigned int, tree);
static void cil32_globalize_label (FILE *, const char *);
static bool cil32_assemble_integer (rtx, unsigned int, int);

static tree cil32_gimplify_va_arg (tree, tree, tree*, tree*);

static bool cil32_vector_mode_supported_p (enum machine_mode);

const struct attribute_spec cil32_attribute_table[];

static tree cil32_builtin_get_vec_stride (tree);
static tree cil32_builtin_build_uniform_vec (tree, tree);
static tree cil32_builtin_build_affine_vec (tree, tree, tree);
static tree cil32_builtin_get_vec_size (tree);
static tree cil32_builtin_get_vec_align (tree);
static tree cil32_builtin_build_reduc_epilogue (enum tree_code, tree);
static bool cil32_builtin_vectorize_independent_drs_only (void);
static bool cil32_builtin_always_realign (void);
static tree cil32_builtin_mask_for_load (void);
static tree cil32_builtin_realign_load (tree);
static bool cil32_builtin_can_force_alignment (void);
static tree cil32_builtin_get_loop_niters (void);
static tree cil32_builtin_pattern (enum tree_code code, tree);
static tree cil32_builtin_realign_offset (tree);

/* Initialize the GCC target structure.  */
#undef TARGET_ATTRIBUTE_TABLE
#define TARGET_ATTRIBUTE_TABLE cil32_attribute_table

#undef TARGET_INIT_BUILTINS
#define TARGET_INIT_BUILTINS cil_init_builtins


#undef TARGET_ASM_FILE_START
#define TARGET_ASM_FILE_START cil32_file_start
#undef TARGET_ASM_FILE_END
#define TARGET_ASM_FILE_END cil32_file_end
#undef	TARGET_ASM_NAMED_SECTION
#define TARGET_ASM_NAMED_SECTION cil32_named_section
#undef TARGET_ASM_GLOBALIZE_LABEL
#define TARGET_ASM_GLOBALIZE_LABEL cil32_globalize_label
#undef  TARGET_ASM_INTEGER
#define TARGET_ASM_INTEGER cil32_assemble_integer

#undef TARGET_BUILD_BUILTIN_VA_LIST
#define TARGET_BUILD_BUILTIN_VA_LIST cil_build_builtin_va_list
#undef TARGET_GIMPLIFY_VA_ARG_EXPR
#define TARGET_GIMPLIFY_VA_ARG_EXPR cil32_gimplify_va_arg

#undef TARGET_VECTOR_MODE_SUPPORTED_P
#define TARGET_VECTOR_MODE_SUPPORTED_P cil32_vector_mode_supported_p

#undef TARGET_VECTORIZE_BUILTIN_GET_VEC_STRIDE
#define TARGET_VECTORIZE_BUILTIN_GET_VEC_STRIDE cil32_builtin_get_vec_stride

#undef TARGET_VECTORIZE_BUILTIN_GET_VEC_SIZE
#define TARGET_VECTORIZE_BUILTIN_GET_VEC_SIZE cil32_builtin_get_vec_size

#undef TARGET_VECTORIZE_BUILTIN_BUILD_UNIFORM_VEC
#define TARGET_VECTORIZE_BUILTIN_BUILD_UNIFORM_VEC \
  cil32_builtin_build_uniform_vec

#undef TARGET_VECTORIZE_BUILTIN_BUILD_AFFINE_VEC
#define TARGET_VECTORIZE_BUILTIN_BUILD_AFFINE_VEC \
  cil32_builtin_build_affine_vec

#undef TARGET_VECTORIZE_BUILTIN_GET_VEC_ALIGN
#define TARGET_VECTORIZE_BUILTIN_GET_VEC_ALIGN cil32_builtin_get_vec_align

#undef TARGET_VECTORIZE_BUILTIN_BUILD_REDUC_EPILOGUE
#define TARGET_VECTORIZE_BUILTIN_BUILD_REDUC_EPILOGUE \
  cil32_builtin_build_reduc_epilogue

#undef TARGET_VECTORIZE_BUILTIN_VECT_INDEPENDENT_DRS
#define TARGET_VECTORIZE_BUILTIN_VECT_INDEPENDENT_DRS \
  cil32_builtin_vectorize_independent_drs_only

#undef TARGET_VECTORIZE_BUILTIN_ALWAYS_REALIGN
#define TARGET_VECTORIZE_BUILTIN_ALWAYS_REALIGN \
  cil32_builtin_always_realign

#undef TARGET_VECTORIZE_BUILTIN_MASK_FOR_LOAD
#define TARGET_VECTORIZE_BUILTIN_MASK_FOR_LOAD \
  cil32_builtin_mask_for_load

#undef TARGET_VECTORIZE_BUILTIN_REALIGN_LOAD
#define TARGET_VECTORIZE_BUILTIN_REALIGN_LOAD \
  cil32_builtin_realign_load

#undef TARGET_VECTORIZE_BUILTIN_CAN_FORCE_ALIGNMENT
#define TARGET_VECTORIZE_BUILTIN_CAN_FORCE_ALIGNMENT \
  cil32_builtin_can_force_alignment

#undef TARGET_VECTORIZE_BUILTIN_GET_LOOP_NITERS
#define TARGET_VECTORIZE_BUILTIN_GET_LOOP_NITERS \
  cil32_builtin_get_loop_niters

#undef TARGET_VECTORIZE_BUILTIN_PATTERN
#define TARGET_VECTORIZE_BUILTIN_PATTERN \
  cil32_builtin_pattern 

#undef TARGET_VECTORIZE_BUILTIN_REALIGN_OFFSET
#define TARGET_VECTORIZE_BUILTIN_REALIGN_OFFSET \
  cil32_builtin_realign_offset

struct gcc_target targetm = TARGET_INITIALIZER;

/* CIL32 Code */

static struct machine_function *
cil_init_machine_status (void)
{
  struct machine_function *machine = GGC_NEW (struct machine_function);

  machine->label_id = 0;
  machine->label_addrs = NULL_TREE;
  machine->locals_init = false;
  machine->has_vec = false;
  machine->bb_seqs = htab_create_ggc (32, cil_basic_block_hash,
				      cil_basic_block_eq, NULL);

  return machine;
}

void
cil_override_options (void)
{
  init_machine_status = cil_init_machine_status;

  if (simd_backend_str)
    {
      if (strcmp (simd_backend_str, "mono") == 0)
        {
	  warning (0, "The Mono SIMD backend is unlikely to work\n");
          simd_type = MONO_SIMD;
        }
      else if (strcmp (simd_backend_str, "gcc") == 0)
        {
	  warning (0, "The Mono GCC backend is unlikely to work\n");
          simd_type = GCC_SIMD;
        }
      else if (strcmp (simd_backend_str, "generic") == 0)
        simd_type = GEN_SIMD;
      else
	{
	  fprintf (stderr, "Unknown SIMD backend '%s', using GENERIC\n",
		   simd_backend_str);
          simd_type = GEN_SIMD;
	}
    }
  else
    simd_type = GEN_SIMD;
}

/* Hash value calculation function for CIL basic blocks.  */

static hashval_t
cil_basic_block_hash (const void *ptr)
{
  const_cil_basic_block cbb = (const_cil_basic_block) ptr;

  return (hashval_t) ((long) cbb->bb >> 3);
}

/* Equality function for CIL basic blocks.  */

static int
cil_basic_block_eq (const void *ptr1, const void *ptr2)
{
  const_cil_basic_block cbb1 = (const_cil_basic_block) ptr1;
  const_cil_basic_block cbb2 = (const_cil_basic_block) ptr2;

  return cbb1->bb == cbb2->bb;
}

static tree
cil32_handle_function_attribute (tree *node, tree name, tree args,
				 int flags ATTRIBUTE_UNUSED,
				 bool *no_add_attrs)
{
  if (TREE_CODE (*node) != FUNCTION_DECL)
    {
      warning (OPT_Wattributes, "%qs attribute only applies to functions",
	       IDENTIFIER_POINTER (name));
      *no_add_attrs = true;
      return NULL_TREE;
    }

  if (strcmp (IDENTIFIER_POINTER (name), "pinvoke") == 0)
    {
      add_pinvoke (*node);
      add_referenced_assembly (TREE_STRING_POINTER (TREE_VALUE (args)));
    }
  else if (strcmp (IDENTIFIER_POINTER (name), "assembly_name") == 0)
    add_referenced_assembly (TREE_STRING_POINTER (TREE_VALUE (args)));

  return NULL_TREE;
}

/* Table of valid machine attributes.  */
const struct attribute_spec cil32_attribute_table[] =
{
  /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
  { "assembly_name", 1,1,false,false,false, cil32_handle_function_attribute },
  { "cil_name",      1,1,false,false,false, cil32_handle_function_attribute },
  { "cil_strattr",   1,1,false,false,false, cil32_handle_function_attribute },
  { "pinvoke",       1,2,false,false,false, cil32_handle_function_attribute },
  { NULL,            0,0,false,false,false, NULL }
};

static void
cil32_file_start (void)
{
  refs_init ();
  emit_vcg_init ();
  emit_cil_init ();
}

static void
cil32_file_end (void)
{
  emit_cil_fini ();
  emit_vcg_fini ();
  refs_fini ();
}

static void
cil32_named_section (const char *name ATTRIBUTE_UNUSED,
                     unsigned int flags ATTRIBUTE_UNUSED,
                     tree decl ATTRIBUTE_UNUSED)
{
}

static void
cil32_globalize_label (FILE *stream ATTRIBUTE_UNUSED,
                       const char *name ATTRIBUTE_UNUSED)
{
}

static bool
cil32_assemble_integer (rtx x ATTRIBUTE_UNUSED,
                        unsigned int size ATTRIBUTE_UNUSED,
                        int aligned_p ATTRIBUTE_UNUSED)
{
  return true;
}



void
cil32_ivdep (struct cpp_reader * x ATTRIBUTE_UNUSED)
{
    warning (OPT_Wcil_pragma_ignored, "pragma ivdep not implemented yet");
}


void
cil32_loopdep_liberal (struct cpp_reader * x ATTRIBUTE_UNUSED)
{
    warning (OPT_Wcil_pragma_ignored, "pragma loopdep not implemented yet");
}

void
cil32_loopdep_parallel (struct cpp_reader * x ATTRIBUTE_UNUSED)
{
    warning (OPT_Wcil_pragma_ignored, "pragma loopdep not implemented yet");
}

void
cil32_loopdep_vector (struct cpp_reader * x ATTRIBUTE_UNUSED)
{
    warning (OPT_Wcil_pragma_ignored, "pragma loopdep not implemented yet");
}

static tree
cil32_gimplify_va_arg (tree valist, tree type, tree *pre_p ATTRIBUTE_UNUSED, tree *post_p ATTRIBUTE_UNUSED)
{
  tree fcall;
  tree ptr_type = build_pointer_type (type);
  tree arglist = build_tree_list (NULL_TREE, build_int_cstu (ptr_type, 0));
  arglist = tree_cons (NULL_TREE, valist, arglist);
  fcall = build_function_call_expr (cil32_builtins[CIL32_BUILT_IN_VA_ARG], arglist);
  TREE_TYPE (fcall) = ptr_type;
  return build1 (INDIRECT_REF, type, fcall);
}

/* Target hook for vector_mode_supported_p.  */
static bool
cil32_vector_mode_supported_p (enum machine_mode mode ATTRIBUTE_UNUSED)
{
  return true;
}

static tree
cil32_builtin_get_vec_size (tree type ATTRIBUTE_UNUSED)
{
  return cil32_builtins[CIL32_GCC_GET_STEP];
}

static tree
cil32_builtin_get_vec_stride (tree type)
{
  tree elem_type = TREE_TYPE (type);
  unsigned element_size = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (elem_type));

  if (TREE_CODE (elem_type) == INTEGER_TYPE)
    {
      switch (element_size)
        {
#if 0
        case 8:
          return cil32_builtins[CIL32_GCC_GET_STRIDE_VDI];
#endif
        case 4:
          return cil32_builtins[CIL32_GCC_GET_STRIDE_VSI];

        case 2:
          return cil32_builtins[CIL32_GCC_GET_STRIDE_VHI];

        case 1:
          return cil32_builtins[CIL32_GCC_GET_STRIDE_VQI];

        default:
          return NULL_TREE;
        }
    }
  else
    {
      switch (element_size)
        {
#if 0
        case 8:
          return cil32_builtins[CIL32_GCC_GET_STRIDE_VDF];
#endif
        case 4:
          return cil32_builtins[CIL32_GCC_GET_STRIDE_VSF];

        default:
          return NULL_TREE;
        }
    }
}

static tree
cil32_builtin_get_vec_align (tree type)
{
  tree elem_type = TREE_TYPE (type);
  unsigned element_size = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (elem_type));

  if (TREE_CODE (elem_type) == INTEGER_TYPE)
    {
      switch (element_size)
        {
#if 0
        case 8:
          return cil32_builtins[CIL32_GCC_GET_ALIGN_VDI];
#endif
        case 4:
          return cil32_builtins[CIL32_GCC_GET_ALIGN_VSI];

        case 2:
          return cil32_builtins[CIL32_GCC_GET_ALIGN_VHI];

        case 1:
          return cil32_builtins[CIL32_GCC_GET_ALIGN_VQI];

        default:
          return NULL_TREE;
        }
    }
  else
    {
      switch (element_size)
        {
#if 0
        case 8:
          return cil32_builtins[CIL32_GCC_GET_ALIGN_VDF];
#endif
        case 4:
          return cil32_builtins[CIL32_GCC_GET_ALIGN_VSF];

        default:
          return NULL_TREE;
        }
    }
}

static tree cil32_builtin_build_uniform_vec (tree value ATTRIBUTE_UNUSED, 
                                             tree type)
{
  tree elem_type = TREE_TYPE (type);
  unsigned element_size = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (elem_type));

  if (TREE_CODE (elem_type) == INTEGER_TYPE)
    {
      switch (element_size)
        {
#if 0
        case 8:
          return cil32_builtins[CIL32_GCC_BUILD_UNIFORM_VEC_VDI];
#endif
        case 4:
          return cil32_builtins[CIL32_GCC_BUILD_UNIFORM_VEC_VSI];

        case 2:
          return cil32_builtins[CIL32_GCC_BUILD_UNIFORM_VEC_VHI];

        case 1:
          return cil32_builtins[CIL32_GCC_BUILD_UNIFORM_VEC_VQI];

        default:
          return NULL_TREE;
        }
    }
  else
    {
      switch (element_size)
        {
#if 0
        case 8:
          return cil32_builtins[CIL32_GCC_BUILD_UNIFORM_VEC_VDF];
#endif
        case 4:
          return cil32_builtins[CIL32_GCC_BUILD_UNIFORM_VEC_VSF];

        default:
          return NULL_TREE;
        }
    }
}

static tree cil32_builtin_build_affine_vec (tree init ATTRIBUTE_UNUSED, 
                                            tree step ATTRIBUTE_UNUSED, 
                                            tree type)
{
  tree elem_type = TREE_TYPE (type);
  unsigned element_size = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (elem_type));

  if (TREE_CODE (elem_type) == INTEGER_TYPE)
    {
      switch (element_size)
        {
#if 0
        case 8:
          return cil32_builtins[CIL32_GCC_BUILD_AFFINE_VEC_VDI];
#endif
        case 4:
          return cil32_builtins[CIL32_GCC_BUILD_AFFINE_VEC_VSI];

        case 2:
          return cil32_builtins[CIL32_GCC_BUILD_AFFINE_VEC_VHI];

        case 1:
          return cil32_builtins[CIL32_GCC_BUILD_AFFINE_VEC_VQI];

        default:
          return NULL_TREE;
        }
    }
  else
    {
      switch (element_size)
        {
#if 0
        case 8:
          return cil32_builtins[CIL32_GCC_BUILD_AFFINE_VEC_VDF];
#endif
        case 4:
          return cil32_builtins[CIL32_GCC_BUILD_AFFINE_VEC_VSF];

        default:
          return NULL_TREE;
        }
    }
}


static tree cil32_builtin_build_reduc_epilogue (enum tree_code reduc_code, 
                                                tree type) 
{
  tree elem_type = TREE_TYPE (type);
  unsigned element_size = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (elem_type));

  if (TREE_CODE (elem_type) == INTEGER_TYPE)
    {
      switch (element_size)
        {
#if 0
        case 8:
          switch (reduc_code)
            {
            case REDUC_MAX_EXPR:
              return cil32_builtins[CIL32_GCC_BUILD_REDUC_MAX_EPILOGUE_VDI];

            case REDUC_MIN_EXPR:
              return cil32_builtins[CIL32_GCC_BUILD_REDUC_MIN_EPILOGUE_VDI];

            case REDUC_PLUS_EXPR:
              return cil32_builtins[CIL32_GCC_BUILD_REDUC_PLUS_EPILOGUE_VDI];

            default:
              return NULL_TREE;
            }
#endif
        case 4:
          switch (reduc_code)
            {
            case REDUC_MAX_EXPR:
              return cil32_builtins[CIL32_GCC_BUILD_REDUC_MAX_EPILOGUE_VSI];

            case REDUC_MIN_EXPR:
              return cil32_builtins[CIL32_GCC_BUILD_REDUC_MIN_EPILOGUE_VSI];

            case REDUC_PLUS_EXPR:
              return cil32_builtins[CIL32_GCC_BUILD_REDUC_PLUS_EPILOGUE_VSI];

            default:
              return NULL_TREE;
            }


        case 2:
          switch (reduc_code)
            {
            case REDUC_MAX_EXPR:
              return cil32_builtins[CIL32_GCC_BUILD_REDUC_MAX_EPILOGUE_VHI];

            case REDUC_MIN_EXPR:
              return cil32_builtins[CIL32_GCC_BUILD_REDUC_MIN_EPILOGUE_VHI];

            case REDUC_PLUS_EXPR:
              return cil32_builtins[CIL32_GCC_BUILD_REDUC_PLUS_EPILOGUE_VHI];

            default:
              return NULL_TREE;
            }

        case 1:
          switch (reduc_code)
            {
            case REDUC_MAX_EXPR:
              return cil32_builtins[CIL32_GCC_BUILD_REDUC_MAX_EPILOGUE_VQI];

            case REDUC_MIN_EXPR:
              return cil32_builtins[CIL32_GCC_BUILD_REDUC_MIN_EPILOGUE_VQI];

            case REDUC_PLUS_EXPR:
              return cil32_builtins[CIL32_GCC_BUILD_REDUC_PLUS_EPILOGUE_VQI];

            default:
              return NULL_TREE;
            }

        default:
          return NULL_TREE;
        }
    }
  else
    {
      switch (element_size)
        {
#if 0
        case 8:
          switch (reduc_code)
            {
            case REDUC_MAX_EXPR:
              return cil32_builtins[CIL32_GCC_BUILD_REDUC_MAX_EPILOGUE_VDF];

            case REDUC_MIN_EXPR:
              return cil32_builtins[CIL32_GCC_BUILD_REDUC_MIN_EPILOGUE_VDF];

            case REDUC_PLUS_EXPR:
              return cil32_builtins[CIL32_GCC_BUILD_REDUC_PLUS_EPILOGUE_VDF];

            default:
              return NULL_TREE;
            }
#endif

        case 4:
          switch (reduc_code)
            {
            case REDUC_MAX_EXPR:
              return cil32_builtins[CIL32_GCC_BUILD_REDUC_MAX_EPILOGUE_VSF];

            case REDUC_MIN_EXPR:
              return cil32_builtins[CIL32_GCC_BUILD_REDUC_MIN_EPILOGUE_VSF];

            case REDUC_PLUS_EXPR:
              return cil32_builtins[CIL32_GCC_BUILD_REDUC_PLUS_EPILOGUE_VSF];

            default:
              return NULL_TREE;
            }

        default:
          return NULL_TREE;
        }
    }
}

static bool cil32_builtin_vectorize_independent_drs_only (void)
{
  return true;
}

static bool cil32_builtin_always_realign (void)
{
  if (TARGET_ALWAYS_REALIGN)
    return true;
  else
    return false;
}

static tree cil32_builtin_mask_for_load (void)
{
  return cil32_builtins[CIL32_GCC_MASK_FOR_LOAD];
}

static tree cil32_builtin_realign_load (tree type)
{
  tree elem_type = TREE_TYPE (type);
  unsigned element_size = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (elem_type));

  if (TREE_CODE (elem_type) == INTEGER_TYPE)
    {
      switch (element_size)
        {
          case 1:
            return cil32_builtins[CIL32_GEN_VQI_REALIGN_LOAD];

          case 2:
            return cil32_builtins[CIL32_GEN_VHI_REALIGN_LOAD];

          case 4:
            return cil32_builtins[CIL32_GEN_VSI_REALIGN_LOAD];

          default:
            return NULL_TREE;
        }
    }
  else
    {
      if (element_size == 4)
        return cil32_builtins[CIL32_GEN_VSF_REALIGN_LOAD];
    }  

  return NULL_TREE;
}

static bool cil32_builtin_can_force_alignment (void)
{
  return false;
}


static tree cil32_builtin_get_loop_niters (void)
{
  return cil32_builtins[CIL32_GCC_GET_LOOP_NITERS];
}


static tree cil32_builtin_pattern (enum tree_code code, tree type)
{
  tree elem_type = TREE_TYPE (type);
  unsigned element_size = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (elem_type));

  if (code == DOT_PROD_EXPR && TREE_CODE (elem_type) == INTEGER_TYPE)
    {
      switch (element_size)
        {
          case 1:
            return cil32_builtins[CIL32_GEN_DOT_PRODUCT_VQI];

          case 2:
            return cil32_builtins[CIL32_GEN_DOT_PRODUCT_VHI];

          default:
            return NULL_TREE;
        }
    }

  return NULL_TREE;
}

static tree cil32_builtin_realign_offset (tree type)
{
  tree elem_type = TREE_TYPE (type);
  unsigned element_size = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (elem_type));

  if (TREE_CODE (elem_type) == INTEGER_TYPE)
    {
      switch (element_size)
        {
        case 4:
          return cil32_builtins[CIL32_GCC_REALIGN_OFFSET_VSI];

        case 2:
          return cil32_builtins[CIL32_GCC_REALIGN_OFFSET_VHI];

        case 1:
          return cil32_builtins[CIL32_GCC_REALIGN_OFFSET_VQI];

        default:
          return NULL_TREE;
        }
    }
  else
    {
      switch (element_size)
        {
        case 4:
          return cil32_builtins[CIL32_GCC_REALIGN_OFFSET_VSF];

        default:
          return NULL_TREE;
        }
    }
}