Skip to content

Loop Distribution #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 93 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
092c22c
[TSAR, Tfm, Clang, Replace] Fix, check for simple references to a str…
kaniandr Mar 7, 2022
2c859a7
[TSAR, Tfm, Clang, Replace] Add support for not arrow dereference exp…
kaniandr Mar 8, 2022
7af2c8f
[TSAR, Tfm, Struct, Replace] Implement replacement of an array of str…
kaniandr Mar 16, 2022
8f7bba2
[TSAR, Pragma] Update representation of pragmas to support identifier…
kaniandr Mar 16, 2022
d8d75ac
[TSAR, Tfm, Replace, Struct] Implement replacement of parameters pass…
kaniandr Mar 16, 2022
720813d
[TSAR, Tfm, Struct, Replace] Implement replacement of local variables…
kaniandr Mar 18, 2022
c76f9a0
[TSAR, Anls, Include, Clang] Do not process files twice.
kaniandr Mar 20, 2022
b4222c6
[TSAR, Anls, Include, Clang] Fix, trivial.
kaniandr Mar 20, 2022
6699571
[TSAR, Clang, Tfm, Replace] Allow using of a default constructor to i…
kaniandr Mar 20, 2022
81558bc
[TSAR, Clang, Tfm, Replace] Fix GCC compilation errors.
kaniandr Mar 20, 2022
a3396df
[TSAR, Tfm, Clang, Replace] Allow the pass to replace macro arguments.
kaniandr Mar 20, 2022
f0d3872
[TSAR, Clang, Tfm, Replace] Fix, disable `InAssignment` flag if an ob…
kaniandr Mar 20, 2022
56867d2
[TSAR, Tfm, Replace, Clang] Replace an actual argument if it is a par…
kaniandr Mar 20, 2022
8204226
[TSAR, APC, Parallel] Implement parallelization of loops without dist…
kaniandr Mar 30, 2022
61514d5
[TSAR, APC, Functions] Fix, ignore unknown locations of instructions.
kaniandr Mar 30, 2022
ba217ef
[TSAR, Clang, Match, Expr] Fix, process the `address of` unary operator.
kaniandr Apr 1, 2022
8f498f0
[TSAR, Anls, Read] Ignore artificial variables while loading external…
kaniandr Apr 10, 2022
a4524e8
[TSAR, Dep, Metadata] Existance of self-copying instructions does not…
kaniandr Apr 10, 2022
6b205e5
[TSAR, DVMH, Parallel] Fix, enclose negative constants in brackets.
kaniandr Apr 17, 2022
084f951
[TSAR, APC, Loop] Fix, do not take into account unreachable exits fro…
kaniandr Apr 17, 2022
8447c47
[TSAR, APC] Fix, some loops in a nest may not have known induction va…
kaniandr Apr 17, 2022
5ec8ace
[TSAR, DI, Dep] Fix, ignore dependencies which have been already unse…
kaniandr Apr 17, 2022
90853fe
[TSAR, Parallel] Allow parallelization of loops that have multiple un…
kaniandr Apr 17, 2022
8020f25
[TSAR, IR, Ptr2Reg] Initial implementation of pointer promotion.
kaniandr Apr 17, 2022
2330778
[TSAR, IR, Utils] Fix, trivial.
kaniandr Apr 22, 2022
493dce9
[TSAR, Metadata, Utils] Move an auxiliary function to the global scope.
kaniandr Apr 26, 2022
0f1563b
[TSAR, Attr, IPO] Use llvm `willreturn` attribute to set `sapfor.alwa…
kaniandr Apr 26, 2022
5f698ea
[TSAR, Memory, Dep] Add a new loop trait to specify variables which a…
kaniandr Apr 26, 2022
4037622
[TSAR, IR, Ptr2Reg] Major update of ptr2reg pass and dependence analy…
kaniandr Apr 26, 2022
595c6ce
[TSAR, LLVM, 15.0] Migrate to LLVM 15.0.
kaniandr Apr 29, 2022
43d645f
[TSAR, Tool] Invoke LLVM IR processing action directly.
kaniandr Apr 30, 2022
5f5cd7a
[TSAR, Core, Frontend] Integration with Flang, implement in a way sim…
kaniandr May 4, 2022
83b986e
[TSAR, Match, Expr] Fix, trivial.
kaniandr May 5, 2022
e7aa372
[TSAR, Flang, IR] Update DICompileUnit for a module if it has not bee…
kaniandr May 6, 2022
60f5b4f
[TSAR, Flang, Frontend] Fix, set missing option to force the parser t…
kaniandr May 8, 2022
6408f56
[TSAR, Flang, Frontend] Update metadata for functions while it is not…
kaniandr May 8, 2022
072d2e9
[TSAR, Flang, Frontend] Store reference to an AST-based representatio…
kaniandr May 6, 2022
ad1193d
[TSAR, Tfm, Flang, RegVar] Add pass to register variables.
kaniandr May 8, 2022
c742592
[TSAR, CMake, Flang, Win] Enable building of Flang as a part of SAPFO…
kaniandr May 27, 2022
19095ab
[TSAR, CMake, Flang] Fix, trivial.
kaniandr May 27, 2022
aa717aa
[TSAR, Clang, Frontend] Compute mangled names directly to store corre…
kaniandr May 30, 2022
61130d8
[TSAR, AST] Implement base for Flang and Clang matchers in a similar …
kaniandr May 31, 2022
7a37ff3
[TSAR, Flang] Add initial implementation of expression matcher.
kaniandr May 31, 2022
6c97436
[TSAR, Tfm, Mixed] Fix, trivial.
kaniandr Jun 2, 2022
2118236
[TSAR, Tfm, Flang, Mixed] Add metadata for variables marked with `sap…
kaniandr May 9, 2022
f9bf384
[TSAR, Tfm, IR] Fix, avoid infinite loop.
kaniandr Jun 2, 2022
ea16564
[TSAR, Utils, Memory] Extend supported instruction chains which lead …
kaniandr Jul 19, 2022
356b16e
[TSAR, Utils, IR] Add function to reveal type of an opaque pointer.
kaniandr Jul 19, 2022
c5a05ab
[TSAR, Delinearize] Try to reestablish omitted zero subscripts for co…
kaniandr Jul 19, 2022
d10bbce
[TSAR, Memory, MD] Add support for 'after pointer' size for metadata-…
kaniandr Jul 19, 2022
ea1d0f3
[TSAR, AliasTree, Print] Fix, trivial.
kaniandr Jul 19, 2022
e1bb694
[TSAR, Unparser] Avoid empty names.
kaniandr Jul 19, 2022
b071e04
[TSAR, Unparser] Distinguish string representation of locations with …
kaniandr Jul 19, 2022
ffeeb89
[TSAR, Memory] Fix, unknown size comparison.
kaniandr Jul 19, 2022
7cc8883
[TSAR, APC] Fix, trivial.
kaniandr Jul 19, 2022
259c4cb
[TSAR, Utils] Fix, overcome error in sys::fs::TempFile move operator.
kaniandr Jul 19, 2022
59e1fdf
[TSAR, Merge] Fix, trivial.
kaniandr Jul 19, 2022
502d074
[TSAR, Memory] Add support for opaque pointers.
kaniandr Jul 19, 2022
9733718
[TSAR] Fix, trivial, migrate to LLVM 15.
kaniandr Jul 19, 2022
de0f08b
[TSAR, Intrinsics] Add support for new experimental LLVM memory intri…
kaniandr Jul 19, 2022
1b54b5f
[TSAR, Dep] Fix output, trivial.
kaniandr Jul 20, 2022
2c92591
[TSAR, Dep, Reduction] Set necessary flags to analyze floating point …
kaniandr Jul 20, 2022
fa6ebd1
[TSAR, Parallel] Fix, specialize cast operations for parallelization …
kaniandr Jul 20, 2022
af9380d
[TSAR, Dep, AddressAccess] Do not collect impossible address accesses.
kaniandr Jul 20, 2022
18a8ad6
[TSAR, Memory] Fix, check that locations to compare start at the same…
kaniandr Jul 20, 2022
b822ab5
[TSAR, AliasTree] Fix, find the nearest alias node to find insertion …
kaniandr Jul 20, 2022
3d4318e
[TSAR, CMake] Fix, names of LLVM libraries.
kaniandr Jul 20, 2022
5f1a10c
[TSAR, AliasTree] Fix, try to accurately estimate size of locations a…
kaniandr Jul 20, 2022
f99728e
[TSAR, Inline] Do not try to promote corrupted locations after functi…
kaniandr Jul 20, 2022
2c1d847
[TSAR, Reduction, Question] Is it correct to consider FMulAdd reducti…
kaniandr Jul 20, 2022
45354f1
[TSAR, Memory, Delinearize] Fix, do not use 'alloca' to represent a s…
kaniandr Jul 22, 2022
af3cb63
[TSAR, Flang, Tfm] Fix, do not crash on error.
kaniandr Jul 22, 2022
3061fcd
[TSAR, Clang, Tfm, Propagate] Fix, take into account stripped ending …
kaniandr Jul 22, 2022
4a8f17c
[TSAR, Tool] Fix, language for prcompiled sources is unknown in a cur…
kaniandr Jul 22, 2022
ea75a74
[TSAR, Memory, Server] Fix, use data from client if a function is not…
kaniandr Jul 22, 2022
b6b471a
[TSAR, Distribution] Initialize pass that will do loop distribution.
wlllle Dec 27, 2020
9f1b30a
[TSAR, Distribution] Refactor constructor of ASTVisitor.
wlllle Dec 27, 2020
f910f85
[TSAR, Distribution] Get split instructions
wlllle Jan 16, 2021
b864c8a
[TSAR, InstructionMatcher] Initialize AST--IR matcher
wlllle Mar 1, 2021
d5a01d8
{Tsar, InstructionMatcher} Remove unnecessary InstructionMatcher
wlllle May 5, 2021
6ccf56a
[TSAR, InstructionMatcher] Rename variables, add const modifier.
wlllle May 8, 2021
063d3c1
[TSAR, Distribution] Add debug information, refactor.
wlllle May 9, 2021
47009b5
[TSAR, Distribution] Pick out funcionality of getting splits.
wlllle May 10, 2021
78f6b65
[TSAR, Distribution] Use ClangExprMatcherPass to get AST node of split.
wlllle May 11, 2021
7389608
tmp
wlllle May 25, 2021
712df31
add rewriter work
wlllle May 31, 2021
73d5d64
Get splitter string
wlllle Aug 7, 2021
ac3988b
Use single ASTVisitor
wlllle Aug 22, 2021
719b9ba
Move out dependence check method
wlllle Aug 29, 2021
ee9783c
Insert header in correct location
wlllle Aug 29, 2021
ebe3daf
Fix null reference exception
wlllle Aug 23, 2022
6302034
Fix trivial
wlllle Aug 26, 2022
af8ce9b
Fix compilation on llvm 15
wlllle Aug 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 51 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.4.3)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

