Add builtins for basic float operations (#3897)

Adds support for unary `-` and binary `+`, `-`, `*`, `/` for floating
point types.

Real literals are now transformed to `llvm::APFloat`s during the check
phase into the `FloatLiteral` instruction.

This PR likely collides a bit with #3892 and might need to be updated
when that one is merged.
This commit is contained in:
Pablo Paglilla
2024-04-19 22:50:54 +00:00
committed by GitHub
parent db324c7247
commit cae62765af
43 changed files with 1550 additions and 93 deletions
@@ -19,7 +19,7 @@ fn F() {
// CHECK:STDOUT: --- fail_param_type.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %.1: f64 = real_literal 10e-1 [template]
// CHECK:STDOUT: %.1: f64 = float_literal 1 [template]
// CHECK:STDOUT: %.2: type = tuple_type () [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
@@ -45,7 +45,7 @@ fn F() {
// CHECK:STDOUT: fn @F() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %G.ref: <function> = name_ref G, file.%G [template = file.%G]
// CHECK:STDOUT: %.loc16: f64 = real_literal 10e-1 [template = constants.%.1]
// CHECK:STDOUT: %.loc16: f64 = float_literal 1 [template = constants.%.1]
// CHECK:STDOUT: %G.call: init () = call %G.ref(<invalid>) [template = <error>]
// CHECK:STDOUT: return
// CHECK:STDOUT: }
@@ -16,7 +16,7 @@ fn Run() {
// CHECK:STDOUT: --- fail_return_type_mismatch.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %.1: f64 = real_literal 10e-1 [template]
// CHECK:STDOUT: %.1: f64 = float_literal 1 [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
@@ -34,7 +34,7 @@ fn Run() {
// CHECK:STDOUT:
// CHECK:STDOUT: fn @Foo() -> f64 {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %.loc7: f64 = real_literal 10e-1 [template = constants.%.1]
// CHECK:STDOUT: %.loc7: f64 = float_literal 1 [template = constants.%.1]
// CHECK:STDOUT: return %.loc7
// CHECK:STDOUT: }
// CHECK:STDOUT: