For example, consider the line of code if cond foo ; else bar ;. But both calls to foo and bar are at the same source line, so a sample count at that line is not sufficient. The compiler needs to know which part of that line is taken more frequently. This is what discriminators provide. In this case, the calls to foo and bar will be at the same line, but will have different discriminator values. This allows the compiler to correctly set edge weights into foo and bar. Number of samples.
This is an integer quantity representing the number of samples collected by the profiler at this source location. If present, this line contains a call instruction. This models both direct and number of samples. For example,. The above means that at relative line offset there is a call instruction that calls one of foo , bar and baz , with baz being the relatively more frequently called target. When built with optimizations enabled, the compiler may inline the calls to bar and foo inside main.
The generated profile could then be something like this:. This profile indicates that there were a total of 35, samples collected in main.
All of those were at line 1 the call to foo. Of those, 31, were spent inside the body of bar. The last line of the profile 2: 0 corresponds to line 2 inside main. No samples were collected there. Clang also supports profiling via instrumentation.
This requires building a special instrumented version of the code and has some runtime overhead during the profiling, but it provides more detailed results than a sampling profiler. It also provides reproducible results, at least to the extent that the code behaves consistently across runs.
Build an instrumented version of the code by compiling and linking with the -fprofile-instr-generate option. Run the instrumented executable with inputs that reflect the typical usage. By default, the profile data will be written to a default. If non-default file name is specified by both the environment variable and the command line option, the environment variable takes precedence. Additionally, multiple raw profiles dumped from different processes that share a file system can be on different hosts will be automatically merged by the profiler runtime during the dumping.
If the program links in multiple instrumented shared libraries, each library will dump the profile data into its own profile data file with its unique integer id embedded in the profile name. Use the merge command of the llvm-profdata tool to do this. Build the code again using the -fprofile-instr-use option to specify the collected profile data.
You can repeat step 4 as often as you like without regenerating the profile. As you make changes to your code, clang may no longer be able to use the profile data. It will warn you when this happens.
Profile generation using an alternative instrumentation method can be controlled by the GCC-compatible flags -fprofile-generate and -fprofile-use. Although these flags are semantically equivalent to their GCC counterparts, they do not handle GCC-compatible profiles. Flag -fcs-profile-generate also instruments programs using the same instrumentation method as -fprofile-generate. If dirname does not exist, it will be created at runtime.
To generate the profile data file with the compiler readable format, the llvm-profdata tool can be used with the profile directory as the input:. The difference is that the instrumentation is performed after inlining so that the resulted profile has a better context sensitive information. They are typically used in conjunction with -fprofile-use flag. The profile generated by -fcs-profile-generate and -fprofile-generate can be merged by llvm-profdata.
A use example:. The first few steps are the same as that in -fprofile-generate compilation. Then perform a second round of instrumentation. The above command will read both profiles to the compiler at the identical point of instrumentations. Without any other arguments, -fprofile-use behaves identically to -fprofile-instr-use. Otherwise, if pathname is the full path to a profile file, it reads from that file. The counters can be inaccurate under thread contention. This option currently works with -fprofile-arcs and -fprofile-instr-generate , but not with -fprofile-generate.
In certain situations, it may be useful to disable profile generation or use for specific files in a build, without affecting the main compilation flags used for the other files in the project. In these cases, you can use the flag -fno-profile-instr-generate or -fno-profile-generate to disable profile generation, and -fno-profile-instr-use or -fno-profile-use to disable profile use.
When none of the translation units inside a binary is instrumented, in the case of Fuchsia the profile runtime will not be linked into the binary and no profile will be produced, while on other platforms the profile runtime will be linked and profile will be produced but there will not be any counters.
For example in automated testing infrastructure, it may be desirable to only instrument files or functions that were modified by a patch to reduce the overhead of instrumenting a full system. This can be done using the -fprofile-list option. This option can be used to apply profile instrumentation only to selected files or functions. To exclude a function or a source file, use! The format also supports wildcard expansion.
The compiler generated functions are assumed to be located in the main source file. It is also possible to restrict the filter to a particular instrumentation type by using a named section. When the file contains only excludes, all files and functions except for the excluded ones will be instrumented.
Otherwise, only the files and functions specified will be instrumented. When the program is compiled after a change that affects many symbol names, pre-existing profile data may no longer match the program.
Clang allows use of a profile remapping file to specify that such differences in mangled names should be ignored when matching the profile data against the program.
Specifies a file containing profile remapping information, that will be used to match mangled names in the profile data to mangled names in the program. Blank lines and lines starting with are ignored. Matching profile data using a profile remapping file is supported on a best-effort basis.
For example, information regarding indirect call targets is currently not remapped. For best results, you are encouraged to generate new profile data matching the updated program, or to remap the profile data using the llvm-cxxmap and llvm-profdata merge tools. GCOV is a test coverage program, it helps to know how often a line of code is executed. When instrumenting the code with --coverage option, some counters are added for each edge linking basic blocks.
At compile time, gcno files are generated containing information about blocks and edges between them. At runtime the counters are incremented and at exit the counters are dumped in gcda files. The tool llvm-cov gcov will parse gcno, gcda and source files to generate a report.
Define a list of regexes separated by a semi-colon. If a file name matches any of the regexes then the file is instrumented. For example, this will only instrument files finishing with. Debug info kind generated by Clang can be set by one of the flags listed below. If multiple flags are present, the last one is used. This kind of debug info allows to obtain stack traces with function names, file names and line numbers by such tools as gdb or addr2line.
Clang supports a number of optimizations to reduce the size of debug information in the binary. They work based on the assumption that the debug type information can be spread out over multiple compilation units. For instance, Clang will not emit type definitions for types that are not needed by a module and could be replaced with a forward declaration.
The -fstandalone-debug option turns off these optimizations. Note that Clang will never emit type information for types that are not referenced at all by the program. On Darwin -fstandalone-debug is enabled by default. The -fno-standalone-debug option can be used to get to turn on the vtable-based optimization described above. This optimization is similar to the optimizations that are enabled as part of -fno-standalone-debug.
This relies on the additional assumption that all classes that are not trivially constructible have a non-trivial constructor that is used somewhere. The negation, -fno-use-ctor-homing, ensures that constructor homing is not used. By default, Clang does not emit type information for types that are defined but not used in a program. To retain the debug info for these unused types, the negation -fno-eliminate-unused-debug-types can be used.
Debug info for C preprocessor macros increases the size of debug information in the binary. Macro debug info generated by Clang can be controlled by the flags listed below. Generate debug info for preprocessor macros. This flag is discarded when -g0 is enabled. Each of these options implies -g. Therefore, if you want both -gline-tables-only and debugger tuning, the tuning option must come first.
By default, value names are only emitted in assertion-enabled builds of Clang. However, when reading IR it can be useful to re-enable the emission of value names to improve readability. This option can be used to re-enable names for release builds of Clang.
Clang parses Doxygen and non-Doxygen style documentation comments and attaches them to the appropriate declaration nodes. Define custom documentation commands as block commands. This allows Clang to construct the correct AST for these custom commands, and silences warnings about unknown commands.
Several commands must be separated by a comma without trailing space ; e. It is also possible to use -fcomment-block-commands several times; e. The support for standard C in clang is feature-complete except for the C99 floating-point pragmas. See Clang Language Extensions. The supported modes for C are c89, gnu89, c94, c99, gnu99, c11, gnu11, c17, gnu17, c2x, gnu2x, and various aliases for those modes. If no -std option is specified, clang defaults to gnu17 mode.
Many C99 and C11 features are supported in earlier modes as a conforming extension, with a warning. Use -pedantic-errors to request an error if a feature from a later standard revision is used in an earlier mode.
Support for general global register variables is unlikely to be implemented soon because it requires additional LLVM backend support. This appears to be a rarely used extension, but could be implemented pending user demand. This is used rarely, but in some potentially interesting places, like the glibc headers, so it may be implemented pending user demand.
Note that because clang pretends to be like GCC 4. This is not a complete list; if you find an unsupported extension missing from this list, please send an e-mail to cfe-dev. Also, this list does not include bugs in mostly-implemented features; please see the bug tracker for known existing bugs FIXME: Is there a section for bug-reporting guidelines somewhere?
To enable these extensions, use the -fms-extensions command-line option. This is the default for Windows targets. For example, it allows unqualified lookup of dependent base class members , which is a common compatibility issue with clang.
This flag is enabled by default for Windows targets. It accepts a dotted version tuple, such as Sets the limit for the number of full-expressions evaluated in a single constant expression evaluation. The default is Clang supports all OpenMP 4. See OpenMP Support for additional details. Use -fopenmp to enable OpenMP. Support for OpenMP can be disabled with -fno-openmp. Use -fopenmp-simd to enable OpenMP simd features only, without linking the runtime library; for combined constructs e.
This can be disabled with -fno-openmp-simd. Controls code generation for OpenMP threadprivate variables. In presence of this option all threadprivate variables are generated the same way as thread local variables, using TLS support.
If -fno-openmp-use-tls is provided or target does not support TLS, code generation for threadprivate variables relies on OpenMP runtime library. Clang can be used to compile OpenCL kernels for execution on a device e. It is possible to compile the kernel into a binary e.
Compiling for a specific target can be done by specifying the triple corresponding to the target, for example:. This will produce a file test. Clang currently supports OpenCL C language standards up to v2. Clang mainly supports full profile. There is only very limited support of the embedded profile. There is ongoing support for OpenCL v3. Most of the OpenCL build options from the specification v2.
Allows to disable all extra types and functions that are not native to the compiler. This might reduce the compilation speed marginally but many declarations from the OpenCL standard will not be accessible. For example, the following will fail to compile.
More information about the standard types and functions is provided in the section on the OpenCL Header. OpenCL targets are derived from the regular Clang target classes. The OpenCL specific parts of the target representation provide address space mapping as well as a set of supported extensions.
SPIR is available as a generic target to allow portable bitcode to be produced that can be used across GPU toolchains. The implementation follows the SPIR specification. There are two flavors available for 32 and 64 bits. Clang will generate SPIR v1. For this, a 3rd party toolchain, such as for example POCL , can be used. This target does not support multiple memory segments and, therefore, the fake address space map can be added using the -ffake-address-space-map flag.
By default Clang will include standard headers and therefore most of OpenCL builtin functions and types are available during compilation. The default declarations of non-native compiler types and functions can be disabled by using flag -cl-no-stdinc. The following example demonstrates that OpenCL kernel sources with various standard builtin functions can be compiled without the need for an explicit includes or compiler flags.
More information about the default headers is provided in OpenCL Support. It is possible to alter the default extensions setting per target using -cl-ext flag. See flags description for more details.
Vendor extensions can be added flexibly by declaring the list of types and functions associated with each extensions enclosed within the following compiler pragma directives:. There is no conflict resolution for identifier clashes among extensions. It is therefore recommended that the identifiers are prefixed with a double underscore to avoid clashing with user space identifiers.
Vendor extension should use reserved identifier prefix e. OpenCL support in Clang contains a set of attribute taken directly from the specification as well as additional attributes. See also Attributes in Clang. Clang supports this attribute to comply to OpenCL v2.
For more details reffer to the specification section 6. The implementation of this feature mirrors the unroll hint for C. More details on the syntax can be found in the specification section 6.
Using convergent guarantees correct execution by keeping CFG equivalence wrt operations marked as convergent. This allows some optimizations to happen as long as the control flow remains unmodified. Alternatively, files with. Global objects with non-trivial constructors require the constructors to be run before the first kernel using the global objects is executed.
Similarly global objects with non-trivial destructors require destructor invocation just after the last kernel using the program objects is executed. In OpenCL versions earlier than v2.
This kernel is only present if there are global objects with non-trivial constructors present in the compiled binary. Note that if multiple files are compiled and linked into libraries, multiple kernels that initialize global objects for multiple modules would have to be invoked. Applications are currently required to run initialization of global objects manually before running any kernels in which the objects are used.
Note that the manual workaround only applies to objects declared at the program scope. There is no manual workaround for the construction of static objects with non-trivial constructors inside functions. Global destructors can not be invoked manually in the OpenCL v2.
However, all memory used for program scope objects should be released on clReleaseProgram. For the X86 target, clang supports the -m16 command line argument which enables bit code output. This is broadly similar to using asm ". The generated code and the ABI remains bit but the assembler emits instructions appropriate for a CPU running in bit mode, with address-size and operand-size prefixes to enable bit addressing and operations. Several micro-architecture levels as specified by the x psABI are defined.
They are cumulative in the sense that features from previous levels are implicitly included in later levels. Clang only supports a limited number of ARM architectures. It does not yet fully support ARMv5, for example. PowerPC 32bit is still missing certain features e. Other platforms are completely unsupported at the moment. Generating assembly requires a suitable LLVM backend. See also Microsoft Extensions. This directory layout is standard for any toolchain you will find on the official MinGW-w64 website.
To enable clang-cl to find system headers, libraries, and the linker when run from the command-line, it should be executed inside a Visual Studio Native Tools Command Prompt or a regular Command Prompt where the environment has been set up using e. The toolset is not part of the installer, but may be installed separately from the Visual Studio Marketplace. Doing so enables an additional Property Page for selecting the clang-cl executable to use for builds.
To use the toolset with MSBuild directly, invoke it with e. This allows trying out the clang-cl toolchain without modifying your project files. To be compatible with cl. Options that are known to clang-cl, but not currently supported, are ignored with a warning.
To suppress warnings about unused arguments, use the -Qunused-arguments option. Options that are not known to clang-cl will be ignored by default. Please file a bug for any valid cl. This mechanism allows you to pass flags that are not exposed in the clang-cl options or flags that have a different meaning when passed to the clang driver.
This causes the class-level dllexport and dllimport attributes to not apply to inline member functions, as they otherwise would. Since the function declaration comes with an inline definition, users of the library can use that definition directly instead of importing it from the DLL. The flag does not apply to explicit class template instantiation definitions or declarations, as those are typically used to explicitly provide a single definition in a DLL, dllexported instantiation definition or to signal that the definition is available elsewhere dllimport instantiation declaration.
Note, the -cc1 argument indicates the compiler front-end, and not the driver, should be run. The compiler front-end has several additional Clang specific features which are not exposed through the GCC compatible driver interface. Quick Links Testing Coverage. Getting Started: Building and Running Clang This page gives you the shortest path to checking out Clang and demos a few options. Building Clang and Working with the Code On Unix-like Systems If you would like to check out and build Clang, the current procedure is as follows: Get the required tools.
Note also that Python is needed for running the test suite. It can be made faster by creating a shallow clone. Shallow clone saves storage and speeds up the checkout time. Note: For subsequent Clang development, you can just run make clang. Source code control program. This is used for generating Visual Studio solution and project files.
It is used to run the clang test suite. Referenced by clang::ImplicitCallPoint::getLocation. Turn a raw encoding of a SourceLocation object into a real SourceLocation. References clang::tooling::X.
Definition at line 53 of file SourceLocation. Return a source location with the specified offset from this SourceLocation. When a SourceLocation itself cannot be used, this returns an opaque pointer encoding for it. This should only be passed to SourceLocation::getFromPtrEncoding , it should not be inspected directly.
References getRawEncoding. When a SourceLocation itself cannot be used, this returns an opaque bit integer encoding for it. This should only be passed to SourceLocation::getFromRawEncoding , it should not be inspected directly. Return true if this is a valid SourceLocation object.
0コメント