From 60e85cbd9d703cf765b59af4e715b28c5a1c7523 Mon Sep 17 00:00:00 2001 From: Tobias Grosser Date: Mon, 7 Nov 2011 12:58:46 +0000 Subject: [PATCH] ScopDetection: Introduce methods to check attributes of ValidatorResult This simplifies e.g: if (Op.type == SCEVType::INT || Op.type == SCEVType::PARAM) to if (Op.isConstant()) llvm-svn: 143959 --- polly/lib/Analysis/ScopDetection.cpp | 38 ++++++++++++++++++---------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/polly/lib/Analysis/ScopDetection.cpp b/polly/lib/Analysis/ScopDetection.cpp index 45d445582b97..883fe2ceafca 100644 --- a/polly/lib/Analysis/ScopDetection.cpp +++ b/polly/lib/Analysis/ScopDetection.cpp @@ -124,6 +124,21 @@ struct ValidatorResult { ValidatorResult(SCEVType::TYPE type) : type(type) {}; + bool isConstant() { + return type == SCEVType::INT || type == SCEVType::PARAM; + } + + bool isValid() { + return type != SCEVType::INVALID; + } + + bool isIV() { + return type == SCEVType::IV; + } + + bool isINT() { + return type == SCEVType::INT; + } }; /// Check if a SCEV is valid in a SCoP. @@ -147,7 +162,7 @@ public: SCEVValidator Validator(R, SE, BaseAddress); ValidatorResult Result = Validator.visit(Scev); - return Result.type != SCEVType::INVALID; + return Result.isValid(); } SCEVValidator(const Region *R, ScalarEvolution &SE, @@ -164,7 +179,7 @@ public: // We currently do not represent a truncate expression as an affine // expression. If it is constant during Scop execution, we treat it as a // parameter, otherwise we bail out. - if (Op.type == SCEVType::INT || Op.type == SCEVType::PARAM) + if (Op.isConstant()) return ValidatorResult(SCEVType::PARAM); return ValidatorResult (SCEVType::INVALID); @@ -176,7 +191,7 @@ public: // We currently do not represent a zero extend expression as an affine // expression. If it is constant during Scop execution, we treat it as a // parameter, otherwise we bail out. - if (Op.type == SCEVType::INT || Op.type == SCEVType::PARAM) + if (Op.isConstant()) return ValidatorResult (SCEVType::PARAM); return ValidatorResult(SCEVType::INVALID); @@ -196,7 +211,7 @@ public: for (int i = 0, e = Expr->getNumOperands(); i < e; ++i) { ValidatorResult Op = visit(Expr->getOperand(i)); - if (Op.type == SCEVType::INVALID) + if (!Op.isValid()) return ValidatorResult(SCEVType::INVALID); Return.type = std::max(Return.type, Op.type); @@ -232,8 +247,7 @@ public: // We currently do not represent a unsigned devision as an affine // expression. If the division is constant during Scop execution we treat it // as a parameter, otherwise we bail out. - if (LHS.type == SCEVType::INT || LHS.type == SCEVType::PARAM || - RHS.type == SCEVType::INT || RHS.type == SCEVType::PARAM) + if (LHS.isConstant() && RHS.isConstant()) return ValidatorResult(SCEVType::PARAM); return ValidatorResult(SCEVType::INVALID); @@ -246,20 +260,18 @@ public: ValidatorResult Start = visit(Expr->getStart()); ValidatorResult Recurrence = visit(Expr->getStepRecurrence(SE)); - if (Start.type == SCEVType::INVALID || - Recurrence.type == SCEVType::INVALID || - Recurrence.type == SCEVType::IV) + if (!Start.isValid() || !Recurrence.isValid() || Recurrence.isIV()) return ValidatorResult(SCEVType::INVALID); if (!R->contains(Expr->getLoop())) { - if (Start.type == SCEVType::IV) + if (Start.isIV()) return ValidatorResult(SCEVType::INVALID); else return ValidatorResult(SCEVType::PARAM); } - if (Recurrence.type != SCEVType::INT) + if (!Recurrence.isINT()) return ValidatorResult(SCEVType::INVALID); return ValidatorResult(SCEVType::IV); @@ -271,7 +283,7 @@ public: for (int i = 0, e = Expr->getNumOperands(); i < e; ++i) { ValidatorResult Op = visit(Expr->getOperand(i)); - if (Op.type == SCEVType::INVALID) + if (!Op.isValid()) return ValidatorResult(SCEVType::INVALID); Return.type = std::max(Return.type, Op.type); @@ -286,7 +298,7 @@ public: for (int i = 0, e = Expr->getNumOperands(); i < e; ++i) { ValidatorResult Op = visit(Expr->getOperand(i)); - if (Op.type != SCEVType::INT && Op.type != SCEVType::PARAM) + if (!Op.isConstant()) return ValidatorResult(SCEVType::INVALID); }