Hoist some sparc specific code into the sparc target
authorChris Lattner <sabre@nondot.org>
Sat, 20 Dec 2003 09:17:40 +0000 (09:17 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 20 Dec 2003 09:17:40 +0000 (09:17 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10554 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/SparcV9/SparcV9CodeEmitter.cpp
lib/Target/SparcV9/SparcV9Internals.h
lib/Target/SparcV9/SparcV9TargetMachine.cpp

index 99f90fffccdf42e453dbde41015e9beb7072df0d..71aa626550224a7b0b4898b4110248b76b797a57 100644 (file)
@@ -53,7 +53,7 @@ bool SparcTargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM,
   MachineCodeEmitter *M = &MCE;
   DEBUG(M = MachineCodeEmitter::createFilePrinterEmitter(MCE));
   PM.add(new SparcV9CodeEmitter(*this, *M));
-  PM.add(createMachineCodeDestructionPass()); // Free stuff no longer needed
+  PM.add(createSparcMachineCodeDestructionPass()); //Free stuff no longer needed
   return false;
 }
 
index 27dc7d012c526fd93a278ec77327b536ab5d12ed..aaf39feb60a688c8ffdb84ec8f1a66a548a41556 100644 (file)
@@ -127,6 +127,8 @@ FunctionPass* createPrologEpilogInsertionPass();
 ///
 Pass* createBytecodeAsmPrinterPass(std::ostream &Out);
 
+FunctionPass *createSparcMachineCodeDestructionPass();
+
 } // End llvm namespace
 
 #endif
index a122e3c11be22ab7a6fd49b12018e4744758a549..505aeb8fe0c068ad86cd40065d94e915d37ea271 100644 (file)
 
 using namespace llvm;
 
-namespace llvm {
-
 static const unsigned ImplicitRegUseList[] = { 0 }; /* not used yet */
 // Build the MachineInstruction Description Array...
-const TargetInstrDescriptor SparcMachineInstrDesc[] = {
+const TargetInstrDescriptor llvm::SparcMachineInstrDesc[] = {
 #define I(ENUM, OPCODESTRING, NUMOPERANDS, RESULTPOS, MAXIMM, IMMSE, \
           NUMDELAYSLOTS, LATENCY, SCHEDCLASS, INSTFLAGS)             \
   { OPCODESTRING, NUMOPERANDS, RESULTPOS, MAXIMM, IMMSE,             \
@@ -66,7 +64,54 @@ namespace {
                           cl::Hidden);
 }
 
-} // End llvm namespace
+//===---------------------------------------------------------------------===//
+// Code generation/destruction passes
+//===---------------------------------------------------------------------===//
+
+namespace {
+  class ConstructMachineFunction : public FunctionPass {
+    TargetMachine &Target;
+  public:
+    ConstructMachineFunction(TargetMachine &T) : Target(T) {}
+    
+    const char *getPassName() const {
+      return "ConstructMachineFunction";
+    }
+    
+    bool runOnFunction(Function &F) {
+      MachineFunction::construct(&F, Target).getInfo()->CalculateArgSize();
+      return false;
+    }
+  };
+
+  struct DestroyMachineFunction : public FunctionPass {
+    const char *getPassName() const { return "FreeMachineFunction"; }
+    
+    static void freeMachineCode(Instruction &I) {
+      MachineCodeForInstruction::destroy(&I);
+    }
+    
+    bool runOnFunction(Function &F) {
+      for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI)
+        for (BasicBlock::iterator I = FI->begin(), E = FI->end(); I != E; ++I)
+          MachineCodeForInstruction::get(I).dropAllReferences();
+      
+      for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI)
+        for_each(FI->begin(), FI->end(), freeMachineCode);
+      
+      return false;
+    }
+  };
+  
+  FunctionPass *createMachineCodeConstructionPass(TargetMachine &Target) {
+    return new ConstructMachineFunction(Target);
+  }
+}
+
+FunctionPass *llvm::createSparcMachineCodeDestructionPass() {
+  return new DestroyMachineFunction();
+}
+
 
 SparcTargetMachine::SparcTargetMachine()
   : TargetMachine("UltraSparc-Native", false),
@@ -141,7 +186,7 @@ SparcTargetMachine::addPassesToEmitAssembly(PassManager &PM, std::ostream &Out)
   // function has been emitted.
   //
   PM.add(createAsmPrinterPass(Out, *this));
-  PM.add(createMachineCodeDestructionPass()); // Free stuff no longer needed
+  PM.add(createSparcMachineCodeDestructionPass()); // Free stuff no longer needed
 
   // Emit bytecode to the assembly file into its special section next
   if (EmitMappingInfo)