LCOV - code coverage report
Current view: top level - lib/IR - ValueSymbolTable.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 28 28 100.0 %
Date: 2017-09-14 15:23:50 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- ValueSymbolTable.cpp - Implement the ValueSymbolTable class --------===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : // This file implements the ValueSymbolTable class for the IR library.
      11             : //
      12             : //===----------------------------------------------------------------------===//
      13             : 
      14             : #include "llvm/IR/ValueSymbolTable.h"
      15             : #include "llvm/ADT/SmallString.h"
      16             : #include "llvm/IR/GlobalValue.h"
      17             : #include "llvm/IR/Type.h"
      18             : #include "llvm/IR/Value.h"
      19             : #include "llvm/Support/Casting.h"
      20             : #include "llvm/Support/Compiler.h"
      21             : #include "llvm/Support/Debug.h"
      22             : #include "llvm/Support/raw_ostream.h"
      23             : #include <cassert>
      24             : #include <utility>
      25             : 
      26             : using namespace llvm;
      27             : 
      28             : #define DEBUG_TYPE "valuesymtab"
      29             : 
      30             : // Class destructor
      31      424641 : ValueSymbolTable::~ValueSymbolTable() {
      32             : #ifndef NDEBUG   // Only do this in -g mode...
      33             :   for (const auto &VI : vmap)
      34             :     dbgs() << "Value still in symbol table! Type = '"
      35             :            << *VI.getValue()->getType() << "' Name = '" << VI.getKeyData()
      36             :            << "'\n";
      37             :   assert(vmap.empty() && "Values remain in symbol table!");
      38             : #endif
      39      424642 : }
      40             : 
      41      230909 : ValueName *ValueSymbolTable::makeUniqueName(Value *V,
      42             :                                             SmallString<256> &UniqueName) {
      43      461818 :   unsigned BaseSize = UniqueName.size();
      44             :   while (true) {
      45             :     // Trim any suffix off and append the next number.
      46      231885 :     UniqueName.resize(BaseSize);
      47      464746 :     raw_svector_ostream S(UniqueName);
      48      231885 :     if (isa<GlobalValue>(V))
      49       49647 :       S << ".";
      50      463770 :     S << ++LastUnique;
      51             : 
      52             :     // Try insert the vmap entry with this suffix.
      53     1159425 :     auto IterBool = vmap.insert(std::make_pair(UniqueName, V));
      54      231885 :     if (IterBool.second)
      55      461818 :       return &*IterBool.first;
      56             :   }
      57             : }
      58             : 
      59             : // Insert a value into the symbol table with the specified name...
      60             : //
      61      796229 : void ValueSymbolTable::reinsertValue(Value* V) {
      62             :   assert(V->hasName() && "Can't insert nameless Value into symbol table");
      63             : 
      64             :   // Try inserting the name, assuming it won't conflict.
      65      796229 :   if (vmap.insert(V->getValueName())) {
      66             :     //DEBUG(dbgs() << " Inserted value: " << V->getValueName() << ": " << *V << "\n");
      67      694943 :     return;
      68             :   }
      69             :   
      70             :   // Otherwise, there is a naming conflict.  Rename this value.
      71      405144 :   SmallString<256> UniqueName(V->getName().begin(), V->getName().end());
      72             : 
      73             :   // The name is too already used, just free it so we can allocate a new name.
      74      202572 :   V->getValueName()->Destroy();
      75             : 
      76      101286 :   ValueName *VN = makeUniqueName(V, UniqueName);
      77      101286 :   V->setValueName(VN);
      78             : }
      79             : 
      80     2480861 : void ValueSymbolTable::removeValueName(ValueName *V) {
      81             :   //DEBUG(dbgs() << " Removing Value: " << V->getKeyData() << "\n");
      82             :   // Remove the value from the symbol table.
      83     4961722 :   vmap.remove(V);
      84     2480861 : }
      85             : 
      86             : /// createValueName - This method attempts to create a value name and insert
      87             : /// it into the symbol table with the specified name.  If it conflicts, it
      88             : /// auto-renames the name and returns that instead.
      89     1737157 : ValueName *ValueSymbolTable::createValueName(StringRef Name, Value *V) {
      90             :   // In the common case, the name is not already in the symbol table.
      91     5211471 :   auto IterBool = vmap.insert(std::make_pair(Name, V));
      92     1737157 :   if (IterBool.second) {
      93             :     //DEBUG(dbgs() << " Inserted value: " << Entry.getKeyData() << ": "
      94             :     //           << *V << "\n");
      95     1607534 :     return &*IterBool.first;
      96             :   }
      97             :   
      98             :   // Otherwise, there is a naming conflict.  Rename this value.
      99      259246 :   SmallString<256> UniqueName(Name.begin(), Name.end());
     100      129623 :   return makeUniqueName(V, UniqueName);
     101             : }
     102             : 
     103             : #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
     104             : // dump - print out the symbol table
     105             : //
     106             : LLVM_DUMP_METHOD void ValueSymbolTable::dump() const {
     107             :   //dbgs() << "ValueSymbolTable:\n";
     108             :   for (const auto &I : *this) {
     109             :     //dbgs() << "  '" << I->getKeyData() << "' = ";
     110             :     I.getValue()->dump();
     111             :     //dbgs() << "\n";
     112             :   }
     113             : }
     114             : #endif

Generated by: LCOV version 1.13