Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions lib/Conversion/SCFToCalyx/SCFToCalyx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,19 @@
#include "mlir/Pass/Pass.h"
#include "mlir/Support/LogicalResult.h"
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/BinaryFormat/MsgPackReader.h"
#include "llvm/Support/LogicalResult.h"
#include "llvm/Support/NativeFormatting.h"
#include "llvm/Support/raw_os_ostream.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <filesystem>
#include <fstream>

#include <locale>
#include <mlir/IR/BuiltinAttributes.h>
#include <numeric>
#include <variant>

Expand Down Expand Up @@ -1301,10 +1305,19 @@ static LogicalResult buildAllocOp(ComponentLoweringState &componentState,
rewriter, allocOp.getLoc(), componentState.getUniqueName("mem"),
memtype.getElementType().getIntOrFloatBitWidth(), sizes, addrSizes);

auto componentOp = componentState.getComponentOp();

// Externalize memories conditionally (only in the top-level component because
// Calyx compiler requires it as a well-formness check).
memoryOp->setAttr("external",
IntegerAttr::get(rewriter.getI1Type(), llvm::APInt(1, 1)));
if (componentOp->hasAttr("toplevel")) {
memoryOp->setAttr(
"external", IntegerAttr::get(rewriter.getI1Type(), llvm::APInt(1, 1)));

} else {
memoryOp->setAttr(
"external", IntegerAttr::get(rewriter.getI1Type(), llvm::APInt(1, 0)));
}

componentState.registerMemoryInterface(allocOp.getResult(),
calyx::MemoryInterface(memoryOp));

Expand Down
5 changes: 5 additions & 0 deletions lib/Dialect/Calyx/Export/CalyxEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,10 @@ struct Emitter {
if (!atFormat) {
buffer << quote() << identifier << quote() << equals() << value;
} else {
// don't emit external(0)
if (identifier == "external" && intAttr.getValue() == 0) {
return "";
}
buffer << addressSymbol() << identifier;
// The only time we may omit the value is when it is a Boolean attribute
// with value 1.
Expand Down Expand Up @@ -875,6 +879,7 @@ void Emitter::emitSeqMemory(SeqMemoryOp memory) {
"supported by the native Calyx compiler.");
return;
}

bool isRef = !memory->hasAttr("external");
indent();
if (isRef)
Expand Down