I've been looking into IR code which is specified using SSA- especially, generating LLVM IR in this form. However, I'm confused about whether or not this can be effective when presented with a type which has non-trivial copy semantics. For example,
void f() {
std::string s = "Too long for you, short string optimization!";
std::string s1 = s + " Also, goodbye SSA.";
some_other_function(s1);
}
In this SSA form, at least at the most obvious level, this results in a nasty mess of copies (even for C++). Can optimizers such as LLVM's actually optimize this case accurately? Is SSA viable for use even for types with non-trivial copy/assignment/etc semantics?
Edit: The question is that if I use an LLVM SSA register to represent a complex type (in this case, std:string
), here represented by manually making it SSA, can LLVM automatically translate this into a mutating +=
call in the underlying assembly in the general case and avoid a nasty copy?