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,
168 string E_ext, string out_lang, string out_ext> : Tool<
169 [(in_language in_lang),
170 (out_language out_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),
181 (switch_on ["emit-llvm", "S"]),
182 [(output_suffix "ll"), (stop_compilation)],
183 (switch_on ["emit-llvm", "c"]), (stop_compilation),
184 (switch_on "fsyntax-only"), [(forward "fsyntax-only"),
185 (no_out_file), (stop_compilation)],
186 (switch_on ["S", "emit-llvm"]), [(forward "S"), (forward "emit-llvm")],
187 (not (or (switch_on ["S", "emit-llvm"]), (switch_on "fsyntax-only"))),
188 [(append_cmd "-c"), (append_cmd "-emit-llvm")],
191 (not_empty "Xpreprocessor"), (forward "Xpreprocessor"),
192 (not_empty "include"), (forward "include"),
193 (not_empty "iquote"), (forward "iquote"),
194 (not_empty "save-temps"), (append_cmd "-save-temps"),
195 (not_empty "I"), (forward "I"),
196 (not_empty "F"), (forward "F"),
197 (not_empty "D"), (forward "D"),
198 (not_empty "arch"), (forward "arch"),
199 (not_empty "march"), (forward "march"),
200 (not_empty "mtune"), (forward "mtune"),
201 (not_empty "mcpu"), (forward "mcpu"),
202 (not_empty "m"), (forward "m"),
203 (switch_on "mfix-and-continue"), (forward "mfix-and-continue"),
204 (switch_on "m32"), (forward "m32"),
205 (switch_on "m64"), (forward "m64"),
206 (switch_on "O0"), (forward "O0"),
207 (switch_on "O1"), (forward "O1"),
208 (switch_on "O2"), (forward "O2"),
209 (switch_on "O3"), (forward "O3"),
210 (switch_on "fPIC"), (forward "fPIC"),
211 (switch_on "mdynamic-no-pic"), (forward "mdynamic-no-pic"),
212 (not_empty "MF"), (forward "MF"),
213 (not_empty "MT"), (forward "MT"))),
217 class llvm_gcc_comp_based <string cmd, string in_lang, string E_ext>
218 : llvm_gcc_based<cmd, in_lang, E_ext, "llvm-bitcode", "bc">;
220 class llvm_gcc_pch_based <string cmd, string in_lang, string E_ext>
221 : llvm_gcc_based<cmd, in_lang, E_ext, "precompiled-header", "gch">;
223 def llvm_gcc_c : llvm_gcc_comp_based
224 <"@LLVMGCCCOMMAND@ -x c", "c", "i">;
225 def llvm_gcc_cpp : llvm_gcc_comp_based
226 <"@LLVMGXXCOMMAND@ -x c++", "c++", "i">;
227 def llvm_gcc_m : llvm_gcc_comp_based
228 <"@LLVMGCCCOMMAND@ -x objective-c", "objective-c", "mi">;
229 def llvm_gcc_mxx : llvm_gcc_comp_based
230 <"@LLVMGCCCOMMAND@ -x objective-c++", "objective-c++", "mi">;
232 def llvm_gcc_c_pch : llvm_gcc_pch_based
233 <"@LLVMGCCCOMMAND@ -x c-header", "c-header", "i">;
234 def llvm_gcc_cpp_pch : llvm_gcc_pch_based
235 <"@LLVMGXXCOMMAND@ -x c++-header", "c++-header", "i">;
236 def llvm_gcc_m_pch : llvm_gcc_pch_based
237 <"@LLVMGCCCOMMAND@ -x objective-c-header", "objective-c-header", "mi">;
238 def llvm_gcc_mxx_pch : llvm_gcc_pch_based
239 <"@LLVMGCCCOMMAND@ -x objective-c++-header", "objective-c++-header", "mi">;
242 [(in_language "llvm-bitcode"),
243 (out_language "llvm-bitcode"),
244 (output_suffix "bc"),
245 (actions (case (not_empty "Wo,"), (forward_value "Wo,"),
246 (switch_on "O1"), (forward "O1"),
247 (switch_on "O2"), (forward "O2"),
248 (switch_on "O3"), (forward "O3"))),
253 [(in_language "llvm-assembler"),
254 (out_language "llvm-bitcode"),
255 (output_suffix "bc"),
257 (actions (case (switch_on "emit-llvm"), (stop_compilation)))
260 def llvm_gcc_assembler : Tool<
261 [(in_language "assembler"),
262 (out_language "object-code"),
264 (command "@LLVMGCCCOMMAND@ -c -x assembler"),
266 (switch_on "c"), (stop_compilation),
267 (not_empty "arch"), (forward "arch"),
268 (not_empty "Xassembler"), (forward "Xassembler"),
269 (switch_on "m32"), (forward "m32"),
270 (switch_on "m64"), (forward "m64"),
271 (not_empty "Wa,"), (forward "Wa,")))
275 [(in_language ["llvm-bitcode", "llvm-assembler"]),
276 (out_language "assembler"),
280 (switch_on "S"), (stop_compilation),
281 (switch_on "O0"), (forward "O0"),
282 (switch_on "O1"), (forward "O1"),
283 (switch_on "O2"), (forward "O2"),
284 (switch_on "O3"), (forward "O3"),
285 (switch_on "fPIC"), (append_cmd "-relocation-model=pic"),
286 (switch_on "mdynamic-no-pic"),
287 (append_cmd "-relocation-model=dynamic-no-pic"),
288 (not_empty "march"), (forward_as "mtune", "-mcpu"),
289 (not_empty "mtune"), (forward_as "mtune", "-mcpu"),
290 (not_empty "mcpu"), (forward "mcpu"),
291 (not_empty "m"), (forward_transformed_value "m", "ConvertToMAttr"),
292 (not_empty "Wllc,"), (forward_value "Wllc,")))
295 // Base class for linkers
296 class llvm_gcc_based_linker <string cmd, dag on_empty> : Tool<
297 [(in_language ["object-code", "static-library", "dynamic-library"]),
298 (out_language "executable"),
299 (output_suffix "out"),
301 (works_on_empty (case (and (not_empty "filelist"), on_empty), true,
305 (switch_on "pthread"), (append_cmd "-lpthread"),
306 (not_empty "L"), (forward "L"),
307 (not_empty "F"), (forward "F"),
308 (not_empty "arch"), (forward "arch"),
309 (not_empty "framework"), (forward "framework"),
310 (not_empty "weak_framework"), (forward "weak_framework"),
311 (not_empty "filelist"), (forward "filelist"),
312 (switch_on "m32"), (forward "m32"),
313 (switch_on "m64"), (forward "m64"),
314 (not_empty "l"), (forward "l"),
315 (not_empty "Xlinker"), (forward "Xlinker"),
316 (not_empty "Wl,"), (forward "Wl,"),
317 (switch_on "nostartfiles"), (forward "nostartfiles"),
318 (switch_on "nodefaultlibs"), (forward "nodefaultlibs"),
319 (switch_on "nostdlib"), (forward "nostdlib"),
320 (switch_on "pie"), (forward "pie"),
321 (switch_on "rdynamic"), (forward "rdynamic"),
322 (switch_on "s"), (forward "s"),
323 (switch_on "static"), (forward "static"),
324 (switch_on "static-libgcc"), (forward "static-libgcc"),
325 (switch_on "shared"), (forward "shared"),
326 (switch_on "shared-libgcc"), (forward "shared-libgcc"),
327 (not_empty "T"), (forward "T"),
328 (not_empty "u"), (forward "u"),
329 (switch_on "dynamiclib"), (forward "dynamiclib"),
330 (switch_on "prebind"), (forward "prebind"),
331 (switch_on "dead_strip"), (forward "dead_strip"),
332 (switch_on "single_module"), (forward "single_module"),
333 (not_empty "compatibility_version"),
334 (forward "compatibility_version"),
335 (not_empty "current_version"), (forward "current_version"),
336 (not_empty "install_name"), (forward "install_name")))
340 def llvm_gcc_linker : llvm_gcc_based_linker<"@LLVMGCCCOMMAND@",
341 (not (or (parameter_equals "linker", "g++"),
342 (parameter_equals "linker", "c++")))>;
343 // Alternative linker for C++
344 def llvm_gcc_cpp_linker : llvm_gcc_based_linker<"@LLVMGXXCOMMAND@",
345 (or (parameter_equals "linker", "g++"),
346 (parameter_equals "linker", "c++"))>;
350 def LanguageMap : LanguageMap<[
351 (lang_to_suffixes "precompiled-header", ["gch", "pch"]),
352 (lang_to_suffixes "c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]),
353 (lang_to_suffixes "c++-header", "hpp"),
354 (lang_to_suffixes "c", "c"),
355 (lang_to_suffixes "c-header", "h"),
356 (lang_to_suffixes "c-cpp-output", "i"),
357 (lang_to_suffixes "objective-c-cpp-output", "mi"),
358 (lang_to_suffixes "objective-c++", "mm"),
359 (lang_to_suffixes "objective-c++-header", "hmm"),
360 (lang_to_suffixes "objective-c", "m"),
361 (lang_to_suffixes "objective-c-header", "hm"),
362 (lang_to_suffixes "assembler", "s"),
363 (lang_to_suffixes "assembler-with-cpp", "S"),
364 (lang_to_suffixes "llvm-assembler", "ll"),
365 (lang_to_suffixes "llvm-bitcode", "bc"),
366 (lang_to_suffixes "object-code", ["o", "*empty*"]),
367 (lang_to_suffixes "static-library", ["a", "lib"]),
368 (lang_to_suffixes "dynamic-library", ["so", "dylib", "dll"]),
369 (lang_to_suffixes "executable", ["out"])
374 def CompilationGraph : CompilationGraph<[
375 (edge "root", "llvm_gcc_c"),
376 (edge "root", "llvm_gcc_assembler"),
377 (edge "root", "llvm_gcc_cpp"),
378 (edge "root", "llvm_gcc_m"),
379 (edge "root", "llvm_gcc_mxx"),
380 (edge "root", "llc"),
382 (edge "root", "llvm_gcc_c_pch"),
383 (edge "root", "llvm_gcc_cpp_pch"),
384 (edge "root", "llvm_gcc_m_pch"),
385 (edge "root", "llvm_gcc_mxx_pch"),
387 (edge "llvm_gcc_c", "llc"),
388 (edge "llvm_gcc_cpp", "llc"),
389 (edge "llvm_gcc_m", "llc"),
390 (edge "llvm_gcc_mxx", "llc"),
391 (edge "llvm_as", "llc"),
393 (optional_edge "root", "llvm_as",
394 (case (switch_on "emit-llvm"), (inc_weight))),
395 (optional_edge "llvm_gcc_c", "opt",
396 (case (switch_on "opt"), (inc_weight))),
397 (optional_edge "llvm_gcc_cpp", "opt",
398 (case (switch_on "opt"), (inc_weight))),
399 (optional_edge "llvm_gcc_m", "opt",
400 (case (switch_on "opt"), (inc_weight))),
401 (optional_edge "llvm_gcc_mxx", "opt",
402 (case (switch_on "opt"), (inc_weight))),
403 (optional_edge "llvm_as", "opt",
404 (case (switch_on "opt"), (inc_weight))),
407 (edge "llc", "llvm_gcc_assembler"),
408 (edge "llvm_gcc_assembler", "llvm_gcc_linker"),
409 (optional_edge "llvm_gcc_assembler", "llvm_gcc_cpp_linker",
411 (or (input_languages_contain "c++"),
412 (input_languages_contain "objective-c++")),
414 (or (parameter_equals "linker", "g++"),
415 (parameter_equals "linker", "c++")), (inc_weight))),
418 (edge "root", "llvm_gcc_linker"),
419 (optional_edge "root", "llvm_gcc_cpp_linker",
421 (or (input_languages_contain "c++"),
422 (input_languages_contain "objective-c++")),
424 (or (parameter_equals "linker", "g++"),
425 (parameter_equals "linker", "c++")), (inc_weight)))