OLD | NEW |
1 //===- subzero/src/IceTargetLowering.cpp - Basic lowering implementation --===// | 1 //===- subzero/src/IceTargetLowering.cpp - Basic lowering implementation --===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This file implements the skeleton of the TargetLowering class, | 10 // This file implements the skeleton of the TargetLowering class, |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "IceCfgNode.h" | 22 #include "IceCfgNode.h" |
23 #include "IceOperand.h" | 23 #include "IceOperand.h" |
24 #include "IceRegAlloc.h" | 24 #include "IceRegAlloc.h" |
25 #include "IceTargetLowering.h" | 25 #include "IceTargetLowering.h" |
26 #include "IceTargetLoweringX8632.h" | 26 #include "IceTargetLoweringX8632.h" |
27 | 27 |
28 namespace Ice { | 28 namespace Ice { |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
| 32 // TODO(stichnot): Move this machinery into llvm2ice.cpp. |
32 namespace cl = llvm::cl; | 33 namespace cl = llvm::cl; |
33 cl::opt<bool> DoNopInsertion("nop-insertion", cl::desc("Randomly insert NOPs"), | 34 cl::opt<bool> DoNopInsertion("nop-insertion", cl::desc("Randomly insert NOPs"), |
34 cl::init(false)); | 35 cl::init(false)); |
35 | 36 |
36 cl::opt<int> MaxNopsPerInstruction( | 37 cl::opt<int> MaxNopsPerInstruction( |
37 "max-nops-per-instruction", | 38 "max-nops-per-instruction", |
38 cl::desc("Max number of nops to insert per instruction"), cl::init(1)); | 39 cl::desc("Max number of nops to insert per instruction"), cl::init(1)); |
39 | 40 |
40 cl::opt<int> NopProbabilityAsPercentage( | 41 cl::opt<int> NopProbabilityAsPercentage( |
41 "nop-insertion-percentage", | 42 "nop-insertion-percentage", |
42 cl::desc("Nop insertion probability as percentage"), cl::init(10)); | 43 cl::desc("Nop insertion probability as percentage"), cl::init(10)); |
| 44 |
| 45 cl::opt<bool> |
| 46 CLRandomizeRegisterAllocation("randomize-regalloc", |
| 47 cl::desc("Randomize register allocation"), |
| 48 cl::init(false)); |
43 } // end of anonymous namespace | 49 } // end of anonymous namespace |
44 | 50 |
45 void LoweringContext::init(CfgNode *N) { | 51 void LoweringContext::init(CfgNode *N) { |
46 Node = N; | 52 Node = N; |
47 End = getNode()->getInsts().end(); | 53 End = getNode()->getInsts().end(); |
48 rewind(); | 54 rewind(); |
49 advanceForward(Next); | 55 advanceForward(Next); |
50 } | 56 } |
51 | 57 |
52 void LoweringContext::rewind() { | 58 void LoweringContext::rewind() { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 return IceTargetX8664::create(Func); | 94 return IceTargetX8664::create(Func); |
89 if (Target == Target_ARM32) | 95 if (Target == Target_ARM32) |
90 return IceTargetARM32::create(Func); | 96 return IceTargetARM32::create(Func); |
91 if (Target == Target_ARM64) | 97 if (Target == Target_ARM64) |
92 return IceTargetARM64::create(Func); | 98 return IceTargetARM64::create(Func); |
93 #endif | 99 #endif |
94 Func->setError("Unsupported target"); | 100 Func->setError("Unsupported target"); |
95 return NULL; | 101 return NULL; |
96 } | 102 } |
97 | 103 |
| 104 TargetLowering::TargetLowering(Cfg *Func) |
| 105 : Func(Func), Ctx(Func->getContext()), |
| 106 RandomizeRegisterAllocation(CLRandomizeRegisterAllocation), |
| 107 HasComputedFrame(false), CallsReturnsTwice(false), StackAdjustment(0), |
| 108 Context() {} |
| 109 |
98 Assembler *TargetLowering::createAssembler(TargetArch Target, Cfg *Func) { | 110 Assembler *TargetLowering::createAssembler(TargetArch Target, Cfg *Func) { |
99 // These statements can be #ifdef'd to specialize the assembler | 111 // These statements can be #ifdef'd to specialize the assembler |
100 // to a subset of the available targets. TODO: use CRTP. | 112 // to a subset of the available targets. TODO: use CRTP. |
101 if (Target == Target_X8632) | 113 if (Target == Target_X8632) |
102 return new x86::AssemblerX86(); | 114 return new x86::AssemblerX86(); |
103 Func->setError("Unsupported target"); | 115 Func->setError("Unsupported target"); |
104 return NULL; | 116 return NULL; |
105 } | 117 } |
106 | 118 |
107 void TargetLowering::doAddressOpt() { | 119 void TargetLowering::doAddressOpt() { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 TimerMarker T(TimerStack::TT_regAlloc, Func); | 241 TimerMarker T(TimerStack::TT_regAlloc, Func); |
230 LinearScan LinearScan(Func); | 242 LinearScan LinearScan(Func); |
231 RegSetMask RegInclude = RegSet_None; | 243 RegSetMask RegInclude = RegSet_None; |
232 RegSetMask RegExclude = RegSet_None; | 244 RegSetMask RegExclude = RegSet_None; |
233 RegInclude |= RegSet_CallerSave; | 245 RegInclude |= RegSet_CallerSave; |
234 RegInclude |= RegSet_CalleeSave; | 246 RegInclude |= RegSet_CalleeSave; |
235 if (hasFramePointer()) | 247 if (hasFramePointer()) |
236 RegExclude |= RegSet_FramePointer; | 248 RegExclude |= RegSet_FramePointer; |
237 LinearScan.init(Kind); | 249 LinearScan.init(Kind); |
238 llvm::SmallBitVector RegMask = getRegisterSet(RegInclude, RegExclude); | 250 llvm::SmallBitVector RegMask = getRegisterSet(RegInclude, RegExclude); |
239 LinearScan.scan(RegMask); | 251 LinearScan.scan(RegMask, RandomizeRegisterAllocation); |
240 } | 252 } |
241 | 253 |
242 TargetGlobalInitLowering * | 254 TargetGlobalInitLowering * |
243 TargetGlobalInitLowering::createLowering(TargetArch Target, | 255 TargetGlobalInitLowering::createLowering(TargetArch Target, |
244 GlobalContext *Ctx) { | 256 GlobalContext *Ctx) { |
245 // These statements can be #ifdef'd to specialize the code generator | 257 // These statements can be #ifdef'd to specialize the code generator |
246 // to a subset of the available targets. TODO: use CRTP. | 258 // to a subset of the available targets. TODO: use CRTP. |
247 if (Target == Target_X8632) | 259 if (Target == Target_X8632) |
248 return TargetGlobalInitX8632::create(Ctx); | 260 return TargetGlobalInitX8632::create(Ctx); |
249 #if 0 | 261 #if 0 |
250 if (Target == Target_X8664) | 262 if (Target == Target_X8664) |
251 return IceTargetGlobalInitX8664::create(Ctx); | 263 return IceTargetGlobalInitX8664::create(Ctx); |
252 if (Target == Target_ARM32) | 264 if (Target == Target_ARM32) |
253 return IceTargetGlobalInitARM32::create(Ctx); | 265 return IceTargetGlobalInitARM32::create(Ctx); |
254 if (Target == Target_ARM64) | 266 if (Target == Target_ARM64) |
255 return IceTargetGlobalInitARM64::create(Ctx); | 267 return IceTargetGlobalInitARM64::create(Ctx); |
256 #endif | 268 #endif |
257 llvm_unreachable("Unsupported target"); | 269 llvm_unreachable("Unsupported target"); |
258 return NULL; | 270 return NULL; |
259 } | 271 } |
260 | 272 |
261 TargetGlobalInitLowering::~TargetGlobalInitLowering() {} | 273 TargetGlobalInitLowering::~TargetGlobalInitLowering() {} |
262 | 274 |
263 } // end of namespace Ice | 275 } // end of namespace Ice |
OLD | NEW |