1 //===-- HexagonTargetMachine.cpp - Define TargetMachine for Hexagon -------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Implements the info about Hexagon target spec.
12 //===----------------------------------------------------------------------===//
14 #include "HexagonTargetMachine.h"
16 #include "HexagonISelLowering.h"
17 #include "llvm/Module.h"
18 #include "llvm/CodeGen/Passes.h"
19 #include "llvm/PassManager.h"
20 #include "llvm/Transforms/IPO/PassManagerBuilder.h"
21 #include "llvm/Transforms/Scalar.h"
22 #include "llvm/Support/CommandLine.h"
23 #include "llvm/Support/TargetRegistry.h"
28 opt<bool> DisableHardwareLoops(
29 "disable-hexagon-hwloops", cl::Hidden,
30 cl::desc("Disable Hardware Loops for Hexagon target"));
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
37 extern "C" int HexagonTargetMachineModule;
38 int HexagonTargetMachineModule = 0;
40 extern "C" void LLVMInitializeHexagonTarget() {
41 // Register the target.
42 RegisterTargetMachine<HexagonTargetMachine> X(TheHexagonTarget);
46 /// HexagonTargetMachine ctor - Create an ILP32 architecture model.
49 /// Hexagon_TODO: Do I need an aggregate alignment?
51 HexagonTargetMachine::HexagonTargetMachine(const Target &T, StringRef TT,
52 StringRef CPU, StringRef FS,
53 const TargetOptions &Options,
57 : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
58 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") ,
61 Subtarget(TT, CPU, FS), InstrInfo(Subtarget), TLInfo(*this),
63 FrameLowering(Subtarget),
64 InstrItins(&Subtarget.getInstrItineraryData()) {
68 // addPassesForOptimizations - Allow the backend (target) to add Target
69 // Independent Optimization passes to the Pass Manager.
70 bool HexagonTargetMachine::addPassesForOptimizations(PassManagerBase &PM) {
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()));
82 /// Hexagon Code Generator Pass Configuration Options.
83 class HexagonPassConfig : public TargetPassConfig {
85 HexagonPassConfig(HexagonTargetMachine *TM, PassManagerBase &PM)
86 : TargetPassConfig(TM, PM) {}
88 HexagonTargetMachine &getHexagonTargetMachine() const {
89 return getTM<HexagonTargetMachine>();
92 virtual bool addInstSelector();
93 virtual bool addPreRegAlloc();
94 virtual bool addPostRegAlloc();
95 virtual bool addPreSched2();
96 virtual bool addPreEmitPass();
100 TargetPassConfig *HexagonTargetMachine::createPassConfig(PassManagerBase &PM) {
101 return new HexagonPassConfig(this, PM);
104 bool HexagonPassConfig::addInstSelector() {
105 PM.add(createHexagonRemoveExtendOps(getHexagonTargetMachine()));
106 PM.add(createHexagonISelDag(getHexagonTargetMachine()));
107 PM.add(createHexagonPeephole());
112 bool HexagonPassConfig::addPreRegAlloc() {
113 if (!DisableHardwareLoops) {
114 PM.add(createHexagonHardwareLoops());
120 bool HexagonPassConfig::addPostRegAlloc() {
121 PM.add(createHexagonCFGOptimizer(getHexagonTargetMachine()));
126 bool HexagonPassConfig::addPreSched2() {
127 PM.add(createHexagonCopyToCombine());
128 addPass(IfConverterID);
132 bool HexagonPassConfig::addPreEmitPass() {
134 if (!DisableHardwareLoops) {
135 PM.add(createHexagonFixupHwLoops());
138 PM.add(createHexagonNewValueJump());
140 // Expand Spill code for predicate registers.
141 PM.add(createHexagonExpandPredSpillCode(getHexagonTargetMachine()));
143 // Split up TFRcondsets into conditional transfers.
144 PM.add(createHexagonSplitTFRCondSets(getHexagonTargetMachine()));
147 PM.add(createHexagonPacketizer());