@@ -78,11 +78,11 @@ void IRBuilderBase::SetInstDebugLocation(Instruction *I) const {
7878
7979CallInst *
8080IRBuilderBase::createCallHelper (Function *Callee, ArrayRef<Value *> Ops,
81- const Twine &Name, Instruction * FMFSource,
81+ const Twine &Name, FMFSource FMFSource,
8282 ArrayRef<OperandBundleDef> OpBundles) {
8383 CallInst *CI = CreateCall (Callee, Ops, OpBundles, Name);
84- if (FMFSource )
85- CI->copyFastMathFlags (FMFSource);
84+ if (isa<FPMathOperator>(CI) )
85+ CI->setFastMathFlags (FMFSource. get (FMF) );
8686 return CI;
8787}
8888
@@ -869,28 +869,28 @@ CallInst *IRBuilderBase::CreateGCGetPointerOffset(Value *DerivedPtr,
869869}
870870
871871CallInst *IRBuilderBase::CreateUnaryIntrinsic (Intrinsic::ID ID, Value *V,
872- Instruction * FMFSource,
872+ FMFSource FMFSource,
873873 const Twine &Name) {
874874 Module *M = BB->getModule ();
875875 Function *Fn = Intrinsic::getOrInsertDeclaration (M, ID, {V->getType ()});
876876 return createCallHelper (Fn, {V}, Name, FMFSource);
877877}
878878
879879Value *IRBuilderBase::CreateBinaryIntrinsic (Intrinsic::ID ID, Value *LHS,
880- Value *RHS, Instruction * FMFSource,
880+ Value *RHS, FMFSource FMFSource,
881881 const Twine &Name) {
882882 Module *M = BB->getModule ();
883883 Function *Fn = Intrinsic::getOrInsertDeclaration (M, ID, {LHS->getType ()});
884884 if (Value *V = Folder.FoldBinaryIntrinsic (ID, LHS, RHS, Fn->getReturnType (),
885- FMFSource))
885+ /* FMFSource= */ nullptr ))
886886 return V;
887887 return createCallHelper (Fn, {LHS, RHS}, Name, FMFSource);
888888}
889889
890890CallInst *IRBuilderBase::CreateIntrinsic (Intrinsic::ID ID,
891891 ArrayRef<Type *> Types,
892892 ArrayRef<Value *> Args,
893- Instruction * FMFSource,
893+ FMFSource FMFSource,
894894 const Twine &Name) {
895895 Module *M = BB->getModule ();
896896 Function *Fn = Intrinsic::getOrInsertDeclaration (M, ID, Types);
@@ -899,7 +899,7 @@ CallInst *IRBuilderBase::CreateIntrinsic(Intrinsic::ID ID,
899899
900900CallInst *IRBuilderBase::CreateIntrinsic (Type *RetTy, Intrinsic::ID ID,
901901 ArrayRef<Value *> Args,
902- Instruction * FMFSource,
902+ FMFSource FMFSource,
903903 const Twine &Name) {
904904 Module *M = BB->getModule ();
905905
@@ -925,16 +925,13 @@ CallInst *IRBuilderBase::CreateIntrinsic(Type *RetTy, Intrinsic::ID ID,
925925}
926926
927927CallInst *IRBuilderBase::CreateConstrainedFPBinOp (
928- Intrinsic::ID ID, Value *L, Value *R, Instruction *FMFSource,
929- const Twine &Name, MDNode *FPMathTag,
930- std::optional<RoundingMode> Rounding,
928+ Intrinsic::ID ID, Value *L, Value *R, FMFSource FMFSource,
929+ const Twine &Name, MDNode *FPMathTag, std::optional<RoundingMode> Rounding,
931930 std::optional<fp::ExceptionBehavior> Except) {
932931 Value *RoundingV = getConstrainedFPRounding (Rounding);
933932 Value *ExceptV = getConstrainedFPExcept (Except);
934933
935- FastMathFlags UseFMF = FMF;
936- if (FMFSource)
937- UseFMF = FMFSource->getFastMathFlags ();
934+ FastMathFlags UseFMF = FMFSource.get (FMF);
938935
939936 CallInst *C = CreateIntrinsic (ID, {L->getType ()},
940937 {L, R, RoundingV, ExceptV}, nullptr , Name);
@@ -944,14 +941,12 @@ CallInst *IRBuilderBase::CreateConstrainedFPBinOp(
944941}
945942
946943CallInst *IRBuilderBase::CreateConstrainedFPUnroundedBinOp (
947- Intrinsic::ID ID, Value *L, Value *R, Instruction * FMFSource,
944+ Intrinsic::ID ID, Value *L, Value *R, FMFSource FMFSource,
948945 const Twine &Name, MDNode *FPMathTag,
949946 std::optional<fp::ExceptionBehavior> Except) {
950947 Value *ExceptV = getConstrainedFPExcept (Except);
951948
952- FastMathFlags UseFMF = FMF;
953- if (FMFSource)
954- UseFMF = FMFSource->getFastMathFlags ();
949+ FastMathFlags UseFMF = FMFSource.get (FMF);
955950
956951 CallInst *C =
957952 CreateIntrinsic (ID, {L->getType ()}, {L, R, ExceptV}, nullptr , Name);
@@ -976,15 +971,12 @@ Value *IRBuilderBase::CreateNAryOp(unsigned Opc, ArrayRef<Value *> Ops,
976971}
977972
978973CallInst *IRBuilderBase::CreateConstrainedFPCast (
979- Intrinsic::ID ID, Value *V, Type *DestTy,
980- Instruction *FMFSource, const Twine &Name, MDNode *FPMathTag,
981- std::optional<RoundingMode> Rounding,
974+ Intrinsic::ID ID, Value *V, Type *DestTy, FMFSource FMFSource,
975+ const Twine &Name, MDNode *FPMathTag, std::optional<RoundingMode> Rounding,
982976 std::optional<fp::ExceptionBehavior> Except) {
983977 Value *ExceptV = getConstrainedFPExcept (Except);
984978
985- FastMathFlags UseFMF = FMF;
986- if (FMFSource)
987- UseFMF = FMFSource->getFastMathFlags ();
979+ FastMathFlags UseFMF = FMFSource.get (FMF);
988980
989981 CallInst *C;
990982 if (Intrinsic::hasConstrainedFPRoundingModeOperand (ID)) {
@@ -1002,9 +994,10 @@ CallInst *IRBuilderBase::CreateConstrainedFPCast(
1002994 return C;
1003995}
1004996
1005- Value *IRBuilderBase::CreateFCmpHelper (
1006- CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name,
1007- MDNode *FPMathTag, bool IsSignaling) {
997+ Value *IRBuilderBase::CreateFCmpHelper (CmpInst::Predicate P, Value *LHS,
998+ Value *RHS, const Twine &Name,
999+ MDNode *FPMathTag, FMFSource FMFSource,
1000+ bool IsSignaling) {
10081001 if (IsFPConstrained) {
10091002 auto ID = IsSignaling ? Intrinsic::experimental_constrained_fcmps
10101003 : Intrinsic::experimental_constrained_fcmp;
@@ -1013,7 +1006,9 @@ Value *IRBuilderBase::CreateFCmpHelper(
10131006
10141007 if (auto *V = Folder.FoldCmp (P, LHS, RHS))
10151008 return V;
1016- return Insert (setFPAttrs (new FCmpInst (P, LHS, RHS), FPMathTag, FMF), Name);
1009+ return Insert (
1010+ setFPAttrs (new FCmpInst (P, LHS, RHS), FPMathTag, FMFSource.get (FMF)),
1011+ Name);
10171012}
10181013
10191014CallInst *IRBuilderBase::CreateConstrainedFPCmp (
@@ -1047,6 +1042,12 @@ CallInst *IRBuilderBase::CreateConstrainedFPCall(
10471042
10481043Value *IRBuilderBase::CreateSelect (Value *C, Value *True, Value *False,
10491044 const Twine &Name, Instruction *MDFrom) {
1045+ return CreateSelectFMF (C, True, False, {}, Name, MDFrom);
1046+ }
1047+
1048+ Value *IRBuilderBase::CreateSelectFMF (Value *C, Value *True, Value *False,
1049+ FMFSource FMFSource, const Twine &Name,
1050+ Instruction *MDFrom) {
10501051 if (auto *V = Folder.FoldSelect (C, True, False))
10511052 return V;
10521053
@@ -1057,7 +1058,7 @@ Value *IRBuilderBase::CreateSelect(Value *C, Value *True, Value *False,
10571058 Sel = addBranchMetadata (Sel, Prof, Unpred);
10581059 }
10591060 if (isa<FPMathOperator>(Sel))
1060- setFPAttrs (Sel, nullptr /* MDNode* */ , FMF);
1061+ setFPAttrs (Sel, /* MDNode= */ nullptr , FMFSource. get ( FMF) );
10611062 return Insert (Sel, Name);
10621063}
10631064
0 commit comments