IBM XL compiler suite reference card

Note: For compilers, _r-suffix ones are to compile threaded (re-entrant) and OpenMP programs.

xlc
gxlc
C compiler.

gxlc will accept GNU C compiler options.

xlc++
xlC
gxlc++
gxlC
C++ compiler.

gxlc++/gxlC will accept GNU C++ compiler options.

xlf
xlf90
xlf95
Fortran compiler.
mpxlc
mpxlC
mpxlf
mpxlf90
Like above compilers, but will automatically links with the MPI and LAPI libraries.

Now the compiler...

Compile

-cCompile *.c and assemble *.s. NO linking.
-IdirAlso search dir for header files.

This can also be controlled by environmental variables C_INCLUDE_PATH and CPLUS_INCLUDE_PATH.

-SCompile *.c into assembly codes *.s. NO linking.
-ERun preprocessor only. The output is sent to stdout.
-CWhen running preprocessor, don't discard comments in the program.
-qshowmacros=preDisplay definitions of built-in macros
-o filePlace output in file
-v
-V
When compiling, also display the programs invoked by the compiler.
-#Like -v, but do NOT invoke the programs.
-qphsinfo When compiling, display what functions it's compiling and time/memory used in preprocessing/parsing etc.
-qversionPrint the version number.
-BprefixSearch prefix for IBM XL Compiler executables.
-qpath=prog=pathSearch path for IBM XL Compiler executable prog, where prog can be a (assembler), l (linker) ...

C/C++ dialect

-qlanglvl=sDetermine the language standard. s can be classic, extended (this is default for C), stdc89, stdc99, extc89 (this is default for C++), extc99 ...
-qsmpEnable OpenMP.

To use this option , one must invoke the compiler with one of the _r-suffix variations of the compiler name.

__IBMSMP__ will be defined.

-qchars=signed
-qchars=unsigned
Whether by default char is signed or unsigned.

__CHAR_SIGNED__ or __CHAR_UNSIGNED__ will be defined.

-qkeyword=asm
-qasm=gcc
Support GCC inline assembly.
-qtlsSupport the thread-local storage keyword __thread.

Preprocessor

-Dname
-Dname=value
Predefine the macro name, with value 1, or with the specified value
-UnameUn-define the (built-in or -D defined) macro name
-M
-qnakedep=gcc
Output a rule (to stdout) suitable for Makefile describing the dependencies of the source file.
-MF fileThe output of -M is written to file.

Warning messages

-qinfo=allEnable all information and warnings.
-wSuppress all warnings.
-qmaxerr=numStop after first num errors.

Link

-LdirAlso search dir for library files. This can also be controlled by environmental variable LIBRARY_PATH.
-llibraryLink to liblibrary

The linker searches libraries and object files in the order they are specified, so

  foo.o -lz bar.o
  
will search library z after file foo.o but before bar.o, so if bar.o refers to functions in z, then -lz must appear AFTER bar.o
-sRemove all symbol information from the executable

-qstaticlinkProduce statically linked executables.

-qstaticlink=libgccLink to libgcc statically.
-qmkshrobj Produce shared libraries.
-qnocrtDon't link to the standard startup files.

-qnolibDon't link to the standard system libraries.

Debugging & Profiling

-gProduce debugging information.
-pgProduce profiling information for gprof.
-qoptdebugProduce useful debugging information when optimization options are in effect.
-qfullpathStore full path information when used with -g option.
-qlinedebugStore line number and source file information when used with -g option.
-qheapdebugEnable debug versions of memory management functions.
-qcheck=opt1:opt2 ..Generate code to perform various runtime checks.

opt can be all, bounds, divzero, nullptr.

-qfunctrace
-qfunctrace=fun
Enable tracing for a specific list of functions fun (a colon-separate list of symbol names.)

The user will need to implement the following two functions: __func_trace_enter and __func_trace_exit.

Optimization

-O0Don't optimize. This is default.
-O2
-O
Optimize.

__OPTIMIZE__ will be defined.

-O3Optimize more.

This level of optimization has the potential to alter the semantics of the program.

-O4Optimize yet more.

It will also optimize for architecture of the compiling machine (-qarch, -qtune, -qcache), perform link time/inter-procedural optimization (-qipa) and high-order transformation loop optimization (-qhot)

-O5The same as -O4 -qipa=level=2
-qreportShow diagnostic information about automatic loop parallelization and other optimizations during compilation.
-qcompactOptimize for code size.

__OPTIMIZE_SIZE__ will be defined.

-qstrict
-qstrict=opt1:opt2 ..
Disable optimizations which have the potential to alter the semantics of the program.

opt can be all, precision, exception, ieeefp, nans, infinities, subnormals, zerosigns, operationprecision, vectorprecision, order, association, reductionorder, guards, library, constructcopy

