Skip to content

Commit

Permalink
Update getPhaseValue to return an mlir::Value. (#304)
Browse files Browse the repository at this point in the history
This PR changes the return value of the Pulse utility method
getPhaseValue() to return an mlir::Value instead of a double.
This is necessary when using parameters, as the phase offset can be
specified as a parameter value in addition to a compile time constant.
By returning the mlir::Value, the caller of phaseOffset has the
ability to differentiate between the two scenarios and act accordingly.
  • Loading branch information
kitbarton authored Mar 26, 2024
1 parent e0b4a85 commit c8e7248
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
5 changes: 2 additions & 3 deletions include/Dialect/Pulse/Utils/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ Waveform_CreateOp getWaveformOp(PlayOp pulsePlayOp,

Waveform_CreateOp getWaveformOp(PlayOp pulsePlayOp,
CallSequenceStack_t &callSequenceOpStack);

double getPhaseValue(ShiftPhaseOp shiftPhaseOp,
CallSequenceStack_t &callSequenceOpStack);
mlir::Value getPhaseValue(ShiftPhaseOp shiftPhaseOp,
CallSequenceStack_t &callSequenceOpStack);

/// this function goes over all the blocks of the input pulse sequence, and for
/// each block, it sorts the pulse ops within the block according to their
Expand Down
17 changes: 6 additions & 11 deletions lib/Dialect/Pulse/Utils/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,20 @@ Waveform_CreateOp getWaveformOp(PlayOp pulsePlayOp,
return waveformOp;
}

double getPhaseValue(ShiftPhaseOp shiftPhaseOp,
CallSequenceStack_t &callSequenceOpStack) {
mlir::Value getPhaseValue(ShiftPhaseOp shiftPhaseOp,
CallSequenceStack_t &callSequenceOpStack) {
auto phaseOffsetIndex = 0;
mlir::Value phaseOffset = shiftPhaseOp.getPhaseOffset();

for (auto it = callSequenceOpStack.rbegin(); it != callSequenceOpStack.rend();
++it) {
if (phaseOffset.isa<BlockArgument>()) {
phaseOffsetIndex = phaseOffset.dyn_cast<BlockArgument>().getArgNumber();
phaseOffset = it->getOperand(phaseOffsetIndex);
} else
if (auto blockArg = dyn_cast<BlockArgument>(phaseOffset))
phaseOffset = it->getOperand(blockArg.getArgNumber());
else
break;
}

auto phaseOffsetOp =
dyn_cast<mlir::arith::ConstantFloatOp>(phaseOffset.getDefiningOp());
if (!phaseOffsetOp)
phaseOffsetOp->emitError() << "Phase offset is not a ConstantFloatOp.";
return phaseOffsetOp.value().convertToDouble();
return phaseOffset;
}

void sortOpsByTimepoint(SequenceOp &sequenceOp) {
Expand Down

0 comments on commit c8e7248

Please sign in to comment.