Ejemplo n.º 1
0
   //! Setup MPI finalize 
  void setupMPIFinalize(SgSourceFile* sfile)
  {
    SgFunctionDeclaration* main_decl = findMain(sfile);
    // TODO: handle multiple files, some of them don't have main()
    ROSE_ASSERT (main_decl != NULL);
    SgFunctionDefinition* main_def = main_decl->get_definition();
    ROSE_ASSERT (main_def != NULL);
    SgBasicBlock* func_body = main_def->get_body();
    ROSE_ASSERT (func_body != NULL);

    SgStatement* mf = buildFunctionCallStmt ("MPI_Finalize", buildVoidType(), NULL, func_body );
    
    instrumentEndOfFunction (main_decl, mf);
  }
Ejemplo n.º 2
0
/*
 * Add calls to register and unregister expressions/arrays with the memory
 * management wrapper.
 */
bool RegisterPointers::addRegUnregCalls()
{
	string msg;

	if(definedInSystemHeader)
	{
		msg = "\t\t\tVariable " + NAME(varSymbol) + " is in system headers";
		WARNING(TOOL, msg);
		return false;
	}

	if(compilerGenerated)
	{
		msg = "\t\t\tVariable " + NAME(varSymbol) + " is compiler-generated";
		WARNING(TOOL, msg);
		return false;
	}

	if(addrUsedInIO)
	{
		msg = "\t\t\tVariable " + NAME(varSymbol) + " has its address taken in "
				+ "a function known to not require registering/unregistering";
		WARNING(TOOL, msg);
		return false;
	}

	//Add register/unregister calls
	SgStatement* prevStmt = NULL;
	SgExprStatement* funcCall = NULL;
	SgType* type = NULL;
	SgExpression* expr = NULL;

	if(isGlobal)
	{
		type = varName->get_type();
		SgName name = varName->get_name();
		int numVals = 1;

		if(isSgPointerType(type))
			return false;	//If its a pointer, it points to a static array, dynamic array, or scalar
							//which has its address taken (all of which have already been registered)

		SgFunctionDeclaration* main = findMain(getScope(varName));
		ROSE_ASSERT(main);
		expr = buildVarRefExp(name, varName->get_scope());
		if(isSgArrayType(type))
			numVals = getArrayElementCount(isSgArrayType(type));
		else
			expr = buildAddressOfOp(expr);

		funcCall = MMCallBuilder::buildRegisterPointerCall(expr, buildUnsignedIntVal(numVals),
				main->get_definition());
		insertStatement(getFirstStatement(main->get_definition()), funcCall);//, false, true);
		funcCall = MMCallBuilder::buildUnregisterPointerCall(expr, main->get_definition());
		instrumentEndOfFunction(main, funcCall);
	}
	else if(expression) //Address-of expressions
	{
		prevStmt = getEnclosingStatement(expression);
		funcCall = MMCallBuilder::buildRegisterPointerCall(expression, buildUnsignedIntVal(1),
				getScope(expression));
		insertStatement(prevStmt, funcCall);
		funcCall = MMCallBuilder::buildUnregisterPointerCall(expression, getScope(expression));
		instrumentEndOfFunction(getEnclosingFunctionDeclaration(prevStmt), funcCall);
	}
	else //Array types
	{
		SgVarRefExp* varRef = buildVarRefExp(varName, getScope(varName));

		int numVals = getArrayElementCount(isSgArrayType(varName->get_type()));
		funcCall = MMCallBuilder::buildRegisterPointerCall(varRef, buildUnsignedIntVal(numVals),
				varName->get_scope());
		insertStatement(varName->get_declaration(), funcCall, false, true);
		varRef = buildVarRefExp(varName, getScope(varName));
		funcCall = MMCallBuilder::buildUnregisterPointerCall(varRef, varName->get_scope());
		instrumentEndOfFunction(getEnclosingFunctionDeclaration(varName), funcCall);
	}

	return true;
}