/src/llvm-project/llvm/lib/IR/SymbolTableListTraitsImpl.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===-- llvm/SymbolTableListTraitsImpl.h - Implementation ------*- C++ -*--===// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | // |
9 | | // This file implements the stickier parts of the SymbolTableListTraits class, |
10 | | // and is explicitly instantiated where needed to avoid defining all this code |
11 | | // in a widely used header. |
12 | | // |
13 | | //===----------------------------------------------------------------------===// |
14 | | |
15 | | #ifndef LLVM_LIB_IR_SYMBOLTABLELISTTRAITSIMPL_H |
16 | | #define LLVM_LIB_IR_SYMBOLTABLELISTTRAITSIMPL_H |
17 | | |
18 | | #include "llvm/IR/SymbolTableListTraits.h" |
19 | | #include "llvm/IR/ValueSymbolTable.h" |
20 | | |
21 | | namespace llvm { |
22 | | |
23 | | /// Notify basic blocks when an instruction is inserted. |
24 | | template <typename ParentClass> |
25 | 5.99M | inline void invalidateParentIListOrdering(ParentClass *Parent) {} void llvm::invalidateParentIListOrdering<llvm::Function>(llvm::Function*) Line | Count | Source | 25 | 3.76M | inline void invalidateParentIListOrdering(ParentClass *Parent) {} |
void llvm::invalidateParentIListOrdering<llvm::Module>(llvm::Module*) Line | Count | Source | 25 | 2.22M | inline void invalidateParentIListOrdering(ParentClass *Parent) {} |
|
26 | | template <> void invalidateParentIListOrdering(BasicBlock *BB); |
27 | | |
28 | | /// setSymTabObject - This is called when (f.e.) the parent of a basic block |
29 | | /// changes. This requires us to remove all the instruction symtab entries from |
30 | | /// the current function and reinsert them into the new function. |
31 | | template <typename ValueSubClass, typename... Args> |
32 | | template <typename TPtr> |
33 | | void SymbolTableListTraits<ValueSubClass, Args...>::setSymTabObject(TPtr *Dest, |
34 | 7.14M | TPtr Src) { |
35 | | // Get the old symtab and value list before doing the assignment. |
36 | 7.14M | ValueSymbolTable *OldST = getSymTab(getListOwner()); |
37 | | |
38 | | // Do it. |
39 | 7.14M | *Dest = Src; |
40 | | |
41 | | // Get the new SymTab object. |
42 | 7.14M | ValueSymbolTable *NewST = getSymTab(getListOwner()); |
43 | | |
44 | | // If there is nothing to do, quick exit. |
45 | 7.14M | if (OldST == NewST) return; |
46 | | |
47 | | // Move all the elements from the old symtab to the new one. |
48 | 7.14M | ListTy &ItemList = getList(getListOwner()); |
49 | 7.14M | if (ItemList.empty()) return; |
50 | | |
51 | 3.28M | if (OldST) { |
52 | | // Remove all entries from the previous symtab. |
53 | 19.6M | for (auto I = ItemList.begin(); I != ItemList.end(); ++I) |
54 | 16.3M | if (I->hasName()) |
55 | 8.40M | OldST->removeValueName(I->getValueName()); |
56 | 3.28M | } |
57 | | |
58 | 3.28M | if (NewST) { |
59 | | // Add all of the items to the new symtab. |
60 | 8.41k | for (auto I = ItemList.begin(); I != ItemList.end(); ++I) |
61 | 4.20k | if (I->hasName()) |
62 | 0 | NewST->reinsertValue(&*I); |
63 | 4.20k | } |
64 | 3.28M | } |
65 | | |
66 | | template <typename ValueSubClass, typename... Args> |
67 | | void SymbolTableListTraits<ValueSubClass, Args...>::addNodeToList( |
68 | 26.6M | ValueSubClass *V) { |
69 | 26.6M | assert(!V->getParent() && "Value already in a container!!"); |
70 | 0 | ItemParentClass *Owner = getListOwner(); |
71 | 26.6M | V->setParent(Owner); |
72 | 26.6M | invalidateParentIListOrdering(Owner); |
73 | 26.6M | if (V->hasName()) |
74 | 3.85M | if (ValueSymbolTable *ST = getSymTab(Owner)) |
75 | 3.85M | ST->reinsertValue(V); |
76 | 26.6M | } llvm::SymbolTableListTraits<llvm::Instruction, llvm::ilist_iterator_bits<true> >::addNodeToList(llvm::Instruction*) Line | Count | Source | 68 | 20.8M | ValueSubClass *V) { | 69 | 20.8M | assert(!V->getParent() && "Value already in a container!!"); | 70 | 0 | ItemParentClass *Owner = getListOwner(); | 71 | 20.8M | V->setParent(Owner); | 72 | 20.8M | invalidateParentIListOrdering(Owner); | 73 | 20.8M | if (V->hasName()) | 74 | 1.64M | if (ValueSymbolTable *ST = getSymTab(Owner)) | 75 | 1.64M | ST->reinsertValue(V); | 76 | 20.8M | } |
llvm::SymbolTableListTraits<llvm::BasicBlock>::addNodeToList(llvm::BasicBlock*) Line | Count | Source | 68 | 3.57M | ValueSubClass *V) { | 69 | 3.57M | assert(!V->getParent() && "Value already in a container!!"); | 70 | 0 | ItemParentClass *Owner = getListOwner(); | 71 | 3.57M | V->setParent(Owner); | 72 | 3.57M | invalidateParentIListOrdering(Owner); | 73 | 3.57M | if (V->hasName()) | 74 | 4.20k | if (ValueSymbolTable *ST = getSymTab(Owner)) | 75 | 4.20k | ST->reinsertValue(V); | 76 | 3.57M | } |
llvm::SymbolTableListTraits<llvm::GlobalVariable>::addNodeToList(llvm::GlobalVariable*) Line | Count | Source | 68 | 987k | ValueSubClass *V) { | 69 | 987k | assert(!V->getParent() && "Value already in a container!!"); | 70 | 0 | ItemParentClass *Owner = getListOwner(); | 71 | 987k | V->setParent(Owner); | 72 | 987k | invalidateParentIListOrdering(Owner); | 73 | 987k | if (V->hasName()) | 74 | 975k | if (ValueSymbolTable *ST = getSymTab(Owner)) | 75 | 975k | ST->reinsertValue(V); | 76 | 987k | } |
llvm::SymbolTableListTraits<llvm::GlobalAlias>::addNodeToList(llvm::GlobalAlias*) Line | Count | Source | 68 | 557 | ValueSubClass *V) { | 69 | 557 | assert(!V->getParent() && "Value already in a container!!"); | 70 | 0 | ItemParentClass *Owner = getListOwner(); | 71 | 557 | V->setParent(Owner); | 72 | 557 | invalidateParentIListOrdering(Owner); | 73 | 557 | if (V->hasName()) | 74 | 523 | if (ValueSymbolTable *ST = getSymTab(Owner)) | 75 | 523 | ST->reinsertValue(V); | 76 | 557 | } |
llvm::SymbolTableListTraits<llvm::GlobalIFunc>::addNodeToList(llvm::GlobalIFunc*) Line | Count | Source | 68 | 10 | ValueSubClass *V) { | 69 | 10 | assert(!V->getParent() && "Value already in a container!!"); | 70 | 0 | ItemParentClass *Owner = getListOwner(); | 71 | 10 | V->setParent(Owner); | 72 | 10 | invalidateParentIListOrdering(Owner); | 73 | 10 | if (V->hasName()) | 74 | 2 | if (ValueSymbolTable *ST = getSymTab(Owner)) | 75 | 2 | ST->reinsertValue(V); | 76 | 10 | } |
llvm::SymbolTableListTraits<llvm::Function>::addNodeToList(llvm::Function*) Line | Count | Source | 68 | 1.23M | ValueSubClass *V) { | 69 | 1.23M | assert(!V->getParent() && "Value already in a container!!"); | 70 | 0 | ItemParentClass *Owner = getListOwner(); | 71 | 1.23M | V->setParent(Owner); | 72 | 1.23M | invalidateParentIListOrdering(Owner); | 73 | 1.23M | if (V->hasName()) | 74 | 1.23M | if (ValueSymbolTable *ST = getSymTab(Owner)) | 75 | 1.23M | ST->reinsertValue(V); | 76 | 1.23M | } |
|
77 | | |
78 | | template <typename ValueSubClass, typename... Args> |
79 | | void SymbolTableListTraits<ValueSubClass, Args...>::removeNodeFromList( |
80 | 26.6M | ValueSubClass *V) { |
81 | 26.6M | V->setParent(nullptr); |
82 | 26.6M | if (V->hasName()) |
83 | 15.4M | if (ValueSymbolTable *ST = getSymTab(getListOwner())) |
84 | 7.06M | ST->removeValueName(V->getValueName()); |
85 | 26.6M | } llvm::SymbolTableListTraits<llvm::Instruction, llvm::ilist_iterator_bits<true> >::removeNodeFromList(llvm::Instruction*) Line | Count | Source | 80 | 20.8M | ValueSubClass *V) { | 81 | 20.8M | V->setParent(nullptr); | 82 | 20.8M | if (V->hasName()) | 83 | 10.9M | if (ValueSymbolTable *ST = getSymTab(getListOwner())) | 84 | 2.53M | ST->removeValueName(V->getValueName()); | 85 | 20.8M | } |
llvm::SymbolTableListTraits<llvm::BasicBlock>::removeNodeFromList(llvm::BasicBlock*) Line | Count | Source | 80 | 3.57M | ValueSubClass *V) { | 81 | 3.57M | V->setParent(nullptr); | 82 | 3.57M | if (V->hasName()) | 83 | 2.32M | if (ValueSymbolTable *ST = getSymTab(getListOwner())) | 84 | 2.32M | ST->removeValueName(V->getValueName()); | 85 | 3.57M | } |
llvm::SymbolTableListTraits<llvm::GlobalVariable>::removeNodeFromList(llvm::GlobalVariable*) Line | Count | Source | 80 | 987k | ValueSubClass *V) { | 81 | 987k | V->setParent(nullptr); | 82 | 987k | if (V->hasName()) | 83 | 979k | if (ValueSymbolTable *ST = getSymTab(getListOwner())) | 84 | 979k | ST->removeValueName(V->getValueName()); | 85 | 987k | } |
llvm::SymbolTableListTraits<llvm::GlobalAlias>::removeNodeFromList(llvm::GlobalAlias*) Line | Count | Source | 80 | 557 | ValueSubClass *V) { | 81 | 557 | V->setParent(nullptr); | 82 | 557 | if (V->hasName()) | 83 | 523 | if (ValueSymbolTable *ST = getSymTab(getListOwner())) | 84 | 523 | ST->removeValueName(V->getValueName()); | 85 | 557 | } |
llvm::SymbolTableListTraits<llvm::GlobalIFunc>::removeNodeFromList(llvm::GlobalIFunc*) Line | Count | Source | 80 | 10 | ValueSubClass *V) { | 81 | 10 | V->setParent(nullptr); | 82 | 10 | if (V->hasName()) | 83 | 2 | if (ValueSymbolTable *ST = getSymTab(getListOwner())) | 84 | 2 | ST->removeValueName(V->getValueName()); | 85 | 10 | } |
llvm::SymbolTableListTraits<llvm::Function>::removeNodeFromList(llvm::Function*) Line | Count | Source | 80 | 1.23M | ValueSubClass *V) { | 81 | 1.23M | V->setParent(nullptr); | 82 | 1.23M | if (V->hasName()) | 83 | 1.22M | if (ValueSymbolTable *ST = getSymTab(getListOwner())) | 84 | 1.22M | ST->removeValueName(V->getValueName()); | 85 | 1.23M | } |
|
86 | | |
87 | | template <typename ValueSubClass, typename... Args> |
88 | | void SymbolTableListTraits<ValueSubClass, Args...>::transferNodesFromList( |
89 | 1.10M | SymbolTableListTraits &L2, iterator first, iterator last) { |
90 | | // Transfering nodes, even within the same BB, invalidates the ordering. The |
91 | | // list that we removed the nodes from still has a valid ordering. |
92 | 1.10M | ItemParentClass *NewIP = getListOwner(); |
93 | 1.10M | invalidateParentIListOrdering(NewIP); |
94 | | |
95 | | // Nothing else needs to be done if we're reording nodes within the same list. |
96 | 1.10M | ItemParentClass *OldIP = L2.getListOwner(); |
97 | 1.10M | if (NewIP == OldIP) |
98 | 224k | return; |
99 | | |
100 | | // We only have to update symbol table entries if we are transferring the |
101 | | // instructions to a different symtab object... |
102 | 880k | ValueSymbolTable *NewST = getSymTab(NewIP); |
103 | 880k | ValueSymbolTable *OldST = getSymTab(OldIP); |
104 | 880k | if (NewST != OldST) { |
105 | 0 | for (; first != last; ++first) { |
106 | 0 | ValueSubClass &V = *first; |
107 | 0 | bool HasName = V.hasName(); |
108 | 0 | if (OldST && HasName) |
109 | 0 | OldST->removeValueName(V.getValueName()); |
110 | 0 | V.setParent(NewIP); |
111 | 0 | if (NewST && HasName) |
112 | 0 | NewST->reinsertValue(&V); |
113 | 0 | } |
114 | 880k | } else { |
115 | | // Just transferring between blocks in the same function, simply update the |
116 | | // parent fields in the instructions... |
117 | 2.07M | for (; first != last; ++first) |
118 | 1.19M | first->setParent(NewIP); |
119 | 880k | } |
120 | 880k | } llvm::SymbolTableListTraits<llvm::Instruction, llvm::ilist_iterator_bits<true> >::transferNodesFromList(llvm::SymbolTableListTraits<llvm::Instruction, llvm::ilist_iterator_bits<true> >&, llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void, true>, false, false>, llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void, true>, false, false>) Line | Count | Source | 89 | 912k | SymbolTableListTraits &L2, iterator first, iterator last) { | 90 | | // Transfering nodes, even within the same BB, invalidates the ordering. The | 91 | | // list that we removed the nodes from still has a valid ordering. | 92 | 912k | ItemParentClass *NewIP = getListOwner(); | 93 | 912k | invalidateParentIListOrdering(NewIP); | 94 | | | 95 | | // Nothing else needs to be done if we're reording nodes within the same list. | 96 | 912k | ItemParentClass *OldIP = L2.getListOwner(); | 97 | 912k | if (NewIP == OldIP) | 98 | 32.8k | return; | 99 | | | 100 | | // We only have to update symbol table entries if we are transferring the | 101 | | // instructions to a different symtab object... | 102 | 880k | ValueSymbolTable *NewST = getSymTab(NewIP); | 103 | 880k | ValueSymbolTable *OldST = getSymTab(OldIP); | 104 | 880k | if (NewST != OldST) { | 105 | 0 | for (; first != last; ++first) { | 106 | 0 | ValueSubClass &V = *first; | 107 | 0 | bool HasName = V.hasName(); | 108 | 0 | if (OldST && HasName) | 109 | 0 | OldST->removeValueName(V.getValueName()); | 110 | 0 | V.setParent(NewIP); | 111 | 0 | if (NewST && HasName) | 112 | 0 | NewST->reinsertValue(&V); | 113 | 0 | } | 114 | 880k | } else { | 115 | | // Just transferring between blocks in the same function, simply update the | 116 | | // parent fields in the instructions... | 117 | 2.07M | for (; first != last; ++first) | 118 | 1.19M | first->setParent(NewIP); | 119 | 880k | } | 120 | 880k | } |
llvm::SymbolTableListTraits<llvm::BasicBlock>::transferNodesFromList(llvm::SymbolTableListTraits<llvm::BasicBlock>&, llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::BasicBlock, true, false, void, false>, false, false>, llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::BasicBlock, true, false, void, false>, false, false>) Line | Count | Source | 89 | 191k | SymbolTableListTraits &L2, iterator first, iterator last) { | 90 | | // Transfering nodes, even within the same BB, invalidates the ordering. The | 91 | | // list that we removed the nodes from still has a valid ordering. | 92 | 191k | ItemParentClass *NewIP = getListOwner(); | 93 | 191k | invalidateParentIListOrdering(NewIP); | 94 | | | 95 | | // Nothing else needs to be done if we're reording nodes within the same list. | 96 | 191k | ItemParentClass *OldIP = L2.getListOwner(); | 97 | 191k | if (NewIP == OldIP) | 98 | 191k | return; | 99 | | | 100 | | // We only have to update symbol table entries if we are transferring the | 101 | | // instructions to a different symtab object... | 102 | 0 | ValueSymbolTable *NewST = getSymTab(NewIP); | 103 | 0 | ValueSymbolTable *OldST = getSymTab(OldIP); | 104 | 0 | if (NewST != OldST) { | 105 | 0 | for (; first != last; ++first) { | 106 | 0 | ValueSubClass &V = *first; | 107 | 0 | bool HasName = V.hasName(); | 108 | 0 | if (OldST && HasName) | 109 | 0 | OldST->removeValueName(V.getValueName()); | 110 | 0 | V.setParent(NewIP); | 111 | 0 | if (NewST && HasName) | 112 | 0 | NewST->reinsertValue(&V); | 113 | 0 | } | 114 | 0 | } else { | 115 | | // Just transferring between blocks in the same function, simply update the | 116 | | // parent fields in the instructions... | 117 | 0 | for (; first != last; ++first) | 118 | 0 | first->setParent(NewIP); | 119 | 0 | } | 120 | 0 | } |
Unexecuted instantiation: llvm::SymbolTableListTraits<llvm::Function>::transferNodesFromList(llvm::SymbolTableListTraits<llvm::Function>&, llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Function, true, false, void, false>, false, false>, llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Function, true, false, void, false>, false, false>) Unexecuted instantiation: llvm::SymbolTableListTraits<llvm::GlobalVariable>::transferNodesFromList(llvm::SymbolTableListTraits<llvm::GlobalVariable>&, llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::GlobalVariable, true, false, void, false>, false, false>, llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::GlobalVariable, true, false, void, false>, false, false>) Unexecuted instantiation: llvm::SymbolTableListTraits<llvm::GlobalAlias>::transferNodesFromList(llvm::SymbolTableListTraits<llvm::GlobalAlias>&, llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::GlobalAlias, true, false, void, false>, false, false>, llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::GlobalAlias, true, false, void, false>, false, false>) Unexecuted instantiation: llvm::SymbolTableListTraits<llvm::GlobalIFunc>::transferNodesFromList(llvm::SymbolTableListTraits<llvm::GlobalIFunc>&, llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::GlobalIFunc, true, false, void, false>, false, false>, llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::GlobalIFunc, true, false, void, false>, false, false>) |
121 | | |
122 | | } // End llvm namespace |
123 | | |
124 | | #endif |