Forward -O0 to llvm-gcc.
[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")),
29  (switch_option "O1",
30     (help "Optimization level 1")),
31  (switch_option "O2",
32     (help "Optimization level 2")),
33  (switch_option "O3",
34     (help "Optimization level 3")),
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  (parameter_option "linker",
50     (help "Choose linker (possible values: gcc, g++)")),
51  (parameter_option "mtune",
52     (help "Target a specific CPU type"), (hidden)),
53  (parameter_option "march",
54     (help "A synonym for -mtune"), (hidden)),
55  (parameter_option "mcpu",
56     (help "A deprecated synonym for -mtune"), (hidden)),
57  (parameter_option "MF",
58     (help "Specify a file to write dependencies to"), (hidden)),
59  (parameter_list_option "MT",
60     (help "Change the name of the rule emitted by dependency generation"),
61     (hidden)),
62  (parameter_list_option "include",
63     (help "Include the named file prior to preprocessing")),
64  (parameter_list_option "framework",
65     (help "Specifies a framework to link against")),
66  (parameter_list_option "weak_framework",
67     (help "Specifies a framework to weakly link against"), (hidden)),
68  (prefix_list_option "F",
69     (help "Add a directory to framework search path")),
70  (prefix_list_option "I",
71     (help "Add a directory to include path")),
72  (prefix_list_option "D",
73     (help "Define a macro")),
74  (prefix_list_option "Wa,", (comma_separated),
75     (help "Pass options to assembler")),
76  (prefix_list_option "Wllc,", (comma_separated),
77     (help "Pass options to llc")),
78  (prefix_list_option "L",
79     (help "Add a directory to link path")),
80  (prefix_list_option "l",
81     (help "Search a library when linking")),
82  (prefix_list_option "Wl,",
83     (help "Pass options to linker")),
84  (prefix_list_option "Wo,", (comma_separated),
85     (help "Pass options to opt")),
86  (prefix_list_option "m",
87      (help "Enable or disable various extensions (-mmmx, -msse, etc.)"),
88      (hidden))
89 ]>;
90
91 // Option preprocessor.
92
93 def Preprocess : OptionPreprocessor<
94 (case (not (any_switch_on ["O0", "O1", "O2", "O3"])),
95            (set_option "O2"),
96       (and (switch_on "O3"), (any_switch_on ["O0", "O1", "O2"])),
97            (unset_option ["O0", "O1", "O2"]),
98       (and (switch_on "O2"), (any_switch_on ["O0", "O1"])),
99            (unset_option ["O0", "O1"]),
100       (switch_on ["O1", "O0"]),
101            (unset_option "O0"))
102 >;
103
104 // Tools
105
106 class llvm_gcc_based <string cmd_prefix, string in_lang, string E_ext> : Tool<
107 [(in_language in_lang),
108  (out_language "llvm-bitcode"),
109  (output_suffix "bc"),
110  (cmd_line (case
111             (switch_on "E"),
112               (case (not_empty "o"),
113                     !strconcat(cmd_prefix, " -E $INFILE -o $OUTFILE"),
114                     (default),
115                     !strconcat(cmd_prefix, " -E $INFILE")),
116             (switch_on "fsyntax-only"),
117               !strconcat(cmd_prefix, " -fsyntax-only $INFILE"),
118             (and (switch_on "S"), (switch_on "emit-llvm")),
119               !strconcat(cmd_prefix, " -S $INFILE -o $OUTFILE -emit-llvm"),
120             (default),
121               !strconcat(cmd_prefix, " -c $INFILE -o $OUTFILE -emit-llvm"))),
122  (actions
123      (case
124          (and (multiple_input_files), (or (switch_on "S"), (switch_on "c"))),
125               (error "cannot specify -o with -c or -S with multiple files"),
126          (switch_on "E"), [(stop_compilation), (output_suffix E_ext)],
127          (switch_on ["emit-llvm", "S"]),
128               [(output_suffix "ll"), (stop_compilation)],
129          (switch_on ["emit-llvm", "c"]), (stop_compilation),
130          (switch_on "fsyntax-only"), (stop_compilation),
131          (not_empty "include"), (forward "include"),
132          (not_empty "save-temps"), (append_cmd "-save-temps"),
133          (not_empty "I"), (forward "I"),
134          (not_empty "F"), (forward "F"),
135          (not_empty "D"), (forward "D"),
136          (not_empty "march"), (forward "march"),
137          (not_empty "mtune"), (forward "mtune"),
138          (not_empty "mcpu"), (forward "mcpu"),
139          (not_empty "m"), (forward "m"),
140          (switch_on "m32"), (forward "m32"),
141          (switch_on "m64"), (forward "m64"),
142          (switch_on "O0"), (forward "O0"),
143          (switch_on "O1"), (forward "O1"),
144          (switch_on "O2"), (forward "O2"),
145          (switch_on "O3"), (forward "O3"),
146          (switch_on "fPIC"), (forward "fPIC"),
147          (switch_on "mdynamic-no-pic"), (forward "mdynamic-no-pic"),
148          (not_empty "MF"), (forward "MF"),
149          (not_empty "MT"), (forward "MT"))),
150  (sink)
151 ]>;
152
153 def llvm_gcc_c : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x c", "c", "i">;
154 def llvm_gcc_cpp : llvm_gcc_based<"@LLVMGXXCOMMAND@ -x c++", "c++", "i">;
155 def llvm_gcc_m : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c",
156                                                   "objective-c", "mi">;
157 def llvm_gcc_mxx : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c++",
158                                   "objective-c++", "mi">;
159
160 def opt : Tool<
161 [(in_language "llvm-bitcode"),
162  (out_language "llvm-bitcode"),
163  (output_suffix "bc"),
164  (actions (case (not_empty "Wo,"), (forward_value "Wo,"),
165                 (switch_on "O1"), (forward "O1"),
166                 (switch_on "O2"), (forward "O2"),
167                 (switch_on "O3"), (forward "O3"))),
168  (cmd_line "opt -f $INFILE -o $OUTFILE")
169 ]>;
170
171 def llvm_as : Tool<
172 [(in_language "llvm-assembler"),
173  (out_language "llvm-bitcode"),
174  (output_suffix "bc"),
175  (cmd_line "llvm-as $INFILE -o $OUTFILE"),
176  (actions (case (switch_on "emit-llvm"), (stop_compilation)))
177 ]>;
178
179 def llvm_gcc_assembler : Tool<
180 [(in_language "assembler"),
181  (out_language "object-code"),
182  (output_suffix "o"),
183  (cmd_line "@LLVMGCCCOMMAND@ -c -x assembler $INFILE -o $OUTFILE"),
184  (actions (case
185           (switch_on "c"), (stop_compilation),
186           (not_empty "Wa,"), (forward_value "Wa,")))
187 ]>;
188
189 def llc : Tool<
190 [(in_language ["llvm-bitcode", "llvm-assembler"]),
191  (out_language "assembler"),
192  (output_suffix "s"),
193  (cmd_line "llc -f $INFILE -o $OUTFILE"),
194  (actions (case
195           (switch_on "S"), (stop_compilation),
196           (switch_on "O0"), (forward "O0"),
197           (switch_on "O1"), (forward "O1"),
198           (switch_on "O2"), (forward "O2"),
199           (switch_on "O3"), (forward "O3"),
200           (switch_on "fPIC"), (append_cmd "-relocation-model=pic"),
201           (switch_on "mdynamic-no-pic"),
202                      (append_cmd "-relocation-model=dynamic-no-pic"),
203           (not_empty "march"), (forward "mcpu"),
204           (not_empty "mtune"), (forward "mcpu"),
205           (not_empty "mcpu"), (forward "mcpu"),
206           (not_empty "m"), (forward_transformed_value "m", "ConvertToMAttr"),
207           (not_empty "Wllc,"), (forward_value "Wllc,")))
208 ]>;
209
210 // Base class for linkers
211 class llvm_gcc_based_linker <string cmd_prefix> : Tool<
212 [(in_language "object-code"),
213  (out_language "executable"),
214  (output_suffix "out"),
215  (cmd_line !strconcat(cmd_prefix, " $INFILE -o $OUTFILE")),
216  (join),
217  (actions (case
218           (switch_on "pthread"), (append_cmd "-lpthread"),
219           (not_empty "L"), (forward "L"),
220           (not_empty "F"), (forward "F"),
221           (not_empty "framework"), (forward "framework"),
222           (not_empty "weak_framework"), (forward "weak_framework"),
223           (switch_on "m32"), (forward "m32"),
224           (switch_on "m64"), (forward "m64"),
225           (not_empty "l"), (forward "l"),
226           (not_empty "Wl,"), (forward "Wl,")))
227 ]>;
228
229 // Default linker
230 def llvm_gcc_linker : llvm_gcc_based_linker<"@LLVMGCCCOMMAND@">;
231 // Alternative linker for C++
232 def llvm_gcc_cpp_linker : llvm_gcc_based_linker<"@LLVMGXXCOMMAND@">;
233
234 // Language map
235
236 def LanguageMap : LanguageMap<
237     [LangToSuffixes<"c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]>,
238      LangToSuffixes<"c", ["c"]>,
239      LangToSuffixes<"c-cpp-output", ["i"]>,
240      LangToSuffixes<"objective-c-cpp-output", ["mi"]>,
241      LangToSuffixes<"objective-c++", ["mm"]>,
242      LangToSuffixes<"objective-c", ["m"]>,
243      LangToSuffixes<"assembler", ["s"]>,
244      LangToSuffixes<"assembler-with-cpp", ["S"]>,
245      LangToSuffixes<"llvm-assembler", ["ll"]>,
246      LangToSuffixes<"llvm-bitcode", ["bc"]>,
247      LangToSuffixes<"object-code", ["o"]>,
248      LangToSuffixes<"executable", ["out"]>
249      ]>;
250
251 // Compilation graph
252
253 def CompilationGraph : CompilationGraph<[
254     Edge<"root", "llvm_gcc_c">,
255     Edge<"root", "llvm_gcc_assembler">,
256     Edge<"root", "llvm_gcc_cpp">,
257     Edge<"root", "llvm_gcc_m">,
258     Edge<"root", "llvm_gcc_mxx">,
259     Edge<"root", "llc">,
260
261     Edge<"llvm_gcc_c", "llc">,
262     Edge<"llvm_gcc_cpp", "llc">,
263     Edge<"llvm_gcc_m", "llc">,
264     Edge<"llvm_gcc_mxx", "llc">,
265     Edge<"llvm_as", "llc">,
266
267     OptionalEdge<"root", "llvm_as",
268                          (case (switch_on "emit-llvm"), (inc_weight))>,
269     OptionalEdge<"llvm_gcc_c", "opt", (case (switch_on "opt"), (inc_weight))>,
270     OptionalEdge<"llvm_gcc_cpp", "opt", (case (switch_on "opt"), (inc_weight))>,
271     OptionalEdge<"llvm_gcc_m", "opt", (case (switch_on "opt"), (inc_weight))>,
272     OptionalEdge<"llvm_gcc_mxx", "opt", (case (switch_on "opt"), (inc_weight))>,
273     OptionalEdge<"llvm_as", "opt", (case (switch_on "opt"), (inc_weight))>,
274     Edge<"opt", "llc">,
275
276     Edge<"llc", "llvm_gcc_assembler">,
277     Edge<"llvm_gcc_assembler", "llvm_gcc_linker">,
278     OptionalEdge<"llvm_gcc_assembler", "llvm_gcc_cpp_linker",
279                  (case
280                      (or (input_languages_contain "c++"),
281                          (input_languages_contain "objective-c++")),
282                      (inc_weight),
283                      (or (parameter_equals "linker", "g++"),
284                          (parameter_equals "linker", "c++")), (inc_weight))>,
285
286
287     Edge<"root", "llvm_gcc_linker">,
288     OptionalEdge<"root", "llvm_gcc_cpp_linker",
289                  (case
290                      (or (input_languages_contain "c++"),
291                          (input_languages_contain "objective-c++")),
292                      (inc_weight),
293                      (or (parameter_equals "linker", "g++"),
294                          (parameter_equals "linker", "c++")), (inc_weight))>
295     ]>;