blob: 03d74ebcaab94bf12522549b5c44e210ecc385eb [file] [log] [blame]
Mikhail Glushenkov6d80d2b2009-10-08 04:40:28 +00001//===- Base.td - LLVMC toolchain descriptions --------------*- tablegen -*-===//
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +00002//
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//
Mikhail Glushenkov6d80d2b2009-10-08 04:40:28 +000010// This file contains compilation graph description used by llvmc.
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +000011//
12//===----------------------------------------------------------------------===//
13
Mikhail Glushenkove4a5ea32008-10-02 21:15:05 +000014include "llvm/CompilerDriver/Common.td"
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +000015
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +000016// Options
17
18def 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")),
Mikhail Glushenkov6b4967e2009-10-17 20:07:49 +000027 (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")),
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +000035 (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")),
Mikhail Glushenkovfa8182e2009-12-04 06:38:45 +000041 (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)),
Mikhail Glushenkov55cd7672009-12-01 09:47:11 +000045 (switch_option "fPIC",
46 (help "Relocation model: PIC"), (hidden)),
47 (switch_option "mdynamic-no-pic",
48 (help "Relocation model: dynamic-no-pic"), (hidden)),
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +000049 (parameter_option "linker",
50 (help "Choose linker (possible values: gcc, g++)")),
Mikhail Glushenkov3ab48832009-12-04 06:38:28 +000051 (parameter_option "mtune",
52 (help "Target a specific CPU type"), (hidden)),
Mikhail Glushenkov058b3f52010-01-26 14:55:44 +000053
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)),
Mikhail Glushenkov3ab48832009-12-04 06:38:28 +000059 (parameter_option "march",
60 (help "A synonym for -mtune"), (hidden)),
61 (parameter_option "mcpu",
62 (help "A deprecated synonym for -mtune"), (hidden)),
Mikhail Glushenkovb88c6f62010-02-13 22:37:00 +000063 (switch_option "mfix-and-continue",
64 (help "Needed by gdb to load .o files dynamically"), (hidden)),
Mikhail Glushenkov6d80d2b2009-10-08 04:40:28 +000065 (parameter_option "MF",
66 (help "Specify a file to write dependencies to"), (hidden)),
Mikhail Glushenkovbc56d862010-01-02 08:27:10 +000067 (parameter_list_option "MT",
Mikhail Glushenkov6d80d2b2009-10-08 04:40:28 +000068 (help "Change the name of the rule emitted by dependency generation"),
69 (hidden)),
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +000070 (parameter_list_option "include",
71 (help "Include the named file prior to preprocessing")),
Mikhail Glushenkov967edd02010-01-26 14:55:30 +000072 (parameter_list_option "iquote",
73 (help "Search dir only for files requested with #inlcude \"file\""),
74 (hidden)),
Mikhail Glushenkov18518602009-12-01 05:59:55 +000075 (parameter_list_option "framework",
76 (help "Specifies a framework to link against")),
77 (parameter_list_option "weak_framework",
78 (help "Specifies a framework to weakly link against"), (hidden)),
79 (prefix_list_option "F",
80 (help "Add a directory to framework search path")),
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +000081 (prefix_list_option "I",
82 (help "Add a directory to include path")),
Mikhail Glushenkov6d80d2b2009-10-08 04:40:28 +000083 (prefix_list_option "D",
84 (help "Define a macro")),
Mikhail Glushenkov5b9b3ba2009-12-07 18:25:54 +000085 (prefix_list_option "Wa,", (comma_separated),
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +000086 (help "Pass options to assembler")),
Mikhail Glushenkov5b9b3ba2009-12-07 18:25:54 +000087 (prefix_list_option "Wllc,", (comma_separated),
Mikhail Glushenkov46801022009-03-31 18:33:54 +000088 (help "Pass options to llc")),
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +000089 (prefix_list_option "L",
90 (help "Add a directory to link path")),
91 (prefix_list_option "l",
92 (help "Search a library when linking")),
93 (prefix_list_option "Wl,",
Mikhail Glushenkovba71d672008-12-11 22:19:14 +000094 (help "Pass options to linker")),
Mikhail Glushenkov5b9b3ba2009-12-07 18:25:54 +000095 (prefix_list_option "Wo,", (comma_separated),
Mikhail Glushenkov84612022009-12-07 17:03:21 +000096 (help "Pass options to opt")),
97 (prefix_list_option "m",
98 (help "Enable or disable various extensions (-mmmx, -msse, etc.)"),
99 (hidden))
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +0000100]>;
101
Mikhail Glushenkov0a22fb62009-10-17 20:09:29 +0000102// Option preprocessor.
103
104def Preprocess : OptionPreprocessor<
Mikhail Glushenkov994dbe02009-12-17 07:49:16 +0000105(case (not (any_switch_on ["O0", "O1", "O2", "O3"])),
106 (set_option "O2"),
107 (and (switch_on "O3"), (any_switch_on ["O0", "O1", "O2"])),
Mikhail Glushenkov0a22fb62009-10-17 20:09:29 +0000108 (unset_option ["O0", "O1", "O2"]),
109 (and (switch_on "O2"), (any_switch_on ["O0", "O1"])),
110 (unset_option ["O0", "O1"]),
Mikhail Glushenkov3a481e32010-01-01 03:50:51 +0000111 (switch_on ["O1", "O0"]),
Mikhail Glushenkov0a22fb62009-10-17 20:09:29 +0000112 (unset_option "O0"))
113>;
114
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +0000115// Tools
116
117class llvm_gcc_based <string cmd_prefix, string in_lang, string E_ext> : Tool<
118[(in_language in_lang),
119 (out_language "llvm-bitcode"),
120 (output_suffix "bc"),
121 (cmd_line (case
122 (switch_on "E"),
123 (case (not_empty "o"),
124 !strconcat(cmd_prefix, " -E $INFILE -o $OUTFILE"),
125 (default),
126 !strconcat(cmd_prefix, " -E $INFILE")),
127 (switch_on "fsyntax-only"),
128 !strconcat(cmd_prefix, " -fsyntax-only $INFILE"),
129 (and (switch_on "S"), (switch_on "emit-llvm")),
130 !strconcat(cmd_prefix, " -S $INFILE -o $OUTFILE -emit-llvm"),
131 (default),
132 !strconcat(cmd_prefix, " -c $INFILE -o $OUTFILE -emit-llvm"))),
133 (actions
134 (case
Mikhail Glushenkovad981bf2009-09-28 01:16:42 +0000135 (and (multiple_input_files), (or (switch_on "S"), (switch_on "c"))),
136 (error "cannot specify -o with -c or -S with multiple files"),
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +0000137 (switch_on "E"), [(stop_compilation), (output_suffix E_ext)],
Mikhail Glushenkov99da5d72010-01-01 04:41:10 +0000138 (switch_on ["emit-llvm", "S"]),
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +0000139 [(output_suffix "ll"), (stop_compilation)],
Mikhail Glushenkov99da5d72010-01-01 04:41:10 +0000140 (switch_on ["emit-llvm", "c"]), (stop_compilation),
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +0000141 (switch_on "fsyntax-only"), (stop_compilation),
142 (not_empty "include"), (forward "include"),
Mikhail Glushenkov967edd02010-01-26 14:55:30 +0000143 (not_empty "iquote"), (forward "iquote"),
Mikhail Glushenkov97955002009-12-01 06:51:30 +0000144 (not_empty "save-temps"), (append_cmd "-save-temps"),
Mikhail Glushenkov976248d2009-10-08 06:03:38 +0000145 (not_empty "I"), (forward "I"),
Mikhail Glushenkov18518602009-12-01 05:59:55 +0000146 (not_empty "F"), (forward "F"),
Mikhail Glushenkov976248d2009-10-08 06:03:38 +0000147 (not_empty "D"), (forward "D"),
Mikhail Glushenkov058b3f52010-01-26 14:55:44 +0000148 (not_empty "arch"), (forward "arch"),
Mikhail Glushenkov3ab48832009-12-04 06:38:28 +0000149 (not_empty "march"), (forward "march"),
150 (not_empty "mtune"), (forward "mtune"),
151 (not_empty "mcpu"), (forward "mcpu"),
Mikhail Glushenkov84612022009-12-07 17:03:21 +0000152 (not_empty "m"), (forward "m"),
Mikhail Glushenkovb88c6f62010-02-13 22:37:00 +0000153 (switch_on "mfix-and-continue"), (forward "mfix-and-continue"),
Mikhail Glushenkovfa8182e2009-12-04 06:38:45 +0000154 (switch_on "m32"), (forward "m32"),
155 (switch_on "m64"), (forward "m64"),
Mikhail Glushenkov364cf752010-01-02 08:27:23 +0000156 (switch_on "O0"), (forward "O0"),
Mikhail Glushenkov6b4967e2009-10-17 20:07:49 +0000157 (switch_on "O1"), (forward "O1"),
158 (switch_on "O2"), (forward "O2"),
159 (switch_on "O3"), (forward "O3"),
Mikhail Glushenkov55cd7672009-12-01 09:47:11 +0000160 (switch_on "fPIC"), (forward "fPIC"),
161 (switch_on "mdynamic-no-pic"), (forward "mdynamic-no-pic"),
Mikhail Glushenkov976248d2009-10-08 06:03:38 +0000162 (not_empty "MF"), (forward "MF"),
Mikhail Glushenkov6d80d2b2009-10-08 04:40:28 +0000163 (not_empty "MT"), (forward "MT"))),
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +0000164 (sink)
165]>;
166
Mikhail Glushenkov4558f482009-04-21 19:46:10 +0000167def llvm_gcc_c : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x c", "c", "i">;
168def llvm_gcc_cpp : llvm_gcc_based<"@LLVMGXXCOMMAND@ -x c++", "c++", "i">;
Mikhail Glushenkov6d80d2b2009-10-08 04:40:28 +0000169def llvm_gcc_m : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c",
170 "objective-c", "mi">;
Mikhail Glushenkov4558f482009-04-21 19:46:10 +0000171def llvm_gcc_mxx : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c++",
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +0000172 "objective-c++", "mi">;
173
174def opt : Tool<
175[(in_language "llvm-bitcode"),
176 (out_language "llvm-bitcode"),
177 (output_suffix "bc"),
Mikhail Glushenkov5b9b3ba2009-12-07 18:25:54 +0000178 (actions (case (not_empty "Wo,"), (forward_value "Wo,"),
Mikhail Glushenkov6b4967e2009-10-17 20:07:49 +0000179 (switch_on "O1"), (forward "O1"),
180 (switch_on "O2"), (forward "O2"),
181 (switch_on "O3"), (forward "O3"))),
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +0000182 (cmd_line "opt -f $INFILE -o $OUTFILE")
183]>;
184
185def llvm_as : Tool<
186[(in_language "llvm-assembler"),
187 (out_language "llvm-bitcode"),
188 (output_suffix "bc"),
Mikhail Glushenkov3ab68892009-10-09 05:45:01 +0000189 (cmd_line "llvm-as $INFILE -o $OUTFILE"),
190 (actions (case (switch_on "emit-llvm"), (stop_compilation)))
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +0000191]>;
192
193def llvm_gcc_assembler : Tool<
194[(in_language "assembler"),
195 (out_language "object-code"),
196 (output_suffix "o"),
Mikhail Glushenkov4558f482009-04-21 19:46:10 +0000197 (cmd_line "@LLVMGCCCOMMAND@ -c -x assembler $INFILE -o $OUTFILE"),
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +0000198 (actions (case
199 (switch_on "c"), (stop_compilation),
Mikhail Glushenkov058b3f52010-01-26 14:55:44 +0000200 (not_empty "arch"), (forward "arch"),
Mikhail Glushenkov5b9b3ba2009-12-07 18:25:54 +0000201 (not_empty "Wa,"), (forward_value "Wa,")))
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +0000202]>;
203
204def llc : Tool<
Mikhail Glushenkov3ab68892009-10-09 05:45:01 +0000205[(in_language ["llvm-bitcode", "llvm-assembler"]),
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +0000206 (out_language "assembler"),
207 (output_suffix "s"),
Mikhail Glushenkov46801022009-03-31 18:33:54 +0000208 (cmd_line "llc -f $INFILE -o $OUTFILE"),
209 (actions (case
210 (switch_on "S"), (stop_compilation),
Mikhail Glushenkov6b4967e2009-10-17 20:07:49 +0000211 (switch_on "O0"), (forward "O0"),
212 (switch_on "O1"), (forward "O1"),
213 (switch_on "O2"), (forward "O2"),
214 (switch_on "O3"), (forward "O3"),
Mikhail Glushenkov55cd7672009-12-01 09:47:11 +0000215 (switch_on "fPIC"), (append_cmd "-relocation-model=pic"),
216 (switch_on "mdynamic-no-pic"),
217 (append_cmd "-relocation-model=dynamic-no-pic"),
Mikhail Glushenkov3ab48832009-12-04 06:38:28 +0000218 (not_empty "march"), (forward "mcpu"),
219 (not_empty "mtune"), (forward "mcpu"),
220 (not_empty "mcpu"), (forward "mcpu"),
Mikhail Glushenkov84612022009-12-07 17:03:21 +0000221 (not_empty "m"), (forward_transformed_value "m", "ConvertToMAttr"),
Mikhail Glushenkov5b9b3ba2009-12-07 18:25:54 +0000222 (not_empty "Wllc,"), (forward_value "Wllc,")))
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +0000223]>;
224
225// Base class for linkers
226class llvm_gcc_based_linker <string cmd_prefix> : Tool<
227[(in_language "object-code"),
228 (out_language "executable"),
229 (output_suffix "out"),
230 (cmd_line !strconcat(cmd_prefix, " $INFILE -o $OUTFILE")),
231 (join),
232 (actions (case
233 (switch_on "pthread"), (append_cmd "-lpthread"),
234 (not_empty "L"), (forward "L"),
Mikhail Glushenkov18518602009-12-01 05:59:55 +0000235 (not_empty "F"), (forward "F"),
Mikhail Glushenkov058b3f52010-01-26 14:55:44 +0000236 (not_empty "arch"), (forward "arch"),
Mikhail Glushenkov18518602009-12-01 05:59:55 +0000237 (not_empty "framework"), (forward "framework"),
238 (not_empty "weak_framework"), (forward "weak_framework"),
Mikhail Glushenkovfa8182e2009-12-04 06:38:45 +0000239 (switch_on "m32"), (forward "m32"),
240 (switch_on "m64"), (forward "m64"),
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +0000241 (not_empty "l"), (forward "l"),
Mikhail Glushenkov6d80d2b2009-10-08 04:40:28 +0000242 (not_empty "Wl,"), (forward "Wl,")))
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +0000243]>;
244
245// Default linker
Mikhail Glushenkov4558f482009-04-21 19:46:10 +0000246def llvm_gcc_linker : llvm_gcc_based_linker<"@LLVMGCCCOMMAND@">;
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +0000247// Alternative linker for C++
Mikhail Glushenkov4558f482009-04-21 19:46:10 +0000248def llvm_gcc_cpp_linker : llvm_gcc_based_linker<"@LLVMGXXCOMMAND@">;
Mikhail Glushenkovde1e5212008-12-11 10:38:06 +0000249
250// Language map
251
252def LanguageMap : LanguageMap<
253 [LangToSuffixes<"c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]>,
254 LangToSuffixes<"c", ["c"]>,
255 LangToSuffixes<"c-cpp-output", ["i"]>,
256 LangToSuffixes<"objective-c-cpp-output", ["mi"]>,
257 LangToSuffixes<"objective-c++", ["mm"]>,
258 LangToSuffixes<"objective-c", ["m"]>,
259 LangToSuffixes<"assembler", ["s"]>,
260 LangToSuffixes<"assembler-with-cpp", ["S"]>,
261 LangToSuffixes<"llvm-assembler", ["ll"]>,
262 LangToSuffixes<"llvm-bitcode", ["bc"]>,
263 LangToSuffixes<"object-code", ["o"]>,
264 LangToSuffixes<"executable", ["out"]>
265 ]>;
266
267// Compilation graph
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000268
Mikhail Glushenkov0d08db02008-05-06 16:35:25 +0000269def CompilationGraph : CompilationGraph<[
Mikhail Glushenkov01088772008-11-17 17:29:18 +0000270 Edge<"root", "llvm_gcc_c">,
271 Edge<"root", "llvm_gcc_assembler">,
272 Edge<"root", "llvm_gcc_cpp">,
273 Edge<"root", "llvm_gcc_m">,
274 Edge<"root", "llvm_gcc_mxx">,
Mikhail Glushenkov57a7e942009-09-10 17:04:32 +0000275 Edge<"root", "llc">,
Mikhail Glushenkovd752c3f2008-05-06 16:36:50 +0000276
Mikhail Glushenkov01088772008-11-17 17:29:18 +0000277 Edge<"llvm_gcc_c", "llc">,
278 Edge<"llvm_gcc_cpp", "llc">,
279 Edge<"llvm_gcc_m", "llc">,
280 Edge<"llvm_gcc_mxx", "llc">,
281 Edge<"llvm_as", "llc">,
Mikhail Glushenkovd752c3f2008-05-06 16:36:50 +0000282
Mikhail Glushenkov3ab68892009-10-09 05:45:01 +0000283 OptionalEdge<"root", "llvm_as",
284 (case (switch_on "emit-llvm"), (inc_weight))>,
Mikhail Glushenkov01088772008-11-17 17:29:18 +0000285 OptionalEdge<"llvm_gcc_c", "opt", (case (switch_on "opt"), (inc_weight))>,
286 OptionalEdge<"llvm_gcc_cpp", "opt", (case (switch_on "opt"), (inc_weight))>,
287 OptionalEdge<"llvm_gcc_m", "opt", (case (switch_on "opt"), (inc_weight))>,
288 OptionalEdge<"llvm_gcc_mxx", "opt", (case (switch_on "opt"), (inc_weight))>,
289 OptionalEdge<"llvm_as", "opt", (case (switch_on "opt"), (inc_weight))>,
290 Edge<"opt", "llc">,
Mikhail Glushenkovd752c3f2008-05-06 16:36:50 +0000291
Mikhail Glushenkov01088772008-11-17 17:29:18 +0000292 Edge<"llc", "llvm_gcc_assembler">,
293 Edge<"llvm_gcc_assembler", "llvm_gcc_linker">,
294 OptionalEdge<"llvm_gcc_assembler", "llvm_gcc_cpp_linker",
Mikhail Glushenkove5557f42008-05-30 06:08:50 +0000295 (case
Daniel Dunbar77e0c852008-11-08 03:25:47 +0000296 (or (input_languages_contain "c++"),
Mikhail Glushenkov01088772008-11-17 17:29:18 +0000297 (input_languages_contain "objective-c++")),
Daniel Dunbar77e0c852008-11-08 03:25:47 +0000298 (inc_weight),
Mikhail Glushenkove5557f42008-05-30 06:08:50 +0000299 (or (parameter_equals "linker", "g++"),
300 (parameter_equals "linker", "c++")), (inc_weight))>,
Mikhail Glushenkov35a85e82008-05-06 18:10:20 +0000301
Mikhail Glushenkov978d4982008-05-06 18:13:00 +0000302
Mikhail Glushenkov01088772008-11-17 17:29:18 +0000303 Edge<"root", "llvm_gcc_linker">,
304 OptionalEdge<"root", "llvm_gcc_cpp_linker",
Mikhail Glushenkove5557f42008-05-30 06:08:50 +0000305 (case
Daniel Dunbar77e0c852008-11-08 03:25:47 +0000306 (or (input_languages_contain "c++"),
Mikhail Glushenkov01088772008-11-17 17:29:18 +0000307 (input_languages_contain "objective-c++")),
Daniel Dunbar77e0c852008-11-08 03:25:47 +0000308 (inc_weight),
Mikhail Glushenkove5557f42008-05-30 06:08:50 +0000309 (or (parameter_equals "linker", "g++"),
310 (parameter_equals "linker", "c++")), (inc_weight))>
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000311 ]>;