Presentation is loading. Please wait.

Presentation is loading. Please wait.

Parasol.tamu.edu/courses/minipolaris. What is Polaris? Polaris is a source to source transforming compiler, originally developed at UIUC, intended to.

Similar presentations


Presentation on theme: "Parasol.tamu.edu/courses/minipolaris. What is Polaris? Polaris is a source to source transforming compiler, originally developed at UIUC, intended to."— Presentation transcript:

1 parasol.tamu.edu/courses/minipolaris

2 What is Polaris? Polaris is a source to source transforming compiler, originally developed at UIUC, intended to parallelize programs written as conventional, sequential algorithms. Polaris is essentially a driver routine which scans a FORTRAN 77 program and converts it into an Abstract Syntax Tree (AST). Then, various passes are called by the driver on the AST. Each pass attempts to optimize the program via specific methods, such as constant propagation, reduction recognition, etc.. The driver program completes its task by printing the program

3 What is Minipolaris? MiniPolaris is a version of Polaris with only the most fundamental passes.The source program is read, parsed, and converted to an AST. The user will then provide custom passes to extract information or make transformations on the statements. After the custom passes are executed, the driver program outputs the resulting code.

4 Polaris Passes Printed CodeProgram IR passes Order of the passes is determined by the driver (~/minipolaris/cvdl/driver/driver.cc). A pass is nothing more that a function call in the driver. User can specify in a switches file (e.g. ~/minipolaris/switches) what passes to do and what options to use. The driver will read this switches file

5 Classes in MiniPolaris Minipolaris provides classes for every Fortran77 construct at various levels. The most important classes for the first projects are: the Program Class the ProgramUnit Class the StmtList Class the Statement Class the Expression Class the Symbol Class

6 Program The Program class is nothing more than a collection of ProgramUnit's. You can iterate over the collection to get to the actual ProgramUnit's. There are some methods to read in complete Fortran programs and display them. But you will not need them for the projects

7 ProgramUnit The ProgramUnit class is mostly a holder for the various data structure elements that make up a Fortran program unit (e.g. main program, subroutines). Examples of data structure elements are the statement list and the symbol table. Some useful methods are: stmts()‏ symtab()‏ routine_name_ref()‏

8 StmtList The StmtList class holds all the executable statements in a ProgramUnit. It's more than just a list. It provides functions to find statements by its tag, inserting and deleting single statements or whole blocks of statements. Some useful methods are: stmts_of_type(STMT_TYPE)‏ ins_before(Statement,Statement)‏ del(Statement)‏

9 Statement The Statement class represents the actual Fortran statements. Almost every Fortran Statement has a representation (examples are AssignmentStmt, DoStmt, IfStmt, WhileStmt,....) All these classes are derived from the base class Statement. The Statement classes provide the methods to get all the information of a given StatementNode: next_ref()‏ prev_ref()‏ lhs(), rhs() for assignments init(), index() for do statements

10 Expression The Expression class holds every type of Fortran Expression the same way as the Statement class represents any type of Fortran statement. Examples are IntConstExpr, IDExpr, BinaryExpr,... Some methods in the Expression classes are: symbol()‏ op() left_guarded()‏ right_guarded()‏ subscript()

11 Symbol The Symbol class represents all of the different Fortran Symbols. Same as for Expression and Statement there are Symbols for every Fortran symbol type. Examples are ProgramSymbol, SubroutineSymbol, VariableSymbol. Some methods are: type()‏ name_ref()‏

12 Example Suppose we are given a ProgramUnit (pu) and want to print all the variables that are defined in the assignment statements. // get all the assignment statements Iterator it = pu.stmts().stmts_of_type(ASSIGN_STMT)‏ //Iterate over the list and for every statement do Expression& lhs = it.current().lhs()‏ //print out the name cout << lhs.symbol().name_ref()‏

13 Collections Polaris provides it's own set of collection classes. For example List<>, DataBase<>. These Collection classes can only holds objects that are derived from the Listable class. Once an object is put into a Collection the Collection owns that object (when the collection gets destroyed, all the elements in the Collection also get destroyed. There are also containers such as RefList. They can only hold references and do not own the elements.

14 Setup MiniPolaris Everything is done on linux.cs.tamu.edu to setup just type /pub/courses/cpsc605/minipolaris/config/setup This will create a new directory minipolaris in your home directory and installs the necessary files The skeleton files for all the projects are stored in the ~/minipolaris directory For compiling you can just use the make command and for running use “mini_polaris -f switchfile my_prog.f”. To test your results you can compile it with the gnu Fortran compiler g77 For detailed information look at the sections page of the minipolaris website.

15 Projects There will be a total of 5 projects: 1A: Transforming Gotos 1B: Find Basic Block 2: SSA/DESSA 3: Constant Propagation/GCSE/??? 4: DDtest 5: Code generation

16 Transforming Gotos Arithmetic if Statement: Computed Goto if (expr) label1, label2, label3 if (expr.LT. 0) then goto label1 elseif ( expr.EQ. 0) then goto label2 else goto label3 endif goto (label1,label2,label3) expr if ( expr.EQ. 1) then goto label1 elsif ( expr.EQ. 2) then goto label2 elsif (expr.EQ. 3) then goto label3 endif

17 Fortran Fortran has very specific rules about its format Column 1 can only be a c or a * to indicate the line is a comment Columns 2 to 6 are reserved for labels Columns 7 to 79 are used for actual statements a * in Column 5 or 6 means it's a continuation of the previous line In Fortran every parameter is passed by reference

18 GOOD LUCK!!! Read all the documentation before you start Start on time check the class newsgroup regularly


Download ppt "Parasol.tamu.edu/courses/minipolaris. What is Polaris? Polaris is a source to source transforming compiler, originally developed at UIUC, intended to."

Similar presentations


Ads by Google