@@ -89,16 +89,19 @@ class IRBuilderCallbackInserter : public IRBuilderDefaultInserter {
8989
9090// / This provides a helper for copying FMF from an instruction or setting
9191// / specified flags.
92- struct FMFSource final {
93- Instruction *Source;
92+ class FMFSource {
9493 std::optional<FastMathFlags> FMF;
9594
96- FMFSource () : Source(nullptr ) {}
97- FMFSource (Instruction *Source) : Source(Source) {
95+ public:
96+ FMFSource () = default ;
97+ FMFSource (Instruction *Source) {
9898 if (Source)
9999 FMF = Source->getFastMathFlags ();
100100 }
101- FMFSource (FastMathFlags FMF) : Source(nullptr ), FMF(FMF) {}
101+ FMFSource (FastMathFlags FMF) : FMF(FMF) {}
102+ FastMathFlags get (FastMathFlags Default) const {
103+ return FMF.value_or (Default);
104+ }
102105};
103106
104107// / Common base class shared among various IRBuilders.
@@ -1575,11 +1578,11 @@ class IRBuilderBase {
15751578 return CreateConstrainedFPBinOp (Intrinsic::experimental_constrained_fadd,
15761579 L, R, FMFSource, Name, FPMD);
15771580
1578- if (Value *V = Folder. FoldBinOpFMF (Instruction::FAdd, L, R,
1579- FMFSource.FMF . value_or (FMF)))
1581+ if (Value *V =
1582+ Folder. FoldBinOpFMF (Instruction::FAdd, L, R, FMFSource.get (FMF)))
15801583 return V;
1581- Instruction *I = setFPAttrs ( BinaryOperator::CreateFAdd (L, R), FPMD,
1582- FMFSource.FMF . value_or (FMF));
1584+ Instruction *I =
1585+ setFPAttrs ( BinaryOperator::CreateFAdd (L, R), FPMD, FMFSource.get (FMF));
15831586 return Insert (I, Name);
15841587 }
15851588
@@ -1594,11 +1597,11 @@ class IRBuilderBase {
15941597 return CreateConstrainedFPBinOp (Intrinsic::experimental_constrained_fsub,
15951598 L, R, FMFSource, Name, FPMD);
15961599
1597- if (Value *V = Folder. FoldBinOpFMF (Instruction::FSub, L, R,
1598- FMFSource.FMF . value_or (FMF)))
1600+ if (Value *V =
1601+ Folder. FoldBinOpFMF (Instruction::FSub, L, R, FMFSource.get (FMF)))
15991602 return V;
1600- Instruction *I = setFPAttrs ( BinaryOperator::CreateFSub (L, R), FPMD,
1601- FMFSource.FMF . value_or (FMF));
1603+ Instruction *I =
1604+ setFPAttrs ( BinaryOperator::CreateFSub (L, R), FPMD, FMFSource.get (FMF));
16021605 return Insert (I, Name);
16031606 }
16041607
@@ -1613,11 +1616,11 @@ class IRBuilderBase {
16131616 return CreateConstrainedFPBinOp (Intrinsic::experimental_constrained_fmul,
16141617 L, R, FMFSource, Name, FPMD);
16151618
1616- if (Value *V = Folder. FoldBinOpFMF (Instruction::FMul, L, R,
1617- FMFSource.FMF . value_or (FMF)))
1619+ if (Value *V =
1620+ Folder. FoldBinOpFMF (Instruction::FMul, L, R, FMFSource.get (FMF)))
16181621 return V;
1619- Instruction *I = setFPAttrs ( BinaryOperator::CreateFMul (L, R), FPMD,
1620- FMFSource.FMF . value_or (FMF));
1622+ Instruction *I =
1623+ setFPAttrs ( BinaryOperator::CreateFMul (L, R), FPMD, FMFSource.get (FMF));
16211624 return Insert (I, Name);
16221625 }
16231626
@@ -1632,11 +1635,11 @@ class IRBuilderBase {
16321635 return CreateConstrainedFPBinOp (Intrinsic::experimental_constrained_fdiv,
16331636 L, R, FMFSource, Name, FPMD);
16341637
1635- if (Value *V = Folder. FoldBinOpFMF (Instruction::FDiv, L, R,
1636- FMFSource.FMF . value_or (FMF)))
1638+ if (Value *V =
1639+ Folder. FoldBinOpFMF (Instruction::FDiv, L, R, FMFSource.get (FMF)))
16371640 return V;
1638- Instruction *I = setFPAttrs ( BinaryOperator::CreateFDiv (L, R), FPMD,
1639- FMFSource.FMF . value_or (FMF));
1641+ Instruction *I =
1642+ setFPAttrs ( BinaryOperator::CreateFDiv (L, R), FPMD, FMFSource.get (FMF));
16401643 return Insert (I, Name);
16411644 }
16421645
@@ -1651,11 +1654,11 @@ class IRBuilderBase {
16511654 return CreateConstrainedFPBinOp (Intrinsic::experimental_constrained_frem,
16521655 L, R, FMFSource, Name, FPMD);
16531656
1654- if (Value *V = Folder. FoldBinOpFMF (Instruction::FRem, L, R,
1655- FMFSource.FMF . value_or (FMF)))
1657+ if (Value *V =
1658+ Folder. FoldBinOpFMF (Instruction::FRem, L, R, FMFSource.get (FMF)))
16561659 return V;
1657- Instruction *I = setFPAttrs ( BinaryOperator::CreateFRem (L, R), FPMD,
1658- FMFSource.FMF . value_or (FMF));
1660+ Instruction *I =
1661+ setFPAttrs ( BinaryOperator::CreateFRem (L, R), FPMD, FMFSource.get (FMF));
16591662 return Insert (I, Name);
16601663 }
16611664
@@ -1672,7 +1675,7 @@ class IRBuilderBase {
16721675 return V;
16731676 Instruction *BinOp = BinaryOperator::Create (Opc, LHS, RHS);
16741677 if (isa<FPMathOperator>(BinOp))
1675- setFPAttrs (BinOp, FPMathTag, FMFSource.FMF . value_or (FMF));
1678+ setFPAttrs (BinOp, FPMathTag, FMFSource.get (FMF));
16761679 return Insert (BinOp, Name);
16771680 }
16781681
@@ -1737,12 +1740,12 @@ class IRBuilderBase {
17371740
17381741 Value *CreateFNegFMF (Value *V, FMFSource FMFSource, const Twine &Name = " " ,
17391742 MDNode *FPMathTag = nullptr ) {
1740- if (Value *Res = Folder. FoldUnOpFMF (Instruction::FNeg, V,
1741- FMFSource.FMF . value_or (FMF)))
1743+ if (Value *Res =
1744+ Folder. FoldUnOpFMF (Instruction::FNeg, V, FMFSource.get (FMF)))
17421745 return Res;
1743- return Insert (setFPAttrs ( UnaryOperator::CreateFNeg (V), FPMathTag,
1744- FMFSource.FMF . value_or (FMF)),
1745- Name);
1746+ return Insert (
1747+ setFPAttrs ( UnaryOperator::CreateFNeg (V), FPMathTag, FMFSource.get (FMF)),
1748+ Name);
17461749 }
17471750
17481751 Value *CreateNot (Value *V, const Twine &Name = " " ) {
@@ -2183,7 +2186,7 @@ class IRBuilderBase {
21832186 return Folded;
21842187 Instruction *Cast = CastInst::Create (Op, V, DestTy);
21852188 if (isa<FPMathOperator>(Cast))
2186- setFPAttrs (Cast, FPMathTag, FMFSource.FMF . value_or (FMF));
2189+ setFPAttrs (Cast, FPMathTag, FMFSource.get (FMF));
21872190 return Insert (Cast, Name);
21882191 }
21892192
0 commit comments