[llvm-dev] Attribute for a invariant function ?

Johannes Doerfert via llvm-dev llvm-dev at lists.llvm.org
Sat Jan 9 10:34:57 PST 2016


Try:
  extern void  *lookup( int a) __attribute__ ((const));

Cheers,
  Johannes

On 01/09, Nat! via llvm-dev wrote:
> I have a read-only lookup table, which takes integer arguments. Optimally I
> would like to indicate in the C source, that the function is invariant (?),
> so that the superflous calls can be optimized away.
> 
> ```
> extern void  *lookup( int a);
> 
> void   foo( void)
> {
>    void   *a, *b;
> 
>    a = lookup( 0x12345678);
>    bar( a);
> 
>    b = lookup( 0x12345678);  // b guaranteed to be the same as a, no call to
> (slow) lookup needed
>    baz( b);
> }
> ```
> 
> But I don't really find anything in clang or llvm in terms of function
> attributes. The best I could come up with is in the llvm code to use
> attributes "argmemonly=true" readonly=true". But still two calls did happen.
> (I am on 3.7)
> 
> Ciao
>    Nat!
> 

> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


-- 

Johannes Doerfert
Researcher / PhD Student

Compiler Design Lab (Prof. Hack)
Saarland University, Computer Science
Building E1.3, Room 4.31

Tel. +49 (0)681 302-57521 : doerfert at cs.uni-saarland.de
Fax. +49 (0)681 302-3065  : http://www.cdl.uni-saarland.de/people/doerfert
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 213 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160109/62e8b126/attachment.sig>


More information about the llvm-dev mailing list