remove redundant includes in all files; [QoREstimation] refactor include structure

This commit is contained in:
Hanchen Ye 2020-12-18 21:16:22 -06:00
parent a6c4ec403d
commit 2d943dd238
20 changed files with 90 additions and 126 deletions

View File

@ -2,27 +2,22 @@
//
//===----------------------------------------------------------------------===//
#ifndef SCALEHLS_ANALYSIS_QORESTIMATION_H
#define SCALEHLS_ANALYSIS_QORESTIMATION_H
#ifndef SCALEHLS_ANALYSIS_UTILS_H
#define SCALEHLS_ANALYSIS_UTILS_H
#include "Dialect/HLSCpp/Visitor.h"
#include "INIReader.h"
#include "mlir/Analysis/AffineAnalysis.h"
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Transforms/LoopUtils.h"
#include "llvm/ADT/TypeSwitch.h"
#include "Dialect/HLSCpp/HLSCpp.h"
#include "mlir/IR/Operation.h"
namespace mlir {
namespace scalehls {
//===----------------------------------------------------------------------===//
// HLSCppToolBase Class Declaration and Definition
// HLSCppAnalysisBase Class
//===----------------------------------------------------------------------===//
class HLSCppToolBase {
class HLSCppAnalysisBase {
public:
explicit HLSCppToolBase(OpBuilder builder) : builder(builder) {}
explicit HLSCppAnalysisBase(OpBuilder builder) : builder(builder) {}
OpBuilder builder;
@ -56,14 +51,14 @@ public:
}
/// Get partition information methods.
StringRef getPartitionType(ArrayOp op, unsigned dim) {
StringRef getPartitionType(hlscpp::ArrayOp op, unsigned dim) {
if (auto attr = op.partition_type()[dim].cast<StringAttr>())
return attr.getValue();
else
return "";
}
unsigned getPartitionFactor(ArrayOp op, unsigned dim) {
unsigned getPartitionFactor(hlscpp::ArrayOp op, unsigned dim) {
if (auto attr = op.partition_factor()[dim].cast<IntegerAttr>())
return attr.getUInt();
else
@ -95,7 +90,7 @@ public:
};
//===----------------------------------------------------------------------===//
// HLSCppEstimator Class Declaration
// Common Used Type Declarations
//===----------------------------------------------------------------------===//
// Profiled latency map.
@ -128,65 +123,7 @@ using PortsMap = DenseMap<Operation *, Ports>;
// For storing PortsMap indexed by the scheduling level.
using PortsMapDict = DenseMap<unsigned, PortsMap>;
class HLSCppEstimator
: public HLSCppVisitorBase<HLSCppEstimator, Optional<unsigned>, unsigned>,
public HLSCppToolBase {
public:
explicit HLSCppEstimator(FuncOp &func, LatencyMap &latencyMap)
: HLSCppToolBase(OpBuilder(func)), func(func), latencyMap(latencyMap) {
getFuncMemRefDepends();
}
void getFuncMemRefDepends();
using HLSCppVisitorBase::visitOp;
Optional<unsigned> visitUnhandledOp(Operation *op, unsigned begin) {
// Default latency of any unhandled operation is 1.
setScheduleValue(op, begin, begin + 1);
return begin + 1;
}
int32_t getPartitionIndex(Operation *op);
unsigned getLoadStoreSchedule(Operation *op, unsigned begin);
Optional<unsigned> visitOp(AffineLoadOp op, unsigned begin) {
return getLoadStoreSchedule(op, begin);
}
Optional<unsigned> visitOp(AffineStoreOp op, unsigned begin) {
return getLoadStoreSchedule(op, begin);
}
unsigned getOpMinII(AffineForOp forOp);
unsigned getResMinII(LoadStoresMap &map);
unsigned getDepMinII(AffineForOp forOp, LoadStoresMap &map);
Optional<unsigned> visitOp(AffineForOp op, unsigned begin);
Optional<unsigned> visitOp(AffineIfOp op, unsigned begin);
Optional<unsigned> visitOp(ReturnOp op, unsigned begin);
Optional<unsigned> visitOp(ArrayOp op, unsigned begin);
/// Handle operations with profiled latency.
#define HANDLE(OPTYPE, KEYNAME) \
Optional<unsigned> visitOp(OPTYPE op, unsigned begin) { \
auto end = begin + latencyMap[KEYNAME] + 1; \
setScheduleValue(op, begin, end); \
return end; \
}
HANDLE(AddFOp, "fadd");
HANDLE(MulFOp, "fmul");
HANDLE(DivFOp, "fdiv");
HANDLE(CmpFOp, "fcmp");
HANDLE(SelectOp, "fselect");
#undef HANDLE
Optional<unsigned> estimateBlock(Block &block, unsigned begin);
void estimateFunc();
FuncOp &func;
DependsMap dependsMap;
PortsMapDict portsMapDict;
LatencyMap &latencyMap;
};
} // namespace scalehls
} // namespace mlir
#endif // SCALEHLS_ANALYSIS_QORESTIMATION_H
#endif // SCALEHLS_ANALYSIS_UTILS_H

View File

@ -9,6 +9,7 @@
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/SCF/SCF.h"
#include "mlir/Dialect/StandardOps/IR/Ops.h"
#include "llvm/ADT/TypeSwitch.h"
namespace mlir {
namespace scalehls {

View File

@ -8,7 +8,6 @@
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/Dialect.h"
#include "mlir/IR/Function.h"
namespace mlir {
namespace scalehls {

View File

@ -7,6 +7,7 @@
#include "Dialect/HLSKernel/HLSKernel.h"
#include "mlir/Dialect/StandardOps/IR/Ops.h"
#include "llvm/ADT/TypeSwitch.h"
namespace mlir {
namespace scalehls {

View File

@ -2,16 +2,16 @@
//
//===----------------------------------------------------------------------===//
#include "Analysis/QoREstimation.h"
#include "Analysis/Passes.h"
#include "Dialect/HLSCpp/HLSCpp.h"
#include "Analysis/Utils.h"
#include "Dialect/HLSCpp/Visitor.h"
#include "INIReader.h"
#include "mlir/Analysis/AffineAnalysis.h"
#include "mlir/Analysis/AffineStructures.h"
#include "mlir/Analysis/LoopAnalysis.h"
#include "mlir/Analysis/Utils.h"
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/Affine/IR/AffineValueMap.h"
#include "mlir/IR/Block.h"
#include "mlir/IR/Operation.h"
#include "mlir/IR/PatternMatch.h"
using namespace std;
using namespace mlir;
@ -19,7 +19,72 @@ using namespace scalehls;
using namespace hlscpp;
//===----------------------------------------------------------------------===//
// Helpers
// HLSCppEstimator Class Delaration
//===----------------------------------------------------------------------===//
namespace {
class HLSCppEstimator
: public HLSCppVisitorBase<HLSCppEstimator, Optional<unsigned>, unsigned>,
public HLSCppAnalysisBase {
public:
explicit HLSCppEstimator(FuncOp &func, LatencyMap &latencyMap)
: HLSCppAnalysisBase(OpBuilder(func)), func(func),
latencyMap(latencyMap) {
getFuncMemRefDepends();
}
void getFuncMemRefDepends();
using HLSCppVisitorBase::visitOp;
Optional<unsigned> visitUnhandledOp(Operation *op, unsigned begin) {
// Default latency of any unhandled operation is 1.
setScheduleValue(op, begin, begin + 1);
return begin + 1;
}
int32_t getPartitionIndex(Operation *op);
unsigned getLoadStoreSchedule(Operation *op, unsigned begin);
Optional<unsigned> visitOp(AffineLoadOp op, unsigned begin) {
return getLoadStoreSchedule(op, begin);
}
Optional<unsigned> visitOp(AffineStoreOp op, unsigned begin) {
return getLoadStoreSchedule(op, begin);
}
unsigned getOpMinII(AffineForOp forOp);
unsigned getResMinII(LoadStoresMap &map);
unsigned getDepMinII(AffineForOp forOp, LoadStoresMap &map);
Optional<unsigned> visitOp(AffineForOp op, unsigned begin);
Optional<unsigned> visitOp(AffineIfOp op, unsigned begin);
Optional<unsigned> visitOp(ReturnOp op, unsigned begin);
Optional<unsigned> visitOp(ArrayOp op, unsigned begin);
/// Handle operations with profiled latency.
#define HANDLE(OPTYPE, KEYNAME) \
Optional<unsigned> visitOp(OPTYPE op, unsigned begin) { \
auto end = begin + latencyMap[KEYNAME] + 1; \
setScheduleValue(op, begin, end); \
return end; \
}
HANDLE(AddFOp, "fadd");
HANDLE(MulFOp, "fmul");
HANDLE(DivFOp, "fdiv");
HANDLE(CmpFOp, "fcmp");
HANDLE(SelectOp, "fselect");
#undef HANDLE
Optional<unsigned> estimateBlock(Block &block, unsigned begin);
void estimateFunc();
FuncOp &func;
DependsMap dependsMap;
PortsMapDict portsMapDict;
LatencyMap &latencyMap;
};
} // namespace
//===----------------------------------------------------------------------===//
// Helper methods
//===----------------------------------------------------------------------===//
// Check if the lhsOp and rhsOp is at the same scheduling level. In this check,
@ -123,7 +188,7 @@ static void getLoadStoresMap(Block &block, LoadStoresMap &map) {
}
//===----------------------------------------------------------------------===//
// MemRef Dependency Collection Methods
// HLSCppEstimator Class Definition
//===----------------------------------------------------------------------===//
/// Collect all dependencies detected in the function.

View File

@ -5,7 +5,6 @@
#include "Conversion/Passes.h"
#include "Dialect/HLSCpp/HLSCpp.h"
#include "mlir/Dialect/StandardOps/IR/Ops.h"
#include "mlir/Pass/Pass.h"
using namespace mlir;
using namespace scalehls;

View File

@ -8,8 +8,6 @@
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/StandardOps/IR/Ops.h"
#include "mlir/IR/IntegerSet.h"
#include "mlir/Pass/Pass.h"
#include "llvm/ADT/TypeSwitch.h"
using namespace mlir;
using namespace scalehls;

View File

@ -3,7 +3,6 @@
//===----------------------------------------------------------------------===//
#include "Dialect/HLSCpp/HLSCpp.h"
#include "mlir/IR/StandardTypes.h"
using namespace mlir;
using namespace scalehls;

View File

@ -3,7 +3,6 @@
//===----------------------------------------------------------------------===//
#include "Dialect/HLSKernel/HLSKernel.h"
#include "mlir/IR/StandardTypes.h"
using namespace mlir;
using namespace scalehls;

View File

@ -3,21 +3,14 @@
//===----------------------------------------------------------------------===//
#include "EmitHLSCpp.h"
#include "Dialect/HLSCpp/HLSCpp.h"
#include "Dialect/HLSCpp/Visitor.h"
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/Affine/IR/AffineValueMap.h"
#include "mlir/Dialect/SCF/SCF.h"
#include "mlir/Dialect/StandardOps/IR/Ops.h"
#include "mlir/IR/AffineExprVisitor.h"
#include "mlir/IR/Function.h"
#include "mlir/IR/IntegerSet.h"
#include "mlir/IR/Module.h"
#include "mlir/IR/StandardTypes.h"
#include "mlir/Support/LLVM.h"
#include "mlir/Translation.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/raw_ostream.h"
using namespace std;

View File

@ -4,9 +4,7 @@
#include "Transforms/Passes.h"
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/IntegerSet.h"
#include "mlir/Transforms/LoopUtils.h"
using namespace std;
using namespace mlir;

View File

@ -2,16 +2,14 @@
//
//===----------------------------------------------------------------------===//
#include "Analysis/QoREstimation.h"
#include "Analysis/Utils.h"
#include "Transforms/Passes.h"
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/Affine/Passes.h"
#include "mlir/IR/Builders.h"
#include "mlir/Transforms/LoopUtils.h"
using namespace std;
using namespace mlir;
using namespace scalehls;
using namespace hlscpp;
namespace {
struct ArrayPartition : public ArrayPartitionBase<ArrayPartition> {
@ -122,13 +120,13 @@ void ArrayPartition::runOnOperation() {
// Collect memory access information.
LoadStoresMap loadMap;
outermost.walk([&](mlir::AffineLoadOp loadOp) {
auto arrayOp = cast<ArrayOp>(loadOp.getMemRef().getDefiningOp());
auto arrayOp = loadOp.getMemRef().getDefiningOp();
loadMap[arrayOp].push_back(loadOp);
});
LoadStoresMap storeMap;
outermost.walk([&](mlir::AffineStoreOp storeOp) {
auto arrayOp = cast<ArrayOp>(storeOp.getMemRef().getDefiningOp());
auto arrayOp = storeOp.getMemRef().getDefiningOp();
storeMap[arrayOp].push_back(storeOp);
});

View File

@ -4,7 +4,6 @@
#include "Dialect/HLSKernel/HLSKernel.h"
#include "Transforms/Passes.h"
#include "mlir/IR/Builders.h"
using namespace std;
using namespace mlir;

View File

@ -4,7 +4,6 @@
#include "Dialect/HLSKernel/HLSKernel.h"
#include "Transforms/Passes.h"
#include "mlir/IR/Builders.h"
using namespace std;
using namespace mlir;

View File

@ -4,8 +4,6 @@
#include "Transforms/Passes.h"
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/Affine/Passes.h"
#include "mlir/IR/Builders.h"
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
#include "mlir/Transforms/LoopUtils.h"

View File

@ -4,8 +4,6 @@
#include "Transforms/Passes.h"
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/Affine/Passes.h"
#include "mlir/IR/Builders.h"
#include "mlir/Transforms/LoopUtils.h"
using namespace std;

View File

@ -2,7 +2,7 @@
//
//===----------------------------------------------------------------------===//
#include "Analysis/QoREstimation.h"
#include "Analysis/Utils.h"
#include "Dialect/HLSCpp/HLSCpp.h"
#include "Transforms/Passes.h"

View File

@ -4,8 +4,6 @@
#include "Transforms/Passes.h"
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/Affine/Passes.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/IntegerSet.h"
#include "mlir/Transforms/LoopUtils.h"

View File

@ -4,7 +4,6 @@
#include "Dialect/HLSKernel/HLSKernel.h"
#include "Transforms/Passes.h"
#include "mlir/IR/Builders.h"
using namespace std;
using namespace mlir;

View File

@ -5,18 +5,10 @@
#include "Analysis/Passes.h"
#include "Dialect/HLSKernel/HLSKernel.h"
#include "INIReader.h"
#include "Transforms/Passes.h"
#include "mlir/IR/Dialect.h"
#include "mlir/IR/MLIRContext.h"
#include "mlir/IR/Types.h"
#include "mlir/InitAllDialects.h"
#include "mlir/InitAllPasses.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Pass/PassManager.h"
#include "mlir/Support/FileUtilities.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/ToolOutputFile.h"
#include <numeric>
@ -384,12 +376,6 @@ static LogicalResult processBenchmarkGen(raw_ostream &os) {
}
int main(int argc, char **argv) {
llvm::InitLLVM y(argc, argv);
// Register any pass manager command line options.
mlir::registerPassManagerCLOptions();
mlir::PassPipelineCLParser passPipeline("", "Compiler passes to run");
// Parse pass names in main to ensure static initialization completed.
llvm::cl::ParseCommandLineOptions(argc, argv,
"MLIR modular optimizer driver\n");