project(TSAR VERSION 0.0.0 LANGUAGES CXX)
project(TSAR VERSION 0.0.0 LANGUAGES C CXX)

if(SAPFOR_VERSION)
set(TSAR_VERSION ${SAPFOR_VERSION})
Expand Down Expand Up @@ -97,18 +97,21 @@ cmake_dependent_option(BUILD_LLC "Build LLVM IR static compiler" OFF
"NOT PACKAGE_LLVM" OFF)
cmake_dependent_option(BUILD_LINK "Build LLVM bitcode linker" OFF
"NOT PACKAGE_LLVM" OFF)
cmake_dependent_option(BUILD_FLANG "Build LLVM native Fortran compiler Flang" OFF UNIX OFF)
cmake_dependent_option(BUILD_FLANG "Build LLVM native Fortran compiler Flang" OFF
"NOT PACKAGE_LLVM" OFF)

option(TSAR_ENABLE_LLVM_DUMP "Enable use of dump() method for LLVM types" ON)

set(LLVM_SOURCE_DIR "${LLVM_PROJECT_DIR}/llvm")
set(CLANG_SOURCE_DIR "${LLVM_PROJECT_DIR}/clang")
set(FLANG_SOURCE_DIR "${LLVM_PROJECT_DIR}/flang")
set(MLIR_SOURCE_DIR "${LLVM_PROJECT_DIR}/mlir")
set(COMPILER_RT_SOURCE_DIR "${LLVM_PROJECT_DIR}/compiler-rt")

