work around an optimizer performance bug in clang.
It seems like some optimization passes of CLang which are enabled by -O2 (at least in my version, 3.3) do not like nested scopes and long functions too much. Thus, slightly change the generated source. Timing on my (quite beefy) machine: without patch: make rm -rf generated-source; time make time make [...] real 10m31.110s user 10m16.264s sys 0m13.672s with patch: make rm -rf generated-source; time make time make [...] real 0m47.011s user 0m44.670s sys 0m1.968s the memory used by the compiler goes from 28.8GB to about 330 MB. (I suppose not everybody has 32 Gigs of memory yet. ;)
This commit is contained in:
@@ -611,25 +611,21 @@ namespace Opm {
|
||||
os << indent << lhs << "->setMatchRegex(\"" << m_matchRegexString << "\");" << std::endl;
|
||||
|
||||
for (size_t i = 0; i < m_record->size(); i++) {
|
||||
os << indent << "{" << std::endl;
|
||||
const std::string local_indent = indent + " ";
|
||||
ParserItemConstPtr item = m_record->get(i);
|
||||
os << local_indent << "ParserItemPtr "<<item->name()<<"item(";
|
||||
item->inlineNew(os);
|
||||
os << ");" << std::endl;
|
||||
os << local_indent << item->name()<<"item->setDescription(\"" << item->getDescription() << "\");" << std::endl;
|
||||
for (size_t idim=0; idim < item->numDimensions(); idim++)
|
||||
os << local_indent <<item->name()<<"item->push_backDimension(\"" << item->getDimension( idim ) << "\");" << std::endl;
|
||||
{
|
||||
const std::string local_indent = indent + " ";
|
||||
ParserItemConstPtr item = m_record->get(i);
|
||||
os << local_indent << "ParserItemPtr item(";
|
||||
item->inlineNew(os);
|
||||
os << ");" << std::endl;
|
||||
os << local_indent << "item->setDescription(\"" << item->getDescription() << "\");" << std::endl;
|
||||
for (size_t idim=0; idim < item->numDimensions(); idim++)
|
||||
os << local_indent << "item->push_backDimension(\"" << item->getDimension( idim ) << "\");" << std::endl;
|
||||
{
|
||||
std::string addItemMethod = "addItem";
|
||||
if (m_isDataKeyword)
|
||||
addItemMethod = "addDataItem";
|
||||
std::string addItemMethod = "addItem";
|
||||
if (m_isDataKeyword)
|
||||
addItemMethod = "addDataItem";
|
||||
|
||||
os << local_indent << lhs << "->" << addItemMethod << "(item);" << std::endl;
|
||||
}
|
||||
os << local_indent << lhs << "->" << addItemMethod << "("<<item->name()<<"item);" << std::endl;
|
||||
}
|
||||
os << indent << "}" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -163,7 +163,7 @@ static void generateSourceForKeyword(std::iostream& of, KeywordElementType keywo
|
||||
of << "{" << std::endl;
|
||||
of << indent << "ParserKeywordPtr ";
|
||||
parserKeyword->inlineNew(of , keywordName , indent);
|
||||
of << indent << "addParserKeyword( " << keywordName << ");" << std::endl;
|
||||
of << indent << "parser->addParserKeyword( " << keywordName << ");" << std::endl;
|
||||
of << "}" << std::endl << std::endl;
|
||||
|
||||
std::cout << "Creating keyword: " << keywordName << std::endl;
|
||||
@@ -171,15 +171,26 @@ static void generateSourceForKeyword(std::iostream& of, KeywordElementType keywo
|
||||
|
||||
static void generateKeywordSource(const char * source_file_name , KeywordMapType& keywordMap) {
|
||||
std::fstream source_file_stream( source_file_name, std::fstream::out );
|
||||
|
||||
createHeader(source_file_stream);
|
||||
startFunction(source_file_stream);
|
||||
for (auto iter=keywordMap.begin(); iter != keywordMap.end(); ++iter)
|
||||
generateSourceForKeyword(source_file_stream , *iter);
|
||||
|
||||
createHeader(source_file_stream);
|
||||
|
||||
for (auto iter=keywordMap.begin(); iter != keywordMap.end(); ++iter) {
|
||||
// the stupid default compiler flags will cause a warning if a function is
|
||||
// defined without declaring a prototype before. So let's give the compiler a
|
||||
// cookie to make it happy...
|
||||
source_file_stream << "void add" << iter->second.first << "Keyword(Opm::Parser *parser);\n";
|
||||
|
||||
source_file_stream << "void add" << iter->second.first << "Keyword(Opm::Parser *parser)\n";
|
||||
generateSourceForKeyword(source_file_stream , *iter);
|
||||
}
|
||||
|
||||
startFunction(source_file_stream);
|
||||
for (auto iter=keywordMap.begin(); iter != keywordMap.end(); ++iter)
|
||||
source_file_stream << " add" << iter->second.first << "Keyword(this);\n";
|
||||
endFunction(source_file_stream);
|
||||
source_file_stream << "}" << std::endl;
|
||||
|
||||
|
||||
source_file_stream << "} // end namespace Opm\n";
|
||||
|
||||
source_file_stream.close( );
|
||||
}
|
||||
|
||||
@@ -283,7 +294,6 @@ int main(int /* argc */, char ** argv) {
|
||||
needToGenerate = true;
|
||||
}
|
||||
|
||||
|
||||
if (needToGenerate) {
|
||||
std::cout << "Generating keywords:" << std::endl;
|
||||
generateKeywordSource(source_file_name, keywordMap );
|
||||
|
||||
Reference in New Issue
Block a user