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