Example #1
0
FrontierDetectionForTokenStreamMapping_SynthesizedAttribute 
FrontierDetectionForTokenStreamMapping::FrontierDetectionForTokenStreamMapping::evaluateSynthesizedAttribute (SgNode* n, 
     FrontierDetectionForTokenStreamMapping_InheritedAttribute inheritedAttribute, 
     SubTreeSynthesizedAttributes synthesizedAttributeList )
   {
     FrontierDetectionForTokenStreamMapping_SynthesizedAttribute returnAttribute;


     if (inheritedAttribute.containsFrontier == true)
        {
#if 1
          printf ("Marking containsFrontier = true (based on inheritedAttribute) at node = %p = %s \n",n,n->class_name().c_str());
#endif
          returnAttribute.containsFrontier = inheritedAttribute.containsFrontier;
        }

     for (size_t i = 0; i < synthesizedAttributeList.size(); i++)
        {
          if (synthesizedAttributeList[i].containsFrontier == true)
             {
#if 1
               printf ("Marking containsFrontier = true (based on synthesizedAttribute) at node = %p = %s \n",n,n->class_name().c_str());
#endif
               returnAttribute.containsFrontier = true;
             }
        }

  // return FrontierDetectionForTokenStreamMapping_SynthesizedAttribute();
     return returnAttribute;
   }
