Create an invariant loop using the CC dialect.
(self,
endVal,
bodyBuilder,
startVal=None,
stepVal=None,
isDecrementing=False)
| 556 | f"type {pyType} to internal IR value.") |
| 557 | |
| 558 | def createInvariantForLoop(self, |
| 559 | endVal, |
| 560 | bodyBuilder, |
| 561 | startVal=None, |
| 562 | stepVal=None, |
| 563 | isDecrementing=False): |
| 564 | """ |
| 565 | Create an invariant loop using the CC dialect. |
| 566 | """ |
| 567 | startVal = self.getConstantInt(0) if startVal == None else startVal |
| 568 | stepVal = self.getConstantInt(1) if stepVal == None else stepVal |
| 569 | |
| 570 | iTy = self.getIntegerType() |
| 571 | inputs = [startVal] |
| 572 | resultTys = [iTy] |
| 573 | |
| 574 | loop = cc.LoopOp(resultTys, inputs, BoolAttr.get(False)) |
| 575 | |
| 576 | whileBlock = Block.create_at_start(loop.whileRegion, [iTy]) |
| 577 | with InsertionPoint(whileBlock): |
| 578 | condPred = IntegerAttr.get( |
| 579 | iTy, 2) if not isDecrementing else IntegerAttr.get(iTy, 4) |
| 580 | cc.ConditionOp( |
| 581 | arith.CmpIOp(condPred, whileBlock.arguments[0], endVal).result, |
| 582 | whileBlock.arguments) |
| 583 | |
| 584 | bodyBlock = Block.create_at_start(loop.bodyRegion, [iTy]) |
| 585 | with InsertionPoint(bodyBlock): |
| 586 | bodyBuilder(bodyBlock.arguments[0]) |
| 587 | cc.ContinueOp(bodyBlock.arguments) |
| 588 | |
| 589 | stepBlock = Block.create_at_start(loop.stepRegion, [iTy]) |
| 590 | with InsertionPoint(stepBlock): |
| 591 | incr = arith.AddIOp(stepBlock.arguments[0], stepVal).result |
| 592 | cc.ContinueOp([incr]) |
| 593 | |
| 594 | loop.attributes.__setitem__('invariant', UnitAttr.get()) |
| 595 | return |
| 596 | |
| 597 | def __createQuakeValue(self, value): |
| 598 | return QuakeValue(value, self) |
no test coverage detected