Add comment.
[oota-llvm.git] / lib / Transforms / Scalar / BasicBlockPlacement.cpp
index a25ab0f12156b29a4a222c302d0bc645645903c7..9bde749035750f5189f0271d6316eb85eba45fbb 100644 (file)
@@ -1,10 +1,10 @@
 //===-- BasicBlockPlacement.cpp - Basic Block Code Layout optimization ----===//
-// 
+//
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
-// 
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
 //===----------------------------------------------------------------------===//
 //
 // This file implements a very simple profile guided basic block placement
 //
 //===----------------------------------------------------------------------===//
 
+#define DEBUG_TYPE "block-placement"
 #include "llvm/Analysis/ProfileInfo.h"
 #include "llvm/Function.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/CFG.h"
-#include "Support/Statistic.h"
+#include "llvm/Support/Compiler.h"
+#include "llvm/ADT/Statistic.h"
+#include "llvm/Transforms/Scalar.h"
 #include <set>
 using namespace llvm;
 
+STATISTIC(NumMoved, "Number of basic blocks moved");
+
 namespace {
-  Statistic<> NumMoved("block-placement", "Number of basic blocks moved");
-  
-  struct BlockPlacement : public FunctionPass {
+  struct VISIBILITY_HIDDEN BlockPlacement : public FunctionPass {
+    static char ID; // Pass identification, replacement for typeid
+    BlockPlacement() : FunctionPass((intptr_t)&ID) {}
+
     virtual bool runOnFunction(Function &F);
 
     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
@@ -67,19 +73,22 @@ namespace {
     void PlaceBlocks(BasicBlock *BB);
   };
 
-  RegisterOpt<BlockPlacement> X("block-placement",
-                                "Profile Guided Basic Block Placement");
+  char BlockPlacement::ID = 0;
+  RegisterPass<BlockPlacement> X("block-placement",
+                                 "Profile Guided Basic Block Placement");
 }
 
+FunctionPass *llvm::createBlockPlacementPass() { return new BlockPlacement(); }
+
 bool BlockPlacement::runOnFunction(Function &F) {
   PI = &getAnalysis<ProfileInfo>();
 
   NumMovedBlocks = 0;
-  InsertPos = F.begin(); 
+  InsertPos = F.begin();
 
   // Recursively place all blocks.
   PlaceBlocks(F.begin());
-  
+
   PlacedBlocks.clear();
   NumMoved += NumMovedBlocks;
   return NumMovedBlocks != 0;
@@ -112,12 +121,12 @@ void BlockPlacement::PlaceBlocks(BasicBlock *BB) {
   while (1) {
     // Okay, now place any unplaced successors.
     succ_iterator SI = succ_begin(BB), E = succ_end(BB);
-    
+
     // Scan for the first unplaced successor.
     for (; SI != E && PlacedBlocks.count(*SI); ++SI)
       /*empty*/;
     if (SI == E) return;  // No more successors to place.
-    
+
     unsigned MaxExecutionCount = PI->getExecutionCount(*SI);
     BasicBlock *MaxSuccessor = *SI;