diff --git a/example/ExampleDialect.cpp b/example/ExampleDialect.cpp index cf84460..e807dea 100644 --- a/example/ExampleDialect.cpp +++ b/example/ExampleDialect.cpp @@ -28,7 +28,7 @@ #define GET_INCLUDES #include "ExampleDialect.cpp.inc" -namespace xd { +namespace xd::cpp { const char *toString(VectorKind kind) { switch (kind) { @@ -48,7 +48,7 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &out, VectorKind x) { return out; } -} // namespace xd +} // namespace xd::cpp #define GET_DIALECT_DEFS #include "ExampleDialect.cpp.inc" diff --git a/example/ExampleDialect.h b/example/ExampleDialect.h index 9ab0907..41d78f8 100644 --- a/example/ExampleDialect.h +++ b/example/ExampleDialect.h @@ -28,7 +28,7 @@ #define GET_INCLUDES #include "ExampleDialect.h.inc" -namespace xd { +namespace xd::cpp { enum class VectorKind { LittleEndian = 0, @@ -38,7 +38,7 @@ enum class VectorKind { const char *toString(VectorKind kind); -} // namespace xd +} // namespace xd::cpp #define GET_DIALECT_DECLS #include "ExampleDialect.h.inc" diff --git a/example/ExampleDialect.td b/example/ExampleDialect.td index 4455ac0..c3710fc 100644 --- a/example/ExampleDialect.td +++ b/example/ExampleDialect.td @@ -27,14 +27,14 @@ include "llvm-dialects/Dialect/Dialect.td" def ExampleDialect : Dialect { let name = "xd.ir"; - let cppNamespace = "xd"; + let cppNamespace = "xd::cpp"; } defm AttrVectorKind : AttrEnum<"VectorKind">; -def VectorKindLittleEndian : CppConstant<"xd::VectorKind::LittleEndian">; -def VectorKindBigEndian : CppConstant<"xd::VectorKind::BigEndian">; -def VectorKindMiddleEndian : CppConstant<"xd::VectorKind::MiddleEndian">; +def VectorKindLittleEndian : CppConstant<"xd::cpp::VectorKind::LittleEndian">; +def VectorKindBigEndian : CppConstant<"xd::cpp::VectorKind::BigEndian">; +def VectorKindMiddleEndian : CppConstant<"xd::cpp::VectorKind::MiddleEndian">; def ImmutableAttrI1 : IntegerAttr<"bool"> { let isImmutable = true; diff --git a/example/ExampleMain.cpp b/example/ExampleMain.cpp index f6c8858..d6371b9 100644 --- a/example/ExampleMain.cpp +++ b/example/ExampleMain.cpp @@ -69,12 +69,12 @@ void useUnnamedStructTypes(Builder &b) { StructType *t2 = StructType::create({b.getInt32Ty(), b.getInt32Ty()}, ""); StructType *t3 = StructType::create({b.getInt64Ty()}, ""); - Value *z1 = b.create(t1); - Value *z2 = b.create(t2); - Value *z3 = b.create(t3); - b.create(z1); - b.create(z2); - b.create(z3); + Value *z1 = b.create(t1); + Value *z2 = b.create(t2); + Value *z3 = b.create(t3); + b.create(z1); + b.create(z2); + b.create(z3); } void createFunctionExample(Module &module, const Twine &name) { @@ -86,47 +86,47 @@ void createFunctionExample(Module &module, const Twine &name) { BasicBlock *bb = BasicBlock::Create(module.getContext(), "entry", fn); b.SetInsertPoint(bb); - Value *x1 = b.create(b.getInt32Ty()); - Value *sizeOf = b.create(b.getHalfTy()); - Value *sizeOf32 = b.create(b.getInt32Ty(), sizeOf); - Value *x2 = b.create(x1, sizeOf32, 11); - Value *x3 = b.create(x2, x1); - Value *x4 = b.create(b.getInt64Ty(), x3); - b.create(x4); - - cast(sizeOf)->setSizeofType(b.getDoubleTy()); - cast(x2)->setExtra(7); - - Value *q1 = b.create(FixedVectorType::get(b.getInt32Ty(), 2)); - Value *q2 = b.create( - xd::XdVectorType::get(xd::VectorKind::BigEndian, b.getInt32Ty(), 2), q1); - - Value *y1 = b.create( - xd::XdVectorType::get(xd::VectorKind::BigEndian, b.getInt32Ty(), 4)); - Value *y2 = b.create(y1, x1); - Value *y3 = b.create(y1, b.getInt32(2)); + Value *x1 = b.create(b.getInt32Ty()); + Value *sizeOf = b.create(b.getHalfTy()); + Value *sizeOf32 = b.create(b.getInt32Ty(), sizeOf); + Value *x2 = b.create(x1, sizeOf32, 11); + Value *x3 = b.create(x2, x1); + Value *x4 = b.create(b.getInt64Ty(), x3); + b.create(x4); + + cast(sizeOf)->setSizeofType(b.getDoubleTy()); + cast(x2)->setExtra(7); + + Value *q1 = b.create(FixedVectorType::get(b.getInt32Ty(), 2)); + Value *q2 = b.create( + xd::cpp::XdVectorType::get(xd::cpp::VectorKind::BigEndian, b.getInt32Ty(), 2), q1); + + Value *y1 = b.create( + xd::cpp::XdVectorType::get(xd::cpp::VectorKind::BigEndian, b.getInt32Ty(), 4)); + Value *y2 = b.create(y1, x1); + Value *y3 = b.create(y1, b.getInt32(2)); Value *y4 = b.CreateAdd(y2, y3); - Value *y5 = b.create(q2, y4, x1); - auto *y6 = b.create(y5, y2, b.getInt32(5)); - b.create(y6); + Value *y5 = b.create(q2, y4, x1); + auto *y6 = b.create(y5, y2, b.getInt32(5)); + b.create(y6); y6->setIndex(b.getInt32(1)); - Value *p1 = b.create(b.getPtrTy(0)); + Value *p1 = b.create(b.getPtrTy(0)); p1->setName("p1"); - Value *p2 = b.create(p1, b.getInt64(14), b.getInt8(0)); + Value *p2 = b.create(p1, b.getInt64(14), b.getInt8(0)); p2->setName("p2"); - b.create(p2); + b.create(p2); - assert(xd::ExampleDialect::isDialectOp(*cast(p2))); + assert(xd::cpp::ExampleDialect::isDialectOp(*cast(p2))); SmallVector varArgs; varArgs.push_back(p1); varArgs.push_back(p2); - b.create(p2, varArgs); - b.create(); + b.create(p2, varArgs); + b.create(); - auto *replaceable = b.create(p2, varArgs); + auto *replaceable = b.create(p2, varArgs); SmallVector MD; MD.push_back(ConstantAsMetadata::get( ConstantInt::get(Type::getInt32Ty(bb->getContext()), 1))); @@ -136,25 +136,25 @@ void createFunctionExample(Module &module, const Twine &name) { varArgs2.push_back(p2); replaceable->replaceArgs(varArgs2); - b.create(FixedVectorType::get(b.getInt32Ty(), 2)); - b.create(y6); + b.create(FixedVectorType::get(b.getInt32Ty(), 2)); + b.create(y6); useUnnamedStructTypes(b); - b.create("name.of.llvm.value"); - b.create(b.getInt32(1)); - b.create(b.getInt32(1), "name.foo"); - b.create(b.getInt32(1), b.getInt32(2)); - b.create(b.getInt32(1), b.getInt32(2), "bar"); + b.create("name.of.llvm.value"); + b.create(b.getInt32(1)); + b.create(b.getInt32(1), "name.foo"); + b.create(b.getInt32(1), b.getInt32(2)); + b.create(b.getInt32(1), b.getInt32(2), "bar"); SmallVector moreVarArgs = varArgs; - b.create(moreVarArgs); - b.create(moreVarArgs, "two.varargs"); + b.create(moreVarArgs); + b.create(moreVarArgs, "two.varargs"); moreVarArgs.push_back(b.getInt32(3)); - b.create(moreVarArgs, "three.varargs"); + b.create(moreVarArgs, "three.varargs"); moreVarArgs.push_back(b.getInt32(4)); - b.create(moreVarArgs, "four.varargs"); + b.create(moreVarArgs, "four.varargs"); - b.create("Hello world!"); + b.create("Hello world!"); b.CreateRetVoid(); } @@ -210,20 +210,20 @@ template const Visitor &getExampleVisitor() { static const auto visitor = VisitorBuilder() .nest([](VisitorBuilder &b) { - b.add([](VisitorNest &self, xd::ReadOp &op) { + b.add([](VisitorNest &self, xd::cpp::ReadOp &op) { *self.out << "visiting ReadOp: " << op << '\n'; }); b.add(&VisitorNest::visitUnaryInstruction); - b.add([](VisitorNest &self, xd::SetReadOp &op) { + b.add([](VisitorNest &self, xd::cpp::SetReadOp &op) { *self.out << "visiting SetReadOp: " << op << '\n'; return op.getType()->isIntegerTy(1) ? VisitorResult::Stop : VisitorResult::Continue; }); - b.addSet( + b.addSet( [](VisitorNest &self, llvm::Instruction &op) { - if (isa(op)) { + if (isa(op)) { *self.out << "visiting SetReadOp (set): " << op << '\n'; - } else if (isa(op)) { + } else if (isa(op)) { *self.out << "visiting SetWriteOp (set): " << op << '\n'; } }); @@ -248,17 +248,17 @@ template const Visitor &getExampleVisitor() { }); b.add(&VisitorNest::visitBinaryOperator); b.nest([](VisitorBuilder &b) { - b.add([](raw_ostream &out, xd::WriteOp &op) { + b.add([](raw_ostream &out, xd::cpp::WriteOp &op) { out << "visiting WriteOp: " << op << '\n'; }); - b.add( - [](raw_ostream &out, xd::WriteVarArgOp &op) { + b.add( + [](raw_ostream &out, xd::cpp::WriteVarArgOp &op) { out << "visiting WriteVarArgOp: " << op << ":\n"; for (Value *arg : op.getArgs()) out << " " << *arg << '\n'; }); - b.add( - [](raw_ostream &out, xd::StringAttrOp &op) { + b.add( + [](raw_ostream &out, xd::cpp::StringAttrOp &op) { out << "visiting StringAttrOp: " << op.getVal() << '\n'; }); b.add([](raw_ostream &out, ReturnInst &ret) { @@ -270,8 +270,8 @@ template const Visitor &getExampleVisitor() { }); }); b.nest([](VisitorBuilder &b) { - b.add([](VisitorInnermost &inner, - xd::ITruncOp &op) { inner.counter++; }); + b.add([](VisitorInnermost &inner, + xd::cpp::ITruncOp &op) { inner.counter++; }); }); }) .setStrategy(rpot ? VisitorStrategy::ReversePostOrder @@ -295,7 +295,7 @@ int main(int argc, char **argv) { llvm::cl::ParseCommandLineOptions(argc, argv); LLVMContext context; - auto dialectContext = DialectContext::make(context); + auto dialectContext = DialectContext::make(context); if (g_action == Action::Build) { auto module = createModuleExample(context); diff --git a/test/example/generated/ExampleDialect.cpp.inc b/test/example/generated/ExampleDialect.cpp.inc index 938f489..db08dec 100644 --- a/test/example/generated/ExampleDialect.cpp.inc +++ b/test/example/generated/ExampleDialect.cpp.inc @@ -23,7 +23,7 @@ #ifdef GET_DIALECT_DEFS #undef GET_DIALECT_DEFS -namespace xd { +namespace xd::cpp { void ExampleDialect::anchor() {} @@ -759,7 +759,7 @@ source && !([&]() { - if (xd::VectorKind::LittleEndian != ::llvm::cast(resultType)->getKind()) { + if (xd::cpp::VectorKind::LittleEndian != ::llvm::cast(resultType)->getKind()) { return false; } return true; @@ -767,7 +767,7 @@ source && !([&]() { - if (xd::VectorKind::BigEndian != ::llvm::cast(resultType)->getKind()) { + if (xd::cpp::VectorKind::BigEndian != ::llvm::cast(resultType)->getKind()) { return false; } return true; @@ -780,10 +780,10 @@ source errs << " failed option 0 (VectorKindLittleEndian):\n"; ([&]() { - if (xd::VectorKind::LittleEndian != ::llvm::cast(resultType)->getKind()) { + if (xd::cpp::VectorKind::LittleEndian != ::llvm::cast(resultType)->getKind()) { errs << " inconsistent value of eq:$rhs found\n"; errs << " while checking VectorKindLittleEndian:\n"; - errs << " here: " << printable(xd::VectorKind::LittleEndian) << '\n'; + errs << " here: " << printable(xd::cpp::VectorKind::LittleEndian) << '\n'; errs << " previously: " << printable(::llvm::cast(resultType)->getKind()) << '\n'; return false; @@ -795,10 +795,10 @@ source errs << " failed option 1 (VectorKindBigEndian):\n"; ([&]() { - if (xd::VectorKind::BigEndian != ::llvm::cast(resultType)->getKind()) { + if (xd::cpp::VectorKind::BigEndian != ::llvm::cast(resultType)->getKind()) { errs << " inconsistent value of eq:$rhs found\n"; errs << " while checking VectorKindBigEndian:\n"; - errs << " here: " << printable(xd::VectorKind::BigEndian) << '\n'; + errs << " here: " << printable(xd::cpp::VectorKind::BigEndian) << '\n'; errs << " previously: " << printable(::llvm::cast(resultType)->getKind()) << '\n'; return false; @@ -2259,11 +2259,11 @@ data } -} // namespace xd +} // namespace xd::cpp template <> const ::llvm_dialects::OpDescription & - ::llvm_dialects::OpDescription::get() { + ::llvm_dialects::OpDescription::get() { static const ::llvm_dialects::OpDescription desc{false, "xd.ir.add32"}; return desc; } @@ -2271,7 +2271,7 @@ data template <> const ::llvm_dialects::OpDescription & - ::llvm_dialects::OpDescription::get() { + ::llvm_dialects::OpDescription::get() { static const ::llvm_dialects::OpDescription desc{true, "xd.ir.combine"}; return desc; } @@ -2279,7 +2279,7 @@ data template <> const ::llvm_dialects::OpDescription & - ::llvm_dialects::OpDescription::get() { + ::llvm_dialects::OpDescription::get() { static const ::llvm_dialects::OpDescription desc{true, "xd.ir.extractelement"}; return desc; } @@ -2287,7 +2287,7 @@ data template <> const ::llvm_dialects::OpDescription & - ::llvm_dialects::OpDescription::get() { + ::llvm_dialects::OpDescription::get() { static const ::llvm_dialects::OpDescription desc{true, "xd.ir.fromfixedvector"}; return desc; } @@ -2295,7 +2295,7 @@ data template <> const ::llvm_dialects::OpDescription & - ::llvm_dialects::OpDescription::get() { + ::llvm_dialects::OpDescription::get() { static const ::llvm_dialects::OpDescription desc{false, "xd.ir.handle.get"}; return desc; } @@ -2303,7 +2303,7 @@ data template <> const ::llvm_dialects::OpDescription & - ::llvm_dialects::OpDescription::get() { + ::llvm_dialects::OpDescription::get() { static const ::llvm_dialects::OpDescription desc{true, "xd.ir.iext"}; return desc; } @@ -2311,7 +2311,7 @@ data template <> const ::llvm_dialects::OpDescription & - ::llvm_dialects::OpDescription::get() { + ::llvm_dialects::OpDescription::get() { static const ::llvm_dialects::OpDescription desc{true, "xd.ir.itrunc"}; return desc; } @@ -2319,7 +2319,7 @@ data template <> const ::llvm_dialects::OpDescription & - ::llvm_dialects::OpDescription::get() { + ::llvm_dialects::OpDescription::get() { static const ::llvm_dialects::OpDescription desc{false, "xd.ir.immutable.op"}; return desc; } @@ -2327,7 +2327,7 @@ data template <> const ::llvm_dialects::OpDescription & - ::llvm_dialects::OpDescription::get() { + ::llvm_dialects::OpDescription::get() { static const ::llvm_dialects::OpDescription desc{true, "xd.ir.insertelement"}; return desc; } @@ -2335,7 +2335,7 @@ data template <> const ::llvm_dialects::OpDescription & - ::llvm_dialects::OpDescription::get() { + ::llvm_dialects::OpDescription::get() { static const ::llvm_dialects::OpDescription desc{false, "xd.ir.inst.name.conflict.double"}; return desc; } @@ -2343,7 +2343,7 @@ data template <> const ::llvm_dialects::OpDescription & - ::llvm_dialects::OpDescription::get() { + ::llvm_dialects::OpDescription::get() { static const ::llvm_dialects::OpDescription desc{false, "xd.ir.inst.name.conflict"}; return desc; } @@ -2351,7 +2351,7 @@ data template <> const ::llvm_dialects::OpDescription & - ::llvm_dialects::OpDescription::get() { + ::llvm_dialects::OpDescription::get() { static const ::llvm_dialects::OpDescription desc{false, "xd.ir.inst.name.conflict.varargs"}; return desc; } @@ -2359,7 +2359,7 @@ data template <> const ::llvm_dialects::OpDescription & - ::llvm_dialects::OpDescription::get() { + ::llvm_dialects::OpDescription::get() { static const ::llvm_dialects::OpDescription desc{true, "xd.ir.read"}; return desc; } @@ -2367,7 +2367,7 @@ data template <> const ::llvm_dialects::OpDescription & - ::llvm_dialects::OpDescription::get() { + ::llvm_dialects::OpDescription::get() { static const ::llvm_dialects::OpDescription desc{true, "xd.ir.set.read"}; return desc; } @@ -2375,7 +2375,7 @@ data template <> const ::llvm_dialects::OpDescription & - ::llvm_dialects::OpDescription::get() { + ::llvm_dialects::OpDescription::get() { static const ::llvm_dialects::OpDescription desc{false, "xd.ir.set.write"}; return desc; } @@ -2383,7 +2383,7 @@ data template <> const ::llvm_dialects::OpDescription & - ::llvm_dialects::OpDescription::get() { + ::llvm_dialects::OpDescription::get() { static const ::llvm_dialects::OpDescription desc{false, "xd.ir.sizeof"}; return desc; } @@ -2391,7 +2391,7 @@ data template <> const ::llvm_dialects::OpDescription & - ::llvm_dialects::OpDescription::get() { + ::llvm_dialects::OpDescription::get() { static const ::llvm_dialects::OpDescription desc{true, "xd.ir.stream.add"}; return desc; } @@ -2399,7 +2399,7 @@ data template <> const ::llvm_dialects::OpDescription & - ::llvm_dialects::OpDescription::get() { + ::llvm_dialects::OpDescription::get() { static const ::llvm_dialects::OpDescription desc{true, "xd.ir.stream.max"}; return desc; } @@ -2407,7 +2407,7 @@ data template <> const ::llvm_dialects::OpDescription & - ::llvm_dialects::OpDescription::get() { + ::llvm_dialects::OpDescription::get() { static const ::llvm_dialects::OpDescription desc{true, "xd.ir.stream.min"}; return desc; } @@ -2415,7 +2415,7 @@ data template <> const ::llvm_dialects::OpDescription & - ::llvm_dialects::OpDescription::get() { + ::llvm_dialects::OpDescription::get() { static const ::llvm_dialects::OpDescription desc{false, "xd.ir.string.attr.op"}; return desc; } @@ -2423,7 +2423,7 @@ data template <> const ::llvm_dialects::OpDescription & - ::llvm_dialects::OpDescription::get() { + ::llvm_dialects::OpDescription::get() { static const ::llvm_dialects::OpDescription desc{false, "xd.ir.write"}; return desc; } @@ -2431,7 +2431,7 @@ data template <> const ::llvm_dialects::OpDescription & - ::llvm_dialects::OpDescription::get() { + ::llvm_dialects::OpDescription::get() { static const ::llvm_dialects::OpDescription desc{false, "xd.ir.write.vararg"}; return desc; } diff --git a/test/example/generated/ExampleDialect.h.inc b/test/example/generated/ExampleDialect.h.inc index b296d9b..0e3e59b 100644 --- a/test/example/generated/ExampleDialect.h.inc +++ b/test/example/generated/ExampleDialect.h.inc @@ -21,7 +21,7 @@ class Builder; #ifdef GET_DIALECT_DECLS #undef GET_DIALECT_DECLS -namespace xd { +namespace xd::cpp { class ExampleDialect : public ::llvm_dialects::DialectImpl { @@ -611,6 +611,6 @@ bool verifier(::llvm::raw_ostream &errs); }; - } // namespace xd + } // namespace xd::cpp #endif // GET_DIALECT_DECLS