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