LCOV - code coverage report
Current view: top level - lib/IR - SymbolTableListTraitsImpl.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 92 132 69.7 %
Date: 2018-10-20 13:21:21 Functions: 15 19 78.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===-- llvm/SymbolTableListTraitsImpl.h - Implementation ------*- C++ -*--===//
       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 stickier parts of the SymbolTableListTraits class,
      11             : // and is explicitly instantiated where needed to avoid defining all this code
      12             : // in a widely used header.
      13             : //
      14             : //===----------------------------------------------------------------------===//
      15             : 
      16             : #ifndef LLVM_LIB_IR_SYMBOLTABLELISTTRAITSIMPL_H
      17             : #define LLVM_LIB_IR_SYMBOLTABLELISTTRAITSIMPL_H
      18             : 
      19             : #include "llvm/IR/SymbolTableListTraits.h"
      20             : #include "llvm/IR/ValueSymbolTable.h"
      21             : 
      22             : namespace llvm {
      23             : 
      24             : /// setSymTabObject - This is called when (f.e.) the parent of a basic block
      25             : /// changes.  This requires us to remove all the instruction symtab entries from
      26             : /// the current function and reinsert them into the new function.
      27             : template <typename ValueSubClass>
      28             : template <typename TPtr>
      29    11536667 : void SymbolTableListTraits<ValueSubClass>::setSymTabObject(TPtr *Dest,
      30             :                                                            TPtr Src) {
      31             :   // Get the old symtab and value list before doing the assignment.
      32             :   ValueSymbolTable *OldST = getSymTab(getListOwner());
      33             : 
      34             :   // Do it.
      35    11536667 :   *Dest = Src;
      36             : 
      37             :   // Get the new SymTab object.
      38             :   ValueSymbolTable *NewST = getSymTab(getListOwner());
      39             : 
      40             :   // If there is nothing to do, quick exit.
      41    11536666 :   if (OldST == NewST) return;
      42             : 
      43             :   // Move all the elements from the old symtab to the new one.
      44             :   ListTy &ItemList = getList(getListOwner());
      45     1450726 :   if (ItemList.empty()) return;
      46             : 
      47      728218 :   if (OldST) {
      48             :     // Remove all entries from the previous symtab.
      49     5027579 :     for (auto I = ItemList.begin(); I != ItemList.end(); ++I)
      50     4348204 :       if (I->hasName())
      51     1624508 :         OldST->removeValueName(I->getValueName());
      52             :   }
      53             : 
      54      728218 :   if (NewST) {
      55             :     // Add all of the items to the new symtab.
      56      565657 :     for (auto I = ItemList.begin(); I != ItemList.end(); ++I)
      57      515601 :       if (I->hasName())
      58      192108 :         NewST->reinsertValue(&*I);
      59             :   }
      60             : 
      61             : }
      62             : 
      63             : template <typename ValueSubClass>
      64    77137528 : void SymbolTableListTraits<ValueSubClass>::addNodeToList(ValueSubClass *V) {
      65             :   assert(!V->getParent() && "Value already in a container!!");
      66             :   ItemParentClass *Owner = getListOwner();
      67    75163243 :   V->setParent(Owner);
      68    77137528 :   if (V->hasName())
      69     2402176 :     if (ValueSymbolTable *ST = getSymTab(Owner))
      70     2212868 :       ST->reinsertValue(V);
      71    77137528 : }
      72     8639355 : 
      73             : template <typename ValueSubClass>
      74             : void SymbolTableListTraits<ValueSubClass>::removeNodeFromList(
      75     7263751 :     ValueSubClass *V) {
      76     8639355 :   V->setParent(nullptr);
      77     1559550 :   if (V->hasName())
      78     1559550 :     if (ValueSymbolTable *ST = getSymTab(getListOwner()))
      79     8639355 :       ST->removeValueName(V->getValueName());
      80    67902604 : }
      81             : 
      82             : template <typename ValueSubClass>
      83    67899492 : void SymbolTableListTraits<ValueSubClass>::transferNodesFromList(
      84    67902604 :     SymbolTableListTraits &L2, iterator first, iterator last) {
      85      281094 :   // We only have to do work here if transferring instructions between BBs
      86       91786 :   ItemParentClass *NewIP = getListOwner(), *OldIP = L2.getListOwner();
      87    67902604 :   assert(NewIP != OldIP && "Expected different list owners");
      88      405098 : 
      89             :   // We only have to update symbol table entries if we are transferring the
      90    37415939 :   // instructions to a different symtab object...
      91             :   ValueSymbolTable *NewST = getSymTab(NewIP);
      92    36550822 :   ValueSymbolTable *OldST = getSymTab(OldIP);
      93    37787593 :   if (NewST != OldST) {
      94     4294961 :     for (; first != last; ++first) {
      95     2704679 :       ValueSubClass &V = *first;
      96    37606411 :       bool HasName = V.hasName();
      97     5539914 :       if (OldST && HasName)
      98             :         OldST->removeValueName(V.getValueName());
      99     4269699 :       V.setParent(NewIP);
     100     5730385 :       if (NewST && HasName)
     101     2002665 :         NewST->reinsertValue(&V);
     102     2002665 :     }
     103     5730385 :   } else {
     104    31876025 :     // Just transferring between blocks in the same function, simply update the
     105             :     // parent fields in the instructions...
     106    32010600 :     for (; first != last; ++first)
     107    31876026 :       first->setParent(NewIP);
     108     2110522 :   }
     109      621370 : }
     110    32002691 : 
     111      126665 : } // End llvm namespace
     112      134575 : 
     113     3965699 : #endif

Generated by: LCOV version 1.13