From eb8c83b4c3220bce902e798bde0d8c1b61742c50 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Wed, 15 Jul 2009 12:49:15 +0000 Subject: [PATCH] Replace large swaths of copy-n-paste code with obvious helper function... - Which was already present in the module! - I skipped this xform for Alpha, since it runs an extra pass during assembly emission, but not when emitting assembly via the DumpAsm flag. - No functionality change. -- ddunbar@giles:llvm$ svn diff | grep '^- ' | sort | uniq -c 18 - PM.add(AsmPrinterCtor(ferrs(), *this, true)); 18 - assert(AsmPrinterCtor && "AsmPrinter was not linked in"); 18 - if (AsmPrinterCtor) 18 - if (DumpAsm) { 18 - } ddunbar@giles:llvm$ svn diff | grep '^+ ' | sort | uniq -c 18 + addAssemblyEmitter(PM, OptLevel, true, ferrs()); 18 + if (DumpAsm) -- llvm-svn: 75782 --- llvm/lib/Target/ARM/ARMTargetMachine.cpp | 42 ++++++-------------- llvm/lib/Target/PowerPC/PPCTargetMachine.cpp | 42 ++++++-------------- llvm/lib/Target/X86/X86TargetMachine.cpp | 42 ++++++-------------- 3 files changed, 36 insertions(+), 90 deletions(-) diff --git a/llvm/lib/Target/ARM/ARMTargetMachine.cpp b/llvm/lib/Target/ARM/ARMTargetMachine.cpp index 78b2f8aa5338..ad800207382a 100644 --- a/llvm/lib/Target/ARM/ARMTargetMachine.cpp +++ b/llvm/lib/Target/ARM/ARMTargetMachine.cpp @@ -155,11 +155,8 @@ bool ARMBaseTargetMachine::addCodeEmitter(PassManagerBase &PM, // Machine code emitter pass for ARM. PM.add(createARMCodeEmitterPass(*this, MCE)); - if (DumpAsm) { - assert(AsmPrinterCtor && "AsmPrinter was not linked in"); - if (AsmPrinterCtor) - PM.add(AsmPrinterCtor(ferrs(), *this, true)); - } + if (DumpAsm) + addAssemblyEmitter(PM, OptLevel, true, ferrs()); return false; } @@ -174,11 +171,8 @@ bool ARMBaseTargetMachine::addCodeEmitter(PassManagerBase &PM, // Machine code emitter pass for ARM. PM.add(createARMJITCodeEmitterPass(*this, JCE)); - if (DumpAsm) { - assert(AsmPrinterCtor && "AsmPrinter was not linked in"); - if (AsmPrinterCtor) - PM.add(AsmPrinterCtor(ferrs(), *this, true)); - } + if (DumpAsm) + addAssemblyEmitter(PM, OptLevel, true, ferrs()); return false; } @@ -193,11 +187,8 @@ bool ARMBaseTargetMachine::addCodeEmitter(PassManagerBase &PM, // Machine code emitter pass for ARM. PM.add(createARMObjectCodeEmitterPass(*this, OCE)); - if (DumpAsm) { - assert(AsmPrinterCtor && "AsmPrinter was not linked in"); - if (AsmPrinterCtor) - PM.add(AsmPrinterCtor(ferrs(), *this, true)); - } + if (DumpAsm) + addAssemblyEmitter(PM, OptLevel, true, ferrs()); return false; } @@ -208,11 +199,8 @@ bool ARMBaseTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, MachineCodeEmitter &MCE) { // Machine code emitter pass for ARM. PM.add(createARMCodeEmitterPass(*this, MCE)); - if (DumpAsm) { - assert(AsmPrinterCtor && "AsmPrinter was not linked in"); - if (AsmPrinterCtor) - PM.add(AsmPrinterCtor(ferrs(), *this, true)); - } + if (DumpAsm) + addAssemblyEmitter(PM, OptLevel, true, ferrs()); return false; } @@ -223,11 +211,8 @@ bool ARMBaseTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, JITCodeEmitter &JCE) { // Machine code emitter pass for ARM. PM.add(createARMJITCodeEmitterPass(*this, JCE)); - if (DumpAsm) { - assert(AsmPrinterCtor && "AsmPrinter was not linked in"); - if (AsmPrinterCtor) - PM.add(AsmPrinterCtor(ferrs(), *this, true)); - } + if (DumpAsm) + addAssemblyEmitter(PM, OptLevel, true, ferrs()); return false; } @@ -238,11 +223,8 @@ bool ARMBaseTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, ObjectCodeEmitter &OCE) { // Machine code emitter pass for ARM. PM.add(createARMObjectCodeEmitterPass(*this, OCE)); - if (DumpAsm) { - assert(AsmPrinterCtor && "AsmPrinter was not linked in"); - if (AsmPrinterCtor) - PM.add(AsmPrinterCtor(ferrs(), *this, true)); - } + if (DumpAsm) + addAssemblyEmitter(PM, OptLevel, true, ferrs()); return false; } diff --git a/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp b/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp index 140734a18798..7e401c453f0f 100644 --- a/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp +++ b/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp @@ -135,11 +135,8 @@ bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM, // Machine code emitter pass for PowerPC. PM.add(createPPCCodeEmitterPass(*this, MCE)); - if (DumpAsm) { - assert(AsmPrinterCtor && "AsmPrinter was not linked in"); - if (AsmPrinterCtor) - PM.add(AsmPrinterCtor(ferrs(), *this, true)); - } + if (DumpAsm) + addAssemblyEmitter(PM, OptLevel, true, ferrs()); return false; } @@ -167,11 +164,8 @@ bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM, // Machine code emitter pass for PowerPC. PM.add(createPPCJITCodeEmitterPass(*this, JCE)); - if (DumpAsm) { - assert(AsmPrinterCtor && "AsmPrinter was not linked in"); - if (AsmPrinterCtor) - PM.add(AsmPrinterCtor(ferrs(), *this, true)); - } + if (DumpAsm) + addAssemblyEmitter(PM, OptLevel, true, ferrs()); return false; } @@ -199,11 +193,8 @@ bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM, // Machine code emitter pass for PowerPC. PM.add(createPPCObjectCodeEmitterPass(*this, OCE)); - if (DumpAsm) { - assert(AsmPrinterCtor && "AsmPrinter was not linked in"); - if (AsmPrinterCtor) - PM.add(AsmPrinterCtor(ferrs(), *this, true)); - } + if (DumpAsm) + addAssemblyEmitter(PM, OptLevel, true, ferrs()); return false; } @@ -214,11 +205,8 @@ bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, MachineCodeEmitter &MCE) { // Machine code emitter pass for PowerPC. PM.add(createPPCCodeEmitterPass(*this, MCE)); - if (DumpAsm) { - assert(AsmPrinterCtor && "AsmPrinter was not linked in"); - if (AsmPrinterCtor) - PM.add(AsmPrinterCtor(ferrs(), *this, true)); - } + if (DumpAsm) + addAssemblyEmitter(PM, OptLevel, true, ferrs()); return false; } @@ -229,11 +217,8 @@ bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, JITCodeEmitter &JCE) { // Machine code emitter pass for PowerPC. PM.add(createPPCJITCodeEmitterPass(*this, JCE)); - if (DumpAsm) { - assert(AsmPrinterCtor && "AsmPrinter was not linked in"); - if (AsmPrinterCtor) - PM.add(AsmPrinterCtor(ferrs(), *this, true)); - } + if (DumpAsm) + addAssemblyEmitter(PM, OptLevel, true, ferrs()); return false; } @@ -244,11 +229,8 @@ bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, ObjectCodeEmitter &OCE) { // Machine code emitter pass for PowerPC. PM.add(createPPCObjectCodeEmitterPass(*this, OCE)); - if (DumpAsm) { - assert(AsmPrinterCtor && "AsmPrinter was not linked in"); - if (AsmPrinterCtor) - PM.add(AsmPrinterCtor(ferrs(), *this, true)); - } + if (DumpAsm) + addAssemblyEmitter(PM, OptLevel, true, ferrs()); return false; } diff --git a/llvm/lib/Target/X86/X86TargetMachine.cpp b/llvm/lib/Target/X86/X86TargetMachine.cpp index 9ea10db74495..c64084756c16 100644 --- a/llvm/lib/Target/X86/X86TargetMachine.cpp +++ b/llvm/lib/Target/X86/X86TargetMachine.cpp @@ -217,11 +217,8 @@ bool X86TargetMachine::addCodeEmitter(PassManagerBase &PM, } PM.add(createX86CodeEmitterPass(*this, MCE)); - if (DumpAsm) { - assert(AsmPrinterCtor && "AsmPrinter was not linked in"); - if (AsmPrinterCtor) - PM.add(AsmPrinterCtor(ferrs(), *this, true)); - } + if (DumpAsm) + addAssemblyEmitter(PM, OptLevel, true, ferrs()); return false; } @@ -249,11 +246,8 @@ bool X86TargetMachine::addCodeEmitter(PassManagerBase &PM, } PM.add(createX86JITCodeEmitterPass(*this, JCE)); - if (DumpAsm) { - assert(AsmPrinterCtor && "AsmPrinter was not linked in"); - if (AsmPrinterCtor) - PM.add(AsmPrinterCtor(ferrs(), *this, true)); - } + if (DumpAsm) + addAssemblyEmitter(PM, OptLevel, true, ferrs()); return false; } @@ -263,11 +257,8 @@ bool X86TargetMachine::addCodeEmitter(PassManagerBase &PM, bool DumpAsm, ObjectCodeEmitter &OCE) { PM.add(createX86ObjectCodeEmitterPass(*this, OCE)); - if (DumpAsm) { - assert(AsmPrinterCtor && "AsmPrinter was not linked in"); - if (AsmPrinterCtor) - PM.add(AsmPrinterCtor(ferrs(), *this, true)); - } + if (DumpAsm) + addAssemblyEmitter(PM, OptLevel, true, ferrs()); return false; } @@ -277,11 +268,8 @@ bool X86TargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, bool DumpAsm, MachineCodeEmitter &MCE) { PM.add(createX86CodeEmitterPass(*this, MCE)); - if (DumpAsm) { - assert(AsmPrinterCtor && "AsmPrinter was not linked in"); - if (AsmPrinterCtor) - PM.add(AsmPrinterCtor(ferrs(), *this, true)); - } + if (DumpAsm) + addAssemblyEmitter(PM, OptLevel, true, ferrs()); return false; } @@ -291,11 +279,8 @@ bool X86TargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, bool DumpAsm, JITCodeEmitter &JCE) { PM.add(createX86JITCodeEmitterPass(*this, JCE)); - if (DumpAsm) { - assert(AsmPrinterCtor && "AsmPrinter was not linked in"); - if (AsmPrinterCtor) - PM.add(AsmPrinterCtor(ferrs(), *this, true)); - } + if (DumpAsm) + addAssemblyEmitter(PM, OptLevel, true, ferrs()); return false; } @@ -305,11 +290,8 @@ bool X86TargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, bool DumpAsm, ObjectCodeEmitter &OCE) { PM.add(createX86ObjectCodeEmitterPass(*this, OCE)); - if (DumpAsm) { - assert(AsmPrinterCtor && "AsmPrinter was not linked in"); - if (AsmPrinterCtor) - PM.add(AsmPrinterCtor(ferrs(), *this, true)); - } + if (DumpAsm) + addAssemblyEmitter(PM, OptLevel, true, ferrs()); return false; }