1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 02:33:06 +01:00

Port some floating point options to new option marshalling infrastructure

This ports a number of OpenCL and fast-math flags for floating point
over to the new marshalling infrastructure.

As part of this, `Opt{In,Out}FFlag` were enhanced to allow other flags to
imply them, via `DefaultAnyOf<>`. For example:
```
defm signed_zeros : OptOutFFlag<"signed-zeros", ...,
  "LangOpts->NoSignedZero",
  DefaultAnyOf<[cl_no_signed_zeros, menable_unsafe_fp_math]>>;
```
defines `-fsigned-zeros` (`false`) and `-fno-signed-zeros` (`true`)
linked to the keypath `LangOpts->NoSignedZero`, defaulting to `false`,
but set to `true` implicitly if one of `-cl-no-signed-zeros` or
`-menable-unsafe-fp-math` is on.

Note that the initial patch was written Daniel Grumberg.

Differential Revision: https://reviews.llvm.org/D82756
This commit is contained in:
Jan Svoboda 2020-11-09 15:51:42 -05:00 committed by Duncan P. N. Exon Smith
parent a6046da09b
commit 4f20c5bff5
5 changed files with 95 additions and 7 deletions

View File

@ -144,6 +144,11 @@ class ValuesCode<code valuecode> { code ValuesCode = valuecode; }
// Helpers for defining marshalling information.
class DefaultAnyOf<list<Option> defaults> {
code DefaultValue = !foldl("false", defaults, accumulator, option,
!strconcat(accumulator, " || ", !cast<string>(option.KeyPath)));
}
class MarshallingInfo<code keypath, code defaultvalue> {
code KeyPath = keypath;
code DefaultValue = defaultvalue;
@ -154,8 +159,8 @@ class MarshallingInfoString<code keypath, code defaultvalue, code normalizerrett
code NormalizerRetTy = normalizerretty;
}
class MarshallingInfoFlag<code keypath, code defaultvalue>
: MarshallingInfo<keypath, defaultvalue> {
class MarshallingInfoFlag<code keypath, DefaultAnyOf defaults = DefaultAnyOf<[]>>
: MarshallingInfo<keypath, defaults.DefaultValue> {
string MarshallingKind = "flag";
}

View File

@ -10,4 +10,5 @@ add_public_tablegen_target(OptsTestTableGen)
add_llvm_unittest(OptionTests
OptionParsingTest.cpp
OptionMarshallingTest.cpp
)

View File

@ -0,0 +1,47 @@
//===- unittest/Support/OptionMarshallingTest.cpp - OptParserEmitter tests ===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "gtest/gtest.h"
struct OptionWithMarshallingInfo {
const char *Name;
const char *KeyPath;
const char *DefaultValue;
};
static const OptionWithMarshallingInfo MarshallingTable[] = {
#define OPTION_WITH_MARSHALLING_FLAG(PREFIX_TYPE, NAME, ID, KIND, GROUP, \
ALIAS, ALIASARGS, FLAGS, PARAM, HELPTEXT, \
METAVAR, VALUES, SPELLING, ALWAYS_EMIT, \
KEYPATH, DEFAULT_VALUE, IS_POSITIVE) \
{ NAME, #KEYPATH, #DEFAULT_VALUE },
#include "Opts.inc"
#undef OPTION_WITH_MARSHALLING_FLAG
};
TEST(OptionMarshalling, EmittedOrderSameAsDefinitionOrder) {
ASSERT_STREQ(MarshallingTable[0].Name, "marshalled-flag-0");
ASSERT_STREQ(MarshallingTable[1].Name, "marshalled-flag-1");
ASSERT_STREQ(MarshallingTable[2].Name, "marshalled-flag-2");
ASSERT_STREQ(MarshallingTable[3].Name, "marshalled-flag-3");
}
TEST(OptionMarshalling, EmittedSpecifiedKeyPath) {
ASSERT_STREQ(MarshallingTable[0].KeyPath, "MarshalledFlag0");
ASSERT_STREQ(MarshallingTable[1].KeyPath, "MarshalledFlag1");
ASSERT_STREQ(MarshallingTable[2].KeyPath, "MarshalledFlag2");
ASSERT_STREQ(MarshallingTable[3].KeyPath, "MarshalledFlag3");
}
TEST(OptionMarshalling, DefaultAnyOfConstructedDisjunctionOfKeypaths) {
ASSERT_STREQ(MarshallingTable[0].DefaultValue, "false");
ASSERT_STREQ(MarshallingTable[1].DefaultValue, "false || MarshalledFlag0");
ASSERT_STREQ(MarshallingTable[2].DefaultValue, "false || MarshalledFlag0");
ASSERT_STREQ(MarshallingTable[3].DefaultValue,
"false || MarshalledFlag1 || MarshalledFlag2");
}

View File

@ -44,3 +44,12 @@ def Blurmpq : Flag<["--"], "blurmp">;
def Blurmpq_eq : Flag<["--"], "blurmp=">;
def DashDash : Option<["--"], "", KIND_REMAINING_ARGS>;
def marshalled_flag_0 : Flag<["-"], "marshalled-flag-0">,
MarshallingInfoFlag<"MarshalledFlag0", DefaultAnyOf<[]>>;
def marshalled_flag_1 : Flag<["-"], "marshalled-flag-1">,
MarshallingInfoFlag<"MarshalledFlag1", DefaultAnyOf<[marshalled_flag_0]>>;
def marshalled_flag_2 : Flag<["-"], "marshalled-flag-2">,
MarshallingInfoFlag<"MarshalledFlag2", DefaultAnyOf<[marshalled_flag_0]>>;
def marshalled_flag_3 : Flag<["-"], "marshalled-flag-3">,
MarshallingInfoFlag<"MarshalledFlag3", DefaultAnyOf<[marshalled_flag_1, marshalled_flag_2]>>;

View File

@ -435,7 +435,12 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS) {
OS << "nullptr";
};
std::vector<std::unique_ptr<MarshallingKindInfo>> OptsWithMarshalling;
auto IsMarshallingOption = [](const Record &R) {
return !isa<UnsetInit>(R.getValueInit("MarshallingKind")) &&
!R.getValueAsString("KeyPath").empty();
};
std::vector<const Record *> OptsWithMarshalling;
for (unsigned I = 0, E = Opts.size(); I != E; ++I) {
const Record &R = *Opts[I];
@ -443,12 +448,33 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS) {
OS << "OPTION(";
WriteOptRecordFields(OS, R);
OS << ")\n";
if (!isa<UnsetInit>(R.getValueInit("MarshallingKind")))
OptsWithMarshalling.push_back(MarshallingKindInfo::create(R));
if (IsMarshallingOption(R))
OptsWithMarshalling.push_back(&R);
}
OS << "#endif // OPTION\n";
for (const auto &KindInfo : OptsWithMarshalling) {
auto CmpMarshallingOpts = [](const Record *const *A, const Record *const *B) {
unsigned AID = (*A)->getID();
unsigned BID = (*B)->getID();
if (AID < BID)
return -1;
if (AID > BID)
return 1;
return 0;
};
// The RecordKeeper stores records (options) in lexicographical order, and we
// have reordered the options again when generating prefix groups. We need to
// restore the original definition order of options with marshalling to honor
// the topology of the dependency graph implied by `DefaultAnyOf`.
array_pod_sort(OptsWithMarshalling.begin(), OptsWithMarshalling.end(),
CmpMarshallingOpts);
std::vector<std::unique_ptr<MarshallingKindInfo>> MarshallingKindInfos;
for (const auto *R : OptsWithMarshalling)
MarshallingKindInfos.push_back(MarshallingKindInfo::create(*R));
for (const auto &KindInfo : MarshallingKindInfos) {
OS << "#ifdef " << KindInfo->MacroName << "\n";
OS << KindInfo->MacroName << "(";
WriteOptRecordFields(OS, KindInfo->R);
@ -463,7 +489,7 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS) {
OS << "\n";
OS << MarshallingStringInfo::ValueTablePreamble;
std::vector<StringRef> ValueTableNames;
for (const auto &KindInfo : OptsWithMarshalling)
for (const auto &KindInfo : MarshallingKindInfos)
if (auto MaybeValueTableName = KindInfo->emitValueTable(OS))
ValueTableNames.push_back(*MaybeValueTableName);