Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1 | //===-- PPCTargetMachine.cpp - Define TargetMachine for PowerPC -----------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 081ce94 | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // Top-level implementation for the PowerPC target. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "PPC.h" |
| 15 | #include "PPCTargetAsmInfo.h" |
| 16 | #include "PPCTargetMachine.h" |
| 17 | #include "llvm/Module.h" |
| 18 | #include "llvm/PassManager.h" |
| 19 | #include "llvm/Target/TargetMachineRegistry.h" |
Dale Johannesen | 493492f | 2008-07-31 18:13:12 +0000 | [diff] [blame] | 20 | #include "llvm/Target/TargetOptions.h" |
David Greene | 302008d | 2009-07-14 20:18:05 +0000 | [diff] [blame] | 21 | #include "llvm/Support/FormattedStream.h" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 22 | using namespace llvm; |
| 23 | |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 24 | // Register the targets |
| 25 | static RegisterTarget<PPC32TargetMachine> |
Daniel Dunbar | fe5939f | 2009-07-15 20:24:03 +0000 | [diff] [blame] | 26 | X(ThePPC32Target, "ppc32", "PowerPC 32"); |
| 27 | |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 28 | static RegisterTarget<PPC64TargetMachine> |
Daniel Dunbar | fe5939f | 2009-07-15 20:24:03 +0000 | [diff] [blame] | 29 | Y(ThePPC64Target, "ppc64", "PowerPC 64"); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 30 | |
Bob Wilson | ebbc1c4 | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 31 | // Force static initialization. |
| 32 | extern "C" void LLVMInitializePowerPCTarget() { } |
Douglas Gregor | 1dc5ff4 | 2009-06-16 20:12:29 +0000 | [diff] [blame] | 33 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 34 | const TargetAsmInfo *PPCTargetMachine::createTargetAsmInfo() const { |
| 35 | if (Subtarget.isDarwin()) |
Anton Korobeynikov | d15bc31 | 2008-07-19 21:44:57 +0000 | [diff] [blame] | 36 | return new PPCDarwinTargetAsmInfo(*this); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 37 | else |
Anton Korobeynikov | d15bc31 | 2008-07-19 21:44:57 +0000 | [diff] [blame] | 38 | return new PPCLinuxTargetAsmInfo(*this); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 39 | } |
| 40 | |
Daniel Dunbar | fe5939f | 2009-07-15 20:24:03 +0000 | [diff] [blame] | 41 | PPCTargetMachine::PPCTargetMachine(const Target&T, const Module &M, |
| 42 | const std::string &FS, bool is64Bit) |
| 43 | : LLVMTargetMachine(T), |
| 44 | Subtarget(*this, M, FS, is64Bit), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 45 | DataLayout(Subtarget.getTargetDataString()), InstrInfo(*this), |
| 46 | FrameInfo(*this, is64Bit), JITInfo(*this, is64Bit), TLInfo(*this), |
| 47 | InstrItins(Subtarget.getInstrItineraryData()), MachOWriterInfo(*this) { |
| 48 | |
Anton Korobeynikov | 8c90d2a | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 49 | if (getRelocationModel() == Reloc::Default) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 50 | if (Subtarget.isDarwin()) |
| 51 | setRelocationModel(Reloc::DynamicNoPIC); |
| 52 | else |
| 53 | setRelocationModel(Reloc::Static); |
Anton Korobeynikov | 8c90d2a | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 54 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | /// Override this for PowerPC. Tail merging happily breaks up instruction issue |
| 58 | /// groups, which typically degrades performance. |
Dan Gohman | 62ea18a | 2007-11-19 20:46:23 +0000 | [diff] [blame] | 59 | bool PPCTargetMachine::getEnableTailMergeDefault() const { return false; } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 60 | |
Daniel Dunbar | fe5939f | 2009-07-15 20:24:03 +0000 | [diff] [blame] | 61 | PPC32TargetMachine::PPC32TargetMachine(const Target &T, const Module &M, |
| 62 | const std::string &FS) |
| 63 | : PPCTargetMachine(T, M, FS, false) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | |
Daniel Dunbar | fe5939f | 2009-07-15 20:24:03 +0000 | [diff] [blame] | 67 | PPC64TargetMachine::PPC64TargetMachine(const Target &T, const Module &M, |
| 68 | const std::string &FS) |
| 69 | : PPCTargetMachine(T, M, FS, true) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | |
| 73 | //===----------------------------------------------------------------------===// |
| 74 | // Pass Pipeline Configuration |
| 75 | //===----------------------------------------------------------------------===// |
| 76 | |
Bill Wendling | 5ed22ac | 2009-04-29 23:29:43 +0000 | [diff] [blame] | 77 | bool PPCTargetMachine::addInstSelector(PassManagerBase &PM, |
| 78 | CodeGenOpt::Level OptLevel) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 79 | // Install an instruction selector. |
| 80 | PM.add(createPPCISelDag(*this)); |
| 81 | return false; |
| 82 | } |
| 83 | |
Bill Wendling | 5ed22ac | 2009-04-29 23:29:43 +0000 | [diff] [blame] | 84 | bool PPCTargetMachine::addPreEmitPass(PassManagerBase &PM, |
| 85 | CodeGenOpt::Level OptLevel) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 86 | // Must run branch selection immediately preceding the asm printer. |
| 87 | PM.add(createPPCBranchSelectionPass()); |
| 88 | return false; |
| 89 | } |
| 90 | |
Bill Wendling | 5ed22ac | 2009-04-29 23:29:43 +0000 | [diff] [blame] | 91 | bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM, |
| 92 | CodeGenOpt::Level OptLevel, |
Daniel Dunbar | 3e0ad8b | 2009-07-15 22:33:19 +0000 | [diff] [blame] | 93 | MachineCodeEmitter &MCE) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 94 | // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64. |
| 95 | // FIXME: This should be moved to TargetJITInfo!! |
| 96 | if (Subtarget.isPPC64()) { |
| 97 | // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many |
| 98 | // instructions to materialize arbitrary global variable + function + |
| 99 | // constant pool addresses. |
| 100 | setRelocationModel(Reloc::PIC_); |
Dale Johannesen | 493492f | 2008-07-31 18:13:12 +0000 | [diff] [blame] | 101 | // Temporary workaround for the inability of PPC64 JIT to handle jump |
| 102 | // tables. |
| 103 | DisableJumpTables = true; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 104 | } else { |
| 105 | setRelocationModel(Reloc::Static); |
| 106 | } |
| 107 | |
| 108 | // Inform the subtarget that we are in JIT mode. FIXME: does this break macho |
| 109 | // writing? |
| 110 | Subtarget.SetJITMode(); |
| 111 | |
| 112 | // Machine code emitter pass for PowerPC. |
| 113 | PM.add(createPPCCodeEmitterPass(*this, MCE)); |
Anton Korobeynikov | 01c0e9f | 2008-08-17 13:54:28 +0000 | [diff] [blame] | 114 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 115 | return false; |
| 116 | } |
| 117 | |
Bruno Cardoso Lopes | 1ea31ff | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 118 | bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM, |
| 119 | CodeGenOpt::Level OptLevel, |
Daniel Dunbar | 3e0ad8b | 2009-07-15 22:33:19 +0000 | [diff] [blame] | 120 | JITCodeEmitter &JCE) { |
Bruno Cardoso Lopes | 1ea31ff | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 121 | // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64. |
| 122 | // FIXME: This should be moved to TargetJITInfo!! |
| 123 | if (Subtarget.isPPC64()) { |
| 124 | // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many |
| 125 | // instructions to materialize arbitrary global variable + function + |
| 126 | // constant pool addresses. |
| 127 | setRelocationModel(Reloc::PIC_); |
| 128 | // Temporary workaround for the inability of PPC64 JIT to handle jump |
| 129 | // tables. |
| 130 | DisableJumpTables = true; |
| 131 | } else { |
| 132 | setRelocationModel(Reloc::Static); |
| 133 | } |
| 134 | |
| 135 | // Inform the subtarget that we are in JIT mode. FIXME: does this break macho |
| 136 | // writing? |
| 137 | Subtarget.SetJITMode(); |
| 138 | |
| 139 | // Machine code emitter pass for PowerPC. |
| 140 | PM.add(createPPCJITCodeEmitterPass(*this, JCE)); |
Bruno Cardoso Lopes | 1ea31ff | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 141 | |
| 142 | return false; |
| 143 | } |
| 144 | |
Bruno Cardoso Lopes | aabb9a5 | 2009-07-06 05:09:34 +0000 | [diff] [blame] | 145 | bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM, |
| 146 | CodeGenOpt::Level OptLevel, |
Daniel Dunbar | 3e0ad8b | 2009-07-15 22:33:19 +0000 | [diff] [blame] | 147 | ObjectCodeEmitter &OCE) { |
Bruno Cardoso Lopes | aabb9a5 | 2009-07-06 05:09:34 +0000 | [diff] [blame] | 148 | // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64. |
| 149 | // FIXME: This should be moved to TargetJITInfo!! |
| 150 | if (Subtarget.isPPC64()) { |
| 151 | // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many |
| 152 | // instructions to materialize arbitrary global variable + function + |
| 153 | // constant pool addresses. |
| 154 | setRelocationModel(Reloc::PIC_); |
| 155 | // Temporary workaround for the inability of PPC64 JIT to handle jump |
| 156 | // tables. |
| 157 | DisableJumpTables = true; |
| 158 | } else { |
| 159 | setRelocationModel(Reloc::Static); |
| 160 | } |
| 161 | |
| 162 | // Inform the subtarget that we are in JIT mode. FIXME: does this break macho |
| 163 | // writing? |
| 164 | Subtarget.SetJITMode(); |
| 165 | |
| 166 | // Machine code emitter pass for PowerPC. |
| 167 | PM.add(createPPCObjectCodeEmitterPass(*this, OCE)); |
Bruno Cardoso Lopes | aabb9a5 | 2009-07-06 05:09:34 +0000 | [diff] [blame] | 168 | |
| 169 | return false; |
| 170 | } |
| 171 | |
Bill Wendling | 5ed22ac | 2009-04-29 23:29:43 +0000 | [diff] [blame] | 172 | bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, |
| 173 | CodeGenOpt::Level OptLevel, |
Bruno Cardoso Lopes | 8e2537b | 2009-06-01 19:57:37 +0000 | [diff] [blame] | 174 | MachineCodeEmitter &MCE) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 175 | // Machine code emitter pass for PowerPC. |
| 176 | PM.add(createPPCCodeEmitterPass(*this, MCE)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 177 | return false; |
| 178 | } |
Bruno Cardoso Lopes | 1ea31ff | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 179 | |
| 180 | bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, |
| 181 | CodeGenOpt::Level OptLevel, |
Bruno Cardoso Lopes | 8e2537b | 2009-06-01 19:57:37 +0000 | [diff] [blame] | 182 | JITCodeEmitter &JCE) { |
Bruno Cardoso Lopes | 1ea31ff | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 183 | // Machine code emitter pass for PowerPC. |
| 184 | PM.add(createPPCJITCodeEmitterPass(*this, JCE)); |
Bruno Cardoso Lopes | 1ea31ff | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 185 | return false; |
| 186 | } |
| 187 | |
Bruno Cardoso Lopes | aabb9a5 | 2009-07-06 05:09:34 +0000 | [diff] [blame] | 188 | bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, |
| 189 | CodeGenOpt::Level OptLevel, |
Bruno Cardoso Lopes | aabb9a5 | 2009-07-06 05:09:34 +0000 | [diff] [blame] | 190 | ObjectCodeEmitter &OCE) { |
| 191 | // Machine code emitter pass for PowerPC. |
| 192 | PM.add(createPPCObjectCodeEmitterPass(*this, OCE)); |
Bruno Cardoso Lopes | aabb9a5 | 2009-07-06 05:09:34 +0000 | [diff] [blame] | 193 | return false; |
| 194 | } |
| 195 | |
| 196 | |