Index: llvm/unittests/Transforms/IPO/CMakeLists.txt =================================================================== --- llvm/unittests/Transforms/IPO/CMakeLists.txt +++ llvm/unittests/Transforms/IPO/CMakeLists.txt @@ -8,3 +8,5 @@ LowerTypeTests.cpp WholeProgramDevirt.cpp ) + +add_subdirectory(OpenMPOpt) Index: llvm/unittests/Transforms/IPO/OpenMPOpt/CMakeLists.txt =================================================================== --- /dev/null +++ llvm/unittests/Transforms/IPO/OpenMPOpt/CMakeLists.txt @@ -0,0 +1,11 @@ +set(LLVM_LINK_COMPONENTS + ipo + Core + Analysis + AsmParser + FrontendOpenMP + ) + +add_llvm_unittest(OpenMPOptUnitTests + HideMemTransferLatencyTest.cpp + ) \ No newline at end of file Index: llvm/unittests/Transforms/IPO/OpenMPOpt/HideMemTransferLatencyTest.cpp =================================================================== --- /dev/null +++ llvm/unittests/Transforms/IPO/OpenMPOpt/HideMemTransferLatencyTest.cpp @@ -0,0 +1,43 @@ +//===- HideMemTransferLatencyTest.cpp -------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "OpenMPOptTest.h" + +namespace { + +class HideMemTransferLatencyTest : public OpenMPOptTest { +protected: + /// This stores the runtime calls for further use within each test. + SmallVector MemTransferCalls; + + void getCallSites(const char *ModuleString) { + auto M = parseModuleString(ModuleString); + initializeOMPInfoCache(*M); + + auto &RFI = OMPInfoCache->RFIs[OMPRTL___tgt_target_data_begin]; + auto GetCallSites = [&](Use &U, Function &Decl) { + auto *RTCall = OMPInformationCache::getCallIfRegularCall(U, &RFI); + if (!RTCall) + return false; + MemTransferCalls.push_back(RTCall); + return false; + }; + RFI.foreachUse(GetCallSites); + EXPECT_FALSE(MemTransferCalls.empty()); + } +}; + +TEST_F(HideMemTransferLatencyTest, GetValuesInOfflArrays) { +// TODO: Update this ModuleString. +const char *ModuleString = ""; +getCallSites(ModuleString); + +EXPECT_TRUE(true); +} + +} // end anonymous namespace \ No newline at end of file Index: llvm/unittests/Transforms/IPO/OpenMPOpt/OpenMPOptTest.h =================================================================== --- /dev/null +++ llvm/unittests/Transforms/IPO/OpenMPOpt/OpenMPOptTest.h @@ -0,0 +1,63 @@ +//===- OpenMPOptTest.h - Base file for OpenMPOpt unittests ----------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_UNITTESTS_TRANSFORMS_IPO_OPENMPOPT_H +#define LLVM_UNITTESTS_TRANSFORMS_IPO_OPENMPOPT_H + +#include "../../../../lib/Transforms/IPO/OpenMPOptPriv.h" +#include "llvm/AsmParser/Parser.h" +#include "gtest/gtest.h" + +using namespace llvm; + +namespace { + +class OpenMPOptTest : public ::testing::Test { +protected: + std::unique_ptr OMPInfoCache; + std::unique_ptr Ctx; + + OpenMPOptTest() : Ctx(new LLVMContext) {} + + /// Initializes OMPInfoCache attribute cache given a module \p M. + /// This must be called before using OMPInfoCache. + void initializeOMPInfoCache(Module &M) { + CallGraph CG(M); + scc_iterator CGI = scc_begin(&CG); + CallGraphSCC CGSCC(CG, &CGI); + + SmallPtrSet ModuleSlice; + SmallVector SCC; + for (CallGraphNode *CGN : CGSCC) + if (Function *Fn = CGN->getFunction()) + if (!Fn->isDeclaration()) { + SCC.push_back(Fn); + ModuleSlice.insert(Fn); + } + + EXPECT_FALSE(SCC.empty()); + + AnalysisGetter AG; + SetVector Functions(SCC.begin(), SCC.end()); + BumpPtrAllocator Allocator; + OMPInfoCache = std::make_unique( + *(Functions.back()->getParent()), AG, Allocator, /*CGSCC*/ &Functions, + ModuleSlice); + } + + std::unique_ptr parseModuleString(const char *ModuleString) { + SMDiagnostic Err; + auto M = parseAssemblyString(ModuleString, Err, *Ctx); + EXPECT_TRUE(M); + return M; + } +}; + +} // end anonymous namespace + +#endif // LLVM_UNITTESTS_TRANSFORMS_IPO_OPENMPOPT_H \ No newline at end of file