llvmc: remove dynamic plugins.
[oota-llvm.git] / tools / llvmc / src / Base.td.in
1 //===- Base.td - LLVMC toolchain descriptions --------------*- tablegen -*-===//
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 //
10 // This file contains compilation graph description used by llvmc.
11 //
12 //===----------------------------------------------------------------------===//
13
14
15 // Options
16
17 def OptList : OptionList<[
18  (switch_option "emit-llvm",
19     (help "Emit LLVM .ll files instead of native object files")),
20  (switch_option "E",
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")),
24  (switch_option "opt",
25     (help "Enable opt")),
26  (switch_option "O0",
27     (help "Turn off optimization"), (zero_or_more)),
28  (switch_option "O1",
29     (help "Optimization level 1"), (zero_or_more)),
30  (switch_option "O2",
31     (help "Optimization level 2"), (zero_or_more)),
32  (switch_option "O3",
33     (help "Optimization level 3"), (zero_or_more)),
34  (switch_option "S",
35     (help "Stop after compilation, do not assemble")),
36  (switch_option "c",
37     (help "Compile and assemble, but do not link")),
38  (switch_option "pthread",
39     (help "Enable threads")),
40  (switch_option "m32",
41     (help "Generate code for a 32-bit environment"), (hidden)),
42  (switch_option "m64",
43     (help "Generate code for a 64-bit environment"), (hidden)),
44  (switch_option "fPIC",
45     (help "Relocation model: PIC"), (hidden)),
46  (switch_option "mdynamic-no-pic",
47     (help "Relocation model: dynamic-no-pic"), (hidden)),
48  (switch_option "shared",
49      (help "Create a DLL instead of the regular executable")),
50  (parameter_option "linker",
51     (help "Choose linker (possible values: gcc, g++)")),
52  (parameter_option "mtune",
53     (help "Target a specific CPU type"), (hidden), (forward_not_split)),
54
55  // TODO: Add a conditional compilation mechanism to make Darwin-only options
56  // like '-arch' really Darwin-only.
57
58  (parameter_option "arch",
59     (help "Compile for the specified target architecture"), (hidden)),
60  (parameter_option "march",
61     (help "A synonym for -mtune"), (hidden), (forward_not_split)),
62  (parameter_option "mcpu",
63     (help "A deprecated synonym for -mtune"), (hidden), (forward_not_split)),
64  (switch_option "mfix-and-continue",
65     (help "Needed by gdb to load .o files dynamically"), (hidden)),
66  (parameter_option "MF",
67     (help "Specify a file to write dependencies to"), (hidden)),
68  (parameter_list_option "MT",
69     (help "Change the name of the rule emitted by dependency generation"),
70     (hidden)),
71  (parameter_list_option "include",
72     (help "Include the named file prior to preprocessing")),
73  (parameter_list_option "iquote",
74     (help "Search dir only for files requested with #inlcude \"file\""),
75     (hidden)),
76  (parameter_list_option "framework",
77     (help "Specifies a framework to link against")),
78  (parameter_list_option "weak_framework",
79     (help "Specifies a framework to weakly link against"), (hidden)),
80  (parameter_option "filelist", (hidden),
81     (help "Link the files listed in file")),
82  (prefix_list_option "F",
83     (help "Add a directory to framework search path")),
84  (prefix_list_option "I",
85     (help "Add a directory to include path")),
86  (prefix_list_option "D",
87     (help "Define a macro")),
88  (parameter_list_option "Xpreprocessor", (hidden),
89     (help "Pass options to preprocessor")),
90  (prefix_list_option "Wa,", (comma_separated),
91     (help "Pass options to assembler")),
92  (parameter_list_option "Xassembler", (hidden),
93     (help "Pass options to assembler")),
94  (prefix_list_option "Wllc,", (comma_separated),
95     (help "Pass options to llc")),
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  (prefix_list_option "Wl,",
101     (help "Pass options to linker")),
102  (parameter_list_option "Xlinker", (hidden),
103     (help "Pass options to linker")),
104  (prefix_list_option "Wo,", (comma_separated),
105     (help "Pass options to opt")),
106  (prefix_list_option "m",
107      (help "Enable or disable various extensions (-mmmx, -msse, etc.)"),
108      (hidden)),
109  (switch_option "dynamiclib", (hidden),
110      (help "Produce a dynamic library")),
111  (switch_option "prebind", (hidden),
112      (help "Prebind all undefined symbols")),
113  (switch_option "dead_strip", (hidden),
114      (help "Remove unreachable blocks of code")),
115  (switch_option "single_module", (hidden),
116      (help "Build the library so it contains only one module")),
117  (parameter_option "install_name", (hidden),
118      (help "File name the library will be installed in")),
119  (parameter_option "compatibility_version", (hidden),
120      (help "Compatibility version number")),
121  (parameter_option "current_version", (hidden),
122      (help "Current version number"))
123 ]>;
124
125 // Option preprocessor.
126
127 def Preprocess : OptionPreprocessor<
128 (case (not (any_switch_on ["O0", "O1", "O2", "O3"])),
129            (set_option "O2"),
130       (and (switch_on "O3"), (any_switch_on ["O0", "O1", "O2"])),
131            (unset_option ["O0", "O1", "O2"]),
132       (and (switch_on "O2"), (any_switch_on ["O0", "O1"])),
133            (unset_option ["O0", "O1"]),
134       (switch_on ["O1", "O0"]),
135            (unset_option "O0"))
136 >;
137
138 // Tools
139
140 class llvm_gcc_based <string cmd_prefix, string in_lang,
141                       string E_ext, string out_lang> : Tool<
142 [(in_language in_lang),
143  (out_language "llvm-bitcode"),
144  (output_suffix out_lang),
145  (command cmd_prefix),
146  (actions
147      (case
148          (and (not_empty "o"),
149               (multiple_input_files), (or (switch_on "S"), (switch_on "c"))),
150               (error "cannot specify -o with -c or -S with multiple files"),
151          (switch_on "E"),
152               [(forward "E"), (stop_compilation), (output_suffix E_ext)],
153          (and (switch_on "E"), (empty "o")), (no_out_file),
154          (switch_on ["emit-llvm", "S"]),
155               [(output_suffix "ll"), (stop_compilation)],
156          (switch_on ["emit-llvm", "c"]), (stop_compilation),
157          (switch_on "fsyntax-only"), [(forward "fsyntax-only"),
158                                       (no_out_file), (stop_compilation)],
159          (switch_on ["S", "emit-llvm"]), [(forward "S"), (forward "emit-llvm")],
160          (not (or (switch_on ["S", "emit-llvm"]), (switch_on "fsyntax-only"))),
161              [(append_cmd "-c"), (append_cmd "-emit-llvm")],
162
163          // Forwards
164          (not_empty "Xpreprocessor"), (forward "Xpreprocessor"),
165          (not_empty "include"), (forward "include"),
166          (not_empty "iquote"), (forward "iquote"),
167          (not_empty "save-temps"), (append_cmd "-save-temps"),
168          (not_empty "I"), (forward "I"),
169          (not_empty "F"), (forward "F"),
170          (not_empty "D"), (forward "D"),
171          (not_empty "arch"), (forward "arch"),
172          (not_empty "march"), (forward "march"),
173          (not_empty "mtune"), (forward "mtune"),
174          (not_empty "mcpu"), (forward "mcpu"),
175          (not_empty "m"), (forward "m"),
176          (switch_on "mfix-and-continue"), (forward "mfix-and-continue"),
177          (switch_on "m32"), (forward "m32"),
178          (switch_on "m64"), (forward "m64"),
179          (switch_on "O0"), (forward "O0"),
180          (switch_on "O1"), (forward "O1"),
181          (switch_on "O2"), (forward "O2"),
182          (switch_on "O3"), (forward "O3"),
183          (switch_on "fPIC"), (forward "fPIC"),
184          (switch_on "mdynamic-no-pic"), (forward "mdynamic-no-pic"),
185          (not_empty "MF"), (forward "MF"),
186          (not_empty "MT"), (forward "MT"))),
187  (sink)
188 ]>;
189
190 def llvm_gcc_c : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x c", "c", "i", "bc">;
191 def llvm_gcc_cpp : llvm_gcc_based<"@LLVMGXXCOMMAND@ -x c++", "c++", "i", "bc">;
192 def llvm_gcc_m : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c",
193                                                   "objective-c", "mi", "bc">;
194 def llvm_gcc_mxx : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c++",
195                                   "objective-c++", "mi", "bc">;
196
197 def llvm_gcc_c_pch : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x c-header",
198                                                       "c-header", "i", "gch">;
199 def llvm_gcc_cpp_pch : llvm_gcc_based<"@LLVMGXXCOMMAND@ -x c++-header",
200                                                         "c++-header",
201                                                         "i", "gch">;
202 def llvm_gcc_m_pch : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c-header",
203                                                       "objective-c-header",
204                                                       "mi", "gch">;
205 def llvm_gcc_mxx_pch
206     : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c++-header",
207                                        "objective-c++-header", "mi", "gch">;
208
209 def opt : Tool<
210 [(in_language "llvm-bitcode"),
211  (out_language "llvm-bitcode"),
212  (output_suffix "bc"),
213  (actions (case (not_empty "Wo,"), (forward_value "Wo,"),
214                 (switch_on "O1"), (forward "O1"),
215                 (switch_on "O2"), (forward "O2"),
216                 (switch_on "O3"), (forward "O3"))),
217  (command "opt -f")
218 ]>;
219
220 def llvm_as : Tool<
221 [(in_language "llvm-assembler"),
222  (out_language "llvm-bitcode"),
223  (output_suffix "bc"),
224  (command "llvm-as"),
225  (actions (case (switch_on "emit-llvm"), (stop_compilation)))
226 ]>;
227
228 def llvm_gcc_assembler : Tool<
229 [(in_language "assembler"),
230  (out_language "object-code"),
231  (output_suffix "o"),
232  (command "@LLVMGCCCOMMAND@ -c -x assembler"),
233  (actions (case
234           (switch_on "c"), (stop_compilation),
235           (not_empty "arch"), (forward "arch"),
236           (not_empty "Xassembler"), (forward "Xassembler"),
237           (switch_on "m32"), (forward "m32"),
238           (switch_on "m64"), (forward "m64"),
239           (not_empty "Wa,"), (forward "Wa,")))
240 ]>;
241
242 def llc : Tool<
243 [(in_language ["llvm-bitcode", "llvm-assembler"]),
244  (out_language "assembler"),
245  (output_suffix "s"),
246  (command "llc"),
247  (actions (case
248           (switch_on "S"), (stop_compilation),
249           (switch_on "O0"), (forward "O0"),
250           (switch_on "O1"), (forward "O1"),
251           (switch_on "O2"), (forward "O2"),
252           (switch_on "O3"), (forward "O3"),
253           (switch_on "fPIC"), (append_cmd "-relocation-model=pic"),
254           (switch_on "mdynamic-no-pic"),
255                      (append_cmd "-relocation-model=dynamic-no-pic"),
256           (not_empty "march"), (forward_as "mtune", "-mcpu"),
257           (not_empty "mtune"), (forward_as "mtune", "-mcpu"),
258           (not_empty "mcpu"), (forward "mcpu"),
259           (not_empty "m"), (forward_transformed_value "m", "ConvertToMAttr"),
260           (not_empty "Wllc,"), (forward_value "Wllc,")))
261 ]>;
262
263 // Base class for linkers
264 class llvm_gcc_based_linker <string cmd_prefix, dag on_empty> : Tool<
265 [(in_language ["object-code", "static-library"]),
266  (out_language "executable"),
267  (output_suffix "out"),
268  (command cmd_prefix),
269  (works_on_empty (case (and (not_empty "filelist"), on_empty), true,
270                        (default), false)),
271  (join),
272  (actions (case
273           (switch_on "pthread"), (append_cmd "-lpthread"),
274           (not_empty "L"), (forward "L"),
275           (not_empty "F"), (forward "F"),
276           (not_empty "arch"), (forward "arch"),
277           (not_empty "framework"), (forward "framework"),
278           (not_empty "weak_framework"), (forward "weak_framework"),
279           (not_empty "filelist"), (forward "filelist"),
280           (switch_on "m32"), (forward "m32"),
281           (switch_on "m64"), (forward "m64"),
282           (not_empty "l"), (forward "l"),
283           (not_empty "Xlinker"), (forward "Xlinker"),
284           (not_empty "Wl,"), (forward "Wl,"),
285           (switch_on "shared"), (forward "shared"),
286           (switch_on "dynamiclib"), (forward "dynamiclib"),
287           (switch_on "prebind"), (forward "prebind"),
288           (switch_on "dead_strip"), (forward "dead_strip"),
289           (switch_on "single_module"), (forward "single_module"),
290           (not_empty "compatibility_version"),
291                      (forward "compatibility_version"),
292           (not_empty "current_version"), (forward "current_version"),
293           (not_empty "install_name"), (forward "install_name")))
294 ]>;
295
296 // Default linker
297 def llvm_gcc_linker : llvm_gcc_based_linker<"@LLVMGCCCOMMAND@",
298     (not (or (parameter_equals "linker", "g++"),
299          (parameter_equals "linker", "c++")))>;
300 // Alternative linker for C++
301 def llvm_gcc_cpp_linker : llvm_gcc_based_linker<"@LLVMGXXCOMMAND@",
302     (or (parameter_equals "linker", "g++"),
303         (parameter_equals "linker", "c++"))>;
304
305 // Language map
306
307 def LanguageMap : LanguageMap<
308     [LangToSuffixes<"c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]>,
309      LangToSuffixes<"c++-header", ["hpp"]>,
310      LangToSuffixes<"c", ["c"]>,
311      LangToSuffixes<"c-header", ["h"]>,
312      LangToSuffixes<"c-cpp-output", ["i"]>,
313      LangToSuffixes<"objective-c-cpp-output", ["mi"]>,
314      LangToSuffixes<"objective-c++", ["mm"]>,
315      LangToSuffixes<"objective-c++-header", ["hmm"]>,
316      LangToSuffixes<"objective-c", ["m"]>,
317      LangToSuffixes<"objective-c-header", ["hm"]>,
318      LangToSuffixes<"assembler", ["s"]>,
319      LangToSuffixes<"assembler-with-cpp", ["S"]>,
320      LangToSuffixes<"llvm-assembler", ["ll"]>,
321      LangToSuffixes<"llvm-bitcode", ["bc"]>,
322      LangToSuffixes<"object-code", ["o", "*empty*"]>,
323      LangToSuffixes<"static-library", ["a", "lib"]>,
324      LangToSuffixes<"executable", ["out"]>
325      ]>;
326
327 // Compilation graph
328
329 def CompilationGraph : CompilationGraph<[
330     Edge<"root", "llvm_gcc_c">,
331     Edge<"root", "llvm_gcc_assembler">,
332     Edge<"root", "llvm_gcc_cpp">,
333     Edge<"root", "llvm_gcc_m">,
334     Edge<"root", "llvm_gcc_mxx">,
335     Edge<"root", "llc">,
336
337     Edge<"root", "llvm_gcc_c_pch">,
338     Edge<"root", "llvm_gcc_cpp_pch">,
339     Edge<"root", "llvm_gcc_m_pch">,
340     Edge<"root", "llvm_gcc_mxx_pch">,
341
342     Edge<"llvm_gcc_c", "llc">,
343     Edge<"llvm_gcc_cpp", "llc">,
344     Edge<"llvm_gcc_m", "llc">,
345     Edge<"llvm_gcc_mxx", "llc">,
346     Edge<"llvm_as", "llc">,
347
348     OptionalEdge<"root", "llvm_as",
349                          (case (switch_on "emit-llvm"), (inc_weight))>,
350     OptionalEdge<"llvm_gcc_c", "opt", (case (switch_on "opt"), (inc_weight))>,
351     OptionalEdge<"llvm_gcc_cpp", "opt", (case (switch_on "opt"), (inc_weight))>,
352     OptionalEdge<"llvm_gcc_m", "opt", (case (switch_on "opt"), (inc_weight))>,
353     OptionalEdge<"llvm_gcc_mxx", "opt", (case (switch_on "opt"), (inc_weight))>,
354     OptionalEdge<"llvm_as", "opt", (case (switch_on "opt"), (inc_weight))>,
355     Edge<"opt", "llc">,
356
357     Edge<"llc", "llvm_gcc_assembler">,
358     Edge<"llvm_gcc_assembler", "llvm_gcc_linker">,
359     OptionalEdge<"llvm_gcc_assembler", "llvm_gcc_cpp_linker",
360                  (case
361                      (or (input_languages_contain "c++"),
362                          (input_languages_contain "objective-c++")),
363                      (inc_weight),
364                      (or (parameter_equals "linker", "g++"),
365                          (parameter_equals "linker", "c++")), (inc_weight))>,
366
367
368     Edge<"root", "llvm_gcc_linker">,
369     OptionalEdge<"root", "llvm_gcc_cpp_linker",
370                  (case
371                      (or (input_languages_contain "c++"),
372                          (input_languages_contain "objective-c++")),
373                      (inc_weight),
374                      (or (parameter_equals "linker", "g++"),
375                          (parameter_equals "linker", "c++")), (inc_weight))>
376     ]>;