| OLD | NEW |
| 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. |
| (...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 | 747 |
| 748 void LLVM2ICEGlobalsConverter::addGlobalInitializer( | 748 void LLVM2ICEGlobalsConverter::addGlobalInitializer( |
| 749 Ice::VariableDeclaration &Global, const Constant *Initializer, | 749 Ice::VariableDeclaration &Global, const Constant *Initializer, |
| 750 bool HasOffset, Ice::RelocOffsetT Offset) { | 750 bool HasOffset, Ice::RelocOffsetT Offset) { |
| 751 (void)HasOffset; | 751 (void)HasOffset; |
| 752 assert(HasOffset || Offset == 0); | 752 assert(HasOffset || Offset == 0); |
| 753 | 753 |
| 754 if (const auto CDA = dyn_cast<ConstantDataArray>(Initializer)) { | 754 if (const auto CDA = dyn_cast<ConstantDataArray>(Initializer)) { |
| 755 assert(!HasOffset && isa<IntegerType>(CDA->getElementType()) && | 755 assert(!HasOffset && isa<IntegerType>(CDA->getElementType()) && |
| 756 (cast<IntegerType>(CDA->getElementType())->getBitWidth() == 8)); | 756 (cast<IntegerType>(CDA->getElementType())->getBitWidth() == 8)); |
| 757 Global.addInitializer(new Ice::VariableDeclaration::DataInitializer( | 757 Global.addInitializer(Ice::VariableDeclaration::DataInitializer::create( |
| 758 CDA->getRawDataValues().data(), CDA->getNumElements())); | 758 CDA->getRawDataValues().data(), CDA->getNumElements())); |
| 759 return; | 759 return; |
| 760 } | 760 } |
| 761 | 761 |
| 762 if (isa<ConstantAggregateZero>(Initializer)) { | 762 if (isa<ConstantAggregateZero>(Initializer)) { |
| 763 if (const auto AT = dyn_cast<ArrayType>(Initializer->getType())) { | 763 if (const auto AT = dyn_cast<ArrayType>(Initializer->getType())) { |
| 764 assert(!HasOffset && isa<IntegerType>(AT->getElementType()) && | 764 assert(!HasOffset && isa<IntegerType>(AT->getElementType()) && |
| 765 (cast<IntegerType>(AT->getElementType())->getBitWidth() == 8)); | 765 (cast<IntegerType>(AT->getElementType())->getBitWidth() == 8)); |
| 766 Global.addInitializer( | 766 Global.addInitializer(Ice::VariableDeclaration::ZeroInitializer::create( |
| 767 new Ice::VariableDeclaration::ZeroInitializer(AT->getNumElements())); | 767 AT->getNumElements())); |
| 768 } else { | 768 } else { |
| 769 llvm_unreachable("Unhandled constant aggregate zero type"); | 769 llvm_unreachable("Unhandled constant aggregate zero type"); |
| 770 } | 770 } |
| 771 return; | 771 return; |
| 772 } | 772 } |
| 773 | 773 |
| 774 if (const auto Exp = dyn_cast<ConstantExpr>(Initializer)) { | 774 if (const auto Exp = dyn_cast<ConstantExpr>(Initializer)) { |
| 775 switch (Exp->getOpcode()) { | 775 switch (Exp->getOpcode()) { |
| 776 case Instruction::Add: | 776 case Instruction::Add: |
| 777 assert(!HasOffset); | 777 assert(!HasOffset); |
| 778 addGlobalInitializer(Global, Exp->getOperand(0), true, | 778 addGlobalInitializer(Global, Exp->getOperand(0), true, |
| 779 getIntegerLiteralConstant(Exp->getOperand(1))); | 779 getIntegerLiteralConstant(Exp->getOperand(1))); |
| 780 return; | 780 return; |
| 781 case Instruction::PtrToInt: { | 781 case Instruction::PtrToInt: { |
| 782 assert(TypeConverter.convertToIceType(Exp->getType()) == | 782 assert(TypeConverter.convertToIceType(Exp->getType()) == |
| 783 Ice::getPointerType()); | 783 Ice::getPointerType()); |
| 784 const auto GV = dyn_cast<GlobalValue>(Exp->getOperand(0)); | 784 const auto GV = dyn_cast<GlobalValue>(Exp->getOperand(0)); |
| 785 assert(GV); | 785 assert(GV); |
| 786 const Ice::GlobalDeclaration *Addr = | 786 const Ice::GlobalDeclaration *Addr = |
| 787 getConverter().getGlobalDeclaration(GV); | 787 getConverter().getGlobalDeclaration(GV); |
| 788 Global.addInitializer( | 788 Global.addInitializer( |
| 789 new Ice::VariableDeclaration::RelocInitializer(Addr, Offset)); | 789 Ice::VariableDeclaration::RelocInitializer::create(Addr, Offset)); |
| 790 return; | 790 return; |
| 791 } | 791 } |
| 792 default: | 792 default: |
| 793 break; | 793 break; |
| 794 } | 794 } |
| 795 } | 795 } |
| 796 | 796 |
| 797 std::string Buffer; | 797 std::string Buffer; |
| 798 raw_string_ostream StrBuf(Buffer); | 798 raw_string_ostream StrBuf(Buffer); |
| 799 StrBuf << "Unhandled global initializer: " << Initializer; | 799 StrBuf << "Unhandled global initializer: " << Initializer; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 860 for (const Function &Func : *Mod) { | 860 for (const Function &Func : *Mod) { |
| 861 FuncSigType Signature; | 861 FuncSigType Signature; |
| 862 FunctionType *FuncType = Func.getFunctionType(); | 862 FunctionType *FuncType = Func.getFunctionType(); |
| 863 Signature.setReturnType( | 863 Signature.setReturnType( |
| 864 Converter.convertToIceType(FuncType->getReturnType())); | 864 Converter.convertToIceType(FuncType->getReturnType())); |
| 865 for (size_t I = 0; I < FuncType->getNumParams(); ++I) { | 865 for (size_t I = 0; I < FuncType->getNumParams(); ++I) { |
| 866 Signature.appendArgType( | 866 Signature.appendArgType( |
| 867 Converter.convertToIceType(FuncType->getParamType(I))); | 867 Converter.convertToIceType(FuncType->getParamType(I))); |
| 868 } | 868 } |
| 869 FunctionDeclaration *IceFunc = FunctionDeclaration::create( | 869 FunctionDeclaration *IceFunc = FunctionDeclaration::create( |
| 870 Signature, Func.getCallingConv(), Func.getLinkage(), Func.empty()); | 870 Ctx, Signature, Func.getCallingConv(), Func.getLinkage(), Func.empty()); |
| 871 IceFunc->setName(Func.getName()); | 871 IceFunc->setName(Func.getName()); |
| 872 GlobalDeclarationMap[&Func] = IceFunc; | 872 GlobalDeclarationMap[&Func] = IceFunc; |
| 873 } | 873 } |
| 874 // Install global variable declarations. | 874 // Install global variable declarations. |
| 875 for (Module::const_global_iterator I = Mod->global_begin(), | 875 for (Module::const_global_iterator I = Mod->global_begin(), |
| 876 E = Mod->global_end(); | 876 E = Mod->global_end(); |
| 877 I != E; ++I) { | 877 I != E; ++I) { |
| 878 const GlobalVariable *GV = I; | 878 const GlobalVariable *GV = I; |
| 879 VariableDeclaration *Var = VariableDeclaration::create(); | 879 VariableDeclaration *Var = VariableDeclaration::create(Ctx); |
| 880 Var->setName(GV->getName()); | 880 Var->setName(GV->getName()); |
| 881 Var->setAlignment(GV->getAlignment()); | 881 Var->setAlignment(GV->getAlignment()); |
| 882 Var->setIsConstant(GV->isConstant()); | 882 Var->setIsConstant(GV->isConstant()); |
| 883 Var->setLinkage(GV->getLinkage()); | 883 Var->setLinkage(GV->getLinkage()); |
| 884 GlobalDeclarationMap[GV] = Var; | 884 GlobalDeclarationMap[GV] = Var; |
| 885 } | 885 } |
| 886 } | 886 } |
| 887 | 887 |
| 888 void Converter::convertGlobals(Module *Mod) { | 888 void Converter::convertGlobals(Module *Mod) { |
| 889 lowerGlobals(LLVM2ICEGlobalsConverter(*this).convertGlobalsToIce(Mod)); | 889 lowerGlobals(LLVM2ICEGlobalsConverter(*this).convertGlobalsToIce(Mod)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 902 Ctx->pushTimer(TimerID, StackID); | 902 Ctx->pushTimer(TimerID, StackID); |
| 903 } | 903 } |
| 904 LLVM2ICEFunctionConverter FunctionConverter(*this); | 904 LLVM2ICEFunctionConverter FunctionConverter(*this); |
| 905 FunctionConverter.convertFunction(&I); | 905 FunctionConverter.convertFunction(&I); |
| 906 if (TimeThisFunction) | 906 if (TimeThisFunction) |
| 907 Ctx->popTimer(TimerID, StackID); | 907 Ctx->popTimer(TimerID, StackID); |
| 908 } | 908 } |
| 909 } | 909 } |
| 910 | 910 |
| 911 } // end of namespace Ice | 911 } // end of namespace Ice |
| OLD | NEW |