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

Side by Side Diff: src/IceGlobalInits.cpp

Issue 624663002: Introduce model of global initializers in Subzero. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Fix nits. Created 6 years, 2 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/IceGlobalInits.h ('k') | src/IceTargetLowering.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 //===- subzero/src/IceGlobalInits.cpp - Global initializers ---------------===//
2 //
3 // The Subzero Code Generator
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the notion of global addresses and
11 // initializers in Subzero.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "llvm/ADT/STLExtras.h"
16 #include "llvm/IR/Function.h"
17 #include "llvm/IR/Value.h"
18
19 #include "IceDefs.h"
20 #include "IceGlobalInits.h"
21 #include "IceTypes.h"
22
23 namespace {
24 char hexdigit(unsigned X) { return X < 10 ? '0' + X : 'A' + X - 10; }
25 }
26
27 namespace Ice {
28
29 GlobalAddress::~GlobalAddress() { llvm::DeleteContainerPointers(Initializers); }
30
31 void GlobalAddress::dumpType(Ostream &Stream) const {
32 if (Initializers.size() == 1) {
33 Initializers.front()->dumpType(Stream);
34 } else {
35 Stream << "<{ ";
36 bool IsFirst = true;
37 for (Initializer *Init : Initializers) {
38 if (IsFirst) {
39 IsFirst = false;
40 } else {
41 Stream << ", ";
42 }
43 Init->dumpType(Stream);
44 }
45 Stream << " }>";
46 }
47 }
48
49 void GlobalAddress::dump(Ostream &Stream) const {
50 Stream << "@" << getName() << " = internal "
51 << (IsConstant ? "constant" : "global") << " ";
52
53 // Add initializer.
54 if (Initializers.size() == 1) {
55 Initializers.front()->dump(Stream);
56 } else {
57 dumpType(Stream);
58 Stream << " <{ ";
59 bool IsFirst = true;
60 for (Initializer *Init : Initializers) {
61 if (IsFirst) {
62 IsFirst = false;
63 } else {
64 Stream << ", ";
65 }
66 Init->dump(Stream);
67 }
68 Stream << " }>";
69 }
70
71 // Add alignment.
72 if (Alignment > 0)
73 Stream << ", align " << Alignment;
74 Stream << "\n";
75 }
76
77 void GlobalAddress::Initializer::dumpType(Ostream &Stream) const {
78 Stream << "[" << getNumBytes() << " x " << Ice::IceType_i8 << "]";
79 }
80
81 void GlobalAddress::DataInitializer::dump(Ostream &Stream) const {
82 dumpType(Stream);
83 Stream << " c\"";
84 // Code taken from PrintEscapedString() in AsmWriter.cpp. Keep
85 // the strings in the same format as the .ll file for practical
86 // diffing.
87 for (uint8_t C : Contents) {
88 if (isprint(C) && C != '\\' && C != '"')
89 Stream << C;
90 else
91 Stream << '\\' << hexdigit(C >> 4) << hexdigit(C & 0x0F);
92 }
93 Stream << "\"";
94 }
95
96 void GlobalAddress::ZeroInitializer::dump(Ostream &Stream) const {
97 dumpType(Stream);
98 Stream << " zeroinitializer";
99 }
100
101 IceString GlobalAddress::RelocInitializer::getName() const {
102 switch (Address.getKind()) {
103 case FunctionRelocation:
104 return Address.getFunction()->getName();
105 case GlobalAddressRelocation:
106 return Address.getGlobalAddr()->getName();
107 default:
108 llvm::report_fatal_error("Malformed relocation address!");
109 }
110 }
111
112 void GlobalAddress::RelocInitializer::dumpType(Ostream &Stream) const {
113 Stream << Ice::IceType_i32;
114 }
115
116 void GlobalAddress::RelocInitializer::dump(Ostream &Stream) const {
117 if (Offset != 0) {
118 dumpType(Stream);
119 Stream << " add (";
120 }
121 dumpType(Stream);
122 Stream << " ptrtoint (";
123 if (Address.getKind() == FunctionRelocation) {
124 Stream << *Address.getFunction()->getType() << " @"
125 << Address.getFunction()->getName();
126 } else {
127 Address.getGlobalAddr()->dumpType(Stream);
128 Stream << "* @" << Address.getGlobalAddr()->getName();
129 }
130 Stream << " to ";
131 dumpType(Stream);
132 Stream << ")";
133 if (Offset != 0) {
134 Stream << ", ";
135 dumpType(Stream);
136 Stream << " " << Offset << ")";
137 }
138 }
139 }
OLDNEW
« no previous file with comments | « src/IceGlobalInits.h ('k') | src/IceTargetLowering.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698