This is an archive of the discontinued LLVM Phabricator instance.

[TableGen] Add field kind to the RecordVal class.
ClosedPublic

Authored by Paul-C-Anagnostopoulos on Jan 1 2021, 9:21 AM.

Details

Summary

This revision adds a field kind to the RecordVal class, replacing the prefix bit in the TyAndKind member (formerly TyAndPrefix). A field can now have one of three kinds: normal, nonconcrete OK (indicated by the 'field' keyword), and template argument.

This revision prepares for the next one, where I will improve the algorithms that deal with class and multiclass template arguments.

Diff Detail

Event Timeline

Paul-C-Anagnostopoulos requested review of this revision.Jan 1 2021, 9:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 1 2021, 9:21 AM

Bumping this for a "looks good."

I'm ok with this, your expertise surpasses mine Paul :-)

@lattner Did you mean to accept this revision?

craig.topper added inline comments.Jan 5 2021, 11:16 AM
llvm/lib/TableGen/Record.cpp
2145

Can you fix this as clang-format suggests? I know it was wrong before you got here and I wouldn't care if the constructor at line 2155 didn't have 4 space indentation. So might as well make them consistent while we're here.

Paul-C-Anagnostopoulos marked an inline comment as done.Jan 6 2021, 9:00 AM

Fixed indentation requested by @craig.topper.

This revision is now accepted and ready to land.Jan 6 2021, 9:44 AM

The llvm tablegen reference guide says the keyword *field* is deprecated.
Is this still valid?

https://llvm.org/docs/TableGen/ProgRef.html

It is deprecated, yes. I'm still investigating whether any TableGen files actually rely on its behavior, which is to allow nonconcrete field values.

Do you have additional information about it?

I had to add 'field' for something like: ( out of tree target)

field string BaseOpcodeSTSrcKind;

...

let BaseOpcodeSTSrcKind = asmstr # opVal # DataSize # PtrMode #

OffsetMode # isSub # isDS # "_ri7";

BaseOpcodeSTSrcKind is then used in InstructionMapping.
Because the initialization of "let BaseOpcodeSTSrcKind =.." is of
type BinOpInit for which isConcrete() returns false.
I am not familiar with tablegen internal enough to understand what is going
on.

Could you post a simple file that reproduces the problem? Without the context of BaseOpcodeSTSrcKind and all the identifiers being pasted, I cannot tell what's going on. It certainly isn't necessary to declare a field 'field' just to set it to a concatenated value.

The identifier come from tablegen class parameter:

class InstD_LD<bits<8> opVal, string DataSize, string PtrMode, string
OffsetMode,

bit isSExt, bit isSub, string SubOrAdd, bit isDS, bit

isTemp,

                 dag outs, dag ins, string asmstr, list<dag> pattern>

let BaseOpcodeLDST = asmstr # DataSize # isSExt # isDS # isTemp;

So this will concat string and bit together.
error: Initializer of 'BaseOpcodeLDST' in 'LD_byte_ptr8_ds_add_sext_ri7'
could not be fully resolved: !strconcat("ldl $rsd2, $addr",
!strconcat("byte", !strconcat("1", !strconcat("1", !cast<string>(0)))))

it seems like isTemp cannot be converted to string.

Sorry I can't reduce this more.. its very difficult to extract the problem
in a self contained test case.

That is plenty of information, thanks. The problem is that the paste operator (#) is not willing to convert a bit to a string. I have no idea why and I will fix this if there is no good reason to prevent it. Meanwhile, you can use:

!cast<int>(isDS)
!cast<int>(isTemp)

And the 'field' keyword is unnecessary.

Thanks, adding the !cast<int> remove the problem. But it would be nice to be able to convert from bit to string automatically otherwise I would need to add the !cast<int> at dozen of places.

I will look at this issue tomorrow and should have a patch soon.