[llvm] 0eb59ca - ADT: Move FPClassTest printing functions to common place
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 3 14:52:04 PST 2023
Author: Matt Arsenault
Date: 2023-03-03T18:20:47-04:00
New Revision: 0eb59cab95a01fa84188049fa08348c3bf97e356
URL: https://github.com/llvm/llvm-project/commit/0eb59cab95a01fa84188049fa08348c3bf97e356
DIFF: https://github.com/llvm/llvm-project/commit/0eb59cab95a01fa84188049fa08348c3bf97e356.diff
LOG: ADT: Move FPClassTest printing functions to common place
Added:
llvm/lib/Support/FloatingPointMode.cpp
Modified:
llvm/include/llvm/ADT/FloatingPointMode.h
llvm/lib/IR/Attributes.cpp
llvm/lib/Support/CMakeLists.txt
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/FloatingPointMode.h b/llvm/include/llvm/ADT/FloatingPointMode.h
index a99f4f151fcde..e6cc3023a88cf 100644
--- a/llvm/include/llvm/ADT/FloatingPointMode.h
+++ b/llvm/include/llvm/ADT/FloatingPointMode.h
@@ -222,6 +222,9 @@ enum FPClassTest : unsigned {
LLVM_DECLARE_ENUM_AS_BITMASK(FPClassTest, /* LargestValue */ fcPosInf);
+/// Write a human readable form of \p Mask to \p OS
+raw_ostream &operator<<(raw_ostream &OS, FPClassTest Mask);
+
} // namespace llvm
#endif // LLVM_ADT_FLOATINGPOINTMODE_H
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index 21f119da342c0..3858f5f2484e1 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -431,56 +431,6 @@ static const char *getModRefStr(ModRefInfo MR) {
llvm_unreachable("Invalid ModRefInfo");
}
-// Every bitfield has a unique name and one or more aliasing names that cover
-// multiple bits. Names should be listed in order of preference, with higher
-// popcounts listed first.
-//
-// Bits are consumed as printed. Each field should only be represented in one
-// printed field.
-static constexpr std::pair<unsigned, StringLiteral> NoFPClassName[] = {
- {fcAllFlags, "all"},
- {fcNan, "nan"},
- {fcSNan, "snan"},
- {fcQNan, "qnan"},
- {fcInf, "inf"},
- {fcNegInf, "ninf"},
- {fcPosInf, "pinf"},
- {fcZero, "zero"},
- {fcNegZero, "nzero"},
- {fcPosZero, "pzero"},
- {fcSubnormal, "sub"},
- {fcNegSubnormal, "nsub"},
- {fcPosSubnormal, "psub"},
- {fcNormal, "norm"},
- {fcNegNormal, "nnorm"},
- {fcPosNormal, "pnorm"}
-};
-
-static std::string getNoFPClassAttrAsString(unsigned Mask) {
- std::string Result("nofpclass(");
- raw_string_ostream OS(Result);
-
- if (Mask == 0) {
- OS << "none)";
- return Result;
- }
-
- ListSeparator LS(" ");
- for (auto [BitTest, Name] : NoFPClassName) {
- if ((Mask & BitTest) == BitTest) {
- OS << LS << Name;
-
- // Clear the bits so we don't print any aliased names later.
- Mask &= ~BitTest;
- }
- }
-
- assert(Mask == 0 && "didn't print some mask bits");
-
- OS << ')';
- return Result;
-}
-
std::string Attribute::getAsString(bool InAttrGrp) const {
if (!pImpl) return {};
@@ -614,8 +564,12 @@ std::string Attribute::getAsString(bool InAttrGrp) const {
return Result;
}
- if (hasAttribute(Attribute::NoFPClass))
- return getNoFPClassAttrAsString(getValueAsInt());
+ if (hasAttribute(Attribute::NoFPClass)) {
+ std::string Result = "nofpclass";
+ raw_string_ostream OS(Result);
+ OS << getNoFPClass();
+ return Result;
+ }
// Convert target-dependent attributes to strings of the form:
//
diff --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt
index 774bc11e973eb..2270575571cf7 100644
--- a/llvm/lib/Support/CMakeLists.txt
+++ b/llvm/lib/Support/CMakeLists.txt
@@ -165,6 +165,7 @@ add_llvm_component_library(LLVMSupport
FileCollector.cpp
FileUtilities.cpp
FileOutputBuffer.cpp
+ FloatingPointMode.cpp
FoldingSet.cpp
FormattedStream.cpp
FormatVariadic.cpp
diff --git a/llvm/lib/Support/FloatingPointMode.cpp b/llvm/lib/Support/FloatingPointMode.cpp
new file mode 100644
index 0000000000000..72131d3348d78
--- /dev/null
+++ b/llvm/lib/Support/FloatingPointMode.cpp
@@ -0,0 +1,61 @@
+//===- FloatingPointMode.cpp ------------------------------------*- 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ADT/FloatingPointMode.h"
+#include "llvm/ADT/StringExtras.h"
+
+using namespace llvm;
+
+// Every bitfield has a unique name and one or more aliasing names that cover
+// multiple bits. Names should be listed in order of preference, with higher
+// popcounts listed first.
+//
+// Bits are consumed as printed. Each field should only be represented in one
+// printed field.
+static constexpr std::pair<FPClassTest, StringLiteral> NoFPClassName[] = {
+ {fcAllFlags, "all"},
+ {fcNan, "nan"},
+ {fcSNan, "snan"},
+ {fcQNan, "qnan"},
+ {fcInf, "inf"},
+ {fcNegInf, "ninf"},
+ {fcPosInf, "pinf"},
+ {fcZero, "zero"},
+ {fcNegZero, "nzero"},
+ {fcPosZero, "pzero"},
+ {fcSubnormal, "sub"},
+ {fcNegSubnormal, "nsub"},
+ {fcPosSubnormal, "psub"},
+ {fcNormal, "norm"},
+ {fcNegNormal, "nnorm"},
+ {fcPosNormal, "pnorm"}
+};
+
+raw_ostream &llvm::operator<<(raw_ostream &OS, FPClassTest Mask) {
+ OS << '(';
+
+ if (Mask == fcNone) {
+ OS << "none)";
+ return OS;
+ }
+
+ ListSeparator LS(" ");
+ for (auto [BitTest, Name] : NoFPClassName) {
+ if ((Mask & BitTest) == BitTest) {
+ OS << LS << Name;
+
+ // Clear the bits so we don't print any aliased names later.
+ Mask &= ~BitTest;
+ }
+ }
+
+ assert(Mask == 0 && "didn't print some mask bits");
+
+ OS << ')';
+ return OS;
+}
More information about the llvm-commits
mailing list