Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(387)

Side by Side Diff: src/IceInstX8632.h

Issue 580903005: Subzero: Add branch optimization. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Code review changes Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/IceGlobalContext.cpp ('k') | src/IceInstX8632.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- subzero/src/IceInstX8632.h - Low-level x86 instructions --*- C++ -*-===// 1 //===- subzero/src/IceInstX8632.h - Low-level 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 // This file declares the InstX8632 and OperandX8632 classes and 10 // This file declares the InstX8632 and OperandX8632 classes and
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 Subss, 218 Subss,
219 Test, 219 Test,
220 Ucomiss, 220 Ucomiss,
221 UD2, 221 UD2,
222 Xadd, 222 Xadd,
223 Xchg, 223 Xchg,
224 Xor 224 Xor
225 }; 225 };
226 226
227 enum BrCond { 227 enum BrCond {
228 #define X(tag, dump, emit) tag, 228 #define X(tag, opp, dump, emit) tag,
229 ICEINSTX8632BR_TABLE 229 ICEINSTX8632BR_TABLE
230 #undef X 230 #undef X
231 Br_None 231 Br_None
232 }; 232 };
233 233
234 static const char *getWidthString(Type Ty); 234 static const char *getWidthString(Type Ty);
235 virtual void emit(const Cfg *Func) const = 0; 235 virtual void emit(const Cfg *Func) const = 0;
236 virtual void dump(const Cfg *Func) const; 236 virtual void dump(const Cfg *Func) const;
237 237
238 protected: 238 protected:
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 virtual ~InstX8632Label() {} 302 virtual ~InstX8632Label() {}
303 SizeT Number; // used only for unique label string generation 303 SizeT Number; // used only for unique label string generation
304 }; 304 };
305 305
306 // Conditional and unconditional branch instruction. 306 // Conditional and unconditional branch instruction.
307 class InstX8632Br : public InstX8632 { 307 class InstX8632Br : public InstX8632 {
308 public: 308 public:
309 // Create a conditional branch to a node. 309 // Create a conditional branch to a node.
310 static InstX8632Br *create(Cfg *Func, CfgNode *TargetTrue, 310 static InstX8632Br *create(Cfg *Func, CfgNode *TargetTrue,
311 CfgNode *TargetFalse, BrCond Condition) { 311 CfgNode *TargetFalse, BrCond Condition) {
312 const InstX8632Label *NoLabel = NULL;
312 return new (Func->allocate<InstX8632Br>()) 313 return new (Func->allocate<InstX8632Br>())
313 InstX8632Br(Func, TargetTrue, TargetFalse, NULL, Condition); 314 InstX8632Br(Func, TargetTrue, TargetFalse, NoLabel, Condition);
314 } 315 }
315 // Create an unconditional branch to a node. 316 // Create an unconditional branch to a node.
316 static InstX8632Br *create(Cfg *Func, CfgNode *Target) { 317 static InstX8632Br *create(Cfg *Func, CfgNode *Target) {
318 const CfgNode *NoCondTarget = NULL;
319 const InstX8632Label *NoLabel = NULL;
317 return new (Func->allocate<InstX8632Br>()) 320 return new (Func->allocate<InstX8632Br>())
318 InstX8632Br(Func, NULL, Target, NULL, Br_None); 321 InstX8632Br(Func, NoCondTarget, Target, NoLabel, Br_None);
319 } 322 }
320 // Create a non-terminator conditional branch to a node, with a 323 // Create a non-terminator conditional branch to a node, with a
321 // fallthrough to the next instruction in the current node. This is 324 // fallthrough to the next instruction in the current node. This is
322 // used for switch lowering. 325 // used for switch lowering.
323 static InstX8632Br *create(Cfg *Func, CfgNode *Target, BrCond Condition) { 326 static InstX8632Br *create(Cfg *Func, CfgNode *Target, BrCond Condition) {
327 const CfgNode *NoUncondTarget = NULL;
328 const InstX8632Label *NoLabel = NULL;
324 return new (Func->allocate<InstX8632Br>()) 329 return new (Func->allocate<InstX8632Br>())
325 InstX8632Br(Func, Target, NULL, NULL, Condition); 330 InstX8632Br(Func, Target, NoUncondTarget, NoLabel, Condition);
326 } 331 }
327 // Create a conditional intra-block branch (or unconditional, if 332 // Create a conditional intra-block branch (or unconditional, if
328 // Condition==Br_None) to a label in the current block. 333 // Condition==Br_None) to a label in the current block.
329 static InstX8632Br *create(Cfg *Func, InstX8632Label *Label, 334 static InstX8632Br *create(Cfg *Func, InstX8632Label *Label,
330 BrCond Condition) { 335 BrCond Condition) {
336 const CfgNode *NoCondTarget = NULL;
337 const CfgNode *NoUncondTarget = NULL;
331 return new (Func->allocate<InstX8632Br>()) 338 return new (Func->allocate<InstX8632Br>())
332 InstX8632Br(Func, NULL, NULL, Label, Condition); 339 InstX8632Br(Func, NoCondTarget, NoUncondTarget, Label, Condition);
333 } 340 }
334 CfgNode *getTargetTrue() const { return TargetTrue; } 341 const CfgNode *getTargetTrue() const { return TargetTrue; }
335 CfgNode *getTargetFalse() const { return TargetFalse; } 342 const CfgNode *getTargetFalse() const { return TargetFalse; }
343 bool optimizeBranch(const CfgNode *NextNode);
336 virtual uint32_t getEmitInstCount() const { 344 virtual uint32_t getEmitInstCount() const {
345 uint32_t Sum = 0;
337 if (Label) 346 if (Label)
338 return 1; 347 ++Sum;
339 if (Condition == Br_None) 348 if (getTargetTrue())
340 return 1; 349 ++Sum;
341 if (getTargetFalse()) 350 if (getTargetFalse())
342 return 2; 351 ++Sum;
343 return 1; 352 return Sum;
344 } 353 }
345 virtual void emit(const Cfg *Func) const; 354 virtual void emit(const Cfg *Func) const;
346 virtual void dump(const Cfg *Func) const; 355 virtual void dump(const Cfg *Func) const;
347 static bool classof(const Inst *Inst) { return isClassof(Inst, Br); } 356 static bool classof(const Inst *Inst) { return isClassof(Inst, Br); }
348 357
349 private: 358 private:
350 InstX8632Br(Cfg *Func, CfgNode *TargetTrue, CfgNode *TargetFalse, 359 InstX8632Br(Cfg *Func, const CfgNode *TargetTrue, const CfgNode *TargetFalse,
351 InstX8632Label *Label, BrCond Condition); 360 const InstX8632Label *Label, BrCond Condition);
352 InstX8632Br(const InstX8632Br &) LLVM_DELETED_FUNCTION; 361 InstX8632Br(const InstX8632Br &) LLVM_DELETED_FUNCTION;
353 InstX8632Br &operator=(const InstX8632Br &) LLVM_DELETED_FUNCTION; 362 InstX8632Br &operator=(const InstX8632Br &) LLVM_DELETED_FUNCTION;
354 virtual ~InstX8632Br() {} 363 virtual ~InstX8632Br() {}
355 BrCond Condition; 364 BrCond Condition;
356 CfgNode *TargetTrue; 365 const CfgNode *TargetTrue;
357 CfgNode *TargetFalse; 366 const CfgNode *TargetFalse;
358 InstX8632Label *Label; // Intra-block branch target 367 const InstX8632Label *Label; // Intra-block branch target
359 }; 368 };
360 369
361 // AdjustStack instruction - subtracts esp by the given amount and 370 // AdjustStack instruction - subtracts esp by the given amount and
362 // updates the stack offset during code emission. 371 // updates the stack offset during code emission.
363 class InstX8632AdjustStack : public InstX8632 { 372 class InstX8632AdjustStack : public InstX8632 {
364 public: 373 public:
365 static InstX8632AdjustStack *create(Cfg *Func, SizeT Amount) { 374 static InstX8632AdjustStack *create(Cfg *Func, SizeT Amount) {
366 return new (Func->allocate<InstX8632AdjustStack>()) 375 return new (Func->allocate<InstX8632AdjustStack>())
367 InstX8632AdjustStack(Func, Amount); 376 InstX8632AdjustStack(Func, Amount);
368 } 377 }
(...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after
1255 template <> void InstX8632Pmuludq::emit(const Cfg *Func) const; 1264 template <> void InstX8632Pmuludq::emit(const Cfg *Func) const;
1256 template <> void InstX8632Psll::emit(const Cfg *Func) const; 1265 template <> void InstX8632Psll::emit(const Cfg *Func) const;
1257 template <> void InstX8632Psra::emit(const Cfg *Func) const; 1266 template <> void InstX8632Psra::emit(const Cfg *Func) const;
1258 template <> void InstX8632Psub::emit(const Cfg *Func) const; 1267 template <> void InstX8632Psub::emit(const Cfg *Func) const;
1259 template <> void InstX8632Sqrtss::emit(const Cfg *Func) const; 1268 template <> void InstX8632Sqrtss::emit(const Cfg *Func) const;
1260 template <> void InstX8632Subss::emit(const Cfg *Func) const; 1269 template <> void InstX8632Subss::emit(const Cfg *Func) const;
1261 1270
1262 } // end of namespace Ice 1271 } // end of namespace Ice
1263 1272
1264 #endif // SUBZERO_SRC_ICEINSTX8632_H 1273 #endif // SUBZERO_SRC_ICEINSTX8632_H
OLDNEW
« no previous file with comments | « src/IceGlobalContext.cpp ('k') | src/IceInstX8632.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698