Possibly fix MSVC compilation after r256054.
[oota-llvm.git] / lib / Support / Statistic.cpp
index 9d075736b3035fa2ddfe5a4da9b9c33f33cc29d2..e49d1cbe06377ee19e5fae846a7382fca4b9b419 100644 (file)
@@ -24,6 +24,7 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Format.h"
 #include "llvm/Support/ManagedStatic.h"
@@ -33,9 +34,6 @@
 #include <cstring>
 using namespace llvm;
 
-// CreateInfoOutputFile - Return a file stream to print our output on.
-namespace llvm { extern raw_ostream *CreateInfoOutputFile(); }
-
 /// -stats - Command line option to cause transformations to emit stats about
 /// what they did.
 ///
@@ -76,7 +74,7 @@ void Statistic::RegisterStatistic() {
       StatInfo->addStatistic(this);
 
     TsanHappensBefore(this);
-    std::atomic_thread_fence(std::memory_order_seq_cst);
+    sys::MemoryFence();
     // Remember we have been registered.
     TsanIgnoreWritesBegin();
     Initialized = true;
@@ -144,20 +142,18 @@ void llvm::PrintStatistics() {
   if (Stats.Stats.empty()) return;
 
   // Get the stream to write to.
-  raw_ostream &OutStream = *CreateInfoOutputFile();
-  PrintStatistics(OutStream);
-  delete &OutStream;   // Close the file.
+  std::unique_ptr<raw_ostream> OutStream = CreateInfoOutputFile();
+  PrintStatistics(*OutStream);
+
 #else
   // Check if the -stats option is set instead of checking
   // !Stats.Stats.empty().  In release builds, Statistics operators
   // do nothing, so stats are never Registered.
   if (Enabled) {
     // Get the stream to write to.
-    raw_ostream &OutStream = *CreateInfoOutputFile();
-    OutStream << "Statistics are disabled.  "
-            << "Build with asserts or with -DLLVM_ENABLE_STATS\n";
-    OutStream.flush();
-    delete &OutStream;   // Close the file.
+    std::unique_ptr<raw_ostream> OutStream = CreateInfoOutputFile();
+    (*OutStream) << "Statistics are disabled.  "
+                 << "Build with asserts or with -DLLVM_ENABLE_STATS\n";
   }
 #endif
 }