blob: 360446ad59af527bccff63c7d84da26a5ec7dc5c [file] [log] [blame]
Tony Linthicumb4b54152011-12-12 21:14:40 +00001//===-- HexagonTargetMachine.cpp - Define TargetMachine for Hexagon -------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10//
11//===----------------------------------------------------------------------===//
12
Tony Linthicumb4b54152011-12-12 21:14:40 +000013#include "HexagonTargetMachine.h"
14#include "Hexagon.h"
15#include "HexagonISelLowering.h"
16#include "llvm/Module.h"
17#include "llvm/CodeGen/Passes.h"
18#include "llvm/PassManager.h"
19#include "llvm/Support/CommandLine.h"
20#include "llvm/Transforms/IPO/PassManagerBuilder.h"
21#include "llvm/Transforms/Scalar.h"
22#include "llvm/Support/TargetRegistry.h"
23#include <iostream>
24
Tony Linthicumb4b54152011-12-12 21:14:40 +000025using namespace llvm;
26
27static cl::
28opt<bool> DisableHardwareLoops(
29 "disable-hexagon-hwloops", cl::Hidden,
30 cl::desc("Disable Hardware Loops for Hexagon target"));
31
32/// HexagonTargetMachineModule - Note that this is used on hosts that
33/// cannot link in a library unless there are references into the
34/// library. In particular, it seems that it is not possible to get
35/// things to work on Win32 without this. Though it is unused, do not
36/// remove it.
37extern "C" int HexagonTargetMachineModule;
38int HexagonTargetMachineModule = 0;
39
40extern "C" void LLVMInitializeHexagonTarget() {
41 // Register the target.
42 RegisterTargetMachine<HexagonTargetMachine> X(TheHexagonTarget);
Tony Linthicumb4b54152011-12-12 21:14:40 +000043}
44
45
46/// HexagonTargetMachine ctor - Create an ILP32 architecture model.
47///
48
49/// Hexagon_TODO: Do I need an aggregate alignment?
50///
51HexagonTargetMachine::HexagonTargetMachine(const Target &T, StringRef TT,
52 StringRef CPU, StringRef FS,
53 TargetOptions Options,
54 Reloc::Model RM,
55 CodeModel::Model CM,
56 CodeGenOpt::Level OL)
57 : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
58 DataLayout("e-p:32:32:32-i64:64:64-i32:32:32-i16:16:16-i1:32:32-a0:0") ,
Benjamin Kramer90345622011-12-16 19:08:59 +000059 Subtarget(TT, CPU, FS), InstrInfo(Subtarget), TLInfo(*this),
Tony Linthicumb4b54152011-12-12 21:14:40 +000060 TSInfo(*this),
61 FrameLowering(Subtarget),
62 InstrItins(&Subtarget.getInstrItineraryData()) {
63 setMCUseCFI(false);
64}
65
66// addPassesForOptimizations - Allow the backend (target) to add Target
67// Independent Optimization passes to the Pass Manager.
68bool HexagonTargetMachine::addPassesForOptimizations(PassManagerBase &PM) {
69
70 PM.add(createConstantPropagationPass());
71 PM.add(createLoopSimplifyPass());
72 PM.add(createDeadCodeEliminationPass());
73 PM.add(createConstantPropagationPass());
74 PM.add(createLoopUnrollPass());
75 PM.add(createLoopStrengthReducePass(getTargetLowering()));
76 return true;
77}
78
Andrew Trick843ee2e2012-02-03 05:12:41 +000079namespace {
80/// Hexagon Code Generator Pass Configuration Options.
81class HexagonPassConfig : public TargetPassConfig {
82public:
Andrew Trick061efcf2012-02-04 02:56:59 +000083 HexagonPassConfig(HexagonTargetMachine *TM, PassManagerBase &PM)
84 : TargetPassConfig(TM, PM) {}
Andrew Trick843ee2e2012-02-03 05:12:41 +000085
86 HexagonTargetMachine &getHexagonTargetMachine() const {
87 return getTM<HexagonTargetMachine>();
88 }
89
90 virtual bool addInstSelector();
91 virtual bool addPreRegAlloc();
92 virtual bool addPostRegAlloc();
93 virtual bool addPreSched2();
94 virtual bool addPreEmitPass();
95};
96} // namespace
97
Andrew Trick061efcf2012-02-04 02:56:59 +000098TargetPassConfig *HexagonTargetMachine::createPassConfig(PassManagerBase &PM) {
99 return new HexagonPassConfig(this, PM);
Andrew Trick843ee2e2012-02-03 05:12:41 +0000100}
101
102bool HexagonPassConfig::addInstSelector() {
103 PM.add(createHexagonRemoveExtendOps(getHexagonTargetMachine()));
104 PM.add(createHexagonISelDag(getHexagonTargetMachine()));
Tony Linthicumb4b54152011-12-12 21:14:40 +0000105 return false;
106}
107
108
Andrew Trick843ee2e2012-02-03 05:12:41 +0000109bool HexagonPassConfig::addPreRegAlloc() {
Tony Linthicumb4b54152011-12-12 21:14:40 +0000110 if (!DisableHardwareLoops) {
111 PM.add(createHexagonHardwareLoops());
112 }
113
114 return false;
115}
116
Andrew Trick843ee2e2012-02-03 05:12:41 +0000117bool HexagonPassConfig::addPostRegAlloc() {
118 PM.add(createHexagonCFGOptimizer(getHexagonTargetMachine()));
Tony Linthicumb4b54152011-12-12 21:14:40 +0000119 return true;
120}
121
122
Andrew Trick843ee2e2012-02-03 05:12:41 +0000123bool HexagonPassConfig::addPreSched2() {
Tony Linthicumb4b54152011-12-12 21:14:40 +0000124 PM.add(createIfConverterPass());
125 return true;
126}
127
Andrew Trick843ee2e2012-02-03 05:12:41 +0000128bool HexagonPassConfig::addPreEmitPass() {
Tony Linthicumb4b54152011-12-12 21:14:40 +0000129
130 if (!DisableHardwareLoops) {
131 PM.add(createHexagonFixupHwLoops());
132 }
133
134 // Expand Spill code for predicate registers.
Andrew Trick843ee2e2012-02-03 05:12:41 +0000135 PM.add(createHexagonExpandPredSpillCode(getHexagonTargetMachine()));
Tony Linthicumb4b54152011-12-12 21:14:40 +0000136
137 // Split up TFRcondsets into conditional transfers.
Andrew Trick843ee2e2012-02-03 05:12:41 +0000138 PM.add(createHexagonSplitTFRCondSets(getHexagonTargetMachine()));
Tony Linthicumb4b54152011-12-12 21:14:40 +0000139
140 return false;
141}