Named Registers Impl

Folks,

I started implementing the named registers in Clang and was presented
with the nice fact that it's mostly there. At least, all the way to
the AST is all good, but the IR emission, as expected, is still
ignoring the register/asm part of the variable.

So, the idea is to transform all reads from that variable to
@llvm.read_register and all writes to @llvm.write_register. I can
think of two ways of doing this:

1. On Sema::ActOnVariableDeclarator(), on the switch detecting named
register variables, I set the initialization to a call to the
intrinsic. That's pretty high level, but it's where we diagnose bad
register names and where we have most of the information we need. Some
fiddling with the return value will be necessary.

2. Down on CodeGenFunction::EmitDeclRefLValue(), using a previously
set flag (isNamedReg), I replace the lowering of the variable (which
was not initialised in CodeGenFunction::EmitAutoVarAlloca()) by
EmitFunctionDeclLValue(intrinsic, etc). This will require no fiddling
with the return values, but will pass down info until much later.

Is there another way? If not, what is the preferred one?

Thanks,
--renato

Folks,

I started implementing the named registers in Clang and was presented
with the nice fact that it's mostly there. At least, all the way to
the AST is all good, but the IR emission, as expected, is still
ignoring the register/asm part of the variable.

So, the idea is to transform all reads from that variable to
@llvm.read_register and all writes to @llvm.write_register. I can
think of two ways of doing this:

1. On Sema::ActOnVariableDeclarator(), on the switch detecting named
register variables, I set the initialization to a call to the
intrinsic. That's pretty high level, but it's where we diagnose bad
register names and where we have most of the information we need. Some
fiddling with the return value will be necessary.

This will call the intrinsic only once, which is incorrect, no?

Hum, I hadn't thought that through, you're right. We'll need two
intrinsics, one for reads, other for writes, plus we need it on every
read/write, not just on initialization.

The second option did look better. Though, I need to make sure that
it'll work on any read/write, and the code was a bit confusing at
start (I'm getting the hang of it now, I think).

AFAICS, EmitDeclRefLValue() will emit the declaration for setting an
LValue (so writes TO the register), but not reading it, which is
spread around many places (like EmitReturnDecl, Expressions and so
on). We need to make sure sub-expressions that contain a register
variable don't get touched before the variables are lowered to the
intrinsic call.

--renato

cheers,
--renato