Skip to content

Commit

Permalink
[SE] Add .clang-format
Browse files Browse the repository at this point in the history
Summary:
The .clang-tidy file is copied from the top-level LLVM source directory.

Also fix warnings generated by clang-format:

* Moved SimpleHostPlatformDevice.h so its header include guard could
  have the right format.
* Changed signatures of methods taking llvm::Twine by value to take it
  by const ref instead.
* Add "noexcept" to some move constructors and assignment operators.
* Removed a bunch of places where single-statement loops and
  conditionals were surrounded with braces. (This was not found by the
  current clang-tidy, but with a local patch that I hope to upstream
  soon.)

Reviewers: jlebar, jprice

Subscribers: parallel_libs-commits

Differential Revision: https://reviews.llvm.org/D24468

llvm-svn: 281374
  • Loading branch information
henline committed Sep 13, 2016
1 parent 6956d29 commit fb62147
Show file tree
Hide file tree
Showing 19 changed files with 120 additions and 153 deletions.
17 changes: 17 additions & 0 deletions parallel-libs/.clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Checks: '-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,readability-identifier-naming'
CheckOptions:
- key: readability-identifier-naming.ClassCase
value: CamelCase
- key: readability-identifier-naming.EnumCase
value: CamelCase
- key: readability-identifier-naming.FunctionCase
value: lowerCase
- key: readability-identifier-naming.MemberCase
value: CamelCase
- key: readability-identifier-naming.ParameterCase
value: CamelCase
- key: readability-identifier-naming.UnionCase
value: CamelCase
- key: readability-identifier-naming.VariableCase
value: CamelCase

6 changes: 2 additions & 4 deletions parallel-libs/streamexecutor/include/streamexecutor/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ class Device {
KernelT>::type>
createKernel(const MultiKernelLoaderSpec &Spec) {
Expected<const void *> MaybeKernelHandle = PDevice->createKernel(Spec);
if (!MaybeKernelHandle) {
if (!MaybeKernelHandle)
return MaybeKernelHandle.takeError();
}
return KernelT(PDevice, *MaybeKernelHandle, Spec.getKernelName());
}

Expand All @@ -68,9 +67,8 @@ class Device {
Expected<RegisteredHostMemory<T>>
registerHostMemory(llvm::MutableArrayRef<T> Memory) {
if (Error E = PDevice->registerHostMemory(Memory.data(),
Memory.size() * sizeof(T))) {
Memory.size() * sizeof(T)))
return std::move(E);
}
return RegisteredHostMemory<T>(this, Memory.data(), Memory.size());
}

