[cfe-commits] [PATCH] merging constants

Douglas Gregor dgregor at apple.com
Fri Oct 30 13:46:41 PDT 2009


On Oct 29, 2009, at 4:02 PM, Tanya Lattner wrote:

> Revised patch (after much discussion) 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 review :)


Thanks for the updated patch. Some comments below; feel free to commit  
once they are addressed.

Index: include/clang/Basic/LangOptions.h
===================================================================
--- include/clang/Basic/LangOptions.h	(revision 85520)
+++ include/clang/Basic/LangOptions.h	(working copy)
@@ -88,6 +88,8 @@

    unsigned ElideConstructors : 1; // Whether C++ copy constructors  
should be
                                    // elided if possible.
+  unsigned MergeAllConstants : 1; // Merge identical constants.
+


This optimization only affects code generation (not language  
semantics), so the MergeAllConstants flag should go into  
CompileOptions (include/clang/Frontend/CompileOptions.h) rather than  
LangOptions. That means you won't have to change the PCH format at all  
(yay).

Index: tools/clang-cc/clang-cc.cpp
===================================================================
--- tools/clang-cc/clang-cc.cpp	(revision 85520)
+++ tools/clang-cc/clang-cc.cpp	(working copy)
@@ -655,6 +656,10 @@
  NoElideConstructors("fno-elide-constructors",
                      llvm::cl::desc("Disable C++ copy constructor  
elision"));

+static llvm::cl::opt<bool>
+NoMergeConstants("fno-merge-all-constants",
+                       llvm::cl::desc("Disallow merging of  
constants."));
+

This adds the appropriate flag to clang-cc. You'll also need to add  
support into the clang driver, which otherwise won't pass the -fno- 
merge-all-constants flag on to clang-cc, and you'll get a warning like  
this:

	dgregor$ clang -fno-merge-all-constants wonky.cpp
	clang: warning: argument unused during compilation: '-fno-merge-all- 
constants'

The driver's options are in include/clang/Driver/Options.def; you will  
probably also need to tweak the Clang tool support to propagate the  
option in lib/Driver.

	- Doug



More information about the cfe-commits mailing list