xiongji90 created this revision. Herald added a project: All. xiongji90 requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
llvm.get.rounding and llvm.set.rounding have been added to llvm and for llvm.get.rounding, a corresponding builtin "__builtin_flt_rounds" has been added but corresponding builtin for llvm.set.rounding has not been added. This patch aims to add builtin for set rounding behavior. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D144454 Files: clang/include/clang/Basic/Builtins.def clang/lib/CodeGen/CGBuiltin.cpp clang/test/CodeGen/builtins.c Index: clang/test/CodeGen/builtins.c =================================================================== --- clang/test/CodeGen/builtins.c +++ clang/test/CodeGen/builtins.c @@ -278,6 +278,9 @@ res = __builtin_flt_rounds(); // CHECK: call i32 @llvm.get.rounding( + + res = __builtin_flt_rounds_set(1); + // CHECK: call void @llvm.set.rounding( } // CHECK-LABEL: define{{.*}} void @test_float_builtin_ops Index: clang/lib/CodeGen/CGBuiltin.cpp =================================================================== --- clang/lib/CodeGen/CGBuiltin.cpp +++ clang/lib/CodeGen/CGBuiltin.cpp @@ -3361,6 +3361,14 @@ return RValue::get(Result); } + case Builtin::BI__builtin_flt_rounds_set: { + Function *F = CGM.getIntrinsic(Intrinsic::set_rounding); + + Value *V = EmitScalarExpr(E->getArg(0)); + Builder.CreateCall(F, V); + return RValue::get(nullptr); + } + case Builtin::BI__builtin_fpclassify: { CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E); // FIXME: for strictfp/IEEE-754 we need to not trap on SNaN here. Index: clang/include/clang/Basic/Builtins.def =================================================================== --- clang/include/clang/Basic/Builtins.def +++ clang/include/clang/Basic/Builtins.def @@ -392,6 +392,7 @@ // Access to floating point environment BUILTIN(__builtin_flt_rounds, "i", "n") +BUILTIN(__builtin_flt_rounds_set, "vi", "n") // C99 complex builtins BUILTIN(__builtin_cabs, "dXd", "Fne")
Index: clang/test/CodeGen/builtins.c =================================================================== --- clang/test/CodeGen/builtins.c +++ clang/test/CodeGen/builtins.c @@ -278,6 +278,9 @@ res = __builtin_flt_rounds(); // CHECK: call i32 @llvm.get.rounding( + + res = __builtin_flt_rounds_set(1); + // CHECK: call void @llvm.set.rounding( } // CHECK-LABEL: define{{.*}} void @test_float_builtin_ops Index: clang/lib/CodeGen/CGBuiltin.cpp =================================================================== --- clang/lib/CodeGen/CGBuiltin.cpp +++ clang/lib/CodeGen/CGBuiltin.cpp @@ -3361,6 +3361,14 @@ return RValue::get(Result); } + case Builtin::BI__builtin_flt_rounds_set: { + Function *F = CGM.getIntrinsic(Intrinsic::set_rounding); + + Value *V = EmitScalarExpr(E->getArg(0)); + Builder.CreateCall(F, V); + return RValue::get(nullptr); + } + case Builtin::BI__builtin_fpclassify: { CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E); // FIXME: for strictfp/IEEE-754 we need to not trap on SNaN here. Index: clang/include/clang/Basic/Builtins.def =================================================================== --- clang/include/clang/Basic/Builtins.def +++ clang/include/clang/Basic/Builtins.def @@ -392,6 +392,7 @@ // Access to floating point environment BUILTIN(__builtin_flt_rounds, "i", "n") +BUILTIN(__builtin_flt_rounds_set, "vi", "n") // C99 complex builtins BUILTIN(__builtin_cabs, "dXd", "Fne")
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits