This is an archive of the discontinued LLVM Phabricator instance.

Add pointer types to global named register
ClosedPublic

Authored by rengolin on May 27 2014, 2:58 AM.

Details

Summary

This patch adds support for pointer types in global named registers variables.
It'll be lowered as a pair of read/write_register and inttoptr/ptrtoint calls.
Also adds some early checks on types on SemaDecl to avoid the assert.

Tests changed accordingly. (PR19837)

Diff Detail

Event Timeline

rengolin updated this revision to Diff 9827.May 27 2014, 2:58 AM
rengolin retitled this revision from to Add pointer types to global named register.
rengolin updated this object.
rengolin edited the test plan for this revision. (Show Details)
rengolin added reviewers: rnk, rafael.
rengolin set the repository for this revision to rL LLVM.
rengolin added subscribers: Unknown Object (MLST), joerg.
joerg added a comment.May 28 2014, 9:48 AM

Not directly related, but can you also check that the size of the integer type can be used for this register at the point of declaration? E.g. long long should be invalid on i386. GCC doesn't seem to check this at declaration time, but that feels bogus especially as it make the code dependent on the optimizer again.

rnk edited edge metadata.May 28 2014, 11:41 AM

Please add a test where the size of the integer type and the size of the register don't match as Joerg suggested.

rafael edited edge metadata.May 29 2014, 10:58 AM

Please include a test with the new error.

I like Joeg and Reid suggestion of rejecting invalid sizes. For
example, a pointer should not go to eax on x86_64, but I think that
requires extra llvm support, no? If so, this patch LGTM, but please do
address their suggestion in a subsequent patch.

Thanks,
Rafael

Hi Joerg,

Sorry for the delay.

I don't think it's currently possible to do the type size verification in Clang, and such a patch would not only be bigger than this, but completely off topic.

AFAIK, the function that checks for register names in Clang join *all* targets' registers into one list and match any of them. So, Clang accepts "sp" as a register names on x86 and "Q12" on ARMv4. The process that will check for real register lists per-target is in LLVM, and that's not even complete.

I can't promote/demote the integral type to the register size, since Clang has no knowledge if LLVM supports vector registers or if the target has more than one size of registers, or if the pointer type is actually the size of the register, etc, etc. Until Clang has that kind of knowledge, and verifies that the register name matches the target and know their sizes, it's when Clang will be able to check if the type size matches the register itself.

At least for now, LLVM has a fatal error on invalid register names and types.

cheers,
--renato

joerg added a comment.Jun 3 2014, 8:51 AM

Yes, I am aware that it is unrelated. I saw the problem while trying out a few things and looking over the patch. Please don't let that inquire hold you back on this patch.

Ok, I'll get this in, then, and have a look at the Clang register reporting next.

Thanks!

rengolin accepted this revision.Jun 5 2014, 9:56 AM
rengolin added a reviewer: rengolin.

Committed in r210274

This revision is now accepted and ready to land.Jun 5 2014, 9:56 AM
rengolin closed this revision.Jun 5 2014, 9:56 AM