Merge "Fix stack overflow errors." into ics-mr1-plus-art
diff --git a/src/compiler_llvm/compilation_unit.cc b/src/compiler_llvm/compilation_unit.cc
index 32f1786..b976fd2 100644
--- a/src/compiler_llvm/compilation_unit.cc
+++ b/src/compiler_llvm/compilation_unit.cc
@@ -204,7 +204,7 @@
   llvm::TargetMachine* target_machine =
     target->createTargetMachine(target_triple, "", target_attr, target_options,
                                 llvm::Reloc::Static, llvm::CodeModel::Small,
-                                llvm::CodeGenOpt::None);
+                                llvm::CodeGenOpt::Less);
 
   CHECK(target_machine != NULL) << "Failed to create target machine";
 
@@ -220,6 +220,14 @@
   llvm::FunctionPassManager fpm(module_);
   fpm.add(new llvm::TargetData(*target_data));
 
+  // Add optimization pass
+  llvm::PassManagerBuilder pm_builder;
+  pm_builder.Inliner = NULL; // TODO: add some inline in the future
+  pm_builder.OptLevel = 1;
+  pm_builder.DisableSimplifyLibCalls = 1;
+  pm_builder.populateModulePassManager(pm);
+  pm_builder.populateFunctionPassManager(fpm);
+
   // Add passes to emit ELF image
   {
     llvm::formatted_raw_ostream formatted_os(
@@ -237,6 +245,14 @@
     // Add pass to update the frame_size_in_bytes_
     pm.add(new ::UpdateFrameSizePass(this));
 
+    // Run the per-function optimization
+    fpm.doInitialization();
+    for (llvm::Module::iterator F = module_->begin(), E = module_->end();
+         F != E; ++F) {
+      fpm.run(*F);
+    }
+    fpm.doFinalization();
+
     // Run the code generation passes
     pm.run(*module_);
   }
diff --git a/src/compiler_llvm/compiler_llvm.cc b/src/compiler_llvm/compiler_llvm.cc
index c890003..443950d 100644
--- a/src/compiler_llvm/compiler_llvm.cc
+++ b/src/compiler_llvm/compiler_llvm.cc
@@ -42,11 +42,12 @@
   extern bool TimePassesIsEnabled;
 }
 
-extern llvm::cl::opt<bool> ReserveR9;
-// ReserveR9 is defined in llvm/lib/Target/ARM/ARMSubtarget.cpp
-extern llvm::cl::opt<bool> EnableARMLongCalls;
 // NOTE: Although EnableARMLongCalls is defined in llvm/lib/Target/ARM/
 // ARMISelLowering.cpp, however, it is not in the llvm namespace.
+extern llvm::cl::opt<bool> EnableARMLongCalls;
+
+// ReserveR9 is defined in llvm/lib/Target/ARM/ARMSubtarget.cpp
+extern llvm::cl::opt<bool> ReserveR9;
 
 
 namespace {
@@ -68,7 +69,7 @@
   // TODO: Maybe we don't have to initialize "all" targets.
 
   // Enable -arm-long-calls
-  EnableARMLongCalls = true;
+  EnableARMLongCalls = false;
 
   // Initialize LLVM optimization passes
   llvm::PassRegistry &registry = *llvm::PassRegistry::getPassRegistry();