-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[RFC] Add clang atomic control options and pragmas #102569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//===--- AtomicOptions.def - Atomic Options database -------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// This file defines the Atomic language options. Users of this file | ||
// must define the OPTION macro to make use of this information. | ||
#ifndef OPTION | ||
# error Define the OPTION macro to handle atomic language options | ||
#endif | ||
|
||
// OPTION(name, type, width, previousName) | ||
OPTION(NoRemoteMemory, bool, 1, First) | ||
OPTION(NoFineGrainedMemory, bool, 1, NoRemoteMemory) | ||
OPTION(IgnoreDenormalMode, bool, 1, NoFineGrainedMemory) | ||
|
||
#undef OPTION | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -579,6 +579,10 @@ class LangOptions : public LangOptionsBase { | |
// WebAssembly target. | ||
bool NoWasmOpt = false; | ||
|
||
/// The default atomic codegen options specified by command line in the | ||
/// format of key:{on|off}. | ||
std::vector<std::string> AtomicOptionsAsWritten; | ||
|
||
LangOptions(); | ||
|
||
/// Set language defaults for the given input language and | ||
|
@@ -1034,6 +1038,169 @@ inline void FPOptions::applyChanges(FPOptionsOverride FPO) { | |
*this = FPO.applyOverrides(*this); | ||
} | ||
|
||
/// Atomic control options | ||
class AtomicOptionsOverride; | ||
class AtomicOptions { | ||
public: | ||
using storage_type = uint16_t; | ||
|
||
static constexpr unsigned StorageBitSize = 8 * sizeof(storage_type); | ||
|
||
static constexpr storage_type FirstShift = 0, FirstWidth = 0; | ||
#define OPTION(NAME, TYPE, WIDTH, PREVIOUS) \ | ||
static constexpr storage_type NAME##Shift = \ | ||
PREVIOUS##Shift + PREVIOUS##Width; \ | ||
static constexpr storage_type NAME##Width = WIDTH; \ | ||
static constexpr storage_type NAME##Mask = ((1 << NAME##Width) - 1) \ | ||
<< NAME##Shift; | ||
#include "clang/Basic/AtomicOptions.def" | ||
|
||
static constexpr storage_type TotalWidth = 0 | ||
#define OPTION(NAME, TYPE, WIDTH, PREVIOUS) +WIDTH | ||
#include "clang/Basic/AtomicOptions.def" | ||
; | ||
static_assert(TotalWidth <= StorageBitSize, | ||
"Too short type for AtomicOptions"); | ||
|
||
private: | ||
storage_type Value; | ||
|
||
AtomicOptionsOverride getChangesSlow(const AtomicOptions &Base) const; | ||
|
||
public: | ||
AtomicOptions() : Value(0) { | ||
setNoRemoteMemory(false); | ||
setNoFineGrainedMemory(false); | ||
setIgnoreDenormalMode(false); | ||
} | ||
explicit AtomicOptions(const LangOptions &LO) { | ||
Value = 0; | ||
#if 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Disabled code |
||
setNoRemoteMemory(LO.NoRemoteMemoryAccess); | ||
setNoFineGrainedMemory(LO.NoFineGrainedMemoryAccess); | ||
setIgnoreDenormalMode(LO.IgnoreDenormals); | ||
#endif | ||
} | ||
|
||
bool operator==(AtomicOptions other) const { return Value == other.Value; } | ||
|
||
/// Return the default value of AtomicOptions that's used when trailing | ||
/// storage isn't required. | ||
static AtomicOptions defaultWithoutTrailingStorage(const LangOptions &LO); | ||
|
||
storage_type getAsOpaqueInt() const { return Value; } | ||
static AtomicOptions getFromOpaqueInt(storage_type Value) { | ||
AtomicOptions Opts; | ||
Opts.Value = Value; | ||
return Opts; | ||
} | ||
|
||
/// Return difference with the given option set. | ||
AtomicOptionsOverride getChangesFrom(const AtomicOptions &Base) const; | ||
|
||
void applyChanges(AtomicOptionsOverride AO); | ||
|
||
#define OPTION(NAME, TYPE, WIDTH, PREVIOUS) \ | ||
TYPE get##NAME() const { \ | ||
return static_cast<TYPE>((Value & NAME##Mask) >> NAME##Shift); \ | ||
} \ | ||
void set##NAME(TYPE value) { \ | ||
Value = (Value & ~NAME##Mask) | (storage_type(value) << NAME##Shift); \ | ||
} | ||
#include "clang/Basic/AtomicOptions.def" | ||
LLVM_DUMP_METHOD void dump(); | ||
}; | ||
|
||
/// Represents difference between two AtomicOptions values. | ||
class AtomicOptionsOverride { | ||
AtomicOptions Options = AtomicOptions::getFromOpaqueInt(0); | ||
AtomicOptions::storage_type OverrideMask = 0; | ||
|
||
public: | ||
/// The type suitable for storing values of AtomicOptionsOverride. Must be | ||
/// twice as wide as bit size of AtomicOption. | ||
using storage_type = uint32_t; | ||
static_assert(sizeof(storage_type) >= 2 * sizeof(AtomicOptions::storage_type), | ||
"Too short type for AtomicOptionsOverride"); | ||
|
||
/// Bit mask selecting bits of OverrideMask in serialized representation of | ||
/// AtomicOptionsOverride. | ||
static constexpr storage_type OverrideMaskBits = | ||
(static_cast<storage_type>(1) << AtomicOptions::StorageBitSize) - 1; | ||
|
||
AtomicOptionsOverride() {} | ||
AtomicOptionsOverride(const LangOptions &LO); | ||
AtomicOptionsOverride(AtomicOptions AO) | ||
: Options(AO), OverrideMask(OverrideMaskBits) {} | ||
AtomicOptionsOverride(AtomicOptions AO, AtomicOptions::storage_type Mask) | ||
: Options(AO), OverrideMask(Mask) {} | ||
|
||
bool requiresTrailingStorage() const { return OverrideMask != 0; } | ||
|
||
storage_type getAsOpaqueInt() const { | ||
return (static_cast<storage_type>(Options.getAsOpaqueInt()) | ||
<< AtomicOptions::StorageBitSize) | | ||
OverrideMask; | ||
} | ||
|
||
static AtomicOptionsOverride getFromOpaqueInt(storage_type I) { | ||
AtomicOptionsOverride Opts; | ||
Opts.OverrideMask = I & OverrideMaskBits; | ||
Opts.Options = | ||
AtomicOptions::getFromOpaqueInt(I >> AtomicOptions::StorageBitSize); | ||
return Opts; | ||
} | ||
|
||
AtomicOptions applyOverrides(AtomicOptions Base) { | ||
AtomicOptions Result = AtomicOptions::getFromOpaqueInt( | ||
(Base.getAsOpaqueInt() & ~OverrideMask) | | ||
(Options.getAsOpaqueInt() & OverrideMask)); | ||
return Result; | ||
} | ||
|
||
AtomicOptions applyOverrides(const LangOptions &LO) { | ||
return applyOverrides(AtomicOptions(LO)); | ||
} | ||
|
||
bool operator==(AtomicOptionsOverride other) const { | ||
return Options == other.Options && OverrideMask == other.OverrideMask; | ||
} | ||
bool operator!=(AtomicOptionsOverride other) const { | ||
return !(*this == other); | ||
} | ||
|
||
#define OPTION(NAME, TYPE, WIDTH, PREVIOUS) \ | ||
bool has##NAME##Override() const { \ | ||
return OverrideMask & AtomicOptions::NAME##Mask; \ | ||
} \ | ||
TYPE get##NAME##Override() const { \ | ||
assert(has##NAME##Override()); \ | ||
return Options.get##NAME(); \ | ||
} \ | ||
void clear##NAME##Override() { \ | ||
Options.set##NAME(TYPE(0)); \ | ||
OverrideMask &= ~AtomicOptions::NAME##Mask; \ | ||
} \ | ||
void set##NAME##Override(TYPE value) { \ | ||
Options.set##NAME(value); \ | ||
OverrideMask |= AtomicOptions::NAME##Mask; \ | ||
} | ||
#include "clang/Basic/AtomicOptions.def" | ||
|
||
LLVM_DUMP_METHOD void dump(); | ||
}; | ||
|
||
inline AtomicOptionsOverride | ||
AtomicOptions::getChangesFrom(const AtomicOptions &Base) const { | ||
if (Value == Base.Value) | ||
return AtomicOptionsOverride(); | ||
return getChangesSlow(Base); | ||
} | ||
|
||
inline void AtomicOptions::applyChanges(AtomicOptionsOverride AO) { | ||
*this = AO.applyOverrides(*this); | ||
} | ||
|
||
/// Describes the kind of translation unit being processed. | ||
enum TranslationUnitKind { | ||
/// The translation unit is a complete translation unit. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
End of file missing line error