set(LLVM_BINARY_DIR "${CMAKE_BINARY_DIR}/llvm-build")
set(CLANG_BINARY_DIR "${LLVM_BINARY_DIR}/tools/clang")
set(FLANG_BINARY_DIR "${LLVM_BINARY_DIR}/tools/flang")
set(MLIR_BINARY_DIR "${LLVM_BINARY_DIR}/tools/mlir")

set(FLANG_FOUND OFF)

Expand All @@ -117,6 +120,7 @@ if(PACKAGE_LLVM)
set(LLVM_SOURCE_DIR "${LLVM_BINARY_DIR}/include/llvm")
set(CLANG_SOURCE_DIR "${LLVM_BINARY_DIR}/include/clang")
set(FLANG_SOURCE_DIR "${LLVM_BINARY_DIR}/include/flang")
set(MLIR_SOURCE_DIR "${LLVM_BINARY_DIR}/include/mlir")
set(CLANG_INCLUDE_DIR "${LLVM_BINARY_DIR}/lib/clang/${LLVM_VERSION}/include")
set(CLANG_EXECUTABLE "${LLVM_BINARY_DIR}/bin/clang${CMAKE_EXECUTABLE_SUFFIX}")
if (EXISTS ${FLANG_SOURCE_DIR})
Expand Down Expand Up @@ -144,14 +148,17 @@ else()
if (BUILD_FLANG AND NOT EXISTS ${FLANG_SOURCE_DIR})
message(FATAL_ERROR "FLANG_SOURCE_DIR '${FLANG_SOURCE_DIR}' does not exist")
endif()
if (BUILD_FLANG AND NOT EXISTS ${MLIR_SOURCE_DIR})
message(FATAL_ERROR "MLIR_SOURCE_DIR '${MLIR_SOURCE_DIR}' does not exist")
endif()
if (BUILD_PROFILE AND NOT EXISTS ${COMPILER_RT_SOURCE_DIR})
message(FATAL_ERROR "COMPILER_RT_SOURCE_DIR '${COMPILER_RT_SOURCE_DIR}' does not exist")
endif()
set(LLVM_STATUS "Configuring LLVM project")
message(STATUS ${LLVM_STATUS})
set(LLVM_PROJECTS clang)
if (BUILD_FLANG)
set(LLVM_PROJECTS ${LLVM_PROJECTS} flang)
set(LLVM_PROJECTS ${LLVM_PROJECTS} flang mlir)
endif()
if (BUILD_PROFILE)
set(LLVM_PROJECTS ${LLVM_PROJECTS} compiler-rt)
Expand Down Expand Up @@ -205,7 +212,7 @@ message(STATUS ${LLVM_STATUS})
set(LLVM_COMPONENTS
analysis asmparser bitreader core instrumentation irreader scalaropts support
tablegen target transformutils coverage mcparser option debuginfodwarf
frontendopenacc)
frontendopenacc lto windowsdriver)

