I fixed it with this:<br><br><a href="http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20081020/008482.html">http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20081020/008482.html</a><br><br><br><div class="gmail_quote">
On Fri, Oct 24, 2008 at 9:56 AM, Zhongxing Xu <span dir="ltr"><<a href="mailto:xuzhongxing@gmail.com">xuzhongxing@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I got the following linking error.<br><br>llvm[1]: Linking Debug executable clang<br>/home/xing/llvm/tools/clang/Driver/Debug/Backend.o: In function `(anonymous namespace)::BackendConsumer::CreatePasses()':<br>/home/xing/llvm/tools/clang/Driver/Backend.cpp:245: undefined reference to `llvm::createRaiseAllocationsPass()'<br>

/home/xing/llvm/tools/clang/Driver/Backend.cpp:249: undefined reference to `llvm::createGlobalOptimizerPass()'<br>/home/xing/llvm/tools/clang/Driver/Backend.cpp:250: undefined reference to `llvm::createGlobalDCEPass()'<br>

/home/xing/llvm/tools/clang/Driver/Backend.cpp:251: undefined reference to `llvm::createIPConstantPropagationPass()'<br>/home/xing/llvm/tools/clang/Driver/Backend.cpp:252: undefined reference to `llvm::createDeadArgEliminationPass()'<br>

/home/xing/llvm/tools/clang/Driver/Backend.cpp:257: undefined reference to `llvm::createPruneEHPass()'<br>/home/xing/llvm/tools/clang/Driver/Backend.cpp:258: undefined reference to `llvm::createAddReadAttrsPass()'<br>

/home/xing/llvm/tools/clang/Driver/Backend.cpp:261: undefined reference to `llvm::createFunctionInliningPass()'<br>/home/xing/llvm/tools/clang/Driver/Backend.cpp:263: undefined reference to `llvm::createAlwaysInlinerPass()'<br>

/home/xing/llvm/tools/clang/Driver/Backend.cpp:265: undefined reference to `llvm::createArgumentPromotionPass(unsigned int)'<br>/home/xing/llvm/tools/clang/Driver/Backend.cpp:300: undefined reference to `llvm::createStripDeadPrototypesPass()'<br>

/home/xing/llvm/tools/clang/Driver/Backend.cpp:301: undefined reference to `llvm::createDeadTypeEliminationPass()'<br>/home/xing/llvm/tools/clang/Driver/Backend.cpp:305: undefined reference to `llvm::createConstantMergePass()'<br>

/home/xing/llvm/tools/clang/Driver/Backend.cpp:307: undefined reference to `llvm::createAlwaysInlinerPass()'<br>collect2: ld returned 1 exit status<br>make[1]: *** [/home/xing/llvm/Debug//bin/clang] error 1<br>make[1]: Leaving directory `/home/xing/llvm/tools/clang/Driver'<br>

make: *** [all] error 1<div><div></div><div class="Wj3C7c"><br><br><br><div class="gmail_quote">On Thu, Oct 23, 2008 at 1:50 PM, Daniel Dunbar <span dir="ltr"><<a href="mailto:daniel@zuster.org" target="_blank">daniel@zuster.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Author: ddunbar<br>
Date: Thu Oct 23 00:50:47 2008<br>
New Revision: 58034<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=58034&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=58034&view=rev</a><br>
Log:<br>
Add -O[0-3s] support (following llvm-gcc).<br>
 - Passes match llvm-gcc but many of the switches aren't wired.<br>
<br>
Added:<br>
    cfe/trunk/include/clang/Driver/CompileOptions.h<br>
Modified:<br>
    cfe/trunk/Driver/ASTConsumers.h<br>
    cfe/trunk/Driver/Backend.cpp<br>
    cfe/trunk/Driver/clang.cpp<br>
<br>
Modified: cfe/trunk/Driver/ASTConsumers.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.h?rev=58034&r1=58033&r2=58034&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.h?rev=58034&r1=58033&r2=58034&view=diff</a><br>


