CIRCT 24.0.0git
Loading...
Searching...
No Matches
CombToSynth.cpp File Reference
#include "circt/Conversion/CombToSynth.h"
#include "circt/Dialect/Comb/CombOps.h"
#include "circt/Dialect/Datapath/DatapathOps.h"
#include "circt/Dialect/HW/HWOps.h"
#include "circt/Dialect/Synth/SynthDialect.h"
#include "circt/Dialect/Synth/SynthOps.h"
#include "circt/Support/LLVM.h"
#include "circt/Support/Naming.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Transforms/DialectConversion.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/PointerUnion.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/DivisionByConstantInfo.h"
#include <array>
#include <utility>
#include "circt/Conversion/Passes.h.inc"
Include dependency graph for CombToSynth.cpp:

Go to the source code of this file.

Namespaces

namespace  circt
 The InstanceGraph op interface, see InstanceGraphInterface.td for more details.

Macros

#define DEBUG_TYPE   "comb-to-synth"
#define GEN_PASS_DEF_CONVERTCOMBTOSYNTH

Functions

static SmallVector< Value > extractBits (OpBuilder &builder, Value val)
template<bool isLeftShift>
static Value createShiftLogic (ConversionPatternRewriter &rewriter, Location loc, Value shiftAmount, int64_t maxShiftAmount, llvm::function_ref< Value(int64_t)> getPadding, llvm::function_ref< Value(int64_t)> getExtract)
static Value createMajorityFunction (OpBuilder &rewriter, Location loc, Value a, Value b, Value carry)
static Value extractMSB (OpBuilder &builder, Value val)
static Value extractOtherThanMSB (OpBuilder &builder, Value val)
static int64_t getNumUnknownBitsAndPopulateValues (Value value, llvm::SmallVectorImpl< ConstantOrValue > &values)
static APInt substitueMaskToValues (size_t width, llvm::SmallVectorImpl< ConstantOrValue > &constantOrValues, uint32_t mask)
static LogicalResult emulateBinaryOpForUnknownBits (ConversionPatternRewriter &rewriter, int64_t maxEmulationUnknownBits, Operation *op, llvm::function_ref< APInt(const APInt &, const APInt &)> emulate)
static Value createLShrByConstant (OpBuilder &builder, Location loc, Value value, unsigned amount)
static Value createAShrByConstant (OpBuilder &builder, Location loc, Value value, unsigned amount)
template<bool isSigned>
static Value createMulHigh (OpBuilder &builder, Location loc, Value lhs, const APInt &rhs)
static Value lowerUnsignedDivByConstant (OpBuilder &builder, Location loc, Value lhs, const APInt &divisor)
static Value lowerSignedDivByConstant (OpBuilder &builder, Location loc, Value lhs, const APInt &divisor)
static std::pair< Value, Value > lowerUnsignedDivRem (OpBuilder &builder, Location loc, Value lhs, Value rhs)
 Lower an unsigned division with a non-constant divisor to a combinational restoring array divider.
static std::pair< Value, Value > lowerSignedDivRem (OpBuilder &builder, Location loc, Value lhs, Value rhs)
 Lower a signed division with a non-constant divisor to a restoring array divider operating on the magnitudes of the operands.
static void populateCombToAIGConversionPatterns (RewritePatternSet &patterns, uint32_t maxEmulationUnknownBits, bool forceAIG)

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "comb-to-synth"

Definition at line 42 of file CombToSynth.cpp.

◆ GEN_PASS_DEF_CONVERTCOMBTOSYNTH

#define GEN_PASS_DEF_CONVERTCOMBTOSYNTH

Definition at line 45 of file CombToSynth.cpp.

Function Documentation

◆ createAShrByConstant()

Value createAShrByConstant ( OpBuilder & builder,
Location loc,
Value value,
unsigned amount )
static

Definition at line 287 of file CombToSynth.cpp.

References hw.ConstantOp::create().

Referenced by lowerSignedDivByConstant().

◆ createLShrByConstant()

Value createLShrByConstant ( OpBuilder & builder,
Location loc,
Value value,
unsigned amount )
static

Definition at line 276 of file CombToSynth.cpp.

References hw.ConstantOp::create().

Referenced by lowerUnsignedDivByConstant().

◆ createMajorityFunction()

Value createMajorityFunction ( OpBuilder & rewriter,
Location loc,
Value a,
Value b,
Value carry )
static

