blob: 133afa0973288c9770250ac7c624df17165f4e98 [file] [log] [blame]
Jia Liu31d157a2012-02-18 12:03:15 +00001//===-- HexagonTargetMachine.cpp - Define TargetMachine for Hexagon -------===//
Tony Linthicumb4b54152011-12-12 21:14:40 +00002//
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//
Jia Liu31d157a2012-02-18 12:03:15 +000010// Implements the info about Hexagon target spec.
Tony Linthicumb4b54152011-12-12 21:14:40 +000011//
12//===----------------------------------------------------------------------===//
13
Tony Linthicumb4b54152011-12-12 21:14:40 +000014#include "HexagonTargetMachine.h"
15#include "Hexagon.h"
16#include "HexagonISelLowering.h"
17#include "llvm/Module.h"
18#include "llvm/CodeGen/Passes.h"
19#include "llvm/PassManager.h"
Tony Linthicumb4b54152011-12-12 21:14:40 +000020#include "llvm/Transforms/IPO/PassManagerBuilder.h"
21#include "llvm/Transforms/Scalar.h"
Benjamin Kramerf3fd7ee2012-02-06 10:19:29 +000022#include "llvm/Support/CommandLine.h"
Tony Linthicumb4b54152011-12-12 21:14:40 +000023#include "llvm/Support/TargetRegistry.h"
Tony Linthicumb4b54152011-12-12 21:14:40 +000024
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"));
Brendon Cahoon6d532d82012-05-11 19:56:59 +000031static cl::
32opt<bool> DisableCExtOpt(
33 "disable-hexagon-cextopt", cl::Hidden,
34 cl::desc("Disable Optimization of Constant Extenders"));
Tony Linthicumb4b54152011-12-12 21:14:40 +000035
36/// HexagonTargetMachineModule - Note that this is used on hosts that
37/// cannot link in a library unless there are references into the
38/// library. In particular, it seems that it is not possible to get
39/// things to work on Win32 without this. Though it is unused, do not
40/// remove it.
41extern "C" int HexagonTargetMachineModule;
42int HexagonTargetMachineModule = 0;
43
44extern "C" void LLVMInitializeHexagonTarget() {
45 // Register the target.
46 RegisterTargetMachine<HexagonTargetMachine> X(TheHexagonTarget);
Tony Linthicumb4b54152011-12-12 21:14:40 +000047}
48
49
50/// HexagonTargetMachine ctor - Create an ILP32 architecture model.
51///
52
53/// Hexagon_TODO: Do I need an aggregate alignment?
54///
55HexagonTargetMachine::HexagonTargetMachine(const Target &T, StringRef TT,
56 StringRef CPU, StringRef FS,
Craig Topper1e0c9ab2012-03-17 09:24:09 +000057 const TargetOptions &Options,
Tony Linthicumb4b54152011-12-12 21:14:40 +000058 Reloc::Model RM,
59 CodeModel::Model CM,
60 CodeGenOpt::Level OL)
61 : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
Sirish Pande7517bbc2012-05-10 20:20:25 +000062 DataLayout("e-p:32:32:32-"
63 "i64:64:64-i32:32:32-i16:16:16-i1:32:32-"
64 "f64:64:64-f32:32:32-a0:0-n32") ,
Benjamin Kramer90345622011-12-16 19:08:59 +000065 Subtarget(TT, CPU, FS), InstrInfo(Subtarget), TLInfo(*this),
Tony Linthicumb4b54152011-12-12 21:14:40 +000066 TSInfo(*this),
67 FrameLowering(Subtarget),
68 InstrItins(&Subtarget.getInstrItineraryData()) {
69 setMCUseCFI(false);
70}
71
72// addPassesForOptimizations - Allow the backend (target) to add Target
73// Independent Optimization passes to the Pass Manager.
74bool HexagonTargetMachine::addPassesForOptimizations(PassManagerBase &PM) {
75
76 PM.add(createConstantPropagationPass());
77 PM.add(createLoopSimplifyPass());
78 PM.add(createDeadCodeEliminationPass());
79 PM.add(createConstantPropagationPass());
80 PM.add(createLoopUnrollPass());
81 PM.add(createLoopStrengthReducePass(getTargetLowering()));
82 return true;
83}
84
Andrew Trick843ee2e2012-02-03 05:12:41 +000085namespace {
86/// Hexagon Code Generator Pass Configuration Options.
87class HexagonPassConfig : public TargetPassConfig {
88public:
Andrew Trick061efcf2012-02-04 02:56:59 +000089 HexagonPassConfig(HexagonTargetMachine *TM, PassManagerBase &PM)
90 : TargetPassConfig(TM, PM) {}
Andrew Trick843ee2e2012-02-03 05:12:41 +000091
92 HexagonTargetMachine &getHexagonTargetMachine() const {
93 return getTM<HexagonTargetMachine>();
94 }
95
96 virtual bool addInstSelector();
97 virtual bool addPreRegAlloc();
98 virtual bool addPostRegAlloc();
99 virtual bool addPreSched2();
100 virtual bool addPreEmitPass();
101};
102} // namespace
103
Andrew Trick061efcf2012-02-04 02:56:59 +0000104TargetPassConfig *HexagonTargetMachine::createPassConfig(PassManagerBase &PM) {
105 return new HexagonPassConfig(this, PM);
Andrew Trick843ee2e2012-02-03 05:12:41 +0000106}
107
108bool HexagonPassConfig::addInstSelector() {
Bill Wendling7c4ce302012-05-01 08:27:43 +0000109 PM->add(createHexagonRemoveExtendOps(getHexagonTargetMachine()));
110 PM->add(createHexagonISelDag(getHexagonTargetMachine()));
111 PM->add(createHexagonPeephole());
Tony Linthicumb4b54152011-12-12 21:14:40 +0000112 return false;
113}
114
115
Andrew Trick843ee2e2012-02-03 05:12:41 +0000116bool HexagonPassConfig::addPreRegAlloc() {
Brendon Cahoon6d532d82012-05-11 19:56:59 +0000117 if (!DisableCExtOpt) {
118 PM->add(createHexagonOptimizeConstExt(getHexagonTargetMachine()));
119 }
Tony Linthicumb4b54152011-12-12 21:14:40 +0000120 if (!DisableHardwareLoops) {
Bill Wendling7c4ce302012-05-01 08:27:43 +0000121 PM->add(createHexagonHardwareLoops());
Tony Linthicumb4b54152011-12-12 21:14:40 +0000122 }
Tony Linthicumb4b54152011-12-12 21:14:40 +0000123 return false;
124}
125
Andrew Trick843ee2e2012-02-03 05:12:41 +0000126bool HexagonPassConfig::addPostRegAlloc() {
Bill Wendling7c4ce302012-05-01 08:27:43 +0000127 PM->add(createHexagonCFGOptimizer(getHexagonTargetMachine()));
Tony Linthicumb4b54152011-12-12 21:14:40 +0000128 return true;
129}
130
131
Andrew Trick843ee2e2012-02-03 05:12:41 +0000132bool HexagonPassConfig::addPreSched2() {
Andrew Trick1dd8c852012-02-08 21:23:13 +0000133 addPass(IfConverterID);
Tony Linthicumb4b54152011-12-12 21:14:40 +0000134 return true;
135}
136
Andrew Trick843ee2e2012-02-03 05:12:41 +0000137bool HexagonPassConfig::addPreEmitPass() {
Tony Linthicumb4b54152011-12-12 21:14:40 +0000138
139 if (!DisableHardwareLoops) {
Bill Wendling7c4ce302012-05-01 08:27:43 +0000140 PM->add(createHexagonFixupHwLoops());
Tony Linthicumb4b54152011-12-12 21:14:40 +0000141 }
142
Sirish Pandeb3385702012-05-12 05:10:30 +0000143 PM->add(createHexagonNewValueJump());
144
Tony Linthicumb4b54152011-12-12 21:14:40 +0000145 // Expand Spill code for predicate registers.
Bill Wendling7c4ce302012-05-01 08:27:43 +0000146 PM->add(createHexagonExpandPredSpillCode(getHexagonTargetMachine()));
Tony Linthicumb4b54152011-12-12 21:14:40 +0000147
148 // Split up TFRcondsets into conditional transfers.
Bill Wendling7c4ce302012-05-01 08:27:43 +0000149 PM->add(createHexagonSplitTFRCondSets(getHexagonTargetMachine()));
Tony Linthicumb4b54152011-12-12 21:14:40 +0000150
Sirish Pande26f61a12012-05-03 21:52:53 +0000151 // Create Packets.
152 PM->add(createHexagonPacketizer());
153
Tony Linthicumb4b54152011-12-12 21:14:40 +0000154 return false;
155}