This is an archive of the discontinued LLVM Phabricator instance.

[TableGen] Add the assert statement, step 1
ClosedPublic

Authored by Paul-C-Anagnostopoulos on Dec 29 2020, 12:06 PM.

Details

Summary

This first step adds the assert statement and supports it at top level and in record definitions. Later steps will support it in class definitions and multiclasses.

I described it in the TableGen Programmer's Reference and added a test.

Diff Detail

Event Timeline

Paul-C-Anagnostopoulos requested review of this revision.Dec 29 2020, 12:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 29 2020, 12:06 PM
craig.topper added inline comments.
llvm/lib/TableGen/TGParser.cpp
3206

Put curly braces on this to be consistent with the elses

3207

Can we use a real error here? I assert(false) should usually be llvm_unreachable but since this is something the user can create it looks like its not truly unreachable.

3211

Drop this blank line

3314

Why is this line removed?

Paul-C-Anagnostopoulos added inline comments.
llvm/lib/TableGen/TGParser.cpp
3206

Will do.

3207

Will do.

3211

Will do.

3314

Because almost none of the comments have a blank comment line at the end and I was being compulsive. I'll put it back.

Paul-C-Anagnostopoulos marked 4 inline comments as done.

I made Craig's suggested changes. I also added one more test to the test file.

llvm/include/llvm/TableGen/Record.h
1586

Do I need to use std::move() here?

craig.topper added inline comments.Dec 30 2020, 11:17 AM
llvm/include/llvm/TableGen/Record.h
1586

Do I need to use std::move() here?

I don't think so. All of individual types are cheap to copy so it should be fine to just copy the tuple.

Bumping this for a final "looks good."

Looks like a great feature to me! I'd recommend requiring the message, I'd also consider requiring parens around the condition and message. This makes it more C like and makes it look less like a type definition:

def Rec14 : Cube<3> {

int double_result = !mul(result, 2);
assert(!eq(double_result, 53), "double_result should be 54");

}

llvm/docs/TableGen/ProgRef.rst
1258

Given that we don't have backwards compatibility issues, I'd just require the message.

I understand requiring the message, but I don't understand the parentheses. It makes the 'assert' statement syntactically incompatible with the 'if' and 'foreach' statements. Also, it makes it look like assert is a function.

Fair enough, good point. In C, it is a function, whereas in tblgen it is a declaration. I'm ok dropping the parens.

The message is now required in the assert statement.

lattner accepted this revision.Jan 6 2021, 5:19 PM
lattner added inline comments.
llvm/docs/TableGen/ProgRef.rst
1258

nit, I think it can just be:

Assert: "assert" condition "," message ";"

This revision is now accepted and ready to land.Jan 6 2021, 5:19 PM
This revision was automatically updated to reflect the committed changes.
Paul-C-Anagnostopoulos marked an inline comment as done.