diff --git a/include/llvm-dialects/Dialect/Dialect.td b/include/llvm-dialects/Dialect/Dialect.td index fd4aa27..46de788 100644 --- a/include/llvm-dialects/Dialect/Dialect.td +++ b/include/llvm-dialects/Dialect/Dialect.td @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License. + * limitations under the License. */ def args; @@ -69,7 +69,7 @@ class Attr : MetaType { // A check statement that is issued before using the C++ value in builders. // $0 is the C++ value. string check = ""; - + // Overriding prevents generating a setter method. Attributes are mutable by default. bit isImmutable = false; } @@ -280,11 +280,11 @@ def : AttrLlvmType; def : AttrLlvmType; def ImmutableStringAttr : Attr<"::llvm::StringRef"> { - let toLlvmValue = [{ $_builder.CreateGlobalString($0) }]; + let toLlvmValue = [{ $_builder.CreateGlobalString($0, "str", 4) }]; let fromLlvmValue = [{ ::llvm::cast<::llvm::ConstantDataArray>(::llvm::cast<::llvm::GlobalVariable>($0)->getInitializer())->getAsString() }]; let isImmutable = true; } - + // Global string variables are essentially pointers in addrspace(0). def : AttrLlvmType; diff --git a/test/example/generated/ExampleDialect.cpp.inc b/test/example/generated/ExampleDialect.cpp.inc index 49680c7..afa16ec 100644 --- a/test/example/generated/ExampleDialect.cpp.inc +++ b/test/example/generated/ExampleDialect.cpp.inc @@ -31,10 +31,10 @@ namespace xd { } bool ExampleDialect::isDialectOp(::llvm::CallInst& op) { - ::llvm::Function *calledFunc = op.getCalledFunction(); + ::llvm::Function *calledFunc = op.getCalledFunction(); if (!calledFunc) return false; - + return isDialectOp(calledFunc->getName()); } @@ -47,126 +47,126 @@ namespace xd { } ::llvm_dialects::Dialect* ExampleDialect::make(::llvm::LLVMContext& context) { - + auto verifierBuild = [](::llvm_dialects::VisitorBuilder<::llvm_dialects::VerifierState> &builder) { - + builder.add([](::llvm_dialects::VerifierState &state, Add32Op &op) { if (!op.verifier(state.out())) state.setError(); }); - + builder.add([](::llvm_dialects::VerifierState &state, CombineOp &op) { if (!op.verifier(state.out())) state.setError(); }); - + builder.add([](::llvm_dialects::VerifierState &state, ExtractElementOp &op) { if (!op.verifier(state.out())) state.setError(); }); - + builder.add([](::llvm_dialects::VerifierState &state, FromFixedVectorOp &op) { if (!op.verifier(state.out())) state.setError(); }); - + builder.add([](::llvm_dialects::VerifierState &state, HandleGetOp &op) { if (!op.verifier(state.out())) state.setError(); }); - + builder.add([](::llvm_dialects::VerifierState &state, IExtOp &op) { if (!op.verifier(state.out())) state.setError(); }); - + builder.add([](::llvm_dialects::VerifierState &state, ITruncOp &op) { if (!op.verifier(state.out())) state.setError(); }); - + builder.add([](::llvm_dialects::VerifierState &state, ImmutableOp &op) { if (!op.verifier(state.out())) state.setError(); }); - + builder.add([](::llvm_dialects::VerifierState &state, InsertElementOp &op) { if (!op.verifier(state.out())) state.setError(); }); - + builder.add([](::llvm_dialects::VerifierState &state, InstNameConflictDoubleOp &op) { if (!op.verifier(state.out())) state.setError(); }); - + builder.add([](::llvm_dialects::VerifierState &state, InstNameConflictOp &op) { if (!op.verifier(state.out())) state.setError(); }); - + builder.add([](::llvm_dialects::VerifierState &state, InstNameConflictVarargsOp &op) { if (!op.verifier(state.out())) state.setError(); }); - + builder.add([](::llvm_dialects::VerifierState &state, ReadOp &op) { if (!op.verifier(state.out())) state.setError(); }); - + builder.add([](::llvm_dialects::VerifierState &state, SetReadOp &op) { if (!op.verifier(state.out())) state.setError(); }); - + builder.add([](::llvm_dialects::VerifierState &state, SetWriteOp &op) { if (!op.verifier(state.out())) state.setError(); }); - + builder.add([](::llvm_dialects::VerifierState &state, SizeOfOp &op) { if (!op.verifier(state.out())) state.setError(); }); - + builder.add([](::llvm_dialects::VerifierState &state, StreamAddOp &op) { if (!op.verifier(state.out())) state.setError(); }); - + builder.add([](::llvm_dialects::VerifierState &state, StreamMaxOp &op) { if (!op.verifier(state.out())) state.setError(); }); - + builder.add([](::llvm_dialects::VerifierState &state, StreamMinOp &op) { if (!op.verifier(state.out())) state.setError(); }); - + builder.add([](::llvm_dialects::VerifierState &state, StringAttrOp &op) { if (!op.verifier(state.out())) state.setError(); }); - + builder.add([](::llvm_dialects::VerifierState &state, WriteOp &op) { if (!op.verifier(state.out())) state.setError(); }); - + builder.add([](::llvm_dialects::VerifierState &state, WriteVarArgOp &op) { if (!op.verifier(state.out())) state.setError(); }); - + }; static const ::llvm_dialects::VerifierExtension verifierExtension = { verifierBuild, }; static ::llvm_dialects::DialectExtensionRegistration<::llvm_dialects::VerifierExtension, ExampleDialect> verifierExtensionRegistration(::llvm_dialects::getVerifierExtensionPoint(), &verifierExtension); - + return new ExampleDialect(context); } @@ -210,7 +210,7 @@ XdHandleType* XdHandleType::get(::llvm::LLVMContext & ctx) { }; ::std::array ints = { - + }; auto *type = ::llvm::cast(::llvm::TargetExtType::get(ctx, s_name, types, ints)); @@ -219,7 +219,7 @@ XdHandleType* XdHandleType::get(::llvm::LLVMContext & ctx) { }, type)); return type; } - + bool XdHandleType::verifier(::llvm::raw_ostream &errs) const { ::llvm::LLVMContext &ctx = getContext(); (void)ctx; @@ -247,12 +247,12 @@ XdHandleType* XdHandleType::get(::llvm::LLVMContext & ctx) { return static_cast(int_params()[0]); } - + ::llvm::Type * XdVectorType::getElementType() const { return type_params()[0]; } - + uint32_t XdVectorType::getNumElements() const { return int_params()[1]; } @@ -277,7 +277,7 @@ numElements, }, type)); return type; } - + bool XdVectorType::verifier(::llvm::raw_ostream &errs) const { ::llvm::LLVMContext &ctx = getContext(); (void)ctx; @@ -308,17 +308,17 @@ return true; bool StreamReduceOp::classof(const ::llvm::CallInst* i) { - + if (StreamAddOp::classof(i)) return true; - + if (StreamMaxOp::classof(i)) return true; - + if (StreamMinOp::classof(i)) return true; - + return false; } - + ::llvm::Value * StreamReduceOp::getPtr() { return getArgOperand(0); } @@ -347,8 +347,8 @@ return true; ::llvm::LLVMContext& context = b.getContext(); (void)context; ::llvm::Module& module = *b.GetInsertBlock()->getModule(); - - + + const ::llvm::AttributeList attrs = ExampleDialect::get(context).getAttributeList(0); auto fnType = ::llvm::FunctionType::get(::llvm::IntegerType::get(context, 32), { @@ -373,13 +373,13 @@ rhs->getType(), assert(fn.getFunctionType() == fnType); assert(::llvm::cast<::llvm::Function>(fn.getCallee())->getFunctionType() == fn.getFunctionType()); - + ::llvm::SmallVector<::llvm::Value*, 3> args = { lhs, rhs, - ::llvm::ConstantInt::get(::llvm::IntegerType::get(context, 32), extra) + ::llvm::ConstantInt::get(::llvm::IntegerType::get(context, 32), extra) }; - + return ::llvm::cast(b.CreateCall(fn, args, instName)); } @@ -389,13 +389,13 @@ rhs, (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 3) { errs << " wrong number of arguments: " << arg_size() << ", expected 3\n"; return false; } - + if (getArgOperand(2)->getType() != ::llvm::IntegerType::get(context, 32)) { errs << " argument 2 (extra) has type: " << *getArgOperand(2)->getType() << '\n'; @@ -415,23 +415,23 @@ uint32_t const extra = getExtra(); errs << " unexpected value of $lhs:\n"; errs << " expected: " << printable(::llvm::IntegerType::get(context, 32)) << '\n'; errs << " actual: " << printable(lhsType) << '\n'; - + return false; } - + if (::llvm::IntegerType::get(context, 32) != rhsType) { errs << " unexpected value of $rhs:\n"; errs << " expected: " << printable(::llvm::IntegerType::get(context, 32)) << '\n'; errs << " actual: " << printable(rhsType) << '\n'; - + return false; } - + if (::llvm::IntegerType::get(context, 32) != resultType) { errs << " unexpected value of $result:\n"; errs << " expected: " << printable(::llvm::IntegerType::get(context, 32)) << '\n'; errs << " actual: " << printable(resultType) << '\n'; - + return false; } return true; @@ -469,11 +469,11 @@ uint32_t const extra = getExtra(); ::llvm::LLVMContext& context = b.getContext(); (void)context; ::llvm::Module& module = *b.GetInsertBlock()->getModule(); - - + + const ::llvm::AttributeList attrs = ExampleDialect::get(context).getAttributeList(0); - + std::string mangledName = ::llvm_dialects::getMangledName(s_name, {lhs->getType()}); auto fnType = ::llvm::FunctionType::get(lhs->getType(), true); @@ -498,7 +498,7 @@ uint32_t const extra = getExtra(); lhs, rhs }; - + return ::llvm::cast(b.CreateCall(fn, args, instName)); } @@ -508,7 +508,7 @@ rhs (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 2) { errs << " wrong number of arguments: " << arg_size() << ", expected 2\n"; @@ -525,15 +525,15 @@ rhs errs << " unexpected value of $lhs:\n"; errs << " expected: " << printable(resultType) << '\n'; errs << " actual: " << printable(lhsType) << '\n'; - + return false; } - + if (resultType != rhsType) { errs << " unexpected value of $rhs:\n"; errs << " expected: " << printable(resultType) << '\n'; errs << " actual: " << printable(rhsType) << '\n'; - + return false; } return true; @@ -564,11 +564,11 @@ rhs ::llvm::LLVMContext& context = b.getContext(); (void)context; ::llvm::Module& module = *b.GetInsertBlock()->getModule(); - - + + const ::llvm::AttributeList attrs = ExampleDialect::get(context).getAttributeList(0); - + std::string mangledName = ::llvm_dialects::getMangledName(s_name, {::llvm::cast(vector->getType())->getElementType()}); auto fnType = ::llvm::FunctionType::get(::llvm::cast(vector->getType())->getElementType(), true); @@ -593,7 +593,7 @@ rhs vector, index }; - + return ::llvm::cast(b.CreateCall(fn, args, instName)); } @@ -603,7 +603,7 @@ index (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 2) { errs << " wrong number of arguments: " << arg_size() << ", expected 2\n"; @@ -620,24 +620,24 @@ index errs << " unexpected value of $index:\n"; errs << " expected: " << printable(::llvm::IntegerType::get(context, 32)) << '\n'; errs << " actual: " << printable(indexType) << '\n'; - + return false; } - + if (!(::llvm::isa(vectorType))) { errs << " failed check for (XdVectorType any, ?:$result, any):$vector\n"; - + errs << " with $vector = " << printable(vectorType) << '\n'; - - + + return false; } - + if (::llvm::cast(vectorType)->getElementType() != resultType) { errs << " unexpected value of $result:\n"; errs << " expected: " << printable(::llvm::cast(vectorType)->getElementType()) << '\n'; errs << " actual: " << printable(resultType) << '\n'; - + return false; } return true; @@ -668,11 +668,11 @@ index ::llvm::LLVMContext& context = b.getContext(); (void)context; ::llvm::Module& module = *b.GetInsertBlock()->getModule(); - - + + const ::llvm::AttributeList attrs = ExampleDialect::get(context).getAttributeList(0); - + std::string mangledName = ::llvm_dialects::getMangledName(s_name, {resultType}); auto fnType = ::llvm::FunctionType::get(resultType, true); @@ -696,7 +696,7 @@ index ::llvm::SmallVector<::llvm::Value*, 1> args = { source }; - + return ::llvm::cast(b.CreateCall(fn, args, instName)); } @@ -706,7 +706,7 @@ source (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 1) { errs << " wrong number of arguments: " << arg_size() << ", expected 1\n"; @@ -719,44 +719,44 @@ source if (!(::llvm::isa<::llvm::FixedVectorType>(sourceType))) { errs << " failed check for (FixedVectorType ?:$scalar_type, ?:$num_elements):$source\n"; - + errs << " with $source = " << printable(sourceType) << '\n'; - - + + return false; } - + if (!(::llvm::isa(resultType))) { errs << " failed check for (XdVectorType ?:$kind, ?:$scalar_type, ?:$num_elements):$result\n"; - + errs << " with $result = " << printable(resultType) << '\n'; - - + + return false; } - + if (::llvm::cast(resultType)->getElementType() != ::llvm::cast<::llvm::FixedVectorType>(sourceType)->getElementType()) { errs << " unexpected value of $scalar_type:\n"; errs << " expected: " << printable(::llvm::cast(resultType)->getElementType()) << '\n'; errs << " actual: " << printable(::llvm::cast<::llvm::FixedVectorType>(sourceType)->getElementType()) << '\n'; - + return false; } - + if (::llvm::cast(resultType)->getNumElements() != ::llvm::cast<::llvm::FixedVectorType>(sourceType)->getNumElements()) { errs << " unexpected value of $num_elements:\n"; errs << " expected: " << printable(::llvm::cast(resultType)->getNumElements()) << '\n'; errs << " actual: " << printable(::llvm::cast<::llvm::FixedVectorType>(sourceType)->getNumElements()) << '\n'; - + return false; } if (![&]() { { if (true - + && !([&]() { - + if (xd::VectorKind::LittleEndian != ::llvm::cast(resultType)->getKind()) { return false; } @@ -764,7 +764,7 @@ source }()) && !([&]() { - + if (xd::VectorKind::BigEndian != ::llvm::cast(resultType)->getKind()) { return false; } @@ -774,34 +774,34 @@ source errs << " eq:$rhs (" << printable(::llvm::cast(resultType)->getKind()) << ") does not match any available option\n"; - + errs << " failed option 0 (VectorKindLittleEndian):\n"; ([&]() { - + if (xd::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 << " previously: " << printable(::llvm::cast(resultType)->getKind()) << '\n'; - + return false; } - + return true; })(); - + errs << " failed option 1 (VectorKindBigEndian):\n"; ([&]() { - + if (xd::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 << " previously: " << printable(::llvm::cast(resultType)->getKind()) << '\n'; - + return false; } - + return true; })(); return false; @@ -811,10 +811,10 @@ source return true; }()) { errs << " while checking (isReasonableVectorKind ?:$kind)\n"; - + errs << " with $kind = " << printable(::llvm::cast(resultType)->getKind()) << '\n'; - - + + return false; } return true; @@ -838,8 +838,8 @@ source ::llvm::LLVMContext& context = b.getContext(); (void)context; ::llvm::Module& module = *b.GetInsertBlock()->getModule(); - - + + const ::llvm::AttributeList attrs = ExampleDialect::get(context).getAttributeList(0); auto fnType = ::llvm::FunctionType::get(XdHandleType::get(context), { @@ -870,7 +870,7 @@ source (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 0) { errs << " wrong number of arguments: " << arg_size() << ", expected 0\n"; @@ -883,7 +883,7 @@ source errs << " unexpected value of $result:\n"; errs << " expected: " << printable(XdHandleType::get(context)) << '\n'; errs << " actual: " << printable(resultType) << '\n'; - + return false; } return true; @@ -900,11 +900,11 @@ source ::llvm::LLVMContext& context = b.getContext(); (void)context; ::llvm::Module& module = *b.GetInsertBlock()->getModule(); - - + + const ::llvm::AttributeList attrs = ExampleDialect::get(context).getAttributeList(0); - + std::string mangledName = ::llvm_dialects::getMangledName(s_name, {resultType}); auto fnType = ::llvm::FunctionType::get(resultType, true); @@ -928,7 +928,7 @@ source ::llvm::SmallVector<::llvm::Value*, 1> args = { source }; - + return ::llvm::cast(b.CreateCall(fn, args, instName)); } @@ -938,7 +938,7 @@ source (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 1) { errs << " wrong number of arguments: " << arg_size() << ", expected 1\n"; @@ -951,30 +951,30 @@ source if (!(sourceType->isIntegerTy())) { errs << " failed check for (IntegerType (le ?:$result_width)):$source\n"; - + errs << " with $source = " << printable(sourceType) << '\n'; - - + + return false; } - + if (!(resultType->isIntegerTy())) { errs << " failed check for (IntegerType ?:$result_width):$result\n"; - + errs << " with $result = " << printable(resultType) << '\n'; - - + + return false; } - + if (!(sourceType->getIntegerBitWidth() <= resultType->getIntegerBitWidth())) { errs << " failed check for (le ?:$result_width):IntegerType:$num_bits\n"; - + errs << " with IntegerType:$num_bits = " << printable(sourceType->getIntegerBitWidth()) << '\n'; - + errs << " with $result_width = " << printable(resultType->getIntegerBitWidth()) << '\n'; - - + + return false; } return true; @@ -998,11 +998,11 @@ source ::llvm::LLVMContext& context = b.getContext(); (void)context; ::llvm::Module& module = *b.GetInsertBlock()->getModule(); - - + + const ::llvm::AttributeList attrs = ExampleDialect::get(context).getAttributeList(0); - + std::string mangledName = ::llvm_dialects::getMangledName(s_name, {resultType}); auto fnType = ::llvm::FunctionType::get(resultType, true); @@ -1026,7 +1026,7 @@ source ::llvm::SmallVector<::llvm::Value*, 1> args = { source }; - + return ::llvm::cast(b.CreateCall(fn, args, instName)); } @@ -1036,7 +1036,7 @@ source (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 1) { errs << " wrong number of arguments: " << arg_size() << ", expected 1\n"; @@ -1049,30 +1049,30 @@ source if (!(sourceType->isIntegerTy())) { errs << " failed check for (IntegerType ?:$source_width):$source\n"; - + errs << " with $source = " << printable(sourceType) << '\n'; - - + + return false; } - + if (!(resultType->isIntegerTy())) { errs << " failed check for (IntegerType ?:$result_width):$result\n"; - + errs << " with $result = " << printable(resultType) << '\n'; - - + + return false; } - + if (!(resultType->getIntegerBitWidth() <= sourceType->getIntegerBitWidth())) { errs << " failed check for (le ?:$result_width, ?:$source_width)\n"; - + errs << " with $result_width = " << printable(resultType->getIntegerBitWidth()) << '\n'; - + errs << " with $source_width = " << printable(sourceType->getIntegerBitWidth()) << '\n'; - - + + return false; } return true; @@ -1096,8 +1096,8 @@ source ::llvm::LLVMContext& context = b.getContext(); (void)context; ::llvm::Module& module = *b.GetInsertBlock()->getModule(); - - + + const ::llvm::AttributeList attrs = ExampleDialect::get(context).getAttributeList(4); auto fnType = ::llvm::FunctionType::get(::llvm::Type::getVoidTy(context), { @@ -1120,11 +1120,11 @@ source assert(fn.getFunctionType() == fnType); assert(::llvm::cast<::llvm::Function>(fn.getCallee())->getFunctionType() == fn.getFunctionType()); - + ::llvm::SmallVector<::llvm::Value*, 1> args = { - ::llvm::ConstantInt::get(::llvm::IntegerType::get(context, 1), val) + ::llvm::ConstantInt::get(::llvm::IntegerType::get(context, 1), val) }; - + return ::llvm::cast(b.CreateCall(fn, args, instName)); } @@ -1134,13 +1134,13 @@ source (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 1) { errs << " wrong number of arguments: " << arg_size() << ", expected 1\n"; return false; } - + if (getArgOperand(0)->getType() != ::llvm::IntegerType::get(context, 1)) { errs << " argument 0 (val) has type: " << *getArgOperand(0)->getType() << '\n'; @@ -1165,11 +1165,11 @@ source ::llvm::LLVMContext& context = b.getContext(); (void)context; ::llvm::Module& module = *b.GetInsertBlock()->getModule(); - - + + const ::llvm::AttributeList attrs = ExampleDialect::get(context).getAttributeList(0); - + std::string mangledName = ::llvm_dialects::getMangledName(s_name, {vector->getType()}); auto fnType = ::llvm::FunctionType::get(vector->getType(), true); @@ -1195,7 +1195,7 @@ vector, value, index }; - + return ::llvm::cast(b.CreateCall(fn, args, instName)); } @@ -1205,7 +1205,7 @@ index (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 3) { errs << " wrong number of arguments: " << arg_size() << ", expected 3\n"; @@ -1224,32 +1224,32 @@ index errs << " unexpected value of $index:\n"; errs << " expected: " << printable(::llvm::IntegerType::get(context, 32)) << '\n'; errs << " actual: " << printable(indexType) << '\n'; - + return false; } - + if (vectorType != resultType) { errs << " unexpected value of $result:\n"; errs << " expected: " << printable(vectorType) << '\n'; errs << " actual: " << printable(resultType) << '\n'; - + return false; } - + if (!(::llvm::isa(resultType))) { errs << " failed check for (XdVectorType ?:$result, any, ?:$value, any)\n"; - + errs << " with $result = " << printable(resultType) << '\n'; - - + + return false; } - + if (::llvm::cast(resultType)->getElementType() != valueType) { errs << " unexpected value of $value:\n"; errs << " expected: " << printable(::llvm::cast(resultType)->getElementType()) << '\n'; errs << " actual: " << printable(valueType) << '\n'; - + return false; } return true; @@ -1287,8 +1287,8 @@ index ::llvm::LLVMContext& context = b.getContext(); (void)context; ::llvm::Module& module = *b.GetInsertBlock()->getModule(); - - + + const ::llvm::AttributeList attrs = ExampleDialect::get(context).getAttributeList(4); auto fnType = ::llvm::FunctionType::get(::llvm::IntegerType::get(context, 32), true); @@ -1313,7 +1313,7 @@ index instName, instName_0 }; - + return ::llvm::cast(b.CreateCall(fn, args, instName_1)); } @@ -1323,7 +1323,7 @@ instName_0 (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 2) { errs << " wrong number of arguments: " << arg_size() << ", expected 2\n"; @@ -1340,7 +1340,7 @@ instName_0 errs << " unexpected value of $result:\n"; errs << " expected: " << printable(::llvm::IntegerType::get(context, 32)) << '\n'; errs << " actual: " << printable(resultType) << '\n'; - + return false; } return true; @@ -1371,8 +1371,8 @@ instName_0 ::llvm::LLVMContext& context = b.getContext(); (void)context; ::llvm::Module& module = *b.GetInsertBlock()->getModule(); - - + + const ::llvm::AttributeList attrs = ExampleDialect::get(context).getAttributeList(4); auto fnType = ::llvm::FunctionType::get(::llvm::IntegerType::get(context, 32), true); @@ -1396,7 +1396,7 @@ instName_0 ::llvm::SmallVector<::llvm::Value*, 1> args = { instName }; - + return ::llvm::cast(b.CreateCall(fn, args, instName_0)); } @@ -1406,7 +1406,7 @@ instName (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 1) { errs << " wrong number of arguments: " << arg_size() << ", expected 1\n"; @@ -1421,7 +1421,7 @@ instName errs << " unexpected value of $result:\n"; errs << " expected: " << printable(::llvm::IntegerType::get(context, 32)) << '\n'; errs << " actual: " << printable(resultType) << '\n'; - + return false; } return true; @@ -1445,8 +1445,8 @@ instName ::llvm::LLVMContext& context = b.getContext(); (void)context; ::llvm::Module& module = *b.GetInsertBlock()->getModule(); - - + + const ::llvm::AttributeList attrs = ExampleDialect::get(context).getAttributeList(4); auto fnType = ::llvm::FunctionType::get(::llvm::IntegerType::get(context, 32), true); @@ -1470,9 +1470,9 @@ instName ::llvm::SmallVector<::llvm::Value*, 0> args = { }; - + args.append(instName_0.begin(), instName_0.end()); - + return ::llvm::cast(b.CreateCall(fn, args, instName)); } @@ -1489,7 +1489,7 @@ instName errs << " unexpected value of $result:\n"; errs << " expected: " << printable(::llvm::IntegerType::get(context, 32)) << '\n'; errs << " actual: " << printable(resultType) << '\n'; - + return false; } return true; @@ -1511,11 +1511,11 @@ instName ::llvm::LLVMContext& context = b.getContext(); (void)context; ::llvm::Module& module = *b.GetInsertBlock()->getModule(); - - + + const ::llvm::AttributeList attrs = ExampleDialect::get(context).getAttributeList(3); - + std::string mangledName = ::llvm_dialects::getMangledName(s_name, {dataType}); auto fnType = ::llvm::FunctionType::get(dataType, { @@ -1546,7 +1546,7 @@ instName (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 0) { errs << " wrong number of arguments: " << arg_size() << ", expected 0\n"; @@ -1568,11 +1568,11 @@ instName ::llvm::LLVMContext& context = b.getContext(); (void)context; ::llvm::Module& module = *b.GetInsertBlock()->getModule(); - - + + const ::llvm::AttributeList attrs = ExampleDialect::get(context).getAttributeList(3); - + std::string mangledName = ::llvm_dialects::getMangledName(s_name, {dataType}); auto fnType = ::llvm::FunctionType::get(dataType, { @@ -1603,7 +1603,7 @@ instName (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 0) { errs << " wrong number of arguments: " << arg_size() << ", expected 0\n"; @@ -1625,8 +1625,8 @@ instName ::llvm::LLVMContext& context = b.getContext(); (void)context; ::llvm::Module& module = *b.GetInsertBlock()->getModule(); - - + + const ::llvm::AttributeList attrs = ExampleDialect::get(context).getAttributeList(2); auto fnType = ::llvm::FunctionType::get(::llvm::Type::getVoidTy(context), true); @@ -1650,7 +1650,7 @@ instName ::llvm::SmallVector<::llvm::Value*, 1> args = { data }; - + return ::llvm::cast(b.CreateCall(fn, args, instName)); } @@ -1660,7 +1660,7 @@ data (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 1) { errs << " wrong number of arguments: " << arg_size() << ", expected 1\n"; @@ -1688,8 +1688,8 @@ data ::llvm::LLVMContext& context = b.getContext(); (void)context; ::llvm::Module& module = *b.GetInsertBlock()->getModule(); - - + + const ::llvm::AttributeList attrs = ExampleDialect::get(context).getAttributeList(0); auto fnType = ::llvm::FunctionType::get(::llvm::IntegerType::get(context, 64), true); @@ -1713,7 +1713,7 @@ data ::llvm::SmallVector<::llvm::Value*, 1> args = { ::llvm::PoisonValue::get(sizeofType) }; - + return ::llvm::cast(b.CreateCall(fn, args, instName)); } @@ -1723,7 +1723,7 @@ data (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 1) { errs << " wrong number of arguments: " << arg_size() << ", expected 1\n"; @@ -1738,7 +1738,7 @@ data errs << " unexpected value of $result:\n"; errs << " expected: " << printable(::llvm::IntegerType::get(context, 64)) << '\n'; errs << " actual: " << printable(resultType) << '\n'; - + return false; } return true; @@ -1762,11 +1762,11 @@ data ::llvm::LLVMContext& context = b.getContext(); (void)context; ::llvm::Module& module = *b.GetInsertBlock()->getModule(); - - + + const ::llvm::AttributeList attrs = ExampleDialect::get(context).getAttributeList(1); - + std::string mangledName = ::llvm_dialects::getMangledName(s_name, {initial->getType()}); auto fnType = ::llvm::FunctionType::get(initial->getType(), true); @@ -1792,7 +1792,7 @@ ptr, count, initial }; - + return ::llvm::cast(b.CreateCall(fn, args, instName)); } @@ -1802,7 +1802,7 @@ initial (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 3) { errs << " wrong number of arguments: " << arg_size() << ", expected 3\n"; @@ -1821,23 +1821,23 @@ initial errs << " unexpected value of $ptr:\n"; errs << " expected: " << printable(::llvm::PointerType::get(::llvm::Type::getInt8Ty(context), 0)) << '\n'; errs << " actual: " << printable(ptrType) << '\n'; - + return false; } - + if (::llvm::IntegerType::get(context, 64) != countType) { errs << " unexpected value of $count:\n"; errs << " expected: " << printable(::llvm::IntegerType::get(context, 64)) << '\n'; errs << " actual: " << printable(countType) << '\n'; - + return false; } - + if (initialType != resultType) { errs << " unexpected value of $result:\n"; errs << " expected: " << printable(initialType) << '\n'; errs << " actual: " << printable(resultType) << '\n'; - + return false; } return true; @@ -1854,11 +1854,11 @@ initial ::llvm::LLVMContext& context = b.getContext(); (void)context; ::llvm::Module& module = *b.GetInsertBlock()->getModule(); - - + + const ::llvm::AttributeList attrs = ExampleDialect::get(context).getAttributeList(1); - + std::string mangledName = ::llvm_dialects::getMangledName(s_name, {initial->getType()}); auto fnType = ::llvm::FunctionType::get(initial->getType(), true); @@ -1884,7 +1884,7 @@ ptr, count, initial }; - + return ::llvm::cast(b.CreateCall(fn, args, instName)); } @@ -1894,7 +1894,7 @@ initial (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 3) { errs << " wrong number of arguments: " << arg_size() << ", expected 3\n"; @@ -1913,23 +1913,23 @@ initial errs << " unexpected value of $ptr:\n"; errs << " expected: " << printable(::llvm::PointerType::get(::llvm::Type::getInt8Ty(context), 0)) << '\n'; errs << " actual: " << printable(ptrType) << '\n'; - + return false; } - + if (::llvm::IntegerType::get(context, 64) != countType) { errs << " unexpected value of $count:\n"; errs << " expected: " << printable(::llvm::IntegerType::get(context, 64)) << '\n'; errs << " actual: " << printable(countType) << '\n'; - + return false; } - + if (initialType != resultType) { errs << " unexpected value of $result:\n"; errs << " expected: " << printable(initialType) << '\n'; errs << " actual: " << printable(resultType) << '\n'; - + return false; } return true; @@ -1946,11 +1946,11 @@ initial ::llvm::LLVMContext& context = b.getContext(); (void)context; ::llvm::Module& module = *b.GetInsertBlock()->getModule(); - - + + const ::llvm::AttributeList attrs = ExampleDialect::get(context).getAttributeList(1); - + std::string mangledName = ::llvm_dialects::getMangledName(s_name, {initial->getType()}); auto fnType = ::llvm::FunctionType::get(initial->getType(), true); @@ -1976,7 +1976,7 @@ ptr, count, initial }; - + return ::llvm::cast(b.CreateCall(fn, args, instName)); } @@ -1986,7 +1986,7 @@ initial (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 3) { errs << " wrong number of arguments: " << arg_size() << ", expected 3\n"; @@ -2005,23 +2005,23 @@ initial errs << " unexpected value of $ptr:\n"; errs << " expected: " << printable(::llvm::PointerType::get(::llvm::Type::getInt8Ty(context), 0)) << '\n'; errs << " actual: " << printable(ptrType) << '\n'; - + return false; } - + if (::llvm::IntegerType::get(context, 64) != countType) { errs << " unexpected value of $count:\n"; errs << " expected: " << printable(::llvm::IntegerType::get(context, 64)) << '\n'; errs << " actual: " << printable(countType) << '\n'; - + return false; } - + if (initialType != resultType) { errs << " unexpected value of $result:\n"; errs << " expected: " << printable(initialType) << '\n'; errs << " actual: " << printable(resultType) << '\n'; - + return false; } return true; @@ -2038,8 +2038,8 @@ initial ::llvm::LLVMContext& context = b.getContext(); (void)context; ::llvm::Module& module = *b.GetInsertBlock()->getModule(); - - + + const ::llvm::AttributeList attrs = ExampleDialect::get(context).getAttributeList(4); auto fnType = ::llvm::FunctionType::get(::llvm::Type::getVoidTy(context), { @@ -2062,11 +2062,11 @@ initial assert(fn.getFunctionType() == fnType); assert(::llvm::cast<::llvm::Function>(fn.getCallee())->getFunctionType() == fn.getFunctionType()); - + ::llvm::SmallVector<::llvm::Value*, 1> args = { - b.CreateGlobalString(val) + b.CreateGlobalString(val, "str", 4) }; - + return ::llvm::cast(b.CreateCall(fn, args, instName)); } @@ -2076,13 +2076,13 @@ initial (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 1) { errs << " wrong number of arguments: " << arg_size() << ", expected 1\n"; return false; } - + if (getArgOperand(0)->getType() != ::llvm::PointerType::get(::llvm::Type::getInt8Ty(context), 0)) { errs << " argument 0 (val) has type: " << *getArgOperand(0)->getType() << '\n'; @@ -2107,8 +2107,8 @@ initial ::llvm::LLVMContext& context = b.getContext(); (void)context; ::llvm::Module& module = *b.GetInsertBlock()->getModule(); - - + + const ::llvm::AttributeList attrs = ExampleDialect::get(context).getAttributeList(2); auto fnType = ::llvm::FunctionType::get(::llvm::Type::getVoidTy(context), true); @@ -2132,7 +2132,7 @@ initial ::llvm::SmallVector<::llvm::Value*, 1> args = { data }; - + return ::llvm::cast(b.CreateCall(fn, args, instName)); } @@ -2142,7 +2142,7 @@ data (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 1) { errs << " wrong number of arguments: " << arg_size() << ", expected 1\n"; @@ -2170,8 +2170,8 @@ data ::llvm::LLVMContext& context = b.getContext(); (void)context; ::llvm::Module& module = *b.GetInsertBlock()->getModule(); - - + + const ::llvm::AttributeList attrs = ExampleDialect::get(context).getAttributeList(2); auto fnType = ::llvm::FunctionType::get(::llvm::Type::getVoidTy(context), true); @@ -2195,9 +2195,9 @@ data ::llvm::SmallVector<::llvm::Value*, 1> arguments = { data }; - + arguments.append(args.begin(), args.end()); - + return ::llvm::cast(b.CreateCall(fn, arguments, instName)); } @@ -2207,7 +2207,7 @@ data (void)context; using ::llvm_dialects::printable; - + if (arg_size() < 1) { errs << " wrong number of arguments: " << arg_size() << ", expected at least 1\n"; @@ -2242,7 +2242,7 @@ data return desc; } - + template <> const ::llvm_dialects::OpDescription & ::llvm_dialects::OpDescription::get() { @@ -2250,7 +2250,7 @@ data return desc; } - + template <> const ::llvm_dialects::OpDescription & ::llvm_dialects::OpDescription::get() { @@ -2258,7 +2258,7 @@ data return desc; } - + template <> const ::llvm_dialects::OpDescription & ::llvm_dialects::OpDescription::get() { @@ -2266,7 +2266,7 @@ data return desc; } - + template <> const ::llvm_dialects::OpDescription & ::llvm_dialects::OpDescription::get() { @@ -2274,7 +2274,7 @@ data return desc; } - + template <> const ::llvm_dialects::OpDescription & ::llvm_dialects::OpDescription::get() { @@ -2282,7 +2282,7 @@ data return desc; } - + template <> const ::llvm_dialects::OpDescription & ::llvm_dialects::OpDescription::get() { @@ -2290,7 +2290,7 @@ data return desc; } - + template <> const ::llvm_dialects::OpDescription & ::llvm_dialects::OpDescription::get() { @@ -2298,7 +2298,7 @@ data return desc; } - + template <> const ::llvm_dialects::OpDescription & ::llvm_dialects::OpDescription::get() { @@ -2306,7 +2306,7 @@ data return desc; } - + template <> const ::llvm_dialects::OpDescription & ::llvm_dialects::OpDescription::get() { @@ -2314,7 +2314,7 @@ data return desc; } - + template <> const ::llvm_dialects::OpDescription & ::llvm_dialects::OpDescription::get() { @@ -2322,7 +2322,7 @@ data return desc; } - + template <> const ::llvm_dialects::OpDescription & ::llvm_dialects::OpDescription::get() { @@ -2330,7 +2330,7 @@ data return desc; } - + template <> const ::llvm_dialects::OpDescription & ::llvm_dialects::OpDescription::get() { @@ -2338,7 +2338,7 @@ data return desc; } - + template <> const ::llvm_dialects::OpDescription & ::llvm_dialects::OpDescription::get() { @@ -2346,7 +2346,7 @@ data return desc; } - + template <> const ::llvm_dialects::OpDescription & ::llvm_dialects::OpDescription::get() { @@ -2354,7 +2354,7 @@ data return desc; } - + template <> const ::llvm_dialects::OpDescription & ::llvm_dialects::OpDescription::get() { @@ -2362,7 +2362,7 @@ data return desc; } - + template <> const ::llvm_dialects::OpDescription & ::llvm_dialects::OpDescription::get() { @@ -2370,7 +2370,7 @@ data return desc; } - + template <> const ::llvm_dialects::OpDescription & ::llvm_dialects::OpDescription::get() { @@ -2378,7 +2378,7 @@ data return desc; } - + template <> const ::llvm_dialects::OpDescription & ::llvm_dialects::OpDescription::get() { @@ -2386,7 +2386,7 @@ data return desc; } - + template <> const ::llvm_dialects::OpDescription & ::llvm_dialects::OpDescription::get() { @@ -2394,7 +2394,7 @@ data return desc; } - + template <> const ::llvm_dialects::OpDescription & ::llvm_dialects::OpDescription::get() { @@ -2402,7 +2402,7 @@ data return desc; } - + template <> const ::llvm_dialects::OpDescription & ::llvm_dialects::OpDescription::get() { @@ -2410,5 +2410,5 @@ data return desc; } - + #endif // GET_DIALECT_DEFS diff --git a/test/example/test-builder.test b/test/example/test-builder.test index eef0f91..08e1258 100644 --- a/test/example/test-builder.test +++ b/test/example/test-builder.test @@ -3,7 +3,7 @@ ; RUN: llvm-dialects-example - | FileCheck --check-prefixes=CHECK %s ;. -; CHECK: @[[GLOB0:[0-9]+]] = private unnamed_addr constant [13 x i8] c"Hello world!\00", align 1 +; CHECK: @[[GLOB0:.*]] = private unnamed_addr addrspace(4) constant [13 x i8] c"Hello world!\00", align 1 ;. ; CHECK-LABEL: @example( ; CHECK-NEXT: entry: