OLD | NEW |
1 //===- subzero/src/IceGlobalContext.cpp - Global context defs ---*- C++ -*-===// | 1 //===- subzero/src/IceGlobalContext.cpp - Global context defs ---*- 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 // This file defines aspects of the compilation that persist across | 10 // This file defines aspects of the compilation that persist across |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 // _ZN3foo3barExyz ==> _ZN6Prefix3foo3barExyz | 106 // _ZN3foo3barExyz ==> _ZN6Prefix3foo3barExyz |
107 // A non-nested but mangled name like bar() gets nested, making it | 107 // A non-nested but mangled name like bar() gets nested, making it |
108 // equivalent to Prefix::bar(). | 108 // equivalent to Prefix::bar(). |
109 // _Z3barxyz ==> ZN6Prefix3barExyz | 109 // _Z3barxyz ==> ZN6Prefix3barExyz |
110 // An unmangled, extern "C" style name, gets a simple prefix: | 110 // An unmangled, extern "C" style name, gets a simple prefix: |
111 // bar ==> Prefixbar | 111 // bar ==> Prefixbar |
112 if (getTestPrefix().empty()) | 112 if (getTestPrefix().empty()) |
113 return Name; | 113 return Name; |
114 | 114 |
115 unsigned PrefixLength = getTestPrefix().length(); | 115 unsigned PrefixLength = getTestPrefix().length(); |
116 char NameBase[1 + Name.length()]; | 116 llvm::SmallVector<char, 32> NameBase(1 + Name.length()); |
117 const size_t BufLen = 30 + Name.length() + PrefixLength; | 117 const size_t BufLen = 30 + Name.length() + PrefixLength; |
118 char NewName[BufLen]; | 118 llvm::SmallVector<char, 32> NewName(BufLen); |
119 uint32_t BaseLength = 0; // using uint32_t due to sscanf format string | 119 uint32_t BaseLength = 0; // using uint32_t due to sscanf format string |
120 | 120 |
121 int ItemsParsed = sscanf(Name.c_str(), "_ZN%s", NameBase); | 121 int ItemsParsed = sscanf(Name.c_str(), "_ZN%s", NameBase.data()); |
122 if (ItemsParsed == 1) { | 122 if (ItemsParsed == 1) { |
123 // Transform _ZN3foo3barExyz ==> _ZN6Prefix3foo3barExyz | 123 // Transform _ZN3foo3barExyz ==> _ZN6Prefix3foo3barExyz |
124 // (splice in "6Prefix") ^^^^^^^ | 124 // (splice in "6Prefix") ^^^^^^^ |
125 snprintf(NewName, BufLen, "_ZN%u%s%s", PrefixLength, | 125 snprintf(NewName.data(), BufLen, "_ZN%u%s%s", PrefixLength, |
126 getTestPrefix().c_str(), NameBase); | 126 getTestPrefix().c_str(), NameBase.data()); |
127 // We ignore the snprintf return value (here and below). If we | 127 // We ignore the snprintf return value (here and below). If we |
128 // somehow miscalculated the output buffer length, the output will | 128 // somehow miscalculated the output buffer length, the output will |
129 // be truncated, but it will be truncated consistently for all | 129 // be truncated, but it will be truncated consistently for all |
130 // mangleName() calls on the same input string. | 130 // mangleName() calls on the same input string. |
131 return NewName; | 131 return NewName.data(); |
132 } | 132 } |
133 | 133 |
134 // Artificially limit BaseLength to 9 digits (less than 1 billion) | 134 // Artificially limit BaseLength to 9 digits (less than 1 billion) |
135 // because sscanf behavior is undefined on integer overflow. If | 135 // because sscanf behavior is undefined on integer overflow. If |
136 // there are more than 9 digits (which we test by looking at the | 136 // there are more than 9 digits (which we test by looking at the |
137 // beginning of NameBase), then we consider this a failure to parse | 137 // beginning of NameBase), then we consider this a failure to parse |
138 // a namespace mangling, and fall back to the simple prefixing. | 138 // a namespace mangling, and fall back to the simple prefixing. |
139 ItemsParsed = sscanf(Name.c_str(), "_Z%9u%s", &BaseLength, NameBase); | 139 ItemsParsed = sscanf(Name.c_str(), "_Z%9u%s", &BaseLength, NameBase.data()); |
140 if (ItemsParsed == 2 && BaseLength <= strlen(NameBase) && | 140 if (ItemsParsed == 2 && BaseLength <= strlen(NameBase.data()) && |
141 !isdigit(NameBase[0])) { | 141 !isdigit(NameBase[0])) { |
142 // Transform _Z3barxyz ==> _ZN6Prefix3barExyz | 142 // Transform _Z3barxyz ==> _ZN6Prefix3barExyz |
143 // ^^^^^^^^ ^ | 143 // ^^^^^^^^ ^ |
144 // (splice in "N6Prefix", and insert "E" after "3bar") | 144 // (splice in "N6Prefix", and insert "E" after "3bar") |
145 // But an "I" after the identifier indicates a template argument | 145 // But an "I" after the identifier indicates a template argument |
146 // list terminated with "E"; insert the new "E" before/after the | 146 // list terminated with "E"; insert the new "E" before/after the |
147 // old "E". E.g.: | 147 // old "E". E.g.: |
148 // Transform _Z3barIabcExyz ==> _ZN6Prefix3barIabcEExyz | 148 // Transform _Z3barIabcExyz ==> _ZN6Prefix3barIabcEExyz |
149 // ^^^^^^^^ ^ | 149 // ^^^^^^^^ ^ |
150 // (splice in "N6Prefix", and insert "E" after "3barIabcE") | 150 // (splice in "N6Prefix", and insert "E" after "3barIabcE") |
151 char OrigName[Name.length()]; | 151 llvm::SmallVector<char, 32> OrigName(Name.length()); |
152 char OrigSuffix[Name.length()]; | 152 llvm::SmallVector<char, 32> OrigSuffix(Name.length()); |
153 uint32_t ActualBaseLength = BaseLength; | 153 uint32_t ActualBaseLength = BaseLength; |
154 if (NameBase[ActualBaseLength] == 'I') { | 154 if (NameBase[ActualBaseLength] == 'I') { |
155 ++ActualBaseLength; | 155 ++ActualBaseLength; |
156 while (NameBase[ActualBaseLength] != 'E' && | 156 while (NameBase[ActualBaseLength] != 'E' && |
157 NameBase[ActualBaseLength] != '\0') | 157 NameBase[ActualBaseLength] != '\0') |
158 ++ActualBaseLength; | 158 ++ActualBaseLength; |
159 } | 159 } |
160 strncpy(OrigName, NameBase, ActualBaseLength); | 160 strncpy(OrigName.data(), NameBase.data(), ActualBaseLength); |
161 OrigName[ActualBaseLength] = '\0'; | 161 OrigName[ActualBaseLength] = '\0'; |
162 strcpy(OrigSuffix, NameBase + ActualBaseLength); | 162 strcpy(OrigSuffix.data(), NameBase.data() + ActualBaseLength); |
163 snprintf(NewName, BufLen, "_ZN%u%s%u%sE%s", PrefixLength, | 163 snprintf(NewName.data(), BufLen, "_ZN%u%s%u%sE%s", PrefixLength, |
164 getTestPrefix().c_str(), BaseLength, OrigName, OrigSuffix); | 164 getTestPrefix().c_str(), BaseLength, OrigName.data(), |
165 return NewName; | 165 OrigSuffix.data()); |
| 166 return NewName.data(); |
166 } | 167 } |
167 | 168 |
168 // Transform bar ==> Prefixbar | 169 // Transform bar ==> Prefixbar |
169 // ^^^^^^ | 170 // ^^^^^^ |
170 return getTestPrefix() + Name; | 171 return getTestPrefix() + Name; |
171 } | 172 } |
172 | 173 |
173 GlobalContext::~GlobalContext() {} | 174 GlobalContext::~GlobalContext() {} |
174 | 175 |
175 Constant *GlobalContext::getConstantInt(Type Ty, uint64_t ConstantInt64) { | 176 Constant *GlobalContext::getConstantInt(Type Ty, uint64_t ConstantInt64) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 | 213 |
213 void Timer::printElapsedUs(GlobalContext *Ctx, const IceString &Tag) const { | 214 void Timer::printElapsedUs(GlobalContext *Ctx, const IceString &Tag) const { |
214 if (Ctx->isVerbose(IceV_Timing)) { | 215 if (Ctx->isVerbose(IceV_Timing)) { |
215 // Prefixing with '#' allows timing strings to be included | 216 // Prefixing with '#' allows timing strings to be included |
216 // without error in textual assembly output. | 217 // without error in textual assembly output. |
217 Ctx->getStrDump() << "# " << getElapsedUs() << " usec " << Tag << "\n"; | 218 Ctx->getStrDump() << "# " << getElapsedUs() << " usec " << Tag << "\n"; |
218 } | 219 } |
219 } | 220 } |
220 | 221 |
221 } // end of namespace Ice | 222 } // end of namespace Ice |
OLD | NEW |