Rename include/spt -> include/cirt, NFC.

This commit is contained in:
Chris Lattner 2020-04-29 11:34:22 -07:00
parent 9d11c786d4
commit 7ff6ffdf2f
30 changed files with 365 additions and 30 deletions

View File

@ -27,7 +27,7 @@ include_directories( ${MLIR_BINARY_INCLUDE_DIR})
include_directories( ${SPT_INCLUDE_DIR})
include_directories( ${SPT_MAIN_SRC_DIR})
add_subdirectory(include/spt)
add_subdirectory(include/cirt)
add_subdirectory(lib)
add_subdirectory(tools)
#add_subdirectory(unittests)

View File

@ -0,0 +1,42 @@
//===- FIRRTL/IR/Dialect.h - FIRRTL dialect declaration ---------*- C++ -*-===//
//
// This file defines an MLIR dialect for the FIRRTL IR.
//
//===----------------------------------------------------------------------===//
#ifndef SPT_DIALECT_FIRRTL_IR_DIALECT_H
#define SPT_DIALECT_FIRRTL_IR_DIALECT_H
#include "mlir/IR/Dialect.h"
namespace cirt {
namespace firrtl {
using namespace mlir;
class FIRRTLType;
class FIRRTLDialect : public Dialect {
public:
/// Create the dialect in the given `context`.
explicit FIRRTLDialect(MLIRContext *context);
~FIRRTLDialect();
Type parseType(DialectAsmParser &parser) const override;
void printType(Type, DialectAsmPrinter &) const override;
Operation *materializeConstant(OpBuilder &builder, Attribute value, Type type,
Location loc) override;
static StringRef getDialectNamespace() { return "firrtl"; }
};
/// If the specified attribute list has a firrtl.name attribute, return its
/// value.
StringAttr getFIRRTLNameAttr(ArrayRef<NamedAttribute> attrs);
} // namespace firrtl
} // namespace cirt
// Pull in all enum type definitions and utility function declarations.
#include "cirt/Dialect/FIRRTL/FIRRTLEnums.h.inc"
#endif // SPT_DIALECT_FIRRTL_IR_DIALECT_H

View File

@ -0,0 +1,67 @@
//===- FIRRTL/IR/Ops.h - Declare FIRRTL dialect operations ------*- C++ -*-===//
//
// This file declares the operation class for the FIRRTL IR.
//
//===----------------------------------------------------------------------===//
#ifndef SPT_DIALECT_FIRRTL_IR_OPS_H
#define SPT_DIALECT_FIRRTL_IR_OPS_H
#include "cirt/Dialect/FIRRTL/Dialect.h"
#include "cirt/Dialect/FIRRTL/Types.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/FunctionSupport.h"
#include "mlir/IR/SymbolTable.h"
#include "mlir/Interfaces/SideEffects.h"
namespace cirt {
namespace firrtl {
/// Return true if the specified operation is a firrtl expression.
bool isExpression(Operation *op);
// Binary primitives.
FIRRTLType getAddSubResult(FIRRTLType lhs, FIRRTLType rhs);
FIRRTLType getMulResult(FIRRTLType lhs, FIRRTLType rhs);
FIRRTLType getDivResult(FIRRTLType lhs, FIRRTLType rhs);
FIRRTLType getRemResult(FIRRTLType lhs, FIRRTLType rhs);
FIRRTLType getCompareResult(FIRRTLType lhs, FIRRTLType rhs);
FIRRTLType getBitwiseBinaryResult(FIRRTLType lhs, FIRRTLType rhs);
FIRRTLType getCatResult(FIRRTLType lhs, FIRRTLType rhs);
FIRRTLType getDShlResult(FIRRTLType lhs, FIRRTLType rhs);
FIRRTLType getDShrResult(FIRRTLType lhs, FIRRTLType rhs);
FIRRTLType getValidIfResult(FIRRTLType lhs, FIRRTLType rhs);
// Unary primitives.
FIRRTLType getAsAsyncResetResult(FIRRTLType input);
FIRRTLType getAsClockResult(FIRRTLType input);
FIRRTLType getAsSIntResult(FIRRTLType input);
FIRRTLType getAsUIntResult(FIRRTLType input);
FIRRTLType getCvtResult(FIRRTLType input);
FIRRTLType getNegResult(FIRRTLType input);
FIRRTLType getNotResult(FIRRTLType input);
FIRRTLType getReductionResult(FIRRTLType input);
FIRRTLType getAsPassiveResult(FIRRTLType input);
typedef std::pair<StringAttr, FIRRTLType> ModulePortInfo;
/// Return the function type that corresponds to a module.
FunctionType getModuleType(Operation *op);
/// This function can extract information about ports from a module and an
/// extmodule.
void getModulePortInfo(Operation *op, SmallVectorImpl<ModulePortInfo> &results);
} // namespace firrtl
} // namespace cirt
namespace cirt {
namespace firrtl {
#define GET_OP_CLASSES
#include "cirt/Dialect/FIRRTL/FIRRTL.h.inc"
} // namespace firrtl
} // namespace cirt
#endif // SPT_DIALECT_FIRRTL_IR_OPS_H

