blob: 66f9c02d053492942786a526de080c18211d09fe [file] [log] [blame]
Misha Brukman5dfe3a92004-06-21 16:55:25 +00001//===-- PowerPCTargetMachine.cpp - Define TargetMachine for PowerPC -------===//
2//
3// The LLVM Compiler Infrastructure
4//
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.
7//
8//===----------------------------------------------------------------------===//
9//
10//
11//===----------------------------------------------------------------------===//
12
13#include "PowerPCTargetMachine.h"
14#include "PowerPC.h"
Misha Brukman5dfe3a92004-06-21 16:55:25 +000015#include "llvm/Module.h"
16#include "llvm/PassManager.h"
Misha Brukman8c9f5202004-06-21 18:30:31 +000017#include "llvm/CodeGen/IntrinsicLowering.h"
Misha Brukman5dfe3a92004-06-21 16:55:25 +000018#include "llvm/CodeGen/MachineFunction.h"
19#include "llvm/CodeGen/Passes.h"
Chris Lattner68905bb2004-07-11 04:17:58 +000020#include "llvm/Target/TargetOptions.h"
Chris Lattnerd36c9702004-07-11 02:48:49 +000021#include "llvm/Target/TargetMachineRegistry.h"
Misha Brukman6f14ad12004-07-16 19:32:12 +000022#include "llvm/Transforms/IPO.h"
Misha Brukman5dfe3a92004-06-21 16:55:25 +000023#include "llvm/Transforms/Scalar.h"
Chris Lattnerd36c9702004-07-11 02:48:49 +000024#include <iostream>
Misha Brukman5dfe3a92004-06-21 16:55:25 +000025using namespace llvm;
26
Chris Lattnerd36c9702004-07-11 02:48:49 +000027namespace {
28 // Register the target.
Chris Lattner017fdcb2004-07-15 02:33:38 +000029 RegisterTarget<PowerPCTargetMachine> X("powerpc", " PowerPC (experimental)");
Chris Lattnerd36c9702004-07-11 02:48:49 +000030}
31
Misha Brukman01eca8d2004-07-12 23:36:12 +000032unsigned PowerPCTargetMachine::getJITMatchQuality() {
33#if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER)
34 return 10;
35#else
36 return 0;
37#endif
38}
39
40unsigned PowerPCTargetMachine::getModuleMatchQuality(const Module &M) {
41 if (M.getEndianness() == Module::BigEndian &&
42 M.getPointerSize() == Module::Pointer32)
43 return 10; // Direct match
44 else if (M.getEndianness() != Module::AnyEndianness ||
45 M.getPointerSize() != Module::AnyPointerSize)
46 return 0; // Match for some other target
47
48 return getJITMatchQuality()/2;
49}
50
51
Misha Brukman5dfe3a92004-06-21 16:55:25 +000052/// PowerPCTargetMachine ctor - Create an ILP32 architecture model
53///
Misha Brukman5dfe3a92004-06-21 16:55:25 +000054PowerPCTargetMachine::PowerPCTargetMachine(const Module &M,
55 IntrinsicLowering *IL)
Misha Brukman6f14ad12004-07-16 19:32:12 +000056 : TargetMachine("PowerPC", IL, false, 4, 4, 8, 4, 4, 4, 4, 4),
Misha Brukman5dfe3a92004-06-21 16:55:25 +000057 FrameInfo(TargetFrameInfo::StackGrowsDown, 16, -4), JITInfo(*this) {
58}
59
60/// addPassesToEmitAssembly - Add passes to the specified pass manager
61/// to implement a static compiler for this target.
62///
63bool PowerPCTargetMachine::addPassesToEmitAssembly(PassManager &PM,
Misha Brukman6f14ad12004-07-16 19:32:12 +000064 std::ostream &Out) {
Misha Brukman5dfe3a92004-06-21 16:55:25 +000065 // FIXME: Implement efficient support for garbage collection intrinsics.
66 PM.add(createLowerGCPass());
67
68 // FIXME: Implement the invoke/unwind instructions!
69 PM.add(createLowerInvokePass());
70
Misha Brukman5dfe3a92004-06-21 16:55:25 +000071 // FIXME: Implement the switch instruction in the instruction selector!
72 PM.add(createLowerSwitchPass());
73
Misha Brukman60f35812004-06-29 23:33:20 +000074 PM.add(createLowerConstantExpressionsPass());
75
Chris Lattnerfab96f02004-07-02 05:48:42 +000076 // Make sure that no unreachable blocks are instruction selected.
77 PM.add(createUnreachableBlockEliminationPass());
78
Misha Brukman5dfe3a92004-06-21 16:55:25 +000079 PM.add(createPPCSimpleInstructionSelector(*this));
Misha Brukman75afe1f2004-06-24 23:55:01 +000080
81 if (PrintMachineCode)
82 PM.add(createMachineFunctionPrinterPass(&std::cerr));
83
Misha Brukman5dfe3a92004-06-21 16:55:25 +000084 PM.add(createRegisterAllocator());
Misha Brukman34fa8712004-06-25 19:57:47 +000085
86 if (PrintMachineCode)
87 PM.add(createMachineFunctionPrinterPass(&std::cerr));
88
Misha Brukman5dfe3a92004-06-21 16:55:25 +000089 PM.add(createPrologEpilogCodeInserter());
90 PM.add(createPPCCodePrinterPass(Out, *this));
91 PM.add(createMachineCodeDeleter());
92 return false;
93}
94
95/// addPassesToJITCompile - Add passes to the specified pass manager to
96/// implement a fast dynamic compiler for this target.
97///
98void PowerPCJITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
99 // FIXME: Implement efficient support for garbage collection intrinsics.
100 PM.add(createLowerGCPass());
101
102 // FIXME: Implement the invoke/unwind instructions!
103 PM.add(createLowerInvokePass());
104
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000105 // FIXME: Implement the switch instruction in the instruction selector!
106 PM.add(createLowerSwitchPass());
107
Misha Brukman60f35812004-06-29 23:33:20 +0000108 PM.add(createLowerConstantExpressionsPass());
109
Chris Lattnerfab96f02004-07-02 05:48:42 +0000110 // Make sure that no unreachable blocks are instruction selected.
111 PM.add(createUnreachableBlockEliminationPass());
112
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000113 PM.add(createPPCSimpleInstructionSelector(TM));
114 PM.add(createRegisterAllocator());
115 PM.add(createPrologEpilogCodeInserter());
116}