Skip to content

Commit 1cea25e

Browse files
committed
[Polly] Remove isConstCall.
The function was intended to catch OpenMP functions such as get_thread_id(). If matched, the call would be considered synthesizable. There were a few problems with this: * get_thread_id() is not 'const' in the sense of have the gcc manual defines it: "do not examine any values except their arguments". get_thread_id() reads OpenCL runtime libreary global state. What was inteded was probably 'speculable'. * isConstCall was implemented using mayReadOrWriteMemory(). 'const' is stricter than that, mayReadOrWriteMemory is e.g. true for malloc(), since it may only read/write addresses that are considered inaccessible fro the application. However, malloc is certainly not speculable. * Values that are isConstCall were not handled consistently throughout Polly. In particular, it was not considered for referenced values (OpenMP outlining and PollyACC). Fix by removing special handling for isConstCall entirely.
1 parent e21b0ba commit 1cea25e

File tree

6 files changed

+2
-304
lines changed

6 files changed

+2
-304
lines changed

polly/include/polly/Support/SCEVValidator.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,6 @@ class SCEVConstant;
2020
namespace polly {
2121
class ScopDetection;
2222

23-
/// Check if a call is side-effect free and has only constant arguments.
24-
///
25-
/// Such calls can be re-generated easily, so we do not need to model them
26-
/// as scalar dependences.
27-
///
28-
/// @param Call The call to check.
29-
bool isConstCall(llvm::CallInst *Call);
30-
31-
/// Check if some parameters in the affine expression might hide induction
32-
/// variables. If this is the case, we will try to delinearize the accesses
33-
/// taking into account this information to possibly obtain a memory access
34-
/// with more structure. Currently we assume that each parameter that
35-
/// comes from a function call might depend on a (virtual) induction variable.
36-
/// This covers calls to 'get_global_id' and 'get_local_id' as they commonly
37-
/// arise in OpenCL code, while not catching any false-positives in our current
38-
/// tests.
39-
bool hasIVParams(const llvm::SCEV *Expr);
40-
4123
/// Find the loops referenced from a SCEV expression.
4224
///
4325
/// @param Expr The SCEV expression to scan for loops.

polly/lib/Analysis/ScopDetection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,7 @@ bool ScopDetection::isValidAccess(Instruction *Inst, const SCEV *AF,
11341134
} else if (PollyDelinearize && !IsVariantInNonAffineLoop) {
11351135
Context.Accesses[BP].push_back({Inst, AF});
11361136

1137-
if (!IsAffine || hasIVParams(AF))
1137+
if (!IsAffine)
11381138
Context.NonAffineAccesses.insert(
11391139
std::make_pair(BP, LI.getLoopFor(Inst->getParent())));
11401140
} else if (!AllowNonAffine && !IsAffine) {

polly/lib/Analysis/ScopInfo.cpp

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,37 +1468,6 @@ const SCEV *Scop::getRepresentingInvariantLoadSCEV(const SCEV *E) const {
14681468
return SCEVSensitiveParameterRewriter::rewrite(E, *SE, InvEquivClassVMap);
14691469
}
14701470

1471-
// This table of function names is used to translate parameter names in more
1472-
// human-readable names. This makes it easier to interpret Polly analysis
1473-
// results.
1474-
StringMap<std::string> KnownNames = {
1475-
{"_Z13get_global_idj", "global_id"},
1476-
{"_Z12get_local_idj", "local_id"},
1477-
{"_Z15get_global_sizej", "global_size"},
1478-
{"_Z14get_local_sizej", "local_size"},
1479-
{"_Z12get_work_dimv", "work_dim"},
1480-
{"_Z17get_global_offsetj", "global_offset"},
1481-
{"_Z12get_group_idj", "group_id"},
1482-
{"_Z14get_num_groupsj", "num_groups"},
1483-
};
1484-
1485-
static std::string getCallParamName(CallInst *Call) {
1486-
std::string Result;
1487-
raw_string_ostream OS(Result);
1488-
std::string Name = Call->getCalledFunction()->getName().str();
1489-
1490-
auto Iterator = KnownNames.find(Name);
1491-
if (Iterator != KnownNames.end())
1492-
Name = "__" + Iterator->getValue();
1493-
OS << Name;
1494-
for (auto &Operand : Call->arg_operands()) {
1495-
ConstantInt *Op = cast<ConstantInt>(&Operand);
1496-
OS << "_" << Op->getValue();
1497-
}
1498-
OS.flush();
1499-
return Result;
1500-
}
1501-
15021471
void Scop::createParameterId(const SCEV *Parameter) {
15031472
assert(Parameters.count(Parameter));
15041473
assert(!ParameterIds.count(Parameter));
@@ -1507,11 +1476,8 @@ void Scop::createParameterId(const SCEV *Parameter) {
15071476

15081477
if (const SCEVUnknown *ValueParameter = dyn_cast<SCEVUnknown>(Parameter)) {
15091478
Value *Val = ValueParameter->getValue();
1510-
CallInst *Call = dyn_cast<CallInst>(Val);
15111479

1512-
if (Call && isConstCall(Call)) {
1513-
ParameterName = getCallParamName(Call);
1514-
} else if (UseInstructionNames) {
1480+
if (UseInstructionNames) {
15151481
// If this parameter references a specific Value and this value has a name
15161482
// we use this name as it is likely to be unique and more useful than just
15171483
// a number.

polly/lib/Support/SCEVValidator.cpp

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,6 @@ raw_ostream &operator<<(raw_ostream &OS, class ValidatorResult &VR) {
117117
return OS;
118118
}
119119

120-
bool polly::isConstCall(llvm::CallInst *Call) {
121-
if (Call->mayReadOrWriteMemory())
122-
return false;
123-
124-
for (auto &Operand : Call->arg_operands())
125-
if (!isa<ConstantInt>(&Operand))
126-
return false;
127-
128-
return true;
129-
}
130-
131120
/// Check if a SCEV is valid in a SCoP.
132121
struct SCEVValidator
133122
: public SCEVVisitor<SCEVValidator, class ValidatorResult> {
@@ -353,18 +342,6 @@ struct SCEVValidator
353342
return ValidatorResult(SCEVType::PARAM, S);
354343
}
355344

356-
ValidatorResult visitCallInstruction(Instruction *I, const SCEV *S) {
357-
assert(I->getOpcode() == Instruction::Call && "Call instruction expected");
358-
359-
if (R->contains(I)) {
360-
auto Call = cast<CallInst>(I);
361-
362-
if (!isConstCall(Call))
363-
return ValidatorResult(SCEVType::INVALID, S);
364-
}
365-
return ValidatorResult(SCEVType::PARAM, S);
366-
}
367-
368345
ValidatorResult visitLoadInstruction(Instruction *I, const SCEV *S) {
369346
if (R->contains(I) && ILS) {
370347
ILS->insert(cast<LoadInst>(I));
@@ -454,8 +431,6 @@ struct SCEVValidator
454431
return visitSDivInstruction(I, Expr);
455432
case Instruction::SRem:
456433
return visitSRemInstruction(I, Expr);
457-
case Instruction::Call:
458-
return visitCallInstruction(I, Expr);
459434
default:
460435
return visitGenericInst(I, Expr);
461436
}
@@ -470,34 +445,6 @@ struct SCEVValidator
470445
}
471446
};
472447

473-
class SCEVHasIVParams {
474-
bool HasIVParams = false;
475-
476-
public:
477-
SCEVHasIVParams() {}
478-
479-
bool follow(const SCEV *S) {
480-
const SCEVUnknown *Unknown = dyn_cast<SCEVUnknown>(S);
481-
if (!Unknown)
482-
return true;
483-
484-
CallInst *Call = dyn_cast<CallInst>(Unknown->getValue());
485-
486-
if (!Call)
487-
return true;
488-
489-
if (isConstCall(Call)) {
490-
HasIVParams = true;
491-
return false;
492-
}
493-
494-
return true;
495-
}
496-
497-
bool isDone() { return HasIVParams; }
498-
bool hasIVParams() { return HasIVParams; }
499-
};
500-
501448
/// Check whether a SCEV refers to an SSA name defined inside a region.
502449
class SCEVInRegionDependences {
503450
const Region *R;
@@ -515,11 +462,6 @@ class SCEVInRegionDependences {
515462
if (auto Unknown = dyn_cast<SCEVUnknown>(S)) {
516463
Instruction *Inst = dyn_cast<Instruction>(Unknown->getValue());
517464

518-
CallInst *Call = dyn_cast<CallInst>(Unknown->getValue());
519-
520-
if (Call && isConstCall(Call))
521-
return false;
522-
523465
if (Inst) {
524466
// When we invariant load hoist a load, we first make sure that there
525467
// can be no dependences created by it in the Scop region. So, we should
@@ -623,13 +565,6 @@ void findValues(const SCEV *Expr, ScalarEvolution &SE,
623565
ST.visitAll(Expr);
624566
}
625567

626-
bool hasIVParams(const SCEV *Expr) {
627-
SCEVHasIVParams HasIVParams;
628-
SCEVTraversal<SCEVHasIVParams> ST(HasIVParams);
629-
ST.visitAll(Expr);
630-
return HasIVParams.hasIVParams();
631-
}
632-
633568
bool hasScalarDepsInsideRegion(const SCEV *Expr, const Region *R,
634569
llvm::Loop *Scope, bool AllowLoops,
635570
const InvariantLoadsSetTy &ILS) {

polly/test/ScopInfo/constant_functions_as_unknowns.ll

Lines changed: 0 additions & 67 deletions
This file was deleted.

polly/test/ScopInfo/constant_functions_multi_dim.ll

Lines changed: 0 additions & 118 deletions
This file was deleted.

0 commit comments

Comments
 (0)