#ifndef LLVM_TRANSFORMS_VECTORIZE_REGIONBASEDGSLP_H
#define LLVM_TRANSFORMS_VECTORIZE_REGIONBASEDGSLP_H

#include "llvm/Transforms/Vectorize/GlobalSLPVectorize.h"

namespace llvm {

static const char *RegionDebug = DEBUG_TYPE "-region";

class RegionBasedGSLP {
public:
  using RegionTypeList = std::vector<RegionType*>;
  using CliquePtrType = HierCompatibilityGraph::CliquePtrType;
  using CliqueListType = HierCompatibilityGraph::CliquesType;
  using HCGPtrListType = std::vector<HierCompatibilityGraph*>;
private:
  // HCG of the entire BB
  // All the cliques built will finally be added into this
  HierCompatibilityGraph *CombinedHCG;
  // Alias Analysis, used by HCG to build local cliques
  AliasAnalysis *AA;
  // Pointer to GSLPUtil class
  GSLPUtil *GSLPU;
  // Pointer to temporary HCG's created. Although these HCG's are not required
  // after the creation of cliques, the underlying CG's and cliques are required
  HCGPtrListType HCGPtrList;
public:
  RegionBasedGSLP(AliasAnalysis *AA_, GSLPUtil *GSLPU_) :
    AA(AA_), GSLPU(GSLPU_), CombinedHCG(nullptr) {}

  ~RegionBasedGSLP() {
    for (auto *HCG: HCGPtrList)
      delete HCG;
  }
  // Build the cliques assuming Region based GSLP and store then in given HCG
  // Memory, Reduction and Singleton cliques are built for the entire BB
  // Arithmetic cliques are not built for the entire BB, but for a region only
  // All these cliques are added to the given HCG, after which
  // buildSetPartition can be run
  // Currently Regions are the levels in the data dependence graph
  // This way only single row cliques are formed
  // TODO: Combine regions to form multi-level cliques
  void buildRegionCliques(HierCompatibilityGraph *HCG);
  // Given a BB, returns a list of Regions in that BB
  RegionTypeList findRegions(BasicBlock *BB);
private:
  // Given a list of all the regions, build Arithmetic cliques for all of them
  // Add the cliques generated to the CombinedHCG
  void buildRegionArithmeticCliques(RegionTypeList &AllRegions);
};

} // end namespace llvm

#endif // LLVM_TRANSFORMS_VECTORIZE_REGIONBASEDGSLP_H
