CIRCT 23.0.0git
Loading...
Searching...
No Matches
Namespaces | Macros | Functions
LowerCoroutines.cpp File Reference
#include "circt/Dialect/Arc/ArcOps.h"
#include "circt/Dialect/Arc/ArcPasses.h"
#include "circt/Dialect/Comb/CombOps.h"
#include "circt/Dialect/HW/HWOps.h"
#include "mlir/Analysis/Liveness.h"
#include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/UB/IR/UBOps.h"
#include "mlir/IR/AttrTypeSubElements.h"
#include "mlir/IR/Dominance.h"
#include "mlir/Pass/Pass.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/GenericIteratedDominanceFrontier.h"
#include "circt/Dialect/Arc/ArcPasses.h.inc"
Include dependency graph for LowerCoroutines.cpp:

Go to the source code of this file.

Namespaces

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

Macros

#define GEN_PASS_DEF_LOWERCOROUTINESPASS
 

Functions

static SmallVector< Block * > collectResumeBlocks (Region &region)
 Collect the resume blocks of a coroutine body, i.e.
 
static LogicalResult captureValue (Value value, Region &region, ArrayRef< Block * > captureBlocks, Liveness &liveness, DominanceInfo &dominance)
 Capture a single value as a trailing block argument of each of the given resume blocks and rewrite all affected uses of the value.
 
static void rematerializeConstant (Value value, Region &region, ArrayRef< Block * > captureBlocks, Liveness &liveness)
 Clone a constant into the using blocks that are reachable from a capturing resume block, where the original definition no longer dominates its uses after the lowering.
 
static LogicalResult captureValuesAcrossSuspension (CoroutineDefineOp defineOp)
 Rewrite the body of a coroutine such that every resume block captures the values that are live across the suspension points it resumes from as trailing block arguments.
 
static CoroutineLowering analyzeDefinition (CoroutineDefineOp defineOp)
 Determine the resume blocks of a coroutine and derive its concrete PC and state types.
 
static void lowerDefinition (CoroutineLowering &lowering)
 Replace a coroutine definition with a state machine function.
 

Macro Definition Documentation

◆ GEN_PASS_DEF_LOWERCOROUTINESPASS

#define GEN_PASS_DEF_LOWERCOROUTINESPASS

Definition at line 72 of file LowerCoroutines.cpp.

Function Documentation

◆ analyzeDefinition()

static CoroutineLowering analyzeDefinition ( CoroutineDefineOp  defineOp)
static

Determine the resume blocks of a coroutine and derive its concrete PC and state types.

To be called after the values live across suspension points have been captured, such that the trailing block arguments of each resume block are exactly the values that have to be persisted.

Definition at line 330 of file LowerCoroutines.cpp.

References collectResumeBlocks(), and context.

◆ captureValue()

static LogicalResult captureValue ( Value  value,
Region &  region,
ArrayRef< Block * >  captureBlocks,
Liveness &  liveness,
DominanceInfo &  dominance 
)
static

Capture a single value as a trailing block argument of each of the given resume blocks and rewrite all affected uses of the value.

Definition at line 118 of file LowerCoroutines.cpp.

References append().

Referenced by captureValuesAcrossSuspension().

◆ captureValuesAcrossSuspension()

static LogicalResult captureValuesAcrossSuspension ( CoroutineDefineOp  defineOp)
static

Rewrite the body of a coroutine such that every resume block captures the values that are live across the suspension points it resumes from as trailing block arguments.

Definition at line 235 of file LowerCoroutines.cpp.

References captureValue(), collectResumeBlocks(), and rematerializeConstant().

◆ collectResumeBlocks()

static SmallVector< Block * > collectResumeBlocks ( Region &  region)
static

Collect the resume blocks of a coroutine body, i.e.

the blocks targeted by yield ops, in region order to make the lowering deterministic.

Definition at line 104 of file LowerCoroutines.cpp.

Referenced by analyzeDefinition(), and captureValuesAcrossSuspension().

◆ lowerDefinition()

static void lowerDefinition ( CoroutineLowering &  lowering)
static

Replace a coroutine definition with a state machine function.

The function takes the persistent state and PC as leading arguments and dispatches on the PC to either the original entry block or, through a trampoline block that unpacks the corresponding state variant, to one of the resume blocks. The coroutine terminators become function returns that produce the new state, resume PC, and yielded values.

Definition at line 380 of file LowerCoroutines.cpp.

References context, hw.ConstantOp::create(), and hw.StructCreateOp::create().

◆ rematerializeConstant()

static void rematerializeConstant ( Value  value,
Region &  region,
ArrayRef< Block * >  captureBlocks,
Liveness &  liveness 
)
static

Clone a constant into the using blocks that are reachable from a capturing resume block, where the original definition no longer dominates its uses after the lowering.

All other uses keep using the original.

Definition at line 201 of file LowerCoroutines.cpp.

Referenced by captureValuesAcrossSuspension().