summaryrefslogtreecommitdiff
path: root/tools/llvmc/src/Base.td.in
blob: 50533f11fa4da942269cf98e12c85d0071abd790 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
//===- Base.td - LLVMC toolchain descriptions --------------*- tablegen -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file contains compilation graph description used by llvmc.
//
//===----------------------------------------------------------------------===//

// Options

def OptList : OptionList<[
 (switch_option "emit-llvm",
    (help "Emit LLVM .ll files instead of native object files")),
 (switch_option "E",
    (help "Stop after the preprocessing stage, do not run the compiler")),
 (switch_option "fsyntax-only",
    (help "Stop after checking the input for syntax errors")),
 (switch_option "opt",
    (help "Enable opt")),
 (switch_option "O0",
    (help "Turn off optimization"), (zero_or_more)),
 (switch_option "O1",
    (help "Optimization level 1"), (zero_or_more)),
 (switch_option "O2",
    (help "Optimization level 2"), (zero_or_more)),
 (switch_option "O3",
    (help "Optimization level 3"), (zero_or_more)),
 (switch_option "S",
    (help "Stop after compilation, do not assemble")),
 (switch_option "c",
    (help "Compile and assemble, but do not link")),
 (switch_option "m32",
    (help "Generate code for a 32-bit environment"), (hidden)),
 (switch_option "m64",
    (help "Generate code for a 64-bit environment"), (hidden)),
 (switch_option "fPIC",
    (help "Relocation model: PIC"), (hidden)),
 (switch_option "mdynamic-no-pic",
    (help "Relocation model: dynamic-no-pic"), (hidden)),
 (parameter_option "linker",
    (help "Choose linker (possible values: gcc, g++)")),
 (parameter_option "mtune",
    (help "Target a specific CPU type"), (forward_not_split)),
 (parameter_list_option "march",
    (help "Generate code for the specified machine type")),
 (parameter_option "mcpu",
    (help "A deprecated synonym for -mtune"), (hidden), (forward_not_split)),
 (parameter_option "mfpu",
    (help "Specify type of floating point unit"),
    (hidden), (forward_not_split)),
 (parameter_option "mabi",
    (help "Generate code for the specified ABI"), (hidden)),
 (parameter_option "mfloat-abi",
    (help "Specifies which floating-point ABI to use"), (hidden)),
 (switch_option "mfix-and-continue",
    (help "Needed by gdb to load .o files dynamically"), (hidden)),
 (parameter_option "MF",
    (help "Specify a file to write dependencies to"), (hidden)),
 (parameter_list_option "MT",
    (help "Change the name of the rule emitted by dependency generation"),
    (hidden)),
 (parameter_list_option "include",
    (help "Include the named file prior to preprocessing")),
 (parameter_list_option "iquote",
    (help "Search dir only for files requested with #inlcude \"file\""),
    (hidden)),
 (prefix_list_option "I",
    (help "Add a directory to include path")),
 (prefix_list_option "D",
    (help "Define a macro")),
 (parameter_list_option "Xpreprocessor", (hidden),
    (help "Pass options to preprocessor")),
 (prefix_list_option "Wa,", (comma_separated),
    (help "Pass options to assembler")),
 (parameter_list_option "Xassembler", (hidden),
    (help "Pass options to assembler")),
 (prefix_list_option "Wllc,", (comma_separated),
    (help "Pass options to llc")),
 (prefix_list_option "Wl,",
    (help "Pass options to linker")),
 (parameter_list_option "Xlinker", (hidden),
    (help "Pass options to linker")),
 (prefix_list_option "Wo,", (comma_separated),
    (help "Pass options to opt")),
 (prefix_list_option "m",
     (help "Enable or disable various extensions (-mmmx, -msse, etc.)"),
     (hidden))
]>;

