[llvm-dev] Possibilities with LLVM

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Mon Apr 9 03:09:43 PDT 2018


Hi Björn,

On 9 April 2018 at 09:43, via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> 1.) Can I teach the LLVM new platform depended intrinsics?
> Like I provide assembly code and want to create a custom intrinsic for it.

Yes. You'd add a declaration to include/llvm/IR/IntrinsicsXYZ.td
(where XYZ is your target), and then you can select them with a normal
pattern in your target's .td files.

On the Clang side you'd add it to include/clang/Basic/BuiltinsXYZ.def
and lib/CodeGen/CGBuiltin.cpp. Possibly lib/Sema/SemaChecking.cpp too
if it has strange validity requirements.

> 2.) Does the IR language have some kind of template support?
> I'm not sure if this even possible - but I thought about having a template
> function and when jitting the IR it could instantiate that template with the
> now known data - okay writing this already sounds weird and I'm not sure if
> I could explain what I wanted.

No template support, I'm afraid. That would be handled by a language's
front-end.

> 3.) Can I implement my own custom calling convention? Like my own
> "__planschiCall" or something?

Yes. The easiest way would be to use a simple numbered calling
convention "cc N" in the LLVM IR. Then you just have to add support to
lib/Target/XYZ/XYZISelLowering.cpp and the corresponding calling
convention .td file (the name varies a bit). ISelLowering usually just
involves a switch based on the call or definition that selects the
right implementation from the .td file. Grep for CCAssignFnForCall to
see the kind of thing you'll be changing.

Clang side, you'll be changing lib/Targets/XYZ.cpp to either make it
the default or support it via __attribute__((pcs("whatever"))). See
ARM.cpp for an example, it already uses both methods.

Cheers.

Tim.


More information about the llvm-dev mailing list