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

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: 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
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 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 raw_os_ostream *Os = 665 raw_os_ostream *Os =
664 new raw_os_ostream(OutputFilename == "-" ? std::cout : Ofs); 666 new raw_os_ostream(OutputFilename == "-" ? std::cout : Ofs);
665 Os->SetUnbuffered(); 667 Os->SetUnbuffered();
666 std::ofstream Lfs; 668 std::ofstream Lfs;
667 if (LogFilename != "-") { 669 if (LogFilename != "-") {
668 Lfs.open(LogFilename.c_str(), std::ofstream::out); 670 Lfs.open(LogFilename.c_str(), std::ofstream::out);
669 } 671 }
670 raw_os_ostream *Ls = new raw_os_ostream(LogFilename == "-" ? std::cout : Lfs); 672 raw_os_ostream *Ls = new raw_os_ostream(LogFilename == "-" ? std::cout : Lfs);
671 Ls->SetUnbuffered(); 673 Ls->SetUnbuffered();
672 674
675 Ice::Cfg *Func = NULL;
673 Ice::GlobalContext Ctx(Ls, Os, VMask, TargetArch, OptLevel, TestPrefix); 676 Ice::GlobalContext Ctx(Ls, Os, VMask, TargetArch, OptLevel, TestPrefix);
674 677
675 for (Module::const_iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) { 678 for (Module::const_iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) {
676 if (I->empty()) 679 if (I->empty())
677 continue; 680 continue;
678 LLVM2ICEConverter FunctionConverter(&Ctx); 681 LLVM2ICEConverter FunctionConverter(&Ctx);
679 682
683 // Ideally, we would have deleted the Ice::Cfg object (Func) at
684 // the end of the previous iteration. However, emitting the
685 // constant pool requires a valid Cfg object, so we need to defer
686 // deleting the last non-empty Cfg object until outside the loop
687 // and after emitting the constant pool. TODO: Since all
688 // constants are globally pooled in the Ice::GlobalContext object,
689 // change all Ice::Constant related functions to use GlobalContext
690 // instead of Cfg, and then clean up this loop.
691 delete Func;
JF 2014/05/22 21:39:47 A smart pointer be better here.
Jim Stichnoth 2014/05/22 23:48:28 Done.
692 Func = NULL;
693
680 Ice::Timer TConvert; 694 Ice::Timer TConvert;
681 Ice::Cfg *Func = FunctionConverter.convertFunction(I); 695 Func = FunctionConverter.convertFunction(I);
682 if (DisableInternal) 696 if (DisableInternal)
683 Func->setInternal(false); 697 Func->setInternal(false);
684 698
685 if (SubzeroTimingEnabled) { 699 if (SubzeroTimingEnabled) {
686 std::cerr << "[Subzero timing] Convert function " 700 std::cerr << "[Subzero timing] Convert function "
687 << Func->getFunctionName() << ": " << TConvert.getElapsedSec() 701 << Func->getFunctionName() << ": " << TConvert.getElapsedSec()
688 << " sec\n"; 702 << " sec\n";
689 } 703 }
690 704
691 if (DisableTranslation) { 705 if (DisableTranslation) {
(...skipping 14 matching lines...) Expand all
706 Ice::Timer TEmit; 720 Ice::Timer TEmit;
707 Func->emit(); 721 Func->emit();
708 if (SubzeroTimingEnabled) { 722 if (SubzeroTimingEnabled) {
709 std::cerr << "[Subzero timing] Emit function " 723 std::cerr << "[Subzero timing] Emit function "
710 << Func->getFunctionName() << ": " << TEmit.getElapsedSec() 724 << Func->getFunctionName() << ": " << TEmit.getElapsedSec()
711 << " sec\n"; 725 << " sec\n";
712 } 726 }
713 } 727 }
714 } 728 }
715 729
730 if (!DisableTranslation && Func)
731 Func->getTarget()->emitConstants();
732
733 delete Func;
734 Func = NULL;
JF 2014/05/22 21:39:47 Same.
Jim Stichnoth 2014/05/22 23:48:28 Done.
735
716 return ExitStatus; 736 return ExitStatus;
717 } 737 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698