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

Side by Side Diff: src/llvm2ice.cpp

Issue 205613002: Initial skeleton of Subzero. (Closed) Base URL: https://gerrit.chromium.org/gerrit/p/native_client/pnacl-subzero.git@master
Patch Set: Introduce IceGlobalContext, and rearrange other things around that Created 6 years, 8 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
OLDNEW
(Empty)
1 //===- subzero/src/llvm2ice.cpp - Driver for testing ----------------------===//
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 defines a driver that uses LLVM capabilities to parse a
11 // bitcode file and build the LLVM IR, and then convert the LLVM basic
12 // blocks, instructions, and operands into their Subzero equivalents.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #include "IceCfg.h"
17 #include "IceCfgNode.h"
18 #include "IceDefs.h"
19 #include "IceGlobalContext.h"
20 #include "IceInst.h"
21 #include "IceOperand.h"
22 #include "IceTypes.h"
23
24 #include "llvm/IR/Constant.h"
25 #include "llvm/IR/Constants.h"
26 #include "llvm/IR/DataLayout.h"
27 #include "llvm/IR/Instruction.h"
28 #include "llvm/IR/Instructions.h"
29 #include "llvm/IR/LLVMContext.h"
30 #include "llvm/IR/Module.h"
31 #include "llvm/IRReader/IRReader.h"
32 #include "llvm/Support/CommandLine.h"
33 #include "llvm/Support/ErrorHandling.h"
34 #include "llvm/Support/raw_os_ostream.h"
35 #include "llvm/Support/SourceMgr.h"
36
37 #include <fstream>
38 #include <iostream>
39
40 using namespace llvm;
41
42 // Debugging helper
43 template <typename T> static std::string LLVMObjectAsString(const T *O) {
44 std::string Dump;
45 raw_string_ostream Stream(Dump);
46 O->print(Stream);
47 return Stream.str();
48 }
49
50 // Converter from LLVM to ICE. The entry point is the convertFunction method.
51 //
52 // Note: this currently assumes that the given IR was verified to be valid PNaCl
53 // bitcode:
54 // https://developers.google.com/native-client/dev/reference/pnacl-bitcode-abi
55 // If not, all kinds of assertions may fire.
56 //
57 class LLVM2ICEConverter {
58 public:
59 LLVM2ICEConverter(IceGlobalContext *Ctx)
60 : Ctx(Ctx), Cfg(NULL), CurrentNode(NULL) {
61 // All PNaCl pointer widths are 32 bits because of the sandbox
62 // model.
63 SubzeroPointerType = IceType_i32;
64 }
65
66 IceCfg *convertFunction(const Function *F) {
67 VarMap.clear();
68 NodeMap.clear();
69 Cfg = new IceCfg(Ctx);
70 Cfg->setName(F->getName());
71 Cfg->setReturnType(convertType(F->getReturnType()));
72 Cfg->setInternal(F->hasInternalLinkage());
73
74 // The initial definition/use of each arg is the entry node.
75 CurrentNode = mapBasicBlockToNode(&F->getEntryBlock());
76 for (Function::const_arg_iterator ArgI = F->arg_begin(),
77 ArgE = F->arg_end();
78 ArgI != ArgE; ++ArgI) {
79 Cfg->addArg(mapValueToIceVar(ArgI));
80 }
81
82 // Make an initial pass through the block list just to resolve the
83 // blocks in the original linearized order. Otherwise the ICE
84 // linearized order will be affected by branch targets in
85 // terminator instructions.
86 for (Function::const_iterator BBI = F->begin(), BBE = F->end(); BBI != BBE;
87 ++BBI) {
88 mapBasicBlockToNode(BBI);
89 }
90 for (Function::const_iterator BBI = F->begin(), BBE = F->end(); BBI != BBE;
91 ++BBI) {
92 CurrentNode = mapBasicBlockToNode(BBI);
93 convertBasicBlock(BBI);
94 }
95 Cfg->setEntryNode(mapBasicBlockToNode(&F->getEntryBlock()));
96 Cfg->registerEdges();
97
98 return Cfg;
99 }
100
101 private:
102 // LLVM values (instructions, etc.) are mapped directly to ICE variables.
103 // mapValueToIceVar has a version that forces an ICE type on the variable,
104 // and a version that just uses convertType on V.
105 IceVariable *mapValueToIceVar(const Value *V, IceType IceTy) {
106 if (IceTy == IceType_void)
107 return NULL;
108 if (VarMap.find(V) == VarMap.end()) {
109 assert(CurrentNode);
110 VarMap[V] = Cfg->makeVariable(IceTy, CurrentNode, V->getName());
111 }
112 return VarMap[V];
113 }
114
115 IceVariable *mapValueToIceVar(const Value *V) {
116 return mapValueToIceVar(V, convertType(V->getType()));
117 }
118
119 IceCfgNode *mapBasicBlockToNode(const BasicBlock *BB) {
120 if (NodeMap.find(BB) == NodeMap.end()) {
121 NodeMap[BB] = Cfg->makeNode(BB->getName());
122 }
123 return NodeMap[BB];
124 }
125
126 IceType convertIntegerType(const IntegerType *IntTy) const {
127 switch (IntTy->getBitWidth()) {
128 case 1:
129 return IceType_i1;
130 case 8:
131 return IceType_i8;
132 case 16:
133 return IceType_i16;
134 case 32:
135 return IceType_i32;
136 case 64:
137 return IceType_i64;
138 default:
139 report_fatal_error(std::string("Invalid PNaCl int type: ") +
140 LLVMObjectAsString(IntTy));
141 return IceType_void;
142 }
143 }
144
145 IceType convertType(const Type *Ty) const {
146 switch (Ty->getTypeID()) {
147 case Type::VoidTyID:
148 return IceType_void;
149 case Type::IntegerTyID:
150 return convertIntegerType(cast<IntegerType>(Ty));
151 case Type::FloatTyID:
152 return IceType_f32;
153 case Type::DoubleTyID:
154 return IceType_f64;
155 case Type::PointerTyID:
156 return SubzeroPointerType;
157 case Type::FunctionTyID:
158 return SubzeroPointerType;
159 default:
160 report_fatal_error(std::string("Invalid PNaCl type: ") +
161 LLVMObjectAsString(Ty));
162 }
163
164 llvm_unreachable("convertType");
165 return IceType_void;
166 }
167
168 // Given a LLVM instruction and an operand number, produce the IceOperand this
169 // refers to. If there's no such operand, return NULL.
170 IceOperand *convertOperand(const Instruction *Inst, unsigned OpNum) {
171 if (OpNum >= Inst->getNumOperands()) {
172 return NULL;
173 }
174 const Value *Op = Inst->getOperand(OpNum);
175 return convertValue(Op);
176 }
177
178 IceOperand *convertValue(const Value *Op) {
179 if (const Constant *Const = dyn_cast<Constant>(Op)) {
180 if (const GlobalValue *GV = dyn_cast<GlobalValue>(Const)) {
181 return Ctx->getConstantSym(convertType(GV->getType()), GV, 0,
182 GV->getName());
183 } else if (const ConstantInt *CI = dyn_cast<ConstantInt>(Const)) {
184 return Ctx->getConstantInt(convertIntegerType(CI->getType()),
185 CI->getZExtValue());
186 } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(Const)) {
187 IceType Type = convertType(CFP->getType());
188 if (Type == IceType_f32)
189 return Ctx->getConstantFloat(CFP->getValueAPF().convertToFloat());
190 else if (Type == IceType_f64)
191 return Ctx->getConstantDouble(CFP->getValueAPF().convertToDouble());
192 assert(0 && "Unexpected floating point type");
193 return NULL;
194 } else {
195 assert(0 && "Unhandled constant type");
196 return NULL;
197 }
198 } else {
199 return mapValueToIceVar(Op);
200 }
201 }
202
203 // Note: this currently assumes a 1x1 mapping between LLVM IR and Ice
204 // instructions.
205 IceInst *convertInstruction(const Instruction *Inst) {
206 switch (Inst->getOpcode()) {
207 case Instruction::PHI:
208 return convertPHINodeInstruction(cast<PHINode>(Inst));
209 case Instruction::Br:
210 return convertBrInstruction(cast<BranchInst>(Inst));
211 case Instruction::Ret:
212 return convertRetInstruction(cast<ReturnInst>(Inst));
213 case Instruction::IntToPtr:
214 return convertIntToPtrInstruction(cast<IntToPtrInst>(Inst));
215 case Instruction::PtrToInt:
216 return convertPtrToIntInstruction(cast<PtrToIntInst>(Inst));
217 case Instruction::ICmp:
218 return convertICmpInstruction(cast<ICmpInst>(Inst));
219 case Instruction::FCmp:
220 return convertFCmpInstruction(cast<FCmpInst>(Inst));
221 case Instruction::Select:
222 return convertSelectInstruction(cast<SelectInst>(Inst));
223 case Instruction::Switch:
224 return convertSwitchInstruction(cast<SwitchInst>(Inst));
225 case Instruction::Load:
226 return convertLoadInstruction(cast<LoadInst>(Inst));
227 case Instruction::Store:
228 return convertStoreInstruction(cast<StoreInst>(Inst));
229 case Instruction::ZExt:
230 return convertCastInstruction(cast<ZExtInst>(Inst), IceInstCast::Zext);
231 case Instruction::SExt:
232 return convertCastInstruction(cast<SExtInst>(Inst), IceInstCast::Sext);
233 case Instruction::Trunc:
234 return convertCastInstruction(cast<TruncInst>(Inst), IceInstCast::Trunc);
235 case Instruction::FPTrunc:
236 return convertCastInstruction(cast<FPTruncInst>(Inst),
237 IceInstCast::Fptrunc);
238 case Instruction::FPExt:
239 return convertCastInstruction(cast<FPExtInst>(Inst), IceInstCast::Fpext);
240 case Instruction::FPToSI:
241 return convertCastInstruction(cast<FPToSIInst>(Inst),
242 IceInstCast::Fptosi);
243 case Instruction::FPToUI:
244 return convertCastInstruction(cast<FPToUIInst>(Inst),
245 IceInstCast::Fptoui);
246 case Instruction::SIToFP:
247 return convertCastInstruction(cast<SIToFPInst>(Inst),
248 IceInstCast::Sitofp);
249 case Instruction::UIToFP:
250 return convertCastInstruction(cast<UIToFPInst>(Inst),
251 IceInstCast::Uitofp);
252 case Instruction::BitCast:
253 return convertCastInstruction(cast<BitCastInst>(Inst),
254 IceInstCast::Bitcast);
255 case Instruction::Add:
256 return convertArithInstruction(Inst, IceInstArithmetic::Add);
257 case Instruction::Sub:
258 return convertArithInstruction(Inst, IceInstArithmetic::Sub);
259 case Instruction::Mul:
260 return convertArithInstruction(Inst, IceInstArithmetic::Mul);
261 case Instruction::UDiv:
262 return convertArithInstruction(Inst, IceInstArithmetic::Udiv);
263 case Instruction::SDiv:
264 return convertArithInstruction(Inst, IceInstArithmetic::Sdiv);
265 case Instruction::URem:
266 return convertArithInstruction(Inst, IceInstArithmetic::Urem);
267 case Instruction::SRem:
268 return convertArithInstruction(Inst, IceInstArithmetic::Srem);
269 case Instruction::Shl:
270 return convertArithInstruction(Inst, IceInstArithmetic::Shl);
271 case Instruction::LShr:
272 return convertArithInstruction(Inst, IceInstArithmetic::Lshr);
273 case Instruction::AShr:
274 return convertArithInstruction(Inst, IceInstArithmetic::Ashr);
275 case Instruction::FAdd:
276 return convertArithInstruction(Inst, IceInstArithmetic::Fadd);
277 case Instruction::FSub:
278 return convertArithInstruction(Inst, IceInstArithmetic::Fsub);
279 case Instruction::FMul:
280 return convertArithInstruction(Inst, IceInstArithmetic::Fmul);
281 case Instruction::FDiv:
282 return convertArithInstruction(Inst, IceInstArithmetic::Fdiv);
283 case Instruction::FRem:
284 return convertArithInstruction(Inst, IceInstArithmetic::Frem);
285 case Instruction::And:
286 return convertArithInstruction(Inst, IceInstArithmetic::And);
287 case Instruction::Or:
288 return convertArithInstruction(Inst, IceInstArithmetic::Or);
289 case Instruction::Xor:
290 return convertArithInstruction(Inst, IceInstArithmetic::Xor);
291 case Instruction::Call:
292 return convertCallInstruction(cast<CallInst>(Inst));
293 case Instruction::Alloca:
294 return convertAllocaInstruction(cast<AllocaInst>(Inst));
295 case Instruction::Unreachable:
296 return convertUnreachableInstruction(cast<UnreachableInst>(Inst));
297 default:
298 report_fatal_error(std::string("Invalid PNaCl instruction: ") +
299 LLVMObjectAsString(Inst));
300 }
301
302 llvm_unreachable("convertInstruction");
303 return NULL;
304 }
305
306 IceInst *convertLoadInstruction(const LoadInst *Inst) {
307 IceOperand *Src = convertOperand(Inst, 0);
308 IceVariable *Dest = mapValueToIceVar(Inst);
309 return IceInstLoad::create(Cfg, Dest, Src);
310 }
311
312 IceInst *convertStoreInstruction(const StoreInst *Inst) {
313 IceOperand *Addr = convertOperand(Inst, 1);
314 IceOperand *Val = convertOperand(Inst, 0);
315 return IceInstStore::create(Cfg, Val, Addr);
316 }
317
318 IceInst *convertArithInstruction(const Instruction *Inst,
319 IceInstArithmetic::OpKind Opcode) {
320 const BinaryOperator *BinOp = cast<BinaryOperator>(Inst);
321 IceOperand *Src0 = convertOperand(Inst, 0);
322 IceOperand *Src1 = convertOperand(Inst, 1);
323 IceVariable *Dest = mapValueToIceVar(BinOp);
324 return IceInstArithmetic::create(Cfg, Opcode, Dest, Src0, Src1);
325 }
326
327 IceInst *convertPHINodeInstruction(const PHINode *Inst) {
328 unsigned NumValues = Inst->getNumIncomingValues();
329 IceInstPhi *IcePhi =
330 IceInstPhi::create(Cfg, NumValues, mapValueToIceVar(Inst));
331 for (unsigned N = 0, E = NumValues; N != E; ++N) {
332 IcePhi->addArgument(convertOperand(Inst, N),
333 mapBasicBlockToNode(Inst->getIncomingBlock(N)));
334 }
335 return IcePhi;
336 }
337
338 IceInst *convertBrInstruction(const BranchInst *Inst) {
339 if (Inst->isConditional()) {
340 IceOperand *Src = convertOperand(Inst, 0);
341 BasicBlock *BBThen = Inst->getSuccessor(0);
342 BasicBlock *BBElse = Inst->getSuccessor(1);
343 IceCfgNode *NodeThen = mapBasicBlockToNode(BBThen);
344 IceCfgNode *NodeElse = mapBasicBlockToNode(BBElse);
345 return IceInstBr::create(Cfg, Src, NodeThen, NodeElse);
346 } else {
347 BasicBlock *BBSucc = Inst->getSuccessor(0);
348 return IceInstBr::create(Cfg, mapBasicBlockToNode(BBSucc));
349 }
350 }
351
352 IceInst *convertIntToPtrInstruction(const IntToPtrInst *Inst) {
353 IceOperand *Src = convertOperand(Inst, 0);
354 IceVariable *Dest = mapValueToIceVar(Inst, SubzeroPointerType);
355 return IceInstAssign::create(Cfg, Dest, Src);
356 }
357
358 IceInst *convertPtrToIntInstruction(const PtrToIntInst *Inst) {
359 IceOperand *Src = convertOperand(Inst, 0);
360 IceVariable *Dest = mapValueToIceVar(Inst);
361 return IceInstAssign::create(Cfg, Dest, Src);
362 }
363
364 IceInst *convertRetInstruction(const ReturnInst *Inst) {
365 IceOperand *RetOperand = convertOperand(Inst, 0);
366 if (RetOperand) {
367 return IceInstRet::create(Cfg, RetOperand);
368 } else {
369 return IceInstRet::create(Cfg);
370 }
371 }
372
373 IceInst *convertCastInstruction(const Instruction *Inst,
374 IceInstCast::OpKind CastKind) {
375 IceOperand *Src = convertOperand(Inst, 0);
376 IceVariable *Dest = mapValueToIceVar(Inst);
377 return IceInstCast::create(Cfg, CastKind, Dest, Src);
378 }
379
380 IceInst *convertICmpInstruction(const ICmpInst *Inst) {
381 IceOperand *Src0 = convertOperand(Inst, 0);
382 IceOperand *Src1 = convertOperand(Inst, 1);
383 IceVariable *Dest = mapValueToIceVar(Inst);
384
385 IceInstIcmp::ICond Cond;
386 switch (Inst->getPredicate()) {
387 default:
388 llvm_unreachable("ICmpInst predicate");
389 case CmpInst::ICMP_EQ:
390 Cond = IceInstIcmp::Eq;
391 break;
392 case CmpInst::ICMP_NE:
393 Cond = IceInstIcmp::Ne;
394 break;
395 case CmpInst::ICMP_UGT:
396 Cond = IceInstIcmp::Ugt;
397 break;
398 case CmpInst::ICMP_UGE:
399 Cond = IceInstIcmp::Uge;
400 break;
401 case CmpInst::ICMP_ULT:
402 Cond = IceInstIcmp::Ult;
403 break;
404 case CmpInst::ICMP_ULE:
405 Cond = IceInstIcmp::Ule;
406 break;
407 case CmpInst::ICMP_SGT:
408 Cond = IceInstIcmp::Sgt;
409 break;
410 case CmpInst::ICMP_SGE:
411 Cond = IceInstIcmp::Sge;
412 break;
413 case CmpInst::ICMP_SLT:
414 Cond = IceInstIcmp::Slt;
415 break;
416 case CmpInst::ICMP_SLE:
417 Cond = IceInstIcmp::Sle;
418 break;
419 }
420
421 return IceInstIcmp::create(Cfg, Cond, Dest, Src0, Src1);
422 }
423
424 IceInst *convertFCmpInstruction(const FCmpInst *Inst) {
425 IceOperand *Src0 = convertOperand(Inst, 0);
426 IceOperand *Src1 = convertOperand(Inst, 1);
427 IceVariable *Dest = mapValueToIceVar(Inst);
428
429 IceInstFcmp::FCond Cond;
430 switch (Inst->getPredicate()) {
431
432 default:
433 llvm_unreachable("FCmpInst predicate");
434
435 case CmpInst::FCMP_FALSE:
436 Cond = IceInstFcmp::False;
437 break;
438 case CmpInst::FCMP_OEQ:
439 Cond = IceInstFcmp::Oeq;
440 break;
441 case CmpInst::FCMP_OGT:
442 Cond = IceInstFcmp::Ogt;
443 break;
444 case CmpInst::FCMP_OGE:
445 Cond = IceInstFcmp::Oge;
446 break;
447 case CmpInst::FCMP_OLT:
448 Cond = IceInstFcmp::Olt;
449 break;
450 case CmpInst::FCMP_OLE:
451 Cond = IceInstFcmp::Ole;
452 break;
453 case CmpInst::FCMP_ONE:
454 Cond = IceInstFcmp::One;
455 break;
456 case CmpInst::FCMP_ORD:
457 Cond = IceInstFcmp::Ord;
458 break;
459 case CmpInst::FCMP_UEQ:
460 Cond = IceInstFcmp::Ueq;
461 break;
462 case CmpInst::FCMP_UGT:
463 Cond = IceInstFcmp::Ugt;
464 break;
465 case CmpInst::FCMP_UGE:
466 Cond = IceInstFcmp::Uge;
467 break;
468 case CmpInst::FCMP_ULT:
469 Cond = IceInstFcmp::Ult;
470 break;
471 case CmpInst::FCMP_ULE:
472 Cond = IceInstFcmp::Ule;
473 break;
474 case CmpInst::FCMP_UNE:
475 Cond = IceInstFcmp::Une;
476 break;
477 case CmpInst::FCMP_UNO:
478 Cond = IceInstFcmp::Uno;
479 break;
480 case CmpInst::FCMP_TRUE:
481 Cond = IceInstFcmp::True;
482 break;
483 }
484
485 return IceInstFcmp::create(Cfg, Cond, Dest, Src0, Src1);
486 }
487
488 IceInst *convertSelectInstruction(const SelectInst *Inst) {
489 IceVariable *Dest = mapValueToIceVar(Inst);
490 IceOperand *Cond = convertValue(Inst->getCondition());
491 IceOperand *Source1 = convertValue(Inst->getTrueValue());
492 IceOperand *Source2 = convertValue(Inst->getFalseValue());
493 return IceInstSelect::create(Cfg, Dest, Cond, Source1, Source2);
494 }
495
496 IceInst *convertSwitchInstruction(const SwitchInst *Inst) {
497 IceOperand *Source = convertValue(Inst->getCondition());
498 IceCfgNode *LabelDefault = mapBasicBlockToNode(Inst->getDefaultDest());
499 unsigned NumCases = Inst->getNumCases();
500 IceInstSwitch *Switch =
501 IceInstSwitch::create(Cfg, NumCases, Source, LabelDefault);
502 unsigned CurrentCase = 0;
503 for (SwitchInst::ConstCaseIt I = Inst->case_begin(), E = Inst->case_end();
504 I != E; ++I, ++CurrentCase) {
505 uint64_t CaseValue = I.getCaseValue()->getZExtValue();
506 IceCfgNode *CaseSuccessor = mapBasicBlockToNode(I.getCaseSuccessor());
507 Switch->addBranch(CurrentCase, CaseValue, CaseSuccessor);
508 }
509 return Switch;
510 }
511
512 IceInst *convertCallInstruction(const CallInst *Inst) {
513 IceVariable *Dest = mapValueToIceVar(Inst);
514 IceOperand *CallTarget = convertValue(Inst->getCalledValue());
515 unsigned NumArgs = Inst->getNumArgOperands();
516 IceInstCall *NewInst =
517 IceInstCall::create(Cfg, NumArgs, Dest, CallTarget, Inst->isTailCall());
518 for (unsigned i = 0; i < NumArgs; ++i) {
519 NewInst->addArg(convertOperand(Inst, i));
520 }
521 return NewInst;
522 }
523
524 IceInst *convertAllocaInstruction(const AllocaInst *Inst) {
525 // PNaCl bitcode only contains allocas of byte-granular objects.
526 IceOperand *ByteCount = convertValue(Inst->getArraySize());
527 uint32_t Align = Inst->getAlignment();
528 IceVariable *Dest = mapValueToIceVar(Inst, SubzeroPointerType);
529
530 return IceInstAlloca::create(Cfg, ByteCount, Align, Dest);
531 }
532
533 IceInst *convertUnreachableInstruction(const UnreachableInst *Inst) {
534 return IceInstUnreachable::create(Cfg);
535 }
536
537 IceCfgNode *convertBasicBlock(const BasicBlock *BB) {
538 IceCfgNode *Node = mapBasicBlockToNode(BB);
539 for (BasicBlock::const_iterator II = BB->begin(), II_e = BB->end();
540 II != II_e; ++II) {
541 IceInst *Inst = convertInstruction(II);
542 Node->appendInst(Inst);
543 }
544 return Node;
545 }
546
547 private:
548 // Data
549 IceGlobalContext *Ctx;
550 IceCfg *Cfg;
551 IceCfgNode *CurrentNode;
552 IceType SubzeroPointerType;
553 std::map<const Value *, IceVariable *> VarMap;
554 std::map<const BasicBlock *, IceCfgNode *> NodeMap;
555 };
556
557 static cl::list<IceVerbose> VerboseList(
558 "verbose", cl::CommaSeparated,
559 cl::desc("Verbose options (can be comma-separated):"),
560 cl::values(
561 clEnumValN(IceV_Instructions, "inst", "Print basic instructions"),
562 clEnumValN(IceV_Deleted, "del", "Include deleted instructions"),
563 clEnumValN(IceV_InstNumbers, "instnum", "Print instruction numbers"),
564 clEnumValN(IceV_Preds, "pred", "Show predecessors"),
565 clEnumValN(IceV_Succs, "succ", "Show successors"),
566 clEnumValN(IceV_Liveness, "live", "Liveness information"),
567 clEnumValN(IceV_RegManager, "rmgr", "Register manager status"),
568 clEnumValN(IceV_RegOrigins, "orig", "Physical register origins"),
569 clEnumValN(IceV_LinearScan, "regalloc", "Linear scan details"),
570 clEnumValN(IceV_Frame, "frame", "Stack frame layout details"),
571 clEnumValN(IceV_Timing, "time", "Pass timing details"),
572 clEnumValN(IceV_All, "all", "Use all verbose options"),
573 clEnumValN(IceV_None, "none", "No verbosity"), clEnumValEnd));
574 static cl::opt<std::string> IRFilename(cl::Positional, cl::desc("<IR file>"),
575 cl::Required);
576 static cl::opt<std::string> OutputFilename("o",
577 cl::desc("Override output filename"),
578 cl::init("-"),
579 cl::value_desc("filename"));
580 static cl::opt<std::string>
581 TestPrefix("prefix", cl::desc("Prepend a prefix to symbol names for testing"),
582 cl::init(""), cl::value_desc("prefix"));
583 static cl::opt<bool>
584 DisableInternal("external",
585 cl::desc("Disable 'internal' linkage type for testing"));
586 static cl::opt<bool>
587 DisableTranslation("notranslate", cl::desc("Disable Subzero translation"));
588
589 static cl::opt<bool> SubzeroTimingEnabled(
590 "timing", cl::desc("Enable breakdown timing of Subzero translation"));
591
592 int main(int argc, char **argv) {
593 cl::ParseCommandLineOptions(argc, argv);
594
595 // Parse the input LLVM IR file into a module.
596 SMDiagnostic Err;
597 Module *Mod;
598
599 {
600 IceTimer T;
601 Mod = ParseIRFile(IRFilename, Err, getGlobalContext());
602
603 if (SubzeroTimingEnabled) {
604 std::cerr << "[Subzero timing] IR Parsing: " << T.getElapsedSec()
605 << " sec\n";
606 }
607 }
608
609 if (!Mod) {
610 Err.print(argv[0], errs());
611 return 1;
612 }
613
614 IceVerboseMask VerboseMask = IceV_None;
615 for (unsigned i = 0; i != VerboseList.size(); ++i)
616 VerboseMask |= VerboseList[i];
617
618 std::ofstream Ofs;
619 if (OutputFilename != "-") {
620 Ofs.open(OutputFilename.c_str(), std::ofstream::out);
621 }
622 raw_os_ostream *Os =
623 new raw_os_ostream(OutputFilename == "-" ? std::cout : Ofs);
624 Os->SetUnbuffered();
625
626 IceGlobalContext Ctx(Os, Os, VerboseMask, TestPrefix);
627
628 for (Module::const_iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) {
629 if (I->empty())
630 continue;
631 LLVM2ICEConverter FunctionConverter(&Ctx);
632
633 IceTimer TConvert;
634 IceCfg *Cfg = FunctionConverter.convertFunction(I);
635 if (DisableInternal)
636 Cfg->setInternal(false);
637
638 if (SubzeroTimingEnabled) {
639 std::cerr << "[Subzero timing] Convert function " << Cfg->getName()
640 << ": " << TConvert.getElapsedSec() << " sec\n";
641 }
642
643 if (DisableTranslation) {
644 Cfg->dump();
645 }
646 }
647
648 return 0;
649 }
OLDNEW
« src/IceTypes.cpp ('K') | « src/IceTypes.cpp ('k') | szdiff.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698