1
//===- Base.td - LLVMC toolchain descriptions --------------*- tablegen -*-===//
3
// The LLVM Compiler Infrastructure
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
8
//===----------------------------------------------------------------------===//
10
// This file contains compilation graph description used by llvmc.
12
//===----------------------------------------------------------------------===//
14
include "llvm/CompilerDriver/Common.td"
18
def OptList : OptionList<[
19
(switch_option "emit-llvm",
20
(help "Emit LLVM .ll files instead of native object files")),
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")),
28
(help "Turn off optimization"), (zero_or_more)),
30
(help "Optimization level 1"), (zero_or_more)),
32
(help "Optimization level 2"), (zero_or_more)),
34
(help "Optimization level 3"), (zero_or_more)),
36
(help "Stop after compilation, do not assemble")),
38
(help "Compile and assemble, but do not link")),
39
(switch_option "pthread",
40
(help "Enable threads")),
42
(help "Generate code for a 32-bit environment"), (hidden)),
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), (forward_not_split)),
54
// TODO: Add a conditional compilation mechanism to make Darwin-only options
55
// like '-arch' really Darwin-only.
57
(parameter_option "arch",
58
(help "Compile for the specified target architecture"), (hidden)),
59
(parameter_option "march",
60
(help "A synonym for -mtune"), (hidden), (forward_not_split)),
61
(parameter_option "mcpu",
62
(help "A deprecated synonym for -mtune"), (hidden), (forward_not_split)),
63
(switch_option "mfix-and-continue",
64
(help "Needed by gdb to load .o files dynamically"), (hidden)),
65
(parameter_option "MF",
66
(help "Specify a file to write dependencies to"), (hidden)),
67
(parameter_list_option "MT",
68
(help "Change the name of the rule emitted by dependency generation"),
70
(parameter_list_option "include",
71
(help "Include the named file prior to preprocessing")),
72
(parameter_list_option "iquote",
73
(help "Search dir only for files requested with #inlcude \"file\""),
75
(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
(parameter_option "filelist", (hidden),
80
(help "Link the files listed in file")),
81
(prefix_list_option "F",
82
(help "Add a directory to framework search path")),
83
(prefix_list_option "I",
84
(help "Add a directory to include path")),
85
(prefix_list_option "D",
86
(help "Define a macro")),
87
(parameter_list_option "Xpreprocessor", (hidden),
88
(help "Pass options to preprocessor")),
89
(prefix_list_option "Wa,", (comma_separated),
90
(help "Pass options to assembler")),
91
(parameter_list_option "Xassembler", (hidden),
92
(help "Pass options to assembler")),
93
(prefix_list_option "Wllc,", (comma_separated),
94
(help "Pass options to llc")),
95
(prefix_list_option "L",
96
(help "Add a directory to link path")),
97
(prefix_list_option "l",
98
(help "Search a library when linking")),
99
(prefix_list_option "Wl,",
100
(help "Pass options to linker")),
101
(parameter_list_option "Xlinker", (hidden),
102
(help "Pass options to linker")),
103
(prefix_list_option "Wo,", (comma_separated),
104
(help "Pass options to opt")),
105
(prefix_list_option "m",
106
(help "Enable or disable various extensions (-mmmx, -msse, etc.)"),
108
(switch_option "dynamiclib", (hidden),
109
(help "Produce a dynamic library")),
110
(switch_option "prebind", (hidden),
111
(help "Prebind all undefined symbols")),
112
(switch_option "dead_strip", (hidden),
113
(help "Remove unreachable blocks of code")),
114
(switch_option "single_module", (hidden),
115
(help "Build the library so it contains only one module")),
116
(parameter_option "install_name", (hidden),
117
(help "File name the library will be installed in")),
118
(parameter_option "compatibility_version", (hidden),
119
(help "Compatibility version number")),
120
(parameter_option "current_version", (hidden),
121
(help "Current version number"))
124
// Option preprocessor.
126
def Preprocess : OptionPreprocessor<
127
(case (not (any_switch_on ["O0", "O1", "O2", "O3"])),
129
(and (switch_on "O3"), (any_switch_on ["O0", "O1", "O2"])),
130
(unset_option ["O0", "O1", "O2"]),
131
(and (switch_on "O2"), (any_switch_on ["O0", "O1"])),
132
(unset_option ["O0", "O1"]),
133
(switch_on ["O1", "O0"]),
139
class llvm_gcc_based <string cmd_prefix, string in_lang,
140
string E_ext, string out_lang> : Tool<
141
[(in_language in_lang),
142
(out_language "llvm-bitcode"),
143
(output_suffix out_lang),
144
(command cmd_prefix),
147
(and (not_empty "o"),
148
(multiple_input_files), (or (switch_on "S"), (switch_on "c"))),
149
(error "cannot specify -o with -c or -S with multiple files"),
151
[(forward "E"), (stop_compilation), (output_suffix E_ext)],
152
(and (switch_on "E"), (empty "o")), (no_out_file),
153
(switch_on ["emit-llvm", "S"]),
154
[(output_suffix "ll"), (stop_compilation)],
155
(switch_on ["emit-llvm", "c"]), (stop_compilation),
156
(switch_on "fsyntax-only"), [(forward "fsyntax-only"),
157
(no_out_file), (stop_compilation)],
158
(switch_on ["S", "emit-llvm"]), [(forward "S"), (forward "emit-llvm")],
159
(not (or (switch_on ["S", "emit-llvm"]), (switch_on "fsyntax-only"))),
160
[(append_cmd "-c"), (append_cmd "-emit-llvm")],
163
(not_empty "Xpreprocessor"), (forward "Xpreprocessor"),
164
(not_empty "include"), (forward "include"),
165
(not_empty "iquote"), (forward "iquote"),
166
(not_empty "save-temps"), (append_cmd "-save-temps"),
167
(not_empty "I"), (forward "I"),
168
(not_empty "F"), (forward "F"),
169
(not_empty "D"), (forward "D"),
170
(not_empty "arch"), (forward "arch"),
171
(not_empty "march"), (forward "march"),
172
(not_empty "mtune"), (forward "mtune"),
173
(not_empty "mcpu"), (forward "mcpu"),
174
(not_empty "m"), (forward "m"),
175
(switch_on "mfix-and-continue"), (forward "mfix-and-continue"),
176
(switch_on "m32"), (forward "m32"),
177
(switch_on "m64"), (forward "m64"),
178
(switch_on "O0"), (forward "O0"),
179
(switch_on "O1"), (forward "O1"),
180
(switch_on "O2"), (forward "O2"),
181
(switch_on "O3"), (forward "O3"),
182
(switch_on "fPIC"), (forward "fPIC"),
183
(switch_on "mdynamic-no-pic"), (forward "mdynamic-no-pic"),
184
(not_empty "MF"), (forward "MF"),
185
(not_empty "MT"), (forward "MT"))),
189
def llvm_gcc_c : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x c", "c", "i", "bc">;
190
def llvm_gcc_cpp : llvm_gcc_based<"@LLVMGXXCOMMAND@ -x c++", "c++", "i", "bc">;
191
def llvm_gcc_m : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c",
192
"objective-c", "mi", "bc">;
193
def llvm_gcc_mxx : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c++",
194
"objective-c++", "mi", "bc">;
196
def llvm_gcc_c_pch : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x c-header",
197
"c-header", "i", "gch">;
198
def llvm_gcc_cpp_pch : llvm_gcc_based<"@LLVMGXXCOMMAND@ -x c++-header",
201
def llvm_gcc_m_pch : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c-header",
202
"objective-c-header",
205
: llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c++-header",
206
"objective-c++-header", "mi", "gch">;
209
[(in_language "llvm-bitcode"),
210
(out_language "llvm-bitcode"),
211
(output_suffix "bc"),
212
(actions (case (not_empty "Wo,"), (forward_value "Wo,"),
213
(switch_on "O1"), (forward "O1"),
214
(switch_on "O2"), (forward "O2"),
215
(switch_on "O3"), (forward "O3"))),
220
[(in_language "llvm-assembler"),
221
(out_language "llvm-bitcode"),
222
(output_suffix "bc"),
224
(actions (case (switch_on "emit-llvm"), (stop_compilation)))
227
def llvm_gcc_assembler : Tool<
228
[(in_language "assembler"),
229
(out_language "object-code"),
231
(command "@LLVMGCCCOMMAND@ -c -x assembler"),
233
(switch_on "c"), (stop_compilation),
234
(not_empty "arch"), (forward "arch"),
235
(not_empty "Xassembler"), (forward "Xassembler"),
236
(not_empty "Wa,"), (forward "Wa,")))
240
[(in_language ["llvm-bitcode", "llvm-assembler"]),
241
(out_language "assembler"),
245
(switch_on "S"), (stop_compilation),
246
(switch_on "O0"), (forward "O0"),
247
(switch_on "O1"), (forward "O1"),
248
(switch_on "O2"), (forward "O2"),
249
(switch_on "O3"), (forward "O3"),
250
(switch_on "fPIC"), (append_cmd "-relocation-model=pic"),
251
(switch_on "mdynamic-no-pic"),
252
(append_cmd "-relocation-model=dynamic-no-pic"),
253
(not_empty "march"), (forward_as "mtune", "-mcpu"),
254
(not_empty "mtune"), (forward_as "mtune", "-mcpu"),
255
(not_empty "mcpu"), (forward "mcpu"),
256
(not_empty "m"), (forward_transformed_value "m", "ConvertToMAttr"),
257
(not_empty "Wllc,"), (forward_value "Wllc,")))
260
// Base class for linkers
261
class llvm_gcc_based_linker <string cmd_prefix> : Tool<
262
[(in_language "object-code"),
263
(out_language "executable"),
264
(output_suffix "out"),
265
(command cmd_prefix),
266
(works_on_empty (case (not_empty "filelist"), true,
270
(switch_on "pthread"), (append_cmd "-lpthread"),
271
(not_empty "L"), (forward "L"),
272
(not_empty "F"), (forward "F"),
273
(not_empty "arch"), (forward "arch"),
274
(not_empty "framework"), (forward "framework"),
275
(not_empty "weak_framework"), (forward "weak_framework"),
276
(not_empty "filelist"), (forward "filelist"),
277
(switch_on "m32"), (forward "m32"),
278
(switch_on "m64"), (forward "m64"),
279
(not_empty "l"), (forward "l"),
280
(not_empty "Xlinker"), (forward "Xlinker"),
281
(not_empty "Wl,"), (forward "Wl,"),
282
(switch_on "dynamiclib"), (forward "dynamiclib"),
283
(switch_on "prebind"), (forward "prebind"),
284
(switch_on "dead_strip"), (forward "dead_strip"),
285
(switch_on "single_module"), (forward "single_module"),
286
(not_empty "compatibility_version"),
287
(forward "compatibility_version"),
288
(not_empty "current_version"), (forward "current_version"),
289
(not_empty "install_name"), (forward "install_name")))
293
def llvm_gcc_linker : llvm_gcc_based_linker<"@LLVMGCCCOMMAND@">;
294
// Alternative linker for C++
295
def llvm_gcc_cpp_linker : llvm_gcc_based_linker<"@LLVMGXXCOMMAND@">;
299
def LanguageMap : LanguageMap<
300
[LangToSuffixes<"c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]>,
301
LangToSuffixes<"c++-header", ["hpp"]>,
302
LangToSuffixes<"c", ["c"]>,
303
LangToSuffixes<"c-header", ["h"]>,
304
LangToSuffixes<"c-cpp-output", ["i"]>,
305
LangToSuffixes<"objective-c-cpp-output", ["mi"]>,
306
LangToSuffixes<"objective-c++", ["mm"]>,
307
LangToSuffixes<"objective-c++-header", ["hmm"]>,
308
LangToSuffixes<"objective-c", ["m"]>,
309
LangToSuffixes<"objective-c-header", ["hm"]>,
310
LangToSuffixes<"assembler", ["s"]>,
311
LangToSuffixes<"assembler-with-cpp", ["S"]>,
312
LangToSuffixes<"llvm-assembler", ["ll"]>,
313
LangToSuffixes<"llvm-bitcode", ["bc"]>,
314
LangToSuffixes<"object-code", ["o", "*empty*"]>,
315
LangToSuffixes<"executable", ["out"]>
320
def CompilationGraph : CompilationGraph<[
321
Edge<"root", "llvm_gcc_c">,
322
Edge<"root", "llvm_gcc_assembler">,
323
Edge<"root", "llvm_gcc_cpp">,
324
Edge<"root", "llvm_gcc_m">,
325
Edge<"root", "llvm_gcc_mxx">,
328
Edge<"root", "llvm_gcc_c_pch">,
329
Edge<"root", "llvm_gcc_cpp_pch">,
330
Edge<"root", "llvm_gcc_m_pch">,
331
Edge<"root", "llvm_gcc_mxx_pch">,
333
Edge<"llvm_gcc_c", "llc">,
334
Edge<"llvm_gcc_cpp", "llc">,
335
Edge<"llvm_gcc_m", "llc">,
336
Edge<"llvm_gcc_mxx", "llc">,
337
Edge<"llvm_as", "llc">,
339
OptionalEdge<"root", "llvm_as",
340
(case (switch_on "emit-llvm"), (inc_weight))>,
341
OptionalEdge<"llvm_gcc_c", "opt", (case (switch_on "opt"), (inc_weight))>,
342
OptionalEdge<"llvm_gcc_cpp", "opt", (case (switch_on "opt"), (inc_weight))>,
343
OptionalEdge<"llvm_gcc_m", "opt", (case (switch_on "opt"), (inc_weight))>,
344
OptionalEdge<"llvm_gcc_mxx", "opt", (case (switch_on "opt"), (inc_weight))>,
345
OptionalEdge<"llvm_as", "opt", (case (switch_on "opt"), (inc_weight))>,
348
Edge<"llc", "llvm_gcc_assembler">,
349
Edge<"llvm_gcc_assembler", "llvm_gcc_linker">,
350
OptionalEdge<"llvm_gcc_assembler", "llvm_gcc_cpp_linker",
352
(or (input_languages_contain "c++"),
353
(input_languages_contain "objective-c++")),
355
(or (parameter_equals "linker", "g++"),
356
(parameter_equals "linker", "c++")), (inc_weight))>,
359
Edge<"root", "llvm_gcc_linker">,
360
OptionalEdge<"root", "llvm_gcc_cpp_linker",
362
(or (input_languages_contain "c++"),
363
(input_languages_contain "objective-c++")),
365
(or (parameter_equals "linker", "g++"),
366
(parameter_equals "linker", "c++")), (inc_weight))>