Index: llvm/lib/Transforms/IPO/OpenMPOpt.cpp =================================================================== --- llvm/lib/Transforms/IPO/OpenMPOpt.cpp +++ llvm/lib/Transforms/IPO/OpenMPOpt.cpp @@ -353,14 +353,12 @@ using OptimizationRemarkGetter = function_ref; - using MemorySSAGetter = function_ref; OpenMPOpt(SmallVectorImpl &SCC, CallGraphUpdater &CGUpdater, - OptimizationRemarkGetter OREGetter, MemorySSAGetter MSSAGetter, + OptimizationRemarkGetter OREGetter, OMPInformationCache &OMPInfoCache) : M(*(*SCC.begin())->getParent()), SCC(SCC), CGUpdater(CGUpdater), - OREGetter(OREGetter), MSSAGetter(MSSAGetter), - OMPInfoCache(OMPInfoCache) {} + OREGetter(OREGetter), OMPInfoCache(OMPInfoCache) {} /// Run all OpenMP optimizations on the underlying SCC/ModuleSlice. bool run() { @@ -527,12 +525,19 @@ bool Changed = false; auto SplitDataTransfer = [&] (Use &U, Function &Decl) { - if (CallInst *RT = getCallIfRegularCall(U, &RFI)) { - if (auto *MSSA = MSSAGetter(RT->getCaller())) { - MemoryTransfer MT(RT, *MSSA); - Changed = splitMemoryTransfer(MT); - } - } + auto *RTCall = getCallIfRegularCall(U, &RFI); + if (!RTCall) + return false; + + auto *MSSAResult = + OMPInfoCache.getAnalysisResultForFunction( + *RTCall->getCaller()); + if (!MSSAResult) + return false; + + auto &MSSA = MSSAResult->getMSSA(); + MemoryTransfer MT(RTCall, MSSA); + Changed = splitMemoryTransfer(MT); return Changed; }; @@ -542,20 +547,18 @@ bool splitMemoryTransfer(MemoryTransfer &MT) { bool Changed = false; - unsigned Status = EXIT_SUCCESS; - - Status = getValuesInOfflArrays(MT); - if (Status == EXIT_FAILURE) { + bool Success = getValuesInOfflArrays(MT); + if (!Success) { LLVM_DEBUG(dbgs() << TAG << "Couldn't get offload arrays in call to " << MT.RuntimeCall->getName() << " in function " << MT.RuntimeCall->getCaller()->getName() << "\n"); - return Changed; + return false; } return Changed; } - unsigned getValuesInOfflArrays(MemoryTransfer &MT) { + bool getValuesInOfflArrays(MemoryTransfer &MT) { auto *RuntimeCall = MT.RuntimeCall; auto *BasePtrsArg = RuntimeCall->arg_begin() + 2; // **offload_baseptrs. auto *PtrsArg = RuntimeCall->arg_begin() + 3; // **offload_ptrs. @@ -564,47 +567,47 @@ // Get values stored in **offload_baseptrs. auto *V = GetUnderlyingObject(BasePtrsArg->get(), DL); - unsigned Status = getValuesInOfflArray(V, *MT.BasePtrs, RuntimeCall); - if (Status == EXIT_FAILURE) { + bool Success = getValuesInOfflArray(V, *MT.BasePtrs, RuntimeCall); + if (!Success) { LLVM_DEBUG(dbgs() << TAG << "Couldn't get offload_baseptrs in call to " << RuntimeCall->getName() << " in function " << RuntimeCall->getCaller()->getName() << "\n"); - return EXIT_FAILURE; + return false; } // Get values stored in **offload_ptrs. V = GetUnderlyingObject(PtrsArg->get(), DL); - Status = getValuesInOfflArray(V, *MT.Ptrs, RuntimeCall); - if (Status == EXIT_FAILURE) { + Success = getValuesInOfflArray(V, *MT.Ptrs, RuntimeCall); + if (!Success) { LLVM_DEBUG(dbgs() << TAG << "Couldn't get offload_ptrs in call to " << RuntimeCall->getName() << " in function " << RuntimeCall->getCaller()->getName() << "\n"); - return EXIT_FAILURE; + return false; } // Get values stored in **offload_sizes. V = GetUnderlyingObject(SizesArg->get(), DL); - Status = getValuesInOfflArray(V, *MT.Sizes, RuntimeCall); - if (Status == EXIT_FAILURE) { + Success = getValuesInOfflArray(V, *MT.Sizes, RuntimeCall); + if (!Success) { LLVM_DEBUG(dbgs() << TAG << "Couldn't get offload_sizes in call to " << RuntimeCall->getName() << " in function " << RuntimeCall->getCaller()->getName() << "\n"); - return EXIT_FAILURE; + return false; } - return EXIT_SUCCESS; + return true; } /// Gets the values stored in \p OfflArray and stores them in \p Dst. /// \p Before serves as a lower bound, so don't look at accesses after that. - unsigned getValuesInOfflArray(Value *OfflArray, + bool getValuesInOfflArray(Value *OfflArray, MemoryTransfer::OffloadArray &Dst, User *Before = nullptr) { assert(OfflArray && "Can't get values in nullptr!"); if (!isa(OfflArray)) { LLVM_DEBUG(dbgs() << TAG << "Only alloca arrays supported.\n"); - return EXIT_FAILURE; + return false; } auto *ArrayAlloc = cast(OfflArray); @@ -640,7 +643,7 @@ auto AccsUsr = Accs->user_begin(); if (AccsUsr == Accs->user_end()) { LLVM_DEBUG(dbgs() << TAG << "Useless access to offload array.\n"); - return EXIT_FAILURE; + return false; } auto *I = cast(*AccsUsr); @@ -649,21 +652,22 @@ if (!isa(*AccsUsr)) { LLVM_DEBUG(dbgs() << TAG << "Unrecognized access pattern.\n"); - return EXIT_FAILURE; + return false; } - StoredAddresses[It] = AccsUsr->getOperand(0); + StoredAddresses[It] = + GetUnderlyingObject(AccsUsr->getOperand(0), OMPInfoCache.getDL()); } if (!isFilled(Dst)) { - LLVM_DEBUG(dbgs() << TAG << "Couldn't fill offload array.\n"); - return EXIT_FAILURE; + LLVM_DEBUG(dbgs() << TAG << "Didn't get all values in offload array.\n"); + return false; } - return EXIT_SUCCESS; + return true; } - bool isFilled(MemoryTransfer::OffloadArray OA) { + bool isFilled(MemoryTransfer::OffloadArray &OA) { for (auto *Acc : OA.LastAccesses) if (!Acc) return false; @@ -915,9 +919,6 @@ /// Callback to get an OptimizationRemarkEmitter from a Function * OptimizationRemarkGetter OREGetter; - /// Used to get the MemorySSA analysis of a specified function. - MemorySSAGetter MSSAGetter; - /// OpenMP-specific information cache. Also Used for Attributor runs. OMPInformationCache &OMPInfoCache; }; @@ -951,12 +952,6 @@ return FAM.getResult(*F); }; - auto MSSAGetter = [&C, &CG, &AM](Function *F) -> MemorySSA * { - FunctionAnalysisManager &FAM = - AM.getResult(C, CG).getManager(); - return &(FAM.getResult(*F).getMSSA()); - }; - CallGraphUpdater CGUpdater; CGUpdater.initialize(CG, C, AM, UR); @@ -966,7 +961,7 @@ /*CGSCC*/ &Functions, ModuleSlice); // TODO: Compute the module slice we are allowed to look at. - OpenMPOpt OMPOpt(SCC, CGUpdater, OREGetter, MSSAGetter, InfoCache); + OpenMPOpt OMPOpt(SCC, CGUpdater, OREGetter, InfoCache); bool Changed = OMPOpt.run(); (void)Changed; return PreservedAnalyses::all(); @@ -1023,10 +1018,6 @@ return *ORE; }; - auto MSSAGetter = [](Function *F) -> MemorySSA * { - return nullptr; - }; - AnalysisGetter AG; SetVector Functions(SCC.begin(), SCC.end()); BumpPtrAllocator Allocator; @@ -1035,7 +1026,7 @@ /*CGSCC*/ &Functions, ModuleSlice); // TODO: Compute the module slice we are allowed to look at. - OpenMPOpt OMPOpt(SCC, CGUpdater, OREGetter, MSSAGetter, InfoCache); + OpenMPOpt OMPOpt(SCC, CGUpdater, OREGetter, InfoCache); return OMPOpt.run(); }