def LinkerOptList : OptionList<[
 (prefix_list_option "L",
    (help "Add a directory to link path")),
 (prefix_list_option "l",
    (help "Search a library when linking")),
 (parameter_option "filelist", (hidden),
    (help "Link the files listed in file")),
 (switch_option "nostartfiles",
    (help "Do not use the standard system startup files when linking"),
    (hidden)),
 (switch_option "nodefaultlibs",
    (help "Do not use the standard system libraries when linking"), (hidden)),
 (switch_option "nostdlib",
    (help
    "Do not use the standard system startup files or libraries when linking"),
    (hidden)),
 (switch_option "pie",
     (help "Produce a position independent executable"), (hidden)),
 (switch_option "rdynamic",
     (help "Add all symbols to the dynamic export table"), (hidden)),
 (switch_option "s",
    (help "Strip all symbols"), (hidden)),
 (switch_option "static",
     (help "Do not link against shared libraries"), (hidden)),
 (switch_option "static-libgcc",
     (help "Use static libgcc"), (hidden)),
 (switch_option "shared",
     (help "Create a DLL instead of the regular executable")),
 (switch_option "shared-libgcc",
     (help "Use shared libgcc"), (hidden)),
 (parameter_option "T",
     (help "Read linker script"), (hidden)),
 (parameter_option "u",
     (help "Start with undefined reference to SYMBOL"), (hidden)),
 (switch_option "pthread",
    (help "Enable threads")),

 // TODO: Add a conditional compilation mechanism to make Darwin-only options
 // like '-arch' really Darwin-only.
 (parameter_option "arch",
    (help "Compile for the specified target architecture"), (hidden)),
 (prefix_list_option "F",
    (help "Add a directory to framework search path")),
 (parameter_list_option "framework",
    (help "Specifies a framework to link against")),
 (parameter_list_option "weak_framework",
    (help "Specifies a framework to weakly link against"), (hidden)),
 (switch_option "dynamiclib", (hidden),
     (help "Produce a dynamic library")),
 (switch_option "prebind", (hidden),
     (help "Prebind all undefined symbols")),
 (switch_option "dead_strip", (hidden),
     (help "Remove unreachable blocks of code")),
 (switch_option "single_module", (hidden),
     (help "Build the library so it contains only one module")),
 (parameter_option "install_name", (hidden),
     (help "File name the library will be installed in")),
 (parameter_option "compatibility_version", (hidden),
     (help "Compatibility version number")),
 (parameter_option "current_version", (hidden),
     (help "Current version number"))
]>;

// Option preprocessor.

def Preprocess : OptionPreprocessor<
(case (not (any_switch_on "O0", "O1", "O2", "O3")),
           (set_option "O2"),
      (and (switch_on "O3"), (any_switch_on "O0", "O1", "O2")),
           (unset_option "O0", "O1", "O2"),
      (and (switch_on "O2"), (any_switch_on "O0", "O1")),
           (unset_option "O0", "O1"),
      (switch_on "O1", "O0"),
           (unset_option "O0"))
>;

// Tools

class llvm_gcc_based <string cmd, string in_lang, string E_ext, dag out_lang,
                      string out_ext> : Tool<
[(in_language in_lang),
 out_lang,
 (output_suffix out_ext),
 (command cmd),
 (actions
     (case
         (and (not_empty "o"),
              (multiple_input_files), (or (switch_on "S"), (switch_on "c"))),
              (error "cannot specify -o with -c or -S with multiple files"),
         (switch_on "E"),
              [(forward "E"), (stop_compilation), (output_suffix E_ext)],
         (and (switch_on "E"), (empty "o")), (no_out_file),

         // ('-emit-llvm') && !('opt') -> stop compilation
         (and (switch_on "emit-llvm"), (not (switch_on "opt"))),
              (stop_compilation),
         // ('-S' && '-emit-llvm') && !('opt') -> output .ll
         (and (switch_on "emit-llvm", "S"), (not (switch_on "opt"))),
              [(forward "S"), (output_suffix "ll")],
         // Ususally just output .bc
         (not (switch_on "fsyntax-only")),
              [(append_cmd "-c"), (append_cmd "-emit-llvm")],

         // -fsyntax-only
         (switch_on "fsyntax-only"), [(forward "fsyntax-only"),
                                      (no_out_file), (stop_compilation)],

         // Forwards
         (not_empty "Xpreprocessor"), (forward "Xpreprocessor"),
         (not_empty "include"), (forward "include"),
         (not_empty "iquote"), (forward "iquote"),
         (not_empty "save-temps"), (append_cmd "-save-temps"),
         (not_empty "I"), (forward "I"),
         (not_empty "F"), (forward "F"),
         (not_empty "D"), (forward "D"),
         (not_empty "arch"), (forward "arch"),
         (not_empty "march"), (forward "march"),
         (not_empty "mcpu"), (forward "mcpu"),
         (not_empty "mtune"), (forward "mtune"),
         (not_empty "mfpu"), (forward "mfpu"),
         (not_empty "mabi"), (forward "mabi"),
         (not_empty "mfloat-abi"), (forward "mfloat-abi"),
         (not_empty "m"), (forward "m"),
         (switch_on "mfix-and-continue"), (forward "mfix-and-continue"),
         (switch_on "m32"), (forward "m32"),
         (switch_on "m64"), (forward "m64"),
         (switch_on "O0"), (forward "O0"),
         (switch_on "O1"), (forward "O1"),
         (switch_on "O2"), (forward "O2"),
         (switch_on "O3"), (forward "O3"),
         (switch_on "fPIC"), (forward "fPIC"),
         (switch_on "mdynamic-no-pic"), (forward "mdynamic-no-pic"),
         (not_empty "MF"), (forward "MF"),
         (not_empty "MT"), (forward "MT"))),
 (sink)
]>;

