Skip to content

Commit

Permalink
made code style changes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
jiahanxie353 committed Jul 31, 2024
1 parent 950d18f commit ad89e27
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 40 deletions.
4 changes: 2 additions & 2 deletions include/circt/Dialect/Calyx/CalyxLoweringUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void buildAssignmentsForRegisterWrite(OpBuilder &builder,
// A structure representing a set of ports which act as a memory interface for
// external memories.
struct MemoryPortsImpl {
StringRef memName;
std::string memName;
std::optional<Value> readData;
std::optional<Value> readOrContentEn;
std::optional<Value> writeData;
Expand All @@ -104,7 +104,7 @@ struct MemoryInterface {
explicit MemoryInterface(calyx::SeqMemoryOp memOp);

// Getter methods for each memory interface port.
StringRef memName();
std::string memName();
Value readData();
Value readEn();
Value contentEn();
Expand Down
68 changes: 33 additions & 35 deletions lib/Conversion/SCFToCalyx/SCFToCalyx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "mlir/Support/LogicalResult.h"
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/LogicalResult.h"

#include <variant>

Expand Down Expand Up @@ -1595,25 +1595,26 @@ class BuildControl : public calyx::FuncOpPartialLoweringPattern {
for (auto operandEnum : enumerate(callSchedPtr->callOp.getOperands())) {
auto operand = operandEnum.value();
auto index = operandEnum.index();
if (isa<MemRefType>(operand.getType())) {
auto memOpName = getState<ComponentLoweringState>()
.getMemoryInterface(operand)
.memName();
auto memOpNameAttr =
SymbolRefAttr::get(rewriter.getContext(), memOpName);
Value argI = calleeFunc.getArgument(index);
if (isa<MemRefType>(argI.getType())) {
NamedAttrList namedAttrList;
namedAttrList.append(
rewriter.getStringAttr(
instanceOpLoweringState->getMemoryInterface(argI)
.memName()),
memOpNameAttr);
refCells.push_back(
DictionaryAttr::get(rewriter.getContext(), namedAttrList));
}
} else {
if (!isa<MemRefType>(operand.getType())) {
inputPorts.push_back(operand);
continue;
}

auto memOpName = getState<ComponentLoweringState>()
.getMemoryInterface(operand)
.memName();
auto memOpNameAttr =
SymbolRefAttr::get(rewriter.getContext(), memOpName);
Value argI = calleeFunc.getArgument(index);
if (isa<MemRefType>(argI.getType())) {
NamedAttrList namedAttrList;
namedAttrList.append(
rewriter.getStringAttr(
instanceOpLoweringState->getMemoryInterface(argI)
.memName()),
memOpNameAttr);
refCells.push_back(
DictionaryAttr::get(rewriter.getContext(), namedAttrList));
}
}
llvm::copy(instanceOp.getResults().take_front(inputPorts.size()),
Expand Down Expand Up @@ -2024,8 +2025,7 @@ class SCFToCalyxPass : public circt::impl::SCFToCalyxBase<SCFToCalyxPass> {
SmallVector<Value, 4> extraMemRefOperands;
SmallVector<Operation *, 4> opsToModify;
for (auto &op : callee.getBody().getOps()) {
if (isa<memref::AllocaOp>(op) || isa<memref::AllocOp>(op) ||
isa<memref::GetGlobalOp>(op))
if (isa<memref::AllocaOp, memref::AllocOp, memref::GetGlobalOp>(op))
opsToModify.push_back(&op);
}

Expand Down Expand Up @@ -2102,14 +2102,12 @@ class SCFToCalyxPass : public circt::impl::SCFToCalyxBase<SCFToCalyxPass> {
/// We only create a new top-level function and call the original top-level
/// function from the new one if the original top-level has `memref` in its
/// argument
bool hasMemrefArgsInTopLevel = false;
for (auto funcOp : moduleOp.getOps<FuncOp>()) {
if (funcOp.getName() == topLevelFunction) {
if (hasMemrefArguments(funcOp)) {
hasMemrefArgsInTopLevel = true;
}
}
}
auto funcOps = moduleOp.getOps<FuncOp>();
bool hasMemrefArgsInTopLevel =
std::any_of(funcOps.begin(), funcOps.end(), [&](auto funcOp) {
return funcOp.getName() == topLevelFunction &&
hasMemrefArguments(funcOp);
});

std::string oldName = topLevelFunction;
if (hasMemrefArgsInTopLevel) {
Expand All @@ -2118,12 +2116,12 @@ class SCFToCalyxPass : public circt::impl::SCFToCalyxBase<SCFToCalyxPass> {
OpBuilder builder(moduleOp.getContext());
Operation *oldTopLevelFuncOp =
SymbolTable::lookupSymbolIn(moduleOp, oldName);
auto oldTopLevelFunc = dyn_cast_or_null<FuncOp>(oldTopLevelFuncOp);

if (!oldTopLevelFunc)
oldTopLevelFunc.emitOpError("Original top-level function not found!");

insertCallFromNewTopLevel(builder, newTopLevelFunc, oldTopLevelFunc);
if (auto oldTopLevelFunc = dyn_cast<FuncOp>(oldTopLevelFuncOp))
insertCallFromNewTopLevel(builder, newTopLevelFunc, oldTopLevelFunc);
else {
moduleOp.emitOpError("Original top-level function not found!");
return failure();
}
}

return success();
Expand Down
6 changes: 3 additions & 3 deletions lib/Dialect/Calyx/Transforms/CalyxLoweringUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,13 @@ Value MemoryInterface::done() {
return done.value();
}

StringRef MemoryInterface::memName() {
std::string MemoryInterface::memName() {
if (auto *memOp = std::get_if<calyx::MemoryOp>(&impl); memOp) {
return memOp->getName();
return memOp->getName().str();
}

if (auto *memOp = std::get_if<calyx::SeqMemoryOp>(&impl); memOp) {
return memOp->getName();
return memOp->getName().str();
}
return std::get<MemoryPortsImpl>(impl).memName;
}
Expand Down

0 comments on commit ad89e27

Please sign in to comment.