-Q
-qinline
Inline all functions that it can.
-qpdf1
-qpdf2
-qfdpr
Profile guided optimization (PGO).

FDPR is Feedback Directed Program Restructuring performance-tuning utility needs to optimize the resulting executable.

-qipaLink time/inter-procedural optimization.
-qhotHigh-order transformation loop optimization.
-qsmpAutomatic parallelization.

To use this option , one must invoke the compiler with one of the _r-suffix variations of the compiler name.

__IBMSMP__ will be defined.

-qarch=cpu
-qarch=auto
Generate code for specific cpu, , e.g. ppc, ppc64, ppc970, pwr3, pwr4, pwr5, pwr6 ..
-qtune=cpu
-qtune=auto
Tune for specific cpu, e.g. ppc970, pwr3, pwr4, pwr5, pwr6 ..
-q64Generate 64-bit code.

__64BIT__ will be defined.

-qaltivecGenerate code using AltiVec SIMD extensions.

__ALTIVEC__ will be defined.

-qsimd=auto(Fortran) Generate code using SIMD extensions/vector instructions.
-qflttrap=opt1:opt2 ..Generate code to detect floating-point exceptions at runtime.

opt can be enable, overflow, underflow, zerodivide, invalid, inexact, imprecise, nanq, nonanq.

-qfloat=opt1:opt2 ..Generate code for various floating-point calculation strategies.

opt can be fltint (floating-point-to-integer conversions with faster inline code that does not check for overflows), fold (constant floating-point expressions are to be evaluated at compile time), maf (fused multiply/add), nan (detect NaN), relax (less conformance with the IEEE 754 standard)...

-qieee=mode(Fortran) Specify the rounding mode, which can be Near, Minus, Plus, Zero.
-qessl(Fortran) Use IBM's Engineering and Scientific Subroutine Library (ESSL) routines in place of Fortran 90 intrinsic procedures.
-qlargepageOptimize for the huge page support on POWER4 and higher systems.

Interesting features

-qsaveoptSave compiler version number and compiler options in the binary executable.

IBM XL C/C++ Compiler built-in macros

One can use
cc -qshowmacros -E foo.c
to see all built-in macros and their values.

__cplusplus Is defined if C++ compiler is in use.

This is ANSI C standard macro

__FILE__
__BASE_FILE__
Name of the current input file (as a C string constant)

This is ANSI C standard macro.

__LINE__ Current input line number (as an integer constant)

This is ANSI C standard macro

__FUNCTION__ If inside a function, the current function name (as a C string constant)

This is ANSI C99 standard macro

__DATE__
__TIME__
Date & time on which the preprocessor is run. (as C string constants)

These are ANSI C standard macros.

__TIMESTAMP__ Last modification time of the input file (as a C string constant)
__STDC__
__STDC_VERSION__
Evaluate to 1 to mean the compiler is ISO standard conformant.

__STDC_VERSION__ evaluates to a C string constant of the form of the form yyyymmL.

__STDC__ is an ANSI C standard macro.

__IBMC__
__IBMCPP__
Evaluate to integer constants representing the IBM XL C/C++ compiler version numbers (version/release/modification), e.g. version 10.1 will evaluate to 1010.
__xlc__
__xlC__
Evaluate to a C string constant representing the IBM XL C/C++ compiler version numbers (version/release/modification), e.g. version 10.1 will evaluate to 10.1.0.0.
__BIG_ENDIAN__ Evaluate to 1 to indicate the endian-ness
__powerpc__
__PPC__
Evaluate to 1 to indicate the architecture
__ALTIVEC__
__VEC__
Defined if -qaltivec option is enabled.
__64BIT__ Defined if 64-bit compilation mode is in effect.
__OPTIMIZE__
__OPTIMIZE_SIZE__
Defined if any optimization is enabled.

Furthermore, __OPTIMIZE_SIZE__ is defined if the optimization is for size.

__IBMSMP__
_IBMSMP
Defined if -qsmp option is enabled.

IBM XL C/C++ Compiler built-in functions

A complete list is here

__builtin_expect Provide branch prediction hint to the compiler.
__compare_and_swap
__compare_and_swaplp
__fetch_and_XXX
__fetch_and_XXXlp
__ldarx
__lwarx
__stdcx
__stwcx
Built-in atomic memory access functions.

XXX can be and, or, swap.

__dcbf
__dcbfl
Flush cache of the given memory region.
__prefetch_by_load
__prefetch_by_stream
Prefetch data in the given memory region.
__builtin_return_address(lvl) Get the address of the caller at call chain level lvl.

IBM XL C/C++ Compiler #pragma directives

A complete list is here

#pragma init Declare the designated function to be called before main is invoked.
#pragma fini Declare the designated function to be called after exit is invoked.