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