本文整理汇总了C++中SgVarRefExp::unparseToString方法的典型用法代码示例。如果您正苦于以下问题:C++ SgVarRefExp::unparseToString方法的具体用法?C++ SgVarRefExp::unparseToString怎么用?C++ SgVarRefExp::unparseToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SgVarRefExp
的用法示例。
在下文中一共展示了SgVarRefExp::unparseToString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char * argv[])
{
SgProject *project = frontend (argc, argv);
SgFunctionDeclaration* func_decl = SageInterface::findDeclarationStatement<SgFunctionDeclaration>
(project, "foo", NULL, true);
Rose_STL_Container<SgNode*> nodeList = NodeQuery::querySubTree(func_decl->get_definition(), V_SgVarRefExp);
for (Rose_STL_Container<SgNode *>::iterator i = nodeList.begin(); i != nodeList.end(); i++)
{
SgVarRefExp *vRef = isSgVarRefExp((*i));
cout<<"varRefExp: "<< vRef->unparseToString()<<endl;
}
// We expect two references
// from input_ompVariableCollecting.C
if (nodeList.size() !=2)
{
cerr<<"Error. We should find exactly two variable references."<<endl;
}
ROSE_ASSERT (nodeList.size() ==2);
return backend(project);
}
示例2: linearizeThisArrayRefs
//.........这里部分代码省略.........
}
else if (indexNo==2) //idy
{
offset = buildVarRefExp(width_str, kernel_body) ;
if(constIntVal != 1)
offset = buildMultiplyOp(offset, buildIntVal(constIntVal));
}
else if(indexNo==3) //idz
{
offset = buildVarRefExp(slice_str, kernel_body) ;
if(constIntVal != 1)
offset = buildMultiplyOp(offset, buildIntVal(constIntVal));
}
if(constIntVal != 0 )
{
ROSE_ASSERT(offset);
if(subtractExp.size() == 1)
indexExp = buildSubtractOp(indexExp, offset);
else if (addExp.size() == 1)
indexExp = buildAddOp(indexExp, offset);
}
}
else if (indexVarExp.size() == 2)
{ //Added in (3 March 2011) to handle boundary loads
//they are typically A[z][y][x + borderOffset] so it is worth to optimize them
Rose_STL_Container<SgNode*>::iterator it = indexVarExp.begin();
SgVarRefExp* first = isSgVarRefExp(*it);
SgVarRefExp* second = isSgVarRefExp(*(++it));
ROSE_ASSERT(first);
ROSE_ASSERT(second);
string secondRef = second->unparseToString();
SgExpression* offset =copyExpression(first);
if(secondRef.find(GIDX) == string::npos && secondRef.find(GIDY) && string::npos && secondRef.find(GIDZ) == string::npos)
{//borderOffset is the second var
offset = copyExpression(second);
}
if (indexNo==2) //idy
{
offset = buildMultiplyOp(offset,buildVarRefExp(width_str, kernel_body)) ;
}
if(indexNo==3) //idz
{
offset = buildMultiplyOp(offset, buildVarRefExp(slice_str, kernel_body)) ;
}
ROSE_ASSERT(offset);
if(subtractExp.size() == 1)
indexExp = buildSubtractOp(indexExp, offset);
else if (addExp.size() == 1)
indexExp = buildAddOp(indexExp, offset);
}
else {
ROSE_ABORT();
}
}
else
{
ROSE_ASSERT(constExp.size() == 0);
//do nothing because it is in the base index
示例3: isShareableReference
bool StencilAnalysis::isShareableReference(const std::vector<SgExpression*> subscripts,
const bool corner_yz //=FALSE
)
{
//March 2 2011, made changes in the function, we have more robust sharing conditions
//checks if an array reference can be replaced with shared memory reference
//by looking at the index expressions
//assumes the variable is already checked for candidacy
//check if subsrcipts are _gidx, _gidy or _gidz
std::vector<SgExpression*>::const_iterator it;
size_t count = 0;
int indexNo = 0;
for(it= subscripts.begin(); it != subscripts.end(); it++)
{
indexNo++;
SgExpression* index = isSgExpression(*it);
Rose_STL_Container<SgNode*> varList = NodeQuery::querySubTree(index, V_SgVarRefExp);
if(varList.size() != 1) //there should be only 1 variable and that should be gidx,y,z
return false;
//check if that varRef is x, y, z
SgVarRefExp* varExp = isSgVarRefExp(*(varList.begin()));
ROSE_ASSERT(varExp);
string index_str = varExp->unparseToString();
if(indexNo == 1 && index_str != GIDX )
return false;
if(indexNo == 2 && index_str != GIDY )
return false;
if(indexNo == 3 && index_str != GIDZ )
return false;
Rose_STL_Container<SgNode*> constList = NodeQuery::querySubTree(index, V_SgIntVal);
if(constList.size() > 1 )
return false;
if(constList.size() == 1)
{
SgIntVal* constVal = isSgIntVal(*(constList.begin()));
ROSE_ASSERT(constVal);
if(constVal->get_value() > MAX_ORDER)
return false;
//we keep maximum 3 planes in shared memory
if(constVal->get_value() > 1 && indexNo == 3)
return false;
Rose_STL_Container<SgNode*> binOpList = NodeQuery::querySubTree(index, V_SgBinaryOp);
if(binOpList.size() != 1)
return false;
SgBinaryOp* binOp = isSgBinaryOp(*(binOpList.begin()));
//we want either one add or subtract operation in the index expression
//no complex indexing is supported for now.
//A[i+2][i-4] is valid but A[i*2] is not valid
if( !isSgAddOp(binOp) && !isSgSubtractOp(binOp))
return false;
if(indexNo == 3 && !corner_yz)
{ //corner of yz is only shareable when corner_yz is true
return false;
}
}
count++;
}
return (count == subscripts.size()) ? true : false ;
}
示例4: getSharingCategory
int StencilAnalysis::getSharingCategory(const std::vector<SgExpression*> subscripts)
{
//return 2 if it is up or down
//return 1 if it is off-center
//return 0 if it is center
//return -1 if it is neither
//check if subsrcipts are _gidx, _gidy or _gidz
std::vector<SgExpression*>::const_iterator it;
size_t count = 0;
int indexNo = 0;
size_t category = 0;
for(it= subscripts.begin(); it != subscripts.end(); it++)
{
indexNo++;
SgExpression* index = isSgExpression(*it);
Rose_STL_Container<SgNode*> varList = NodeQuery::querySubTree(index, V_SgVarRefExp);
if(varList.size() != 1) //there should be only 1 variable and that should be gidx,y,z
return -1;
//check if that varRef is x, y, z
SgVarRefExp* varExp = isSgVarRefExp(*(varList.begin()));
ROSE_ASSERT(varExp);
string index_str = varExp->unparseToString();
if(indexNo == 1 && index_str != GIDX )
return -1;
else if(indexNo == 2 && index_str != GIDY )
return -1;
else if(indexNo == 3 && index_str != GIDZ )
return -1;
Rose_STL_Container<SgNode*> constList = NodeQuery::querySubTree(index, V_SgIntVal);
if(constList.size() > 1 )
return -1;
if(constList.size() == 1)
{
category = 1;
SgIntVal* constVal = isSgIntVal(*(constList.begin()));
ROSE_ASSERT(constVal);
if(constVal->get_value() > MAX_ORDER)
return -1;
//we keep maximum 3 planes in shared memory
if(constVal->get_value() > 1 && indexNo == 3)
return -1;
Rose_STL_Container<SgNode*> binOpList = NodeQuery::querySubTree(index, V_SgBinaryOp);
if(binOpList.size() != 1)
return -1;
SgBinaryOp* binOp = isSgBinaryOp(*(binOpList.begin()));
//we want either one add or subtract operation in the index expression
//no complex indexing is supported for now.
//A[i+2][i-4] is valid but A[i*2] is not valid
if( !isSgAddOp(binOp) && !isSgSubtractOp(binOp))
return -1;
if(indexNo == 3)
{
category = 2;
}
}
count++;
}
return (count == subscripts.size()) ? category : -1 ;
}