llvm_map_components_to_libnames(LLVM_LIBS ${LLVM_COMPONENTS})

Expand All @@ -226,7 +233,28 @@ set(CLANG_LIBS

if(FLANG_FOUND)
set(FLANG_LIBS
FortranSemantics FortranEvaluate FortranParser FortranDecimal FortranCommon)
flangFrontend FortranLower FortranSemantics FortranEvaluate FortranParser
FortranDecimal FortranCommon FIRCodeGen FIRTransforms FIRBuilder
FIRDialect FIRSupport MLIROpenMPToLLVM MLIROpenMPToLLVMIRTranslation
MLIRLLVMToLLVMIRTranslation MLIROpenACCDialect MLIROpenMPDialect
MLIRSCFToControlFlow MLIRFuncToLLVM MLIRArithmeticToLLVM MLIRControlFlowToLLVM
MLIRTargetLLVMIRExport MLIRDLTIDialect MLIRLLVMIRTransforms MLIRMemRefToLLVM
MLIRParser MLIRSCFDialect MLIRBufferizationDialect MLIRAffineDialect
MLIRVectorDialect MLIRMemRefDialect MLIRVectorInterfaces MLIRLLVMCommonConversion
MLIRTransforms MLIRLLVMDialect MLIRFuncDialect MLIRControlFlowDialect
MLIRTensorDialect MLIRArithmeticUtils MLIRComplexDialect
MLIRArithmeticDialect MLIRDialectUtils MLIRTransformUtils MLIRRewrite
MLIRPDLToPDLInterp MLIRPDLInterpDialect MLIRPDLDialect MLIRPass MLIRAnalysis
MLIRCallInterfaces MLIRControlFlowInterfaces MLIRInferTypeOpInterface
MLIRSideEffectInterfaces MLIRDataLayoutInterfaces MLIRViewLikeInterface
MLIRInferIntRangeInterface MLIRIR MLIRSupport)
include(TestBigEndian)
test_big_endian(IS_BIGENDIAN)
if (IS_BIGENDIAN)
add_compile_definitions(FLANG_BIG_ENDIAN=1)
else()
add_compile_definitions(FLANG_LITTLE_ENDIAN=1)
endif()
endif()

