/3rd_party/llvm/lib/VMCore/SymbolTableListTraitsImpl.h

https://code.google.com/p/softart/ · C++ Header · 118 lines · 72 code · 17 blank · 29 comment · 30 complexity · 5804a642febd36f7c7f6d7d3d31e3bdb MD5 · raw file

  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. #ifndef LLVM_SYMBOLTABLELISTTRAITS_IMPL_H
  16. #define LLVM_SYMBOLTABLELISTTRAITS_IMPL_H
  17. #include "llvm/SymbolTableListTraits.h"
  18. #include "llvm/ValueSymbolTable.h"
  19. namespace llvm {
  20. /// setSymTabObject - This is called when (f.e.) the parent of a basic block
  21. /// changes. This requires us to remove all the instruction symtab entries from
  22. /// the current function and reinsert them into the new function.
  23. template<typename ValueSubClass, typename ItemParentClass>
  24. template<typename TPtr>
  25. void SymbolTableListTraits<ValueSubClass,ItemParentClass>
  26. ::setSymTabObject(TPtr *Dest, TPtr Src) {
  27. // Get the old symtab and value list before doing the assignment.
  28. ValueSymbolTable *OldST = TraitsClass::getSymTab(getListOwner());
  29. // Do it.
  30. *Dest = Src;
  31. // Get the new SymTab object.
  32. ValueSymbolTable *NewST = TraitsClass::getSymTab(getListOwner());
  33. // If there is nothing to do, quick exit.
  34. if (OldST == NewST) return;
  35. // Move all the elements from the old symtab to the new one.
  36. iplist<ValueSubClass> &ItemList = TraitsClass::getList(getListOwner());
  37. if (ItemList.empty()) return;
  38. if (OldST) {
  39. // Remove all entries from the previous symtab.
  40. for (typename iplist<ValueSubClass>::iterator I = ItemList.begin();
  41. I != ItemList.end(); ++I)
  42. if (I->hasName())
  43. OldST->removeValueName(I->getValueName());
  44. }
  45. if (NewST) {
  46. // Add all of the items to the new symtab.
  47. for (typename iplist<ValueSubClass>::iterator I = ItemList.begin();
  48. I != ItemList.end(); ++I)
  49. if (I->hasName())
  50. NewST->reinsertValue(I);
  51. }
  52. }
  53. template<typename ValueSubClass, typename ItemParentClass>
  54. void SymbolTableListTraits<ValueSubClass,ItemParentClass>
  55. ::addNodeToList(ValueSubClass *V) {
  56. assert(V->getParent() == 0 && "Value already in a container!!");
  57. ItemParentClass *Owner = getListOwner();
  58. V->setParent(Owner);
  59. if (V->hasName())
  60. if (ValueSymbolTable *ST = TraitsClass::getSymTab(Owner))
  61. ST->reinsertValue(V);
  62. }
  63. template<typename ValueSubClass, typename ItemParentClass>
  64. void SymbolTableListTraits<ValueSubClass,ItemParentClass>
  65. ::removeNodeFromList(ValueSubClass *V) {
  66. V->setParent(0);
  67. if (V->hasName())
  68. if (ValueSymbolTable *ST = TraitsClass::getSymTab(getListOwner()))
  69. ST->removeValueName(V->getValueName());
  70. }
  71. template<typename ValueSubClass, typename ItemParentClass>
  72. void SymbolTableListTraits<ValueSubClass,ItemParentClass>
  73. ::transferNodesFromList(ilist_traits<ValueSubClass> &L2,
  74. ilist_iterator<ValueSubClass> first,
  75. ilist_iterator<ValueSubClass> last) {
  76. // We only have to do work here if transferring instructions between BBs
  77. ItemParentClass *NewIP = getListOwner(), *OldIP = L2.getListOwner();
  78. if (NewIP == OldIP) return; // No work to do at all...
  79. // We only have to update symbol table entries if we are transferring the
  80. // instructions to a different symtab object...
  81. ValueSymbolTable *NewST = TraitsClass::getSymTab(NewIP);
  82. ValueSymbolTable *OldST = TraitsClass::getSymTab(OldIP);
  83. if (NewST != OldST) {
  84. for (; first != last; ++first) {
  85. ValueSubClass &V = *first;
  86. bool HasName = V.hasName();
  87. if (OldST && HasName)
  88. OldST->removeValueName(V.getValueName());
  89. V.setParent(NewIP);
  90. if (NewST && HasName)
  91. NewST->reinsertValue(&V);
  92. }
  93. } else {
  94. // Just transferring between blocks in the same function, simply update the
  95. // parent fields in the instructions...
  96. for (; first != last; ++first)
  97. first->setParent(NewIP);
  98. }
  99. }
  100. } // End llvm namespace
  101. #endif