[llvm-commits] [llvm] r75753 - in /llvm/trunk: include/llvm/Target/TargetRegistry.h lib/Support/TargetRegistry.cpp

Daniel Dunbar daniel at zuster.org
Wed Jul 15 00:09:29 PDT 2009


Author: ddunbar
Date: Wed Jul 15 02:09:29 2009
New Revision: 75753

URL: http://llvm.org/viewvc/llvm-project?rev=75753&view=rev
Log:
Address some review comments on TargetRegistry.

Modified:
    llvm/trunk/include/llvm/Target/TargetRegistry.h
    llvm/trunk/lib/Support/TargetRegistry.cpp

Modified: llvm/trunk/include/llvm/Target/TargetRegistry.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetRegistry.h?rev=75753&r1=75752&r2=75753&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/TargetRegistry.h (original)
+++ llvm/trunk/include/llvm/Target/TargetRegistry.h Wed Jul 15 02:09:29 2009
@@ -32,7 +32,11 @@
   ///
   /// For registration purposes, this is a POD type so that targets can be
   /// registered without the use of static constructors.
-  struct Target {
+  ///
+  /// Targets should implement a single global instance of this class (which
+  /// will be zero initialized), and pass that instance to the TargetRegistry as
+  /// part of their initialization.
+  class Target {
   private:
     typedef unsigned (*TripleMatchQualityFnTy)(const std::string &TT);
     typedef unsigned (*ModuleMatchQualityFnTy)(const Module &M);
@@ -44,7 +48,7 @@
                                               TargetMachine &,
                                               bool);
 
-    friend class TargetRegistry;
+    friend struct TargetRegistry;
 
     /// Next - The next registered target in the linked list, maintained by the
     /// TargetRegistry.
@@ -132,6 +136,10 @@
     /// @{
 
     /// RegisterTarget - Register the given target.
+    /// 
+    /// Clients are responsible for ensuring that registration doesn't occur
+    /// while another thread is attempting to access the registry. Typically
+    /// this is done by initializing all targets at program startup.
     ///
     /// @param T - The target being registered.
     /// @param Name - The target name. This should be a static string.
@@ -153,6 +161,10 @@
     /// RegisterTargetMachine - Register a TargetMachine implementation for the
     /// given target.
     /// 
+    /// Clients are responsible for ensuring that registration doesn't occur
+    /// while another thread is attempting to access the registry. Typically
+    /// this is done by initializing all targets at program startup.
+    /// 
     /// @param T - The target being registered.
     /// @param Fn - A function to construct a TargetMachine for the target.
     static void RegisterTargetMachine(Target &T, 
@@ -164,6 +176,10 @@
     /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
     /// target.
     /// 
+    /// Clients are responsible for ensuring that registration doesn't occur
+    /// while another thread is attempting to access the registry. Typically
+    /// this is done by initializing all targets at program startup.
+    ///
     /// @param T - The target being registered.
     /// @param Fn - A function to construct an AsmPrinter for the target.
     static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {

Modified: llvm/trunk/lib/Support/TargetRegistry.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/TargetRegistry.cpp?rev=75753&r1=75752&r2=75753&view=diff

==============================================================================
--- llvm/trunk/lib/Support/TargetRegistry.cpp (original)
+++ llvm/trunk/lib/Support/TargetRegistry.cpp Wed Jul 15 02:09:29 2009
@@ -11,9 +11,7 @@
 #include <cassert>
 using namespace llvm;
 
-// FIXME: Worry about locking? In general everything should be registered at
-// startup.
-
+// Clients are responsible for avoid race conditions in registration.
 static Target *FirstTarget = 0;
 
 const Target *





More information about the llvm-commits mailing list