[cfe-dev] Adding custom builtins

Sam Parker S.Parker3 at lboro.ac.uk
Thu Oct 25 03:05:48 PDT 2012


Hi Dani,

I've just added some builtins for my target and this is what I needed to do:
LLVM was modified by:
- Created an Intrinsics*.td in include/llvm/ and defined the intrinsic to extend GCCBuiltin. This file was included at the bottom of Intrinsics.td in the same directory.
- The instruction was defined in the lib/Target/*InstrInfo.td file which used the intrinsic as it's pattern.

Clang was modified by:
- Created a Builtins*.def for the target in clang/include/clang/Basic.
- Modified include/clang/Basic/TargetBuiltins.h to include the target by copying the other targets but referencing the newly created .def file.
- Modified the TargetInfo class to contain BuiltinInfo in clang/lib/Basic/Targets.cpp.
- Add a function in clang/lib/CodeGen/CGBuiltin.cpp to the handle the builtin and a case in EmitTargetBuiltinExpr to call that function.

If you just follow the examples of the existing targets, its quite simple. Hope that helps.

Regards,
Sam

Research Student
Electronic Systems Design Group
Loughborough University
________________________________
From: cfe-dev-bounces at cs.uiuc.edu [cfe-dev-bounces at cs.uiuc.edu] on behalf of Daniel Kudrow [dkudrow at gmail.com]
Sent: 24 October 2012 19:57
To: cfe-dev at cs.uiuc.edu
Subject: [cfe-dev] Adding custom builtins

Hi all,
I'm hacking clang to parse a c-like quantum programming language and am having trouble parsing builtin functions. It seems to me that FunctionDecl::getBuiltinID() [Decl.cpp] is chiefly responsible for determining whether a function identifier is a builtin or not. However the guts of this function: IdentifierInfo::getBuiltinID() [IdentfierTable.h] but it appears to me that this function will only recognize objective c builtins.

  /// getBuiltinID - Return a value indicating whether this is a builtin
  /// function.  0 is not-built-in.  1 is builtin-for-some-nonprimary-target.
  /// 2+ are specific builtin functions.
  unsigned getBuiltinID() const {
    if (ObjCOrBuiltinID >= tok::NUM_OBJC_KEYWORDS)
      return ObjCOrBuiltinID - tok::NUM_OBJC_KEYWORDS;
    else
      return 0;
  }

Am I missing a step in the builtin lookup process?

Many thanks,
Dani
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20121025/7332d1b1/attachment.html>


More information about the cfe-dev mailing list