class llvm_gcc_comp_based <string cmd, string in_lang, string E_ext>
: llvm_gcc_based<cmd, in_lang, E_ext,
  (out_language "llvm-bitcode", "object-code"), "bc">;

class llvm_gcc_pch_based <string cmd, string in_lang, string E_ext>
: llvm_gcc_based<cmd, in_lang, E_ext,
  (out_language "precompiled-header"), "gch">;

def llvm_gcc_c : llvm_gcc_comp_based
    <"@LLVMGCCCOMMAND@ -x c", "c", "i">;
def llvm_gcc_cpp : llvm_gcc_comp_based
    <"@LLVMGXXCOMMAND@ -x c++", "c++", "i">;
def llvm_gcc_m : llvm_gcc_comp_based
    <"@LLVMGCCCOMMAND@ -x objective-c", "objective-c", "mi">;
def llvm_gcc_mxx : llvm_gcc_comp_based
    <"@LLVMGCCCOMMAND@ -x objective-c++", "objective-c++", "mi">;

def llvm_gcc_c_pch : llvm_gcc_pch_based
    <"@LLVMGCCCOMMAND@ -x c-header", "c-header", "i">;
def llvm_gcc_cpp_pch : llvm_gcc_pch_based
    <"@LLVMGXXCOMMAND@ -x c++-header", "c++-header", "i">;
def llvm_gcc_m_pch : llvm_gcc_pch_based
    <"@LLVMGCCCOMMAND@ -x objective-c-header", "objective-c-header", "mi">;
def llvm_gcc_mxx_pch : llvm_gcc_pch_based
    <"@LLVMGCCCOMMAND@ -x objective-c++-header", "objective-c++-header", "mi">;

def opt : Tool<
[(in_language "llvm-bitcode"),
 (out_language "llvm-bitcode"),
 (output_suffix "opt.bc"),
 (actions (case (switch_on "emit-llvm"), (stop_compilation),
                (switch_on "emit-llvm", "S"),
                [(append_cmd "-S"), (output_suffix "ll")],
                (not_empty "Wo,"), (forward_value "Wo,"),
                (switch_on "O1"), (forward "O1"),
                (switch_on "O2"), (forward "O2"),
                (switch_on "O3"), (forward "O3"))),
 (command "opt -f")
]>;

def llvm_as : Tool<
[(in_language "llvm-assembler"),
 (out_language "llvm-bitcode"),
 (output_suffix "bc"),
 (command "llvm-as"),
 (actions (case (and (switch_on "emit-llvm"), (not (switch_on "opt"))),
                (stop_compilation)))
]>;

