1 //===-- PowerPCTargetMachine.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 "PowerPCTargetMachine.h"
16 #include "PowerPCFrameInfo.h"
17 #include "PPC32TargetMachine.h"
18 #include "PPC32JITInfo.h"
19 #include "llvm/Module.h"
20 #include "llvm/PassManager.h"
21 #include "llvm/Analysis/Verifier.h"
22 #include "llvm/CodeGen/IntrinsicLowering.h"
23 #include "llvm/CodeGen/MachineFunction.h"
24 #include "llvm/CodeGen/Passes.h"
25 #include "llvm/Target/TargetOptions.h"
26 #include "llvm/Target/TargetMachineRegistry.h"
27 #include "llvm/Transforms/Scalar.h"
28 #include "llvm/Support/CommandLine.h"
33 const std::string PPC32ID = "PowerPC/32bit";
35 // Register the targets
36 RegisterTarget<PPC32TargetMachine>
37 X("ppc32", " PowerPC 32-bit");
40 PowerPCTargetMachine::PowerPCTargetMachine(const std::string &name,
41 IntrinsicLowering *IL,
44 const PowerPCFrameInfo &TFI)
45 : TargetMachine(name, IL, TD), FrameInfo(TFI), Subtarget(M) {
46 if (TargetDefault == PPCTarget) {
47 if (Subtarget.isAIX()) PPCTarget = TargetAIX;
48 if (Subtarget.isDarwin()) PPCTarget = TargetDarwin;
52 unsigned PPC32TargetMachine::getJITMatchQuality() {
53 #if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER)
60 /// addPassesToEmitFile - Add passes to the specified pass manager to implement
61 /// a static compiler for this target.
63 bool PowerPCTargetMachine::addPassesToEmitFile(PassManager &PM,
65 CodeGenFileType FileType) {
66 if (FileType != TargetMachine::AssemblyFile) return true;
68 // Run loop strength reduction before anything else.
69 PM.add(createLoopStrengthReducePass());
70 PM.add(createCFGSimplificationPass());
72 // FIXME: Implement efficient support for garbage collection intrinsics.
73 PM.add(createLowerGCPass());
75 // FIXME: Implement the invoke/unwind instructions!
76 PM.add(createLowerInvokePass());
78 // FIXME: Implement the switch instruction in the instruction selector!
79 PM.add(createLowerSwitchPass());
81 // Make sure that no unreachable blocks are instruction selected.
82 PM.add(createUnreachableBlockEliminationPass());
84 // Default to pattern ISel
85 if (PatternISelTriState == 0) {
86 PM.add(createLowerConstantExpressionsPass());
87 PM.add(createPPC32ISelSimple(*this));
89 PM.add(createPPC32ISelPattern(*this));
92 PM.add(createMachineFunctionPrinterPass(&std::cerr));
94 PM.add(createRegisterAllocator());
97 PM.add(createMachineFunctionPrinterPass(&std::cerr));
99 PM.add(createPrologEpilogCodeInserter());
101 // Must run branch selection immediately preceding the asm printer
102 PM.add(createPPCBranchSelectionPass());
104 // Decide which asm printer to use. If the user has not specified one on
105 // the command line, choose whichever one matches the default (current host).
108 PM.add(createAIXAsmPrinter(Out, *this));
112 PM.add(createDarwinAsmPrinter(Out, *this));
116 PM.add(createMachineCodeDeleter());
120 void PowerPCJITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
121 // The JIT does not support or need PIC.
124 // Run loop strength reduction before anything else.
125 PM.add(createLoopStrengthReducePass());
126 PM.add(createCFGSimplificationPass());
128 // FIXME: Implement efficient support for garbage collection intrinsics.
129 PM.add(createLowerGCPass());
131 // FIXME: Implement the invoke/unwind instructions!
132 PM.add(createLowerInvokePass());
134 // FIXME: Implement the switch instruction in the instruction selector!
135 PM.add(createLowerSwitchPass());
137 // Make sure that no unreachable blocks are instruction selected.
138 PM.add(createUnreachableBlockEliminationPass());
140 // Default to pattern ISel
141 if (PatternISelTriState == 0) {
142 PM.add(createLowerConstantExpressionsPass());
143 PM.add(createPPC32ISelSimple(TM));
145 PM.add(createPPC32ISelPattern(TM));
148 PM.add(createRegisterAllocator());
149 PM.add(createPrologEpilogCodeInserter());
151 // Must run branch selection immediately preceding the asm printer
152 PM.add(createPPCBranchSelectionPass());
154 if (PrintMachineCode)
155 PM.add(createMachineFunctionPrinterPass(&std::cerr));
158 /// PowerPCTargetMachine ctor - Create an ILP32 architecture model
160 PPC32TargetMachine::PPC32TargetMachine(const Module &M, IntrinsicLowering *IL)
161 : PowerPCTargetMachine(PPC32ID, IL, M,
162 TargetData(PPC32ID,false,4,4,4,4,4,4,2,1,1),
163 PowerPCFrameInfo(*this, false)), JITInfo(*this) {}
165 unsigned PPC32TargetMachine::getModuleMatchQuality(const Module &M) {
166 // We strongly match "powerpc-*".
167 std::string TT = M.getTargetTriple();
168 if (TT.size() >= 8 && std::string(TT.begin(), TT.begin()+8) == "powerpc-")
171 if (M.getEndianness() == Module::BigEndian &&
172 M.getPointerSize() == Module::Pointer32)
173 return 10; // Weak match
174 else if (M.getEndianness() != Module::AnyEndianness ||
175 M.getPointerSize() != Module::AnyPointerSize)
176 return 0; // Match for some other target
178 return getJITMatchQuality()/2;