@@ -294,22 +294,22 @@ class BuildOpGroups : public calyx::FuncOpPartialLoweringPattern {
294
294
funcOp.walk ([&](Operation *_op) {
295
295
opBuiltSuccessfully &=
296
296
TypeSwitch<mlir::Operation *, bool >(_op)
297
- .template Case <arith::ConstantOp, ReturnOp, BranchOpInterface,
298
- // / SCF
299
- scf::YieldOp, scf::WhileOp, scf::ForOp, scf::IfOp,
300
- scf::ParallelOp , scf::ReduceOp ,
301
- scf::ExecuteRegionOp,
302
- // / memref
303
- memref::AllocOp, memref::AllocaOp, memref::LoadOp,
304
- memref::StoreOp, memref::GetGlobalOp,
305
- // / standard arithmetic
306
- AddIOp, SubIOp, CmpIOp, ShLIOp, ShRUIOp, ShRSIOp,
307
- AndIOp, XOrIOp, OrIOp, ExtUIOp, ExtSIOp, TruncIOp,
308
- MulIOp, DivUIOp, DivSIOp, RemUIOp, RemSIOp,
309
- // / floating point
310
- AddFOp, SubFOp, MulFOp, CmpFOp, FPToSIOp, SIToFPOp,
311
- // / others
312
- SelectOp, IndexCastOp, BitcastOp, CallOp>(
297
+ .template Case <
298
+ arith::ConstantOp, ReturnOp, BranchOpInterface,
299
+ // / SCF
300
+ scf::YieldOp, scf::WhileOp, scf::ForOp , scf::IfOp ,
301
+ scf::ParallelOp, scf::ReduceOp, scf::ExecuteRegionOp,
302
+ // / memref
303
+ memref::AllocOp, memref::AllocaOp, memref::LoadOp,
304
+ memref::StoreOp, memref::GetGlobalOp,
305
+ // / standard arithmetic
306
+ AddIOp, SubIOp, CmpIOp, ShLIOp, ShRUIOp, ShRSIOp, AndIOp ,
307
+ XOrIOp, OrIOp, ExtUIOp, ExtSIOp, TruncIOp, MulIOp, DivUIOp ,
308
+ DivSIOp, RemUIOp, RemSIOp,
309
+ // / floating point
310
+ AddFOp, SubFOp, MulFOp, CmpFOp, FPToSIOp, SIToFPOp, DivFOp ,
311
+ // / others
312
+ SelectOp, IndexCastOp, BitcastOp, CallOp>(
313
313
[&](auto op) { return buildOp (rewriter, op).succeeded (); })
314
314
.template Case <FuncOp, scf::ConditionOp>([&](auto ) {
315
315
// / Skip: these special cases will be handled separately.
@@ -370,6 +370,7 @@ class BuildOpGroups : public calyx::FuncOpPartialLoweringPattern {
370
370
LogicalResult buildOp (PatternRewriter &rewriter, CmpFOp op) const ;
371
371
LogicalResult buildOp (PatternRewriter &rewriter, FPToSIOp op) const ;
372
372
LogicalResult buildOp (PatternRewriter &rewriter, SIToFPOp op) const ;
373
+ LogicalResult buildOp (PatternRewriter &rewriter, DivFOp op) const ;
373
374
LogicalResult buildOp (PatternRewriter &rewriter, ShRUIOp op) const ;
374
375
LogicalResult buildOp (PatternRewriter &rewriter, ShRSIOp op) const ;
375
376
LogicalResult buildOp (PatternRewriter &rewriter, ShLIOp op) const ;
@@ -514,6 +515,12 @@ class BuildOpGroups : public calyx::FuncOpPartialLoweringPattern {
514
515
/* subtract=*/ 1 );
515
516
}
516
517
rewriter.create <calyx::AssignOp>(loc, opFOp.getSubOp (), subOp);
518
+ } else if (auto opFOp =
519
+ dyn_cast<calyx::DivSqrtOpIEEE754>(opPipe.getOperation ())) {
520
+ bool isSqrt = !isa<arith::DivFOp>(op);
521
+ hw::ConstantOp sqrtOp =
522
+ createConstant (loc, rewriter, getComponent (), /* width=*/ 1 , isSqrt);
523
+ rewriter.create <calyx::AssignOp>(loc, opFOp.getSqrtOp (), sqrtOp);
517
524
}
518
525
519
526
// Register the values for the pipeline.
@@ -1056,6 +1063,24 @@ LogicalResult BuildOpGroups::buildOp(PatternRewriter &rewriter,
1056
1063
sitofp.getOut ().getType ().getIntOrFloatBitWidth (), " signedIn" );
1057
1064
}
1058
1065
1066
+ LogicalResult BuildOpGroups::buildOp (PatternRewriter &rewriter,
1067
+ DivFOp divf) const {
1068
+ Location loc = divf.getLoc ();
1069
+ IntegerType one = rewriter.getI1Type (), three = rewriter.getIntegerType (3 ),
1070
+ five = rewriter.getIntegerType (5 ),
1071
+ width = rewriter.getIntegerType (
1072
+ divf.getType ().getIntOrFloatBitWidth ());
1073
+ auto divFOp = getState<ComponentLoweringState>()
1074
+ .getNewLibraryOpInstance <calyx::DivSqrtOpIEEE754>(
1075
+ rewriter, loc,
1076
+ {/* clk=*/ one, /* reset=*/ one, /* go=*/ one,
1077
+ /* control=*/ one, /* sqrtOp=*/ one, /* left=*/ width,
1078
+ /* right=*/ width, /* roundingMode=*/ three, /* out=*/ width,
1079
+ /* exceptionalFlags=*/ five, /* done=*/ one});
1080
+ return buildLibraryBinaryPipeOp<calyx::DivSqrtOpIEEE754>(
1081
+ rewriter, divf, divFOp, divFOp.getOut ());
1082
+ }
1083
+
1059
1084
template <typename TAllocOp>
1060
1085
static LogicalResult buildAllocOp (ComponentLoweringState &componentState,
1061
1086
PatternRewriter &rewriter, TAllocOp allocOp) {
@@ -2482,7 +2507,7 @@ class SCFToCalyxPass : public circt::impl::SCFToCalyxBase<SCFToCalyxPass> {
2482
2507
CondBranchOp, BranchOp, MulIOp, DivUIOp, DivSIOp, RemUIOp,
2483
2508
RemSIOp, ReturnOp, arith::ConstantOp, IndexCastOp,
2484
2509
BitcastOp, FuncOp, ExtSIOp, CallOp, AddFOp, SubFOp,
2485
- MulFOp, CmpFOp, FPToSIOp, SIToFPOp>();
2510
+ MulFOp, CmpFOp, FPToSIOp, SIToFPOp, DivFOp >();
2486
2511
2487
2512
RewritePatternSet legalizePatterns (&getContext ());
2488
2513
legalizePatterns.add <DummyPattern>(&getContext ());
0 commit comments