def llvm_gcc_assembler : Tool<
[(in_language "assembler"),
 (out_language "object-code"),
 (output_suffix "o"),
 (command "@LLVMGCCCOMMAND@ -c -x assembler"),
 (actions (case
          (switch_on "c"), (stop_compilation),
          (not_empty "arch"), (forward "arch"),
          (not_empty "Xassembler"), (forward "Xassembler"),
          (not_empty "march"), (forward "march"),
          (not_empty "mcpu"), (forward "mcpu"),
          (not_empty "mtune"), (forward "mtune"),
          (not_empty "mabi"), (forward "mabi"),
          (not_empty "mfloat-abi"), (forward "mfloat-abi"),
          (switch_on "m32"), (forward "m32"),
          (switch_on "m64"), (forward "m64"),
          (not_empty "Wa,"), (forward "Wa,")))
]>;

def llc : Tool<
[(in_language "llvm-bitcode", "llvm-assembler"),
 (out_language "assembler"),
 (output_suffix "s"),
 (command "llc"),
 (actions (case
          (switch_on "S"), (stop_compilation),
          (switch_on "O0"), (forward "O0"),
          (switch_on "O1"), (forward "O1"),
          (switch_on "O2"), (forward "O2"),
          (switch_on "O3"), (forward "O3"),
          (switch_on "fPIC"), (append_cmd "-relocation-model=pic"),
          (switch_on "mdynamic-no-pic"),
                     (append_cmd "-relocation-model=dynamic-no-pic"),
          (not_empty "march"), (forward_transformed_value
                                "march", "ConvertMArchToMAttr"),
          (not_empty "mcpu"), (forward_transformed_value "mcpu", "ConvertMCpu"),
          (and (not_empty "mtune"), (empty "mcpu")),
                     (forward_as "mtune", "-mcpu"),
          (not_empty "mfpu"), (forward_transformed_value "mfpu", "ConvertMFpu"),
          (not_empty "m"), (forward_transformed_value "m", "ConvertToMAttr"),
          (not_empty "Wllc,"), (forward_value "Wllc,")))
]>;

// Base class for linkers
class llvm_gcc_based_linker <string cmd, dag on_empty> : Tool<
[(in_language "object-code", "static-library", "dynamic-library"),
 (out_language "executable"),
 (output_suffix "out"),
 (command cmd),
 (works_on_empty (case (and (not_empty "filelist"), on_empty), true,
                       (default), false)),
 (join),
 (actions (case
          (switch_on "pthread"), (append_cmd "-lpthread"),
          (not_empty "L"), (forward "L"),
          (not_empty "F"), (forward "F"),
          (not_empty "arch"), (forward "arch"),
          (not_empty "framework"), (forward "framework"),
          (not_empty "weak_framework"), (forward "weak_framework"),
          (not_empty "filelist"), (forward "filelist"),
          (not_empty "march"), (forward "march"),
          (not_empty "mcpu"), (forward "mcpu"),
          (not_empty "mtune"), (forward "mtune"),
          (not_empty "mabi"), (forward "mabi"),
          (not_empty "mfloat-abi"), (forward "mfloat-abi"),
          (switch_on "m32"), (forward "m32"),
          (switch_on "m64"), (forward "m64"),
          (not_empty "l"), (forward "l"),
          (not_empty "Xlinker"), (forward "Xlinker"),
          (not_empty "Wl,"), (forward "Wl,"),
          (switch_on "nostartfiles"), (forward "nostartfiles"),
          (switch_on "nodefaultlibs"), (forward "nodefaultlibs"),
          (switch_on "nostdlib"), (forward "nostdlib"),
          (switch_on "pie"), (forward "pie"),
          (switch_on "rdynamic"), (forward "rdynamic"),
          (switch_on "s"), (forward "s"),
          (switch_on "static"), (forward "static"),
          (switch_on "static-libgcc"), (forward "static-libgcc"),
          (switch_on "shared"), (forward "shared"),
          (switch_on "shared-libgcc"), (forward "shared-libgcc"),
          (not_empty "T"), (forward "T"),
          (not_empty "u"), (forward "u"),
          (switch_on "dynamiclib"), (forward "dynamiclib"),
          (switch_on "prebind"), (forward "prebind"),
          (switch_on "dead_strip"), (forward "dead_strip"),
          (switch_on "single_module"), (forward "single_module"),
          (not_empty "compatibility_version"),
                     (forward "compatibility_version"),
          (not_empty "current_version"), (forward "current_version"),
          (not_empty "install_name"), (forward "install_name")))
]>;