<br>
==============================================================================<br>
--- cfe/trunk/Driver/ASTConsumers.h (original)<br>
+++ cfe/trunk/Driver/ASTConsumers.h Thu Oct 23 00:50:47 2008<br>
@@ -27,9 +27,10 @@<br>
 class ASTConsumer;<br>
 class Diagnostic;<br>
 class FileManager;<br>
-struct LangOptions;<br>
 class Preprocessor;<br>
 class PreprocessorFactory;<br>
+struct CompileOptions;<br>
+struct LangOptions;<br>
<br>
 ASTConsumer *CreateASTPrinter(llvm::raw_ostream* OS = NULL);<br>
<br>
@@ -50,6 +51,7 @@<br>
 ASTConsumer *CreateBackendConsumer(BackendAction Action,<br>
                                    Diagnostic &Diags,<br>
                                    const LangOptions &Features,<br>
+                                   const CompileOptions &CompileOpts,<br>
                                    const std::string& InFile,<br>
                                    const std::string& OutFile,<br>
                                    bool GenerateDebugInfo);<br>
<br>
Modified: cfe/trunk/Driver/Backend.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/Backend.cpp?rev=58034&r1=58033&r2=58034&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/Backend.cpp?rev=58034&r1=58033&r2=58034&view=diff</a><br>


<br>
==============================================================================<br>
--- cfe/trunk/Driver/Backend.cpp (original)<br>
+++ cfe/trunk/Driver/Backend.cpp Thu Oct 23 00:50:47 2008<br>
@@ -14,11 +14,14 @@<br>
 #include "clang/AST/TranslationUnit.h"<br>
 #include "clang/Basic/TargetInfo.h"<br>
 #include "clang/CodeGen/ModuleBuilder.h"<br>
+#include "clang/Driver/CompileOptions.h"<br>
 #include "llvm/Module.h"<br>
 #include "llvm/ModuleProvider.h"<br>
 #include "llvm/PassManager.h"<br>
 #include "llvm/ADT/OwningPtr.h"<br>
 #include "llvm/Assembly/PrintModulePass.h"<br>
+#include "llvm/Analysis/CallGraph.h"<br>
+#include "llvm/Analysis/Verifier.h"<br>
 #include "llvm/Bitcode/ReaderWriter.h"<br>
 #include "llvm/CodeGen/RegAllocRegistry.h"<br>
 #include "llvm/CodeGen/SchedulerRegistry.h"<br>
@@ -30,6 +33,8 @@<br>
 #include "llvm/Target/TargetData.h"<br>
 #include "llvm/Target/TargetMachine.h"<br>
 #include "llvm/Target/TargetMachineRegistry.h"<br>
+#include "llvm/Transforms/Scalar.h"<br>
+#include "llvm/Transforms/IPO.h"<br>
 #include <fstream> // FIXME: Remove<br>
<br>
 using namespace clang;<br>
