[LLVMdev] Type operator defenition

Kasra kasra_n500 at yahoo.com
Wed Apr 1 13:54:47 PDT 2009


When I was poking arround my llvm code, I realised that given a Type
there isn't a seperate container for the type operator functions.
Am I correct?

If so, wouldn't it make more sence to provide a container to put 
the objects operator function in to reduce the overhead of 
going through each non operator function to find the operator
function defined for it??

The reason for this seperate container is because most of languages
defined operators to manipulate objects. 

For example each time there is an expression:
  class int_t : some_custom_interger ;
  int_t a, b;
  a + b

we have to do : O(n)
  const Type* ta = typeof("a");
  for (int i=0, e=ta->getNumContainedTypes(); i<e; i++)
      if( isa<Function>(*ta->getContainedType(i)) )
        if( ta->getName() == "$operator +" )
          call(function, valueof("a"), valueof("b") );

where else we could do something like: O(1)
  enum { operator_add = 0, ... } ;
  call( typeof("a")->operator[operator_add], 
       valueof("a"), valueof("b"));

With best regards,
-- Kasra


More information about the llvm-dev mailing list