diff options
author | dim <dim@FreeBSD.org> | 2011-02-20 12:57:14 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2011-02-20 12:57:14 +0000 |
commit | cbb70ce070d220642b038ea101d9c0f9fbf860d6 (patch) | |
tree | d2b61ce94e654cb01a254d2195259db5f9cc3f3c /tools/llvmc | |
parent | 4ace901e87dac5bbbac78ed325e75462e48e386e (diff) | |
download | FreeBSD-src-cbb70ce070d220642b038ea101d9c0f9fbf860d6.zip FreeBSD-src-cbb70ce070d220642b038ea101d9c0f9fbf860d6.tar.gz |
Vendor import of llvm trunk r126079:
http://llvm.org/svn/llvm-project/llvm/trunk@126079
Diffstat (limited to 'tools/llvmc')
-rw-r--r-- | tools/llvmc/doc/LLVMC-Reference.rst | 71 | ||||
-rw-r--r-- | tools/llvmc/examples/mcc16/Hooks.cpp | 2 | ||||
-rw-r--r-- | tools/llvmc/examples/mcc16/Main.cpp | 2 | ||||
-rw-r--r-- | tools/llvmc/src/Base.td.in | 227 | ||||
-rw-r--r-- | tools/llvmc/src/Clang.td | 6 | ||||
-rw-r--r-- | tools/llvmc/src/Hooks.cpp | 181 |
6 files changed, 366 insertions, 123 deletions
diff --git a/tools/llvmc/doc/LLVMC-Reference.rst b/tools/llvmc/doc/LLVMC-Reference.rst index d160e75..ec9098b 100644 --- a/tools/llvmc/doc/LLVMC-Reference.rst +++ b/tools/llvmc/doc/LLVMC-Reference.rst @@ -319,7 +319,8 @@ separate option groups syntactically. - ``alias_option`` - a special option type for creating aliases. Unlike other option types, aliases are not allowed to have any properties besides the - aliased option name. Usage example: ``(alias_option "preprocess", "E")`` + aliased option name. + Usage example: ``(alias_option "preprocess", "E")`` - ``switch_list_option`` - like ``switch_option`` with the ``zero_or_more`` property, but remembers how many times the switch was turned on. Useful @@ -456,22 +457,22 @@ use TableGen inheritance instead. * Possible tests are: - ``switch_on`` - Returns true if a given command-line switch is provided by - the user. Can be given a list as argument, in that case ``(switch_on ["foo", - "bar", "baz"])`` is equivalent to ``(and (switch_on "foo"), (switch_on + the user. Can be given multiple arguments, in that case ``(switch_on "foo", + "bar", "baz")`` is equivalent to ``(and (switch_on "foo"), (switch_on "bar"), (switch_on "baz"))``. Example: ``(switch_on "opt")``. - - ``any_switch_on`` - Given a list of switch options, returns true if any of + - ``any_switch_on`` - Given a number of switch options, returns true if any of the switches is turned on. - Example: ``(any_switch_on ["foo", "bar", "baz"])`` is equivalent to ``(or + Example: ``(any_switch_on "foo", "bar", "baz")`` is equivalent to ``(or (switch_on "foo"), (switch_on "bar"), (switch_on "baz"))``. - - ``parameter_equals`` - Returns true if a command-line parameter equals - a given value. + - ``parameter_equals`` - Returns true if a command-line parameter (first + argument) equals a given value (second argument). Example: ``(parameter_equals "W", "all")``. - - ``element_in_list`` - Returns true if a command-line parameter - list contains a given value. + - ``element_in_list`` - Returns true if a command-line parameter list (first + argument) contains a given value (second argument). Example: ``(element_in_list "l", "pthread")``. - ``input_languages_contain`` - Returns true if a given language @@ -479,27 +480,27 @@ use TableGen inheritance instead. Example: ``(input_languages_contain "c++")``. - ``in_language`` - Evaluates to true if the input file language is equal to - the argument. At the moment works only with ``cmd_line`` and ``actions`` (on + the argument. At the moment works only with ``command`` and ``actions`` (on non-join nodes). Example: ``(in_language "c++")``. - ``not_empty`` - Returns true if a given option (which should be either a parameter or a parameter list) is set by the user. Like ``switch_on``, can - be also given a list as argument. - Example: ``(not_empty "o")``. + be also given multiple arguments. + Examples: ``(not_empty "o")``, ``(not_empty "o", "l")``. - ``any_not_empty`` - Returns true if ``not_empty`` returns true for any of - the options in the list. - Example: ``(any_not_empty ["foo", "bar", "baz"])`` is equivalent to ``(or + the provided options. + Example: ``(any_not_empty "foo", "bar", "baz")`` is equivalent to ``(or (not_empty "foo"), (not_empty "bar"), (not_empty "baz"))``. - ``empty`` - The opposite of ``not_empty``. Equivalent to ``(not (not_empty - X))``. Provided for convenience. Can be given a list as argument. + X))``. Can be given multiple arguments. - ``any_not_empty`` - Returns true if ``not_empty`` returns true for any of - the options in the list. - Example: ``(any_empty ["foo", "bar", "baz"])`` is equivalent to ``(not (and - (not_empty "foo"), (not_empty "bar"), (not_empty "baz")))``. + the provided options. + Example: ``(any_empty "foo", "bar", "baz")`` is equivalent to ``(or + (not_empty "foo"), (not_empty "bar"), (not_empty "baz"))``. - ``single_input_file`` - Returns true if there was only one input file provided on the command-line. Used without arguments: @@ -511,16 +512,18 @@ use TableGen inheritance instead. - ``default`` - Always evaluates to true. Should always be the last test in the ``case`` expression. - - ``and`` - A standard binary logical combinator that returns true iff all of + - ``and`` - A standard logical combinator that returns true iff all of its arguments return true. Used like this: ``(and (test1), (test2), ... (testN))``. Nesting of ``and`` and ``or`` is allowed, but not encouraged. - - ``or`` - A binary logical combinator that returns true iff any of its - arguments returns true. Example: ``(or (test1), (test2), ... (testN))``. + - ``or`` - A logical combinator that returns true iff any of its arguments + return true. + Example: ``(or (test1), (test2), ... (testN))``. - ``not`` - Standard unary logical combinator that negates its - argument. Example: ``(not (or (test1), (test2), ... (testN)))``. + argument. + Example: ``(not (or (test1), (test2), ... (testN)))``. @@ -549,10 +552,10 @@ The complete list of all currently implemented tool properties follows. * Possible tool properties: - - ``in_language`` - input language name. Can be either a string or a - list, in case the tool supports multiple input languages. + - ``in_language`` - input language name. Can be given multiple arguments, in + case the tool supports multiple input languages. - - ``out_language`` - output language name. Multiple output languages are not + - ``out_language`` - output language name. Multiple output languages are allowed. - ``output_suffix`` - output file suffix. Can also be changed @@ -687,12 +690,12 @@ occasions. Example (adapted from the built-in Base plugin):: def Preprocess : OptionPreprocessor< - (case (not (any_switch_on ["O0", "O1", "O2", "O3"])), + (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"]), + (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"), (and (switch_on "O1"), (switch_on "O0")), (unset_option "O0")) >; @@ -709,10 +712,10 @@ set or unset a given option. To set an option with ``set_option``, use the two-argument form: ``(set_option "parameter", VALUE)``. Here, ``VALUE`` can be either a string, a string list, or a boolean constant. -For convenience, ``set_option`` and ``unset_option`` also work on lists. That -is, instead of ``[(unset_option "A"), (unset_option "B")]`` you can use -``(unset_option ["A", "B"])``. Obviously, ``(set_option ["A", "B"])`` is valid -only if both ``A`` and ``B`` are switches. +For convenience, ``set_option`` and ``unset_option`` also work with multiple +arguments. That is, instead of ``[(unset_option "A"), (unset_option "B")]`` you +can use ``(unset_option "A", "B")``. Obviously, ``(set_option "A", "B")`` is +only valid if both ``A`` and ``B`` are switches. More advanced topics diff --git a/tools/llvmc/examples/mcc16/Hooks.cpp b/tools/llvmc/examples/mcc16/Hooks.cpp index edb91e1..95158ef 100644 --- a/tools/llvmc/examples/mcc16/Hooks.cpp +++ b/tools/llvmc/examples/mcc16/Hooks.cpp @@ -1,4 +1,4 @@ -#include "llvm/System/Path.h" +#include "llvm/Support/Path.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/raw_ostream.h" diff --git a/tools/llvmc/examples/mcc16/Main.cpp b/tools/llvmc/examples/mcc16/Main.cpp index 55ae912..5d4992d 100644 --- a/tools/llvmc/examples/mcc16/Main.cpp +++ b/tools/llvmc/examples/mcc16/Main.cpp @@ -16,7 +16,7 @@ #include "llvm/CompilerDriver/BuiltinOptions.h" #include "llvm/CompilerDriver/Main.h" -#include "llvm/System/Path.h" +#include "llvm/Support/Path.h" #include "llvm/Config/config.h" #include <iostream> diff --git a/tools/llvmc/src/Base.td.in b/tools/llvmc/src/Base.td.in index 0c4de4c..50533f1 100644 --- a/tools/llvmc/src/Base.td.in +++ b/tools/llvmc/src/Base.td.in @@ -11,7 +11,6 @@ // //===----------------------------------------------------------------------===// - // Options def OptList : OptionList<[ @@ -35,8 +34,6 @@ def OptList : OptionList<[ (help "Stop after compilation, do not assemble")), (switch_option "c", (help "Compile and assemble, but do not link")), - (switch_option "pthread", - (help "Enable threads")), (switch_option "m32", (help "Generate code for a 32-bit environment"), (hidden)), (switch_option "m64", @@ -45,22 +42,21 @@ def OptList : OptionList<[ (help "Relocation model: PIC"), (hidden)), (switch_option "mdynamic-no-pic", (help "Relocation model: dynamic-no-pic"), (hidden)), - (switch_option "shared", - (help "Create a DLL instead of the regular executable")), (parameter_option "linker", (help "Choose linker (possible values: gcc, g++)")), (parameter_option "mtune", - (help "Target a specific CPU type"), (hidden), (forward_not_split)), - - // 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)), - (parameter_option "march", - (help "A synonym for -mtune"), (hidden), (forward_not_split)), + (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", @@ -73,14 +69,6 @@ def OptList : OptionList<[ (parameter_list_option "iquote", (help "Search dir only for files requested with #inlcude \"file\""), (hidden)), - (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)), - (parameter_option "filelist", (hidden), - (help "Link the files listed in file")), - (prefix_list_option "F", - (help "Add a directory to framework search path")), (prefix_list_option "I", (help "Add a directory to include path")), (prefix_list_option "D", @@ -93,10 +81,6 @@ def OptList : OptionList<[ (help "Pass options to assembler")), (prefix_list_option "Wllc,", (comma_separated), (help "Pass options to llc")), - (prefix_list_option "L", - (help "Add a directory to link path")), - (prefix_list_option "l", - (help "Search a library when linking")), (prefix_list_option "Wl,", (help "Pass options to linker")), (parameter_list_option "Xlinker", (hidden), @@ -105,7 +89,56 @@ def OptList : OptionList<[ (help "Pass options to opt")), (prefix_list_option "m", (help "Enable or disable various extensions (-mmmx, -msse, etc.)"), - (hidden)), + (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), @@ -125,24 +158,24 @@ def OptList : OptionList<[ // Option preprocessor. def Preprocess : OptionPreprocessor< -(case (not (any_switch_on ["O0", "O1", "O2", "O3"])), +(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"]), + (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_prefix, string in_lang, - string E_ext, string out_lang> : Tool< +class llvm_gcc_based <string cmd, string in_lang, string E_ext, dag out_lang, + string out_ext> : Tool< [(in_language in_lang), - (out_language "llvm-bitcode"), - (output_suffix out_lang), - (command cmd_prefix), + out_lang, + (output_suffix out_ext), + (command cmd), (actions (case (and (not_empty "o"), @@ -151,14 +184,20 @@ class llvm_gcc_based <string cmd_prefix, string in_lang, (switch_on "E"), [(forward "E"), (stop_compilation), (output_suffix E_ext)], (and (switch_on "E"), (empty "o")), (no_out_file), - (switch_on ["emit-llvm", "S"]), - [(output_suffix "ll"), (stop_compilation)], - (switch_on ["emit-llvm", "c"]), (stop_compilation), + + // ('-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)], - (switch_on ["S", "emit-llvm"]), [(forward "S"), (forward "emit-llvm")], - (not (or (switch_on ["S", "emit-llvm"]), (switch_on "fsyntax-only"))), - [(append_cmd "-c"), (append_cmd "-emit-llvm")], // Forwards (not_empty "Xpreprocessor"), (forward "Xpreprocessor"), @@ -170,8 +209,11 @@ class llvm_gcc_based <string cmd_prefix, string in_lang, (not_empty "D"), (forward "D"), (not_empty "arch"), (forward "arch"), (not_empty "march"), (forward "march"), - (not_empty "mtune"), (forward "mtune"), (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"), @@ -187,30 +229,40 @@ class llvm_gcc_based <string cmd_prefix, string in_lang, (sink) ]>; -def llvm_gcc_c : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x c", "c", "i", "bc">; -def llvm_gcc_cpp : llvm_gcc_based<"@LLVMGXXCOMMAND@ -x c++", "c++", "i", "bc">; -def llvm_gcc_m : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c", - "objective-c", "mi", "bc">; -def llvm_gcc_mxx : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c++", - "objective-c++", "mi", "bc">; +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_pch : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x c-header", - "c-header", "i", "gch">; -def llvm_gcc_cpp_pch : llvm_gcc_based<"@LLVMGXXCOMMAND@ -x c++-header", - "c++-header", - "i", "gch">; -def llvm_gcc_m_pch : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c-header", - "objective-c-header", - "mi", "gch">; -def llvm_gcc_mxx_pch - : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c++-header", - "objective-c++-header", "mi", "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 "bc"), - (actions (case (not_empty "Wo,"), (forward_value "Wo,"), + (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"))), @@ -222,7 +274,8 @@ def llvm_as : Tool< (out_language "llvm-bitcode"), (output_suffix "bc"), (command "llvm-as"), - (actions (case (switch_on "emit-llvm"), (stop_compilation))) + (actions (case (and (switch_on "emit-llvm"), (not (switch_on "opt"))), + (stop_compilation))) ]>; def llvm_gcc_assembler : Tool< @@ -234,13 +287,18 @@ def llvm_gcc_assembler : Tool< (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"]), +[(in_language "llvm-bitcode", "llvm-assembler"), (out_language "assembler"), (output_suffix "s"), (command "llc"), @@ -253,19 +311,22 @@ def llc : Tool< (switch_on "fPIC"), (append_cmd "-relocation-model=pic"), (switch_on "mdynamic-no-pic"), (append_cmd "-relocation-model=dynamic-no-pic"), - (not_empty "march"), (forward_as "mtune", "-mcpu"), - (not_empty "mtune"), (forward_as "mtune", "-mcpu"), - (not_empty "mcpu"), (forward "mcpu"), + (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_prefix, dag on_empty> : Tool< -[(in_language ["object-code", "static-library", "dynamic-library"]), +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_prefix), + (command cmd), (works_on_empty (case (and (not_empty "filelist"), on_empty), true, (default), false)), (join), @@ -277,12 +338,28 @@ class llvm_gcc_based_linker <string cmd_prefix, dag on_empty> : Tool< (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"), @@ -305,6 +382,7 @@ def llvm_gcc_cpp_linker : llvm_gcc_based_linker<"@LLVMGXXCOMMAND@", // 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"), @@ -322,7 +400,7 @@ def LanguageMap : LanguageMap<[ (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"]) + (lang_to_suffixes "executable", "out") ]>; // Compilation graph @@ -347,7 +425,8 @@ def CompilationGraph : CompilationGraph<[ (edge "llvm_as", "llc"), (optional_edge "root", "llvm_as", - (case (switch_on "emit-llvm"), (inc_weight))), + (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", diff --git a/tools/llvmc/src/Clang.td b/tools/llvmc/src/Clang.td index 1d75743..e2d32e8 100644 --- a/tools/llvmc/src/Clang.td +++ b/tools/llvmc/src/Clang.td @@ -25,12 +25,12 @@ class clang_based<string language, string cmd, string ext_E> : Tool< [(forward "E"), (stop_compilation), (output_suffix ext_E)], (and (switch_on "E"), (empty "o")), (no_out_file), (switch_on "fsyntax-only"), (stop_compilation), - (switch_on ["S", "emit-llvm"]), + (switch_on "S", "emit-llvm"), [(append_cmd "-emit-llvm"), (stop_compilation), (output_suffix "ll")], - (not (switch_on ["S", "emit-llvm"])), + (not (switch_on "S", "emit-llvm")), (append_cmd "-emit-llvm-bc"), - (switch_on ["c", "emit-llvm"]), + (switch_on "c", "emit-llvm"), (stop_compilation), (not_empty "include"), (forward "include"), (not_empty "I"), (forward "I"))), diff --git a/tools/llvmc/src/Hooks.cpp b/tools/llvmc/src/Hooks.cpp index 661a914..5aa250e 100644 --- a/tools/llvmc/src/Hooks.cpp +++ b/tools/llvmc/src/Hooks.cpp @@ -1,14 +1,182 @@ +#include "llvm/ADT/StringMap.h" + #include <string> #include <vector> namespace hooks { + +/// NUM_KEYS - Calculate the size of a const char* array. +#define NUM_KEYS(Keys) sizeof(Keys) / sizeof(const char*) + +// See http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 +inline unsigned NextHighestPowerOf2 (unsigned i) { + --i; + i |= i >> 1; + i |= i >> 2; + i |= i >> 4; + i |= i >> 8; + i |= i >> 16; + ++i; + return i; +} + typedef std::vector<std::string> StrVec; +typedef llvm::StringMap<const char*> ArgMap; + +/// AddPlusOrMinus - Convert 'no-foo' to '-foo' and 'foo' to '+foo'. +void AddPlusOrMinus (const std::string& Arg, std::string& out) { + if (Arg.find("no-") == 0 && Arg[3] != 0) { + out += '-'; + out += Arg.c_str() + 3; + } + else { + out += '+'; + out += Arg; + } +} + +// -march values that need to be special-cased. +const char* MArchKeysARM[] = { "armv4t", "armv5t", "armv5te", "armv6", + "armv6-m", "armv6t2", "armv7-a", "armv7-m" }; +const char* MArchValuesARM[] = { "v4t", "v5t", "v5te", "v6", "v6m", "v6t2", + "v7a", "v7m" }; +const unsigned MArchNumKeysARM = NUM_KEYS(MArchKeysARM); +const unsigned MArchMapSize = NextHighestPowerOf2(MArchNumKeysARM); + +// -march values that should be forwarded as -mcpu +const char* MArchMCpuKeysARM[] = { "iwmmxt", "ep9312" }; +const char* MArchMCpuValuesARM[] = { "iwmmxt", "ep9312"}; +const unsigned MArchMCpuNumKeysARM = NUM_KEYS(MArchMCpuKeysARM); +const unsigned MArchMCpuMapSize = NextHighestPowerOf2(MArchMCpuNumKeysARM); + + +void FillInArgMap(ArgMap& Args, const char* Keys[], + const char* Values[], unsigned NumKeys) +{ + for (unsigned i = 0; i < NumKeys; ++i) { + // Explicit cast to StringRef here is necessary to pick up the right + // overload. + Args.GetOrCreateValue(llvm::StringRef(Keys[i]), Values[i]); + } +} + +/// ConvertMArchToMAttr - Convert -march from the gcc dialect to +/// something llc can understand. +std::string ConvertMArchToMAttr(const StrVec& Opts) { + static ArgMap MArchMap(MArchMapSize); + static ArgMap MArchMCpuMap(MArchMapSize); + static bool StaticDataInitialized = false; + + if (!StaticDataInitialized) { + FillInArgMap(MArchMap, MArchKeysARM, MArchValuesARM, MArchNumKeysARM); + FillInArgMap(MArchMCpuMap, MArchMCpuKeysARM, + MArchMCpuValuesARM, MArchMCpuNumKeysARM); + StaticDataInitialized = true; + } + + std::string mattr("-mattr="); + std::string mcpu("-mcpu="); + bool mattrTouched = false; + bool mcpuTouched = false; + + for (StrVec::const_iterator B = Opts.begin(), E = Opts.end(); B!=E; ++B) { + const std::string& Arg = *B; + + // Check if the argument should be forwarded to -mcpu instead of -mattr. + { + ArgMap::const_iterator I = MArchMCpuMap.find(Arg); + + if (I != MArchMCpuMap.end()) { + mcpuTouched = true; + mcpu += I->getValue(); + continue; + } + } + + if (mattrTouched) + mattr += ","; + + // Check if the argument is a special case. + { + ArgMap::const_iterator I = MArchMap.find(Arg); -/// ConvertToMAttr - Convert -m* and -mno-* to -mattr=+*,-* + if (I != MArchMap.end()) { + mattrTouched = true; + mattr += '+'; + mattr += I->getValue(); + continue; + } + } + + AddPlusOrMinus(Arg, mattr); + } + + std::string out; + if (mattrTouched) + out += mattr; + if (mcpuTouched) + out += (mattrTouched ? " " : "") + mcpu; + + return out; +} + +// -mcpu values that need to be special-cased. +const char* MCpuKeysPPC[] = { "G3", "G4", "G5", "powerpc", "powerpc64"}; +const char* MCpuValuesPPC[] = { "g3", "g4", "g5", "ppc", "ppc64"}; +const unsigned MCpuNumKeysPPC = NUM_KEYS(MCpuKeysPPC); +const unsigned MCpuMapSize = NextHighestPowerOf2(MCpuNumKeysPPC); + +/// ConvertMCpu - Convert -mcpu value from the gcc to the llc dialect. +std::string ConvertMCpu(const char* Val) { + static ArgMap MCpuMap(MCpuMapSize); + static bool StaticDataInitialized = false; + + if (!StaticDataInitialized) { + FillInArgMap(MCpuMap, MCpuKeysPPC, MCpuValuesPPC, MCpuNumKeysPPC); + StaticDataInitialized = true; + } + + std::string ret = "-mcpu="; + ArgMap::const_iterator I = MCpuMap.find(Val); + if (I != MCpuMap.end()) { + return ret + I->getValue(); + } + return ret + Val; +} + +// -mfpu values that need to be special-cased. +const char* MFpuKeysARM[] = { "vfp", "vfpv3", + "vfpv3-fp16", "vfpv3-d16", "vfpv3-d16-fp16", + "neon", "neon-fp16" }; +const char* MFpuValuesARM[] = { "vfp2", "vfp3", + "+vfp3,+fp16", "+vfp3,+d16", "+vfp3,+d16,+fp16", + "+neon", "+neon,+neonfp" }; +const unsigned MFpuNumKeysARM = NUM_KEYS(MFpuKeysARM); +const unsigned MFpuMapSize = NextHighestPowerOf2(MFpuNumKeysARM); + +/// ConvertMFpu - Convert -mfpu value from the gcc to the llc dialect. +std::string ConvertMFpu(const char* Val) { + static ArgMap MFpuMap(MFpuMapSize); + static bool StaticDataInitialized = false; + + if (!StaticDataInitialized) { + FillInArgMap(MFpuMap, MFpuKeysARM, MFpuValuesARM, MFpuNumKeysARM); + StaticDataInitialized = true; + } + + std::string ret = "-mattr="; + ArgMap::const_iterator I = MFpuMap.find(Val); + if (I != MFpuMap.end()) { + return ret + I->getValue(); + } + return ret + '+' + Val; +} + +/// ConvertToMAttr - Convert '-mfoo' and '-mno-bar' to '-mattr=+foo,-bar'. std::string ConvertToMAttr(const StrVec& Opts) { std::string out("-mattr="); - bool firstIter = true; + for (StrVec::const_iterator B = Opts.begin(), E = Opts.end(); B!=E; ++B) { const std::string& Arg = *B; @@ -17,14 +185,7 @@ std::string ConvertToMAttr(const StrVec& Opts) { else out += ","; - if (Arg.find("no-") == 0 && Arg[3] != 0) { - out += '-'; - out += Arg.c_str() + 3; - } - else { - out += '+'; - out += Arg; - } + AddPlusOrMinus(Arg, out); } return out; |