[LLVMdev] Queue implementation is being trapped

Cristianno Martins cristiannomartins at gmail.com
Tue May 14 11:42:51 PDT 2013

Hello there,

I'm trying to use a simple implementation of a queue (my own implementation
of it, actually), and I'm trying to use the functions defined on my queue
class inside some llvm-ir code. Unfortunately, the names of the functions
are being messed up, then I created some function wrappers just to avoid
having to deal with the C++ weird function renaming.

So, to easily wrapper the class, I wrote a queue_wrapper.h library, which,
basically, has the following code (where Q is a reference to my queue, and
the channel is not really important):

*extern "C" { *

*#ifdef INT_TYPE*

*  void __attribute__((noinline))*

*  TYPED_NAME(produceValue)(int channel, TYPE elem)*

*  {Q->addElement (channel, (long)elem);}*


*  TYPE __attribute__((noinline))*

*  TYPED_NAME(consumeValue)(int channel)*

*  {return (TYPE) Q->removeElement (channel);}*



*  void __attribute__((noinline))*

*  TYPED_NAME(producePtrValue)(int channel, TYPE* elem)*

*  {Q->addPtrElement (channel, (void*)elem);}*


*  TYPE* __attribute__((noinline))*

*  TYPED_NAME(consumePtrValue)(int channel)*

*  {return (TYPE*) Q->removePtrElement (channel);}*

*  *

*#ifdef FP_TYPE*

*  void __attribute__((noinline))*

*  TYPED_NAME(produceFPValue)(int channel, TYPE elem)*

*  {Q->addFPElement (channel, (double)elem);}*


*  TYPE __attribute__((noinline))*

*  TYPED_NAME(consumeFPValue)(int channel)*

*  {return (TYPE) Q->removeFPElement (channel);}*



In order to define a set of functions for a type, I can simply insert the
following lines on my original library:

*#define INT_TYPE*

*#define TYPE char*

*#define TYPED_NAME(x) i8_##x*

*#include "queue_wrappers.h"*

*#undef TYPE*

*#undef TYPED_NAME*

*#undef INT_TYPE*

And, for this example, the functions i8_produceValue, i8_consumeValue,
i8_producePtrValue and i8_consumePtrValue should be defined.

Well, the problem is that all those functions are being defined, indeed,
but every function inside the #ifdef INT_TYPE's preprocessor flag has only
a call to llvm.trap() function inside its body =/

And this is only happening to the functions (*)_consumeValue and
(*)_produceValue: all the other functions [(*)_consumePtrValue,
(*)_producePtrValue, (*)_consumeFPValue and (*)_produceFPValue] has their
bodies correctly defined on the resultant bc file.

Since the only difference between their implementation on the queue is the
type defined inside the queue (long for integer types, void* for pointers
and double for floating point numbers), does anyone have any ideia why I am
having this issue with integers?

PS: I tried to implement the integer type functions using C++ templates,
and it was as I expected: the functions for integer types were created with
their correct set of instructions inside. However, when using templates,
the names of the functions are being messed up (which was the issue I was
trying to avoid in the first place).

Thanks in advance,

Cristianno Martins
PhD Student of Computer Science
University of Campinas
cmartins at ic.unicamp.br
 <cristiannomartins at hotmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130514/4bf331f5/attachment.html>

More information about the llvm-dev mailing list