From 9b4e458bd7a31b288e5c944cd27419a7f434367e Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 27 Nov 2018 23:29:15 +0000 Subject: compiler: record final type for numeric expressions Inlinable function bodies are generated after the determine_types pass, so we know the type for all constants. Rather than try to determine it again when inlining, record the type in the export data, using a $convert expression. Reduce the number of explicit $convert expressions by recording a type context with the expected type in cases where that type is known. Reviewed-on: https://go-review.googlesource.com/c/150071 From-SVN: r266534 --- gcc/go/gofrontend/export.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'gcc/go/gofrontend/export.h') diff --git a/gcc/go/gofrontend/export.h b/gcc/go/gofrontend/export.h index 3cbf8e1..69fbd6e 100644 --- a/gcc/go/gofrontend/export.h +++ b/gcc/go/gofrontend/export.h @@ -303,7 +303,7 @@ class Export_function_body : public String_dump { public: Export_function_body(Export* exp, int indent) - : exp_(exp), indent_(indent) + : exp_(exp), type_context_(NULL), indent_(indent) { } // Write a character to the body. @@ -326,6 +326,16 @@ class Export_function_body : public String_dump write_type(const Type* type) { this->exp_->write_type_to(type, this); } + // Return the current type context. + Type* + type_context() const + { return this->type_context_; } + + // Set the current type context. + void + set_type_context(Type* type) + { this->type_context_ = type; } + // Append as many spaces as the current indentation level. void indent() @@ -354,6 +364,8 @@ class Export_function_body : public String_dump Export* exp_; // The body we are building. std::string body_; + // Current type context. Used to avoid duplicate type conversions. + Type* type_context_; // Current indentation level: the number of spaces before each statement. int indent_; }; -- cgit v1.1