aboutsummaryrefslogtreecommitdiff
path: root/gcc/config/cil32/cil32.c
blob: 73386c9cca1aba77a971abf3c672a2334ed47a9e (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
/* Definitions for GCC.  Part of the machine description for cil32.

   Copyright (C) 2006 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>
Erven Rohou             <erven.rohou@st.com>
*/

#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 "gen-cil.h"

/* Per-function machine data.  */
struct machine_function GTY(())
{
  char dummy;
};

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 void cil32_init_builtins (void);
static tree cil32_build_builtin_va_list (void);
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[];

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

#undef TARGET_INIT_BUILTINS
#define TARGET_INIT_BUILTINS cil32_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 cil32_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


struct gcc_target targetm = TARGET_INITIALIZER;

/* CIL32 Code */

static tree
cil32_handle_function_attribute (tree *node, tree name,
				 tree args ATTRIBUTE_UNUSED,
				 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)
    cil_add_pinvoke(*node);

  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)
{
  gen_cil_init ();
}

static void
cil32_file_end (void)
{
  gen_cil_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;
}

tree cil32_builtin_va_start_decl;
tree cil32_builtin_va_arg_decl;
tree cil32_builtin_va_end_decl;
tree cil32_builtin_va_copy_decl;
tree cil32_builtin_is_LE_decl;

tree cil32_va_list_type = NULL_TREE;
tree cil32_arg_iterator_type;

/* constructors of vector types. */
/* float */
tree cil32_v2sf_ctor;
tree cil32_v4sf_ctor;
/* 32-bit integer */
tree cil32_v4qi_ctor;
tree cil32_v2hi_ctor;
/* 64-bit integer */
tree cil32_v8qi_ctor;
tree cil32_v4hi_ctor;
tree cil32_v2si_ctor;
/* 128-bit integer */
tree cil32_v4si_ctor;
tree cil32_v8hi_ctor;
tree cil32_v16qi_ctor;


static void
cil32_build_builtin_types (void)
{
  if (cil32_va_list_type == NULL_TREE) {
    tree f_dummy, record, type_decl;

    record = (*lang_hooks.types.make_type) (RECORD_TYPE);
    type_decl = build_decl (TYPE_DECL, get_identifier ("__arg_iterator"), record);

    f_dummy = build_decl (FIELD_DECL, get_identifier ("__dummy"), ptr_type_node);

    DECL_FIELD_CONTEXT (f_dummy) = record;

    TREE_CHAIN (record) = type_decl;
    TYPE_NAME (record)  = type_decl;
    TYPE_FIELDS (record) = f_dummy;

    layout_type (record);

    cil32_arg_iterator_type = record;

    cil32_va_list_type = build_pointer_type (cil32_arg_iterator_type);
  }
}

