[cfe-commits] Patch to change how const arrays/structs are handled
Tanya Lattner
lattner at apple.com
Thu Oct 22 14:22:42 PDT 2009
On Oct 21, 2009, at 4:12 PM, Douglas Gregor wrote:
>
> On Oct 21, 2009, at 2:10 PM, Tanya Lattner wrote:
>
>> Hi. I'd like to get a review of my patch that takes const arrays
>> and structs (unions, classes, etc) and creates a global instead of
>> storing it to the stack (treating it like a static const, for
>> performance reasons).
>>
>> Please let me know if you have questions.
>
> Index: lib/CodeGen/CGDecl.cpp
> ===================================================================
> --- lib/CodeGen/CGDecl.cpp (revision 84777)
> +++ lib/CodeGen/CGDecl.cpp (working copy)
> @@ -316,6 +316,14 @@
> llvm::Value *DeclPtr;
> if (Ty->isConstantSizeType()) {
> if (!Target.useGlobalsForAutomaticVariables()) {
> +
> + // All constant structs and arrays should be global.
> + if (Ty.isConstant(getContext())
> + && (isa<ArrayType>(Ty) || isa<RecordType>(Ty))) {
> + EmitStaticBlockVarDecl(D);
> + return;
> + }
> +
>
> This looks too aggressive. There are more conditions that need to be
> checked before we can perform this optimization, e.g.,
>
> (1) Is the initializer constant?
> (2) In C++, is the type/element type of the array a POD?
>
Ok, made these changes.
> There are probably other conditions; for example, we might not want
> to perform this optimization if the address of the variable is ever
> taken.
>
Ok, I don't understand why address taken should matter if it is
declared const. Am I missing something?
Thanks,
Tanya
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20091022/fca5bf76/attachment.html>
More information about the cfe-commits
mailing list