1 //===-- PPCTargetMachine.cpp - Define TargetMachine for PowerPC -----------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Top-level implementation for the PowerPC target.
12 //===----------------------------------------------------------------------===//
15 #include "PPCFrameInfo.h"
16 #include "PPCTargetMachine.h"
17 #include "PPCJITInfo.h"
18 #include "llvm/Module.h"
19 #include "llvm/PassManager.h"
20 #include "llvm/Analysis/Verifier.h"
21 #include "llvm/CodeGen/MachineFunction.h"
22 #include "llvm/CodeGen/Passes.h"
23 #include "llvm/Target/TargetOptions.h"
24 #include "llvm/Target/TargetMachineRegistry.h"
25 #include "llvm/Transforms/Scalar.h"
26 #include "llvm/Support/CommandLine.h"
31 // Register the targets
32 RegisterTarget<PPCTargetMachine>
33 X("ppc32", " PowerPC");
36 unsigned PPCTargetMachine::getJITMatchQuality() {
37 #if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER)
44 unsigned PPCTargetMachine::getModuleMatchQuality(const Module &M) {
45 // We strongly match "powerpc-*".
46 std::string TT = M.getTargetTriple();
47 if (TT.size() >= 8 && std::string(TT.begin(), TT.begin()+8) == "powerpc-")
50 if (M.getEndianness() == Module::BigEndian &&
51 M.getPointerSize() == Module::Pointer32)
52 return 10; // Weak match
53 else if (M.getEndianness() != Module::AnyEndianness ||
54 M.getPointerSize() != Module::AnyPointerSize)
55 return 0; // Match for some other target
57 return getJITMatchQuality()/2;
60 PPCTargetMachine::PPCTargetMachine(const Module &M, const std::string &FS)
61 : TargetMachine("PowerPC"),
62 DataLayout(std::string("PowerPC"), std::string("E-p:32:32-d:64:32-l:64:32")),
63 Subtarget(M, FS), FrameInfo(*this, false), JITInfo(*this),
64 TLInfo(*this), InstrItins(Subtarget.getInstrItineraryData()) {
65 if (TargetDefault == PPCTarget) {
66 if (Subtarget.isAIX()) PPCTarget = TargetAIX;
67 if (Subtarget.isDarwin()) PPCTarget = TargetDarwin;
69 if (getRelocationModel() == Reloc::Default)
70 if (Subtarget.isDarwin())
71 setRelocationModel(Reloc::DynamicNoPIC);
73 setRelocationModel(Reloc::PIC);
76 /// addPassesToEmitFile - Add passes to the specified pass manager to implement
77 /// a static compiler for this target.
79 bool PPCTargetMachine::addPassesToEmitFile(PassManager &PM,
81 CodeGenFileType FileType,
83 if (FileType != TargetMachine::AssemblyFile) return true;
85 // Run loop strength reduction before anything else.
86 if (!Fast) PM.add(createLoopStrengthReducePass(&TLInfo));
88 // FIXME: Implement efficient support for garbage collection intrinsics.
89 PM.add(createLowerGCPass());
91 // FIXME: Implement the invoke/unwind instructions!
92 PM.add(createLowerInvokePass());
94 // Clean up after other passes, e.g. merging critical edges.
95 if (!Fast) PM.add(createCFGSimplificationPass());
97 // Make sure that no unreachable blocks are instruction selected.
98 PM.add(createUnreachableBlockEliminationPass());
100 // Install an instruction selector.
101 PM.add(createPPCISelDag(*this));
103 if (PrintMachineCode)
104 PM.add(createMachineFunctionPrinterPass(&std::cerr));
106 PM.add(createRegisterAllocator());
108 if (PrintMachineCode)
109 PM.add(createMachineFunctionPrinterPass(&std::cerr));
111 PM.add(createPrologEpilogCodeInserter());
113 // Must run branch selection immediately preceding the asm printer
114 PM.add(createPPCBranchSelectionPass());
116 // Decide which asm printer to use. If the user has not specified one on
117 // the command line, choose whichever one matches the default (current host).
120 PM.add(createAIXAsmPrinter(Out, *this));
124 PM.add(createDarwinAsmPrinter(Out, *this));
128 PM.add(createMachineCodeDeleter());
132 void PPCJITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
133 // The JIT should use the static relocation model.
134 TM.setRelocationModel(Reloc::Static);
136 // Run loop strength reduction before anything else.
137 PM.add(createLoopStrengthReducePass(TM.getTargetLowering()));
139 // FIXME: Implement efficient support for garbage collection intrinsics.
140 PM.add(createLowerGCPass());
142 // FIXME: Implement the invoke/unwind instructions!
143 PM.add(createLowerInvokePass());
145 // Clean up after other passes, e.g. merging critical edges.
146 PM.add(createCFGSimplificationPass());
148 // Make sure that no unreachable blocks are instruction selected.
149 PM.add(createUnreachableBlockEliminationPass());
151 // Install an instruction selector.
152 PM.add(createPPCISelDag(TM));
154 PM.add(createRegisterAllocator());
155 PM.add(createPrologEpilogCodeInserter());
157 // Must run branch selection immediately preceding the asm printer
158 PM.add(createPPCBranchSelectionPass());
160 if (PrintMachineCode)
161 PM.add(createMachineFunctionPrinterPass(&std::cerr));