CIRCT  19.0.0git
Typedefs | Functions
LLHDToLLVM.cpp File Reference
#include "circt/Conversion/LLHDToLLVM.h"
#include "../PassDetail.h"
#include "circt/Conversion/CombToArith.h"
#include "circt/Conversion/CombToLLVM.h"
#include "circt/Conversion/HWToLLVM.h"
#include "circt/Dialect/LLHD/IR/LLHDDialect.h"
#include "circt/Dialect/LLHD/IR/LLHDOps.h"
#include "circt/Support/LLVM.h"
#include "circt/Support/Namespace.h"
#include "mlir/Conversion/ArithToLLVM/ArithToLLVM.h"
#include "mlir/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.h"
#include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVM.h"
#include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVMPass.h"
#include "mlir/Conversion/LLVMCommon/ConversionTarget.h"
#include "mlir/Conversion/LLVMCommon/Pattern.h"
#include "mlir/Conversion/ReconcileUnrealizedCasts/ReconcileUnrealizedCasts.h"
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/IR/IRMapping.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Transforms/DialectConversion.h"
Include dependency graph for LLHDToLLVM.cpp:

Go to the source code of this file.

Typedefs

using LoadOpConversion = OneToOneConvertToLLVMPattern< llhd::LoadOp, LLVM::LoadOp >
 

Functions

static Value getGlobalString (Location loc, OpBuilder &builder, const TypeConverter *typeConverter, LLVM::GlobalOp &str)
 Get an existing global string. More...
 
static LLVM::LLVMFuncOp getOrInsertFunction (ModuleOp &module, ConversionPatternRewriter &rewriter, Location loc, std::string name, Type signature, bool insertBodyAndTerminator=false)
 Looks up a symbol and inserts a new functino at the beginning of the module's region in case the function does not exists. More...
 
static Type getLLVMSigType (LLVM::LLVMDialect *dialect)
 Return the LLVM type used to represent a signal. More...
 
static std::vector< Value > getSignalDetail (ConversionPatternRewriter &rewriter, LLVM::LLVMDialect *dialect, Location loc, Value signal, bool extractIndices=false)
 Extract the details from the given signal struct. More...
 
static Value createSubSig (LLVM::LLVMDialect *dialect, ConversionPatternRewriter &rewriter, Location loc, std::vector< Value > originDetail, Value newPtr, Value newOffset)
 Create a subsignal struct. More...
 
static bool isWaitDestArg (WaitOp op, Value val)
 Returns true if the given value is passed as an argument to the destination block of the given WaitOp. More...
 
static bool isWaitDestArg (Operation *op)
 
static Type getProcPersistenceTy (LLVM::LLVMDialect *dialect, const TypeConverter *converter, ProcOp &proc)
 Gather the types of values that are used outside of the block they're defined in. More...
 
static void insertComparisonBlock (ConversionPatternRewriter &rewriter, LLVM::LLVMDialect *dialect, Location loc, Region *body, Value resumeIdx, int currIdx, Block *trueDest, ValueRange trueDestArgs, Block *falseDest=nullptr)
 Insert a comparison block that either jumps to the trueDest block, if the resume index mathces the current index, or to falseDest otherwise. More...
 
static Value gepPersistenceState (LLVM::LLVMDialect *dialect, Location loc, ConversionPatternRewriter &rewriter, Type stateTy, int index, Value state)
 Insert a GEP operation to the pointer of the i-th value in the process persistence table. More...
 
static void persistValue (LLVM::LLVMDialect *dialect, Location loc, const TypeConverter *converter, ConversionPatternRewriter &rewriter, Type stateTy, int &i, Value state, Value persist)
 Persist a Value by storing it into the process persistence table, and substituting the uses that escape the block the operation is defined in with a load from the persistence table. More...
 
static void insertPersistence (const TypeConverter *converter, ConversionPatternRewriter &rewriter, LLVM::LLVMDialect *dialect, Location loc, ProcOp &proc, Type &stateTy, LLVM::LLVMFuncOp &converted, Operation *splitEntryBefore)
 Insert the blocks and operations needed to persist values across suspension, as well as ones needed to resume execution at the right spot. More...
 
