2020
2121#include "llvm/Analysis/TargetLibraryInfo.h"
2222
23- /*
24- //For updating below one should read MemoryBuiltins.cpp, TargetLibraryInfo.cpp
25- static inline
26- bool mapAllocationToDeallocation(const llvm::LibFunc libfunc, const llvm::TargetLibraryInfo &TLI) {
27-
28-
29-
30- // void operator delete[](void*);
31- case LibFunc_msvc_delete_array_ptr32:
32- // void operator delete[](void*);
33- case LibFunc_msvc_delete_array_ptr64:
34- // void operator delete(void*);
35- case LibFunc_msvc_delete_ptr32:
36- // void operator delete(void*);
37- case LibFunc_msvc_delete_ptr64:
38- return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
39-
40- // void operator delete[](void*, unsigned long);
41- case LibFunc_ZdaPvm:
42- // void operator delete(void*, nothrow);
43- case LibFunc_ZdlPvRKSt9nothrow_t:
44- // void operator delete(void*, unsigned int);
45- case LibFunc_ZdlPvj:
46- // void operator delete(void*, unsigned long);
47- case LibFunc_ZdlPvm:
48- // void operator delete(void*, align_val_t)
49- case LibFunc_ZdlPvSt11align_val_t:
50- // void operator delete[](void*, align_val_t)
51- case LibFunc_ZdaPvSt11align_val_t:
52- // void operator delete[](void*, unsigned int);
53- case LibFunc_msvc_delete_array_ptr32_int:
54- // void operator delete[](void*, nothrow);
55- case LibFunc_msvc_delete_array_ptr32_nothrow:
56- // void operator delete[](void*, unsigned long long);
57- case LibFunc_msvc_delete_array_ptr64_longlong:
58- // void operator delete[](void*, nothrow);
59- case LibFunc_msvc_delete_array_ptr64_nothrow:
60- // void operator delete(void*, unsigned int);
61- case LibFunc_msvc_delete_ptr32_int:
62- // void operator delete(void*, nothrow);
63- case LibFunc_msvc_delete_ptr32_nothrow:
64- // void operator delete(void*, unsigned long long);
65- case LibFunc_msvc_delete_ptr64_longlong:
66- // void operator delete(void*, nothrow);
67- case LibFunc_msvc_delete_ptr64_nothrow:
68- return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
69-
70- // void operator delete(void*, align_val_t, nothrow)
71- case LibFunc_ZdlPvSt11align_val_tRKSt9nothrow_t:
72- // void operator delete[](void*, align_val_t, nothrow)
73- case LibFunc_ZdaPvSt11align_val_tRKSt9nothrow_t:
74-
75- switch (libfunc) {
76- case LibFunc_malloc: // malloc(unsigned int);
77- case LibFunc_valloc: // valloc(unsigned int);
78- return LibFunc_free;
79-
80- case LibFunc_Znwj: // new(unsigned int);
81- return LibFunc_ZdlPv; // void operator delete(void*);
82-
83- case LibFunc_ZnwjRKSt9nothrow_t: // new(unsigned int, nothrow);
84- case LibFunc_ZnwjSt11align_val_t: // new(unsigned int, align_val_t)
85- case LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t: // new(unsigned int, align_val_t, nothrow)
86-
87- case LibFunc_Znwm: // new(unsigned long);
88- case LibFunc_ZnwmRKSt9nothrow_t: // new(unsigned long, nothrow);
89- case LibFunc_ZnwmSt11align_val_t: // new(unsigned long, align_val_t)
90- case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t: // new(unsigned long, align_val_t, nothrow)
91-
92- case LibFunc_Znaj: // new[](unsigned int);
93- return LibFunc_ZdaPv; // void operator delete[](void*);
94-
95- case LibFunc_ZnajRKSt9nothrow_t: // new[](unsigned int, nothrow);
96- return LibFunc_ZdaPvRKSt9nothrow_t; // void operator delete[](void*, nothrow);
97-
98- case LibFunc_ZnajSt11align_val_t: // new[](unsigned int, align_val_t)
99-
100- return LibFunc_ZdaPvj; // void operator delete[](void*, unsigned int);
101-
102- case LibFunc_ZnajSt11align_val_tRKSt9nothrow_t: // new[](unsigned int, align_val_t, nothrow)
103-
104-
105- case LibFunc_Znam: // new[](unsigned long);
106- case LibFunc_ZnamRKSt9nothrow_t: // new[](unsigned long, nothrow);
107- case LibFunc_ZnamSt11align_val_t: // new[](unsigned long, align_val_t)
108- case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t: // new[](unsigned long, align_val_t, nothrow)
109-
110- case LibFunc_msvc_new_int: // new(unsigned int);
111- case LibFunc_msvc_new_int_nothrow: // new(unsigned int, nothrow);
112- case LibFunc_msvc_new_longlong: // new(unsigned long long);
113- case LibFunc_msvc_new_longlong_nothrow: // new(unsigned long long, nothrow);
114- case LibFunc_msvc_new_array_int: // new[](unsigned int);
115- case LibFunc_msvc_new_array_int_nothrow: // new[](unsigned int, nothrow);
116- case LibFunc_msvc_new_array_longlong: // new[](unsigned long long);
117- case LibFunc_msvc_new_array_longlong_nothrow: // new[](unsigned long long, nothrow);
118-
119- //TODO strdup, strndup
120-
121- //TODO call, realloc, reallocf
122-
123- //TODO (perhaps) posix_memalign
124- TLI.get
125- return true;
126- default:
127- llvm_unreachable("unknown allocation function to find deallocation function for");
128- return false;
129- }
130- */
13123
13224//For updating below one should read MemoryBuiltins.cpp, TargetLibraryInfo.cpp
13325static inline
@@ -141,8 +33,10 @@ bool isAllocationFunction(const llvm::Function &F, const llvm::TargetLibraryInfo
14133
14234 case LibFunc_Znwj : // new(unsigned int);
14335 case LibFunc_ZnwjRKSt9nothrow_t : // new(unsigned int, nothrow);
36+ #if LLVM_VERSION_MAJOR > 6
14437 case LibFunc_ZnwjSt11align_val_t : // new(unsigned int, align_val_t)
14538 case LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t : // new(unsigned int, align_val_t, nothrow)
39+ #endif
14640
14741 case LibFunc_Znwm : // new(unsigned long);
14842 case LibFunc_ZnwmRKSt9nothrow_t : // new(unsigned long, nothrow);
@@ -268,8 +162,10 @@ CallInst* freeKnownAllocation(llvm::IRBuilder <>& builder, llvm::Value* tofree,
268162
269163 case LibFunc_Znwj : // new(unsigned int);
270164 case LibFunc_ZnwjRKSt9nothrow_t : // new(unsigned int, nothrow);
165+ #if LLVM_VERSION_MAJOR > 6
271166 case LibFunc_ZnwjSt11align_val_t : // new(unsigned int, align_val_t)
272167 case LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t : // new(unsigned int, align_val_t, nothrow)
168+ #endif
273169
274170 case LibFunc_Znwm : // new(unsigned long);
275171 case LibFunc_ZnwmRKSt9nothrow_t : // new(unsigned long, nothrow);
@@ -320,4 +216,4 @@ CallInst* freeKnownAllocation(llvm::IRBuilder <>& builder, llvm::Value* tofree,
320216 return freecall ;
321217}
322218
323- #endif
219+ #endif
0 commit comments