├── .gitignore ├── test ├── CMakeLists.txt ├── perf │ └── CMakeLists.txt └── instrumentation │ ├── Jacobi.f90 │ └── Jacobi.c ├── lib ├── Frontend │ ├── CMakeLists.txt │ ├── Flang │ │ └── CMakeLists.txt │ └── Clang │ │ ├── CMakeLists.txt │ │ ├── Passes.cpp │ │ └── FrontendActions.cpp ├── Transform │ ├── CMakeLists.txt │ ├── IR │ │ ├── CMakeLists.txt │ │ ├── Passes.cpp │ │ └── MetadataUtils.cpp │ ├── AST │ │ ├── CMakeLists.txt │ │ └── Passes.cpp │ ├── Flang │ │ ├── CMakeLists.txt │ │ └── Passes.cpp │ ├── Mixed │ │ ├── CMakeLists.txt │ │ ├── Passes.cpp │ │ └── FlangStubs.cpp │ └── Clang │ │ ├── CMakeLists.txt │ │ └── Passes.cpp ├── CMakeLists.txt ├── Unparse │ └── CMakeLists.txt ├── Support │ ├── Flang │ │ ├── CMakeLists.txt │ │ └── Diagnostic.cpp │ ├── Clang │ │ ├── CMakeLists.txt │ │ └── Diagnostic.cpp │ ├── CMakeLists.txt │ ├── GlobalOptions.cpp │ ├── EmptyPass.cpp │ ├── Diagnostic.cpp │ ├── PassBarrier.cpp │ └── RewriterBase.cpp ├── Analysis │ ├── Parallel │ │ ├── CMakeLists.txt │ │ └── Passes.cpp │ ├── Flang │ │ ├── CMakeLists.txt │ │ └── Passes.cpp │ ├── Reader │ │ ├── CMakeLists.txt │ │ └── Passes.cpp │ ├── Clang │ │ ├── CMakeLists.txt │ │ └── Passes.cpp │ ├── Passes.cpp │ ├── CMakeLists.txt │ ├── Memory │ │ ├── CMakeLists.txt │ │ ├── TraitFilter.cpp │ │ ├── Passes.cpp │ │ └── DFMemoryLocation.cpp │ ├── AnalysisServer.cpp │ └── Attributes.cpp ├── APC │ ├── CMakeLists.txt │ ├── Passes.cpp │ ├── DistributionUtils.h │ ├── LoopGraphTraits.h │ └── APCContextImpl.h └── Core │ ├── CMakeLists.txt │ └── Passes.cpp ├── tools ├── CMakeLists.txt ├── tsar │ ├── CMakeLists.txt │ └── main.cpp └── tsar-server │ ├── ClangMessages.h │ ├── Passes.h │ └── CMakeLists.txt ├── utils └── TableGen │ └── CMakeLists.txt ├── cmake ├── utility.cmake └── tsar-tablegen.cmake ├── include └── tsar │ ├── Core │ ├── Passes.h │ ├── IRAction.h │ └── tsar-config.h.in │ ├── APC │ └── Utils.h │ ├── Analysis │ ├── Attributes.td │ ├── Memory │ │ ├── GlobalsAccess.h │ │ ├── ServerUtils.h │ │ ├── DelinearizeJSON.h │ │ ├── AllocasModRef.h │ │ └── TraitFilter.h │ ├── Flang │ │ └── Passes.h │ ├── Parallel │ │ ├── Passes.h │ │ └── ParallelLoop.h │ ├── PrintUtils.h │ ├── Clang │ │ ├── MemoryMatcher.h │ │ ├── Utils.h │ │ ├── PerfectLoop.h │ │ └── ExpressionMatcher.h │ ├── Intrinsics.h │ ├── LibraryFunctions.def │ ├── Reader │ │ └── Passes.h │ └── Attributes.h │ ├── Transform │ ├── Clang │ │ ├── Format.h │ │ ├── DeadDeclsElimination.h │ │ └── RenameLocal.h │ ├── Flang │ │ ├── Format.h │ │ └── Passes.h │ ├── AST │ │ └── Passes.h │ └── IR │ │ ├── InterprocAttr.h │ │ ├── MetadataUtils.h │ │ └── Utils.h │ ├── Support │ ├── PassBarrier.h │ ├── Clang │ │ ├── PresumedLocationInfo.h │ │ ├── Diagnostic.h │ │ └── NamedDeclMapInfo.h │ ├── Flang │ │ ├── PresumedLocationInfo.h │ │ └── Diagnostic.h │ ├── EmptyPass.h │ ├── NumericUtils.h │ ├── AnalysisWrapperPass.h │ ├── Tags.h │ └── SCEVUtils.h │ ├── Frontend │ ├── Clang │ │ ├── Passes.h │ │ ├── DefaultPragmaHandlers.h │ │ └── FrontendActions.h │ └── Flang │ │ └── Tooling.h │ ├── Unparse │ ├── VariableLocation.h │ ├── SourceUnparserUtils.h │ ├── CSourceUnparser.h │ └── FortranSourceUnparser.h │ └── ADT │ └── PersistentIteratorInfo.h └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | wiki/ -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(perf) 2 | -------------------------------------------------------------------------------- /lib/Frontend/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Clang) 2 | if(FLANG_FOUND) 3 | add_subdirectory(Flang) 4 | endif() -------------------------------------------------------------------------------- /tools/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(tsar) 2 | if (TSAR_SERVER) 3 | add_subdirectory(tsar-server) 4 | endif() -------------------------------------------------------------------------------- /utils/TableGen/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_LINK_COMPONENTS Support) 2 | 3 | add_tablegen(tsar-tblgen TSAR 4 | TableGen.cpp 5 | ) 6 | -------------------------------------------------------------------------------- /lib/Transform/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(IR) 2 | add_subdirectory(Clang) 3 | if(FLANG_FOUND) 4 | add_subdirectory(Flang) 5 | endif() 6 | add_subdirectory(AST) 7 | add_subdirectory(Mixed) 8 | -------------------------------------------------------------------------------- /lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Support) 2 | add_subdirectory(Analysis) 3 | add_subdirectory(Transform) 4 | add_subdirectory(Unparse) 5 | add_subdirectory(Frontend) 6 | if(APC_FOUND) 7 | add_subdirectory(APC) 8 | endif() 9 | add_subdirectory(Core) 10 | 11 | -------------------------------------------------------------------------------- /cmake/utility.cmake: -------------------------------------------------------------------------------- 1 | # Copy file with a patch to a specified target if a specified patch exist. 2 | function(sapfor_configure_patch patchfile targetfile) 3 | if(NOT EXISTS ${patchfile}) 4 | return() 5 | endif() 6 | configure_file(${patchfile} ${targetfile}) 7 | endfunction(sapfor_configure_patch) 8 | -------------------------------------------------------------------------------- /test/perf/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}) 2 | add_executable(tsar-map-perf Map.cpp) 3 | add_dependencies(tsar-map-perf tsar) 4 | add_definitions("-D${PROJECT_NAME}_PROJECT" "-D${PROJECT_NAME}_CONFIG") 5 | target_link_libraries(tsar-map-perf ${LLVM_LIBS} BCL::Core) 6 | set_target_properties(tsar-map-perf PROPERTIES FOLDER "Tsar performance") 7 | install(TARGETS tsar-map-perf RUNTIME DESTINATION bin) 8 | -------------------------------------------------------------------------------- /tools/tsar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(TSAR_EXEC_SOURCES main.cpp) 2 | 3 | add_executable(tsar ${TSAR_EXEC_SOURCES}) 4 | 5 | if(MSVC_IDE) 6 | file(GLOB ANALYSIS_INTERNAL_HEADERS 7 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) 8 | source_group(bcl FILES ${BCL_CORE_HEADERS}) 9 | if (APC_FOUND) 10 | source_group(apc FILES ${APC_CORE_HEADERS}) 11 | endif() 12 | if(lp_solve_FOUND) 13 | source_group(lp_solve FILES ${lp_solve_HEADERS}) 14 | endif() 15 | endif() 16 | 17 | add_dependencies(tsar TSARTool) 18 | if(NOT PACKAGE_LLVM) 19 | add_dependencies(tsar ${CLANG_LIBS} ${FLANG_LIBS} ${LLVM_LIBS}) 20 | endif() 21 | target_link_libraries(tsar TSARTool ${CLANG_LIBS} ${FLANG_LIBS} ${LLVM_LIBS} BCL::Core) 22 | 23 | set_target_properties(tsar PROPERTIES FOLDER "${TSAR_FOLDER}") 24 | 25 | install(TARGETS tsar EXPORT TSARExports RUNTIME DESTINATION bin) 26 | -------------------------------------------------------------------------------- /lib/Unparse/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(UNPARSE_SOURCES DIUnparser.cpp SourceUnparser.cpp SourceUnparserUtils.cpp 2 | Utils.cpp) 3 | 4 | if(MSVC_IDE) 5 | file(GLOB_RECURSE UNPARSE_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 6 | ${PROJECT_SOURCE_DIR}/include/tsar/Unparse/*.h) 7 | file(GLOB_RECURSE UNPARSE_INTERNAL_HEADERS 8 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) 9 | source_group(bcl FILES ${BCL_CORE_HEADERS}) 10 | endif() 11 | 12 | add_library(TSARUnparse STATIC 13 | ${UNPARSE_SOURCES} ${UNPARSE_HEADERS} ${UNPARSE_INTERNAL_HEADERS}) 14 | 15 | if(NOT PACKAGE_LLVM) 16 | add_dependencies(TSARUnparse ${LLVM_LIBS}) 17 | endif() 18 | target_link_libraries(TSARUnparse TSARAnalysisMemory BCL::Core) 19 | 20 | set_target_properties(TSARUnparse PROPERTIES 21 | FOLDER "${TSAR_LIBRARY_FOLDER}" 22 | COMPILE_DEFINITIONS $<$>:NDEBUG>) 23 | 24 | -------------------------------------------------------------------------------- /lib/Support/Flang/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SUPPORT_SOURCES Rewriter.cpp Diagnostic.cpp) 2 | 3 | if(MSVC_IDE) 4 | file(GLOB SUPPORT_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 5 | ${PROJECT_SOURCE_DIR}/include/tsar/Support/Flang/*.h) 6 | file(GLOB SUPPORT_INTERNAL_HEADERS 7 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) 8 | source_group(bcl FILES ${BCL_CORE_HEADERS}) 9 | endif() 10 | 11 | add_library(TSARSupportFlang STATIC 12 | ${SUPPORT_SOURCES} ${SUPPORT_HEADERS} ${SUPPORT_INTERNAL_HEADERS}) 13 | 14 | if(NOT PACKAGE_LLVM) 15 | add_dependencies(TSARSupportFlang ${FLANG_LIBS} ${LLVM_LIBS}) 16 | endif() 17 | add_dependencies(TSARSupportFlang DirectivesGen DiagnosticKinds) 18 | target_link_libraries(TSARSupportFlang TSARSupport BCL::Core) 19 | 20 | set_target_properties(TSARSupportFlang PROPERTIES 21 | FOLDER "${TSAR_LIBRARY_FOLDER}" 22 | COMPILE_DEFINITIONS $<$>:NDEBUG>) -------------------------------------------------------------------------------- /lib/Support/Clang/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SUPPORT_SOURCES Diagnostic.cpp Utils.cpp) 2 | 3 | if(MSVC_IDE) 4 | file(GLOB SUPPORT_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 5 | ${PROJECT_SOURCE_DIR}/include/tsar/Support/Clang/*.h) 6 | file(GLOB SUPPORT_INTERNAL_HEADERS 7 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) 8 | source_group(bcl FILES ${BCL_CORE_HEADERS}) 9 | endif() 10 | 11 | add_library(TSARSupportClang STATIC 12 | ${SUPPORT_SOURCES} ${SUPPORT_HEADERS} ${SUPPORT_INTERNAL_HEADERS}) 13 | 14 | if(NOT PACKAGE_LLVM) 15 | add_dependencies(TSARSupportClang ${CLANG_LIBS} ${LLVM_LIBS}) 16 | endif() 17 | add_dependencies(TSARSupportClang DirectivesGen DiagnosticKinds) 18 | target_link_libraries(TSARSupportClang TSARSupport ${CLANG_LIBS} BCL::Core) 19 | 20 | set_target_properties(TSARSupportClang PROPERTIES 21 | FOLDER "${TSAR_LIBRARY_FOLDER}" 22 | COMPILE_DEFINITIONS $<$>:NDEBUG>) -------------------------------------------------------------------------------- /lib/Frontend/Flang/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(FRONTEND_SOURCES TransformationContext.cpp Tooling.cpp Action.cpp) 3 | 4 | if(MSVC_IDE) 5 | file(GLOB_RECURSE FRONTEND_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 6 | ${PROJECT_SOURCE_DIR}/include/tsar/Frontend/Flang/*.h) 7 | file(GLOB_RECURSE FRONTEND_INTERNAL_HEADERS 8 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) 9 | source_group(bcl FILES ${BCL_CORE_HEADERS}) 10 | endif() 11 | 12 | add_library(TSARFrontendFlang STATIC 13 | ${FRONTEND_SOURCES} ${FRONTEND_HEADERS} ${FRONTEND_INTERNAL_HEADERS}) 14 | 15 | if(NOT PACKAGE_LLVM) 16 | add_dependencies(TSARFrontendFlang ${FLANG_LIBS} ${LLVM_LIBS}) 17 | endif() 18 | add_dependencies(TSARFrontendFlang DirectivesGen DiagnosticKinds) 19 | target_link_libraries(TSARFrontendFlang BCL::Core) 20 | 21 | set_target_properties(TSARFrontendFlang PROPERTIES 22 | FOLDER "${TSAR_LIBRARY_FOLDER}" 23 | COMPILE_DEFINITIONS $<$>:NDEBUG>) 24 | -------------------------------------------------------------------------------- /lib/Analysis/Parallel/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(ANALYSIS_SOURCES Passes.cpp ParallelLoop.cpp) 2 | 3 | if(MSVC_IDE) 4 | file(GLOB_RECURSE ANALYSIS_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 5 | ${PROJECT_SOURCE_DIR}/include/tsar/Analysis/Parallel/*.h) 6 | file(GLOB_RECURSE ANALYSIS_INTERNAL_HEADERS 7 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) 8 | source_group(bcl FILES ${BCL_CORE_HEADERS}) 9 | endif() 10 | 11 | add_library(TSARAnalysisParallel STATIC 12 | ${ANALYSIS_SOURCES} ${ANALYSIS_HEADERS} ${ANALYSIS_INTERNAL_HEADERS}) 13 | 14 | if(NOT PACKAGE_LLVM) 15 | add_dependencies(TSARAnalysisParallel ${LLVM_LIBS}) 16 | endif() 17 | add_dependencies(TSARAnalysisParallel IntrinsicsGen AttributesGen) 18 | target_link_libraries(TSARAnalysisParallel 19 | TSARUnparse TSARAnalysisMemory BCL::Core) 20 | 21 | set_target_properties(TSARAnalysisParallel PROPERTIES 22 | FOLDER "${TSAR_LIBRARY_FOLDER}" 23 | COMPILE_DEFINITIONS $<$>:NDEBUG>) 24 | -------------------------------------------------------------------------------- /lib/Analysis/Flang/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(ANALYSIS_SOURCES Passes.cpp ExpressionMatcher.cpp) 2 | 3 | if(MSVC_IDE) 4 | file(GLOB_RECURSE ANALYSIS_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 5 | ${PROJECT_SOURCE_DIR}/include/tsar/Analysis/Flang/*.h) 6 | file(GLOB_RECURSE ANALYSIS_INTERNAL_HEADERS 7 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) 8 | source_group(bcl FILES ${BCL_CORE_HEADERS}) 9 | endif() 10 | 11 | add_library(TSARAnalysisFlang STATIC 12 | ${ANALYSIS_SOURCES} ${ANALYSIS_HEADERS} ${ANALYSIS_INTERNAL_HEADERS}) 13 | 14 | if(NOT PACKAGE_LLVM) 15 | add_dependencies(TSARAnalysisFlang ${FLANG_LIBS} ${LLVM_LIBS}) 16 | endif() 17 | add_dependencies(TSARAnalysisFlang DirectivesGen DiagnosticKinds 18 | IntrinsicsGen AttributesGen) 19 | target_link_libraries(TSARAnalysisFlang 20 | TSARAnalysisMemory TSARSupportFlang TSARTool BCL::Core) 21 | 22 | set_target_properties(TSARAnalysisFlang PROPERTIES 23 | FOLDER "${TSAR_LIBRARY_FOLDER}" 24 | COMPILE_DEFINITIONS $<$>:NDEBUG>) 25 | -------------------------------------------------------------------------------- /lib/Analysis/Reader/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(ANALYSIS_SOURCES Passes.cpp AnalysisReader.cpp RegionWeights.cpp 2 | AnalysisWriter.cpp) 3 | 4 | if(MSVC_IDE) 5 | file(GLOB_RECURSE ANALYSIS_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 6 | ${PROJECT_SOURCE_DIR}/include/tsar/Analysis/Reader/*.h) 7 | file(GLOB_RECURSE ANALYSIS_INTERNAL_HEADERS 8 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) 9 | source_group(bcl FILES ${BCL_CORE_HEADERS}) 10 | endif() 11 | 12 | add_library(TSARAnalysisReader STATIC 13 | ${ANALYSIS_SOURCES} ${ANALYSIS_HEADERS} ${ANALYSIS_INTERNAL_HEADERS}) 14 | 15 | if(NOT PACKAGE_LLVM) 16 | add_dependencies(TSARAnalysisReader ${LLVM_LIBS}) 17 | endif() 18 | add_dependencies(TSARAnalysisReader IntrinsicsGen AttributesGen) 19 | target_link_libraries(TSARAnalysisReader 20 | TSARAnalysis TSARAnalysisMemory TSARSupport BCL::Core) 21 | 22 | set_target_properties(TSARAnalysisReader PROPERTIES 23 | FOLDER "${TSAR_LIBRARY_FOLDER}" 24 | COMPILE_DEFINITIONS $<$>:NDEBUG>) 25 | -------------------------------------------------------------------------------- /lib/Transform/IR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(TRANSFORM_SOURCES Passes.cpp DeadCodeElimination.cpp InterprocAttr.cpp 2 | MetadataUtils.cpp Utils.cpp CallExtractor.cpp DependenceInliner.cpp 3 | NoCaptureAnalysis.cpp PointerScalarizer.cpp) 4 | 5 | if(MSVC_IDE) 6 | file(GLOB_RECURSE TRANSFORM_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 7 | ${PROJECT_SOURCE_DIR}/include/tsar/Transform/IR/*.h) 8 | file(GLOB_RECURSE TRANSFORM_INTERNAL_HEADERS 9 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) 10 | source_group(bcl FILES ${BCL_CORE_HEADERS}) 11 | endif() 12 | 13 | add_library(TSARTransformIR STATIC 14 | ${TRANSFORM_SOURCES} ${TRANSFORM_HEADERS} ${TRANSFORM_INTERNAL_HEADERS}) 15 | 16 | if(NOT PACKAGE_LLVM) 17 | add_dependencies(TSARTransformIR ${LLVM_LIBS}) 18 | endif() 19 | add_dependencies(TSARTransformIR TSARAnalysisMemory IntrinsicsGen AttributesGen) 20 | target_link_libraries(TSARTransformIR BCL::Core) 21 | 22 | set_target_properties(TSARTransformIR PROPERTIES 23 | FOLDER "${TSAR_LIBRARY_FOLDER}" 24 | COMPILE_DEFINITIONS $<$>:NDEBUG>) 25 | -------------------------------------------------------------------------------- /lib/Frontend/Clang/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(FRONTEND_SOURCES FrontendActions.cpp ASTMergeAction.cpp Passes.cpp 2 | Action.cpp PragmaHandlers.cpp Pragma.cpp TransformationContext.cpp) 3 | 4 | if(MSVC_IDE) 5 | file(GLOB_RECURSE FRONTEND_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 6 | ${PROJECT_SOURCE_DIR}/include/tsar/Frontend/Clang/*.h) 7 | file(GLOB_RECURSE FRONTEND_INTERNAL_HEADERS 8 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) 9 | source_group(bcl FILES ${BCL_CORE_HEADERS}) 10 | endif() 11 | 12 | add_library(TSARFrontendClang STATIC 13 | ${FRONTEND_SOURCES} ${FRONTEND_HEADERS} ${FRONTEND_INTERNAL_HEADERS}) 14 | 15 | if(NOT PACKAGE_LLVM) 16 | add_dependencies(TSARFrontendClang ${CLANG_LIBS} ${FLANG_LIBS} ${LLVM_LIBS}) 17 | endif() 18 | add_dependencies(TSARFrontendClang DirectivesGen DiagnosticKinds) 19 | target_link_libraries(TSARFrontendClang TSARAnalysisClang BCL::Core ${FLANG_LIBS}) 20 | 21 | set_target_properties(TSARFrontendClang PROPERTIES 22 | FOLDER "${TSAR_LIBRARY_FOLDER}" 23 | COMPILE_DEFINITIONS $<$>:NDEBUG>) 24 | 25 | -------------------------------------------------------------------------------- /lib/APC/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(APC_SOURCES Passes.cpp APCContext.cpp Utils.cpp LoopInfo.cpp 2 | ArrayInfo.cpp FunctionInfo.cpp Parallelization.cpp ClangDVMHWriter.cpp 3 | DistributionLimits.cpp DirectivesCollector.cpp DiagnosticPrinter.cpp) 4 | 5 | if(MSVC_IDE) 6 | file(GLOB_RECURSE APC_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 7 | ${PROJECT_SOURCE_DIR}/include/tsar/APC/*.h) 8 | file(GLOB_RECURSE APC_INTERNAL_HEADERS 9 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) 10 | source_group(apc FILES ${APC_CORE_HEADERS}) 11 | source_group(bcl FILES ${BCL_CORE_HEADERS}) 12 | endif() 13 | 14 | add_library(APC STATIC ${APC_SOURCES} ${APC_HEADERS} ${APC_INTERNAL_HEADERS}) 15 | 16 | if(NOT PACKAGE_LLVM) 17 | add_dependencies(APC ${CLANG_LIBS} ${LLVM_LIBS}) 18 | endif() 19 | add_dependencies(APC DirectivesGen DiagnosticKinds IntrinsicsGen AttributesGen) 20 | target_link_libraries(APC TSARTransformClang BCL::Core APC::APCCore) 21 | 22 | add_definitions("-D__SPC") 23 | set_target_properties(APC PROPERTIES 24 | FOLDER "${TSAR_LIBRARY_FOLDER}" 25 | COMPILE_DEFINITIONS $<$>:NDEBUG>) 26 | -------------------------------------------------------------------------------- /lib/Transform/AST/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(TRANSFORM_SOURCES Passes.cpp FormatPass.cpp) 2 | 3 | if(MSVC_IDE) 4 | file(GLOB_RECURSE TRANSFORM_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 5 | ${PROJECT_SOURCE_DIR}/include/tsar/Transform/AST/*.h) 6 | file(GLOB_RECURSE TRANSFORM_INTERNAL_HEADERS 7 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) 8 | source_group(bcl FILES ${BCL_CORE_HEADERS}) 9 | endif() 10 | 11 | add_library(TSARTransformAST STATIC 12 | ${TRANSFORM_SOURCES} ${TRANSFORM_HEADERS} ${TRANSFORM_INTERNAL_HEADERS}) 13 | 14 | if(NOT PACKAGE_LLVM) 15 | add_dependencies(TSARTransformAST ${CLANG_LIBS} ${FLANG_LIBS} ${LLVM_LIBS}) 16 | endif() 17 | add_dependencies(TSARTransformAST DirectivesGen DiagnosticKinds 18 | IntrinsicsGen AttributesGen) 19 | target_link_libraries(TSARTransformAST PRIVATE 20 | TSARTransformClang TSARTool BCL::Core) 21 | if (FLANG_FOUND) 22 | target_link_libraries(TSARTransformAST PRIVATE TSARTransformFlang) 23 | endif() 24 | 25 | set_target_properties(TSARTransformAST PROPERTIES 26 | FOLDER "${TSAR_LIBRARY_FOLDER}" 27 | COMPILE_DEFINITIONS $<$>:NDEBUG>) 28 | -------------------------------------------------------------------------------- /cmake/tsar-tablegen.cmake: -------------------------------------------------------------------------------- 1 | function(tsar_tablegen) 2 | # Syntax: 3 | # tsar_tablegen output-file [tablegen-arg ...] SOURCE source-file 4 | # [[TARGET cmake-target-name] [DEPENDS extra-dependency ...]] 5 | # 6 | # Generates a custom command for invoking tblgen as 7 | # 8 | # tblgen source-file -o=output-file tablegen-arg ... 9 | # 10 | # and, if cmake-target-name is provided, creates a custom target for 11 | # executing the custom command depending on output-file. It is 12 | # possible to list more files to depend after DEPENDS. 13 | 14 | cmake_parse_arguments(TTG "" "SOURCE;TARGET" "" ${ARGN}) 15 | 16 | if( NOT TTG_SOURCE ) 17 | message(FATAL_ERROR "SOURCE source-file required by tsar_tablegen") 18 | endif() 19 | 20 | set( LLVM_TARGET_DEFINITIONS ${TTG_SOURCE} ) 21 | 22 | tablegen(TSAR ${TTG_UNPARSED_ARGUMENTS}) 23 | 24 | if(TTG_TARGET) 25 | add_public_tablegen_target(${TTG_TARGET}) 26 | set_target_properties( ${TTG_TARGET} PROPERTIES FOLDER "Tsar tablegenning") 27 | set_property(GLOBAL APPEND PROPERTY TSAR_TABLEGEN_TARGETS ${TTG_TARGET}) 28 | endif() 29 | endfunction(tsar_tablegen) -------------------------------------------------------------------------------- /lib/Transform/Flang/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(TRANSFORM_SOURCES Passes.cpp Format.cpp ConstantReplacement.cpp 2 | VariableRegistration.cpp) 3 | 4 | if(MSVC_IDE) 5 | file(GLOB_RECURSE TRANSFORM_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 6 | ${PROJECT_SOURCE_DIR}/include/tsar/Transform/Flang/*.h) 7 | file(GLOB_RECURSE TRANSFORM_INTERNAL_HEADERS 8 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) 9 | source_group(bcl FILES ${BCL_CORE_HEADERS}) 10 | endif() 11 | 12 | add_library(TSARTransformFlang STATIC 13 | ${TRANSFORM_SOURCES} ${TRANSFORM_HEADERS} ${TRANSFORM_INTERNAL_HEADERS}) 14 | 15 | if(MSVC) 16 | target_compile_options(TSARTransformFlang 17 | PRIVATE $<$>:/bigobj>) 18 | endif() 19 | 20 | if(NOT PACKAGE_LLVM) 21 | add_dependencies(TSARTransformFlang ${FLANG_LIBS} ${LLVM_LIBS}) 22 | endif() 23 | add_dependencies(TSARTransformFlang DirectivesGen DiagnosticKinds 24 | IntrinsicsGen AttributesGen) 25 | target_link_libraries(TSARTransformFlang TSARTool BCL::Core) 26 | 27 | set_target_properties(TSARTransformFlang PROPERTIES 28 | FOLDER "${TSAR_LIBRARY_FOLDER}" 29 | COMPILE_DEFINITIONS $<$>:NDEBUG>) 30 | -------------------------------------------------------------------------------- /test/instrumentation/Jacobi.f90: -------------------------------------------------------------------------------- 1 | !===--- Jacobi.f90 ----- Jacobi Iterative Method ----*- Fortran -*-===! 2 | ! 3 | ! This file implements Jacobi iterative method which is an iterative 4 | ! method used to solve partial differential equations. 5 | ! 6 | !===---------------------------------------------------------------===! 7 | 8 | program Jacobi 9 | parameter (L = 8, ITMAX = 10) 10 | real A(L,L), Eps, Maxeps, B(L, L) 11 | MAXEPS = 0.5 12 | do J = 1, L 13 | do I = 1, L 14 | A(I, J) = 0. 15 | if (I == 1 .or. J == 1 .or. I == L .or. J == L) then 16 | B(I, J) = 0. 17 | else 18 | B(I, J) = 1. + I + J 19 | endif 20 | enddo 21 | enddo 22 | do It = 1, ITMAX 23 | Eps = 0. 24 | do J = 2, L - 1 25 | do I = 2, L - 1 26 | Eps = max(Eps, abs(B(I, J) - A(I, J))) 27 | A(I, J) = B(I, J) 28 | enddo 29 | enddo 30 | do J = 2, L - 1 31 | do I = 2, l - 1 32 | B(I, J) = (A(I, J-1) + A(I-1, J) + A(I+1, J) + A(I, J+1) ) / 4. 33 | enddo 34 | enddo 35 | print 200, It, Eps 36 | 200 format (' It = ', i4, ' Eps = ', e14.7) 37 | if (Eps < MAXEPS) exit 38 | enddo 39 | end 40 | -------------------------------------------------------------------------------- /lib/Transform/Mixed/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(TRANSFORM_SOURCES Passes.cpp Instrumentation.cpp DILoopRetriever.cpp 2 | DINodeRetriever.cpp) 3 | 4 | if(FLANG_FOUND) 5 | set(TRANSFORM_SOURCES ${TRANSFORM_SOURCES} DummyScopeAAPass.cpp 6 | DIVariableRetriever.cpp) 7 | else() 8 | set(TRANSFORM_SOURCES ${TRANSFORM_SOURCES} FlangStubs.cpp) 9 | endif() 10 | 11 | if(MSVC_IDE) 12 | file(GLOB_RECURSE TRANSFORM_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 13 | ${PROJECT_SOURCE_DIR}/include/tsar/Transform/Mixed/*.h) 14 | file(GLOB_RECURSE TRANSFORM_INTERNAL_HEADERS 15 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) 16 | source_group(bcl FILES ${BCL_CORE_HEADERS}) 17 | endif() 18 | 19 | add_library(TSARTransformMixed STATIC 20 | ${TRANSFORM_SOURCES} ${TRANSFORM_HEADERS} ${TRANSFORM_INTERNAL_HEADERS}) 21 | 22 | if(NOT PACKAGE_LLVM) 23 | add_dependencies(TSARTransformMixed ${LLVM_LIBS} ${CLANG_LIBS}) 24 | endif() 25 | add_dependencies(TSARTransformMixed IntrinsicsGen AttributesGen) 26 | target_link_libraries(TSARTransformMixed TSARTransformIR BCL::Core) 27 | 28 | set_target_properties(TSARTransformMixed PROPERTIES 29 | FOLDER "${TSAR_LIBRARY_FOLDER}" 30 | COMPILE_DEFINITIONS $<$>:NDEBUG>) 31 | -------------------------------------------------------------------------------- /lib/Frontend/Clang/Passes.cpp: -------------------------------------------------------------------------------- 1 | //=== Passes.cpp - Create and Initialize Parse Passes (Clang) - -*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This contains functions to initialize passes which are necessary to parse 22 | // C programs. 23 | // 24 | //===----------------------------------------------------------------------===// 25 | 26 | #include "tsar/Frontend/Clang/Passes.h" 27 | 28 | using namespace llvm; 29 | 30 | void llvm::initializeClangParse(PassRegistry &Registry) { 31 | } 32 | -------------------------------------------------------------------------------- /lib/Analysis/Clang/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(ANALYSIS_SOURCES Passes.cpp DIMemoryMatcher.cpp NoMacroAssert.cpp 2 | MemoryMatcher.cpp LoopMatcher.cpp ExpressionMatcher.cpp CanonicalLoop.cpp 3 | PerfectLoop.cpp GlobalInfoExtractor.cpp ControlFlowTraits.cpp 4 | RegionDirectiveInfo.cpp VariableCollector.cpp ASTDependenceAnalysis.cpp 5 | IncludeTree.cpp Utils.cpp) 6 | 7 | 8 | if(MSVC_IDE) 9 | file(GLOB_RECURSE ANALYSIS_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 10 | ${PROJECT_SOURCE_DIR}/include/tsar/Analysis/Clang/*.h) 11 | file(GLOB_RECURSE ANALYSIS_INTERNAL_HEADERS 12 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) 13 | source_group(bcl FILES ${BCL_CORE_HEADERS}) 14 | endif() 15 | 16 | add_library(TSARAnalysisClang STATIC 17 | ${ANALYSIS_SOURCES} ${ANALYSIS_HEADERS} ${ANALYSIS_INTERNAL_HEADERS}) 18 | 19 | if(NOT PACKAGE_LLVM) 20 | add_dependencies(TSARAnalysisClang ${CLANG_LIBS} ${LLVM_LIBS}) 21 | endif() 22 | add_dependencies(TSARAnalysisClang DirectivesGen DiagnosticKinds 23 | IntrinsicsGen AttributesGen) 24 | target_link_libraries(TSARAnalysisClang 25 | TSARAnalysisMemory TSARSupportClang TSARTool BCL::Core) 26 | 27 | set_target_properties(TSARAnalysisClang PROPERTIES 28 | FOLDER "${TSAR_LIBRARY_FOLDER}" 29 | COMPILE_DEFINITIONS $<$>:NDEBUG>) 30 | -------------------------------------------------------------------------------- /lib/Analysis/Passes.cpp: -------------------------------------------------------------------------------- 1 | //=== Passes.cpp - Create and Initialize Analysis Passes (Base) -*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This contains functions to initialize general analysis passes. 22 | // 23 | //===----------------------------------------------------------------------===// 24 | 25 | #include "tsar/Analysis/Passes.h" 26 | 27 | using namespace llvm; 28 | 29 | void llvm::initializeAnalysisBase(PassRegistry &Registry) { 30 | initializeDFRegionInfoPassPass(Registry); 31 | initializeAnalysisConnectionImmutableWrapperPass(Registry); 32 | } 33 | -------------------------------------------------------------------------------- /lib/Analysis/Flang/Passes.cpp: -------------------------------------------------------------------------------- 1 | //=== Passes.cpp - Create and Initialize Analysis Passes (Flang) *- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2022 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This contains functions to initialize passes which are necessary for 22 | // source-base analysis of Fortran programs. 23 | // 24 | //===----------------------------------------------------------------------===// 25 | 26 | #include "tsar/Analysis/Flang/Passes.h" 27 | 28 | using namespace llvm; 29 | 30 | void llvm::initializeFlangAnalysis(PassRegistry &Registry) { 31 | initializeFlangExprMatcherPassPass(Registry); 32 | } 33 | -------------------------------------------------------------------------------- /lib/Analysis/Parallel/Passes.cpp: -------------------------------------------------------------------------------- 1 | //=== Passes.cpp - Create and Initialize Parallelization Passes -*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2019 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This contains functions to initialize analysis passes which determine 22 | // opportunities of program parallelization. 23 | // 24 | //===----------------------------------------------------------------------===// 25 | 26 | #include "tsar/Analysis/Parallel/Passes.h" 27 | 28 | using namespace llvm; 29 | 30 | void llvm::initializeParallelizationAnalysis(PassRegistry &Registry) { 31 | initializeParallelLoopPassPass(Registry); 32 | } 33 | -------------------------------------------------------------------------------- /include/tsar/Core/Passes.h: -------------------------------------------------------------------------------- 1 | //===------ Passes.h ------ Initialize TSAR Passes --------------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This contains functions to initialize passes that are implemented in TSAR. 22 | // 23 | //===----------------------------------------------------------------------===// 24 | 25 | #ifndef TSAR_CORE_PASSES_H 26 | #define TSAR_CORE_PASSES_H 27 | 28 | namespace llvm { 29 | class PassRegistry; 30 | 31 | /// Initializes all passes developed for TSAR project 32 | void initializeTSAR(PassRegistry &Registry); 33 | } 34 | 35 | #endif//TSAR_CORE_PASSES_H 36 | -------------------------------------------------------------------------------- /test/instrumentation/Jacobi.c: -------------------------------------------------------------------------------- 1 | //===--- Jacobi.c --------- Jacobi Iterative Method ---------------*- C -*-===// 2 | // 3 | // This file implements Jacobi iterative method which is an iterative method 4 | // used to solve partial differential equations. 5 | // 6 | //===----------------------------------------------------------------------===// 7 | 8 | #include 9 | #include 10 | 11 | #define Max(A, B) ((A) > (B) ? (A) : (B)) 12 | 13 | #define L 8 14 | #define ITMAX 10 15 | #define MAXEPS 0.5 16 | 17 | double A[L][L]; 18 | double B[L][L]; 19 | 20 | int main() { 21 | for (int I = 0; I < L; ++I) 22 | for (int J = 0; J < L; ++J) { 23 | A[I][J] = 0; 24 | if (I == 0 || J == 0 || I == L - 1 || J == L - 1) 25 | B[I][J] = 0; 26 | else 27 | B[I][J] = 3 + I + J; 28 | } 29 | for (int It = 1; It <= ITMAX; ++It) { 30 | double Eps = 0; 31 | for (int I = 1; I < L - 1; ++I) 32 | for (int J = 1; J < L - 1; ++J) { 33 | double Tmp = fabs(B[I][J] - A[I][J]); 34 | Eps = Max(Tmp, Eps); 35 | A[I][J] = B[I][J]; 36 | } 37 | for (int I = 1; I < L - 1; ++I) 38 | for (int J = 1; J < L - 1; ++J) 39 | B[I][J] = (A[I - 1][J] + A[I][J - 1] + A[I][J + 1] + A[I + 1][J]) / 4.0; 40 | printf("It=%4i Eps=%e\n", It, Eps); 41 | if (Eps < MAXEPS) 42 | break; 43 | } 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /lib/Support/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SUPPORT_SOURCES SCEVUtils.cpp GlobalOptions.cpp Utils.cpp Directives.cpp 2 | PassBarrier.cpp EmptyPass.cpp Diagnostic.cpp RewriterBase.cpp) 3 | 4 | if(MSVC_IDE) 5 | file(GLOB SUPPORT_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 6 | ${PROJECT_SOURCE_DIR}/include/tsar/Support/*.h) 7 | file(GLOB SUPPORT_INTERNAL_HEADERS 8 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) 9 | source_group(bcl FILES ${BCL_CORE_HEADERS}) 10 | endif() 11 | 12 | add_library(TSARSupport STATIC 13 | ${SUPPORT_SOURCES} ${SUPPORT_HEADERS} ${SUPPORT_INTERNAL_HEADERS}) 14 | 15 | if(NOT PACKAGE_LLVM) 16 | add_dependencies(TSARSupport ${LLVM_LIBS}) 17 | endif() 18 | target_link_libraries(TSARSupport ${LLVM_LIBS} BCL::Core) 19 | 20 | set_target_properties(TSARSupport PROPERTIES 21 | FOLDER "${TSAR_LIBRARY_FOLDER}" 22 | COMPILE_DEFINITIONS $<$>:NDEBUG>) 23 | 24 | include(tsar-tablegen) 25 | 26 | tsar_tablegen(Directives.gen -gen-tsar-directives-defs 27 | SOURCE ${PROJECT_SOURCE_DIR}/include/tsar/Support/Directives.td 28 | TARGET DirectivesGen) 29 | tsar_tablegen(DiagnosticKinds.inc -gen-tsar-diags-defs 30 | SOURCE ${PROJECT_SOURCE_DIR}/include/tsar/Support/DiagnosticKinds.td 31 | TARGET DiagnosticKinds) 32 | add_dependencies(TSARSupport DirectivesGen DiagnosticKinds) 33 | 34 | add_subdirectory(Clang) 35 | 36 | if(FLANG_FOUND) 37 | add_subdirectory(Flang) 38 | endif() -------------------------------------------------------------------------------- /lib/Transform/Clang/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(TRANSFORM_SOURCES Passes.cpp ExprPropagation.cpp Inline.cpp RenameLocal.cpp 2 | DeadDeclsElimination.cpp Format.cpp OpenMPAutoPar.cpp DVMHWriter.cpp 3 | SharedMemoryAutoPar.cpp DVMHDirecitves.cpp DVMHSMAutoPar.cpp 4 | DVMHDataTransferIPO.cpp StructureReplacement.cpp LoopInterchange.cpp 5 | LoopReversal.cpp UnreachableCodeElimination.cpp) 6 | 7 | if(MSVC_IDE) 8 | file(GLOB_RECURSE TRANSFORM_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 9 | ${PROJECT_SOURCE_DIR}/include/tsar/Transform/Clang/*.h) 10 | file(GLOB_RECURSE TRANSFORM_INTERNAL_HEADERS 11 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) 12 | source_group(bcl FILES ${BCL_CORE_HEADERS}) 13 | endif() 14 | 15 | add_library(TSARTransformClang STATIC 16 | ${TRANSFORM_SOURCES} ${TRANSFORM_HEADERS} ${TRANSFORM_INTERNAL_HEADERS}) 17 | 18 | if(MSVC) 19 | target_compile_options(TSARTransformClang 20 | PRIVATE $<$>:/bigobj>) 21 | endif() 22 | 23 | if(NOT PACKAGE_LLVM) 24 | add_dependencies(TSARTransformClang ${CLANG_LIBS} ${LLVM_LIBS}) 25 | endif() 26 | add_dependencies(TSARTransformClang DirectivesGen DiagnosticKinds 27 | IntrinsicsGen AttributesGen) 28 | target_link_libraries(TSARTransformClang TSARAnalysisClang TSARTool BCL::Core) 29 | 30 | set_target_properties(TSARTransformClang PROPERTIES 31 | FOLDER "${TSAR_LIBRARY_FOLDER}" 32 | COMPILE_DEFINITIONS $<$>:NDEBUG>) 33 | -------------------------------------------------------------------------------- /lib/Transform/Flang/Passes.cpp: -------------------------------------------------------------------------------- 1 | //=== Passes.cpp Create and Initialize Transform Passes (Flang) *- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2021 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This contains functions to initialize passes which are necessary for 22 | // source-to-source transformation of Fortran programs. 23 | // 24 | //===----------------------------------------------------------------------===// 25 | 26 | #include "tsar/Transform/Flang/Passes.h" 27 | 28 | using namespace llvm; 29 | 30 | void llvm::initializeFlangTransform(PassRegistry &Registry) { 31 | initializeFlangConstantReplacementPassPass(Registry); 32 | initializeFlangVariableRegistrationPassPass(Registry); 33 | } 34 | -------------------------------------------------------------------------------- /include/tsar/APC/Utils.h: -------------------------------------------------------------------------------- 1 | //===--- Utils.h -------- Utility Methods and Classes ----------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file defines abstractions which simplify usage of other abstractions. 22 | // 23 | //===----------------------------------------------------------------------===// 24 | 25 | #ifndef TSAR_APC_UTILS_H 26 | #define TSAR_APC_UTILS_H 27 | 28 | #include 29 | 30 | namespace llvm { 31 | class raw_ostream; 32 | } 33 | 34 | namespace tsar { 35 | /// Print version of auto-parallelizing compiler to a specified stream. 36 | void printAPCVersion(llvm::raw_ostream &OS); 37 | } 38 | #endif//TSAR_APC_UTILS_H 39 | -------------------------------------------------------------------------------- /lib/Analysis/Reader/Passes.cpp: -------------------------------------------------------------------------------- 1 | //=== Passes.cpp Create and Initialize Analysis Passes (Reader) *- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This contains functions to initialize passes which are necessary 22 | // to read external analysis results. 23 | // 24 | //===----------------------------------------------------------------------===// 25 | 26 | #include "tsar/Analysis/Reader/Passes.h" 27 | 28 | using namespace llvm; 29 | 30 | void llvm::initializeAnalysisReader(PassRegistry &Registry) { 31 | initializeAnalysisReaderPass(Registry); 32 | initializeAnalysisWriterPass(Registry); 33 | initializeRegionWeightsEstimatorPass(Registry); 34 | } 35 | -------------------------------------------------------------------------------- /lib/Transform/AST/Passes.cpp: -------------------------------------------------------------------------------- 1 | //===- Passes.cpp Create and Initialize Transform Passes (AST) -*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2020 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file contains functions to initialize passes which are necessary for 22 | // source-to-source transformation. These passes combine frontend-dependent 23 | // passes and provide a general frontend-independent interface to manage 24 | // program transformation. 25 | // 26 | //===----------------------------------------------------------------------===// 27 | 28 | #include "tsar/Transform/AST/Passes.h" 29 | 30 | using namespace llvm; 31 | 32 | void llvm::initializeASTTransform(PassRegistry &Registry) { 33 | initializeASTFormatPassPass(Registry); 34 | } 35 | -------------------------------------------------------------------------------- /include/tsar/Analysis/Attributes.td: -------------------------------------------------------------------------------- 1 | //===- Attribute.td --- Defines all TSAR attributes --------*- tablegen -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file defines properties of all TSAR attributes. 22 | // 23 | //===----------------------------------------------------------------------===// 24 | 25 | // Define one attribute. 26 | class Attribute { 27 | string Name = name; 28 | } 29 | 30 | def NoIO : Attribute<"sapfor.noio">; 31 | def AlwaysReturn : Attribute<"sapfor.alwaysreturn">; 32 | def LibFunc : Attribute<"sapfor.libfunc">; 33 | def DirectUserCallee : Attribute<"sapfor.direct-user-callee">; 34 | def Inline : Attribute<"sapfor.inline">; 35 | def IndirectCall : Attribute<"sapfor.indirect-call">; -------------------------------------------------------------------------------- /lib/Analysis/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(ANALYSIS_SOURCES Passes.cpp PrintUtils.cpp DFRegionInfo.cpp Attributes.cpp 2 | Intrinsics.cpp AnalysisSocket.cpp AnalysisServer.cpp) 3 | 4 | if(MSVC_IDE) 5 | file(GLOB ANALYSIS_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 6 | ${PROJECT_SOURCE_DIR}/include/tsar/Analysis/*.h) 7 | file(GLOB ANALYSIS_INTERNAL_HEADERS 8 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) 9 | source_group(bcl FILES ${BCL_CORE_HEADERS}) 10 | endif() 11 | 12 | add_library(TSARAnalysis STATIC 13 | ${ANALYSIS_SOURCES} ${ANALYSIS_HEADERS} ${ANALYSIS_INTERNAL_HEADERS}) 14 | 15 | if(NOT PACKAGE_LLVM) 16 | add_dependencies(TSARAnalysis ${LLVM_LIBS}) 17 | endif() 18 | target_link_libraries(TSARAnalysis TSARSupport BCL::Core) 19 | 20 | set_target_properties(TSARAnalysis PROPERTIES 21 | FOLDER "${TSAR_LIBRARY_FOLDER}" 22 | COMPILE_DEFINITIONS $<$>:NDEBUG>) 23 | 24 | include(tsar-tablegen) 25 | 26 | tsar_tablegen(Intrinsics.gen -gen-tsar-intrinsics-defs 27 | SOURCE ${PROJECT_SOURCE_DIR}/include/tsar/Analysis/Intrinsics.td 28 | TARGET IntrinsicsGen) 29 | tsar_tablegen(Attributes.gen -gen-tsar-attributes-defs 30 | SOURCE ${PROJECT_SOURCE_DIR}/include/tsar/Analysis/Attributes.td 31 | TARGET AttributesGen) 32 | add_dependencies(TSARAnalysis IntrinsicsGen AttributesGen) 33 | 34 | add_subdirectory(Clang) 35 | if(FLANG_FOUND) 36 | add_subdirectory(Flang) 37 | endif() 38 | add_subdirectory(Memory) 39 | add_subdirectory(Reader) 40 | add_subdirectory(Parallel) 41 | -------------------------------------------------------------------------------- /lib/Analysis/Memory/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(ANALYSIS_SOURCES Passes.cpp DependenceAnalysis.cpp PrivateAnalysis.cpp 2 | DIDependenceAnalysis.cpp BitMemoryTrait.cpp ProcessTraitPass.cpp Utils.cpp 3 | TraitFilter.cpp NotInitializedMemory.cpp DIEstimateMemory.cpp 4 | EstimateMemory.cpp DefinedMemory.cpp LiveMemory.cpp AliasTreePrinter.cpp 5 | DIAliasTreePrinter.cpp DIMemoryLocation.cpp DFMemoryLocation.cpp 6 | Delinearization.cpp ServerUtils.cpp ClonedDIMemoryMatcher.cpp 7 | GlobalLiveMemory.cpp GlobalDefinedMemory.cpp DIClientServerInfo.cpp 8 | DIMemoryAnalysisServer.cpp DIArrayAccess.cpp AllocasModRef.cpp 9 | MemoryLocationRange.cpp GlobalsAccess.cpp) 10 | 11 | if(MSVC_IDE) 12 | file(GLOB_RECURSE ANALYSIS_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 13 | ${PROJECT_SOURCE_DIR}/include/tsar/Analysis/Memory/*.h) 14 | file(GLOB_RECURSE ANALYSIS_INTERNAL_HEADERS 15 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) 16 | source_group(bcl FILES ${BCL_CORE_HEADERS}) 17 | endif() 18 | 19 | add_library(TSARAnalysisMemory STATIC 20 | ${ANALYSIS_SOURCES} ${ANALYSIS_HEADERS} ${ANALYSIS_INTERNAL_HEADERS}) 21 | 22 | if(NOT PACKAGE_LLVM) 23 | add_dependencies(TSARAnalysisMemory ${LLVM_LIBS}) 24 | endif() 25 | add_dependencies(TSARAnalysisMemory IntrinsicsGen AttributesGen) 26 | target_link_libraries(TSARAnalysisMemory TSARUnparse TSARAnalysis BCL::Core) 27 | 28 | set_target_properties(TSARAnalysisMemory PROPERTIES 29 | FOLDER "${TSAR_LIBRARY_FOLDER}" 30 | COMPILE_DEFINITIONS $<$>:NDEBUG>) 31 | -------------------------------------------------------------------------------- /include/tsar/Transform/Clang/Format.h: -------------------------------------------------------------------------------- 1 | //===----- Format.h --- Source-level Reformat Pass (Clang) ------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file declares functions to reformat sources after transformations. 22 | // 23 | //===----------------------------------------------------------------------===// 24 | 25 | #ifndef TSAR_CLANG_FORMAT_H 26 | #define TSAR_CLANG_FORMAT_H 27 | 28 | #include "tsar/Core/TransformationContext.h" 29 | 30 | namespace tsar { 31 | class ClangTransformationContext; 32 | struct GlobalOptions; 33 | 34 | bool formatSourceAndPrepareToRelease( 35 | const GlobalOptions &GlobalOpts, ClangTransformationContext &TfmCtx, 36 | const FilenameAdjuster &Adjuster); 37 | } 38 | #endif//TSAR_CLANG_FORMAT_H 39 | -------------------------------------------------------------------------------- /include/tsar/Transform/Flang/Format.h: -------------------------------------------------------------------------------- 1 | //===----- Format.h --- Source-level Reformat Pass (Flang) ------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2020 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file declares functions to reformat sources after transformations. 22 | // 23 | //===----------------------------------------------------------------------===// 24 | 25 | #ifndef TSAR_FLANG_FORMAT_H 26 | #define TSAR_FLANG_FORMAT_H 27 | 28 | #include "tsar/Core/TransformationContext.h" 29 | 30 | namespace tsar { 31 | class FlangTransformationContext; 32 | struct GlobalOptions; 33 | 34 | bool formatSourceAndPrepareToRelease( 35 | const GlobalOptions &GlobalOpts, FlangTransformationContext &TfmCtx, 36 | const FilenameAdjuster &Adjuster); 37 | } 38 | #endif//TSAR_FLANG_FORMAT_H 39 | -------------------------------------------------------------------------------- /lib/Support/GlobalOptions.cpp: -------------------------------------------------------------------------------- 1 | //===--- GlobalOptions.h - Global Command Line Options ----------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file defines classes to store command line options. 22 | // 23 | //===----------------------------------------------------------------------===// 24 | 25 | #include "tsar/Support/GlobalOptions.h" 26 | 27 | using namespace llvm; 28 | using namespace tsar; 29 | 30 | char GlobalOptionsImmutableWrapper::ID = 0; 31 | INITIALIZE_PASS(GlobalOptionsImmutableWrapper, "global-options", 32 | "Global Command Line Options Accessor", true, true) 33 | 34 | ImmutablePass * llvm::createGlobalOptionsImmutableWrapper( 35 | const GlobalOptions *Options) { 36 | return new GlobalOptionsImmutableWrapper(Options); 37 | } 38 | -------------------------------------------------------------------------------- /lib/Support/EmptyPass.cpp: -------------------------------------------------------------------------------- 1 | //===---- EmptyPass.cpp ------ Trivial Empty Pass ----------------*- C++ -*===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2020 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file implements a trivial empty pass which does nothing. It can be use 22 | // as a stub if configuration of the build does not provide some passes. 23 | // 24 | //===----------------------------------------------------------------------===// 25 | 26 | #include "tsar/Support/EmptyPass.h" 27 | 28 | using namespace llvm; 29 | 30 | char EmptyFunctionPass::ID = 0; 31 | INITIALIZE_PASS(EmptyFunctionPass, "empty-function-pass", "Empty Function Pass", 32 | true, true) 33 | 34 | char EmptyModulePass::ID = 0; 35 | INITIALIZE_PASS(EmptyModulePass, "empty-module-pass", "Empty Module Pass", true, 36 | true) 37 | -------------------------------------------------------------------------------- /include/tsar/Support/PassBarrier.h: -------------------------------------------------------------------------------- 1 | //===--- PassBarrier.h ---------- Pass Barrier ------------------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2020 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | //===----------------------------------------------------------------------===// 19 | // 20 | // Some function passes (for example DefinedMemoryPass) may use results of 21 | // module passes and these results becomes invalid after transformations. 22 | // A pass in this file do nothing but allow us to finish processing of 23 | // all functions before transformations. 24 | // 25 | //===----------------------------------------------------------------------===// 26 | 27 | #ifndef TSAR_PASS_BARRIER_H 28 | #define TSAR_PASS_BARRIER_H 29 | 30 | namespace llvm { 31 | class ModulePass; 32 | class PassRegistry; 33 | 34 | void initializePassBarrierPass(PassRegistry &Registry); 35 | 36 | ModulePass *createPassBarrier(); 37 | } 38 | 39 | #endif//TSAR_PASS_BARRIER_H 40 | -------------------------------------------------------------------------------- /lib/Transform/Mixed/Passes.cpp: -------------------------------------------------------------------------------- 1 | //=== Passes.cpp Create and Initialize Transform Passes (Clang) *- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This contains functions to initialize passes which performs transformation 22 | // of LLVM IR however depends on source-level information. 23 | // 24 | //===----------------------------------------------------------------------===// 25 | 26 | #include "tsar/Transform/Mixed/Passes.h" 27 | 28 | using namespace llvm; 29 | 30 | void llvm::initializeMixedTransform(PassRegistry &Registry) { 31 | initializeInstrumentationPassPass(Registry); 32 | initializeDILoopRetrieverPassPass(Registry); 33 | initializeDINodeRetrieverPassPass(Registry); 34 | initializeFlangDummyAliasAnalysisPass(Registry); 35 | initializeFlangDIVariableRetrieverPassPass(Registry); 36 | } 37 | -------------------------------------------------------------------------------- /lib/Transform/Mixed/FlangStubs.cpp: -------------------------------------------------------------------------------- 1 | //===---- FlangStubs.cpp -------- Flang Stubs --------------------*- C++ -*===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2020 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // Use this file to create stubs instead of concrete passes if Flang is not 22 | // available. 23 | // 24 | //===----------------------------------------------------------------------===// 25 | 26 | #include "tsar/Transform/Mixed/Passes.h" 27 | #include "tsar/Support/EmptyPass.h" 28 | 29 | using namespace llvm; 30 | 31 | void llvm::initializeFlangDummyAliasAnalysisPass(PassRegistry &) {} 32 | FunctionPass *llvm::createFlangDummyAliasAnalysis() { 33 | return createEmptyFunctionPass(); 34 | } 35 | 36 | void llvm::initializeFlangDIVariableRetrieverPassPass(PassRegistry &) {} 37 | ModulePass *llvm::createFlangDIVariableRetrieverPass() { 38 | return createEmptyModulePass(); 39 | } 40 | -------------------------------------------------------------------------------- /include/tsar/Analysis/Memory/GlobalsAccess.h: -------------------------------------------------------------------------------- 1 | //===- GlobalsAccess.h --- Globals Access Collector -------------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2021 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file implements a pass to collect explicit accesses to global values in 22 | // a function. 23 | // 24 | //===----------------------------------------------------------------------===// 25 | 26 | #ifndef TSAR_GLOBALS_ACCESS_H 27 | #define TSAR_GLOBALS_ACCESS_H 28 | 29 | #include "tsar/Support/AnalysisWrapperPass.h" 30 | #include 31 | #include 32 | 33 | namespace tsar { 34 | using GlobalsAccessMap = 35 | llvm::ValueMap>; 37 | } 38 | 39 | namespace llvm { 40 | /// Wrapper to access global variables referenced in functions. 41 | using GlobalsAccessWrapper = AnalysisWrapperPass; 42 | } 43 | #endif//TSAR_GLOBALS_ACCESS_H 44 | -------------------------------------------------------------------------------- /lib/APC/Passes.cpp: -------------------------------------------------------------------------------- 1 | //===- Passes.cpp ----- Create and Initialize APC Passes --------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This contains functions to initialize passes which are necessary for 22 | // parallelization. 23 | // 24 | //===----------------------------------------------------------------------===// 25 | 26 | #include "tsar/APC/Passes.h" 27 | 28 | using namespace llvm; 29 | 30 | void llvm::initializeAPC(PassRegistry &Registry) { 31 | initializeAPCLoopInfoBasePassPass(Registry); 32 | initializeAPCArrayInfoPassPass(Registry); 33 | initializeAPCFunctionInfoPassPass(Registry); 34 | initializeAPCParallelizationPassPass(Registry); 35 | initializeAPCClangDVMHWriterPass(Registry); 36 | initializeAPCDistrLimitsCheckerPass(Registry); 37 | initializeAPCDistrLimitsIPOCheckerPass(Registry); 38 | initializeAPCClangDirectivesCollectorPass(Registry); 39 | initializeAPCClangDiagnosticPrinterPass(Registry); 40 | } 41 | -------------------------------------------------------------------------------- /tools/tsar-server/ClangMessages.h: -------------------------------------------------------------------------------- 1 | //===-- ClangMessages.h ----- JSON Messages (Clang) -------------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This defines Clang-based messages for server-client interaction, 22 | // where server is TSAR. 23 | // 24 | //===----------------------------------------------------------------------===// 25 | #ifndef TSAR_CLANG_MESSAGES_H 26 | #define TSAR_CLANG_MESSAGES_H 27 | 28 | #include "Messages.h" 29 | 30 | namespace clang { 31 | class SourceLocation; 32 | class SourceManager; 33 | } 34 | 35 | namespace llvm { 36 | class DebugLoc; 37 | } 38 | 39 | namespace tsar { 40 | /// Converts a specified location to JSON. 41 | msg::Location getLocation( 42 | const clang::SourceLocation &SLoc, const clang::SourceManager &SrcMgr); 43 | 44 | /// Convert a specified location to JSON. 45 | msg::Location getLocation( 46 | llvm::DebugLoc &Loc, const clang::SourceManager &SrcMgr); 47 | } 48 | #endif//TSAR_CLANG_MESSAGES_H 49 | -------------------------------------------------------------------------------- /tools/tsar-server/Passes.h: -------------------------------------------------------------------------------- 1 | //===------ Passes.h ---- Initialize TSAR Server Passes ---------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This contains functions to initialize passes which are necessary to use 22 | // TSAR server. 23 | // 24 | //===----------------------------------------------------------------------===// 25 | 26 | #ifndef TSAR_SERVER_PASSES_H 27 | #define TSAR_SERVER_PASSES_H 28 | 29 | namespace bcl { 30 | class IntrusiveConnection; 31 | class RedirectIO; 32 | } 33 | 34 | namespace llvm { 35 | class ModulePass; 36 | class PassRegistry; 37 | 38 | /// Create an interaction pass to obtain results of private variables analysis. 39 | ModulePass * createPrivateServerPass( 40 | bcl::IntrusiveConnection &IC, bcl::RedirectIO &StdErr); 41 | 42 | /// Initialize an interaction pass to obtain results of private variables 43 | /// analysis. 44 | void initializePrivateServerPassPass(PassRegistry &Registry); 45 | } 46 | 47 | #endif//TSAR_SERVER_PASSES_H 48 | -------------------------------------------------------------------------------- /include/tsar/Core/IRAction.h: -------------------------------------------------------------------------------- 1 | //===--- IRAction.h --------- TSAR IR Action --------------------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2022 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file implements an action to process multi-file project. It loads IR 22 | // from a file, parses corresponding sources and attach them to the 23 | // transformation context. 24 | // 25 | //===----------------------------------------------------------------------===// 26 | 27 | #ifndef TSAR_IR_ACTION_H 28 | #define TSAR_IR_ACTION_H 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | namespace clang { 35 | namespace tooling { 36 | class CompilationDatabase; 37 | } 38 | } // namespace clang 39 | 40 | namespace tsar { 41 | class QueryManager; 42 | 43 | int executeIRAction( 44 | llvm::StringRef ToolName, llvm::ArrayRef Sources, 45 | QueryManager &QM, 46 | const clang::tooling::CompilationDatabase *Compilations = nullptr); 47 | } 48 | #endif//TSAR_IR_ACTION_H 49 | -------------------------------------------------------------------------------- /lib/Analysis/AnalysisServer.cpp: -------------------------------------------------------------------------------- 1 | //===--- AnalysisServer.cpp ---- Analysis Server ----------------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2019 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file implements base representation of analysis server and a server pass 22 | // which could be used to send response. 23 | // 24 | //===----------------------------------------------------------------------===// 25 | 26 | #include "tsar/Analysis/AnalysisServer.h" 27 | 28 | using namespace llvm; 29 | 30 | template<> char AnalysisClientServerMatcherWrapper::ID = 0; 31 | INITIALIZE_PASS(AnalysisClientServerMatcherWrapper, "analysis-cs-matcher-iw", 32 | "Analysis Client Server Matcher (Wrapper)", true, true) 33 | 34 | ImmutablePass * llvm::createAnalysisClientServerMatcherWrapper( 35 | ValueToValueMapTy &OriginToClone) { 36 | initializeAnalysisClientServerMatcherWrapperPass( 37 | *PassRegistry::getPassRegistry()); 38 | auto P = new AnalysisClientServerMatcherWrapper; 39 | P->set(OriginToClone); 40 | return P; 41 | } 42 | 43 | -------------------------------------------------------------------------------- /include/tsar/Core/tsar-config.h.in: -------------------------------------------------------------------------------- 1 | //===------------- tsar_config.h - tsar configuration -------------*- C -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file enumerates variables from the TSAR configuration. 22 | // 23 | //===----------------------------------------------------------------------===// 24 | 25 | #ifndef TSAR_CONFIG_H 26 | #define TSAR_CONFIG_H 27 | 28 | #define TSAR_VERSION_MAJOR @TSAR_VERSION_MAJOR@ 29 | #define TSAR_VERSION_MINOR @TSAR_VERSION_MINOR@ 30 | #define TSAR_VERSION_PATCH @TSAR_VERSION_PATCH@ 31 | #define TSAR_VERSION_SUFFIX "@TSAR_VERSION_SUFFIX@" 32 | #define TSAR_VERSION_STRING "@TSAR_VERSION@" 33 | #define TSAR_DESCRIPTION "@TSAR_DESCRIPTION@" 34 | #define TSAR_HOMEPAGE_URL "@TSAR_HOMEPAGE_URL@" 35 | #cmakedefine APC_FOUND 36 | #cmakedefine lp_solve_FOUND 37 | #cmakedefine LLVM_DEBUG_BUILD @LLVM_DEBUG_BUILD@ 38 | #cmakedefine LLVM_RELEASE_BUILD @LLVM_RELEASE_BUILD@ 39 | #cmakedefine TSAR_ENABLE_LLVM_DUMP 40 | #cmakedefine FLANG_FOUND 41 | 42 | #endif//TSAR_CONFIG_H 43 | -------------------------------------------------------------------------------- /tools/tsar/main.cpp: -------------------------------------------------------------------------------- 1 | //===-------- main.cpp ------ Traits Static Analyzer ------------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // Traits Static Analyzer (TSAR) is a part of a system for automated 22 | // parallelization SAPFOR. This file declares interfaces to execute analysis 23 | // and to perform transformations. 24 | // 25 | //===----------------------------------------------------------------------===// 26 | 27 | #include "tsar/Core/Tool.h" 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | using namespace llvm; 34 | using namespace tsar; 35 | 36 | int main(int Argc, const char** Argv) { 37 | sys::PrintStackTraceOnErrorSignal(Argv[0]); 38 | PrettyStackTraceProgram StackTraceProgram(Argc, Argv); 39 | EnableDebugBuffering = true; 40 | llvm_shutdown_obj ShutdownObj; //call llvm_shutdown() on exit 41 | Tool Analyzer(Argc, Argv); 42 | return Analyzer.run(); 43 | } -------------------------------------------------------------------------------- /lib/Support/Diagnostic.cpp: -------------------------------------------------------------------------------- 1 | //===---- Diagnostic.h -- Low-level Diagnostic Handling ---------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2020 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file implements functions to emit different TSAR-embeded diagnostics. 22 | // 23 | //===----------------------------------------------------------------------===// 24 | 25 | 26 | #include "tsar/Support/Diagnostic.h" 27 | #include 28 | 29 | static const tsar::DiagnosticInfo Infos[] = { 30 | #define DIAG(ENUM,LEVEL,DESC) \ 31 | tsar::DiagnosticInfo{ \ 32 | tsar::DiagnosticInfo::LEVEL, \ 33 | DESC, \ 34 | std::char_traits::length(DESC) \ 35 | }, 36 | #include "tsar/Support/DiagnosticKinds.inc" 37 | #undef DIAG 38 | }; 39 | 40 | const tsar::DiagnosticInfo * 41 | tsar::getDiagnosticInfo(unsigned DiagId) { 42 | if (DiagId <= tsar::diag::PADDING_BUILTIN_TSAR_DIAGNOSTIC || 43 | DiagId >= tsar::diag::INVALID_BUILTIN_TSAR_DIAGNOSTIC) 44 | return nullptr; 45 | return &Infos[DiagId - tsar::diag::PADDING_BUILTIN_TSAR_DIAGNOSTIC - 1]; 46 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Traits Static Analyzer (TSAR) 2 | 3 | Traits Static Analyzer (TSAR) is a part of a system for automated parallelization SAPFOR. 4 | The main goal of analyzer is to determine data dependences, privatizable, reduction and induction variables and other traits of analyzed program which could be helpful to parallelize program in automated way. Both scalar variables and arrays are explored. 5 | 6 | The analyzer is based on the [LLVM] compiler infrastructure and uses the [LLVM IR] as an internal representation. This allows us implement algorithms independent from the source language of an investigated program. This approach is limited only by the necessity of having the appropriate frontend that generates appropriate LLVM IR for the source code. [Clang] is used for C/C ++ languages. 7 | 8 | All of the code in TSAR is available under the Apache License v2.0. 9 | 10 | In the TSAR source tree a certain coding standards is used. 11 | 12 | The main golden rule is following ([LLVM Coding Standards][LLVM CS]): 13 | 14 | > **If you are extending, enhancing, or bug fixing already implemented code, use the style 15 | that is already being used so that the source is uniform and easy to follow.** 16 | 17 | The standards are based on [LLVM Coding Standards][LLVM CS] and [Google C++ Style Guide][Google CS] and are partially described in [TSAR Wiki][TSAR Wiki]. 18 | 19 | [LLVM]: http://llvm.org/ "LLVM ompiler Infrastructure" 20 | [LLVM IR]: http://llvm.org/docs/LangRef.html "LLVM Intermediate Representation" 21 | [Clang]: http://clang.llvm.org/ "Clang Compiler" 22 | [LLVM CS]: http://llvm.org/docs/CodingStandards.html "LLVM Coding Standards" 23 | [Google CS]: https://google.github.io/styleguide/cppguide.html "Google C++ Style Guide" 24 | [TSAR Wiki]: https://github.com/dvm-system/tsar/wiki "TSAR Wiki" 25 | -------------------------------------------------------------------------------- /lib/Transform/IR/Passes.cpp: -------------------------------------------------------------------------------- 1 | //=== Passes.cpp Create and Initialize Transform Passes (Clang) *- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This contains functions to initialize passes which performs transformation 22 | // of LLVM IR. 23 | // 24 | //===----------------------------------------------------------------------===// 25 | 26 | #include "tsar/Transform/IR/Passes.h" 27 | 28 | using namespace llvm; 29 | 30 | void llvm::initializeIRTransform(PassRegistry &Registry) { 31 | initializeNoMetadataDSEPassPass(Registry); 32 | initializePOFunctionAttrsAnalysisPass(Registry); 33 | initializeRPOFunctionAttrsAnalysisPass(Registry); 34 | initializeLoopAttributesDeductionPassPass(Registry); 35 | initializeCallExtractorPassPass(Registry); 36 | initializeFunctionMemoryAttrsAnalysisPass(Registry); 37 | initializeDependenceInlinerPassPass(Registry); 38 | initializeDependenceInlinerAttributerPass(Registry); 39 | initializeNoCaptureAnalysisPass(Registry); 40 | initializePointerScalarizerPassPass(Registry); 41 | } 42 | -------------------------------------------------------------------------------- /lib/Support/Flang/Diagnostic.cpp: -------------------------------------------------------------------------------- 1 | //=== Diagnostic.cpp - Fortran Language Family Diagnostic Handling -* C++ *===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // Implements the Diagnostic-related interfaces. 22 | // 23 | //===----------------------------------------------------------------------===// 24 | 25 | #include "tsar/Support/Flang/Diagnostic.h" 26 | #include "tsar/Support/Diagnostic.h" 27 | 28 | using namespace Fortran; 29 | using namespace llvm; 30 | using namespace tsar; 31 | 32 | const tsar::DiagnosticInfo * tsar::getFlangMessageText(unsigned int DiagId, 33 | SmallVectorImpl &Text) { 34 | Text.clear(); 35 | auto Diag{getDiagnosticInfo(DiagId)}; 36 | if (!Diag) 37 | return nullptr; 38 | char PrevChar{'\0'}; 39 | bool InArgRef{false}; 40 | for (auto C : Diag->description()) { 41 | if (InArgRef) { 42 | if (std::isdigit(C)) 43 | continue; 44 | InArgRef = false; 45 | Text.push_back('s'); 46 | } else if (PrevChar != '\\' && C == '%') { 47 | InArgRef = true; 48 | } 49 | Text.push_back(C); 50 | PrevChar = C; 51 | } 52 | return Diag; 53 | } -------------------------------------------------------------------------------- /include/tsar/Support/Clang/PresumedLocationInfo.h: -------------------------------------------------------------------------------- 1 | //===-- PresumedLocationInfo.h - Type Traits for llvm::DenseMap -*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2022 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | // 20 | //===----------------------------------------------------------------------===// 21 | // 22 | // This file provide implementation of llvm::DenseMapInfo to compare different 23 | // representations of a presumed location with a metadata location 24 | // llvm::DILocation. 25 | // 26 | //===----------------------------------------------------------------------===// 27 | 28 | #ifndef TSAR_CLANG_PRESUMED_LOCATION_INFO_H 29 | #define TSAR_CLANG_PRESUMED_LOCATION_INFO_H 30 | 31 | #include "tsar/Support/DILocationMapInfo.h" 32 | #include 33 | 34 | namespace tsar { 35 | template <> struct PresumedLocationInfo { 36 | static unsigned getLine(const clang::PresumedLoc &Loc) { 37 | return Loc.getLine(); 38 | } 39 | static unsigned getColumn(const clang::PresumedLoc &Loc) { 40 | return Loc.getColumn(); 41 | } 42 | static llvm::StringRef getFilename(const clang::PresumedLoc &Loc) { 43 | return Loc.getFilename(); 44 | } 45 | }; 46 | } // namespace tsar 47 | 48 | #endif//TSAR_CLANG_PRESUMED_LOCATION_INFO_H 49 | -------------------------------------------------------------------------------- /include/tsar/Support/Flang/PresumedLocationInfo.h: -------------------------------------------------------------------------------- 1 | //===-- PresumedLocationInfo.h - Type Traits for llvm::DenseMap -*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2022 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | // 20 | //===----------------------------------------------------------------------===// 21 | // 22 | // This file provide implementation of llvm::DenseMapInfo to compare different 23 | // representations of a presumed location with a metadata location 24 | // llvm::DILocation. 25 | // 26 | //===----------------------------------------------------------------------===// 27 | 28 | #ifndef TSAR_FLANG_PRESUMED_LOCATION_INFO_H 29 | #define TSAR_FLANG_PRESUMED_LOCATION_INFO_H 30 | 31 | #include "tsar/Support/DILocationMapInfo.h" 32 | #include 33 | 34 | namespace tsar { 35 | template <> struct PresumedLocationInfo { 36 | static unsigned getLine(Fortran::parser::SourcePosition Loc) { 37 | return Loc.line; 38 | } 39 | static unsigned getColumn(Fortran::parser::SourcePosition Loc) { 40 | return Loc.column; 41 | } 42 | static std::string getFilename(Fortran::parser::SourcePosition Loc) { 43 | return Loc.file.path(); 44 | } 45 | }; 46 | } // namespace tsar 47 | 48 | #endif//TSAR_FLANG_PRESUMED_LOCATION_INFO_H -------------------------------------------------------------------------------- /lib/Support/PassBarrier.cpp: -------------------------------------------------------------------------------- 1 | //===--- PassBarrier.cpp -------- Pass Barrier ------------------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2020 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | //===----------------------------------------------------------------------===// 19 | // 20 | // Some function passes (for example DefinedMemoryPass) may use results of 21 | // module passes and these results becomes invalid after transformations. 22 | // A pass in this file do nothing but allow us to finish processing of 23 | // all functions before transformations. 24 | // 25 | //===----------------------------------------------------------------------===// 26 | 27 | #include "tsar/Support/PassBarrier.h" 28 | #include 29 | #include 30 | 31 | using namespace llvm; 32 | 33 | namespace { 34 | class PassBarrier : public ModulePass, private bcl::Uncopyable { 35 | public: 36 | static char ID; 37 | PassBarrier() : ModulePass(ID) { 38 | initializePassBarrierPass(*PassRegistry::getPassRegistry()); 39 | } 40 | 41 | bool runOnModule(Module &M) override { return false; } 42 | }; 43 | } 44 | 45 | char PassBarrier::ID = 0; 46 | INITIALIZE_PASS(PassBarrier, "pass-barrier", "Pass Barrier", true, true) 47 | 48 | ModulePass *llvm:: createPassBarrier() { return new PassBarrier; } 49 | -------------------------------------------------------------------------------- /include/tsar/Analysis/Flang/Passes.h: -------------------------------------------------------------------------------- 1 | //===- Passes.h - Create and Initialize Analysis Passes (Flang) -*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2022 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // It contains declarations of functions that initialize and create an instances 22 | // of TSAR passes which are necessary for source-based analysis of Fortran 23 | // programs. 24 | // Declarations of appropriate methods for an each new pass should 25 | // be added to this file. 26 | // 27 | //===----------------------------------------------------------------------===// 28 | 29 | #ifndef TSAR_FLANG_ANALYSIS_PASSES_H 30 | #define TSAR_FLANG_ANALYSIS_PASSES_H 31 | 32 | namespace llvm { 33 | class PassRegistry; 34 | class FunctionPass; 35 | class ModulePass; 36 | 37 | /// Initialize all passes to perform source-base analysis of Fortran programs. 38 | void initializeFlangAnalysis(PassRegistry &Registry); 39 | 40 | /// Initialize a pass to match high-level and low-level expressions. 41 | void initializeFlangExprMatcherPassPass(PassRegistry &Registry); 42 | 43 | /// Create a pass to match high-level and low-level expressions. 44 | FunctionPass * createFlangExprMatcherPass(); 45 | 46 | } 47 | #endif//TSAR_FLANG_ANALYSIS_PASSES_H 48 | -------------------------------------------------------------------------------- /lib/Transform/Clang/Passes.cpp: -------------------------------------------------------------------------------- 1 | //=== Passes.cpp Create and Initialize Transform Passes (Clang) *- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This contains functions to initialize passes which are necessary for 22 | // source-to-source transformation of C programs. 23 | // 24 | //===----------------------------------------------------------------------===// 25 | 26 | #include "tsar/Transform/Clang/Passes.h" 27 | 28 | using namespace llvm; 29 | 30 | void llvm::initializeClangTransform(PassRegistry &Registry) { 31 | initializeClangExprPropagationPass(Registry); 32 | initializeClangInlinerPassPass(Registry); 33 | initializeClangRenameLocalPassPass(Registry); 34 | initializeClangStructureReplacementPassPass(Registry); 35 | initializeClangDeadDeclsEliminationPass(Registry); 36 | initializeClangOpenMPParallelizationPass(Registry); 37 | initializeClangDVMHWriterPass(Registry); 38 | initializeClangDVMHSMParallelizationPass(Registry); 39 | initializeDVMHDataTransferIPOPassPass(Registry); 40 | initializeClangLoopInterchangePass(Registry); 41 | initializeClangLoopReversePass(Registry); 42 | initializeClangUnreachableCodeEliminationPassPass(Registry); 43 | } 44 | -------------------------------------------------------------------------------- /include/tsar/Frontend/Clang/Passes.h: -------------------------------------------------------------------------------- 1 | //===- Passes.h - Create and Initialize Parse Passes (Clang) ----*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // It contains declarations of functions that initialize and create an instances 22 | // of TSAR passes which are necessary to parse C programs. 23 | // Declarations of appropriate methods for an each new pass should 24 | // be added to this file. 25 | // 26 | //===----------------------------------------------------------------------===// 27 | 28 | #ifndef TSAR_PARSE_CLANG_PASSES_H 29 | #define TSAR_PARSE_CLANG_PASSES_H 30 | 31 | namespace tsar { 32 | struct ASTImportInfo; 33 | } 34 | 35 | namespace llvm { 36 | class PassRegistry; 37 | class ImmutablePass; 38 | 39 | /// Initialize all passes to parse C programs. 40 | void initializeClangParse(PassRegistry &Registry); 41 | 42 | /// Initialize a pass to obtain access to the import process information. 43 | void initializeImmutableASTImportInfoPassPass(PassRegistry &Registry); 44 | 45 | /// Create a pass to obtain access to the import process information. 46 | ImmutablePass * createImmutableASTImportInfoPass( 47 | const tsar::ASTImportInfo &Info); 48 | } 49 | #endif//TSAR_PARSE_CLANG_PASSES_H 50 | -------------------------------------------------------------------------------- /include/tsar/Transform/Clang/DeadDeclsElimination.h: -------------------------------------------------------------------------------- 1 | //=== DeadDeclsElimination.h - Dead Decls Elimination (Clang) ----*- C++ -*===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===---------------------------------------------------------------------===// 20 | // 21 | // This file defines a pass to eliminate dead declarations in a source code. 22 | // Dead declaration is a declaration which is never used. Note, that only 23 | // local declarations can be safely removed. 24 | // 25 | //===---------------------------------------------------------------------===// 26 | 27 | #ifndef TSAR_CLANG_DE_DECLS_H 28 | #define TSAR_CLANG_DE_DECLS_H 29 | 30 | #include "tsar/Transform/Clang/Passes.h" 31 | #include 32 | #include 33 | 34 | namespace llvm { 35 | /// This per-function pass perform source-level elimination of 36 | /// local dead declarations. 37 | class ClangDeadDeclsElimination : public FunctionPass, private bcl::Uncopyable { 38 | public: 39 | static char ID; 40 | 41 | ClangDeadDeclsElimination() : FunctionPass(ID) { 42 | initializeClangDeadDeclsEliminationPass(*PassRegistry::getPassRegistry()); 43 | } 44 | 45 | bool runOnFunction(Function &F) override; 46 | void getAnalysisUsage(AnalysisUsage &AU) const override; 47 | }; 48 | } 49 | #endif//TSAR_CLANG_DE_DECLS_H 50 | -------------------------------------------------------------------------------- /include/tsar/Analysis/Parallel/Passes.h: -------------------------------------------------------------------------------- 1 | //===- Passes.h - Create and Initialize Parallelization Passes --*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2019 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // It contains declarations of functions that initialize and create an instances 22 | // of TSAR analysis passes which determine opportunities of program 23 | // parallelization. Declarations of appropriate methods for an each new pass 24 | // should be added to this file. 25 | // 26 | //===----------------------------------------------------------------------===// 27 | 28 | #ifndef TSAR_PARALLEL_ANALYSIS_PASSES_H 29 | #define TSAR_PARALLEL_ANALYSIS_PASSES_H 30 | 31 | namespace llvm { 32 | class PassRegistry; 33 | class FunctionPass; 34 | 35 | /// Initialize analysis passes which determine opportunities of program 36 | /// parallelization. 37 | void initializeParallelizationAnalysis(PassRegistry &Registry); 38 | 39 | /// Initialize a pass to determine loops which could be executed 40 | /// in a parallel way. 41 | void initializeParallelLoopPassPass(PassRegistry &Registry); 42 | 43 | /// Initialize a pass to determine loops which could be executed 44 | /// in a parallel way. 45 | FunctionPass *createParallelLoopPass(); 46 | } 47 | #endif//TSAR_PARALLEL_ANALYSIS_PASSES_H 48 | -------------------------------------------------------------------------------- /include/tsar/Analysis/Memory/ServerUtils.h: -------------------------------------------------------------------------------- 1 | //===--- ServerUtils.h ------ Analysis Server Utils -------------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2019 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | //===----------------------------------------------------------------------===// 19 | // 20 | // This file defines functions to simplify client to server data mapping. 21 | // 22 | //===----------------------------------------------------------------------===// 23 | 24 | #ifndef TSAR_ANALYSIS_MEMORY_SERVER_H 25 | #define TSAR_ANALYSIS_MEMORY_SERVER_H 26 | 27 | #include 28 | 29 | namespace llvm { 30 | class Module; 31 | class AnalysisUsage; 32 | class Pass; 33 | namespace legacy { 34 | class PassManager; 35 | } 36 | } 37 | 38 | namespace tsar { 39 | /// Enable mapping of metadata-level memory locations attached to a 40 | /// metadata-level alias tree. 41 | struct ClientToServerMemory { 42 | static void prepareToClone(llvm::Module &ClientM, 43 | llvm::ValueToValueMapTy &ClientToServer); 44 | 45 | static void initializeServer(llvm::Pass &P, llvm::Module &ClientM, 46 | llvm::Module &ServerM, llvm::ValueToValueMapTy &ClientToServer, 47 | llvm::legacy::PassManager &PM); 48 | 49 | static void prepareToClose(llvm::legacy::PassManager &PM); 50 | 51 | static void getAnalysisUsage(llvm::AnalysisUsage &AU); 52 | }; 53 | } 54 | #endif//TSAR_ANALYSIS_MEMORY_SERVER_H 55 | -------------------------------------------------------------------------------- /include/tsar/Transform/AST/Passes.h: -------------------------------------------------------------------------------- 1 | //===--- Passes.h- Create and Initialize Transform Passes (AST) -*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2020 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // It contains declarations of functions that initialize and create an instances 22 | // of TSAR passes which is necessary for source-to-source transformation of C 23 | // programs. Declarations of appropriate methods for an each new pass should 24 | // be added to this file. These passes combine frontend-dependent passes and 25 | // provide a general frontend-independent interface to manage program 26 | // transformation. 27 | // 28 | //===----------------------------------------------------------------------===// 29 | 30 | #ifndef TSAR_AST_TRANSFORM_PASSES_H 31 | #define TSAR_AST_TRANSFORM_PASSES_H 32 | 33 | namespace llvm { 34 | class PassRegistry; 35 | class FunctionPass; 36 | class ModulePass; 37 | 38 | /// Initialize all source-to-source transformation passes. 39 | void initializeASTTransform(PassRegistry &Registry); 40 | 41 | /// Initialize a pass to reformat sources after transformationg. 42 | void initializeASTFormatPassPass(PassRegistry& Registry); 43 | 44 | /// Create a pass to reformat sources after transformation using. 45 | llvm::ModulePass *createASTFormatPass(); 46 | } 47 | #endif//TSAR_AST_TRANSFORM_PASSES_H 48 | -------------------------------------------------------------------------------- /include/tsar/Support/Clang/Diagnostic.h: -------------------------------------------------------------------------------- 1 | //===--- Diagnostic.h - C Language Family Diagnostic Handling ---*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // Defines the Diagnostic-related interfaces. 22 | // 23 | //===----------------------------------------------------------------------===// 24 | 25 | #ifndef TSAR_CLANG_DIAGNOSTIC_H 26 | #define TSAR_CLANG_DIAGNOSTIC_H 27 | 28 | #include "tsar/Support/Diagnostic.h" 29 | #include 30 | #include 31 | 32 | namespace tsar { 33 | /// \brief Issue the message to the client. 34 | /// 35 | /// This actually returns an instance of DiagnosticBuilder which emits the 36 | /// diagnostics when it is destroyed. 37 | /// 38 | /// Built-in (TSAR and Clang) and custom diagnostics may be used 39 | clang::DiagnosticBuilder toDiag(clang::DiagnosticsEngine &Diags, 40 | clang::SourceLocation Loc, unsigned int DiagId); 41 | 42 | /// \brief Issue the message to the client. 43 | /// 44 | /// This actually returns an instance of DiagnosticBuilder which emits the 45 | /// diagnostics when it is destroyed. 46 | /// 47 | /// Built-in (TSAR and Clang) and custom diagnostics may be used 48 | clang::DiagnosticBuilder toDiag(clang::DiagnosticsEngine &Diags, 49 | unsigned int DiagId); 50 | } 51 | #endif//TSAR_CLANG_DIAGNOSTIC_H 52 | -------------------------------------------------------------------------------- /include/tsar/Transform/Clang/RenameLocal.h: -------------------------------------------------------------------------------- 1 | //===- RenameLocal.h - Source-level Renaming of Local Objects -- *- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file declares a pass to perform renaming of objects into a specified 22 | // scope. The goal of this transformation is to ensure that there is no 23 | // different objects with the same name at a specified scope. The transformation 24 | // also guaranties that names of objects declared in a specified scope do not 25 | // match any name from other scopes. 26 | // 27 | //===----------------------------------------------------------------------===// 28 | 29 | #ifndef TSAR_CLANG_RENAME_LOCAL_H 30 | #define TSAR_CLANG_RENAME_LOCAL_H 31 | 32 | #include "tsar/Transform/Clang/Passes.h" 33 | #include 34 | #include 35 | 36 | namespace llvm { 37 | /// This pass performs renaming of objects into a specified scope. 38 | class ClangRenameLocalPass : public ModulePass, private bcl::Uncopyable { 39 | public: 40 | static char ID; 41 | 42 | ClangRenameLocalPass() : ModulePass(ID) { 43 | initializeClangRenameLocalPassPass(*PassRegistry::getPassRegistry()); 44 | } 45 | 46 | bool runOnModule(Module &M) override; 47 | void getAnalysisUsage(AnalysisUsage &AU) const override; 48 | }; 49 | } 50 | #endif//TSAR_CLANG_RENAME_LOCAL_H 51 | -------------------------------------------------------------------------------- /lib/Analysis/Memory/TraitFilter.cpp: -------------------------------------------------------------------------------- 1 | //===--- TraitFilter.cpp ----- Filters Of Traits ----------------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file defines some filters which marks memory location if some 22 | // traits are set. 23 | // 24 | //===----------------------------------------------------------------------===// 25 | 26 | #include "tsar/Analysis/Memory/DIMemoryTrait.h" 27 | #include "tsar/Analysis/Memory/EstimateMemory.h" 28 | #include "tsar/Analysis/Memory/TraitFilter.h" 29 | #include 30 | 31 | using namespace llvm; 32 | 33 | namespace tsar { 34 | void markIfNotPromoted(const DataLayout &DL, DIMemoryTrait &T) { 35 | auto DIEM = dyn_cast(T.getMemory()); 36 | if (!DIEM) 37 | return; 38 | auto DIVar = DIEM->getVariable(); 39 | for (auto VH : *DIEM) { 40 | if (!VH || isa(VH)) 41 | continue; 42 | auto *AI = dyn_cast(stripPointer(DL, VH)); 43 | if (!AI || AI->isArrayAllocation() || 44 | AI->getAllocatedType()->isArrayTy()) 45 | continue; 46 | bool DbgDeclareFound = false; 47 | for (auto *U : FindDbgAddrUses(AI)) { 48 | if (isa(U) || U->getVariable() == DIVar) { 49 | T.set(); 50 | return; 51 | } 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /lib/Analysis/Clang/Passes.cpp: -------------------------------------------------------------------------------- 1 | //=== Passes.cpp - Create and Initialize Analysis Passes (Clang) *- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This contains functions to initialize passes which are necessary for 22 | // source-base analysis of C programs. 23 | // 24 | //===----------------------------------------------------------------------===// 25 | 26 | #include "tsar/Analysis/Clang/Passes.h" 27 | 28 | using namespace llvm; 29 | 30 | void llvm::initializeClangAnalysis(PassRegistry &Registry) { 31 | initializeClangGlobalInfoPassPass(Registry); 32 | initializeClangDIMemoryMatcherPassPass(Registry); 33 | initializeClangDIGlobalMemoryMatcherPassPass(Registry); 34 | initializeClangExprMatcherPassPass(Registry); 35 | initializeLoopMatcherPassPass(Registry); 36 | initializeClangPerfectLoopPassPass(Registry); 37 | initializeCanonicalLoopPassPass(Registry); 38 | initializeClangCFTraitsPassPass(Registry); 39 | initializeClangRegionCollectorPass(Registry); 40 | initializeClangIncludeTreePassPass(Registry); 41 | initializeClangIncludeTreePrinterPass(Registry); 42 | initializeClangIncludeTreeOnlyPrinterPass(Registry); 43 | initializeClangIncludeTreeViewerPass(Registry); 44 | initializeClangIncludeTreeOnlyViewerPass(Registry); 45 | // Initialize checkers. 46 | initializeClangNoMacroAssertPass(Registry); 47 | } 48 | -------------------------------------------------------------------------------- /include/tsar/Unparse/VariableLocation.h: -------------------------------------------------------------------------------- 1 | //===- VariableLocation.h -- Position of a variable in a code ------ C++ -*===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2022 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file implements functions to get variable location in a source code from 22 | // a metadata-level memory representation. 23 | // 24 | //===----------------------------------------------------------------------===// 25 | 26 | #ifndef TSAR_UNPARSE_VARIABLE_LOCATION_H 27 | #define TSAR_UNPARSE_VARIABLE_LOCATION_H 28 | 29 | #include "tsar/Support/Tags.h" 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | namespace tsar { 36 | class DIEstimateMemory; 37 | 38 | /// Position of a variable in a source code. 39 | using VariableLocationT = bcl::tagged_tuple< 40 | bcl::tagged, bcl::tagged, 41 | bcl::tagged, bcl::tagged>; 42 | 43 | llvm::Optional 44 | buildVariable(unsigned DWLang, const DIEstimateMemory &DIEM, 45 | llvm::SmallVectorImpl &Path); 46 | 47 | llvm::Optional buildVariable(unsigned DWLang, 48 | const DIEstimateMemory &DIEM); 49 | } // namespace tsar 50 | #endif//TSAR_UNPARSE_VARIABLE_LOCATION_H 51 | -------------------------------------------------------------------------------- /lib/Support/Clang/Diagnostic.cpp: -------------------------------------------------------------------------------- 1 | //===--- Diagnostic.h - C Language Family Diagnostic Handling ---*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // Implements the Diagnostic-related interfaces. 22 | // 23 | //===----------------------------------------------------------------------===// 24 | 25 | #include "tsar/Support/Clang/Diagnostic.h" 26 | 27 | namespace tsar { 28 | clang::DiagnosticBuilder toDiag(clang::DiagnosticsEngine &Diags, 29 | clang::SourceLocation Loc, unsigned int DiagId) { 30 | switch (DiagId) { 31 | default: return Diags.Report(Loc, DiagId); 32 | #define DIAG(ENUM,LEVEL,DESC) \ 33 | case tsar::diag::ENUM: \ 34 | { \ 35 | unsigned CustomId = Diags.getCustomDiagID( \ 36 | clang::DiagnosticsEngine::LEVEL, DESC); \ 37 | return Diags.Report(Loc, CustomId); \ 38 | } 39 | #include "tsar/Support/DiagnosticKinds.inc" 40 | #undef DIAG 41 | } 42 | } 43 | 44 | clang::DiagnosticBuilder toDiag(clang::DiagnosticsEngine &Diags, 45 | unsigned int DiagId) { 46 | switch (DiagId) { 47 | default: return Diags.Report(DiagId); 48 | #define DIAG(ENUM,LEVEL,DESC) \ 49 | case tsar::diag::ENUM: \ 50 | { \ 51 | unsigned CustomId = Diags.getCustomDiagID( \ 52 | clang::DiagnosticsEngine::LEVEL, DESC); \ 53 | return Diags.Report(CustomId); \ 54 | } 55 | #include "tsar/Support/DiagnosticKinds.inc" 56 | #undef DIAG 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /lib/APC/DistributionUtils.h: -------------------------------------------------------------------------------- 1 | //===- DistributionUtils.h - Utils to Process Distribution Rules *- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file contains useful functions to explore distribution rules. 22 | // 23 | //===----------------------------------------------------------------------===// 24 | 25 | #ifndef TSAR_DISTRIBUTION_UTILS_H 26 | #define TSAR_DISTRIBUTION_UTILS_H 27 | 28 | #include "tsar/APC/APCContext.h" 29 | #include 30 | 31 | namespace tsar { 32 | /// Convert alignment rule to rules for each dimension of a template. 33 | /// 34 | /// Initially, there is list of alignment rules which attached to a dimension of 35 | /// an array. 36 | /// \return Array of size equal to number of template dimensions. For each 37 | /// dimension index of corresponding alignment rule in 38 | /// apc::AlignRule::alinRuleWith will be set. 39 | /// If template dimension should not be aligned it will be set to a number of 40 | /// template dimensions. 41 | llvm::SmallVector extractTplDimsAlignmentIndexes( 42 | const apc::AlignRule &AR); 43 | 44 | /// Convert a specified message to a string representation. 45 | void messageToString(const apc::Messages &Msg, 46 | llvm::SmallVectorImpl &Out); 47 | 48 | /// Print a specified message to a string representation. 49 | void messagePrint(const llvm::Twine &File, const apc::Messages &Msg, 50 | llvm::raw_ostream &OS); 51 | } 52 | #endif//TSAR_DISTRIBUTION_UTILS_H 53 | -------------------------------------------------------------------------------- /include/tsar/Analysis/PrintUtils.h: -------------------------------------------------------------------------------- 1 | //===- PrintUtils.h --------- Output Functions ------------------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file defines a set of output functions for various bits of information. 22 | // 23 | //===----------------------------------------------------------------------===// 24 | 25 | #ifndef TSAR_SUPPORT_PRINT_H 26 | #define TSAR_SUPPORT_PRINT_H 27 | 28 | #include 29 | #include 30 | 31 | namespace llvm { 32 | class raw_ostreap; 33 | class LoopInfo; 34 | } 35 | 36 | namespace tsar { 37 | /// \brief Print loop tree which is calculated by the LoopInfo pass. 38 | /// 39 | /// \param [in] LI Information about natural loops identified 40 | /// by the LoopInfor pass. 41 | /// param [in] FilenameOnly If it is true only name of a file will be printed. 42 | void printLoops(llvm::raw_ostream &OS, const llvm::LoopInfo &LI, 43 | bool FilenameOnly = false); 44 | 45 | /// Return name of a file or full path to a file for a specified location. 46 | /// If `FilenameOnly` is true only name of a file will be returned. 47 | llvm::StringRef getFile(llvm::DebugLoc Loc, bool FilenameOnly = false); 48 | 49 | /// This is similar to default DebugLoc::print() method, however, an output 50 | /// depends on `FilenameOnly` parameter. 51 | /// If `FilenameOnly` is true only name of a file will be printed. 52 | void print(llvm::raw_ostream &OS, llvm::DebugLoc Loc, bool FilenameOnly = false); 53 | } 54 | #endif//TSAR_SUPPORT_PRINT_H 55 | -------------------------------------------------------------------------------- /lib/APC/LoopGraphTraits.h: -------------------------------------------------------------------------------- 1 | //===- LoopGraphTraits.h ----- APC Loop Graph Traits ------------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file contains specialization of llvm::GraphTraits to traverse LoopGraph. 22 | // 23 | //===----------------------------------------------------------------------===// 24 | #ifndef TSAR_APC_LOOP_GRAPH_TRAITS_H 25 | #define TSAR_APC_LOOP_GRAPH_TRAITS_H 26 | 27 | #include 28 | #include 29 | 30 | namespace llvm { 31 | template<> struct GraphTraits<::LoopGraph *> { 32 | using NodeRef = ::LoopGraph *; 33 | static NodeRef getEntryNode(NodeRef L) noexcept { return L; } 34 | using ChildIteratorType = 35 | decltype(std::declval<::LoopGraph>().children)::iterator; 36 | static ChildIteratorType child_begin(NodeRef L) { 37 | return L->children.begin(); 38 | } 39 | static ChildIteratorType child_end(NodeRef L) { 40 | return L->children.end(); 41 | } 42 | }; 43 | 44 | template<> struct GraphTraits { 45 | using NodeRef = const ::LoopGraph *; 46 | static NodeRef getEntryNode(NodeRef L) noexcept { return L; } 47 | using ChildIteratorType = 48 | decltype(std::declval<::LoopGraph>().children)::const_iterator; 49 | static ChildIteratorType child_begin(NodeRef L) { 50 | return L->children.begin(); 51 | } 52 | static ChildIteratorType child_end(NodeRef L) { 53 | return L->children.end(); 54 | } 55 | }; 56 | } 57 | #endif//TSAR_APC_LOOP_GRAPH_TRAITS_H 58 | -------------------------------------------------------------------------------- /include/tsar/Support/EmptyPass.h: -------------------------------------------------------------------------------- 1 | //===---- EmptyPass.h -------- Trivial Empty Pass ----------------*- C++ -*===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2020 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file implements a trivial empty pass which does nothing. It can be use 22 | // as a stub if configuration of the build does not provide some passes. 23 | // 24 | //===----------------------------------------------------------------------===// 25 | 26 | #ifndef TSAR_EMPTY_PASS_H 27 | #define TSAR_EMPTY_PASS_H 28 | 29 | #include 30 | #include 31 | 32 | namespace llvm { 33 | void initializeEmptyFunctionPassPass(PassRegistry &); 34 | 35 | class EmptyFunctionPass : public FunctionPass, private bcl::Uncopyable { 36 | public: 37 | static char ID; 38 | EmptyFunctionPass() : FunctionPass(ID) { 39 | initializeEmptyFunctionPassPass(*PassRegistry::getPassRegistry()); 40 | } 41 | bool runOnFunction(Function &F) override { return false; } 42 | }; 43 | 44 | inline FunctionPass *createEmptyFunctionPass() { return new EmptyFunctionPass; } 45 | 46 | void initializeEmptyModulePassPass(PassRegistry &); 47 | 48 | class EmptyModulePass : public ModulePass, private bcl::Uncopyable { 49 | public: 50 | static char ID; 51 | EmptyModulePass() : ModulePass(ID) { 52 | initializeEmptyModulePassPass(*PassRegistry::getPassRegistry()); 53 | } 54 | bool runOnModule(Module &) override { return false; } 55 | }; 56 | 57 | inline ModulePass *createEmptyModulePass() { return new EmptyModulePass; } 58 | } 59 | #endif//TSAR_EMPTY_PASS_H 60 | 61 | -------------------------------------------------------------------------------- /lib/Analysis/Memory/Passes.cpp: -------------------------------------------------------------------------------- 1 | //=== Passes.cpp - Create and Initialize Memory Analysis Passes -*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This contains functions to initialize passes which are necessary for 22 | // analysis of memory accesses. 23 | // 24 | //===----------------------------------------------------------------------===// 25 | 26 | #include "tsar/Analysis/Memory/Passes.h" 27 | 28 | using namespace llvm; 29 | 30 | void llvm::initializeMemoryAnalysis(PassRegistry &Registry) { 31 | initializeDefinedMemoryPassPass(Registry); 32 | initializeLiveMemoryPassPass(Registry); 33 | initializeEstimateMemoryPassPass(Registry); 34 | initializeDIEstimateMemoryPassPass(Registry); 35 | initializeAliasTreeViewerPass(Registry); 36 | initializeAliasTreeOnlyViewerPass(Registry); 37 | initializeDIAliasTreeViewerPass(Registry); 38 | initializeAliasTreePrinterPass(Registry); 39 | initializeAliasTreeOnlyPrinterPass(Registry); 40 | initializeDIAliasTreePrinterPass(Registry); 41 | initializePrivateRecognitionPassPass(Registry); 42 | initializeDIDependencyAnalysisPassPass(Registry); 43 | initializeProcessDIMemoryTraitPassPass(Registry); 44 | initializeNotInitializedMemoryAnalysisPass(Registry); 45 | initializeDelinearizationPassPass(Registry); 46 | initializeGlobalDefinedMemoryPass(Registry); 47 | initializeGlobalLiveMemoryPass(Registry); 48 | initializeDIArrayAccessWrapperPass(Registry); 49 | initializeAllocasAAWrapperPassPass(Registry); 50 | initializeGlobalsAccessWrapperPass(Registry); 51 | } 52 | -------------------------------------------------------------------------------- /include/tsar/Analysis/Memory/DelinearizeJSON.h: -------------------------------------------------------------------------------- 1 | //===-- DelinearizeJSON.h -------- TSAR Attributes --------------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file describes delinearized array accesses in JSON format. 22 | // 23 | //===----------------------------------------------------------------------===// 24 | 25 | #ifndef TSAR_DELINEARIZE_JSON_H 26 | #define TSAR_DELINEARIZE_JSON_H 27 | 28 | #include 29 | 30 | namespace llvm { 31 | class ScalarEvolution; 32 | } 33 | 34 | namespace tsar { 35 | class DelinearizeInfo; 36 | 37 | /// Description of delinearized array accesses. 38 | JSON_OBJECT_BEGIN(RawDelinearizeInfo) 39 | JSON_OBJECT_ROOT_PAIR_3(RawDelinearizeInfo, 40 | Accesses, std::map>>)>, 42 | Sizes, std::map)>, 43 | IsDelinearized, int) 44 | 45 | RawDelinearizeInfo() : JSON_INIT_ROOT{} 46 | 47 | RawDelinearizeInfo(const RawDelinearizeInfo &) = default; 48 | RawDelinearizeInfo & operator=(const RawDelinearizeInfo &) = default; 49 | RawDelinearizeInfo(RawDelinearizeInfo &&) = default; 50 | RawDelinearizeInfo & operator=(RawDelinearizeInfo &&) = default; 51 | JSON_OBJECT_END(RawDelinearizeInfo) 52 | 53 | /// Builds JSON representation for delinearized array accesses. 54 | RawDelinearizeInfo toJSON(const DelinearizeInfo &Info, 55 | llvm::ScalarEvolution &SE, bool IsSafeTypeCast = true); 56 | } 57 | JSON_DEFAULT_TRAITS(tsar::, RawDelinearizeInfo) 58 | #endif//TSAR_DELINEARIZE_JSON_H 59 | -------------------------------------------------------------------------------- /include/tsar/Transform/Flang/Passes.h: -------------------------------------------------------------------------------- 1 | //===- Passes.h- Create and Initialize Transform Passes (Flang) -*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2021 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // It contains declarations of functions that initialize and create an instances 22 | // of TSAR passes which is necessary for source-to-source transformation of 23 | // Fortran programs. Declarations of appropriate methods for an each new pass 24 | // should be added to this file. 25 | // 26 | //===----------------------------------------------------------------------===// 27 | 28 | #ifndef TSAR_FLANG_TRANSFORM_PASSES_H 29 | #define TSAR_FLANG_TRANSFORM_PASSES_H 30 | 31 | namespace llvm { 32 | class PassRegistry; 33 | class FunctionPass; 34 | class ModulePass; 35 | 36 | /// Initialize all source-to-source transformation passes. 37 | void initializeFlangTransform(PassRegistry &Registry); 38 | 39 | /// Initialize a pass to replace constants with variables with values equal 40 | /// to the replaced constants. 41 | void initializeFlangConstantReplacementPassPass(PassRegistry &Registry); 42 | 43 | /// Create a pass to replace constants with variables with values equal 44 | /// to the replaced constants. 45 | FunctionPass *createFlangConstantReplacementPass(); 46 | 47 | /// Initialize a pass to register all varaiables in a program unit. 48 | void initializeFlangVariableRegistrationPassPass(PassRegistry &Registry); 49 | 50 | /// Create a pass to register all varaiables in a program unit. 51 | FunctionPass *createFlangVariableRegistrationPass(); 52 | } // namespace llvm 53 | 54 | #endif//TSAR_FLANG_TRANSFORM_PASSES_H 55 | -------------------------------------------------------------------------------- /lib/Support/RewriterBase.cpp: -------------------------------------------------------------------------------- 1 | //===- RewriterBase.cpp---------TSAR Rewriter Base --------------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2020 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file provides classes to implements rewriters in the same way as 22 | // clang::Rewriter is implemented. 23 | // 24 | //===----------------------------------------------------------------------===// 25 | 26 | #include "tsar/Support/RewriterBase.h" 27 | 28 | void tsar::RewriterBaseImpl::ReplaceText( 29 | std::size_t OrigBegin, std::size_t Length, llvm::StringRef NewStr) { 30 | std::size_t OrigBeginIdx = 2 * OrigBegin; 31 | std::size_t OrigEndIdx = 2 * (OrigBegin + Length - 1) + 1; 32 | auto Begin = mMapping[OrigBeginIdx]; 33 | auto End = mMapping[OrigEndIdx] + 1; 34 | auto NewStrSize = NewStr.size(); 35 | if (End - Begin < NewStrSize) { 36 | for (std::size_t I = OrigEndIdx, EI = mMapping.size(); I < EI; ++I) 37 | mMapping[I] += NewStrSize - (End - Begin); 38 | } else if (End - Begin > NewStrSize) { 39 | for (std::size_t I = OrigEndIdx, EI = mMapping.size(); I < EI; ++I) 40 | mMapping[I] -= (End - Begin) - NewStrSize; 41 | } 42 | mBuffer.replace(Begin, End - Begin, std::string(NewStr)); 43 | } 44 | 45 | void tsar::RewriterBaseImpl::InsertText( 46 | std::size_t OrigBegin, llvm::StringRef NewStr, bool InsertAfter) { 47 | std::size_t OrigIdx = InsertAfter ? 2 * OrigBegin + 1 : 2 * OrigBegin; 48 | mBuffer.insert(mMapping[OrigIdx], NewStr.str()); 49 | auto NewStrSize = NewStr.size(); 50 | for (std::size_t I = OrigIdx, EI = mMapping.size(); I < EI; ++I) 51 | mMapping[I] += NewStrSize; 52 | } 53 | 54 | -------------------------------------------------------------------------------- /tools/tsar-server/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(TSAR_SHARED_SOURCES Server.cpp PrivateServerPass.cpp ClangMessages.cpp) 2 | 3 | if(MSVC_IDE) 4 | file(GLOB TSAR_SHARED_INTERNAL_HEADERS 5 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) 6 | source_group(bcl FILES ${BCL_CORE_HEADERS}) 7 | if (APC_FOUND) 8 | source_group(apc FILES ${APC_CORE_HEADERS}) 9 | endif() 10 | if(lp_solve_FOUND) 11 | source_group(lp_solve FILES ${lp_solve_HEADERS}) 12 | endif() 13 | endif() 14 | 15 | set_property(TARGET TSARTool TSARSupport TSARAnalysis TSARAnalysisReader 16 | TSARAnalysisMemory TSARAnalysisParallel TSARTransformIR TSARTransformMixed 17 | TSARTransformClang TSARAnalysisClang TSARFrontendClang TSARSupportClang 18 | TSARUnparse TSARTransformAST PROPERTY POSITION_INDEPENDENT_CODE ON) 19 | 20 | if (BUILD_APC) 21 | set_property(TARGET APC APCCore APCDirectiveProcessing APCDistribution 22 | APCGraphLoopsBase APCGraphCall APCUtils 23 | PROPERTY POSITION_INDEPENDENT_CODE ON) 24 | endif() 25 | 26 | if (FLANG_FOUND) 27 | set_property(TARGET TSARFrontendFlang TSARSupportFlang TSARTransformFlang 28 | TSARAnalysisFlang PROPERTY POSITION_INDEPENDENT_CODE ON) 29 | endif() 30 | 31 | add_library(TSARServer SHARED 32 | ${TSAR_SHARED_SOURCES} ${TSAR_SHARED_INTERNAL_HEADERS}) 33 | 34 | add_dependencies(TSARServer TSARTool) 35 | if(NOT PACKAGE_LLVM) 36 | add_dependencies(TSARServer ${CLANG_LIBS} ${FLANG_LIBS} ${LLVM_LIBS}) 37 | endif() 38 | target_link_libraries(TSARServer TSARTool ${CLANG_LIBS} ${FLANG_LIBS} ${LLVM_LIBS} BCL::Core) 39 | 40 | set_target_properties(TSARServer PROPERTIES 41 | COMPILE_DEFINITIONS BCL_EXPORTING 42 | FOLDER "${TSAR_SERVER_FOLDER}") 43 | 44 | install(TARGETS TSARServer 45 | LIBRARY DESTINATION lib 46 | RUNTIME DESTINATION bin 47 | ARCHIVE DESTINATION lib) 48 | 49 | add_executable(tsar-server main.cpp) 50 | 51 | add_dependencies(tsar-server TSARServer) 52 | if(NOT PACKAGE_LLVM) 53 | add_dependencies(tsar-server ${LLVM_LIBS}) 54 | endif() 55 | target_link_libraries(tsar-server TSARServer ${LLVM_LIBS} BCL::CSocket TSARServer) 56 | set_target_properties(tsar-server PROPERTIES 57 | COMPILE_DEFINITIONS BCL_EXPORTING 58 | FOLDER "${TSAR_SERVER_FOLDER}") 59 | 60 | # Specify RPATH to look up for necessary shared libraries after installation. 61 | set_target_properties(tsar-server PROPERTIES 62 | INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") 63 | 64 | install(TARGETS tsar-server EXPORT TSARExports RUNTIME DESTINATION bin) 65 | -------------------------------------------------------------------------------- /include/tsar/Support/Clang/NamedDeclMapInfo.h: -------------------------------------------------------------------------------- 1 | //===- NamedDeclMapInfo.h - Name Base Map Info For NamedDecl's --*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file provides implementation of llvm::DenseMapInfo for clang::NamedDecl. 22 | // Name of declaration is used to construct keys, so it is possible to use 23 | // find_as("...") methods to find declaration in a container. 24 | // 25 | //===----------------------------------------------------------------------===// 26 | 27 | #ifndef TSAR_NAMED_DECL_MAP_INFO_H 28 | #define TSAR_NAMED_DECL_MAP_INFO_H 29 | 30 | #include 31 | #include 32 | 33 | namespace tsar { 34 | struct NamedDeclMapInfo { 35 | static inline clang::NamedDecl * getEmptyKey() { 36 | return llvm::DenseMapInfo::getEmptyKey(); 37 | } 38 | static inline clang::NamedDecl * getTombstoneKey() { 39 | return llvm::DenseMapInfo::getTombstoneKey(); 40 | } 41 | static inline unsigned getHashValue(const clang::NamedDecl *ND) { 42 | return llvm::DenseMapInfo::getHashValue(ND->getName()); 43 | } 44 | static inline unsigned getHashValue(llvm::StringRef Name) { 45 | return llvm::DenseMapInfo::getHashValue(Name); 46 | } 47 | static inline bool isEqual(const clang::NamedDecl *LHS, 48 | const clang::NamedDecl *RHS) noexcept { 49 | return LHS == RHS; 50 | } 51 | static inline bool isEqual(llvm::StringRef LHS, 52 | const clang::NamedDecl *RHS) { 53 | return RHS != getEmptyKey() && RHS != getTombstoneKey() && 54 | RHS->getName() == LHS; 55 | } 56 | }; 57 | } 58 | #endif//TSAR_NAMED_DECL_MAP_INFO_H 59 | -------------------------------------------------------------------------------- /include/tsar/Analysis/Clang/MemoryMatcher.h: -------------------------------------------------------------------------------- 1 | //===- MemoryMatcher.h - High and Low Level Memory Matcher ------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // Classes and functions from this file match variables in a source high-level 22 | // code and appropriate allocas or globals in low-level LLVM IR. This file 23 | // implements classes to access results of such analysis. 24 | // 25 | //===----------------------------------------------------------------------===// 26 | 27 | #ifndef TSAR_MEMORY_MATCHER_H 28 | #define TSAR_MEMORY_MATCHER_H 29 | 30 | #include "tsar/ADT/Bimap.h" 31 | #include "tsar/ADT/ListBimap.h" 32 | #include "tsar/Support/AnalysisWrapperPass.h" 33 | #include "tsar/Support/Tags.h" 34 | #include 35 | #include 36 | 37 | namespace clang { 38 | class FuncDecl; 39 | class VarDecl; 40 | } 41 | 42 | namespace llvm { 43 | class Value; 44 | } 45 | 46 | namespace tsar { 47 | /// This provides access to results of a memory match analysis. 48 | /// 49 | /// Note that matcher contains canonical declarations (Decl::getCanonicalDecl). 50 | struct MemoryMatchInfo : private bcl::Uncopyable { 51 | typedef tsar::ListBimap< 52 | bcl::tagged, 53 | bcl::tagged> MemoryMatcher; 54 | 55 | typedef llvm::DenseSet MemoryASTSet; 56 | 57 | /// Memory matcher for the last analyzed module. 58 | MemoryMatcher Matcher; 59 | 60 | /// Unmatched memory in AST. 61 | MemoryASTSet UnmatchedAST; 62 | }; 63 | } 64 | 65 | namespace llvm { 66 | /// Wrapper to access results of a memory matcher pass. 67 | using MemoryMatcherImmutableWrapper = AnalysisWrapperPass; 68 | } 69 | #endif//TSAR_MEMORY_MATCHER_H 70 | -------------------------------------------------------------------------------- /include/tsar/Analysis/Intrinsics.h: -------------------------------------------------------------------------------- 1 | //===-- Instrinsics.h - TSAR Intrinsic Function Handling --------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file defines a enum of intrinsic identifiers supported by TSAR. Some 22 | // helpful methods to process these intrinsics are also defined. The TSAR 23 | // intrinsic functions is a normal functions (not LLVM intrinsics) which are 24 | // used for analyzer to obtain some special information about a program at 25 | // runtime. 26 | // 27 | //===----------------------------------------------------------------------===// 28 | #ifndef TSAR_INTRINSICS_H 29 | #define TSAR_INTRINSICS_H 30 | 31 | #include 32 | #include 33 | 34 | namespace llvm { 35 | class Function; 36 | class FunctionType; 37 | class Module; 38 | class LLVMContext; 39 | } 40 | 41 | namespace tsar { 42 | /// This namespace contains an enum with a value for every intrinsic/builtin 43 | /// function known by TSAR. 44 | enum class IntrinsicId : unsigned { 45 | not_intrinsic = 0, 46 | #define GET_INTRINSIC_ENUM_VALUES 47 | #include "tsar/Analysis/Intrinsics.gen" 48 | #undef GET_INTRINSIC_ENUM_VALUES 49 | num_intrinsics 50 | }; 51 | 52 | /// Returns the name for an intrinsic with no overloads. 53 | llvm::StringRef getName(IntrinsicId Id); 54 | 55 | /// Returns the function type for an intrinsic. 56 | llvm::FunctionType *getType(llvm::LLVMContext &Ctx, IntrinsicId Id); 57 | 58 | /// Creates or inserts an LLVM Function declaration for an intrinsic. 59 | llvm::FunctionCallee getDeclaration(llvm::Module *M, IntrinsicId Id); 60 | 61 | /// Find tsar function by name. Return false if not found. 62 | bool getTsarLibFunc(llvm::StringRef funcName, IntrinsicId &Id); 63 | } 64 | #endif//TSAR_INTRINSICS_H 65 | -------------------------------------------------------------------------------- /include/tsar/Analysis/LibraryFunctions.def: -------------------------------------------------------------------------------- 1 | //===- LibraryFunctions.def - Known Library Functions -----------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file kontains list of library functions with some known function traits. 22 | // For example, it contains list of input/output functions. All functions in 23 | // this file are considered by TargetLibraryInfo as a library functions. 24 | // 25 | //===----------------------------------------------------------------------===// 26 | 27 | #ifdef GET_IO_FUNCTIONS 28 | "clearerr", 29 | "ctermid", 30 | "dprintf", 31 | "fclose", 32 | "fdopen", 33 | "feof", 34 | "ferror", 35 | "fflush", 36 | "fgetc", 37 | "fgetpos", 38 | "fgetc", 39 | "fgetpos", 40 | "fgets", 41 | "fileno", 42 | "flockfile", 43 | "fmemopen", 44 | "fopen", 45 | "fprintf", 46 | "fputc", 47 | "fputs", 48 | "fread", 49 | "freopen", 50 | "fscanf", 51 | "fseek", 52 | "fseeko", 53 | "fsetpos", 54 | "ftell", 55 | "ftello", 56 | "ftrylockfile", 57 | "funlockfile", 58 | "fwrite", 59 | "getc", 60 | "getchar", 61 | "getc_unlocked", 62 | "getchar_unlocked", 63 | "getdelim", 64 | "getline", 65 | "gets", 66 | "open_memstream", 67 | "pclose", 68 | "perror", 69 | "popen", 70 | "printf", 71 | "putc", 72 | "putchar", 73 | "putc_unlocked", 74 | "putchar_unlocked", 75 | "puts", 76 | "remove", 77 | "rename", 78 | "renameat", 79 | "rewind", 80 | "scanf", 81 | "setbuf", 82 | "setvbuf", 83 | "snprintf", 84 | "sprintf", 85 | "sscanf", 86 | "tempnam", 87 | "tmpfile", 88 | "tmpnam", 89 | "tmpfile", 90 | "tmpnam", 91 | "ungetc", 92 | "vdprintf", 93 | "vfprintf", 94 | "vfscanf", 95 | "vprintf", 96 | "vscanf", 97 | "vsprintf", 98 | "vsscanf", 99 | #endif//GET_IO_FUNCTIONS 100 | -------------------------------------------------------------------------------- /include/tsar/Unparse/SourceUnparserUtils.h: -------------------------------------------------------------------------------- 1 | //===- SourceUnparserUtils.h - Utils For Source Info Unparser ---*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file defines utility functions to generalize unparsing of metdata 22 | // for different source languages. 23 | // 24 | //===----------------------------------------------------------------------===// 25 | 26 | #ifndef TSAR_SOURCE_UNPARSER_UTILS_H 27 | #define TSAR_SOURCE_UNPARSER_UTILS_H 28 | 29 | #include 30 | 31 | namespace llvm { 32 | class raw_ostream; 33 | class DominatorTree; 34 | class CallBase; 35 | class Module; 36 | } 37 | 38 | namespace tsar { 39 | struct DIMemoryLocation; 40 | 41 | /// Unparses the expression (in a specified language DWLang) and appends result 42 | /// to a specified string, returns true on success. 43 | bool unparseToString(unsigned DWLang, 44 | const DIMemoryLocation &Loc, llvm::SmallVectorImpl &S, 45 | bool IsMinimal = true); 46 | 47 | /// Unparses the expression (in a specified language DWLang) and prints result 48 | /// to a specified stream returns true on success. 49 | bool unparsePrint(unsigned DWLang, 50 | const DIMemoryLocation &Loc, llvm::raw_ostream &OS, 51 | bool IsMinimal = true); 52 | 53 | /// Unparses the expression (in a specified language DWLang) and prints result 54 | /// to the debug stream returns true on success. 55 | bool unparseDump(unsigned DWLang, const DIMemoryLocation &Loc, 56 | bool IsMinimal = true); 57 | 58 | /// Unparses callee and appends result to a specified string, 59 | /// returns true on success. 60 | bool unparseCallee(const llvm::CallBase &CB, llvm::Module &M, 61 | llvm::DominatorTree &DT, llvm::SmallVectorImpl &S, 62 | bool IsMinimal = true); 63 | } 64 | #endif//TSAR_SOURCE_UNPARSER_UTILS_H 65 | -------------------------------------------------------------------------------- /lib/Core/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | configure_file(${PROJECT_SOURCE_DIR}/include/tsar/Core/tsar-config.h.in 2 | tsar-config.h) 3 | 4 | set(CORE_SOURCES TransformationContext.cpp Query.cpp Passes.cpp Tool.cpp 5 | IRAction.cpp) 6 | 7 | if(MSVC_IDE) 8 | file(GLOB_RECURSE CORE_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 9 | ${PROJECT_SOURCE_DIR}/include/tsar/Core/*.h) 10 | file(GLOB_RECURSE CORE_INTERNAL_HEADERS 11 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) 12 | source_group(bcl FILES ${BCL_CORE_HEADERS}) 13 | if (APC_FOUND) 14 | source_group(apc FILES ${APC_CORE_HEADERS}) 15 | endif() 16 | if(lp_solve_FOUND) 17 | source_group(lp_solve FILES ${lp_solve_HEADERS}) 18 | endif() 19 | endif() 20 | 21 | add_library(TSARTool STATIC 22 | ${CORE_SOURCES} ${CORE_HEADERS} ${CORE_INTERNAL_HEADERS}) 23 | 24 | set_target_properties(TSARTool PROPERTIES FOLDER "${TSAR_LIBRARY_FOLDER}") 25 | set_target_properties(TSARTool PROPERTIES 26 | COMPILE_DEFINITIONS $<$>:NDEBUG>) 27 | 28 | if(APC_FOUND) 29 | add_dependencies(TSARTool APC) 30 | target_link_libraries(TSARTool PRIVATE APC) 31 | endif() 32 | 33 | if(lp_solve_FOUND) 34 | add_dependencies(TSARTool lp_solve) 35 | target_link_libraries(TSARTool PRIVATE lp_solve) 36 | endif() 37 | 38 | # Do not specify dependencies in case of PACKAGE_LLVM because Clang and LLVM 39 | # libraries are not top-level targets in this case. So this works incorrect. 40 | if(NOT PACKAGE_LLVM) 41 | if(Flang_FOUND) 42 | add_dependencies(TSARTool TSARTransformFlang TSARFrontendFlang 43 | TSARAnalysisFlang TSARSupportFlang) 44 | endif() 45 | add_dependencies(TSARTool 46 | TSARTransformAST 47 | TSARTransformClang TSARTransformMixed TSARTransformIR TSARFrontendClang 48 | TSARAnalysisClang TSARAnalysisParallel TSARAnalysisReader TSARAnalysisMemory 49 | TSARAnalysis TSARUnparse TSARSupportClang TSARSupport 50 | ${CLANG_LIBS} ${LLVM_LIBS} ${FLANG_LIBS} BCL::Core) 51 | endif() 52 | 53 | if (FLANG_FOUND) 54 | target_link_libraries(TSARTool PRIVATE TSARTransformFlang TSARFrontendFlang 55 | TSARAnalysisFlang TSARSupportFlang) 56 | endif() 57 | 58 | target_link_libraries(TSARTool PRIVATE 59 | TSARTransformAST 60 | TSARTransformClang TSARTransformMixed TSARTransformIR TSARFrontendClang 61 | TSARAnalysisClang TSARAnalysisParallel TSARAnalysisReader TSARAnalysisMemory 62 | TSARAnalysis TSARUnparse TSARSupportClang TSARSupport BCL::Core) 63 | 64 | if(WIN32) 65 | # clangDriver uses version.dll. 66 | target_link_libraries(TSARTool PRIVATE version) 67 | endif() 68 | -------------------------------------------------------------------------------- /lib/Frontend/Clang/FrontendActions.cpp: -------------------------------------------------------------------------------- 1 | //===-- FrontendActions.cpp - Useful Frontend Actions -----------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file implements useful frontend actions. 22 | // 23 | //===----------------------------------------------------------------------===// 24 | 25 | #include "tsar/Frontend/Clang/FrontendActions.h" 26 | #include "tsar/Frontend/Clang/DefaultPragmaHandlers.h" 27 | #include "tsar/Frontend/Clang/Pragma.h" 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | using namespace clang; 35 | using namespace llvm; 36 | using namespace tsar; 37 | 38 | std::unique_ptr 39 | tsar::ASTPrintAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { 40 | return CreateASTPrinter(nullptr, ""); 41 | } 42 | 43 | std::unique_ptr 44 | tsar::ASTDumpAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { 45 | return CreateASTDumper(nullptr, "", true, true, true, true, ADOF_Default); 46 | } 47 | 48 | bool GenPCHPragmaAction::BeginSourceFileAction(CompilerInstance &CI) { 49 | CI.getLangOpts().CompilingPCH = true; 50 | mPP = &CI.getPreprocessor(); 51 | AddPragmaHandlers(*mPP, mNamespaces); 52 | if (!WrapperFrontendAction::BeginSourceFileAction(CI)) { 53 | return false; 54 | } 55 | return true; 56 | } 57 | 58 | void GenPCHPragmaAction::EndSourceFileAction() { 59 | WrapperFrontendAction::EndSourceFileAction(); 60 | using ItrTy = 61 | pointer_iterator>; 62 | RemovePragmaHandlers(*mPP, 63 | ItrTy(mNamespaces.begin()), ItrTy(mNamespaces.end())); 64 | } 65 | -------------------------------------------------------------------------------- /include/tsar/Analysis/Reader/Passes.h: -------------------------------------------------------------------------------- 1 | //=== Passes.h - Create and Initialize Analysis Passes (Reader) -*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // It contains declarations of functions that initialize and create an instances 22 | // of TSAR passes which are necessary to load external analysis results. 23 | // Declarations of appropriate methods for an each new pass should 24 | // be added to this file. 25 | // 26 | //===----------------------------------------------------------------------===// 27 | 28 | #ifndef TSAR_ANALYSIS_READER_PASSES_H 29 | #define TSAR_ANALYSIS_READER_PASSES_H 30 | 31 | #include 32 | 33 | namespace llvm { 34 | class PassRegistry; 35 | class FunctionPass; 36 | class ModulePass; 37 | 38 | /// Initialize all passes which is necessary to load external analysis results. 39 | void initializeAnalysisReader(PassRegistry &Registry); 40 | 41 | /// Create a reader of external analysis results. 42 | /// 43 | /// Files with external results must be specified in GlobalOptions::AnalysisUse 44 | /// option. 45 | /// If `Filename` is empty `GlobalOptions::AnalysisUse` value is used. 46 | FunctionPass * createAnalysisReader(); 47 | 48 | /// Initialize a reader of external analysis results. 49 | void initializeAnalysisReaderPass(PassRegistry &Registry); 50 | 51 | /// Create a writer of analysis results. 52 | ModulePass * createAnalysisWriter(); 53 | 54 | /// Initialize a writer of analysis results. 55 | void initializeAnalysisWriterPass(PassRegistry &Registry); 56 | 57 | /// Initialize a pass to estimate region weights in a source code. 58 | void initializeRegionWeightsEstimatorPass(PassRegistry &Registry); 59 | 60 | /// Create a pass to estimate region weights in a source code. 61 | ModulePass *createRegionWeightsEstimator(); 62 | } 63 | #endif//TSAR_ANALYSIS_READER_PASSES_H 64 | -------------------------------------------------------------------------------- /include/tsar/Frontend/Clang/DefaultPragmaHandlers.h: -------------------------------------------------------------------------------- 1 | //===-- DefaultPrgmaHandlers.h - Pragma Handlers ----------------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file implements initialization of all available pragma handlers. 22 | // Update `Add...` and `Remove...` functions to implement custom initialization 23 | // of some handlers if necessary. 24 | // 25 | //===----------------------------------------------------------------------===// 26 | 27 | #ifndef DEFAULT_PRAGMA_HANDLERS_H 28 | #define DEFAULT_PRAGMA_HANDLERS_H 29 | 30 | #include "tsar/Support/Directives.h" 31 | #include "tsar/Frontend/Clang/PragmaHandlers.h" 32 | #include 33 | 34 | namespace tsar { 35 | template 36 | void AddPragmaHandlers(clang::Preprocessor &PP, ContainerT &C) { 37 | for (auto NId = DirectiveNamespaceId::NotNamespace + 1; 38 | NId < DirectiveNamespaceId::NumNamespaces; ++NId) { 39 | auto NR = new PragmaNamespaceReplacer(NId); 40 | C.emplace_back(NR); 41 | PP.AddPragmaHandler(NR); 42 | for (auto DId = DirectiveId::NotDirective + 1; 43 | DId < DirectiveId::NumDirectives; ++DId) { 44 | if (tsar::getParent(DId) != NId) 45 | continue; 46 | if (tsar::getParent(DId) == DirectiveNamespaceId::Dvm) 47 | continue; 48 | auto *PR = new PragmaReplacer(DId, *NR); 49 | NR->AddPragma(PR); 50 | for (ClauseId CId = ClauseId::NotClause + 1; 51 | CId < ClauseId::NumClauses; ++CId) 52 | if (tsar::getParent(CId) == DId) 53 | PR->AddPragma(new ClauseReplacer(CId, *PR)); 54 | } 55 | } 56 | } 57 | 58 | template 59 | void RemovePragmaHandlers(clang::Preprocessor &PP, ItrT I, ItrT E) { 60 | for (; I != E; ++I) 61 | PP.RemovePragmaHandler(*I); 62 | } 63 | } 64 | #endif//DEFAULT_PRAGMA_HANDLERS_H 65 | -------------------------------------------------------------------------------- /include/tsar/Analysis/Attributes.h: -------------------------------------------------------------------------------- 1 | //===-- Attributes.h -------- TSAR Attributes -------------------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file defines a enum of attributes supported by TSAR. Some helpful 22 | // methods to process these attributes are also defined. 23 | // 24 | //===----------------------------------------------------------------------===// 25 | 26 | #ifndef TSAR_ATTRIBUTES_H 27 | #define TSAR_ATTRIBUTES_H 28 | 29 | #include 30 | 31 | namespace llvm { 32 | class Function; 33 | } 34 | 35 | namespace tsar { 36 | /// This enum contains a value for every attribute known by TSAR. 37 | enum class AttrKind : unsigned { 38 | not_attribute = 0, 39 | #define GET_ATTRIBUTE_ENUM_VALUES 40 | #include "tsar/Analysis/Attributes.gen" 41 | #undef GET_ATTRIBUTE_ENUM_VALUES 42 | num_attributes 43 | }; 44 | 45 | /// Returns string representation of the attribute. 46 | llvm::StringRef getAsString(AttrKind Kind); 47 | 48 | /// Adds function attributes to a specified function. 49 | void addFnAttr(llvm::Function &F, AttrKind Kind, 50 | llvm::StringRef Val = llvm::StringRef()); 51 | 52 | /// Removes function attributes from a specified function. 53 | void removeFnAttr(llvm::Function &F, AttrKind Kind); 54 | 55 | /// Returns true if the function has a specified attribute. 56 | bool hasFnAttr(const llvm::Function &F, AttrKind Kind); 57 | 58 | /// Applies the given function object to each attribute. 59 | template void for_each_attr(Function &&F) { 60 | auto KindI = static_cast(AttrKind::not_attribute); 61 | auto KindE = static_cast(AttrKind::num_attributes); 62 | for (KindI++; KindI < KindE; ++KindI) 63 | F(static_cast(KindI)); 64 | } 65 | 66 | /// Returns true if a specified name is a name of input/output library function. 67 | bool isIOLibFuncName(llvm::StringRef FuncName); 68 | } 69 | #endif//TSAR_ATTRIBUTES_H 70 | -------------------------------------------------------------------------------- /lib/Analysis/Memory/DFMemoryLocation.cpp: -------------------------------------------------------------------------------- 1 | //===--- DFMemoryLocation.cpp - Data Flow Framework ----- -------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file implements methods declared in DFMemoryLocation.h 22 | // 23 | //===----------------------------------------------------------------------===// 24 | 25 | #include "tsar/Analysis/Memory/DFMemoryLocation.h" 26 | #include "tsar/Unparse/Utils.h" 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | using namespace llvm; 34 | 35 | namespace tsar { 36 | bool LocationDFValue::intersect(const LocationDFValue &With) { 37 | assert(mKind != INVALID_KIND && "Collection is corrupted!"); 38 | assert(With.mKind != INVALID_KIND && "Collection is corrupted!"); 39 | if (With.mKind == KIND_FULL) 40 | return false; 41 | if (mKind == KIND_FULL) { 42 | *this = With; 43 | return true; 44 | } 45 | return mLocations.intersect(With.mLocations); 46 | } 47 | 48 | bool LocationDFValue::merge(const LocationDFValue &With) { 49 | assert(mKind != INVALID_KIND && "Collection is corrupted!"); 50 | assert(With.mKind != INVALID_KIND && "Collection is corrupted!"); 51 | if (mKind == KIND_FULL) 52 | return false; 53 | if (With.mKind == KIND_FULL) { 54 | mLocations.clear(); 55 | mKind = KIND_FULL; 56 | return true; 57 | } 58 | return mLocations.merge(With.mLocations); 59 | } 60 | 61 | void LocationDFValue::print(raw_ostream &OS, const DominatorTree *DT) const { 62 | if (mKind == KIND_FULL) { 63 | OS << "whole program memory\n"; 64 | return; 65 | } 66 | for (auto &Loc: mLocations) { 67 | printLocationSource(OS, Loc, DT); 68 | OS << " " << *Loc.Ptr << "\n"; 69 | } 70 | } 71 | 72 | LLVM_DUMP_METHOD void LocationDFValue::dump(const DominatorTree *DT) const { 73 | print(dbgs(), DT); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /lib/Core/Passes.cpp: -------------------------------------------------------------------------------- 1 | //===------ Passes.cpp ---- Initialize TSAR Passes --------------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This contains functions to initialize passes that are implemented in TSAR. 22 | // 23 | //===----------------------------------------------------------------------===// 24 | 25 | #include "tsar/Core/Passes.h" 26 | #include "tsar/Analysis/Passes.h" 27 | #include "tsar/Analysis/Clang/Passes.h" 28 | #include "tsar/Analysis/Memory/Passes.h" 29 | #include "tsar/Analysis/Parallel/Passes.h" 30 | #include "tsar/Analysis/Reader/Passes.h" 31 | #include "tsar/Core/TransformationContext.h" 32 | #include "tsar/Core/tsar-config.h" 33 | #include "tsar/Support/GlobalOptions.h" 34 | #include "tsar/Transform/AST/Passes.h" 35 | #include "tsar/Transform/Clang/Passes.h" 36 | #include "tsar/Transform/IR/Passes.h" 37 | #include "tsar/Transform/Mixed/Passes.h" 38 | #ifdef FLANG_FOUND 39 | # include "tsar/Analysis/Flang/Passes.h" 40 | # include "tsar/Transform/Flang/Passes.h" 41 | #endif 42 | #ifdef APC_FOUND 43 | # include "tsar/APC/Passes.h" 44 | #endif 45 | 46 | using namespace llvm; 47 | 48 | void llvm::initializeTSAR(PassRegistry &Registry) { 49 | initializeGlobalOptionsImmutableWrapperPass(Registry); 50 | initializeTransformationEnginePassPass(Registry); 51 | initializeAnalysisBase(Registry); 52 | initializeMemoryAnalysis(Registry); 53 | initializeAnalysisReader(Registry); 54 | initializeParallelizationAnalysis(Registry); 55 | initializeClangAnalysis(Registry); 56 | initializeIRTransform(Registry); 57 | initializeMixedTransform(Registry); 58 | initializeASTTransform(Registry); 59 | initializeClangTransform(Registry); 60 | #ifdef FLANG_FOUND 61 | initializeFlangAnalysis(Registry); 62 | initializeFlangTransform(Registry); 63 | #endif 64 | #ifdef APC_FOUND 65 | initializeAPC(Registry); 66 | #endif 67 | } 68 | 69 | void initializeTSAR(LLVMPassRegistryRef R) { 70 | initializeTSAR(*unwrap(R)); 71 | } 72 | -------------------------------------------------------------------------------- /include/tsar/Analysis/Memory/AllocasModRef.h: -------------------------------------------------------------------------------- 1 | //===- AllocasModRef.h --- Simple Mod/Ref AA for Allocas --------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2020 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file implements a simple mod/ref and alias analysis over allocas. 22 | // 23 | //===----------------------------------------------------------------------===// 24 | 25 | #ifndef TSAR_ALLOCAS_MODREF_H 26 | #define TSAR_ALLOCAS_MODREF_H 27 | 28 | #include "tsar/Analysis/Memory/Passes.h" 29 | #include 30 | #include 31 | 32 | namespace llvm { 33 | class AllocaInst; 34 | class DataLayout; 35 | 36 | /// An alias result set for allocas. 37 | class AllocasAAResult : public AAResultBase { 38 | public: 39 | explicit AllocasAAResult(const DataLayout &DL) : mDL(DL) {} 40 | 41 | AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, 42 | AAQueryInfo &AAQI); 43 | 44 | using AAResultBase::getModRefInfo; 45 | ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc, 46 | AAQueryInfo &AAQI); 47 | 48 | void analyzeFunction(const Function &F); 49 | 50 | private: 51 | SmallPtrSet mNonAddressTakenAllocas; 52 | const DataLayout &mDL; 53 | }; 54 | 55 | /// Analysis pass that provides the AllocasAAResult object. 56 | class AllocasAAWrapperPass : public ImmutablePass { 57 | public: 58 | static char ID; 59 | 60 | explicit AllocasAAWrapperPass() : ImmutablePass(ID) { 61 | initializeAllocasAAWrapperPassPass(*PassRegistry::getPassRegistry()); 62 | } 63 | 64 | AllocasAAResult &getResult() { return *mResult; } 65 | const AllocasAAResult &getResult() const { return *mResult; } 66 | 67 | bool doInitialization(Module &M) override; 68 | bool doFinalization(Module &M) override; 69 | 70 | private: 71 | std::unique_ptr mResult; 72 | }; 73 | } 74 | #endif//TSAR_ALLOCA_ALIAS_ANALYSIS_H 75 | -------------------------------------------------------------------------------- /lib/Transform/IR/MetadataUtils.cpp: -------------------------------------------------------------------------------- 1 | //===----- MetadataUtils.cpp - Utils for exploring metadata -----*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file implements helpful functions to create and access metadata. 22 | // 23 | //===----------------------------------------------------------------------===// 24 | 25 | #include "tsar/Transform/IR/MetadataUtils.h" 26 | #include 27 | #include 28 | 29 | using namespace llvm; 30 | 31 | namespace tsar { 32 | void addNameDAMetadata(GlobalObject &GO, StringRef NamedMD, 33 | StringRef ValueKind, ArrayRef MDs) { 34 | assert(GO.getParent() && "Function must be inserted into a module!"); 35 | auto GOKindMD = MDString::get(GO.getContext(), ValueKind); 36 | auto *GORefMD = ValueAsMetadata::get(&GO); 37 | SmallVector Ops({ GOKindMD, GORefMD }); 38 | Ops.append(MDs.begin(), MDs.end()); 39 | auto GOMD = MDNode::get(GO.getContext(), Ops); 40 | GO.setMetadata(NamedMD, GOMD); 41 | auto NamedMDPtr = GO.getParent()->getOrInsertNamedMetadata(NamedMD); 42 | NamedMDPtr->addOperand(GOMD); 43 | } 44 | 45 | Optional eraseFromParent(Module &M, StringRef NamedMD, 46 | StringRef MD) { 47 | if (auto NamedMDPtr = M.getNamedMetadata(NamedMD)) 48 | if (auto MDPtr = getMDOfKind(*NamedMDPtr, MD)) { 49 | auto Item = extractMD(*MDPtr); 50 | if (Item.first) { 51 | Item.first->eraseFromParent(); 52 | return Item.second; 53 | } 54 | } 55 | return None; 56 | } 57 | 58 | static MDString * getMDKindString(MDNode &MD) { 59 | for (auto &Op : MD.operands()) { 60 | if (auto *Str = dyn_cast(Op)) 61 | return Str; 62 | } 63 | return nullptr; 64 | } 65 | 66 | MDNode * getMDOfKind(NamedMDNode &NamedMD, StringRef Kind) { 67 | for (auto *MD : NamedMD.operands()) 68 | if (getMDKindString(*MD)->getString() == Kind) 69 | return MD; 70 | return nullptr; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /include/tsar/Transform/IR/InterprocAttr.h: -------------------------------------------------------------------------------- 1 | //===- InterprocAttr.h - Interprocedural Attributes Deduction ---*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file declares passes which perform interprocedural analysis in order to 22 | // deduce some function and loop attributes. 23 | // 24 | //===----------------------------------------------------------------------===// 25 | 26 | #include "tsar/Analysis/Attributes.h" 27 | #include "tsar/Transform/IR/Passes.h" 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #ifndef TSAR_INTERPROC_ATTR_H 36 | #define TSAR_INTERPROC_ATTR_H 37 | 38 | namespace llvm { 39 | class Loop; 40 | 41 | /// This pass uses functions which are called from a loop in order to deduce 42 | /// loop attributes. 43 | class LoopAttributesDeductionPass : 44 | public FunctionPass, private bcl::Uncopyable { 45 | 46 | template 47 | using TaggedSet = bcl::tagged, AttrT>; 48 | public: 49 | static char ID; 50 | LoopAttributesDeductionPass() : FunctionPass(ID) { 51 | initializeLoopAttributesDeductionPassPass(*PassRegistry::getPassRegistry()); 52 | } 53 | 54 | bool runOnFunction(Function &F) override; 55 | void releaseMemory() override { mAttrs.clear(); } 56 | void getAnalysisUsage(AnalysisUsage &AU) const override; 57 | 58 | /// Returns true if a specified loop has a specified attribute. 59 | /// 60 | /// LLVM and SAPFOR attributes are supported. 61 | template 62 | bool hasAttr(const Loop &L, KindT Kind) { 63 | auto I = mAttrs.find(&L); 64 | return I != mAttrs.end() && I->second.get().count(Kind); 65 | } 66 | private: 67 | DenseMap, 69 | TaggedSet>> mAttrs; 70 | }; 71 | } 72 | 73 | #endif//TSAR_INTERPRO_ATTR_H 74 | -------------------------------------------------------------------------------- /include/tsar/Analysis/Parallel/ParallelLoop.h: -------------------------------------------------------------------------------- 1 | //===- ParallelLoop.h ------ Parallel Loop Analysis ------------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2019 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file defines passes to determine parallelization opportunities of loops. 22 | // 23 | //===----------------------------------------------------------------------===// 24 | 25 | #ifndef TSAR_ANALYSIS_PARALLEL_LOOP_H 26 | #define TSAR_ANALYSIS_PARALLEL_LOOP_H 27 | 28 | #include "tsar/Analysis/Parallel/Passes.h" 29 | #include "bcl/utility.h" 30 | #include 31 | #include 32 | 33 | namespace llvm { 34 | class Loop; 35 | } 36 | 37 | namespace tsar { 38 | class ParallelInfo { 39 | public: 40 | ParallelInfo(bool HostOnly = true) : mHostOnly(HostOnly) {} 41 | bool isHostOnly() const noexcept { return mHostOnly; } 42 | private: 43 | bool mHostOnly; 44 | }; 45 | 46 | /// List of loops which could be executed in a parallel way. 47 | using ParallelLoopInfo = llvm::DenseMap; 48 | } 49 | 50 | namespace llvm { 51 | /// Determine loops which could be executed in a parallel way. 52 | class ParallelLoopPass : public FunctionPass, private bcl::Uncopyable { 53 | public: 54 | static char ID; 55 | 56 | ParallelLoopPass() : FunctionPass(ID) { 57 | initializeParallelLoopPassPass(*PassRegistry::getPassRegistry()); 58 | } 59 | 60 | bool runOnFunction(Function &F) override; 61 | void getAnalysisUsage(AnalysisUsage &AU) const override; 62 | 63 | void releaseMemory() override { mParallelLoops.clear(); } 64 | 65 | /// Return list of loops which could be executed in a parallel way. 66 | tsar::ParallelLoopInfo &getParallelLoopInfo() { return mParallelLoops; } 67 | 68 | /// Return list of loops which could be executed in a parallel way. 69 | const tsar::ParallelLoopInfo &getParallelLoopInfo() const { 70 | return mParallelLoops; 71 | } 72 | 73 | private: 74 | tsar::ParallelLoopInfo mParallelLoops; 75 | }; 76 | } 77 | 78 | #endif//TSAR_ANALYSIS_PARALLEL_LOOP_H 79 | -------------------------------------------------------------------------------- /include/tsar/Analysis/Clang/Utils.h: -------------------------------------------------------------------------------- 1 | //===----- Utils.h -------- Utility Methods and Classes ---------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2020 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file defines abstractions which simplify usage of other abstractions. 22 | // 23 | //===----------------------------------------------------------------------===// 24 | 25 | #ifndef TSAR_ANALYSIS_CLANG_UTILS_H 26 | #define TSAR_ANALYSIS_CLANG_UTILS_H 27 | 28 | #include "tsar/Analysis/Clang/CanonicalLoop.h" 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | namespace llvm { 35 | class Loop; 36 | class MDNode; 37 | } 38 | 39 | namespace tsar { 40 | class DFRegionInfo; 41 | struct MemoryMatchInfo; 42 | 43 | /// Determine direction of induction if step is known. 44 | llvm::Optional isGrowingInduction(llvm::Loop &L, 45 | const CanonicalLoopSet &CL, DFRegionInfo &DFI); 46 | 47 | /// Determine direction of base induction variables for all canonical 48 | /// loops in the nest. If direction is not known and `DirectionIfUnknown` is 49 | /// specified assume the specified direction. 50 | /// 51 | /// Do not process multiple sub-loops of a loop. 52 | llvm::BitVector isGrowingInduction(llvm::Loop &Outermost, unsigned SizeOfNest, 53 | const CanonicalLoopSet &CL, DFRegionInfo &DFI, 54 | bool *DirectionIfUnknown = nullptr); 55 | 56 | /// Search for base induction variables in a specified loop nest. 57 | /// 58 | /// All loops in the nest have to be presented in a canonical loop form. We do 59 | /// not process multiple sub-loops of a loop. 60 | /// \return false if a number of processed loops is less than a size of the 61 | /// nest. 62 | bool getBaseInductionsForNest(llvm::Loop &Outermost, unsigned SizeOfNest, 63 | const CanonicalLoopSet &CL, const DFRegionInfo &RI, 64 | const MemoryMatchInfo &MM, 65 | llvm::SmallVectorImpl> 66 | &Inductions); 67 | } 68 | #endif//TSAR_ANALYSIS_CLANG_UTILS_H 69 | -------------------------------------------------------------------------------- /lib/Analysis/Attributes.cpp: -------------------------------------------------------------------------------- 1 | //===--- Attributes.cpp --- TSAR Attributes ---------------------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file implements functions from Attributes.h which allow to process 22 | // TSAR attributes. 23 | // 24 | //===----------------------------------------------------------------------===// 25 | 26 | #include "tsar/Analysis/Attributes.h" 27 | #include 28 | #include 29 | 30 | using namespace llvm; 31 | using namespace tsar; 32 | 33 | /// Table of string attribute names indexed by enum value. 34 | static const char * const AttributeNameTable[] = { 35 | "not_attribute", 36 | #define GET_ATTRIBUTE_NAME_TABLE 37 | #include "tsar/Analysis/Attributes.gen" 38 | #undef GET_ATTRIBUTE_NAME_TABLE 39 | }; 40 | 41 | namespace tsar { 42 | StringRef getAsString(AttrKind Kind) { 43 | assert(Kind < AttrKind::num_attributes && Kind > AttrKind::not_attribute && 44 | "Invalid attribute kind!"); 45 | return AttributeNameTable[static_cast(Kind)]; 46 | } 47 | 48 | void addFnAttr(llvm::Function &F, AttrKind Kind, StringRef Val) { 49 | F.addFnAttr(getAsString(Kind), Val); 50 | } 51 | void removeFnAttr(llvm::Function &F, AttrKind Kind) { 52 | F.removeFnAttr(getAsString(Kind)); 53 | } 54 | 55 | bool hasFnAttr(const llvm::Function &F, AttrKind Kind) { 56 | return F.hasFnAttribute(getAsString(Kind)); 57 | } 58 | 59 | /// Table of string names of input/output library functions. 60 | static const char * const IOFunctionNameTable[] = { 61 | #define GET_IO_FUNCTIONS 62 | #include "tsar/Analysis/LibraryFunctions.def" 63 | #undef GET_IO_FUNCTIONS 64 | }; 65 | 66 | bool isIOLibFuncName(StringRef FuncName) { 67 | const char* const *Start = &IOFunctionNameTable[0]; 68 | const char* const *End = 69 | &IOFunctionNameTable[bcl::array_sizeof(IOFunctionNameTable)]; 70 | if (FuncName.empty()) 71 | return false; 72 | const char* const *I = std::find(Start, End, FuncName); 73 | if (I != End) 74 | return true; 75 | return false; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /lib/APC/APCContextImpl.h: -------------------------------------------------------------------------------- 1 | //===- APCContext.h - Opaque implementation of APC context --- -*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file declares APCContextImpl, opaque implementation of APCContext. 22 | // 23 | //===----------------------------------------------------------------------===// 24 | 25 | #ifndef TSAR_APC_CONTEXT_IMPL_H 26 | #define TSAR_APC_CONTEXT_IMPL_H 27 | 28 | #include "AstWrapperImpl.h" 29 | #include "tsar/Support/Tags.h" 30 | #include "tsar/Transform/Clang/DVMHDirecitves.h" 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | namespace tsar { 41 | struct APCContextImpl { 42 | using ExpressionPool = std::vector>; 43 | using SymbolPool = std::vector>; 44 | using StatementPool = std::vector>; 45 | using ParallelRegionPool = std::vector>; 46 | 47 | using LoopPool = std::vector>; 48 | using LoopMap = llvm::DenseMap; 49 | 50 | using ArrayMap = llvm::DenseMap>; 51 | using TemplateMap = llvm::DenseMap; 52 | 53 | using FunctionMap = 54 | llvm::DenseMap>; 55 | 56 | using FileDiagnostics = std::map>; 57 | 58 | ExpressionPool Expressions; 59 | SymbolPool Symbols; 60 | StatementPool Statements; 61 | ParallelRegionPool ParallelRegions; 62 | 63 | LoopPool OuterLoops; 64 | LoopMap Loops; 65 | 66 | ArrayMap Arrays; 67 | TemplateMap Templates; 68 | 69 | FunctionMap Functions; 70 | 71 | FileDiagnostics Diags; 72 | }; 73 | } 74 | 75 | #endif//TSAR_APC_CONTEXT_IMPL_H 76 | -------------------------------------------------------------------------------- /include/tsar/ADT/PersistentIteratorInfo.h: -------------------------------------------------------------------------------- 1 | //=== PersistentIteratorInfo.h Type traits for PersistentIterator*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (TSAR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file defines llvm::DenseMapInfo traits for persistent iterators. 22 | // 23 | //===----------------------------------------------------------------------===// 24 | #ifndef TSAR_PERSISTENT_ITERATOR_INFO_H 25 | #define TSAR_PERSISTENT_ITERATOR_INFO_H 26 | 27 | #include "PersistentIterator.h" 28 | #include 29 | 30 | namespace llvm { 31 | template struct DenseMapInfo< 32 | tsar::PersistentIteratorC> { 33 | protected: 34 | using Iterator = tsar::PersistentIteratorC; 35 | using PersistentBucket = typename Iterator::PersistentBucket; 36 | public: 37 | static inline Iterator getEmptyKey() { 38 | return Iterator(DenseMapInfo::getEmptyKey()); 39 | } 40 | static inline Iterator getTombstoneKey() { 41 | return Iterator(DenseMapInfo::getTombstoneKey()); 42 | } 43 | static unsigned getHashValue(const Iterator &Val) { 44 | return DenseMapInfo::getHashValue(Val.mPtr); 45 | } 46 | static bool isEqual(const Iterator &LHS, const Iterator &RHS) { 47 | return LHS == RHS; 48 | } 49 | }; 50 | 51 | template struct DenseMapInfo< 52 | tsar::PersistentIterator> : 53 | public DenseMapInfo> { 54 | protected: 55 | using Iterator = tsar::PersistentIterator; 56 | using PersistentBucket = 57 | typename DenseMapInfo> 58 | ::PersistentBucket; 59 | public: 60 | static inline Iterator getEmptyKey() { 61 | return Iterator(DenseMapInfo::getEmptyKey()); 62 | } 63 | static inline Iterator getTombstoneKey() { 64 | return Iterator(DenseMapInfo::getTombstoneKey()); 65 | } 66 | }; 67 | } 68 | #endif//TSAR_PERSISTENT_ITERATOR_INFO_H 69 | -------------------------------------------------------------------------------- /include/tsar/Frontend/Flang/Tooling.h: -------------------------------------------------------------------------------- 1 | //===- Tooling.h ----------- Flang Based Tool (Flang) ------------*- C++ -*===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2022 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file implements functions to run flang tools standalone instead of 22 | // running them as a plugin. 23 | // 24 | //===----------------------------------------------------------------------===// 25 | 26 | #ifndef TSAR_FLANG_TOOLING_H 27 | #define TSAR_FLANG_TOOLING_H 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | namespace clang::tooling { 38 | class CompilationDatabase; 39 | } 40 | 41 | namespace tsar { 42 | class FlangFrontendActionFactory; 43 | 44 | class FlangTool { 45 | public: 46 | FlangTool(const clang::tooling::CompilationDatabase &Compilations, 47 | llvm::ArrayRef SourcePaths, 48 | llvm::IntrusiveRefCntPtr BaseFS = 49 | llvm::vfs::getRealFileSystem()) 50 | : mCompilations(Compilations), mSourcePaths(SourcePaths), 51 | mOverlayFileSystem( 52 | new llvm::vfs::OverlayFileSystem(std::move(BaseFS))) { 53 | appendArgumentsAdjuster(clang::tooling::getClangStripOutputAdjuster()); 54 | } 55 | 56 | ~FlangTool() = default; 57 | 58 | int run(FlangFrontendActionFactory *Factory); 59 | 60 | void setRestoreWorkingDir(bool RestoreCWD) noexcept { 61 | mRestoreCWD = RestoreCWD; 62 | } 63 | 64 | void appendArgumentsAdjuster(clang::tooling::ArgumentsAdjuster Adjuster); 65 | void clearArgumentsAdjusters() { mArgsAdjuster = nullptr; } 66 | 67 | private: 68 | const clang::tooling::CompilationDatabase &mCompilations; 69 | std::vector mSourcePaths; 70 | llvm::IntrusiveRefCntPtr mOverlayFileSystem; 71 | bool mRestoreCWD{true}; 72 | clang::tooling::ArgumentsAdjuster mArgsAdjuster; 73 | }; 74 | } // namespace tsar 75 | #endif//TSAR_FLANG_TOOLING_H 76 | -------------------------------------------------------------------------------- /include/tsar/Analysis/Clang/PerfectLoop.h: -------------------------------------------------------------------------------- 1 | //=== PerfectLoop.h --- High Level Perfect Loop Analyzer --------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file defines classes to identify perfect for-loops in a source code. 22 | // 23 | //===----------------------------------------------------------------------===// 24 | 25 | #ifndef TSAR_CLANG_PERFECT_LOOP_H 26 | #define TSAR_CLANG_PERFECT_LOOP_H 27 | 28 | #include "tsar/Analysis/Clang/Passes.h" 29 | #include 30 | #include 31 | #include 32 | 33 | namespace tsar { 34 | class DFNode; 35 | 36 | /// Set of perfect loops. 37 | using PerfectLoopInfo = llvm::DenseSet; 38 | } 39 | 40 | namespace llvm { 41 | /// \brief This per-function pass determines perfect for-loops in a source code. 42 | /// 43 | /// A for-loop is treated as perfect if it has no internal for-loops or if it 44 | /// has only one internal for-loop and there are no other statements between 45 | /// loop bounds. 46 | class ClangPerfectLoopPass : public FunctionPass, private bcl::Uncopyable { 47 | public: 48 | /// Pass identification, replacement for typeid. 49 | static char ID; 50 | 51 | /// Default constructor. 52 | ClangPerfectLoopPass() : FunctionPass(ID) { 53 | initializeClangPerfectLoopPassPass(*PassRegistry::getPassRegistry()); 54 | } 55 | 56 | /// Returns information about perfect loops in an analyzed function. 57 | tsar::PerfectLoopInfo & getPerfectLoopInfo() noexcept { 58 | return mPerfectLoopInfo; 59 | } 60 | 61 | /// Returns information about perfect loops in an analyzed function. 62 | const tsar::PerfectLoopInfo & getPerfectLoopInfo() const noexcept { 63 | return mPerfectLoopInfo; 64 | } 65 | 66 | // Determines perfect loops in a specified functions. 67 | bool runOnFunction(Function &F) override; 68 | 69 | void releaseMemory() override { mPerfectLoopInfo.clear(); } 70 | 71 | /// Specifies a list of analyzes that are necessary for this pass. 72 | void getAnalysisUsage(AnalysisUsage &AU) const override; 73 | 74 | private: 75 | tsar::PerfectLoopInfo mPerfectLoopInfo; 76 | }; 77 | } 78 | #endif// TSAR_CLANG_PERFECT_LOOP_H 79 | -------------------------------------------------------------------------------- /include/tsar/Support/NumericUtils.h: -------------------------------------------------------------------------------- 1 | //===- NumericUtils.h - Utilities To Use Numeric Constants ------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file implements utility methods to work with different representations 22 | // of numeric constant. 23 | // 24 | //===----------------------------------------------------------------------===// 25 | 26 | #ifndef TSAR_NUMERIC_UTILS 27 | #define TSAR_NUMERIC_UTILS 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | namespace tsar { 35 | /// Returns true if cast from a specified value `Const` to a specified 36 | /// type `IntT` leads to integer overflow or a source value is signed and 37 | /// a target value is unsigned. 38 | template 39 | inline bool isOverflow(const llvm::APInt &Const, bool IsSigned) { 40 | return 41 | std::numeric_limits::is_signed ? 42 | IsSigned ? 43 | !Const.isSignedIntN(sizeof(IntT) * CHAR_BIT - 1) : 44 | !Const.isIntN(sizeof(IntT) * CHAR_BIT - 1) : 45 | IsSigned ? 46 | true : // it is not possible to represent signed as unsigned 47 | !Const.isIntN(sizeof(IntT) * CHAR_BIT); 48 | } 49 | 50 | /// Cast a specified value `Const` to a specified type `IntT`, returns `true` 51 | /// on success and `false` if integer overflow has been occurred. 52 | template 53 | inline bool castAPInt(const llvm::APInt &Const, bool IsSigned, IntT &Out) { 54 | if (isOverflow(Const, IsSigned)) 55 | return false; 56 | if (IsSigned) 57 | Out = static_cast(Const.getSExtValue()); 58 | else 59 | Out = static_cast(Const.getZExtValue()); 60 | return true; 61 | } 62 | 63 | /// Cast a specified value `Expr` to a specified type `IntT`, 64 | /// returns `false` if a value not a constant or integer overflow occurs. 65 | template 66 | inline bool castSCEV(const llvm::SCEV *Expr, bool IsSigned, IntT &Out) { 67 | assert(Expr && "Expression must not be null!"); 68 | if (auto Const = llvm::dyn_cast(Expr)) 69 | return castAPInt(Const->getAPInt(), IsSigned, Out); 70 | return false; 71 | } 72 | } 73 | #endif//TSAR_NUMERIC_UTILS 74 | -------------------------------------------------------------------------------- /include/tsar/Unparse/CSourceUnparser.h: -------------------------------------------------------------------------------- 1 | //===--- CSourceUnparser.h -- C Source Info Unparser ------------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file defines unparser to print metadata objects as constructs in C/C++. 22 | // 23 | //===----------------------------------------------------------------------===// 24 | 25 | #ifndef TSAR_C_SOURCE_UNPARSER_H 26 | #define TSAR_C_SOURCE_UNPARSER_H 27 | 28 | #include "tsar/Unparse/SourceUnparser.h" 29 | #include 30 | 31 | namespace tsar { 32 | /// This is an unparser for C and C++ languages. 33 | class CSourceUnparser : public SourceUnparser { 34 | public: 35 | ///Creates unparser for a specified expression. 36 | explicit CSourceUnparser(const DIMemoryLocation &Loc, bool Minimal) noexcept : 37 | SourceUnparser(Loc, true, Minimal) {} 38 | 39 | private: 40 | friend SourceUnparser; 41 | 42 | void appendToken(Token T, bool IsSubscript, 43 | llvm::SmallVectorImpl &Str) { 44 | switch (T) { 45 | default: llvm_unreachable("Unsupported kind of token!"); break; 46 | case TOKEN_ADDRESS: Str.push_back('&'); break; 47 | case TOKEN_DEREF: Str.push_back('*'); break; 48 | case TOKEN_PARENTHESES_LEFT: Str.push_back('('); break; 49 | case TOKEN_PARENTHESES_RIGHT: Str.push_back(')'); break; 50 | case TOKEN_ADD: Str.push_back('+'); break; 51 | case TOKEN_SUB: Str.push_back('-'); break; 52 | case TOKEN_FIELD: Str.push_back('.'); break; 53 | case TOKEN_UNKNOWN: Str.push_back('?'); break; 54 | case TOKEN_SEPARATOR: 55 | if (IsSubscript) 56 | Str.append({ ']', '[' }); 57 | break; 58 | case TOKEN_CAST_TO_ADDRESS: 59 | Str.append({ '(', 'c', 'h', 'a', 'r', '*', ')' }); break; 60 | } 61 | } 62 | 63 | void appendUConst( 64 | uint64_t C, bool IsSubscript, llvm::SmallVectorImpl &Str) { 65 | llvm::APInt Const(64, C, false); 66 | Const.toString(Str, 10, false); 67 | } 68 | 69 | 70 | void beginSubscript(llvm::SmallVectorImpl &Str) { 71 | Str.push_back('['); 72 | } 73 | 74 | void endSubscript(llvm::SmallVectorImpl &Str) { 75 | Str.push_back(']'); 76 | } 77 | }; 78 | } 79 | #endif//TSAR_C_SOURCE_UNPARSER_H 80 | -------------------------------------------------------------------------------- /include/tsar/Transform/IR/MetadataUtils.h: -------------------------------------------------------------------------------- 1 | //===----- MetadataUtils.h - Utils for exploring metadata -------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file defines helpful functions to create and access metadata. 22 | // 23 | //===----------------------------------------------------------------------===// 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #ifndef TSAR_METADATA_UTILS_H 31 | #define TSAR_METADATA_UTILS_H 32 | 33 | namespace tsar { 34 | /// \brief Add description of a global value into the list of a named metadata. 35 | /// 36 | /// This description will contain: 37 | /// - string with a value `ValueKind`; 38 | /// - metadata which refers to the global value; 39 | /// - metadata from MDs. 40 | /// A global value will be also marked with `NamedMD` metadata which 41 | /// refers to this description. 42 | void addNameDAMetadata(llvm::GlobalObject &GV, llvm::StringRef NamedMD, 43 | llvm::StringRef ValueKind, llvm::ArrayRef MDs = {}); 44 | 45 | /// \brief Erase from a specified module `M` a global object which is identified 46 | /// by a metadata `MD` in a list of named metadata `NamedMD`. 47 | /// 48 | /// This function searches for metadata which contains `MDString` equal to`MD`. 49 | /// If there are no such object or metadata, do nothing. 50 | /// \return Index of operand which points to a removed object in the `MD` 51 | /// metadata. 52 | llvm::Optional eraseFromParent(llvm::Module &M, 53 | llvm::StringRef NamedMD, llvm::StringRef MD); 54 | 55 | /// Returns metadata from a named list of metdata which contains a specified 56 | /// string. 57 | llvm::MDNode * getMDOfKind(llvm::NamedMDNode &NamedMD, llvm::StringRef Kind); 58 | 59 | /// Returns operand which is a llvm::Value and which can be converted 60 | /// to a specified type. 61 | template 62 | static std::pair extractMD(llvm::MDNode &MD) { 63 | for (unsigned I = 0, E = MD.getNumOperands(); I != E; ++I) 64 | if (auto *V = llvm::mdconst::dyn_extract_or_null(MD.getOperand(I))) 65 | return std::make_pair(V, I); 66 | return std::make_pair(nullptr, 0); 67 | } 68 | } 69 | 70 | #endif//TSAR_METADATA_UTILS_H 71 | -------------------------------------------------------------------------------- /include/tsar/Analysis/Memory/TraitFilter.h: -------------------------------------------------------------------------------- 1 | //===---- TraitFilter.h ------ Filters Of Traits ----------------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file defines some filters which marks memory location if some 22 | // traits are set. These filters can be used in `ProcessDIMemoryTraitPass` and 23 | // as a parameters for `createProcessDIMemoryTraitPass()` function to define 24 | // which traits should be marked. 25 | // 26 | //===----------------------------------------------------------------------===// 27 | 28 | #ifndef TSAR_MEMORY_TRAIT_FILTER_H 29 | #define TSAR_MEMORY_TRAIT_FILTER_H 30 | 31 | #include 32 | 33 | namespace llvm { 34 | class DataLayout; 35 | } 36 | 37 | namespace tsar { 38 | /// Set `WhatT` trait. 39 | template void mark(DIMemoryTrait &T) { 40 | T.set(); 41 | } 42 | 43 | /// Unset `WhatT` trait. 44 | template void unmark(DIMemoryTrait &T) { 45 | T.unset(); 46 | } 47 | 48 | /// Set `WhatT` trait if all specified traits `Traits` is set for `T`. 49 | template void markIf(DIMemoryTrait &T) { 50 | if (T.is()) 51 | T.set(); 52 | } 53 | 54 | /// Unset `WhatT` trait if all specified traits `Traits` is set for `T`. 55 | template void unmarkIf(DIMemoryTrait &T) { 56 | if (T.is()) 57 | T.unset(); 58 | } 59 | 60 | /// Set `WhatT` trait if at least one of specified traits `Traits` is set for 61 | /// `T`. 62 | template void markIfAny(DIMemoryTrait &T) { 63 | if (T.is_any()) 64 | T.set(); 65 | } 66 | 67 | /// Unset `WhatT` trait if at least one of specified traits `Traits` is set for 68 | /// `T`. 69 | template void unmarkIfAny(DIMemoryTrait &T) { 70 | if (T.is_any()) 71 | T.unset(); 72 | } 73 | 74 | /// This filter marks locations which have not been promoted yet. 75 | /// 76 | /// Actually this filter looks for `dbg.declare` metadata and if it 77 | /// exist the filter marks appropriate location as a not promoted. 78 | void markIfNotPromoted(const llvm::DataLayout &DL, DIMemoryTrait &T); 79 | } 80 | #endif//TSAR_MEMORY_TRAIT_FILTER_H 81 | -------------------------------------------------------------------------------- /include/tsar/Support/Flang/Diagnostic.h: -------------------------------------------------------------------------------- 1 | 2 | //=== Diagnostic.h - Fortran Language Family Diagnostic Handling *- C++ -*-===// 3 | // 4 | // Traits Static Analyzer (SAPFOR) 5 | // 6 | // Copyright 2021 DVM System Group 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | // 20 | //===----------------------------------------------------------------------===// 21 | // 22 | // Defines the Diagnostic-related interfaces. 23 | // 24 | //===----------------------------------------------------------------------===// 25 | 26 | #ifndef TSAR_FLANG_DIAGNOSTIC_H 27 | #define TSAR_FLANG_DIAGNOSTIC_H 28 | 29 | #include "tsar/Support/Diagnostic.h" 30 | #include 31 | #include 32 | 33 | namespace tsar { 34 | // Return fixed part of a message which describes a specified diagnostic. 35 | const DiagnosticInfo * getFlangMessageText(unsigned int DiagId, 36 | llvm::SmallVectorImpl &Text); 37 | 38 | /// Issue the message to the client. 39 | template 40 | Fortran::parser::Message &toDiag(Fortran::semantics::SemanticsContext &Ctx, 41 | Fortran::parser::CharBlock Loc, unsigned int DiagId, ArgT &&... Args) { 42 | llvm::SmallString<128> Text; 43 | auto *Diag{getFlangMessageText(DiagId, Text)}; 44 | assert(Diag && !Text.empty() && "Unknown diagnostic ID!"); 45 | // We use MessageFormattedText around MessageFixedText, because 46 | // MessageFixedText does not make a copy of text and it points to a 47 | // temporary object Text. 48 | return Ctx.Say(Loc, Fortran::parser::MessageFormattedText{ 49 | Fortran::parser::MessageFixedText{ 50 | Text.data(), Text.size(), 51 | Diag->isError() 52 | ? Fortran::parser::Severity::Error 53 | : Fortran::parser::Severity::Warning}, 54 | std::forward(Args)...}); 55 | } 56 | 57 | /// Issue the message to the client. 58 | template 59 | Fortran::parser::Message &toDiag(Fortran::semantics::SemanticsContext &Ctx, 60 | unsigned int DiagId, ArgT &&... Args) { 61 | auto Loc{Ctx.allCookedSources().allSources().GetFirstFileProvenance()}; 62 | assert(Loc && "At least one file must be parsed!"); 63 | return toDiag(Ctx, *Loc, DiagId, std::forward(Args)...); 64 | } 65 | } // namespace tsar 66 | 67 | #endif//TSAR_FLANG_DIAGNOSTIC_H 68 | -------------------------------------------------------------------------------- /include/tsar/Unparse/FortranSourceUnparser.h: -------------------------------------------------------------------------------- 1 | //===- FortranSourceUnparser.h - Fortran Source Info Unparser ---*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file defines unparser to print metadata objects as constructs in Fortran. 22 | // 23 | //===----------------------------------------------------------------------===// 24 | 25 | #ifndef TSAR_FORTRAN_SOURCE_UNPARSER_H 26 | #define TSAR_FORTRAN_SOURCE_UNPARSER_H 27 | 28 | #include "tsar/Unparse/SourceUnparser.h" 29 | #include 30 | 31 | namespace tsar { 32 | /// This is an unparser for Fortran language. 33 | class FortranSourceUnparser : public SourceUnparser { 34 | public: 35 | ///Creates unparser for a specified expression. 36 | explicit FortranSourceUnparser(const DIMemoryLocation &Loc, 37 | bool Minimal) noexcept : 38 | SourceUnparser(Loc, true, Minimal) {} 39 | 40 | private: 41 | friend SourceUnparser; 42 | 43 | void appendToken(Token T, bool IsSubscript, 44 | llvm::SmallVectorImpl &Str) { 45 | switch (T) { 46 | default: llvm_unreachable("Unsupported kind of token!"); break; 47 | case TOKEN_ADDRESS: Str.push_back('&'); break; 48 | case TOKEN_DEREF: Str.push_back('*'); break; 49 | case TOKEN_PARENTHESES_LEFT: Str.push_back('('); break; 50 | case TOKEN_PARENTHESES_RIGHT: Str.push_back(')'); break; 51 | case TOKEN_ADD: Str.push_back('+'); break; 52 | case TOKEN_SUB: Str.push_back('-'); break; 53 | case TOKEN_FIELD: Str.push_back('%'); break; 54 | case TOKEN_UNKNOWN: Str.push_back('?'); break; 55 | case TOKEN_SEPARATOR: 56 | if (IsSubscript) 57 | Str.push_back(','); 58 | break; 59 | case TOKEN_CAST_TO_ADDRESS: 60 | Str.append({ '(', '?', 'b', 'y', 't', 'e', '*', '?', ')' }); break; 61 | } 62 | } 63 | 64 | void appendUConst( 65 | uint64_t C, bool IsSubscript, llvm::SmallVectorImpl &Str) { 66 | llvm::APInt Const(64, C, false); 67 | Const.toString(Str, 10, false); 68 | } 69 | 70 | 71 | void beginSubscript(llvm::SmallVectorImpl &Str) { 72 | Str.push_back('('); 73 | } 74 | 75 | void endSubscript(llvm::SmallVectorImpl &Str) { 76 | Str.push_back(')'); 77 | } 78 | }; 79 | } 80 | #endif//TSAR_FORTRAN_SOURCE_UNPARSER_H 81 | 82 | -------------------------------------------------------------------------------- /include/tsar/Support/AnalysisWrapperPass.h: -------------------------------------------------------------------------------- 1 | //===--- AnalysisWrapperPass.h - Analysis Results Wrapper -------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | //===----------------------------------------------------------------------===// 19 | // 20 | // This file implements a wrapper to simplify access to results of analysis 21 | // passes in case of wrapper and analysis pass are executed by different 22 | // pass managers. 23 | // 24 | //===----------------------------------------------------------------------===// 25 | 26 | #ifndef TSAR_ANALYSIS_WRAPPER_PASS_H 27 | #define TSAR_ANALYSIS_WRAPPER_PASS_H 28 | 29 | #include 30 | #include 31 | 32 | namespace llvm { 33 | /// \brief This wrapper provides access to a pass which has been executed early. 34 | /// 35 | /// For example, this is useful to access result of a module pass from a 36 | /// function pass manager. In this case module pass must be executed by 37 | /// an outer pass manager. Then a wrapper can be used to access this pass. 38 | /// It should be initialized (for example, using a pass provider) by a reference 39 | /// to the module pass or its result. 40 | template 41 | class AnalysisWrapperPass : public WrapperTy, private bcl::Uncopyable { 42 | public: 43 | /// Pass identification, replacement for typeid. 44 | static char ID; 45 | 46 | /// Default constructor. 47 | AnalysisWrapperPass() : WrapperTy(ID) { } 48 | 49 | /// Returns an underlying pass. 50 | AnalysisTy & get() noexcept { 51 | assert(mAnalysis && "Wrapped pass must be specified!"); 52 | return *mAnalysis; 53 | } 54 | 55 | /// Returns an underlying pass. 56 | const AnalysisTy & get() const noexcept { 57 | assert(mAnalysis && "Wrapped pass must be specified!"); 58 | return *mAnalysis; 59 | } 60 | 61 | /// Initializes this wrapper. 62 | void set(AnalysisTy &P) noexcept { mAnalysis = &P; } 63 | 64 | /// Returns true if this wrapper is initialized. 65 | operator bool() const noexcept { return mAnalysis != nullptr; } 66 | 67 | AnalysisTy & operator*() noexcept { return get(); } 68 | AnalysisTy * operator->() noexcept { return &operator *(); } 69 | const AnalysisTy & operator*() const noexcept { return get(); } 70 | const AnalysisTy * operator->() const noexcept { return &operator *(); } 71 | private: 72 | AnalysisTy *mAnalysis = nullptr; 73 | }; 74 | } 75 | #endif//TSAR_ANALYSIS_WRAPPER_PASS_H 76 | -------------------------------------------------------------------------------- /include/tsar/Support/Tags.h: -------------------------------------------------------------------------------- 1 | //===----- Tags.h --------------- List Of Tags ------------------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file defines tags to identify mark different objects. 22 | // 23 | //===----------------------------------------------------------------------===// 24 | 25 | #ifndef TSAR_SUPPORT_TAGS_H 26 | #define TSAR_SUPPORT_TAGS_H 27 | 28 | namespace llvm { 29 | class MDNode; 30 | } 31 | 32 | namespace tsar { 33 | /// This tag provides access to low-level representation of matched entities. 34 | struct IR {}; 35 | 36 | /// This tag provides access to source-level representation of matched entities. 37 | struct AST {}; 38 | 39 | /// This tag provides access to metadata-level representation of matched entities. 40 | struct MD {}; 41 | 42 | /// This tag is used to implement hierarchy of nodes. 43 | struct Hierarchy {}; 44 | 45 | /// This tag is used to implement a sequence of memory locations which may alias. 46 | struct Alias {}; 47 | 48 | /// This tag is used to implement a sequence of sibling nodes. 49 | struct Sibling {}; 50 | 51 | /// This tag is used to implement a sequence of nodes which is treated as a pool. 52 | struct Pool {}; 53 | 54 | /// This tag is used to provide access to a set of traits of a region. 55 | struct Region {}; 56 | 57 | /// This tag is used to provide access to entities related to a original object. 58 | struct Origin {}; 59 | 60 | /// This tag is used to provide access to entities related to a cloned object. 61 | struct Clone {}; 62 | 63 | /// This tag is used to represent the beginning of a range. 64 | struct Begin {}; 65 | 66 | /// This tag is used to represent a range end. 67 | struct End {}; 68 | 69 | /// This tag is used to represent step in a sequence of values. 70 | struct Step {}; 71 | 72 | /// This tag is used to provide access to a root object. 73 | struct Root {}; 74 | 75 | /// This tag is used to provide access to a description of a file. 76 | struct File {}; 77 | 78 | /// This tag is used to provide access to a description of a line. 79 | struct Line {}; 80 | 81 | /// This tag is used to provide access to a description of a column. 82 | struct Column {}; 83 | 84 | /// This tag is used to provide access to a description of an identifier. 85 | struct Identifier {}; 86 | 87 | /// Identifier of an object, for example, loops. 88 | using ObjectID = llvm::MDNode *; 89 | } 90 | #endif//TSAR_SUPPORT_TAGS_H 91 | -------------------------------------------------------------------------------- /include/tsar/Analysis/Clang/ExpressionMatcher.h: -------------------------------------------------------------------------------- 1 | //=== ExpressionMatcher.h - High and Low Level Expression Matcher*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // Classes and functions from this file match expressions in Clang AST and 22 | // appropriate expressions in low-level LLVM IR. This file implements 23 | // pass to perform this functionality. 24 | // 25 | //===----------------------------------------------------------------------===// 26 | 27 | #include "tsar/ADT/Bimap.h" 28 | #include "tsar/Analysis/Clang/Passes.h" 29 | #include "tsar/Support/Tags.h" 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #ifndef TSAR_CLANG_EXPRESSION_MATCHER_H 37 | #define TSAR_CLANG_EXPRESSION_MATCHER_H 38 | 39 | namespace tsar { 40 | class ClangTransformationContext; 41 | } 42 | 43 | namespace llvm { 44 | class Value; 45 | 46 | /// This per-function pass matches expressions in a source code (Clang AST) and 47 | /// appropriate expressions in low-level LLVM IR. 48 | /// 49 | /// At this moment only call expressions are processed. 50 | class ClangExprMatcherPass : 51 | public FunctionPass, private bcl::Uncopyable { 52 | public: 53 | using ExprMatcher = tsar::Bimap < 54 | bcl::tagged, 55 | bcl::tagged>; 56 | 57 | using ExprASTSet = llvm::DenseSet; 58 | 59 | static char ID; 60 | 61 | ClangExprMatcherPass() : FunctionPass(ID) { 62 | initializeClangExprMatcherPassPass(*PassRegistry::getPassRegistry()); 63 | } 64 | 65 | bool runOnFunction(Function &F) override; 66 | 67 | void getAnalysisUsage(AnalysisUsage &AU) const override; 68 | 69 | void releaseMemory() override { 70 | mTfmCtx = nullptr; 71 | mMatcher.clear(); 72 | mUnmatchedAST.clear(); 73 | } 74 | 75 | void print(raw_ostream &OS, const Module *M) const override; 76 | 77 | /// Returns expression matcher for the analyzed function. 78 | const ExprMatcher & getMatcher() const noexcept { return mMatcher; } 79 | 80 | /// Returns unmatched expressions in AST. 81 | const ExprASTSet & getUnmatchedAST() const noexcept { return mUnmatchedAST; } 82 | 83 | private: 84 | tsar::ClangTransformationContext *mTfmCtx{nullptr}; 85 | ExprMatcher mMatcher; 86 | ExprASTSet mUnmatchedAST; 87 | }; 88 | 89 | } 90 | 91 | #endif//TSAR_CLANG_EXPRESSION_MATCHER_H 92 | -------------------------------------------------------------------------------- /include/tsar/Transform/IR/Utils.h: -------------------------------------------------------------------------------- 1 | //===----- Utils.h -------- Utility Methods and Classes ---------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file defines helper methods for IR-level transformations. 22 | // 23 | //===----------------------------------------------------------------------===// 24 | 25 | #ifndef TSAR_TRANSFORM_IR_UTILS_H 26 | #define TSAR_TRANSFORM_IR_UTILS_H 27 | 28 | #include 29 | 30 | namespace llvm { 31 | class DominatorTree; 32 | class Instruction; 33 | class Use; 34 | } 35 | 36 | namespace tsar { 37 | /// Clone chain of instruction. 38 | /// 39 | /// All clones instruction will be pushed to the `CloneList`. If some of 40 | /// instructions can not be cloned the `CloneList` will not be updated. 41 | /// Clones will not be inserted into IR. The lowest clone sill be the first 42 | /// instruction which is pushed into the `CloneList`. 43 | /// 44 | /// If `BoundInst` and `DT` is `nullptr` the full use-def chain will be cloned 45 | /// (except Phi-nodes and alloca instructions). In case of Phi-nodes this method 46 | /// returns false (cloning is impossible). The lowest instruction in the cloned 47 | /// chain is `From`. If `BoundInst` and `DT` is specified instructions which 48 | /// dominate BoundInst will not be cloned. 49 | /// 50 | /// \return `true` on success, if instructions should not be cloned this 51 | /// function also returns `true`. 52 | bool cloneChain(llvm::Instruction *From, 53 | llvm::SmallVectorImpl &CloneList, 54 | llvm::Instruction *BoundInst = nullptr, llvm::DominatorTree *DT = nullptr); 55 | 56 | /// Traverses chains of operands of `From` instruction and performs a 57 | /// a search for operands which do not dominate a specified `BoundInstr`. 58 | /// 59 | /// This method if helpful when some instruction is cloned. Insertion 60 | /// of a clone into IR should be performed accurately. Because operands must be 61 | /// calculated before their uses. This functions can be used to determine 62 | /// operands that should be fixed (for example, also cloned). 63 | /// 64 | /// \return `true` if `From` does not dominate `BoundInst` (in this case NotDom 65 | /// will be empty), otherwise return `false` (`NotDom` will contain all 66 | /// instructions which have been found). 67 | bool findNotDom(llvm::Instruction *From, 68 | llvm::Instruction *BoundInst, llvm::DominatorTree *DT, 69 | llvm::SmallVectorImpl &NotDom); 70 | } 71 | 72 | #endif//TSAR_TRANSFORM_IR_UTILS_H 73 | -------------------------------------------------------------------------------- /include/tsar/Frontend/Clang/FrontendActions.h: -------------------------------------------------------------------------------- 1 | //===-- FrontendActions.h - Useful Frontend Actions -------------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file implements useful frontend actions. 22 | // 23 | //===----------------------------------------------------------------------===// 24 | 25 | #ifndef TSAR_FRONTEND_ACTIONS_H 26 | #define TSAR_FRONTEND_ACTIONS_H 27 | 28 | #include "tsar/Frontend/Clang/PragmaHandlers.h" 29 | #include 30 | 31 | namespace tsar { 32 | /// \brief This is an action which wraps other action. 33 | /// 34 | /// This is similar to `clang::WrapperFrontendAction` but implement public 35 | /// methods to access a wrapped action. 36 | /// \attention This manages wrapped action, so do not delete it outside 37 | /// this class. 38 | class PublicWrapperFrontendAction : public clang::WrapperFrontendAction { 39 | public: 40 | explicit PublicWrapperFrontendAction(clang::FrontendAction *WrappedAction) : 41 | clang::WrapperFrontendAction( 42 | std::unique_ptr(WrappedAction)), 43 | mWrappedAction(WrappedAction) {} 44 | 45 | clang::FrontendAction & getWrappedAction() noexcept { 46 | return *mWrappedAction; 47 | } 48 | const clang::FrontendAction & getWrappedAction() const noexcept { 49 | return *mWrappedAction; 50 | } 51 | private: 52 | clang::FrontendAction *mWrappedAction; 53 | }; 54 | 55 | /// This action is used to print AST. 56 | class ASTPrintAction : public clang::ASTFrontendAction { 57 | protected: 58 | std::unique_ptr CreateASTConsumer( 59 | clang::CompilerInstance &CI, llvm::StringRef InFile) override; 60 | }; 61 | 62 | /// This action is used to dump AST. 63 | class ASTDumpAction : public clang::ASTFrontendAction { 64 | protected: 65 | std::unique_ptr CreateASTConsumer( 66 | clang::CompilerInstance &CI, llvm::StringRef InFile) override; 67 | }; 68 | 69 | /// This action wraps other action and setups pragma handlers. 70 | class GenPCHPragmaAction : public PublicWrapperFrontendAction { 71 | public: 72 | GenPCHPragmaAction(std::unique_ptr WrappedAction) 73 | : PublicWrapperFrontendAction(WrappedAction.release()) {} 74 | 75 | bool BeginSourceFileAction(clang::CompilerInstance& CI) override; 76 | void EndSourceFileAction() override; 77 | private: 78 | llvm::SmallVector mNamespaces; 79 | clang::Preprocessor* mPP = nullptr; 80 | }; 81 | } 82 | #endif//TSAR_FRONTEND_ACTIONS_H 83 | -------------------------------------------------------------------------------- /include/tsar/Support/SCEVUtils.h: -------------------------------------------------------------------------------- 1 | //===--- SCEVUtils.h ----------- SCEV Utils ---------------------*- C++ -*-===// 2 | // 3 | // Traits Static Analyzer (SAPFOR) 4 | // 5 | // Copyright 2018 DVM System Group 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //===----------------------------------------------------------------------===// 20 | // 21 | // This file declares functions to evaluate SCEVs. 22 | // 23 | //===----------------------------------------------------------------------===// 24 | 25 | #ifndef TSAR_SCEV_UTILS_H 26 | #define TSAR_SCEV_UTILS_H 27 | 28 | #include 29 | #include 30 | 31 | namespace llvm { 32 | class ScalarEvolution; 33 | class SCEV; 34 | } 35 | 36 | namespace tsar { 37 | struct SCEVDivisionResult { 38 | const llvm::SCEV *Quotient; 39 | const llvm::SCEV *Remainder; 40 | bool IsSafeTypeCast; 41 | }; 42 | 43 | /// Computes the Quotient and Remainder of the division of Numerator by 44 | /// Denominator. If IsSafeTypeCast is `false` then type casts in SCEVs are 45 | /// ignored and divison may be incorrect. 46 | /// 47 | /// If some type casts have been ignored `IsSafeTypeCast` member of return 48 | /// value is set to `false`. 49 | SCEVDivisionResult divide(llvm::ScalarEvolution &SE, const llvm::SCEV *Numerator, 50 | const llvm::SCEV *Denominator, bool IsSafeTypeCast = true); 51 | 52 | /// Simplify a specified expression and transform it to AddRec expression if 53 | /// possible. 54 | /// 55 | /// This function uses unsafe type cast and may drop some truncate and extend 56 | /// operations or chnage order of theses operations. In this case the second 57 | /// returned value is `false`. 58 | std::pair computeSCEVAddRec( 59 | const llvm::SCEV *Expr, llvm::ScalarEvolution &SE); 60 | 61 | /// Find GCD for specified expressions. 62 | /// 63 | /// This function do not perform any simplification of expressions, except 64 | /// the following ones. 65 | /// (1) This splits AddRec expressions: A*I + B into two expressions A and B. 66 | /// (2) Each factor of a Mul expression is evaluated separately and may be a GCD. 67 | /// TODO (kaniandr@gmail.com): may be it is useful to perform factorization of 68 | /// constants? However, calculation of prime numbers may degrade performance. 69 | /// Note, that is seems that we also can not safely use Euclid algorithm. 70 | const llvm::SCEV* findGCD(llvm::ArrayRef Expressions, 71 | llvm::ScalarEvolution &SE, bool IsSafeTypeCast = true); 72 | 73 | /// Returns list of primes which is less or equal than a specified bound. 74 | /// 75 | /// This function implements Sieve of Atkin with cache. 76 | std::vector countPrimeNumbers(std::size_t Bound); 77 | } 78 | #endif//TSAR_SCEV_UTILS_H 79 | --------------------------------------------------------------------------------