Remove dead code. Improve llvm_unreachable text. Simplify some control flow.
[oota-llvm.git] / tools / llvm-objdump / MCFunction.h
index 60f6429209256e467b627d17528b43e13fa36e87..c0362d3a43fa56048251c620c5bf9d159a5726ce 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 
+#ifndef LLVM_OBJECTDUMP_MCFUNCTION_H
+#define LLVM_OBJECTDUMP_MCFUNCTION_H
+
 #include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/DenseSet.h"
 #include "llvm/MC/MCInst.h"
 #include <map>
 
 namespace llvm {
 
 class MCDisassembler;
-class MCInstrInfo;
+class MCInstrAnalysis;
 class MemoryObject;
 class raw_ostream;
 
@@ -31,15 +34,20 @@ struct MCDecodedInst {
   uint64_t Size;
   MCInst Inst;
 
+  MCDecodedInst() {}
   MCDecodedInst(uint64_t Address, uint64_t Size, MCInst Inst)
     : Address(Address), Size(Size), Inst(Inst) {}
+
+  bool operator<(const MCDecodedInst &RHS) const {
+    return Address < RHS.Address;
+  }
 };
 
 /// MCBasicBlock - Consists of multiple MCDecodedInsts and a list of successing
 /// MCBasicBlocks.
 class MCBasicBlock {
-  SmallVector<MCDecodedInst, 8> Insts;
-  typedef SmallPtrSet<MCBasicBlock*, 8> SetTy;
+  std::vector<MCDecodedInst> Insts;
+  typedef DenseSet<uint64_t> SetTy;
   SetTy Succs;
 public:
   ArrayRef<MCDecodedInst> getInsts() const { return Insts; }
@@ -48,8 +56,14 @@ public:
   succ_iterator succ_begin() const { return Succs.begin(); }
   succ_iterator succ_end() const { return Succs.end(); }
 
+  bool contains(uint64_t Addr) const { return Succs.count(Addr); }
+
   void addInst(const MCDecodedInst &Inst) { Insts.push_back(Inst); }
-  void addSucc(MCBasicBlock *BB) { Succs.insert(BB); }
+  void addSucc(uint64_t Addr) { Succs.insert(Addr); }
+
+  bool operator<(const MCBasicBlock &RHS) const {
+    return Insts.size() < RHS.Insts.size();
+  }
 };
 
 /// MCFunction - Represents a named function in machine code, containing
@@ -57,7 +71,7 @@ public:
 class MCFunction {
   const StringRef Name;
   // Keep BBs sorted by address.
-  typedef std::map<uint64_t, MCBasicBlock> MapTy;
+  typedef std::vector<std::pair<uint64_t, MCBasicBlock> > MapTy;
   MapTy Blocks;
 public:
   MCFunction(StringRef Name) : Name(Name) {}
@@ -65,24 +79,22 @@ public:
   // Create an MCFunction from a region of binary machine code.
   static MCFunction
   createFunctionFromMC(StringRef Name, const MCDisassembler *DisAsm,
-                       const MemoryObject &Region, uint64_t Start, uint64_t End,
-                       const MCInstrInfo *InstrInfo, raw_ostream &DebugOut);
+                       MemoryObject &Region, uint64_t Start, uint64_t End,
+                       const MCInstrAnalysis *Ana, raw_ostream &DebugOut,
+                       SmallVectorImpl<uint64_t> &Calls);
 
-  typedef MapTy::iterator iterator;
-  iterator begin() { return Blocks.begin(); }
-  iterator end() { return Blocks.end(); }
+  typedef MapTy::const_iterator iterator;
+  iterator begin() const { return Blocks.begin(); }
+  iterator end() const { return Blocks.end(); }
 
   StringRef getName() const { return Name; }
 
   MCBasicBlock &addBlock(uint64_t Address, const MCBasicBlock &BB) {
-    assert(!Blocks.count(Address) && "Already a BB at address.");
-    return Blocks[Address] = BB;
-  }
-
-  MCBasicBlock &getBlockAtAddress(uint64_t Address) {
-    assert(Blocks.count(Address) && "No BB at address.");
-    return Blocks[Address];
+    Blocks.push_back(std::make_pair(Address, BB));
+    return Blocks.back().second;
   }
 };
 
 }
+
+#endif