Skip to content

Commit fbd775b

Browse files
authored
Reduce using namespace in global scope (Xilinx#1042)
* Reduce using namespace in global scope * Fixup extra qualification in declarations
1 parent b68be01 commit fbd775b

33 files changed

+370
-392
lines changed

mlir/lib/Conversion/AIRLoweringPass.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@
4545
#define DEBUG_TYPE "air-lowering-pass"
4646

4747
using namespace mlir;
48-
using namespace xilinx;
4948

50-
namespace {
49+
namespace xilinx {
50+
namespace air {
5151

5252
class AIRLaunchConversion : public ConversionPattern {
5353
public:
@@ -1390,7 +1390,8 @@ class AIRLoweringPass : public air::impl::AIRLoweringBase<AIRLoweringPass> {
13901390
}
13911391
};
13921392

1393-
} // namespace
1393+
} // namespace air
1394+
} // namespace xilinx
13941395

13951396
namespace xilinx {
13961397
namespace air {

mlir/lib/Conversion/AIRRtToLLVMPass.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
#define DEBUG_TYPE "airrt-to-llvm-pass"
3030

3131
using namespace mlir;
32-
using namespace xilinx;
3332

34-
namespace {
33+
namespace xilinx {
34+
3535
#define GEN_PASS_DEF_AIRRTTOLLVM
3636
#include "air/Conversion/Passes.h.inc"
3737

@@ -1316,7 +1316,7 @@ class AIRRtToLLVM : public impl::AIRRtToLLVMBase<AIRRtToLLVM> {
13161316
private:
13171317
};
13181318

1319-
} // namespace
1319+
} // namespace xilinx
13201320

13211321
namespace xilinx {
13221322
namespace airrt {

mlir/lib/Conversion/AIRRtToNpuPass.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
#define DEBUG_TYPE "airrt-to-npu-pass"
3535

3636
using namespace mlir;
37-
using namespace xilinx;
3837

39-
namespace {
38+
namespace xilinx {
39+
4040
#define GEN_PASS_DECL_AIRRTTONPU
4141
#define GEN_PASS_DEF_AIRRTTONPU
4242
#include "air/Conversion/Passes.h.inc"
@@ -1353,7 +1353,7 @@ struct AIRRtToNpuPass : public impl::AIRRtToNpuBase<AIRRtToNpuPass> {
13531353
}
13541354
};
13551355

1356-
} // namespace
1356+
} // namespace xilinx
13571357

13581358
namespace xilinx {
13591359
namespace airrt {

mlir/lib/Conversion/AIRToAIEPass.cpp

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@
4949
#define DEBUG_TYPE "air-to-aie"
5050

5151
using namespace mlir;
52-
using namespace xilinx;
5352

54-
namespace {
53+
// namespace {
54+
namespace xilinx {
55+
namespace air {
5556

5657
struct AIRToAIEConversionOptions {
5758
int64_t col_offset;
@@ -166,7 +167,7 @@ AIE::BufferOp allocateBufferOp(uint64_t &BufferId, MemRefType memrefTy,
166167
}
167168

168169
void outlineAIECores(OpBuilder &builder, AIE::DeviceOp aie_device,
169-
xilinx::air::HerdOp h,
170+
air::HerdOp h,
170171
std::map<AIE::TileOp, air::HerdOp> &tileToHerdMap,
171172
AIRToAIEConversionOptions &options) {
172173
builder.setInsertionPointToStart(aie_device.getBody());
@@ -184,8 +185,8 @@ void outlineAIECores(OpBuilder &builder, AIE::DeviceOp aie_device,
184185
// use the command line offsets unless the attribute is present
185186
int64_t col_offset = options.col_offset;
186187
int64_t row_offset = options.row_offset;
187-
auto col_name = xilinx::air::HerdOp::getColOffsetAttrName();
188-
auto row_name = xilinx::air::HerdOp::getRowOffsetAttrName();
188+
auto col_name = air::HerdOp::getColOffsetAttrName();
189+
auto row_name = air::HerdOp::getRowOffsetAttrName();
189190
auto ctx = h->getContext();
190191
if (auto co = h.getColOffset())
191192
col_offset = *co;
@@ -444,7 +445,7 @@ std::vector<AIE::TileOp> getMemtilesFromDeviceOp(AIE::DeviceOp d) {
444445
}
445446

446447
void outlineAIEMemtiles(OpBuilder &builder, AIE::DeviceOp aie_device,
447-
xilinx::air::SegmentOp seg,
448+
air::SegmentOp seg,
448449
AIRToAIEConversionOptions &options) {
449450
builder.setInsertionPointToStart(aie_device.getBody());
450451

@@ -490,15 +491,15 @@ void push_back_if_unique(std::vector<T> &vec, T entry) {
490491

491492
void createAIEModulesAndOutlineCores(
492493
ModuleOp module,
493-
std::vector<std::pair<AIE::DeviceOp, xilinx::air::HerdOp>> &aie_modules,
494+
std::vector<std::pair<AIE::DeviceOp, air::HerdOp>> &aie_modules,
494495
std::map<AIE::TileOp, air::HerdOp> &tileToHerdMap,
495496
AIRToAIEConversionOptions &options) {
496497

497498
SmallVector<air::SegmentOp> segments;
498499
SmallVector<air::HerdOp> herds;
499-
module.walk([&](xilinx::air::SegmentOp s) { segments.push_back(s); });
500-
module.walk([&](xilinx::air::HerdOp h) {
501-
if (h->getParentOfType<xilinx::air::SegmentOp>())
500+
module.walk([&](air::SegmentOp s) { segments.push_back(s); });
501+
module.walk([&](air::HerdOp h) {
502+
if (h->getParentOfType<air::SegmentOp>())
502503
return;
503504
herds.push_back(h);
504505
});
@@ -519,9 +520,7 @@ void createAIEModulesAndOutlineCores(
519520
StringAttr::get(builder.getContext(), segment_name));
520521
AIE::DeviceOp::ensureTerminator(aie_dev.getRegion(), builder,
521522
aie_dev.getLoc());
522-
seg.walk([&](xilinx::air::HerdOp h) {
523-
aie_modules.push_back({aie_dev, h});
524-
});
523+
seg.walk([&](air::HerdOp h) { aie_modules.push_back({aie_dev, h}); });
525524
// If the device has memtiles, then outline memtiles
526525
if (aie_dev.getTargetModel().getNumMemTileRows()) {
527526
outlineAIEMemtiles(builder, aie_dev, seg, options);
@@ -762,7 +761,7 @@ struct LowerScfTokenPattern : public OpRewritePattern<scf::ForOp> {
762761
Value v =
763762
fop.getOperand(block_arg.getArgNumber() - fop.getNumInductionVars() +
764763
fop.getNumControlOperands());
765-
if (llvm::isa<xilinx::air::AsyncTokenType>(v.getType())) {
764+
if (llvm::isa<air::AsyncTokenType>(v.getType())) {
766765
block_arg.replaceAllUsesWith(v);
767766
iter_args_idx.set(block_arg.getArgNumber());
768767
} else {
@@ -795,12 +794,11 @@ struct LowerScfTokenPattern : public OpRewritePattern<scf::ForOp> {
795794
// use the new for op's results
796795
int idx = 0;
797796
for (auto r : fop.getResults()) {
798-
if (llvm::isa<xilinx::air::AsyncTokenType>(r.getType()))
797+
if (llvm::isa<air::AsyncTokenType>(r.getType()))
799798
r.replaceAllUsesWith(
800799
rewriter
801-
.create<xilinx::air::WaitAllOp>(
802-
fop->getLoc(),
803-
xilinx::air::AsyncTokenType::get(fop->getContext()),
800+
.create<air::WaitAllOp>(
801+
fop->getLoc(), air::AsyncTokenType::get(fop->getContext()),
804802
SmallVector<Value, 1>{})
805803
.getResult(0));
806804
else
@@ -813,13 +811,13 @@ struct LowerScfTokenPattern : public OpRewritePattern<scf::ForOp> {
813811
SmallVector<Value, 4> yield_operands;
814812
SmallVector<Value, 4> token_operands;
815813
for (auto o : yield->getOperands()) {
816-
if (llvm::isa<xilinx::air::AsyncTokenType>(o.getType()))
814+
if (llvm::isa<air::AsyncTokenType>(o.getType()))
817815
token_operands.push_back(o);
818816
else
819817
yield_operands.push_back(o);
820818
}
821-
rewriter.create<xilinx::air::WaitAllOp>(
822-
fop->getLoc(), SmallVector<Type, 1>{}, token_operands);
819+
rewriter.create<air::WaitAllOp>(fop->getLoc(), SmallVector<Type, 1>{},
820+
token_operands);
823821
rewriter.create<scf::YieldOp>(yield->getLoc(), yield_operands);
824822
rewriter.eraseOp(yield);
825823

@@ -1669,12 +1667,11 @@ class AIRToAIEPass : public air::impl::AIRToAIEBase<AIRToAIEPass> {
16691667
public:
16701668
AIRToAIEPass() = default;
16711669
AIRToAIEPass(const AIRToAIEPass &pass) {}
1672-
AIRToAIEPass(const ::xilinx::air::AIRToAIEOptions &options)
1673-
: AIRToAIEBase(options) {}
1670+
AIRToAIEPass(const air::AIRToAIEOptions &options) : AIRToAIEBase(options) {}
16741671

16751672
void getDependentDialects(::mlir::DialectRegistry &registry) const override {
1676-
registry.insert<xilinx::air::airDialect>();
1677-
registry.insert<xilinx::airrt::AIRRtDialect>();
1673+
registry.insert<air::airDialect>();
1674+
registry.insert<airrt::AIRRtDialect>();
16781675
registry.insert<xilinx::AIE::AIEDialect>();
16791676
registry.insert<xilinx::AIEX::AIEXDialect>();
16801677
registry.insert<LLVM::LLVMDialect>();
@@ -1890,8 +1887,7 @@ class AIRToAIEPass : public air::impl::AIRToAIEBase<AIRToAIEPass> {
18901887

18911888
// Unroll scf.parallel
18921889
RewritePatternSet patterns(ctx);
1893-
xilinx::air::populateAIRunrollAIRChannelPutGetInScfParallelPatterns(
1894-
patterns);
1890+
air::populateAIRunrollAIRChannelPutGetInScfParallelPatterns(patterns);
18951891
(void)applyPatternsGreedily(aie_device, std::move(patterns));
18961892

18971893
// Substituting index operands, such as strides and offsets, to constant
@@ -3399,10 +3395,10 @@ class AIRToAIEPass : public air::impl::AIRToAIEBase<AIRToAIEPass> {
33993395
std::vector<Operation *> memcpy_ops;
34003396
getAIRMemcpyOpInRegion<T>(device.getRegion(), memcpy_ops);
34013397
for (auto o : memcpy_ops) {
3402-
auto a = dyn_cast<xilinx::air::AsyncOpInterface>(o);
3398+
auto a = dyn_cast<air::AsyncOpInterface>(o);
34033399
if (a && a.getAsyncToken()) {
34043400
OpBuilder b(o);
3405-
o->replaceAllUsesWith(b.create<xilinx::air::WaitAllOp>(
3401+
o->replaceAllUsesWith(b.create<air::WaitAllOp>(
34063402
o->getLoc(), air::AsyncTokenType::get(o->getContext()),
34073403
a.getAsyncDependencies()));
34083404
}
@@ -3586,7 +3582,7 @@ class AIRToAIEPass : public air::impl::AIRToAIEBase<AIRToAIEPass> {
35863582
std::set<AIE::DeviceOp> seen;
35873583
for (auto &p : aie_devices) {
35883584
auto device = std::get<0>(p);
3589-
xilinx::air::HerdOp h = std::get<1>(p);
3585+
air::HerdOp h = std::get<1>(p);
35903586
auto ctx = device->getContext();
35913587

35923588
if (seen.find(device) != seen.end())
@@ -3839,7 +3835,7 @@ class SplitAIEDevicesPass
38393835
removepatterns.add<OpRemovalPattern<airrt::ModuleMetadataOp>>(ctx);
38403836

38413837
ConversionTarget target(*ctx);
3842-
target.addIllegalDialect<xilinx::airrt::AIRRtDialect>();
3838+
target.addIllegalDialect<airrt::AIRRtDialect>();
38433839
if (failed(applyPartialConversion(aie_module, target,
38443840
std::move(removepatterns))))
38453841
signalPassFailure();
@@ -3958,7 +3954,8 @@ void AIRLinalgToFuncPass::runOnOperation() {
39583954
signalPassFailure();
39593955
}
39603956

3961-
} // namespace
3957+
} // namespace air
3958+
} // namespace xilinx
39623959

39633960
namespace xilinx {
39643961
namespace air {
@@ -3988,14 +3985,12 @@ FailureOr<ModuleOp> convertAIRToAIE(mlir::RewriterBase &rewriter,
39883985
/*.trace_size = */ 0,
39893986
/*.ctrl_packet = */ false,
39903987
/* .device = */ *device};
3991-
std::vector<std::pair<ModuleOp, xilinx::air::HerdOp>> aie_modules;
3992-
p.walk([&](xilinx::air::HerdOp h) {
3993-
aie_modules.push_back({aie_module, h});
3994-
});
3988+
std::vector<std::pair<ModuleOp, air::HerdOp>> aie_modules;
3989+
p.walk([&](air::HerdOp h) { aie_modules.push_back({aie_module, h}); });
39953990
std::map<AIE::TileOp, air::HerdOp> tileToHerdMap;
39963991
for (auto &p : aie_modules) {
39973992
ModuleOp aie_module = std::get<0>(p);
3998-
xilinx::air::HerdOp h = std::get<1>(p);
3993+
air::HerdOp h = std::get<1>(p);
39993994
rewriter.setInsertionPointToStart(aie_module.getBody());
40003995
auto devOp = rewriter.create<AIE::DeviceOp>(
40013996
aie_module.getLoc(),

0 commit comments

Comments
 (0)