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

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: Fix after native_client pull 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') | src/IceRNG.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/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 = std::numeric_limits<uint8_t>::max(),
55 }; 55 };
56 static_assert(kTarget <= kTarget_Max, "Must not be above max.");
56 OperandKind getKind() const { return Kind; } 57 OperandKind getKind() const { return Kind; }
57 Type getType() const { return Ty; } 58 Type getType() const { return Ty; }
58 59
59 /// Every Operand keeps an array of the Variables referenced in 60 /// Every Operand keeps an array of the Variables referenced in the operand.
60 /// the operand. This is so that the liveness operations can get 61 /// 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 62 /// variables of interest, without having to dig so far into the operand.
62 /// so far into the operand.
63 SizeT getNumVars() const { return NumVars; } 63 SizeT getNumVars() const { return NumVars; }
64 Variable *getVar(SizeT I) const { 64 Variable *getVar(SizeT I) const {
65 assert(I < getNumVars()); 65 assert(I < getNumVars());
66 return Vars[I]; 66 return Vars[I];
67 } 67 }
68 virtual void emit(const Cfg *Func) const = 0; 68 virtual void emit(const Cfg *Func) const = 0;
69 69
70 /// \name Dumping functions. 70 /// \name Dumping functions.
71 /// @{ 71 /// @{
72 72
73 /// The dump(Func,Str) implementation must be sure to handle the 73 /// The dump(Func,Str) implementation must be sure to handle the
74 /// situation where Func==nullptr. 74 /// situation where Func==nullptr.
75 virtual void dump(const Cfg *Func, Ostream &Str) const = 0; 75 virtual void dump(const Cfg *Func, Ostream &Str) const = 0;
76 void dump(const Cfg *Func) const { 76 void dump(const Cfg *Func) const {
77 if (!BuildDefs::dump()) 77 if (!BuildDefs::dump())
78 return; 78 return;
79 assert(Func); 79 assert(Func);
80 dump(Func, Func->getContext()->getStrDump()); 80 dump(Func, Func->getContext()->getStrDump());
81 } 81 }
82 void dump(Ostream &Str) const { 82 void dump(Ostream &Str) const {
83 if (BuildDefs::dump()) 83 if (BuildDefs::dump())
84 dump(nullptr, Str); 84 dump(nullptr, Str);
85 } 85 }
86 /// @} 86 /// @}
87 87
88 protected: 88 protected:
89 Operand(OperandKind Kind, Type Ty) : Ty(Ty), Kind(Kind) {} 89 Operand(OperandKind Kind, Type Ty) : Ty(Ty), Kind(Kind) {
90 // It is undefined behavior to have a larger value in the enum
91 assert(Kind <= kTarget_Max);
92 }
90 virtual ~Operand() = default; 93 virtual ~Operand() = default;
91 94
92 const Type Ty; 95 const Type Ty;
93 const OperandKind Kind; 96 const OperandKind Kind;
94 /// Vars and NumVars are initialized by the derived class. 97 /// Vars and NumVars are initialized by the derived class.
95 SizeT NumVars = 0; 98 SizeT NumVars = 0;
96 Variable **Vars = nullptr; 99 Variable **Vars = nullptr;
97 }; 100 };
98 101
99 template <class StreamType> 102 template <class StreamType>
(...skipping 11 matching lines...) Expand all
111 114
112 public: 115 public:
113 void emitPoolLabel(Ostream &Str) const { 116 void emitPoolLabel(Ostream &Str) const {
114 Str << ".L$" << getType() << "$" << PoolEntryID; 117 Str << ".L$" << getType() << "$" << PoolEntryID;
115 } 118 }
116 void emit(const Cfg *Func) const override { emit(Func->getTarget()); } 119 void emit(const Cfg *Func) const override { emit(Func->getTarget()); }
117 virtual void emit(TargetLowering *Target) const = 0; 120 virtual void emit(TargetLowering *Target) const = 0;
118 121
119 static bool classof(const Operand *Operand) { 122 static bool classof(const Operand *Operand) {
120 OperandKind Kind = Operand->getKind(); 123 OperandKind Kind = Operand->getKind();
121 return Kind >= kConst_Base && Kind <= kConst_Num; 124 return Kind >= kConst_Base && Kind <= kConst_Max;
122 } 125 }
123 126
124 /// Judge if this given immediate should be randomized or pooled 127 /// Judge if this given immediate should be randomized or pooled
125 /// By default should return false, only constant integers should 128 /// By default should return false, only constant integers should
126 /// truly go through this method. 129 /// truly go through this method.
127 virtual bool shouldBeRandomizedOrPooled(const GlobalContext *Ctx) { 130 virtual bool shouldBeRandomizedOrPooled(const GlobalContext *Ctx) {
128 (void)Ctx; 131 (void)Ctx;
129 return false; 132 return false;
130 } 133 }
131 134
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 504
502 void emit(const Cfg *Func) const override; 505 void emit(const Cfg *Func) const override;
503 using Operand::dump; 506 using Operand::dump;
504 void dump(const Cfg *Func, Ostream &Str) const override; 507 void dump(const Cfg *Func, Ostream &Str) const override;
505 508
506 /// Return reg num of base register, if different from stack/frame register. 509 /// Return reg num of base register, if different from stack/frame register.
507 virtual int32_t getBaseRegNum() const { return NoRegister; } 510 virtual int32_t getBaseRegNum() const { return NoRegister; }
508 511
509 static bool classof(const Operand *Operand) { 512 static bool classof(const Operand *Operand) {
510 OperandKind Kind = Operand->getKind(); 513 OperandKind Kind = Operand->getKind();
511 return Kind >= kVariable && Kind <= kVariable_Num; 514 return Kind >= kVariable && Kind <= kVariable_Max;
512 } 515 }
513 516
514 protected: 517 protected:
515 Variable(OperandKind K, Type Ty, SizeT Index) 518 Variable(OperandKind K, Type Ty, SizeT Index)
516 : Operand(K, Ty), Number(Index) { 519 : Operand(K, Ty), Number(Index) {
517 Vars = VarsReal; 520 Vars = VarsReal;
518 Vars[0] = this; 521 Vars[0] = this;
519 NumVars = 1; 522 NumVars = 1;
520 } 523 }
521 /// Number is unique across all variables, and is used as a 524 /// 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: 659 private:
657 const Cfg *Func; 660 const Cfg *Func;
658 MetadataKind Kind; 661 MetadataKind Kind;
659 std::vector<VariableTracking> Metadata; 662 std::vector<VariableTracking> Metadata;
660 const static InstDefList NoDefinitions; 663 const static InstDefList NoDefinitions;
661 }; 664 };
662 665
663 } // end of namespace Ice 666 } // end of namespace Ice
664 667
665 #endif // SUBZERO_SRC_ICEOPERAND_H 668 #endif // SUBZERO_SRC_ICEOPERAND_H
OLDNEW
« no previous file with comments | « src/IceInst.h ('k') | src/IceRNG.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698