summaryrefslogtreecommitdiff
path: root/make
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2010-01-18 06:48:56 +0000
committerDaniel Dunbar <daniel@zuster.org>2010-01-18 06:48:56 +0000
commit78cfbc57c62949e16fa7b4a69775aa6450343a00 (patch)
tree9bb559ed49496b0e7a13bed4b060ce989cbf97b9 /make
parent6260e4a3af0d4cd136e7976feb3465489da59141 (diff)
Add 'SelectFunctionDir' function, to select appropriate function implementation based on a configuration and architecture.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@93717 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'make')
-rw-r--r--make/lib_info.mk45
-rw-r--r--make/lib_util.mk56
2 files changed, 101 insertions, 0 deletions
diff --git a/make/lib_info.mk b/make/lib_info.mk
new file mode 100644
index 000000000..d7fc607d3
--- /dev/null
+++ b/make/lib_info.mk
@@ -0,0 +1,45 @@
+# compiler-rt Library Info
+#
+# This should be included once the subdirectory information has been loaded, and
+# uses the utilities in 'util.mk'.
+#
+# This defines the following variables describing compiler-rt:
+# AvailableFunctions - The entire list of function names (unmangled) the
+# library can provide.
+# CommonFunctions - The list of generic functions available.
+# ArchFunctions.<arch> - The list of functions commonly available for
+# 'arch'. This does not include any config specific
+# functions.
+#
+# AvailableIn.<function> - The list of subdir keys where 'function' is
+# defined.
+
+AvailableArchs := $(sort $(foreach key,$(SubDirKeys),\
+ $($(key).OnlyArchs)))
+
+AvailableFunctions := $(sort $(foreach key,$(SubDirKeys),\
+ $(basename $($(key).ObjNames))))
+
+CommonFunctions := $(sort\
+ $(foreach key,$(SubDirKeys),\
+ $(if $(call strneq,,$(strip $($(key).OnlyArchs) $($(key).OnlyConfigs))),,\
+ $(basename $($(key).ObjNames)))))
+
+# Compute common arch functions.
+$(foreach key,$(SubDirKeys),\
+ $(if $(call strneq,,$($(key).OnlyConfigs)),,\
+ $(foreach arch,$($(key).OnlyArchs),\
+ $(call Append,ArchFunctions.$(arch),$(sort \
+ $(basename $($(key).ObjNames)))))))
+
+# Compute arch only functions.
+$(foreach arch,$(AvailableArchs),\
+ $(call Set,ArchFunctions.$(arch),$(sort $(ArchFunctions.$(arch))))\
+ $(call Set,ArchOnlyFunctions.$(arch),\
+ $(call set_difference,$(ArchFunctions.$(arch)),$(CommonFunctions))))
+
+# Compute lists of where each function is available.
+$(foreach key,$(SubDirKeys),\
+ $(foreach fn,$(basename $($(key).ObjNames)),\
+ $(call Append,AvailableIn.$(fn),$(key))))
+
diff --git a/make/lib_util.mk b/make/lib_util.mk
new file mode 100644
index 000000000..768558b4e
--- /dev/null
+++ b/make/lib_util.mk
@@ -0,0 +1,56 @@
+# Library Utility Functions
+#
+# This should be included following 'lib_info.mk'.
+
+# Function: SelectFunctionDir config arch function-name optimized
+#
+# Choose the appropriate implementation directory to use for 'function-name' in
+# the configuration 'config' and on given arch.
+SelectFunctionDir = $(strip \
+ $(call Set,Tmp.SelectFunctionDir,$(call SelectFunctionDirs,$(1),$(2),$(3),$(4)))\
+ $(if $(call streq,1,$(words $(Tmp.SelectFunctionDir))),\
+ $(Tmp.SelectFunctionDir),\
+ $(error SelectFunctionDir: invalid function name "$(3)" ($(strip\
+ $(if $(call streq,0,$(words $(Tmp.SelectFunctionDir))),\
+ no such function,\
+ function implemented in multiple directories!!!))))))
+
+# Helper functions that select the entire list of subdirs where a function is
+# defined with a certain specificity.
+SelectFunctionDirs_Opt_ConfigAndArch = $(strip \
+ $(foreach key,$(AvailableIn.$(3)),\
+ $(if $(and $(call streq,Optimized,$($(key).Target)),\
+ $(call contains,$($(key).OnlyConfigs),$(1)),\
+ $(call contains,$($(key).OnlyArchs),$(2))),$(key),)))
+SelectFunctionDirs_Opt_Config = $(strip \
+ $(foreach key,$(AvailableIn.$(3)),\
+ $(if $(and $(call streq,Optimized,$($(key).Target)),\
+ $(call contains,$($(key).OnlyConfigs),$(1))),$(key),)))
+SelectFunctionDirs_Opt_Arch = $(strip \
+ $(foreach key,$(AvailableIn.$(3)),\
+ $(if $(and $(call streq,Optimized,$($(key).Target)),\
+ $(call contains,$($(key).OnlyArchs),$(2))),$(key),)))
+SelectFunctionDirs_Gen = $(strip \
+ $(foreach key,$(AvailableIn.$(3)),\
+ $(if $(call streq,Generic,$($(key).Target)),$(key))))
+
+# Helper function to select the right set of dirs in generic priority order.
+SelectFunctions_Gen = \
+ $(or $(call SelectFunctionDirs_Gen,$(1),$(2),$(3)),\
+ $(call SelectFunctionDirs_Opt_ConfigAndArch,$(1),$(2),$(3)), \
+ $(call SelectFunctionDirs_Opt_Config,$(1),$(2),$(3)), \
+ $(call SelectFunctionDirs_Opt_Arch,$(1),$(2),$(3)))
+
+# Helper function to select the right set of dirs in optimized priority order.
+SelectFunctions_Opt = \
+ $(or $(call SelectFunctionDirs_Opt_ConfigAndArch,$(1),$(2),$(3)), \
+ $(call SelectFunctionDirs_Opt_Config,$(1),$(2),$(3)), \
+ $(call SelectFunctionDirs_Opt_Arch,$(1),$(2),$(3)), \
+ $(call SelectFunctionDirs_Gen,$(1),$(2),$(3)))
+
+# Helper function to select the right set of dirs (which should be exactly one)
+# for a function.
+SelectFunctionDirs = \
+ $(if $(call streq,1,$(4)),\
+ $(call SelectFunctions_Opt,$(1),$(2),$(3)),\
+ $(call SelectFunctions_Gen,$(1),$(2),$(3)))