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
2 changes: 1 addition & 1 deletion example/ExampleDialect.td
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def StructBackedType : DialectType<ExampleDialect, "struct.backed"> {
let description = [{
Test that a struct-backed type works correctly.
}];
let typeArguments = (args AttrI32:$field0, AttrI32:$field1, AttrI32:$field2);
let typeArguments = (args AttrI32:$field0, AttrI8:$field1, AttrVectorKind:$field2);
let representation = (repr_struct (IntegerType 41));

let defaultGetterHasExplicitContextArgument = 1;
Expand Down
2 changes: 1 addition & 1 deletion example/ExampleMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void createFunctionExample(Module &module, const Twine &name) {

b.create<xd::cpp::StringAttrOp>("Hello world!");

xd::cpp::StructBackedType *structBackedTy = xd::cpp::StructBackedType::get(bb->getContext(), 1, 0, 2);
xd::cpp::StructBackedType *structBackedTy = xd::cpp::StructBackedType::get(bb->getContext(), 1, 0, xd::cpp::VectorKind::BigEndian);
auto *structBackedVal = b.create<xd::cpp::DummyStructBackedOutpOp>(structBackedTy, b.getInt32(42), "gen.struct.backed.val");
b.create<xd::cpp::DummyStructBackedInpOp>(structBackedVal, "consume.struct.backed.val");

Expand Down
14 changes: 7 additions & 7 deletions lib/TableGen/DialectType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,14 @@ void DialectType::emitDeclaration(raw_ostream &out, GenDialect *dialect) const {
for (const auto &argument : typeArguments()) {
std::string camel = convertToCamelFromSnakeCase(argument.name, true);
out << tgfmt(
R"( unsigned get$0() const {
::llvm::Type *elt = getElementType($1);
R"( $0 get$1() const {
::llvm::Type *elt = getElementType($2);
if (elt->isStructTy())
return 0;
return ::llvm::cast<::llvm::IntegerType>(elt)->getBitWidth();
return ($0)0;
return ($0)::llvm::cast<::llvm::IntegerType>(elt)->getBitWidth();
}
)",
&fmt, camel, fieldIdx++);
&fmt, argument.type->getCppType(), camel, fieldIdx++);
}

out << " };\n\n";
Expand Down Expand Up @@ -309,10 +309,10 @@ void DialectType::emitDefinition(raw_ostream &out, GenDialect *dialect) const {

for (const auto &getterArg : getterArgs) {
out << tgfmt(R"(
if ($0 == 0)
if ((uint64_t)$0 == 0)
$fields.push_back(::llvm::StructType::get($_context));
else
$fields.push_back(::llvm::IntegerType::get($_context, $0));
$fields.push_back(::llvm::IntegerType::get($_context, (uint64_t)$0));
Comment on lines +312 to +315
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conversions here and above should use getToUnsigned and getFromUnsigned

)",
&fmt, getterArg.name);
}
Expand Down
16 changes: 8 additions & 8 deletions test/example/generated/ExampleDialect.cpp.inc
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,10 @@ m_attributeLists[6] = argAttrList.addFnAttributes(context, attrBuilder);
}
}

StructBackedType* StructBackedType::get(::llvm::LLVMContext & ctx, uint32_t field0, uint32_t field1, uint32_t field2) {

StructBackedType* StructBackedType::get(::llvm::LLVMContext & ctx, uint32_t field0, uint8_t field1, VectorKind field2) {


static_assert(sizeof(field2) <= sizeof(unsigned));
std::string name; ::llvm::raw_string_ostream os(name);
os << "struct.backed";
os << '.' << (uint64_t)field0;
Expand All @@ -270,20 +270,20 @@ StructBackedType* StructBackedType::get(::llvm::LLVMContext & ctx, uint32_t fiel
::std::vector<::llvm::Type*> fields;
fields.push_back(::llvm::IntegerType::get(ctx, 41));

if (field0 == 0)
if ((uint64_t)field0 == 0)
fields.push_back(::llvm::StructType::get(ctx));
else
fields.push_back(::llvm::IntegerType::get(ctx, field0));
fields.push_back(::llvm::IntegerType::get(ctx, (uint64_t)field0));

if (field1 == 0)
if ((uint64_t)field1 == 0)
fields.push_back(::llvm::StructType::get(ctx));
else
fields.push_back(::llvm::IntegerType::get(ctx, field1));
fields.push_back(::llvm::IntegerType::get(ctx, (uint64_t)field1));

if (field2 == 0)
if ((uint64_t)field2 == 0)
fields.push_back(::llvm::StructType::get(ctx));
else
fields.push_back(::llvm::IntegerType::get(ctx, field2));
fields.push_back(::llvm::IntegerType::get(ctx, (uint64_t)field2));
auto *st = ::llvm::StructType::create(ctx, fields, os.str(), /*isPacked=*/false);
return static_cast<StructBackedType *>(st);
}
Expand Down
20 changes: 10 additions & 10 deletions test/example/generated/ExampleDialect.h.inc
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,27 @@ namespace xd::cpp {
using ::llvm::StructType::getElementType;

static StructBackedType *get(
::llvm::LLVMContext & ctx, uint32_t field0, uint32_t field1, uint32_t field2);
::llvm::LLVMContext & ctx, uint32_t field0, uint8_t field1, VectorKind field2);

static bool classof(const ::llvm::Type *t);

unsigned getField0() const {
uint32_t getField0() const {
::llvm::Type *elt = getElementType(1);
if (elt->isStructTy())
return 0;
return ::llvm::cast<::llvm::IntegerType>(elt)->getBitWidth();
return (uint32_t)0;
return (uint32_t)::llvm::cast<::llvm::IntegerType>(elt)->getBitWidth();
}
unsigned getField1() const {
uint8_t getField1() const {
::llvm::Type *elt = getElementType(2);
if (elt->isStructTy())
return 0;
return ::llvm::cast<::llvm::IntegerType>(elt)->getBitWidth();
return (uint8_t)0;
return (uint8_t)::llvm::cast<::llvm::IntegerType>(elt)->getBitWidth();
}
unsigned getField2() const {
VectorKind getField2() const {
::llvm::Type *elt = getElementType(3);
if (elt->isStructTy())
return 0;
return ::llvm::cast<::llvm::IntegerType>(elt)->getBitWidth();
return (VectorKind)0;
return (VectorKind)::llvm::cast<::llvm::IntegerType>(elt)->getBitWidth();
}
};

Expand Down