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

Side by Side Diff: src/llvm2ice.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/IceTypes.def ('k') | tests_lit/llvm2ice_tests/64bit.pnacl.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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 return SubzeroPointerType; 158 return SubzeroPointerType;
159 default: 159 default:
160 report_fatal_error(std::string("Invalid PNaCl type: ") + 160 report_fatal_error(std::string("Invalid PNaCl type: ") +
161 LLVMObjectAsString(Ty)); 161 LLVMObjectAsString(Ty));
162 } 162 }
163 163
164 llvm_unreachable("convertType"); 164 llvm_unreachable("convertType");
165 return Ice::IceType_void; 165 return Ice::IceType_void;
166 } 166 }
167 167
168 // Given a LLVM instruction and an operand number, produce the Operand this 168 // Given an LLVM instruction and an operand number, produce the
169 // refers to. If there's no such operand, return NULL. 169 // Ice::Operand this refers to. If there's no such operand, return
170 // NULL.
170 Ice::Operand *convertOperand(const Instruction *Inst, unsigned OpNum) { 171 Ice::Operand *convertOperand(const Instruction *Inst, unsigned OpNum) {
171 if (OpNum >= Inst->getNumOperands()) { 172 if (OpNum >= Inst->getNumOperands()) {
172 return NULL; 173 return NULL;
173 } 174 }
174 const Value *Op = Inst->getOperand(OpNum); 175 const Value *Op = Inst->getOperand(OpNum);
175 return convertValue(Op); 176 return convertValue(Op);
176 } 177 }
177 178
178 Ice::Operand *convertValue(const Value *Op) { 179 Ice::Operand *convertValue(const Value *Op) {
179 if (const Constant *Const = dyn_cast<Constant>(Op)) { 180 if (const Constant *Const = dyn_cast<Constant>(Op)) {
180 if (const GlobalValue *GV = dyn_cast<GlobalValue>(Const)) { 181 if (const GlobalValue *GV = dyn_cast<GlobalValue>(Const)) {
181 return Ctx->getConstantSym(convertType(GV->getType()), 0, 182 return Ctx->getConstantSym(convertType(GV->getType()), 0,
182 GV->getName()); 183 GV->getName());
183 } else if (const ConstantInt *CI = dyn_cast<ConstantInt>(Const)) { 184 } else if (const ConstantInt *CI = dyn_cast<ConstantInt>(Const)) {
184 return Ctx->getConstantInt(convertIntegerType(CI->getType()), 185 return Ctx->getConstantInt(convertIntegerType(CI->getType()),
185 CI->getZExtValue()); 186 CI->getZExtValue());
186 } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(Const)) { 187 } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(Const)) {
187 Ice::Type Type = convertType(CFP->getType()); 188 Ice::Type Type = convertType(CFP->getType());
188 if (Type == Ice::IceType_f32) 189 if (Type == Ice::IceType_f32)
189 return Ctx->getConstantFloat(CFP->getValueAPF().convertToFloat()); 190 return Ctx->getConstantFloat(CFP->getValueAPF().convertToFloat());
190 else if (Type == Ice::IceType_f64) 191 else if (Type == Ice::IceType_f64)
191 return Ctx->getConstantDouble(CFP->getValueAPF().convertToDouble()); 192 return Ctx->getConstantDouble(CFP->getValueAPF().convertToDouble());
192 assert(0 && "Unexpected floating point type"); 193 llvm_unreachable("Unexpected floating point type");
193 return NULL; 194 return NULL;
194 } else { 195 } else {
195 assert(0 && "Unhandled constant type"); 196 llvm_unreachable("Unhandled constant type");
196 return NULL; 197 return NULL;
197 } 198 }
198 } else { 199 } else {
199 return mapValueToIceVar(Op); 200 return mapValueToIceVar(Op);
200 } 201 }
201 } 202 }
202 203
203 // Note: this currently assumes a 1x1 mapping between LLVM IR and Ice 204 // Note: this currently assumes a 1x1 mapping between LLVM IR and Ice
204 // instructions. 205 // instructions.
205 Ice::Inst *convertInstruction(const Instruction *Inst) { 206 Ice::Inst *convertInstruction(const Instruction *Inst) {
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 528
528 Ice::Inst *convertAllocaInstruction(const AllocaInst *Inst) { 529 Ice::Inst *convertAllocaInstruction(const AllocaInst *Inst) {
529 // PNaCl bitcode only contains allocas of byte-granular objects. 530 // PNaCl bitcode only contains allocas of byte-granular objects.
530 Ice::Operand *ByteCount = convertValue(Inst->getArraySize()); 531 Ice::Operand *ByteCount = convertValue(Inst->getArraySize());
531 uint32_t Align = Inst->getAlignment(); 532 uint32_t Align = Inst->getAlignment();
532 Ice::Variable *Dest = mapValueToIceVar(Inst, SubzeroPointerType); 533 Ice::Variable *Dest = mapValueToIceVar(Inst, SubzeroPointerType);
533 534
534 return Ice::InstAlloca::create(Func, ByteCount, Align, Dest); 535 return Ice::InstAlloca::create(Func, ByteCount, Align, Dest);
535 } 536 }
536 537
537 Ice::Inst *convertUnreachableInstruction(const UnreachableInst *Inst) { 538 Ice::Inst *convertUnreachableInstruction(const UnreachableInst * /*Inst*/) {
538 return Ice::InstUnreachable::create(Func); 539 return Ice::InstUnreachable::create(Func);
539 } 540 }
540 541
541 Ice::CfgNode *convertBasicBlock(const BasicBlock *BB) { 542 Ice::CfgNode *convertBasicBlock(const BasicBlock *BB) {
542 Ice::CfgNode *Node = mapBasicBlockToNode(BB); 543 Ice::CfgNode *Node = mapBasicBlockToNode(BB);
543 for (BasicBlock::const_iterator II = BB->begin(), II_e = BB->end(); 544 for (BasicBlock::const_iterator II = BB->begin(), II_e = BB->end();
544 II != II_e; ++II) { 545 II != II_e; ++II) {
545 Ice::Inst *Inst = convertInstruction(II); 546 Ice::Inst *Inst = convertInstruction(II);
546 Node->appendInst(Inst); 547 Node->appendInst(Inst);
547 } 548 }
(...skipping 21 matching lines...) Expand all
569 clEnumValN(Ice::IceV_Preds, "pred", "Show predecessors"), 570 clEnumValN(Ice::IceV_Preds, "pred", "Show predecessors"),
570 clEnumValN(Ice::IceV_Succs, "succ", "Show successors"), 571 clEnumValN(Ice::IceV_Succs, "succ", "Show successors"),
571 clEnumValN(Ice::IceV_Liveness, "live", "Liveness information"), 572 clEnumValN(Ice::IceV_Liveness, "live", "Liveness information"),
572 clEnumValN(Ice::IceV_RegManager, "rmgr", "Register manager status"), 573 clEnumValN(Ice::IceV_RegManager, "rmgr", "Register manager status"),
573 clEnumValN(Ice::IceV_RegOrigins, "orig", "Physical register origins"), 574 clEnumValN(Ice::IceV_RegOrigins, "orig", "Physical register origins"),
574 clEnumValN(Ice::IceV_LinearScan, "regalloc", "Linear scan details"), 575 clEnumValN(Ice::IceV_LinearScan, "regalloc", "Linear scan details"),
575 clEnumValN(Ice::IceV_Frame, "frame", "Stack frame layout details"), 576 clEnumValN(Ice::IceV_Frame, "frame", "Stack frame layout details"),
576 clEnumValN(Ice::IceV_Timing, "time", "Pass timing details"), 577 clEnumValN(Ice::IceV_Timing, "time", "Pass timing details"),
577 clEnumValN(Ice::IceV_All, "all", "Use all verbose options"), 578 clEnumValN(Ice::IceV_All, "all", "Use all verbose options"),
578 clEnumValN(Ice::IceV_None, "none", "No verbosity"), clEnumValEnd)); 579 clEnumValN(Ice::IceV_None, "none", "No verbosity"), clEnumValEnd));
580 static cl::opt<Ice::TargetArch> TargetArch(
581 "target", cl::desc("Target architecture:"), cl::init(Ice::Target_X8632),
582 cl::values(
583 clEnumValN(Ice::Target_X8632, "x8632", "x86-32"),
584 clEnumValN(Ice::Target_X8632, "x86-32", "x86-32 (same as x8632)"),
585 clEnumValN(Ice::Target_X8632, "x86_32", "x86-32 (same as x8632)"),
586 clEnumValN(Ice::Target_X8664, "x8664", "x86-64"),
587 clEnumValN(Ice::Target_X8664, "x86-64", "x86-64 (same as x8664)"),
588 clEnumValN(Ice::Target_X8664, "x86_64", "x86-64 (same as x8664)"),
589 clEnumValN(Ice::Target_ARM32, "arm", "arm32"),
590 clEnumValN(Ice::Target_ARM32, "arm32", "arm32 (same as arm)"),
591 clEnumValN(Ice::Target_ARM64, "arm64", "arm64"), clEnumValEnd));
592 static cl::opt<Ice::OptLevel>
593 OptLevel(cl::desc("Optimization level"), cl::init(Ice::Opt_m1),
594 cl::value_desc("level"),
595 cl::values(clEnumValN(Ice::Opt_m1, "Om1", "-1"),
596 clEnumValN(Ice::Opt_m1, "O-1", "-1"),
597 clEnumValN(Ice::Opt_0, "O0", "0"),
598 clEnumValN(Ice::Opt_1, "O1", "1"),
599 clEnumValN(Ice::Opt_2, "O2", "2"), clEnumValEnd));
579 static cl::opt<std::string> IRFilename(cl::Positional, cl::desc("<IR file>"), 600 static cl::opt<std::string> IRFilename(cl::Positional, cl::desc("<IR file>"),
580 cl::init("-")); 601 cl::init("-"));
581 static cl::opt<std::string> OutputFilename("o", 602 static cl::opt<std::string> OutputFilename("o",
582 cl::desc("Override output filename"), 603 cl::desc("Override output filename"),
583 cl::init("-"), 604 cl::init("-"),
584 cl::value_desc("filename")); 605 cl::value_desc("filename"));
606 static cl::opt<std::string> LogFilename("log", cl::desc("Set log filename"),
607 cl::init("-"),
608 cl::value_desc("filename"));
585 static cl::opt<std::string> 609 static cl::opt<std::string>
586 TestPrefix("prefix", cl::desc("Prepend a prefix to symbol names for testing"), 610 TestPrefix("prefix", cl::desc("Prepend a prefix to symbol names for testing"),
587 cl::init(""), cl::value_desc("prefix")); 611 cl::init(""), cl::value_desc("prefix"));
588 static cl::opt<bool> 612 static cl::opt<bool>
589 DisableInternal("external", 613 DisableInternal("external",
590 cl::desc("Disable 'internal' linkage type for testing")); 614 cl::desc("Disable 'internal' linkage type for testing"));
591 static cl::opt<bool> 615 static cl::opt<bool>
592 DisableTranslation("notranslate", cl::desc("Disable Subzero translation")); 616 DisableTranslation("notranslate", cl::desc("Disable Subzero translation"));
593 617
594 static cl::opt<bool> SubzeroTimingEnabled( 618 static cl::opt<bool> SubzeroTimingEnabled(
595 "timing", cl::desc("Enable breakdown timing of Subzero translation")); 619 "timing", cl::desc("Enable breakdown timing of Subzero translation"));
596 620
597 static cl::opt<NaClFileFormat> 621 static cl::opt<NaClFileFormat>
598 InputFileFormat( 622 InputFileFormat(
599 "bitcode-format", 623 "bitcode-format",
600 cl::desc("Define format of input file:"), 624 cl::desc("Define format of input file:"),
601 cl::values( 625 cl::values(
602 clEnumValN(LLVMFormat, "llvm", "LLVM file (default)"), 626 clEnumValN(LLVMFormat, "llvm", "LLVM file (default)"),
603 clEnumValN(PNaClFormat, "pnacl", "PNaCl bitcode file"), 627 clEnumValN(PNaClFormat, "pnacl", "PNaCl bitcode file"),
604 clEnumValEnd), 628 clEnumValEnd),
605 cl::init(LLVMFormat)); 629 cl::init(LLVMFormat));
606 630
607 int main(int argc, char **argv) { 631 int main(int argc, char **argv) {
632 int ExitStatus = 0;
633
608 cl::ParseCommandLineOptions(argc, argv); 634 cl::ParseCommandLineOptions(argc, argv);
609 635
610 // Parse the input LLVM IR file into a module. 636 // Parse the input LLVM IR file into a module.
611 SMDiagnostic Err; 637 SMDiagnostic Err;
612 Module *Mod; 638 Module *Mod;
613 639
614 { 640 {
615 Ice::Timer T; 641 Ice::Timer T;
616 Mod = NaClParseIRFile(IRFilename, InputFileFormat, Err, getGlobalContext()); 642 Mod = NaClParseIRFile(IRFilename, InputFileFormat, Err, getGlobalContext());
617 643
(...skipping 12 matching lines...) Expand all
630 for (unsigned i = 0; i != VerboseList.size(); ++i) 656 for (unsigned i = 0; i != VerboseList.size(); ++i)
631 VMask |= VerboseList[i]; 657 VMask |= VerboseList[i];
632 658
633 std::ofstream Ofs; 659 std::ofstream Ofs;
634 if (OutputFilename != "-") { 660 if (OutputFilename != "-") {
635 Ofs.open(OutputFilename.c_str(), std::ofstream::out); 661 Ofs.open(OutputFilename.c_str(), std::ofstream::out);
636 } 662 }
637 raw_os_ostream *Os = 663 raw_os_ostream *Os =
638 new raw_os_ostream(OutputFilename == "-" ? std::cout : Ofs); 664 new raw_os_ostream(OutputFilename == "-" ? std::cout : Ofs);
639 Os->SetUnbuffered(); 665 Os->SetUnbuffered();
666 std::ofstream Lfs;
667 if (LogFilename != "-") {
668 Lfs.open(LogFilename.c_str(), std::ofstream::out);
669 }
670 raw_os_ostream *Ls = new raw_os_ostream(LogFilename == "-" ? std::cout : Lfs);
671 Ls->SetUnbuffered();
640 672
641 Ice::GlobalContext Ctx(Os, Os, VMask, TestPrefix); 673 Ice::GlobalContext Ctx(Ls, Os, VMask, TargetArch, OptLevel, TestPrefix);
642 674
643 for (Module::const_iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) { 675 for (Module::const_iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) {
644 if (I->empty()) 676 if (I->empty())
645 continue; 677 continue;
646 LLVM2ICEConverter FunctionConverter(&Ctx); 678 LLVM2ICEConverter FunctionConverter(&Ctx);
647 679
648 Ice::Timer TConvert; 680 Ice::Timer TConvert;
649 Ice::Cfg *Func = FunctionConverter.convertFunction(I); 681 Ice::Cfg *Func = FunctionConverter.convertFunction(I);
650 if (DisableInternal) 682 if (DisableInternal)
651 Func->setInternal(false); 683 Func->setInternal(false);
652 684
653 if (SubzeroTimingEnabled) { 685 if (SubzeroTimingEnabled) {
654 std::cerr << "[Subzero timing] Convert function " 686 std::cerr << "[Subzero timing] Convert function "
655 << Func->getFunctionName() << ": " << TConvert.getElapsedSec() 687 << Func->getFunctionName() << ": " << TConvert.getElapsedSec()
656 << " sec\n"; 688 << " sec\n";
657 } 689 }
658 690
659 if (DisableTranslation) { 691 if (DisableTranslation) {
660 Func->dump(); 692 Func->dump();
693 } else {
694 Ice::Timer TTranslate;
695 Func->translate();
696 if (SubzeroTimingEnabled) {
697 std::cerr << "[Subzero timing] Translate function "
698 << Func->getFunctionName() << ": "
699 << TTranslate.getElapsedSec() << " sec\n";
700 }
701 if (Func->hasError()) {
702 errs() << "ICE translation error: " << Func->getError() << "\n";
703 ExitStatus = 1;
704 }
705
706 Ice::Timer TEmit;
707 Func->emit();
708 if (SubzeroTimingEnabled) {
709 std::cerr << "[Subzero timing] Emit function "
710 << Func->getFunctionName() << ": " << TEmit.getElapsedSec()
711 << " sec\n";
712 }
661 } 713 }
662 } 714 }
663 715
664 return 0; 716 return ExitStatus;
665 } 717 }
OLDNEW
« no previous file with comments | « src/IceTypes.def ('k') | tests_lit/llvm2ice_tests/64bit.pnacl.ll » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698