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

Side by Side Diff: src/llvm2ice.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/PNaClTranslator.cpp ('k') | tests_lit/llvm2ice_tests/global.ll » ('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/llvm2ice.cpp - Driver for testing ----------------------===// 1 //===- subzero/src/llvm2ice.cpp - Driver for testing ----------------------===//
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 a driver that uses LLVM capabilities to parse a 10 // This file defines a driver that uses LLVM capabilities to parse a
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 clEnumValN(Ice::Target_X8664, "x8664", "x86-64"), 58 clEnumValN(Ice::Target_X8664, "x8664", "x86-64"),
59 clEnumValN(Ice::Target_X8664, "x86-64", "x86-64 (same as x8664)"), 59 clEnumValN(Ice::Target_X8664, "x86-64", "x86-64 (same as x8664)"),
60 clEnumValN(Ice::Target_X8664, "x86_64", "x86-64 (same as x8664)"), 60 clEnumValN(Ice::Target_X8664, "x86_64", "x86-64 (same as x8664)"),
61 clEnumValN(Ice::Target_ARM32, "arm", "arm32"), 61 clEnumValN(Ice::Target_ARM32, "arm", "arm32"),
62 clEnumValN(Ice::Target_ARM32, "arm32", "arm32 (same as arm)"), 62 clEnumValN(Ice::Target_ARM32, "arm32", "arm32 (same as arm)"),
63 clEnumValN(Ice::Target_ARM64, "arm64", "arm64"), clEnumValEnd)); 63 clEnumValN(Ice::Target_ARM64, "arm64", "arm64"), clEnumValEnd));
64 static cl::opt<bool> UseSandboxing("sandbox", cl::desc("Use sandboxing")); 64 static cl::opt<bool> UseSandboxing("sandbox", cl::desc("Use sandboxing"));
65 static cl::opt<bool> 65 static cl::opt<bool>
66 FunctionSections("ffunction-sections", 66 FunctionSections("ffunction-sections",
67 cl::desc("Emit functions into separate sections")); 67 cl::desc("Emit functions into separate sections"));
68 static cl::opt<bool>
69 DataSections("fdata-sections",
70 cl::desc("Emit (global) data into separate sections"));
68 static cl::opt<Ice::OptLevel> 71 static cl::opt<Ice::OptLevel>
69 OptLevel(cl::desc("Optimization level"), cl::init(Ice::Opt_m1), 72 OptLevel(cl::desc("Optimization level"), cl::init(Ice::Opt_m1),
70 cl::value_desc("level"), 73 cl::value_desc("level"),
71 cl::values(clEnumValN(Ice::Opt_m1, "Om1", "-1"), 74 cl::values(clEnumValN(Ice::Opt_m1, "Om1", "-1"),
72 clEnumValN(Ice::Opt_m1, "O-1", "-1"), 75 clEnumValN(Ice::Opt_m1, "O-1", "-1"),
73 clEnumValN(Ice::Opt_0, "O0", "0"), 76 clEnumValN(Ice::Opt_0, "O0", "0"),
74 clEnumValN(Ice::Opt_1, "O1", "1"), 77 clEnumValN(Ice::Opt_1, "O1", "1"),
75 clEnumValN(Ice::Opt_2, "O2", "2"), clEnumValEnd)); 78 clEnumValN(Ice::Opt_2, "O2", "2"), clEnumValEnd));
76 static cl::opt<std::string> IRFilename(cl::Positional, cl::desc("<IR file>"), 79 static cl::opt<std::string> IRFilename(cl::Positional, cl::desc("<IR file>"),
77 cl::init("-")); 80 cl::init("-"));
(...skipping 22 matching lines...) Expand all
100 103
101 // This is currently unused, and is a placeholder for lit tests. 104 // This is currently unused, and is a placeholder for lit tests.
102 static cl::opt<bool> 105 static cl::opt<bool>
103 DisablePhiEdgeSplit("no-phi-edge-split", 106 DisablePhiEdgeSplit("no-phi-edge-split",
104 cl::desc("Disable edge splitting for Phi lowering")); 107 cl::desc("Disable edge splitting for Phi lowering"));
105 108
106 static cl::opt<bool> 109 static cl::opt<bool>
107 DumpStats("stats", 110 DumpStats("stats",
108 cl::desc("Print statistics after translating each function")); 111 cl::desc("Print statistics after translating each function"));
109 112
113 // This is currently needed by crosstest.py.
114 static cl::opt<bool> AllowUninitializedGlobals(
115 "allow-uninitialized-globals",
116 cl::desc("Allow global variables to be uninitialized"));
117
110 static cl::opt<NaClFileFormat> InputFileFormat( 118 static cl::opt<NaClFileFormat> InputFileFormat(
111 "bitcode-format", cl::desc("Define format of input file:"), 119 "bitcode-format", cl::desc("Define format of input file:"),
112 cl::values(clEnumValN(LLVMFormat, "llvm", "LLVM file (default)"), 120 cl::values(clEnumValN(LLVMFormat, "llvm", "LLVM file (default)"),
113 clEnumValN(PNaClFormat, "pnacl", "PNaCl bitcode file"), 121 clEnumValN(PNaClFormat, "pnacl", "PNaCl bitcode file"),
114 clEnumValEnd), 122 clEnumValEnd),
115 cl::init(LLVMFormat)); 123 cl::init(LLVMFormat));
116 124
117 static cl::opt<std::string> 125 static cl::opt<std::string>
118 DefaultGlobalPrefix("default-global-prefix", 126 DefaultGlobalPrefix("default-global-prefix",
119 cl::desc("Define default global prefix for naming " 127 cl::desc("Define default global prefix for naming "
120 "unnamed globals"), 128 "unnamed globals"),
121 cl::init("Global")); 129 cl::init("Global"));
122 130
123 static cl::opt<std::string> 131 static cl::opt<std::string>
124 DefaultFunctionPrefix("default-function-prefix", 132 DefaultFunctionPrefix("default-function-prefix",
125 cl::desc("Define default function prefix for naming " 133 cl::desc("Define default function prefix for naming "
126 "unnamed functions"), 134 "unnamed functions"),
127 cl::init("Function")); 135 cl::init("Function"));
128 136
129 static cl::opt<bool> 137 static cl::opt<bool>
130 BuildOnRead("build-on-read", 138 BuildOnRead("build-on-read",
131 cl::desc("Build ICE instructions when reading bitcode"), 139 cl::desc("Build ICE instructions when reading bitcode"),
132 cl::init(false)); 140 cl::init(false));
133 141
134 static cl::opt<bool> 142 static cl::opt<bool>
135 UseIntegratedAssembler("integrated-as", 143 UseIntegratedAssembler("integrated-as",
136 cl::desc("Use integrated assembler (default yes)"), 144 cl::desc("Use integrated assembler (default yes)"),
137 cl::init(true)); 145 cl::init(true));
146
138 static cl::alias UseIas("ias", cl::desc("Alias for -integrated-as"), 147 static cl::alias UseIas("ias", cl::desc("Alias for -integrated-as"),
139 cl::NotHidden, cl::aliasopt(UseIntegratedAssembler)); 148 cl::NotHidden, cl::aliasopt(UseIntegratedAssembler));
140 149
150 static cl::opt<bool> AlwaysExitSuccess(
151 "exit-success", cl::desc("Exit with success status, even if errors found"),
152 cl::init(false));
153
154 static int GetReturnValue(int Val) {
155 if (AlwaysExitSuccess)
156 return 0;
157 return Val;
158 }
159
141 int main(int argc, char **argv) { 160 int main(int argc, char **argv) {
142 161
143 cl::ParseCommandLineOptions(argc, argv); 162 cl::ParseCommandLineOptions(argc, argv);
144 163
145 Ice::VerboseMask VMask = Ice::IceV_None; 164 Ice::VerboseMask VMask = Ice::IceV_None;
146 for (unsigned i = 0; i != VerboseList.size(); ++i) 165 for (unsigned i = 0; i != VerboseList.size(); ++i)
147 VMask |= VerboseList[i]; 166 VMask |= VerboseList[i];
148 167
149 std::ofstream Ofs; 168 std::ofstream Ofs;
150 if (OutputFilename != "-") { 169 if (OutputFilename != "-") {
151 Ofs.open(OutputFilename.c_str(), std::ofstream::out); 170 Ofs.open(OutputFilename.c_str(), std::ofstream::out);
152 } 171 }
153 raw_os_ostream *Os = 172 raw_os_ostream *Os =
154 new raw_os_ostream(OutputFilename == "-" ? std::cout : Ofs); 173 new raw_os_ostream(OutputFilename == "-" ? std::cout : Ofs);
155 Os->SetUnbuffered(); 174 Os->SetUnbuffered();
156 std::ofstream Lfs; 175 std::ofstream Lfs;
157 if (LogFilename != "-") { 176 if (LogFilename != "-") {
158 Lfs.open(LogFilename.c_str(), std::ofstream::out); 177 Lfs.open(LogFilename.c_str(), std::ofstream::out);
159 } 178 }
160 raw_os_ostream *Ls = new raw_os_ostream(LogFilename == "-" ? std::cout : Lfs); 179 raw_os_ostream *Ls = new raw_os_ostream(LogFilename == "-" ? std::cout : Lfs);
161 Ls->SetUnbuffered(); 180 Ls->SetUnbuffered();
162 181
163 Ice::ClFlags Flags; 182 Ice::ClFlags Flags;
164 Flags.DisableInternal = DisableInternal; 183 Flags.DisableInternal = DisableInternal;
165 Flags.SubzeroTimingEnabled = SubzeroTimingEnabled; 184 Flags.SubzeroTimingEnabled = SubzeroTimingEnabled;
166 Flags.DisableTranslation = DisableTranslation; 185 Flags.DisableTranslation = DisableTranslation;
167 Flags.DisableGlobals = DisableGlobals; 186 Flags.DisableGlobals = DisableGlobals;
168 Flags.FunctionSections = FunctionSections; 187 Flags.FunctionSections = FunctionSections;
188 Flags.DataSections = DataSections;
169 Flags.UseIntegratedAssembler = UseIntegratedAssembler; 189 Flags.UseIntegratedAssembler = UseIntegratedAssembler;
170 Flags.UseSandboxing = UseSandboxing; 190 Flags.UseSandboxing = UseSandboxing;
171 Flags.DumpStats = DumpStats; 191 Flags.DumpStats = DumpStats;
192 Flags.AllowUninitializedGlobals = AllowUninitializedGlobals;
172 Flags.DefaultGlobalPrefix = DefaultGlobalPrefix; 193 Flags.DefaultGlobalPrefix = DefaultGlobalPrefix;
173 Flags.DefaultFunctionPrefix = DefaultFunctionPrefix; 194 Flags.DefaultFunctionPrefix = DefaultFunctionPrefix;
174 195
175 Ice::GlobalContext Ctx(Ls, Os, VMask, TargetArch, OptLevel, TestPrefix, 196 Ice::GlobalContext Ctx(Ls, Os, VMask, TargetArch, OptLevel, TestPrefix,
176 Flags); 197 Flags);
177 static Ice::TimerIdT IDszmain = Ice::GlobalContext::getTimerID("szmain"); 198 static Ice::TimerIdT IDszmain = Ice::GlobalContext::getTimerID("szmain");
178 Ice::TimerMarker T(IDszmain, &Ctx); 199 Ice::TimerMarker T(IDszmain, &Ctx);
179 200
180 int ErrorStatus = 0; 201 int ErrorStatus = 0;
181 if (BuildOnRead) { 202 if (BuildOnRead) {
182 Ice::PNaClTranslator Translator(&Ctx, Flags); 203 Ice::PNaClTranslator Translator(&Ctx, Flags);
183 Translator.translate(IRFilename); 204 Translator.translate(IRFilename);
184 ErrorStatus = Translator.getErrorStatus(); 205 ErrorStatus = Translator.getErrorStatus();
185 } else { 206 } else {
186 // Parse the input LLVM IR file into a module. 207 // Parse the input LLVM IR file into a module.
187 SMDiagnostic Err; 208 SMDiagnostic Err;
188 static Ice::TimerIdT IDparse = Ice::GlobalContext::getTimerID("parse"); 209 static Ice::TimerIdT IDparse = Ice::GlobalContext::getTimerID("parse");
189 Ice::TimerMarker T1(IDparse, &Ctx); 210 Ice::TimerMarker T1(IDparse, &Ctx);
190 Module *Mod = 211 Module *Mod =
191 NaClParseIRFile(IRFilename, InputFileFormat, Err, getGlobalContext()); 212 NaClParseIRFile(IRFilename, InputFileFormat, Err, getGlobalContext());
192 213
193 if (!Mod) { 214 if (!Mod) {
194 Err.print(argv[0], errs()); 215 Err.print(argv[0], errs());
195 return 1; 216 return GetReturnValue(1);
196 } 217 }
197 218
198 Ice::Converter Converter(Mod, &Ctx, Flags); 219 Ice::Converter Converter(Mod, &Ctx, Flags);
199 Converter.convertToIce(); 220 Converter.convertToIce();
200 ErrorStatus = Converter.getErrorStatus(); 221 ErrorStatus = Converter.getErrorStatus();
201 } 222 }
202 if (SubzeroTimingEnabled) 223 if (SubzeroTimingEnabled)
203 Ctx.dumpTimers(); 224 Ctx.dumpTimers();
204 const bool FinalStats = true; 225 const bool FinalStats = true;
205 Ctx.dumpStats("_FINAL_", FinalStats); 226 Ctx.dumpStats("_FINAL_", FinalStats);
206 return ErrorStatus; 227 return GetReturnValue(ErrorStatus);
207 } 228 }
OLDNEW
« no previous file with comments | « src/PNaClTranslator.cpp ('k') | tests_lit/llvm2ice_tests/global.ll » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698