View File

@ -0,0 +1,226 @@
//===- FIRRTL/IR/Visitors.h - FIRRTL Dialect Visitors -----------*- C++ -*-===//
//
// This file defines visitors that make it easier to work with FIRRTL IR.
//
//===----------------------------------------------------------------------===//
#ifndef SPT_DIALECT_FIRRTL_IR_VISITORS_H
#define SPT_DIALECT_FIRRTL_IR_VISITORS_H
#include "cirt/Dialect/FIRRTL/Ops.h"
#include "llvm/ADT/TypeSwitch.h"
namespace cirt {
namespace firrtl {
/// ExprVisitor is a visitor for FIRRTL expression nodes.
template <typename ConcreteType, typename ResultType = void,
typename... ExtraArgs>
class ExprVisitor {
public:
ResultType dispatchExprVisitor(Operation *op, ExtraArgs... args) {
auto *thisCast = static_cast<ConcreteType *>(this);
return TypeSwitch<Operation *, ResultType>(op)
// Basic Expressions
.template Case<
ConstantOp, SubfieldOp, SubindexOp, SubaccessOp,
// Arithmetic and Logical Binary Primitives.
AddPrimOp, SubPrimOp, MulPrimOp, DivPrimOp, RemPrimOp, AndPrimOp,
OrPrimOp, XorPrimOp,
// Comparisons.
LEQPrimOp, LTPrimOp, GEQPrimOp, GTPrimOp, EQPrimOp, NEQPrimOp,
// Misc Binary Primitives.
CatPrimOp, DShlPrimOp, DShrPrimOp, ValidIfPrimOp,
// Unary operators.
AsSIntPrimOp, AsUIntPrimOp, AsAsyncResetPrimOp, AsClockPrimOp,
CvtPrimOp, NegPrimOp, NotPrimOp, AndRPrimOp, OrRPrimOp, XorRPrimOp,
// Miscellaneous.
BitsPrimOp, HeadPrimOp, MuxPrimOp, PadPrimOp, ShlPrimOp, ShrPrimOp,
TailPrimOp>([&](auto expr) -> ResultType {
return thisCast->visitExpr(expr, args...);
})
.Default([&](auto expr) -> ResultType {
return thisCast->visitInvalidExpr(op, args...);
});
}
/// This callback is invoked on any non-expression operations.
ResultType visitInvalidExpr(Operation *op, ExtraArgs... args) {
op->emitOpError("unknown firrtl expression");
abort();
}
/// This callback is invoked on any expression operations that are not handled
/// by the concrete visitor.
ResultType visitUnhandledExpr(Operation *op, ExtraArgs... args) {
return ResultType();
}
/// This fallback is invoked on any unary expr that isn't explicitly handled.
/// The default implementation delegates to the unhandled expression fallback.
ResultType visitUnaryExpr(Operation *op, ExtraArgs... args) {
return static_cast<ConcreteType *>(this)->visitUnhandledExpr(op, args...);
}
/// This fallback is invoked on any binary expr that isn't explicitly handled.
/// The default implementation delegates to the unhandled expression fallback.
ResultType visitBinaryExpr(Operation *op, ExtraArgs... args) {
return static_cast<ConcreteType *>(this)->visitUnhandledExpr(op, args...);
}
#define HANDLE(OPTYPE, OPKIND) \
ResultType visitExpr(OPTYPE op, ExtraArgs... args) { \
return static_cast<ConcreteType *>(this)->visit##OPKIND##Expr(op, \
args...); \
}
// Basic expressions.
HANDLE(ConstantOp, Unhandled)
HANDLE(SubfieldOp, Unhandled);
HANDLE(SubindexOp, Unhandled);
HANDLE(SubaccessOp, Unhandled);
// Arithmetic and Logical Binary Primitives.
HANDLE(AddPrimOp, Binary);
HANDLE(SubPrimOp, Binary);
HANDLE(MulPrimOp, Binary);
HANDLE(DivPrimOp, Binary);
HANDLE(RemPrimOp, Binary);
HANDLE(AndPrimOp, Binary);
HANDLE(OrPrimOp, Binary);
HANDLE(XorPrimOp, Binary);
// Comparisons.
HANDLE(LEQPrimOp, Binary);
HANDLE(LTPrimOp, Binary);
HANDLE(GEQPrimOp, Binary);
HANDLE(GTPrimOp, Binary);
HANDLE(EQPrimOp, Binary);
HANDLE(NEQPrimOp, Binary);
// Misc Binary Primitives.
HANDLE(CatPrimOp, Binary);
HANDLE(DShlPrimOp, Binary);
HANDLE(DShrPrimOp, Binary);
HANDLE(ValidIfPrimOp, Binary);
// Unary operators.
HANDLE(AsSIntPrimOp, Unary);
HANDLE(AsUIntPrimOp, Unary);
HANDLE(AsAsyncResetPrimOp, Unary);
HANDLE(AsClockPrimOp, Unary);
HANDLE(CvtPrimOp, Unary);
HANDLE(NegPrimOp, Unary);
HANDLE(NotPrimOp, Unary);
HANDLE(AndRPrimOp, Unary);
HANDLE(OrRPrimOp, Unary);
HANDLE(XorRPrimOp, Unary);
// Miscellaneous.
HANDLE(BitsPrimOp, Unhandled);
HANDLE(HeadPrimOp, Unhandled);
HANDLE(MuxPrimOp, Unhandled);
HANDLE(PadPrimOp, Unhandled);
HANDLE(ShlPrimOp, Unhandled);
HANDLE(ShrPrimOp, Unhandled);
HANDLE(TailPrimOp, Unhandled);
#undef HANDLE
};
/// ExprVisitor is a visitor for FIRRTL statement nodes.
template <typename ConcreteType, typename ResultType = void,
typename... ExtraArgs>
class StmtVisitor {
public:
ResultType dispatchStmtVisitor(Operation *op, ExtraArgs... args) {
auto *thisCast = static_cast<ConcreteType *>(this);
return TypeSwitch<Operation *, ResultType>(op)
.template Case<ConnectOp, DoneOp, InvalidOp, MemoryPortOp,
PartialConnectOp, PrintFOp, SkipOp, StopOp, WhenOp>(
[&](auto opNode) -> ResultType {
return thisCast->visitStmt(opNode, args...);
})
.Default([&](auto expr) -> ResultType {
return thisCast->visitInvalidStmt(op, args...);
});
}
/// This callback is invoked on any non-Stmt operations.
ResultType visitInvalidStmt(Operation *op, ExtraArgs... args) {
op->emitOpError("unknown firrtl stmt");
abort();
}
/// This callback is invoked on any Stmt operations that are not handled
/// by the concrete visitor.
ResultType visitUnhandledStmt(Operation *op, ExtraArgs... args) {
return ResultType();
}
#define HANDLE(OPTYPE) \
ResultType visitStmt(OPTYPE op, ExtraArgs... args) { \
return static_cast<ConcreteType *>(this)->visitUnhandledStmt(op, args...); \
}
HANDLE(ConnectOp);
HANDLE(DoneOp);
HANDLE(InvalidOp);
HANDLE(MemoryPortOp);
HANDLE(PartialConnectOp);
HANDLE(PrintFOp);
HANDLE(SkipOp);
HANDLE(StopOp);
HANDLE(WhenOp);
#undef HANDLE
};
/// ExprVisitor is a visitor for FIRRTL declaration nodes.
template <typename ConcreteType, typename ResultType = void,
typename... ExtraArgs>
class DeclVisitor {
public:
ResultType dispatchDeclVisitor(Operation *op, ExtraArgs... args) {
auto *thisCast = static_cast<ConcreteType *>(this);
return TypeSwitch<Operation *, ResultType>(op)
.template Case<CMemOp, InstanceOp, MemOp, NodeOp, RegOp, SMemOp,
RegInitOp, WireOp>([&](auto opNode) -> ResultType {
return thisCast->visitDecl(opNode, args...);
})
.Default([&](auto expr) -> ResultType {
return thisCast->visitInvalidDecl(op, args...);
});
}
/// This callback is invoked on any non-Decl operations.
ResultType visitInvalidDecl(Operation *op, ExtraArgs... args) {
op->emitOpError("unknown firrtl decl");
abort();
}
/// This callback is invoked on any Decl operations that are not handled
/// by the concrete visitor.
ResultType visitUnhandledDecl(Operation *op, ExtraArgs... args) {
return ResultType();
}
#define HANDLE(OPTYPE) \
ResultType visitDecl(OPTYPE op, ExtraArgs... args) { \
return static_cast<ConcreteType *>(this)->visitUnhandledDecl(op, args...); \
}
HANDLE(CMemOp);
HANDLE(InstanceOp);
HANDLE(MemOp);
HANDLE(NodeOp);
HANDLE(RegOp);
HANDLE(RegInitOp);
HANDLE(SMemOp);
HANDLE(WireOp);
#undef HANDLE
};
} // namespace firrtl
} // namespace cirt
#endif // SPT_DIALECT_FIRRTL_IR_VISITORS_H

