Spectral LLVM C++ family language features

Introduction

This page describes the general C++-family language enhancements that have been made to Clang compared to upstream. In addition, we have created the SCALE language, which is an enhanced programming language that is compatible with the CUDA programming language.

Attributes

[[clang::loop_unroll]]

Like #pragma unroll, but as a C++11 attribute so that it can receive template arguments. Unrolling can be set to a specific degree (e.g: 4) using [[clang::loop_unroll(4)]]. Unrolling can be disabled with [[clang::loop_unroll(0)]]. Full loop unrolling can be enabled with [[clang::loop_unroll(-1)]].

__attribute__((unique_inline))

This attribute directs the compiler to inline a single instance of a function into the caller and use it for all calls to the function. This means a large function can be inlined, and so benefit from knowledge of how it’s used, without generating multiple copies of a large amount of code.

Intrinsics and functions

__builtin_provable

The __builtin_provable(cond) compiler intrinsic is 1 if the compiler is able to prove cond (sufficiently early), and 0 otherwise. This is useful, for example, to optimize inlined function calls with knowledge of the call’s arguments without having to specify them as template arguments. For example:

void doSomething(int arg)
{
    if (__builtin_provable(arg < 4)) {
        fastPath();
        return;
    }
    slowPath();
}

void callSomething()
{
     doSomething(2); // If doSomething() inlines, it calls fastPath().
}

__byte_perm and __nvvm_prmt

The __nvvm_prmt intrinsic and the function, __byte_perm, that uses it are constexpr.

Bit-counting functions

The default-included bit-counting functions __brev, __clz, __popc and their *ll counterparts are constexpr.