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

Side by Side Diff: src/llvm2ice.cpp

Issue 659513005: Allow conditional lit tests in Subzero, based on build flags. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Add -Wno-error=unused-parameter Created 6 years, 1 month 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/IceTypes.def ('k') | tests_lit/lit.cfg » ('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
11 // bitcode file and build the LLVM IR, and then convert the LLVM basic 11 // bitcode file and build the LLVM IR, and then convert the LLVM basic
12 // blocks, instructions, and operands into their Subzero equivalents. 12 // blocks, instructions, and operands into their Subzero equivalents.
13 // 13 //
14 //===----------------------------------------------------------------------===// 14 //===----------------------------------------------------------------------===//
15 15
16 #include <fstream> 16 #include <fstream>
17 #include <iostream> 17 #include <iostream>
18 18
19 #include "llvm/ADT/STLExtras.h"
19 #include "llvm/IR/LLVMContext.h" 20 #include "llvm/IR/LLVMContext.h"
20 #include "llvm/IRReader/IRReader.h" 21 #include "llvm/IRReader/IRReader.h"
21 #include "llvm/Support/CommandLine.h" 22 #include "llvm/Support/CommandLine.h"
22 #include "llvm/Support/raw_os_ostream.h" 23 #include "llvm/Support/raw_os_ostream.h"
23 #include "llvm/Support/SourceMgr.h" 24 #include "llvm/Support/SourceMgr.h"
24 25
25 #include "IceCfg.h" 26 #include "IceCfg.h"
26 #include "IceClFlags.h" 27 #include "IceClFlags.h"
27 #include "IceConverter.h" 28 #include "IceConverter.h"
28 #include "PNaClTranslator.h" 29 #include "PNaClTranslator.h"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 cl::desc("Use integrated assembler (default yes)"), 158 cl::desc("Use integrated assembler (default yes)"),
158 cl::init(true)); 159 cl::init(true));
159 160
160 static cl::alias UseIas("ias", cl::desc("Alias for -integrated-as"), 161 static cl::alias UseIas("ias", cl::desc("Alias for -integrated-as"),
161 cl::NotHidden, cl::aliasopt(UseIntegratedAssembler)); 162 cl::NotHidden, cl::aliasopt(UseIntegratedAssembler));
162 163
163 static cl::opt<bool> AlwaysExitSuccess( 164 static cl::opt<bool> AlwaysExitSuccess(
164 "exit-success", cl::desc("Exit with success status, even if errors found"), 165 "exit-success", cl::desc("Exit with success status, even if errors found"),
165 cl::init(false)); 166 cl::init(false));
166 167
168 static cl::opt<bool> GenerateBuildAtts(
169 "build-atts", cl::desc("Generate list of build attributes associated with "
170 "this executable."),
171 cl::init(false));
172
167 static int GetReturnValue(int Val) { 173 static int GetReturnValue(int Val) {
168 if (AlwaysExitSuccess) 174 if (AlwaysExitSuccess)
169 return 0; 175 return 0;
170 return Val; 176 return Val;
171 } 177 }
172 178
179 static struct {
180 const char *FlagName;
181 int FlagValue;
182 } ConditionalBuildAttributes[] = {
183 { "text_asm", ALLOW_TEXT_ASM },
184 { "dump", ALLOW_DUMP },
185 { "llvm_cl", ALLOW_LLVM_CL },
186 { "llvm_ir", ALLOW_LLVM_IR },
187 { "llvm_ir_as_input", ALLOW_LLVM_IR_AS_INPUT }
188 };
189
190 // Validates values of build attributes. Prints them to Stream if
191 // Stream is non-null.
192 static void ValidateAndGenerateBuildAttributes(raw_os_ostream *Stream) {
193
194 if (Stream)
195 *Stream << TargetArch << "\n";
196
197 for (size_t i = 0; i < array_lengthof(ConditionalBuildAttributes); ++i) {
198 switch (ConditionalBuildAttributes[i].FlagValue) {
199 case 0:
200 if (Stream)
201 *Stream << "no_" << ConditionalBuildAttributes[i].FlagName << "\n";
202 break;
203 case 1:
204 if (Stream)
205 *Stream << "allow_" << ConditionalBuildAttributes[i].FlagName << "\n";
206 break;
207 default: {
208 std::string Buffer;
209 raw_string_ostream StrBuf(Buffer);
210 StrBuf << "Flag " << ConditionalBuildAttributes[i].FlagName
211 << " must be defined as 0/1. Found: "
212 << ConditionalBuildAttributes[i].FlagValue;
213 report_fatal_error(StrBuf.str());
214 }
215 }
216 }
217 }
218
173 int main(int argc, char **argv) { 219 int main(int argc, char **argv) {
174 220
175 cl::ParseCommandLineOptions(argc, argv); 221 cl::ParseCommandLineOptions(argc, argv);
176 222
177 Ice::VerboseMask VMask = Ice::IceV_None; 223 Ice::VerboseMask VMask = Ice::IceV_None;
178 for (unsigned i = 0; i != VerboseList.size(); ++i) 224 for (unsigned i = 0; i != VerboseList.size(); ++i)
179 VMask |= VerboseList[i]; 225 VMask |= VerboseList[i];
180 226
181 std::ofstream Ofs; 227 std::ofstream Ofs;
182 if (OutputFilename != "-") { 228 if (OutputFilename != "-") {
183 Ofs.open(OutputFilename.c_str(), std::ofstream::out); 229 Ofs.open(OutputFilename.c_str(), std::ofstream::out);
184 } 230 }
185 raw_os_ostream *Os = 231 raw_os_ostream *Os =
186 new raw_os_ostream(OutputFilename == "-" ? std::cout : Ofs); 232 new raw_os_ostream(OutputFilename == "-" ? std::cout : Ofs);
187 Os->SetUnbuffered(); 233 Os->SetUnbuffered();
234
235 ValidateAndGenerateBuildAttributes(GenerateBuildAtts ? Os : nullptr);
236 if (GenerateBuildAtts)
237 return GetReturnValue(0);
238
188 std::ofstream Lfs; 239 std::ofstream Lfs;
189 if (LogFilename != "-") { 240 if (LogFilename != "-") {
190 Lfs.open(LogFilename.c_str(), std::ofstream::out); 241 Lfs.open(LogFilename.c_str(), std::ofstream::out);
191 } 242 }
192 raw_os_ostream *Ls = new raw_os_ostream(LogFilename == "-" ? std::cout : Lfs); 243 raw_os_ostream *Ls = new raw_os_ostream(LogFilename == "-" ? std::cout : Lfs);
193 Ls->SetUnbuffered(); 244 Ls->SetUnbuffered();
194 245
195 Ice::ClFlags Flags; 246 Ice::ClFlags Flags;
196 Flags.DisableInternal = DisableInternal; 247 Flags.DisableInternal = DisableInternal;
197 Flags.SubzeroTimingEnabled = SubzeroTimingEnabled; 248 Flags.SubzeroTimingEnabled = SubzeroTimingEnabled;
198 Flags.DisableTranslation = DisableTranslation; 249 Flags.DisableTranslation = DisableTranslation;
199 Flags.FunctionSections = FunctionSections; 250 Flags.FunctionSections = FunctionSections;
200 Flags.DataSections = DataSections; 251 Flags.DataSections = DataSections;
201 Flags.UseIntegratedAssembler = UseIntegratedAssembler; 252 Flags.UseIntegratedAssembler = UseIntegratedAssembler;
202 Flags.UseSandboxing = UseSandboxing; 253 Flags.UseSandboxing = UseSandboxing;
203 Flags.PhiEdgeSplit = EnablePhiEdgeSplit; 254 Flags.PhiEdgeSplit = EnablePhiEdgeSplit;
204 Flags.DumpStats = DumpStats; 255 Flags.DumpStats = DumpStats;
205 Flags.AllowUninitializedGlobals = AllowUninitializedGlobals; 256 Flags.AllowUninitializedGlobals = AllowUninitializedGlobals;
206 Flags.TimeEachFunction = TimeEachFunction; 257 Flags.TimeEachFunction = TimeEachFunction;
207 Flags.DefaultGlobalPrefix = DefaultGlobalPrefix; 258 Flags.DefaultGlobalPrefix = DefaultGlobalPrefix;
208 Flags.DefaultFunctionPrefix = DefaultFunctionPrefix; 259 Flags.DefaultFunctionPrefix = DefaultFunctionPrefix;
209 Flags.TimingFocusOn = TimingFocusOn; 260 Flags.TimingFocusOn = TimingFocusOn;
210 Flags.VerboseFocusOn = VerboseFocusOn; 261 Flags.VerboseFocusOn = VerboseFocusOn;
211 Flags.TranslateOnly = TranslateOnly; 262 Flags.TranslateOnly = TranslateOnly;
212 263
213 Ice::GlobalContext Ctx(Ls, Os, VMask, TargetArch, OptLevel, TestPrefix, 264 Ice::GlobalContext Ctx(Ls, Os, VMask, TargetArch, OptLevel, TestPrefix,
214 Flags); 265 Flags);
266
215 Ice::TimerMarker T(Ice::TimerStack::TT_szmain, &Ctx); 267 Ice::TimerMarker T(Ice::TimerStack::TT_szmain, &Ctx);
216 268
217 int ErrorStatus = 0; 269 int ErrorStatus = 0;
218 if (BuildOnRead) { 270 if (BuildOnRead) {
219 Ice::PNaClTranslator Translator(&Ctx, Flags); 271 Ice::PNaClTranslator Translator(&Ctx, Flags);
220 Translator.translate(IRFilename); 272 Translator.translate(IRFilename);
221 ErrorStatus = Translator.getErrorStatus(); 273 ErrorStatus = Translator.getErrorStatus();
222 } else { 274 } else {
223 // Parse the input LLVM IR file into a module. 275 // Parse the input LLVM IR file into a module.
224 SMDiagnostic Err; 276 SMDiagnostic Err;
(...skipping 13 matching lines...) Expand all
238 if (TimeEachFunction) { 290 if (TimeEachFunction) {
239 const bool DumpCumulative = false; 291 const bool DumpCumulative = false;
240 Ctx.dumpTimers(Ice::GlobalContext::TSK_Funcs, DumpCumulative); 292 Ctx.dumpTimers(Ice::GlobalContext::TSK_Funcs, DumpCumulative);
241 } 293 }
242 if (SubzeroTimingEnabled) 294 if (SubzeroTimingEnabled)
243 Ctx.dumpTimers(); 295 Ctx.dumpTimers();
244 const bool FinalStats = true; 296 const bool FinalStats = true;
245 Ctx.dumpStats("_FINAL_", FinalStats); 297 Ctx.dumpStats("_FINAL_", FinalStats);
246 return GetReturnValue(ErrorStatus); 298 return GetReturnValue(ErrorStatus);
247 } 299 }
OLDNEW
« no previous file with comments | « src/IceTypes.def ('k') | tests_lit/lit.cfg » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698