Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup calls to dyn_cast #980

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions include/aie/Dialect/AIE/IR/AIEOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -1509,11 +1509,11 @@ def AIE_ObjectFifoCreateOp: AIE_Op<"objectfifo", [HasParent<"DeviceOp">, Symbol]
let extraClassDeclaration = [{
int size(int index = 0) {
if (llvm::isa<mlir::ArrayAttr>(getElemNumber()))
return llvm::dyn_cast<mlir::IntegerAttr>(
llvm::dyn_cast<mlir::ArrayAttr>(getElemNumber())[index])
return llvm::cast<mlir::IntegerAttr>(
llvm::cast<mlir::ArrayAttr>(getElemNumber())[index])
.getInt();
else
return llvm::dyn_cast<mlir::IntegerAttr>(getElemNumber()).getInt();
return llvm::cast<mlir::IntegerAttr>(getElemNumber()).getInt();
}

TileOp getProducerTileOp();
Expand Down
24 changes: 12 additions & 12 deletions lib/Dialect/AIE/IR/AIEDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static TileElement getParentTileElement(Operation *op) {
return element;
parent = parent->getParentOp();
}
return llvm::dyn_cast<TileElement>(parent);
return llvm::cast<TileElement>(parent);
}

struct UsesAreAccessable {
Expand Down Expand Up @@ -656,10 +656,10 @@ std::vector<ObjectFifoCreateOp> ObjectFifoLinkOp::getInputObjectFifos() {
while ((parent = parent->getParentOp())) {
if (parent->hasTrait<OpTrait::SymbolTable>()) {
for (auto sym : getFifoIns()) {
auto name = dyn_cast<FlatSymbolRefAttr>(sym);
auto name = cast<FlatSymbolRefAttr>(sym);
if (auto *st = SymbolTable::lookupSymbolIn(parent, name);
isa_and_nonnull<ObjectFifoCreateOp>(st))
inputObjFifos.push_back(dyn_cast<ObjectFifoCreateOp>(st));
inputObjFifos.push_back(cast<ObjectFifoCreateOp>(st));
}
}
}
Expand All @@ -672,10 +672,10 @@ std::vector<ObjectFifoCreateOp> ObjectFifoLinkOp::getOutputObjectFifos() {
while ((parent = parent->getParentOp())) {
if (parent->hasTrait<OpTrait::SymbolTable>()) {
for (auto sym : getFifoOuts()) {
auto name = dyn_cast<FlatSymbolRefAttr>(sym);
auto name = cast<FlatSymbolRefAttr>(sym);
if (auto *st = SymbolTable::lookupSymbolIn(parent, name);
isa_and_nonnull<ObjectFifoCreateOp>(st))
outputObjFifos.push_back(dyn_cast<ObjectFifoCreateOp>(st));
outputObjFifos.push_back(cast<ObjectFifoCreateOp>(st));
}
}
}
Expand Down Expand Up @@ -703,7 +703,7 @@ ObjectFifoCreateOp ObjectFifoRegisterExternalBuffersOp::getObjectFifo() {
if (parent->hasTrait<OpTrait::SymbolTable>()) {
if (auto *st = SymbolTable::lookupSymbolIn(parent, getObjFifoName());
isa_and_nonnull<ObjectFifoCreateOp>(st))
return dyn_cast<ObjectFifoCreateOp>(st);
return cast<ObjectFifoCreateOp>(st);
}
}
return {};
Expand Down Expand Up @@ -759,7 +759,7 @@ ObjectFifoCreateOp ObjectFifoAcquireOp::getObjectFifo() {
if (parent->hasTrait<OpTrait::SymbolTable>()) {
if (auto *st = SymbolTable::lookupSymbolIn(parent, getObjFifoName());
isa_and_nonnull<ObjectFifoCreateOp>(st))
return dyn_cast<ObjectFifoCreateOp>(st);
return cast<ObjectFifoCreateOp>(st);
}
}
return {};
Expand Down Expand Up @@ -807,7 +807,7 @@ ObjectFifoCreateOp ObjectFifoReleaseOp::getObjectFifo() {
if (parent->hasTrait<OpTrait::SymbolTable>()) {
if (auto *st = SymbolTable::lookupSymbolIn(parent, getObjFifoName());
isa_and_nonnull<ObjectFifoCreateOp>(st))
return dyn_cast<ObjectFifoCreateOp>(st);
return cast<ObjectFifoCreateOp>(st);
}
}
return {};
Expand Down Expand Up @@ -858,7 +858,7 @@ ObjectFifoCreateOp ObjectFifoRegisterProcessOp::getObjectFifo() {
if (parent->hasTrait<OpTrait::SymbolTable>()) {
if (auto *st = SymbolTable::lookupSymbolIn(parent, getObjFifoName());
isa_and_nonnull<ObjectFifoCreateOp>(st))
return dyn_cast<ObjectFifoCreateOp>(st);
return cast<ObjectFifoCreateOp>(st);
}
}
return {};
Expand Down Expand Up @@ -1545,7 +1545,7 @@ LogicalResult SwitchboxOp::verify() {

int arbiter = -1;
for (auto val : connectOp.getAmsels()) {
auto amsel = dyn_cast<AMSelOp>(val.getDefiningOp());
auto amsel = cast<AMSelOp>(val.getDefiningOp());
if (arbiter != -1 && arbiter != amsel.arbiterIndex())
return connectOp.emitOpError(
"a master port can only be tied to one arbiter");
Expand All @@ -1564,7 +1564,7 @@ LogicalResult SwitchboxOp::verify() {
std::vector<PacketRulesOp> slvs;
for (auto *user : amselOp.getResult().getUsers()) {
if (auto s = dyn_cast<PacketRuleOp>(user)) {
auto pktRules = dyn_cast<PacketRulesOp>(s->getParentOp());
auto pktRules = cast<PacketRulesOp>(s->getParentOp());
slvs.push_back(pktRules);
} else if (auto m = dyn_cast<MasterSetOp>(user))
mstrs.push_back(m);
Expand Down Expand Up @@ -1680,7 +1680,7 @@ struct AcquireReleaseOneStateInDMABlock {
struct AccessesLocalLocks {
static LogicalResult verifyTrait(Operation *op) {
if (auto memOp = op->getParentOfType<MemOp>()) {
auto useLock = dyn_cast<UseLockOp>(op);
auto useLock = cast<UseLockOp>(op);
if (auto lock = useLock.getLockOp();
lock.getTileOp().colIndex() != memOp.colIndex() ||
lock.getTileOp().rowIndex() != memOp.rowIndex())
Expand Down
10 changes: 5 additions & 5 deletions lib/Dialect/AIE/Transforms/AIECreatePacketFlows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,12 @@ struct AIERoutePacketFlowsPass

for (Operation &Op : b.getOperations()) {
if (auto pktSource = dyn_cast<PacketSourceOp>(Op)) {
auto srcTile = dyn_cast<TileOp>(pktSource.getTile().getDefiningOp());
auto srcTile = cast<TileOp>(pktSource.getTile().getDefiningOp());
xSrc = srcTile.colIndex();
ySrc = srcTile.rowIndex();
sourcePort = pktSource.port();
} else if (auto pktDest = dyn_cast<PacketDestOp>(Op)) {
auto destTile = dyn_cast<TileOp>(pktDest.getTile().getDefiningOp());
auto destTile = cast<TileOp>(pktDest.getTile().getDefiningOp());
int xDest = destTile.colIndex();
int yDest = destTile.rowIndex();
Port destPort = pktDest.port();
Expand Down Expand Up @@ -487,7 +487,7 @@ struct AIERoutePacketFlowsPass
WireBundle bundle = physPort.second.bundle;
int channel = physPort.second.channel;
assert(tileOp);
auto tile = dyn_cast<TileOp>(tileOp);
auto tile = cast<TileOp>(tileOp);
LLVM_DEBUG(llvm::dbgs()
<< "master " << tile << " " << stringifyWireBundle(bundle)
<< " : " << channel << '\n');
Expand Down Expand Up @@ -571,7 +571,7 @@ struct AIERoutePacketFlowsPass
LLVM_DEBUG(llvm::dbgs() << "CHECK Slave Masks\n");
for (auto map : slaveMasks) {
auto port = map.first.first;
auto tile = dyn_cast<TileOp>(port.first);
auto tile = cast<TileOp>(port.first);
WireBundle bundle = port.second.bundle;
int channel = port.second.channel;
int ID = map.first.second;
Expand All @@ -595,7 +595,7 @@ struct AIERoutePacketFlowsPass
// Realize the routes in MLIR
for (auto map : tiles) {
Operation *tileOp = map.second;
auto tile = dyn_cast<TileOp>(tileOp);
auto tile = cast<TileOp>(tileOp);

// Create a switchbox for the routes and insert inside it.
builder.setInsertionPointAfter(tileOp);
Expand Down
2 changes: 1 addition & 1 deletion lib/Dialect/AIE/Transforms/AIELocalizeLocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct AIELocalizeLocksPass : AIELocalizeLocksBase<AIELocalizeLocksPass> {
// Collect the locks used in this core.
const auto &targetModel = getTargetModel(coreOp);

auto thisTile = dyn_cast<TileOp>(coreOp.getTile().getDefiningOp());
auto thisTile = cast<TileOp>(coreOp.getTile().getDefiningOp());
int col = thisTile.colIndex();
int row = thisTile.rowIndex();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ struct AIEObjectFifoRegisterProcessPass
builder.setInsertionPointToEnd(device.getBody());
ObjectFifoCreateOp objFifo = registerOp.getObjectFifo();
auto elementType =
llvm::dyn_cast<AIEObjectFifoType>(objFifo.getElemType())
llvm::cast<AIEObjectFifoType>(objFifo.getElemType())
.getElementType();
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved

if (consumersPerFifo.find(objFifo) == consumersPerFifo.end()) {
Expand Down
12 changes: 6 additions & 6 deletions lib/Dialect/AIE/Transforms/AIEObjectFifoStatefulTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ struct AIEObjectFifoStatefulTransformPass
creation_tile = op.getProducerTileOp();
else {
auto consumerTileOp =
dyn_cast<TileOp>(op.getConsumerTiles()[0].getDefiningOp());
cast<TileOp>(op.getConsumerTiles()[0].getDefiningOp());
creation_tile = consumerTileOp;
}

Expand Down Expand Up @@ -949,16 +949,16 @@ struct AIEObjectFifoStatefulTransformPass
.getDefiningOp<arith::ConstantOp>()
.getValue();
int64_t old_upper_value =
llvm::dyn_cast<IntegerAttr>(old_upper_bound).getInt();
llvm::cast<IntegerAttr>(old_upper_bound).getInt();
auto old_lower_bound = forLoop.getLowerBound()
.getDefiningOp<arith::ConstantOp>()
.getValue();
int64_t old_lower_value =
llvm::dyn_cast<IntegerAttr>(old_lower_bound).getInt();
llvm::cast<IntegerAttr>(old_lower_bound).getInt();
auto old_step =
forLoop.getStep().getDefiningOp<arith::ConstantOp>().getValue();
int64_t old_step_value =
llvm::dyn_cast<IntegerAttr>(old_step).getInt();
llvm::cast<IntegerAttr>(old_step).getInt();
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
int64_t num_iter =
(old_upper_value - old_lower_value) / old_step_value;

Expand Down Expand Up @@ -1200,7 +1200,7 @@ struct AIEObjectFifoStatefulTransformPass
continue;

for (auto consumerTile : createOp.getConsumerTiles()) {
auto consumerTileOp = dyn_cast<TileOp>(consumerTile.getDefiningOp());
auto consumerTileOp = cast<TileOp>(consumerTile.getDefiningOp());

if (isa<ArrayAttr>(createOp.getElemNumber())) {
// +1 to account for 1st depth (producer)
Expand Down Expand Up @@ -1273,7 +1273,7 @@ struct AIEObjectFifoStatefulTransformPass
// loop unrolling pass
objectFifoTiles.insert(createOp.getProducerTileOp());
for (auto consumerTile : createOp.getConsumerTiles()) {
auto consumerTileOp = dyn_cast<TileOp>(consumerTile.getDefiningOp());
auto consumerTileOp = cast<TileOp>(consumerTile.getDefiningOp());
objectFifoTiles.insert(consumerTileOp);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Dialect/AIEX/Transforms/AIECreateBroadcastPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct AIEBroadcastPacketPass
Block &b = r.front();
Port sourcePort = broadcastpacket.port();
TileOp srcTile =
dyn_cast<TileOp>(broadcastpacket.getTile().getDefiningOp());
cast<TileOp>(broadcastpacket.getTile().getDefiningOp());
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved

for (Operation &Op : b.getOperations()) {
if (BPIDOp bpid = dyn_cast<BPIDOp>(Op)) {
Expand All @@ -75,7 +75,7 @@ struct AIEBroadcastPacketPass
for (Operation &op : b_bpid.getOperations()) {
if (BPDestOp bpdest = dyn_cast<BPDestOp>(op)) {
TileOp destTile =
dyn_cast<TileOp>(bpdest.getTile().getDefiningOp());
cast<TileOp>(bpdest.getTile().getDefiningOp());
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
Port destPort = bpdest.port();
builder.setInsertionPointToEnd(b_pkFlow);
builder.create<PacketDestOp>(builder.getUnknownLoc(), destTile,
Expand Down
6 changes: 3 additions & 3 deletions lib/Dialect/AIEX/Transforms/AIECreateCores.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ struct AIECreateCoresPass : public AIECreateCoresBase<AIECreateCoresPass> {
tiles[{colIndex, rowIndex}] = tile;
}
Operation *tileOp = tiles[{colIndex, rowIndex}];
TileOp tile = dyn_cast<TileOp>(tileOp);
TileOp tile = cast<TileOp>(tileOp);
builder.setInsertionPointAfter(tileOp);

// create MemOp
Expand Down Expand Up @@ -216,8 +216,8 @@ struct AIECreateCoresPass : public AIECreateCoresBase<AIECreateCoresPass> {
// DenseMap<Value, int> destChannel;
// for (auto op : device.getOps<MemcpyOp>()) {
// builder.setInsertionPoint(op);
// TileOp srcTile = dyn_cast<TileOp>(op.srcTile().getDefiningOp());
// TileOp dstTile = dyn_cast<TileOp>(op.dstTile().getDefiningOp());
// TileOp srcTile = cast<TileOp>(op.srcTile().getDefiningOp());
// TileOp dstTile = cast<TileOp>(op.dstTile().getDefiningOp());
// // TODO: perhaps a better approach is to not assert here, but rather
// have a subsequent pass
// // that legally relocates the ports
Expand Down
2 changes: 1 addition & 1 deletion lib/Dialect/AIEX/Transforms/AIECreateLocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ struct AIECreateLocksPass : public AIECreateLocksBase<AIECreateLocksPass> {
assert(tileOp &&
"Sorry, the lock users of this chain do not have a common lock");

TileOp tile = dyn_cast<TileOp>(tileOp);
TileOp tile = cast<TileOp>(tileOp);
int lockID = getLockID(locks, tileOp);
assert(lockID >= 0 && "No more locks to allocate!");
LLVM_DEBUG(llvm::dbgs() << "Shared tile \n"; tileOp->print(llvm::dbgs()));
Expand Down
18 changes: 9 additions & 9 deletions lib/Dialect/AIEX/Transforms/AIEHerdRouting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,25 +217,25 @@ struct AIEHerdRoutingPass : AIEHerdRoutingBase<AIEHerdRoutingPass> {
routeOps.push_back(routeOp);

auto sourceHerds =
dyn_cast<SelectOp>(routeOp.getSourceHerds().getDefiningOp());
cast<SelectOp>(routeOp.getSourceHerds().getDefiningOp());
auto destHerds =
dyn_cast<SelectOp>(routeOp.getDestHerds().getDefiningOp());
cast<SelectOp>(routeOp.getDestHerds().getDefiningOp());
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
WireBundle sourceBundle = routeOp.getSourceBundle();
WireBundle destBundle = routeOp.getDestBundle();
int sourceChannel = routeOp.getSourceChannelValue();
int destChannel = routeOp.getDestChannelValue();

HerdOp sourceHerd =
dyn_cast<HerdOp>(sourceHerds.getStartHerd().getDefiningOp());
cast<HerdOp>(sourceHerds.getStartHerd().getDefiningOp());
IterOp sourceIterX =
dyn_cast<IterOp>(sourceHerds.getIterX().getDefiningOp());
cast<IterOp>(sourceHerds.getIterX().getDefiningOp());
IterOp sourceIterY =
dyn_cast<IterOp>(sourceHerds.getIterY().getDefiningOp());
cast<IterOp>(sourceHerds.getIterY().getDefiningOp());
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved

HerdOp destHerd =
dyn_cast<HerdOp>(destHerds.getStartHerd().getDefiningOp());
IterOp destIterX = dyn_cast<IterOp>(destHerds.getIterX().getDefiningOp());
IterOp destIterY = dyn_cast<IterOp>(destHerds.getIterY().getDefiningOp());
cast<HerdOp>(destHerds.getStartHerd().getDefiningOp());
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
IterOp destIterX = cast<IterOp>(destHerds.getIterX().getDefiningOp());
IterOp destIterY = cast<IterOp>(destHerds.getIterY().getDefiningOp());

int sourceStartX = sourceIterX.getStartValue();
int sourceEndX = sourceIterX.getEndValue();
Expand Down Expand Up @@ -293,7 +293,7 @@ struct AIEHerdRoutingPass : AIEHerdRoutingBase<AIEHerdRoutingPass> {
int x = swboxCfg.first.second.col;
int y = swboxCfg.first.second.row;
auto connects = swboxCfg.second;
HerdOp herd = dyn_cast<HerdOp>(herdOp);
HerdOp herd = cast<HerdOp>(herdOp);

builder.setInsertionPoint(device.getBody()->getTerminator());

Expand Down
8 changes: 4 additions & 4 deletions lib/Dialect/AIEX/Transforms/AIELowerMemcpy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ using namespace xilinx::AIE;
using namespace xilinx::AIEX;

static TileOp srcTileOp(xilinx::AIEX::MemcpyOp op) {
return llvm::dyn_cast<xilinx::AIE::TileOp>(op.getSrcTile().getDefiningOp());
return llvm::cast<xilinx::AIE::TileOp>(op.getSrcTile().getDefiningOp());
}
static TileOp dstTileOp(xilinx::AIEX::MemcpyOp op) {
return llvm::dyn_cast<xilinx::AIE::TileOp>(op.getDstTile().getDefiningOp());
return llvm::cast<xilinx::AIE::TileOp>(op.getDstTile().getDefiningOp());
}

struct LowerAIEMemcpy : public OpConversionPattern<MemcpyOp> {
Expand Down Expand Up @@ -113,8 +113,8 @@ struct AIELowerMemcpyPass : public AIELowerMemcpyBase<AIELowerMemcpyPass> {
DenseMap<Value, int> destChannel;
for (auto op : device.getOps<MemcpyOp>()) {
builder.setInsertionPoint(op);
TileOp srcTile = dyn_cast<TileOp>(op.getSrcTile().getDefiningOp());
TileOp dstTile = dyn_cast<TileOp>(op.getDstTile().getDefiningOp());
TileOp srcTile = cast<TileOp>(op.getSrcTile().getDefiningOp());
TileOp dstTile = cast<TileOp>(op.getDstTile().getDefiningOp());
// TODO: perhaps a better approach is to not assert here, but rather have
// a subsequent pass that legally relocates the ports
assert(destChannel[op.getDstTile()] <= 2 &&
Expand Down
4 changes: 2 additions & 2 deletions lib/Dialect/AIEX/Transforms/AIELowerMulticast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ struct AIELowerMulticastPass : public AIEMulticastBase<AIELowerMulticastPass> {
Region &r = multicast.getPorts();
Block &b = r.front();
Port sourcePort = multicast.port();
TileOp srcTile = dyn_cast<TileOp>(multicast.getTile().getDefiningOp());
TileOp srcTile = cast<TileOp>(multicast.getTile().getDefiningOp());
for (Operation &Op : b.getOperations()) {
if (MultiDestOp multiDest = dyn_cast<MultiDestOp>(Op)) {
TileOp destTile =
dyn_cast<TileOp>(multiDest.getTile().getDefiningOp());
cast<TileOp>(multiDest.getTile().getDefiningOp());
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
Port destPort = multiDest.port();
builder.create<FlowOp>(builder.getUnknownLoc(), srcTile,
sourcePort.bundle, sourcePort.channel,
Expand Down
Loading