Adventist Adventurer Awards/Buttons - Wikibooks, open books for an open world

ROSE Compiler Framework/Declaration move tool

ROSE instruments>


This instrument will transfer variable declarations to their innermost attainable used scopes.

For a declaration, discover the innermost scope we are able to transfer it into, with out breaking the code’s authentic semantics.

  • For a single use place, transfer to the innermost scope.
  • For the case of a number of makes use of, we could have to duplicate the declarations and transfer to 2 scopes if there is no such thing as a variable reuse in between, in any other case, we transfer the declaration into the innermost widespread scope of the a number of makes use of.

Set up[edit]

This instrument is launched as a part of the ROSE compiler. Please set up ROSE (model or later) by following the directions at

  • Set up: Throughout configuration, you may need to specify a prefix path, corresponding to –prefix=/house/youraccount/decide/rose- Then, comply with the ROSE set up information to construct and set up ROSE.

To save lots of time, you possibly can simply construct/set up librose and the instrument you have an interest in. Observe in your construct tree:

  • sort “make install-core -j8” # this construct and a few core instruments

Alternatively, you possibly can set up all the things, which takes for much longer time:

  • sort make set up -j8 to put in core ROSE libraries and a few prebuilt instruments.

An executable file moveDeclarationToInnermostScope will likely be created through the strategy of constructing/putting in ROSE. The instrument will likely be put in to the trail specified by –prefix=ROSE INSTALLATION PATH. Customers can use it to course of their codes.

The subsequent step is to set atmosphere variables for search paths for ROSE executables (together with this transfer instrument ) and shared libraries. Assume you might be utilizing bash, put the next traces right into a file (e.g. set.rose) and supply it (typing supply set.rose)

export ROSE_INS
export PATH

Now you should use this instrument to rework your code. Assume you might have a sequential file: file.c, simply sort moveDeclarationToInnermostScope -c file.c. An output file rose file.c will likely be generated.

To course of a number of recordsdata, it’s worthwhile to change your makefile to make use of moveDeclarationToInnermostScope because the compiler to compile your code. The instrument will remodel your code first and generate rose_originalFile.C and invoke a backend compiler (normally GCC/G++) to complete the compilation.

Person directions[edit]

The translator accepts the next choices:

  • -rose:merge_decl_assign will merge the moved declaration with an instantly adopted task.
  • -rose:aggressive : activate the aggressive mode, which can transfer declarations with initializers, and throughout loop boundaries. A warning message will likely be despatched out if the transfer crosses a loop boundary. With out this feature, the instrument solely strikes a declaration with out an initializer to be protected.
  • -rose:debug, which is turned on by default within the testing. Some dot graph recordsdata will likely be generated for scope bushes of variables for debugging goal.
  • -rose:keep_going will ignore assertions as a lot as attainable (at present on skip the assertion on complicated for loop initialization assertion listing). With out this feature, the instrument will cease on assertion failures.
  • -rose:id will flip off any transformations and act like an id translator. Helpful for debugging functions.
  • -rose:trans-tracking will activate the transformation monitoring mode, exhibiting the supply statements of a transfer/merged declaration

Important output of moveDeclarationToInnermostScope –help

MOVEDECLARATIONTOINNERMOSTSCOPE(1)                          ROSE Command-line Instruments                         MOVEDECLARATIONTOINNERMOSTSCOPE(1)

       moveDeclarationToInnermostScope - This instrument strikes variable declarations to their innermost attainable scopes

       moveDeclarationToInnermostScope switches recordsdata...

       This instrument is designed to assist parallelizing code by shifting variable declarations into their innermost attainable scopes (primarily
       making lots of them personal). Consequently, much less variables have to be shared.


   The transfer instrument switches
       These switches management the transfer instrument.

           Allow aggressive mode: declarations with initializers will likely be moved.

           Allow the debugging mode.

           Allow appearing like an id translator, not doing any transformation in any respect.

           Permit the instrument to proceed with out being stopped by assertions.

           After the transfer, additional merge the moved bare variable declaration (with out initialization) with a adopted variable task.

           Allow monitoring of transformation steps.

   ROSE's built-in switches
           Present the old-style ROSE assist.                                              Thursday October 12 13:51:28 2017                    MOVEDECLARATIONTOINNERMOSTSCOPE(1)

supply and exams[edit]

