13-Jan-2009

C compiler optimization tricks

On Alpha and IA64 versions of OpenVMS, you can assist the C compiler in producing better optimized code by using various compiler and programming options.

One of the easiest options to use is a compiler qualifier called /PLUS_LIST_OPTIMIZE. If you have a list of various C modules, you may have developed them by the usual method of compiling each individually, and then linking them together. For example, you might do:


$ CC FOO.C
$ CC BAR.C
$ CC BAZ.C
$ LINK FOO,BAR,BAZ

However, if you use the /PLUS_LIST_OPTIMIZE qualifier, the compiler may be able to make optimizations (such as inlining code, or reordering code based on cross module side effects) that it can't make if you compile each module separately. Use it like so:


$ CC/PLUS_LIST_OPTIMIZE FOO+BAR+BAZ
$ LINK FOO

If your code is only to run on a specific version of architecture (in particular, a specific class of Alpha chip), you should investigate the /ARCHITECTURE qualifier.

Getting a little more complex, you can use the #pragma assert func_attrs directive in your code to tell the compiler various things about functions. For example, if a function never accesses file scoped variables, you can indicate this with the appropriate pragma directive. These directives can significantly assist the compiler to produce better code. For more information about this directive see the relevant section of the C User's Guide.

Posted at January 13, 2009 10:39 AM
Tag Set:

Comments are closed