@@ -331,6 +331,27 @@ class SelectionDAG {
331331 virtual void anchor ();
332332 };
333333
334+ // / Help to insert SDNodeFlags automatically in transforming. Use
335+ // / RAII to save and resume flags in current scope.
336+ class FlagInserter {
337+ SelectionDAG &DAG;
338+ SDNodeFlags Flags;
339+ FlagInserter *LastInserter;
340+
341+ public:
342+ FlagInserter (SelectionDAG &SDAG, SDNode *N)
343+ : DAG(SDAG), Flags(N->getFlags ()),
344+ LastInserter(SDAG.getFlagInserter()) {
345+ SDAG.setFlagInserter (this );
346+ }
347+
348+ FlagInserter (const FlagInserter &) = delete;
349+ FlagInserter &operator =(const FlagInserter &) = delete ;
350+ ~FlagInserter () { DAG.setFlagInserter (LastInserter); }
351+
352+ const SDNodeFlags getFlags () const { return Flags; }
353+ };
354+
334355 // / When true, additional steps are taken to
335356 // / ensure that getConstant() and similar functions return DAG nodes that
336357 // / have legal types. This is important after type legalization since
@@ -433,6 +454,9 @@ class SelectionDAG {
433454 ProfileSummaryInfo *getPSI () const { return PSI; }
434455 BlockFrequencyInfo *getBFI () const { return BFI; }
435456
457+ FlagInserter *getFlagInserter () { return Inserter; }
458+ void setFlagInserter (FlagInserter *FI) { Inserter = FI; }
459+
436460 // / Just dump dot graph to a user-provided path and title.
437461 // / This doesn't open the dot viewer program and
438462 // / helps visualization when outside debugging session.
@@ -945,21 +969,31 @@ class SelectionDAG {
945969 SDValue getNode (unsigned Opcode, const SDLoc &DL, EVT VT,
946970 ArrayRef<SDUse> Ops);
947971 SDValue getNode (unsigned Opcode, const SDLoc &DL, EVT VT,
948- ArrayRef<SDValue> Ops, const SDNodeFlags Flags = SDNodeFlags() );
972+ ArrayRef<SDValue> Ops, const SDNodeFlags Flags);
949973 SDValue getNode (unsigned Opcode, const SDLoc &DL, ArrayRef<EVT> ResultTys,
950974 ArrayRef<SDValue> Ops);
951975 SDValue getNode (unsigned Opcode, const SDLoc &DL, SDVTList VTList,
952- ArrayRef<SDValue> Ops, const SDNodeFlags Flags = SDNodeFlags());
976+ ArrayRef<SDValue> Ops, const SDNodeFlags Flags);
977+
978+ // Use flags from current flag inserter.
979+ SDValue getNode (unsigned Opcode, const SDLoc &DL, EVT VT,
980+ ArrayRef<SDValue> Ops);
981+ SDValue getNode (unsigned Opcode, const SDLoc &DL, SDVTList VTList,
982+ ArrayRef<SDValue> Ops);
983+ SDValue getNode (unsigned Opcode, const SDLoc &DL, EVT VT, SDValue Operand);
984+ SDValue getNode (unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1,
985+ SDValue N2);
986+ SDValue getNode (unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1,
987+ SDValue N2, SDValue N3);
953988
954989 // Specialize based on number of operands.
955990 SDValue getNode (unsigned Opcode, const SDLoc &DL, EVT VT);
956991 SDValue getNode (unsigned Opcode, const SDLoc &DL, EVT VT, SDValue Operand,
957- const SDNodeFlags Flags = SDNodeFlags() );
992+ const SDNodeFlags Flags);
958993 SDValue getNode (unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1,
959- SDValue N2, const SDNodeFlags Flags = SDNodeFlags() );
994+ SDValue N2, const SDNodeFlags Flags);
960995 SDValue getNode (unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1,
961- SDValue N2, SDValue N3,
962- const SDNodeFlags Flags = SDNodeFlags());
996+ SDValue N2, SDValue N3, const SDNodeFlags Flags);
963997 SDValue getNode (unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1,
964998 SDValue N2, SDValue N3, SDValue N4);
965999 SDValue getNode (unsigned Opcode, const SDLoc &DL, EVT VT, SDValue N1,
@@ -1469,8 +1503,10 @@ class SelectionDAG {
14691503 SDValue Operand, SDValue Subreg);
14701504
14711505 // / Get the specified node if it's already available, or else return NULL.
1472- SDNode *getNodeIfExists (unsigned Opcode, SDVTList VTList, ArrayRef<SDValue> Ops,
1473- const SDNodeFlags Flags = SDNodeFlags());
1506+ SDNode *getNodeIfExists (unsigned Opcode, SDVTList VTList,
1507+ ArrayRef<SDValue> Ops, const SDNodeFlags Flags);
1508+ SDNode *getNodeIfExists (unsigned Opcode, SDVTList VTList,
1509+ ArrayRef<SDValue> Ops);
14741510
14751511 // / Creates a SDDbgValue node.
14761512 SDDbgValue *getDbgValue (DIVariable *Var, DIExpression *Expr, SDNode *N,
@@ -1999,6 +2035,8 @@ class SelectionDAG {
19992035
20002036 std::map<std::pair<std::string, unsigned >, SDNode *> TargetExternalSymbols;
20012037 DenseMap<MCSymbol *, SDNode *> MCSymbols;
2038+
2039+ FlagInserter *Inserter = nullptr ;
20022040};
20032041
20042042template <> struct GraphTraits <SelectionDAG*> : public GraphTraits<SDNode*> {
0 commit comments