Skip to content

Commit 4ec125b

Browse files
committed
[TSAR, Transform] Create loop swapping tranformation.
1 parent d498eb8 commit 4ec125b

File tree

6 files changed

+682
-1
lines changed

6 files changed

+682
-1
lines changed

include/tsar/Support/Directives.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ def Replace : Clause<"replace", Transform,
126126

127127
def With : Clause<"with", Transform, [LParen, Identifier, RParen]>;
128128

129+
def SwapLoops: Clause<"swaploops", Transform>;
130+
129131
def Private : Clause<"private", Analysis,
130132
[LParen, Identifier, ZeroOrMore<[Comma, Identifier]>, RParen]>;
131133

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
//=== LoopSwapping.h - Loop Swapping (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+
// The file declares a pass to perform swapping of specific loops.
22+
//
23+
//===---------------------------------------------------------------------===//
24+
25+
#ifndef TSAR_CLANG_LOOP_SWAPPING_H
26+
#define TSAR_CLANG_LOOP_SWAPPING_H
27+
28+
#include "tsar/Support/Tags.h"
29+
#include "tsar/Transform/Clang/Passes.h"
30+
#include "tsar/Analysis/AnalysisServer.h"
31+
#include "tsar/Analysis/Memory/DIDependencyAnalysis.h"
32+
#include "tsar/Support/GlobalOptions.h"
33+
#include <bcl/utility.h>
34+
#include <llvm/Pass.h>
35+
36+
namespace tsar {
37+
class TransformationContext;
38+
class DIAliasNode;
39+
class DIAliasTree;
40+
class MemoryMatchInfo;
41+
}
42+
43+
namespace clang {
44+
class SourceRange;
45+
class Rewriter;
46+
}
47+
48+
namespace llvm {
49+
50+
class Loop;
51+
class MDNode;
52+
class GlobalsAAResult;
53+
54+
class ClangLoopSwapping : public FunctionPass, private bcl::Uncopyable {
55+
public:
56+
static char ID;
57+
58+
ClangLoopSwapping() : FunctionPass(ID) {
59+
initializeClangLoopSwappingPass(*PassRegistry::getPassRegistry());
60+
}
61+
bool runOnFunction(Function &F) override;
62+
void getAnalysisUsage(AnalysisUsage &AU) const override;
63+
void releaseMemory() override;
64+
65+
private:
66+
void initializeProviderOnClient(llvm::Module &M);
67+
void initializeProviderOnServer();
68+
69+
bool LoadDependenceAnalysisInfo(Function &F);
70+
void SwapLoops(const std::vector<std::vector<clang::SourceRange>> &mRangePairs,
71+
const std::vector<std::vector<Loop *>> &mLoopPairs);
72+
bool IsNoLoopID(llvm::MDNode *LoopID);
73+
std::vector<tsar::DIAliasNode *> GetLoopNodes(llvm::MDNode *LoopID);
74+
bool IsSwappingAvailable(std::vector<Loop *> loops);
75+
76+
tsar::TransformationContext *mTfmCtx = nullptr;
77+
tsar::DIDependencInfo *DIDepInfo = nullptr;
78+
tsar::DIAliasTree *DIAT = nullptr;
79+
const tsar::GlobalOptions *mGlobalOpts = nullptr;
80+
GlobalsAAResult * mGlobalsAA = nullptr;
81+
tsar::AnalysisSocket *mSocket = nullptr;
82+
tsar::MemoryMatchInfo *mMemoryMatcher = nullptr;
83+
std::function<tsar::ObjectID(tsar::ObjectID)> getLoopID;
84+
};
85+
86+
}
87+
88+
#endif//TSAR_CLANG_LOOP_SWAPPING_H

include/tsar/Transform/Clang/Passes.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,12 @@ ModulePass * createClangStructureReplacementPass();
9393
/// with separate variables.
9494
void initializeClangStructureReplacementPassPass(PassRegistry &Registry);
9595
}
96+
/// Creates a pass to perform swapping of loops.
97+
FunctionPass * createClangLoopSwapping();
98+
99+
/// Initializes a pass to perform swapping of loops.
100+
void initializeClangLoopSwappingPass(PassRegistry &Registry);
101+
102+
}
103+
96104
#endif//TSAR_CLANG_TRANSFORM_PASSES_H

lib/Transform/Clang/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
set(TRANSFORM_SOURCES Passes.cpp ExprPropagation.cpp Inline.cpp RenameLocal.cpp
22
DeadDeclsElimination.cpp FormatPass.cpp OpenMPAutoPar.cpp
3-
SharedMemoryAutoPar.cpp DVMHSMAutoPar.cpp StructureReplacement.cpp)
3+
SharedMemoryAutoPar.cpp DVMHSMAutoPar.cpp StructureReplacement.cpp
4+
LoopSwapping.cpp)
45

56
if(MSVC_IDE)
67
file(GLOB_RECURSE TRANSFORM_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}

0 commit comments

Comments
 (0)