Skip to content

Commit ae466a6

Browse files
committed
[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.
1 parent 0aa22dc commit ae466a6

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

llvm/include/llvm/CodeGen/SelectionDAG.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
#ifndef LLVM_CODEGEN_SELECTIONDAG_H
1515
#define LLVM_CODEGEN_SELECTIONDAG_H
1616

17-
#include "llvm/ADT/APFloat.h"
18-
#include "llvm/ADT/APInt.h"
1917
#include "llvm/ADT/ArrayRef.h"
2018
#include "llvm/ADT/DenseMap.h"
2119
#include "llvm/ADT/DenseSet.h"
@@ -1824,16 +1822,7 @@ class SelectionDAG {
18241822
/// Returns an APFloat semantics tag appropriate for the given type. If VT is
18251823
/// a vector type, the element semantics are returned.
18261824
static const fltSemantics &EVTToAPFloatSemantics(EVT VT) {
1827-
switch (VT.getScalarType().getSimpleVT().SimpleTy) {
1828-
default: llvm_unreachable("Unknown FP format");
1829-
case MVT::f16: return APFloat::IEEEhalf();
1830-
case MVT::bf16: return APFloat::BFloat();
1831-
case MVT::f32: return APFloat::IEEEsingle();
1832-
case MVT::f64: return APFloat::IEEEdouble();
1833-
case MVT::f80: return APFloat::x87DoubleExtended();
1834-
case MVT::f128: return APFloat::IEEEquad();
1835-
case MVT::ppcf128: return APFloat::PPCDoubleDouble();
1836-
}
1825+
return VT.getFltSemantics();
18371826
}
18381827

18391828
/// Add a dbg_value SDNode. If SD is non-null that means the

llvm/include/llvm/CodeGen/ValueTypes.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ namespace llvm {
2727

2828
class LLVMContext;
2929
class Type;
30+
struct fltSemantics;
3031

3132
/// Extended Value Type. Capable of holding value types which are not native
3233
/// for any processor (such as the i12345 type), as well as the types an MVT
@@ -512,6 +513,10 @@ namespace llvm {
512513
}
513514
};
514515

516+
/// Returns an APFloat semantics tag appropriate for the value type. If this
517+
/// is a vector type, the element semantics are returned.
518+
const fltSemantics &getFltSemantics() const;
519+
515520
private:
516521
// Methods for handling the Extended-type case in functions above.
517522
// These are all out-of-line to prevent users of this header file

llvm/include/llvm/CodeGenTypes/MachineValueType.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
namespace llvm {
2727

2828
class Type;
29+
struct fltSemantics;
2930
class raw_ostream;
3031

3132
/// Machine Value Type. Every type that is supported natively by some
@@ -476,6 +477,10 @@ namespace llvm {
476477
/// to a concrete value type.
477478
static MVT getVT(Type *Ty, bool HandleUnknown = false);
478479

480+
/// Returns an APFloat semantics tag appropriate for the value type. If this
481+
/// is a vector type, the element semantics are returned.
482+
const fltSemantics &getFltSemantics() const;
483+
479484
public:
480485
/// SimpleValueType Iteration
481486
/// @{

llvm/lib/CodeGen/ValueTypes.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "llvm/CodeGen/ValueTypes.h"
10+
#include "llvm/ADT/APFloat.h"
1011
#include "llvm/ADT/StringExtras.h"
1112
#include "llvm/IR/DerivedTypes.h"
1213
#include "llvm/IR/Type.h"
@@ -289,6 +290,23 @@ EVT EVT::getEVT(Type *Ty, bool HandleUnknown){
289290
}
290291
}
291292

293+
const fltSemantics &MVT::getFltSemantics() const {
294+
switch (getScalarType().SimpleTy) {
295+
default: llvm_unreachable("Unknown FP format");
296+
case MVT::f16: return APFloat::IEEEhalf();
297+
case MVT::bf16: return APFloat::BFloat();
298+
case MVT::f32: return APFloat::IEEEsingle();
299+
case MVT::f64: return APFloat::IEEEdouble();
300+
case MVT::f80: return APFloat::x87DoubleExtended();
301+
case MVT::f128: return APFloat::IEEEquad();
302+
case MVT::ppcf128: return APFloat::PPCDoubleDouble();
303+
}
304+
}
305+
306+
const fltSemantics &EVT::getFltSemantics() const {
307+
return getScalarType().getSimpleVT().getFltSemantics();
308+
}
309+
292310
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
293311
void MVT::dump() const {
294312
print(dbgs());

0 commit comments

Comments
 (0)