barannikov88 updated this revision to Diff 519723. barannikov88 added a comment.
Add a templated overload to help derived classes avoid explicit casts Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D148092/new/ https://reviews.llvm.org/D148092 Files: clang/lib/CodeGen/TargetInfo.cpp clang/lib/CodeGen/TargetInfo.h
Index: clang/lib/CodeGen/TargetInfo.h =================================================================== --- clang/lib/CodeGen/TargetInfo.h +++ clang/lib/CodeGen/TargetInfo.h @@ -52,6 +52,11 @@ // by returning true from TargetInfo::checkCallingConvention for them. std::unique_ptr<SwiftABIInfo> SwiftInfo; + // Returns ABI info helper for the target. This is for use by derived classes. + template <typename T> const T &getABIInfo() const { + return static_cast<const T &>(*Info); + } + public: TargetCodeGenInfo(std::unique_ptr<ABIInfo> Info); virtual ~TargetCodeGenInfo(); Index: clang/lib/CodeGen/TargetInfo.cpp =================================================================== --- clang/lib/CodeGen/TargetInfo.cpp +++ clang/lib/CodeGen/TargetInfo.cpp @@ -2483,10 +2483,6 @@ std::make_unique<SwiftABIInfo>(CGT, /*SwiftErrorInRegister=*/true); } - const X86_64ABIInfo &getABIInfo() const { - return static_cast<const X86_64ABIInfo&>(TargetCodeGenInfo::getABIInfo()); - } - /// Disable tail call on x86-64. The epilogue code before the tail jump blocks /// autoreleaseRV/retainRV and autoreleaseRV/unsafeClaimRV optimizations. bool markARCOptimizedReturnCallsAsNoTail() const override { return true; } @@ -2523,7 +2519,7 @@ bool HasAVXType = false; for (CallArgList::const_iterator it = args.begin(), ie = args.end(); it != ie; ++it) { - if (getABIInfo().isPassedUsingAVXType(it->Ty)) { + if (getABIInfo<X86_64ABIInfo>().isPassedUsingAVXType(it->Ty)) { HasAVXType = true; break; } @@ -6404,10 +6400,6 @@ SwiftInfo = std::make_unique<ARMSwiftABIInfo>(CGT); } - const ARMABIInfo &getABIInfo() const { - return static_cast<const ARMABIInfo&>(TargetCodeGenInfo::getABIInfo()); - } - int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const override { return 13; } @@ -6426,7 +6418,8 @@ } unsigned getSizeOfUnwindException() const override { - if (getABIInfo().isEABI()) return 88; + if (getABIInfo<ARMABIInfo>().isEABI()) + return 88; return TargetCodeGenInfo::getSizeOfUnwindException(); } @@ -6493,7 +6486,7 @@ Fn->addFnAttr("interrupt", Kind); - ARMABIKind ABI = cast<ARMABIInfo>(getABIInfo()).getABIKind(); + ARMABIKind ABI = getABIInfo<ARMABIInfo>().getABIKind(); if (ABI == ARMABIKind::APCS) return; @@ -7431,10 +7424,6 @@ class SystemZTargetCodeGenInfo : public TargetCodeGenInfo { ASTContext &Ctx; - const SystemZABIInfo &getABIInfo() const { - return static_cast<const SystemZABIInfo&>(TargetCodeGenInfo::getABIInfo()); - } - // These are used for speeding up the search for a visible vector ABI. mutable bool HasVisibleVecABIFlag = false; mutable std::set<const Type *> SeenTypes; @@ -7883,8 +7872,9 @@ // it will be passed in a vector register. A wide (>16 bytes) vector will // be passed via "hidden" pointer where any extra alignment is not // required (per GCC). - const Type *SingleEltTy = - getABIInfo().GetSingleElementType(QualType(Ty, 0)).getTypePtr(); + const Type *SingleEltTy = getABIInfo<SystemZABIInfo>() + .GetSingleElementType(QualType(Ty, 0)) + .getTypePtr(); bool SingleVecEltStruct = SingleEltTy != Ty && SingleEltTy->isVectorType() && Ctx.getTypeSize(SingleEltTy) == Ctx.getTypeSize(Ty); if (Ty->isVectorType() || SingleVecEltStruct) @@ -11857,10 +11847,6 @@ public: BPFTargetCodeGenInfo(CodeGenTypes &CGT) : TargetCodeGenInfo(std::make_unique<BPFABIInfo>(CGT)) {} - - const BPFABIInfo &getABIInfo() const { - return static_cast<const BPFABIInfo&>(TargetCodeGenInfo::getABIInfo()); - } }; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits