OLD | NEW |
1 //===---- TargetInfo.cpp - Encapsulate target details -----------*- C++ -*-===// | 1 //===---- TargetInfo.cpp - Encapsulate target details -----------*- C++ -*-===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
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 // These classes wrap the information about a call or function | 10 // These classes wrap the information about a call or function |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 return ABIArgInfo::getIndirect(0); | 425 return ABIArgInfo::getIndirect(0); |
426 | 426 |
427 // Treat an enum type as its underlying type. | 427 // Treat an enum type as its underlying type. |
428 if (const EnumType *EnumTy = RetTy->getAs<EnumType>()) | 428 if (const EnumType *EnumTy = RetTy->getAs<EnumType>()) |
429 RetTy = EnumTy->getDecl()->getIntegerType(); | 429 RetTy = EnumTy->getDecl()->getIntegerType(); |
430 | 430 |
431 return (RetTy->isPromotableIntegerType() ? | 431 return (RetTy->isPromotableIntegerType() ? |
432 ABIArgInfo::getExtend() : ABIArgInfo::getDirect()); | 432 ABIArgInfo::getExtend() : ABIArgInfo::getDirect()); |
433 } | 433 } |
434 | 434 |
435 // @LOCALMOD-START Emscripten | |
436 //===----------------------------------------------------------------------===// | |
437 // Emscripten ABI Implementation | |
438 // | |
439 // This is a very simple ABI that relies a lot on DefaultABIInfo. | |
440 //===----------------------------------------------------------------------===// | |
441 | |
442 class EmscriptenABIInfo : public DefaultABIInfo { | |
443 public: | |
444 explicit EmscriptenABIInfo(CodeGen::CodeGenTypes &CGT) | |
445 : DefaultABIInfo(CGT) {} | |
446 | |
447 ABIArgInfo classifyReturnType(QualType RetTy) const; | |
448 ABIArgInfo classifyArgumentType(QualType Ty) const; | |
449 | |
450 // DefaultABIInfo's classifyReturnType and classifyArgumentType are | |
451 // non-virtual, but computeInfo is virtual, so we overload that. | |
452 void computeInfo(CGFunctionInfo &FI) const override { | |
453 FI.getReturnInfo() = classifyReturnType(FI.getReturnType()); | |
454 for (auto &Arg : FI.arguments()) | |
455 Arg.info = classifyArgumentType(Arg.type); | |
456 } | |
457 }; | |
458 | |
459 class EmscriptenTargetCodeGenInfo : public TargetCodeGenInfo { | |
460 public: | |
461 explicit EmscriptenTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT) | |
462 : TargetCodeGenInfo(new EmscriptenABIInfo(CGT)) {} | |
463 }; | |
464 | |
465 /// \brief Classify argument of given type \p Ty. | |
466 ABIArgInfo EmscriptenABIInfo::classifyArgumentType(QualType Ty) const { | |
467 if (isAggregateTypeForABI(Ty)) { | |
468 unsigned TypeAlign = getContext().getTypeAlignInChars(Ty).getQuantity(); | |
469 if (auto RAA = getRecordArgABI(Ty, getCXXABI())) | |
470 return ABIArgInfo::getIndirect(TypeAlign, | |
471 RAA == CGCXXABI::RAA_DirectInMemory); | |
472 return ABIArgInfo::getIndirect(TypeAlign); | |
473 } | |
474 | |
475 // Otherwise just do the default thing. | |
476 return DefaultABIInfo::classifyArgumentType(Ty); | |
477 } | |
478 | |
479 ABIArgInfo EmscriptenABIInfo::classifyReturnType(QualType RetTy) const { | |
480 if (isAggregateTypeForABI(RetTy)) { | |
481 // As an optimization, lower single-element structs to just return a regular | |
482 // value. | |
483 if (const Type *SeltTy = isSingleElementStruct(RetTy, getContext())) | |
484 return ABIArgInfo::getDirect(CGT.ConvertType(QualType(SeltTy, 0))); | |
485 } | |
486 | |
487 // Otherwise just do the default thing. | |
488 return DefaultABIInfo::classifyReturnType(RetTy); | |
489 } | |
490 // @LOCALMOD-END Emscripten | |
491 | |
492 //===----------------------------------------------------------------------===// | 435 //===----------------------------------------------------------------------===// |
493 // le32/PNaCl bitcode ABI Implementation | 436 // le32/PNaCl bitcode ABI Implementation |
494 // | 437 // |
495 // This is a simplified version of the x86_32 ABI. Arguments and return values | 438 // This is a simplified version of the x86_32 ABI. Arguments and return values |
496 // are always passed on the stack. | 439 // are always passed on the stack. |
497 //===----------------------------------------------------------------------===// | 440 //===----------------------------------------------------------------------===// |
498 | 441 |
499 class PNaClABIInfo : public ABIInfo { | 442 class PNaClABIInfo : public ABIInfo { |
500 public: | 443 public: |
501 PNaClABIInfo(CodeGen::CodeGenTypes &CGT) : ABIInfo(CGT) {} | 444 PNaClABIInfo(CodeGen::CodeGenTypes &CGT) : ABIInfo(CGT) {} |
(...skipping 6537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7039 | 6982 |
7040 const TargetCodeGenInfo &CodeGenModule::getTargetCodeGenInfo() { | 6983 const TargetCodeGenInfo &CodeGenModule::getTargetCodeGenInfo() { |
7041 if (TheTargetCodeGenInfo) | 6984 if (TheTargetCodeGenInfo) |
7042 return *TheTargetCodeGenInfo; | 6985 return *TheTargetCodeGenInfo; |
7043 | 6986 |
7044 const llvm::Triple &Triple = getTarget().getTriple(); | 6987 const llvm::Triple &Triple = getTarget().getTriple(); |
7045 switch (Triple.getArch()) { | 6988 switch (Triple.getArch()) { |
7046 default: | 6989 default: |
7047 return *(TheTargetCodeGenInfo = new DefaultTargetCodeGenInfo(Types)); | 6990 return *(TheTargetCodeGenInfo = new DefaultTargetCodeGenInfo(Types)); |
7048 | 6991 |
7049 // @LOCALMOD-START Emscripten | |
7050 case llvm::Triple::asmjs: | |
7051 return *(TheTargetCodeGenInfo = new EmscriptenTargetCodeGenInfo(Types)); | |
7052 // @LOCALMOD-END Emscripten | |
7053 | |
7054 case llvm::Triple::le32: | 6992 case llvm::Triple::le32: |
7055 return *(TheTargetCodeGenInfo = new PNaClTargetCodeGenInfo(Types)); | 6993 return *(TheTargetCodeGenInfo = new PNaClTargetCodeGenInfo(Types)); |
7056 case llvm::Triple::mips: | 6994 case llvm::Triple::mips: |
7057 case llvm::Triple::mipsel: | 6995 case llvm::Triple::mipsel: |
7058 if (Triple.getOS() == llvm::Triple::NaCl) | 6996 if (Triple.getOS() == llvm::Triple::NaCl) |
7059 return *(TheTargetCodeGenInfo = new PNaClTargetCodeGenInfo(Types)); | 6997 return *(TheTargetCodeGenInfo = new PNaClTargetCodeGenInfo(Types)); |
7060 return *(TheTargetCodeGenInfo = new MIPSTargetCodeGenInfo(Types, true)); | 6998 return *(TheTargetCodeGenInfo = new MIPSTargetCodeGenInfo(Types, true)); |
7061 | 6999 |
7062 case llvm::Triple::mips64: | 7000 case llvm::Triple::mips64: |
7063 case llvm::Triple::mips64el: | 7001 case llvm::Triple::mips64el: |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7171 case llvm::Triple::r600: | 7109 case llvm::Triple::r600: |
7172 return *(TheTargetCodeGenInfo = new AMDGPUTargetCodeGenInfo(Types)); | 7110 return *(TheTargetCodeGenInfo = new AMDGPUTargetCodeGenInfo(Types)); |
7173 case llvm::Triple::amdgcn: | 7111 case llvm::Triple::amdgcn: |
7174 return *(TheTargetCodeGenInfo = new AMDGPUTargetCodeGenInfo(Types)); | 7112 return *(TheTargetCodeGenInfo = new AMDGPUTargetCodeGenInfo(Types)); |
7175 case llvm::Triple::sparcv9: | 7113 case llvm::Triple::sparcv9: |
7176 return *(TheTargetCodeGenInfo = new SparcV9TargetCodeGenInfo(Types)); | 7114 return *(TheTargetCodeGenInfo = new SparcV9TargetCodeGenInfo(Types)); |
7177 case llvm::Triple::xcore: | 7115 case llvm::Triple::xcore: |
7178 return *(TheTargetCodeGenInfo = new XCoreTargetCodeGenInfo(Types)); | 7116 return *(TheTargetCodeGenInfo = new XCoreTargetCodeGenInfo(Types)); |
7179 } | 7117 } |
7180 } | 7118 } |
OLD | NEW |