Skip to content

Commit

Permalink
Merge commit 'd69a5f65264616b784c6c8c2add32b4a2232d84e' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
rosecompiler committed Apr 30, 2021
2 parents a72b2b6 + d69a5f6 commit 14d7eff
Show file tree
Hide file tree
Showing 32 changed files with 603 additions and 518 deletions.
15 changes: 15 additions & 0 deletions config/support-rose.m4
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,21 @@ AC_ARG_WITH(wave-default, [ --with-wave-default Use Wave as the default pre
[AC_DEFINE([ROSE_WAVE_DEFAULT], false, [Simple preprocessor as default in ROSE])]
)
AC_ARG_WITH(alloc-memset, [ --with-alloc-memset Memory pool protection (memory is set on memory pool operation): 0 -> none, 1 -> command-line (NIY), 2 -> zeroed new/delete, 3 -> aggressive (diff. value for each mempool operation)],
[AC_DEFINE_UNQUOTED([ROSE_ALLOC_MEMSET], $with_alloc_memset, [With memset on mempool operations])],
[AC_DEFINE([ROSE_ALLOC_MEMSET], 0, [Without memset on mempool operations])]
)
AC_ARG_WITH(pedantic-alloc, [ --with-pedantic-alloc Enables pedantic assertions in Memory Pool: 0 -> none, 1 -> enabled ],
[AC_DEFINE_UNQUOTED([ROSE_PEDANTIC_ALLOC], $with_pedantic_alloc, [With pedantic allocation check])],
[AC_DEFINE([ROSE_PEDANTIC_ALLOC], 0, [Without pedantic allocation check])]
)
AC_ARG_WITH(alloc-trace, [ --with-alloc-trace Memory pool allocation tracing (tiny reproducers only): 0 -> none, 1 -> command-line (NIY), 2 -> enabled],
[AC_DEFINE_UNQUOTED([ROSE_ALLOC_TRACE], $with_alloc_trace, [With tracing of memory pool operation])],
[AC_DEFINE([ROSE_ALLOC_TRACE], 0, [Without tracing of memory pool operation])]
)
# Add --disable-binary-analysis-tests flag to turn off tests that sometimes
# sometimes break.
# Pei-Hung (10/24/2016) use only ROSE_BUILD_BINARY_ANALYSIS_SUPPORT to control binary analysis tests
Expand Down
62 changes: 23 additions & 39 deletions src/ROSETTA/Grammar/Common.code
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,30 @@ HEADER_START
/*! \brief Casts pointer from base class to derived class (for const pointers) */
ROSE_DLL_API friend const $CLASSNAME* is$CLASSNAME( const SgNode * s );

// ******************************************
// * Memory Pool / New / Delete
// ******************************************

public:
// DQ (9/21/2005): Support for memory pools
static const unsigned pool_size; //
static std::vector<unsigned char *> pools; //

static $CLASSNAME * next_node; //

static unsigned long initializeStorageClassArray($CLASSNAMEStorageClass *); //

static void clearMemoryPool(); //

static void extendMemoryPoolForFileIO(); //

static $CLASSNAME * getPointerFromGlobalIndex(unsigned long); //
static $CLASSNAME * getPointerFromGlobalIndex(AstSpecificDataManagingClass *, unsigned long); //

static unsigned long getNumberOfValidNodesAndSetGlobalIndexInFreepointer(unsigned long); //
static void resetValidFreepointers(); //
static unsigned long getNumberOfLastValidPointer(); //


#if defined(INLINE_FUNCTIONS)
/*! \brief returns pointer to newly allocated IR node */
inline void *operator new (size_t size);
Expand All @@ -40,24 +62,12 @@ HEADER_START
/*! \brief deallocated memory for IR node (returns memory to memory pool for reuse) */
void operator delete (void* pointer, size_t size);

#if 1
/* RPM (2009-06-03): Apparently this must all be on one line for configuration "--with-javaport"; reverting r5427 */
// void operator delete (void* pointer) { $CLASSNAME::operator delete (pointer,sizeof($CLASSNAME)); };
// DQ (9/2/2015): Added comment for delete operator.
/*! \brief ROSETTA generated delete operator: deletes all non-traversed members. */
//void operator delete (void* pointer);
#else
// DQ (4/5/2007): This is not the correct operator that we want, but appears to be required to compile ROSE with ROSE.
void operator delete (void* pointer)
{
// DQ (4/20/2009): Added comment and assertion to make sure this is not executed!
// printf ("This is not the correct operator that we want, but appears to be required to compile ROSE with ROSE \n");
// ROSE_ASSERT(false);

// This is the generated delete operator...
$CLASSNAME::operator delete (pointer,sizeof($CLASSNAME));
}
#endif

// DQ (6/7/2010): Change the return type to size_t to support larger number of IR nodes
// using values that overflow signed values of int.
Expand Down Expand Up @@ -289,33 +299,7 @@ HEADER_START
*/
// typedef unsigned long AddressType;

// #ifndef ROSE_USE_SWIG_SUPPORT
#ifndef SWIG

/*! \brief Methods to find the pointer to a global and local index
*/
friend $CLASSNAME* $CLASSNAME_getPointerFromGlobalIndex ( unsigned long globalIndex ) ;

/*! \brief Get the size of the memory pool

It actually returns the size of the whole blocks allocated, no matter they contain valid pointers or not.
*/
friend unsigned long $CLASSNAME_getNumberOfValidNodesAndSetGlobalIndexInFreepointer( unsigned long );

/*! \brief clear the memory pool */
friend void $CLASSNAME_clearMemoryPool ( );

/*! \brief internal support for AST file I/O (operating on the memory pools) */
friend void $CLASSNAME_extendMemoryPoolForFileIO ( unsigned long );

/*! \brief internal support for AST file I/O (operating on the memory pools) */
friend void $CLASSNAME_getNextValidPointer ( std::pair<$CLASSNAME*, std::vector < unsigned char* > :: const_iterator >& );

/*! \brief internal support for AST file I/O (operating on the memory pools) */
friend void $CLASSNAME_resetValidFreepointers( );

// endif for ifndef ROSE_USE_SWIG_SUPPORT
#endif

// necessary, to have direct access to the p_freepointer and the private methods !
/*! \brief friend class declaration to support AST File I/O */
Expand Down
2 changes: 1 addition & 1 deletion src/ROSETTA/Grammar/Expression.code
Original file line number Diff line number Diff line change
Expand Up @@ -1865,7 +1865,7 @@ HEADER_JOVIAL_TABLE_PRESET_EXP_END

// Rasmussen (4/9/2021): Added SgJovialPresetPositionExp to support initialization of Jovial tables
HEADER_JOVIAL_PRESET_POSITION_EXP_START
int replace_expression (SgExpression *o, SgExpression *n);
int replace_expression (SgExpression *o, SgExpression *n) $ROSE_OVERRIDE;
HEADER_JOVIAL_PRESET_POSITION_EXP_END

HEADER_UPC_LOCAL_SIZEOF_EXPRESSION_START
Expand Down
4 changes: 2 additions & 2 deletions src/ROSETTA/Grammar/Node.code
Original file line number Diff line number Diff line change
Expand Up @@ -2711,8 +2711,8 @@ SgNode::get_parent () const
// the symbol table as a way to support better debugging within the AST merge mechanims.
// Sage II semantics: Types and Symbols always have a NULL parent (This is the way it is implemented (from Sage II))
// if ( (isSgType( const_cast<SgNode*>(this) ) != NULL) || (isSgSymbol( const_cast<SgNode*>(this) ) != NULL) )
if ( isSgType( const_cast<SgNode*>(this) ) != NULL )
returnNode = NULL;
// if ( isSgType( const_cast<SgNode*>(this) ) != NULL )
// returnNode = NULL;

return returnNode;
}
Expand Down
169 changes: 39 additions & 130 deletions src/ROSETTA/Grammar/grammarAST_FileIoSource.code
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,6 @@

