mirror of https://github.com/llvm/circt.git
69 lines
2.4 KiB
C++
69 lines
2.4 KiB
C++
//===----------------------------------------------------------------------===//
|
|
//
|
|
// 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 datapath ops.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "circt/Dialect/Datapath/DatapathOps.h"
|
|
|
|
using namespace circt;
|
|
using namespace datapath;
|
|
|
|
LogicalResult CompressOp::verify() {
|
|
// The compressor must reduce the number of operands by at least 1 otherwise
|
|
// it fails to perform any reduction.
|
|
if (getNumOperands() < 3)
|
|
return emitOpError("requires 3 or more arguments - otherwise use add");
|
|
|
|
if (getNumResults() >= getNumOperands())
|
|
return emitOpError("must reduce the number of operands by at least 1");
|
|
|
|
if (getNumResults() < 2)
|
|
return emitOpError("must produce at least 2 results");
|
|
|
|
return success();
|
|
}
|
|
|
|
// Parser for the custom type format
|
|
// Parser for "<input-type> [<num-inputs> -> <num-outputs>]"
|
|
static ParseResult parseCompressFormat(OpAsmParser &parser,
|
|
SmallVectorImpl<Type> &inputTypes,
|
|
SmallVectorImpl<Type> &resultTypes) {
|
|
|
|
int64_t inputCount, resultCount;
|
|
Type inputElementType;
|
|
|
|
if (parser.parseType(inputElementType) || parser.parseLSquare() ||
|
|
parser.parseInteger(inputCount) || parser.parseArrow() ||
|
|
parser.parseInteger(resultCount) || parser.parseRSquare())
|
|
return failure();
|
|
|
|
// Inputs and results have same type
|
|
inputTypes.assign(inputCount, inputElementType);
|
|
resultTypes.assign(resultCount, inputElementType);
|
|
|
|
return success();
|
|
}
|
|
|
|
// Printer for "<input-type> [<num-inputs> -> <num-outputs>]"
|
|
static void printCompressFormat(OpAsmPrinter &printer, Operation *op,
|
|
TypeRange inputTypes, TypeRange resultTypes) {
|
|
|
|
printer << inputTypes[0] << " [" << inputTypes.size() << " -> "
|
|
<< resultTypes.size() << "]";
|
|
}
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// TableGen generated logic.
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Provide the autogenerated implementation guts for the Op classes.
|
|
#define GET_OP_CLASSES
|
|
#include "circt/Dialect/Datapath/Datapath.cpp.inc"
|