MCPcopy Create free account
hub / github.com/AdaptiveCpp/AdaptiveCpp / run

Method run

src/compiler/stdpar/MallocToUSM.cpp:144–366  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

142}
143
144llvm::PreservedAnalyses MallocToUSMPass::run(llvm::Module &M, llvm::ModuleAnalysisManager &AM) {
145
146 static constexpr const char* AllocIdentifier = "hipsycl_stdpar_alloc";
147 static constexpr const char* FreeIdentifier = "hipsycl_stdpar_free";
148 // In principle we try to identify allocation/deallocation functions with clang::annotate
149 // attributes using AllocIdentifier/FreeIdentifier as identifiers.
150 // However, it seems that this is not reliable for all LLVM versions and compilation flows.
151 // (in particular, a failure was observed with LLVM 18 and --acpp-targets=omp).
152 // This issue is not yet fully understood. As a workaround, also statically define
153 // mangled names for alloc/free functions.
154 llvm::SmallSet<std::string, 16> KnownFreeFunctions;
155 llvm::SmallSet<std::string, 16> KnownAllocFunctions;
156 for (const auto &S :
157 {"_ZdaPvm", "_ZdaPv", "_ZdaPvRKSt9nothrow_t", "_ZdlPv", "_ZdlPvSt11align_val_t",
158 "_ZdaPvmSt11align_val_t", "_ZdlPvRKSt9nothrow_t", "_ZdlPvSt11align_val_tRKSt9nothrow_t",
159 "free", "_ZdlPvm", "_ZdaPvSt11align_val_t", "_ZdaPvSt11align_val_tRKSt9nothrow_t",
160 "_ZdlPvmSt11align_val_t"}) {
161 KnownFreeFunctions.insert(S);
162 }
163 for (const auto &S : {
164 "malloc",
165 "aligned_alloc",
166 "_ZnwmSt11align_val_tRKSt9nothrow_t",
167 "_ZnwmSt11align_val_t",
168 "_ZnamSt11align_val_tRKSt9nothrow_t",
169 "_ZnwmRKSt9nothrow_t",
170 "_ZnamSt11align_val_t",
171 "_Znam",
172 "_Znwm",
173 "_ZnamRKSt9nothrow_t",
174 }) {
175 KnownAllocFunctions.insert(S);
176 }
177
178 llvm::SmallPtrSet<llvm::Function*, 16> ManagedAllocFunctions;
179 llvm::SmallPtrSet<llvm::Function*, 16> ManagedFreeFunctions;
180
181 for(auto& F : M) {
182 if(KnownFreeFunctions.contains(F.getName().str()))
183 ManagedFreeFunctions.insert(&F);
184 if(KnownAllocFunctions.contains(F.getName().str()))
185 ManagedAllocFunctions.insert(&F);
186 }
187
188 utils::findFunctionsWithStringAnnotations(M, [&](llvm::Function* F, llvm::StringRef Annotation){
189 if(F) {
190 if(Annotation.compare(AllocIdentifier) == 0) {
191 HIPSYCL_DEBUG_INFO
192 << "[stdpar] MallocToUSM: Found new memory allocation function definition: "
193 << F->getName() << "\n";
194 ManagedAllocFunctions.insert(F);
195
196 }
197 if (Annotation.compare(FreeIdentifier) == 0) {
198 ManagedFreeFunctions.insert(F);
199 }
200 }
201 });

Callers

nothing calls this directly

Calls 12

collectAllCalleesFunction · 0.85
collectAllCallersFromSetFunction · 0.85
addABITagFunction · 0.85
isStdFunctionFunction · 0.85
noneClass · 0.85
insertMethod · 0.45
containsMethod · 0.45
strMethod · 0.45
sizeMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected