llvm.org GIT mirror llvm / 4cdc5bb
Delete the MacOSJITEventListener per echristo's request. It was disabled by default and didn't work anyway. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84720 91177308-0d34-0410-b5e6-96231b3b80d8 Jeffrey Yasskin 10 years ago
3 changed file(s) with 1 addition(s) and 175 deletion(s). Raw diff Collapse all Expand all
6666 virtual void NotifyFreeingMachineCode(const Function &F, void *OldPtr) {}
6767 };
6868
69 // These return NULL if support isn't available.
70 JITEventListener *createMacOSJITEventListener();
69 // This returns NULL if support isn't available.
7170 JITEventListener *createOProfileJITEventListener();
7271
7372 } // end namespace llvm.
+0
-172
lib/ExecutionEngine/JIT/MacOSJITEventListener.cpp less more
None //===-- MacOSJITEventListener.cpp - Save symbol table for OSX perf tools --===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines a JITEventListener object that records JITted functions to
10 // a global __jitSymbolTable linked list. Apple's performance tools use this to
11 // determine a symbol name and accurate code range for a PC value. Because
12 // performance tools are generally asynchronous, the code below is written with
13 // the hope that it could be interrupted at any time and have useful answers.
14 // However, we don't go crazy with atomic operations, we just do a "reasonable
15 // effort".
16 //
17 //===----------------------------------------------------------------------===//
18
19 #define DEBUG_TYPE "macos-jit-event-listener"
20 #include "llvm/Function.h"
21 #include "llvm/ExecutionEngine/JITEventListener.h"
22 #include
23 using namespace llvm;
24
25 #ifdef __APPLE__
26 #define ENABLE_JIT_SYMBOL_TABLE 0
27 #endif
28
29 #if ENABLE_JIT_SYMBOL_TABLE
30
31 namespace {
32
33 /// JITSymbolEntry - Each function that is JIT compiled results in one of these
34 /// being added to an array of symbols. This indicates the name of the function
35 /// as well as the address range it occupies. This allows the client to map
36 /// from a PC value to the name of the function.
37 struct JITSymbolEntry {
38 const char *FnName; // FnName - a strdup'd string.
39 void *FnStart;
40 intptr_t FnSize;
41 };
42
43
44 struct JITSymbolTable {
45 /// NextPtr - This forms a linked list of JitSymbolTable entries. This
46 /// pointer is not used right now, but might be used in the future. Consider
47 /// it reserved for future use.
48 JITSymbolTable *NextPtr;
49
50 /// Symbols - This is an array of JitSymbolEntry entries. Only the first
51 /// 'NumSymbols' symbols are valid.
52 JITSymbolEntry *Symbols;
53
54 /// NumSymbols - This indicates the number entries in the Symbols array that
55 /// are valid.
56 unsigned NumSymbols;
57
58 /// NumAllocated - This indicates the amount of space we have in the Symbols
59 /// array. This is a private field that should not be read by external tools.
60 unsigned NumAllocated;
61 };
62
63 class MacOSJITEventListener : public JITEventListener {
64 public:
65 virtual void NotifyFunctionEmitted(const Function &F,
66 void *FnStart, size_t FnSize,
67 const EmittedFunctionDetails &Details);
68 virtual void NotifyFreeingMachineCode(const Function &F, void *OldPtr);
69 };
70
71 } // anonymous namespace.
72
73 // This is a public symbol so the performance tools can find it.
74 JITSymbolTable *__jitSymbolTable;
75
76 namespace llvm {
77 JITEventListener *createMacOSJITEventListener() {
78 return new MacOSJITEventListener;
79 }
80 }
81
82 // Adds the just-emitted function to the symbol table.
83 void MacOSJITEventListener::NotifyFunctionEmitted(
84 const Function &F, void *FnStart, size_t FnSize,
85 const EmittedFunctionDetails &) {
86 assert(F.hasName() && FnStart != 0 && "Bad symbol to add");
87 JITSymbolTable **SymTabPtrPtr = 0;
88 SymTabPtrPtr = &__jitSymbolTable;
89
90 // If this is the first entry in the symbol table, add the JITSymbolTable
91 // index.
92 if (*SymTabPtrPtr == 0) {
93 JITSymbolTable *New = new JITSymbolTable();
94 New->NextPtr = 0;
95 New->Symbols = 0;
96 New->NumSymbols = 0;
97 New->NumAllocated = 0;
98 *SymTabPtrPtr = New;
99 }
100
101 JITSymbolTable *SymTabPtr = *SymTabPtrPtr;
102
103 // If we have space in the table, reallocate the table.
104 if (SymTabPtr->NumSymbols >= SymTabPtr->NumAllocated) {
105 // If we don't have space, reallocate the table.
106 unsigned NewSize = std::max(64U, SymTabPtr->NumAllocated*2);
107 JITSymbolEntry *NewSymbols = new JITSymbolEntry[NewSize];
108 JITSymbolEntry *OldSymbols = SymTabPtr->Symbols;
109
110 // Copy the old entries over.
111 memcpy(NewSymbols, OldSymbols, SymTabPtr->NumSymbols*sizeof(OldSymbols[0]));
112
113 // Swap the new symbols in, delete the old ones.
114 SymTabPtr->Symbols = NewSymbols;
115 SymTabPtr->NumAllocated = NewSize;
116 delete [] OldSymbols;
117 }
118
119 // Otherwise, we have enough space, just tack it onto the end of the array.
120 JITSymbolEntry &Entry = SymTabPtr->Symbols[SymTabPtr->NumSymbols];
121 Entry.FnName = strdup(F.getName().data());
122 Entry.FnStart = FnStart;
123 Entry.FnSize = FnSize;
124 ++SymTabPtr->NumSymbols;
125 }
126
127 // Removes the to-be-deleted function from the symbol table.
128 void MacOSJITEventListener::NotifyFreeingMachineCode(
129 const Function &, void *FnStart) {
130 assert(FnStart && "Invalid function pointer");
131 JITSymbolTable **SymTabPtrPtr = 0;
132 SymTabPtrPtr = &__jitSymbolTable;
133
134 JITSymbolTable *SymTabPtr = *SymTabPtrPtr;
135 JITSymbolEntry *Symbols = SymTabPtr->Symbols;
136
137 // Scan the table to find its index. The table is not sorted, so do a linear
138 // scan.
139 unsigned Index;
140 for (Index = 0; Symbols[Index].FnStart != FnStart; ++Index)
141 assert(Index != SymTabPtr->NumSymbols && "Didn't find function!");
142
143 // Once we have an index, we know to nuke this entry, overwrite it with the
144 // entry at the end of the array, making the last entry redundant.
145 const char *OldName = Symbols[Index].FnName;
146 Symbols[Index] = Symbols[SymTabPtr->NumSymbols-1];
147 free((void*)OldName);
148
149 // Drop the number of symbols in the table.
150 --SymTabPtr->NumSymbols;
151
152 // Finally, if we deleted the final symbol, deallocate the table itself.
153 if (SymTabPtr->NumSymbols != 0)
154 return;
155
156 *SymTabPtrPtr = 0;
157 delete [] Symbols;
158 delete SymTabPtr;
159 }
160
161 #else // !ENABLE_JIT_SYMBOL_TABLE
162
163 namespace llvm {
164 // By defining this to return NULL, we can let clients call it unconditionally,
165 // even if they aren't on an Apple system.
166 JITEventListener *createMacOSJITEventListener() {
167 return NULL;
168 }
169 } // namespace llvm
170
171 #endif // ENABLE_JIT_SYMBOL_TABLE
162162 exit(1);
163163 }
164164
165 EE->RegisterJITEventListener(createMacOSJITEventListener());
166165 EE->RegisterJITEventListener(createOProfileJITEventListener());
167166
168167 if (NoLazyCompilation)