@@ -38,6 +43,7 @@<br>
 namespace {<br>
   class VISIBILITY_HIDDEN BackendConsumer  : public ASTConsumer {<br>
     BackendAction Action;<br>
+    CompileOptions CompileOpts;<br>
     const std::string &InputFile;<br>
     std::string OutputFile;<br>
     llvm::OwningPtr<CodeGenerator> Gen;<br>
@@ -70,10 +76,11 @@<br>
<br>
   public:<br>
     BackendConsumer(BackendAction action, Diagnostic &Diags,<br>
-                    const LangOptions &Features,<br>
+                    const LangOptions &Features, const CompileOptions &compopts,<br>
                     const std::string& infile, const std::string& outfile,<br>
                     bool GenerateDebugInfo)  :<br>
       Action(action),<br>
+      CompileOpts(compopts),<br>
       InputFile(infile),<br>
       OutputFile(outfile),<br>
       Gen(CreateLLVMCodeGen(Diags, Features, InputFile, GenerateDebugInfo)),<br>
@@ -218,7 +225,88 @@<br>
 }<br>
<br>
 void BackendConsumer::CreatePasses() {<br>
-<br>
+  // In -O0 if checking is disabled, we don't even have per-function passes.<br>
+  if (CompileOpts.VerifyModule)<br>
+    getPerFunctionPasses()->add(createVerifierPass());<br>
+<br>
+  if (CompileOpts.OptimizationLevel > 0) {<br>
+    FunctionPassManager *PM = getPerFunctionPasses();<br>
+    PM->add(createCFGSimplificationPass());<br>
+    if (CompileOpts.OptimizationLevel == 1)<br>
+      PM->add(createPromoteMemoryToRegisterPass());<br>
+    else<br>
+      PM->add(createScalarReplAggregatesPass());<br>
+    PM->add(createInstructionCombiningPass());<br>
+  }<br>
+<br>
+  // For now we always create per module passes.<br>
+  PassManager *PM = getPerModulePasses();<br>
+  if (CompileOpts.OptimizationLevel > 0) {<br>
+    if (CompileOpts.UnitAtATime)<br>
+      PM->add(createRaiseAllocationsPass());      // call %malloc -> malloc inst<br>
+    PM->add(createCFGSimplificationPass());       // Clean up disgusting code<br>
+    PM->add(createPromoteMemoryToRegisterPass()); // Kill useless allocas<br>
+    if (CompileOpts.UnitAtATime) {<br>
+      PM->add(createGlobalOptimizerPass());       // Optimize out global vars<br>
+      PM->add(createGlobalDCEPass());             // Remove unused fns and globs<br>
+      PM->add(createIPConstantPropagationPass()); // IP Constant Propagation<br>
+      PM->add(createDeadArgEliminationPass());    // Dead argument elimination<br>
+    }<br>
+    PM->add(createInstructionCombiningPass());    // Clean up after IPCP & DAE<br>
+    PM->add(createCFGSimplificationPass());       // Clean up after IPCP & DAE<br>
+    if (CompileOpts.UnitAtATime) {<br>
+      PM->add(createPruneEHPass());               // Remove dead EH info<br>
+      PM->add(createAddReadAttrsPass());          // Set readonly/readnone attrs<br>
+    }<br>
+    if (CompileOpts.InlineFunctions)<br>
+      PM->add(createFunctionInliningPass());      // Inline small functions<br>
+    else<br>
+      PM->add(createAlwaysInlinerPass());         // Respect always_inline<br>
+    if (CompileOpts.OptimizationLevel > 2)<br>
+      PM->add(createArgumentPromotionPass());     // Scalarize uninlined fn args<br>
+    if (CompileOpts.SimplifyLibCalls)<br>
+      PM->add(createSimplifyLibCallsPass());      // Library Call Optimizations<br>
+    PM->add(createInstructionCombiningPass());    // Cleanup for scalarrepl.<br>
+    PM->add(createJumpThreadingPass());           // Thread jumps.<br>
+    PM->add(createCFGSimplificationPass());       // Merge & remove BBs<br>
+    PM->add(createScalarReplAggregatesPass());    // Break up aggregate allocas<br>
+    PM->add(createInstructionCombiningPass());    // Combine silly seq's<br>
+    PM->add(createCondPropagationPass());         // Propagate conditionals<br>
+    PM->add(createTailCallEliminationPass());     // Eliminate tail calls<br>
+    PM->add(createCFGSimplificationPass());       // Merge & remove BBs<br>
+    PM->add(createReassociatePass());             // Reassociate expressions<br>
+    PM->add(createLoopRotatePass());              // Rotate Loop<br>
+    PM->add(createLICMPass());                    // Hoist loop invariants<br>
+    PM->add(createLoopUnswitchPass(CompileOpts.OptimizeSize ? true : false));<br>
+    PM->add(createLoopIndexSplitPass());          // Split loop index<br>
+    PM->add(createInstructionCombiningPass());<br>
+    PM->add(createIndVarSimplifyPass());          // Canonicalize indvars<br>
+    PM->add(createLoopDeletionPass());            // Delete dead loops<br>
+    if (CompileOpts.UnrollLoops)<br>
+      PM->add(createLoopUnrollPass());            // Unroll small loops<br>
+    PM->add(createInstructionCombiningPass());    // Clean up after the unroller<br>
+    PM->add(createGVNPass());                     // Remove redundancies<br>
+    PM->add(createMemCpyOptPass());               // Remove memcpy / form memset<br>
+    PM->add(createSCCPPass());                    // Constant prop with SCCP<br>
+<br>
+    // Run instcombine after redundancy elimination to exploit opportunities<br>
+    // opened up by them.<br>
+    PM->add(createInstructionCombiningPass());<br>
+    PM->add(createCondPropagationPass());         // Propagate conditionals<br>
+    PM->add(createDeadStoreEliminationPass());    // Delete dead stores<br>
+    PM->add(createAggressiveDCEPass());           // Delete dead instructions<br>
+    PM->add(createCFGSimplificationPass());       // Merge & remove BBs<br>
+<br>
+    if (CompileOpts.UnitAtATime) {<br>
+      PM->add(createStripDeadPrototypesPass());   // Get rid of dead prototypes<br>
+      PM->add(createDeadTypeEliminationPass());   // Eliminate dead types<br>
+    }<br>
+<br>
+    if (CompileOpts.OptimizationLevel > 1 && CompileOpts.UnitAtATime)<br>
+      PM->add(createConstantMergePass());         // Merge dup global constants<br>
+  } else {<br>
+    PerModulePasses->add(createAlwaysInlinerPass());<br>
+  }<br>
 }<br>
<br>
 /// EmitAssembly - Handle interaction with LLVM backend to generate<br>
@@ -275,9 +363,10 @@<br>
 ASTConsumer *clang::CreateBackendConsumer(BackendAction Action,<br>
                                           Diagnostic &Diags,<br>
                                           const LangOptions &Features,<br>
+                                          const CompileOptions &CompileOpts,<br>
                                           const std::string& InFile,<br>
                                           const std::string& OutFile,<br>
                                           bool GenerateDebugInfo) {<br>
-  return new BackendConsumer(Action, Diags, Features, InFile, OutFile,<br>
-                             GenerateDebugInfo);<br>
+  return new BackendConsumer(Action, Diags, Features, CompileOpts,<br>
+                             InFile, OutFile, GenerateDebugInfo);<br>
 }<br>
<br>
Modified: cfe/trunk/Driver/clang.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.cpp?rev=58034&r1=58033&r2=58034&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.cpp?rev=58034&r1=58033&r2=58034&view=diff</a><br>


<br>
==============================================================================<br>
--- cfe/trunk/Driver/clang.cpp (original)<br>
+++ cfe/trunk/Driver/clang.cpp Thu Oct 23 00:50:47 2008<br>
@@ -24,6 +24,7 @@<br>
<br>
 #include "clang.h"<br>
 #include "ASTConsumers.h"<br>
+#include "clang/Driver/CompileOptions.h"<br>
 #include "clang/Driver/HTMLDiagnostics.h"<br>
 #include "clang/Driver/InitHeaderSearch.h"<br>
 #include "clang/Driver/TextDiagnosticBuffer.h"<br>
@@ -1084,6 +1085,37 @@<br>
 }<br>