using namespace std;

#if 0
namespace AST_FileIO
{
class MemoryCheckingTraversalForAstFileIO : public ROSE_VisitTraversal
{
public:
int counter;
void visit ( SgNode* node );
};

void MemoryCheckingTraversalForAstFileIO::visit ( SgNode* node )
{
ROSE_ASSERT(node != NULL);
// printf ("MemoryCheckingTraversalForAstFileIO::visit: node = %s \n",node->class_name().c_str());
ROSE_ASSERT(node->get_freepointer() == AST_FileIO::IS_VALID_POINTER());
node->checkDataMemberPointersIfInMemoryPool();
}
}
#endif

/* JH(01/17/2006) Initializing the static data members
*/
AstData*
AST_FILE_IO :: actualRebuildAst;

Expand All @@ -56,9 +34,14 @@ AST_FILE_IO::registeredAttributes;
memory pools, already stored in listOfAccumulatedPoolSizes [ V_$CLASSNAME ].
*/

#define DEBUG_AstFileIO_startUp 0

void
AST_FILE_IO :: startUp( SgProject* root )
{
#if DEBUG_AstFileIO_startUp
std::cout << "AST_FILE_IO::startUp" << std::endl;
#endif
/* Our array containing the total memory pool sizes starts at startingIndex. This is the first multiple of 100
that is greater than the indices used internally. We sort the the memory pool size at
position [ V_$CLASSNAME + 1 ]. Concurrently, we allocate the appropriate STORAGE_class_list arrays.
Expand Down Expand Up @@ -93,6 +76,10 @@ AST_FILE_IO :: startUp( SgProject* root )

$REPLACE_STARTUP

#if DEBUG_AstFileIO_startUp
std::cout << "listOfMemoryPoolSizes [935] = " << std::dec << listOfMemoryPoolSizes [935] << std::endl;
#endif

{
// DQ (4/22/2006): Added timer information for AST File I/O
TimingPerformance nested_timer ("AST_FILE_IO::startUp() Build contiguious storage:");
Expand Down Expand Up @@ -300,135 +287,57 @@ AST_FILE_IO :: areFreepointersContainingGlobalIndices ( )
return freepointersOfCurrentAstAreSetToGlobalIndices;
}

#define DEBUG_AstFileIO_getGlobalIndexFromSgClassPointer 0

unsigned long AST_FILE_IO::getGlobalIndexFromSgClassPointer(SgNode * pointer) {
if (pointer == nullptr) return 0;

/* JH (01/03/2006) manipulatePointerDataMembers: check if the pointer points to a valid SgNode.
First check, if the pointer is a NILL pointer. If so, do nothing. Otherwise:
* if yes, call the appropriate virual function to receive the global index. That is stored
in the pointer again.
* if no, we have somehow a pointer that is not valid. Thus, we look, if the pointer is in any
memory pools. If so, we get its global index an store it, but print a warning. If not, we
break with an assert.
*/
unsigned long
AST_FILE_IO::getGlobalIndexFromSgClassPointer ( SgNode* pointer )
{
// This converts the pointer value held in the p_freepointer into a global index.
unsigned long globalIndex = 0;
if ( pointer != NULL )
{
#if FILE_IO_EXTRA_CHECK
assert ( freepointersOfCurrentAstAreSetToGlobalIndices == true );
#if 0
// Debugging code
printf ("In AST_FILE_IO::getGlobalIndexFromSgClassPointer(): pointer = %p \n",pointer);
printf ("In AST_FILE_IO::getGlobalIndexFromSgClassPointer(): pointer = %p = %s \n",pointer,pointer->class_name().c_str());
printf ("In AST_FILE_IO::getGlobalIndexFromSgClassPointer(): pointer->p_freepointer = %p \n",pointer->p_freepointer);
printf ("In AST_FILE_IO::getGlobalIndexFromSgClassPointer(): AST_FileIO::IS_VALID_POINTER() = %p \n",AST_FileIO::IS_VALID_POINTER());
printf ("In AST_FILE_IO::getGlobalIndexFromSgClassPointer(): pointer = %p = %s \n",pointer,pointer->class_name().c_str());
#endif
assert ( pointer->p_freepointer != AST_FileIO::IS_VALID_POINTER() );
ROSE_ASSERT(freepointersOfCurrentAstAreSetToGlobalIndices);
#if DEBUG_AstFileIO_getGlobalIndexFromSgClassPointer
printf ("In AST_FILE_IO::getGlobalIndexFromSgClassPointer():\n");
printf (" pointer = %p = %s \n", pointer, pointer ? pointer->class_name().c_str() : "");
printf (" pointer->p_freepointer = %p \n", pointer ? pointer->p_freepointer : nullptr);
#endif
//ROSE_ASSERT(pointer->p_freepointer != nullptr);
ROSE_ASSERT(pointer->p_freepointer != AST_FileIO::IS_VALID_POINTER());

#if FILE_IO_EXTRA_CHECK
if (pointer->p_freepointer == NULL)
{
printf ("In AST_FILE_IO::getGlobalIndexFromSgClassPointer(): pointer = %p \n",pointer);
printf ("In AST_FILE_IO::getGlobalIndexFromSgClassPointer(): pointer = %p = %s \n",pointer,pointer->class_name().c_str());
printf ("In AST_FILE_IO::getGlobalIndexFromSgClassPointer(): pointer->p_freepointer = %p \n",pointer->p_freepointer);
printf ("In AST_FILE_IO::getGlobalIndexFromSgClassPointer(): AST_FileIO::IS_VALID_POINTER() = %p \n",AST_FileIO::IS_VALID_POINTER());
printf ("In AST_FILE_IO::getGlobalIndexFromSgClassPointer(): pointer = %p = %s \n",pointer,pointer->class_name().c_str());
}
unsigned long globalIndex = (unsigned long) (pointer->p_freepointer);
#if DEBUG_AstFileIO_getGlobalIndexFromSgClassPointer
printf (" globalIndex = %zd \n", globalIndex);
#endif
// DQ (6/6/2010): This is equivalent to the test for (globalIndex > 0).
assert ( pointer->p_freepointer != NULL );

globalIndex = (unsigned long) (pointer->p_freepointer);
return globalIndex;
}

#if FILE_IO_EXTRA_CHECK
if (globalIndex == 0)
{
printf ("In AST_FILE_IO::getGlobalIndexFromSgClassPointer(): globalIndex = %lu \n",globalIndex);
printf ("In AST_FILE_IO::getGlobalIndexFromSgClassPointer(): pointer = %p \n",pointer);
printf ("In AST_FILE_IO::getGlobalIndexFromSgClassPointer(): pointer = %p = %s \n",pointer,pointer->class_name().c_str());
printf ("In AST_FILE_IO::getGlobalIndexFromSgClassPointer(): pointer->p_freepointer = %p \n",pointer->p_freepointer);
printf ("In AST_FILE_IO::getGlobalIndexFromSgClassPointer(): AST_FileIO::IS_VALID_POINTER() = %p \n",AST_FileIO::IS_VALID_POINTER());
printf ("In AST_FILE_IO::getGlobalIndexFromSgClassPointer(): pointer = %p = %s \n",pointer,pointer->class_name().c_str());
}
#define DEBUG_AstFileIO_getSgClassPointerFromGlobalIndex 0

assert ( 0 < globalIndex );
// DQ (7/10/2010): I think this is not a reasonable test. And large AST's demonstrate this problem.
#if 0
// assert ( AST_FILE_IO::getAccumulatedPoolSizeOfNewAst(pointer->variantT()) <= globalIndex );
if (AST_FILE_IO::getAccumulatedPoolSizeOfNewAst(pointer->variantT()) > globalIndex )
{
printf ("In AST_FILE_IO::getGlobalIndexFromSgClassPointer( SgNode* pointer = %p = %s) \n",pointer,pointer->class_name().c_str());
printf (" pointer->p_freepointer = %p = %" PRIuPTR " \n",pointer->p_freepointer,(unsigned long)pointer->p_freepointer);
printf (" AST_FILE_IO::getAccumulatedPoolSizeOfNewAst(pointer->variantT()) = %" PRIuPTR " \n",AST_FILE_IO::getAccumulatedPoolSizeOfNewAst(pointer->variantT()));
}
// assert ( AST_FILE_IO::getAccumulatedPoolSizeOfNewAst(pointer->variantT()) <= globalIndex );
#endif
SgNode * AST_FILE_IO :: getSgClassPointerFromGlobalIndex ( unsigned long globalIndex ) {
if (globalIndex == 0) return nullptr;

// DQ (7/10/2010): I think this is not a reasonable test. And large AST's demonstrate this problem.
#if 0
// assert ( globalIndex < AST_FILE_IO::getAccumulatedPoolSizeOfNewAst(pointer->variantT()+1) );
if (globalIndex >= AST_FILE_IO::getAccumulatedPoolSizeOfNewAst(pointer->variantT()+1) )
{
printf ("In AST_FILE_IO::getGlobalIndexFromSgClassPointer( SgNode* pointer = %p = %s) \n",pointer,pointer->class_name().c_str());
printf (" pointer->p_freepointer = %p = %" PRIuPTR " \n",pointer->p_freepointer,(unsigned long)pointer->p_freepointer);
printf (" AST_FILE_IO::getAccumulatedPoolSizeOfNewAst(pointer->variantT()+1) = %" PRIuPTR " \n",AST_FILE_IO::getAccumulatedPoolSizeOfNewAst(pointer->variantT()+1));
}
// assert ( globalIndex < AST_FILE_IO::getAccumulatedPoolSizeOfNewAst(pointer->variantT()+1) );
#endif
#if DEBUG_AstFileIO_getGlobalIndexFromSgClassPointer
printf ("In AST_FILE_IO::getSgClassPointerFromGlobalIndex():\n");
printf (" globalIndex = %zd \n", globalIndex);
#endif
}

return globalIndex;
}

ROSE_ASSERT(!freepointersOfCurrentAstAreSetToGlobalIndices);
ROSE_ASSERT( globalIndex < getTotalNumberOfNodesOfAstInMemoryPool() + getTotalNumberOfNodesOfNewAst() );

SgNode* returnPointer = NULL;

$REPLACE_GETSGPOINTER

/* JH (01/03/2006) remanipulatePointerDataMembers: check if the index stored in the pointer is
lesss than 100, then we have one of the operate types or an builtin type. Otherwise,
we get the pointer after computing the type od memory pool, that contains the pointer.
*/
SgNode*
AST_FILE_IO :: getSgClassPointerFromGlobalIndex ( unsigned long globalIndex )
{

// DQ (9/3/2015): This function currently generates a warning from Intel where it is used (called).
// The reason is that the input is a ROSE IR node pointer cast to a unsigned long int, and then
// used as an integer index to the (for example) SgAddOp_getPointerFromGlobalIndex( unsigned long globalIndex )
// function in the code that is generated by ROSETTA below. To avoid the warning it would be a
// better design to have this function (getSgClassPointerFromGlobalIndex(unsigned long)) take
// a SgNode pointer and modify the (for example) SgAddOp_getPointerFromGlobalIndex( unsigned long globalIndex )
// functions to take the same SgNode pointer so that we can avoid the problematic casting (which
// appears to be the cause for the warnings). This should be implemented later as part of a
// seperate commit and push not connected to this current work to support the Intel v14
// compiler.

#if FILE_IO_EXTRA_CHECK
assert ( freepointersOfCurrentAstAreSetToGlobalIndices == false );
// std::cout << globalIndex << " " << getTotalNumberOfNodesOfAstInMemoryPool() << " " << getTotalNumberOfNodesOfNewAst( ) << std::endl;
assert ( globalIndex < getTotalNumberOfNodesOfAstInMemoryPool() + getTotalNumberOfNodesOfNewAst( ));
#if DEBUG_AstFileIO_getSgClassPointerFromGlobalIndex
printf (" returnPointer = %p\n", returnPointer); // might not have been read yet
#endif

SgNode* returnPointer = NULL;

$REPLACE_GETSGPOINTER

return returnPointer;
}
return returnPointer;
}



/* JH (01/03/2006) This mehtods steps through all memory pools and deletes all data contained in
the pools, to prepare the base for starting the memory extension for rebuilding the AST.
*/
void
AST_FILE_IO :: clearAllMemoryPools ( )
{
void AST_FILE_IO::clearAllMemoryPools( ) {
freepointersOfCurrentAstAreSetToGlobalIndices = false;
// JH (08/08/2006) calling delete on the roots of the stored ASTs, in order to have
// empty memory pools afterwards
Expand Down
15 changes: 3 additions & 12 deletions src/ROSETTA/Grammar/grammarDestructorDefinitionMacros.macro
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,8 @@ a traversal which deletes a whole AST is provided by DeleteSgTree(SgNode*).
automatically deleted their members.)

*/
$CLASSNAME::~$CLASSNAME ()
{
#if 0
// debugging information!
printf ("In $CLASSNAME::~$CLASSNAME (destructor) \n");
#endif

#if 1
// DQ (6/25/2006): Commented out destructor body to allow the File I/O to work.
$DESTRUCTOR_BODY
#endif
}
$CLASSNAME::~$CLASSNAME () {
$DESTRUCTOR_BODY
}


Loading

0 comments on commit 14d7eff

Please sign in to comment.