1 //===- Base.td - LLVMC toolchain descriptions --------------*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains compilation graph description used by llvmc.
12 //===----------------------------------------------------------------------===//
16 def OptList : OptionList<[
17 (switch_option "emit-llvm",
18 (help "Emit LLVM .ll files instead of native object files")),
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")),
26 (help "Turn off optimization"), (zero_or_more)),
28 (help "Optimization level 1"), (zero_or_more)),
30 (help "Optimization level 2"), (zero_or_more)),
32 (help "Optimization level 3"), (zero_or_more)),
34 (help "Stop after compilation, do not assemble")),
36 (help "Compile and assemble, but do not link")),
38 (help "Generate code for a 32-bit environment"), (hidden)),
40 (help "Generate code for a 64-bit environment"), (hidden)),
41 (switch_option "fPIC",
42 (help "Relocation model: PIC"), (hidden)),
43 (switch_option "mdynamic-no-pic",
44 (help "Relocation model: dynamic-no-pic"), (hidden)),
45 (parameter_option "linker",
46 (help "Choose linker (possible values: gcc, g++)")),
47 (parameter_option "mtune",
48 (help "Target a specific CPU type"), (forward_not_split)),
49 (parameter_list_option "march",
50 (help "Generate code for the specified machine type")),
51 (parameter_option "mcpu",
52 (help "A deprecated synonym for -mtune"), (hidden), (forward_not_split)),
53 (switch_option "mfix-and-continue",
54 (help "Needed by gdb to load .o files dynamically"), (hidden)),
55 (parameter_option "MF",
56 (help "Specify a file to write dependencies to"), (hidden)),
57 (parameter_list_option "MT",
58 (help "Change the name of the rule emitted by dependency generation"),
60 (parameter_list_option "include",
61 (help "Include the named file prior to preprocessing")),
62 (parameter_list_option "iquote",
63 (help "Search dir only for files requested with #inlcude \"file\""),
65 (prefix_list_option "I",
66 (help "Add a directory to include path")),
67 (prefix_list_option "D",
68 (help "Define a macro")),
69 (parameter_list_option "Xpreprocessor", (hidden),
70 (help "Pass options to preprocessor")),
71 (prefix_list_option "Wa,", (comma_separated),
72 (help "Pass options to assembler")),
73 (parameter_list_option "Xassembler", (hidden),
74 (help "Pass options to assembler")),
75 (prefix_list_option "Wllc,", (comma_separated),
76 (help "Pass options to llc")),
77 (prefix_list_option "Wl,",
78 (help "Pass options to linker")),
79 (parameter_list_option "Xlinker", (hidden),
80 (help "Pass options to linker")),
81 (prefix_list_option "Wo,", (comma_separated),
82 (help "Pass options to opt")),
83 (prefix_list_option "m",
84 (help "Enable or disable various extensions (-mmmx, -msse, etc.)"),
88 def LinkerOptList : OptionList<[
89 (prefix_list_option "L",
90 (help "Add a directory to link path")),
91 (prefix_list_option "l",
92 (help "Search a library when linking")),
93 (parameter_option "filelist", (hidden),
94 (help "Link the files listed in file")),
95 (switch_option "nostartfiles",
96 (help "Do not use the standard system startup files when linking"),
98 (switch_option "nodefaultlibs",
99 (help "Do not use the standard system libraries when linking"), (hidden)),
100 (switch_option "nostdlib",
102 "Do not use the standard system startup files or libraries when linking"),
104 (switch_option "pie",
105 (help "Produce a position independent executable"), (hidden)),
106 (switch_option "rdynamic",
107 (help "Add all symbols to the dynamic export table"), (hidden)),
109 (help "Strip all symbols"), (hidden)),
110 (switch_option "static",
111 (help "Do not link against shared libraries"), (hidden)),
112 (switch_option "static-libgcc",
113 (help "Use static libgcc"), (hidden)),
114 (switch_option "shared",
115 (help "Create a DLL instead of the regular executable")),
116 (switch_option "shared-libgcc",
117 (help "Use shared libgcc"), (hidden)),
118 (parameter_option "T",
119 (help "Read linker script"), (hidden)),
120 (parameter_option "u",
121 (help "Start with undefined reference to SYMBOL"), (hidden)),
122 (switch_option "pthread",
123 (help "Enable threads")),
125 // TODO: Add a conditional compilation mechanism to make Darwin-only options
126 // like '-arch' really Darwin-only.
127 (parameter_option "arch",
128 (help "Compile for the specified target architecture"), (hidden)),
129 (prefix_list_option "F",
130 (help "Add a directory to framework search path")),
131 (parameter_list_option "framework",
132 (help "Specifies a framework to link against")),
133 (parameter_list_option "weak_framework",
134 (help "Specifies a framework to weakly link against"), (hidden)),
135 (switch_option "dynamiclib", (hidden),
136 (help "Produce a dynamic library")),
137 (switch_option "prebind", (hidden),
138 (help "Prebind all undefined symbols")),
139 (switch_option "dead_strip", (hidden),
140 (help "Remove unreachable blocks of code")),
141 (switch_option "single_module", (hidden),
142 (help "Build the library so it contains only one module")),
143 (parameter_option "install_name", (hidden),
144 (help "File name the library will be installed in")),
145 (parameter_option "compatibility_version", (hidden),
146 (help "Compatibility version number")),
147 (parameter_option "current_version", (hidden),
148 (help "Current version number"))
151 // Option preprocessor.
153 def Preprocess : OptionPreprocessor<
154 (case (not (any_switch_on "O0", "O1", "O2", "O3")),
156 (and (switch_on "O3"), (any_switch_on "O0", "O1", "O2")),
157 (unset_option "O0", "O1", "O2"),
158 (and (switch_on "O2"), (any_switch_on "O0", "O1")),
159 (unset_option "O0", "O1"),
160 (switch_on "O1", "O0"),
166 class llvm_gcc_based <string cmd, string in_lang, string E_ext, dag out_lang,
167 string out_ext> : Tool<
168 [(in_language in_lang),
170 (output_suffix out_ext),
174 (and (not_empty "o"),
175 (multiple_input_files), (or (switch_on "S"), (switch_on "c"))),
176 (error "cannot specify -o with -c or -S with multiple files"),
178 [(forward "E"), (stop_compilation), (output_suffix E_ext)],
179 (and (switch_on "E"), (empty "o")), (no_out_file),
181 // ('-emit-llvm') && !('opt') -> stop compilation
182 (and (switch_on "emit-llvm"), (not (switch_on "opt"))),
184 // ('-S' && '-emit-llvm') && !('opt') -> output .ll
185 (and (switch_on "emit-llvm", "S"), (not (switch_on "opt"))),
186 [(forward "S"), (output_suffix "ll")],
187 // Ususally just output .bc
188 (not (switch_on "fsyntax-only")),
189 [(append_cmd "-c"), (append_cmd "-emit-llvm")],
192 (switch_on "fsyntax-only"), [(forward "fsyntax-only"),
193 (no_out_file), (stop_compilation)],
196 (not_empty "Xpreprocessor"), (forward "Xpreprocessor"),
197 (not_empty "include"), (forward "include"),
198 (not_empty "iquote"), (forward "iquote"),
199 (not_empty "save-temps"), (append_cmd "-save-temps"),
200 (not_empty "I"), (forward "I"),
201 (not_empty "F"), (forward "F"),
202 (not_empty "D"), (forward "D"),
203 (not_empty "arch"), (forward "arch"),
204 (not_empty "march"), (forward "march"),
205 (not_empty "mcpu"), (forward "mcpu"),
206 (not_empty "mtune"), (forward "mtune"),
207 (not_empty "m"), (forward "m"),
208 (switch_on "mfix-and-continue"), (forward "mfix-and-continue"),
209 (switch_on "m32"), (forward "m32"),
210 (switch_on "m64"), (forward "m64"),
211 (switch_on "O0"), (forward "O0"),
212 (switch_on "O1"), (forward "O1"),
213 (switch_on "O2"), (forward "O2"),
214 (switch_on "O3"), (forward "O3"),
215 (switch_on "fPIC"), (forward "fPIC"),
216 (switch_on "mdynamic-no-pic"), (forward "mdynamic-no-pic"),
217 (not_empty "MF"), (forward "MF"),
218 (not_empty "MT"), (forward "MT"))),
222 class llvm_gcc_comp_based <string cmd, string in_lang, string E_ext>
223 : llvm_gcc_based<cmd, in_lang, E_ext,
224 (out_language "llvm-bitcode", "object-code"), "bc">;
226 class llvm_gcc_pch_based <string cmd, string in_lang, string E_ext>
227 : llvm_gcc_based<cmd, in_lang, E_ext,
228 (out_language "precompiled-header"), "gch">;
230 def llvm_gcc_c : llvm_gcc_comp_based
231 <"@LLVMGCCCOMMAND@ -x c", "c", "i">;
232 def llvm_gcc_cpp : llvm_gcc_comp_based
233 <"@LLVMGXXCOMMAND@ -x c++", "c++", "i">;
234 def llvm_gcc_m : llvm_gcc_comp_based
235 <"@LLVMGCCCOMMAND@ -x objective-c", "objective-c", "mi">;
236 def llvm_gcc_mxx : llvm_gcc_comp_based
237 <"@LLVMGCCCOMMAND@ -x objective-c++", "objective-c++", "mi">;
239 def llvm_gcc_c_pch : llvm_gcc_pch_based
240 <"@LLVMGCCCOMMAND@ -x c-header", "c-header", "i">;
241 def llvm_gcc_cpp_pch : llvm_gcc_pch_based
242 <"@LLVMGXXCOMMAND@ -x c++-header", "c++-header", "i">;
243 def llvm_gcc_m_pch : llvm_gcc_pch_based
244 <"@LLVMGCCCOMMAND@ -x objective-c-header", "objective-c-header", "mi">;
245 def llvm_gcc_mxx_pch : llvm_gcc_pch_based
246 <"@LLVMGCCCOMMAND@ -x objective-c++-header", "objective-c++-header", "mi">;
249 [(in_language "llvm-bitcode"),
250 (out_language "llvm-bitcode"),
251 (output_suffix "opt.bc"),
252 (actions (case (switch_on "emit-llvm"), (stop_compilation),
253 (switch_on "emit-llvm", "S"),
254 [(append_cmd "-S"), (output_suffix "ll")],
255 (not_empty "Wo,"), (forward_value "Wo,"),
256 (switch_on "O1"), (forward "O1"),
257 (switch_on "O2"), (forward "O2"),
258 (switch_on "O3"), (forward "O3"))),
263 [(in_language "llvm-assembler"),
264 (out_language "llvm-bitcode"),
265 (output_suffix "bc"),
267 (actions (case (switch_on "emit-llvm"), (stop_compilation)))
270 def llvm_gcc_assembler : Tool<
271 [(in_language "assembler"),
272 (out_language "object-code"),
274 (command "@LLVMGCCCOMMAND@ -c -x assembler"),
276 (switch_on "c"), (stop_compilation),
277 (not_empty "arch"), (forward "arch"),
278 (not_empty "Xassembler"), (forward "Xassembler"),
279 (switch_on "m32"), (forward "m32"),
280 (switch_on "m64"), (forward "m64"),
281 (not_empty "Wa,"), (forward "Wa,")))
285 [(in_language "llvm-bitcode", "llvm-assembler"),
286 (out_language "assembler"),
290 (switch_on "S"), (stop_compilation),
291 (switch_on "O0"), (forward "O0"),
292 (switch_on "O1"), (forward "O1"),
293 (switch_on "O2"), (forward "O2"),
294 (switch_on "O3"), (forward "O3"),
295 (switch_on "fPIC"), (append_cmd "-relocation-model=pic"),
296 (switch_on "mdynamic-no-pic"),
297 (append_cmd "-relocation-model=dynamic-no-pic"),
298 (not_empty "march"), (forward_transformed_value
299 "march", "ConvertMArchToMAttr"),
300 (not_empty "mcpu"), (forward "mcpu"),
301 (and (not_empty "mtune"), (empty "mcpu")),
302 (forward_as "mtune", "-mcpu"),
303 (not_empty "m"), (forward_transformed_value "m", "ConvertToMAttr"),
304 (not_empty "Wllc,"), (forward_value "Wllc,")))
307 // Base class for linkers
308 class llvm_gcc_based_linker <string cmd, dag on_empty> : Tool<
309 [(in_language "object-code", "static-library", "dynamic-library"),
310 (out_language "executable"),
311 (output_suffix "out"),
313 (works_on_empty (case (and (not_empty "filelist"), on_empty), true,
317 (switch_on "pthread"), (append_cmd "-lpthread"),
318 (not_empty "L"), (forward "L"),
319 (not_empty "F"), (forward "F"),
320 (not_empty "arch"), (forward "arch"),
321 (not_empty "framework"), (forward "framework"),
322 (not_empty "weak_framework"), (forward "weak_framework"),
323 (not_empty "filelist"), (forward "filelist"),
324 (switch_on "m32"), (forward "m32"),
325 (switch_on "m64"), (forward "m64"),
326 (not_empty "l"), (forward "l"),
327 (not_empty "Xlinker"), (forward "Xlinker"),
328 (not_empty "Wl,"), (forward "Wl,"),
329 (switch_on "nostartfiles"), (forward "nostartfiles"),
330 (switch_on "nodefaultlibs"), (forward "nodefaultlibs"),
331 (switch_on "nostdlib"), (forward "nostdlib"),
332 (switch_on "pie"), (forward "pie"),
333 (switch_on "rdynamic"), (forward "rdynamic"),
334 (switch_on "s"), (forward "s"),
335 (switch_on "static"), (forward "static"),
336 (switch_on "static-libgcc"), (forward "static-libgcc"),
337 (switch_on "shared"), (forward "shared"),
338 (switch_on "shared-libgcc"), (forward "shared-libgcc"),
339 (not_empty "T"), (forward "T"),
340 (not_empty "u"), (forward "u"),
341 (switch_on "dynamiclib"), (forward "dynamiclib"),
342 (switch_on "prebind"), (forward "prebind"),
343 (switch_on "dead_strip"), (forward "dead_strip"),
344 (switch_on "single_module"), (forward "single_module"),
345 (not_empty "compatibility_version"),
346 (forward "compatibility_version"),
347 (not_empty "current_version"), (forward "current_version"),
348 (not_empty "install_name"), (forward "install_name")))
352 def llvm_gcc_linker : llvm_gcc_based_linker<"@LLVMGCCCOMMAND@",
353 (not (or (parameter_equals "linker", "g++"),
354 (parameter_equals "linker", "c++")))>;
355 // Alternative linker for C++
356 def llvm_gcc_cpp_linker : llvm_gcc_based_linker<"@LLVMGXXCOMMAND@",
357 (or (parameter_equals "linker", "g++"),
358 (parameter_equals "linker", "c++"))>;
362 def LanguageMap : LanguageMap<[
363 (lang_to_suffixes "precompiled-header", ["gch", "pch"]),
364 (lang_to_suffixes "c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]),
365 (lang_to_suffixes "c++-header", "hpp"),
366 (lang_to_suffixes "c", "c"),
367 (lang_to_suffixes "c-header", "h"),
368 (lang_to_suffixes "c-cpp-output", "i"),
369 (lang_to_suffixes "objective-c-cpp-output", "mi"),
370 (lang_to_suffixes "objective-c++", "mm"),
371 (lang_to_suffixes "objective-c++-header", "hmm"),
372 (lang_to_suffixes "objective-c", "m"),
373 (lang_to_suffixes "objective-c-header", "hm"),
374 (lang_to_suffixes "assembler", "s"),
375 (lang_to_suffixes "assembler-with-cpp", "S"),
376 (lang_to_suffixes "llvm-assembler", "ll"),
377 (lang_to_suffixes "llvm-bitcode", "bc"),
378 (lang_to_suffixes "object-code", ["o", "*empty*"]),
379 (lang_to_suffixes "static-library", ["a", "lib"]),
380 (lang_to_suffixes "dynamic-library", ["so", "dylib", "dll"]),
381 (lang_to_suffixes "executable", "out")
386 def CompilationGraph : CompilationGraph<[
387 (edge "root", "llvm_gcc_c"),
388 (edge "root", "llvm_gcc_assembler"),
389 (edge "root", "llvm_gcc_cpp"),
390 (edge "root", "llvm_gcc_m"),
391 (edge "root", "llvm_gcc_mxx"),
392 (edge "root", "llc"),
394 (edge "root", "llvm_gcc_c_pch"),
395 (edge "root", "llvm_gcc_cpp_pch"),
396 (edge "root", "llvm_gcc_m_pch"),
397 (edge "root", "llvm_gcc_mxx_pch"),
399 (edge "llvm_gcc_c", "llc"),
400 (edge "llvm_gcc_cpp", "llc"),
401 (edge "llvm_gcc_m", "llc"),
402 (edge "llvm_gcc_mxx", "llc"),
403 (edge "llvm_as", "llc"),
405 (optional_edge "root", "llvm_as",
406 (case (switch_on "emit-llvm"), (inc_weight))),
407 (optional_edge "llvm_gcc_c", "opt",
408 (case (switch_on "opt"), (inc_weight))),
409 (optional_edge "llvm_gcc_cpp", "opt",
410 (case (switch_on "opt"), (inc_weight))),
411 (optional_edge "llvm_gcc_m", "opt",
412 (case (switch_on "opt"), (inc_weight))),
413 (optional_edge "llvm_gcc_mxx", "opt",
414 (case (switch_on "opt"), (inc_weight))),
415 (optional_edge "llvm_as", "opt",
416 (case (switch_on "opt"), (inc_weight))),
419 (edge "llc", "llvm_gcc_assembler"),
420 (edge "llvm_gcc_assembler", "llvm_gcc_linker"),
421 (optional_edge "llvm_gcc_assembler", "llvm_gcc_cpp_linker",
423 (or (input_languages_contain "c++"),
424 (input_languages_contain "objective-c++")),
426 (or (parameter_equals "linker", "g++"),
427 (parameter_equals "linker", "c++")), (inc_weight))),
430 (edge "root", "llvm_gcc_linker"),
431 (optional_edge "root", "llvm_gcc_cpp_linker",
433 (or (input_languages_contain "c++"),
434 (input_languages_contain "objective-c++")),
436 (or (parameter_equals "linker", "g++"),
437 (parameter_equals "linker", "c++")), (inc_weight)))