Skip to content

Commit 629d786

Browse files
committed
???
1 parent 459c08b commit 629d786

File tree

7 files changed

+79
-9
lines changed

7 files changed

+79
-9
lines changed

include/tsar/Analysis/Memory/MemoryLocationRange.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,14 @@ struct MemoryLocationRange {
224224
return *this;
225225
assert(UpperBound.hasValue() && "UpperBound must have a value!");
226226
auto FullSize = UpperBound.getValue();;
227-
for (std::size_t I = 1; I < DimList.size(); ++I)
227+
for (std::size_t I = 0; I < DimList.size(); ++I)
228228
FullSize *= DimList[I].DimSize;
229+
if (FullSize == 0)
230+
return *this;
229231
return MemoryLocationRange(Ptr, 0, LocationSize(FullSize), AATags);
230232
}
233+
234+
void delinearize(const MemoryLocationRange &From);
231235
};
232236

233237
/// \brief Finds an intersection between memory locations LHS and RHS.

include/tsar/Transform/IR/Passes.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,11 @@ void initializeRedundantEdgeEliminationPassPass(PassRegistry &Registry);
114114
/// Create a pass that replaces the always true conditional branch
115115
/// instructions with an unconditional branch instruction.
116116
FunctionPass *createRedundantEdgeEliminationPass();
117+
118+
/// TODO
119+
void initializeArrayIndexExtenderPassPass(PassRegistry &Registry);
120+
121+
/// TODO
122+
Pass *createArrayIndexExtenderPass();
117123
}
118124
#endif//TSAR_IR_TRANSFORM_PASSES_H

lib/Analysis/Memory/DefinedMemory.cpp

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ std::pair<MemoryLocationRange, bool> aggregate(
278278
auto ArrayPtr = LocInfo.first;
279279
if (!ArrayPtr || !ArrayPtr->isDelinearized() || !LocInfo.second->isValid()) {
280280
//LLVM_DEBUG(dbgs() << "[AGGREGATE] Failed to delinearize location.\n");
281-
/*LLVM_DEBUG(
281+
LLVM_DEBUG(
282282
dbgs() << "[AGGREGATE] Failed to delinearize location: ";
283283
printLocationSource(dbgs(), Loc);
284284
dbgs() << ". Reason: ";
@@ -289,7 +289,54 @@ std::pair<MemoryLocationRange, bool> aggregate(
289289
else
290290
dbgs() << "!LocInfo.second->isValid()";
291291
dbgs() << "\n";
292-
);*/
292+
);
293+
294+
// for cases like: <lhs, 240, 248> (Default)
295+
// lhs[13][3][5][5]
296+
/*if (!ArrayPtr) {
297+
ArrayPtr = Fwk->getDelinearizeInfo()->findArray(Loc.Ptr, false);
298+
}
299+
auto Lower = Loc.LowerBound;
300+
auto Upper = Loc.UpperBound;
301+
if (ArrayPtr && Lower.hasValue() && Upper.hasValue()) {
302+
LLVM_DEBUG(dbgs() << "Check plain location: "; printLocationSource(dbgs(), Loc); dbgs() << "\n";);
303+
auto ArrayType{getPointerElementType(*ArrayPtr->getBase())};
304+
auto ArraySizeInfo = arraySize(ArrayType);
305+
if (ArraySizeInfo != std::make_tuple(0, 1, ArrayType)) {
306+
LLVM_DEBUG(dbgs() << "Here.1\n");
307+
auto LV = Lower.getValue();
308+
auto UV = Upper.getValue();
309+
auto ElemSize = Fwk->getDataLayout().getTypeStoreSize(
310+
std::get<2>(ArraySizeInfo)).getFixedSize();
311+
MemoryLocationRange FakeCollapsed;
312+
FakeCollapsed.Ptr = nullptr;
313+
FakeCollapsed.LowerBound = 0;
314+
FakeCollapsed.UpperBound = ElemSize;
315+
FakeCollapsed.SE = SE;
316+
FakeCollapsed.Kind = LocKind::Collapsed;
317+
auto DimN = ArrayPtr->getNumberOfDims();
318+
FakeCollapsed.DimList.resize(DimN);
319+
bool AreAllKnown = true;
320+
for (size_t I = 0; I < DimN; ++I) {
321+
auto DimSizeSCEV = ArrayPtr->getDimSize(I);
322+
if (ArrayPtr->isKnownDimSize(I) && isa<SCEVConstant>(DimSizeSCEV)) {
323+
auto &Dim = FakeCollapsed.DimList[I];
324+
Dim.DimSize = cast<SCEVConstant>(DimSizeSCEV)->getAPInt().getZExtValue();
325+
Dim.Start = Dim.End = Dim.Step = SE->getConstant(Type::getInt64Ty(SE->getContext()), 1);
326+
} else {
327+
AreAllKnown = false;
328+
break;
329+
}
330+
}
331+
if (AreAllKnown) {
332+
LLVM_DEBUG(dbgs() << "Here.2\n");
333+
ResLoc.delinearize(FakeCollapsed);
334+
LLVM_DEBUG(dbgs() << "After collapsing: "; printLocationSource(dbgs(), ResLoc); dbgs() << "\n";);
335+
return std::make_pair(ResLoc, true);
336+
}
337+
}
338+
LLVM_DEBUG(dbgs() << "Here.3\n");
339+
}*/
293340
ResLoc.Kind = LocKind::Default;
294341
return std::make_pair(ResLoc, true);
295342
}

lib/Analysis/Memory/MemoryLocationRange.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,11 @@ void printSolutionInfo(llvm::raw_ostream &OS,
183183
}
184184
}
185185
#endif
186+
}
186187

187-
void delinearize(const MemoryLocationRange &From, MemoryLocationRange &What) {
188+
void MemoryLocationRange::delinearize(const MemoryLocationRange &From) {
188189
typedef MemoryLocationRange::LocKind LocKind;
190+
auto &What = *this;
189191
assert(!(What.Kind & LocKind::Collapsed) &&
190192
"It is forbidden to delinearize collapsed location!");
191193
if (What.Kind & LocKind::NonCollapsable || !(From.Kind & LocKind::Collapsed))
@@ -258,6 +260,7 @@ void delinearize(const MemoryLocationRange &From, MemoryLocationRange &What) {
258260
What.AM = From.AM;
259261
}
260262

263+
namespace {
261264
llvm::Optional<MemoryLocationRange> intersectScalar(
262265
MemoryLocationRange LHS,
263266
MemoryLocationRange RHS,
@@ -1392,11 +1395,11 @@ llvm::Optional<MemoryLocationRange> intersect(
13921395
if (!(LHS.Kind & LocKind::Collapsed) &&
13931396
!(LHS.Kind & LocKind::NonCollapsable) &&
13941397
(RHS.Kind & LocKind::Collapsed))
1395-
delinearize(RHS, LHS);
1398+
LHS.delinearize(RHS);
13961399
if (!(RHS.Kind & LocKind::Collapsed) &&
13971400
!(RHS.Kind & LocKind::NonCollapsable) &&
13981401
(LHS.Kind & LocKind::Collapsed))
1399-
delinearize(LHS, RHS);
1402+
RHS.delinearize(LHS);
14001403
if (!(LHS.Kind & LocKind::Collapsed) && !(RHS.Kind & LocKind::Collapsed))
14011404
return intersectScalar(LHS, RHS, LC, RC);
14021405
if (!(LHS.Kind & LocKind::Collapsed) || !(RHS.Kind & LocKind::Collapsed))
@@ -1407,8 +1410,9 @@ llvm::Optional<MemoryLocationRange> intersect(
14071410
LHS.DimList == RHS.DimList)
14081411
return LHS;
14091412
MemoryLocationRange Int(LHS);
1410-
assert(LHS.SE && RHS.SE && LHS.SE == RHS.SE &&
1411-
"ScalarEvolution must be specified!");
1413+
assert(LHS.SE && RHS.SE && "ScalarEvolution must be specified!");
1414+
if (LHS.SE != RHS.SE)
1415+
return MemoryLocationRange();
14121416
auto SE = LHS.SE;
14131417
for (std::size_t I = 0; I < LHS.DimList.size(); ++I) {
14141418
auto &Left = LHS.DimList[I];

lib/Core/Query.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ void addAfterLoopRotateAnalysis(legacy::PassManager &Passes) {
223223
Passes.add(createCallExtractorPass());
224224
Passes.add(createRedundantEdgeEliminationPass());
225225
Passes.add(createUnreachableBlockEliminationPass());
226+
Passes.add(createArrayIndexExtenderPass());
226227
Passes.add(createGlobalDefinedMemoryPass());
227228
Passes.add(createGlobalLiveMemoryPass());
228229
Passes.add(createFunctionMemoryAttrsAnalysis());

lib/Core/Tool.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ struct Options : private bcl::Uncopyable {
178178
llvm::cl::OptionCategory TransformCategory;
179179
llvm::cl::opt<bool> NoFormat;
180180
llvm::cl::opt<std::string> OutputSuffix;
181+
llvm::cl::opt<bool> ExtendArrayIndex;
182+
llvm::cl::opt<bool> NoExtendArrayIndex;
183+
181184
private:
182185
/// Default constructor.
183186
///
@@ -338,6 +341,10 @@ Options::Options() :
338341
TransformCategory("Transformation options"),
339342
NoFormat("no-format", cl::cat(TransformCategory),
340343
cl::desc("Disable format of transformed sources")),
344+
ExtendArrayIndex("fextend-array-index", cl::cat(TransformCategory),
345+
cl::desc("Convert array indices to int64_t type")),
346+
NoExtendArrayIndex("fno-extend-array-index", cl::cat(TransformCategory),
347+
cl::desc("Do not convert array indices to int64_t type")),
341348
OutputSuffix("output-suffix", cl::cat(TransformCategory), cl::value_desc("suffix"),
342349
cl::desc("Filename suffix (between name and extension) for transformed sources")) {
343350
StringMap<cl::Option*> &Opts = cl::getRegisteredOptions();

lib/Transform/IR/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 DeadCodeElimination.cpp InterprocAttr.cpp
22
MetadataUtils.cpp Utils.cpp CallExtractor.cpp DependenceInliner.cpp
3-
NoCaptureAnalysis.cpp PointerScalarizer.cpp RedundantEdgeElimination.cpp)
3+
NoCaptureAnalysis.cpp PointerScalarizer.cpp RedundantEdgeElimination.cpp
4+
ArrayIndexExtender.cpp)
45

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

0 commit comments

Comments
 (0)