Expand Down
16 changes: 12 additions & 4 deletions parallel-libs/streamexecutor/include/streamexecutor/DeviceMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,15 @@ class GlobalDeviceMemoryBase {
: TheDevice(D), Handle(Handle), ByteCount(ByteCount) {}

/// Transfer ownership of the underlying handle.
GlobalDeviceMemoryBase(GlobalDeviceMemoryBase &&Other)
GlobalDeviceMemoryBase(GlobalDeviceMemoryBase &&Other) noexcept
: TheDevice(Other.TheDevice), Handle(Other.Handle),
ByteCount(Other.ByteCount) {
Other.TheDevice = nullptr;
Other.Handle = nullptr;
Other.ByteCount = 0;
}

GlobalDeviceMemoryBase &operator=(GlobalDeviceMemoryBase &&Other) {
GlobalDeviceMemoryBase &operator=(GlobalDeviceMemoryBase &&Other) noexcept {
TheDevice = Other.TheDevice;
Handle = Other.Handle;
ByteCount = Other.ByteCount;
Expand All @@ -178,8 +178,8 @@ class GlobalDeviceMemory : public GlobalDeviceMemoryBase {
public:
using ElementTy = ElemT;

GlobalDeviceMemory(GlobalDeviceMemory &&Other) = default;
GlobalDeviceMemory &operator=(GlobalDeviceMemory &&Other) = default;
GlobalDeviceMemory(GlobalDeviceMemory &&) noexcept;
GlobalDeviceMemory &operator=(GlobalDeviceMemory &&) noexcept;

/// Returns the number of elements of type ElemT that constitute this
/// allocation.
Expand All @@ -203,6 +203,14 @@ class GlobalDeviceMemory : public GlobalDeviceMemoryBase {
: GlobalDeviceMemoryBase(D, Handle, ElementCount * sizeof(ElemT)) {}
};

template <typename ElemT>
GlobalDeviceMemory<ElemT>::GlobalDeviceMemory(
GlobalDeviceMemory<ElemT> &&) noexcept = default;

template <typename ElemT>
GlobalDeviceMemory<ElemT> &GlobalDeviceMemory<ElemT>::
operator=(GlobalDeviceMemory<ElemT> &&) noexcept = default;

/// A class to represent the size of a dynamic shared memory buffer of elements
/// of type T on a device.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ using llvm::Expected;
using llvm::Twine;

/// Makes an Error object from an error message.
Error make_error(Twine Message);
Error make_error(const Twine &Message);

/// Consumes the input error and returns its error message.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ template <typename ElemT> class RegisteredHostMemory {
RegisteredHostMemory(const RegisteredHostMemory &) = delete;
RegisteredHostMemory &operator=(const RegisteredHostMemory &) = delete;

RegisteredHostMemory(RegisteredHostMemory &&Other)
RegisteredHostMemory(RegisteredHostMemory &&Other) noexcept
: TheDevice(Other.TheDevice), Pointer(Other.Pointer),
ElementCount(Other.ElementCount) {
Other.TheDevice = nullptr;
Other.Pointer = nullptr;
}

RegisteredHostMemory &operator=(RegisteredHostMemory &&Other) {
RegisteredHostMemory &operator=(RegisteredHostMemory &&Other) noexcept {
TheDevice = Other.TheDevice;
Pointer = Other.Pointer;
ElementCount = Other.ElementCount;
Expand Down
15 changes: 11 additions & 4 deletions parallel-libs/streamexecutor/include/streamexecutor/Kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class KernelBase {
KernelBase(const KernelBase &Other) = delete;
KernelBase &operator=(const KernelBase &Other) = delete;

KernelBase(KernelBase &&Other);
KernelBase &operator=(KernelBase &&Other);
KernelBase(KernelBase &&Other) noexcept;
KernelBase &operator=(KernelBase &&Other) noexcept;

~KernelBase();

Expand All @@ -68,10 +68,17 @@ template <typename... ParameterTs> class Kernel : public KernelBase {
llvm::StringRef Name)
: KernelBase(D, PlatformKernelHandle, Name) {}

Kernel(Kernel &&Other) = default;
Kernel &operator=(Kernel &&Other) = default;
Kernel(Kernel &&Other) noexcept;
Kernel &operator=(Kernel &&Other) noexcept;
};

template <typename... ParameterTs>
Kernel<ParameterTs...>::Kernel(Kernel<ParameterTs...> &&) noexcept = default;

template <typename... ParameterTs>
Kernel<ParameterTs...> &Kernel<ParameterTs...>::
operator=(Kernel<ParameterTs...> &&) noexcept = default;

} // namespace streamexecutor

#endif // STREAMEXECUTOR_KERNEL_H
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,8 @@ class OpenCLTextInMemorySpec : public KernelLoaderSpec {
class MultiKernelLoaderSpec {
public:
std::string getKernelName() const {
if (TheKernelName) {
if (TheKernelName)
return *TheKernelName;
}
return "";
}

Expand Down
6 changes: 3 additions & 3 deletions parallel-libs/streamexecutor/include/streamexecutor/Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class Stream {
Stream(const Stream &Other) = delete;
Stream &operator=(const Stream &Other) = delete;

Stream(Stream &&Other);
Stream &operator=(Stream &&Other);
Stream(Stream &&Other) noexcept;
Stream &operator=(Stream &&Other) noexcept;

~Stream();

Expand Down Expand Up @@ -288,7 +288,7 @@ class Stream {
/// Sets the error state from an error message.
///
/// Does not overwrite the error if it is already set.
void setError(llvm::Twine Message) {
void setError(const llvm::Twine &Message) {
llvm::sys::ScopedWriter WriterLock(*ErrorMessageMutex);
if (!ErrorMessage)
ErrorMessage = Message.str();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
///
//===----------------------------------------------------------------------===//

#ifndef STREAMEXECUTOR_LIB_UNITTESTS_SIMPLEHOSTPLATFORMDEVICE_H
#define STREAMEXECUTOR_LIB_UNITTESTS_SIMPLEHOSTPLATFORMDEVICE_H
#ifndef STREAMEXECUTOR_UNITTESTS_CORETESTS_SIMPLEHOSTPLATFORMDEVICE_H
#define STREAMEXECUTOR_UNITTESTS_CORETESTS_SIMPLEHOSTPLATFORMDEVICE_H

#include <cstdlib>
#include <cstring>
Expand Down Expand Up @@ -135,4 +135,4 @@ class SimpleHostPlatformDevice : public streamexecutor::PlatformDevice {
} // namespace test
} // namespace streamexecutor

#endif // STREAMEXECUTOR_LIB_UNITTESTS_SIMPLEHOSTPLATFORMDEVICE_H
#endif // STREAMEXECUTOR_UNITTESTS_CORETESTS_SIMPLEHOSTPLATFORMDEVICE_H
3 changes: 1 addition & 2 deletions parallel-libs/streamexecutor/lib/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ Device::~Device() = default;

Expected<Stream> Device::createStream() {
Expected<const void *> MaybePlatformStream = PDevice->createStream();
if (!MaybePlatformStream) {
if (!MaybePlatformStream)
return MaybePlatformStream.takeError();
}
return Stream(PDevice, *MaybePlatformStream);
}

Expand Down
3 changes: 1 addition & 2 deletions parallel-libs/streamexecutor/lib/DeviceMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
namespace streamexecutor {

GlobalDeviceMemoryBase::~GlobalDeviceMemoryBase() {
if (Handle) {
if (Handle)
// TODO(jhen): How to handle errors here.
consumeError(TheDevice->freeDeviceMemory(*this));
}
}

} // namespace streamexecutor
5 changes: 2 additions & 3 deletions parallel-libs/streamexecutor/lib/Error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,13 @@ char StreamExecutorError::ID = 0;

namespace streamexecutor {

Error make_error(Twine Message) {
Error make_error(const Twine &Message) {
return llvm::make_error<StreamExecutorError>(Message.str());
}

std::string consumeAndGetMessage(Error &&E) {
if (!E) {
if (!E)
return "success";
}
std::string Message;
llvm::handleAllErrors(std::move(E),
[&Message](const StreamExecutorError &SEE) {
Expand Down
3 changes: 1 addition & 2 deletions parallel-libs/streamexecutor/lib/HostMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ namespace internal {

void destroyRegisteredHostMemoryInternals(Device *TheDevice, void *Pointer) {
// TODO(jhen): How to handle errors here?
if (Pointer) {
if (Pointer)
consumeError(TheDevice->unregisterHostMemory(Pointer));
}
}

} // namespace internal
Expand Down
4 changes: 2 additions & 2 deletions parallel-libs/streamexecutor/lib/Kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ KernelBase::KernelBase(PlatformDevice *D, const void *PlatformKernelHandle,
"cannot construct a kernel object with a null platform kernel handle");
}

KernelBase::KernelBase(KernelBase &&Other)
KernelBase::KernelBase(KernelBase &&Other) noexcept
: PDevice(Other.PDevice), PlatformKernelHandle(Other.PlatformKernelHandle),
Name(std::move(Other.Name)),
DemangledName(std::move(Other.DemangledName)) {
Other.PDevice = nullptr;
Other.PlatformKernelHandle = nullptr;
}

KernelBase &KernelBase::operator=(KernelBase &&Other) {
KernelBase &KernelBase::operator=(KernelBase &&Other) noexcept {
PDevice = Other.PDevice;
PlatformKernelHandle = Other.PlatformKernelHandle;
Name = std::move(Other.Name);
Expand Down
11 changes: 4 additions & 7 deletions parallel-libs/streamexecutor/lib/KernelSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,17 @@ CUDAPTXInMemorySpec::CUDAPTXInMemorySpec(
llvm::StringRef KernelName,
const llvm::ArrayRef<CUDAPTXInMemorySpec::PTXSpec> SpecList)
: KernelLoaderSpec(KernelName) {
for (const auto &Spec : SpecList) {
for (const auto &Spec : SpecList)
PTXByComputeCapability.emplace(Spec.TheComputeCapability, Spec.PTXCode);
}
}

const char *CUDAPTXInMemorySpec::getCode(int ComputeCapabilityMajor,
int ComputeCapabilityMinor) const {
auto PTXIter =
PTXByComputeCapability.find(CUDAPTXInMemorySpec::ComputeCapability{
ComputeCapabilityMajor, ComputeCapabilityMinor});
if (PTXIter == PTXByComputeCapability.end()) {
if (PTXIter == PTXByComputeCapability.end())
return nullptr;
}
return PTXIter->second;
}

Expand All @@ -50,12 +48,11 @@ OpenCLTextInMemorySpec::OpenCLTextInMemorySpec(llvm::StringRef KernelName,
: KernelLoaderSpec(KernelName), Text(Text) {}

void MultiKernelLoaderSpec::setKernelName(llvm::StringRef KernelName) {
if (TheKernelName) {
if (TheKernelName)
assert(KernelName.equals(*TheKernelName) &&
"different kernel names in one MultiKernelLoaderSpec");
} else {
else
TheKernelName = llvm::make_unique<std::string>(KernelName);
}
}

MultiKernelLoaderSpec &MultiKernelLoaderSpec::addCUDAPTXInMemory(
Expand Down
4 changes: 2 additions & 2 deletions parallel-libs/streamexecutor/lib/Stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ Stream::Stream(PlatformDevice *D, const void *PlatformStreamHandle)
"cannot construct a stream object with a null platform stream handle");
}

Stream::Stream(Stream &&Other)
Stream::Stream(Stream &&Other) noexcept
: PDevice(Other.PDevice), PlatformStreamHandle(Other.PlatformStreamHandle),
ErrorMessageMutex(std::move(Other.ErrorMessageMutex)),
ErrorMessage(std::move(Other.ErrorMessage)) {
Other.PDevice = nullptr;
Other.PlatformStreamHandle = nullptr;
}

Stream &Stream::operator=(Stream &&Other) {
Stream &Stream::operator=(Stream &&Other) noexcept {
PDevice = Other.PDevice;
PlatformStreamHandle = Other.PlatformStreamHandle;
ErrorMessageMutex = std::move(Other.ErrorMessageMutex);
Expand Down
Loading

0 comments on commit fb62147

Please sign in to comment.