[llvm-dev] running intrinsics from C code

Rail Shafigulin via llvm-dev llvm-dev at lists.llvm.org
Thu May 26 16:24:48 PDT 2016


Thanks for the tip. For some reason it didn't work. I'm sure I'm missing
something very simple. Do you mind helping out? Here is what I have so far:

I'm getting a following error when I run a simple test:
cannot compile this builtin function yet

Here is the test code:
typedef int v4si __attribute__ ((vector_size (16)));

int foo (int a, int b, int c, int d) {
  v4si vec = {a, b, c, d};
  return esencia_hadd(vec);
}

My intrinsic is defined in <full path to
llvm>/include/llvm/IR/IntrinsicsEsencia.td

let TargetPrefix = "esencia" in
def int_esencia_hadd : Intrinsic<[llvm_i32_ty],
                              [llvm_v4i32_ty],
                              [IntrNoMem]>;


My builtin is defined in <full path to
clang>/include/clang/Basic/BuiltinsEsencia.def
BUILTIN(esencia_hadd, "iV4Si", "nc")

I've also added code to <full path to clang/lib/Basic/Targerts.cpp

const Builtin::Info EsenciaTargetInfo::BuiltinInfo[] = {
#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
                                              ALL_LANGUAGES },
#include "clang/Basic/BuiltinsEsencia.def"
};


as well as to <full path to clang>/include/clang/Basic/TargetBuiltins.h

  /// \brief Esencia builtins
  namespace Esencia {
    enum {
        LastTIBuiltin = clang::Builtin::FirstTSBuiltin-1,
#define BUILTIN(ID, TYPE, ATTRS) BI##ID,
#include "clang/Basic/BuiltinsEsencia.def"
        LastTSBuiltin
    };
  }

What am I missing?

On Tue, May 24, 2016 at 6:09 PM, Craig Topper <craig.topper at gmail.com>
wrote:

> GCCBuiltin just gives it a name for clang to lookup. Generally they match
> up with builtins that gcc also implements, but that's not a requirement.
>
> If you add a builtin with the same name to the builtin file in clang's
> include/clang/Basic/Builtins*.def then they will find each other.
>
> You can also just add a builtin to clang's builtin file and catch it in
> clang's lib/CodeGen/CGBuiltins.cpp and implement whatever IR you want
> including calling an intrinsic.
>
> Hope this helps.
>
> On Tue, May 24, 2016 at 5:04 PM, Rail Shafigulin via llvm-dev <
> llvm-dev at lists.llvm.org> wrote:
>
>> I've created an intrinsic from my target, but I can't figure out how I
>> can run it from a C code. Most of the targets have a GCCBuiltin and it
>> looks like it is the way to execute an intrinsic from C code. However in my
>> case there is no actual GCC built in.
>>
>> Any help on this is really appreciated.
>>
>> --
>> Rail Shafigulin
>> Software Engineer
>> Esencia Technologies
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> llvm-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>>
>>
>
>
> --
> ~Craig
>



-- 
Rail Shafigulin
Software Engineer
Esencia Technologies
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160526/1ee0d498/attachment.html>


More information about the llvm-dev mailing list