00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include <stdio.h>
00041
00042 #include "compile_vect.hh"
00043 #include "compile_scal.hh"
00044 #include "sigtype.hh"
00045 #include "sigtyperules.hh"
00046 #include "sigprint.hh"
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 int ScalarCompiler::getSharingCount(Tree sig)
00063 {
00064
00065 Tree c;
00066 if (getProperty(sig, fSharingKey, c)) {
00067
00068 return c->node().getInt();
00069 } else {
00070
00071 return 0;
00072 }
00073 }
00074
00075 void ScalarCompiler::setSharingCount(Tree sig, int count)
00076 {
00077
00078 setProperty(sig, fSharingKey, tree(count));
00079 }
00080
00081
00082
00083 int VectorCompiler::getSharingCount(Tree t, int ctxt)
00084 {
00085 Tree c;
00086
00087 if(ctxt==kVect) {
00088
00089 if (getProperty(t, fSharingKeyVec, c)) {
00090 return c->node().getInt();
00091 } else {
00092 return 0;
00093 }
00094
00095 } else if(ctxt==kScal) {
00096
00097 if (getProperty(t, fSharingKeyScal, c)) {
00098 return c->node().getInt();
00099 } else {
00100 return 0;
00101 }
00102
00103 } else {
00104
00105 if (getProperty(t, fSharingKeyTrueScal, c)) {
00106 return c->node().getInt();
00107 } else {
00108 return 0;
00109 }
00110
00111 }
00112 }
00113
00114
00115
00116
00117
00118
00119
00120
00121 void ScalarCompiler::sharingAnalysis(Tree t)
00122 {
00123 fSharingKey = shprkey(t);
00124 if (isList(t)) {
00125 while (isList(t)) {
00126 sharingAnnotation(kSamp, hd(t));
00127 t = tl(t);
00128 }
00129 } else {
00130 sharingAnnotation(kSamp, t);
00131 }
00132 }
00133
00134
00135
00136 void VectorCompiler::sharingAnalysis(Tree t)
00137 {
00138 fSharingKeyVec = shprkey(t);
00139 if (isList(t)) {
00140 while (isList(t)) {
00141 sharingAnnotation(kSamp, hd(t), kVect);
00142 t = tl(t);
00143 }
00144 } else {
00145 sharingAnnotation(kSamp, t, kVect);
00146 }
00147 }
00148
00149
00150
00151
00152
00153
00154 void ScalarCompiler::sharingAnnotation(int vctxt, Tree sig)
00155 {
00156
00157 int count = getSharingCount(sig);
00158
00159 if (count > 0) {
00160
00161 setSharingCount(sig, count+1);
00162
00163 } else {
00164
00165 int v = getSigType(sig)->variability();
00166
00167
00168 if (v < vctxt) {
00169 setSharingCount(sig, 2);
00170 } else {
00171 setSharingCount(sig, 1);
00172 }
00173
00174
00175 vector<Tree> subsig;
00176 int n = getSubSignals(sig, subsig);
00177 if (n>0 && ! isSigGen(sig)) {
00178 for (int i=0; i<n; i++) sharingAnnotation(v, subsig[i]);
00179 }
00180 }
00181
00182 }
00183
00184
00185
00186
00187 void VectorCompiler::sharingAnnotation(int vctxt, Tree t, int ctxt)
00188 {
00189 Tree tt;
00190
00191
00192
00193
00194 int cVect = getSharingCount(t,kVect);
00195 int cScal = getSharingCount(t,kScal);
00196 int cTrueScal = getSharingCount(t,kTrueScal);
00197
00198
00199 int type;
00200
00201 if ((cVect==0)&&(cScal==0)&&(cTrueScal==0)) {
00202
00203 if (getProperty(t, NULLENV, tt)) {
00204
00205
00206 Type ty((AudioType*)tree2ptr(tt));
00207
00208
00209
00210 int v = ty->variability();
00211 if (v < vctxt) {
00212
00213 cVect = 1;
00214 cScal = 1;
00215 if(ctxt==kVect) setProperty(t, fSharingKeyScal, tree(cScal+1));
00216 else if(ctxt==kScal) setProperty(t, fSharingKeyVec, tree(cVect+1));
00217
00218
00219 vctxt = v;
00220 }
00221 }
00222
00223 int n = t->arity();
00224 if (n>0 && ! isSigGen(t)) {
00225
00226 Tree x,y,ff,largs,id,z,label,le;
00227
00228
00229 if (getProperty(t, NULLENV, tt)) {
00230 Type ty = ((AudioType*)tree2ptr(tt));
00231 type = ty->vectorability();
00232 }
00233
00234 if(vctxt<kSamp) for (int i=0; i<n; i++) sharingAnnotation(vctxt, t->branch(i),kTrueScal);
00235 else if(isSigRDTbl(t,x,y)||isSigFFun(t,ff,largs)) for (int i=0; i<n; i++) sharingAnnotation(vctxt, t->branch(i),kTrueScal);
00236 else if(isSigWRTbl(t,id,x,y,z)) { sharingAnnotation(vctxt, t->branch(0),kTrueScal); sharingAnnotation(vctxt, t->branch(1),kTrueScal); sharingAnnotation(vctxt, t->branch(2),kTrueScal); sharingAnnotation(vctxt, t->branch(3),kScal); }
00237 else if(isRec(t,label,le)||isRef(t,label)) for (int i=0; i<n; i++) sharingAnnotation(vctxt, t->branch(i),kScal);
00238
00239 else if(ctxt==kTrueScal) for (int i=0; i<n; i++) sharingAnnotation(vctxt, t->branch(i),type);
00240 else for (int i=0; i<n; i++) sharingAnnotation(vctxt, t->branch(i),ctxt|type);
00241
00242
00243
00244
00245
00246 }
00247
00248
00249
00250
00251 }
00252
00253
00254
00255 if((!getProperty(t, NULLENV, tt))||(ctxt==type)) {
00256 if(ctxt==kVect) setProperty(t, fSharingKeyVec, tree(cVect+1));
00257 else if(ctxt==kScal) setProperty(t, fSharingKeyScal, tree(cScal+1));
00258 else setProperty(t, fSharingKeyTrueScal, tree(cTrueScal+1));
00259 } else {
00260 if(ctxt==kVect) setProperty(t, fSharingKeyVec, tree(cVect+1));
00261 else if(ctxt==kScal) setProperty(t, fSharingKeyScal, tree(cScal+1));
00262 else setProperty(t, fSharingKeyTrueScal, tree(cTrueScal+1));
00263
00264 if(type==kVect) setProperty(t, fSharingKeyVec, tree(cVect+1));
00265 else if(type==kScal) setProperty(t, fSharingKeyScal, tree(cScal+1));
00266
00267 }
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281 }
00282
00283
00284
00285
00286