Mikhail Glushenkov | 6d80d2b | 2009-10-08 04:40:28 +0000 | [diff] [blame] | 1 | //===- Base.td - LLVMC toolchain descriptions --------------*- tablegen -*-===// |
Anton Korobeynikov | ac67b7e | 2008-03-23 08:57:20 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Mikhail Glushenkov | 6d80d2b | 2009-10-08 04:40:28 +0000 | [diff] [blame] | 10 | // This file contains compilation graph description used by llvmc. |
Anton Korobeynikov | ac67b7e | 2008-03-23 08:57:20 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Mikhail Glushenkov | e4a5ea3 | 2008-10-02 21:15:05 +0000 | [diff] [blame] | 14 | include "llvm/CompilerDriver/Common.td" |
Anton Korobeynikov | ac67b7e | 2008-03-23 08:57:20 +0000 | [diff] [blame] | 15 | |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 16 | // Options |
| 17 | |
| 18 | def OptList : OptionList<[ |
| 19 | (switch_option "emit-llvm", |
| 20 | (help "Emit LLVM .ll files instead of native object files")), |
| 21 | (switch_option "E", |
| 22 | (help "Stop after the preprocessing stage, do not run the compiler")), |
| 23 | (switch_option "fsyntax-only", |
| 24 | (help "Stop after checking the input for syntax errors")), |
| 25 | (switch_option "opt", |
| 26 | (help "Enable opt")), |
| 27 | (switch_option "S", |
| 28 | (help "Stop after compilation, do not assemble")), |
| 29 | (switch_option "c", |
| 30 | (help "Compile and assemble, but do not link")), |
| 31 | (switch_option "pthread", |
| 32 | (help "Enable threads")), |
| 33 | (parameter_option "linker", |
| 34 | (help "Choose linker (possible values: gcc, g++)")), |
Mikhail Glushenkov | 6d80d2b | 2009-10-08 04:40:28 +0000 | [diff] [blame] | 35 | (parameter_option "MF", |
| 36 | (help "Specify a file to write dependencies to"), (hidden)), |
| 37 | (parameter_option "MT", |
| 38 | (help "Change the name of the rule emitted by dependency generation"), |
| 39 | (hidden)), |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 40 | (parameter_list_option "include", |
| 41 | (help "Include the named file prior to preprocessing")), |
| 42 | (prefix_list_option "I", |
| 43 | (help "Add a directory to include path")), |
Mikhail Glushenkov | 6d80d2b | 2009-10-08 04:40:28 +0000 | [diff] [blame] | 44 | (prefix_list_option "D", |
| 45 | (help "Define a macro")), |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 46 | (prefix_list_option "Wa,", |
| 47 | (help "Pass options to assembler")), |
Mikhail Glushenkov | 4680102 | 2009-03-31 18:33:54 +0000 | [diff] [blame] | 48 | (prefix_list_option "Wllc,", |
| 49 | (help "Pass options to llc")), |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 50 | (prefix_list_option "L", |
| 51 | (help "Add a directory to link path")), |
| 52 | (prefix_list_option "l", |
| 53 | (help "Search a library when linking")), |
| 54 | (prefix_list_option "Wl,", |
Mikhail Glushenkov | ba71d67 | 2008-12-11 22:19:14 +0000 | [diff] [blame] | 55 | (help "Pass options to linker")), |
| 56 | (prefix_list_option "Wo,", |
| 57 | (help "Pass options to opt")) |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 58 | ]>; |
| 59 | |
| 60 | // Tools |
| 61 | |
| 62 | class llvm_gcc_based <string cmd_prefix, string in_lang, string E_ext> : Tool< |
| 63 | [(in_language in_lang), |
| 64 | (out_language "llvm-bitcode"), |
| 65 | (output_suffix "bc"), |
| 66 | (cmd_line (case |
| 67 | (switch_on "E"), |
| 68 | (case (not_empty "o"), |
| 69 | !strconcat(cmd_prefix, " -E $INFILE -o $OUTFILE"), |
| 70 | (default), |
| 71 | !strconcat(cmd_prefix, " -E $INFILE")), |
| 72 | (switch_on "fsyntax-only"), |
| 73 | !strconcat(cmd_prefix, " -fsyntax-only $INFILE"), |
| 74 | (and (switch_on "S"), (switch_on "emit-llvm")), |
| 75 | !strconcat(cmd_prefix, " -S $INFILE -o $OUTFILE -emit-llvm"), |
| 76 | (default), |
| 77 | !strconcat(cmd_prefix, " -c $INFILE -o $OUTFILE -emit-llvm"))), |
| 78 | (actions |
| 79 | (case |
Mikhail Glushenkov | ad981bf | 2009-09-28 01:16:42 +0000 | [diff] [blame] | 80 | (and (multiple_input_files), (or (switch_on "S"), (switch_on "c"))), |
| 81 | (error "cannot specify -o with -c or -S with multiple files"), |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 82 | (switch_on "E"), [(stop_compilation), (output_suffix E_ext)], |
| 83 | (and (switch_on "emit-llvm"), (switch_on "S")), |
| 84 | [(output_suffix "ll"), (stop_compilation)], |
| 85 | (and (switch_on "emit-llvm"), (switch_on "c")), (stop_compilation), |
| 86 | (switch_on "fsyntax-only"), (stop_compilation), |
| 87 | (not_empty "include"), (forward "include"), |
Mikhail Glushenkov | 976248d | 2009-10-08 06:03:38 +0000 | [diff] [blame] | 88 | (not_empty "I"), (forward "I"), |
| 89 | (not_empty "D"), (forward "D"), |
| 90 | (not_empty "MF"), (forward "MF"), |
Mikhail Glushenkov | 6d80d2b | 2009-10-08 04:40:28 +0000 | [diff] [blame] | 91 | (not_empty "MT"), (forward "MT"))), |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 92 | (sink) |
| 93 | ]>; |
| 94 | |
Mikhail Glushenkov | 4558f48 | 2009-04-21 19:46:10 +0000 | [diff] [blame] | 95 | def llvm_gcc_c : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x c", "c", "i">; |
| 96 | def llvm_gcc_cpp : llvm_gcc_based<"@LLVMGXXCOMMAND@ -x c++", "c++", "i">; |
Mikhail Glushenkov | 6d80d2b | 2009-10-08 04:40:28 +0000 | [diff] [blame] | 97 | def llvm_gcc_m : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c", |
| 98 | "objective-c", "mi">; |
Mikhail Glushenkov | 4558f48 | 2009-04-21 19:46:10 +0000 | [diff] [blame] | 99 | def llvm_gcc_mxx : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c++", |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 100 | "objective-c++", "mi">; |
| 101 | |
| 102 | def opt : Tool< |
| 103 | [(in_language "llvm-bitcode"), |
| 104 | (out_language "llvm-bitcode"), |
| 105 | (output_suffix "bc"), |
Mikhail Glushenkov | ba71d67 | 2008-12-11 22:19:14 +0000 | [diff] [blame] | 106 | (actions (case (not_empty "Wo,"), (unpack_values "Wo,"))), |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 107 | (cmd_line "opt -f $INFILE -o $OUTFILE") |
| 108 | ]>; |
| 109 | |
| 110 | def llvm_as : Tool< |
| 111 | [(in_language "llvm-assembler"), |
| 112 | (out_language "llvm-bitcode"), |
| 113 | (output_suffix "bc"), |
Mikhail Glushenkov | 3ab6889 | 2009-10-09 05:45:01 +0000 | [diff] [blame^] | 114 | (cmd_line "llvm-as $INFILE -o $OUTFILE"), |
| 115 | (actions (case (switch_on "emit-llvm"), (stop_compilation))) |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 116 | ]>; |
| 117 | |
| 118 | def llvm_gcc_assembler : Tool< |
| 119 | [(in_language "assembler"), |
| 120 | (out_language "object-code"), |
| 121 | (output_suffix "o"), |
Mikhail Glushenkov | 4558f48 | 2009-04-21 19:46:10 +0000 | [diff] [blame] | 122 | (cmd_line "@LLVMGCCCOMMAND@ -c -x assembler $INFILE -o $OUTFILE"), |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 123 | (actions (case |
| 124 | (switch_on "c"), (stop_compilation), |
| 125 | (not_empty "Wa,"), (unpack_values "Wa,"))) |
| 126 | ]>; |
| 127 | |
| 128 | def llc : Tool< |
Mikhail Glushenkov | 3ab6889 | 2009-10-09 05:45:01 +0000 | [diff] [blame^] | 129 | [(in_language ["llvm-bitcode", "llvm-assembler"]), |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 130 | (out_language "assembler"), |
| 131 | (output_suffix "s"), |
Mikhail Glushenkov | 4680102 | 2009-03-31 18:33:54 +0000 | [diff] [blame] | 132 | (cmd_line "llc -f $INFILE -o $OUTFILE"), |
| 133 | (actions (case |
| 134 | (switch_on "S"), (stop_compilation), |
| 135 | (not_empty "Wllc,"), (unpack_values "Wllc,"))) |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 136 | ]>; |
| 137 | |
| 138 | // Base class for linkers |
| 139 | class llvm_gcc_based_linker <string cmd_prefix> : Tool< |
| 140 | [(in_language "object-code"), |
| 141 | (out_language "executable"), |
| 142 | (output_suffix "out"), |
| 143 | (cmd_line !strconcat(cmd_prefix, " $INFILE -o $OUTFILE")), |
| 144 | (join), |
| 145 | (actions (case |
| 146 | (switch_on "pthread"), (append_cmd "-lpthread"), |
| 147 | (not_empty "L"), (forward "L"), |
| 148 | (not_empty "l"), (forward "l"), |
Mikhail Glushenkov | 6d80d2b | 2009-10-08 04:40:28 +0000 | [diff] [blame] | 149 | (not_empty "Wl,"), (forward "Wl,"))) |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 150 | ]>; |
| 151 | |
| 152 | // Default linker |
Mikhail Glushenkov | 4558f48 | 2009-04-21 19:46:10 +0000 | [diff] [blame] | 153 | def llvm_gcc_linker : llvm_gcc_based_linker<"@LLVMGCCCOMMAND@">; |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 154 | // Alternative linker for C++ |
Mikhail Glushenkov | 4558f48 | 2009-04-21 19:46:10 +0000 | [diff] [blame] | 155 | def llvm_gcc_cpp_linker : llvm_gcc_based_linker<"@LLVMGXXCOMMAND@">; |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 156 | |
| 157 | // Language map |
| 158 | |
| 159 | def LanguageMap : LanguageMap< |
| 160 | [LangToSuffixes<"c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]>, |
| 161 | LangToSuffixes<"c", ["c"]>, |
| 162 | LangToSuffixes<"c-cpp-output", ["i"]>, |
| 163 | LangToSuffixes<"objective-c-cpp-output", ["mi"]>, |
| 164 | LangToSuffixes<"objective-c++", ["mm"]>, |
| 165 | LangToSuffixes<"objective-c", ["m"]>, |
| 166 | LangToSuffixes<"assembler", ["s"]>, |
| 167 | LangToSuffixes<"assembler-with-cpp", ["S"]>, |
| 168 | LangToSuffixes<"llvm-assembler", ["ll"]>, |
| 169 | LangToSuffixes<"llvm-bitcode", ["bc"]>, |
| 170 | LangToSuffixes<"object-code", ["o"]>, |
| 171 | LangToSuffixes<"executable", ["out"]> |
| 172 | ]>; |
| 173 | |
| 174 | // Compilation graph |
Anton Korobeynikov | ac67b7e | 2008-03-23 08:57:20 +0000 | [diff] [blame] | 175 | |
Mikhail Glushenkov | 0d08db0 | 2008-05-06 16:35:25 +0000 | [diff] [blame] | 176 | def CompilationGraph : CompilationGraph<[ |
Mikhail Glushenkov | 0108877 | 2008-11-17 17:29:18 +0000 | [diff] [blame] | 177 | Edge<"root", "llvm_gcc_c">, |
| 178 | Edge<"root", "llvm_gcc_assembler">, |
| 179 | Edge<"root", "llvm_gcc_cpp">, |
| 180 | Edge<"root", "llvm_gcc_m">, |
| 181 | Edge<"root", "llvm_gcc_mxx">, |
Mikhail Glushenkov | 57a7e94 | 2009-09-10 17:04:32 +0000 | [diff] [blame] | 182 | Edge<"root", "llc">, |
Mikhail Glushenkov | d752c3f | 2008-05-06 16:36:50 +0000 | [diff] [blame] | 183 | |
Mikhail Glushenkov | 0108877 | 2008-11-17 17:29:18 +0000 | [diff] [blame] | 184 | Edge<"llvm_gcc_c", "llc">, |
| 185 | Edge<"llvm_gcc_cpp", "llc">, |
| 186 | Edge<"llvm_gcc_m", "llc">, |
| 187 | Edge<"llvm_gcc_mxx", "llc">, |
| 188 | Edge<"llvm_as", "llc">, |
Mikhail Glushenkov | d752c3f | 2008-05-06 16:36:50 +0000 | [diff] [blame] | 189 | |
Mikhail Glushenkov | 3ab6889 | 2009-10-09 05:45:01 +0000 | [diff] [blame^] | 190 | OptionalEdge<"root", "llvm_as", |
| 191 | (case (switch_on "emit-llvm"), (inc_weight))>, |
Mikhail Glushenkov | 0108877 | 2008-11-17 17:29:18 +0000 | [diff] [blame] | 192 | OptionalEdge<"llvm_gcc_c", "opt", (case (switch_on "opt"), (inc_weight))>, |
| 193 | OptionalEdge<"llvm_gcc_cpp", "opt", (case (switch_on "opt"), (inc_weight))>, |
| 194 | OptionalEdge<"llvm_gcc_m", "opt", (case (switch_on "opt"), (inc_weight))>, |
| 195 | OptionalEdge<"llvm_gcc_mxx", "opt", (case (switch_on "opt"), (inc_weight))>, |
| 196 | OptionalEdge<"llvm_as", "opt", (case (switch_on "opt"), (inc_weight))>, |
| 197 | Edge<"opt", "llc">, |
Mikhail Glushenkov | d752c3f | 2008-05-06 16:36:50 +0000 | [diff] [blame] | 198 | |
Mikhail Glushenkov | 0108877 | 2008-11-17 17:29:18 +0000 | [diff] [blame] | 199 | Edge<"llc", "llvm_gcc_assembler">, |
| 200 | Edge<"llvm_gcc_assembler", "llvm_gcc_linker">, |
| 201 | OptionalEdge<"llvm_gcc_assembler", "llvm_gcc_cpp_linker", |
Mikhail Glushenkov | e5557f4 | 2008-05-30 06:08:50 +0000 | [diff] [blame] | 202 | (case |
Daniel Dunbar | 77e0c85 | 2008-11-08 03:25:47 +0000 | [diff] [blame] | 203 | (or (input_languages_contain "c++"), |
Mikhail Glushenkov | 0108877 | 2008-11-17 17:29:18 +0000 | [diff] [blame] | 204 | (input_languages_contain "objective-c++")), |
Daniel Dunbar | 77e0c85 | 2008-11-08 03:25:47 +0000 | [diff] [blame] | 205 | (inc_weight), |
Mikhail Glushenkov | e5557f4 | 2008-05-30 06:08:50 +0000 | [diff] [blame] | 206 | (or (parameter_equals "linker", "g++"), |
| 207 | (parameter_equals "linker", "c++")), (inc_weight))>, |
Mikhail Glushenkov | 35a85e8 | 2008-05-06 18:10:20 +0000 | [diff] [blame] | 208 | |
Mikhail Glushenkov | 978d498 | 2008-05-06 18:13:00 +0000 | [diff] [blame] | 209 | |
Mikhail Glushenkov | 0108877 | 2008-11-17 17:29:18 +0000 | [diff] [blame] | 210 | Edge<"root", "llvm_gcc_linker">, |
| 211 | OptionalEdge<"root", "llvm_gcc_cpp_linker", |
Mikhail Glushenkov | e5557f4 | 2008-05-30 06:08:50 +0000 | [diff] [blame] | 212 | (case |
Daniel Dunbar | 77e0c85 | 2008-11-08 03:25:47 +0000 | [diff] [blame] | 213 | (or (input_languages_contain "c++"), |
Mikhail Glushenkov | 0108877 | 2008-11-17 17:29:18 +0000 | [diff] [blame] | 214 | (input_languages_contain "objective-c++")), |
Daniel Dunbar | 77e0c85 | 2008-11-08 03:25:47 +0000 | [diff] [blame] | 215 | (inc_weight), |
Mikhail Glushenkov | e5557f4 | 2008-05-30 06:08:50 +0000 | [diff] [blame] | 216 | (or (parameter_equals "linker", "g++"), |
| 217 | (parameter_equals "linker", "c++")), (inc_weight))> |
Anton Korobeynikov | ac67b7e | 2008-03-23 08:57:20 +0000 | [diff] [blame] | 218 | ]>; |