Skip to content

Commit 7f87dac

Browse files
committed
[CodeGen] Virtualize isTargetStrictFPOpcode / isTargetMemoryOpcode
1 parent af6d99c commit 7f87dac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+299
-122
lines changed

llvm/include/llvm/CodeGen/ISDOpcodes.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,17 +1490,6 @@ enum NodeType {
14901490
BUILTIN_OP_END
14911491
};
14921492

1493-
/// FIRST_TARGET_STRICTFP_OPCODE - Target-specific pre-isel operations
1494-
/// which cannot raise FP exceptions should be less than this value.
1495-
/// Those that do must not be less than this value.
1496-
static const int FIRST_TARGET_STRICTFP_OPCODE = BUILTIN_OP_END + 400;
1497-
1498-
/// FIRST_TARGET_MEMORY_OPCODE - Target-specific pre-isel operations
1499-
/// which do not reference a specific memory location should be less than
1500-
/// this value. Those that do must not be less than this value, and can
1501-
/// be used with SelectionDAG::getMemIntrinsicNode.
1502-
static const int FIRST_TARGET_MEMORY_OPCODE = BUILTIN_OP_END + 500;
1503-
15041493
/// Whether this is bitwise logic opcode.
15051494
inline bool isBitwiseLogicOp(unsigned Opcode) {
15061495
return Opcode == ISD::AND || Opcode == ISD::OR || Opcode == ISD::XOR;

llvm/include/llvm/CodeGen/SelectionDAG.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,8 +1327,8 @@ class SelectionDAG {
13271327

13281328
/// Creates a MemIntrinsicNode that may produce a
13291329
/// result and takes a list of operands. Opcode may be INTRINSIC_VOID,
1330-
/// INTRINSIC_W_CHAIN, or a target-specific opcode with a value not
1331-
/// less than FIRST_TARGET_MEMORY_OPCODE.
1330+
/// INTRINSIC_W_CHAIN, or a target-specific memory-referencing opcode
1331+
// (see `SelectionDAGTargetInfo::isTargetMemoryOpcode`).
13321332
SDValue getMemIntrinsicNode(
13331333
unsigned Opcode, const SDLoc &dl, SDVTList VTList, ArrayRef<SDValue> Ops,
13341334
EVT MemVT, MachinePointerInfo PtrInfo, Align Alignment,

llvm/include/llvm/CodeGen/SelectionDAGNodes.h

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ class SDValue {
210210
inline const SDValue &getOperand(unsigned i) const;
211211
inline uint64_t getConstantOperandVal(unsigned i) const;
212212
inline const APInt &getConstantOperandAPInt(unsigned i) const;
213-
inline bool isTargetMemoryOpcode() const;
214213
inline bool isTargetOpcode() const;
215214
inline bool isMachineOpcode() const;
216215
inline bool isUndef() const;
@@ -688,22 +687,6 @@ END_TWO_BYTE_PACK()
688687
/// \<target\>ISD namespace).
689688
bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
690689

691-
/// Test if this node has a target-specific opcode that may raise
692-
/// FP exceptions (in the \<target\>ISD namespace and greater than
693-
/// FIRST_TARGET_STRICTFP_OPCODE). Note that all target memory
694-
/// opcode are currently automatically considered to possibly raise
695-
/// FP exceptions as well.
696-
bool isTargetStrictFPOpcode() const {
697-
return NodeType >= ISD::FIRST_TARGET_STRICTFP_OPCODE;
698-
}
699-
700-
/// Test if this node has a target-specific
701-
/// memory-referencing opcode (in the \<target\>ISD namespace and
702-
/// greater than FIRST_TARGET_MEMORY_OPCODE).
703-
bool isTargetMemoryOpcode() const {
704-
return NodeType >= ISD::FIRST_TARGET_MEMORY_OPCODE;
705-
}
706-
707690
/// Return true if the type of the node type undefined.
708691
bool isUndef() const { return NodeType == ISD::UNDEF; }
709692

@@ -1214,10 +1197,6 @@ inline bool SDValue::isTargetOpcode() const {
12141197
return Node->isTargetOpcode();
12151198
}
12161199

1217-
inline bool SDValue::isTargetMemoryOpcode() const {
1218-
return Node->isTargetMemoryOpcode();
1219-
}
1220-
12211200
inline bool SDValue::isMachineOpcode() const {
12221201
return Node->isMachineOpcode();
12231202
}
@@ -1571,10 +1550,10 @@ class AtomicSDNode : public MemSDNode {
15711550
}
15721551
};
15731552

1574-
/// This SDNode is used for target intrinsics that touch
1575-
/// memory and need an associated MachineMemOperand. Its opcode may be
1576-
/// INTRINSIC_VOID, INTRINSIC_W_CHAIN, PREFETCH, or a target-specific opcode
1577-
/// with a value not less than FIRST_TARGET_MEMORY_OPCODE.
1553+
/// This SDNode is used for target intrinsics that touch memory and need
1554+
/// an associated MachineMemOperand. Its opcode may be INTRINSIC_VOID,
1555+
/// INTRINSIC_W_CHAIN, PREFETCH, or a target-specific memory-referencing
1556+
/// opcode (see `SelectionDAGTargetInfo::isTargetMemoryOpcode`).
15781557
class MemIntrinsicSDNode : public MemSDNode {
15791558
public:
15801559
MemIntrinsicSDNode(unsigned Opc, unsigned Order, const DebugLoc &dl,

llvm/include/llvm/CodeGen/SelectionDAGTargetInfo.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ class SelectionDAGTargetInfo {
3535
SelectionDAGTargetInfo &operator=(const SelectionDAGTargetInfo &) = delete;
3636
virtual ~SelectionDAGTargetInfo();
3737

38+
/// Returns true if a node with the given target-specific opcode has
39+
/// a memory operand. Nodes with such opcodes can only be created with
40+
/// `SelectionDAG::getMemIntrinsicNode`.
41+
virtual bool isTargetMemoryOpcode(unsigned Opcode) const { return false; }
42+
43+
/// Returns true if a node with the given target-specific opcode has
44+
/// strict floating-point semantics.
45+
virtual bool isTargetStrictFPOpcode(unsigned Opcode) const { return false; }
46+
47+
/// Returns true if a node with the given target-specific opcode
48+
/// may raise a floating-point exception.
49+
virtual bool mayRaiseFPException(unsigned Opcode) const;
50+
3851
/// Emit target-specific code that performs a memcpy.
3952
/// This can be used by targets to provide code sequences for cases
4053
/// that don't fit the target's parameters for simple loads/stores and can be

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8978,12 +8978,12 @@ SDValue SelectionDAG::getMemIntrinsicNode(unsigned Opcode, const SDLoc &dl,
89788978
SDVTList VTList,
89798979
ArrayRef<SDValue> Ops, EVT MemVT,
89808980
MachineMemOperand *MMO) {
8981-
assert((Opcode == ISD::INTRINSIC_VOID ||
8982-
Opcode == ISD::INTRINSIC_W_CHAIN ||
8983-
Opcode == ISD::PREFETCH ||
8984-
(Opcode <= (unsigned)std::numeric_limits<int>::max() &&
8985-
(int)Opcode >= ISD::FIRST_TARGET_MEMORY_OPCODE)) &&
8986-
"Opcode is not a memory-accessing opcode!");
8981+
assert(
8982+
(Opcode == ISD::INTRINSIC_VOID || Opcode == ISD::INTRINSIC_W_CHAIN ||
8983+
Opcode == ISD::PREFETCH ||
8984+
(Opcode <= (unsigned)std::numeric_limits<int>::max() &&
8985+
Opcode >= ISD::BUILTIN_OP_END && TSI->isTargetMemoryOpcode(Opcode))) &&
8986+
"Opcode is not a memory-accessing opcode!");
89878987

89888988
// Memoize the node unless it returns a glue result.
89898989
MemIntrinsicSDNode *N;

llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include "llvm/CodeGen/SchedulerRegistry.h"
5252
#include "llvm/CodeGen/SelectionDAG.h"
5353
#include "llvm/CodeGen/SelectionDAGNodes.h"
54+
#include "llvm/CodeGen/SelectionDAGTargetInfo.h"
5455
#include "llvm/CodeGen/StackMaps.h"
5556
#include "llvm/CodeGen/StackProtector.h"
5657
#include "llvm/CodeGen/SwiftErrorValueTracking.h"
@@ -4394,8 +4395,10 @@ bool SelectionDAGISel::mayRaiseFPException(SDNode *N) const {
43944395

43954396
// For ISD opcodes, only StrictFP opcodes may raise an FP
43964397
// exception.
4397-
if (N->isTargetOpcode())
4398-
return N->isTargetStrictFPOpcode();
4398+
if (N->isTargetOpcode()) {
4399+
const SelectionDAGTargetInfo &TSI = CurDAG->getSelectionDAGInfo();
4400+
return TSI.mayRaiseFPException(N->getOpcode());
4401+
}
43994402
return N->isStrictFPOpcode();
44004403
}
44014404

llvm/lib/CodeGen/SelectionDAG/SelectionDAGTargetInfo.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@
1515
using namespace llvm;
1616

1717
SelectionDAGTargetInfo::~SelectionDAGTargetInfo() = default;
18+
19+
bool SelectionDAGTargetInfo::mayRaiseFPException(unsigned Opcode) const {
20+
// FIXME: All target memory opcodes are currently automatically considered
21+
// to possibly raise FP exceptions. See rev. 63336795.
22+
return isTargetStrictFPOpcode(Opcode) || isTargetMemoryOpcode(Opcode);
23+
}

llvm/lib/Target/AArch64/AArch64ISelLowering.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,15 +477,16 @@ enum NodeType : unsigned {
477477
MSRR,
478478

479479
// Strict (exception-raising) floating point comparison
480-
STRICT_FCMP = ISD::FIRST_TARGET_STRICTFP_OPCODE,
480+
STRICT_FCMP,
481481
STRICT_FCMPE,
482482

483483
// SME ZA loads and stores
484484
SME_ZA_LDR,
485485
SME_ZA_STR,
486486

487487
// NEON Load/Store with post-increment base updates
488-
LD2post = ISD::FIRST_TARGET_MEMORY_OPCODE,
488+
FIRST_MEMORY_OPCODE,
489+
LD2post = FIRST_MEMORY_OPCODE,
489490
LD3post,
490491
LD4post,
491492
ST2post,
@@ -520,6 +521,7 @@ enum NodeType : unsigned {
520521
STP,
521522
STILP,
522523
STNP,
524+
LAST_MEMORY_OPCODE = STNP,
523525
};
524526

525527
} // end namespace AArch64ISD

llvm/lib/Target/AArch64/AArch64SelectionDAGInfo.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,26 @@ static cl::opt<bool>
2323
"to lower to librt functions"),
2424
cl::init(true));
2525

26+
bool AArch64SelectionDAGInfo::isTargetMemoryOpcode(unsigned Opcode) const {
27+
if (Opcode >= AArch64ISD::FIRST_MEMORY_OPCODE &&
28+
Opcode <= AArch64ISD::LAST_MEMORY_OPCODE)
29+
return true;
30+
return SelectionDAGTargetInfo::isTargetMemoryOpcode(Opcode);
31+
}
32+
33+
bool AArch64SelectionDAGInfo::isTargetStrictFPOpcode(unsigned Opcode) const {
34+
switch (static_cast<AArch64ISD::NodeType>(Opcode)) {
35+
default:
36+
break;
37+
case AArch64ISD::STRICT_FCMP:
38+
case AArch64ISD::STRICT_FCMPE:
39+
case AArch64ISD::SME_ZA_LDR:
40+
case AArch64ISD::SME_ZA_STR:
41+
return true;
42+
}
43+
return SelectionDAGTargetInfo::isTargetStrictFPOpcode(Opcode);
44+
}
45+
2646
SDValue AArch64SelectionDAGInfo::EmitMOPS(unsigned Opcode, SelectionDAG &DAG,
2747
const SDLoc &DL, SDValue Chain,
2848
SDValue Dst, SDValue SrcOrValue,

llvm/lib/Target/AArch64/AArch64SelectionDAGInfo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ namespace llvm {
1919

2020
class AArch64SelectionDAGInfo : public SelectionDAGTargetInfo {
2121
public:
22+
bool isTargetMemoryOpcode(unsigned Opcode) const override;
23+
24+
bool isTargetStrictFPOpcode(unsigned Opcode) const override;
25+
2226
SDValue EmitMOPS(unsigned Opcode, SelectionDAG &DAG, const SDLoc &DL,
2327
SDValue Chain, SDValue Dst, SDValue SrcOrValue, SDValue Size,
2428
Align Alignment, bool isVolatile,

0 commit comments

Comments
 (0)