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

Side by Side Diff: src/IceConverter.cpp

Issue 387023002: Clean up exit status and globals procecessing in llvm2ice. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Change ExitStatus to ErrorStatus. Created 6 years, 5 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/IceConverter.h ('k') | src/IceTranslator.h » ('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/IceConverter.cpp - Converts LLVM to Ice ---------------===// 1 //===- subzero/src/IceConverter.cpp - Converts LLVM to Ice ---------------===//
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 implements the LLVM to ICE converter. 10 // This file implements the LLVM to ICE converter.
11 // 11 //
12 //===----------------------------------------------------------------------===// 12 //===----------------------------------------------------------------------===//
13 13
14 #include "IceConverter.h" 14 #include "IceConverter.h"
15 15
16 #include "IceCfg.h" 16 #include "IceCfg.h"
17 #include "IceCfgNode.h" 17 #include "IceCfgNode.h"
18 #include "IceClFlags.h" 18 #include "IceClFlags.h"
19 #include "IceDefs.h" 19 #include "IceDefs.h"
20 #include "IceGlobalContext.h" 20 #include "IceGlobalContext.h"
21 #include "IceInst.h" 21 #include "IceInst.h"
22 #include "IceOperand.h" 22 #include "IceOperand.h"
23 #include "IceTargetLowering.h"
23 #include "IceTypes.h" 24 #include "IceTypes.h"
24 25
25 #include "llvm/IR/Constant.h" 26 #include "llvm/IR/Constant.h"
26 #include "llvm/IR/Constants.h" 27 #include "llvm/IR/Constants.h"
27 #include "llvm/IR/DataLayout.h" 28 #include "llvm/IR/DataLayout.h"
28 #include "llvm/IR/Instruction.h" 29 #include "llvm/IR/Instruction.h"
29 #include "llvm/IR/Instructions.h" 30 #include "llvm/IR/Instructions.h"
30 #include "llvm/IR/LLVMContext.h" 31 #include "llvm/IR/LLVMContext.h"
31 #include "llvm/IR/Module.h" 32 #include "llvm/IR/Module.h"
32 33
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 Ice::GlobalContext *Ctx; 651 Ice::GlobalContext *Ctx;
651 Ice::Cfg *Func; 652 Ice::Cfg *Func;
652 Ice::CfgNode *CurrentNode; 653 Ice::CfgNode *CurrentNode;
653 Ice::Type SubzeroPointerType; 654 Ice::Type SubzeroPointerType;
654 std::map<const Value *, Ice::Variable *> VarMap; 655 std::map<const Value *, Ice::Variable *> VarMap;
655 std::map<const BasicBlock *, Ice::CfgNode *> NodeMap; 656 std::map<const BasicBlock *, Ice::CfgNode *> NodeMap;
656 }; 657 };
657 658
658 } // end of anonymous namespace. 659 } // end of anonymous namespace.
659 660
660 int Ice::Converter::convertToIce(llvm::Module *Mod) { 661 namespace Ice {
662
663 void Converter::convertToIce(Module *Mod) {
664 convertGlobals(Mod);
665 convertFunctions(Mod);
666 }
667
668 void Converter::convertGlobals(Module *Mod) {
669 OwningPtr<TargetGlobalInitLowering> GlobalLowering(
670 TargetGlobalInitLowering::createLowering(Ctx->getTargetArch(), Ctx));
671 for (Module::const_global_iterator I = Mod->global_begin(),
672 E = Mod->global_end();
673 I != E; ++I) {
674 if (!I->hasInitializer())
675 continue;
676 const llvm::Constant *Initializer = I->getInitializer();
677 IceString Name = I->getName();
678 unsigned Align = I->getAlignment();
679 uint64_t NumElements = 0;
680 const char *Data = NULL;
681 bool IsInternal = I->hasInternalLinkage();
682 bool IsConst = I->isConstant();
683 bool IsZeroInitializer = false;
684
685 if (const ConstantDataArray *CDA =
686 dyn_cast<ConstantDataArray>(Initializer)) {
687 NumElements = CDA->getNumElements();
688 assert(isa<IntegerType>(CDA->getElementType()) &&
689 cast<IntegerType>(CDA->getElementType())->getBitWidth() == 8);
690 Data = CDA->getRawDataValues().data();
691 } else if (isa<ConstantAggregateZero>(Initializer)) {
692 if (const ArrayType *AT = dyn_cast<ArrayType>(Initializer->getType())) {
693 assert(isa<IntegerType>(AT->getElementType()) &&
694 cast<IntegerType>(AT->getElementType())->getBitWidth() == 8);
695 NumElements = AT->getNumElements();
696 IsZeroInitializer = true;
697 } else {
698 llvm_unreachable("Unhandled constant aggregate zero type");
699 }
700 } else {
701 llvm_unreachable("Unhandled global initializer");
702 }
703
704 GlobalLowering->lower(Name, Align, IsInternal, IsConst, IsZeroInitializer,
705 NumElements, Data, Flags.DisableTranslation);
706 }
707 GlobalLowering.reset();
708 }
709
710 void Converter::convertFunctions(Module *Mod) {
661 for (Module::const_iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) { 711 for (Module::const_iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) {
662 if (I->empty()) 712 if (I->empty())
663 continue; 713 continue;
664 LLVM2ICEConverter FunctionConverter(Ctx); 714 LLVM2ICEConverter FunctionConverter(Ctx);
665 715
666 Ice::Timer TConvert; 716 Timer TConvert;
667 Ice::Cfg *Fcn = FunctionConverter.convertFunction(I); 717 Cfg *Fcn = FunctionConverter.convertFunction(I);
668 if (Flags.SubzeroTimingEnabled) { 718 if (Flags.SubzeroTimingEnabled) {
669 std::cerr << "[Subzero timing] Convert function " 719 std::cerr << "[Subzero timing] Convert function "
670 << Fcn->getFunctionName() << ": " << TConvert.getElapsedSec() 720 << Fcn->getFunctionName() << ": " << TConvert.getElapsedSec()
671 << " sec\n"; 721 << " sec\n";
672 } 722 }
673 translateFcn(Fcn); 723 translateFcn(Fcn);
674 } 724 }
675 725
676 emitConstants(); 726 emitConstants();
677 return ExitStatus;
678 } 727 }
728
729 } // end of Ice namespace.
OLDNEW
« no previous file with comments | « src/IceConverter.h ('k') | src/IceTranslator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698