[clang] [llvm] OpenMP offload 'simd' directive (PR #91261)
Johannes Doerfert via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 27 16:33:59 PDT 2024
================
@@ -790,8 +794,167 @@ void OpenMPIRBuilder::finalize(Function *Fn) {
"OMPIRBuilder finalization \n";
};
- if (!OffloadInfoManager.empty())
+ if (!OffloadInfoManager.empty())
createOffloadEntriesAndInfoMetadata(ErrorReportFn);
+
+ if (Config.EmitLLVMUsed) {
+ std::vector<WeakTrackingVH> LLVMCompilerUsed = {
+ M.getGlobalVariable("__openmp_nvptx_data_transfer_temporary_storage")};
+ emitUsed("llvm.compiler.used", LLVMCompilerUsed);
+ }
+
+}
+
+CallInst * OpenMPIRBuilder::globalizeAlloca(
+ AllocaInst *Alloca,
+ SmallVector<Instruction*, 32> &ToBeDeleted
+) {
+ FunctionCallee AllocFn = getOrCreateRuntimeFunctionPtr(
+ OMPRTL___kmpc_alloc_shared
+ );
+
+ Builder.SetInsertPoint(Alloca);
+ Value *SharedAllocArgs[] = {
+ //ConstantInt::get(Int64, Alloca->getType()->getScalarSizeInBits()/8)
+
+ //ConstantInt::get(Int64, Alloca->getAllocationSize(M.getDataLayout()));
+ //ConstantExpr::getSizeOf(Alloca->getAllocatedType())
+ ConstantInt::get(Int64, Alloca->getAllocationSize(M.getDataLayout())->getFixedValue())
+ };
+
+ CallInst *AllocSharedCall = Builder.CreateCall(AllocFn, ArrayRef<Value*>(SharedAllocArgs, 1));
+ AllocSharedCall->setName(Alloca->getName() + "_on_stack");
+ //Value *ReplValue = Builder.CreateBitcast(AllocSharedCall, Alloca->getType(), Alloca->getName() + "_on_stack");
+
+ dbgs() << "Created " << *AllocSharedCall << "\n";
+ dbgs() << *(Alloca->getType()) << "\n";
+ dbgs() << *(AllocSharedCall->getType()) << "\n";
+
+ //Type *CastType = PointerType::get(Alloca->getAllocatedType(), 0);
+ //dbgs() << " " << *CastType << "\n";
+ //llvm::Value *CastedSharedAlloc = Builder.CreateBitCast(
+ // AllocSharedCall, CastType, Alloca->getName()+"_on_stack"
+ //);
+
+ //dbgs() << " Casted " << *CastedSharedAlloc << "\n";
+
+ //Alloca->replaceAllUsesWith(AllocSharedCall);
+
+ // If the Alloca was allocated in address space 5 (local) we need to
+ // account for a type mismatch between it and the return from __kmpc_shared_alloc
+
+ for(auto U = Alloca->user_begin(); U != Alloca->user_end(); U++) {
+ dbgs () << " User - " << *(*U) << "\n";
+ }
+
+ if(Alloca->hasOneUser() && isa<AddrSpaceCastInst>(Alloca->user_back())) {
+ auto AddrSpaceCast = dyn_cast<AddrSpaceCastInst>(Alloca->user_back());
+ dbgs() << *(AddrSpaceCast->getType()) << "\n";
+ AddrSpaceCast->replaceAllUsesWith(AllocSharedCall);
+ //AddrSpaceCast->removeFromParent();
+ ToBeDeleted.push_back(AddrSpaceCast);
+ } else {
+ Alloca->replaceAllUsesWith(AllocSharedCall);
+ }
+ ToBeDeleted.push_back(Alloca);
+ //Alloca->removeFromParent();
+
+ //for(auto U = AllocSharedCall->user_begin(); U != AllocSharedCall->user_end(); U++) {
+ // if(auto AddrSpaceCast = dyn_cast<AddrSpaceCastInst>(*U)) {
+ // if(AddrSpaceCast->getSrcAddressSpace() == AddrSpaceCast->getDestAddressSpace()) {
+ // AddrSpaceCast->replaceAllUsesWith(CastedSharedAlloc);
+ // AddrSpaceCast->removeFromParent();
+ // }
+ // }
+ //}
+
+ //Alloca->removeFromParent();
+
+ dbgs() << " var globalized!\n";
+
+ return AllocSharedCall;
+
+}
+
+void OpenMPIRBuilder::globalizeParallelVars(
----------------
jdoerfert wrote:
Why does this globalize all allocas?
https://github.com/llvm/llvm-project/pull/91261
More information about the llvm-commits
mailing list