mirror of https://github.com/llvm/circt.git
64 lines
2.5 KiB
C++
64 lines
2.5 KiB
C++
//===- CombDialect.cpp - Implement the Comb dialect -----------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file implements the Comb dialect.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "circt/Dialect/Comb/CombDialect.h"
|
|
#include "circt/Dialect/Comb/CombOps.h"
|
|
#include "circt/Dialect/HW/HWOps.h"
|
|
#include "mlir/IR/Builders.h"
|
|
#include "mlir/IR/BuiltinTypes.h"
|
|
#include "mlir/IR/DialectImplementation.h"
|
|
|
|
using namespace circt;
|
|
using namespace comb;
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// Dialect specification.
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
void CombDialect::initialize() {
|
|
// Register operations.
|
|
addOperations<
|
|
#define GET_OP_LIST
|
|
#include "circt/Dialect/Comb/Comb.cpp.inc"
|
|
>();
|
|
}
|
|
|
|
/// Registered hook to materialize a single constant operation from a given
|
|
/// attribute value with the desired resultant type. This method should use
|
|
/// the provided builder to create the operation without changing the
|
|
/// insertion position. The generated operation is expected to be constant
|
|
/// like, i.e. single result, zero operands, non side-effecting, etc. On
|
|
/// success, this hook should return the value generated to represent the
|
|
/// constant value. Otherwise, it should return null on failure.
|
|
Operation *CombDialect::materializeConstant(OpBuilder &builder, Attribute value,
|
|
Type type, Location loc) {
|
|
// Integer constants.
|
|
if (auto intType = dyn_cast<IntegerType>(type))
|
|
if (auto attrValue = dyn_cast<IntegerAttr>(value))
|
|
return hw::ConstantOp::create(builder, loc, type, attrValue);
|
|
|
|
// Parameter expressions materialize into hw.param.value.
|
|
auto *parentOp = builder.getBlock()->getParentOp();
|
|
auto curModule = dyn_cast<hw::HWModuleOp>(parentOp);
|
|
if (!curModule)
|
|
curModule = parentOp->getParentOfType<hw::HWModuleOp>();
|
|
if (curModule && isValidParameterExpression(value, curModule))
|
|
return hw::ParamValueOp::create(builder, loc, type, value);
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
// Provide implementations for the enums we use.
|
|
#include "circt/Dialect/Comb/CombEnums.cpp.inc"
|
|
|
|
#include "circt/Dialect/Comb/CombDialect.cpp.inc"
|