OLD | NEW |
1 //===- subzero/src/IceFixups.cpp - Implementation of Assembler Fixups -----===// | 1 //===- subzero/src/IceFixups.cpp - Implementation of Assembler Fixups -----===// |
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 AssemblerFixup class, a very basic target-independent | 11 /// \brief Implements the AssemblerFixup class, a very basic target-independent |
12 /// representation of a fixup or relocation. | 12 /// representation of a fixup or relocation. |
13 /// | 13 /// |
14 //===----------------------------------------------------------------------===// | 14 //===----------------------------------------------------------------------===// |
15 | 15 |
16 #include "IceFixups.h" | 16 #include "IceFixups.h" |
17 | 17 |
18 #include "IceOperand.h" | 18 #include "IceOperand.h" |
19 | 19 |
20 namespace Ice { | 20 namespace Ice { |
21 | 21 |
22 const Constant *AssemblerFixup::NullSymbol = nullptr; | 22 const Constant *AssemblerFixup::NullSymbol = nullptr; |
23 | 23 |
24 RelocOffsetT AssemblerFixup::offset() const { | 24 RelocOffsetT AssemblerFixup::offset() const { |
25 if (isNullSymbol()) | 25 if (isNullSymbol()) |
26 return addend_; | 26 return addend_; |
27 if (const auto *CR = llvm::dyn_cast<ConstantRelocatable>(value_)) | 27 if (!ValueIsSymbol) { |
28 return CR->getOffset() + addend_; | 28 if (const auto *CR = llvm::dyn_cast<ConstantRelocatable>(ConstValue)) |
| 29 return CR->getOffset() + addend_; |
| 30 } |
29 return addend_; | 31 return addend_; |
30 } | 32 } |
31 | 33 |
32 IceString AssemblerFixup::symbol(const Assembler *Asm) const { | 34 IceString AssemblerFixup::symbol() const { |
| 35 assert(!isNullSymbol()); |
| 36 assert(!ValueIsSymbol); |
| 37 const Constant *C = ConstValue; |
| 38 if (const auto *CR = llvm::dyn_cast<ConstantRelocatable>(C)) { |
| 39 return CR->getName(); |
| 40 } |
| 41 // NOTE: currently only float/doubles are put into constant pools. In the |
| 42 // future we may put integers as well. |
| 43 assert(llvm::isa<ConstantFloat>(C) || llvm::isa<ConstantDouble>(C)); |
33 std::string Buffer; | 44 std::string Buffer; |
34 llvm::raw_string_ostream Str(Buffer); | 45 llvm::raw_string_ostream Str(Buffer); |
35 const Constant *C = value_; | 46 C->emitPoolLabel(Str); |
36 assert(!isNullSymbol()); | |
37 if (const auto *CR = llvm::dyn_cast<ConstantRelocatable>(C)) { | |
38 Str << CR->getName(); | |
39 if (Asm && !Asm->fixupIsPCRel(kind()) && | |
40 GlobalContext::getFlags().getUseNonsfi() && | |
41 CR->getName() != GlobalOffsetTable) { | |
42 // TODO(jpp): remove the special GOT test. | |
43 Str << "@GOTOFF"; | |
44 } | |
45 } else { | |
46 // NOTE: currently only float/doubles are put into constant pools. In the | |
47 // future we may put integers as well. | |
48 assert(llvm::isa<ConstantFloat>(C) || llvm::isa<ConstantDouble>(C)); | |
49 C->emitPoolLabel(Str); | |
50 } | |
51 return Str.str(); | 47 return Str.str(); |
52 } | 48 } |
53 | 49 |
54 size_t AssemblerFixup::emit(GlobalContext *Ctx, const Assembler &Asm) const { | 50 size_t AssemblerFixup::emit(GlobalContext *Ctx, const Assembler &Asm) const { |
55 static constexpr const size_t FixupSize = 4; | 51 static constexpr const size_t FixupSize = 4; |
56 if (!BuildDefs::dump()) | 52 if (!BuildDefs::dump()) |
57 return FixupSize; | 53 return FixupSize; |
58 Ostream &Str = Ctx->getStrEmit(); | 54 Ostream &Str = Ctx->getStrEmit(); |
59 Str << "\t.long "; | 55 Str << "\t.long "; |
60 IceString Symbol; | 56 IceString Symbol; |
61 if (isNullSymbol()) { | 57 if (isNullSymbol()) { |
62 Str << "__Sz_AbsoluteZero"; | 58 Str << "__Sz_AbsoluteZero"; |
63 } else { | 59 } else { |
64 Symbol = symbol(&Asm); | 60 Symbol = symbol(); |
65 Str << Symbol; | 61 Str << Symbol; |
| 62 assert(!ValueIsSymbol); |
| 63 if (const auto *CR = llvm::dyn_cast<ConstantRelocatable>(ConstValue)) { |
| 64 if (!Asm.fixupIsPCRel(kind()) && |
| 65 GlobalContext::getFlags().getUseNonsfi() && |
| 66 CR->getName() != GlobalOffsetTable) { |
| 67 Str << "@GOTOFF"; |
| 68 } |
| 69 } |
66 } | 70 } |
67 | 71 |
68 assert(Asm.load<RelocOffsetT>(position()) == 0); | 72 assert(Asm.load<RelocOffsetT>(position()) == 0); |
69 | 73 |
70 RelocOffsetT Offset = offset(); | 74 RelocOffsetT Offset = offset(); |
71 if (Offset != 0) { | 75 if (Offset != 0) { |
72 if (Offset > 0) { | 76 if (Offset > 0) { |
73 Str << " + " << Offset; | 77 Str << " + " << Offset; |
74 } else { | 78 } else { |
75 assert(Offset != std::numeric_limits<RelocOffsetT>::lowest()); | 79 assert(Offset != std::numeric_limits<RelocOffsetT>::lowest()); |
(...skipping 13 matching lines...) Expand all Loading... |
89 void AssemblerFixup::emitOffset(Assembler *Asm) const { | 93 void AssemblerFixup::emitOffset(Assembler *Asm) const { |
90 Asm->store(position(), offset()); | 94 Asm->store(position(), offset()); |
91 } | 95 } |
92 | 96 |
93 size_t AssemblerTextFixup::emit(GlobalContext *Ctx, const Assembler &) const { | 97 size_t AssemblerTextFixup::emit(GlobalContext *Ctx, const Assembler &) const { |
94 Ctx->getStrEmit() << Message << "\n"; | 98 Ctx->getStrEmit() << Message << "\n"; |
95 return NumBytes; | 99 return NumBytes; |
96 } | 100 } |
97 | 101 |
98 } // end of namespace Ice | 102 } // end of namespace Ice |
OLD | NEW |