[Polly] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).

llvm-svn: 311802
This commit is contained in:
Eugene Zelenko 2017-08-25 21:35:27 +00:00
parent f42bd31323
commit a32707d5b1
7 changed files with 330 additions and 284 deletions

View File

@ -11,20 +11,22 @@
//
//===----------------------------------------------------------------------===//
#ifndef POLLY_ANALYSIS_PRUNEUNPROFITABLE_H
#define POLLY_ANALYSIS_PRUNEUNPROFITABLE_H
#ifndef POLLY_PRUNEUNPROFITABLE_H
#define POLLY_PRUNEUNPROFITABLE_H
namespace llvm {
class PassRegistry;
class Pass;
class PassRegistry;
void initializePruneUnprofitablePass(PassRegistry &);
} // namespace llvm
namespace polly {
llvm::Pass *createPruneUnprofitablePass();
} // namespace polly
namespace llvm {
void initializePruneUnprofitablePass(llvm::PassRegistry &);
} // namespace llvm
#endif /* POLLY_ANALYSIS_PRUNEUNPROFITABLE_H */
#endif // POLLY_PRUNEUNPROFITABLE_H

View File

@ -1,4 +1,4 @@
//===--- ScopDetection.h - Detect Scops -------------------------*- C++ -*-===//
//===- ScopDetection.h - Detect Scops ---------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@ -44,38 +44,58 @@
//
//===----------------------------------------------------------------------===//
#ifndef POLLY_SCOP_DETECTION_H
#define POLLY_SCOP_DETECTION_H
#ifndef POLLY_SCOPDETECTION_H
#define POLLY_SCOPDETECTION_H
#include "polly/ScopDetectionDiagnostic.h"
#include "polly/Support/ScopHelper.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/AliasSetTracker.h"
#include "llvm/Analysis/OptimizationDiagnosticInfo.h"
#include "llvm/Analysis/RegionInfo.h"
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
#include "llvm/Pass.h"
#include <algorithm>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace llvm;
namespace llvm {
class LoopInfo;
class BasicBlock;
class BranchInst;
class CallInst;
class DebugLoc;
class DominatorTree;
class Function;
class Instruction;
class IntrinsicInst;
class Loop;
class LoopInfo;
class OptimizationRemarkEmitter;
class PassRegistry;
class raw_ostream;
class ScalarEvolution;
class SCEV;
class SCEVAddRecExpr;
class SCEVUnknown;
class CallInst;
class Instruction;
class SwitchInst;
class Value;
class IntrinsicInst;
void initializeScopDetectionWrapperPassPass(PassRegistry &);
} // namespace llvm
namespace polly {
typedef std::set<const SCEV *> ParamSetType;
using ParamSetType = std::set<const SCEV *>;
// Description of the shape of an array.
struct ArrayShape {
@ -85,7 +105,7 @@ struct ArrayShape {
// Sizes of each delinearized dimension.
SmallVector<const SCEV *, 4> DelinearizedSizes;
ArrayShape(const SCEVUnknown *B) : BasePointer(B), DelinearizedSizes() {}
ArrayShape(const SCEVUnknown *B) : BasePointer(B) {}
};
struct MemAcc {
@ -98,14 +118,14 @@ struct MemAcc {
SmallVector<const SCEV *, 4> DelinearizedSubscripts;
MemAcc(const Instruction *I, std::shared_ptr<ArrayShape> S)
: Insn(I), Shape(S), DelinearizedSubscripts() {}
: Insn(I), Shape(S) {}
};
typedef std::map<const Instruction *, MemAcc> MapInsnToMemAcc;
typedef std::pair<const Instruction *, const SCEV *> PairInstSCEV;
typedef std::vector<PairInstSCEV> AFs;
typedef std::map<const SCEVUnknown *, AFs> BaseToAFs;
typedef std::map<const SCEVUnknown *, const SCEV *> BaseToElSize;
using MapInsnToMemAcc = std::map<const Instruction *, MemAcc>;
using PairInstSCEV = std::pair<const Instruction *, const SCEV *>;
using AFs = std::vector<PairInstSCEV>;
using BaseToAFs = std::map<const SCEVUnknown *, AFs>;
using BaseToElSize = std::map<const SCEVUnknown *, const SCEV *>;
extern bool PollyTrackFailures;
extern bool PollyDelinearize;
@ -116,14 +136,14 @@ extern bool PollyAllowUnsignedOperations;
extern bool PollyAllowFullFunction;
/// A function attribute which will cause Polly to skip the function
extern llvm::StringRef PollySkipFnAttr;
extern StringRef PollySkipFnAttr;
//===----------------------------------------------------------------------===//
/// Pass to detect the maximal static control parts (Scops) of a
/// function.
class ScopDetection {
public:
typedef SetVector<const Region *> RegionSet;
using RegionSet = SetVector<const Region *>;
// Remember the valid regions
RegionSet ValidRegions;
@ -151,13 +171,13 @@ public:
BaseToElSize ElementSize;
/// The region has at least one load instruction.
bool hasLoads;
bool hasLoads = false;
/// The region has at least one store instruction.
bool hasStores;
bool hasStores = false;
/// Flag to indicate the region has at least one unknown access.
bool HasUnknownAccess;
bool HasUnknownAccess = false;
/// The set of non-affine subregions in the region we analyze.
RegionSet NonAffineSubRegionSet;
@ -174,8 +194,7 @@ public:
/// Initialize a DetectionContext from scratch.
DetectionContext(Region &R, AliasAnalysis &AA, bool Verify)
: CurRegion(R), AST(AA), Verifying(Verify), Log(&R), hasLoads(false),
hasStores(false), HasUnknownAccess(false) {}
: CurRegion(R), AST(AA), Verifying(Verify), Log(&R) {}
/// Initialize a DetectionContext with the data from @p DC.
DetectionContext(const DetectionContext &&DC)
@ -495,7 +514,7 @@ private:
/// Check if the function @p F is marked as invalid.
///
/// @note An OpenMP subfunction will be marked as invalid.
bool isValidFunction(llvm::Function &F);
bool isValidFunction(Function &F);
/// Can ISL compute the trip count of a loop.
///
@ -506,7 +525,7 @@ private:
bool canUseISLTripCount(Loop *L, DetectionContext &Context) const;
/// Print the locations of all detected scops.
void printLocations(llvm::Function &F);
void printLocations(Function &F);
/// Check if a region is reducible or not.
///
@ -569,8 +588,8 @@ public:
/// These iterators iterator over all maximum region in Scops of this
/// function.
//@{
typedef RegionSet::iterator iterator;
typedef RegionSet::const_iterator const_iterator;
using iterator = RegionSet::iterator;
using const_iterator = RegionSet::const_iterator;
iterator begin() { return ValidRegions.begin(); }
iterator end() { return ValidRegions.end(); }
@ -617,15 +636,20 @@ public:
struct ScopAnalysis : public AnalysisInfoMixin<ScopAnalysis> {
static AnalysisKey Key;
using Result = ScopDetection;
ScopAnalysis();
Result run(Function &F, FunctionAnalysisManager &FAM);
};
struct ScopAnalysisPrinterPass : public PassInfoMixin<ScopAnalysisPrinterPass> {
ScopAnalysisPrinterPass(raw_ostream &O) : Stream(O) {}
ScopAnalysisPrinterPass(raw_ostream &OS) : OS(OS) {}
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
raw_ostream &Stream;
raw_ostream &OS;
};
struct ScopDetectionWrapperPass : public FunctionPass {
@ -633,23 +657,19 @@ struct ScopDetectionWrapperPass : public FunctionPass {
std::unique_ptr<ScopDetection> Result;
ScopDetectionWrapperPass();
/// @name FunctionPass interface
//@{
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
virtual void releaseMemory();
virtual bool runOnFunction(Function &F);
virtual void print(raw_ostream &OS, const Module *) const;
void getAnalysisUsage(AnalysisUsage &AU) const override;
void releaseMemory() override;
bool runOnFunction(Function &F) override;
void print(raw_ostream &OS, const Module *) const override;
//@}
ScopDetection &getSD() { return *Result; }
const ScopDetection &getSD() const { return *Result; }
};
} // end namespace polly
} // namespace polly
namespace llvm {
class PassRegistry;
void initializeScopDetectionWrapperPassPass(llvm::PassRegistry &);
} // namespace llvm
#endif
#endif // POLLY_SCOPDETECTION_H

View File

@ -1,4 +1,4 @@
//=== ScopDetectionDiagnostic.h -- Diagnostic for ScopDetection -*- C++ -*-===//
//===- ScopDetectionDiagnostic.h - Diagnostic for ScopDetection -*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@ -17,29 +17,32 @@
// to diagnose the error and generate a helpful error message.
//
//===----------------------------------------------------------------------===//
#ifndef POLLY_SCOP_DETECTION_DIAGNOSTIC_H
#define POLLY_SCOP_DETECTION_DIAGNOSTIC_H
#ifndef POLLY_SCOPDETECTIONDIAGNOSTIC_H
#define POLLY_SCOPDETECTIONDIAGNOSTIC_H
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/AliasSetTracker.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/OptimizationDiagnosticInfo.h"
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Value.h"
#include "llvm/Support/Casting.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/IR/Instruction.h"
#include <cstddef>
#include <memory>
#include <string>
#include <utility>
#include <vector>
using namespace llvm;
namespace llvm {
class SCEV;
class AliasSet;
class BasicBlock;
class Value;
class OptimizationRemarkEmitter;
class raw_ostream;
class Region;
class SCEV;
class Value;
} // namespace llvm
namespace polly {
@ -54,6 +57,7 @@ BBPair getBBPairForRegion(const Region *R);
void getDebugLocations(const BBPair &P, DebugLoc &Begin, DebugLoc &End);
class RejectLog;
/// Emit optimization remarks about the rejected regions to the user.
///
/// This emits the content of the reject log as optimization remarks.
@ -111,7 +115,6 @@ enum class RejectReasonKind {
/// diagnostic information to help clients figure out what and where something
/// went wrong in the Scop detection.
class RejectReason {
//===--------------------------------------------------------------------===//
private:
const RejectReasonKind Kind;
@ -119,11 +122,11 @@ protected:
static const DebugLoc Unknown;
public:
RejectReasonKind getKind() const { return Kind; }
RejectReason(RejectReasonKind K);
virtual ~RejectReason() {}
virtual ~RejectReason() = default;
RejectReasonKind getKind() const { return Kind; }
/// Generate the remark name to identify this remark.
///
@ -153,20 +156,20 @@ public:
/// Get the source location of this error.
///
/// @return The debug location for this error.
virtual const llvm::DebugLoc &getDebugLoc() const;
virtual const DebugLoc &getDebugLoc() const;
};
typedef std::shared_ptr<RejectReason> RejectReasonPtr;
using RejectReasonPtr = std::shared_ptr<RejectReason>;
/// Stores all errors that occurred during the detection.
class RejectLog {
Region *R;
llvm::SmallVector<RejectReasonPtr, 1> ErrorReports;
SmallVector<RejectReasonPtr, 1> ErrorReports;
public:
explicit RejectLog(Region *R) : R(R) {}
typedef llvm::SmallVector<RejectReasonPtr, 1>::const_iterator iterator;
using iterator = SmallVector<RejectReasonPtr, 1>::const_iterator;
iterator begin() const { return ErrorReports.begin(); }
iterator end() const { return ErrorReports.end(); }
@ -189,7 +192,6 @@ public:
/// Scop candidates that violate structural restrictions can be grouped under
/// this reject reason class.
class ReportCFG : public RejectReason {
//===--------------------------------------------------------------------===//
public:
ReportCFG(const RejectReasonKind K);
@ -215,10 +217,10 @@ public:
/// @name RejectReason interface
//@{
virtual std::string getRemarkName() const override;
virtual const Value *getRemarkBB() const override;
virtual std::string getMessage() const override;
virtual const DebugLoc &getDebugLoc() const override;
std::string getRemarkName() const override;
const Value *getRemarkBB() const override;
std::string getMessage() const override;
const DebugLoc &getDebugLoc() const override;
//@}
};
@ -239,11 +241,11 @@ public:
/// @name RejectReason interface
//@{
virtual std::string getRemarkName() const override;
virtual const Value *getRemarkBB() const override;
virtual std::string getMessage() const override;
virtual std::string getEndUserMessage() const override;
virtual const DebugLoc &getDebugLoc() const override;
std::string getRemarkName() const override;
const Value *getRemarkBB() const override;
std::string getMessage() const override;
std::string getEndUserMessage() const override;
const DebugLoc &getDebugLoc() const override;
//@}
};
@ -265,11 +267,11 @@ public:
/// @name RejectReason interface
//@{
virtual std::string getRemarkName() const override;
virtual const Value *getRemarkBB() const override;
virtual std::string getMessage() const override;
virtual std::string getEndUserMessage() const override;
virtual const DebugLoc &getDebugLoc() const override;
std::string getRemarkName() const override;
const Value *getRemarkBB() const override;
std::string getMessage() const override;
std::string getEndUserMessage() const override;
const DebugLoc &getDebugLoc() const override;
//@}
};
@ -279,8 +281,6 @@ public:
/// Scop candidates that violate restrictions to affinity are reported under
/// this class.
class ReportAffFunc : public RejectReason {
//===--------------------------------------------------------------------===//
protected:
// The instruction that caused non-affinity to occur.
const Instruction *Inst;
@ -295,17 +295,13 @@ public:
/// @name RejectReason interface
//@{
virtual const DebugLoc &getDebugLoc() const override {
return Inst->getDebugLoc();
}
const DebugLoc &getDebugLoc() const override { return Inst->getDebugLoc(); }
//@}
};
//===----------------------------------------------------------------------===//
/// Captures a condition that is based on an 'undef' value.
class ReportUndefCond : public ReportAffFunc {
//===--------------------------------------------------------------------===//
// The BasicBlock we found the broken condition in.
BasicBlock *BB;
@ -320,9 +316,9 @@ public:
/// @name RejectReason interface
//@{
virtual std::string getRemarkName() const override;
virtual const Value *getRemarkBB() const override;
virtual std::string getMessage() const override;
std::string getRemarkName() const override;
const Value *getRemarkBB() const override;
std::string getMessage() const override;
//@}
};
@ -331,8 +327,6 @@ public:
///
/// Conditions have to be either constants or icmp instructions.
class ReportInvalidCond : public ReportAffFunc {
//===--------------------------------------------------------------------===//
// The BasicBlock we found the broken condition in.
BasicBlock *BB;
@ -347,17 +341,15 @@ public:
/// @name RejectReason interface
//@{
virtual std::string getRemarkName() const override;
virtual const Value *getRemarkBB() const override;
virtual std::string getMessage() const override;
std::string getRemarkName() const override;
const Value *getRemarkBB() const override;
std::string getMessage() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// Captures an undefined operand.
class ReportUndefOperand : public ReportAffFunc {
//===--------------------------------------------------------------------===//
// The BasicBlock we found the undefined operand in.
BasicBlock *BB;
@ -372,17 +364,15 @@ public:
/// @name RejectReason interface
//@{
virtual std::string getRemarkName() const override;
virtual const Value *getRemarkBB() const override;
virtual std::string getMessage() const override;
std::string getRemarkName() const override;
const Value *getRemarkBB() const override;
std::string getMessage() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// Captures a non-affine branch.
class ReportNonAffBranch : public ReportAffFunc {
//===--------------------------------------------------------------------===//
// The BasicBlock we found the non-affine branch in.
BasicBlock *BB;
@ -408,16 +398,15 @@ public:
/// @name RejectReason interface
//@{
virtual std::string getRemarkName() const override;
virtual const Value *getRemarkBB() const override;
virtual std::string getMessage() const override;
std::string getRemarkName() const override;
const Value *getRemarkBB() const override;
std::string getMessage() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// Captures a missing base pointer.
class ReportNoBasePtr : public ReportAffFunc {
//===--------------------------------------------------------------------===//
public:
ReportNoBasePtr(const Instruction *Inst)
: ReportAffFunc(RejectReasonKind::NoBasePtr, Inst) {}
@ -429,16 +418,15 @@ public:
/// @name RejectReason interface
//@{
virtual std::string getRemarkName() const override;
virtual const Value *getRemarkBB() const override;
virtual std::string getMessage() const override;
std::string getRemarkName() const override;
const Value *getRemarkBB() const override;
std::string getMessage() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// Captures an undefined base pointer.
class ReportUndefBasePtr : public ReportAffFunc {
//===--------------------------------------------------------------------===//
public:
ReportUndefBasePtr(const Instruction *Inst)
: ReportAffFunc(RejectReasonKind::UndefBasePtr, Inst) {}
@ -450,17 +438,15 @@ public:
/// @name RejectReason interface
//@{
virtual std::string getRemarkName() const override;
virtual const Value *getRemarkBB() const override;
virtual std::string getMessage() const override;
std::string getRemarkName() const override;
const Value *getRemarkBB() const override;
std::string getMessage() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// Captures a base pointer that is not invariant in the region.
class ReportVariantBasePtr : public ReportAffFunc {
//===--------------------------------------------------------------------===//
// The variant base pointer.
Value *BaseValue;
@ -476,18 +462,16 @@ public:
/// @name RejectReason interface
//@{
virtual std::string getRemarkName() const override;
virtual const Value *getRemarkBB() const override;
virtual std::string getMessage() const override;
virtual std::string getEndUserMessage() const override;
std::string getRemarkName() const override;
const Value *getRemarkBB() const override;
std::string getMessage() const override;
std::string getEndUserMessage() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// Captures a non-affine access function.
class ReportNonAffineAccess : public ReportAffFunc {
//===--------------------------------------------------------------------===//
// The non-affine access function.
const SCEV *AccessFunction;
@ -509,18 +493,16 @@ public:
/// @name RejectReason interface
//@{
virtual std::string getRemarkName() const override;
virtual const Value *getRemarkBB() const override;
virtual std::string getMessage() const override;
virtual std::string getEndUserMessage() const override;
std::string getRemarkName() const override;
const Value *getRemarkBB() const override;
std::string getMessage() const override;
std::string getEndUserMessage() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// Report array accesses with differing element size.
class ReportDifferentArrayElementSize : public ReportAffFunc {
//===--------------------------------------------------------------------===//
// The base pointer of the memory access.
const Value *BaseValue;
@ -536,18 +518,16 @@ public:
/// @name RejectReason interface
//@{
virtual std::string getRemarkName() const override;
virtual const Value *getRemarkBB() const override;
virtual std::string getMessage() const override;
virtual std::string getEndUserMessage() const override;
std::string getRemarkName() const override;
const Value *getRemarkBB() const override;
std::string getMessage() const override;
std::string getEndUserMessage() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// Captures errors with non affine loop bounds.
class ReportLoopBound : public RejectReason {
//===--------------------------------------------------------------------===//
// The offending loop.
Loop *L;
@ -569,19 +549,17 @@ public:
/// @name RejectReason interface
//@{
virtual std::string getRemarkName() const override;
virtual const Value *getRemarkBB() const override;
virtual std::string getMessage() const override;
virtual const DebugLoc &getDebugLoc() const override;
virtual std::string getEndUserMessage() const override;
std::string getRemarkName() const override;
const Value *getRemarkBB() const override;
std::string getMessage() const override;
const DebugLoc &getDebugLoc() const override;
std::string getEndUserMessage() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// Captures errors when loop has no exit.
class ReportLoopHasNoExit : public RejectReason {
//===--------------------------------------------------------------------===//
/// The loop that has no exit.
Loop *L;
@ -599,19 +577,17 @@ public:
/// @name RejectReason interface
//@{
virtual std::string getRemarkName() const override;
virtual const Value *getRemarkBB() const override;
virtual std::string getMessage() const override;
virtual const DebugLoc &getDebugLoc() const override;
virtual std::string getEndUserMessage() const override;
std::string getRemarkName() const override;
const Value *getRemarkBB() const override;
std::string getMessage() const override;
const DebugLoc &getDebugLoc() const override;
std::string getEndUserMessage() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// Captures errors when not all loop latches are part of the scop.
class ReportLoopOnlySomeLatches : public RejectReason {
//===--------------------------------------------------------------------===//
/// The loop for which not all loop latches are part of the scop.
Loop *L;
@ -629,19 +605,17 @@ public:
/// @name RejectReason interface
//@{
virtual std::string getRemarkName() const override;
virtual const Value *getRemarkBB() const override;
virtual std::string getMessage() const override;
virtual const DebugLoc &getDebugLoc() const override;
virtual std::string getEndUserMessage() const override;
std::string getRemarkName() const override;
const Value *getRemarkBB() const override;
std::string getMessage() const override;
const DebugLoc &getDebugLoc() const override;
std::string getEndUserMessage() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// Captures errors with non-side-effect-known function calls.
class ReportFuncCall : public RejectReason {
//===--------------------------------------------------------------------===//
// The offending call instruction.
Instruction *Inst;
@ -655,20 +629,19 @@ public:
/// @name RejectReason interface
//@{
virtual std::string getRemarkName() const override;
virtual const Value *getRemarkBB() const override;
virtual std::string getMessage() const override;
virtual const DebugLoc &getDebugLoc() const override;
virtual std::string getEndUserMessage() const override;
std::string getRemarkName() const override;
const Value *getRemarkBB() const override;
std::string getMessage() const override;
const DebugLoc &getDebugLoc() const override;
std::string getEndUserMessage() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// Captures errors with aliasing.
class ReportAlias : public RejectReason {
//===--------------------------------------------------------------------===//
public:
typedef std::vector<const llvm::Value *> PointerSnapshotTy;
using PointerSnapshotTy = std::vector<const Value *>;
private:
/// Format an invalid alias set.
@ -695,18 +668,17 @@ public:
/// @name RejectReason interface
//@{
virtual std::string getRemarkName() const override;
virtual const Value *getRemarkBB() const override;
virtual std::string getMessage() const override;
virtual const DebugLoc &getDebugLoc() const override;
virtual std::string getEndUserMessage() const override;
std::string getRemarkName() const override;
const Value *getRemarkBB() const override;
std::string getMessage() const override;
const DebugLoc &getDebugLoc() const override;
std::string getEndUserMessage() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// Base class for otherwise ungrouped reject reasons.
class ReportOther : public RejectReason {
//===--------------------------------------------------------------------===//
public:
ReportOther(const RejectReasonKind K);
@ -717,16 +689,14 @@ public:
/// @name RejectReason interface
//@{
virtual std::string getRemarkName() const override;
virtual std::string getMessage() const override;
std::string getRemarkName() const override;
std::string getMessage() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// Captures errors with bad IntToPtr instructions.
class ReportIntToPtr : public ReportOther {
//===--------------------------------------------------------------------===//
// The offending base value.
Instruction *BaseValue;
@ -740,17 +710,16 @@ public:
/// @name RejectReason interface
//@{
virtual std::string getRemarkName() const override;
virtual const Value *getRemarkBB() const override;
virtual std::string getMessage() const override;
virtual const DebugLoc &getDebugLoc() const override;
std::string getRemarkName() const override;
const Value *getRemarkBB() const override;
std::string getMessage() const override;
const DebugLoc &getDebugLoc() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// Captures errors with alloca instructions.
class ReportAlloca : public ReportOther {
//===--------------------------------------------------------------------===//
Instruction *Inst;
public:
@ -763,17 +732,16 @@ public:
/// @name RejectReason interface
//@{
virtual std::string getRemarkName() const override;
virtual const Value *getRemarkBB() const override;
virtual std::string getMessage() const override;
virtual const DebugLoc &getDebugLoc() const override;
std::string getRemarkName() const override;
const Value *getRemarkBB() const override;
std::string getMessage() const override;
const DebugLoc &getDebugLoc() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// Captures errors with unknown instructions.
class ReportUnknownInst : public ReportOther {
//===--------------------------------------------------------------------===//
Instruction *Inst;
public:
@ -786,17 +754,16 @@ public:
/// @name RejectReason interface
//@{
virtual std::string getRemarkName() const override;
virtual const Value *getRemarkBB() const override;
virtual std::string getMessage() const override;
virtual const DebugLoc &getDebugLoc() const override;
std::string getRemarkName() const override;
const Value *getRemarkBB() const override;
std::string getMessage() const override;
const DebugLoc &getDebugLoc() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// Captures errors with regions containing the function entry block.
class ReportEntry : public ReportOther {
//===--------------------------------------------------------------------===//
BasicBlock *BB;
public:
@ -809,18 +776,17 @@ public:
/// @name RejectReason interface
//@{
virtual std::string getRemarkName() const override;
virtual const Value *getRemarkBB() const override;
virtual std::string getMessage() const override;
virtual std::string getEndUserMessage() const override;
virtual const DebugLoc &getDebugLoc() const override;
std::string getRemarkName() const override;
const Value *getRemarkBB() const override;
std::string getMessage() const override;
std::string getEndUserMessage() const override;
const DebugLoc &getDebugLoc() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// Report regions that seem not profitable to be optimized.
class ReportUnprofitable : public ReportOther {
//===--------------------------------------------------------------------===//
Region *R;
public:
@ -833,19 +799,17 @@ public:
/// @name RejectReason interface
//@{
virtual std::string getRemarkName() const override;
virtual const Value *getRemarkBB() const override;
virtual std::string getMessage() const override;
virtual std::string getEndUserMessage() const override;
virtual const DebugLoc &getDebugLoc() const override;
std::string getRemarkName() const override;
const Value *getRemarkBB() const override;
std::string getMessage() const override;
std::string getEndUserMessage() const override;
const DebugLoc &getDebugLoc() const override;
//@}
};
//===----------------------------------------------------------------------===//
/// Captures errors with non-simple memory accesses.
class ReportNonSimpleMemoryAccess : public ReportOther {
//===--------------------------------------------------------------------===//
// The offending call instruction.
Instruction *Inst;
@ -859,14 +823,14 @@ public:
/// @name RejectReason interface
//@{
virtual std::string getRemarkName() const override;
virtual const Value *getRemarkBB() const override;
virtual std::string getMessage() const override;
virtual const DebugLoc &getDebugLoc() const override;
virtual std::string getEndUserMessage() const override;
std::string getRemarkName() const override;
const Value *getRemarkBB() const override;
std::string getMessage() const override;
const DebugLoc &getDebugLoc() const override;
std::string getEndUserMessage() const override;
//@}
};
} // namespace polly
#endif // POLLY_SCOP_DETECTION_DIAGNOSTIC_H
#endif // POLLY_SCOPDETECTIONDIAGNOSTIC_H

View File

@ -1,4 +1,4 @@
//===- PruneUnprofitable.cpp ------------------------------------*- C++ -*-===//
//===- PruneUnprofitable.cpp ----------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
@ -12,12 +12,19 @@
//===----------------------------------------------------------------------===//
#include "polly/PruneUnprofitable.h"
#include "polly/ScopDetection.h"
#include "polly/ScopInfo.h"
#include "polly/ScopPass.h"
#define DEBUG_TYPE "polly-prune-unprofitable"
#include "llvm/ADT/Statistic.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/Pass.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
using namespace polly;
using namespace llvm;
using namespace polly;
#define DEBUG_TYPE "polly-prune-unprofitable"
namespace {
@ -37,9 +44,6 @@ STATISTIC(NumAffineLoops, "Number of affine loops in SCoPs after pruning");
class PruneUnprofitable : public ScopPass {
private:
PruneUnprofitable(const PruneUnprofitable &) = delete;
const PruneUnprofitable &operator=(const PruneUnprofitable &) = delete;
void updateStatistics(Scop &S, bool Pruned) {
auto ScopStats = S.getStatistics();
if (Pruned) {
@ -57,14 +61,17 @@ private:
public:
static char ID;
explicit PruneUnprofitable() : ScopPass(ID) {}
virtual void getAnalysisUsage(AnalysisUsage &AU) const override {
explicit PruneUnprofitable() : ScopPass(ID) {}
PruneUnprofitable(const PruneUnprofitable &) = delete;
PruneUnprofitable &operator=(const PruneUnprofitable &) = delete;
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequired<ScopInfoRegionPass>();
AU.setPreservesAll();
}
virtual bool runOnScop(Scop &S) override {
bool runOnScop(Scop &S) override {
if (PollyProcessUnprofitable) {
DEBUG(dbgs() << "NOTE: -polly-process-unprofitable active, won't prune "
"anything\n");
@ -86,8 +93,9 @@ public:
}
};
} // namespace
char PruneUnprofitable::ID;
} // anonymous namespace
Pass *polly::createPruneUnprofitablePass() { return new PruneUnprofitable(); }

View File

@ -1,3 +1,4 @@
//===- ScopDetection.cpp - Detect Scops -----------------------------------===//
//
// The LLVM Compiler Infrastructure
//
@ -44,28 +45,59 @@
//===----------------------------------------------------------------------===//
#include "polly/ScopDetection.h"
#include "polly/CodeGen/CodeGeneration.h"
#include "polly/LinkAllPasses.h"
#include "polly/Options.h"
#include "polly/ScopDetectionDiagnostic.h"
#include "polly/Support/SCEVValidator.h"
#include "polly/Support/ScopHelper.h"
#include "polly/Support/ScopLocation.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/Loads.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/RegionIterator.h"
#include "llvm/Analysis/MemoryLocation.h"
#include "llvm/Analysis/OptimizationDiagnosticInfo.h"
#include "llvm/Analysis/RegionInfo.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/DiagnosticPrinter.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Value.h"
#include "llvm/Pass.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Regex.h"
#include <set>
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <memory>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace llvm;
using namespace polly;
@ -83,6 +115,7 @@ static cl::opt<int> ProfitabilityMinPerLoopInstructions(
cl::Hidden, cl::ValueRequired, cl::init(100000000), cl::cat(PollyCategory));
bool polly::PollyProcessUnprofitable;
static cl::opt<bool, true> XPollyProcessUnprofitable(
"polly-process-unprofitable",
cl::desc(
@ -107,6 +140,7 @@ static cl::list<std::string> IgnoredFunctions(
cl::ZeroOrMore, cl::CommaSeparated, cl::cat(PollyCategory));
bool polly::PollyAllowFullFunction;
static cl::opt<bool, true>
XAllowFullFunction("polly-detect-full-functions",
cl::desc("Allow the detection of full functions"),
@ -127,6 +161,7 @@ static cl::opt<bool>
cl::cat(PollyCategory));
bool polly::PollyAllowUnsignedOperations;
static cl::opt<bool, true> XPollyAllowUnsignedOperations(
"polly-allow-unsigned-operations",
cl::desc("Allow unsigned operations such as comparisons or zero-extends."),
@ -134,6 +169,7 @@ static cl::opt<bool, true> XPollyAllowUnsignedOperations(
cl::init(true), cl::cat(PollyCategory));
bool polly::PollyUseRuntimeAliasChecks;
static cl::opt<bool, true> XPollyUseRuntimeAliasChecks(
"polly-use-runtime-alias-checks",
cl::desc("Use runtime alias checks to resolve possible aliasing."),
@ -197,6 +233,7 @@ static cl::opt<bool>
cl::cat(PollyCategory));
bool polly::PollyInvariantLoadHoisting;
static cl::opt<bool, true> XPollyInvariantLoadHoisting(
"polly-invariant-load-hoisting", cl::desc("Hoist invariant loads."),
cl::location(PollyInvariantLoadHoisting), cl::Hidden, cl::ZeroOrMore,
@ -245,6 +282,8 @@ STATISTIC(MaxNumLoopsInProfScop,
static void updateLoopCountStatistic(ScopDetection::LoopStats Stats,
bool OnlyProfitable);
namespace {
class DiagnosticScopFound : public DiagnosticInfo {
private:
static int PluginDiagnosticKind;
@ -259,13 +298,15 @@ public:
: DiagnosticInfo(PluginDiagnosticKind, DS_Note), F(F), FileName(FileName),
EntryLine(EntryLine), ExitLine(ExitLine) {}
virtual void print(DiagnosticPrinter &DP) const;
void print(DiagnosticPrinter &DP) const override;
static bool classof(const DiagnosticInfo *DI) {
return DI->getKind() == PluginDiagnosticKind;
}
};
} // namespace
int DiagnosticScopFound::PluginDiagnosticKind =
getNextAvailablePluginDiagnosticKind();
@ -307,13 +348,12 @@ ScopDetection::ScopDetection(Function &F, const DominatorTree &DT,
ScalarEvolution &SE, LoopInfo &LI, RegionInfo &RI,
AliasAnalysis &AA, OptimizationRemarkEmitter &ORE)
: DT(DT), SE(SE), LI(LI), RI(RI), AA(AA), ORE(ORE) {
if (!PollyProcessUnprofitable && LI.empty())
return;
Region *TopRegion = RI.getTopLevelRegion();
if (OnlyFunctions.size() > 0 &&
if (!OnlyFunctions.empty() &&
!doesStringMatchAnyRegex(F.getName(), OnlyFunctions))
return;
@ -361,7 +401,6 @@ ScopDetection::ScopDetection(Function &F, const DominatorTree &DT,
template <class RR, typename... Args>
inline bool ScopDetection::invalid(DetectionContext &Context, bool Assert,
Args &&... Arguments) const {
if (!Context.Verifying) {
RejectLog &Log = Context.Log;
std::shared_ptr<RR> RejectReason = std::make_shared<RR>(Arguments...);
@ -410,7 +449,6 @@ std::string ScopDetection::regionIsInvalidBecause(const Region *R) const {
bool ScopDetection::addOverApproximatedRegion(Region *AR,
DetectionContext &Context) const {
// If we already know about Ar we can exit.
if (!Context.NonAffineSubRegionSet.insert(AR))
return true;
@ -448,7 +486,6 @@ bool ScopDetection::onlyValidRequiredInvariantLoads(
return false;
for (auto NonAffineRegion : Context.NonAffineSubRegionSet) {
if (isSafeToLoadUnconditionally(Load->getPointerOperand(),
Load->getAlignment(), DL))
continue;
@ -500,7 +537,6 @@ bool ScopDetection::involvesMultiplePtrs(const SCEV *S0, const SCEV *S1,
bool ScopDetection::isAffine(const SCEV *S, Loop *Scope,
DetectionContext &Context) const {
InvariantLoadsSetTy AccessILS;
if (!isAffineExpr(&Context.CurRegion, Scope, S, SE, &AccessILS))
return false;
@ -538,7 +574,6 @@ bool ScopDetection::isValidSwitch(BasicBlock &BB, SwitchInst *SI,
bool ScopDetection::isValidBranch(BasicBlock &BB, BranchInst *BI,
Value *Condition, bool IsLoopBranch,
DetectionContext &Context) const {
// Constant integer conditions are always affine.
if (isa<ConstantInt>(Condition))
return true;
@ -708,8 +743,8 @@ bool ScopDetection::isValidIntrinsicInst(IntrinsicInst &II,
switch (II.getIntrinsicID()) {
// Memory intrinsics that can be represented are supported.
case llvm::Intrinsic::memmove:
case llvm::Intrinsic::memcpy:
case Intrinsic::memmove:
case Intrinsic::memcpy:
AF = SE.getSCEVAtScope(cast<MemTransferInst>(II).getSource(), L);
if (!AF->isZero()) {
BP = dyn_cast<SCEVUnknown>(SE.getPointerBase(AF));
@ -718,7 +753,7 @@ bool ScopDetection::isValidIntrinsicInst(IntrinsicInst &II,
return false;
}
// Fall through
case llvm::Intrinsic::memset:
case Intrinsic::memset:
AF = SE.getSCEVAtScope(cast<MemIntrinsic>(II).getDest(), L);
if (!AF->isZero()) {
BP = dyn_cast<SCEVUnknown>(SE.getPointerBase(AF));
@ -764,6 +799,8 @@ bool ScopDetection::isInvariant(Value &Val, const Region &Reg,
return false;
}
namespace {
/// Remove smax of smax(0, size) expressions from a SCEV expression and
/// register the '...' components.
///
@ -778,15 +815,15 @@ bool ScopDetection::isInvariant(Value &Val, const Region &Reg,
/// that 0 <= size, which means smax(0, size) == size.
class SCEVRemoveMax : public SCEVRewriteVisitor<SCEVRemoveMax> {
public:
SCEVRemoveMax(ScalarEvolution &SE, std::vector<const SCEV *> *Terms)
: SCEVRewriteVisitor(SE), Terms(Terms) {}
static const SCEV *rewrite(const SCEV *Scev, ScalarEvolution &SE,
std::vector<const SCEV *> *Terms = nullptr) {
SCEVRemoveMax Rewriter(SE, Terms);
return Rewriter.visit(Scev);
}
SCEVRemoveMax(ScalarEvolution &SE, std::vector<const SCEV *> *Terms)
: SCEVRewriteVisitor(SE), Terms(Terms) {}
const SCEV *visitSMaxExpr(const SCEVSMaxExpr *Expr) {
if ((Expr->getNumOperands() == 2) && Expr->getOperand(0)->isZero()) {
auto Res = visit(Expr->getOperand(1));
@ -802,6 +839,8 @@ private:
std::vector<const SCEV *> *Terms;
};
} // namespace
SmallVector<const SCEV *, 4>
ScopDetection::getDelinearizationTerms(DetectionContext &Context,
const SCEVUnknown *BasePointer) const {
@ -809,7 +848,7 @@ ScopDetection::getDelinearizationTerms(DetectionContext &Context,
for (const auto &Pair : Context.Accesses[BasePointer]) {
std::vector<const SCEV *> MaxTerms;
SCEVRemoveMax::rewrite(Pair.second, SE, &MaxTerms);
if (MaxTerms.size() > 0) {
if (!MaxTerms.empty()) {
Terms.insert(Terms.begin(), MaxTerms.begin(), MaxTerms.end());
continue;
}
@ -1345,6 +1384,7 @@ Region *ScopDetection::expandRegion(Region &R) {
return LastValidRegion.release();
}
static bool regionWithoutLoops(Region &R, LoopInfo &LI) {
for (const BasicBlock *BB : R.blocks())
if (R.contains(LI.getLoopFor(BB)))
@ -1586,11 +1626,11 @@ void ScopDetection::markFunctionAsInvalid(Function *F) {
F->addFnAttr(PollySkipFnAttr);
}
bool ScopDetection::isValidFunction(llvm::Function &F) {
bool ScopDetection::isValidFunction(Function &F) {
return !F.hasFnAttribute(PollySkipFnAttr);
}
void ScopDetection::printLocations(llvm::Function &F) {
void ScopDetection::printLocations(Function &F) {
for (const Region *R : *this) {
unsigned LineEntry, LineExit;
std::string FileName;
@ -1733,14 +1773,14 @@ const RejectLog *ScopDetection::lookupRejectionLog(const Region *R) const {
return DC ? &DC->Log : nullptr;
}
void polly::ScopDetection::verifyRegion(const Region &R) const {
void ScopDetection::verifyRegion(const Region &R) const {
assert(isMaxRegionInScop(R) && "Expect R is a valid region.");
DetectionContext Context(const_cast<Region &>(R), AA, true /*verifying*/);
isValidRegion(Context);
}
void polly::ScopDetection::verifyAnalysis() const {
void ScopDetection::verifyAnalysis() const {
if (!VerifyScops)
return;
@ -1748,7 +1788,7 @@ void polly::ScopDetection::verifyAnalysis() const {
verifyRegion(*R);
}
bool ScopDetectionWrapperPass::runOnFunction(llvm::Function &F) {
bool ScopDetectionWrapperPass::runOnFunction(Function &F) {
auto &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
auto &RI = getAnalysis<RegionInfoPass>().getRegionInfo();
auto &AA = getAnalysis<AAResultsWrapperPass>().getAAResults();
@ -1782,6 +1822,7 @@ ScopDetectionWrapperPass::ScopDetectionWrapperPass() : FunctionPass(ID) {
if (IgnoreAliasing)
PollyUseRuntimeAliasChecks = false;
}
ScopAnalysis::ScopAnalysis() {
// Disable runtime alias checks if we ignore aliasing all together.
if (IgnoreAliasing)
@ -1806,12 +1847,12 @@ ScopDetection ScopAnalysis::run(Function &F, FunctionAnalysisManager &FAM) {
PreservedAnalyses ScopAnalysisPrinterPass::run(Function &F,
FunctionAnalysisManager &FAM) {
Stream << "Detected Scops in Function " << F.getName() << "\n";
OS << "Detected Scops in Function " << F.getName() << "\n";
auto &SD = FAM.getResult<ScopAnalysis>(F);
for (const Region *R : SD.ValidRegions)
Stream << "Valid Region for Scop: " << R->getNameStr() << '\n';
OS << "Valid Region for Scop: " << R->getNameStr() << '\n';
Stream << "\n";
OS << "\n";
return PreservedAnalyses::all();
}

View File

@ -1,4 +1,4 @@
//=== ScopDetectionDiagnostic.cpp - Error diagnostics --------- -*- C++ -*-===//
//===- ScopDetectionDiagnostic.cpp - Error diagnostics --------------------===//
//
// The LLVM Compiler Infrastructure
//
@ -17,32 +17,38 @@
// to diagnose the error and generate a helpful error message.
//
//===----------------------------------------------------------------------===//
#include "polly/ScopDetectionDiagnostic.h"
#include "polly/Support/ScopLocation.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/AliasSetTracker.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/OptimizationDiagnosticInfo.h"
#include "llvm/Analysis/RegionInfo.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Value.h"
#define DEBUG_TYPE "polly-detect"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <string>
#include <utility>
using namespace llvm;
#define DEBUG_TYPE "polly-detect"
#define SCOP_STAT(NAME, DESC) \
{ "polly-detect", "NAME", "Number of rejected regions: " DESC, {0}, false }
llvm::Statistic RejectStatistics[] = {
Statistic RejectStatistics[] = {
SCOP_STAT(CFG, ""),
SCOP_STAT(InvalidTerminator, "Unsupported terminator instruction"),
SCOP_STAT(UnreachableInExit, "Unreachable in exit block"),
@ -76,6 +82,7 @@ llvm::Statistic RejectStatistics[] = {
};
namespace polly {
/// Small string conversion via raw_string_stream.
template <typename T> std::string operator+(Twine LHS, const T &RHS) {
std::string Buf;
@ -85,17 +92,21 @@ template <typename T> std::string operator+(Twine LHS, const T &RHS) {
return LHS.concat(Buf).str();
}
} // namespace polly
namespace llvm {
// Lexicographic order on (line, col) of our debug locations.
static bool operator<(const llvm::DebugLoc &LHS, const llvm::DebugLoc &RHS) {
static bool operator<(const DebugLoc &LHS, const DebugLoc &RHS) {
return LHS.getLine() < RHS.getLine() ||
(LHS.getLine() == RHS.getLine() && LHS.getCol() < RHS.getCol());
}
} // namespace llvm
namespace polly {
BBPair getBBPairForRegion(const Region *R) {
return std::make_pair(R->getEntry(), R->getExit());
}
@ -163,7 +174,7 @@ RejectReason::RejectReason(RejectReasonKind K) : Kind(K) {
const DebugLoc RejectReason::Unknown = DebugLoc();
const llvm::DebugLoc &RejectReason::getDebugLoc() const {
const DebugLoc &RejectReason::getDebugLoc() const {
// Allocate an empty DebugLoc and return it a reference to it.
return Unknown;
}
@ -401,8 +412,8 @@ bool ReportDifferentArrayElementSize::classof(const RejectReason *RR) {
}
std::string ReportDifferentArrayElementSize::getEndUserMessage() const {
llvm::StringRef BaseName = BaseValue->getName();
std::string Name = (BaseName.size() > 0) ? BaseName : "UNKNOWN";
StringRef BaseName = BaseValue->getName();
std::string Name = BaseName.empty() ? "UNKNOWN" : BaseName;
return "The array \"" + Name +
"\" is accessed through elements that differ "
"in size";
@ -428,8 +439,8 @@ bool ReportNonAffineAccess::classof(const RejectReason *RR) {
}
std::string ReportNonAffineAccess::getEndUserMessage() const {
llvm::StringRef BaseName = BaseValue->getName();
std::string Name = (BaseName.size() > 0) ? BaseName : "UNKNOWN";
StringRef BaseName = BaseValue->getName();
std::string Name = BaseName.empty() ? "UNKNOWN" : BaseName;
return "The array subscript of \"" + Name + "\" is not affine";
}
@ -572,7 +583,6 @@ bool ReportNonSimpleMemoryAccess::classof(const RejectReason *RR) {
ReportAlias::ReportAlias(Instruction *Inst, AliasSet &AS)
: RejectReason(RejectReasonKind::Alias), Inst(Inst) {
for (const auto &I : AS)
Pointers.push_back(I.getValue());
}
@ -590,7 +600,7 @@ std::string ReportAlias::formatInvalidAlias(std::string Prefix,
const Value *V = *PI;
assert(V && "Diagnostic info does not match found LLVM-IR anymore.");
if (V->getName().size() == 0)
if (V->getName().empty())
OS << "\" <unknown> \"";
else
OS << "\"" << V->getName() << "\"";
@ -712,6 +722,7 @@ bool ReportUnknownInst::classof(const RejectReason *RR) {
//===----------------------------------------------------------------------===//
// ReportEntry.
ReportEntry::ReportEntry(BasicBlock *BB)
: ReportOther(RejectReasonKind::Entry), BB(BB) {}
@ -737,6 +748,7 @@ bool ReportEntry::classof(const RejectReason *RR) {
//===----------------------------------------------------------------------===//
// ReportUnprofitable.
ReportUnprofitable::ReportUnprofitable(Region *R)
: ReportOther(RejectReasonKind::Unprofitable), R(R) {}
@ -764,4 +776,5 @@ const DebugLoc &ReportUnprofitable::getDebugLoc() const {
bool ReportUnprofitable::classof(const RejectReason *RR) {
return RR->getKind() == RejectReasonKind::Unprofitable;
}
} // namespace polly

View File

@ -1,4 +1,4 @@
//===---------------- MaximalStaticExpansion.cpp -------------------------===//
//===- MaximalStaticExpansion.cpp -----------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
@ -13,14 +13,20 @@
//===----------------------------------------------------------------------===//
#include "polly/DependenceInfo.h"
#include "polly/FlattenAlgo.h"
#include "polly/LinkAllPasses.h"
#include "polly/Options.h"
#include "polly/ScopInfo.h"
#include "polly/ScopPass.h"
#include "polly/Support/GICHelper.h"
#include "polly/Support/ISLOStream.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/Support/Debug.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Analysis/OptimizationDiagnosticInfo.h"
#include "llvm/Pass.h"
#include "isl/isl-noexceptions.h"
#include "isl/union_map.h"
#include <cassert>
#include <limits>
#include <string>
#include <vector>
using namespace llvm;
using namespace polly;
@ -28,12 +34,14 @@ using namespace polly;
#define DEBUG_TYPE "polly-mse"
namespace {
class MaximalStaticExpander : public ScopPass {
public:
static char ID;
explicit MaximalStaticExpander() : ScopPass(ID) {}
~MaximalStaticExpander() {}
~MaximalStaticExpander() override = default;
/// Expand the accesses of the SCoP.
///
@ -104,15 +112,14 @@ private:
void expandPhi(Scop &S, const ScopArrayInfo *SAI,
const isl::union_map &Dependences);
};
} // namespace
namespace {
} // namespace
#ifndef NDEBUG
/// Whether a dimension of a set is bounded (lower and upper) by a constant,
/// i.e. there are two constants Min and Max, such that every value x of the
/// chosen dimensions is Min <= x <= Max.
bool isDimBoundedByConstant(isl::set Set, unsigned dim) {
static bool isDimBoundedByConstant(isl::set Set, unsigned dim) {
auto ParamDims = Set.dim(isl::dim::param);
Set = Set.project_out(isl::dim::param, 0, ParamDims);
Set = Set.project_out(isl::dim::set, 0, dim);
@ -125,7 +132,7 @@ bool isDimBoundedByConstant(isl::set Set, unsigned dim) {
/// If @p PwAff maps to a constant, return said constant. If @p Max/@p Min, it
/// can also be a piecewise constant and it would return the minimum/maximum
/// value. Otherwise, return NaN.
isl::val getConstant(isl::pw_aff PwAff, bool Max, bool Min) {
static isl::val getConstant(isl::pw_aff PwAff, bool Max, bool Min) {
assert(!Max || !Min);
isl::val Result;
PwAff.foreach_piece([=, &Result](isl::set Set, isl::aff Aff) -> isl::stat {
@ -165,13 +172,10 @@ isl::val getConstant(isl::pw_aff PwAff, bool Max, bool Min) {
return Result;
}
} // namespace
char MaximalStaticExpander::ID = 0;
isl::union_map MaximalStaticExpander::filterDependences(
Scop &S, const isl::union_map &Dependences, MemoryAccess *MA) {
auto SAI = MA->getLatestScopArrayInfo();
auto AccessDomainSet = MA->getAccessRelation().domain();
@ -216,7 +220,6 @@ bool MaximalStaticExpander::isExpandable(
const ScopArrayInfo *SAI, SmallPtrSetImpl<MemoryAccess *> &Writes,
SmallPtrSetImpl<MemoryAccess *> &Reads, Scop &S,
const isl::union_map &Dependences) {
if (SAI->isValueKind()) {
Writes.insert(S.getValueDef(SAI));
for (auto MA : S.getValueUses(SAI))
@ -262,7 +265,6 @@ bool MaximalStaticExpander::isExpandable(
auto StmtWrites = isl::union_map::empty(S.getParamSpace());
for (MemoryAccess *MA : Stmt) {
// Check if the current MemoryAccess involved the current SAI.
if (SAI != MA->getLatestScopArrayInfo())
continue;
@ -308,7 +310,6 @@ bool MaximalStaticExpander::isExpandable(
// Check if it is possible to expand this read.
if (MA->isRead()) {
// Get the domain of the current ScopStmt.
auto StmtDomain = Stmt.getDomain();
@ -368,9 +369,7 @@ void MaximalStaticExpander::mapAccess(Scop &S,
const isl::union_map &Dependences,
ScopArrayInfo *ExpandedSAI,
bool Reverse) {
for (auto MA : Accesses) {
// Get the current AM.
auto CurrentAccessMap = MA->getAccessRelation();
@ -405,7 +404,6 @@ void MaximalStaticExpander::mapAccess(Scop &S,
}
ScopArrayInfo *MaximalStaticExpander::expandAccess(Scop &S, MemoryAccess *MA) {
// Get the current AM.
auto CurrentAccessMap = MA->getAccessRelation();