sagexx_attr (1158315), страница 2
Текст из файла (страница 2)
The method returnsthe number of nodes deleted. The function also deletes the attributes attached to lowlevel nodes. The parameters are the following :int deleteExpressionNode : allows, if not zero, to remove the lower implementationof the node from data base.int verbose : if non zero prints the message "garbage collection in process".7Project Tablesfile 0file 1file 2statementsstatementsstatementsfunc pgm2endfunc pgm1endexpressionsexpressionsvarvarsymbolssymbolsxpgm1ypgm2typestypesintintfunction pgm1integer x....endfunction pgm2integer y....endfunc pgm3endexpressionsvarsymbolszpgm3typesintfunction pgm3integer z....endFigure 1: Database structureBecause the system cannot be aware of all the SgExpression nodes in the system (forinstance node created but not yet referenced in the data base) it is possible to avoid thedeletion of those nodes by adding an attribute with type NOGARBAGE ATTRIBUTE.3 Multiple Files ProjectMultiple les capabilities exist in sage but there exists a set of limitations: only one le canbe selected at a time.
A le is selected by the methods:SgProject::file(int i)SgFile::SgFile(char * dep_file_name)When a le is selected then all the operation in the data base will use the current le datastructure (see Figure 1). For instance, if a statement is created, it is added in the currentle structure. When the project is opened then the rst le is automatically selected.Here is an example of the usage of the multiple le capability:project = new SgProject("test.proj");nbfile = project->numberOfFiles();8for (i=0; i< nbfile; i++){file = &(project->file(i));printf("|||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n");// any operations here will operate on file number i// file i has been selected by the method project->file(i)// do work here.......file->unparsestdout();}3.1 Example: How to Retrieve a Function in Multiple FilesHere is an example of code to retrieve a function code in a multiple le project :nbfile = project->numberOfFiles();printf("Give the name of the function: ");scanf("%s",str);for (i=0; i< nbfile; i++){file = &(project->file(i));if (!file){Message("file not found",0);exit(1);}nbfunc = file->numberOfFunctions();for (j=0; j<nbfunc; j++){func = file->functions(j);if (!strcmp(func->symbol()->identifier(),str)){printf("Function %s found in file %s\n",func->symbol()->identifier(),project->fileName(i));break;}}}3.2 From one File to AnotherCopy across les must be done by the member function inline SgSymbol &SgSymbol::copyAcrossFiles(SgStatement &where) where the parameter where indicates where9the statements will be inserted.
This method can only copy a full function, subroutine, classor structure. It duplicates all the expressions, symbols and types referenced in the body ofa function, so that after the copy there are no more references to the original le.To illustrate the problem of copying across les, let's consider this incorrect example.The result is illustrated in Figure 2:project = new SgProject("test.proj");nbfile = project->numberOfFiles();file = &(project->file(0));func = file->functions(0); // take the first function of file 0 to//be copied and inserted in the other filefunc->extractStmt(); // extract to allow copyfor (i=1; i< nbfile; i++){file = &(project->file(i));if (!file){Message("file not found",0);exit(1);}first =file->firstStatement();copyoffunc = &(func->copy()); // THIS IS REAL WRONGfirst->insertStmtAfter(*copyoffunc);printf("|||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n");file->unparsestdout();// unparse correctly but database is corrupted.sprintf(str,"debug%d.dep",i);file->saveDepFile(str); // incorrect database output.}Remark: Even though the multiple le operation is very limited and fragile it is stillpossible to use it for creating complex data structures easily.
In one le an object to becopied can be created by the parser. It can then be copied into another le to be used as atemplate......project = new SgProject("test.proj");nbfile = project->numberOfFiles();// set to the first filefile = &(project->file(0));// get the first functionfunc = file->functions(0);// get the symbolfc = func->symbol();10Project Tablesfile 0file 1file 2statementsstatementsstatementsfunc pgm1endfunc pgm2endfunc pgm1endexpressionsfunc pgm3endfunc pgm1endexpressionsvarexpressionsvarsymbolsvarsymbolsxpgm1symbolsypgm2typeszpgm3typesinttypesintfunction pgm1integer x....endstatements are correctly copiedbut refer to the data base ofother files.
This will screw up thesage behavior later.intfunction pgm1integer x....endfunction pgm1integer x....endfunction pgm2integer y....endfunction pgm3integer z....endFigure 2: Database structure after the invalid copy11// the following loop add the first function// of file number 0 to all the other filesfor (i=1; i< nbfile; i++){file = &(project->file(i));first =file->firstStatement();// call the copy across file functionfccop = &(fc->copyAcrossFiles(*first));// how to get the corresponding statementcopyoffunc = fccop->body();file->unparsestdout();}.....}4 Data Dependences For Fortran In SageSage provides data dependence computation for Fortran using the Omega Test. The information is provided using the attribute mechanism in Sage.4.1 Initializing the Data DependencesTo initialize the data dependences in Sage two function are available:1.2.void doDependenceAnalysisOnTheFullFile(SgFile *file, int printdep,int printannotation, int verbose)void doDependenceAnalysisForAFunction(SgFile *file,int printannotation, int verbose)SgStatement *func, int printdep,The rst function computes the data dependence for a full le and the second appliesonly on a function basis.
These two functions also initialize the annotation system. Theparameters are the following :SgFile *le : The current leSgStatement *func : the functionint printdep : display the data dependences if not zeroint printannotation : display the annotation found if not zeroint verbose : display the current function name.In order for dependence analysis to work, the following le needs to be included:12#include "depInterfaceExt.h"and the program must be linked with the library:sage/Sage++/extentions/SageAnalysisTool/libDep.aHere is, for example, the structure of a program (The full example can be found in/sage/Sage++/extentions/DemoDataDep/analyze.c).......#include "sage++user.h"#include "depInterfaceExt.h".......main(){.........project = new SgProject(ifi);file = &(project->file(0));........if (file->languageType() != ForSrc){Message("This is not a Fortran file; exiting",0);exit(1);}doDependenceAnalysisOnTheFullFile(file,0,0,0);.......}4.2 How to Retrieve the Data Dependence InformationAttributes are used to store the information in the database:DEPENDENCE ATTRIBUTE : there is an attribute for each data dependence.
Theseattributes are attached to outermost loops statements only.SgStatement *stmt; // a statementdepNode *dep;int i, nbatt;nbatt = stmt->numberOfAttributes(DEPENDENCE_ATTRIBUTE);for (i=0; i< nbatt; i++){dep = (depNode *) stmt->attributeValue(i,DEPENDENCE_ATTRIBUTE);...........}// the dep node class13class depNode {.....public:SgStatement *stmtin;SgStatement *stmtout;SgExpression *varin;SgExpression *varout;inttypedep;// source statement of the dependence// sink statement of the dependence// source expression of the dependence// sink expression of the dependence// WRONGDEP:????// ARRAYDEP:dependence on an array ref// PRIVATEDEP:The scalar variable (varin->symbol())//referenced can be privatized// REDUCTIONDEP: The scalar variable (varin->symbol())//is subject to a reduction computation.// SCALARDEP:The scalar reference was not found to//be a reduction or private.intkinddep; // The type of the dependence: ddflow, ddanti, ddoutputint lenghtvect;// lenght of the vector data depint distance[MAXNESTEDLOOP]; // distance if known (0 is the outermost loop)int knowndist[MAXNESTEDLOOP];// indicate if the distance is known// here is an example how to use these two last vectors:// for (i=1;i<= lenghtvect; i++)// {//if (knowndist[i])//printf("%d", distance[i]);//else//{//if (distance[i] & DEPZERO)//{//printf("0");//}//if (distance[i] & DEPGREATER)//{//printf("+");//}//if (distance[i] & DEPLESS)//{//printf("-");//}//}//if (i< lenghtvect)//printf(", ");//}depNode(SgStatement *sin,SgStatement *sout,SgExpression *vin,SgExpression *vout,14int tdep, int kdep,int *dist, int *kdist, int le);~depNode();void setNext(depNode *n); // set the next dependence node in the listdepNode *nextNode();// next dependence node in the listvoid displayDep();// display the dependence}INDUCTION ATTRIBUTE : Lists of the induction variablesint j;SgStatement *loop;// a loop statementSet*inducset; // this is a set structure// (see /sage/Sage++/extentions/SageAnalysisTool/Set.h)PT_INDUCVAR *ind;inducset = (Set *) loop->attributeValue(0,INDUCTION_ATTRIBUTE);for (j=0; j < inducset->size(); j++){ind = (PT_INDUCVAR) inducset->getElement(j);.....}struct inducvar {int constante;SgStatement *stmt;SgExpression *var;SgExpression *stride;SgExpression *lbound;SgExpression *ubound;Set *reachdef;int level;int loopnum;int include;}typedef struct inducvar////////////////////indicate if constant or inductionthe loop it is coming from;this is a SgVarRef node;the stride;the lower boundthe upper boundnot used currently;internal info;internal info;internal info;*PT_INDUCVAR;ACCESS ATTRIBUTE : The attribute contains a list of the access to variable in linearform for array access.int i;SgStatementSetPT_ACCESSARRAY*loop;// a loop statement*accesset; // this is a set structure//(see /sage/Sage++/extentions/SageAnalysisTool/Set.h)el;15accesset = (Set *) loop->attributeValue(0,ACCESS_ATTRIBUTE);for (i=0 ; i< accesset->size(); i++){el = (PT_ACCESSARRAY) accesset->getElement(i);.......}struct arrayAccess {SgStatement *stmt;////SgExpression *var;//intlinear[MAXDIMARRAY][MAXNESTEDLOOP]; //intisLinear[MAXDIMARRAY];////intcst[MAXNESTEDLOOP];//// here is an example of storage// do i = 1,n//do j = 1,n//a(2*i+3, 4*i + 5*j + 6) = ...//enddo// enddo// gives the following values of sets;//// isLinearlinearcst// [0] = 1[0][0] = 2 [0][1] = 0[0] = 3// [1] = 1[1][0] = 4 [1][1] = 5[1] = 6//intnbdim;////intsize;//////inttype;//intrw;////intscalar;////intlevel;//The statement the accessis coming fromThe access expressionmatrix of accessflag for each line to indicateif linear or notconstante valuethe number of dimension of thearray access (or an upper bound)the number of induction var thatenclosed the statement(2 for previous example)internal infoif different from zero this is anaccess in read otherwise in writif different from zero then thisis a scalar variable accessinternal info}typedef struct arrayAccess *PT_ACCESSARRAY;DEPGRAPH ATTRIBUTE : The attribute contains a pointer to the class depGraphwhich gathers all the information concerning the data dependences.