Introduction to CCE Clang

Describing CCE Clang and its components

CCE Clang supports compiling the C, C++, and UPC languages and the OpenMP parallel programming model for targets available on supported systems. Using this compiler for other languages, models, or targets is not supported; any documentation related to such features is provided as-is for reference purposes only.

Beta support for HIP language is provided in this release.

Invoking Clang

The CCE Clang C and C++ compilers should be invoked via cc and CC as usual. This will set the target based on the loaded craype-arch module and link with the usual Cray libraries, including the Cray-optimized math functions, memcpy, and OpenMP runtime. Use of the native clang or clang++ commands is discouraged, as doing so may not find necessary paths and will not link automatically with Cray libraries.

To invoke Clang:

For C programs
cc [options] [filename] ...
For C++ programs
CC [options] [filename] ...
For UPC programs
cc -hupc [options] [filename] ...
For HIP programs
CC [options] -x hip [filename] ...

Compilation Stages

clang is a C, C++, and Objective-C compiler that encompasses preprocessing, parsing, optimization, code generation, assembly, and linking. Depending on which high-level mode setting is passed, Clang will stop before doing a full link. While Clang is highly integrated, it is important to understand the stages of compilation, to understand how to invoke it. These stages are:

Driver
The clang executable is actually a small driver that controls the overall execution of other tools such as the compiler, assembler and linker. Typically you do not need to interact with the driver, but you transparently use it to run the other tools.
Preprocessing
This stage handles tokenization of the input source file, macro expansion, #include expansion and handling of other preprocessor directives. The output of this stage is typically called a ".i" (for C), ".ii" (for C++), ".mi" (for Objective-C), or ".mii" (for Objective-C++) file.
Parsing and Semantic Analysis
This stage parses the input file, translating preprocessor tokens into a parse tree. Once in the form of a parse tree, it applies semantic analysis to compute types for expressions as well and determine whether the code is well formed. This stage is responsible for generating most of the compiler warnings as well as parse errors. The output of this stage is an "Abstract Syntax Tree" (AST).
Code Generation and Optimization
This stage translates an AST into low-level intermediate code (known as "LLVM IR") and ultimately to machine code. This phase is responsible for optimizing the generated code and handling target-specific code generation. The output of this stage is typically called a ".s" file or "assembly" file.
Clang also supports the use of an integrated assembler, in which the code generator produces object files directly. This avoids the overhead of generating the ".s" file and of calling the target assembler.
Assembler
This stage runs the target assembler to translate the output of the compiler into a target object file. The output of this stage is typically called a ".o" file or "object" file.
Linker
This stage runs the target linker to merge multiple object files into an executable or dynamic library. The output of this stage is typically called an "a.out", ".dylib" or ".so" file.
Static Analyzer
The Clang Static Analyzer is a tool that scans source code to try to find bugs through code analysis. This tool uses many parts of Clang and is built into the same driver. Please see https://clang-analyzer.llvm.org for more details on how to use the static analyzer.