[llvm] ae466a6 - [SelectionDAG] Add getFltSemantics to MVT and EVT. NFC
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 13 11:36:18 PDT 2024
Author: Craig Topper
Date: 2024-08-13T11:35:27-07:00
New Revision: ae466a61d39454d9f311e2e4b624e256bbd5d18b
URL: https://github.com/llvm/llvm-project/commit/ae466a61d39454d9f311e2e4b624e256bbd5d18b
DIFF: https://github.com/llvm/llvm-project/commit/ae466a61d39454d9f311e2e4b624e256bbd5d18b.diff
LOG: [SelectionDAG] Add getFltSemantics to MVT and EVT. NFC
This will be used to replace SelectionDAG::EVTToAPFloatSemantics
A similar method exists in IR's Type class.
Added:
Modified:
llvm/include/llvm/CodeGen/SelectionDAG.h
llvm/include/llvm/CodeGen/ValueTypes.h
llvm/include/llvm/CodeGenTypes/MachineValueType.h
llvm/lib/CodeGen/ValueTypes.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/SelectionDAG.h b/llvm/include/llvm/CodeGen/SelectionDAG.h
index 9ce3c48a7f76cb..8757af4d6e96d9 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAG.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAG.h
@@ -14,8 +14,6 @@
#ifndef LLVM_CODEGEN_SELECTIONDAG_H
#define LLVM_CODEGEN_SELECTIONDAG_H
-#include "llvm/ADT/APFloat.h"
-#include "llvm/ADT/APInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
@@ -1824,16 +1822,7 @@ class SelectionDAG {
/// Returns an APFloat semantics tag appropriate for the given type. If VT is
/// a vector type, the element semantics are returned.
static const fltSemantics &EVTToAPFloatSemantics(EVT VT) {
- switch (VT.getScalarType().getSimpleVT().SimpleTy) {
- default: llvm_unreachable("Unknown FP format");
- case MVT::f16: return APFloat::IEEEhalf();
- case MVT::bf16: return APFloat::BFloat();
- case MVT::f32: return APFloat::IEEEsingle();
- case MVT::f64: return APFloat::IEEEdouble();
- case MVT::f80: return APFloat::x87DoubleExtended();
- case MVT::f128: return APFloat::IEEEquad();
- case MVT::ppcf128: return APFloat::PPCDoubleDouble();
- }
+ return VT.getFltSemantics();
}
/// Add a dbg_value SDNode. If SD is non-null that means the
diff --git a/llvm/include/llvm/CodeGen/ValueTypes.h b/llvm/include/llvm/CodeGen/ValueTypes.h
index dab6c421bf6e6d..c7cad3d509750e 100644
--- a/llvm/include/llvm/CodeGen/ValueTypes.h
+++ b/llvm/include/llvm/CodeGen/ValueTypes.h
@@ -27,6 +27,7 @@ namespace llvm {
class LLVMContext;
class Type;
+ struct fltSemantics;
/// Extended Value Type. Capable of holding value types which are not native
/// for any processor (such as the i12345 type), as well as the types an MVT
@@ -512,6 +513,10 @@ namespace llvm {
}
};
+ /// Returns an APFloat semantics tag appropriate for the value type. If this
+ /// is a vector type, the element semantics are returned.
+ const fltSemantics &getFltSemantics() const;
+
private:
// Methods for handling the Extended-type case in functions above.
// These are all out-of-line to prevent users of this header file
diff --git a/llvm/include/llvm/CodeGenTypes/MachineValueType.h b/llvm/include/llvm/CodeGenTypes/MachineValueType.h
index 556531c3147e5d..8bffdc31e5cdc5 100644
--- a/llvm/include/llvm/CodeGenTypes/MachineValueType.h
+++ b/llvm/include/llvm/CodeGenTypes/MachineValueType.h
@@ -26,6 +26,7 @@
namespace llvm {
class Type;
+ struct fltSemantics;
class raw_ostream;
/// Machine Value Type. Every type that is supported natively by some
@@ -476,6 +477,10 @@ namespace llvm {
/// to a concrete value type.
static MVT getVT(Type *Ty, bool HandleUnknown = false);
+ /// Returns an APFloat semantics tag appropriate for the value type. If this
+ /// is a vector type, the element semantics are returned.
+ const fltSemantics &getFltSemantics() const;
+
public:
/// SimpleValueType Iteration
/// @{
diff --git a/llvm/lib/CodeGen/ValueTypes.cpp b/llvm/lib/CodeGen/ValueTypes.cpp
index 0c6b726a28a242..c74ea5879acb54 100644
--- a/llvm/lib/CodeGen/ValueTypes.cpp
+++ b/llvm/lib/CodeGen/ValueTypes.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/CodeGen/ValueTypes.h"
+#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Type.h"
@@ -289,6 +290,23 @@ EVT EVT::getEVT(Type *Ty, bool HandleUnknown){
}
}
+const fltSemantics &MVT::getFltSemantics() const {
+ switch (getScalarType().SimpleTy) {
+ default: llvm_unreachable("Unknown FP format");
+ case MVT::f16: return APFloat::IEEEhalf();
+ case MVT::bf16: return APFloat::BFloat();
+ case MVT::f32: return APFloat::IEEEsingle();
+ case MVT::f64: return APFloat::IEEEdouble();
+ case MVT::f80: return APFloat::x87DoubleExtended();
+ case MVT::f128: return APFloat::IEEEquad();
+ case MVT::ppcf128: return APFloat::PPCDoubleDouble();
+ }
+}
+
+const fltSemantics &EVT::getFltSemantics() const {
+ return getScalarType().getSimpleVT().getFltSemantics();
+}
+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void MVT::dump() const {
print(dbgs());
More information about the llvm-commits
mailing list