Index: include/llvm/Analysis/TargetTransformInfo.h =================================================================== --- include/llvm/Analysis/TargetTransformInfo.h +++ include/llvm/Analysis/TargetTransformInfo.h @@ -598,6 +598,16 @@ /// @} + /// Returns true iff i32 parameters to library functions should have + /// signext or zeroext attributes if they correspond to C-level int or + /// unsigned int, respectively. + bool shouldExtI32Param() const; + + /// Returns true iff i32 results from library functions should have + /// signext or zeroext attributes if they correspond to C-level int or + /// unsigned int, respectively. + bool shouldExtI32Result() const; + private: /// \brief The abstract base class used to type erase specific TTI /// implementations. @@ -716,6 +726,8 @@ Type *ExpectedType) = 0; virtual bool areInlineCompatible(const Function *Caller, const Function *Callee) const = 0; + virtual bool shouldExtI32Param() const = 0; + virtual bool shouldExtI32Result() const = 0; }; template @@ -948,6 +960,12 @@ const Function *Callee) const override { return Impl.areInlineCompatible(Caller, Callee); } + bool shouldExtI32Param() const override { + return Impl.shouldExtI32Param(); + } + bool shouldExtI32Result() const override { + return Impl.shouldExtI32Result(); + } }; template Index: include/llvm/Analysis/TargetTransformInfoImpl.h =================================================================== --- include/llvm/Analysis/TargetTransformInfoImpl.h +++ include/llvm/Analysis/TargetTransformInfoImpl.h @@ -371,6 +371,10 @@ (Caller->getFnAttribute("target-features") == Callee->getFnAttribute("target-features")); } + + bool shouldExtI32Param() const { return false; } + + bool shouldExtI32Result() const { return false; } }; /// \brief CRTP base class for use as a mix-in that aids implementing Index: lib/Analysis/TargetTransformInfo.cpp =================================================================== --- lib/Analysis/TargetTransformInfo.cpp +++ lib/Analysis/TargetTransformInfo.cpp @@ -396,6 +396,14 @@ return TTIImpl->areInlineCompatible(Caller, Callee); } +bool TargetTransformInfo::shouldExtI32Param() const { + return TTIImpl->shouldExtI32Param(); +} + +bool TargetTransformInfo::shouldExtI32Result() const { + return TTIImpl->shouldExtI32Result(); +} + TargetTransformInfo::Concept::~Concept() {} TargetIRAnalysis::TargetIRAnalysis() : TTICallback(&getDefaultTTI) {} Index: lib/Target/Mips/MipsTargetMachine.cpp =================================================================== --- lib/Target/Mips/MipsTargetMachine.cpp +++ lib/Target/Mips/MipsTargetMachine.cpp @@ -24,6 +24,7 @@ #include "MipsSEISelLowering.h" #include "MipsSEInstrInfo.h" #include "MipsTargetObjectFile.h" +#include "MipsTargetTransformInfo.h" #include "llvm/Analysis/TargetTransformInfo.h" #include "llvm/CodeGen/Passes.h" #include "llvm/CodeGen/TargetPassConfig.h" @@ -253,7 +254,7 @@ } DEBUG(errs() << "Target Transform Info Pass Added\n"); - return TargetTransformInfo(BasicTTIImpl(this, F)); + return TargetTransformInfo(MipsTTIImpl(this, F)); }); } Index: lib/Target/Mips/MipsTargetTransformInfo.h =================================================================== --- /dev/null +++ lib/Target/Mips/MipsTargetTransformInfo.h @@ -0,0 +1,47 @@ +//===-- MipsTargetTransformInfo.h - Mips-specific TTI ---------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIB_TARGET_MIPS_MIPSTARGETTRANSFORMINFO_H +#define LLVM_LIB_TARGET_MIPS_MIPSTARGETTRANSFORMINFO_H + +#include "MipsTargetMachine.h" +#include "llvm/Analysis/TargetTransformInfo.h" +#include "llvm/CodeGen/BasicTTIImpl.h" + +namespace llvm { + +class MipsTTIImpl : public BasicTTIImplBase { + typedef BasicTTIImplBase BaseT; + typedef TargetTransformInfo TTI; + friend BaseT; + + const MipsSubtarget *ST; + const MipsTargetLowering *TLI; + + const MipsSubtarget *getST() const { return ST; } + const MipsTargetLowering *getTLI() const { return TLI; } + +public: + explicit MipsTTIImpl(const MipsTargetMachine *TM, const Function &F) + : BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl(F)), + TLI(ST->getTargetLowering()) {} + + // Provide value semantics. MSVC requires that we spell all of these out. + MipsTTIImpl(const MipsTTIImpl &Arg) + : BaseT(static_cast(Arg)), ST(Arg.ST), TLI(Arg.TLI) {} + MipsTTIImpl(MipsTTIImpl &&Arg) + : BaseT(std::move(static_cast(Arg))), ST(std::move(Arg.ST)), + TLI(std::move(Arg.TLI)) {} + + bool shouldExtI32Param() const { return ST->isABI_N64(); } +}; + +} // end namespace llvm + +#endif Index: lib/Target/PowerPC/PPCTargetTransformInfo.h =================================================================== --- lib/Target/PowerPC/PPCTargetTransformInfo.h +++ lib/Target/PowerPC/PPCTargetTransformInfo.h @@ -92,6 +92,9 @@ unsigned AddressSpace); /// @} + + bool shouldExtI32Param() const { return ST->isPPC64(); } + bool shouldExtI32Result() const { return ST->isPPC64(); } }; } // end namespace llvm Index: lib/Target/Sparc/LLVMBuild.txt =================================================================== --- lib/Target/Sparc/LLVMBuild.txt +++ lib/Target/Sparc/LLVMBuild.txt @@ -31,6 +31,6 @@ type = Library name = SparcCodeGen parent = Sparc -required_libraries = AsmPrinter CodeGen Core MC SelectionDAG SparcAsmPrinter - SparcDesc SparcInfo Support Target +required_libraries = Analysis AsmPrinter CodeGen Core MC SelectionDAG + SparcAsmPrinter SparcDesc SparcInfo Support Target add_to_library_groups = Sparc Index: lib/Target/Sparc/SparcTargetMachine.h =================================================================== --- lib/Target/Sparc/SparcTargetMachine.h +++ lib/Target/Sparc/SparcTargetMachine.h @@ -35,6 +35,8 @@ const SparcSubtarget *getSubtargetImpl() const { return &Subtarget; } const SparcSubtarget *getSubtargetImpl(const Function &) const override; + TargetIRAnalysis getTargetIRAnalysis() override; + // Pass Pipeline Configuration TargetPassConfig *createPassConfig(PassManagerBase &PM) override; TargetLoweringObjectFile *getObjFileLowering() const override { Index: lib/Target/Sparc/SparcTargetMachine.cpp =================================================================== --- lib/Target/Sparc/SparcTargetMachine.cpp +++ lib/Target/Sparc/SparcTargetMachine.cpp @@ -12,6 +12,7 @@ #include "SparcTargetMachine.h" #include "SparcTargetObjectFile.h" +#include "SparcTargetTransformInfo.h" #include "Sparc.h" #include "LeonPasses.h" #include "llvm/CodeGen/Passes.h" @@ -163,6 +164,12 @@ } } +TargetIRAnalysis SparcTargetMachine::getTargetIRAnalysis() { + return TargetIRAnalysis([this](const Function &F) { + return TargetTransformInfo(SparcTTIImpl(this, F)); + }); +} + void SparcV8TargetMachine::anchor() { } SparcV8TargetMachine::SparcV8TargetMachine(const Target &T, const Triple &TT, Index: lib/Target/Sparc/SparcTargetTransformInfo.h =================================================================== --- /dev/null +++ lib/Target/Sparc/SparcTargetTransformInfo.h @@ -0,0 +1,48 @@ +//===-- SparcTargetTransformInfo.h - Sparc-specific TTI ---------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIB_TARGET_SPARC_SPARCTARGETTRANSFORMINFO_H +#define LLVM_LIB_TARGET_SPARC_SPARCTARGETTRANSFORMINFO_H + +#include "SparcTargetMachine.h" +#include "llvm/Analysis/TargetTransformInfo.h" +#include "llvm/CodeGen/BasicTTIImpl.h" + +namespace llvm { + +class SparcTTIImpl : public BasicTTIImplBase { + typedef BasicTTIImplBase BaseT; + typedef TargetTransformInfo TTI; + friend BaseT; + + const SparcSubtarget *ST; + const SparcTargetLowering *TLI; + + const SparcSubtarget *getST() const { return ST; } + const SparcTargetLowering *getTLI() const { return TLI; } + +public: + explicit SparcTTIImpl(const SparcTargetMachine *TM, const Function &F) + : BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl(F)), + TLI(ST->getTargetLowering()) {} + + // Provide value semantics. MSVC requires that we spell all of these out. + SparcTTIImpl(const SparcTTIImpl &Arg) + : BaseT(static_cast(Arg)), ST(Arg.ST), TLI(Arg.TLI) {} + SparcTTIImpl(SparcTTIImpl &&Arg) + : BaseT(std::move(static_cast(Arg))), ST(std::move(Arg.ST)), + TLI(std::move(Arg.TLI)) {} + + bool shouldExtI32Param() const { return ST->isV9(); } + bool shouldExtI32Result() const { return ST->isV9(); } +}; + +} // end namespace llvm + +#endif Index: lib/Target/SystemZ/SystemZTargetTransformInfo.h =================================================================== --- lib/Target/SystemZ/SystemZTargetTransformInfo.h +++ lib/Target/SystemZ/SystemZTargetTransformInfo.h @@ -59,6 +59,9 @@ unsigned getRegisterBitWidth(bool Vector); /// @} + + bool shouldExtI32Param() const { return true; } + bool shouldExtI32Result() const { return true; } }; } // end namespace llvm