Skip to content

Commit 79fc23f

Browse files
author
Johannes Doerfert
committed
Make getIslCompatibleName globaly available
llvm-svn: 213907
1 parent 08e1bbd commit 79fc23f

File tree

4 files changed

+41
-32
lines changed

4 files changed

+41
-32
lines changed

polly/include/polly/ScopInfo.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ class MemoryAccess {
106106
const Value *BaseAddr;
107107
std::string BaseName;
108108
isl_basic_map *createBasicAccessMap(ScopStmt *Statement);
109-
void setBaseName();
110109
ScopStmt *Statement;
111110

112111
/// @brief Reduction type for reduction like accesses, RT_NONE otherwise

polly/include/polly/Support/GICHelper.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include "isl/ctx.h"
1919
#include "llvm/Support/raw_ostream.h"
2020

21+
#include <string>
22+
2123
struct isl_map;
2224
struct isl_union_map;
2325
struct isl_set;
@@ -29,6 +31,10 @@ struct isl_aff;
2931
struct isl_pw_aff;
3032
struct isl_val;
3133

34+
namespace llvm {
35+
class Value;
36+
}
37+
3238
namespace polly {
3339
__isl_give isl_val *isl_valFromAPInt(isl_ctx *Ctx, const llvm::APInt Int,
3440
bool IsSigned);
@@ -58,6 +64,11 @@ inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
5864
OS << polly::stringFromIslObj(Map);
5965
return OS;
6066
}
67+
68+
/// @brief Return @p Prefix + @p Val->getName() + @p Suffix but Isl compatible.
69+
std::string getIslCompatibleName(std::string Prefix, const llvm::Value *Val,
70+
std::string Suffix);
71+
6172
} // end namespace polly
6273

6374
#endif

polly/lib/Analysis/ScopInfo.cpp

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -309,30 +309,6 @@ MemoryAccess::~MemoryAccess() {
309309
isl_map_free(newAccessRelation);
310310
}
311311

312-
static void replace(std::string &str, const std::string &find,
313-
const std::string &replace) {
314-
size_t pos = 0;
315-
while ((pos = str.find(find, pos)) != std::string::npos) {
316-
str.replace(pos, find.length(), replace);
317-
pos += replace.length();
318-
}
319-
}
320-
321-
static void makeIslCompatible(std::string &str) {
322-
str.erase(0, 1);
323-
replace(str, ".", "_");
324-
replace(str, "\"", "_");
325-
}
326-
327-
void MemoryAccess::setBaseName() {
328-
raw_string_ostream OS(BaseName);
329-
getBaseAddr()->printAsOperand(OS, false);
330-
BaseName = OS.str();
331-
332-
makeIslCompatible(BaseName);
333-
BaseName = "MemRef_" + BaseName;
334-
}
335-
336312
isl_map *MemoryAccess::getAccessRelation() const {
337313
return isl_map_copy(AccessRelation);
338314
}
@@ -424,7 +400,7 @@ MemoryAccess::MemoryAccess(const IRAccess &Access, const Instruction *AccInst,
424400
: Statement(Statement), Inst(AccInst), newAccessRelation(nullptr) {
425401

426402
BaseAddr = Access.getBase();
427-
setBaseName();
403+
BaseName = getIslCompatibleName("MemRef_", getBaseAddr(), "");
428404

429405
if (!Access.isAffine()) {
430406
// We overapproximate non-affine accesses with a possible access to the
@@ -809,12 +785,7 @@ ScopStmt::ScopStmt(Scop &parent, TempScop &tempScop, const Region &CurRegion,
809785
NestLoops[i] = Nest[i];
810786
}
811787

812-
raw_string_ostream OS(BaseName);
813-
bb.printAsOperand(OS, false);
814-
BaseName = OS.str();
815-
816-
makeIslCompatible(BaseName);
817-
BaseName = "Stmt_" + BaseName;
788+
BaseName = getIslCompatibleName("Stmt_", &bb, "");
818789

819790
Domain = buildDomain(tempScop, CurRegion);
820791
buildScattering(Scatter);

polly/lib/Support/GICHelper.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313
#include "polly/Support/GICHelper.h"
14+
#include "llvm/IR/Value.h"
1415
#include "isl/aff.h"
1516
#include "isl/map.h"
1617
#include "isl/schedule.h"
@@ -124,3 +125,30 @@ std::string polly::stringFromIslObj(__isl_keep isl_pw_aff *pwaff) {
124125
return stringFromIslObjInternal(pwaff, isl_pw_aff_get_ctx,
125126
isl_printer_print_pw_aff);
126127
}
128+
129+
static void replace(std::string &str, const std::string &find,
130+
const std::string &replace) {
131+
size_t pos = 0;
132+
while ((pos = str.find(find, pos)) != std::string::npos) {
133+
str.replace(pos, find.length(), replace);
134+
pos += replace.length();
135+
}
136+
}
137+
138+
static void makeIslCompatible(std::string &str) {
139+
replace(str, ".", "_");
140+
replace(str, "\"", "_");
141+
}
142+
143+
std::string polly::getIslCompatibleName(std::string Prefix, const Value *Val,
144+
std::string Suffix) {
145+
std::string ValStr;
146+
raw_string_ostream OS(ValStr);
147+
Val->printAsOperand(OS, false);
148+
ValStr = OS.str();
149+
// Remove the leading %
150+
ValStr.erase(0, 1);
151+
ValStr = Prefix + ValStr + Suffix;
152+
makeIslCompatible(ValStr);
153+
return ValStr;
154+
}

0 commit comments

Comments
 (0)