@@ -78,11 +78,11 @@ void IRBuilderBase::SetInstDebugLocation(Instruction *I) const {
78
78
79
79
CallInst *
80
80
IRBuilderBase::createCallHelper (Function *Callee, ArrayRef<Value *> Ops,
81
- const Twine &Name, Instruction * FMFSource,
81
+ const Twine &Name, FMFSource FMFSource,
82
82
ArrayRef<OperandBundleDef> OpBundles) {
83
83
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) );
86
86
return CI;
87
87
}
88
88
@@ -869,28 +869,28 @@ CallInst *IRBuilderBase::CreateGCGetPointerOffset(Value *DerivedPtr,
869
869
}
870
870
871
871
CallInst *IRBuilderBase::CreateUnaryIntrinsic (Intrinsic::ID ID, Value *V,
872
- Instruction * FMFSource,
872
+ FMFSource FMFSource,
873
873
const Twine &Name) {
874
874
Module *M = BB->getModule ();
875
875
Function *Fn = Intrinsic::getOrInsertDeclaration (M, ID, {V->getType ()});
876
876
return createCallHelper (Fn, {V}, Name, FMFSource);
877
877
}
878
878
879
879
Value *IRBuilderBase::CreateBinaryIntrinsic (Intrinsic::ID ID, Value *LHS,
880
- Value *RHS, Instruction * FMFSource,
880
+ Value *RHS, FMFSource FMFSource,
881
881
const Twine &Name) {
882
882
Module *M = BB->getModule ();
883
883
Function *Fn = Intrinsic::getOrInsertDeclaration (M, ID, {LHS->getType ()});
884
884
if (Value *V = Folder.FoldBinaryIntrinsic (ID, LHS, RHS, Fn->getReturnType (),
885
- FMFSource))
885
+ /* FMFSource= */ nullptr ))
886
886
return V;
887
887
return createCallHelper (Fn, {LHS, RHS}, Name, FMFSource);
888
888
}
889
889
890
890
CallInst *IRBuilderBase::CreateIntrinsic (Intrinsic::ID ID,
891
891
ArrayRef<Type *> Types,
892
892
ArrayRef<Value *> Args,
893
- Instruction * FMFSource,
893
+ FMFSource FMFSource,
894
894
const Twine &Name) {
895
895
Module *M = BB->getModule ();
896
896
Function *Fn = Intrinsic::getOrInsertDeclaration (M, ID, Types);
@@ -899,7 +899,7 @@ CallInst *IRBuilderBase::CreateIntrinsic(Intrinsic::ID ID,
899
899
900
900
CallInst *IRBuilderBase::CreateIntrinsic (Type *RetTy, Intrinsic::ID ID,
901
901
ArrayRef<Value *> Args,
902
- Instruction * FMFSource,
902
+ FMFSource FMFSource,
903
903
const Twine &Name) {
904
904
Module *M = BB->getModule ();
905
905
@@ -925,16 +925,13 @@ CallInst *IRBuilderBase::CreateIntrinsic(Type *RetTy, Intrinsic::ID ID,
925
925
}
926
926
927
927
CallInst *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,
931
930
std::optional<fp::ExceptionBehavior> Except) {
932
931
Value *RoundingV = getConstrainedFPRounding (Rounding);
933
932
Value *ExceptV = getConstrainedFPExcept (Except);
934
933
935
- FastMathFlags UseFMF = FMF;
936
- if (FMFSource)
937
- UseFMF = FMFSource->getFastMathFlags ();
934
+ FastMathFlags UseFMF = FMFSource.get (FMF);
938
935
939
936
CallInst *C = CreateIntrinsic (ID, {L->getType ()},
940
937
{L, R, RoundingV, ExceptV}, nullptr , Name);
@@ -944,14 +941,12 @@ CallInst *IRBuilderBase::CreateConstrainedFPBinOp(
944
941
}
945
942
946
943
CallInst *IRBuilderBase::CreateConstrainedFPUnroundedBinOp (
947
- Intrinsic::ID ID, Value *L, Value *R, Instruction * FMFSource,
944
+ Intrinsic::ID ID, Value *L, Value *R, FMFSource FMFSource,
948
945
const Twine &Name, MDNode *FPMathTag,
949
946
std::optional<fp::ExceptionBehavior> Except) {
950
947
Value *ExceptV = getConstrainedFPExcept (Except);
951
948
952
- FastMathFlags UseFMF = FMF;
953
- if (FMFSource)
954
- UseFMF = FMFSource->getFastMathFlags ();
949
+ FastMathFlags UseFMF = FMFSource.get (FMF);
955
950
956
951
CallInst *C =
957
952
CreateIntrinsic (ID, {L->getType ()}, {L, R, ExceptV}, nullptr , Name);
@@ -976,15 +971,12 @@ Value *IRBuilderBase::CreateNAryOp(unsigned Opc, ArrayRef<Value *> Ops,
976
971
}
977
972
978
973
CallInst *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,
982
976
std::optional<fp::ExceptionBehavior> Except) {
983
977
Value *ExceptV = getConstrainedFPExcept (Except);
984
978
985
- FastMathFlags UseFMF = FMF;
986
- if (FMFSource)
987
- UseFMF = FMFSource->getFastMathFlags ();
979
+ FastMathFlags UseFMF = FMFSource.get (FMF);
988
980
989
981
CallInst *C;
990
982
if (Intrinsic::hasConstrainedFPRoundingModeOperand (ID)) {
@@ -1002,9 +994,10 @@ CallInst *IRBuilderBase::CreateConstrainedFPCast(
1002
994
return C;
1003
995
}
1004
996
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) {
1008
1001
if (IsFPConstrained) {
1009
1002
auto ID = IsSignaling ? Intrinsic::experimental_constrained_fcmps
1010
1003
: Intrinsic::experimental_constrained_fcmp;
@@ -1013,7 +1006,9 @@ Value *IRBuilderBase::CreateFCmpHelper(
1013
1006
1014
1007
if (auto *V = Folder.FoldCmp (P, LHS, RHS))
1015
1008
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);
1017
1012
}
1018
1013
1019
1014
CallInst *IRBuilderBase::CreateConstrainedFPCmp (
@@ -1047,6 +1042,12 @@ CallInst *IRBuilderBase::CreateConstrainedFPCall(
1047
1042
1048
1043
Value *IRBuilderBase::CreateSelect (Value *C, Value *True, Value *False,
1049
1044
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) {
1050
1051
if (auto *V = Folder.FoldSelect (C, True, False))
1051
1052
return V;
1052
1053
@@ -1057,7 +1058,7 @@ Value *IRBuilderBase::CreateSelect(Value *C, Value *True, Value *False,
1057
1058
Sel = addBranchMetadata (Sel, Prof, Unpred);
1058
1059
}
1059
1060
if (isa<FPMathOperator>(Sel))
1060
- setFPAttrs (Sel, nullptr /* MDNode* */ , FMF);
1061
+ setFPAttrs (Sel, /* MDNode= */ nullptr , FMFSource. get ( FMF) );
1061
1062
return Insert (Sel, Name);
1062
1063
}
1063
1064
0 commit comments