// Functions required by the global tree traversal mechanism
ProgramTransformationSynthesizedAttributeType
ArrayStatementTraversal::evaluateRewriteSynthesizedAttribute (
    SgNode* astNode,
    ProgramTransformationInheritedAttributeType inheritedAttribute,
    SubTreeSynthesizedAttributes synthesizedAttributeList)
{
    // Build the synthesizied attribute that this function will return
    ProgramTransformationSynthesizedAttributeType returnSynthesizedAttribute(astNode);

#if 0
    printf ("$$$$$ TOP of ArrayStatementTraversal::evaluateRewriteSynthesizedAttribute (astNode = %s) (synthesizedAttributeList.size() = %d) \n",
            astNode->sage_class_name(),synthesizedAttributeList.size());
    // inheritedAttribute.display("In ArrayStatementTraversal::evaluateRewriteInheritedAttribute");
#endif

    if (astNode->variantT() == V_SgExprStatement)
    {
        // The program logic can't reset the returnSynthesizedAttribute for each transformation
#if 0
        printf ("ERROR: In ArrayStatementTraversal::evaluateRewriteSynthesizedAttribute(): The program logic can't reset the returnSynthesizedAttribute for each transformation... \n");
        ROSE_ABORT();
#endif

        // printf ("Found an expression statement (programTransformation.C) \n");

        // We use the operator+=() because more than one transformation function could be called in general.
        // Below we will call the scalar indexing transformation as a second transformation.  Both, and more,
        // will be called for Expression statements in the future (e.g. indirect addressing).
        // returnSynthesizedAttribute += arrayAssignmentTransformation(inheritedAttribute,astNode);
#if 0
        // printf ("Calling arrayAssignmentTransformation() \n");
        returnSynthesizedAttribute = arrayAssignmentTransformation(inheritedAttribute,astNode);
        // arrayAssignmentTransformation(inheritedAttribute,astNode);
        // printf ("DONE: arrayAssignmentTransformation() \n");
#endif

#if 1
        // Turn off the scalar indexing transformation for now
        // returnSynthesizedAttribute += ScalarIndexingArrayStatementTransformation::transformation(project,astNode);
        // returnSynthesizedAttribute += ScalarIndexingArrayStatementTransformation::transformation(inheritedAttribute,astNode);
        returnSynthesizedAttribute = arrayScalarIndexingTransformation(inheritedAttribute,astNode);
#endif
    }

#if 0
    printf ("$$$$$ BOTTOM of attributeAssemblyFunction (astNode = %s) (declaration list size = %d) (returnSynthesizedAttribute.getTransformationSourceCode() = \n%s) \n",
            astNode->sage_class_name(),
            returnSynthesizedAttribute.variableDeclarationList.size(),
            returnSynthesizedAttribute.getSourceCodeString().c_str());
#endif

    return returnSynthesizedAttribute;
}
Example #3
0
StencilEvaluation_SynthesizedAttribute
StencilEvaluationTraversal::evaluateSynthesizedAttribute (SgNode* astNode, StencilEvaluation_InheritedAttribute inheritedAttribute, SubTreeSynthesizedAttributes synthesizedAttributeList )
   {
     StencilEvaluation_SynthesizedAttribute return_synthesizedAttribute;

#if 0
     printf ("In StencilEvaluationTraversal::evaluateSynthesizedAttribute(): astNode = %p = %s \n",astNode,astNode->class_name().c_str());
#endif

     bool foundStencilOffsetFSM = false;
     SgConstructorInitializer* constructorInitializer = isSgConstructorInitializer(astNode);
     if (constructorInitializer != NULL && inheritedAttribute.stencilOffsetFSM != NULL)
        {
#if 0
          printf ("Found pair<Shift,double>(x,y): set then in the synthesizedAttribute: astNode = %p = %s \n",astNode,astNode->class_name().c_str());
#endif
          return_synthesizedAttribute.stencilOffsetFSM       = inheritedAttribute.stencilOffsetFSM;
          return_synthesizedAttribute.stencilCoeficientValue = inheritedAttribute.stencilCoeficientValue;
#if 0
          printf ("return_synthesizedAttribute.stencilCoeficientValue = %f \n",return_synthesizedAttribute.stencilCoeficientValue);
#endif
          foundStencilOffsetFSM = true;
        }

  // There should only be a single child set with a pair<Shift,double>(x,y) object.
     for (size_t i = 0; i < synthesizedAttributeList.size(); i++)
        {
          if (synthesizedAttributeList[i].stencilOffsetFSM != NULL)
             {
            // Check that the return_synthesizedAttribute.stencilOffsetFSM has not already been set.
            // This could happend if we allows nesting of pair<Shift,double>(x,y) within itself (not allowed).
#if 0
               printf ("synthesizedAttributeList[i].stencilOffsetFSM != NULL \n");
#endif
            // ROSE_ASSERT(foundStencilOffsetFSM == false);
               if (foundStencilOffsetFSM == false)
                  {
#if 0
                    printf ("foundStencilOffsetFSM == false \n");
#endif
                 // ROSE_ASSERT(return_synthesizedAttribute.stencilOffsetFSM == NULL);
                    if (return_synthesizedAttribute.stencilOffsetFSM == NULL)
                       {
#if 0
                         printf ("return_synthesizedAttribute.stencilOffsetFSM != NULL \n");
#endif
                         return_synthesizedAttribute.stencilOffsetFSM = synthesizedAttributeList[i].stencilOffsetFSM;
                         return_synthesizedAttribute.stencilCoeficientValue = synthesizedAttributeList[i].stencilCoeficientValue;
                       }

                    foundStencilOffsetFSM = true;
                  }
             }
        }

  // This allows us to find the variables of type vector<Point> and vector<double> used as an alternative way
  // to specify a stencil (using the Stencil constructor that takes these variables as input arguments).
  // It relies upon a previous traversal to have identified the inputs to Stencil constructor.
  // This support is incomplete while I focus on the alternative approach to the specification of the stencil
  // using intremental union of a stencil with a pair<Shift,double>() template instantiation.
     SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(astNode);
     if (variableDeclaration != NULL)
        {
       // Get the SgInitializedName from the SgVariableDeclaration.
          SgInitializedName* initializedName = SageInterface::getFirstInitializedName(variableDeclaration);
#if 0
          printf ("In evaluateInheritedAttribute(): case SgInitializedName from variable declaration: initializedName = %p name = %s \n",initializedName,initializedName->get_name().str());
#endif
          bool foundStencilDeclaration = false;
          if (find(stencilInputInitializedNameList.begin(),stencilInputInitializedNameList.end(),initializedName) != stencilInputInitializedNameList.end())
             {
#if 0
               printf ("Found declaration associated with stencil input: initializedName = %p = %s name = %s \n",initializedName,initializedName->class_name().c_str(),initializedName->get_name().str());
#endif
            // Build the finite state machine for the stencil and add it to the map using the name (in SgInitializedName) as a key.
            // For now we assume that the stencil specification is using the default construction.
               if (initializedName->get_initptr() != NULL)
                  {
                    printf ("FIXME: This declaration of a stencil appears to have constrcutor arguments (this not the default constuctor as interprest below). \n");
#if 0
                    ROSE_ASSERT(false);
#endif
                  }

               foundStencilDeclaration = true;
             }
            else
             {
            // Verify that this is a Stencil declaration.
               SgClassType* classType = isSgClassType(initializedName->get_type());
               if (classType != NULL)
                  {
                 // Check if this is associated with a template instantiation.
                    SgTemplateInstantiationDecl* templateInstantiationDecl = isSgTemplateInstantiationDecl(classType->get_declaration());
                    if (templateInstantiationDecl != NULL)
                       {
#if 0
                         printf ("case SgTemplateInstaiationDecl: class name = %s \n",classType->get_name().str());
                         printf ("case SgTemplateInstaiationDecl: templateInstantiationDecl->get_templateName() = %s \n",templateInstantiationDecl->get_templateName().str());
#endif
                         if (templateInstantiationDecl->get_templateName() == "Stencil")
                            {
#if 0
                              printf ("This is verified to be associated with the Stencil template class \n");
#endif
                              foundStencilDeclaration = true;
                            }
                       }
                  }
             }

          if (foundStencilDeclaration == true)
             {
               string name = initializedName->get_name();
               ROSE_ASSERT(stencilMap.find(name) == stencilMap.end());
            // stencilMap[name] = new StencilFSM();
               StencilFSM* stencilFSM = new StencilFSM();
               ROSE_ASSERT(stencilFSM != NULL);
               stencilMap[name] = stencilFSM;
               ROSE_ASSERT(stencilMap.find(name) != stencilMap.end());
#if 0
               printf ("Added StencilFSM to stencilMap using name = %s \n",name.c_str());
#endif
#if 0
               printf ("Trigger an event on the stencilFSM ========================== %p \n",stencilFSM);
               printf ("   --- Use the return_synthesizedAttribute.stencilOffsetFSM = %p \n",return_synthesizedAttribute.stencilOffsetFSM);
#endif
               if (return_synthesizedAttribute.stencilOffsetFSM != NULL)
                  {
                 // Trigger the event to add the stencil offset to the stencil.
                 // Trigger the event on the finite state machine using the elements saved in the synthesized attribute.
                    StencilFSM stencil_rhs (*(return_synthesizedAttribute.stencilOffsetFSM),return_synthesizedAttribute.stencilCoeficientValue);

                 // This reproduces the same semantics in our finite state machine as the Stencil class's operator+()
                 // in the stencil specification. but this permits use to accumulate the state at compile time.
                    stencilFSM->operator+(stencil_rhs);

                 // We have now used these values so avoid letting then be used again.
                    return_synthesizedAttribute.stencilOffsetFSM       = NULL;
                    return_synthesizedAttribute.stencilCoeficientValue = 0.0;
                  }
#if 0
               stencilFSM->display("after FSM stencil default construction plus union event: StencilEvaluationTraversal::evaluateSynthesizedAttribute()");
#endif
#if 0
               printf ("Exiting as a test! \n");
               ROSE_ASSERT(false);
#endif
             }
        }

  // Recognize member function calls on "Stencil" objects so that we can trigger events on those associated finite state machines.
     bool isTemplateClass = true;
     bool isTemplateFunctionInstantiation = true;
     SgInitializedName* initializedNameUsedToCallMemberFunction = NULL;
     SgFunctionCallExp* functionCallExp = detectMemberFunctionOfSpecificClassType(astNode,initializedNameUsedToCallMemberFunction,"Stencil",isTemplateClass,"operator+",isTemplateFunctionInstantiation);
     if (return_synthesizedAttribute.stencilOffsetFSM != NULL && functionCallExp != NULL)
        {
       // This is the DSL specific part of the synthesized attribute evaluation.

          ROSE_ASSERT(initializedNameUsedToCallMemberFunction != NULL);
          string name = initializedNameUsedToCallMemberFunction->get_name();
#if 0
          printf ("This is verified to be the operator+ member function of the Stencil templated class (so this corresponds to an event in the Stencil finite state machine) \n");
          printf ("   --- stencil object name = %s \n",name.c_str());
#endif
       // Lookup the stencil FSM in the map of stencil FSMs using the name as the key.
          ROSE_ASSERT(stencilMap.find(name) != stencilMap.end());
          StencilFSM* stencilFSM = stencilMap[name];
          ROSE_ASSERT(stencilFSM != NULL);
#if 0
          printf ("Trigger an event on the stencilFSM ========================== %p \n",stencilFSM);
          printf ("   --- Use the return_synthesizedAttribute.stencilOffsetFSM = %p \n",return_synthesizedAttribute.stencilOffsetFSM);
#endif
       // Make sure we have the input parameter for the stencil's finite state machine.
          ROSE_ASSERT(return_synthesizedAttribute.stencilOffsetFSM != NULL);

       // Trigger the event on the finite state machine using the elements saved in the synthesized attribute.
          StencilFSM stencil_rhs (*(return_synthesizedAttribute.stencilOffsetFSM),return_synthesizedAttribute.stencilCoeficientValue);

       // This reproduces the same semantics in our finite state machine as the Stencil class's operator+()
       // in the stencil specification. but this permits use to accumulate the state at compile time.
          stencilFSM->operator+(stencil_rhs);

       // We have now used these values so avoid letting then be used again.
          return_synthesizedAttribute.stencilOffsetFSM       = NULL;
          return_synthesizedAttribute.stencilCoeficientValue = 0.0;
#if 0
          stencilFSM->display("after FSM stencil union event: StencilEvaluationTraversal::evaluateSynthesizedAttribute()");
#endif
        }

#if 0
     printf ("Leaving StencilEvaluationTraversal::evaluateSynthesizedAttribute(): return_synthesizedAttribute.stencilOffsetFSM = %p \n",return_synthesizedAttribute.stencilOffsetFSM);
#endif
#if 0
     printf ("Leaving StencilEvaluationTraversal::evaluateSynthesizedAttribute(): return_synthesizedAttribute.stencilCoeficientValue = %f \n",return_synthesizedAttribute.stencilCoeficientValue);
#endif

     return return_synthesizedAttribute;
   }
