From affc6cf9d2b2b74532ce82027ac4524d1e29a658 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Thu, 10 Nov 2011 00:50:07 +0000 Subject: [PATCH] llvm-build: Add --native-target and --enable-targets options, and add logic to 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 --- lib/Target/ARM/LLVMBuild.txt | 1 - lib/Target/CBackend/LLVMBuild.txt | 1 - lib/Target/CellSPU/LLVMBuild.txt | 1 - lib/Target/CppBackend/LLVMBuild.txt | 1 - lib/Target/LLVMBuild.txt | 20 +++- lib/Target/MBlaze/LLVMBuild.txt | 1 - lib/Target/MSP430/LLVMBuild.txt | 1 - lib/Target/Mips/LLVMBuild.txt | 1 - lib/Target/PTX/LLVMBuild.txt | 1 - lib/Target/PowerPC/LLVMBuild.txt | 1 - lib/Target/Sparc/LLVMBuild.txt | 1 - lib/Target/X86/LLVMBuild.txt | 1 - lib/Target/XCore/LLVMBuild.txt | 1 - utils/llvm-build/llvmbuild/componentinfo.py | 4 + utils/llvm-build/llvmbuild/main.py | 113 ++++++++++++++++++++ 15 files changed, 133 insertions(+), 16 deletions(-) diff --git a/lib/Target/ARM/LLVMBuild.txt b/lib/Target/ARM/LLVMBuild.txt index cfac6ac51ba..79cae91f5b9 100644 --- a/lib/Target/ARM/LLVMBuild.txt +++ b/lib/Target/ARM/LLVMBuild.txt @@ -19,7 +19,6 @@ type = TargetGroup name = ARM parent = Target -add_to_library_groups = all-targets has_jit = 1 [component_1] diff --git a/lib/Target/CBackend/LLVMBuild.txt b/lib/Target/CBackend/LLVMBuild.txt index 0b1f885703d..851ded923c7 100644 --- a/lib/Target/CBackend/LLVMBuild.txt +++ b/lib/Target/CBackend/LLVMBuild.txt @@ -19,7 +19,6 @@ type = TargetGroup name = CBackend parent = Target -add_to_library_groups = all-targets [component_1] type = Library diff --git a/lib/Target/CellSPU/LLVMBuild.txt b/lib/Target/CellSPU/LLVMBuild.txt index e8db9f3f84d..a2127dd1c00 100644 --- a/lib/Target/CellSPU/LLVMBuild.txt +++ b/lib/Target/CellSPU/LLVMBuild.txt @@ -19,7 +19,6 @@ type = TargetGroup name = CellSPU parent = Target -add_to_library_groups = all-targets [component_1] type = Library diff --git a/lib/Target/CppBackend/LLVMBuild.txt b/lib/Target/CppBackend/LLVMBuild.txt index 79ad4c1f544..77e31c7af0b 100644 --- a/lib/Target/CppBackend/LLVMBuild.txt +++ b/lib/Target/CppBackend/LLVMBuild.txt @@ -19,7 +19,6 @@ type = TargetGroup name = CppBackend parent = Target -add_to_library_groups = all-targets [component_1] type = Library diff --git a/lib/Target/LLVMBuild.txt b/lib/Target/LLVMBuild.txt index 073a76a0f1a..09dadd6b1e9 100644 --- a/lib/Target/LLVMBuild.txt +++ b/lib/Target/LLVMBuild.txt @@ -21,20 +21,32 @@ name = Target 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 +; This is a special group whose required libraries are extended (by llvm-build) +; with the configured native target, if any. [component_2] type = LibraryGroup -name = native +name = Native 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 -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 -required_libraries = X86CodeGen diff --git a/lib/Target/MBlaze/LLVMBuild.txt b/lib/Target/MBlaze/LLVMBuild.txt index b953e3df305..fa8955252d8 100644 --- a/lib/Target/MBlaze/LLVMBuild.txt +++ b/lib/Target/MBlaze/LLVMBuild.txt @@ -19,7 +19,6 @@ type = TargetGroup name = MBlaze parent = Target -add_to_library_groups = all-targets [component_1] type = Library diff --git a/lib/Target/MSP430/LLVMBuild.txt b/lib/Target/MSP430/LLVMBuild.txt index 8b0b1f6534d..9ade1106688 100644 --- a/lib/Target/MSP430/LLVMBuild.txt +++ b/lib/Target/MSP430/LLVMBuild.txt @@ -19,7 +19,6 @@ type = TargetGroup name = MSP430 parent = Target -add_to_library_groups = all-targets [component_1] type = Library diff --git a/lib/Target/Mips/LLVMBuild.txt b/lib/Target/Mips/LLVMBuild.txt index bcec4a9661f..65c7d7fd2f0 100644 --- a/lib/Target/Mips/LLVMBuild.txt +++ b/lib/Target/Mips/LLVMBuild.txt @@ -19,7 +19,6 @@ type = TargetGroup name = Mips parent = Target -add_to_library_groups = all-targets has_jit = 1 [component_1] diff --git a/lib/Target/PTX/LLVMBuild.txt b/lib/Target/PTX/LLVMBuild.txt index 27119c2a3e7..180e7ce82cc 100644 --- a/lib/Target/PTX/LLVMBuild.txt +++ b/lib/Target/PTX/LLVMBuild.txt @@ -19,7 +19,6 @@ type = TargetGroup name = PTX parent = Target -add_to_library_groups = all-targets [component_1] type = Library diff --git a/lib/Target/PowerPC/LLVMBuild.txt b/lib/Target/PowerPC/LLVMBuild.txt index 3c439f37738..ce8b2e9196a 100644 --- a/lib/Target/PowerPC/LLVMBuild.txt +++ b/lib/Target/PowerPC/LLVMBuild.txt @@ -19,7 +19,6 @@ type = TargetGroup name = PowerPC parent = Target -add_to_library_groups = all-targets has_jit = 1 [component_1] diff --git a/lib/Target/Sparc/LLVMBuild.txt b/lib/Target/Sparc/LLVMBuild.txt index f59cc2eec42..d99057f20b2 100644 --- a/lib/Target/Sparc/LLVMBuild.txt +++ b/lib/Target/Sparc/LLVMBuild.txt @@ -19,7 +19,6 @@ type = TargetGroup name = Sparc parent = Target -add_to_library_groups = all-targets [component_1] type = Library diff --git a/lib/Target/X86/LLVMBuild.txt b/lib/Target/X86/LLVMBuild.txt index 7f48a9e485c..814e81b304b 100644 --- a/lib/Target/X86/LLVMBuild.txt +++ b/lib/Target/X86/LLVMBuild.txt @@ -19,7 +19,6 @@ type = TargetGroup name = X86 parent = Target -add_to_library_groups = all-targets has_jit = 1 [component_1] diff --git a/lib/Target/XCore/LLVMBuild.txt b/lib/Target/XCore/LLVMBuild.txt index 41943c36906..f1b75740cbe 100644 --- a/lib/Target/XCore/LLVMBuild.txt +++ b/lib/Target/XCore/LLVMBuild.txt @@ -19,7 +19,6 @@ type = TargetGroup name = XCore parent = Target -add_to_library_groups = all-targets [component_1] type = Library diff --git a/utils/llvm-build/llvmbuild/componentinfo.py b/utils/llvm-build/llvmbuild/componentinfo.py index 00b8ac52a94..6897d10f31a 100644 --- a/utils/llvm-build/llvmbuild/componentinfo.py +++ b/utils/llvm-build/llvmbuild/componentinfo.py @@ -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 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 diff --git a/utils/llvm-build/llvmbuild/main.py b/utils/llvm-build/llvmbuild/main.py index e27acd2f326..fe852a0c4e2 100644 --- a/utils/llvm-build/llvmbuild/main.py +++ b/utils/llvm-build/llvmbuild/main.py @@ -498,6 +498,105 @@ configure_file(\"%s\" 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]") @@ -533,6 +632,17 @@ def main(): 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) @@ -558,6 +668,9 @@ def main(): 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() -- 2.34.1