1 /*
2  * Copyright (c) 2017, NVIDIA CORPORATION.  All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #include "lz.h"
19 
20 typedef union {
21   struct {
22     int descr;
23     int rank;
24     int flag;
25     int dist_target;
26     int dist_target_descr;
27     int isstar;
28     int align_target;
29     int target_descr;
30     int conform;
31     int collapse;
32     int lb[MAXRANK];
33     int ub[MAXRANK];
34     int type;
35     int alignee_sc;
36     int target_sc;
37   } template;
38   struct {
39     int descr;
40     int rank;
41     int template;
42     int dtype;
43     int kind;
44     int size;
45   } instance;
46   int which; /* 1 for template, 2 for instance */
47 } DTABLE;
48 
49 typedef struct {
50   DTABLE *base;
51   int size;
52   int avl;
53 } DTB;
54 
55 extern DTB dtb;
56 
57 #define TMPL_DESCR(i) dtb.base[i].template.descr
58 #define TMPL_RANK(i) dtb.base[i].template.rank
59 #define TMPL_FLAG(i) dtb.base[i].template.flag
60 #define TMPL_DIST_TARGET(i) dtb.base[i].template.dist_target
61 #define TMPL_DIST_TARGET_DESCR(i) dtb.base[i].template.dist_target_descr
62 #define TMPL_ISSTAR(i) dtb.base[i].template.isstar
63 #define TMPL_ALIGN_TARGET(i) dtb.base[i].template.align_target
64 #define TMPL_TARGET_DESCR(i) dtb.base[i].template.target_descr
65 #define TMPL_CONFORM(i) dtb.base[i].template.conform
66 #define TMPL_COLLAPSE(i) dtb.base[i].template.collapse
67 #define TMPL_LB(i, j) dtb.base[i].template.lb[j]
68 #define TMPL_UB(i, j) dtb.base[i].template.ub[j]
69 #define TMPL_TYPE(i) dtb.base[i].template.type
70 #define TMPL_ALIGNEE_SC(i) dtb.base[i].template.alignee_sc
71 #define TMPL_TARGET_SC(i) dtb.base[i].template.target_sc
72 
73 #define INS_DESCR(i) dtb.base[i].instance.descr
74 #define INS_RANK(i) dtb.base[i].instance.rank
75 #define INS_TEMPLATE(i) dtb.base[i].instance.template
76 #define INS_DTYPE(i) dtb.base[i].instance.dtype
77 #define INS_KIND(i) dtb.base[i].instance.kind
78 #define INS_SIZE(i) dtb.base[i].instance.size
79 
80 #define __ASSUMED_SIZE 0x0001
81 #define __SEQUENTIAL 0x0002
82 #define __ASSUMED_SHAPE 0x0004
83 #define __SAVE 0x0008
84 
85 #define __INHERIT 0x0010
86 #define __NO_OVERLAPS 0x00020
87 
88 #define __INTENT_INOUT 0
89 #define __INTENT_IN 0x0040
90 #define __INTENT_OUT 0x0080
91 
92 #define __OMITTED_DIST_TARGET 0
93 #define __PRESCRIPTIVE_DIST_TARGET 0x0100
94 #define __DESCRIPTIVE_DIST_TARGET 0x0200
95 #define __TRANSCRIPTIVE_DIST_TARGET 0x0300
96 
97 #define __OMITTED_DIST_FORMAT 0
98 #define __PRESCRIPTIVE_DIST_FORMAT 0x0400
99 #define __DESCRIPTIVE_DIST_FORMAT 0x0800
100 #define __TRANSCRIPTIVE_DIST_FORMAT 0x0c00
101 
102 #define __PRESCRIPTIVE_ALIGN_TARGET 0x1000
103 #define __DESCRIPTIVE_ALIGN_TARGET 0x2000
104 #define __IDENTITY_MAP 0x4000
105 
106 #define __DYNAMIC 0x8000
107 #define __POINTER 0x10000
108 #define __LOCAL 0x20000
109 #define __F77_LOCAL_DUMMY 0x40000
110 #define __OFF_TEMPLATE 0x80000
111 
112 #define REPLICATED 0
113 #define DISTRIBUTED 1
114 #define ALIGNED 2
115 #define INHERITED 3
116 
117 #define DIST_TARGET_SHIFT 8
118 #define DIST_FORMAT_SHIFT 10
119 #define ALIGN_TARGET_SHIFT 12
120 
121 #define OMIT 0
122 #define PRESCRIP 1
123 #define DESCRIP 2
124 #define TRANSCRIP 3
125 
126 #define NONE_SC 0
127 #define ALLOC_SC 1
128 #define DUMMY_SC 2
129 #define STATIC_SC 3
130 #define COMMON_SC 4
131 
132 typedef struct {
133   int *base;
134   int avl;
135   int size;
136 } FL;
137 
138 extern FL fl;
139 
140 void set_typed_alloc(DTYPE);
141 void set_type_in_descriptor(int descriptor_ast, int sptr, DTYPE dtype,
142                             int parent_ast, int before_std);
143 int make_simple_template_from_ast(int ast, int std, LOGICAL need_type_in_descr);
144 
145 int newargs_for_llvmiface(int sptr);
146 void interface_for_llvmiface(int this_entry, int new_dscptr);
147 void undouble_callee_args_llvmf90(int iface);
148