8f928cc40cb60f1d746b44e89642a11941221730
[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_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 (and (switch_on "O3"), (any_switch_on ["O0", "O1", "O2"])),
95            (unset_option ["O0", "O1", "O2"]),
96       (and (switch_on "O2"), (any_switch_on ["O0", "O1"])),
97            (unset_option ["O0", "O1"]),
98       (and (switch_on "O1"), (switch_on "O0")),
99            (unset_option "O0"))
100 >;
101
102
103 // Tools
104
105 class llvm_gcc_based <string cmd_prefix, string in_lang, string E_ext> : Tool<
106 [(in_language in_lang),
107  (out_language "llvm-bitcode"),
108  (output_suffix "bc"),
109  (cmd_line (case
110             (switch_on "E"),
111               (case (not_empty "o"),
112                     !strconcat(cmd_prefix, " -E $INFILE -o $OUTFILE"),
113                     (default),
114                     !strconcat(cmd_prefix, " -E $INFILE")),
115             (switch_on "fsyntax-only"),
116               !strconcat(cmd_prefix, " -fsyntax-only $INFILE"),
117             (and (switch_on "S"), (switch_on "emit-llvm")),
118               !strconcat(cmd_prefix, " -S $INFILE -o $OUTFILE -emit-llvm"),
119             (default),
120               !strconcat(cmd_prefix, " -c $INFILE -o $OUTFILE -emit-llvm"))),
121  (actions
122      (case
123          (and (multiple_input_files), (or (switch_on "S"), (switch_on "c"))),
124               (error "cannot specify -o with -c or -S with multiple files"),
125          (switch_on "E"), [(stop_compilation), (output_suffix E_ext)],
126          (and (switch_on "emit-llvm"), (switch_on "S")),
127               [(output_suffix "ll"), (stop_compilation)],
128          (and (switch_on "emit-llvm"), (switch_on "c")), (stop_compilation),
129          (switch_on "fsyntax-only"), (stop_compilation),
130          (not_empty "include"), (forward "include"),
131          (not_empty "save-temps"), (append_cmd "-save-temps"),
132          (not_empty "I"), (forward "I"),
133          (not_empty "F"), (forward "F"),
134          (not_empty "D"), (forward "D"),
135          (not_empty "march"), (forward "march"),
136          (not_empty "mtune"), (forward "mtune"),
137          (not_empty "mcpu"), (forward "mcpu"),
138          (not_empty "m"), (forward "m"),
139          (switch_on "m32"), (forward "m32"),
140          (switch_on "m64"), (forward "m64"),
141          (switch_on "O1"), (forward "O1"),
142          (switch_on "O2"), (forward "O2"),
143          (switch_on "O3"), (forward "O3"),
144          (switch_on "fPIC"), (forward "fPIC"),
145          (switch_on "mdynamic-no-pic"), (forward "mdynamic-no-pic"),
146          (not_empty "MF"), (forward "MF"),
147          (not_empty "MT"), (forward "MT"))),
148  (sink)
149 ]>;
150
151 def llvm_gcc_c : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x c", "c", "i">;
152 def llvm_gcc_cpp : llvm_gcc_based<"@LLVMGXXCOMMAND@ -x c++", "c++", "i">;
153 def llvm_gcc_m : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c",
154                                                   "objective-c", "mi">;
155 def llvm_gcc_mxx : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c++",
156                                   "objective-c++", "mi">;
157
158 def opt : Tool<
159 [(in_language "llvm-bitcode"),
160  (out_language "llvm-bitcode"),
161  (output_suffix "bc"),
162  (actions (case (not_empty "Wo,"), (forward_value "Wo,"),
163                 (switch_on "O1"), (forward "O1"),
164                 (switch_on "O2"), (forward "O2"),
165                 (switch_on "O3"), (forward "O3"))),
166  (cmd_line "opt -f $INFILE -o $OUTFILE")
167 ]>;
168
169 def llvm_as : Tool<
170 [(in_language "llvm-assembler"),
171  (out_language "llvm-bitcode"),
172  (output_suffix "bc"),
173  (cmd_line "llvm-as $INFILE -o $OUTFILE"),
174  (actions (case (switch_on "emit-llvm"), (stop_compilation)))
175 ]>;
176
177 def llvm_gcc_assembler : Tool<
178 [(in_language "assembler"),
179  (out_language "object-code"),
180  (output_suffix "o"),
181  (cmd_line "@LLVMGCCCOMMAND@ -c -x assembler $INFILE -o $OUTFILE"),
182  (actions (case
183           (switch_on "c"), (stop_compilation),
184           (not_empty "Wa,"), (forward_value "Wa,")))
185 ]>;
186
187 def llc : Tool<
188 [(in_language ["llvm-bitcode", "llvm-assembler"]),
189  (out_language "assembler"),
190  (output_suffix "s"),
191  (cmd_line "llc -f $INFILE -o $OUTFILE"),
192  (actions (case
193           (switch_on "S"), (stop_compilation),
194           (switch_on "O0"), (forward "O0"),
195           (switch_on "O1"), (forward "O1"),
196           (switch_on "O2"), (forward "O2"),
197           (switch_on "O3"), (forward "O3"),
198           (switch_on "fPIC"), (append_cmd "-relocation-model=pic"),
199           (switch_on "mdynamic-no-pic"),
200                      (append_cmd "-relocation-model=dynamic-no-pic"),
201           (not_empty "march"), (forward "mcpu"),
202           (not_empty "mtune"), (forward "mcpu"),
203           (not_empty "mcpu"), (forward "mcpu"),
204           (not_empty "m"), (forward_transformed_value "m", "ConvertToMAttr"),
205           (not_empty "Wllc,"), (forward_value "Wllc,")))
206 ]>;
207
208 // Base class for linkers
209 class llvm_gcc_based_linker <string cmd_prefix> : Tool<
210 [(in_language "object-code"),
211  (out_language "executable"),
212  (output_suffix "out"),
213  (cmd_line !strconcat(cmd_prefix, " $INFILE -o $OUTFILE")),
214  (join),
215  (actions (case
216           (switch_on "pthread"), (append_cmd "-lpthread"),
217           (not_empty "L"), (forward "L"),
218           (not_empty "F"), (forward "F"),
219           (not_empty "framework"), (forward "framework"),
220           (not_empty "weak_framework"), (forward "weak_framework"),
221           (switch_on "m32"), (forward "m32"),
222           (switch_on "m64"), (forward "m64"),
223           (not_empty "l"), (forward "l"),
224           (not_empty "Wl,"), (forward "Wl,")))
225 ]>;
226
227 // Default linker
228 def llvm_gcc_linker : llvm_gcc_based_linker<"@LLVMGCCCOMMAND@">;
229 // Alternative linker for C++
230 def llvm_gcc_cpp_linker : llvm_gcc_based_linker<"@LLVMGXXCOMMAND@">;
231
232 // Language map
233
234 def LanguageMap : LanguageMap<
235     [LangToSuffixes<"c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]>,
236      LangToSuffixes<"c", ["c"]>,
237      LangToSuffixes<"c-cpp-output", ["i"]>,
238      LangToSuffixes<"objective-c-cpp-output", ["mi"]>,
239      LangToSuffixes<"objective-c++", ["mm"]>,
240      LangToSuffixes<"objective-c", ["m"]>,
241      LangToSuffixes<"assembler", ["s"]>,
242      LangToSuffixes<"assembler-with-cpp", ["S"]>,
243      LangToSuffixes<"llvm-assembler", ["ll"]>,
244      LangToSuffixes<"llvm-bitcode", ["bc"]>,
245      LangToSuffixes<"object-code", ["o"]>,
246      LangToSuffixes<"executable", ["out"]>
247      ]>;
248
249 // Compilation graph
250
251 def CompilationGraph : CompilationGraph<[
252     Edge<"root", "llvm_gcc_c">,
253     Edge<"root", "llvm_gcc_assembler">,
254     Edge<"root", "llvm_gcc_cpp">,
255     Edge<"root", "llvm_gcc_m">,
256     Edge<"root", "llvm_gcc_mxx">,
257     Edge<"root", "llc">,
258
259     Edge<"llvm_gcc_c", "llc">,
260     Edge<"llvm_gcc_cpp", "llc">,
261     Edge<"llvm_gcc_m", "llc">,
262     Edge<"llvm_gcc_mxx", "llc">,
263     Edge<"llvm_as", "llc">,
264
265     OptionalEdge<"root", "llvm_as",
266                          (case (switch_on "emit-llvm"), (inc_weight))>,
267     OptionalEdge<"llvm_gcc_c", "opt", (case (switch_on "opt"), (inc_weight))>,
268     OptionalEdge<"llvm_gcc_cpp", "opt", (case (switch_on "opt"), (inc_weight))>,
269     OptionalEdge<"llvm_gcc_m", "opt", (case (switch_on "opt"), (inc_weight))>,
270     OptionalEdge<"llvm_gcc_mxx", "opt", (case (switch_on "opt"), (inc_weight))>,
271     OptionalEdge<"llvm_as", "opt", (case (switch_on "opt"), (inc_weight))>,
272     Edge<"opt", "llc">,
273
274     Edge<"llc", "llvm_gcc_assembler">,
275     Edge<"llvm_gcc_assembler", "llvm_gcc_linker">,
276     OptionalEdge<"llvm_gcc_assembler", "llvm_gcc_cpp_linker",
277                  (case
278                      (or (input_languages_contain "c++"),
279                          (input_languages_contain "objective-c++")),
280                      (inc_weight),
281                      (or (parameter_equals "linker", "g++"),
282                          (parameter_equals "linker", "c++")), (inc_weight))>,
283
284
285     Edge<"root", "llvm_gcc_linker">,
286     OptionalEdge<"root", "llvm_gcc_cpp_linker",
287                  (case
288                      (or (input_languages_contain "c++"),
289                          (input_languages_contain "objective-c++")),
290                      (inc_weight),
291                      (or (parameter_equals "linker", "g++"),
292                          (parameter_equals "linker", "c++")), (inc_weight))>
293     ]>;