blob: 8af95a9c206fa0d4854634e2b42822cdb5066d09 [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"));
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,
Craig Topper1e0c9ab2012-03-17 09:24:09 +000053 const TargetOptions &Options,
Tony Linthicumb4b54152011-12-12 21:14:40 +000054 Reloc::Model RM,
55 CodeModel::Model CM,
56 CodeGenOpt::Level OL)
57 : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
Sirish Pande7517bbc2012-05-10 20:20:25 +000058 DataLayout("e-p:32:32:32-"
59 "i64:64:64-i32:32:32-i16:16:16-i1:32:32-"
60 "f64:64:64-f32:32:32-a0:0-n32") ,
Benjamin Kramer90345622011-12-16 19:08:59 +000061 Subtarget(TT, CPU, FS), InstrInfo(Subtarget), TLInfo(*this),
Tony Linthicumb4b54152011-12-12 21:14:40 +000062 TSInfo(*this),
63 FrameLowering(Subtarget),
64 InstrItins(&Subtarget.getInstrItineraryData()) {
65 setMCUseCFI(false);
66}
67
68// addPassesForOptimizations - Allow the backend (target) to add Target
69// Independent Optimization passes to the Pass Manager.
70bool HexagonTargetMachine::addPassesForOptimizations(PassManagerBase &PM) {
71
72 PM.add(createConstantPropagationPass());
73 PM.add(createLoopSimplifyPass());
74 PM.add(createDeadCodeEliminationPass());
75 PM.add(createConstantPropagationPass());
76 PM.add(createLoopUnrollPass());
77 PM.add(createLoopStrengthReducePass(getTargetLowering()));
78 return true;
79}
80
Andrew Trick843ee2e2012-02-03 05:12:41 +000081namespace {
82/// Hexagon Code Generator Pass Configuration Options.
83class HexagonPassConfig : public TargetPassConfig {
84public:
Andrew Trick061efcf2012-02-04 02:56:59 +000085 HexagonPassConfig(HexagonTargetMachine *TM, PassManagerBase &PM)
86 : TargetPassConfig(TM, PM) {}
Andrew Trick843ee2e2012-02-03 05:12:41 +000087
88 HexagonTargetMachine &getHexagonTargetMachine() const {
89 return getTM<HexagonTargetMachine>();
90 }
91
92 virtual bool addInstSelector();
93 virtual bool addPreRegAlloc();
94 virtual bool addPostRegAlloc();
95 virtual bool addPreSched2();
96 virtual bool addPreEmitPass();
97};
98} // namespace
99
Andrew Trick061efcf2012-02-04 02:56:59 +0000100TargetPassConfig *HexagonTargetMachine::createPassConfig(PassManagerBase &PM) {
101 return new HexagonPassConfig(this, PM);
Andrew Trick843ee2e2012-02-03 05:12:41 +0000102}
103
104bool HexagonPassConfig::addInstSelector() {
Bill Wendling7c4ce302012-05-01 08:27:43 +0000105 PM->add(createHexagonRemoveExtendOps(getHexagonTargetMachine()));
106 PM->add(createHexagonISelDag(getHexagonTargetMachine()));
107 PM->add(createHexagonPeephole());
Tony Linthicumb4b54152011-12-12 21:14:40 +0000108 return false;
109}
110
111
Andrew Trick843ee2e2012-02-03 05:12:41 +0000112bool HexagonPassConfig::addPreRegAlloc() {
Tony Linthicumb4b54152011-12-12 21:14:40 +0000113 if (!DisableHardwareLoops) {
Bill Wendling7c4ce302012-05-01 08:27:43 +0000114 PM->add(createHexagonHardwareLoops());
Tony Linthicumb4b54152011-12-12 21:14:40 +0000115 }
Tony Linthicumb4b54152011-12-12 21:14:40 +0000116 return false;
117}
118
Andrew Trick843ee2e2012-02-03 05:12:41 +0000119bool HexagonPassConfig::addPostRegAlloc() {
Bill Wendling7c4ce302012-05-01 08:27:43 +0000120 PM->add(createHexagonCFGOptimizer(getHexagonTargetMachine()));
Tony Linthicumb4b54152011-12-12 21:14:40 +0000121 return true;
122}
123
124
Andrew Trick843ee2e2012-02-03 05:12:41 +0000125bool HexagonPassConfig::addPreSched2() {
Andrew Trick1dd8c852012-02-08 21:23:13 +0000126 addPass(IfConverterID);
Tony Linthicumb4b54152011-12-12 21:14:40 +0000127 return true;
128}
129
Andrew Trick843ee2e2012-02-03 05:12:41 +0000130bool HexagonPassConfig::addPreEmitPass() {
Tony Linthicumb4b54152011-12-12 21:14:40 +0000131
132 if (!DisableHardwareLoops) {
Bill Wendling7c4ce302012-05-01 08:27:43 +0000133 PM->add(createHexagonFixupHwLoops());
Tony Linthicumb4b54152011-12-12 21:14:40 +0000134 }
135
136 // Expand Spill code for predicate registers.
Bill Wendling7c4ce302012-05-01 08:27:43 +0000137 PM->add(createHexagonExpandPredSpillCode(getHexagonTargetMachine()));
Tony Linthicumb4b54152011-12-12 21:14:40 +0000138
139 // Split up TFRcondsets into conditional transfers.
Bill Wendling7c4ce302012-05-01 08:27:43 +0000140 PM->add(createHexagonSplitTFRCondSets(getHexagonTargetMachine()));
Tony Linthicumb4b54152011-12-12 21:14:40 +0000141
Sirish Pande26f61a12012-05-03 21:52:53 +0000142 // Create Packets.
143 PM->add(createHexagonPacketizer());
144
Tony Linthicumb4b54152011-12-12 21:14:40 +0000145 return false;
146}