From 31db28601be3de19ec039044335d50208a2e6cba Mon Sep 17 00:00:00 2001 From: hjk Date: Fri, 24 Jun 2022 12:29:42 +0200 Subject: [PATCH] CPlusPlus: Use a global variable for the undefined type instance ... and split the FullySpecifiedType in two overloads. Initially: 29 [1] FullySpecifiedType::FullySpecifiedType(Type *type) : <+ 24> 41 54 push %r12 <+ 26> 55 push %rbp 34 [1] static UndefinedType t; <+ 27> 48 8b 2d 26 68 13 00 mov 0x136826(%rip),%rbp 29 [1] FullySpecifiedType::FullySpecifiedType(Type *type) : <+ 34> 53 push %rbx <+ 35> 48 89 fb mov %rdi,%rbx 34 [1] static UndefinedType t; <+ 38> 0f b6 45 00 movzbl 0x0(%rbp),%eax <+ 42> 84 c0 test %al,%al <+ 44> 74 12 je 0x7fffc135c620 <_ZN9CPlusPlus18FullySpecifiedTypeC2EPNS_4TypeE+64> <+ 46> 4c 8b 25 5b 66 13 00 mov 0x13665b(%rip),%r12 35 [1] return &t; <+ 53> 4c 89 23 mov %r12,(%rbx) 34 [1] } <+ 56> 5b pop %rbx <+ 57> 5d pop %rbp <+ 58> 41 5c pop %r12 <+ 60> c3 ret After making it a global variable: 29 [1] FullySpecifiedType::FullySpecifiedType(Type *type) : f3 0f 1e fa endbr64 30 [1] _type(type), _flags(0) <+ 4> c7 47 08 00 00 00 00 movl $0x0,0x8(%rdi) 32 [1] if (! type) <+ 11> 48 85 f6 test %rsi,%rsi <+ 14> 74 08 je 0x7fffc14675f8 <_ZN9CPlusPlus18FullySpecifiedTypeC2EPNS_4TypeE+24> <+ 16> 48 89 37 mov %rsi,(%rdi) 34 [1] } <+ 19> c3 ret <+ 20> 0f 1f 40 00 nopl 0x0(%rax) 33 [1] _type = &UndefinedType::instance; <+ 24> 48 8b 35 49 67 13 00 mov 0x136749(%rip),%rsi # 0x7fffc159dd48 <+ 31> 48 89 37 mov %rsi,(%rdi) 34 [1] } <+ 34> c3 ret The no-parameters branch after splitting: 29 [1] FullySpecifiedType::FullySpecifiedType() : f3 0f 1e fa endbr64 30 [1] _type(&UndefinedType::instance), _flags(0) <+ 4> 48 8b 05 5d 67 13 00 mov 0x13675d(%rip),%rax # 0x7fffc159dd48 <+ 11> c7 47 08 00 00 00 00 movl $0x0,0x8(%rdi) <+ 18> 48 89 07 mov %rax,(%rdi) 31 [1] {} <+ 21> c3 ret Change-Id: I61439d68921cf9fa422304033b75de16bb4aa0d5 Reviewed-by: Christian Kandeler --- src/libs/3rdparty/cplusplus/CoreTypes.cpp | 7 +++++-- src/libs/3rdparty/cplusplus/CoreTypes.h | 6 +----- src/libs/3rdparty/cplusplus/FullySpecifiedType.cpp | 10 +++++++--- src/libs/3rdparty/cplusplus/FullySpecifiedType.h | 3 ++- src/libs/3rdparty/cplusplus/Type.cpp | 2 +- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/libs/3rdparty/cplusplus/CoreTypes.cpp b/src/libs/3rdparty/cplusplus/CoreTypes.cpp index 0561f660584..4519eabc036 100644 --- a/src/libs/3rdparty/cplusplus/CoreTypes.cpp +++ b/src/libs/3rdparty/cplusplus/CoreTypes.cpp @@ -21,10 +21,11 @@ #include "CoreTypes.h" #include "TypeVisitor.h" #include "Matcher.h" -#include "Names.h" #include -using namespace CPlusPlus; +namespace CPlusPlus { + +UndefinedType UndefinedType::instance; void UndefinedType::accept0(TypeVisitor *visitor) { visitor->visit(this); } @@ -204,3 +205,5 @@ bool NamedType::match0(const Type *otherType, Matcher *matcher) const return false; } + +} // CPlusPlus diff --git a/src/libs/3rdparty/cplusplus/CoreTypes.h b/src/libs/3rdparty/cplusplus/CoreTypes.h index 0db1dd81837..5f2c30e89c6 100644 --- a/src/libs/3rdparty/cplusplus/CoreTypes.h +++ b/src/libs/3rdparty/cplusplus/CoreTypes.h @@ -29,11 +29,7 @@ namespace CPlusPlus { class CPLUSPLUS_EXPORT UndefinedType : public Type { public: - static UndefinedType *instance() - { - static UndefinedType t; - return &t; - } + static UndefinedType instance; const UndefinedType *asUndefinedType() const override { return this; } diff --git a/src/libs/3rdparty/cplusplus/FullySpecifiedType.cpp b/src/libs/3rdparty/cplusplus/FullySpecifiedType.cpp index 7333f306296..27be623821b 100644 --- a/src/libs/3rdparty/cplusplus/FullySpecifiedType.cpp +++ b/src/libs/3rdparty/cplusplus/FullySpecifiedType.cpp @@ -26,15 +26,19 @@ using namespace CPlusPlus; +FullySpecifiedType::FullySpecifiedType() : + _type(&UndefinedType::instance), _flags(0) +{} + FullySpecifiedType::FullySpecifiedType(Type *type) : _type(type), _flags(0) { if (! type) - _type = UndefinedType::instance(); + _type = &UndefinedType::instance; } bool FullySpecifiedType::isValid() const -{ return _type != UndefinedType::instance(); } +{ return _type != &UndefinedType::instance; } FullySpecifiedType FullySpecifiedType::qualifiedType() const @@ -170,7 +174,7 @@ Type &FullySpecifiedType::operator*() { return *_type; } FullySpecifiedType::operator bool() const -{ return _type != UndefinedType::instance(); } +{ return _type != &UndefinedType::instance; } const Type &FullySpecifiedType::operator*() const { return *_type; } diff --git a/src/libs/3rdparty/cplusplus/FullySpecifiedType.h b/src/libs/3rdparty/cplusplus/FullySpecifiedType.h index ec54b8bdd98..03f82b788ea 100644 --- a/src/libs/3rdparty/cplusplus/FullySpecifiedType.h +++ b/src/libs/3rdparty/cplusplus/FullySpecifiedType.h @@ -28,7 +28,8 @@ namespace CPlusPlus { class CPLUSPLUS_EXPORT FullySpecifiedType final { public: - FullySpecifiedType(Type *type = nullptr); + FullySpecifiedType(); + FullySpecifiedType(Type *type); ~FullySpecifiedType() = default; bool isValid() const; diff --git a/src/libs/3rdparty/cplusplus/Type.cpp b/src/libs/3rdparty/cplusplus/Type.cpp index e9b0f2d3c17..00e84b0a61c 100644 --- a/src/libs/3rdparty/cplusplus/Type.cpp +++ b/src/libs/3rdparty/cplusplus/Type.cpp @@ -33,7 +33,7 @@ Type::~Type() { } bool Type::isUndefinedType() const -{ return this == UndefinedType::instance(); } +{ return this == &UndefinedType::instance; } bool Type::isVoidType() const { return asVoidType() != nullptr; }