if(NOT PACKAGE_LLVM)
Expand All @@ -235,7 +263,21 @@ if(NOT PACKAGE_LLVM)
endif()
if(NOT PACKAGE_LLVM AND FLANG_FOUND)
list(APPEND LLVM_INCLUDE_DIRS
${FLANG_SOURCE_DIR}/include ${FLANG_BINARY_DIR}/include)
${FLANG_SOURCE_DIR}/include ${FLANG_BINARY_DIR}/include
${MLIR_SOURCE_DIR}/include ${MLIR_BINARY_DIR}/include)
# TODO: LLVM specify include directories relative to build path, however
# in case of SAPFOR build path is not a build path for LLVM.
# Hence we manually add correct include directories for Flang libraries.
target_include_directories(obj.FIRBuilder SYSTEM PRIVATE ${LLVM_INCLUDE_DIRS})
target_include_directories(obj.FIRCodeGen SYSTEM PRIVATE ${LLVM_INCLUDE_DIRS})
target_include_directories(obj.FIRDialect SYSTEM PRIVATE ${LLVM_INCLUDE_DIRS})
target_include_directories(obj.FIRSupport SYSTEM PRIVATE ${LLVM_INCLUDE_DIRS})
target_include_directories(obj.FIRTransforms SYSTEM PRIVATE ${LLVM_INCLUDE_DIRS})
target_include_directories(obj.flangFrontend SYSTEM PRIVATE ${LLVM_INCLUDE_DIRS})
target_include_directories(obj.flangFrontendTool SYSTEM PRIVATE ${LLVM_INCLUDE_DIRS})
target_include_directories(obj.FortranLower SYSTEM PRIVATE ${LLVM_INCLUDE_DIRS})
target_include_directories(obj.FortranEvaluate SYSTEM PRIVATE ${LLVM_INCLUDE_DIRS})
target_include_directories(flang-new SYSTEM PRIVATE ${LLVM_INCLUDE_DIRS})
endif()
include_directories(${LLVM_INCLUDE_DIRS})

Expand Down Expand Up @@ -284,6 +326,9 @@ if (MSVC)
add_compile_options("/MD")
endif()
endif()
if (MSVC_VERSION GREATER_EQUAL 1920)
add_compile_options("/Zc:__cplusplus")
endif()
endif()

foreach(C ${CMAKE_CONFIGURATION_TYPES})
Expand Down
2 changes: 1 addition & 1 deletion cmake/llvm-utility.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ macro(sapfor_install_llvm)
endif()

if(BUILD_FLANG)
add_external_tool(FLANG_BUILD flang)
add_external_tool(FLANG_BUILD flang-new)
endif()

if(BUILD_PROFILE)
Expand Down
4 changes: 2 additions & 2 deletions include/tsar/ADT/PersistentIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <type_traits>

namespace llvm {
template<class T> struct DenseMapInfo;
template<typename T, typename Enable> struct DenseMapInfo;
}

namespace tsar {
Expand Down Expand Up @@ -119,7 +119,7 @@ class NotPersistentIterator {
template<class PersistentT, class MapT>
class PersistentIteratorC {
friend struct PersistentValueWrapper<PersistentT, MapT>;
friend struct llvm::DenseMapInfo<PersistentIteratorC>;
friend struct llvm::DenseMapInfo<PersistentIteratorC, void>;
using NotPersistentIteratorC = NotPersistentIterator<true, PersistentT, MapT>;
protected:
using PersistentBucket = typename MapT::value_type;
Expand Down
155 changes: 155 additions & 0 deletions include/tsar/Analysis/AST/Matcher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
//===-- Matcher.h --------- High and Low Level Matcher ----------*- C++ -*-===//
//
// Traits Static Analyzer (SAPFOR)
//
// Copyright 2022 DVM System Group
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//
//===----------------------------------------------------------------------===//
//
// This file defines general classes and functions to match some entities
// (loops, variables, etc.) in a source high-level code and appropriate entities
// (loops, allocas, etc.) in low-level LLVM IR.
//
//===----------------------------------------------------------------------===//

#ifndef TSAR_MATCHER_H
#define TSAR_MATCHER_H

#include "tsar/ADT/Bimap.h"
#include "tsar/Support/DILocationMapInfo.h"
#include "tsar/Support/Tags.h"
#include "tsar/Support/MetadataUtils.h"
#include <llvm/ADT/DenseMap.h>
#include <llvm/ADT/SmallString.h>
#include <llvm/ADT/Statistic.h>
#include <llvm/ADT/TinyPtrVector.h>
#include <llvm/IR/DebugInfoMetadata.h>

namespace tsar {
/// This is a base class which is inherited to match different entities (loops,
/// variables, etc.).
///
/// The ImplTy class must inherit this class and implement following methods:
/// - typename LocToIRMap::iterator findItrForLocation(ASTLocationTy Loc);
/// - PresumedLocationTy getPresumedLocation(RawLocationTy Loc);
/// Note, that tsar::PresumedLocationInfo<...> template must be specialized for
/// the PresumedLocationTy type.
template<typename ImplTy, typename IRItemTy, typename ASTItemTy,
typename ASTLocationTy,
typename IRLocationTy = llvm::DILocation *,
typename IRLocationMapInfo = DILocationMapInfo,
typename RawLocationTy = std::size_t,
typename RawLocationMapInfo = llvm::DenseMapInfo<RawLocationTy>,
typename MatcherTy = Bimap<
bcl::tagged<ASTItemTy, AST>, bcl::tagged<IRItemTy, IR>>,
typename UnmatchedASTSetTy = llvm::DenseSet<ASTItemTy>>
class MatchASTBase {
public:
using Matcher = MatcherTy;

using UnmatchedASTSet = UnmatchedASTSetTy;

/// This is a map from entity location to a queue of IR entities.
using LocToIRMap =
llvm::DenseMap<IRLocationTy,
std::conditional_t<std::is_pointer_v<IRItemTy>,
llvm::TinyPtrVector<IRItemTy>,
llvm::SmallVector<IRItemTy, 1>>,
IRLocationMapInfo>;

/// This is a map from location in a source file to an queue of AST
/// entities, which are associated with this location.
///
/// The key in this map is a raw encoding for location.
using LocToASTMap =
llvm::DenseMap<RawLocationTy,
std::conditional_t<std::is_pointer_v<ASTItemTy>,
llvm::TinyPtrVector<ASTItemTy>,
llvm::SmallVector<ASTItemTy, 1>>,
RawLocationMapInfo>;

/// \brief Constructor.
///
/// \param[in, out] M Representation of match.
/// \param[in, out] UM Storage for unmatched ast entities.
/// \param[in, out] LocToIR Map from entity location to a queue
/// of IR entities.
/// \param[in, out] LocToMacro A map form entity expansion location to a queue
/// of AST entities. All entities explicitly (not implicit loops) defined in
/// macros is going to store in this map. The key in this map is a raw
/// encoding for expansion location.
MatchASTBase(Matcher &M, UnmatchedASTSet &UM,
LocToIRMap &LocToIR, LocToASTMap &LocToMacro) :
mMatcher(&M), mUnmatchedAST(&UM),
mLocToIR(&LocToIR), mLocToMacro(&LocToMacro) {}

/// Finds low-level representation of an entity at the specified location.
///
/// \return LLVM IR for an entity or `nullptr`.
IRItemTy findIRForLocation(ASTLocationTy Loc) {
auto LocItr = static_cast<ImplTy *>(this)->findItrForLocation(Loc);
if (LocItr == mLocToIR->end())
return nullptr;
auto Res = LocItr->second.back();
LocItr->second.pop_back();
return Res;
}

/// Evaluates entities located in macros.
///
/// This matches entities from mLocToMacro and mLocToIR. It is recommended
/// to evaluate at first all entities outside macros and then consider macros
/// separately.
///
/// \param [in] Strict If it is true, macros, containing exactly a single
/// item, are processed.
void matchInMacro(llvm::Statistic &NumMatch, llvm::Statistic &NumNonMatchAST,
llvm::Statistic &NumNonMatchIR, bool Strict = false) {
for (auto &InMacro : *mLocToMacro) {
auto PLoc{static_cast<ImplTy *>(this)->getPresumedLoc(InMacro.first)};
auto IREntityItr = mLocToIR->find_as(PLoc);
// If sizes of queues of AST and IR entities are not equal this is mean
// that there are implicit entities (for example, implicit loops) in
// a macro. Such entities are not going to be evaluated due to necessity
// of additional analysis of AST.
if (IREntityItr == mLocToIR->end() ||
IREntityItr->second.size() != InMacro.second.size() ||
Strict && InMacro.second.size() > 1) {
NumNonMatchAST += InMacro.second.size();
while (!InMacro.second.empty()) {
mUnmatchedAST->insert(InMacro.second.back());
InMacro.second.pop_back();
}
} else {
NumMatch += InMacro.second.size();
NumNonMatchIR -= InMacro.second.size();
while (!InMacro.second.empty()) {
mMatcher->emplace(InMacro.second.back(), IREntityItr->second.back());
InMacro.second.pop_back();
IREntityItr->second.pop_back();
}
}
}
}

protected:
Matcher *mMatcher;
UnmatchedASTSet *mUnmatchedAST;
LocToIRMap *mLocToIR;
LocToASTMap *mLocToMacro;
};
}
#endif//TSAR_MATCHER_H
4 changes: 2 additions & 2 deletions include/tsar/Analysis/AnalysisServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class AnalysisResponsePass : public ModulePass, private bcl::Uncopyable {
WaitForRequest = false;
return { tsar::AnalysisSocket::Notify };
}
json::Parser<tsar::AnalysisRequest> Parser(Request);
::json::Parser<tsar::AnalysisRequest> Parser(Request);
tsar::AnalysisRequest R;
if (!Parser.parse(R)) {
llvm_unreachable("Unknown request: listen for analysis request!");
Expand Down Expand Up @@ -332,7 +332,7 @@ class AnalysisResponsePass : public ModulePass, private bcl::Uncopyable {
}
}
return tsar::AnalysisSocket::Data +
json::Parser<tsar::AnalysisResponse>::unparseAsObject(Response);
::json::Parser<tsar::AnalysisResponse>::unparseAsObject(Response);
}))
;
return false;
Expand Down
6 changes: 3 additions & 3 deletions include/tsar/Analysis/AnalysisSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class AnalysisSocket final : public SMStringSocketBase<AnalysisSocket> {
/// analysis pass. A `nullptr` could be encoded with empty string.
void processResponse(const std::string &Response) const {
llvm::StringRef Json(Response.data() + 1, Response.size() - 2);
json::Parser<AnalysisResponse> Parser(Json.str());
::json::Parser<AnalysisResponse> Parser(Json.str());
AnalysisResponse R;
if (!Parser.parse(R))
mAnalysis.clear();
Expand All @@ -103,7 +103,7 @@ class AnalysisSocket final : public SMStringSocketBase<AnalysisSocket> {
R[AnalysisRequest::Function] = nullptr;
bcl::TypeList<AnalysisType...>::for_each_type(PushBackAnalysisID{R});
auto Request =
json::Parser<AnalysisRequest>::unparseAsObject(R) + Delimiter;
::json::Parser<AnalysisRequest>::unparseAsObject(R) + Delimiter;
for (auto &Callback : mReceiveCallbacks)
Callback(Request);
// Note, that callback run send() in client, so mAnalysisPass is already
Expand All @@ -130,7 +130,7 @@ class AnalysisSocket final : public SMStringSocketBase<AnalysisSocket> {
R[AnalysisRequest::Function] = &F;
bcl::TypeList<AnalysisType...>::for_each_type(PushBackAnalysisID{R});
auto Request =
json::Parser<AnalysisRequest>::unparseAsObject(R) + Delimiter;
::json::Parser<AnalysisRequest>::unparseAsObject(R) + Delimiter;
for (auto &Callback : mReceiveCallbacks)
Callback(Request);
// Note, that callback run send() in client, so mAnalysisPass is already
Expand Down
6 changes: 3 additions & 3 deletions include/tsar/Analysis/Clang/ExpressionMatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
#include <llvm/ADT/DenseSet.h>
#include <llvm/Pass.h>

#ifndef TSAR_EXPRESSION_MATCHER_H
#define TSAR_EXPRESSION_MATCHER_H
#ifndef TSAR_CLANG_EXPRESSION_MATCHER_H
#define TSAR_CLANG_EXPRESSION_MATCHER_H

namespace tsar {
class ClangTransformationContext;
Expand Down Expand Up @@ -88,4 +88,4 @@ class ClangExprMatcherPass :

}

#endif//TSAR_EXPRESSION_MATCHER_H
#endif//TSAR_CLANG_EXPRESSION_MATCHER_H
6 changes: 3 additions & 3 deletions include/tsar/Analysis/Clang/IncludeTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class FileNode {
iterator() = default;
iterator(ChildrenT::iterator I)
: iterator_adaptor_base(std::move(I)) {}
ChildT &operator*() { return this->I->first; }
ChildT &operator*() const { return this->I->first; }
};

using iterator_range = llvm::iterator_range<iterator>;
Expand Down Expand Up @@ -211,10 +211,10 @@ class FileTree {
public:
iterator_impl() = default;

FileNode::ChildT & operator*() {
FileNode::ChildT & operator*() const {
return FileNode::isDecl(*mRootItr) ? *mRootItr : **mChildItr;
}
FileNode::ChildT * operator->() { return &operator*(); }
FileNode::ChildT * operator->() const { return &operator*(); }

iterator &operator++() {
if (FileNode::isDecl(*mRootItr)) {
Expand Down
Loading