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 | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 14 | // Options |
| 15 | |
| 16 | def OptList : OptionList<[ |
| 17 | (switch_option "emit-llvm", |
| 18 | (help "Emit LLVM .ll files instead of native object files")), |
| 19 | (switch_option "E", |
| 20 | (help "Stop after the preprocessing stage, do not run the compiler")), |
| 21 | (switch_option "fsyntax-only", |
| 22 | (help "Stop after checking the input for syntax errors")), |
| 23 | (switch_option "opt", |
| 24 | (help "Enable opt")), |
Mikhail Glushenkov | 6b4967e | 2009-10-17 20:07:49 +0000 | [diff] [blame] | 25 | (switch_option "O0", |
Mikhail Glushenkov | b5c4239 | 2010-03-05 04:46:39 +0000 | [diff] [blame] | 26 | (help "Turn off optimization"), (zero_or_more)), |
Mikhail Glushenkov | 6b4967e | 2009-10-17 20:07:49 +0000 | [diff] [blame] | 27 | (switch_option "O1", |
Mikhail Glushenkov | b5c4239 | 2010-03-05 04:46:39 +0000 | [diff] [blame] | 28 | (help "Optimization level 1"), (zero_or_more)), |
Mikhail Glushenkov | 6b4967e | 2009-10-17 20:07:49 +0000 | [diff] [blame] | 29 | (switch_option "O2", |
Mikhail Glushenkov | b5c4239 | 2010-03-05 04:46:39 +0000 | [diff] [blame] | 30 | (help "Optimization level 2"), (zero_or_more)), |
Mikhail Glushenkov | 6b4967e | 2009-10-17 20:07:49 +0000 | [diff] [blame] | 31 | (switch_option "O3", |
Mikhail Glushenkov | b5c4239 | 2010-03-05 04:46:39 +0000 | [diff] [blame] | 32 | (help "Optimization level 3"), (zero_or_more)), |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 33 | (switch_option "S", |
| 34 | (help "Stop after compilation, do not assemble")), |
| 35 | (switch_option "c", |
| 36 | (help "Compile and assemble, but do not link")), |
Mikhail Glushenkov | fa8182e | 2009-12-04 06:38:45 +0000 | [diff] [blame] | 37 | (switch_option "m32", |
| 38 | (help "Generate code for a 32-bit environment"), (hidden)), |
| 39 | (switch_option "m64", |
| 40 | (help "Generate code for a 64-bit environment"), (hidden)), |
Mikhail Glushenkov | 55cd767 | 2009-12-01 09:47:11 +0000 | [diff] [blame] | 41 | (switch_option "fPIC", |
| 42 | (help "Relocation model: PIC"), (hidden)), |
| 43 | (switch_option "mdynamic-no-pic", |
| 44 | (help "Relocation model: dynamic-no-pic"), (hidden)), |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 45 | (parameter_option "linker", |
| 46 | (help "Choose linker (possible values: gcc, g++)")), |
Mikhail Glushenkov | 3ab4883 | 2009-12-04 06:38:28 +0000 | [diff] [blame] | 47 | (parameter_option "mtune", |
Mikhail Glushenkov | 0289413 | 2010-11-22 17:10:09 +0000 | [diff] [blame] | 48 | (help "Target a specific CPU type"), (forward_not_split)), |
Mikhail Glushenkov | 325f69d | 2010-11-28 00:31:13 +0000 | [diff] [blame] | 49 | (parameter_list_option "march", |
| 50 | (help "Generate code for the specified machine type")), |
Mikhail Glushenkov | 3ab4883 | 2009-12-04 06:38:28 +0000 | [diff] [blame] | 51 | (parameter_option "mcpu", |
Mikhail Glushenkov | b5c2a5d | 2010-02-23 14:29:42 +0000 | [diff] [blame] | 52 | (help "A deprecated synonym for -mtune"), (hidden), (forward_not_split)), |
Mikhail Glushenkov | 2ac7eb8 | 2010-12-15 01:22:20 +0000 | [diff] [blame] | 53 | (parameter_option "mfpu", |
| 54 | (help "Specify type of floating point unit"), |
| 55 | (hidden), (forward_not_split)), |
Mikhail Glushenkov | 73e7809 | 2010-12-15 01:22:10 +0000 | [diff] [blame] | 56 | (parameter_option "mabi", |
| 57 | (help "Generate code for the specified ABI"), (hidden)), |
| 58 | (parameter_option "mfloat-abi", |
| 59 | (help "Specifies which floating-point ABI to use"), (hidden)), |
Mikhail Glushenkov | b88c6f6 | 2010-02-13 22:37:00 +0000 | [diff] [blame] | 60 | (switch_option "mfix-and-continue", |
| 61 | (help "Needed by gdb to load .o files dynamically"), (hidden)), |
Mikhail Glushenkov | 6d80d2b | 2009-10-08 04:40:28 +0000 | [diff] [blame] | 62 | (parameter_option "MF", |
| 63 | (help "Specify a file to write dependencies to"), (hidden)), |
Mikhail Glushenkov | bc56d86 | 2010-01-02 08:27:10 +0000 | [diff] [blame] | 64 | (parameter_list_option "MT", |
Mikhail Glushenkov | 6d80d2b | 2009-10-08 04:40:28 +0000 | [diff] [blame] | 65 | (help "Change the name of the rule emitted by dependency generation"), |
| 66 | (hidden)), |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 67 | (parameter_list_option "include", |
| 68 | (help "Include the named file prior to preprocessing")), |
Mikhail Glushenkov | 967edd0 | 2010-01-26 14:55:30 +0000 | [diff] [blame] | 69 | (parameter_list_option "iquote", |
| 70 | (help "Search dir only for files requested with #inlcude \"file\""), |
| 71 | (hidden)), |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 72 | (prefix_list_option "I", |
| 73 | (help "Add a directory to include path")), |
Mikhail Glushenkov | 6d80d2b | 2009-10-08 04:40:28 +0000 | [diff] [blame] | 74 | (prefix_list_option "D", |
| 75 | (help "Define a macro")), |
Mikhail Glushenkov | 130bede | 2010-02-23 09:05:15 +0000 | [diff] [blame] | 76 | (parameter_list_option "Xpreprocessor", (hidden), |
| 77 | (help "Pass options to preprocessor")), |
Mikhail Glushenkov | 5b9b3ba | 2009-12-07 18:25:54 +0000 | [diff] [blame] | 78 | (prefix_list_option "Wa,", (comma_separated), |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 79 | (help "Pass options to assembler")), |
Mikhail Glushenkov | 130bede | 2010-02-23 09:05:15 +0000 | [diff] [blame] | 80 | (parameter_list_option "Xassembler", (hidden), |
| 81 | (help "Pass options to assembler")), |
Mikhail Glushenkov | 5b9b3ba | 2009-12-07 18:25:54 +0000 | [diff] [blame] | 82 | (prefix_list_option "Wllc,", (comma_separated), |
Mikhail Glushenkov | 4680102 | 2009-03-31 18:33:54 +0000 | [diff] [blame] | 83 | (help "Pass options to llc")), |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 84 | (prefix_list_option "Wl,", |
Mikhail Glushenkov | ba71d67 | 2008-12-11 22:19:14 +0000 | [diff] [blame] | 85 | (help "Pass options to linker")), |
Mikhail Glushenkov | 130bede | 2010-02-23 09:05:15 +0000 | [diff] [blame] | 86 | (parameter_list_option "Xlinker", (hidden), |
| 87 | (help "Pass options to linker")), |
Mikhail Glushenkov | 5b9b3ba | 2009-12-07 18:25:54 +0000 | [diff] [blame] | 88 | (prefix_list_option "Wo,", (comma_separated), |
Mikhail Glushenkov | 8461202 | 2009-12-07 17:03:21 +0000 | [diff] [blame] | 89 | (help "Pass options to opt")), |
| 90 | (prefix_list_option "m", |
| 91 | (help "Enable or disable various extensions (-mmmx, -msse, etc.)"), |
Mikhail Glushenkov | b4c7a12 | 2010-09-21 11:57:04 +0000 | [diff] [blame] | 92 | (hidden)) |
| 93 | ]>; |
| 94 | |
| 95 | def LinkerOptList : OptionList<[ |
| 96 | (prefix_list_option "L", |
| 97 | (help "Add a directory to link path")), |
| 98 | (prefix_list_option "l", |
| 99 | (help "Search a library when linking")), |
| 100 | (parameter_option "filelist", (hidden), |
| 101 | (help "Link the files listed in file")), |
| 102 | (switch_option "nostartfiles", |
| 103 | (help "Do not use the standard system startup files when linking"), |
| 104 | (hidden)), |
| 105 | (switch_option "nodefaultlibs", |
| 106 | (help "Do not use the standard system libraries when linking"), (hidden)), |
| 107 | (switch_option "nostdlib", |
| 108 | (help |
| 109 | "Do not use the standard system startup files or libraries when linking"), |
| 110 | (hidden)), |
| 111 | (switch_option "pie", |
| 112 | (help "Produce a position independent executable"), (hidden)), |
| 113 | (switch_option "rdynamic", |
| 114 | (help "Add all symbols to the dynamic export table"), (hidden)), |
| 115 | (switch_option "s", |
| 116 | (help "Strip all symbols"), (hidden)), |
| 117 | (switch_option "static", |
| 118 | (help "Do not link against shared libraries"), (hidden)), |
| 119 | (switch_option "static-libgcc", |
| 120 | (help "Use static libgcc"), (hidden)), |
| 121 | (switch_option "shared", |
| 122 | (help "Create a DLL instead of the regular executable")), |
| 123 | (switch_option "shared-libgcc", |
| 124 | (help "Use shared libgcc"), (hidden)), |
| 125 | (parameter_option "T", |
| 126 | (help "Read linker script"), (hidden)), |
| 127 | (parameter_option "u", |
| 128 | (help "Start with undefined reference to SYMBOL"), (hidden)), |
| 129 | (switch_option "pthread", |
| 130 | (help "Enable threads")), |
| 131 | |
| 132 | // TODO: Add a conditional compilation mechanism to make Darwin-only options |
| 133 | // like '-arch' really Darwin-only. |
| 134 | (parameter_option "arch", |
| 135 | (help "Compile for the specified target architecture"), (hidden)), |
| 136 | (prefix_list_option "F", |
| 137 | (help "Add a directory to framework search path")), |
| 138 | (parameter_list_option "framework", |
| 139 | (help "Specifies a framework to link against")), |
| 140 | (parameter_list_option "weak_framework", |
| 141 | (help "Specifies a framework to weakly link against"), (hidden)), |
Mikhail Glushenkov | 49e496b | 2010-02-13 22:37:13 +0000 | [diff] [blame] | 142 | (switch_option "dynamiclib", (hidden), |
| 143 | (help "Produce a dynamic library")), |
| 144 | (switch_option "prebind", (hidden), |
| 145 | (help "Prebind all undefined symbols")), |
| 146 | (switch_option "dead_strip", (hidden), |
| 147 | (help "Remove unreachable blocks of code")), |
| 148 | (switch_option "single_module", (hidden), |
| 149 | (help "Build the library so it contains only one module")), |
Mikhail Glushenkov | 9f2a080 | 2010-02-23 09:04:18 +0000 | [diff] [blame] | 150 | (parameter_option "install_name", (hidden), |
| 151 | (help "File name the library will be installed in")), |
Mikhail Glushenkov | 49e496b | 2010-02-13 22:37:13 +0000 | [diff] [blame] | 152 | (parameter_option "compatibility_version", (hidden), |
| 153 | (help "Compatibility version number")), |
| 154 | (parameter_option "current_version", (hidden), |
| 155 | (help "Current version number")) |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 156 | ]>; |
| 157 | |
Mikhail Glushenkov | 0a22fb6 | 2009-10-17 20:09:29 +0000 | [diff] [blame] | 158 | // Option preprocessor. |
| 159 | |
| 160 | def Preprocess : OptionPreprocessor< |
Mikhail Glushenkov | 17ef94f | 2010-10-23 07:32:46 +0000 | [diff] [blame] | 161 | (case (not (any_switch_on "O0", "O1", "O2", "O3")), |
Mikhail Glushenkov | 994dbe0 | 2009-12-17 07:49:16 +0000 | [diff] [blame] | 162 | (set_option "O2"), |
Mikhail Glushenkov | 17ef94f | 2010-10-23 07:32:46 +0000 | [diff] [blame] | 163 | (and (switch_on "O3"), (any_switch_on "O0", "O1", "O2")), |
| 164 | (unset_option "O0", "O1", "O2"), |
| 165 | (and (switch_on "O2"), (any_switch_on "O0", "O1")), |
| 166 | (unset_option "O0", "O1"), |
| 167 | (switch_on "O1", "O0"), |
Mikhail Glushenkov | 0a22fb6 | 2009-10-17 20:09:29 +0000 | [diff] [blame] | 168 | (unset_option "O0")) |
| 169 | >; |
| 170 | |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 171 | // Tools |
| 172 | |
Mikhail Glushenkov | 17ef94f | 2010-10-23 07:32:46 +0000 | [diff] [blame] | 173 | class llvm_gcc_based <string cmd, string in_lang, string E_ext, dag out_lang, |
Mikhail Glushenkov | dea1c5b | 2010-10-14 11:22:06 +0000 | [diff] [blame] | 174 | string out_ext> : Tool< |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 175 | [(in_language in_lang), |
Mikhail Glushenkov | 17ef94f | 2010-10-23 07:32:46 +0000 | [diff] [blame] | 176 | out_lang, |
Mikhail Glushenkov | 47e87db | 2010-09-21 14:59:47 +0000 | [diff] [blame] | 177 | (output_suffix out_ext), |
Mikhail Glushenkov | b4c7a12 | 2010-09-21 11:57:04 +0000 | [diff] [blame] | 178 | (command cmd), |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 179 | (actions |
| 180 | (case |
Mikhail Glushenkov | a34f97a | 2010-02-23 09:04:44 +0000 | [diff] [blame] | 181 | (and (not_empty "o"), |
| 182 | (multiple_input_files), (or (switch_on "S"), (switch_on "c"))), |
Mikhail Glushenkov | ad981bf | 2009-09-28 01:16:42 +0000 | [diff] [blame] | 183 | (error "cannot specify -o with -c or -S with multiple files"), |
Mikhail Glushenkov | a34f97a | 2010-02-23 09:04:44 +0000 | [diff] [blame] | 184 | (switch_on "E"), |
| 185 | [(forward "E"), (stop_compilation), (output_suffix E_ext)], |
| 186 | (and (switch_on "E"), (empty "o")), (no_out_file), |
Mikhail Glushenkov | 3724945 | 2010-09-22 09:00:41 +0000 | [diff] [blame] | 187 | |
| 188 | // ('-emit-llvm') && !('opt') -> stop compilation |
| 189 | (and (switch_on "emit-llvm"), (not (switch_on "opt"))), |
| 190 | (stop_compilation), |
| 191 | // ('-S' && '-emit-llvm') && !('opt') -> output .ll |
Mikhail Glushenkov | 17ef94f | 2010-10-23 07:32:46 +0000 | [diff] [blame] | 192 | (and (switch_on "emit-llvm", "S"), (not (switch_on "opt"))), |
Mikhail Glushenkov | 3724945 | 2010-09-22 09:00:41 +0000 | [diff] [blame] | 193 | [(forward "S"), (output_suffix "ll")], |
Chris Lattner | 7a2bdde | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 194 | // Usually just output .bc |
Mikhail Glushenkov | 3724945 | 2010-09-22 09:00:41 +0000 | [diff] [blame] | 195 | (not (switch_on "fsyntax-only")), |
| 196 | [(append_cmd "-c"), (append_cmd "-emit-llvm")], |
| 197 | |
| 198 | // -fsyntax-only |
Mikhail Glushenkov | a34f97a | 2010-02-23 09:04:44 +0000 | [diff] [blame] | 199 | (switch_on "fsyntax-only"), [(forward "fsyntax-only"), |
| 200 | (no_out_file), (stop_compilation)], |
Mikhail Glushenkov | a34f97a | 2010-02-23 09:04:44 +0000 | [diff] [blame] | 201 | |
| 202 | // Forwards |
Mikhail Glushenkov | 130bede | 2010-02-23 09:05:15 +0000 | [diff] [blame] | 203 | (not_empty "Xpreprocessor"), (forward "Xpreprocessor"), |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 204 | (not_empty "include"), (forward "include"), |
Mikhail Glushenkov | 967edd0 | 2010-01-26 14:55:30 +0000 | [diff] [blame] | 205 | (not_empty "iquote"), (forward "iquote"), |
Mikhail Glushenkov | 9795500 | 2009-12-01 06:51:30 +0000 | [diff] [blame] | 206 | (not_empty "save-temps"), (append_cmd "-save-temps"), |
Mikhail Glushenkov | 976248d | 2009-10-08 06:03:38 +0000 | [diff] [blame] | 207 | (not_empty "I"), (forward "I"), |
Mikhail Glushenkov | 1851860 | 2009-12-01 05:59:55 +0000 | [diff] [blame] | 208 | (not_empty "F"), (forward "F"), |
Mikhail Glushenkov | 976248d | 2009-10-08 06:03:38 +0000 | [diff] [blame] | 209 | (not_empty "D"), (forward "D"), |
Mikhail Glushenkov | 058b3f5 | 2010-01-26 14:55:44 +0000 | [diff] [blame] | 210 | (not_empty "arch"), (forward "arch"), |
Mikhail Glushenkov | 3ab4883 | 2009-12-04 06:38:28 +0000 | [diff] [blame] | 211 | (not_empty "march"), (forward "march"), |
Mikhail Glushenkov | 3ab4883 | 2009-12-04 06:38:28 +0000 | [diff] [blame] | 212 | (not_empty "mcpu"), (forward "mcpu"), |
Mikhail Glushenkov | 0289413 | 2010-11-22 17:10:09 +0000 | [diff] [blame] | 213 | (not_empty "mtune"), (forward "mtune"), |
Mikhail Glushenkov | 2ac7eb8 | 2010-12-15 01:22:20 +0000 | [diff] [blame] | 214 | (not_empty "mfpu"), (forward "mfpu"), |
Mikhail Glushenkov | 73e7809 | 2010-12-15 01:22:10 +0000 | [diff] [blame] | 215 | (not_empty "mabi"), (forward "mabi"), |
| 216 | (not_empty "mfloat-abi"), (forward "mfloat-abi"), |
Mikhail Glushenkov | 8461202 | 2009-12-07 17:03:21 +0000 | [diff] [blame] | 217 | (not_empty "m"), (forward "m"), |
Mikhail Glushenkov | b88c6f6 | 2010-02-13 22:37:00 +0000 | [diff] [blame] | 218 | (switch_on "mfix-and-continue"), (forward "mfix-and-continue"), |
Mikhail Glushenkov | fa8182e | 2009-12-04 06:38:45 +0000 | [diff] [blame] | 219 | (switch_on "m32"), (forward "m32"), |
| 220 | (switch_on "m64"), (forward "m64"), |
Mikhail Glushenkov | 364cf75 | 2010-01-02 08:27:23 +0000 | [diff] [blame] | 221 | (switch_on "O0"), (forward "O0"), |
Mikhail Glushenkov | 6b4967e | 2009-10-17 20:07:49 +0000 | [diff] [blame] | 222 | (switch_on "O1"), (forward "O1"), |
| 223 | (switch_on "O2"), (forward "O2"), |
| 224 | (switch_on "O3"), (forward "O3"), |
Mikhail Glushenkov | 55cd767 | 2009-12-01 09:47:11 +0000 | [diff] [blame] | 225 | (switch_on "fPIC"), (forward "fPIC"), |
| 226 | (switch_on "mdynamic-no-pic"), (forward "mdynamic-no-pic"), |
Mikhail Glushenkov | 976248d | 2009-10-08 06:03:38 +0000 | [diff] [blame] | 227 | (not_empty "MF"), (forward "MF"), |
Mikhail Glushenkov | 6d80d2b | 2009-10-08 04:40:28 +0000 | [diff] [blame] | 228 | (not_empty "MT"), (forward "MT"))), |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 229 | (sink) |
| 230 | ]>; |
| 231 | |
Mikhail Glushenkov | 47e87db | 2010-09-21 14:59:47 +0000 | [diff] [blame] | 232 | class llvm_gcc_comp_based <string cmd, string in_lang, string E_ext> |
Mikhail Glushenkov | 17ef94f | 2010-10-23 07:32:46 +0000 | [diff] [blame] | 233 | : llvm_gcc_based<cmd, in_lang, E_ext, |
| 234 | (out_language "llvm-bitcode", "object-code"), "bc">; |
Mikhail Glushenkov | c6e0dbf | 2010-02-23 09:04:33 +0000 | [diff] [blame] | 235 | |
Mikhail Glushenkov | 47e87db | 2010-09-21 14:59:47 +0000 | [diff] [blame] | 236 | class llvm_gcc_pch_based <string cmd, string in_lang, string E_ext> |
Mikhail Glushenkov | 17ef94f | 2010-10-23 07:32:46 +0000 | [diff] [blame] | 237 | : llvm_gcc_based<cmd, in_lang, E_ext, |
| 238 | (out_language "precompiled-header"), "gch">; |
Mikhail Glushenkov | 47e87db | 2010-09-21 14:59:47 +0000 | [diff] [blame] | 239 | |
| 240 | def llvm_gcc_c : llvm_gcc_comp_based |
| 241 | <"@LLVMGCCCOMMAND@ -x c", "c", "i">; |
| 242 | def llvm_gcc_cpp : llvm_gcc_comp_based |
| 243 | <"@LLVMGXXCOMMAND@ -x c++", "c++", "i">; |
| 244 | def llvm_gcc_m : llvm_gcc_comp_based |
| 245 | <"@LLVMGCCCOMMAND@ -x objective-c", "objective-c", "mi">; |
| 246 | def llvm_gcc_mxx : llvm_gcc_comp_based |
| 247 | <"@LLVMGCCCOMMAND@ -x objective-c++", "objective-c++", "mi">; |
| 248 | |
| 249 | def llvm_gcc_c_pch : llvm_gcc_pch_based |
| 250 | <"@LLVMGCCCOMMAND@ -x c-header", "c-header", "i">; |
| 251 | def llvm_gcc_cpp_pch : llvm_gcc_pch_based |
| 252 | <"@LLVMGXXCOMMAND@ -x c++-header", "c++-header", "i">; |
| 253 | def llvm_gcc_m_pch : llvm_gcc_pch_based |
| 254 | <"@LLVMGCCCOMMAND@ -x objective-c-header", "objective-c-header", "mi">; |
| 255 | def llvm_gcc_mxx_pch : llvm_gcc_pch_based |
| 256 | <"@LLVMGCCCOMMAND@ -x objective-c++-header", "objective-c++-header", "mi">; |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 257 | |
| 258 | def opt : Tool< |
| 259 | [(in_language "llvm-bitcode"), |
| 260 | (out_language "llvm-bitcode"), |
Mikhail Glushenkov | c9aa78d | 2010-09-22 09:00:35 +0000 | [diff] [blame] | 261 | (output_suffix "opt.bc"), |
Mikhail Glushenkov | 3724945 | 2010-09-22 09:00:41 +0000 | [diff] [blame] | 262 | (actions (case (switch_on "emit-llvm"), (stop_compilation), |
Mikhail Glushenkov | 17ef94f | 2010-10-23 07:32:46 +0000 | [diff] [blame] | 263 | (switch_on "emit-llvm", "S"), |
Mikhail Glushenkov | 3724945 | 2010-09-22 09:00:41 +0000 | [diff] [blame] | 264 | [(append_cmd "-S"), (output_suffix "ll")], |
| 265 | (not_empty "Wo,"), (forward_value "Wo,"), |
Mikhail Glushenkov | 6b4967e | 2009-10-17 20:07:49 +0000 | [diff] [blame] | 266 | (switch_on "O1"), (forward "O1"), |
| 267 | (switch_on "O2"), (forward "O2"), |
| 268 | (switch_on "O3"), (forward "O3"))), |
Mikhail Glushenkov | a34f97a | 2010-02-23 09:04:44 +0000 | [diff] [blame] | 269 | (command "opt -f") |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 270 | ]>; |
| 271 | |
| 272 | def llvm_as : Tool< |
| 273 | [(in_language "llvm-assembler"), |
| 274 | (out_language "llvm-bitcode"), |
| 275 | (output_suffix "bc"), |
Mikhail Glushenkov | a34f97a | 2010-02-23 09:04:44 +0000 | [diff] [blame] | 276 | (command "llvm-as"), |
Mikhail Glushenkov | 75dab00 | 2011-02-19 00:33:27 +0000 | [diff] [blame] | 277 | (actions (case (and (switch_on "emit-llvm"), (not (switch_on "opt"))), |
| 278 | (stop_compilation))) |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 279 | ]>; |
| 280 | |
| 281 | def llvm_gcc_assembler : Tool< |
| 282 | [(in_language "assembler"), |
| 283 | (out_language "object-code"), |
| 284 | (output_suffix "o"), |
Mikhail Glushenkov | a34f97a | 2010-02-23 09:04:44 +0000 | [diff] [blame] | 285 | (command "@LLVMGCCCOMMAND@ -c -x assembler"), |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 286 | (actions (case |
| 287 | (switch_on "c"), (stop_compilation), |
Mikhail Glushenkov | 058b3f5 | 2010-01-26 14:55:44 +0000 | [diff] [blame] | 288 | (not_empty "arch"), (forward "arch"), |
Mikhail Glushenkov | 130bede | 2010-02-23 09:05:15 +0000 | [diff] [blame] | 289 | (not_empty "Xassembler"), (forward "Xassembler"), |
Mikhail Glushenkov | bebea87 | 2010-12-15 01:22:05 +0000 | [diff] [blame] | 290 | (not_empty "march"), (forward "march"), |
| 291 | (not_empty "mcpu"), (forward "mcpu"), |
| 292 | (not_empty "mtune"), (forward "mtune"), |
Mikhail Glushenkov | 73e7809 | 2010-12-15 01:22:10 +0000 | [diff] [blame] | 293 | (not_empty "mabi"), (forward "mabi"), |
| 294 | (not_empty "mfloat-abi"), (forward "mfloat-abi"), |
Mikhail Glushenkov | 62d1da0 | 2010-03-31 23:51:55 +0000 | [diff] [blame] | 295 | (switch_on "m32"), (forward "m32"), |
| 296 | (switch_on "m64"), (forward "m64"), |
Mikhail Glushenkov | 130bede | 2010-02-23 09:05:15 +0000 | [diff] [blame] | 297 | (not_empty "Wa,"), (forward "Wa,"))) |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 298 | ]>; |
| 299 | |
| 300 | def llc : Tool< |
Mikhail Glushenkov | 17ef94f | 2010-10-23 07:32:46 +0000 | [diff] [blame] | 301 | [(in_language "llvm-bitcode", "llvm-assembler"), |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 302 | (out_language "assembler"), |
| 303 | (output_suffix "s"), |
Dan Gohman | 281ead4 | 2010-04-29 18:46:52 +0000 | [diff] [blame] | 304 | (command "llc"), |
Mikhail Glushenkov | 4680102 | 2009-03-31 18:33:54 +0000 | [diff] [blame] | 305 | (actions (case |
| 306 | (switch_on "S"), (stop_compilation), |
Mikhail Glushenkov | 6b4967e | 2009-10-17 20:07:49 +0000 | [diff] [blame] | 307 | (switch_on "O0"), (forward "O0"), |
| 308 | (switch_on "O1"), (forward "O1"), |
| 309 | (switch_on "O2"), (forward "O2"), |
| 310 | (switch_on "O3"), (forward "O3"), |
Mikhail Glushenkov | 55cd767 | 2009-12-01 09:47:11 +0000 | [diff] [blame] | 311 | (switch_on "fPIC"), (append_cmd "-relocation-model=pic"), |
| 312 | (switch_on "mdynamic-no-pic"), |
| 313 | (append_cmd "-relocation-model=dynamic-no-pic"), |
Mikhail Glushenkov | 325f69d | 2010-11-28 00:31:13 +0000 | [diff] [blame] | 314 | (not_empty "march"), (forward_transformed_value |
| 315 | "march", "ConvertMArchToMAttr"), |
Mikhail Glushenkov | 2ac7eb8 | 2010-12-15 01:22:20 +0000 | [diff] [blame] | 316 | (not_empty "mcpu"), (forward_transformed_value "mcpu", "ConvertMCpu"), |
Mikhail Glushenkov | 0289413 | 2010-11-22 17:10:09 +0000 | [diff] [blame] | 317 | (and (not_empty "mtune"), (empty "mcpu")), |
| 318 | (forward_as "mtune", "-mcpu"), |
Mikhail Glushenkov | 2ac7eb8 | 2010-12-15 01:22:20 +0000 | [diff] [blame] | 319 | (not_empty "mfpu"), (forward_transformed_value "mfpu", "ConvertMFpu"), |
Mikhail Glushenkov | 8461202 | 2009-12-07 17:03:21 +0000 | [diff] [blame] | 320 | (not_empty "m"), (forward_transformed_value "m", "ConvertToMAttr"), |
Mikhail Glushenkov | 5b9b3ba | 2009-12-07 18:25:54 +0000 | [diff] [blame] | 321 | (not_empty "Wllc,"), (forward_value "Wllc,"))) |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 322 | ]>; |
| 323 | |
| 324 | // Base class for linkers |
Mikhail Glushenkov | b4c7a12 | 2010-09-21 11:57:04 +0000 | [diff] [blame] | 325 | class llvm_gcc_based_linker <string cmd, dag on_empty> : Tool< |
Mikhail Glushenkov | 17ef94f | 2010-10-23 07:32:46 +0000 | [diff] [blame] | 326 | [(in_language "object-code", "static-library", "dynamic-library"), |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 327 | (out_language "executable"), |
| 328 | (output_suffix "out"), |
Mikhail Glushenkov | b4c7a12 | 2010-09-21 11:57:04 +0000 | [diff] [blame] | 329 | (command cmd), |
Mikhail Glushenkov | 002dd18 | 2010-07-01 01:00:32 +0000 | [diff] [blame] | 330 | (works_on_empty (case (and (not_empty "filelist"), on_empty), true, |
Mikhail Glushenkov | be6ee7c | 2010-02-23 09:04:28 +0000 | [diff] [blame] | 331 | (default), false)), |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 332 | (join), |
| 333 | (actions (case |
| 334 | (switch_on "pthread"), (append_cmd "-lpthread"), |
| 335 | (not_empty "L"), (forward "L"), |
Mikhail Glushenkov | 1851860 | 2009-12-01 05:59:55 +0000 | [diff] [blame] | 336 | (not_empty "F"), (forward "F"), |
Mikhail Glushenkov | 058b3f5 | 2010-01-26 14:55:44 +0000 | [diff] [blame] | 337 | (not_empty "arch"), (forward "arch"), |
Mikhail Glushenkov | 1851860 | 2009-12-01 05:59:55 +0000 | [diff] [blame] | 338 | (not_empty "framework"), (forward "framework"), |
| 339 | (not_empty "weak_framework"), (forward "weak_framework"), |
Mikhail Glushenkov | be6ee7c | 2010-02-23 09:04:28 +0000 | [diff] [blame] | 340 | (not_empty "filelist"), (forward "filelist"), |
Mikhail Glushenkov | bebea87 | 2010-12-15 01:22:05 +0000 | [diff] [blame] | 341 | (not_empty "march"), (forward "march"), |
| 342 | (not_empty "mcpu"), (forward "mcpu"), |
| 343 | (not_empty "mtune"), (forward "mtune"), |
Mikhail Glushenkov | 73e7809 | 2010-12-15 01:22:10 +0000 | [diff] [blame] | 344 | (not_empty "mabi"), (forward "mabi"), |
| 345 | (not_empty "mfloat-abi"), (forward "mfloat-abi"), |
Mikhail Glushenkov | fa8182e | 2009-12-04 06:38:45 +0000 | [diff] [blame] | 346 | (switch_on "m32"), (forward "m32"), |
| 347 | (switch_on "m64"), (forward "m64"), |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 348 | (not_empty "l"), (forward "l"), |
Mikhail Glushenkov | 130bede | 2010-02-23 09:05:15 +0000 | [diff] [blame] | 349 | (not_empty "Xlinker"), (forward "Xlinker"), |
Mikhail Glushenkov | 49e496b | 2010-02-13 22:37:13 +0000 | [diff] [blame] | 350 | (not_empty "Wl,"), (forward "Wl,"), |
Mikhail Glushenkov | b4c7a12 | 2010-09-21 11:57:04 +0000 | [diff] [blame] | 351 | (switch_on "nostartfiles"), (forward "nostartfiles"), |
| 352 | (switch_on "nodefaultlibs"), (forward "nodefaultlibs"), |
| 353 | (switch_on "nostdlib"), (forward "nostdlib"), |
| 354 | (switch_on "pie"), (forward "pie"), |
| 355 | (switch_on "rdynamic"), (forward "rdynamic"), |
| 356 | (switch_on "s"), (forward "s"), |
| 357 | (switch_on "static"), (forward "static"), |
| 358 | (switch_on "static-libgcc"), (forward "static-libgcc"), |
Mikhail Glushenkov | cbf1aa9 | 2010-04-03 02:00:03 +0000 | [diff] [blame] | 359 | (switch_on "shared"), (forward "shared"), |
Mikhail Glushenkov | b4c7a12 | 2010-09-21 11:57:04 +0000 | [diff] [blame] | 360 | (switch_on "shared-libgcc"), (forward "shared-libgcc"), |
| 361 | (not_empty "T"), (forward "T"), |
| 362 | (not_empty "u"), (forward "u"), |
Mikhail Glushenkov | 49e496b | 2010-02-13 22:37:13 +0000 | [diff] [blame] | 363 | (switch_on "dynamiclib"), (forward "dynamiclib"), |
| 364 | (switch_on "prebind"), (forward "prebind"), |
| 365 | (switch_on "dead_strip"), (forward "dead_strip"), |
| 366 | (switch_on "single_module"), (forward "single_module"), |
| 367 | (not_empty "compatibility_version"), |
| 368 | (forward "compatibility_version"), |
Mikhail Glushenkov | 9f2a080 | 2010-02-23 09:04:18 +0000 | [diff] [blame] | 369 | (not_empty "current_version"), (forward "current_version"), |
| 370 | (not_empty "install_name"), (forward "install_name"))) |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 371 | ]>; |
| 372 | |
| 373 | // Default linker |
Mikhail Glushenkov | 002dd18 | 2010-07-01 01:00:32 +0000 | [diff] [blame] | 374 | def llvm_gcc_linker : llvm_gcc_based_linker<"@LLVMGCCCOMMAND@", |
| 375 | (not (or (parameter_equals "linker", "g++"), |
| 376 | (parameter_equals "linker", "c++")))>; |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 377 | // Alternative linker for C++ |
Mikhail Glushenkov | 002dd18 | 2010-07-01 01:00:32 +0000 | [diff] [blame] | 378 | def llvm_gcc_cpp_linker : llvm_gcc_based_linker<"@LLVMGXXCOMMAND@", |
| 379 | (or (parameter_equals "linker", "g++"), |
| 380 | (parameter_equals "linker", "c++"))>; |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 381 | |
| 382 | // Language map |
| 383 | |
Mikhail Glushenkov | d9a7316 | 2010-08-23 23:21:23 +0000 | [diff] [blame] | 384 | def LanguageMap : LanguageMap<[ |
Mikhail Glushenkov | 47e87db | 2010-09-21 14:59:47 +0000 | [diff] [blame] | 385 | (lang_to_suffixes "precompiled-header", ["gch", "pch"]), |
Mikhail Glushenkov | d9a7316 | 2010-08-23 23:21:23 +0000 | [diff] [blame] | 386 | (lang_to_suffixes "c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]), |
| 387 | (lang_to_suffixes "c++-header", "hpp"), |
| 388 | (lang_to_suffixes "c", "c"), |
| 389 | (lang_to_suffixes "c-header", "h"), |
| 390 | (lang_to_suffixes "c-cpp-output", "i"), |
| 391 | (lang_to_suffixes "objective-c-cpp-output", "mi"), |
| 392 | (lang_to_suffixes "objective-c++", "mm"), |
| 393 | (lang_to_suffixes "objective-c++-header", "hmm"), |
| 394 | (lang_to_suffixes "objective-c", "m"), |
| 395 | (lang_to_suffixes "objective-c-header", "hm"), |
| 396 | (lang_to_suffixes "assembler", "s"), |
| 397 | (lang_to_suffixes "assembler-with-cpp", "S"), |
| 398 | (lang_to_suffixes "llvm-assembler", "ll"), |
| 399 | (lang_to_suffixes "llvm-bitcode", "bc"), |
| 400 | (lang_to_suffixes "object-code", ["o", "*empty*"]), |
| 401 | (lang_to_suffixes "static-library", ["a", "lib"]), |
Mikhail Glushenkov | 743547f | 2010-09-02 14:06:21 +0000 | [diff] [blame] | 402 | (lang_to_suffixes "dynamic-library", ["so", "dylib", "dll"]), |
Mikhail Glushenkov | dea1c5b | 2010-10-14 11:22:06 +0000 | [diff] [blame] | 403 | (lang_to_suffixes "executable", "out") |
Mikhail Glushenkov | d9a7316 | 2010-08-23 23:21:23 +0000 | [diff] [blame] | 404 | ]>; |
Mikhail Glushenkov | de1e521 | 2008-12-11 10:38:06 +0000 | [diff] [blame] | 405 | |
| 406 | // Compilation graph |
Anton Korobeynikov | ac67b7e | 2008-03-23 08:57:20 +0000 | [diff] [blame] | 407 | |
Mikhail Glushenkov | 0d08db0 | 2008-05-06 16:35:25 +0000 | [diff] [blame] | 408 | def CompilationGraph : CompilationGraph<[ |
Mikhail Glushenkov | d9a7316 | 2010-08-23 23:21:23 +0000 | [diff] [blame] | 409 | (edge "root", "llvm_gcc_c"), |
| 410 | (edge "root", "llvm_gcc_assembler"), |
| 411 | (edge "root", "llvm_gcc_cpp"), |
| 412 | (edge "root", "llvm_gcc_m"), |
| 413 | (edge "root", "llvm_gcc_mxx"), |
| 414 | (edge "root", "llc"), |
Mikhail Glushenkov | d752c3f | 2008-05-06 16:36:50 +0000 | [diff] [blame] | 415 | |
Mikhail Glushenkov | d9a7316 | 2010-08-23 23:21:23 +0000 | [diff] [blame] | 416 | (edge "root", "llvm_gcc_c_pch"), |
| 417 | (edge "root", "llvm_gcc_cpp_pch"), |
| 418 | (edge "root", "llvm_gcc_m_pch"), |
| 419 | (edge "root", "llvm_gcc_mxx_pch"), |
Mikhail Glushenkov | c6e0dbf | 2010-02-23 09:04:33 +0000 | [diff] [blame] | 420 | |
Mikhail Glushenkov | d9a7316 | 2010-08-23 23:21:23 +0000 | [diff] [blame] | 421 | (edge "llvm_gcc_c", "llc"), |
| 422 | (edge "llvm_gcc_cpp", "llc"), |
| 423 | (edge "llvm_gcc_m", "llc"), |
| 424 | (edge "llvm_gcc_mxx", "llc"), |
| 425 | (edge "llvm_as", "llc"), |
Mikhail Glushenkov | d752c3f | 2008-05-06 16:36:50 +0000 | [diff] [blame] | 426 | |
Mikhail Glushenkov | d9a7316 | 2010-08-23 23:21:23 +0000 | [diff] [blame] | 427 | (optional_edge "root", "llvm_as", |
Mikhail Glushenkov | 75dab00 | 2011-02-19 00:33:27 +0000 | [diff] [blame] | 428 | (case (or (switch_on "emit-llvm"), |
| 429 | (switch_on "opt")), (inc_weight))), |
Mikhail Glushenkov | d9a7316 | 2010-08-23 23:21:23 +0000 | [diff] [blame] | 430 | (optional_edge "llvm_gcc_c", "opt", |
| 431 | (case (switch_on "opt"), (inc_weight))), |
| 432 | (optional_edge "llvm_gcc_cpp", "opt", |
| 433 | (case (switch_on "opt"), (inc_weight))), |
| 434 | (optional_edge "llvm_gcc_m", "opt", |
| 435 | (case (switch_on "opt"), (inc_weight))), |
| 436 | (optional_edge "llvm_gcc_mxx", "opt", |
| 437 | (case (switch_on "opt"), (inc_weight))), |
| 438 | (optional_edge "llvm_as", "opt", |
| 439 | (case (switch_on "opt"), (inc_weight))), |
| 440 | (edge "opt", "llc"), |
Mikhail Glushenkov | d752c3f | 2008-05-06 16:36:50 +0000 | [diff] [blame] | 441 | |
Mikhail Glushenkov | d9a7316 | 2010-08-23 23:21:23 +0000 | [diff] [blame] | 442 | (edge "llc", "llvm_gcc_assembler"), |
| 443 | (edge "llvm_gcc_assembler", "llvm_gcc_linker"), |
| 444 | (optional_edge "llvm_gcc_assembler", "llvm_gcc_cpp_linker", |
Mikhail Glushenkov | e5557f4 | 2008-05-30 06:08:50 +0000 | [diff] [blame] | 445 | (case |
Daniel Dunbar | 77e0c85 | 2008-11-08 03:25:47 +0000 | [diff] [blame] | 446 | (or (input_languages_contain "c++"), |
Mikhail Glushenkov | 0108877 | 2008-11-17 17:29:18 +0000 | [diff] [blame] | 447 | (input_languages_contain "objective-c++")), |
Daniel Dunbar | 77e0c85 | 2008-11-08 03:25:47 +0000 | [diff] [blame] | 448 | (inc_weight), |
Mikhail Glushenkov | e5557f4 | 2008-05-30 06:08:50 +0000 | [diff] [blame] | 449 | (or (parameter_equals "linker", "g++"), |
Mikhail Glushenkov | d9a7316 | 2010-08-23 23:21:23 +0000 | [diff] [blame] | 450 | (parameter_equals "linker", "c++")), (inc_weight))), |
Mikhail Glushenkov | 35a85e8 | 2008-05-06 18:10:20 +0000 | [diff] [blame] | 451 | |
Mikhail Glushenkov | 978d498 | 2008-05-06 18:13:00 +0000 | [diff] [blame] | 452 | |
Mikhail Glushenkov | d9a7316 | 2010-08-23 23:21:23 +0000 | [diff] [blame] | 453 | (edge "root", "llvm_gcc_linker"), |
| 454 | (optional_edge "root", "llvm_gcc_cpp_linker", |
Mikhail Glushenkov | e5557f4 | 2008-05-30 06:08:50 +0000 | [diff] [blame] | 455 | (case |
Daniel Dunbar | 77e0c85 | 2008-11-08 03:25:47 +0000 | [diff] [blame] | 456 | (or (input_languages_contain "c++"), |
Mikhail Glushenkov | 0108877 | 2008-11-17 17:29:18 +0000 | [diff] [blame] | 457 | (input_languages_contain "objective-c++")), |
Daniel Dunbar | 77e0c85 | 2008-11-08 03:25:47 +0000 | [diff] [blame] | 458 | (inc_weight), |
Mikhail Glushenkov | e5557f4 | 2008-05-30 06:08:50 +0000 | [diff] [blame] | 459 | (or (parameter_equals "linker", "g++"), |
Mikhail Glushenkov | d9a7316 | 2010-08-23 23:21:23 +0000 | [diff] [blame] | 460 | (parameter_equals "linker", "c++")), (inc_weight))) |
| 461 | ]>; |