// Default linker
def llvm_gcc_linker : llvm_gcc_based_linker<"@LLVMGCCCOMMAND@",
    (not (or (parameter_equals "linker", "g++"),
         (parameter_equals "linker", "c++")))>;
// Alternative linker for C++
def llvm_gcc_cpp_linker : llvm_gcc_based_linker<"@LLVMGXXCOMMAND@",
    (or (parameter_equals "linker", "g++"),
        (parameter_equals "linker", "c++"))>;

// Language map

def LanguageMap : LanguageMap<[
    (lang_to_suffixes "precompiled-header", ["gch", "pch"]),
    (lang_to_suffixes "c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]),
    (lang_to_suffixes "c++-header", "hpp"),
    (lang_to_suffixes "c", "c"),
    (lang_to_suffixes "c-header", "h"),
    (lang_to_suffixes "c-cpp-output", "i"),
    (lang_to_suffixes "objective-c-cpp-output", "mi"),
    (lang_to_suffixes "objective-c++", "mm"),
    (lang_to_suffixes "objective-c++-header", "hmm"),
    (lang_to_suffixes "objective-c", "m"),
    (lang_to_suffixes "objective-c-header", "hm"),
    (lang_to_suffixes "assembler", "s"),
    (lang_to_suffixes "assembler-with-cpp", "S"),
    (lang_to_suffixes "llvm-assembler", "ll"),
    (lang_to_suffixes "llvm-bitcode", "bc"),
    (lang_to_suffixes "object-code", ["o", "*empty*"]),
    (lang_to_suffixes "static-library", ["a", "lib"]),
    (lang_to_suffixes "dynamic-library", ["so", "dylib", "dll"]),
    (lang_to_suffixes "executable", "out")
]>;

// Compilation graph

def CompilationGraph : CompilationGraph<[
    (edge "root", "llvm_gcc_c"),
    (edge "root", "llvm_gcc_assembler"),
    (edge "root", "llvm_gcc_cpp"),
    (edge "root", "llvm_gcc_m"),
    (edge "root", "llvm_gcc_mxx"),
    (edge "root", "llc"),

    (edge "root", "llvm_gcc_c_pch"),
    (edge "root", "llvm_gcc_cpp_pch"),
    (edge "root", "llvm_gcc_m_pch"),
    (edge "root", "llvm_gcc_mxx_pch"),

    (edge "llvm_gcc_c", "llc"),
    (edge "llvm_gcc_cpp", "llc"),
    (edge "llvm_gcc_m", "llc"),
    (edge "llvm_gcc_mxx", "llc"),
    (edge "llvm_as", "llc"),

    (optional_edge "root", "llvm_as",
                   (case (or (switch_on "emit-llvm"),
                             (switch_on "opt")), (inc_weight))),
    (optional_edge "llvm_gcc_c", "opt",
                   (case (switch_on "opt"), (inc_weight))),
    (optional_edge "llvm_gcc_cpp", "opt",
                   (case (switch_on "opt"), (inc_weight))),
    (optional_edge "llvm_gcc_m", "opt",
                   (case (switch_on "opt"), (inc_weight))),
    (optional_edge "llvm_gcc_mxx", "opt",
                   (case (switch_on "opt"), (inc_weight))),
    (optional_edge "llvm_as", "opt",
                   (case (switch_on "opt"), (inc_weight))),
    (edge "opt", "llc"),

    (edge "llc", "llvm_gcc_assembler"),
    (edge "llvm_gcc_assembler", "llvm_gcc_linker"),
    (optional_edge "llvm_gcc_assembler", "llvm_gcc_cpp_linker",
                 (case
                     (or (input_languages_contain "c++"),
                         (input_languages_contain "objective-c++")),
                     (inc_weight),
                     (or (parameter_equals "linker", "g++"),
                         (parameter_equals "linker", "c++")), (inc_weight))),


    (edge "root", "llvm_gcc_linker"),
    (optional_edge "root", "llvm_gcc_cpp_linker",
                 (case
                     (or (input_languages_contain "c++"),
                         (input_languages_contain "objective-c++")),
                     (inc_weight),
                     (or (parameter_equals "linker", "g++"),
                         (parameter_equals "linker", "c++")), (inc_weight)))
]>;