diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index a7bb5a12..2e73e5eb 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - config: [boilerplate, release, debug_cuda_only, debug_mpi_only, debug_threads_only] + config: [boilerplate, release, debug_cuda_only, debug_mpi_only, debug_threads_only, boilerplate_caliper] include: - config: boilerplate @@ -17,30 +17,42 @@ jobs: PERFFLOWASPECT_WITH_MPI: ON PERFFLOWASPECT_WITH_MULTITHREADS: ON CMAKE_BUILD_TYPE: Debug + PERFFLOWASPECT_WITH_CALIPER: OFF - config: release PERFFLOWASPECT_WITH_CUDA: OFF PERFFLOWASPECT_WITH_MPI: ON PERFFLOWASPECT_WITH_MULTITHREADS: ON CMAKE_BUILD_TYPE: Release + PERFFLOWASPECT_WITH_CALIPER: OFF - config: debug_cuda_only PERFFLOWASPECT_WITH_CUDA: OFF PERFFLOWASPECT_WITH_MPI: OFF PERFFLOWASPECT_WITH_MULTITHREADS: OFF CMAKE_BUILD_TYPE: Debug + PERFFLOWASPECT_WITH_CALIPER: OFF - config: debug_mpi_only PERFFLOWASPECT_WITH_CUDA: OFF PERFFLOWASPECT_WITH_MPI: ON PERFFLOWASPECT_WITH_MULTITHREADS: OFF CMAKE_BUILD_TYPE: Debug + PERFFLOWASPECT_WITH_CALIPER: OFF - config: debug_threads_only PERFFLOWASPECT_WITH_CUDA: OFF PERFFLOWASPECT_WITH_MPI: OFF PERFFLOWASPECT_WITH_MULTITHREADS: ON CMAKE_BUILD_TYPE: Debug + PERFFLOWASPECT_WITH_CALIPER: OFF + + - config: boilerplate_caliper + PERFFLOWASPECT_WITH_CUDA: OFF + PERFFLOWASPECT_WITH_MPI: OFF + PERFFLOWASPECT_WITH_MULTITHREADS: OFF + CMAKE_BUILD_TYPE: Debug + PERFFLOWASPECT_WITH_CALIPER: ON steps: # Checkout PerfFlowAspect repository under $GITHUB_WORKSPACE @@ -52,6 +64,21 @@ jobs: sudo apt install clang llvm-dev libjansson-dev libssl-dev bison flex make cmake mpich clang++ --version + - name: Clone Caliper + uses: actions/checkout@v2 + with: + repository: LLNL/Caliper + path: Caliper + + - name: Build Caliper + working-directory: Caliper + run: | + mkdir build && mkdir install + cd build + cmake -DCMAKE_INSTALL_PREFIX=../install ../ + make VERBOSE=1 + make install + - name: Compile check run: | cd src/c @@ -62,6 +89,7 @@ jobs: export CMAKE_OPTS="${CMAKE_OPTS} -DPERFFLOWASPECT_WITH_CUDA=${{matrix.PERFFLOWASPECT_WITH_CUDA}}" export CMAKE_OPTS="${CMAKE_OPTS} -DPERFFLOWASPECT_WITH_MPI=${{matrix.PERFFLOWASPECT_WITH_MPI}}" export CMAKE_OPTS="${CMAKE_OPTS} -DPERFFLOWASPECT_WITH_MULTITHREADS=${{matrix.PERFFLOWASPECT_WITH_MULTITHREADS}}" + export CMAKE_OPTS="${CMAKE_OPTS} -DPERFFLOWASPECT_WITH_CALIPER=${{matrix.PERFFLOWASPECT_WITH_CALIPER}} -Dcaliper_DIR=/home/runner/work/PerfFlowAspect/PerfFlowAspect/Caliper/install" echo -e ${CMAKE_OPTS} cmake ${CMAKE_OPTS} .. # build diff --git a/docs/CaliperIntegration.rst b/docs/CaliperIntegration.rst new file mode 100644 index 00000000..879359d4 --- /dev/null +++ b/docs/CaliperIntegration.rst @@ -0,0 +1,77 @@ +.. + # Copyright 2021 Lawrence Livermore National Security, LLC and other + # PerfFlowAspect Project Developers. See the top-level LICENSE file for + # details. + # + # SPDX-License-Identifier: LGPL-3.0 + +##################### + Caliper Integration +##################### + +PerfFlowAspect can be built with Caliper to leverage collection of additional +performance data, such as hardware performance counters on CPUs and GPU measurements on +NVIDIA GPUs. `Caliper <https://github.com/llnl/caliper>`_ is an instrumentation and +performance annotation library. A Caliper install is required before building +PerfFlowAspect: + +.. code:: bash + + cmake -Dcaliper_DIR=<path-to-install>/share/lib/caliper ../ + +Caliper can be configured at runtime, for example: + +.. code:: bash + + CALI_CONFIG=runtime-report ./smoketest + CALI_CONFIG=runtime-report,output=test.cali ./smoketest + +.. code:: bash + + Path Min time/rank Max time/rank Avg time/rank Time % + _Z3fooRKSs 0.004527 0.004527 0.004527 45.778137 + _Z3barv 0.004511 0.004511 0.004511 45.616341 + _Z3basv 0.000079 0.000079 0.000079 0.798867 + +.. code:: bash + + CALI_PAPI_COUNTERS=PAPI_TOT_CYC,PAPI_L2_DCM CALI_SERVICES_ENABLE=event,trace,papi,report ./smoketest + +.. code:: bash + + event.begin#annotation papi.PAPI_TOT_CYC papi.PAPI_L2_DCM annotation region.count event.end#annotation + _Z3fooRKSs 118289 679 + _Z3barv 200050 765 _Z3fooRKSs + _Z3basv 115098 352 _Z3fooRKSs/_Z3barv + 66564 242 _Z3fooRKSs/_Z3barv/_Z3basv 1 _Z3basv + 117061 385 _Z3fooRKSs/_Z3barv 1 _Z3barv + 93592 206 _Z3fooRKSs 1 _Z3fooRKSs + _Z3fooRKSs 146308 332 + _Z3barv 87811 255 _Z3fooRKSs + _Z3basv 84904 244 _Z3fooRKSs/_Z3barv + 34547 66 _Z3fooRKSs/_Z3barv/_Z3basv 1 _Z3basv + 82540 168 _Z3fooRKSs/_Z3barv 1 _Z3barv + 80711 144 _Z3fooRKSs 1 _Z3fooRKSs + _Z3fooRKSs 127765 183 + _Z3barv 85440 241 _Z3fooRKSs + _Z3basv 82100 250 _Z3fooRKSs/_Z3barv + 33969 67 _Z3fooRKSs/_Z3barv/_Z3basv 1 _Z3basv + 81511 161 _Z3fooRKSs/_Z3barv 1 _Z3barv + 77498 128 _Z3fooRKSs 1 _Z3fooRKSs + _Z3fooRKSs 119853 164 + _Z3barv 83285 227 _Z3fooRKSs + _Z3basv 82702 297 _Z3fooRKSs/_Z3barv + 34170 78 _Z3fooRKSs/_Z3barv/_Z3basv 1 _Z3basv + 81589 149 _Z3fooRKSs/_Z3barv 1 _Z3barv + 78920 119 _Z3fooRKSs 1 _Z3fooRKSs + +.. code:: bash + + PERFFLOW_OPTIONS='cpu-mem-usage=True:log-event=compact' CALI_CONFIG="load(time_exclusive.json),spot" ./smoketest + +.. code:: bash + + Path Min time/rank Max time/rank Avg time/rank Total time spot.channel + _Z3fooRKSs 0.018068 0.018068 0.018068 0.018068 regionprofile + _Z3barv 0.009124 0.009124 0.009124 0.009124 regionprofile + _Z3basv 0.000074 0.000074 0.000074 0.000074 regionprofile diff --git a/docs/index.rst b/docs/index.rst index a8de2d9b..1d0fa902 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -85,6 +85,7 @@ uniformity as to how performance is measured and controlled. BuildingPerfFlowAspect Annotations + CaliperIntegration UpcomingFeatures .. toctree:: diff --git a/src/c/CMakeLists.txt b/src/c/CMakeLists.txt index 0f001d9c..6fc1da05 100644 --- a/src/c/CMakeLists.txt +++ b/src/c/CMakeLists.txt @@ -2,6 +2,12 @@ cmake_minimum_required(VERSION 3.12) project(PerfFlowAspect VERSION "0.1.0") +# Build Options +option(PERFFLOWASPECT_WITH_CUDA "Build CUDA smoketest" ON) +option(PERFFLOWASPECT_WITH_MPI "Build MPI smoketest" ON) +option(PERFFLOWASPECT_WITH_MULTITHREADS "Build multi-threaded smoketest" ON) +option(PERFFLOWASPECT_WITH_CALIPER "Build with Caliper support" ON) + # Fail if using Clang < 9.0 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") # require at least Clang 9.0 diff --git a/src/c/cmake/Setup3rdParty.cmake b/src/c/cmake/Setup3rdParty.cmake index d7f203a6..ec83efb6 100644 --- a/src/c/cmake/Setup3rdParty.cmake +++ b/src/c/cmake/Setup3rdParty.cmake @@ -19,3 +19,19 @@ include(cmake/thirdparty/FindOpenSSL.cmake) if(PERFFLOWASPECT_WITH_MULTITHREADS) include(cmake/thirdparty/FindThreads.cmake) endif() + +if(PERFFLOWASPECT_WITH_CALIPER) + # first Check for CALIPER_DIR + if(NOT caliper_DIR) + MESSAGE(FATAL_ERROR "Caliper support needs explicit caliper_DIR") + endif() + + if(caliper_DIR) + message(STATUS "PPP ${caliper_DIR}") + include(cmake/thirdparty/FindCaliper.cmake) + endif() + + if(CALIPER_FOUND) + add_definitions(-DPERFFLOWASPECT_WITH_CALIPER) + endif() +endif() diff --git a/src/c/cmake/thirdparty/FindCaliper.cmake b/src/c/cmake/thirdparty/FindCaliper.cmake new file mode 100644 index 00000000..585cd921 --- /dev/null +++ b/src/c/cmake/thirdparty/FindCaliper.cmake @@ -0,0 +1,31 @@ +## most common case: caliper is built with adiak support +## and caliper needs us to find adiak, or else find_pacakge caliper +## will fail +# +## Check for ADIAK_DIR +# +#if(NOT ADIAK_DIR) +# MESSAGE(FATAL_ERROR "Caliper support needs explicit ADIAK_DIR") +#endif() +# +#message(STATUS "Looking for Adiak in: ${ADIAK_DIR}") +# +#find_package(adiak REQUIRED +# NO_DEFAULT_PATH +# PATHS ${ADIAK_DIR}/lib/cmake/adiak) + +message(STATUS "Looking for Caliper in: ${caliper_DIR}") + +find_package(caliper REQUIRED + PATHS ${caliper_DIR}/share/cmake/caliper + NO_DEFAULT_PATH + NO_CMAKE_ENVIRONMENT_PATH + NO_CMAKE_PATH + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH) + +message(STATUS "FOUND Caliper: ${caliper_INSTALL_PREFIX}") + +#set(ADIAK_FOUND TRUE) +set(CALIPER_FOUND TRUE) +set(PERFFLOWASPECT_CALIPER_ENABLED TRUE) diff --git a/src/c/config/CMakeLists.txt b/src/c/config/CMakeLists.txt index 455c4089..959f6897 100644 --- a/src/c/config/CMakeLists.txt +++ b/src/c/config/CMakeLists.txt @@ -42,6 +42,8 @@ configure_package_config_file( install(FILES ${CMAKE_CURRENT_BINARY_DIR}/perfflowaspect-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/perfflowaspect-config-version.cmake + perfflowaspect_setup_deps.cmake + perfflowaspect_setup_targets.cmake DESTINATION ${PERFFLOWASPECT_INSTALL_CMAKE_MODULE_DIR}) # Create pkg-config .pc file diff --git a/src/c/config/perfflowaspect-config.cmake.in b/src/c/config/perfflowaspect-config.cmake.in index 60a9d4a7..c8e7b809 100644 --- a/src/c/config/perfflowaspect-config.cmake.in +++ b/src/c/config/perfflowaspect-config.cmake.in @@ -3,7 +3,10 @@ if (NOT PERFFLOWASPECT_CONFIG_LOADED) set(PERFFLOWASPECT_DIR "@CMAKE_INSTALL_PREFIX@") set(PERFFLOWASPECT_LIB_DIR "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@") - include(CMakeFindDependencyMacro) + set(PERFFLOWASPECT_CALIPER_ENABLED "@PERFFLOWASPECT_CALIPER_ENABLED@") + set(PERFFLOWASPECT_CALIPER_DIR "@caliper_DIR@") + + include(${PERFFLOWASPECT_DIR}/share/perfflowaspect_setup_deps.cmake) find_dependency(OpenSSL REQUIRED) diff --git a/src/c/config/perfflowaspect_setup_deps.cmake b/src/c/config/perfflowaspect_setup_deps.cmake new file mode 100644 index 00000000..98f6ba02 --- /dev/null +++ b/src/c/config/perfflowaspect_setup_deps.cmake @@ -0,0 +1,17 @@ +include(CMakeFindDependencyMacro) + +if (NOT caliper_DIR) + set(caliper_DIR ${PERFFLOWASPECT_CALIPER_DIR}) +endif() + +if(caliper_DIR) + if(NOT PerfFlowAspect_FIND_QUIETLY) + message(STATUS "PerfFlowAspect was built with Caliper Support") + message(STATUS "Looking for Caliper at: ${caliper_DIR}/share/cmake/caliper") + endif() + + # find caliper + find_package(caliper REQUIRED + NO_DEFAULT_PATH + PATHS ${caliper_DIR}/share/cmake/caliper) +endif() diff --git a/src/c/config/perfflowaspect_setup_targets.cmake b/src/c/config/perfflowaspect_setup_targets.cmake new file mode 100644 index 00000000..ed5d28c7 --- /dev/null +++ b/src/c/config/perfflowaspect_setup_targets.cmake @@ -0,0 +1,6 @@ +# create convenience target that bundles all reg perfflowaspect deps +add_library(perfflowaspect::perfflowaspect INTERFACE IMPORTED) + +set_property(TARGET perfflowaspect::perfflowaspect + PROPERTY INTERFACE_LINK_LIBRARIES + perfflowaspect) diff --git a/src/c/examples/using-with-cmake/CMakeLists.txt b/src/c/examples/using-with-cmake/CMakeLists.txt index fc17f929..72c66743 100644 --- a/src/c/examples/using-with-cmake/CMakeLists.txt +++ b/src/c/examples/using-with-cmake/CMakeLists.txt @@ -23,6 +23,21 @@ cmake_minimum_required(VERSION 3.0) project(using_with_cmake) +# Fail if using Clang < 9.0 +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + # require at least Clang 9.0 + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0) + message(FATAL_ERROR "Clang++ version must be at least 9.0!") + elseif (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 11) + set(PERFFLOWASPECT_CLANG_11_NEWER TRUE CACHE BOOL "using >=clang11") + add_definitions(-DPERFFLOWASPECT_CLANG_11_NEWER) + elseif (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11) + set(PERFFLOWASPECT_CLANG_11_NEWER FALSE CACHE BOOL "using >=clang11") + endif() +else() + message(WARNING "Unsupported CXX compiler: please use Clang >= 9.0") +endif() + # # Provide default for PERFFLOWASPECT_DIR that works for an PerfFlowAspect install # @@ -39,3 +54,16 @@ if(NOT EXISTS ${PERFFLOWASPECT_DIR}/share/perfflowaspect-config.cmake) endif() # +# Use CMake's find_package to import PerfFlowAspect's targets +# +find_package(PerfFlowAspect REQUIRED + NO_DEFAULT_PATH + PATHS ${PERFFLOWASPECT_DIR}/share) + +# create our example +add_executable(smoketest smoketest.cpp) + +# link to PerfFlowAspect +target_link_libraries(smoketest perfflowaspect::perfflowaspect) + +# diff --git a/src/c/runtime/CMakeLists.txt b/src/c/runtime/CMakeLists.txt index 12e4fba5..05130853 100644 --- a/src/c/runtime/CMakeLists.txt +++ b/src/c/runtime/CMakeLists.txt @@ -14,12 +14,20 @@ set(perfflow_runtime_sources include_directories(${JANSSON_INCLUDE_DIRS}) +if(PERFFLOWASPECT_WITH_CALIPER) + include_directories(${caliper_INCLUDE_DIR}) +endif() + add_library(perfflow_runtime SHARED ${perfflow_runtime_sources} ${perfflow_runtime_headers} ) -target_link_libraries(perfflow_runtime ${JANSSON_LIBRARY} OpenSSL::SSL OpenSSL::Crypto) +if(PERFFLOWASPECT_WITH_CALIPER) + target_link_libraries(perfflow_runtime ${JANSSON_LIBRARY} OpenSSL::SSL OpenSSL::Crypto caliper) +else() + target_link_libraries(perfflow_runtime ${JANSSON_LIBRARY} OpenSSL::SSL OpenSSL::Crypto) +endif() install(TARGETS perfflow_runtime EXPORT perfflow_export diff --git a/src/c/test/CMakeLists.txt b/src/c/test/CMakeLists.txt index aae008c8..4ee796ef 100644 --- a/src/c/test/CMakeLists.txt +++ b/src/c/test/CMakeLists.txt @@ -12,7 +12,11 @@ foreach(TEST ${SMOKETESTS}) message(STATUS " [*] Adding test: ${TEST}") add_executable(${TEST} ${TEST}.cpp) set_source_files_properties(${TEST}.cpp COMPILE_FLAGS "-Xclang -load -Xclang ../weaver/weave/libWeavePass.so -fPIC") - target_link_libraries(${TEST} ${perfflow_deps}) + if(PERFFLOWASPECT_WITH_CALIPER) + target_link_libraries(${TEST} ${perfflow_deps} caliper) + else() + target_link_libraries(${TEST} ${perfflow_deps}) + endif() endforeach() # Build Options @@ -35,7 +39,11 @@ if(PERFFLOWASPECT_WITH_MULTITHREADS) add_executable(smoketest_MT smoketest_MT.cpp) set_source_files_properties(smoketest_MT.cpp COMPILE_FLAGS "-Xclang -load -Xclang ../weaver/weave/libWeavePass.so -fPIC") set(THREADS_PREFER_PTHREAD_FLAG ON) - target_link_libraries(smoketest_MT ${perfflow_deps} pthread) + if(PERFFLOWASPECT_WITH_CALIPER) + target_link_libraries(smoketest_MT ${perfflow_deps} pthread caliper) + else() + target_link_libraries(smoketest_MT ${perfflow_deps} pthread) + endif() endif() if(PERFFLOWASPECT_WITH_MPI) @@ -43,14 +51,22 @@ if(PERFFLOWASPECT_WITH_MPI) add_executable(smoketest_MPI smoketest_MPI.cpp) set_source_files_properties(smoketest_MPI.cpp COMPILE_FLAGS "-Xclang -load -Xclang ../weaver/weave/libWeavePass.so -fPIC") include_directories(${MPI_INCLUDE_PATH}) - target_link_libraries(smoketest_MPI ${perfflow_deps} ${MPI_LIBRARIES}) + if(PERFFLOWASPECT_WITH_CALIPER) + target_link_libraries(smoketest_MPI ${perfflow_deps} ${MPI_LIBRARIES} caliper) + else() + target_link_libraries(smoketest_MPI ${perfflow_deps} ${MPI_LIBRARIES}) + endif() endif() if(PERFFLOWASPECT_WITH_CUDA) message(STATUS " [*] Adding test: smoketest_cuda") set(CUDA_NVCC_FLAGS "-ccbin ${CMAKE_CXX_COMPILER} -Xcompiler=-Xclang -Xcompiler=-load -Xcompiler=-Xclang -Xcompiler=../../../weaver/weave/libWeavePass.so") cuda_add_executable(smoketest_cuda smoketest_cuda_wrapper.cpp smoketest_cuda_kernel.cu) - target_link_libraries(smoketest_cuda ${perfflow_deps} ${CUDA_LIBRARIES}) + if(PERFFLOWASPECT_WITH_CALIPER) + target_link_libraries(smoketest_cuda ${perfflow_deps} ${CUDA_LIBRARIES} caliper) + else() + target_link_libraries(smoketest_cuda ${perfflow_deps} ${CUDA_LIBRARIES}) + endif() endif() configure_file(t0001-cbinding-basic.t.in diff --git a/src/c/weaver/weave/perfflow_weave.cpp b/src/c/weaver/weave/perfflow_weave.cpp index 4e81003c..8cf17821 100644 --- a/src/c/weaver/weave/perfflow_weave.cpp +++ b/src/c/weaver/weave/perfflow_weave.cpp @@ -20,6 +20,7 @@ #include "llvm/IR/Module.h" #include "llvm/IR/Argument.h" #include "llvm/IR/IRBuilder.h" +#include "llvm/IR/InstIterator.h" #include "llvm/Transforms/IPO/PassManagerBuilder.h" #include "llvm/Support/raw_ostream.h" @@ -28,7 +29,6 @@ using namespace llvm; - /****************************************************************************** * * * Private Methods of WeavingPass Class * @@ -88,6 +88,55 @@ bool WeavingPass::insertAfter(Module &m, Function &f, StringRef &a, return true; } +#ifdef PERFFLOWASPECT_WITH_CALIPER +bool WeavingPass::instrumentCaliper(Module &M, Function &F) +{ + IRBuilder<> IRB(M.getContext()); + BasicBlock &Entry = F.getEntryBlock(); + SplitBlock(&Entry, &*Entry.getFirstInsertionPt()); + + IRB.SetInsertPoint(Entry.getTerminator()); + std::string FunctionName = F.getName().str(); + auto *FnStr = IRB.CreateGlobalStringPtr(FunctionName); + IRB.CreateCall(CaliBeginRegion, {FnStr}); + + bool RetFound = false; + for (inst_iterator It = inst_begin(F), E = inst_end(F); It != E; ++It) + { + Instruction *I = &*It; + if (!isa<ReturnInst>(I) && !isa<CallInst>(I) && !isa<InvokeInst>(I)) + { + continue; + } + + if (isa<ReturnInst>(I)) + { + IRB.SetInsertPoint(I); + IRB.CreateCall(CaliEndRegion, {FnStr}); + RetFound = true; + } + + // This is a call instruction + CallBase *CB = dyn_cast<CallBase>(I); + if (CB && CB->doesNotReturn()) + { + IRB.SetInsertPoint(I); + IRB.CreateCall(CaliEndRegion, {FnStr}); + RetFound = true; + } + } + + // All functions need to have at least one exit block + if (!RetFound) + { + dbgs() << "Could not find return for " << FunctionName << "\n"; + abort(); + } + + return RetFound; +} +#endif + bool WeavingPass::insertBefore(Module &m, Function &f, StringRef &a, int async, std::string &scope, std::string &flow, std::string pcut) { @@ -152,6 +201,21 @@ bool WeavingPass::doInitialization(Module &m) return false; } + IRBuilder<> IRB(m.getContext()); + AttrBuilder AB; + AB.addAttribute(Attribute::AlwaysInline); + //It was not added in LLVM@10. + //AB.addAttribute(Attribute::ArgMemOnly); + AttributeList Attrs = AttributeList::get(m.getContext(), + AttributeList::FunctionIndex, AB); +#ifdef PERFFLOWASPECT_WITH_CALIPER + // Insert Functions on the module + CaliBeginRegion = m.getOrInsertFunction("cali_begin_region", Attrs, + IRB.getVoidTy(), IRB.getInt8PtrTy()); + CaliEndRegion = m.getOrInsertFunction("cali_end_region", Attrs, IRB.getVoidTy(), + IRB.getInt8PtrTy()); +#endif + bool changed = false; auto a = cast<ConstantArray> (annotations->getOperand(0)); for (unsigned int i = 0; i < a->getNumOperands(); i++) @@ -159,6 +223,12 @@ bool WeavingPass::doInitialization(Module &m) auto e = cast<ConstantStruct> (a->getOperand(i)); if (auto *fn = dyn_cast<Function> (e->getOperand(0)->getOperand(0))) { +#ifdef PERFFLOWASPECT_WITH_CALIPER + // We insert Caliper Instrumentation before weaver. + // Thus weaver will include Caliper overheads + changed |= instrumentCaliper(m, *fn); +#endif + auto anno = cast<ConstantDataArray>( cast<GlobalVariable>(e->getOperand(1)->getOperand(0)) ->getOperand(0)) diff --git a/src/c/weaver/weave/perfflow_weave.hpp b/src/c/weaver/weave/perfflow_weave.hpp index 3db17445..c29a5955 100644 --- a/src/c/weaver/weave/perfflow_weave.hpp +++ b/src/c/weaver/weave/perfflow_weave.hpp @@ -11,9 +11,13 @@ #ifndef PERFFLOW_WEAVE_H #define PERFFLOW_WEAVE_H +#include "llvm/IR/Attributes.h" #include "llvm/IR/Function.h" #include "llvm/IR/Module.h" +#include "llvm/IR/IRBuilder.h" #include "llvm/Pass.h" +#include "llvm/Support/Debug.h" +#include "llvm/Transforms/Utils/BasicBlockUtils.h" #include <string> @@ -24,6 +28,8 @@ namespace { class WeavingPass : public FunctionPass { public: + FunctionCallee CaliBeginRegion; + FunctionCallee CaliEndRegion; static char ID; WeavingPass () : FunctionPass (ID) {} virtual bool doInitialization (Module &m); @@ -34,6 +40,10 @@ class WeavingPass : public FunctionPass int async, std::string &scope, std::string &flow, std::string pcut); bool insertBefore (Module &m, Function &f, StringRef &a, int async, std::string &scope, std::string &flow, std::string pcut); + +#ifdef PERFFLOWASPECT_WITH_CALIPER + bool instrumentCaliper(Module &M, Function &F); +#endif }; }