<br>
 //===----------------------------------------------------------------------===//<br>
+// Code generation options<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+static llvm::cl::opt<bool><br>
+OptSize("Os",<br>
+       llvm::cl::desc("Optimize for size"));<br>
+<br>
+// It might be nice to add bounds to the CommandLine library directly.<br>
+struct OptLevelParser : public llvm::cl::parser<unsigned> {<br>
+  bool parse(llvm::cl::Option &O, const char *ArgName,<br>
+             const std::string &Arg, unsigned &Val) {<br>
+    if (llvm::cl::parser<unsigned>::parse(O, ArgName, Arg, Val))<br>
+      return true;<br>
+    // FIXME: Support -O4.<br>
+    if (Val > 3)<br>
+      return O.error(": '" + Arg + "' invalid optimization level!");<br>
+    return false;<br>
+  }<br>
+};<br>
+static llvm::cl::opt<unsigned, false, OptLevelParser><br>
+OptLevel("O", llvm::cl::Prefix,<br>
+         llvm::cl::desc("Optimization level"),<br>
+         llvm::cl::init(0));<br>
+<br>
+static void InitializeCompileOptions(CompileOptions &Opts) {<br>
+  Opts.OptimizationLevel = OptLevel;<br>
+  Opts.OptimizeSize = OptSize;<br>
+  // FIXME: Wire other options.<br>
+}<br>
+<br>
+//===----------------------------------------------------------------------===//<br>
 // Main driver<br>
 //===----------------------------------------------------------------------===//<br>
