LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HexagonTargetMachine.cpp
Go to the documentation of this file.
1 //===-- 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 // Implements the info about Hexagon target spec.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "HexagonTargetMachine.h"
15 #include "Hexagon.h"
16 #include "HexagonISelLowering.h"
19 #include "llvm/CodeGen/Passes.h"
20 #include "llvm/IR/Module.h"
21 #include "llvm/PassManager.h"
25 #include "llvm/Transforms/Scalar.h"
26 
27 using namespace llvm;
28 
29 static cl:: opt<bool> DisableHardwareLoops("disable-hexagon-hwloops",
30  cl::Hidden, cl::desc("Disable Hardware Loops for Hexagon target"));
31 
32 static cl::opt<bool> DisableHexagonMISched("disable-hexagon-misched",
34  cl::desc("Disable Hexagon MI Scheduling"));
35 
36 static cl::opt<bool> DisableHexagonCFGOpt("disable-hexagon-cfgopt",
38  cl::desc("Disable Hexagon CFG Optimization"));
39 
40 
41 /// HexagonTargetMachineModule - Note that this is used on hosts that
42 /// cannot link in a library unless there are references into the
43 /// library. In particular, it seems that it is not possible to get
44 /// things to work on Win32 without this. Though it is unused, do not
45 /// remove it.
48 
49 extern "C" void LLVMInitializeHexagonTarget() {
50  // Register the target.
52 }
53 
55  return new VLIWMachineScheduler(C, new ConvergingVLIWScheduler());
56 }
57 
59 SchedCustomRegistry("hexagon", "Run Hexagon's custom scheduler",
61 
62 /// HexagonTargetMachine ctor - Create an ILP32 architecture model.
63 ///
64 
65 /// Hexagon_TODO: Do I need an aggregate alignment?
66 ///
68  StringRef CPU, StringRef FS,
69  const TargetOptions &Options,
73  : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
74  DL("e-p:32:32:32-"
75  "i64:64:64-i32:32:32-i16:16:16-i1:32:32-"
76  "f64:64:64-f32:32:32-a0:0-n32") ,
77  Subtarget(TT, CPU, FS), InstrInfo(Subtarget), TLInfo(*this),
78  TSInfo(*this),
79  FrameLowering(Subtarget),
80  InstrItins(&Subtarget.getInstrItineraryData()) {
81  setMCUseCFI(false);
82  initAsmInfo();
83 }
84 
85 // addPassesForOptimizations - Allow the backend (target) to add Target
86 // Independent Optimization passes to the Pass Manager.
88  if (getOptLevel() != CodeGenOpt::None) {
90  PM.add(createLoopSimplifyPass());
93  PM.add(createLoopUnrollPass());
95  }
96  return true;
97 }
98 
99 namespace {
100 /// Hexagon Code Generator Pass Configuration Options.
101 class HexagonPassConfig : public TargetPassConfig {
102 public:
103  HexagonPassConfig(HexagonTargetMachine *TM, PassManagerBase &PM)
104  : TargetPassConfig(TM, PM) {
105  // FIXME: Rather than calling enablePass(&MachineSchedulerID) below, define
106  // HexagonSubtarget::enableMachineScheduler() { return true; }.
107  // That will bypass the SelectionDAG VLIW scheduler, which is probably just
108  // hurting compile time and will be removed eventually anyway.
110  disablePass(&MachineSchedulerID);
111  else
112  enablePass(&MachineSchedulerID);
113  }
114 
115  HexagonTargetMachine &getHexagonTargetMachine() const {
116  return getTM<HexagonTargetMachine>();
117  }
118 
119  virtual ScheduleDAGInstrs *
120  createMachineScheduler(MachineSchedContext *C) const {
121  return createVLIWMachineSched(C);
122  }
123 
124  virtual bool addInstSelector();
125  virtual bool addPreRegAlloc();
126  virtual bool addPostRegAlloc();
127  virtual bool addPreSched2();
128  virtual bool addPreEmitPass();
129 };
130 } // namespace
131 
133  return new HexagonPassConfig(this, PM);
134 }
135 
136 bool HexagonPassConfig::addInstSelector() {
137  HexagonTargetMachine &TM = getHexagonTargetMachine();
138  bool NoOpt = (getOptLevel() == CodeGenOpt::None);
139 
140  if (!NoOpt)
141  addPass(createHexagonRemoveExtendArgs(TM));
142 
143  addPass(createHexagonISelDag(TM, getOptLevel()));
144 
145  if (!NoOpt) {
146  addPass(createHexagonPeephole());
147  printAndVerify("After hexagon peephole pass");
148  }
149 
150  return false;
151 }
152 
153 bool HexagonPassConfig::addPreRegAlloc() {
154  if (getOptLevel() != CodeGenOpt::None)
156  addPass(createHexagonHardwareLoops());
157  return false;
158 }
159 
160 bool HexagonPassConfig::addPostRegAlloc() {
161  const HexagonTargetMachine &TM = getHexagonTargetMachine();
162  if (getOptLevel() != CodeGenOpt::None)
164  addPass(createHexagonCFGOptimizer(TM));
165  return false;
166 }
167 
168 bool HexagonPassConfig::addPreSched2() {
169  const HexagonTargetMachine &TM = getHexagonTargetMachine();
170  const HexagonTargetObjectFile &TLOF =
171  (const HexagonTargetObjectFile &)getTargetLowering()->getObjFileLowering();
172 
173  addPass(createHexagonCopyToCombine());
174  if (getOptLevel() != CodeGenOpt::None)
175  addPass(&IfConverterID);
176  if (!TLOF.IsSmallDataEnabled()) {
178  printAndVerify("After hexagon split const32/64 pass");
179  }
180  return true;
181 }
182 
183 bool HexagonPassConfig::addPreEmitPass() {
184  const HexagonTargetMachine &TM = getHexagonTargetMachine();
185  bool NoOpt = (getOptLevel() == CodeGenOpt::None);
186 
187  if (!NoOpt)
188  addPass(createHexagonNewValueJump());
189 
190  // Expand Spill code for predicate registers.
192 
193  // Split up TFRcondsets into conditional transfers.
194  addPass(createHexagonSplitTFRCondSets(TM));
195 
196  // Create Packets.
197  if (!NoOpt) {
199  addPass(createHexagonFixupHwLoops());
200  addPass(createHexagonPacketizer());
201  }
202 
203  return false;
204 }
FunctionPass * createHexagonCopyToCombine()
Pass * createLoopSimplifyPass()
Pass * createLoopStrengthReducePass()
void setMCUseCFI(bool Value)
setMCUseCFI - Set whether all we should use dwarf's .cfi_* directives.
static MachineSchedRegistry SchedCustomRegistry("hexagon","Run Hexagon's custom scheduler", createVLIWMachineSched)
char & MachineSchedulerID
MachineScheduler - This pass schedules machine instructions.
FunctionPass * createHexagonHardwareLoops()
FunctionPass * createConstantPropagationPass()
static cl::opt< bool > DisableHexagonMISched("disable-hexagon-misched", cl::Hidden, cl::ZeroOrMore, cl::init(false), cl::desc("Disable Hexagon MI Scheduling"))
HexagonTargetMachine(const Target &T, StringRef TT, StringRef CPU, StringRef FS, const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM, CodeGenOpt::Level OL)
FunctionPass * createDeadCodeEliminationPass()
Definition: DCE.cpp:131
FunctionPass * createHexagonFixupHwLoops()
CodeGenOpt::Level getOptLevel() const
Pass * createLoopUnrollPass(int Threshold=-1, int Count=-1, int AllowPartial=-1, int Runtime=-1)
int HexagonTargetMachineModule
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:314
static ScheduleDAGInstrs * createVLIWMachineSched(MachineSchedContext *C)
FunctionPass * createHexagonPacketizer()
static cl::opt< bool > DisableHexagonCFGOpt("disable-hexagon-cfgopt", cl::Hidden, cl::ZeroOrMore, cl::init(false), cl::desc("Disable Hexagon CFG Optimization"))
FunctionPass * createHexagonSplitConst32AndConst64(const HexagonTargetMachine &TM)
FunctionPass * createHexagonExpandPredSpillCode(const HexagonTargetMachine &TM)
virtual bool addPassesForOptimizations(PassManagerBase &PM)
FunctionPass * createHexagonNewValueJump()
FunctionPass * createHexagonCFGOptimizer(const HexagonTargetMachine &TM)
FunctionPass * createHexagonPeephole()
FunctionPass * createHexagonSplitTFRCondSets(const HexagonTargetMachine &TM)
FunctionPass * createHexagonRemoveExtendArgs(const HexagonTargetMachine &TM)
char & IfConverterID
IfConverter - This pass performs machine code if conversion.
FunctionPass * createHexagonISelDag(HexagonTargetMachine &TM, CodeGenOpt::Level OptLevel)
virtual TargetPassConfig * createPassConfig(PassManagerBase &PM)
static cl::opt< bool > DisableHardwareLoops("disable-hexagon-hwloops", cl::Hidden, cl::desc("Disable Hardware Loops for Hexagon target"))
Target TheHexagonTarget
static RegisterPass< NVPTXAllocaHoisting > X("alloca-hoisting","Hoisting alloca instructions in non-entry ""blocks to the entry block")
void LLVMInitializeHexagonTarget()