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

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: Fixes Absolute Relocation Type for x86-64. 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 <iostream>
Jim Stichnoth 2016/02/02 17:13:44 System includes go at the end of the list.
John 2016/02/02 19:36:39 Done.
17
16 #include "IceOperand.h" 18 #include "IceOperand.h"
17 19
18 #include "IceCfg.h" 20 #include "IceCfg.h"
19 #include "IceCfgNode.h" 21 #include "IceCfgNode.h"
20 #include "IceInst.h" 22 #include "IceInst.h"
21 #include "IceInstVarIter.h" 23 #include "IceInstVarIter.h"
22 #include "IceTargetLowering.h" // dumping stack/frame pointer register 24 #include "IceTargetLowering.h" // dumping stack/frame pointer register
23 25
24 namespace Ice { 26 namespace Ice {
25 27
26 bool operator==(const RelocatableTuple &A, const RelocatableTuple &B) { 28 bool operator==(const RelocatableTuple &A, const RelocatableTuple &B) {
27 return A.Offset == B.Offset && A.Name == B.Name; 29 // A and B are the same if:
30 // (1) they have the same name; and
31 // (2) they have the same offset.
32 //
33 // (1) is trivial to implement, but (2) requires some care.
Jim Stichnoth 2016/02/02 17:13:44 I would s/implement/check/ .
John 2016/02/02 19:36:39 Done.
34 //
35 // For (2):
36 // if A and B have known offsets (i.e., no symbolic references), then
37 // A == B -> A.Offset == B.Offset.
38 // else each element i in A.OffsetExpr[i] must be the same (or have the same
39 // value) than B.OffsetExpr[i].
Jim Stichnoth 2016/02/02 17:13:44 s/than/as/
John 2016/02/02 19:36:39 Done.
40 if (A.Name != B.Name) {
41 return false;
42 }
43
44 bool BothHaveKnownOffsets = true;
45 RelocOffsetT OffsetA = 0;
46 RelocOffsetT OffsetB = 0;
47 for (SizeT i = 0; i < A.OffsetExpr.size() && BothHaveKnownOffsets; ++i) {
48 BothHaveKnownOffsets = A.OffsetExpr[i]->hasOffset();
49 if (BothHaveKnownOffsets) {
50 OffsetA += A.OffsetExpr[i]->getOffset();
51 }
52 }
53 for (SizeT i = 0; i < B.OffsetExpr.size() && BothHaveKnownOffsets; ++i) {
54 BothHaveKnownOffsets = B.OffsetExpr[i]->hasOffset();
55 if (BothHaveKnownOffsets) {
56 OffsetB += B.OffsetExpr[i]->getOffset();
57 }
58 }
59 if (BothHaveKnownOffsets) {
60 // Both have known offsets (i.e., no unresolved symbolic references), so
61 // A == B -> A.Offset == B.Offset.
62 return OffsetA == OffsetB;
63 }
64
65 // Otherwise, A and B are not the same if their OffsetExpr's have different
66 // sizes.
67 if (A.OffsetExpr.size() != B.OffsetExpr.size()) {
68 return false;
69 }
70
71 // If the OffsetExprs' sizes are the same, then
72 // for each i in OffsetExprSize:
73 for (SizeT i = 0; i < A.OffsetExpr.size(); ++i) {
74 const auto *const RelocOffsetA = A.OffsetExpr[i];
75 const auto *const RelocOffsetB = B.OffsetExpr[i];
76 if (RelocOffsetA->hasOffset() && RelocOffsetB->hasOffset()) {
77 // A.OffsetExpr[i].Offset == B.OffsetExpr[i].Offset iff they are both
78 // defined;
79 if (RelocOffsetA->getOffset() != RelocOffsetB->getOffset()) {
80 return false;
81 }
82 } else if (RelocOffsetA != RelocOffsetB) {
83 // or, if they are undefined, then the RelocOffsets must be the same.
84 return false;
85 }
86 }
87
88 return true;
28 } 89 }
29 90
30 bool operator<(const RegWeight &A, const RegWeight &B) { 91 bool operator<(const RegWeight &A, const RegWeight &B) {
31 return A.getWeight() < B.getWeight(); 92 return A.getWeight() < B.getWeight();
32 } 93 }
33 bool operator<=(const RegWeight &A, const RegWeight &B) { return !(B < A); } 94 bool operator<=(const RegWeight &A, const RegWeight &B) { return !(B < A); }
34 bool operator==(const RegWeight &A, const RegWeight &B) { 95 bool operator==(const RegWeight &A, const RegWeight &B) {
35 return !(B < A) && !(A < B); 96 return !(B < A) && !(A < B);
36 } 97 }
37 98
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 555
495 void ConstantRelocatable::dump(const Cfg *Func, Ostream &Str) const { 556 void ConstantRelocatable::dump(const Cfg *Func, Ostream &Str) const {
496 if (!BuildDefs::dump()) 557 if (!BuildDefs::dump())
497 return; 558 return;
498 Str << "@"; 559 Str << "@";
499 if (Func && !SuppressMangling) { 560 if (Func && !SuppressMangling) {
500 Str << Func->getContext()->mangleName(Name); 561 Str << Func->getContext()->mangleName(Name);
501 } else { 562 } else {
502 Str << Name; 563 Str << Name;
503 } 564 }
504 if (Offset) 565 const RelocOffsetT Offset = getOffset();
505 Str << "+" << Offset; 566 if (Offset) {
567 if (Offset >= 0) {
568 Str << "+";
569 }
570 Str << Offset;
571 }
506 } 572 }
507 573
508 void ConstantUndef::emit(TargetLowering *Target) const { Target->emit(this); } 574 void ConstantUndef::emit(TargetLowering *Target) const { Target->emit(this); }
509 575
510 void LiveRange::dump(Ostream &Str) const { 576 void LiveRange::dump(Ostream &Str) const {
511 if (!BuildDefs::dump()) 577 if (!BuildDefs::dump())
512 return; 578 return;
513 bool First = true; 579 bool First = true;
514 for (const RangeElementType &I : Range) { 580 for (const RangeElementType &I : Range) {
515 if (!First) 581 if (!First)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 if (getType() != IceType_i32 && getType() != IceType_i16 && 613 if (getType() != IceType_i32 && getType() != IceType_i16 &&
548 getType() != IceType_i8) 614 getType() != IceType_i8)
549 return false; 615 return false;
550 // The Following checks if the signed representation of Value is between 616 // The Following checks if the signed representation of Value is between
551 // -Threshold/2 and +Threshold/2 617 // -Threshold/2 and +Threshold/2
552 bool largerThanThreshold = Threshold / 2 + Value >= Threshold; 618 bool largerThanThreshold = Threshold / 2 + Value >= Threshold;
553 return largerThanThreshold; 619 return largerThanThreshold;
554 } 620 }
555 621
556 } // end of namespace Ice 622 } // 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