Skip to content

Commit

Permalink
Upgrade to clang-format 13 (#6689)
Browse files Browse the repository at this point in the history
Goal here: eliminate the need for a local version of llvm/clang-12, and don't stay too far behind the toolchain.

As always, clang-format doesn't promise backwards compatibility, but the main differences in formatting are:
- more regularization of spaces at the start of comments (I like this change)
- minor difference of formatting of function-pointer-type declarations (not a fan of this, but I can't find a way to disable it and it's only really used in a handful of place in the Python bindings)
  • Loading branch information
steven-johnson authored Apr 8, 2022
1 parent b5840f7 commit 887d340
Show file tree
Hide file tree
Showing 52 changed files with 272 additions and 274 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: DoozyX/clang-format-lint-action@v0.12
- uses: DoozyX/clang-format-lint-action@v0.13
with:
source: '.'
extensions: 'h,c,cpp'
clangFormatVersion: 12
clangFormatVersion: 13
check_clang_tidy:
name: Check clang-tidy
runs-on: ubuntu-20.04
Expand Down
30 changes: 15 additions & 15 deletions python_bindings/src/PyBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,23 +363,23 @@ void define_buffer(py::module &m) {
.def("set_name", &Buffer<>::set_name)
.def("name", &Buffer<>::name)

.def("same_as", (bool (Buffer<>::*)(const Buffer<> &other) const) & Buffer<>::same_as, py::arg("other"))
.def("same_as", (bool(Buffer<>::*)(const Buffer<> &other) const) & Buffer<>::same_as, py::arg("other"))
.def("defined", &Buffer<>::defined)

.def("type", &Buffer<>::type)
.def("channels", (int (Buffer<>::*)() const) & Buffer<>::channels)
.def("dimensions", (int (Buffer<>::*)() const) & Buffer<>::dimensions)
.def("width", (int (Buffer<>::*)() const) & Buffer<>::width)
.def("height", (int (Buffer<>::*)() const) & Buffer<>::height)
.def("top", (int (Buffer<>::*)() const) & Buffer<>::top)
.def("bottom", (int (Buffer<>::*)() const) & Buffer<>::bottom)
.def("left", (int (Buffer<>::*)() const) & Buffer<>::left)
.def("right", (int (Buffer<>::*)() const) & Buffer<>::right)
.def("channels", (int(Buffer<>::*)() const) & Buffer<>::channels)
.def("dimensions", (int(Buffer<>::*)() const) & Buffer<>::dimensions)
.def("width", (int(Buffer<>::*)() const) & Buffer<>::width)
.def("height", (int(Buffer<>::*)() const) & Buffer<>::height)
.def("top", (int(Buffer<>::*)() const) & Buffer<>::top)
.def("bottom", (int(Buffer<>::*)() const) & Buffer<>::bottom)
.def("left", (int(Buffer<>::*)() const) & Buffer<>::left)
.def("right", (int(Buffer<>::*)() const) & Buffer<>::right)
.def("number_of_elements", (size_t(Buffer<>::*)() const) & Buffer<>::number_of_elements)
.def("size_in_bytes", (size_t(Buffer<>::*)() const) & Buffer<>::size_in_bytes)
.def("has_device_allocation", (bool (Buffer<>::*)() const) & Buffer<>::has_device_allocation)
.def("host_dirty", (bool (Buffer<>::*)() const) & Buffer<>::host_dirty)
.def("device_dirty", (bool (Buffer<>::*)() const) & Buffer<>::device_dirty)
.def("has_device_allocation", (bool(Buffer<>::*)() const) & Buffer<>::has_device_allocation)
.def("host_dirty", (bool(Buffer<>::*)() const) & Buffer<>::host_dirty)
.def("device_dirty", (bool(Buffer<>::*)() const) & Buffer<>::device_dirty)

.def(
"set_host_dirty", [](Buffer<> &b, bool dirty) -> void {
Expand All @@ -395,13 +395,13 @@ void define_buffer(py::module &m) {
.def("copy", &Buffer<>::copy)
.def("copy_from", &Buffer<>::copy_from<void, Buffer<>::AnyDims>)

.def("add_dimension", (void (Buffer<>::*)()) & Buffer<>::add_dimension)
.def("add_dimension", (void(Buffer<>::*)()) & Buffer<>::add_dimension)

.def("allocate", [](Buffer<> &b) -> void {
b.allocate(nullptr, nullptr);
})
.def("deallocate", (void (Buffer<>::*)()) & Buffer<>::deallocate)
.def("device_deallocate", (void (Buffer<>::*)()) & Buffer<>::device_deallocate)
.def("deallocate", (void(Buffer<>::*)()) & Buffer<>::deallocate)
.def("device_deallocate", (void(Buffer<>::*)()) & Buffer<>::device_deallocate)

.def(
"crop", [](Buffer<> &b, int d, int min, int extent) -> void {
Expand Down
26 changes: 13 additions & 13 deletions python_bindings/src/PyFunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,19 +186,19 @@ void define_func(py::module &m) {

.def("compile_to", &Func::compile_to, py::arg("outputs"), py::arg("arguments"), py::arg("fn_name"), py::arg("target") = get_target_from_environment())

.def("compile_to_bitcode", (void (Func::*)(const std::string &, const std::vector<Argument> &, const std::string &, const Target &target)) & Func::compile_to_bitcode, py::arg("filename"), py::arg("arguments"), py::arg("fn_name"), py::arg("target") = get_target_from_environment())
.def("compile_to_bitcode", (void (Func::*)(const std::string &, const std::vector<Argument> &, const Target &target)) & Func::compile_to_bitcode, py::arg("filename"), py::arg("arguments"), py::arg("target") = get_target_from_environment())
.def("compile_to_bitcode", (void(Func::*)(const std::string &, const std::vector<Argument> &, const std::string &, const Target &target)) & Func::compile_to_bitcode, py::arg("filename"), py::arg("arguments"), py::arg("fn_name"), py::arg("target") = get_target_from_environment())
.def("compile_to_bitcode", (void(Func::*)(const std::string &, const std::vector<Argument> &, const Target &target)) & Func::compile_to_bitcode, py::arg("filename"), py::arg("arguments"), py::arg("target") = get_target_from_environment())

.def("compile_to_llvm_assembly", (void (Func::*)(const std::string &, const std::vector<Argument> &, const std::string &, const Target &target)) & Func::compile_to_llvm_assembly, py::arg("filename"), py::arg("arguments"), py::arg("fn_name"), py::arg("target") = get_target_from_environment())
.def("compile_to_llvm_assembly", (void (Func::*)(const std::string &, const std::vector<Argument> &, const Target &target)) & Func::compile_to_llvm_assembly, py::arg("filename"), py::arg("arguments"), py::arg("target") = get_target_from_environment())
.def("compile_to_llvm_assembly", (void(Func::*)(const std::string &, const std::vector<Argument> &, const std::string &, const Target &target)) & Func::compile_to_llvm_assembly, py::arg("filename"), py::arg("arguments"), py::arg("fn_name"), py::arg("target") = get_target_from_environment())
.def("compile_to_llvm_assembly", (void(Func::*)(const std::string &, const std::vector<Argument> &, const Target &target)) & Func::compile_to_llvm_assembly, py::arg("filename"), py::arg("arguments"), py::arg("target") = get_target_from_environment())

.def("compile_to_object", (void (Func::*)(const std::string &, const std::vector<Argument> &, const std::string &, const Target &target)) & Func::compile_to_object, py::arg("filename"), py::arg("arguments"), py::arg("fn_name"), py::arg("target") = get_target_from_environment())
.def("compile_to_object", (void (Func::*)(const std::string &, const std::vector<Argument> &, const Target &target)) & Func::compile_to_object, py::arg("filename"), py::arg("arguments"), py::arg("target") = get_target_from_environment())
.def("compile_to_object", (void(Func::*)(const std::string &, const std::vector<Argument> &, const std::string &, const Target &target)) & Func::compile_to_object, py::arg("filename"), py::arg("arguments"), py::arg("fn_name"), py::arg("target") = get_target_from_environment())
.def("compile_to_object", (void(Func::*)(const std::string &, const std::vector<Argument> &, const Target &target)) & Func::compile_to_object, py::arg("filename"), py::arg("arguments"), py::arg("target") = get_target_from_environment())

.def("compile_to_header", &Func::compile_to_header, py::arg("filename"), py::arg("arguments"), py::arg("fn_name") = "", py::arg("target") = get_target_from_environment())

.def("compile_to_assembly", (void (Func::*)(const std::string &, const std::vector<Argument> &, const std::string &, const Target &target)) & Func::compile_to_assembly, py::arg("filename"), py::arg("arguments"), py::arg("fn_name"), py::arg("target") = get_target_from_environment())
.def("compile_to_assembly", (void (Func::*)(const std::string &, const std::vector<Argument> &, const Target &target)) & Func::compile_to_assembly, py::arg("filename"), py::arg("arguments"), py::arg("target") = get_target_from_environment())
.def("compile_to_assembly", (void(Func::*)(const std::string &, const std::vector<Argument> &, const std::string &, const Target &target)) & Func::compile_to_assembly, py::arg("filename"), py::arg("arguments"), py::arg("fn_name"), py::arg("target") = get_target_from_environment())
.def("compile_to_assembly", (void(Func::*)(const std::string &, const std::vector<Argument> &, const Target &target)) & Func::compile_to_assembly, py::arg("filename"), py::arg("arguments"), py::arg("target") = get_target_from_environment())

.def("compile_to_c", &Func::compile_to_c, py::arg("filename"), py::arg("arguments"), py::arg("fn_name") = "", py::arg("target") = get_target_from_environment())

Expand Down Expand Up @@ -242,13 +242,13 @@ void define_func(py::module &m) {
.def("is_extern", &Func::is_extern)
.def("extern_function_name", &Func::extern_function_name)

.def("define_extern", (void (Func::*)(const std::string &, const std::vector<ExternFuncArgument> &, const std::vector<Type> &, const std::vector<Var> &, NameMangling, DeviceAPI)) & Func::define_extern, py::arg("function_name"), py::arg("params"), py::arg("types"), py::arg("arguments"), py::arg("mangling") = NameMangling::Default, py::arg("device_api") = DeviceAPI::Host)
.def("define_extern", (void(Func::*)(const std::string &, const std::vector<ExternFuncArgument> &, const std::vector<Type> &, const std::vector<Var> &, NameMangling, DeviceAPI)) & Func::define_extern, py::arg("function_name"), py::arg("params"), py::arg("types"), py::arg("arguments"), py::arg("mangling") = NameMangling::Default, py::arg("device_api") = DeviceAPI::Host)

.def("define_extern", (void (Func::*)(const std::string &, const std::vector<ExternFuncArgument> &, Type, int, NameMangling, DeviceAPI)) & Func::define_extern, py::arg("function_name"), py::arg("params"), py::arg("type"), py::arg("dimensionality"), py::arg("mangling") = NameMangling::Default, py::arg("device_api") = DeviceAPI::Host)
.def("define_extern", (void(Func::*)(const std::string &, const std::vector<ExternFuncArgument> &, Type, int, NameMangling, DeviceAPI)) & Func::define_extern, py::arg("function_name"), py::arg("params"), py::arg("type"), py::arg("dimensionality"), py::arg("mangling") = NameMangling::Default, py::arg("device_api") = DeviceAPI::Host)

.def("define_extern", (void (Func::*)(const std::string &, const std::vector<ExternFuncArgument> &, const std::vector<Type> &, int, NameMangling, DeviceAPI)) & Func::define_extern, py::arg("function_name"), py::arg("params"), py::arg("types"), py::arg("dimensionality"), py::arg("mangling") = NameMangling::Default, py::arg("device_api") = DeviceAPI::Host)
.def("define_extern", (void(Func::*)(const std::string &, const std::vector<ExternFuncArgument> &, const std::vector<Type> &, int, NameMangling, DeviceAPI)) & Func::define_extern, py::arg("function_name"), py::arg("params"), py::arg("types"), py::arg("dimensionality"), py::arg("mangling") = NameMangling::Default, py::arg("device_api") = DeviceAPI::Host)

.def("define_extern", (void (Func::*)(const std::string &, const std::vector<ExternFuncArgument> &, Type, const std::vector<Var> &, NameMangling, DeviceAPI)) & Func::define_extern, py::arg("function_name"), py::arg("params"), py::arg("type"), py::arg("arguments"), py::arg("mangling") = NameMangling::Default, py::arg("device_api") = DeviceAPI::Host)
.def("define_extern", (void(Func::*)(const std::string &, const std::vector<ExternFuncArgument> &, Type, const std::vector<Var> &, NameMangling, DeviceAPI)) & Func::define_extern, py::arg("function_name"), py::arg("params"), py::arg("type"), py::arg("arguments"), py::arg("mangling") = NameMangling::Default, py::arg("device_api") = DeviceAPI::Host)

.def("output_buffer", &Func::output_buffer)
.def("output_buffers", &Func::output_buffers)
Expand Down Expand Up @@ -350,7 +350,7 @@ void define_func(py::module &m) {
define_set<Var, FuncRef>(func_class);
define_set<Var, Expr>(func_class);
define_set<Var, Tuple>(func_class);
//define_set<Var, std::vector<Var>>(func_class);
// define_set<Var, std::vector<Var>>(func_class);

// LHS(Expr, ...Expr) can only be LHS of an update definition.
define_set<Expr, FuncRef>(func_class);
Expand Down
4 changes: 2 additions & 2 deletions python_bindings/src/PyModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ void define_module(py::module &m) {
.def("buffers", &Module::buffers)
.def("submodules", &Module::submodules)

.def("append", (void (Module::*)(const Buffer<> &)) & Module::append, py::arg("buffer"))
.def("append", (void (Module::*)(const Module &)) & Module::append, py::arg("module"))
.def("append", (void(Module::*)(const Buffer<> &)) & Module::append, py::arg("buffer"))
.def("append", (void(Module::*)(const Module &)) & Module::append, py::arg("module"))

.def("compile", &Module::compile, py::arg("outputs"))

Expand Down
2 changes: 1 addition & 1 deletion python_bindings/src/PyTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void define_target(py::module &m) {
.def("__str__", &Target::to_string)
.def("to_string", &Target::to_string)

.def("has_feature", (bool (Target::*)(Target::Feature) const) & Target::has_feature)
.def("has_feature", (bool(Target::*)(Target::Feature) const) & Target::has_feature)
.def("features_any_of", &Target::features_any_of, py::arg("features"))
.def("features_all_of", &Target::features_all_of, py::arg("features"))

Expand Down
6 changes: 3 additions & 3 deletions python_bindings/src/PyType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ void define_type(py::module &m) {
// .def("__lt__", [](const Type &value, Type *value2) -> bool { return value2 && value < *value2; })

.def("element_of", &Type::element_of)
.def("can_represent", (bool (Type::*)(Type) const) & Type::can_represent, py::arg("other"))
.def("can_represent", (bool(Type::*)(Type) const) & Type::can_represent, py::arg("other"))
// Python doesn't have unsigned integers -- all integers are signed --
// so we'll never see anything that can usefully be routed to the uint64_t
// overloads of these methods.
.def("is_max", (bool (Type::*)(int64_t) const) & Type::is_max, py::arg("value"))
.def("is_min", (bool (Type::*)(int64_t) const) & Type::is_min, py::arg("value"))
.def("is_max", (bool(Type::*)(int64_t) const) & Type::is_max, py::arg("value"))
.def("is_min", (bool(Type::*)(int64_t) const) & Type::is_min, py::arg("value"))
.def("max", &Type::max)
.def("min", &Type::min)
.def("__repr__", &type_repr)
Expand Down
6 changes: 3 additions & 3 deletions python_bindings/src/PyVar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ void define_var(py::module &m) {
.def(py::init<std::string>())
.def("name", &Var::name)
.def("same_as", &Var::same_as)
.def("is_implicit", (bool (Var::*)() const) & Var::is_implicit)
.def("implicit_index", (int (Var::*)() const) & Var::implicit_index)
.def("is_placeholder", (bool (Var::*)() const) & Var::is_placeholder)
.def("is_implicit", (bool(Var::*)() const) & Var::is_implicit)
.def("implicit_index", (int(Var::*)() const) & Var::implicit_index)
.def("is_placeholder", (bool(Var::*)() const) & Var::is_placeholder)
.def_static("implicit", (Var(*)(int)) & Var::implicit)
.def_static("outermost", &Var::outermost)
.def("__repr__", &var_repr)
Expand Down
14 changes: 7 additions & 7 deletions run-clang-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ set -e

ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

# We are currently standardized on using LLVM/Clang12 for this script.
# We are currently standardized on using LLVM/Clang13 for this script.
# Note that this is totally independent of the version of LLVM that you
# are using to build Halide itself. If you don't have LLVM12 installed,
# are using to build Halide itself. If you don't have LLVM13 installed,
# you can usually install what you need easily via:
#
# sudo apt-get install llvm-12 clang-12 libclang-12-dev clang-tidy-12
# export CLANG_FORMAT_LLVM_INSTALL_DIR=/usr/lib/llvm-12
# sudo apt-get install llvm-13 clang-13 libclang-13-dev clang-tidy-13
# export CLANG_FORMAT_LLVM_INSTALL_DIR=/usr/lib/llvm-13

[ -z "$CLANG_FORMAT_LLVM_INSTALL_DIR" ] && echo "CLANG_FORMAT_LLVM_INSTALL_DIR must point to an LLVM installation dir for this script." && exit
echo CLANG_FORMAT_LLVM_INSTALL_DIR = ${CLANG_FORMAT_LLVM_INSTALL_DIR}

VERSION=$(${CLANG_FORMAT_LLVM_INSTALL_DIR}/bin/clang-format --version)
if [[ ${VERSION} =~ .*version\ 12.* ]]
if [[ ${VERSION} =~ .*version\ 13.* ]]
then
echo "clang-format version 12 found."
echo "clang-format version 13 found."
else
echo "CLANG_FORMAT_LLVM_INSTALL_DIR must point to an LLVM 12 install!"
echo "CLANG_FORMAT_LLVM_INSTALL_DIR must point to an LLVM 13 install!"
exit 1
fi

Expand Down
2 changes: 1 addition & 1 deletion src/Elf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ std::unique_ptr<Object> parse_object_internal(const char *data, size_t size) {
internal_assert(to_relocate != obj->sections_end());
// TODO: This assert should work, but it seems like this
// isn't a reliable test. We rely on the names intead.
//internal_assert(&*to_relocate == section_map[sh->sh_link]);
// internal_assert(&*to_relocate == section_map[sh->sh_link]);
for (uint64_t i = 0; i < sh->sh_size / sh->sh_entsize; i++) {
const char *rela_ptr = data + sh->sh_offset + i * sh->sh_entsize;
internal_assert(data <= rela_ptr && rela_ptr + sizeof(Rela<T>) <= data + size);
Expand Down
2 changes: 1 addition & 1 deletion src/HexagonOffload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ void do_reloc(char *addr, uint32_t mask, uintptr_t val, bool is_signed, bool ver
// Pull out the subinstructions. They're the low 13
// bits of each half-word.
uint32_t hi = (inst >> 16) & ((1 << 13) - 1);
//uint32_t lo = inst & ((1 << 13) - 1);
// uint32_t lo = inst & ((1 << 13) - 1);

// We only understand the ones where hi starts with 010
internal_assert((hi >> 10) == 2);
Expand Down
18 changes: 9 additions & 9 deletions src/IROperator.h
Original file line number Diff line number Diff line change
Expand Up @@ -1034,21 +1034,21 @@ Expr round(Expr x);
Expr trunc(Expr x);

/** Returns true if the argument is a Not a Number (NaN). Requires a
* floating point argument. Vectorizes cleanly.
* Note that the Expr passed in will be evaluated in strict_float mode,
* regardless of whether strict_float mode is enabled in the current Target. */
* floating point argument. Vectorizes cleanly.
* Note that the Expr passed in will be evaluated in strict_float mode,
* regardless of whether strict_float mode is enabled in the current Target. */
Expr is_nan(Expr x);

/** Returns true if the argument is Inf or -Inf. Requires a
* floating point argument. Vectorizes cleanly.
* Note that the Expr passed in will be evaluated in strict_float mode,
* regardless of whether strict_float mode is enabled in the current Target. */
* floating point argument. Vectorizes cleanly.
* Note that the Expr passed in will be evaluated in strict_float mode,
* regardless of whether strict_float mode is enabled in the current Target. */
Expr is_inf(Expr x);

/** Returns true if the argument is a finite value (ie, neither NaN nor Inf).
* Requires a floating point argument. Vectorizes cleanly.
* Note that the Expr passed in will be evaluated in strict_float mode,
* regardless of whether strict_float mode is enabled in the current Target. */
* Requires a floating point argument. Vectorizes cleanly.
* Note that the Expr passed in will be evaluated in strict_float mode,
* regardless of whether strict_float mode is enabled in the current Target. */
Expr is_finite(Expr x);

/** Return the fractional part of a floating-point expression. If the argument
Expand Down
4 changes: 2 additions & 2 deletions src/LLVM_Runtime_Linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,10 @@ DECLARE_NO_INITMOD(wasm_math)
#endif // WITH_WEBASSEMBLY

#ifdef WITH_RISCV
//DECLARE_LL_INITMOD(riscv)
// DECLARE_LL_INITMOD(riscv)
DECLARE_CPP_INITMOD(riscv_cpu_features)
#else
//DECLARE_NO_INITMOD(riscv)
// DECLARE_NO_INITMOD(riscv)
DECLARE_NO_INITMOD(riscv_cpu_features)
#endif // WITH_RISCV

Expand Down
2 changes: 1 addition & 1 deletion src/Lambda.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ Func lambda(const Var &x, const Var &y, const Var &z, const Var &w, const Var &v

} // namespace Halide

#endif //HALIDE_LAMBDA_H
#endif // HALIDE_LAMBDA_H
Loading

0 comments on commit 887d340

Please sign in to comment.