/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/IR/SymbolTableListTraits.h
Line | Count | Source |
1 | | //===- llvm/SymbolTableListTraits.h - Traits for iplist ---------*- 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 defines a generic class that is used to implement the automatic |
10 | | // symbol table manipulation that occurs when you put (for example) a named |
11 | | // instruction into a basic block. |
12 | | // |
13 | | // The way that this is implemented is by using a special traits class with the |
14 | | // intrusive list that makes up the list of instructions in a basic block. When |
15 | | // a new element is added to the list of instructions, the traits class is |
16 | | // notified, allowing the symbol table to be updated. |
17 | | // |
18 | | // This generic class implements the traits class. It must be generic so that |
19 | | // it can work for all uses it, which include lists of instructions, basic |
20 | | // blocks, arguments, functions, global variables, etc... |
21 | | // |
22 | | //===----------------------------------------------------------------------===// |
23 | | |
24 | | #ifndef LLVM_IR_SYMBOLTABLELISTTRAITS_H |
25 | | #define LLVM_IR_SYMBOLTABLELISTTRAITS_H |
26 | | |
27 | | #include "llvm/ADT/ilist.h" |
28 | | #include "llvm/ADT/simple_ilist.h" |
29 | | #include <cstddef> |
30 | | |
31 | | namespace llvm { |
32 | | |
33 | | class Argument; |
34 | | class BasicBlock; |
35 | | class Function; |
36 | | class GlobalAlias; |
37 | | class GlobalIFunc; |
38 | | class GlobalVariable; |
39 | | class Instruction; |
40 | | class Module; |
41 | | class ValueSymbolTable; |
42 | | |
43 | | /// Template metafunction to get the parent type for a symbol table list. |
44 | | /// |
45 | | /// Implementations create a typedef called \c type so that we only need a |
46 | | /// single template parameter for the list and traits. |
47 | | template <typename NodeTy> struct SymbolTableListParentType {}; |
48 | | |
49 | | #define DEFINE_SYMBOL_TABLE_PARENT_TYPE(NODE, PARENT) \ |
50 | | template <> struct SymbolTableListParentType<NODE> { using type = PARENT; }; |
51 | | DEFINE_SYMBOL_TABLE_PARENT_TYPE(Instruction, BasicBlock) |
52 | | DEFINE_SYMBOL_TABLE_PARENT_TYPE(BasicBlock, Function) |
53 | | DEFINE_SYMBOL_TABLE_PARENT_TYPE(Argument, Function) |
54 | | DEFINE_SYMBOL_TABLE_PARENT_TYPE(Function, Module) |
55 | | DEFINE_SYMBOL_TABLE_PARENT_TYPE(GlobalVariable, Module) |
56 | | DEFINE_SYMBOL_TABLE_PARENT_TYPE(GlobalAlias, Module) |
57 | | DEFINE_SYMBOL_TABLE_PARENT_TYPE(GlobalIFunc, Module) |
58 | | #undef DEFINE_SYMBOL_TABLE_PARENT_TYPE |
59 | | |
60 | | template <typename NodeTy> class SymbolTableList; |
61 | | |
62 | | // ValueSubClass - The type of objects that I hold, e.g. Instruction. |
63 | | // ItemParentClass - The type of object that owns the list, e.g. BasicBlock. |
64 | | // |
65 | | template <typename ValueSubClass> |
66 | | class SymbolTableListTraits : public ilist_alloc_traits<ValueSubClass> { |
67 | | using ListTy = SymbolTableList<ValueSubClass>; |
68 | | using iterator = typename simple_ilist<ValueSubClass>::iterator; |
69 | | using ItemParentClass = |
70 | | typename SymbolTableListParentType<ValueSubClass>::type; |
71 | | |
72 | | public: |
73 | | SymbolTableListTraits() = default; |
74 | | |
75 | | private: |
76 | | /// getListOwner - Return the object that owns this list. If this is a list |
77 | | /// of instructions, it returns the BasicBlock that owns them. |
78 | 108M | ItemParentClass *getListOwner() { |
79 | 108M | size_t Offset(size_t(&((ItemParentClass*)nullptr->*ItemParentClass:: |
80 | 108M | getSublistAccess(static_cast<ValueSubClass*>(nullptr))))); |
81 | 108M | ListTy *Anchor(static_cast<ListTy *>(this)); |
82 | 108M | return reinterpret_cast<ItemParentClass*>(reinterpret_cast<char*>(Anchor)- |
83 | 108M | Offset); |
84 | 108M | } llvm::SymbolTableListTraits<llvm::Instruction>::getListOwner() Line | Count | Source | 78 | 93.5M | ItemParentClass *getListOwner() { | 79 | 93.5M | size_t Offset(size_t(&((ItemParentClass*)nullptr->*ItemParentClass:: | 80 | 93.5M | getSublistAccess(static_cast<ValueSubClass*>(nullptr))))); | 81 | 93.5M | ListTy *Anchor(static_cast<ListTy *>(this)); | 82 | 93.5M | return reinterpret_cast<ItemParentClass*>(reinterpret_cast<char*>(Anchor)- | 83 | 93.5M | Offset); | 84 | 93.5M | } |
llvm::SymbolTableListTraits<llvm::BasicBlock>::getListOwner() Line | Count | Source | 78 | 9.73M | ItemParentClass *getListOwner() { | 79 | 9.73M | size_t Offset(size_t(&((ItemParentClass*)nullptr->*ItemParentClass:: | 80 | 9.73M | getSublistAccess(static_cast<ValueSubClass*>(nullptr))))); | 81 | 9.73M | ListTy *Anchor(static_cast<ListTy *>(this)); | 82 | 9.73M | return reinterpret_cast<ItemParentClass*>(reinterpret_cast<char*>(Anchor)- | 83 | 9.73M | Offset); | 84 | 9.73M | } |
llvm::SymbolTableListTraits<llvm::Function>::getListOwner() Line | Count | Source | 78 | 3.98M | ItemParentClass *getListOwner() { | 79 | 3.98M | size_t Offset(size_t(&((ItemParentClass*)nullptr->*ItemParentClass:: | 80 | 3.98M | getSublistAccess(static_cast<ValueSubClass*>(nullptr))))); | 81 | 3.98M | ListTy *Anchor(static_cast<ListTy *>(this)); | 82 | 3.98M | return reinterpret_cast<ItemParentClass*>(reinterpret_cast<char*>(Anchor)- | 83 | 3.98M | Offset); | 84 | 3.98M | } |
llvm::SymbolTableListTraits<llvm::GlobalVariable>::getListOwner() Line | Count | Source | 78 | 778k | ItemParentClass *getListOwner() { | 79 | 778k | size_t Offset(size_t(&((ItemParentClass*)nullptr->*ItemParentClass:: | 80 | 778k | getSublistAccess(static_cast<ValueSubClass*>(nullptr))))); | 81 | 778k | ListTy *Anchor(static_cast<ListTy *>(this)); | 82 | 778k | return reinterpret_cast<ItemParentClass*>(reinterpret_cast<char*>(Anchor)- | 83 | 778k | Offset); | 84 | 778k | } |
llvm::SymbolTableListTraits<llvm::GlobalAlias>::getListOwner() Line | Count | Source | 78 | 6.63k | ItemParentClass *getListOwner() { | 79 | 6.63k | size_t Offset(size_t(&((ItemParentClass*)nullptr->*ItemParentClass:: | 80 | 6.63k | getSublistAccess(static_cast<ValueSubClass*>(nullptr))))); | 81 | 6.63k | ListTy *Anchor(static_cast<ListTy *>(this)); | 82 | 6.63k | return reinterpret_cast<ItemParentClass*>(reinterpret_cast<char*>(Anchor)- | 83 | 6.63k | Offset); | 84 | 6.63k | } |
llvm::SymbolTableListTraits<llvm::GlobalIFunc>::getListOwner() Line | Count | Source | 78 | 296 | ItemParentClass *getListOwner() { | 79 | 296 | size_t Offset(size_t(&((ItemParentClass*)nullptr->*ItemParentClass:: | 80 | 296 | getSublistAccess(static_cast<ValueSubClass*>(nullptr))))); | 81 | 296 | ListTy *Anchor(static_cast<ListTy *>(this)); | 82 | 296 | return reinterpret_cast<ItemParentClass*>(reinterpret_cast<char*>(Anchor)- | 83 | 296 | Offset); | 84 | 296 | } |
|
85 | | |
86 | 5.30M | static ListTy &getList(ItemParentClass *Par) { |
87 | 5.30M | return Par->*(Par->getSublistAccess((ValueSubClass*)nullptr)); |
88 | 5.30M | } llvm::SymbolTableListTraits<llvm::Instruction>::getList(llvm::BasicBlock*) Line | Count | Source | 86 | 5.30M | static ListTy &getList(ItemParentClass *Par) { | 87 | 5.30M | return Par->*(Par->getSublistAccess((ValueSubClass*)nullptr)); | 88 | 5.30M | } |
Unexecuted instantiation: llvm::SymbolTableListTraits<llvm::BasicBlock>::getList(llvm::Function*) Unexecuted instantiation: llvm::SymbolTableListTraits<llvm::Function>::getList(llvm::Module*) Unexecuted instantiation: llvm::SymbolTableListTraits<llvm::GlobalVariable>::getList(llvm::Module*) Unexecuted instantiation: llvm::SymbolTableListTraits<llvm::GlobalAlias>::getList(llvm::Module*) Unexecuted instantiation: llvm::SymbolTableListTraits<llvm::GlobalIFunc>::getList(llvm::Module*) |
89 | | |
90 | 41.0M | static ValueSymbolTable *getSymTab(ItemParentClass *Par) { |
91 | 18.4E | return Par ? toPtr(Par->getValueSymbolTable())41.0M : nullptr; |
92 | 41.0M | } llvm::SymbolTableListTraits<llvm::Instruction>::getSymTab(llvm::BasicBlock*) Line | Count | Source | 90 | 35.8M | static ValueSymbolTable *getSymTab(ItemParentClass *Par) { | 91 | 18.4E | return Par ? toPtr(Par->getValueSymbolTable())35.8M : nullptr; | 92 | 35.8M | } |
llvm::SymbolTableListTraits<llvm::BasicBlock>::getSymTab(llvm::Function*) Line | Count | Source | 90 | 1.97M | static ValueSymbolTable *getSymTab(ItemParentClass *Par) { | 91 | 18.4E | return Par ? toPtr(Par->getValueSymbolTable())1.97M : nullptr; | 92 | 1.97M | } |
llvm::SymbolTableListTraits<llvm::Function>::getSymTab(llvm::Module*) Line | Count | Source | 90 | 2.79M | static ValueSymbolTable *getSymTab(ItemParentClass *Par) { | 91 | 18.4E | return Par ? toPtr(Par->getValueSymbolTable())2.79M : nullptr; | 92 | 2.79M | } |
llvm::SymbolTableListTraits<llvm::GlobalVariable>::getSymTab(llvm::Module*) Line | Count | Source | 90 | 458k | static ValueSymbolTable *getSymTab(ItemParentClass *Par) { | 91 | 18.4E | return Par ? toPtr(Par->getValueSymbolTable())458k : nullptr; | 92 | 458k | } |
llvm::SymbolTableListTraits<llvm::GlobalAlias>::getSymTab(llvm::Module*) Line | Count | Source | 90 | 6.22k | static ValueSymbolTable *getSymTab(ItemParentClass *Par) { | 91 | 6.22k | return Par ? toPtr(Par->getValueSymbolTable()) : nullptr0 ; | 92 | 6.22k | } |
llvm::SymbolTableListTraits<llvm::GlobalIFunc>::getSymTab(llvm::Module*) Line | Count | Source | 90 | 247 | static ValueSymbolTable *getSymTab(ItemParentClass *Par) { | 91 | 247 | return Par ? toPtr(Par->getValueSymbolTable()) : nullptr0 ; | 92 | 247 | } |
|
93 | | |
94 | | public: |
95 | | void addNodeToList(ValueSubClass *V); |
96 | | void removeNodeFromList(ValueSubClass *V); |
97 | | void transferNodesFromList(SymbolTableListTraits &L2, iterator first, |
98 | | iterator last); |
99 | | // private: |
100 | | template<typename TPtr> |
101 | | void setSymTabObject(TPtr *, TPtr); |
102 | 37.7M | static ValueSymbolTable *toPtr(ValueSymbolTable *P) { return P; } llvm::SymbolTableListTraits<llvm::Instruction>::toPtr(llvm::ValueSymbolTable*) Line | Count | Source | 102 | 35.8M | static ValueSymbolTable *toPtr(ValueSymbolTable *P) { return P; } |
llvm::SymbolTableListTraits<llvm::BasicBlock>::toPtr(llvm::ValueSymbolTable*) Line | Count | Source | 102 | 1.97M | static ValueSymbolTable *toPtr(ValueSymbolTable *P) { return P; } |
Unexecuted instantiation: llvm::SymbolTableListTraits<llvm::Function>::toPtr(llvm::ValueSymbolTable*) Unexecuted instantiation: llvm::SymbolTableListTraits<llvm::GlobalVariable>::toPtr(llvm::ValueSymbolTable*) Unexecuted instantiation: llvm::SymbolTableListTraits<llvm::GlobalAlias>::toPtr(llvm::ValueSymbolTable*) Unexecuted instantiation: llvm::SymbolTableListTraits<llvm::GlobalIFunc>::toPtr(llvm::ValueSymbolTable*) |
103 | 3.25M | static ValueSymbolTable *toPtr(ValueSymbolTable &R) { return &R; } Unexecuted instantiation: llvm::SymbolTableListTraits<llvm::Instruction>::toPtr(llvm::ValueSymbolTable&) Unexecuted instantiation: llvm::SymbolTableListTraits<llvm::BasicBlock>::toPtr(llvm::ValueSymbolTable&) llvm::SymbolTableListTraits<llvm::Function>::toPtr(llvm::ValueSymbolTable&) Line | Count | Source | 103 | 2.79M | static ValueSymbolTable *toPtr(ValueSymbolTable &R) { return &R; } |
llvm::SymbolTableListTraits<llvm::GlobalVariable>::toPtr(llvm::ValueSymbolTable&) Line | Count | Source | 103 | 458k | static ValueSymbolTable *toPtr(ValueSymbolTable &R) { return &R; } |
llvm::SymbolTableListTraits<llvm::GlobalAlias>::toPtr(llvm::ValueSymbolTable&) Line | Count | Source | 103 | 6.22k | static ValueSymbolTable *toPtr(ValueSymbolTable &R) { return &R; } |
llvm::SymbolTableListTraits<llvm::GlobalIFunc>::toPtr(llvm::ValueSymbolTable&) Line | Count | Source | 103 | 247 | static ValueSymbolTable *toPtr(ValueSymbolTable &R) { return &R; } |
|
104 | | }; |
105 | | |
106 | | /// List that automatically updates parent links and symbol tables. |
107 | | /// |
108 | | /// When nodes are inserted into and removed from this list, the associated |
109 | | /// symbol table will be automatically updated. Similarly, parent links get |
110 | | /// updated automatically. |
111 | | template <class T> |
112 | | class SymbolTableList |
113 | | : public iplist_impl<simple_ilist<T>, SymbolTableListTraits<T>> {}; |
114 | | |
115 | | } // end namespace llvm |
116 | | |
117 | | #endif // LLVM_IR_SYMBOLTABLELISTTRAITS_H |