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