Allow multiple registrations of the same target.
authorDaniel Dunbar <daniel@zuster.org>
Wed, 15 Jul 2009 10:32:44 +0000 (10:32 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Wed, 15 Jul 2009 10:32:44 +0000 (10:32 +0000)
 - This doesn't necessarily seem like a good idea, but the JIT unittest
   currently relies on it.

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

include/llvm/Target/TargetRegistry.h
lib/Support/TargetRegistry.cpp

index 8417fef1864b2528e2a8d8f3a98d331ac1b91d3c..7d934368e338b1f20cfedd3533754af253e19eb6 100644 (file)
@@ -137,7 +137,8 @@ namespace llvm {
     /// @name Target Registration
     /// @{
 
-    /// RegisterTarget - Register the given target.
+    /// RegisterTarget - Register the given target. Attempts to register a
+    /// target which has already been registered will be ignored.
     /// 
     /// Clients are responsible for ensuring that registration doesn't occur
     /// while another thread is attempting to access the registry. Typically
index 258d703d16df403d518b9a8b726e9719ba6578eb..77cf2dd72cf3a2720f6bdca715ede3b35480331b 100644 (file)
@@ -111,15 +111,13 @@ void TargetRegistry::RegisterTarget(Target &T,
                                     Target::TripleMatchQualityFnTy TQualityFn,
                                     Target::ModuleMatchQualityFnTy MQualityFn,
                                     Target::JITMatchQualityFnTy JITQualityFn) {
-  // Note that we don't require the constructor functions already be defined, in
-  // case a module happens to initialize the optional functionality before the
-  // target.
-  assert(!T.Next && !T.Name && !T.ShortDesc && !T.TripleMatchQualityFn &&
-         !T.ModuleMatchQualityFn && !T.JITMatchQualityFn && 
-         "This Target already registered!");
-
   assert(Name && ShortDesc && TQualityFn && MQualityFn && JITQualityFn &&
          "Missing required target information!");
+
+  // Check if this target has already been initialized, we allow this as a
+  // convenience to some clients.
+  if (T.Name)
+    return;
          
   // Add to the list of targets.
   T.Next = FirstTarget;