This is an archive of the discontinued LLVM Phabricator instance.

Add _LIBCPP_BUILTIN_CONSTANT_P support.
ClosedPublic

Authored by mvels on Jan 30 2020, 11:20 AM.

Details

Summary

This change adds the macros _LIBCPP_COMPILER_HAS_BUILTIN_CONSTANT_P and _LIBCPP_BUILTIN_CONSTANT_P to detect compile time constants, and optimze the code accordingly.

A planned usage example:
The implementation of basic_string::assign() can short-cut a compile time known short string assignent into a fast and compact inlined assignment:

basic_string::assign(const value_type* __s) {
  if (_LIBCPP_BUILTIN_CONSTANT_P(__s[0]) && length(__s) < __min_cap) {
    copy(pointer(), _s, length(__s) + 1);
    set_size(length(__s));
  } else {
    // delegate / tail call out of line implementation
  }
}

Diff Detail

Event Timeline

mvels created this revision.Jan 30 2020, 11:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 30 2020, 11:20 AM
mvels edited the summary of this revision. (Show Details)Jan 30 2020, 11:21 AM
mvels added a reviewer: EricWF.
EricWF accepted this revision.Feb 23 2020, 5:34 PM
EricWF added inline comments.
libcxx/include/__config
546

Just put this in the same block as the other feature check for the same version.

This revision is now accepted and ready to land.Feb 23 2020, 5:34 PM
mvels updated this revision to Diff 246728.Feb 26 2020, 7:44 AM
mvels marked an inline comment as done.

Combined ifdef block for GNUC_VER

This revision was automatically updated to reflect the committed changes.