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")),
30 (help "Optimization level 1")),
32 (help "Optimization level 2")),
34 (help "Optimization level 3")),
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)),
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"),
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,", (comma_separated),
75 (help "Pass options to assembler")),
76 (prefix_list_option "Wllc,", (comma_separated),
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,", (comma_separated),
85 (help "Pass options to opt")),
86 (prefix_list_option "m",
87 (help "Enable or disable various extensions (-mmmx, -msse, etc.)"),
91 // Option preprocessor.
93 def Preprocess : OptionPreprocessor<
94 (case (not (any_switch_on ["O0", "O1", "O2", "O3"])),
96 (and (switch_on "O3"), (any_switch_on ["O0", "O1", "O2"])),
97 (unset_option ["O0", "O1", "O2"]),
98 (and (switch_on "O2"), (any_switch_on ["O0", "O1"])),
99 (unset_option ["O0", "O1"]),
100 (and (switch_on "O1"), (switch_on "O0")),
107 class llvm_gcc_based <string cmd_prefix, string in_lang, string E_ext> : Tool<
108 [(in_language in_lang),
109 (out_language "llvm-bitcode"),
110 (output_suffix "bc"),
113 (case (not_empty "o"),
114 !strconcat(cmd_prefix, " -E $INFILE -o $OUTFILE"),
116 !strconcat(cmd_prefix, " -E $INFILE")),
117 (switch_on "fsyntax-only"),
118 !strconcat(cmd_prefix, " -fsyntax-only $INFILE"),
119 (and (switch_on "S"), (switch_on "emit-llvm")),
120 !strconcat(cmd_prefix, " -S $INFILE -o $OUTFILE -emit-llvm"),
122 !strconcat(cmd_prefix, " -c $INFILE -o $OUTFILE -emit-llvm"))),
125 (and (multiple_input_files), (or (switch_on "S"), (switch_on "c"))),
126 (error "cannot specify -o with -c or -S with multiple files"),
127 (switch_on "E"), [(stop_compilation), (output_suffix E_ext)],
128 (and (switch_on "emit-llvm"), (switch_on "S")),
129 [(output_suffix "ll"), (stop_compilation)],
130 (and (switch_on "emit-llvm"), (switch_on "c")), (stop_compilation),
131 (switch_on "fsyntax-only"), (stop_compilation),
132 (not_empty "include"), (forward "include"),
133 (not_empty "save-temps"), (append_cmd "-save-temps"),
134 (not_empty "I"), (forward "I"),
135 (not_empty "F"), (forward "F"),
136 (not_empty "D"), (forward "D"),
137 (not_empty "march"), (forward "march"),
138 (not_empty "mtune"), (forward "mtune"),
139 (not_empty "mcpu"), (forward "mcpu"),
140 (not_empty "m"), (forward "m"),
141 (switch_on "m32"), (forward "m32"),
142 (switch_on "m64"), (forward "m64"),
143 (switch_on "O1"), (forward "O1"),
144 (switch_on "O2"), (forward "O2"),
145 (switch_on "O3"), (forward "O3"),
146 (switch_on "fPIC"), (forward "fPIC"),
147 (switch_on "mdynamic-no-pic"), (forward "mdynamic-no-pic"),
148 (not_empty "MF"), (forward "MF"),
149 (not_empty "MT"), (forward "MT"))),
153 def llvm_gcc_c : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x c", "c", "i">;
154 def llvm_gcc_cpp : llvm_gcc_based<"@LLVMGXXCOMMAND@ -x c++", "c++", "i">;
155 def llvm_gcc_m : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c",
156 "objective-c", "mi">;
157 def llvm_gcc_mxx : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c++",
158 "objective-c++", "mi">;
161 [(in_language "llvm-bitcode"),
162 (out_language "llvm-bitcode"),
163 (output_suffix "bc"),
164 (actions (case (not_empty "Wo,"), (forward_value "Wo,"),
165 (switch_on "O1"), (forward "O1"),
166 (switch_on "O2"), (forward "O2"),
167 (switch_on "O3"), (forward "O3"))),
168 (cmd_line "opt -f $INFILE -o $OUTFILE")
172 [(in_language "llvm-assembler"),
173 (out_language "llvm-bitcode"),
174 (output_suffix "bc"),
175 (cmd_line "llvm-as $INFILE -o $OUTFILE"),
176 (actions (case (switch_on "emit-llvm"), (stop_compilation)))
179 def llvm_gcc_assembler : Tool<
180 [(in_language "assembler"),
181 (out_language "object-code"),
183 (cmd_line "@LLVMGCCCOMMAND@ -c -x assembler $INFILE -o $OUTFILE"),
185 (switch_on "c"), (stop_compilation),
186 (not_empty "Wa,"), (forward_value "Wa,")))
190 [(in_language ["llvm-bitcode", "llvm-assembler"]),
191 (out_language "assembler"),
193 (cmd_line "llc -f $INFILE -o $OUTFILE"),
195 (switch_on "S"), (stop_compilation),
196 (switch_on "O0"), (forward "O0"),
197 (switch_on "O1"), (forward "O1"),
198 (switch_on "O2"), (forward "O2"),
199 (switch_on "O3"), (forward "O3"),
200 (switch_on "fPIC"), (append_cmd "-relocation-model=pic"),
201 (switch_on "mdynamic-no-pic"),
202 (append_cmd "-relocation-model=dynamic-no-pic"),
203 (not_empty "march"), (forward "mcpu"),
204 (not_empty "mtune"), (forward "mcpu"),
205 (not_empty "mcpu"), (forward "mcpu"),
206 (not_empty "m"), (forward_transformed_value "m", "ConvertToMAttr"),
207 (not_empty "Wllc,"), (forward_value "Wllc,")))
210 // Base class for linkers
211 class llvm_gcc_based_linker <string cmd_prefix> : Tool<
212 [(in_language "object-code"),
213 (out_language "executable"),
214 (output_suffix "out"),
215 (cmd_line !strconcat(cmd_prefix, " $INFILE -o $OUTFILE")),
218 (switch_on "pthread"), (append_cmd "-lpthread"),
219 (not_empty "L"), (forward "L"),
220 (not_empty "F"), (forward "F"),
221 (not_empty "framework"), (forward "framework"),
222 (not_empty "weak_framework"), (forward "weak_framework"),
223 (switch_on "m32"), (forward "m32"),
224 (switch_on "m64"), (forward "m64"),
225 (not_empty "l"), (forward "l"),
226 (not_empty "Wl,"), (forward "Wl,")))
230 def llvm_gcc_linker : llvm_gcc_based_linker<"@LLVMGCCCOMMAND@">;
231 // Alternative linker for C++
232 def llvm_gcc_cpp_linker : llvm_gcc_based_linker<"@LLVMGXXCOMMAND@">;
236 def LanguageMap : LanguageMap<
237 [LangToSuffixes<"c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]>,
238 LangToSuffixes<"c", ["c"]>,
239 LangToSuffixes<"c-cpp-output", ["i"]>,
240 LangToSuffixes<"objective-c-cpp-output", ["mi"]>,
241 LangToSuffixes<"objective-c++", ["mm"]>,
242 LangToSuffixes<"objective-c", ["m"]>,
243 LangToSuffixes<"assembler", ["s"]>,
244 LangToSuffixes<"assembler-with-cpp", ["S"]>,
245 LangToSuffixes<"llvm-assembler", ["ll"]>,
246 LangToSuffixes<"llvm-bitcode", ["bc"]>,
247 LangToSuffixes<"object-code", ["o"]>,
248 LangToSuffixes<"executable", ["out"]>
253 def CompilationGraph : CompilationGraph<[
254 Edge<"root", "llvm_gcc_c">,
255 Edge<"root", "llvm_gcc_assembler">,
256 Edge<"root", "llvm_gcc_cpp">,
257 Edge<"root", "llvm_gcc_m">,
258 Edge<"root", "llvm_gcc_mxx">,
261 Edge<"llvm_gcc_c", "llc">,
262 Edge<"llvm_gcc_cpp", "llc">,
263 Edge<"llvm_gcc_m", "llc">,
264 Edge<"llvm_gcc_mxx", "llc">,
265 Edge<"llvm_as", "llc">,
267 OptionalEdge<"root", "llvm_as",
268 (case (switch_on "emit-llvm"), (inc_weight))>,
269 OptionalEdge<"llvm_gcc_c", "opt", (case (switch_on "opt"), (inc_weight))>,
270 OptionalEdge<"llvm_gcc_cpp", "opt", (case (switch_on "opt"), (inc_weight))>,
271 OptionalEdge<"llvm_gcc_m", "opt", (case (switch_on "opt"), (inc_weight))>,
272 OptionalEdge<"llvm_gcc_mxx", "opt", (case (switch_on "opt"), (inc_weight))>,
273 OptionalEdge<"llvm_as", "opt", (case (switch_on "opt"), (inc_weight))>,
276 Edge<"llc", "llvm_gcc_assembler">,
277 Edge<"llvm_gcc_assembler", "llvm_gcc_linker">,
278 OptionalEdge<"llvm_gcc_assembler", "llvm_gcc_cpp_linker",
280 (or (input_languages_contain "c++"),
281 (input_languages_contain "objective-c++")),
283 (or (parameter_equals "linker", "g++"),
284 (parameter_equals "linker", "c++")), (inc_weight))>,
287 Edge<"root", "llvm_gcc_linker">,
288 OptionalEdge<"root", "llvm_gcc_cpp_linker",
290 (or (input_languages_contain "c++"),
291 (input_languages_contain "objective-c++")),
293 (or (parameter_equals "linker", "g++"),
294 (parameter_equals "linker", "c++")), (inc_weight))>