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 291213003: Subzero: Fix x86 floating-point constant emission (Closed) Base URL: https://gerrit.chromium.org/gerrit/p/native_client/pnacl-subzero.git@master
Patch Set: "Fix" static casting 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/IceTargetLoweringX8632.cpp ('k') | tests_lit/llvm2ice_tests/fpconst.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
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 "IceCfg.h" 16 #include "IceCfg.h"
17 #include "IceCfgNode.h" 17 #include "IceCfgNode.h"
18 #include "IceDefs.h" 18 #include "IceDefs.h"
19 #include "IceGlobalContext.h" 19 #include "IceGlobalContext.h"
20 #include "IceInst.h" 20 #include "IceInst.h"
21 #include "IceOperand.h" 21 #include "IceOperand.h"
22 #include "IceTargetLowering.h"
22 #include "IceTypes.h" 23 #include "IceTypes.h"
23 24
24 #include "llvm/IR/Constant.h" 25 #include "llvm/IR/Constant.h"
25 #include "llvm/IR/Constants.h" 26 #include "llvm/IR/Constants.h"
26 #include "llvm/IR/DataLayout.h" 27 #include "llvm/IR/DataLayout.h"
27 #include "llvm/IR/Instruction.h" 28 #include "llvm/IR/Instruction.h"
28 #include "llvm/IR/Instructions.h" 29 #include "llvm/IR/Instructions.h"
29 #include "llvm/IR/LLVMContext.h" 30 #include "llvm/IR/LLVMContext.h"
30 #include "llvm/IR/Module.h" 31 #include "llvm/IR/Module.h"
31 #include "llvm/IRReader/IRReader.h" 32 #include "llvm/IRReader/IRReader.h"
(...skipping 24 matching lines...) Expand all
56 // 57 //
57 class LLVM2ICEConverter { 58 class LLVM2ICEConverter {
58 public: 59 public:
59 LLVM2ICEConverter(Ice::GlobalContext *Ctx) 60 LLVM2ICEConverter(Ice::GlobalContext *Ctx)
60 : Ctx(Ctx), Func(NULL), CurrentNode(NULL) { 61 : Ctx(Ctx), Func(NULL), CurrentNode(NULL) {
61 // All PNaCl pointer widths are 32 bits because of the sandbox 62 // All PNaCl pointer widths are 32 bits because of the sandbox
62 // model. 63 // model.
63 SubzeroPointerType = Ice::IceType_i32; 64 SubzeroPointerType = Ice::IceType_i32;
64 } 65 }
65 66
67 // Caller is expected to delete the returned Ice::Cfg object.
66 Ice::Cfg *convertFunction(const Function *F) { 68 Ice::Cfg *convertFunction(const Function *F) {
67 VarMap.clear(); 69 VarMap.clear();
68 NodeMap.clear(); 70 NodeMap.clear();
69 Func = new Ice::Cfg(Ctx); 71 Func = new Ice::Cfg(Ctx);
70 Func->setFunctionName(F->getName()); 72 Func->setFunctionName(F->getName());
71 Func->setReturnType(convertType(F->getReturnType())); 73 Func->setReturnType(convertType(F->getReturnType()));
72 Func->setInternal(F->hasInternalLinkage()); 74 Func->setInternal(F->hasInternalLinkage());
73 75
74 // The initial definition/use of each arg is the entry node. 76 // The initial definition/use of each arg is the entry node.
75 CurrentNode = mapBasicBlockToNode(&F->getEntryBlock()); 77 CurrentNode = mapBasicBlockToNode(&F->getEntryBlock());
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 cl::init(""), cl::value_desc("prefix")); 613 cl::init(""), cl::value_desc("prefix"));
612 static cl::opt<bool> 614 static cl::opt<bool>
613 DisableInternal("external", 615 DisableInternal("external",
614 cl::desc("Disable 'internal' linkage type for testing")); 616 cl::desc("Disable 'internal' linkage type for testing"));
615 static cl::opt<bool> 617 static cl::opt<bool>
616 DisableTranslation("notranslate", cl::desc("Disable Subzero translation")); 618 DisableTranslation("notranslate", cl::desc("Disable Subzero translation"));
617 619
618 static cl::opt<bool> SubzeroTimingEnabled( 620 static cl::opt<bool> SubzeroTimingEnabled(
619 "timing", cl::desc("Enable breakdown timing of Subzero translation")); 621 "timing", cl::desc("Enable breakdown timing of Subzero translation"));
620 622
621 static cl::opt<NaClFileFormat> 623 static cl::opt<NaClFileFormat> InputFileFormat(
622 InputFileFormat( 624 "bitcode-format", cl::desc("Define format of input file:"),
623 "bitcode-format", 625 cl::values(clEnumValN(LLVMFormat, "llvm", "LLVM file (default)"),
624 cl::desc("Define format of input file:"), 626 clEnumValN(PNaClFormat, "pnacl", "PNaCl bitcode file"),
625 cl::values( 627 clEnumValEnd),
626 clEnumValN(LLVMFormat, "llvm", "LLVM file (default)"),
627 clEnumValN(PNaClFormat, "pnacl", "PNaCl bitcode file"),
628 clEnumValEnd),
629 cl::init(LLVMFormat)); 628 cl::init(LLVMFormat));
630 629
631 int main(int argc, char **argv) { 630 int main(int argc, char **argv) {
632 int ExitStatus = 0; 631 int ExitStatus = 0;
633 632
634 cl::ParseCommandLineOptions(argc, argv); 633 cl::ParseCommandLineOptions(argc, argv);
635 634
636 // Parse the input LLVM IR file into a module. 635 // Parse the input LLVM IR file into a module.
637 SMDiagnostic Err; 636 SMDiagnostic Err;
638 Module *Mod; 637 Module *Mod;
(...skipping 24 matching lines...) Expand all
663 raw_os_ostream *Os = 662 raw_os_ostream *Os =
664 new raw_os_ostream(OutputFilename == "-" ? std::cout : Ofs); 663 new raw_os_ostream(OutputFilename == "-" ? std::cout : Ofs);
665 Os->SetUnbuffered(); 664 Os->SetUnbuffered();
666 std::ofstream Lfs; 665 std::ofstream Lfs;
667 if (LogFilename != "-") { 666 if (LogFilename != "-") {
668 Lfs.open(LogFilename.c_str(), std::ofstream::out); 667 Lfs.open(LogFilename.c_str(), std::ofstream::out);
669 } 668 }
670 raw_os_ostream *Ls = new raw_os_ostream(LogFilename == "-" ? std::cout : Lfs); 669 raw_os_ostream *Ls = new raw_os_ostream(LogFilename == "-" ? std::cout : Lfs);
671 Ls->SetUnbuffered(); 670 Ls->SetUnbuffered();
672 671
672 // Ideally, Func would be declared inside the loop and its object
673 // would be automatically deleted at the end of the loop iteration.
674 // However, emitting the constant pool requires a valid Cfg object,
675 // so we need to defer deleting the last non-empty Cfg object until
676 // outside the loop and after emitting the constant pool. TODO:
677 // Since all constants are globally pooled in the Ice::GlobalContext
678 // object, change all Ice::Constant related functions to use
679 // GlobalContext instead of Cfg, and then clean up this loop.
680 OwningPtr<Ice::Cfg> Func;
673 Ice::GlobalContext Ctx(Ls, Os, VMask, TargetArch, OptLevel, TestPrefix); 681 Ice::GlobalContext Ctx(Ls, Os, VMask, TargetArch, OptLevel, TestPrefix);
674 682
675 for (Module::const_iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) { 683 for (Module::const_iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) {
676 if (I->empty()) 684 if (I->empty())
677 continue; 685 continue;
678 LLVM2ICEConverter FunctionConverter(&Ctx); 686 LLVM2ICEConverter FunctionConverter(&Ctx);
679 687
680 Ice::Timer TConvert; 688 Ice::Timer TConvert;
681 Ice::Cfg *Func = FunctionConverter.convertFunction(I); 689 Func.reset(FunctionConverter.convertFunction(I));
682 if (DisableInternal) 690 if (DisableInternal)
683 Func->setInternal(false); 691 Func->setInternal(false);
684 692
685 if (SubzeroTimingEnabled) { 693 if (SubzeroTimingEnabled) {
686 std::cerr << "[Subzero timing] Convert function " 694 std::cerr << "[Subzero timing] Convert function "
687 << Func->getFunctionName() << ": " << TConvert.getElapsedSec() 695 << Func->getFunctionName() << ": " << TConvert.getElapsedSec()
688 << " sec\n"; 696 << " sec\n";
689 } 697 }
690 698
691 if (DisableTranslation) { 699 if (DisableTranslation) {
(...skipping 14 matching lines...) Expand all
706 Ice::Timer TEmit; 714 Ice::Timer TEmit;
707 Func->emit(); 715 Func->emit();
708 if (SubzeroTimingEnabled) { 716 if (SubzeroTimingEnabled) {
709 std::cerr << "[Subzero timing] Emit function " 717 std::cerr << "[Subzero timing] Emit function "
710 << Func->getFunctionName() << ": " << TEmit.getElapsedSec() 718 << Func->getFunctionName() << ": " << TEmit.getElapsedSec()
711 << " sec\n"; 719 << " sec\n";
712 } 720 }
713 } 721 }
714 } 722 }
715 723
724 if (!DisableTranslation && Func)
725 Func->getTarget()->emitConstants();
726
716 return ExitStatus; 727 return ExitStatus;
717 } 728 }
OLDNEW
« no previous file with comments | « src/IceTargetLoweringX8632.cpp ('k') | tests_lit/llvm2ice_tests/fpconst.pnacl.ll » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698