-
-
-//===---------------------------------------------------------------------===//
-// GenerateCodeForTarget Pass
-//
-// Native code generation for a specified target.
-//===---------------------------------------------------------------------===//
-
-class ConstructMachineCodeForMethod : public MethodPass {
- TargetMachine &Target;
-public:
- inline ConstructMachineCodeForMethod(TargetMachine &T) : Target(T) {}
- bool runOnMethod(Method *M) {
- MachineCodeForMethod::construct(M, Target);
- return false;
- }
-};
-
-class InstructionSelection : public MethodPass {
- TargetMachine &Target;
-public:
- inline InstructionSelection(TargetMachine &T) : Target(T) {}
- bool runOnMethod(Method *M) {
- if (SelectInstructionsForMethod(M, Target))
- cerr << "Instr selection failed for method " << M->getName() << "\n";
- return false;
- }
-};
-
-struct FreeMachineCodeForMethod : public MethodPass {
- static void freeMachineCode(Instruction *I) {
- MachineCodeForInstruction::destroy(I);
- }
-
- bool runOnMethod(Method *M) {
- for_each(M->inst_begin(), M->inst_end(), freeMachineCode);
- // Don't destruct MachineCodeForMethod - The global printer needs it
- //MachineCodeForMethod::destruct(M);
- return false;
- }
-};
-
-
-
-// addPassesToEmitAssembly - This method controls the entire code generation
-// process for the ultra sparc.
-//
-void UltraSparc::addPassesToEmitAssembly(PassManager &PM, std::ostream &Out) {
- // Construct and initialize the MachineCodeForMethod object for this method.
- PM.add(new ConstructMachineCodeForMethod(*this));
-
- PM.add(new InstructionSelection(*this));
-
- //PM.add(createInstructionSchedulingWithSSAPass(*this));
-
- PM.add(getRegisterAllocator(*this));
-
- //PM.add(new OptimizeLeafProcedures());
- //PM.add(new DeleteFallThroughBranches());
- //PM.add(new RemoveChainedBranches()); // should be folded with previous
- //PM.add(new RemoveRedundantOps()); // operations with %g0, NOP, etc.
-
- PM.add(new InsertPrologEpilogCode(*this));
-
- // Output assembly language to the .s file. Assembly emission is split into
- // two parts: Method output and Global value output. This is because method
- // output is pipelined with all of the rest of code generation stuff,
- // allowing machine code representations for methods to be free'd after the
- // method has been emitted.
- //
- PM.add(getMethodAsmPrinterPass(PM, Out));
- PM.add(new FreeMachineCodeForMethod()); // Free stuff no longer needed
-
- // Emit Module level assembly after all of the methods have been processed.
- PM.add(getModuleAsmPrinterPass(PM, Out));
-
- // Emit bytecode to the sparc assembly file into its special section next
- PM.add(getEmitBytecodeToAsmPass(Out));
-}