I have some questions about the behavior of getReg:
__getReg ultimately invokes getRegisterByName in http://llvm.org/doxygen/AArch64ISelLowering_8cpp_source.html.
You can __getReg only those registers which appear in the switch-case inside that function. Even then the logic there checks if the requested register is reserved. If not, then it makes the reg = 0 which results in "Invalid register name" error.
I am not sure how this should be dealt with. Is it fine to add all regs (0-31) to the switch-case in getRegisterByName? And should the checks for isRegReserved be bypassed for COFF?
I don't really know about this one, I'll add a few more people who might be able to comment on it. @efriedma @peter.smith
read_register only allows reading reserved registers because reading an allocatable register is meaningless (the compiler can store arbitrary data in allocatable registers).
The same applies to __getReg; given that, I would assume real code doesn't use anything other than __getReg(18) or __getReg(31), so we can just reject any other constant.
Semantic checks belong in SemaChecking, not here. IIRC you can request constant checking in the .def file, although I don't remember the syntax off the top of my head.
There is no register named x31. Maybe you need a special case here to use "sp" if the input is 31?
Could you just write this as std::string Reg = Value == 31 ? "sp" : "x" + Value.toString(10);, and get rid of StrVal?
Needs a testcase for the error message like we have for other intrinsics in test/Sema/builtins-arm64.c . Otherwise LGTM.