diff options
Diffstat (limited to 'polly/lib/Support/SCEVValidator.cpp')
-rw-r--r-- | polly/lib/Support/SCEVValidator.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/polly/lib/Support/SCEVValidator.cpp b/polly/lib/Support/SCEVValidator.cpp index 848357f5afb..0e159f42993 100644 --- a/polly/lib/Support/SCEVValidator.cpp +++ b/polly/lib/Support/SCEVValidator.cpp @@ -117,6 +117,17 @@ raw_ostream &operator<<(raw_ostream &OS, class ValidatorResult &VR) { return OS; } +bool polly::isConstCall(llvm::CallInst *Call) { + if (Call->mayReadOrWriteMemory()) + return false; + + for (auto &Operand : Call->arg_operands()) + if (!isa<ConstantInt>(&Operand)) + return false; + + return true; +} + /// Check if a SCEV is valid in a SCoP. struct SCEVValidator : public SCEVVisitor<SCEVValidator, class ValidatorResult> { @@ -306,6 +317,17 @@ public: return ValidatorResult(SCEVType::PARAM, S); } + ValidatorResult visitCallInstruction(Instruction *I, const SCEV *S) { + assert(I->getOpcode() == Instruction::Call && "Call instruction expected"); + + auto Call = cast<CallInst>(I); + + if (!isConstCall(Call)) + return ValidatorResult(SCEVType::INVALID, S); + + return ValidatorResult(SCEVType::PARAM, S); + } + ValidatorResult visitLoadInstruction(Instruction *I, const SCEV *S) { if (R->contains(I) && ILS) { ILS->insert(cast<LoadInst>(I)); @@ -396,6 +418,8 @@ public: return visitSDivInstruction(I, Expr); case Instruction::SRem: return visitSRemInstruction(I, Expr); + case Instruction::Call: + return visitCallInstruction(I, Expr); default: return visitGenericInst(I, Expr); } @@ -420,6 +444,11 @@ public: if (auto Unknown = dyn_cast<SCEVUnknown>(S)) { Instruction *Inst = dyn_cast<Instruction>(Unknown->getValue()); + CallInst *Call = dyn_cast<CallInst>(Unknown->getValue()); + + if (Call && isConstCall(Call)) + return false; + // Return true when Inst is defined inside the region R. if (!Inst || !R->contains(Inst)) return true; |