static LLVM::LLVMStructType getRegStateTy (LLVM::LLVMDialect *dialect, Operation *entity)
 Return a struct type of arrays containing one entry for each RegOp condition that require more than one state of the trigger to infer it (i.e. More...
 
static Value zextByOne (Location loc, ConversionPatternRewriter &rewriter, Value value)
 Create a zext operation by one bit on the given value. More...
 
static Value adjustBitWidth (Location loc, ConversionPatternRewriter &rewriter, Type targetTy, Value value)
 Adjust the bithwidth of value to be the same as targetTy's bitwidth. More...
 
static unsigned getIndexOfOperandResult (Operation *op, Value result)
 
static Value recursiveCloneInit (OpBuilder &initBuilder, IRMapping &mapping, Value init)
 Recursively clone the init origin of a sig operation into the init function, up to the initial constant value(s). More...
 
static bool isArrayOrStruct (Type type)
 Check if the given type is either of LLHD's ArrayType, StructType, or LLVM array or struct type. More...
 
static std::pair< Value, Value > shiftIntegerSigPointer (Location loc, LLVM::LLVMDialect *dialect, ConversionPatternRewriter &rewriter, Value pointer, Value index)
 Shift an integer signal pointer to obtain a view of the underlying value as if it was shifted. More...
 
static Value shiftStructuredSigPointer (Location loc, ConversionPatternRewriter &rewriter, Type elemTy, Value pointer, LLVM::GEPArg index)
 Shift the pointer of a structured-type (array or struct) signal, to change its view as if the desired slice/element was extracted. More...
 
static Value shiftArraySigPointer (Location loc, ConversionPatternRewriter &rewriter, Type arrTy, Value pointer, LLVM::GEPArg index)
 Shift the pointer of an array-typed signal, to change its view as if the desired slice/element was extracted. More...
 
static Type convertSigType (SigType type, LLVMTypeConverter &converter)
 
static Type convertTimeType (TimeType type, LLVMTypeConverter &converter)
 
static Type convertPtrType (PtrType type, LLVMTypeConverter &converter)
 

Typedef Documentation

◆ LoadOpConversion

using LoadOpConversion = OneToOneConvertToLLVMPattern<llhd::LoadOp, LLVM::LoadOp>

Definition at line 1806 of file LLHDToLLVM.cpp.

Function Documentation

◆ adjustBitWidth()

static Value adjustBitWidth ( Location  loc,
ConversionPatternRewriter &  rewriter,
Type  targetTy,
Value  value 
)
static

Adjust the bithwidth of value to be the same as targetTy's bitwidth.

Definition at line 439 of file LLHDToLLVM.cpp.

◆ convertPtrType()

static Type convertPtrType ( PtrType  type,
LLVMTypeConverter &  converter 
)
static

Definition at line 576 of file LLHDToLLVM.cpp.

References circt::calyx::direction::get().

◆ convertSigType()

static Type convertSigType ( SigType  type,
LLVMTypeConverter &  converter 
)
static

Definition at line 562 of file LLHDToLLVM.cpp.

References circt::calyx::direction::get().

◆ convertTimeType()

static Type convertTimeType ( TimeType  type,
LLVMTypeConverter &  converter 
)
static

Definition at line 571 of file LLHDToLLVM.cpp.

References circt::calyx::direction::get().

◆ createSubSig()

static Value createSubSig ( LLVM::LLVMDialect *  dialect,
ConversionPatternRewriter &  rewriter,
Location  loc,
std::vector< Value >  originDetail,
Value  newPtr,
Value  newOffset 
)
static

Create a subsignal struct.

Definition at line 124 of file LLHDToLLVM.cpp.

References circt::calyx::direction::get(), and getLLVMSigType().

◆ gepPersistenceState()

static Value gepPersistenceState ( LLVM::LLVMDialect *  dialect,
Location  loc,
ConversionPatternRewriter &  rewriter,
Type  stateTy,
int  index,
Value  state 
)
static

Insert a GEP operation to the pointer of the i-th value in the process persistence table.

Definition at line 233 of file LLHDToLLVM.cpp.

References circt::calyx::direction::get().

Referenced by persistValue().

◆ getGlobalString()

static Value getGlobalString ( Location  loc,
OpBuilder &  builder,
const TypeConverter *  typeConverter,
LLVM::GlobalOp &  str 
)
static

Get an existing global string.

Definition at line 44 of file LLHDToLLVM.cpp.

References builder, and circt::calyx::direction::get().

◆ getIndexOfOperandResult()

static unsigned getIndexOfOperandResult ( Operation *  op,
Value  result 
)
static

Definition at line 453 of file LLHDToLLVM.cpp.

Referenced by recursiveCloneInit().

◆ getLLVMSigType()

static Type getLLVMSigType ( LLVM::LLVMDialect *  dialect)
static

Return the LLVM type used to represent a signal.

It corresponds to a struct with the format: {valuePtr, bitOffset, instanceIndex, globalIndex}.

Definition at line 80 of file LLHDToLLVM.cpp.

References circt::calyx::direction::get().

Referenced by createSubSig(), getSignalDetail(), and persistValue().

◆ getOrInsertFunction()

static LLVM::LLVMFuncOp getOrInsertFunction ( ModuleOp &  module,
ConversionPatternRewriter &  rewriter,
Location  loc,
std::string  name,
Type  signature,
bool  insertBodyAndTerminator = false 
)
static

Looks up a symbol and inserts a new functino at the beginning of the module's region in case the function does not exists.

If insertBodyAndTerminator is set, also adds the entry block and return terminator.

Definition at line 62 of file LLHDToLLVM.cpp.

◆ getProcPersistenceTy()

static Type getProcPersistenceTy ( LLVM::LLVMDialect *  dialect,
const TypeConverter *  converter,
ProcOp &  proc 
)
static

Gather the types of values that are used outside of the block they're defined in.

An LLVMType structure containing those types, in order of appearance, is returned.

Definition at line 175 of file LLHDToLLVM.cpp.

References isWaitDestArg().

◆ getRegStateTy()

static LLVM::LLVMStructType getRegStateTy ( LLVM::LLVMDialect *  dialect,
Operation *  entity 
)
static

Return a struct type of arrays containing one entry for each RegOp condition that require more than one state of the trigger to infer it (i.e.

both, rise and fall).

Definition at line 409 of file LLHDToLLVM.cpp.

References circt::calyx::direction::get().

◆ getSignalDetail()

static std::vector<Value> getSignalDetail ( ConversionPatternRewriter &  rewriter,
LLVM::LLVMDialect *  dialect,
Location  loc,
Value  signal,
bool  extractIndices = false 
)
static

Extract the details from the given signal struct.

The details are returned in the original struct order.

Definition at line 89 of file LLHDToLLVM.cpp.

References circt::calyx::direction::get(), and getLLVMSigType().

◆ insertComparisonBlock()

static void insertComparisonBlock ( ConversionPatternRewriter &  rewriter,
LLVM::LLVMDialect *  dialect,
Location  loc,
Region *  body,
Value  resumeIdx,
int  currIdx,
Block *  trueDest,
ValueRange  trueDestArgs,
Block *  falseDest = nullptr 
)
static

Insert a comparison block that either jumps to the trueDest block, if the resume index mathces the current index, or to falseDest otherwise.

If no falseDest is provided, the next block is taken insead.

Definition at line 205 of file LLHDToLLVM.cpp.

References circt::calyx::direction::get().

Referenced by insertPersistence().

◆ insertPersistence()

static void insertPersistence ( const TypeConverter *  converter,
ConversionPatternRewriter &  rewriter,
LLVM::LLVMDialect *  dialect,
Location  loc,
ProcOp &  proc,
Type &  stateTy,
LLVM::LLVMFuncOp &  converted,
Operation *  splitEntryBefore 
)
static

Insert the blocks and operations needed to persist values across suspension, as well as ones needed to resume execution at the right spot.

Definition at line 320 of file LLHDToLLVM.cpp.

References circt::calyx::direction::get(), insertComparisonBlock(), isWaitDestArg(), and persistValue().

◆ isArrayOrStruct()

static bool isArrayOrStruct ( Type  type)
static

Check if the given type is either of LLHD's ArrayType, StructType, or LLVM array or struct type.

Definition at line 508 of file LLHDToLLVM.cpp.

◆ isWaitDestArg() [1/2]

static bool isWaitDestArg ( Operation *  op)
static

Definition at line 164 of file LLHDToLLVM.cpp.

References isWaitDestArg().

◆ isWaitDestArg() [2/2]

static bool isWaitDestArg ( WaitOp  op,
Value  val 
)
static

Returns true if the given value is passed as an argument to the destination block of the given WaitOp.

Definition at line 154 of file LLHDToLLVM.cpp.

Referenced by getProcPersistenceTy(), insertPersistence(), isWaitDestArg(), and persistValue().

◆ persistValue()

static void persistValue ( LLVM::LLVMDialect *  dialect,
Location  loc,
const TypeConverter *  converter,
ConversionPatternRewriter &  rewriter,
Type  stateTy,
int &  i,
Value  state,
Value  persist 
)
static

Persist a Value by storing it into the process persistence table, and substituting the uses that escape the block the operation is defined in with a load from the persistence table.

Definition at line 244 of file LLHDToLLVM.cpp.

References gepPersistenceState(), getLLVMSigType(), and isWaitDestArg().

Referenced by insertPersistence().

◆ recursiveCloneInit()

static Value recursiveCloneInit ( OpBuilder &  initBuilder,
IRMapping &  mapping,
Value  init 
)
static

Recursively clone the init origin of a sig operation into the init function, up to the initial constant value(s).

This is required to clone the initialization of array and struct signals, where the init operand cannot originate from a constant operation.

Definition at line 466 of file LLHDToLLVM.cpp.

References getIndexOfOperandResult().

◆ shiftArraySigPointer()

static Value shiftArraySigPointer ( Location  loc,
ConversionPatternRewriter &  rewriter,
Type  arrTy,
Value  pointer,
LLVM::GEPArg  index 
)
static

Shift the pointer of an array-typed signal, to change its view as if the desired slice/element was extracted.

Definition at line 549 of file LLHDToLLVM.cpp.

References shiftStructuredSigPointer(), and zextByOne().

◆ shiftIntegerSigPointer()

static std::pair<Value, Value> shiftIntegerSigPointer ( Location  loc,
LLVM::LLVMDialect *  dialect,
ConversionPatternRewriter &  rewriter,
Value  pointer,
Value  index 
)
static

Shift an integer signal pointer to obtain a view of the underlying value as if it was shifted.

Definition at line 516 of file LLHDToLLVM.cpp.

References circt::calyx::direction::get().

◆ shiftStructuredSigPointer()

static Value shiftStructuredSigPointer ( Location  loc,
ConversionPatternRewriter &  rewriter,
Type  elemTy,
Value  pointer,
LLVM::GEPArg  index 
)
static

Shift the pointer of a structured-type (array or struct) signal, to change its view as if the desired slice/element was extracted.

Definition at line 537 of file LLHDToLLVM.cpp.

References circt::calyx::direction::get().

Referenced by shiftArraySigPointer().

◆ zextByOne()

static Value zextByOne ( Location  loc,
ConversionPatternRewriter &  rewriter,
Value  value 
)
static

Create a zext operation by one bit on the given value.

This is useful when passing unsigned indexes to a GEP instruction, which treats indexes as signed values, to avoid unexpected "sign overflows".

Definition at line 430 of file LLHDToLLVM.cpp.

References circt::calyx::direction::get().

Referenced by shiftArraySigPointer().