X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=utils%2FTableGen%2FLLVMCConfigurationEmitter.cpp;h=fc9553ed268843cc99154315dd34bf029c150cf4;hb=15511cf1660cfd6bb8b8e8fca2db9450f50430ee;hp=d43e62bad8f7e63f972de024f4a6e066cfd0750e;hpb=35fde150591d7c5f032a5e7c9643315e5f2bedde;p=oota-llvm.git diff --git a/utils/TableGen/LLVMCConfigurationEmitter.cpp b/utils/TableGen/LLVMCConfigurationEmitter.cpp index d43e62bad8f..fc9553ed268 100644 --- a/utils/TableGen/LLVMCConfigurationEmitter.cpp +++ b/utils/TableGen/LLVMCConfigurationEmitter.cpp @@ -198,7 +198,8 @@ struct OptionDescription { // Global option description. namespace GlobalOptionDescriptionFlags { - enum GlobalOptionDescriptionFlags { Required = 0x1 }; + enum GlobalOptionDescriptionFlags { Required = 0x1, Hidden = 0x2, + ReallyHidden = 0x4 }; } struct GlobalOptionDescription : public OptionDescription { @@ -222,17 +223,31 @@ struct GlobalOptionDescription : public OptionDescription { Flags |= GlobalOptionDescriptionFlags::Required; } + bool isHidden() const { + return Flags & GlobalOptionDescriptionFlags::Hidden; + } + void setHidden() { + Flags |= GlobalOptionDescriptionFlags::Hidden; + } + + bool isReallyHidden() const { + return Flags & GlobalOptionDescriptionFlags::ReallyHidden; + } + void setReallyHidden() { + Flags |= GlobalOptionDescriptionFlags::ReallyHidden; + } + /// Merge - Merge two option descriptions. void Merge (const GlobalOptionDescription& other) { if (other.Type != Type) throw "Conflicting definitions for the option " + Name + "!"; - if (Help == DefaultHelpString) + if (Help == other.Help || Help == DefaultHelpString) Help = other.Help; else if (other.Help != DefaultHelpString) { - llvm::cerr << "Warning: more than one help string defined for option " - + Name + "\n"; + llvm::cerr << "Warning: several different help strings" + " defined for option " + Name + "\n"; } Flags |= other.Flags; @@ -412,8 +427,12 @@ public: &CollectOptionProperties::onForwardAs; optionPropertyHandlers_["help"] = &CollectOptionProperties::onHelp; + optionPropertyHandlers_["hidden"] = + &CollectOptionProperties::onHidden; optionPropertyHandlers_["output_suffix"] = &CollectOptionProperties::onOutputSuffix; + optionPropertyHandlers_["really_hidden"] = + &CollectOptionProperties::onReallyHidden; optionPropertyHandlers_["required"] = &CollectOptionProperties::onRequired; optionPropertyHandlers_["stop_compilation"] = @@ -493,6 +512,18 @@ private: optDesc_.Help = help_message; } + void onHidden (const DagInit* d) { + checkNumberOfArguments(d, 0); + checkToolProps(d); + optDesc_.setHidden(); + } + + void onReallyHidden (const DagInit* d) { + checkNumberOfArguments(d, 0); + checkToolProps(d); + optDesc_.setReallyHidden(); + } + void onRequired (const DagInit* d) { checkNumberOfArguments(d, 0); checkToolProps(d); @@ -1413,6 +1444,17 @@ void EmitOptionDescriptions (const GlobalOptionDescriptions& descs, } } + if (val.isReallyHidden() || val.isHidden()) { + if (val.isRequired()) + O << " |"; + else + O << ","; + if (val.isReallyHidden()) + O << " cl::ReallyHidden"; + else + O << " cl::Hidden"; + } + if (!val.Help.empty()) O << ", cl::desc(\"" << val.Help << "\")"; @@ -1497,20 +1539,18 @@ void FillInToolToLang (const ToolPropertiesList& TPList, /// on all edges do match. This doesn't do much when the information /// about the whole graph is not available (i.e. when compiling most /// plugins). -// TODO: add a --check-graph switch to llvmc2. It would also make it -// possible to detect cycles and multiple default edges. -void TypecheckGraph (const Record* CompilationGraph, +void TypecheckGraph (const RecordVector& EdgeVector, const ToolPropertiesList& TPList) { StringMap > ToolToInLang; StringMap ToolToOutLang; FillInToolToLang(TPList, ToolToInLang, ToolToOutLang); - ListInit* edges = CompilationGraph->getValueAsListInit("edges"); StringMap::iterator IAE = ToolToOutLang.end(); StringMap >::iterator IBE = ToolToInLang.end(); - for (unsigned i = 0; i < edges->size(); ++i) { - const Record* Edge = edges->getElementAsRecord(i); + for (RecordVector::const_iterator B = EdgeVector.begin(), + E = EdgeVector.end(); B != E; ++B) { + const Record* Edge = *B; const std::string& A = Edge->getValueAsString("a"); const std::string& B = Edge->getValueAsString("b"); StringMap::iterator IA = ToolToOutLang.find(A); @@ -1571,31 +1611,28 @@ void EmitEdgeClass (unsigned N, const std::string& Target, } /// EmitEdgeClasses - Emit Edge* classes that represent graph edges. -void EmitEdgeClasses (const Record* CompilationGraph, +void EmitEdgeClasses (const RecordVector& EdgeVector, const GlobalOptionDescriptions& OptDescs, std::ostream& O) { - ListInit* edges = CompilationGraph->getValueAsListInit("edges"); - - for (unsigned i = 0; i < edges->size(); ++i) { - const Record* Edge = edges->getElementAsRecord(i); + int i = 0; + for (RecordVector::const_iterator B = EdgeVector.begin(), + E = EdgeVector.end(); B != E; ++B) { + const Record* Edge = *B; const std::string& B = Edge->getValueAsString("b"); DagInit* Weight = Edge->getValueAsDag("weight"); - if (isDagEmpty(Weight)) - continue; - - EmitEdgeClass(i, B, Weight, OptDescs, O); + if (!isDagEmpty(Weight)) + EmitEdgeClass(i, B, Weight, OptDescs, O); + ++i; } } /// EmitPopulateCompilationGraph - Emit the PopulateCompilationGraph() /// function. -void EmitPopulateCompilationGraph (const Record* CompilationGraph, +void EmitPopulateCompilationGraph (const RecordVector& EdgeVector, const ToolPropertiesList& ToolProps, std::ostream& O) { - ListInit* edges = CompilationGraph->getValueAsListInit("edges"); - O << "namespace {\n\n"; O << "void PopulateCompilationGraphLocal(CompilationGraph& G) {\n"; @@ -1607,8 +1644,10 @@ void EmitPopulateCompilationGraph (const Record* CompilationGraph, // Insert edges. - for (unsigned i = 0; i < edges->size(); ++i) { - const Record* Edge = edges->getElementAsRecord(i); + int i = 0; + for (RecordVector::const_iterator B = EdgeVector.begin(), + E = EdgeVector.end(); B != E; ++B) { + const Record* Edge = *B; const std::string& A = Edge->getValueAsString("a"); const std::string& B = Edge->getValueAsString("b"); DagInit* Weight = Edge->getValueAsDag("weight"); @@ -1621,6 +1660,7 @@ void EmitPopulateCompilationGraph (const Record* CompilationGraph, O << "new Edge" << i << "()"; O << ");\n"; + ++i; } O << "}\n\n}\n\n"; @@ -1754,15 +1794,16 @@ public: /// FilterNotInGraph - Filter out from ToolProps all Tools not /// mentioned in the compilation graph definition. -void FilterNotInGraph (const Record* CompilationGraph, +void FilterNotInGraph (const RecordVector& EdgeVector, ToolPropertiesList& ToolProps) { // List all tools mentioned in the graph. llvm::StringSet<> ToolsInGraph; - ListInit* edges = CompilationGraph->getValueAsListInit("edges"); - for (unsigned i = 0; i < edges->size(); ++i) { - const Record* Edge = edges->getElementAsRecord(i); + for (RecordVector::const_iterator B = EdgeVector.begin(), + E = EdgeVector.end(); B != E; ++B) { + + const Record* Edge = *B; const std::string& A = Edge->getValueAsString("a"); const std::string& B = Edge->getValueAsString("b"); @@ -1778,6 +1819,7 @@ void FilterNotInGraph (const Record* CompilationGraph, ToolProps.erase(new_end, ToolProps.end()); } +/// CalculatePriority - Calculate the priority of this plugin. int CalculatePriority(RecordVector::const_iterator B, RecordVector::const_iterator E) { int total = 0; @@ -1787,6 +1829,18 @@ int CalculatePriority(RecordVector::const_iterator B, return total; } +/// FillInEdgeVector - Merge all compilation graph definitions into +/// one single edge list. +void FillInEdgeVector(RecordVector::const_iterator B, + RecordVector::const_iterator E, RecordVector& Out) { + for (; B != E; ++B) { + const ListInit* edges = (*B)->getValueAsListInit("edges"); + + for (unsigned i = 0; i < edges->size(); ++i) + Out.push_back(edges->getElementAsRecord(i)); + } +} + // End of anonymous namespace } @@ -1798,33 +1852,30 @@ void LLVMCConfigurationEmitter::run (std::ostream &O) { EmitSourceFileHeader("LLVMC Configuration Library", O); EmitIncludes(O); - // Get a list of all defined Tools. - + // Collect tool properties. RecordVector Tools = Records.getAllDerivedDefinitions("Tool"); - if (Tools.empty()) - throw std::string("No tool definitions found!"); - - // Gather information from the Tool description dags. ToolPropertiesList ToolProps; GlobalOptionDescriptions OptDescs; CollectToolProperties(Tools.begin(), Tools.end(), ToolProps, OptDescs); + // Collect option properties. const RecordVector& OptionLists = Records.getAllDerivedDefinitions("OptionList"); CollectPropertiesFromOptionLists(OptionLists.begin(), OptionLists.end(), OptDescs); - // TOTHINK: Nothing actually prevents us from having multiple - // compilation graphs in a single plugin; OTOH, I do not see how - // that could be useful. - const Record* CompilationGraphRecord = Records.getDef("CompilationGraph"); - if (!CompilationGraphRecord) - throw std::string("Compilation graph description not found!"); + // Collect compilation graph edges. + const RecordVector& CompilationGraphs = + Records.getAllDerivedDefinitions("CompilationGraph"); + RecordVector EdgeVector; + FillInEdgeVector(CompilationGraphs.begin(), CompilationGraphs.end(), + EdgeVector); - FilterNotInGraph(CompilationGraphRecord, ToolProps); + // Filter out all tools not mentioned in the compilation graph. + FilterNotInGraph(EdgeVector, ToolProps); // Typecheck the compilation graph. - TypecheckGraph(CompilationGraphRecord, ToolProps); + TypecheckGraph(EdgeVector, ToolProps); // Check that there are no options without side effects (specified // only in the OptionList). @@ -1846,16 +1897,16 @@ void LLVMCConfigurationEmitter::run (std::ostream &O) { EmitToolClassDefinition(*(*B), OptDescs, O); // Emit Edge# classes. - EmitEdgeClasses(CompilationGraphRecord, OptDescs, O); + EmitEdgeClasses(EdgeVector, OptDescs, O); // Emit PopulateCompilationGraph() function. - EmitPopulateCompilationGraph(CompilationGraphRecord, ToolProps, O); + EmitPopulateCompilationGraph(EdgeVector, ToolProps, O); // Emit code for plugin registration. const RecordVector& Priorities = Records.getAllDerivedDefinitions("PluginPriority"); - EmitRegisterPlugin(CalculatePriority(Priorities.begin(), Priorities.end()), - O); + EmitRegisterPlugin(CalculatePriority(Priorities.begin(), + Priorities.end()), O); // EOF } catch (std::exception& Error) {