Example #4
0
// void RemoveConstantFoldedValue::visit ( SgNode* node )
RemoveConstantFoldedValueSynthesizedAttribute
RemoveConstantFoldedValue::evaluateSynthesizedAttribute ( SgNode* node, SubTreeSynthesizedAttributes synthesizedAttributeList )
   {
     ROSE_ASSERT(node != NULL);

  // DQ (3/11/2006): Set NULL pointers where we would like to have none.
#if 0
#if 0
  // Avoid excessive output.
     if (isSgFunctionDeclaration(node) == NULL && isSgInitializedName(node) == NULL && isSgFunctionParameterList(node) == NULL)
          printf ("In RemoveConstantFoldedValue::evaluateSynthesizedAttribute(): node = %p = %s synthesizedAttributeList.size() = %" PRIuPTR " \n",node,node->class_name().c_str(),synthesizedAttributeList.size());
#else
     printf ("In RemoveConstantFoldedValue::evaluateSynthesizedAttribute(): node = %p = %s synthesizedAttributeList.size() = %" PRIuPTR " \n",node,node->class_name().c_str(),synthesizedAttributeList.size());
#endif
#endif

  // Here we reset the pointer to the constant folded value to be the pointer to the original expression tree.
     SubTreeSynthesizedAttributes::iterator i = synthesizedAttributeList.begin();
     while (i != synthesizedAttributeList.end())
        {
#if 0
       // Avoid excessive output.
          if (isSgFunctionDeclaration(i->node) == NULL && isSgInitializedName(i->node) == NULL && isSgFunctionParameterList(i->node) == NULL && i->node != NULL)
               printf ("synthesizedAttribute = %p = %s \n",i->node,(i->node != NULL) ? i->node->class_name().c_str() : "NULL");
#endif

       // DQ (10/8/2011): Refectored this code so that we could better support chains of original expression trees (see test2011_146.C).
          handleTheSynthesizedAttribute(node,*i);

          i++;
        }

  // Here we force the nested traversal of the originalExpressionTree, since it is not traversed as part of the AST.
  // Note that these are not always leaf nodes that we want to interogate (see test2011_140.C).

  // DQ (9/24/2011): I think this is the wrong place to process this case (see test2011_140.C).
  // DQ (9/24/2011): We have fixed the AST traversal to no longer traverse originalExpressionTree subtree's (since 
  // it make analysis using the traversal redundant with the constant folded values).
  // If the current node is an expression and a leaf node of the AST, then check if it has an originalExpressionTree, 
  // since we no longer traverse the originalExpressionTree as part of the definition of the AST.
  // SgExpression* leafExpression = (synthesizedAttributeList.empty() == true) ? isSgExpression(node) : NULL;
     SgExpression* expression = isSgExpression(node);
     if (expression != NULL)
        {
#if 0
          printf ("In RemoveConstantFoldedValue::evaluateSynthesizedAttribute(): Found an expression \n");
#endif
          SgExpression* originalExpressionTree = expression->get_originalExpressionTree();
          if (originalExpressionTree != NULL)
             {
#if 0
               printf ("Found an expression with a valid originalExpressionTree\n");
#endif
            // Make sure that the traversal will see the nested subtrees of any originalExpressionTree (since they may have constant folded subexpresions).
               RemoveConstantFoldedValue nestedOriginalExpressionTreeTraversal;
               RemoveConstantFoldedValueSynthesizedAttribute nestedSynthesizedAttribute = nestedOriginalExpressionTreeTraversal.traverse(originalExpressionTree);
#if 0
            // DQ (10/8/2011): We should not handl this here, I think.
               handleTheSynthesizedAttribute(node,nestedSynthesizedAttribute);
#endif
#if 0
               printf ("DONE: Found an expression with a valid originalExpressionTree nestedSynthesizedAttribute \n");
#endif
             }
        }

     return RemoveConstantFoldedValueSynthesizedAttribute(node);
   }