Supply code


Instance Use[edit]

For the next enter code, Take a look

void AccumulateForce(int *idxBound, int *idxList, int len,
                    double *tmp, double *pressure)
   register int ii ;
   register int jj ;
   int rely ;
   int *listing ;
   int idx ;
   double sum ;
   for (ii=0; ii 

You'll be able to run the transfer instrument as follows to provide the output file under:

moveDeclarationToInnermostScope -rose:unparse_tokens -rose:merge_decl_assign -c Take a look

There are a number of issues to note about this command line. The moveDeclarationToInnermostScope instrument acts as a front-end to an underlying compiler, and the command line choices for that compiler will likely be honored. Right here, we even have some ROSE/instrument particular command line choices. The '-rose:unparse_tokens' choice tells ROSE to take further care to protect the source-code formatting from the enter supply file when producing the output file. The '-rose:merge_decl_assign' choice is restricted to the rescoping instrument, and signifies that any moved declarations ought to attempt to be mixed with pre-existing task statements within the goal scope.

The output file will seem like

void AccumulateForce(int *idxBound, int *idxList, int len,
                    double *tmp, double *pressure)
   for (register int ii = 0; ii 

Wanting on the reworked supply code above, there are a number of factors of curiosity:

  • Any qualifiers related to declarations are preserved when the declaration is moved.
  • Declarations associated to for-loop management variables are moved into the loop header.
  • Assignments and declarations are merged, as a result of presence of the -rose:merge_decl_assign command line choice.

Inner Algorithms[edit]


Construct a scope tree for every declaration

  • nodes: DS (declaration scope), IS (intermediate scope), and US (used scope)
  • edges: parent-child relation between two scopes

Circumstances for tree form properties

  • single straight line tree
    • single backside used scope: transfer the declaration to the underside
    • a number of used scopes: trim shadowed used scopes, transfer the declaration to the primary used scope
  • a number of branches for the tree
    • has LiveIn between branching sibling nodes: transfer declaration to the mum or dad scope of the sibling.
    • No liveIn between sibling nodes: transfer declaration to every branching scope
      • unequal depths of goal scopes: tentatively transfer to the equal depth, iteratively transfer the inserted declarations. worklist algorithm

Related supply code

  • Scope_Node* generateScopeTree(SgDeclarationStatement* decl, bool debug = false)

V1: Worklist algorithm[edit]

V1: Worklist algorithm

  • preliminary worklist = authentic declarations within the perform
  • whereas (!worklist.empty())
    • decl = worklist.entrance(); worklist.pop();
    • moveDeclarationToInnermostScope(decl, inserted_decls);
    • worklist.push_back( every of inserted_decls)

V2: Separated evaluation and transfer[edit]

V2: specializing in discovering goal scopes, since a number of (iterative) declaration strikes are pointless

  • if we all know the ultimate scopes to be moved into, we are able to copy-move a declaration to all goal scopes in a single shot

Algorithm v2:

  • Evaluation: findFinalTargetScopes (declaration, &target_scopes)
    • scope_tree_worklist.push(scope_tree);
    • whereas (!scope_tree_worklist.empty())
      • current_scope_tree = scope_tree_worklist.entrance(); …
      • collectCandidateTargetScopes(decl, current_scope_tree);
        • if (discovered a backside scope) target_scopes.push_back(candidate)
        • else scope_tree_worklist.push_back(candiate)
  • Transformation:
    • if (target_scopes.dimension()>0)
      • copyMoveVariableDeclaration(decl, target_scopes);

name stack[edit]

most important()

  • exampleTraversal.traverseWithinFile (s_file, preorder); // transfer declarations
    • visitorTraversal::go to()
  • if (merge_decl_assign) collectiveMergeDeclarationAndAssignment (inserted_decls); // transfer declaration with assignments

Limitations and ongoing work[edit]


  • Presently a conservative syntactic liveness evaluation is used, we're shifting it to make use of a greater liveness evaluation
  • the instrument solely strikes native variables declared inside a perform, not international variables.
    • Shifting international variables requires international evaluation throughout a number of supply recordsdata to keep away from breaking authentic semantics.
    • Additionally, usually international variables are declared in header recordsdata. Remodeling header recordsdata remains to be on-going work.

Author: admin

Leave a Reply

Your email address will not be published. Required fields are marked *