Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 //===- subzero/src/IceInstX86Base.h - Generic x86 instructions -*- C++ -*--===// | 1 //===- subzero/src/IceInstX86Base.h - Generic x86 instructions -*- C++ -*--===// |
| 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 /// \file | 10 /// \file |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 SizeT Number; // used for unique label generation. | 287 SizeT Number; // used for unique label generation. |
| 288 }; | 288 }; |
| 289 | 289 |
| 290 /// Conditional and unconditional branch instruction. | 290 /// Conditional and unconditional branch instruction. |
| 291 template <class Machine> class InstX86Br final : public InstX86Base<Machine> { | 291 template <class Machine> class InstX86Br final : public InstX86Base<Machine> { |
| 292 InstX86Br() = delete; | 292 InstX86Br() = delete; |
| 293 InstX86Br(const InstX86Br &) = delete; | 293 InstX86Br(const InstX86Br &) = delete; |
| 294 InstX86Br &operator=(const InstX86Br &) = delete; | 294 InstX86Br &operator=(const InstX86Br &) = delete; |
| 295 | 295 |
| 296 public: | 296 public: |
| 297 enum BrKind { Near, Far }; | |
| 298 | |
| 297 /// Create a conditional branch to a node. | 299 /// Create a conditional branch to a node. |
| 298 static InstX86Br * | 300 static InstX86Br * |
| 299 create(Cfg *Func, CfgNode *TargetTrue, CfgNode *TargetFalse, | 301 create(Cfg *Func, CfgNode *TargetTrue, CfgNode *TargetFalse, |
| 300 typename InstX86Base<Machine>::Traits::Cond::BrCond Condition) { | 302 typename InstX86Base<Machine>::Traits::Cond::BrCond Condition, |
| 303 BrKind Kind) { | |
| 301 assert(Condition != InstX86Base<Machine>::Traits::Cond::Br_None); | 304 assert(Condition != InstX86Base<Machine>::Traits::Cond::Br_None); |
| 302 const InstX86Label<Machine> *NoLabel = nullptr; | 305 const InstX86Label<Machine> *NoLabel = nullptr; |
| 303 return new (Func->allocate<InstX86Br>()) | 306 return new (Func->allocate<InstX86Br>()) |
| 304 InstX86Br(Func, TargetTrue, TargetFalse, NoLabel, Condition); | 307 InstX86Br(Func, TargetTrue, TargetFalse, NoLabel, Condition, Kind); |
| 305 } | 308 } |
| 306 /// Create an unconditional branch to a node. | 309 /// Create an unconditional branch to a node. |
| 307 static InstX86Br *create(Cfg *Func, CfgNode *Target) { | 310 static InstX86Br *create(Cfg *Func, CfgNode *Target, BrKind Kind) { |
| 308 const CfgNode *NoCondTarget = nullptr; | 311 const CfgNode *NoCondTarget = nullptr; |
| 309 const InstX86Label<Machine> *NoLabel = nullptr; | 312 const InstX86Label<Machine> *NoLabel = nullptr; |
| 310 return new (Func->allocate<InstX86Br>()) | 313 return new (Func->allocate<InstX86Br>()) |
| 311 InstX86Br(Func, NoCondTarget, Target, NoLabel, | 314 InstX86Br(Func, NoCondTarget, Target, NoLabel, |
| 312 InstX86Base<Machine>::Traits::Cond::Br_None); | 315 InstX86Base<Machine>::Traits::Cond::Br_None, Kind); |
| 313 } | 316 } |
| 314 /// Create a non-terminator conditional branch to a node, with a | 317 /// Create a non-terminator conditional branch to a node, with a |
| 315 /// fallthrough to the next instruction in the current node. This is | 318 /// fallthrough to the next instruction in the current node. This is |
| 316 /// used for switch lowering. | 319 /// used for switch lowering. |
| 317 static InstX86Br * | 320 static InstX86Br * |
| 318 create(Cfg *Func, CfgNode *Target, | 321 create(Cfg *Func, CfgNode *Target, |
| 319 typename InstX86Base<Machine>::Traits::Cond::BrCond Condition) { | 322 typename InstX86Base<Machine>::Traits::Cond::BrCond Condition, |
| 323 BrKind Kind) { | |
| 320 assert(Condition != InstX86Base<Machine>::Traits::Cond::Br_None); | 324 assert(Condition != InstX86Base<Machine>::Traits::Cond::Br_None); |
| 321 const CfgNode *NoUncondTarget = nullptr; | 325 const CfgNode *NoUncondTarget = nullptr; |
| 322 const InstX86Label<Machine> *NoLabel = nullptr; | 326 const InstX86Label<Machine> *NoLabel = nullptr; |
| 323 return new (Func->allocate<InstX86Br>()) | 327 return new (Func->allocate<InstX86Br>()) |
| 324 InstX86Br(Func, Target, NoUncondTarget, NoLabel, Condition); | 328 InstX86Br(Func, Target, NoUncondTarget, NoLabel, Condition, Kind); |
| 325 } | 329 } |
| 326 /// Create a conditional intra-block branch (or unconditional, if | 330 /// Create a conditional intra-block branch (or unconditional, if |
| 327 /// Condition==Br_None) to a label in the current block. | 331 /// Condition==Br_None) to a label in the current block. |
| 328 static InstX86Br * | 332 static InstX86Br * |
| 329 create(Cfg *Func, InstX86Label<Machine> *Label, | 333 create(Cfg *Func, InstX86Label<Machine> *Label, |
| 330 typename InstX86Base<Machine>::Traits::Cond::BrCond Condition) { | 334 typename InstX86Base<Machine>::Traits::Cond::BrCond Condition, |
| 335 BrKind Kind) { | |
| 331 const CfgNode *NoCondTarget = nullptr; | 336 const CfgNode *NoCondTarget = nullptr; |
| 332 const CfgNode *NoUncondTarget = nullptr; | 337 const CfgNode *NoUncondTarget = nullptr; |
| 333 return new (Func->allocate<InstX86Br>()) | 338 return new (Func->allocate<InstX86Br>()) |
| 334 InstX86Br(Func, NoCondTarget, NoUncondTarget, Label, Condition); | 339 InstX86Br(Func, NoCondTarget, NoUncondTarget, Label, Condition, Kind); |
| 335 } | 340 } |
| 336 const CfgNode *getTargetTrue() const { return TargetTrue; } | 341 const CfgNode *getTargetTrue() const { return TargetTrue; } |
| 337 const CfgNode *getTargetFalse() const { return TargetFalse; } | 342 const CfgNode *getTargetFalse() const { return TargetFalse; } |
| 343 bool isNear() const { return Kind == Near; } | |
| 338 bool optimizeBranch(const CfgNode *NextNode); | 344 bool optimizeBranch(const CfgNode *NextNode); |
| 339 uint32_t getEmitInstCount() const override { | 345 uint32_t getEmitInstCount() const override { |
| 340 uint32_t Sum = 0; | 346 uint32_t Sum = 0; |
| 341 if (Label) | 347 if (Label) |
| 342 ++Sum; | 348 ++Sum; |
| 343 if (getTargetTrue()) | 349 if (getTargetTrue()) |
| 344 ++Sum; | 350 ++Sum; |
| 345 if (getTargetFalse()) | 351 if (getTargetFalse()) |
| 346 ++Sum; | 352 ++Sum; |
| 347 return Sum; | 353 return Sum; |
| 348 } | 354 } |
| 349 bool isUnconditionalBranch() const override { | 355 bool isUnconditionalBranch() const override { |
| 350 return !Label && Condition == InstX86Base<Machine>::Traits::Cond::Br_None; | 356 return !Label && Condition == InstX86Base<Machine>::Traits::Cond::Br_None; |
| 351 } | 357 } |
| 352 bool repointEdges(CfgNode *OldNode, CfgNode *NewNode) override; | 358 bool repointEdges(CfgNode *OldNode, CfgNode *NewNode) override; |
| 353 void emit(const Cfg *Func) const override; | 359 void emit(const Cfg *Func) const override; |
| 354 void emitIAS(const Cfg *Func) const override; | 360 void emitIAS(const Cfg *Func) const override; |
| 355 void dump(const Cfg *Func) const override; | 361 void dump(const Cfg *Func) const override; |
| 356 static bool classof(const Inst *Inst) { | 362 static bool classof(const Inst *Inst) { |
| 357 return InstX86Base<Machine>::isClassof(Inst, InstX86Base<Machine>::Br); | 363 return InstX86Base<Machine>::isClassof(Inst, InstX86Base<Machine>::Br); |
| 358 } | 364 } |
| 359 | 365 |
| 360 private: | 366 private: |
| 361 InstX86Br(Cfg *Func, const CfgNode *TargetTrue, const CfgNode *TargetFalse, | 367 InstX86Br(Cfg *Func, const CfgNode *TargetTrue, const CfgNode *TargetFalse, |
| 362 const InstX86Label<Machine> *Label, | 368 const InstX86Label<Machine> *Label, |
| 363 typename InstX86Base<Machine>::Traits::Cond::BrCond Condition); | 369 typename InstX86Base<Machine>::Traits::Cond::BrCond Condition, |
| 370 BrKind Kind); | |
| 364 | 371 |
| 365 typename InstX86Base<Machine>::Traits::Cond::BrCond Condition; | 372 typename InstX86Base<Machine>::Traits::Cond::BrCond Condition; |
| 366 const CfgNode *TargetTrue; | 373 const CfgNode *TargetTrue; |
| 367 const CfgNode *TargetFalse; | 374 const CfgNode *TargetFalse; |
| 368 const InstX86Label<Machine> *Label; // Intra-block branch target | 375 const InstX86Label<Machine> *Label; // Intra-block branch target |
| 376 const BrKind Kind; | |
|
Jim Stichnoth
2015/07/30 15:20:23
Consider changing the field name to something more
ascull
2015/07/30 17:29:59
Done.
| |
| 369 }; | 377 }; |
| 370 | 378 |
| 371 /// Jump to a target outside this function, such as tailcall, nacljump, | 379 /// Jump to a target outside this function, such as tailcall, nacljump, |
| 372 /// naclret, unreachable. This is different from a Branch instruction | 380 /// naclret, unreachable. This is different from a Branch instruction |
| 373 /// in that there is no intra-function control flow to represent. | 381 /// in that there is no intra-function control flow to represent. |
| 374 template <class Machine> class InstX86Jmp final : public InstX86Base<Machine> { | 382 template <class Machine> class InstX86Jmp final : public InstX86Base<Machine> { |
| 375 InstX86Jmp() = delete; | 383 InstX86Jmp() = delete; |
| 376 InstX86Jmp(const InstX86Jmp &) = delete; | 384 InstX86Jmp(const InstX86Jmp &) = delete; |
| 377 InstX86Jmp &operator=(const InstX86Jmp &) = delete; | 385 InstX86Jmp &operator=(const InstX86Jmp &) = delete; |
| 378 | 386 |
| (...skipping 2760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3139 &InstX86Base<Machine>::Traits::Assembler::psrl}; \ | 3147 &InstX86Base<Machine>::Traits::Assembler::psrl}; \ |
| 3140 } \ | 3148 } \ |
| 3141 } | 3149 } |
| 3142 | 3150 |
| 3143 } // end of namespace X86Internal | 3151 } // end of namespace X86Internal |
| 3144 } // end of namespace Ice | 3152 } // end of namespace Ice |
| 3145 | 3153 |
| 3146 #include "IceInstX86BaseImpl.h" | 3154 #include "IceInstX86BaseImpl.h" |
| 3147 | 3155 |
| 3148 #endif // SUBZERO_SRC_ICEINSTX86BASE_H | 3156 #endif // SUBZERO_SRC_ICEINSTX86BASE_H |
| OLD | NEW |