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

Side by Side Diff: src/IceOperand.h

Issue 1311653003: Add UBSAN build option and fix undefined behaviour errors. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Remove x-macros Created 5 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/IceInst.h ('k') | no next file » | 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/IceOperand.h - High-level operands -----------*- C++ -*-===// 1 //===- subzero/src/IceOperand.h - High-level operands -----------*- 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
11 /// This file declares the Operand class and its target-independent 11 /// This file declares the Operand class and its target-independent subclasses.
12 /// subclasses. The main classes are Variable, which represents an 12 /// The main classes are Variable, which represents an LLVM variable that is
13 /// LLVM variable that is either register- or stack-allocated, and the 13 /// either register- or stack-allocated, and the Constant hierarchy, which
14 /// Constant hierarchy, which represents integer, floating-point, 14 /// represents integer, floating-point, and/or symbolic constants.
15 /// and/or symbolic constants.
16 /// 15 ///
17 //===----------------------------------------------------------------------===// 16 //===----------------------------------------------------------------------===//
18 17
19 #ifndef SUBZERO_SRC_ICEOPERAND_H 18 #ifndef SUBZERO_SRC_ICEOPERAND_H
20 #define SUBZERO_SRC_ICEOPERAND_H 19 #define SUBZERO_SRC_ICEOPERAND_H
21 20
22 #include "IceCfg.h" 21 #include "IceCfg.h"
23 #include "IceDefs.h" 22 #include "IceDefs.h"
24 #include "IceGlobalContext.h" 23 #include "IceGlobalContext.h"
25 #include "IceTypes.h" 24 #include "IceTypes.h"
26 25
27 namespace Ice { 26 namespace Ice {
28 27
29 class Operand { 28 class Operand {
30 Operand() = delete; 29 Operand() = delete;
31 Operand(const Operand &) = delete; 30 Operand(const Operand &) = delete;
32 Operand &operator=(const Operand &) = delete; 31 Operand &operator=(const Operand &) = delete;
33 32
34 public: 33 public:
35 static const size_t MaxTargetKinds = 10; 34 static constexpr size_t MaxTargetKinds = 10;
36 enum OperandKind { 35 enum OperandKind {
37 kConst_Base, 36 kConst_Base,
38 kConstInteger32, 37 kConstInteger32,
39 kConstInteger64, 38 kConstInteger64,
40 kConstFloat, 39 kConstFloat,
41 kConstDouble, 40 kConstDouble,
42 kConstRelocatable, 41 kConstRelocatable,
43 kConstUndef, 42 kConstUndef,
44 kConst_Target, // leave space for target-specific constant kinds 43 kConst_Target, // leave space for target-specific constant kinds
45 kConst_Num = kConst_Target + MaxTargetKinds, 44 kConst_Max = kConst_Target + MaxTargetKinds,
46 kVariable, 45 kVariable,
47 kVariable_Target, // leave space for target-specific variable kinds 46 kVariable_Target, // leave space for target-specific variable kinds
48 kVariable_Num = kVariable_Target + MaxTargetKinds, 47 kVariable_Max = kVariable_Target + MaxTargetKinds,
49 // Target-specific operand classes use kTarget as the starting 48 // Target-specific operand classes use kTarget as the starting
50 // point for their Kind enum space. Note that the value-spaces are shared 49 // point for their Kind enum space. Note that the value-spaces are shared
51 // across targets. To avoid confusion over the definition of shared 50 // across targets. To avoid confusion over the definition of shared
52 // values, an object specific to one target should never be passed 51 // values, an object specific to one target should never be passed
53 // to a different target. 52 // to a different target.
54 kTarget 53 kTarget,
54 kTarget_Max = kTarget + MaxTargetKinds,
Jim Stichnoth 2015/09/08 22:10:32 What do you think of setting kTarget_Max = uint8_t
55 }; 55 };
56 OperandKind getKind() const { return Kind; } 56 OperandKind getKind() const { return Kind; }
57 Type getType() const { return Ty; } 57 Type getType() const { return Ty; }
58 58
59 /// Every Operand keeps an array of the Variables referenced in 59 /// Every Operand keeps an array of the Variables referenced in the operand.
60 /// the operand. This is so that the liveness operations can get 60 /// This is so that the liveness operations can get quick access to the
61 /// quick access to the variables of interest, without having to dig 61 /// variables of interest, without having to dig so far into the operand.
62 /// so far into the operand.
63 SizeT getNumVars() const { return NumVars; } 62 SizeT getNumVars() const { return NumVars; }
64 Variable *getVar(SizeT I) const { 63 Variable *getVar(SizeT I) const {
65 assert(I < getNumVars()); 64 assert(I < getNumVars());
66 return Vars[I]; 65 return Vars[I];
67 } 66 }
68 virtual void emit(const Cfg *Func) const = 0; 67 virtual void emit(const Cfg *Func) const = 0;
69 68
70 /// \name Dumping functions. 69 /// \name Dumping functions.
71 /// @{ 70 /// @{
72 71
73 /// The dump(Func,Str) implementation must be sure to handle the 72 /// The dump(Func,Str) implementation must be sure to handle the
74 /// situation where Func==nullptr. 73 /// situation where Func==nullptr.
75 virtual void dump(const Cfg *Func, Ostream &Str) const = 0; 74 virtual void dump(const Cfg *Func, Ostream &Str) const = 0;
76 void dump(const Cfg *Func) const { 75 void dump(const Cfg *Func) const {
77 if (!BuildDefs::dump()) 76 if (!BuildDefs::dump())
78 return; 77 return;
79 assert(Func); 78 assert(Func);
80 dump(Func, Func->getContext()->getStrDump()); 79 dump(Func, Func->getContext()->getStrDump());
81 } 80 }
82 void dump(Ostream &Str) const { 81 void dump(Ostream &Str) const {
83 if (BuildDefs::dump()) 82 if (BuildDefs::dump())
84 dump(nullptr, Str); 83 dump(nullptr, Str);
85 } 84 }
86 /// @} 85 /// @}
87 86
88 protected: 87 protected:
89 Operand(OperandKind Kind, Type Ty) : Ty(Ty), Kind(Kind) {} 88 Operand(OperandKind Kind, Type Ty) : Ty(Ty), Kind(Kind) {
89 // It is undefined behavior to have a larger value in the enum
90 assert(Kind <= kTarget_Max);
91 }
90 virtual ~Operand() = default; 92 virtual ~Operand() = default;
91 93
92 const Type Ty; 94 const Type Ty;
93 const OperandKind Kind; 95 const OperandKind Kind;
94 /// Vars and NumVars are initialized by the derived class. 96 /// Vars and NumVars are initialized by the derived class.
95 SizeT NumVars = 0; 97 SizeT NumVars = 0;
96 Variable **Vars = nullptr; 98 Variable **Vars = nullptr;
97 }; 99 };
98 100
99 template <class StreamType> 101 template <class StreamType>
(...skipping 11 matching lines...) Expand all
111 113
112 public: 114 public:
113 void emitPoolLabel(Ostream &Str) const { 115 void emitPoolLabel(Ostream &Str) const {
114 Str << ".L$" << getType() << "$" << PoolEntryID; 116 Str << ".L$" << getType() << "$" << PoolEntryID;
115 } 117 }
116 void emit(const Cfg *Func) const override { emit(Func->getTarget()); } 118 void emit(const Cfg *Func) const override { emit(Func->getTarget()); }
117 virtual void emit(TargetLowering *Target) const = 0; 119 virtual void emit(TargetLowering *Target) const = 0;
118 120
119 static bool classof(const Operand *Operand) { 121 static bool classof(const Operand *Operand) {
120 OperandKind Kind = Operand->getKind(); 122 OperandKind Kind = Operand->getKind();
121 return Kind >= kConst_Base && Kind <= kConst_Num; 123 return Kind >= kConst_Base && Kind <= kConst_Max;
122 } 124 }
123 125
124 /// Judge if this given immediate should be randomized or pooled 126 /// Judge if this given immediate should be randomized or pooled
125 /// By default should return false, only constant integers should 127 /// By default should return false, only constant integers should
126 /// truly go through this method. 128 /// truly go through this method.
127 virtual bool shouldBeRandomizedOrPooled(const GlobalContext *Ctx) { 129 virtual bool shouldBeRandomizedOrPooled(const GlobalContext *Ctx) {
128 (void)Ctx; 130 (void)Ctx;
129 return false; 131 return false;
130 } 132 }
131 133
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 503
502 void emit(const Cfg *Func) const override; 504 void emit(const Cfg *Func) const override;
503 using Operand::dump; 505 using Operand::dump;
504 void dump(const Cfg *Func, Ostream &Str) const override; 506 void dump(const Cfg *Func, Ostream &Str) const override;
505 507
506 /// Return reg num of base register, if different from stack/frame register. 508 /// Return reg num of base register, if different from stack/frame register.
507 virtual int32_t getBaseRegNum() const { return NoRegister; } 509 virtual int32_t getBaseRegNum() const { return NoRegister; }
508 510
509 static bool classof(const Operand *Operand) { 511 static bool classof(const Operand *Operand) {
510 OperandKind Kind = Operand->getKind(); 512 OperandKind Kind = Operand->getKind();
511 return Kind >= kVariable && Kind <= kVariable_Num; 513 return Kind >= kVariable && Kind <= kVariable_Max;
512 } 514 }
513 515
514 protected: 516 protected:
515 Variable(OperandKind K, Type Ty, SizeT Index) 517 Variable(OperandKind K, Type Ty, SizeT Index)
516 : Operand(K, Ty), Number(Index) { 518 : Operand(K, Ty), Number(Index) {
517 Vars = VarsReal; 519 Vars = VarsReal;
518 Vars[0] = this; 520 Vars[0] = this;
519 NumVars = 1; 521 NumVars = 1;
520 } 522 }
521 /// Number is unique across all variables, and is used as a 523 /// Number is unique across all variables, and is used as a
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 private: 658 private:
657 const Cfg *Func; 659 const Cfg *Func;
658 MetadataKind Kind; 660 MetadataKind Kind;
659 std::vector<VariableTracking> Metadata; 661 std::vector<VariableTracking> Metadata;
660 const static InstDefList NoDefinitions; 662 const static InstDefList NoDefinitions;
661 }; 663 };
662 664
663 } // end of namespace Ice 665 } // end of namespace Ice
664 666
665 #endif // SUBZERO_SRC_ICEOPERAND_H 667 #endif // SUBZERO_SRC_ICEOPERAND_H
OLDNEW
« no previous file with comments | « src/IceInst.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698