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

Side by Side Diff: src/IceGlobalContext.cpp

Issue 265703002: Add Om1 lowering with no optimizations (Closed) Base URL: https://gerrit.chromium.org/gerrit/p/native_client/pnacl-subzero.git@master
Patch Set: Merge changed from Karl's committed CL Created 6 years, 7 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/IceGlobalContext.h ('k') | src/IceInst.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 // multiple functions. 11 // multiple functions.
12 // 12 //
13 //===----------------------------------------------------------------------===// 13 //===----------------------------------------------------------------------===//
14 14
15 #include "IceDefs.h" 15 #include "IceDefs.h"
16 #include "IceTypes.h" 16 #include "IceTypes.h"
17 #include "IceCfg.h" 17 #include "IceCfg.h"
18 #include "IceGlobalContext.h" 18 #include "IceGlobalContext.h"
19 #include "IceOperand.h" 19 #include "IceOperand.h"
20 #include "IceTargetLowering.h"
20 21
21 namespace Ice { 22 namespace Ice {
22 23
23 // TypePool maps constants of type KeyType (e.g. float) to pointers to 24 // TypePool maps constants of type KeyType (e.g. float) to pointers to
24 // type ValueType (e.g. ConstantFloat). KeyType values are compared 25 // type ValueType (e.g. ConstantFloat). KeyType values are compared
25 // using memcmp() because of potential NaN values in KeyType values. 26 // using memcmp() because of potential NaN values in KeyType values.
26 // KeyTypeHasFP indicates whether KeyType is a floating-point type 27 // KeyTypeHasFP indicates whether KeyType is a floating-point type
27 // whose values need to be compared using memcmp() for NaN 28 // whose values need to be compared using memcmp() for NaN
28 // correctness. TODO: use std::is_floating_point<KeyType> instead of 29 // correctness. TODO: use std::is_floating_point<KeyType> instead of
29 // KeyTypeHasFP with C++11. 30 // KeyTypeHasFP with C++11.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 public: 69 public:
69 ConstantPool() {} 70 ConstantPool() {}
70 TypePool<float, ConstantFloat, true> Floats; 71 TypePool<float, ConstantFloat, true> Floats;
71 TypePool<double, ConstantDouble, true> Doubles; 72 TypePool<double, ConstantDouble, true> Doubles;
72 TypePool<uint64_t, ConstantInteger> Integers; 73 TypePool<uint64_t, ConstantInteger> Integers;
73 TypePool<RelocatableTuple, ConstantRelocatable> Relocatables; 74 TypePool<RelocatableTuple, ConstantRelocatable> Relocatables;
74 }; 75 };
75 76
76 GlobalContext::GlobalContext(llvm::raw_ostream *OsDump, 77 GlobalContext::GlobalContext(llvm::raw_ostream *OsDump,
77 llvm::raw_ostream *OsEmit, VerboseMask Mask, 78 llvm::raw_ostream *OsEmit, VerboseMask Mask,
79 TargetArch Arch, OptLevel Opt,
78 IceString TestPrefix) 80 IceString TestPrefix)
79 : StrDump(OsDump), StrEmit(OsEmit), VMask(Mask), 81 : StrDump(OsDump), StrEmit(OsEmit), VMask(Mask),
80 ConstPool(new ConstantPool()), TestPrefix(TestPrefix) {} 82 ConstPool(new ConstantPool()), Arch(Arch), Opt(Opt),
83 TestPrefix(TestPrefix), HasEmittedFirstMethod(false) {}
81 84
82 // In this context, name mangling means to rewrite a symbol using a 85 // In this context, name mangling means to rewrite a symbol using a
83 // given prefix. For a C++ symbol, nest the original symbol inside 86 // given prefix. For a C++ symbol, nest the original symbol inside
84 // the "prefix" namespace. For other symbols, just prepend the 87 // the "prefix" namespace. For other symbols, just prepend the
85 // prefix. 88 // prefix.
86 IceString GlobalContext::mangleName(const IceString &Name) const { 89 IceString GlobalContext::mangleName(const IceString &Name) const {
87 // TODO: Add explicit tests (beyond the implicit tests in the linker
88 // that come from the cross tests).
89 //
90 // An already-nested name like foo::bar() gets pushed down one 90 // An already-nested name like foo::bar() gets pushed down one
91 // level, making it equivalent to Prefix::foo::bar(). 91 // level, making it equivalent to Prefix::foo::bar().
92 // _ZN3foo3barExyz ==> _ZN6Prefix3foo3barExyz 92 // _ZN3foo3barExyz ==> _ZN6Prefix3foo3barExyz
93 // A non-nested but mangled name like bar() gets nested, making it 93 // A non-nested but mangled name like bar() gets nested, making it
94 // equivalent to Prefix::bar(). 94 // equivalent to Prefix::bar().
95 // _Z3barxyz ==> ZN6Prefix3barExyz 95 // _Z3barxyz ==> ZN6Prefix3barExyz
96 // An unmangled, extern "C" style name, gets a simple prefix: 96 // An unmangled, extern "C" style name, gets a simple prefix:
97 // bar ==> Prefixbar 97 // bar ==> Prefixbar
98 if (getTestPrefix().empty()) 98 if (getTestPrefix().empty())
99 return Name; 99 return Name;
100 100
101 unsigned PrefixLength = getTestPrefix().length(); 101 unsigned PrefixLength = getTestPrefix().length();
102 char NameBase[1 + Name.length()]; 102 char NameBase[1 + Name.length()];
103 const size_t BufLen = 30 + Name.length() + getTestPrefix().length(); 103 const size_t BufLen = 30 + Name.length() + PrefixLength;
104 char NewName[BufLen]; 104 char NewName[BufLen];
105 uint32_t BaseLength = 0; 105 uint32_t BaseLength = 0; // using uint32_t due to sscanf format string
106 106
107 int ItemsParsed = sscanf(Name.c_str(), "_ZN%s", NameBase); 107 int ItemsParsed = sscanf(Name.c_str(), "_ZN%s", NameBase);
108 if (ItemsParsed == 1) { 108 if (ItemsParsed == 1) {
109 // Transform _ZN3foo3barExyz ==> _ZN6Prefix3foo3barExyz 109 // Transform _ZN3foo3barExyz ==> _ZN6Prefix3foo3barExyz
110 // (splice in "6Prefix") ^^^^^^^ 110 // (splice in "6Prefix") ^^^^^^^
111 snprintf(NewName, BufLen, "_ZN%u%s%s", PrefixLength, 111 snprintf(NewName, BufLen, "_ZN%u%s%s", PrefixLength,
112 getTestPrefix().c_str(), NameBase); 112 getTestPrefix().c_str(), NameBase);
113 // We ignore the snprintf return value (here and below). If we 113 // We ignore the snprintf return value (here and below). If we
114 // somehow miscalculated the output buffer length, the output will 114 // somehow miscalculated the output buffer length, the output will
115 // be truncated, but it will be truncated consistently for all 115 // be truncated, but it will be truncated consistently for all
116 // mangleName() calls on the same input string. 116 // mangleName() calls on the same input string.
117 return NewName; 117 return NewName;
118 } 118 }
119 119
120 ItemsParsed = sscanf(Name.c_str(), "_Z%u%s", &BaseLength, NameBase); 120 ItemsParsed = sscanf(Name.c_str(), "_Z%u%s", &BaseLength, NameBase);
121 if (ItemsParsed == 2) { 121 if (ItemsParsed == 2 && BaseLength <= strlen(NameBase)) {
122 // Transform _Z3barxyz ==> ZN6Prefix3barExyz 122 // Transform _Z3barxyz ==> _ZN6Prefix3barExyz
123 // ^^^^^^^^ ^ 123 // ^^^^^^^^ ^
124 // (splice in "N6Prefix", and insert "E" after "3bar") 124 // (splice in "N6Prefix", and insert "E" after "3bar")
125 // But an "I" after the identifier indicates a template argument
126 // list terminated with "E"; insert the new "E" before/after the
127 // old "E". E.g.:
128 // Transform _Z3barIabcExyz ==> _ZN6Prefix3barIabcEExyz
129 // ^^^^^^^^ ^
130 // (splice in "N6Prefix", and insert "E" after "3barIabcE")
125 char OrigName[Name.length()]; 131 char OrigName[Name.length()];
126 char OrigSuffix[Name.length()]; 132 char OrigSuffix[Name.length()];
127 strncpy(OrigName, NameBase, BaseLength); 133 uint32_t ActualBaseLength = BaseLength;
128 OrigName[BaseLength] = '\0'; 134 if (NameBase[ActualBaseLength] == 'I') {
129 strcpy(OrigSuffix, NameBase + BaseLength); 135 ++ActualBaseLength;
136 while (NameBase[ActualBaseLength] != 'E' &&
137 NameBase[ActualBaseLength] != '\0')
138 ++ActualBaseLength;
139 }
140 strncpy(OrigName, NameBase, ActualBaseLength);
141 OrigName[ActualBaseLength] = '\0';
142 strcpy(OrigSuffix, NameBase + ActualBaseLength);
130 snprintf(NewName, BufLen, "_ZN%u%s%u%sE%s", PrefixLength, 143 snprintf(NewName, BufLen, "_ZN%u%s%u%sE%s", PrefixLength,
131 getTestPrefix().c_str(), BaseLength, OrigName, OrigSuffix); 144 getTestPrefix().c_str(), BaseLength, OrigName, OrigSuffix);
132 return NewName; 145 return NewName;
133 } 146 }
134 147
135 // Transform bar ==> Prefixbar 148 // Transform bar ==> Prefixbar
136 // ^^^^^^ 149 // ^^^^^^
137 return getTestPrefix() + Name; 150 return getTestPrefix() + Name;
138 } 151 }
139 152
(...skipping 20 matching lines...) Expand all
160 173
161 void Timer::printElapsedUs(GlobalContext *Ctx, const IceString &Tag) const { 174 void Timer::printElapsedUs(GlobalContext *Ctx, const IceString &Tag) const {
162 if (Ctx->isVerbose(IceV_Timing)) { 175 if (Ctx->isVerbose(IceV_Timing)) {
163 // Prefixing with '#' allows timing strings to be included 176 // Prefixing with '#' allows timing strings to be included
164 // without error in textual assembly output. 177 // without error in textual assembly output.
165 Ctx->getStrDump() << "# " << getElapsedUs() << " usec " << Tag << "\n"; 178 Ctx->getStrDump() << "# " << getElapsedUs() << " usec " << Tag << "\n";
166 } 179 }
167 } 180 }
168 181
169 } // end of namespace Ice 182 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceGlobalContext.h ('k') | src/IceInst.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698