View File

@ -7,7 +7,7 @@
#ifndef SPT_EMIT_VERILOG_H
#define SPT_EMIT_VERILOG_H
#include "spt/Support/LLVM.h"
#include "cirt/Support/LLVM.h"
namespace mlir {
struct LogicalResult;

View File

@ -37,6 +37,6 @@ StringAttr getFIRRTLNameAttr(ArrayRef<NamedAttribute> attrs);
} // namespace cirt
// Pull in all enum type definitions and utility function declarations.
#include "spt/Dialect/FIRRTL/FIRRTLEnums.h.inc"
#include "cirt/Dialect/FIRRTL/FIRRTLEnums.h.inc"
#endif // SPT_DIALECT_FIRRTL_IR_DIALECT_H

View File

@ -11,8 +11,8 @@
#include "mlir/IR/FunctionSupport.h"
#include "mlir/IR/SymbolTable.h"
#include "mlir/Interfaces/SideEffects.h"
#include "spt/Dialect/FIRRTL/Dialect.h"
#include "spt/Dialect/FIRRTL/Types.h"
#include "cirt/Dialect/FIRRTL/Dialect.h"
#include "cirt/Dialect/FIRRTL/Types.h"
namespace cirt {
namespace firrtl {
@ -59,7 +59,7 @@ namespace cirt {
namespace firrtl {
#define GET_OP_CLASSES
#include "spt/Dialect/FIRRTL/FIRRTL.h.inc"
#include "cirt/Dialect/FIRRTL/FIRRTL.h.inc"
} // namespace firrtl
} // namespace cirt

View File

@ -7,7 +7,7 @@
#ifndef SPT_DIALECT_FIRRTL_IR_VISITORS_H
#define SPT_DIALECT_FIRRTL_IR_VISITORS_H
#include "spt/Dialect/FIRRTL/Ops.h"
#include "cirt/Dialect/FIRRTL/Ops.h"
#include "llvm/ADT/TypeSwitch.h"
namespace cirt {

View File

@ -2,9 +2,9 @@
//
//===----------------------------------------------------------------------===//
#include "spt/Dialect/FIRRTL/Dialect.h"
#include "cirt/Dialect/FIRRTL/Dialect.h"
#include "cirt/Dialect/FIRRTL/Ops.h"
#include "mlir/IR/DialectImplementation.h"
#include "spt/Dialect/FIRRTL/Ops.h"
using namespace cirt;
using namespace firrtl;
@ -102,7 +102,7 @@ FIRRTLDialect::FIRRTLDialect(MLIRContext *context)
// Register operations.
addOperations<
#define GET_OP_LIST
#include "spt/Dialect/FIRRTL/FIRRTL.cpp.inc"
#include "cirt/Dialect/FIRRTL/FIRRTL.cpp.inc"
>();
// Register interface implementations.
@ -134,4 +134,4 @@ Operation *FIRRTLDialect::materializeConstant(OpBuilder &builder,
}
// Provide implementations for the enums we use.
#include "spt/Dialect/FIRRTL/FIRRTLEnums.cpp.inc"
#include "cirt/Dialect/FIRRTL/FIRRTLEnums.cpp.inc"

View File

@ -2,7 +2,7 @@
//
//===----------------------------------------------------------------------===//
#include "spt/Dialect/FIRRTL/Dialect.h"
#include "cirt/Dialect/FIRRTL/Dialect.h"
using namespace cirt;
using namespace firrtl;

View File

@ -2,13 +2,13 @@
//
//===----------------------------------------------------------------------===//
#include "spt/Dialect/FIRRTL/Ops.h"
#include "cirt/Dialect/FIRRTL/Ops.h"
#include "cirt/Dialect/FIRRTL/Visitors.h"
#include "mlir/Dialect/CommonFolders.h"
#include "mlir/IR/DialectImplementation.h"
#include "mlir/IR/FunctionImplementation.h"
#include "mlir/IR/Matchers.h"
#include "mlir/IR/StandardTypes.h"
#include "spt/Dialect/FIRRTL/Visitors.h"
using namespace cirt;
using namespace firrtl;
@ -946,4 +946,4 @@ FIRRTLType TailPrimOp::getResultType(FIRRTLType input, int32_t amount) {
// Provide the autogenerated implementation guts for the Op classes.
#define GET_OP_CLASSES
#include "spt/Dialect/FIRRTL/FIRRTL.cpp.inc"
#include "cirt/Dialect/FIRRTL/FIRRTL.cpp.inc"

View File

@ -2,9 +2,9 @@
//
//===----------------------------------------------------------------------===//
#include "spt/Dialect/FIRRTL/Types.h"
#include "cirt/Dialect/FIRRTL/Types.h"
#include "cirt/Dialect/FIRRTL/Ops.h"
#include "mlir/IR/DialectImplementation.h"
#include "spt/Dialect/FIRRTL/Ops.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringSwitch.h"

View File

@ -4,11 +4,11 @@
//
//===----------------------------------------------------------------------===//
#include "spt/EmitVerilog.h"
#include "cirt/EmitVerilog.h"
#include "cirt/Dialect/FIRRTL/Visitors.h"
#include "cirt/Support/LLVM.h"
#include "mlir/IR/Module.h"
#include "mlir/Translation.h"
#include "spt/Dialect/FIRRTL/Visitors.h"
#include "spt/Support/LLVM.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Support/raw_ostream.h"

View File

@ -7,7 +7,7 @@
#ifndef FIRTOMLIR_FIRLEXER_H
#define FIRTOMLIR_FIRLEXER_H
#include "spt/Support/LLVM.h"
#include "cirt/Support/LLVM.h"
#include "llvm/Support/SourceMgr.h"
namespace mlir {

View File

@ -4,14 +4,14 @@
//
//===----------------------------------------------------------------------===//
#include "spt/FIRParser.h"
#include "cirt/FIRParser.h"
#include "FIRLexer.h"
#include "cirt/Dialect/FIRRTL/Ops.h"
#include "mlir/Analysis/Verifier.h"
#include "mlir/IR/Diagnostics.h"
#include "mlir/IR/Module.h"
#include "mlir/IR/StandardTypes.h"
#include "mlir/Translation.h"
#include "spt/Dialect/FIRRTL/Ops.h"
#include "llvm/ADT/ScopedHashTable.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/raw_ostream.h"

View File

@ -5,6 +5,9 @@
//
//===----------------------------------------------------------------------===//
#include "cirt/Dialect/FIRRTL/Dialect.h"
#include "cirt/EmitVerilog.h"
#include "cirt/FIRParser.h"
#include "mlir/Dialect/StandardOps/IR/Ops.h"
#include "mlir/IR/Module.h"
#include "mlir/Parser.h"
@ -12,9 +15,6 @@
#include "mlir/Pass/PassManager.h"
#include "mlir/Support/FileUtilities.h"
#include "mlir/Transforms/Passes.h"
#include "spt/Dialect/FIRRTL/Dialect.h"
#include "spt/EmitVerilog.h"
#include "spt/FIRParser.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/ToolOutputFile.h"

View File

@ -5,6 +5,7 @@
//
//===----------------------------------------------------------------------===//
#include "cirt/Dialect/FIRRTL/Dialect.h"
#include "mlir/Dialect/StandardOps/IR/Ops.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Pass/PassManager.h"
@ -12,7 +13,6 @@
#include "mlir/Support/FileUtilities.h"
#include "mlir/Support/MlirOptMain.h"
#include "mlir/Transforms/Passes.h"
#include "spt/Dialect/FIRRTL/Dialect.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/ToolOutputFile.h"

View File

@ -5,6 +5,9 @@
//
//===----------------------------------------------------------------------===//
#include "cirt/Dialect/FIRRTL/Dialect.h"
#include "cirt/EmitVerilog.h"
#include "cirt/FIRParser.h"
#include "mlir/Dialect/StandardOps/IR/Ops.h"
#include "mlir/IR/AsmState.h"
#include "mlir/IR/Diagnostics.h"
@ -13,9 +16,6 @@
#include "mlir/Support/FileUtilities.h"
#include "mlir/Support/ToolUtilities.h"
#include "mlir/Translation.h"
#include "spt/Dialect/FIRRTL/Dialect.h"
#include "spt/EmitVerilog.h"
#include "spt/FIRParser.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/ToolOutputFile.h"