static void
cil32_init_builtins (void)
{
  tree arglist;

  cil32_build_builtin_types ();

  arglist = build_tree_list (NULL_TREE, cil32_va_list_type);
  cil32_builtin_va_start_decl = add_builtin_function ("__builtin_cil_va_start",
                                                      build_function_type (void_type_node,
                                                                           arglist),
                                                      CIL32_BUILT_IN_VA_START,
                                                      BUILT_IN_MD,
                                                      NULL,
                                                      NULL_TREE);
  arglist = build_tree_list (NULL_TREE, ptr_type_node);
  arglist = tree_cons (NULL_TREE, cil32_va_list_type, arglist);
  cil32_builtin_va_arg_decl = add_builtin_function ("__builtin_cil_va_arg",
                                                    build_function_type (ptr_type_node,
                                                                         arglist),
                                                    CIL32_BUILT_IN_VA_ARG,
                                                    BUILT_IN_MD,
                                                    NULL,
                                                    NULL_TREE);
  arglist = build_tree_list (NULL_TREE, cil32_va_list_type);
  cil32_builtin_va_end_decl = add_builtin_function ("__builtin_cil_va_end",
                                                    build_function_type (void_type_node,
                                                                         arglist),
                                                    CIL32_BUILT_IN_VA_END,
                                                    BUILT_IN_MD,
                                                    NULL,
                                                    NULL_TREE);
  arglist = build_tree_list (NULL_TREE, cil32_va_list_type);
  arglist = tree_cons (NULL_TREE, cil32_va_list_type, arglist);
  cil32_builtin_va_copy_decl = add_builtin_function ("__builtin_cil_va_copy",
                                                     build_function_type (void_type_node,
                                                                          arglist),
                                                     CIL32_BUILT_IN_VA_COPY,
                                                     BUILT_IN_MD,
                                                     NULL,
                                                     NULL_TREE);
  cil32_builtin_is_LE_decl = add_builtin_function ("__builtin_isLittleEndian",
                                                   build_function_type (integer_type_node,
                                                                        NULL_TREE),
                                                   CIL32_BUILT_IN_IS_LITTLE_ENDIAN,
                                                   BUILT_IN_MD,
                                                   NULL,
                                                   NULL_TREE);

  arglist = build_tree_list (NULL_TREE, float_type_node);
  arglist = tree_cons (NULL_TREE, float_type_node, arglist);
  cil32_v2sf_ctor = add_builtin_function ("V2SF_ctor1",
                                          build_function_type (build_vector_type (float_type_node, 2),
                                                               arglist),
                                          CIL32_V2SF_CTOR,
                                          BUILT_IN_MD,
                                          NULL,
                                          NULL_TREE);

  arglist = build_tree_list (NULL_TREE, float_type_node);
  arglist = tree_cons (NULL_TREE, float_type_node, arglist);
  arglist = tree_cons (NULL_TREE, float_type_node, arglist);
  arglist = tree_cons (NULL_TREE, float_type_node, arglist);
  cil32_v4sf_ctor = add_builtin_function ("V4SF_ctor1",
                                          build_function_type (build_vector_type (float_type_node, 4),
                                                               arglist),
                                          CIL32_V4SF_CTOR,
                                          BUILT_IN_MD,
                                          NULL,
                                          NULL_TREE);

  arglist = build_tree_list (NULL_TREE, unsigned_intQI_type_node);
  arglist = tree_cons (NULL_TREE, unsigned_intQI_type_node, arglist);
  arglist = tree_cons (NULL_TREE, unsigned_intQI_type_node, arglist);
  arglist = tree_cons (NULL_TREE, unsigned_intQI_type_node, arglist);
  cil32_v4qi_ctor = add_builtin_function ("V4QI_ctor1",
                                          build_function_type (build_vector_type (intQI_type_node, 4),
                                                               arglist),
                                          CIL32_V4QI_CTOR,
                                          BUILT_IN_MD,
                                          NULL,
                                          NULL_TREE);

  arglist = build_tree_list (NULL_TREE, unsigned_intHI_type_node);
  arglist = tree_cons (NULL_TREE, intHI_type_node, arglist);
  cil32_v2hi_ctor = add_builtin_function ("V2HI_ctor1",
                                          build_function_type (build_vector_type (intHI_type_node, 2),
                                                               arglist),
                                          CIL32_V2HI_CTOR,
                                          BUILT_IN_MD,
                                          NULL,
                                          NULL_TREE);

  arglist = build_tree_list (NULL_TREE, unsigned_intQI_type_node);
  arglist = tree_cons (NULL_TREE, unsigned_intQI_type_node, arglist);
  arglist = tree_cons (NULL_TREE, unsigned_intQI_type_node, arglist);
  arglist = tree_cons (NULL_TREE, unsigned_intQI_type_node, arglist);
  arglist = tree_cons (NULL_TREE, unsigned_intQI_type_node, arglist);
  arglist = tree_cons (NULL_TREE, unsigned_intQI_type_node, arglist);
  arglist = tree_cons (NULL_TREE, unsigned_intQI_type_node, arglist);
  arglist = tree_cons (NULL_TREE, unsigned_intQI_type_node, arglist);
  cil32_v8qi_ctor = add_builtin_function ("V8QI_ctor1",
                                          build_function_type (build_vector_type (intQI_type_node, 8),
                                                               arglist),
                                          CIL32_V8QI_CTOR,
                                          BUILT_IN_MD,
                                          NULL,
                                          NULL_TREE);

  arglist = build_tree_list (NULL_TREE, unsigned_intHI_type_node);
  arglist = tree_cons (NULL_TREE, unsigned_intHI_type_node, arglist);
  arglist = tree_cons (NULL_TREE, unsigned_intHI_type_node, arglist);
  arglist = tree_cons (NULL_TREE, unsigned_intHI_type_node, arglist);
  cil32_v4hi_ctor = add_builtin_function ("V4HI_ctor1",
                                          build_function_type (build_vector_type (intHI_type_node, 4),
                                                               arglist),
                                          CIL32_V4HI_CTOR,
                                          BUILT_IN_MD,
                                          NULL,
                                          NULL_TREE);

  arglist = build_tree_list (NULL_TREE, unsigned_intSI_type_node);
  arglist = tree_cons (NULL_TREE, unsigned_intSI_type_node, arglist);
  cil32_v2si_ctor = add_builtin_function ("V2SI_ctor1",
                                          build_function_type (build_vector_type (intSI_type_node, 2),
                                                               arglist),
                                          CIL32_V2SI_CTOR,
                                          BUILT_IN_MD,
                                          NULL,
                                          NULL_TREE);

  arglist = build_tree_list (NULL_TREE, unsigned_intSI_type_node);
  arglist = tree_cons (NULL_TREE, unsigned_intSI_type_node, arglist);
  arglist = tree_cons (NULL_TREE, unsigned_intSI_type_node, arglist);
  arglist = tree_cons (NULL_TREE, unsigned_intSI_type_node, arglist);
  cil32_v4si_ctor = add_builtin_function ("V4SI_ctor1",
                                          build_function_type (build_vector_type (intSI_type_node, 4),
                                                               arglist),
                                          CIL32_V4SI_CTOR,
                                          BUILT_IN_MD,
                                          NULL,
                                          NULL_TREE);

  arglist = build_tree_list (NULL_TREE, unsigned_intHI_type_node);
  arglist = tree_cons (NULL_TREE, unsigned_intHI_type_node, arglist);
  arglist = tree_cons (NULL_TREE, unsigned_intHI_type_node, arglist);
  arglist = tree_cons (NULL_TREE, unsigned_intHI_type_node, arglist);
  arglist = tree_cons (NULL_TREE, unsigned_intHI_type_node, arglist);
  arglist = tree_cons (NULL_TREE, unsigned_intHI_type_node, arglist);
  arglist = tree_cons (NULL_TREE, unsigned_intHI_type_node, arglist);
  arglist = tree_cons (NULL_TREE, unsigned_intHI_type_node, arglist);
  cil32_v8hi_ctor = add_builtin_function ("V8HI_ctor1",
                                          build_function_type (build_vector_type (intHI_type_node, 8),
                                                               arglist),
                                          CIL32_V8HI_CTOR,
                                          BUILT_IN_MD,
                                          NULL,
                                          NULL_TREE);

  arglist = build_tree_list (NULL_TREE, unsigned_intQI_type_node);
  arglist = tree_cons (NULL_TREE, unsigned_intQI_type_node, arglist);
  arglist = tree_cons (NULL_TREE, unsigned_intQI_type_node, arglist);
  arglist = tree_cons (NULL_TREE, unsigned_intQI_type_node, arglist);
  arglist = tree_cons (NULL_TREE, unsigned_intQI_type_node, arglist);
  arglist = tree_cons (NULL_TREE, unsigned_intQI_type_node, arglist);
  arglist = tree_cons (NULL_TREE, unsigned_intQI_type_node, arglist);
  arglist = tree_cons (NULL_TREE, unsigned_intQI_type_node, arglist);
  arglist = tree_cons (NULL_TREE, unsigned_intQI_type_node, arglist);
  arglist = tree_cons (NULL_TREE, unsigned_intQI_type_node, arglist);
  arglist = tree_cons (NULL_TREE, unsigned_intQI_type_node, arglist);
  arglist = tree_cons (NULL_TREE, unsigned_intQI_type_node, arglist);
  arglist = tree_cons (NULL_TREE, unsigned_intQI_type_node, arglist);
  arglist = tree_cons (NULL_TREE, unsigned_intQI_type_node, arglist);
  arglist = tree_cons (NULL_TREE, unsigned_intQI_type_node, arglist);
  arglist = tree_cons (NULL_TREE, unsigned_intQI_type_node, arglist);
  cil32_v16qi_ctor = add_builtin_function ("V16QI_ctor1",
                                           build_function_type (build_vector_type (intQI_type_node, 16),
                                                                arglist),
                                           CIL32_V16QI_CTOR,
                                           BUILT_IN_MD,
                                           NULL,
                                           NULL_TREE);
}

static tree
cil32_build_builtin_va_list (void)
{
  cil32_build_builtin_types ();
  return cil32_va_list_type;
}

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_builtin_va_arg_decl, 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;
}

#include "gt-cil32.h"