[llvm-commits] CVS: llvm/lib/CodeGen/Passes.cpp RegAllocLinearScan.cpp RegAllocLocal.cpp RegAllocSimple.cpp

Jim Laskey jlaskey at apple.com
Tue Aug 1 07:21:49 PDT 2006



Changes in directory llvm/lib/CodeGen:

Passes.cpp updated: 1.18 -> 1.19
RegAllocLinearScan.cpp updated: 1.125 -> 1.126
RegAllocLocal.cpp updated: 1.83 -> 1.84
RegAllocSimple.cpp updated: 1.70 -> 1.71
---
Log message:

Introducing plugable register allocators and instruction schedulers.


---
Diffs of the changes:  (+31 -57)

 Passes.cpp             |   71 +++++++++----------------------------------------
 RegAllocLinearScan.cpp |    5 +++
 RegAllocLocal.cpp      |    7 ++++
 RegAllocSimple.cpp     |    5 +++
 4 files changed, 31 insertions(+), 57 deletions(-)


Index: llvm/lib/CodeGen/Passes.cpp
diff -u llvm/lib/CodeGen/Passes.cpp:1.18 llvm/lib/CodeGen/Passes.cpp:1.19
--- llvm/lib/CodeGen/Passes.cpp:1.18	Thu Jul 27 15:05:00 2006
+++ llvm/lib/CodeGen/Passes.cpp	Tue Aug  1 09:21:23 2006
@@ -12,74 +12,31 @@
 //
 //===---------------------------------------------------------------------===//
 
+#include "llvm/CodeGen/MachinePassRegistry.h"
 #include "llvm/CodeGen/Passes.h"
-#include "llvm/Pass.h"
 #include "llvm/Support/CommandLine.h"
 #include <iostream>
+
 using namespace llvm;
 
 namespace {
-  enum RegAllocName { simple, local, linearscan };
-
-  static cl::opt<RegAllocName>
-  RegAlloc(
-    "regalloc",
-    cl::desc("Register allocator to use: (default = linearscan)"),
-    cl::Prefix,
-    cl::values(
-       clEnumVal(simple,        "  simple register allocator"),
-       clEnumVal(local,         "  local register allocator"),
-       clEnumVal(linearscan,    "  linear scan register allocator"),
-       clEnumValEnd),
-    cl::init(linearscan));
-}
-
-
-RegisterRegAlloc *RegisterRegAlloc::List = NULL;
-
-/// Find - Finds a register allocator in registration list.
-///
-RegisterRegAlloc::FunctionPassCtor RegisterRegAlloc::Find(const char *N) {
-  for (RegisterRegAlloc *RA = List; RA; RA = RA->Next) {
-    if (strcmp(N, RA->Name) == 0) return RA->Ctor;
-  }
-  return NULL;
-}
-
-
-#ifndef NDEBUG  
-void RegisterRegAlloc::print() {
-  for (RegisterRegAlloc *RA = List; RA; RA = RA->Next) {
-    std::cerr << "RegAlloc:" << RA->Name << "\n";
-  }
+  cl::opt<const char *, false, RegisterPassParser<RegisterRegAlloc> >
+  RegAlloc("regalloc",
+           cl::init("linearscan"),
+           cl::desc("Register allocator to use: (default = linearscan)")); 
 }
-#endif
-
-
-static RegisterRegAlloc
-  simpleRegAlloc("simple", "  simple register allocator",
-                 createSimpleRegisterAllocator);
-
-static RegisterRegAlloc
-  localRegAlloc("local", "  local register allocator",
-                createLocalRegisterAllocator);
-
-static RegisterRegAlloc
-  linearscanRegAlloc("linearscan", "linear scan register allocator",
-                     createLinearScanRegisterAllocator);
-
 
 FunctionPass *llvm::createRegisterAllocator() {
-  const char *Names[] = {"simple", "local", "linearscan"};
-  const char *DefltName = "linearscan";
+  RegisterRegAlloc::FunctionPassCtor Ctor = RegisterRegAlloc::getCache();
+  
+  if (!Ctor) {
+    Ctor = RegisterRegAlloc::FindCtor(RegAlloc);
+    assert(Ctor && "No register allocator found");
+    if (!Ctor) Ctor = RegisterRegAlloc::FirstCtor();
+    RegisterRegAlloc::setCache(Ctor);
+  }
   
-  RegisterRegAlloc::FunctionPassCtor Ctor =
-                    RegisterRegAlloc::Find(Names[RegAlloc]);
-  if (!Ctor) Ctor = RegisterRegAlloc::Find(DefltName);
-
   assert(Ctor && "No register allocator found");
   
   return Ctor();
 }
