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

Side by Side Diff: src/IceOperand.cpp

Issue 1651163002: Subzero. Enables moar complex relocation offsets. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Addresses comments. Created 4 years, 10 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.cpp - High-level operand implementation -----===// 1 //===- subzero/src/IceOperand.cpp - High-level operand implementation -----===//
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 /// \brief Implements the Operand class and its target-independent subclasses, 11 /// \brief Implements the Operand class and its target-independent subclasses,
12 /// primarily for the methods of the Variable class. 12 /// primarily for the methods of the Variable class.
13 /// 13 ///
14 //===----------------------------------------------------------------------===// 14 //===----------------------------------------------------------------------===//
15 15
16 #include "IceOperand.h" 16 #include "IceOperand.h"
17 17
18 #include "IceCfg.h" 18 #include "IceCfg.h"
19 #include "IceCfgNode.h" 19 #include "IceCfgNode.h"
20 #include "IceInst.h" 20 #include "IceInst.h"
21 #include "IceInstVarIter.h" 21 #include "IceInstVarIter.h"
22 #include "IceTargetLowering.h" // dumping stack/frame pointer register 22 #include "IceTargetLowering.h" // dumping stack/frame pointer register
23 23
24 namespace Ice { 24 namespace Ice {
25 25
26 bool operator==(const RelocatableTuple &A, const RelocatableTuple &B) { 26 bool operator==(const RelocatableTuple &A, const RelocatableTuple &B) {
27 return A.Offset == B.Offset && A.Name == B.Name; 27 // A and B are the same if:
28 // (1) they have the same name; and
29 // (2) they have the same offset.
30 //
31 // (1) is trivial to check, but (2) requires some care.
32 //
33 // For (2):
34 // if A and B have known offsets (i.e., no symbolic references), then
35 // A == B -> A.Offset == B.Offset.
36 // else each element i in A.OffsetExpr[i] must be the same (or have the same
37 // value) as B.OffsetExpr[i].
38 if (A.Name != B.Name) {
39 return false;
40 }
41
42 bool BothHaveKnownOffsets = true;
43 RelocOffsetT OffsetA = 0;
44 RelocOffsetT OffsetB = 0;
45 for (SizeT i = 0; i < A.OffsetExpr.size() && BothHaveKnownOffsets; ++i) {
46 BothHaveKnownOffsets = A.OffsetExpr[i]->hasOffset();
47 if (BothHaveKnownOffsets) {
48 OffsetA += A.OffsetExpr[i]->getOffset();
49 }
50 }
51 for (SizeT i = 0; i < B.OffsetExpr.size() && BothHaveKnownOffsets; ++i) {
52 BothHaveKnownOffsets = B.OffsetExpr[i]->hasOffset();
53 if (BothHaveKnownOffsets) {
54 OffsetB += B.OffsetExpr[i]->getOffset();
55 }
56 }
57 if (BothHaveKnownOffsets) {
58 // Both have known offsets (i.e., no unresolved symbolic references), so
59 // A == B -> A.Offset == B.Offset.
60 return OffsetA == OffsetB;
61 }
62
63 // Otherwise, A and B are not the same if their OffsetExpr's have different
64 // sizes.
65 if (A.OffsetExpr.size() != B.OffsetExpr.size()) {
66 return false;
67 }
68
69 // If the OffsetExprs' sizes are the same, then
70 // for each i in OffsetExprSize:
71 for (SizeT i = 0; i < A.OffsetExpr.size(); ++i) {
72 const auto *const RelocOffsetA = A.OffsetExpr[i];
73 const auto *const RelocOffsetB = B.OffsetExpr[i];
74 if (RelocOffsetA->hasOffset() && RelocOffsetB->hasOffset()) {
75 // A.OffsetExpr[i].Offset == B.OffsetExpr[i].Offset iff they are both
76 // defined;
77 if (RelocOffsetA->getOffset() != RelocOffsetB->getOffset()) {
78 return false;
79 }
80 } else if (RelocOffsetA != RelocOffsetB) {
81 // or, if they are undefined, then the RelocOffsets must be the same.
82 return false;
83 }
84 }
85
86 return true;
28 } 87 }
29 88
30 bool operator<(const RegWeight &A, const RegWeight &B) { 89 bool operator<(const RegWeight &A, const RegWeight &B) {
31 return A.getWeight() < B.getWeight(); 90 return A.getWeight() < B.getWeight();
32 } 91 }
33 bool operator<=(const RegWeight &A, const RegWeight &B) { return !(B < A); } 92 bool operator<=(const RegWeight &A, const RegWeight &B) { return !(B < A); }
34 bool operator==(const RegWeight &A, const RegWeight &B) { 93 bool operator==(const RegWeight &A, const RegWeight &B) {
35 return !(B < A) && !(A < B); 94 return !(B < A) && !(A < B);
36 } 95 }
37 96
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 553
495 void ConstantRelocatable::dump(const Cfg *Func, Ostream &Str) const { 554 void ConstantRelocatable::dump(const Cfg *Func, Ostream &Str) const {
496 if (!BuildDefs::dump()) 555 if (!BuildDefs::dump())
497 return; 556 return;
498 Str << "@"; 557 Str << "@";
499 if (Func && !SuppressMangling) { 558 if (Func && !SuppressMangling) {
500 Str << Func->getContext()->mangleName(Name); 559 Str << Func->getContext()->mangleName(Name);
501 } else { 560 } else {
502 Str << Name; 561 Str << Name;
503 } 562 }
504 if (Offset) 563 const RelocOffsetT Offset = getOffset();
505 Str << "+" << Offset; 564 if (Offset) {
565 if (Offset >= 0) {
566 Str << "+";
567 }
568 Str << Offset;
569 }
506 } 570 }
507 571
508 void ConstantUndef::emit(TargetLowering *Target) const { Target->emit(this); } 572 void ConstantUndef::emit(TargetLowering *Target) const { Target->emit(this); }
509 573
510 void LiveRange::dump(Ostream &Str) const { 574 void LiveRange::dump(Ostream &Str) const {
511 if (!BuildDefs::dump()) 575 if (!BuildDefs::dump())
512 return; 576 return;
513 bool First = true; 577 bool First = true;
514 for (const RangeElementType &I : Range) { 578 for (const RangeElementType &I : Range) {
515 if (!First) 579 if (!First)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 if (getType() != IceType_i32 && getType() != IceType_i16 && 611 if (getType() != IceType_i32 && getType() != IceType_i16 &&
548 getType() != IceType_i8) 612 getType() != IceType_i8)
549 return false; 613 return false;
550 // The Following checks if the signed representation of Value is between 614 // The Following checks if the signed representation of Value is between
551 // -Threshold/2 and +Threshold/2 615 // -Threshold/2 and +Threshold/2
552 bool largerThanThreshold = Threshold / 2 + Value >= Threshold; 616 bool largerThanThreshold = Threshold / 2 + Value >= Threshold;
553 return largerThanThreshold; 617 return largerThanThreshold;
554 } 618 }
555 619
556 } // end of namespace Ice 620 } // end of namespace Ice
OLDNEW
« src/IceOperand.h ('K') | « src/IceOperand.h ('k') | src/IceTargetLowering.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698