<br>
@@ -1115,14 +1147,21 @@<br>
       return CreateSerializationTest(Diag, FileMgr);<br>
<br>
     case EmitAssembly:<br>
-      return CreateBackendConsumer(Backend_EmitAssembly, Diag, LangOpts,<br>
-                                   InFile, OutputFile, GenerateDebugInfo);<br>
     case EmitLLVM:<br>
-      return CreateBackendConsumer(Backend_EmitLL, Diag, LangOpts,<br>
-                                   InFile, OutputFile, GenerateDebugInfo);<br>
-    case EmitBC:<br>
-      return CreateBackendConsumer(Backend_EmitBC, Diag, LangOpts,<br>
+    case EmitBC: {<br>
+      BackendAction Act;<br>
+      if (ProgAction == EmitAssembly) {<br>
+        Act = Backend_EmitAssembly;<br>
+      } else if (ProgAction == EmitLLVM) {<br>
+        Act = Backend_EmitLL;<br>
+      } else {<br>
+        Act = Backend_EmitBC;<br>
+      }<br>
+      CompileOptions Opts;<br>
+      InitializeCompileOptions(Opts);<br>
+      return CreateBackendConsumer(Act, Diag, LangOpts, Opts,<br>
                                    InFile, OutputFile, GenerateDebugInfo);<br>
+    }<br>
<br>
     case SerializeAST:<br>
       // FIXME: Allow user to tailor where the file is written.<br>
<br>
Added: cfe/trunk/include/clang/Driver/CompileOptions.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CompileOptions.h?rev=58034&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CompileOptions.h?rev=58034&view=auto</a><br>


<br>
==============================================================================<br>
--- cfe/trunk/include/clang/Driver/CompileOptions.h (added)<br>
+++ cfe/trunk/include/clang/Driver/CompileOptions.h Thu Oct 23 00:50:47 2008<br>
@@ -0,0 +1,45 @@<br>
+//===--- CompileOptions.h ---------------------------------------*- C++ -*-===//<br>
+//<br>
+//                     The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+//<br>
+//  This file defines the CompileOptions interface.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#ifndef LLVM_CLANG_COMPILEOPTIONS_H<br>
+#define LLVM_CLANG_COMPILEOPTIONS_H<br>
+<br>
+namespace clang {<br>
+<br>
+/// CompileOptions - Track various options which control how the code<br>
+/// is optimized and passed to the backend.<br>
+struct CompileOptions {<br>
+  unsigned OptimizationLevel : 3; /// The -O[0-4] option specified.<br>
+  unsigned OptimizeSize      : 1; /// If -Os is specified.<br>
+  unsigned UnitAtATime       : 1; /// Unused. For mirroring GCC<br>
+                                  /// optimization selection.<br>
+  unsigned InlineFunctions   : 1; /// Should functions be inlined?<br>
+  unsigned SimplifyLibCalls  : 1; /// Should standard library calls be<br>
+                                  /// treated specially.<br>
+  unsigned UnrollLoops       : 1; /// Control whether loops are unrolled.<br>
+  unsigned VerifyModule      : 1; /// Control whether the module<br>
+                                  /// should be run through the LLVM Verifier.<br>
+<br>
+public:<br>
+  CompileOptions() {<br>
+    OptimizationLevel = 0;<br>
+    OptimizeSize = 0;<br>
+    UnitAtATime = InlineFunctions = SimplifyLibCalls = 1;<br>
+    UnrollLoops = 1;<br>
+    VerifyModule = 1;<br>
+  }<br>
+};<br>
+<br>
+}  // end namespace clang<br>
+<br>
+#endif<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br>
</div></div></blockquote></div><br>