llvm-build: Add --native-target and --enable-targets options, and add logic to
authorDaniel Dunbar <daniel@zuster.org>
Thu, 10 Nov 2011 00:50:07 +0000 (00:50 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Thu, 10 Nov 2011 00:50:07 +0000 (00:50 +0000)
handle defining the "magic" target related components (like native,
nativecodegen, and engine).
 - We still require these components to be in the project (currently in
   lib/Target) so that we have a place to document them and hopefully make it
   more obvious that they are "magic".

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@144253 91177308-0d34-0410-b5e6-96231b3b80d8

15 files changed:
lib/Target/ARM/LLVMBuild.txt
lib/Target/CBackend/LLVMBuild.txt
lib/Target/CellSPU/LLVMBuild.txt
lib/Target/CppBackend/LLVMBuild.txt
lib/Target/LLVMBuild.txt
lib/Target/MBlaze/LLVMBuild.txt
lib/Target/MSP430/LLVMBuild.txt
lib/Target/Mips/LLVMBuild.txt
lib/Target/PTX/LLVMBuild.txt
lib/Target/PowerPC/LLVMBuild.txt
lib/Target/Sparc/LLVMBuild.txt
lib/Target/X86/LLVMBuild.txt
lib/Target/XCore/LLVMBuild.txt
utils/llvm-build/llvmbuild/componentinfo.py
utils/llvm-build/llvmbuild/main.py

index cfac6ac51ba2c8f82921d2f228161f39f1d5d82b..79cae91f5b9185f176d799cd0b6b17abd05d0a5d 100644 (file)
@@ -19,7 +19,6 @@
 type = TargetGroup
 name = ARM
 parent = Target
 type = TargetGroup
 name = ARM
 parent = Target
-add_to_library_groups = all-targets
 has_jit = 1
 
 [component_1]
 has_jit = 1
 
 [component_1]
index 0b1f885703d662ab6fb0824c11ae32d4284e8a37..851ded923c7b691cd9036c41d9e0e033c64f43a2 100644 (file)
@@ -19,7 +19,6 @@
 type = TargetGroup
 name = CBackend
 parent = Target
 type = TargetGroup
 name = CBackend
 parent = Target
-add_to_library_groups = all-targets
 
 [component_1]
 type = Library
 
 [component_1]
 type = Library
index e8db9f3f84da5838caad666e07eb1577905ea026..a2127dd1c000eae2e7f0a93bf3e584bc20edc556 100644 (file)
@@ -19,7 +19,6 @@
 type = TargetGroup
 name = CellSPU
 parent = Target
 type = TargetGroup
 name = CellSPU
 parent = Target
-add_to_library_groups = all-targets
 
 [component_1]
 type = Library
 
 [component_1]
 type = Library
index 79ad4c1f54453ee5ab0d955becc88fe9956684bd..77e31c7af0bc577e0f3b1eba0a3c6d9f898e615f 100644 (file)
@@ -19,7 +19,6 @@
 type = TargetGroup
 name = CppBackend
 parent = Target
 type = TargetGroup
 name = CppBackend
 parent = Target
-add_to_library_groups = all-targets
 
 [component_1]
 type = Library
 
 [component_1]
 type = Library
index 073a76a0f1a0aa205f27ef6ffb6ac8c5bf5d5cd7..09dadd6b1e9d1e8fc1e3cfee9bb5d1d135b4e5e7 100644 (file)
@@ -21,20 +21,32 @@ name = Target
 parent = Libraries
 required_libraries = Core MC Support
 
 parent = Libraries
 required_libraries = Core MC Support
 
+; This is a convenient group we define (and expect targets to add to) which
+; makes it easy for tools to include every target.
 [component_1]
 type = LibraryGroup
 name = all-targets
 parent = Libraries
 
 [component_1]
 type = LibraryGroup
 name = all-targets
 parent = Libraries
 
+; This is a special group whose required libraries are extended (by llvm-build)
+; with the configured native target, if any.
 [component_2]
 type = LibraryGroup
 [component_2]
 type = LibraryGroup
-name = native
+name = Native
 parent = Libraries
 parent = Libraries
-required_libraries = X86
 
 
+; This is a special group whose required libraries are extended (by llvm-build)
+; with the configured native code generator, if any.
 [component_3]
 type = LibraryGroup
 [component_3]
 type = LibraryGroup
-name = nativecodegen
+name = NativeCodeGen
+parent = Libraries
+
+; This is a special group whose required libraries are extended (by llvm-build)
+; with the best execution engine (the native JIT, if available, or the
+; interpreter).
+[component_4]
+type = LibraryGroup
+name = Engine
 parent = Libraries
 parent = Libraries
-required_libraries = X86CodeGen
 
 
index b953e3df305662c9a0c464089e418cee19b13bd3..fa8955252d80c463dad4e0d1a3bb71ab2fb8f0e5 100644 (file)
@@ -19,7 +19,6 @@
 type = TargetGroup
 name = MBlaze
 parent = Target
 type = TargetGroup
 name = MBlaze
 parent = Target
-add_to_library_groups = all-targets
 
 [component_1]
 type = Library
 
 [component_1]
 type = Library
index 8b0b1f6534d4a429a8af2cd6cba1150c7bca5035..9ade11066880345fb9d391debafb523a4ec66cca 100644 (file)
@@ -19,7 +19,6 @@
 type = TargetGroup
 name = MSP430
 parent = Target
 type = TargetGroup
 name = MSP430
 parent = Target
-add_to_library_groups = all-targets
 
 [component_1]
 type = Library
 
 [component_1]
 type = Library
index bcec4a9661f866aa96842849ecc18a1470b3b31f..65c7d7fd2f0ceb730a000b02ac334336ae56339e 100644 (file)
@@ -19,7 +19,6 @@
 type = TargetGroup
 name = Mips
 parent = Target
 type = TargetGroup
 name = Mips
 parent = Target
-add_to_library_groups = all-targets
 has_jit = 1
 
 [component_1]
 has_jit = 1
 
 [component_1]
index 27119c2a3e7ea13c3d366ea6b67464f1a106b804..180e7ce82cc76d49817802e1b5cb25c0a6714a60 100644 (file)
@@ -19,7 +19,6 @@
 type = TargetGroup
 name = PTX
 parent = Target
 type = TargetGroup
 name = PTX
 parent = Target
-add_to_library_groups = all-targets
 
 [component_1]
 type = Library
 
 [component_1]
 type = Library
index 3c439f37738547cccd4274b249deeb3445f42d1e..ce8b2e9196a6aa03d5507e1bdcf7e473ef0f60fb 100644 (file)
@@ -19,7 +19,6 @@
 type = TargetGroup
 name = PowerPC
 parent = Target
 type = TargetGroup
 name = PowerPC
 parent = Target
-add_to_library_groups = all-targets
 has_jit = 1
 
 [component_1]
 has_jit = 1
 
 [component_1]
index f59cc2eec422df171e60191e34e3c1745a215a02..d99057f20b26ecf9a895568ded4dfcd2de559b9d 100644 (file)
@@ -19,7 +19,6 @@
 type = TargetGroup
 name = Sparc
 parent = Target
 type = TargetGroup
 name = Sparc
 parent = Target
-add_to_library_groups = all-targets
 
 [component_1]
 type = Library
 
 [component_1]
 type = Library
index 7f48a9e485cfa1e39df88d3de099db00e6455ca2..814e81b304bf169dfba8e9b81d93baf76893c85a 100644 (file)
@@ -19,7 +19,6 @@
 type = TargetGroup
 name = X86
 parent = Target
 type = TargetGroup
 name = X86
 parent = Target
-add_to_library_groups = all-targets
 has_jit = 1
 
 [component_1]
 has_jit = 1
 
 [component_1]
index 41943c3690604d3f81689cbf339a91d3f17354ec..f1b75740cbeef029c79f0392cc38c7f0ff2cfa7a 100644 (file)
@@ -19,7 +19,6 @@
 type = TargetGroup
 name = XCore
 parent = Target
 type = TargetGroup
 name = XCore
 parent = Target
-add_to_library_groups = all-targets
 
 [component_1]
 type = Library
 
 [component_1]
 type = Library
index 00b8ac52a94537a4dfc26e296bca652dc00b189f..6897d10f31a04f035f9abe4c7e02789df9eef929 100644 (file)
@@ -215,6 +215,10 @@ class TargetGroupComponentInfo(ComponentInfo):
         # Whether or not this target supports the JIT.
         self.has_jit = bool(has_jit)
 
         # Whether or not this target supports the JIT.
         self.has_jit = bool(has_jit)
 
+        # Whether or not this target is enabled. This is set in response to
+        # configuration parameters.
+        self.enabled = False
+
     def get_component_references(self):
         for r in ComponentInfo.get_component_references(self):
             yield r
     def get_component_references(self):
         for r in ComponentInfo.get_component_references(self):
             yield r
index e27acd2f32659192f5a8fb7b229d8ecba769fc2a..fe852a0c4e2a38bd58205af143c75c9fab81e5ef 100644 (file)
@@ -498,6 +498,105 @@ configure_file(\"%s\"
 
         f.close()
 
 
         f.close()
 
+def add_magic_target_components(parser, project, opts):
+    """add_magic_target_components(project, opts) -> None
+
+    Add the "magic" target based components to the project, which can only be
+    determined based on the target configuration options.
+
+    This currently is responsible for populating the required_libraries list of
+    the "Native", "NativeCodeGen", and "Engine" components.
+    """
+
+    # Determine the available targets.
+    available_targets = dict((ci.name,ci)
+                             for ci in project.component_infos
+                             if ci.type_name == 'TargetGroup')
+
+    # Find the configured native target.
+
+    # We handle a few special cases of target names here for historical
+    # reasons, as these are the names configure currently comes up with.
+    native_target_name = { 'x86' : 'X86',
+                           'x86_64' : 'X86',
+                           'Unknown' : None }.get(opts.native_target,
+                                                  opts.native_target)
+    if native_target_name is None:
+        native_target = None
+    else:
+        native_target = available_targets.get(native_target_name)
+        if native_target is None:
+            parser.error("invalid native target: %r (not in project)" % (
+                    opts.native_target,))
+        if native_target.type_name != 'TargetGroup':
+            parser.error("invalid native target: %r (not a target)" % (
+                    opts.native_target,))
+
+    # Find the list of targets to enable.
+    if opts.enable_targets is None:
+        enable_targets = available_targets.values()
+    else:
+        enable_targets = []
+        for name in opts.enable_targets.split():
+            target = available_targets.get(name)
+            if target is None:
+                parser.error("invalid target to enable: %r (not in project)" % (
+                        name,))
+            if target.type_name != 'TargetGroup':
+                parser.error("invalid target to enable: %r (not a target)" % (
+                        name,))
+            enable_targets.append(target)
+
+    # Find the special library groups we are going to populate. We enforce that
+    # these appear in the project (instead of just adding them) so that they at
+    # least have an explicit representation in the project LLVMBuild files (and
+    # comments explaining how they are populated).
+    def find_special_group(name):
+        info = info_map.get(name)
+        if info is None:
+            fatal("expected project to contain special %r component" % (
+                    name,))
+
+        if info.type_name != 'LibraryGroup':
+            fatal("special component %r should be a LibraryGroup" % (
+                    name,))
+
+        if info.required_libraries:
+            fatal("special component %r must have empty %r list" % (
+                    name, 'required_libraries'))
+        if info.add_to_library_groups:
+            fatal("special component %r must have empty %r list" % (
+                    name, 'add_to_library_groups'))
+
+        return info
+
+    info_map = dict((ci.name, ci) for ci in project.component_infos)
+    all_targets = find_special_group('all-targets')
+    native_group = find_special_group('Native')
+    native_codegen_group = find_special_group('NativeCodeGen')
+    engine_group = find_special_group('Engine')
+
+    # Set the enabled bit in all the target groups, and append to the
+    # all-targets list.
+    for ci in enable_targets:
+        all_targets.required_libraries.append(ci.name)
+        ci.enabled = True
+
+    # If we have a native target, then that defines the native and
+    # native_codegen libraries.
+    if native_target and native_target.enabled:
+        native_group.required_libraries.append(native_target.name)
+        native_codegen_group.required_libraries.append(
+            '%sCodeGen' % native_target.name)
+
+    # If we have a native target with a JIT, use that for the engine. Otherwise,
+    # use the interpreter.
+    if native_target and native_target.enabled and native_target.has_jit:
+        engine_group.required_libraries.append('JIT')
+        engine_group.required_libraries.append(native_group.name)
+    else:
+        engine_group.required_libraries.append('Interpreter')
+
 def main():
     from optparse import OptionParser, OptionGroup
     parser = OptionParser("usage: %prog [options]")
 def main():
     from optparse import OptionParser, OptionGroup
     parser = OptionParser("usage: %prog [options]")
@@ -533,6 +632,17 @@ def main():
                      help="Write the Makefile project information to PATH",
                      action="store", default=None)
     parser.add_option_group(group)
                      help="Write the Makefile project information to PATH",
                      action="store", default=None)
     parser.add_option_group(group)
+
+    group = OptionGroup(parser, "Configuration Options")
+    group.add_option("", "--native-target",
+                      dest="native_target", metavar="NAME",
+                      help=("Treat the named target as the 'native' one, if "
+                            "given [%default]"),
+                      action="store", default=None)
+    group.add_option("", "--enable-targets",
+                      dest="enable_targets", metavar="NAMES",
+                      help=("Enable the given space separated list of targets, "
+                            "or all targets if not present"),
                       action="store", default=None)
     parser.add_option_group(group)
 
                       action="store", default=None)
     parser.add_option_group(group)
 
@@ -558,6 +668,9 @@ def main():
     project_info = LLVMProjectInfo.load_from_path(
         source_root, llvmbuild_source_root)
 
     project_info = LLVMProjectInfo.load_from_path(
         source_root, llvmbuild_source_root)
 
+    # Add the magic target based components.
+    add_magic_target_components(parser, project_info, opts)
+
     # Validate the project component info.
     project_info.validate_components()
 
     # Validate the project component info.
     project_info.validate_components()