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

Side by Side Diff: lib/CodeGen/TargetInfo.cpp

Issue 1022123003: clang: add support for asmjs arch and Emscripten OS (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-clang.git@master
Patch Set: Address comments. Created 5 years, 9 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 | « lib/CodeGen/ItaniumCXXABI.cpp ('k') | lib/Driver/Driver.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 return ABIArgInfo::getIndirect(0); 418 return ABIArgInfo::getIndirect(0);
419 419
420 // Treat an enum type as its underlying type. 420 // Treat an enum type as its underlying type.
421 if (const EnumType *EnumTy = RetTy->getAs<EnumType>()) 421 if (const EnumType *EnumTy = RetTy->getAs<EnumType>())
422 RetTy = EnumTy->getDecl()->getIntegerType(); 422 RetTy = EnumTy->getDecl()->getIntegerType();
423 423
424 return (RetTy->isPromotableIntegerType() ? 424 return (RetTy->isPromotableIntegerType() ?
425 ABIArgInfo::getExtend() : ABIArgInfo::getDirect()); 425 ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
426 } 426 }
427 427
428 // @LOCALMOD-START Emscripten
429 //===----------------------------------------------------------------------===//
430 // Emscripten ABI Implementation
431 //
432 // This is a very simple ABI that relies a lot on DefaultABIInfo.
433 //===----------------------------------------------------------------------===//
434
435 class EmscriptenABIInfo : public DefaultABIInfo {
436 public:
437 explicit EmscriptenABIInfo(CodeGen::CodeGenTypes &CGT)
438 : DefaultABIInfo(CGT) {}
439
440 ABIArgInfo classifyReturnType(QualType RetTy) const;
441 ABIArgInfo classifyArgumentType(QualType Ty) const;
442
443 // DefaultABIInfo's classifyReturnType and classifyArgumentType are
444 // non-virtual, but computeInfo is virtual, so we overload that.
445 void computeInfo(CGFunctionInfo &FI) const override {
446 FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
447 for (auto &Arg : FI.arguments())
448 Arg.info = classifyArgumentType(Arg.type);
449 }
450 };
451
452 class EmscriptenTargetCodeGenInfo : public TargetCodeGenInfo {
453 public:
454 explicit EmscriptenTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT)
455 : TargetCodeGenInfo(new EmscriptenABIInfo(CGT)) {}
456 };
457
458 /// \brief Classify argument of given type \p Ty.
459 ABIArgInfo EmscriptenABIInfo::classifyArgumentType(QualType Ty) const {
460 if (isAggregateTypeForABI(Ty)) {
461 unsigned TypeAlign = getContext().getTypeAlignInChars(Ty).getQuantity();
462 if (auto RAA = getRecordArgABI(Ty, getCXXABI()))
463 return ABIArgInfo::getIndirect(TypeAlign,
464 RAA == CGCXXABI::RAA_DirectInMemory);
465 return ABIArgInfo::getIndirect(TypeAlign);
466 }
467
468 // Otherwise just do the default thing.
469 return DefaultABIInfo::classifyArgumentType(Ty);
470 }
471
472 ABIArgInfo EmscriptenABIInfo::classifyReturnType(QualType RetTy) const {
473 if (isAggregateTypeForABI(RetTy)) {
474 // As an optimization, lower single-element structs to just return a regular
475 // value.
476 if (const Type *SeltTy = isSingleElementStruct(RetTy, getContext()))
477 return ABIArgInfo::getDirect(CGT.ConvertType(QualType(SeltTy, 0)));
478 }
479
480 // Otherwise just do the default thing.
481 return DefaultABIInfo::classifyReturnType(RetTy);
482 }
483 // @LOCALMOD-END Emscripten
484
428 //===----------------------------------------------------------------------===// 485 //===----------------------------------------------------------------------===//
429 // le32/PNaCl bitcode ABI Implementation 486 // le32/PNaCl bitcode ABI Implementation
430 // 487 //
431 // This is a simplified version of the x86_32 ABI. Arguments and return values 488 // This is a simplified version of the x86_32 ABI. Arguments and return values
432 // are always passed on the stack. 489 // are always passed on the stack.
433 //===----------------------------------------------------------------------===// 490 //===----------------------------------------------------------------------===//
434 491
435 class PNaClABIInfo : public ABIInfo { 492 class PNaClABIInfo : public ABIInfo {
436 public: 493 public:
437 PNaClABIInfo(CodeGen::CodeGenTypes &CGT) : ABIInfo(CGT) {} 494 PNaClABIInfo(CodeGen::CodeGenTypes &CGT) : ABIInfo(CGT) {}
(...skipping 6583 matching lines...) Expand 10 before | Expand all | Expand 10 after
7021 7078
7022 const TargetCodeGenInfo &CodeGenModule::getTargetCodeGenInfo() { 7079 const TargetCodeGenInfo &CodeGenModule::getTargetCodeGenInfo() {
7023 if (TheTargetCodeGenInfo) 7080 if (TheTargetCodeGenInfo)
7024 return *TheTargetCodeGenInfo; 7081 return *TheTargetCodeGenInfo;
7025 7082
7026 const llvm::Triple &Triple = getTarget().getTriple(); 7083 const llvm::Triple &Triple = getTarget().getTriple();
7027 switch (Triple.getArch()) { 7084 switch (Triple.getArch()) {
7028 default: 7085 default:
7029 return *(TheTargetCodeGenInfo = new DefaultTargetCodeGenInfo(Types)); 7086 return *(TheTargetCodeGenInfo = new DefaultTargetCodeGenInfo(Types));
7030 7087
7088 // @LOCALMOD-START Emscripten
7089 case llvm::Triple::asmjs:
7090 return *(TheTargetCodeGenInfo = new EmscriptenTargetCodeGenInfo(Types));
7091 // @LOCALMOD-END Emscripten
7092
7031 case llvm::Triple::le32: 7093 case llvm::Triple::le32:
7032 return *(TheTargetCodeGenInfo = new PNaClTargetCodeGenInfo(Types)); 7094 return *(TheTargetCodeGenInfo = new PNaClTargetCodeGenInfo(Types));
7033 case llvm::Triple::mips: 7095 case llvm::Triple::mips:
7034 case llvm::Triple::mipsel: 7096 case llvm::Triple::mipsel:
7035 return *(TheTargetCodeGenInfo = new MIPSTargetCodeGenInfo(Types, true)); 7097 return *(TheTargetCodeGenInfo = new MIPSTargetCodeGenInfo(Types, true));
7036 7098
7037 case llvm::Triple::mips64: 7099 case llvm::Triple::mips64:
7038 case llvm::Triple::mips64el: 7100 case llvm::Triple::mips64el:
7039 return *(TheTargetCodeGenInfo = new MIPSTargetCodeGenInfo(Types, false)); 7101 return *(TheTargetCodeGenInfo = new MIPSTargetCodeGenInfo(Types, false));
7040 7102
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
7142 } 7204 }
7143 } 7205 }
7144 case llvm::Triple::hexagon: 7206 case llvm::Triple::hexagon:
7145 return *(TheTargetCodeGenInfo = new HexagonTargetCodeGenInfo(Types)); 7207 return *(TheTargetCodeGenInfo = new HexagonTargetCodeGenInfo(Types));
7146 case llvm::Triple::sparcv9: 7208 case llvm::Triple::sparcv9:
7147 return *(TheTargetCodeGenInfo = new SparcV9TargetCodeGenInfo(Types)); 7209 return *(TheTargetCodeGenInfo = new SparcV9TargetCodeGenInfo(Types));
7148 case llvm::Triple::xcore: 7210 case llvm::Triple::xcore:
7149 return *(TheTargetCodeGenInfo = new XCoreTargetCodeGenInfo(Types)); 7211 return *(TheTargetCodeGenInfo = new XCoreTargetCodeGenInfo(Types));
7150 } 7212 }
7151 } 7213 }
OLDNEW
« no previous file with comments | « lib/CodeGen/ItaniumCXXABI.cpp ('k') | lib/Driver/Driver.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698