Add MC assembly/disassembly support for VRINT{A, N, P, M} to V8FP.
[oota-llvm.git] / lib / Analysis / ProfileDataLoaderPass.cpp
index 2a61a0b6ed68a10c15c3ef308882c2a617c7b5b4..2ee0093a8f577d928a18172fc13a7a2732144f4e 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 #define DEBUG_TYPE "profile-metadata-loader"
-#include "llvm/BasicBlock.h"
-#include "llvm/InstrTypes.h"
-#include "llvm/Module.h"
-#include "llvm/LLVMContext.h"
-#include "llvm/MDBuilder.h"
-#include "llvm/Metadata.h"
-#include "llvm/Pass.h"
 #include "llvm/Analysis/Passes.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/Statistic.h"
 #include "llvm/Analysis/ProfileDataLoader.h"
-#include "llvm/Support/CommandLine.h"
+#include "llvm/IR/BasicBlock.h"
+#include "llvm/IR/InstrTypes.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/MDBuilder.h"
+#include "llvm/IR/Metadata.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Pass.h"
 #include "llvm/Support/CFG.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
-#include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/Format.h"
-#include "llvm/ADT/Statistic.h"
-#include <vector>
+#include "llvm/Support/raw_ostream.h"
 using namespace llvm;
 
 STATISTIC(NumEdgesRead, "The # of edges read.");
@@ -63,8 +63,8 @@ namespace {
     }
 
     virtual void readEdge(unsigned, ProfileData&, ProfileData::Edge,
-                          std::vector<unsigned>&);
-    virtual unsigned matchEdges(Module&, ProfileData&, std::vector<unsigned>&);
+                          ArrayRef<unsigned>);
+    virtual unsigned matchEdges(Module&, ProfileData&, ArrayRef<unsigned>);
     virtual void setBranchWeightMetadata(Module&, ProfileData&);
 
     virtual bool runOnModule(Module &M);
@@ -92,21 +92,21 @@ ModulePass *llvm::createProfileMetadataLoaderPass(const std::string &Filename) {
 /// readEdge - Take the value from a profile counter and assign it to an edge.
 void ProfileMetadataLoaderPass::readEdge(unsigned ReadCount,
                                          ProfileData &PB, ProfileData::Edge e,
-                                         std::vector<unsigned> &Counters) {
-  if (ReadCount < Counters.size()) {
-    unsigned weight = Counters[ReadCount];
-    assert(weight != ProfileDataLoader::Uncounted);
-    PB.addEdgeWeight(e, weight);
-
-    DEBUG(dbgs() << "-- Read Edge Counter for " << e
-                 << " (# "<< (ReadCount) << "): "
-                 << PB.getEdgeWeight(e) << "\n");
-  }
+                                         ArrayRef<unsigned> Counters) {
+  if (ReadCount >= Counters.size()) return;
+
+  unsigned weight = Counters[ReadCount];
+  assert(weight != ProfileDataLoader::Uncounted);
+  PB.addEdgeWeight(e, weight);
+
+  DEBUG(dbgs() << "-- Read Edge Counter for " << e
+               << " (# "<< (ReadCount) << "): "
+               << PB.getEdgeWeight(e) << "\n");
 }
 
 /// matchEdges - Link every profile counter with an edge.
 unsigned ProfileMetadataLoaderPass::matchEdges(Module &M, ProfileData &PB,
-                                             std::vector<unsigned> &Counters) {
+                                               ArrayRef<unsigned> Counters) {
   if (Counters.size() == 0) return 0;
 
   unsigned ReadCount = 0;
@@ -147,7 +147,7 @@ void ProfileMetadataLoaderPass::setBranchWeightMetadata(Module &M,
       // Load the weights of all edges leading from this terminator.
       DEBUG(dbgs() << "-- Terminator with " << NumSuccessors
                    << " successors:\n");
-      std::vector<uint32_t> Weights(NumSuccessors);
+      SmallVector<uint32_t, 4> Weights(NumSuccessors);
       for (unsigned s = 0 ; s < NumSuccessors ; ++s) {
           ProfileData::Edge edge = PB.getEdge(BB, TI->getSuccessor(s));
           Weights[s] = (uint32_t)PB.getEdgeWeight(edge);
@@ -172,7 +172,7 @@ bool ProfileMetadataLoaderPass::runOnModule(Module &M) {
   ProfileDataLoader PDL("profile-data-loader", Filename);
   ProfileData PB;
 
-  std::vector<unsigned> Counters = PDL.getRawEdgeCounts();
+  ArrayRef<unsigned> Counters = PDL.getRawEdgeCounts();
 
   unsigned ReadCount = matchEdges(M, PB, Counters);