// first visits the VarRef and then creates entry in operandDatabase which is
// useful in expressionStatement transformation. Thus, we replace the VarRef
// at the end of the traversal and insert loops during traversal
ArrayAssignmentStatementQuerySynthesizedAttributeType ArrayAssignmentStatementTransformation::evaluateSynthesizedAttribute(
		SgNode* astNode,
		ArrayAssignmentStatementQueryInheritedAttributeType arrayAssignmentStatementQueryInheritedData,
		SubTreeSynthesizedAttributes synthesizedAttributeList) {
	// This function assembles the elements of the input list (a list of char*) to form the output (a single char*)

#if DEBUG
	printf ("\n$$$$$ TOP of evaluateSynthesizedAttribute (astNode = %s) (synthesizedAttributeList.size() = %d) \n",
			astNode->sage_class_name(),synthesizedAttributeList.size());
	//cout << " Ast node string: " << astNode->unparseToString() << endl;
#endif

	// Build the return value for this function
	ArrayAssignmentStatementQuerySynthesizedAttributeType returnSynthesizedAttribute(astNode);

	// Iterator used within several error checking loops (not sure we should declare it here!)
	vector<ArrayAssignmentStatementQuerySynthesizedAttributeType>::iterator i;

	// Make a reference to the global operand database
	OperandDataBaseType & operandDataBase = accumulatorValue.operandDataBase;

	// Make sure the data base has been setup properly
	ROSE_ASSERT(operandDataBase.transformationOption > ArrayTransformationSupport::UnknownIndexingAccess);
	ROSE_ASSERT(operandDataBase.dimension > -1);

	// Build up a return string
	string returnString = "";

	string operatorString;

	// Need to handle all unary and binary operators and variables (but not much else)
	switch (astNode->variant()) {

	case FUNC_CALL: {

		// Error checking: Verify that we have a SgFunctionCallExp object
		SgFunctionCallExp* functionCallExpression = isSgFunctionCallExp(astNode);
		ROSE_ASSERT(functionCallExpression != NULL);

		string operatorName = TransformationSupport::getFunctionName(functionCallExpression);
		ROSE_ASSERT(operatorName.c_str() != NULL);

		string functionTypeName = TransformationSupport::getFunctionTypeName(functionCallExpression);

		if ((functionTypeName != "doubleArray") && (functionTypeName != "floatArray") && (functionTypeName
				!= "intArray")) {
			// Use this query to handle only A++ function call expressions
			// printf ("Break out of overloaded operator processing since type = %s is not to be processed \n",functionTypeName.c_str());
			break;
		} else {
			// printf ("Processing overloaded operator of type = %s \n",functionTypeName.c_str());
		}

		ROSE_ASSERT((functionTypeName == "doubleArray") || (functionTypeName == "floatArray") || (functionTypeName
				== "intArray"));

		// printf ("CASE FUNC_CALL: Overloaded operator = %s \n",operatorName.c_str());

		// Get the number of parameters to this function
		SgExprListExp* exprListExp = functionCallExpression->get_args();
		ROSE_ASSERT(exprListExp != NULL);

		SgExpressionPtrList & expressionPtrList = exprListExp->get_expressions();
		int numberOfParameters = expressionPtrList.size();

		TransformationSupport::operatorCodeType operatorCodeVariant =
				TransformationSupport::classifyOverloadedOperator(operatorName.c_str(), numberOfParameters);
		// printf ("CASE FUNC_CALL: numberOfParameters = %d operatorCodeVariant = %d \n",
		//      numberOfParameters,operatorCodeVariant);

		ROSE_ASSERT(operatorName.length() > 0);

		// Separating this case into additional cases makes up to some
		// extent for using a more specific higher level grammar.
		switch (operatorCodeVariant) {

		case TransformationSupport::ASSIGN_OPERATOR_CODE: {
			vector<ArrayOperandDataBase>::iterator lhs = operandDataBase.arrayOperandList.begin();
			vector<ArrayOperandDataBase>::iterator rhs = lhs;
			rhs++;
			while (rhs != operandDataBase.arrayOperandList.end()) {
				// look at the operands on the rhs for a match with the one on the lhs
				if ((*lhs).arrayVariableName == (*rhs).arrayVariableName) {
					// A loop dependence has been identified

					// Mark the synthesized attribute to record
					// the loop dependence within this statement
					returnSynthesizedAttribute.setLoopDependence(TRUE);
				}

				rhs++;
			}
			break;
		}

		default:
			break;
		}

		break;
	}
	case EXPR_STMT: {
		printf("Found a EXPR STMT expression %s\n", astNode->unparseToString().c_str());

		// The assembly associated with the SgExprStatement is what 
		// triggers the generation of the transformation string
		SgExprStatement* expressionStatement = isSgExprStatement(astNode);
		ROSE_ASSERT(expressionStatement != NULL);

		ArrayAssignmentStatementQuerySynthesizedAttributeType innerLoopTransformation =
				synthesizedAttributeList[SgExprStatement_expression];

		// Call another global support
		// Create appropriate macros, nested loops, etc
		expressionStatementTransformation(expressionStatement, arrayAssignmentStatementQueryInheritedData,
				innerLoopTransformation, operandDataBase);

		break;
	}

		//		case TransformationSupport::PARENTHESIS_OPERATOR_CODE: {
		//			ROSE_ASSERT (operatorName == "operator()");
		//			// printf ("Indexing of InternalIndex objects in not implemented yet! \n");
		//
		//			// Now get the operands out and search for the offsets in the index objects
		//
		//			// We only want to pass on the transformationOptions as inherited attributes
		//			// to the indexOffsetQuery
		//			// list<int> & transformationOptionList = arrayAssignmentStatementQueryInheritedData.getTransformationOptions();
		//
		//			// string offsetString;
		//			string indexOffsetString[6]; // = {NULL,NULL,NULL,NULL,NULL,NULL};
		//
		//			// retrieve the variable name from the data base (so that we can add the associated index object names)
		//			// printf ("WARNING (WHICH OPERAND TO SELECT): operandDataBase.size() = %d \n",operandDataBase.size());
		//			// ROSE_ASSERT (operandDataBase.size() == 1);
		//			// string arrayVariableName = returnSynthesizedAttribute.arrayOperandList[0].arrayVariableName;
		//			int lastOperandInDataBase = operandDataBase.size() - 1;
		//			ArrayOperandDataBase & arrayOperandDB = operandDataBase.arrayOperandList[lastOperandInDataBase];
		//			// string arrayVariableName =
		//			//      operandDataBase.arrayOperandList[operandDataBase.size()-1].arrayVariableName;
		//			string arrayVariableName = arrayOperandDB.arrayVariableName;
		//
		//			string arrayDataPointerNameSubstring = string("_") + arrayVariableName;
		//
		//			// printf ("***** WARNING: Need to get identifier from the database using the ArrayOperandDataBase::generateIdentifierString() function \n");
		//
		//			if (expressionPtrList.size() == 0) {
		//				// Case of A() (index object with no offset integer expression) Nothing to do here (I think???)
		//				printf("Special case of Indexing with no offset! exiting ... \n");
		//				ROSE_ABORT();
		//
		//				returnString = "";
		//			} else {
		//				// Get the value of the offsets (start the search from the functionCallExp)
		//				SgExprListExp* exprListExp = functionCallExpression->get_args();
		//				ROSE_ASSERT (exprListExp != NULL);
		//
		//				SgExpressionPtrList & expressionPtrList = exprListExp->get_expressions();
		//				SgExpressionPtrList::iterator i = expressionPtrList.begin();
		//
		//				// Case of indexing objects used within operator()
		//				int counter = 0;
		//				while (i != expressionPtrList.end()) {
		//					// printf ("Looking for the offset on #%d of %d (total) \n",counter,expressionPtrList.size());
		//
		//					// Build up the name of the final index variable (or at least give
		//					// it a unique number by dimension)
		//					string counterString = StringUtility::numberToString(counter + 1);
		//
		//					// Call another transformation mechanism to generate string for the index
		//					// expression (since we don't have an unparser mechanism in ROSE yet)
		//					indexOffsetString[counter] = IndexOffsetQuery::transformation(*i);
		//
		//					ROSE_ASSERT (indexOffsetString[counter].c_str() != NULL);
		//					// printf ("indexOffsetString [%d] = %s \n",counter,indexOffsetString[counter].c_str());
		//
		//					// Accumulate a list of all the InternalIndex, Index, and Range objects
		//					printf(" Warning - Need to handle indexNameList from the older code \n");
		//
		//					i++;
		//					counter++;
		//				}

		// Added VAR_REF case (moved from the local function)
	case VAR_REF: {
		// A VAR_REF has to output a string (the variable name)
#if DEBUG
		printf ("Found a variable reference expression \n");
#endif

		// Since we are at a leaf in the traversal of the AST this attribute list should a size of 0.
		ROSE_ASSERT(synthesizedAttributeList.size() == 0);

		SgVarRefExp* varRefExp = isSgVarRefExp(astNode);
		ROSE_ASSERT(varRefExp != NULL);
		SgVariableSymbol* variableSymbol = varRefExp->get_symbol();
		ROSE_ASSERT(variableSymbol != NULL);
		SgInitializedName* initializedName = variableSymbol->get_declaration();
		ROSE_ASSERT(initializedName != NULL);
		SgName variableName = initializedName->get_name();

		string buffer;
		string indexOffsetString;

		// Now compute the offset to the index objects (form a special query for this???)

		SgType* type = variableSymbol->get_type();
		ROSE_ASSERT(type != NULL);

		string typeName = TransformationSupport::getTypeName(type);
		ROSE_ASSERT(typeName.c_str() != NULL);

		// Recognize only these types at present
		if (typeName == "intArray" || typeName == "floatArray" || typeName == "doubleArray") {
			// Only define the variable name if we are using an object of array type
			// Copy the string from the SgName object to a string object
			string variableNameString = variableName.str();

#if DEBUG
			printf("Handle case of A++ array object VariableName: %s \n", variableNameString.c_str());
#endif

			if (arrayAssignmentStatementQueryInheritedData.arrayStatementDimensionDefined == TRUE) {
				cout << " Dim: " << arrayAssignmentStatementQueryInheritedData.arrayStatementDimension << endl;
				// The the globally computed array dimension from the arrayAssignmentStatementQueryInheritedData
				dimensionList.push_back(arrayAssignmentStatementQueryInheritedData.arrayStatementDimension);
			} else {
				dimensionList.push_back(6); // Default dimension for A++/P++
			}

			nodeList.push_back(isSgExpression(varRefExp));
			//processArrayRefExp(varRefExp, arrayAssignmentStatementQueryInheritedData);

			// Setup an intry in the synthesized attribute data base for this variable any
			// future results from analysis could be place there at this point as well
			// record the name in the synthesized attribute
			ROSE_ASSERT(operandDataBase.transformationOption > ArrayTransformationSupport::UnknownIndexingAccess);
			ArrayOperandDataBase arrayOperandDB = operandDataBase.setVariableName(variableNameString);
		}

		break;
	}

	default: {
		break;
	}
	} // End of main switch statement


#if DEBUG
	printf ("$$$$$ BOTTOM of arrayAssignmentStatementAssembly::evaluateSynthesizedAttribute (astNode = %s) \n",astNode->sage_class_name());
	printf ("      BOTTOM: returnString = \n%s \n",returnString.c_str());
#endif

	return returnSynthesizedAttribute;
}
Example #6
0
ParallelContainerQuerySynthesizedAttribute
ParallelContainerQueryTraversal::evaluateSynthesizedAttribute (
     SgNode* astNode,
     ParallelContainerQueryInheritedAttribute inheritedAttribute,
     SubTreeSynthesizedAttributes synthesizedAttributeList )
   {
     ParallelContainerQuerySynthesizedAttribute returnAttribute;

  // printf ("In evaluateSynthesizedAttribute: (astNode->sage_class_name() = %s) \n",
  //      astNode->sage_class_name());

     switch(astNode->variantT())
        {
          case V_SgForStatement:
             {
               bool isValidForLoopInitializer = synthesizedAttributeList[SgForStatement_for_init_stmt].validInitializer;
            // DQ (11/28/2005): The interface to SgForStatement has been changed to allow for tests to be a SgStatement (declaration)
            // bool isValidForLoopTest        = synthesizedAttributeList[SgForStatement_test_expr_root].validTestExpression;
               bool isValidForLoopTest        = synthesizedAttributeList[SgForStatement_test].validTestExpression;
               bool isValidForLoopIncrement   = synthesizedAttributeList[SgForStatement_increment_expr_root].validIncrementExpression;
               bool isValidForLoopHeader      = isValidForLoopInitializer && isValidForLoopTest && isValidForLoopIncrement;

               bool isValidForLoopBody        = synthesizedAttributeList[SgForStatement_loop_body].validLoopBody;

            // printf ("isValidForLoopInitializer = %s \n",isValidForLoopInitializer ? "true" : "false");
            // printf ("isValidForLoopTest        = %s \n",isValidForLoopTest ? "true" : "false");
            // printf ("isValidForLoopIncrement   = %s \n",isValidForLoopIncrement ? "true" : "false");
            // printf ("isValidForLoopHeader      = %s \n",isValidForLoopHeader ? "true" : "false");
            // printf ("isValidForLoopBody        = %s \n",isValidForLoopBody ? "true" : "false");

               returnAttribute.validParallelTransformation = isValidForLoopHeader && isValidForLoopBody;
               break;
             }

          case V_SgFunctionCallExp:
             {
            // printf ("Found the SgFunctionCallExp \n");

               SgFunctionCallExp* functionCall = isSgFunctionCallExp(astNode);
               ROSE_ASSERT (functionCall != NULL);
               string functionName = TransformationSupport::getFunctionName(functionCall);
               string className = TransformationSupport::getFunctionTypeName(functionCall);

            // printf ("className = %s function name = %s \n",className.c_str(),functionName.c_str());

               if (inheritedAttribute.inInitializer == true)
                  {
                 // initalizer should be either "list::iterator i = list.begin()" or "i = list.begin()"
                 // printf ("Found the SgFunctionCallExp in the for loop initializer \n");
                    OpenMP_Translation_Utility::AbstractionListType l = 
                         containerInfoList->matchingContainerNameList (className);
                    ROSE_ASSERT (l.size() > 0);
                    ROSE_ASSERT (functionName == "begin");
                    returnAttribute.validInitializer = true;
                  }
               if (inheritedAttribute.inTestExpression == true)
                  {
                 // test expression should be "iter != mylist.end()"
                 // printf ("Found the SgFunctionCallExp in the for loop test expression \n");

                    if (className != "iterator")
                       {
                      // Don't test iterator member functions, typically "operator!=()"
                         OpenMP_Translation_Utility::AbstractionListType l = 
                              containerInfoList->matchingContainerNameList (className);
                         ROSE_ASSERT (l.size() > 0);
                         ROSE_ASSERT (functionName == "end");
                         returnAttribute.validTestExpression = true;
                       }
                      else
                       {
                      // need to pass along the synthesized attribute information
                         for (unsigned int i=0; i < synthesizedAttributeList.size(); i++)
                            {
                              returnAttribute.validTestExpression = 
                                   returnAttribute.validTestExpression || 
                                   synthesizedAttributeList[i].validTestExpression;
                            }
                       }
                  }
               if (inheritedAttribute.inIncrementExpression == true)
                  {
                 // This expression should just be "i++", so likely there is something wrong here
                 // (unless it is the operator++() member function)
                 // printf ("Found the SgFunctionCallExp in the for loop increment expression \n");
                    ROSE_ASSERT (functionName == "operator++");
                    returnAttribute.validIncrementExpression = true;
                  }
               if (inheritedAttribute.inLoopBody == true)
                  {
                 // Make sure it is a function from the target library
                 // printf ("Found the SgFunctionCallExp in the for loop body \n");
                    if (className != "iterator")
                       {
                         OpenMP_Translation_Utility::AbstractionListType l = 
                              containerInfoList->matchingFunctionNameList (functionName);
                         ROSE_ASSERT (l.size() > 0);
                         returnAttribute.validLoopBody = true;
                       }
                  }
               
               break;
             }

          default:
             {
            // Merge allthe child attributes to a single synthesized attribute
               for (unsigned int i=0; i < synthesizedAttributeList.size(); i++)
                  {
                    returnAttribute.validInitializer = 
                         returnAttribute.validInitializer || 
                         synthesizedAttributeList[i].validInitializer;
                    returnAttribute.validTestExpression = 
                         returnAttribute.validTestExpression || 
                         synthesizedAttributeList[i].validTestExpression;
                    returnAttribute.validIncrementExpression = 
                         returnAttribute.validIncrementExpression || 
                         synthesizedAttributeList[i].validIncrementExpression;
                    returnAttribute.validLoopBody = 
                         returnAttribute.validLoopBody || 
                         synthesizedAttributeList[i].validLoopBody;
                    returnAttribute.validParallelTransformation = 
                         returnAttribute.validParallelTransformation || 
                         synthesizedAttributeList[i].validParallelTransformation;
                  }
             }
        }

     return returnAttribute;
   }