-
-


Index: llvm/lib/CodeGen/RegAllocLinearScan.cpp
diff -u llvm/lib/CodeGen/RegAllocLinearScan.cpp:1.125 llvm/lib/CodeGen/RegAllocLinearScan.cpp:1.126
--- llvm/lib/CodeGen/RegAllocLinearScan.cpp:1.125	Thu Jul 20 12:28:38 2006
+++ llvm/lib/CodeGen/RegAllocLinearScan.cpp	Tue Aug  1 09:21:23 2006
@@ -18,6 +18,7 @@
 #include "llvm/Function.h"
 #include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/CodeGen/MachineInstr.h"
+#include "llvm/CodeGen/MachinePassRegistry.h"
 #include "llvm/CodeGen/Passes.h"
 #include "llvm/CodeGen/SSARegMap.h"
 #include "llvm/Target/MRegisterInfo.h"
@@ -42,6 +43,10 @@
   static Statistic<> NumBacktracks
   ("regalloc", "Number of times we had to backtrack");
 
+  static RegisterRegAlloc
+    linearscanRegAlloc("linearscan", "  linear scan register allocator",
+                       createLinearScanRegisterAllocator);
+
   static unsigned numIterations = 0;
   static unsigned numIntervals = 0;
 


Index: llvm/lib/CodeGen/RegAllocLocal.cpp
diff -u llvm/lib/CodeGen/RegAllocLocal.cpp:1.83 llvm/lib/CodeGen/RegAllocLocal.cpp:1.84
--- llvm/lib/CodeGen/RegAllocLocal.cpp:1.83	Fri Jul 21 16:15:20 2006
+++ llvm/lib/CodeGen/RegAllocLocal.cpp	Tue Aug  1 09:21:23 2006
@@ -18,6 +18,7 @@
 #include "llvm/CodeGen/MachineInstr.h"
 #include "llvm/CodeGen/SSARegMap.h"
 #include "llvm/CodeGen/MachineFrameInfo.h"
+#include "llvm/CodeGen/MachinePassRegistry.h"
 #include "llvm/CodeGen/LiveVariables.h"
 #include "llvm/Target/TargetInstrInfo.h"
 #include "llvm/Target/TargetMachine.h"
@@ -35,6 +36,12 @@
   static Statistic<> NumLoads ("ra-local", "Number of loads added");
   static Statistic<> NumFolded("ra-local", "Number of loads/stores folded "
 			       "into instructions");
+
+  static RegisterRegAlloc
+    localRegAlloc("local", "  local register allocator",
+                  createLocalRegisterAllocator);
+
+
   class VISIBILITY_HIDDEN RA : public MachineFunctionPass {
     const TargetMachine *TM;
     MachineFunction *MF;


Index: llvm/lib/CodeGen/RegAllocSimple.cpp
diff -u llvm/lib/CodeGen/RegAllocSimple.cpp:1.70 llvm/lib/CodeGen/RegAllocSimple.cpp:1.71
--- llvm/lib/CodeGen/RegAllocSimple.cpp:1.70	Fri Jul 21 16:15:20 2006
+++ llvm/lib/CodeGen/RegAllocSimple.cpp	Tue Aug  1 09:21:23 2006
@@ -20,6 +20,7 @@
 #include "llvm/CodeGen/MachineInstr.h"
 #include "llvm/CodeGen/SSARegMap.h"
 #include "llvm/CodeGen/MachineFrameInfo.h"
+#include "llvm/CodeGen/MachinePassRegistry.h"
 #include "llvm/Target/TargetInstrInfo.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Support/Debug.h"
@@ -33,6 +34,10 @@
   static Statistic<> NumStores("ra-simple", "Number of stores added");
   static Statistic<> NumLoads ("ra-simple", "Number of loads added");
 
+  static RegisterRegAlloc
+    simpleRegAlloc("simple", "  simple register allocator",
+                   createSimpleRegisterAllocator);
+
   class VISIBILITY_HIDDEN RegAllocSimple : public MachineFunctionPass {
     MachineFunction *MF;
     const TargetMachine *TM;






More information about the llvm-commits mailing list