This is an archive of the discontinued LLVM Phabricator instance.

CodeGen: Emit string literal in constant address space
ClosedPublic

Authored by yaxunl on May 9 2018, 8:53 AM.

Details

Summary

Some targets have constant address space (e.g. amdgcn). For them string literal should be
emitted in constant address space then casted to default address space.

Diff Detail

Event Timeline

The part about string literals looks fine, but:

lib/CodeGen/CGDecl.cpp
1375

I don't understand why a patch about string literals is changing auto variable emission.

yaxunl marked an inline comment as done.May 9 2018, 12:04 PM
yaxunl added inline comments.
lib/CodeGen/CGDecl.cpp
1375

It is a bug about alloca revealed by the lit test

char l_array[] = "l_array";

Loc contains the alloca casted to default address space, therefore it needs to be casted back to alloca address space here, otherwise CreateBitCast returns invalid bitcast. Unlike lifetime.start, memcpy does not require alloca address space, so an alternative fix is to let BP take address space of Loc.

rjmccall added inline comments.May 10 2018, 8:41 AM
lib/CodeGen/CGDecl.cpp
1375

Yeah, I think using the address space of Loc is more appropriate.

yaxunl updated this revision to Diff 146468.May 12 2018, 4:51 AM
yaxunl marked an inline comment as done.

Revised by John's comments. Also refactored to extract common code.

rjmccall added inline comments.May 14 2018, 9:51 AM
lib/CodeGen/CGDecl.cpp
1373

CGM.Int8Ty exists.

lib/CodeGen/CodeGenModule.cpp
3077

This should really just be a static function in this file.

yaxunl updated this revision to Diff 146647.May 14 2018, 11:11 AM
yaxunl marked 2 inline comments as done.

Revised by John's comments.

rjmccall accepted this revision.May 14 2018, 11:45 AM

Thanks, LGTM.

This revision is now accepted and ready to land.May 14 2018, 11:45 AM
This revision was automatically updated to reflect the committed changes.