Example #7
0
Detection_SynthesizedAttribute
DetectionTraversal::evaluateSynthesizedAttribute (SgNode* astNode, Detection_InheritedAttribute inheritedAttribute, SubTreeSynthesizedAttributes synthesizedAttributeList )
   {
     ROSE_ASSERT(astNode != NULL);

     Detection_SynthesizedAttribute return_synthesizedAttribute(astNode);

#if 1
     printf ("In evaluateSynthesizedAttribute(): astNode = %p = %s synthesizedAttributeList.size() = %zu dslChildren.size() = %zu \n",
          astNode,astNode->class_name().c_str(),synthesizedAttributeList.size(),return_synthesizedAttribute.dslChildren.size());
#endif

  // At each IR node and across all children, accumulate the dslChildren (child nodes for each of the DSL AST nodes).
     for (SubTreeSynthesizedAttributes::iterator i = synthesizedAttributeList.begin(); i != synthesizedAttributeList.end(); i++)
        {
          SgNode* childNode = (*i).node;
       // ROSE_ASSERT(childNode != NULL);
          if (childNode != NULL)
             {
#if 0
               printf ("Identified child node in evaluateSynthesizedAttribute(): childNode = %p = %s \n",childNode,childNode->class_name().c_str());
#endif
            // Insert each list from the child into the accumulated list in the current Synthesized Attribute.
               return_synthesizedAttribute.dslChildren.insert(return_synthesizedAttribute.dslChildren.end(),i->dslChildren.begin(),i->dslChildren.end());
#if 0
               printf ("   --- copying i->dslChildren.size() = %zu into return_synthesizedAttribute.dslChildren.size() = %zu \n",i->dslChildren.size(),return_synthesizedAttribute.dslChildren.size());
#endif
               if (return_synthesizedAttribute.dslChildren.empty() == false)
                  {
#if 0
                    printf ("In evaluateSynthesizedAttribute(): dslChildren.size() = %zu \n",return_synthesizedAttribute.dslChildren.size());
#endif
                  }
             }
            else
             {
#if 1
               printf ("childNode == NULL \n");
#endif
             }
        }


  // Recognition of other control statements (e.g. for loops for the stencil evaluation) or expression/statement abstractions (e.g. function calls)
  // Note: DSL specific control abstractions might be recognised as loops containing DSL abstractions and having constant evaluatable base and bounds.


  // For any DSL specific AST nodes (C++ AST nodes containing a DSL_Attribute), initialize the pointers to children of the DSL IR node.
     AstAttributeMechanism* astAttributeContainer = astNode->get_attributeMechanism();
     if (astAttributeContainer != NULL)
        {
#if 1
          printf ("In evaluateSynthesizedAttribute(): found a attribute on astNode = %p = %s \n",astNode,astNode->class_name().c_str());
#endif
       // I think there should only be one DSL attribute, in the future we can support more on a single IR node.
          if (astAttributeContainer->size() != 1)
             {
               printf ("WARNING: astAttributeContainer->size() != 1: astAttributeContainer->size() = %zu \n",astAttributeContainer->size());
             }
#if 1
       // DQ: Allow this for the moment while testing.
          ROSE_ASSERT(astAttributeContainer->size() == 1);
#endif
       // Loop over all the attributes at this IR node
       // Pei-Hung (12/22/15): THe ASTAttributeMechanmsim is changed and has to use new API
       // for (AstAttributeMechanism::iterator i = astAttributeContainer->begin(); i != astAttributeContainer->end(); i++)
          BOOST_FOREACH (const std::string &attributeName, astAttributeContainer->getAttributeIdentifiers()) 
             {
               AstAttribute* attribute = astNode->getAttribute(attributeName);
               ROSE_ASSERT(attribute != NULL);
#if 1
            // DSL_Attribute* dslAstAttribute = dynamic_cast<DSL_Attribute*>(attribute);
               dsl_attribute* dslAstAttribute = dynamic_cast<dsl_attribute*>(attribute);
               ROSE_ASSERT(dslAstAttribute != NULL);
#if 1
               printf ("Identified dslAstAttribute in evaluateSynthesizedAttribute(): astNode = %p = %s \n",astNode,astNode->class_name().c_str());
               printf ("   --- return_synthesizedAttribute.dslChildren.size() = %zu \n",return_synthesizedAttribute.dslChildren.size());
#endif
            // Copy the dsl child data to the dsl attribute.
               dslAstAttribute->currentNode = astNode;
               dslAstAttribute->dslChildren = return_synthesizedAttribute.dslChildren;
#endif
             }

       // Clear the dsl attributes becasue we the only collect dsl child attributes at dsl attributed IR nodes and don't pass then further up the tree.          
          return_synthesizedAttribute.dslChildren.clear();

       // Add the current node since it has an attribute.
          return_synthesizedAttribute.dslChildren.push_back(astNode);

#if 0
          printf ("Exiting as a test! \n");
          ROSE_ASSERT(false);
#endif
        }
DetectMacroExpansionsToBeUnparsedAsAstTransformationsSynthesizedAttribute 
DetectMacroExpansionsToBeUnparsedAsAstTransformations::evaluateSynthesizedAttribute ( 
   SgNode* n, 
   DetectMacroExpansionsToBeUnparsedAsAstTransformationsInheritedAttribute inheritedAttribute, 
   SubTreeSynthesizedAttributes synthesizedAttributeList )
   {
     DetectMacroExpansionsToBeUnparsedAsAstTransformationsSynthesizedAttribute returnAttribute(n);

#if 0
     printf ("In (Detect Transformations in Macro Expansions) evaluateSynthesizedAttribute(): n = %s n->get_containsTransformation() = %s \n",n->class_name().c_str(),n->get_containsTransformation() ? "true" : "false");
#endif

  // DQ (11/8/2015): This has to be moved to after the tokenStreamSequenceMap has been setup since we need that to determine if 
  // IR nodes have a token mapping or not (subparts of macros expansions will not and we need this infor to recognize parts of 
  // the AST that are associated with macro expansions.
  // DQ (11/8/2015): If this has been marked as containing a transformation then check if there is token info for each of the children.
  // If there is not token info for each of the children then this currentStatement (e.g. n) must be marked as a transformation.
  // This case happens when a transformation is done to a child of a statement that is part of a macro.  In this case the parent will
  // have token information which is the macro call, but since there is a transformation, we have to unparse the fully expanded form 
  // of the macro (from the AST), so the whole subtree must be unparsed.  NOTE: this case might be more complex if multiple statements
  // are associated with a macro (so that there is not a single root of the subtree.  I need to build an example of this to better 
  // understand if there is a problem and if so just what would be the best solution.  It will b at least an iterative refinement of
  // this specific problem.  See tests/roseTests/astInterfaceTests/inputmoveDeclarationToInnermostScope_test2015_135.C for an example
  // of this problem.
     if (n->get_containsTransformation() == true)
        {
#if 0
          printf ("Found case of statement marked as containing a transforamtion \n");
#endif
          SgStatement* currentStatement = isSgStatement(n);
#if 0
          if (currentStatement != NULL)
             {
            // printf ("currentStatement = %p = %s \n",currentStatement,currentStatement->class_name().c_str());
               printf ("currentStatement = %s \n",currentStatement->class_name().c_str());
               printf ("   --- currentStatement->isTransformation()    = %s \n",currentStatement->isTransformation() ? "true" : "false");
             }
#endif
       // We have to test for a macro exapansion (will only work on statement level grainularity where parent statement has child statements).
          bool all_children_have_token_info = true;
          for (size_t i = 0; i < synthesizedAttributeList.size(); i++)
             {
               SgStatement* statement = isSgStatement(synthesizedAttributeList[i].node);
               if (statement != NULL)
                  {
#if 0
                 // printf ("(child) statement = %p = %s \n",statement,statement->class_name().c_str());
                    printf ("(child) statement = %s \n",statement->class_name().c_str());
                    printf ("   --- statement->isTransformation()           = %s \n",statement->isTransformation() ? "true" : "false");
                    printf ("   --- statement->get_containsTransformation() = %s \n",statement->get_containsTransformation() ? "true" : "false");
#endif
                 // DQ (11/8/2015): We might need to also check the surrounding white space as well (except that I think this is set later).
                    if (tokenStreamSequenceMap.find(statement) != tokenStreamSequenceMap.end())
                       {
                      // If we have a token mapping then we don't have to do anything.
                         TokenStreamSequenceToNodeMapping* mapping = tokenStreamSequenceMap[statement];
                         ROSE_ASSERT(mapping != NULL);
                       }
                      else
                       {
#if 0
                      // printf ("Parent statement = %p = %s No token stream information found for child statement = %p = %s \n",
                      //      currentStatement,currentStatement->class_name().c_str(),statement,statement->class_name().c_str());
                         printf ("Parent statement = %s No token stream information found for child statement = %s \n",
                              currentStatement->class_name().c_str(),statement->class_name().c_str());
                         printf ("   --- at line: %d \n",statement->get_file_info()->get_line());

                      // When this is a function declaration, try to understand more about it.
                         SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(statement);
                         if (functionDeclaration != NULL)
                            {
                              printf ("   --- functionDeclaration name = %s \n",functionDeclaration->get_name().str());
                            }
#endif
                         all_children_have_token_info = false;
                       }
                  }
             }

          if (currentStatement != NULL && all_children_have_token_info == false)
             {
#if 0
            // printf ("*** Found case of statement marked as containing a transforamtion, but all children without token info (detected a macro expansion): currentStatement = %p = %s \n",currentStatement,currentStatement->class_name().c_str());
               printf ("*** Found case of statement marked as containing a transforamtion, but all children without token info (detected a macro expansion): currentStatement = %s \n",currentStatement->class_name().c_str());
#endif

            // DQ (11/9/2015): Added support for specific scopes where we don't want them the be 
            // unparsed from the token stream when children of them are transformed.
            // DQ (11/8/2015): I think that this should not apply to a SgBasicBlock (for example see 
            // tests/roseTests/astInterfaceTests/inputmoveDeclarationToInnermostScope_test2015_94.C).
            // The reason is that a block is not the same sort for compound statement as a SgForStatement.
            // if (isSgBasicBlock(currentStatement) == NULL)
               bool current_statement_is_allowed_to_have_statements_with_unmapped_token_sequences = 
                    ( (isSgGlobal(currentStatement) != NULL)          || 
                      (isSgBasicBlock(currentStatement) != NULL)      ||
                   // (isSgEnumDefinition(currentStatement) != NULL)  ||
                      (isSgClassDefinition(currentStatement) != NULL) );

               if (current_statement_is_allowed_to_have_statements_with_unmapped_token_sequences == false)
                  {
                 // Mark as a transformation instead of containing a transformation.
                    currentStatement->setTransformation();

                 // We also need to mark this too!
                    currentStatement->setOutputInCodeGeneration();

                 // And reset this to NOT contain a transformation.
                    currentStatement->set_containsTransformation(false);
#if 0
                    printf ("Exiting as a test! \n");
                    ROSE_ASSERT(false);
#endif
                  }
                 else
                  {
#if 0
                 // printf ("This currentStatement = %p = %s is allowed to have a child without a token sequence mapping \n",currentStatement,currentStatement->class_name().c_str());
                    printf ("This currentStatement = %s is allowed to have a child without a token sequence mapping \n",currentStatement->class_name().c_str());
#endif
                  }
             }
#if 0
       // Debugging code.
          if (isSgForStatement(n) != NULL)
             {
               printf ("Exiting as a test! \n");
               ROSE_ASSERT(false);
             }
#endif
        }

     return returnAttribute;
   }