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

Side by Side Diff: src/IceTargetLowering.h

Issue 1775253003: Cache common constants before lowering. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Clean up code. Created 4 years, 9 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 | « no previous file | src/IceTargetLowering.cpp » ('j') | src/IceTargetLowering.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- subzero/src/IceTargetLowering.h - Lowering interface -----*- C++ -*-===// 1 //===- subzero/src/IceTargetLowering.h - Lowering interface -----*- 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 10 matching lines...) Expand all
21 //===----------------------------------------------------------------------===// 21 //===----------------------------------------------------------------------===//
22 22
23 #ifndef SUBZERO_SRC_ICETARGETLOWERING_H 23 #ifndef SUBZERO_SRC_ICETARGETLOWERING_H
24 #define SUBZERO_SRC_ICETARGETLOWERING_H 24 #define SUBZERO_SRC_ICETARGETLOWERING_H
25 25
26 #include "IceDefs.h" 26 #include "IceDefs.h"
27 #include "IceBitVector.h" 27 #include "IceBitVector.h"
28 #include "IceCfgNode.h" 28 #include "IceCfgNode.h"
29 #include "IceInst.h" // for the names of the Inst subtypes 29 #include "IceInst.h" // for the names of the Inst subtypes
30 #include "IceOperand.h" 30 #include "IceOperand.h"
31 #include "IceTargetLowering.def"
31 #include "IceTypes.h" 32 #include "IceTypes.h"
32 33
33 #include <utility> 34 #include <utility>
34 35
35 namespace Ice { 36 namespace Ice {
36 37
37 // UnimplementedError is defined as a macro so that we can get actual line 38 // UnimplementedError is defined as a macro so that we can get actual line
38 // numbers. 39 // numbers.
39 #define UnimplementedError(Flags) \ 40 #define UnimplementedError(Flags) \
40 do { \ 41 do { \
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 void assignVarStackSlots(VarList &SortedSpilledVariables, 455 void assignVarStackSlots(VarList &SortedSpilledVariables,
455 size_t SpillAreaPaddingBytes, 456 size_t SpillAreaPaddingBytes,
456 size_t SpillAreaSizeBytes, 457 size_t SpillAreaSizeBytes,
457 size_t GlobalsAndSubsequentPaddingSize, 458 size_t GlobalsAndSubsequentPaddingSize,
458 bool UsesFramePointer); 459 bool UsesFramePointer);
459 460
460 /// Sort the variables in Source based on required alignment. The variables 461 /// Sort the variables in Source based on required alignment. The variables
461 /// with the largest alignment need are placed in the front of the Dest list. 462 /// with the largest alignment need are placed in the front of the Dest list.
462 void sortVarsByAlignment(VarList &Dest, const VarList &Source) const; 463 void sortVarsByAlignment(VarList &Dest, const VarList &Source) const;
463 464
464 /// Make a call to an external helper function. 465 // Runtime helper function names
Karl 2016/03/16 22:50:52 Also moved this enum to global context, so that we
465 InstCall *makeHelperCall(const IceString &Name, Variable *Dest, 466 enum RuntimeHelperFuncKind {
467 #define X(Tag, Name) H_##Tag,
468 RUNTIME_HELPER_FUNCTIONS_TABLE
469 #undef X
470 H_Num
471 };
472
473 InstCall *makeHelperCall(RuntimeHelperFuncKind Target, Variable *Dest,
466 SizeT MaxSrcs); 474 SizeT MaxSrcs);
467 475
468 void _set_dest_redefined() { Context.getLastInserted()->setDestRedefined(); } 476 void _set_dest_redefined() { Context.getLastInserted()->setDestRedefined(); }
469 477
470 bool shouldOptimizeMemIntrins(); 478 bool shouldOptimizeMemIntrins();
471 479
472 void scalarizeArithmetic(InstArithmetic::OpKind K, Variable *Dest, 480 void scalarizeArithmetic(InstArithmetic::OpKind K, Variable *Dest,
473 Operand *Src0, Operand *Src1); 481 Operand *Src0, Operand *Src1);
474 482
475 /// Generalizes scalarizeArithmetic to support other instruction types. 483 /// Generalizes scalarizeArithmetic to support other instruction types.
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 570
563 Cfg *Func; 571 Cfg *Func;
564 GlobalContext *Ctx; 572 GlobalContext *Ctx;
565 bool HasComputedFrame = false; 573 bool HasComputedFrame = false;
566 bool CallsReturnsTwice = false; 574 bool CallsReturnsTwice = false;
567 SizeT NextLabelNumber = 0; 575 SizeT NextLabelNumber = 0;
568 SizeT NextJumpTableNumber = 0; 576 SizeT NextJumpTableNumber = 0;
569 LoweringContext Context; 577 LoweringContext Context;
570 const SandboxType SandboxingType = ST_None; 578 const SandboxType SandboxingType = ST_None;
571 579
572 // Runtime helper function names 580 /// Returns constant zero of Ty.
Jim Stichnoth 2016/03/10 00:24:46 You should probably also try to capture the calls
Karl 2016/03/16 22:50:52 The plan was to capture more constants. This CL wa
573 const static constexpr char *H_bitcast_16xi1_i16 = "__Sz_bitcast_16xi1_i16"; 581 Constant *getConstantZero(Type Ty) const {
574 const static constexpr char *H_bitcast_8xi1_i8 = "__Sz_bitcast_8xi1_i8"; 582 assert(Ty < IceType_NUM);
575 const static constexpr char *H_bitcast_i16_16xi1 = "__Sz_bitcast_i16_16xi1"; 583 if (Constant *Result = ConstZeroForType[Ty])
576 const static constexpr char *H_bitcast_i8_8xi1 = "__Sz_bitcast_i8_8xi1"; 584 return Result;
577 const static constexpr char *H_call_ctpop_i32 = "__popcountsi2"; 585 return Ctx->getConstantZero(Ty);
578 const static constexpr char *H_call_ctpop_i64 = "__popcountdi2"; 586 }
579 const static constexpr char *H_call_longjmp = "longjmp"; 587
580 const static constexpr char *H_call_memcpy = "memcpy"; 588 /// Returns the constant defining the corresponding runtime helper function.
581 const static constexpr char *H_call_memmove = "memmove"; 589 Constant *getRuntimeHelperFunc(RuntimeHelperFuncKind Kind) const {
Karl 2016/03/16 22:50:52 Moved this to global context, and modified body (h
582 const static constexpr char *H_call_memset = "memset"; 590 assert(Kind < H_Num);
583 const static constexpr char *H_call_read_tp = "__nacl_read_tp"; 591 Constant *Result = RuntimeHelperFunc[Kind];
584 const static constexpr char *H_call_setjmp = "setjmp"; 592 assert(Result != nullptr && "No such runtime helper function");
585 const static constexpr char *H_fptosi_f32_i64 = "__Sz_fptosi_f32_i64"; 593 return Result;
586 const static constexpr char *H_fptosi_f64_i64 = "__Sz_fptosi_f64_i64"; 594 }
587 const static constexpr char *H_fptoui_4xi32_f32 = "__Sz_fptoui_4xi32_f32"; 595
588 const static constexpr char *H_fptoui_f32_i32 = "__Sz_fptoui_f32_i32";
589 const static constexpr char *H_fptoui_f32_i64 = "__Sz_fptoui_f32_i64";
590 const static constexpr char *H_fptoui_f64_i32 = "__Sz_fptoui_f64_i32";
591 const static constexpr char *H_fptoui_f64_i64 = "__Sz_fptoui_f64_i64";
592 const static constexpr char *H_frem_f32 = "fmodf";
593 const static constexpr char *H_frem_f64 = "fmod";
594 const static constexpr char *H_getIP_prefix = "__Sz_getIP_"; 596 const static constexpr char *H_getIP_prefix = "__Sz_getIP_";
595 const static constexpr char *H_sdiv_i32 = "__divsi3"; 597
596 const static constexpr char *H_sdiv_i64 = "__divdi3"; 598 private:
597 const static constexpr char *H_sitofp_i64_f32 = "__Sz_sitofp_i64_f32"; 599 // Holds constant zero for each type.
598 const static constexpr char *H_sitofp_i64_f64 = "__Sz_sitofp_i64_f64"; 600 static Constant *ConstZeroForType[IceType_NUM];
John 2016/03/09 23:26:56 What do you think of making this array a non-stati
Karl 2016/03/16 22:50:52 Moved to global context, and used as cache inside
599 const static constexpr char *H_srem_i32 = "__modsi3"; 601 // Holds the constants representing each runtime helper function.
600 const static constexpr char *H_srem_i64 = "__moddi3"; 602 static Constant *RuntimeHelperFunc[H_Num];
Karl 2016/03/16 22:50:52 Also moved this array to global context (as non-st
601 const static constexpr char *H_udiv_i32 = "__udivsi3";
602 const static constexpr char *H_udiv_i64 = "__udivdi3";
603 const static constexpr char *H_uitofp_4xi32_4xf32 = "__Sz_uitofp_4xi32_4xf32";
604 const static constexpr char *H_uitofp_i32_f32 = "__Sz_uitofp_i32_f32";
605 const static constexpr char *H_uitofp_i32_f64 = "__Sz_uitofp_i32_f64";
606 const static constexpr char *H_uitofp_i64_f32 = "__Sz_uitofp_i64_f32";
607 const static constexpr char *H_uitofp_i64_f64 = "__Sz_uitofp_i64_f64";
608 const static constexpr char *H_urem_i32 = "__umodsi3";
609 const static constexpr char *H_urem_i64 = "__umoddi3";
610 }; 603 };
611 604
612 /// TargetDataLowering is used for "lowering" data including initializers for 605 /// TargetDataLowering is used for "lowering" data including initializers for
613 /// global variables, and the internal constant pools. It is separated out from 606 /// global variables, and the internal constant pools. It is separated out from
614 /// TargetLowering because it does not require a Cfg. 607 /// TargetLowering because it does not require a Cfg.
615 class TargetDataLowering { 608 class TargetDataLowering {
616 TargetDataLowering() = delete; 609 TargetDataLowering() = delete;
617 TargetDataLowering(const TargetDataLowering &) = delete; 610 TargetDataLowering(const TargetDataLowering &) = delete;
618 TargetDataLowering &operator=(const TargetDataLowering &) = delete; 611 TargetDataLowering &operator=(const TargetDataLowering &) = delete;
619 612
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 virtual void lower() {} 648 virtual void lower() {}
656 649
657 protected: 650 protected:
658 explicit TargetHeaderLowering(GlobalContext *Ctx) : Ctx(Ctx) {} 651 explicit TargetHeaderLowering(GlobalContext *Ctx) : Ctx(Ctx) {}
659 GlobalContext *Ctx; 652 GlobalContext *Ctx;
660 }; 653 };
661 654
662 } // end of namespace Ice 655 } // end of namespace Ice
663 656
664 #endif // SUBZERO_SRC_ICETARGETLOWERING_H 657 #endif // SUBZERO_SRC_ICETARGETLOWERING_H
OLDNEW
« no previous file with comments | « no previous file | src/IceTargetLowering.cpp » ('j') | src/IceTargetLowering.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698