Skip to content

Commit

Permalink
Merge remote branch into bd-performance-regression
Browse files Browse the repository at this point in the history
  • Loading branch information
bcdonovan committed Nov 1, 2023
2 parents 7bcd0da + a54ff88 commit 7dad980
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 26 deletions.
7 changes: 2 additions & 5 deletions include/Dialect/QCS/Utils/ParameterInitialValueAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,11 @@ using InitialValueType = llvm::StringMap<ParameterType>;

class ParameterInitialValueAnalysis {
private:
static InitialValueType initial_values_;
static bool invalid_;
InitialValueType initial_values_;
bool invalid_{true};

public:
ParameterInitialValueAnalysis(mlir::Operation *op);
ParameterInitialValueAnalysis(mlir::Operation *op,
qssc::hal::SystemConfiguration *config)
: ParameterInitialValueAnalysis(op) {}
InitialValueType &getNames() { return initial_values_; }
void invalidate() { invalid_ = true; }
bool isInvalidated(const AnalysisManager::PreservedAnalyses &pa) {
Expand Down
55 changes: 34 additions & 21 deletions lib/Dialect/QCS/Utils/ParameterInitialValueAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,44 @@ InitialValueType ParameterInitialValueAnalysis::initial_values_;
bool ParameterInitialValueAnalysis::invalid_ = true;

ParameterInitialValueAnalysis::ParameterInitialValueAnalysis(
mlir::Operation *op) {
mlir::Operation *moduleOp)
{

if (not invalid_)
return;

op->walk([&](DeclareParameterOp declareParameterOp) {
double initial_value = 0.0;
if (declareParameterOp.initial_value().hasValue()) {
auto angleAttr = declareParameterOp.initial_value()
.getValue()
.dyn_cast<mlir::quir::AngleAttr>();
auto floatAttr =
declareParameterOp.initial_value().getValue().dyn_cast<FloatAttr>();
if (!(angleAttr || floatAttr))
op->emitError(
"Parameters are currently limited to angles or float[64] only.");

if (angleAttr)
initial_value = angleAttr.getValue().convertToDouble();

if (floatAttr)
initial_value = floatAttr.getValue().convertToDouble();
}
initial_values_[declareParameterOp.sym_name()] = initial_value;
});
// process the module top level to cache declareParameterOp initial_values
// this does not use a walk method so that submodule (if present) are not
// processed in order to limit processing time

for (auto &region : moduleOp->getRegions())
for (auto &block : region.getBlocks())
for (auto &op : block.getOperations()) {
auto declareParameterOp = dyn_cast<DeclareParameterOp>(op);
if (!declareParameterOp)
continue;

// moduleOp->walk([&](DeclareParameterOp declareParameterOp) {
double initial_value = 0.0;
if (declareParameterOp.initial_value().hasValue()) {
auto angleAttr = declareParameterOp.initial_value()
.getValue()
.dyn_cast<mlir::quir::AngleAttr>();
auto floatAttr = declareParameterOp.initial_value()
.getValue()
.dyn_cast<FloatAttr>();
if (!(angleAttr || floatAttr))
declareParameterOp.emitError("Parameters are currently limited to "
"angles or float[64] only.");

if (angleAttr)
initial_value = angleAttr.getValue().convertToDouble();

if (floatAttr)
initial_value = floatAttr.getValue().convertToDouble();
}
initial_values_[declareParameterOp.sym_name()] = initial_value;
}
invalid_ = false;
}

Expand Down

0 comments on commit 7dad980

Please sign in to comment.