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
This commit is contained in:
Daniel Dunbar 2011-11-10 00:50:07 +00:00
parent b4eaee7a44
commit affc6cf9d2
15 changed files with 133 additions and 16 deletions

View File

@ -19,7 +19,6 @@
type = TargetGroup
name = ARM
parent = Target
add_to_library_groups = all-targets
has_jit = 1
[component_1]

View File

@ -19,7 +19,6 @@
type = TargetGroup
name = CBackend
parent = Target
add_to_library_groups = all-targets
[component_1]
type = Library

View File

@ -19,7 +19,6 @@
type = TargetGroup
name = CellSPU
parent = Target
add_to_library_groups = all-targets
[component_1]
type = Library

View File

@ -19,7 +19,6 @@
type = TargetGroup
name = CppBackend
parent = Target
add_to_library_groups = all-targets
[component_1]
type = Library

View File

@ -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

View File

@ -19,7 +19,6 @@
type = TargetGroup
name = MBlaze
parent = Target
add_to_library_groups = all-targets
[component_1]
type = Library

View File

@ -19,7 +19,6 @@
type = TargetGroup
name = MSP430
parent = Target
add_to_library_groups = all-targets
[component_1]
type = Library

View File

@ -19,7 +19,6 @@
type = TargetGroup
name = Mips
parent = Target
add_to_library_groups = all-targets
has_jit = 1
[component_1]

View File

@ -19,7 +19,6 @@
type = TargetGroup
name = PTX
parent = Target
add_to_library_groups = all-targets
[component_1]
type = Library

View File

@ -19,7 +19,6 @@
type = TargetGroup
name = PowerPC
parent = Target
add_to_library_groups = all-targets
has_jit = 1
[component_1]

View File

@ -19,7 +19,6 @@
type = TargetGroup
name = Sparc
parent = Target
add_to_library_groups = all-targets
[component_1]
type = Library

View File

@ -19,7 +19,6 @@
type = TargetGroup
name = X86
parent = Target
add_to_library_groups = all-targets
has_jit = 1
[component_1]

View File

@ -19,7 +19,6 @@
type = TargetGroup
name = XCore
parent = Target
add_to_library_groups = all-targets
[component_1]
type = Library

View 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 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

View File

@ -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()