llvm.org GIT mirror llvm / 64683ed
Add new edge properties: parameter_equals, element_in_list, and. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50730 91177308-0d34-0410-b5e6-96231b3b80d8 Mikhail Glushenkov 11 years ago
4 changed file(s) with 82 addition(s) and 30 deletion(s). Raw diff Collapse all Expand all
4949 def switch_on;
5050 def parameter_equals;
5151 def element_in_list;
52 def or;
52 def and;
5353
5454 // Map from suffixes to language names
5555
2525 Edge,
2626 Edge,
2727
28 OptionalEdge,
29 OptionalEdge,
30 OptionalEdge,
31 OptionalEdge<opt, llc, [(switch_on "opt")]>,
28 OptionalEdge<llvm_gcc_c, opt, [(switch_on "S")]>,
29 OptionalEdge,
30 OptionalEdge,
31 OptionalEdge
32 (element_in_list "P", "E")]>,
3233
3334 Edge,
3435 Edge
3737 def opt : Tool<
3838 [(in_language "llvm-bitcode"),
3939 (out_language "llvm-bitcode"),
40 (switch_option "opt", (help "Enable opt")),
40 (switch_option "S", (help "Test switch")),
41 (parameter_option "O", (help "Test Parameter")),
42 (prefix_list_option "P", (help "Test Parameter List")),
4143 (output_suffix "bc"),
4244 (cmd_line "opt $INFILE -o $OUTFILE")
4345 ]>;
904904 }
905905 }
906906
907 // Helper function used by EmitEdgePropertyTest.
908 void EmitEdgePropertyTest1Arg(const DagInit& Prop,
909 const GlobalOptionDescriptions& OptDescs,
910 std::ostream& O) {
911 checkNumberOfArguments(&Prop, 1);
912 const std::string& OptName = InitPtrToString(Prop.getArg(0));
913 const GlobalOptionDescription& OptDesc = OptDescs.FindOption(OptName);
914 if (OptDesc.Type != OptionType::Switch)
915 throw OptName + ": incorrect option type!";
916 O << OptDesc.GenVariableName();
917 }
918
919 // Helper function used by EmitEdgePropertyTest.
920 void EmitEdgePropertyTest2Args(const std::string& PropName,
921 const DagInit& Prop,
922 const GlobalOptionDescriptions& OptDescs,
923 std::ostream& O) {
924 checkNumberOfArguments(&Prop, 2);
925 const std::string& OptName = InitPtrToString(Prop.getArg(0));
926 const std::string& OptArg = InitPtrToString(Prop.getArg(1));
927 const GlobalOptionDescription& OptDesc = OptDescs.FindOption(OptName);
928
929 if (PropName == "parameter_equals") {
930 if (OptDesc.Type != OptionType::Parameter
931 && OptDesc.Type != OptionType::Prefix)
932 throw OptName + ": incorrect option type!";
933 O << OptDesc.GenVariableName() << " == \"" << OptArg << "\"";
934 }
935 else if (PropName == "element_in_list") {
936 if (OptDesc.Type != OptionType::ParameterList
937 && OptDesc.Type != OptionType::PrefixList)
938 throw OptName + ": incorrect option type!";
939 const std::string& VarName = OptDesc.GenVariableName();
940 O << "std::find(" << VarName << ".begin(),\n"
941 << Indent3 << VarName << ".end(), \""
942 << OptArg << "\") != " << VarName << ".end()";
943 }
944 else
945 throw PropName + ": unknown edge property!";
946 }
947
948 // Helper function used by EmitEdgeClasses.
949 void EmitEdgePropertyTest(const std::string& PropName,
950 const DagInit& Prop,
951 const GlobalOptionDescriptions& OptDescs,
952 std::ostream& O) {
953 if (PropName == "switch_on")
954 EmitEdgePropertyTest1Arg(Prop, OptDescs, O);
955 else
956 EmitEdgePropertyTest2Args(PropName, Prop, OptDescs, O);
957 }
958
907959 // Emit Edge* classes that represent edges in the graph.
908960 void EmitEdgeClasses (Record* CompilationGraph,
909961 const GlobalOptionDescriptions& OptDescs,
922974 << "public:\n"
923975 << Indent1 << "Edge" << i << "() : Edge(\"" << B->getName()
924976 << "\") {}\n\n"
925 << Indent1 << "bool isEnabled() const {\n";
977 << Indent1 << "bool isEnabled() const {\n"
978 << Indent2 << "bool ret = false;\n";
926979
927980 for (unsigned i = 0; i < Props->size(); ++i) {
928981 const DagInit& Prop = dynamic_cast(*Props->getElement(i));
929982 const std::string& PropName = Prop.getOperator()->getAsString();
930983
931 if (PropName == "switch_on") {
932 checkNumberOfArguments(&Prop, 1);
933 const std::string& OptName = InitPtrToString(Prop.getArg(0));
934 const GlobalOptionDescription& OptDesc = OptDescs.FindOption(OptName);
935 if (OptDesc.Type != OptionType::Switch)
936 throw OptName + ": incorrect option type!";
937 O << Indent2 << "if (" << OptDesc.GenVariableName() << ")\n"
938 << Indent3 << "return true;\n";
939 }
940 else if (PropName == "parameter_equals") {
941 checkNumberOfArguments(&Prop, 2);
942 throw PropName + ": not implemented!";
943 }
944 else if (PropName == "element_in_list") {
945 checkNumberOfArguments(&Prop, 2);
946 throw PropName + ": not implemented!";
947 }
948 else if (PropName == "or") {
949 throw PropName + ": not implemented!";
984 O << Indent2 << "if (ret || (";
985 if (PropName == "and") {
986 const unsigned NumArgs = Prop.getNumArgs();
987 O << '(';
988 for (unsigned j = 0; j < NumArgs; ++j) {
989 const DagInit& InnerProp = dynamic_cast(*Prop.getArg(j));
990 const std::string& InnerPropName =
991 InnerProp.getOperator()->getAsString();
992 EmitEdgePropertyTest(InnerPropName, InnerProp, OptDescs, O);
993 if (j != NumArgs - 1)
994 O << ")\n" << Indent3 << " && (";
995 else
996 O << ')';
997 }
950998 }
951999 else {
952 throw "No such edge property: " + PropName;
1000 EmitEdgePropertyTest(PropName, Prop, OptDescs, O);
9531001 }
954 }
955
956 O << Indent2 << "return false;\n"
1002 O << "))\n" << Indent3 << "ret = true;\n";
1003 }
1004
1005 O << Indent2 << "return ret;\n"
9571006 << Indent1 << "};\n\n"
9581007 << Indent1 << "bool isDefault() const { return false; }\n"
9591008 << "};\n\n";