This is an archive of the discontinued LLVM Phabricator instance.

[TableGen] Make Record::getValueAsString and getValueAsListOfStrings return StringRefs instead of std::string
ClosedPublic

Authored by craig.topper on May 30 2017, 11:44 PM.

Details

Summary

Internally both these methods just return the result of getValue on either a StringInit or a CodeInit object. In both cases this returns a StringRef pointing to a string allocated in the BumpPtrAllocator so its not going anywhere. So we can just pass that StringRef along.

This is a fairly naive patch that targets just the build failures caused by this change. There's additional work that can be done to avoid creating std::string at call sites that still think getValueAsString returns a std::string. I'll try to clean those up in future patches.

Diff Detail

Event Timeline

craig.topper created this revision.May 30 2017, 11:44 PM
craig.topper added inline comments.
utils/TableGen/OptParserEmitter.cpp
57

This is a bit of a hack because the compare function expects a null terminated const char* array which the StringRef doesn't guarantee so I had to create a string first. This can be cleaned up in a future commit.

dblaikie accepted this revision.May 31 2017, 8:22 AM
dblaikie added inline comments.
utils/TableGen/OptParserEmitter.cpp
57

Please leave a FIXME unless you're planning to do this follow up soon.

This revision is now accepted and ready to land.May 31 2017, 8:22 AM