This is both more efficient and more ergonomic than going
through an std::string, e.g. when using llvm::utostr and
in string concat cases.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
What about just having the twine format given StringRef converts to twine implicitly and there is the getSingleStringRef method that should avoid extra overhead?
I'm open to that, only two downsides I can think of:
- absolutely tiny additional runtime overhead, slight codebloat for making the temporary twine. I'm not concerned about this.
- additional header depedency for everything that uses these methods, they'd have to include twine.h. This may already be happening implicitly though.
BuiltinAttributes.h already includes Twine.h transitively, Identifier.h doesn't. Though I would suspect that many uses of Identifier.h also bring in Twine.h through some other means.
Simplify the API for Identifier::get and StringAttr::get to always take Twines.
River pointed out that Twine is effectively pervasive already, so we might as well
just use it.
mlir/lib/IR/MLIRContext.cpp | ||
---|---|---|
758 | nit: Spell out auto here. |
mlir/lib/IR/MLIRContext.cpp | ||
---|---|---|
758 | I'm a bit puzzled by this change: this is pessimizing all the clients code that have a string already formed and were able to just pass a StringRef. I feel that Twine is justified when an API may not have to materialize the string, otherwise in most cases you better hoist everything in the caller and keep the StringRef case fast (especially when it is the common case) |
mlir/lib/IR/MLIRContext.cpp | ||
---|---|---|
758 | What is your concern here? If you pass in something stringref compatible "toStringRef" will do the right thing, it doesn't add a copy of the data into tempStr unless needed. |
mlir/lib/IR/MLIRContext.cpp | ||
---|---|---|
758 | Ohhhh I didn't know about this toStringRef behavior! I thought the copy always happened... |
mlir/lib/IR/MLIRContext.cpp | ||
---|---|---|
758 | Nope! The vector is only there in case it is necessary, it isn't filled in if not. |
nit: Spell out auto here.