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