[PATCH] [RFC] Implement Named Register Global Variables in LLVM

Renato Golin renato.golin at linaro.org
Wed Apr 2 07:06:28 PDT 2014


Hi all,

This is the first attempt at implementing named register globals in LLVM. There are a number of hacks that will need to be pruned and properly implemented and a number of questions that I have in the code about how to better achieve this. They're commented inline as FIXME.

The key design decisions:

1. The LangRef change explains the semantics of the change. Basically:
  1. The register name is a private global string
  2. The value on write is a pointer type, to get the correct size from the target description
  3. The front end is responsible for casting it (ptrtoint/inttoptr) when needed
2. I'm using an intrinsic for read/write from registers, so that way there will be no side effects from emitting them, nor will it allow taking the address of the register variable.
3. I'm using a global string as the description, as it was the simplest IR I could come up with. I couldn't find a way to have literal strings ([3 x i8]* "sp\0") or how to embed metadata as a node. The problem with this is that the constant is still being emitted in the final file.
  1. If the constant is fine, I need to remove it from the DAG at the right moment. On getRegisterStringValue() is a bit too soon, as it breaks the DAG shortly after. I'll check when it's safe to call the clean up routines.
  2. If metadata is better, to avoid dangling data sections, how do I embed it in the intrinsic call?
4. SelectionDAG -> Lower Intrinsic will lower the intrinsic call into either READ_REGISTER or WRITE_REGISTER nodes. The former is a simple replacement, the latter needs to become a DAG root and long the chain from the value's chain.
  1. I'm not sure that's the best way to catch the chain from the value, which could be anything, not just a copy from virtual register.
5. TargetLowering simply converts READ -> CopyFromReg and WRITE -> CopyToReg(Value)
  1. getRegisterStringValue encodes the knowledge of reading the literal string from the global/metadata
  2. getRegisterByName encodes the logic of which registers are valid. This could be a TableGen property and auto-generated
6. On all targets, lowering READ/WRITE nodes and getting the string literal are identical. Is there a place I can common them up?

Welcoming any comment. Thanks!

http://llvm-reviews.chandlerc.com/D3261

Files:
  docs/LangRef.rst
  include/llvm/CodeGen/ISDOpcodes.h
  include/llvm/IR/Intrinsics.td
  include/llvm/Target/TargetLowering.h
  lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
  lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp
  lib/Target/AArch64/AArch64ISelLowering.cpp
  lib/Target/AArch64/AArch64ISelLowering.h
  lib/Target/ARM/ARMISelLowering.cpp
  lib/Target/ARM/ARMISelLowering.h
  lib/Target/X86/X86ISelLowering.cpp
  lib/Target/X86/X86ISelLowering.h
  test/CodeGen/AArch64/stackpointer.ll
  test/CodeGen/ARM/stackpointer.ll
  test/CodeGen/X86/stackpointer.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3261.1.patch
Type: text/x-patch
Size: 22401 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140402/f4262c2f/attachment.bin>


More information about the llvm-commits mailing list