Add #include to get alloca, patch by Kenneth Boyd!
[oota-llvm.git] / lib / CodeGen / LLVMTargetMachine.cpp
index 60925f31ddf0347a4b568ba328d95fefd5ddd92f..cd444552f7ac21aaa9edf5419e97d8c92c68d43a 100644 (file)
 #include "llvm/Support/raw_ostream.h"
 using namespace llvm;
 
+namespace llvm {
+  bool EnableFastISel;
+}
+
 static cl::opt<bool> PrintLSR("print-lsr-output", cl::Hidden,
     cl::desc("Print LLVM IR produced by the loop-reduce pass"));
 static cl::opt<bool> PrintISelInput("print-isel-input", cl::Hidden,
@@ -49,6 +53,16 @@ DisablePostRAScheduler("disable-post-RA-scheduler",
                        cl::desc("Disable scheduling after register allocation"),
                        cl::init(true));
 
+// Enable or disable FastISel. Both options are needed, because
+// FastISel is enabled by default with -fast, and we wish to be
+// able to enable or disable fast-isel independently from -fast.
+static cl::opt<bool>
+EnableFastISelOption("fast-isel", cl::Hidden,
+  cl::desc("Enable the experimental \"fast\" instruction selector"));
+static cl::opt<bool>
+DisableFastISelOption("disable-fast-isel", cl::Hidden,
+  cl::desc("Disable the experimental \"fast\" instruction selector"));
+
 FileModel::Model
 LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
                                        raw_ostream &Out,
@@ -67,7 +81,7 @@ LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
   if (addPreEmitPass(PM, Fast) && PrintMachineCode)
     PM.add(createMachineFunctionPrinterPass(cerr));
 
-  if (!Fast && !OptimizeForSize)
+  if (!Fast)
     PM.add(createLoopAlignerPass());
 
   switch (FileType) {
@@ -160,6 +174,13 @@ bool LLVMTargetMachine::addCommonCodeGenPasses(PassManagerBase &PM, bool Fast) {
 
   // Standard Lower-Level Passes.
 
+  // Enable FastISel with -fast, but allow that to be overridden.
+  assert((!EnableFastISelOption || !DisableFastISelOption) &&
+         "Both -fast-isel and -disable-fast-isel given!");
+  if (EnableFastISelOption ||
+      (Fast && !DisableFastISelOption))
+    EnableFastISel = true;
+
   // Ask the target for an isel.
   if (addInstSelector(PM, Fast))
     return true;
@@ -168,6 +189,10 @@ bool LLVMTargetMachine::addCommonCodeGenPasses(PassManagerBase &PM, bool Fast) {
   if (PrintMachineCode)
     PM.add(createMachineFunctionPrinterPass(cerr));
 
+  // If we're using Fast-ISel, clean up the mess.
+  if (EnableFastISel)
+    PM.add(createDeadMachineInstructionElimPass());
+
   if (EnableLICM)
     PM.add(createMachineLICMPass());