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

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: 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
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"
24 #include "IceTargetKinds.def"
25 #include "IceTypes.h" 25 #include "IceTypes.h"
26 26
27 namespace Ice { 27 namespace Ice {
28 28
29 class Operand { 29 class Operand {
30 Operand() = delete; 30 Operand() = delete;
31 Operand(const Operand &) = delete; 31 Operand(const Operand &) = delete;
32 Operand &operator=(const Operand &) = delete; 32 Operand &operator=(const Operand &) = delete;
33 33
34 public: 34 public:
35 static const 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 #define X(n) kConst_Target##n,
45 kConst_Num = kConst_Target + MaxTargetKinds, 44 TARGETKINDS_TABLE
45 #undef X
46 kConst_Max = kConst_Target0 + TARGETKINDS_TABLE_MAX,
46 kVariable, 47 kVariable,
47 kVariable_Target, // leave space for target-specific variable kinds 48 #define X(n) kVariable_Target##n,
48 kVariable_Num = kVariable_Target + MaxTargetKinds, 49 TARGETKINDS_TABLE
50 #undef X
51 kVariable_Max = kVariable_Target0 + TARGETKINDS_TABLE_MAX,
49 // Target-specific operand classes use kTarget as the starting 52 // Target-specific operand classes use kTarget as the starting
50 // point for their Kind enum space. Note that the value-spaces are shared 53 // point for their Kind enum space. Note that the value-spaces are shared
51 // across targets. To avoid confusion over the definition of shared 54 // across targets. To avoid confusion over the definition of shared
52 // values, an object specific to one target should never be passed 55 // values, an object specific to one target should never be passed
53 // to a different target. 56 // to a different target.
54 kTarget 57 #define X(n) kTarget##n,
58 TARGETKINDS_TABLE
59 #undef X
55 }; 60 };
56 OperandKind getKind() const { return Kind; } 61 OperandKind getKind() const { return Kind; }
57 Type getType() const { return Ty; } 62 Type getType() const { return Ty; }
58 63
59 /// Every Operand keeps an array of the Variables referenced in 64 /// Every Operand keeps an array of the Variables referenced in the operand.
60 /// the operand. This is so that the liveness operations can get 65 /// 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 66 /// variables of interest, without having to dig so far into the operand.
62 /// so far into the operand.
63 SizeT getNumVars() const { return NumVars; } 67 SizeT getNumVars() const { return NumVars; }
64 Variable *getVar(SizeT I) const { 68 Variable *getVar(SizeT I) const {
65 assert(I < getNumVars()); 69 assert(I < getNumVars());
66 return Vars[I]; 70 return Vars[I];
67 } 71 }
68 virtual void emit(const Cfg *Func) const = 0; 72 virtual void emit(const Cfg *Func) const = 0;
69 73
70 /// \name Dumping functions. 74 /// \name Dumping functions.
71 /// @{ 75 /// @{
72 76
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 115
112 public: 116 public:
113 void emitPoolLabel(Ostream &Str) const { 117 void emitPoolLabel(Ostream &Str) const {
114 Str << ".L$" << getType() << "$" << PoolEntryID; 118 Str << ".L$" << getType() << "$" << PoolEntryID;
115 } 119 }
116 void emit(const Cfg *Func) const override { emit(Func->getTarget()); } 120 void emit(const Cfg *Func) const override { emit(Func->getTarget()); }
117 virtual void emit(TargetLowering *Target) const = 0; 121 virtual void emit(TargetLowering *Target) const = 0;
118 122
119 static bool classof(const Operand *Operand) { 123 static bool classof(const Operand *Operand) {
120 OperandKind Kind = Operand->getKind(); 124 OperandKind Kind = Operand->getKind();
121 return Kind >= kConst_Base && Kind <= kConst_Num; 125 return Kind >= kConst_Base && Kind <= kConst_Max;
122 } 126 }
123 127
124 /// Judge if this given immediate should be randomized or pooled 128 /// Judge if this given immediate should be randomized or pooled
125 /// By default should return false, only constant integers should 129 /// By default should return false, only constant integers should
126 /// truly go through this method. 130 /// truly go through this method.
127 virtual bool shouldBeRandomizedOrPooled(const GlobalContext *Ctx) { 131 virtual bool shouldBeRandomizedOrPooled(const GlobalContext *Ctx) {
128 (void)Ctx; 132 (void)Ctx;
129 return false; 133 return false;
130 } 134 }
131 135
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 505
502 void emit(const Cfg *Func) const override; 506 void emit(const Cfg *Func) const override;
503 using Operand::dump; 507 using Operand::dump;
504 void dump(const Cfg *Func, Ostream &Str) const override; 508 void dump(const Cfg *Func, Ostream &Str) const override;
505 509
506 /// Return reg num of base register, if different from stack/frame register. 510 /// Return reg num of base register, if different from stack/frame register.
507 virtual int32_t getBaseRegNum() const { return NoRegister; } 511 virtual int32_t getBaseRegNum() const { return NoRegister; }
508 512
509 static bool classof(const Operand *Operand) { 513 static bool classof(const Operand *Operand) {
510 OperandKind Kind = Operand->getKind(); 514 OperandKind Kind = Operand->getKind();
511 return Kind >= kVariable && Kind <= kVariable_Num; 515 return Kind >= kVariable && Kind <= kVariable_Max;
512 } 516 }
513 517
514 protected: 518 protected:
515 Variable(OperandKind K, Type Ty, SizeT Index) 519 Variable(OperandKind K, Type Ty, SizeT Index)
516 : Operand(K, Ty), Number(Index) { 520 : Operand(K, Ty), Number(Index) {
517 Vars = VarsReal; 521 Vars = VarsReal;
518 Vars[0] = this; 522 Vars[0] = this;
519 NumVars = 1; 523 NumVars = 1;
520 } 524 }
521 /// Number is unique across all variables, and is used as a 525 /// 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: 660 private:
657 const Cfg *Func; 661 const Cfg *Func;
658 MetadataKind Kind; 662 MetadataKind Kind;
659 std::vector<VariableTracking> Metadata; 663 std::vector<VariableTracking> Metadata;
660 const static InstDefList NoDefinitions; 664 const static InstDefList NoDefinitions;
661 }; 665 };
662 666
663 } // end of namespace Ice 667 } // end of namespace Ice
664 668
665 #endif // SUBZERO_SRC_ICEOPERAND_H 669 #endif // SUBZERO_SRC_ICEOPERAND_H
OLDNEW
« src/IceInst.h ('K') | « src/IceInstX86Base.h ('k') | src/IceTargetKinds.def » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698