| 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 /// \file | 10 /// \file |
| 11 /// \brief Implements the LLVM to ICE converter. | 11 /// \brief Implements the LLVM to ICE converter. |
| 12 /// | 12 /// |
| 13 //===----------------------------------------------------------------------===// | 13 //===----------------------------------------------------------------------===// |
| 14 | 14 |
| 15 #include "IceConverter.h" | 15 #include "IceConverter.h" |
| 16 | 16 |
| 17 #include "IceCfg.h" | 17 #include "IceCfg.h" |
| 18 #include "IceCfgNode.h" | 18 #include "IceCfgNode.h" |
| 19 #include "IceClFlags.h" | 19 #include "IceClFlags.h" |
| 20 #include "IceDefs.h" | 20 #include "IceDefs.h" |
| 21 #include "IceGlobalContext.h" | 21 #include "IceGlobalContext.h" |
| 22 #include "IceGlobalInits.h" | 22 #include "IceGlobalInits.h" |
| 23 #include "IceInst.h" | 23 #include "IceInst.h" |
| 24 #include "IceMangling.h" |
| 24 #include "IceOperand.h" | 25 #include "IceOperand.h" |
| 25 #include "IceTargetLowering.h" | 26 #include "IceTargetLowering.h" |
| 26 #include "IceTypes.h" | 27 #include "IceTypes.h" |
| 27 #include "IceTypeConverter.h" | 28 #include "IceTypeConverter.h" |
| 28 | 29 |
| 29 #ifdef __clang__ | 30 #ifdef __clang__ |
| 30 #pragma clang diagnostic push | 31 #pragma clang diagnostic push |
| 31 #pragma clang diagnostic ignored "-Wunused-parameter" | 32 #pragma clang diagnostic ignored "-Wunused-parameter" |
| 32 #endif // __clang__ | 33 #endif // __clang__ |
| 33 | 34 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 explicit LLVM2ICEFunctionConverter(Ice::Converter &Converter) | 95 explicit LLVM2ICEFunctionConverter(Ice::Converter &Converter) |
| 95 : LLVM2ICEConverter(Converter), Func(nullptr) {} | 96 : LLVM2ICEConverter(Converter), Func(nullptr) {} |
| 96 | 97 |
| 97 void convertFunction(const Function *F) { | 98 void convertFunction(const Function *F) { |
| 98 Func = Ice::Cfg::create(Ctx, Converter.getNextSequenceNumber()); | 99 Func = Ice::Cfg::create(Ctx, Converter.getNextSequenceNumber()); |
| 99 { | 100 { |
| 100 Ice::CfgLocalAllocatorScope _(Func.get()); | 101 Ice::CfgLocalAllocatorScope _(Func.get()); |
| 101 | 102 |
| 102 VarMap.clear(); | 103 VarMap.clear(); |
| 103 NodeMap.clear(); | 104 NodeMap.clear(); |
| 104 Func->setFunctionName(F->getName()); | 105 Func->setFunctionName(Ice::mangleName(F->getName())); |
| 105 Func->setReturnType(convertToIceType(F->getReturnType())); | 106 Func->setReturnType(convertToIceType(F->getReturnType())); |
| 106 Func->setInternal(F->hasInternalLinkage()); | 107 Func->setInternal(F->hasInternalLinkage()); |
| 107 Ice::TimerMarker T(Ice::TimerStack::TT_llvmConvert, Func.get()); | 108 Ice::TimerMarker T(Ice::TimerStack::TT_llvmConvert, Func.get()); |
| 108 | 109 |
| 109 // The initial definition/use of each arg is the entry node. | 110 // The initial definition/use of each arg is the entry node. |
| 110 for (auto ArgI = F->arg_begin(), ArgE = F->arg_end(); ArgI != ArgE; | 111 for (auto ArgI = F->arg_begin(), ArgE = F->arg_end(); ArgI != ArgE; |
| 111 ++ArgI) { | 112 ++ArgI) { |
| 112 Func->addArg(mapValueToIceVar(ArgI)); | 113 Func->addArg(mapValueToIceVar(ArgI)); |
| 113 } | 114 } |
| 114 | 115 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 134 if (const auto *Func = llvm::dyn_cast<Ice::FunctionDeclaration>(Decl)) | 135 if (const auto *Func = llvm::dyn_cast<Ice::FunctionDeclaration>(Decl)) |
| 135 IsUndefined = Func->isProto(); | 136 IsUndefined = Func->isProto(); |
| 136 else if (const auto *Var = llvm::dyn_cast<Ice::VariableDeclaration>(Decl)) | 137 else if (const auto *Var = llvm::dyn_cast<Ice::VariableDeclaration>(Decl)) |
| 137 IsUndefined = !Var->hasInitializer(); | 138 IsUndefined = !Var->hasInitializer(); |
| 138 else | 139 else |
| 139 report_fatal_error("Unhandled GlobalDeclaration type"); | 140 report_fatal_error("Unhandled GlobalDeclaration type"); |
| 140 if (IsUndefined) | 141 if (IsUndefined) |
| 141 return Ctx->getConstantExternSym(Decl->getName()); | 142 return Ctx->getConstantExternSym(Decl->getName()); |
| 142 else { | 143 else { |
| 143 const Ice::RelocOffsetT Offset = 0; | 144 const Ice::RelocOffsetT Offset = 0; |
| 144 return Ctx->getConstantSym(Offset, Decl->getName(), | 145 return Ctx->getConstantSym(Offset, Decl->getName()); |
| 145 Decl->getSuppressMangling()); | |
| 146 } | 146 } |
| 147 } else if (const auto CI = dyn_cast<ConstantInt>(Const)) { | 147 } else if (const auto CI = dyn_cast<ConstantInt>(Const)) { |
| 148 Ice::Type Ty = convertToIceType(CI->getType()); | 148 Ice::Type Ty = convertToIceType(CI->getType()); |
| 149 return Ctx->getConstantInt(Ty, CI->getSExtValue()); | 149 return Ctx->getConstantInt(Ty, CI->getSExtValue()); |
| 150 } else if (const auto CFP = dyn_cast<ConstantFP>(Const)) { | 150 } else if (const auto CFP = dyn_cast<ConstantFP>(Const)) { |
| 151 Ice::Type Type = convertToIceType(CFP->getType()); | 151 Ice::Type Type = convertToIceType(CFP->getType()); |
| 152 if (Type == Ice::IceType_f32) | 152 if (Type == Ice::IceType_f32) |
| 153 return Ctx->getConstantFloat(CFP->getValueAPF().convertToFloat()); | 153 return Ctx->getConstantFloat(CFP->getValueAPF().convertToFloat()); |
| 154 else if (Type == Ice::IceType_f64) | 154 else if (Type == Ice::IceType_f64) |
| 155 return Ctx->getConstantDouble(CFP->getValueAPF().convertToDouble()); | 155 return Ctx->getConstantDouble(CFP->getValueAPF().convertToDouble()); |
| (...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 } | 882 } |
| 883 if (!IceFunc->validateTypeSignature(Ctx)) | 883 if (!IceFunc->validateTypeSignature(Ctx)) |
| 884 report_fatal_error(IceFunc->getTypeSignatureError(Ctx)); | 884 report_fatal_error(IceFunc->getTypeSignatureError(Ctx)); |
| 885 GlobalDeclarationMap[&Func] = IceFunc; | 885 GlobalDeclarationMap[&Func] = IceFunc; |
| 886 } | 886 } |
| 887 // Install global variable declarations. | 887 // Install global variable declarations. |
| 888 for (Module::const_global_iterator I = Mod->global_begin(), | 888 for (Module::const_global_iterator I = Mod->global_begin(), |
| 889 E = Mod->global_end(); | 889 E = Mod->global_end(); |
| 890 I != E; ++I) { | 890 I != E; ++I) { |
| 891 const GlobalVariable *GV = I; | 891 const GlobalVariable *GV = I; |
| 892 auto *Var = VariableDeclaration::create(Ctx); | 892 constexpr bool NoSuppressMangling = false; |
| 893 Var->setName(GV->getName()); | 893 auto *Var = |
| 894 VariableDeclaration::create(Ctx, NoSuppressMangling, GV->getLinkage()); |
| 894 Var->setAlignment(GV->getAlignment()); | 895 Var->setAlignment(GV->getAlignment()); |
| 895 Var->setIsConstant(GV->isConstant()); | 896 Var->setIsConstant(GV->isConstant()); |
| 896 Var->setLinkage(GV->getLinkage()); | 897 Var->setName(GV->getName()); |
| 897 if (!Var->verifyLinkageCorrect(Ctx)) { | 898 if (!Var->verifyLinkageCorrect(Ctx)) { |
| 898 std::string Buffer; | 899 std::string Buffer; |
| 899 raw_string_ostream StrBuf(Buffer); | 900 raw_string_ostream StrBuf(Buffer); |
| 900 StrBuf << "Global " << Var->getName() | 901 StrBuf << "Global " << Var->getName() |
| 901 << " has incorrect linkage: " << Var->getLinkageName(); | 902 << " has incorrect linkage: " << Var->getLinkageName(); |
| 902 if (Var->isExternal()) | 903 if (Var->isExternal()) |
| 903 StrBuf << "\n Use flag -allow-externally-defined-symbols to override"; | 904 StrBuf << "\n Use flag -allow-externally-defined-symbols to override"; |
| 904 report_fatal_error(StrBuf.str()); | 905 report_fatal_error(StrBuf.str()); |
| 905 } | 906 } |
| 906 GlobalDeclarationMap[GV] = Var; | 907 GlobalDeclarationMap[GV] = Var; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 924 Ctx->pushTimer(TimerID, StackID); | 925 Ctx->pushTimer(TimerID, StackID); |
| 925 } | 926 } |
| 926 LLVM2ICEFunctionConverter FunctionConverter(*this); | 927 LLVM2ICEFunctionConverter FunctionConverter(*this); |
| 927 FunctionConverter.convertFunction(&I); | 928 FunctionConverter.convertFunction(&I); |
| 928 if (TimeThisFunction) | 929 if (TimeThisFunction) |
| 929 Ctx->popTimer(TimerID, StackID); | 930 Ctx->popTimer(TimerID, StackID); |
| 930 } | 931 } |
| 931 } | 932 } |
| 932 | 933 |
| 933 } // end of namespace Ice | 934 } // end of namespace Ice |
| OLD | NEW |