Definition at line 119 of file CombToSynth.cpp.

◆ createMulHigh()

template<bool isSigned>
Value createMulHigh ( OpBuilder & builder,
Location loc,
Value lhs,
const APInt & rhs )
static

Definition at line 299 of file CombToSynth.cpp.

References hw.ConstantOp::create().

Referenced by lowerSignedDivByConstant(), and lowerUnsignedDivByConstant().

◆ createShiftLogic()

template<bool isLeftShift>
Value createShiftLogic ( ConversionPatternRewriter & rewriter,
Location loc,
Value shiftAmount,
int64_t maxShiftAmount,
llvm::function_ref< Value(int64_t)> getPadding,
llvm::function_ref< Value(int64_t)> getExtract )
static

Definition at line 71 of file CombToSynth.cpp.

References assert(), hw.ConstantOp::create(), and extractBits().

◆ emulateBinaryOpForUnknownBits()

LogicalResult emulateBinaryOpForUnknownBits ( ConversionPatternRewriter & rewriter,
int64_t maxEmulationUnknownBits,
Operation * op,
llvm::function_ref< APInt(const APInt &, const APInt &)> emulate )
static

◆ extractBits()

SmallVector< Value > extractBits ( OpBuilder & builder,
Value val )
static

◆ extractMSB()

Value extractMSB ( OpBuilder & builder,
Value val )
static

Definition at line 129 of file CombToSynth.cpp.

◆ extractOtherThanMSB()

Value extractOtherThanMSB ( OpBuilder & builder,
Value val )
static

Definition at line 134 of file CombToSynth.cpp.

◆ getNumUnknownBitsAndPopulateValues()

int64_t getNumUnknownBitsAndPopulateValues ( Value value,
llvm::SmallVectorImpl< ConstantOrValue > & values )
static

◆ lowerSignedDivByConstant()

Value lowerSignedDivByConstant ( OpBuilder & builder,
Location loc,
Value lhs,
const APInt & divisor )
static

Definition at line 327 of file CombToSynth.cpp.

References createAShrByConstant(), and createMulHigh().

◆ lowerSignedDivRem()

std::pair< Value, Value > lowerSignedDivRem ( OpBuilder & builder,
Location loc,
Value lhs,
Value rhs )
static

Lower a signed division with a non-constant divisor to a restoring array divider operating on the magnitudes of the operands.

Returns the quotient and the remainder, rounded towards zero like comb.divs / comb.mods: the quotient is negative iff the signs of the operands differ, and the remainder takes the sign of the dividend.

Definition at line 397 of file CombToSynth.cpp.

References hw.ConstantOp::create(), and lowerUnsignedDivRem().

◆ lowerUnsignedDivByConstant()

Value lowerUnsignedDivByConstant ( OpBuilder & builder,
Location loc,
Value lhs,
const APInt & divisor )
static

Definition at line 314 of file CombToSynth.cpp.

References createLShrByConstant(), and createMulHigh().

◆ lowerUnsignedDivRem()

std::pair< Value, Value > lowerUnsignedDivRem ( OpBuilder & builder,
Location loc,
Value lhs,
Value rhs )
static

Lower an unsigned division with a non-constant divisor to a combinational restoring array divider.

Returns the quotient and the remainder.

The divider processes the dividend from MSB to LSB. In every step the partial remainder is shifted left by one, the next dividend bit is shifted in, and the divisor is trially subtracted. If the subtraction does not borrow, the quotient bit is one and the difference becomes the new partial remainder; otherwise the quotient bit is zero and the partial remainder is restored. The partial remainder is kept width + 1 bits wide so the borrow can be read off the MSB of the difference.

Division by zero yields an all-ones quotient and the dividend as remainder.

Definition at line 359 of file CombToSynth.cpp.

References hw.ConstantOp::create(), and extractBits().

Referenced by lowerSignedDivRem().

◆ populateCombToAIGConversionPatterns()

void populateCombToAIGConversionPatterns ( RewritePatternSet & patterns,
uint32_t maxEmulationUnknownBits,
bool forceAIG )
static

◆ substitueMaskToValues()

APInt substitueMaskToValues ( size_t width,
llvm::SmallVectorImpl< ConstantOrValue > & constantOrValues,
uint32_t mask )
static

Definition at line 178 of file CombToSynth.cpp.

References assert(), and circt::hw::getBitWidth().

Referenced by emulateBinaryOpForUnknownBits().