Access the TargetLoweringInfo from the TargetMachine object instead of caching it. The TLI may change between functions. No functionality change.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184349 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Bill Wendling 2013-06-19 20:51:24 +00:00
parent 2e1dc2d265
commit ea44281d5d
10 changed files with 56 additions and 46 deletions

View File

@ -329,7 +329,7 @@ namespace llvm {
/// This pass implements the target transform info analysis using the target /// This pass implements the target transform info analysis using the target
/// independent information available to the LLVM code generator. /// independent information available to the LLVM code generator.
ImmutablePass * ImmutablePass *
createBasicTargetTransformInfoPass(const TargetLoweringBase *TLI); createBasicTargetTransformInfoPass(const TargetMachine *TLI);
/// createUnreachableBlockEliminationPass - The LLVM code generator does not /// createUnreachableBlockEliminationPass - The LLVM code generator does not
/// work well with unreachable basic blocks (what live ranges make sense for a /// work well with unreachable basic blocks (what live ranges make sense for a
@ -518,7 +518,7 @@ namespace llvm {
/// createStackProtectorPass - This pass adds stack protectors to functions. /// createStackProtectorPass - This pass adds stack protectors to functions.
/// ///
FunctionPass *createStackProtectorPass(const TargetLoweringBase *tli); FunctionPass *createStackProtectorPass(const TargetMachine *TM);
/// createMachineVerifierPass - This pass verifies cenerated machine code /// createMachineVerifierPass - This pass verifies cenerated machine code
/// instructions for correctness. /// instructions for correctness.
@ -527,12 +527,12 @@ namespace llvm {
/// createDwarfEHPass - This pass mulches exception handling code into a form /// createDwarfEHPass - This pass mulches exception handling code into a form
/// adapted to code generation. Required if using dwarf exception handling. /// adapted to code generation. Required if using dwarf exception handling.
FunctionPass *createDwarfEHPass(const TargetLoweringBase *tli); FunctionPass *createDwarfEHPass(const TargetMachine *TM);
/// createSjLjEHPreparePass - This pass adapts exception handling code to use /// createSjLjEHPreparePass - This pass adapts exception handling code to use
/// the GCC-style builtin setjmp/longjmp (sjlj) to handling EH control flow. /// the GCC-style builtin setjmp/longjmp (sjlj) to handling EH control flow.
/// ///
FunctionPass *createSjLjEHPreparePass(const TargetLoweringBase *tli); FunctionPass *createSjLjEHPreparePass(const TargetMachine *TM);
/// LocalStackSlotAllocation - This pass assigns local frame indices to stack /// LocalStackSlotAllocation - This pass assigns local frame indices to stack
/// slots relative to one another and allocates base registers to access them /// slots relative to one another and allocates base registers to access them

View File

@ -26,18 +26,20 @@ using namespace llvm;
namespace { namespace {
class BasicTTI : public ImmutablePass, public TargetTransformInfo { class BasicTTI : public ImmutablePass, public TargetTransformInfo {
const TargetLoweringBase *TLI; const TargetMachine *TM;
/// Estimate the overhead of scalarizing an instruction. Insert and Extract /// Estimate the overhead of scalarizing an instruction. Insert and Extract
/// are set if the result needs to be inserted and/or extracted from vectors. /// are set if the result needs to be inserted and/or extracted from vectors.
unsigned getScalarizationOverhead(Type *Ty, bool Insert, bool Extract) const; unsigned getScalarizationOverhead(Type *Ty, bool Insert, bool Extract) const;
const TargetLoweringBase *getTLI() const { return TM->getTargetLowering(); }
public: public:
BasicTTI() : ImmutablePass(ID), TLI(0) { BasicTTI() : ImmutablePass(ID), TM(0) {
llvm_unreachable("This pass cannot be directly constructed"); llvm_unreachable("This pass cannot be directly constructed");
} }
BasicTTI(const TargetLoweringBase *TLI) : ImmutablePass(ID), TLI(TLI) { BasicTTI(const TargetMachine *TM) : ImmutablePass(ID), TM(TM) {
initializeBasicTTIPass(*PassRegistry::getPassRegistry()); initializeBasicTTIPass(*PassRegistry::getPassRegistry());
} }
@ -118,17 +120,17 @@ INITIALIZE_AG_PASS(BasicTTI, TargetTransformInfo, "basictti",
char BasicTTI::ID = 0; char BasicTTI::ID = 0;
ImmutablePass * ImmutablePass *
llvm::createBasicTargetTransformInfoPass(const TargetLoweringBase *TLI) { llvm::createBasicTargetTransformInfoPass(const TargetMachine *TM) {
return new BasicTTI(TLI); return new BasicTTI(TM);
} }
bool BasicTTI::isLegalAddImmediate(int64_t imm) const { bool BasicTTI::isLegalAddImmediate(int64_t imm) const {
return TLI->isLegalAddImmediate(imm); return getTLI()->isLegalAddImmediate(imm);
} }
bool BasicTTI::isLegalICmpImmediate(int64_t imm) const { bool BasicTTI::isLegalICmpImmediate(int64_t imm) const {
return TLI->isLegalICmpImmediate(imm); return getTLI()->isLegalICmpImmediate(imm);
} }
bool BasicTTI::isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, bool BasicTTI::isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV,
@ -139,7 +141,7 @@ bool BasicTTI::isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV,
AM.BaseOffs = BaseOffset; AM.BaseOffs = BaseOffset;
AM.HasBaseReg = HasBaseReg; AM.HasBaseReg = HasBaseReg;
AM.Scale = Scale; AM.Scale = Scale;
return TLI->isLegalAddressingMode(AM, Ty); return getTLI()->isLegalAddressingMode(AM, Ty);
} }
int BasicTTI::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV, int BasicTTI::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
@ -150,27 +152,28 @@ int BasicTTI::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
AM.BaseOffs = BaseOffset; AM.BaseOffs = BaseOffset;
AM.HasBaseReg = HasBaseReg; AM.HasBaseReg = HasBaseReg;
AM.Scale = Scale; AM.Scale = Scale;
return TLI->getScalingFactorCost(AM, Ty); return getTLI()->getScalingFactorCost(AM, Ty);
} }
bool BasicTTI::isTruncateFree(Type *Ty1, Type *Ty2) const { bool BasicTTI::isTruncateFree(Type *Ty1, Type *Ty2) const {
return TLI->isTruncateFree(Ty1, Ty2); return getTLI()->isTruncateFree(Ty1, Ty2);
} }
bool BasicTTI::isTypeLegal(Type *Ty) const { bool BasicTTI::isTypeLegal(Type *Ty) const {
EVT T = TLI->getValueType(Ty); EVT T = getTLI()->getValueType(Ty);
return TLI->isTypeLegal(T); return getTLI()->isTypeLegal(T);
} }
unsigned BasicTTI::getJumpBufAlignment() const { unsigned BasicTTI::getJumpBufAlignment() const {
return TLI->getJumpBufAlignment(); return getTLI()->getJumpBufAlignment();
} }
unsigned BasicTTI::getJumpBufSize() const { unsigned BasicTTI::getJumpBufSize() const {
return TLI->getJumpBufSize(); return getTLI()->getJumpBufSize();
} }
bool BasicTTI::shouldBuildLookupTables() const { bool BasicTTI::shouldBuildLookupTables() const {
const TargetLoweringBase *TLI = getTLI();
return TLI->supportJumpTables() && return TLI->supportJumpTables() &&
(TLI->isOperationLegalOrCustom(ISD::BR_JT, MVT::Other) || (TLI->isOperationLegalOrCustom(ISD::BR_JT, MVT::Other) ||
TLI->isOperationLegalOrCustom(ISD::BRIND, MVT::Other)); TLI->isOperationLegalOrCustom(ISD::BRIND, MVT::Other));
@ -213,6 +216,7 @@ unsigned BasicTTI::getArithmeticInstrCost(unsigned Opcode, Type *Ty,
OperandValueKind, OperandValueKind,
OperandValueKind) const { OperandValueKind) const {
// Check if any of the operands are vector operands. // Check if any of the operands are vector operands.
const TargetLoweringBase *TLI = getTLI();
int ISD = TLI->InstructionOpcodeToISD(Opcode); int ISD = TLI->InstructionOpcodeToISD(Opcode);
assert(ISD && "Invalid opcode"); assert(ISD && "Invalid opcode");
@ -259,6 +263,7 @@ unsigned BasicTTI::getShuffleCost(ShuffleKind Kind, Type *Tp, int Index,
unsigned BasicTTI::getCastInstrCost(unsigned Opcode, Type *Dst, unsigned BasicTTI::getCastInstrCost(unsigned Opcode, Type *Dst,
Type *Src) const { Type *Src) const {
const TargetLoweringBase *TLI = getTLI();
int ISD = TLI->InstructionOpcodeToISD(Opcode); int ISD = TLI->InstructionOpcodeToISD(Opcode);
assert(ISD && "Invalid opcode"); assert(ISD && "Invalid opcode");
@ -352,6 +357,7 @@ unsigned BasicTTI::getCFInstrCost(unsigned Opcode) const {
unsigned BasicTTI::getCmpSelInstrCost(unsigned Opcode, Type *ValTy, unsigned BasicTTI::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
Type *CondTy) const { Type *CondTy) const {
const TargetLoweringBase *TLI = getTLI();
int ISD = TLI->InstructionOpcodeToISD(Opcode); int ISD = TLI->InstructionOpcodeToISD(Opcode);
assert(ISD && "Invalid opcode"); assert(ISD && "Invalid opcode");
@ -396,7 +402,7 @@ unsigned BasicTTI::getMemoryOpCost(unsigned Opcode, Type *Src,
unsigned Alignment, unsigned Alignment,
unsigned AddressSpace) const { unsigned AddressSpace) const {
assert(!Src->isVoidTy() && "Invalid type"); assert(!Src->isVoidTy() && "Invalid type");
std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(Src); std::pair<unsigned, MVT> LT = getTLI()->getTypeLegalizationCost(Src);
// Assume that all loads of legal types cost 1. // Assume that all loads of legal types cost 1.
return LT.first; return LT.first;
@ -443,6 +449,7 @@ unsigned BasicTTI::getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy,
case Intrinsic::fmuladd: ISD = ISD::FMA; break; // FIXME: mul + add? case Intrinsic::fmuladd: ISD = ISD::FMA; break; // FIXME: mul + add?
} }
const TargetLoweringBase *TLI = getTLI();
std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(RetTy); std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(RetTy);
if (TLI->isOperationLegalOrPromote(ISD, LT.second)) { if (TLI->isOperationLegalOrPromote(ISD, LT.second)) {
@ -476,7 +483,7 @@ unsigned BasicTTI::getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy,
} }
unsigned BasicTTI::getNumberOfParts(Type *Tp) const { unsigned BasicTTI::getNumberOfParts(Type *Tp) const {
std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(Tp); std::pair<unsigned, MVT> LT = getTLI()->getTypeLegalizationCost(Tp);
return LT.first; return LT.first;
} }

View File

@ -32,7 +32,7 @@ STATISTIC(NumResumesLowered, "Number of resume calls lowered");
namespace { namespace {
class DwarfEHPrepare : public FunctionPass { class DwarfEHPrepare : public FunctionPass {
const TargetLoweringBase *TLI; const TargetMachine *TM;
// RewindFunction - _Unwind_Resume or the target equivalent. // RewindFunction - _Unwind_Resume or the target equivalent.
Constant *RewindFunction; Constant *RewindFunction;
@ -42,8 +42,8 @@ namespace {
public: public:
static char ID; // Pass identification, replacement for typeid. static char ID; // Pass identification, replacement for typeid.
DwarfEHPrepare(const TargetLoweringBase *TLI) : DwarfEHPrepare(const TargetMachine *TM) :
FunctionPass(ID), TLI(TLI), RewindFunction(0) { FunctionPass(ID), TM(TM), RewindFunction(0) {
initializeDominatorTreePass(*PassRegistry::getPassRegistry()); initializeDominatorTreePass(*PassRegistry::getPassRegistry());
} }
@ -59,8 +59,8 @@ namespace {
char DwarfEHPrepare::ID = 0; char DwarfEHPrepare::ID = 0;
FunctionPass *llvm::createDwarfEHPass(const TargetLoweringBase *TLI) { FunctionPass *llvm::createDwarfEHPass(const TargetMachine *TM) {
return new DwarfEHPrepare(TLI); return new DwarfEHPrepare(TM);
} }
/// GetExceptionObject - Return the exception object from the value passed into /// GetExceptionObject - Return the exception object from the value passed into
@ -117,6 +117,7 @@ bool DwarfEHPrepare::InsertUnwindResumeCalls(Function &Fn) {
return false; return false;
// Find the rewind function if we didn't already. // Find the rewind function if we didn't already.
const TargetLowering *TLI = TM->getTargetLowering();
if (!RewindFunction) { if (!RewindFunction) {
LLVMContext &Ctx = Resumes[0]->getContext(); LLVMContext &Ctx = Resumes[0]->getContext();
FunctionType *FTy = FunctionType::get(Type::getVoidTy(Ctx), FunctionType *FTy = FunctionType::get(Type::getVoidTy(Ctx),

View File

@ -83,7 +83,7 @@ LLVMTargetMachine::LLVMTargetMachine(const Target &T, StringRef Triple,
} }
void LLVMTargetMachine::addAnalysisPasses(PassManagerBase &PM) { void LLVMTargetMachine::addAnalysisPasses(PassManagerBase &PM) {
PM.add(createBasicTargetTransformInfoPass(getTargetLowering())); PM.add(createBasicTargetTransformInfoPass(this));
} }
/// addPassesToX helper drives creation and initialization of TargetPassConfig. /// addPassesToX helper drives creation and initialization of TargetPassConfig.
@ -115,7 +115,6 @@ static MCContext *addPassesToGenerateCode(LLVMTargetMachine *TM,
new MachineModuleInfo(*TM->getMCAsmInfo(), *TM->getRegisterInfo(), new MachineModuleInfo(*TM->getMCAsmInfo(), *TM->getRegisterInfo(),
&TM->getTargetLowering()->getObjFileLowering()); &TM->getTargetLowering()->getObjFileLowering());
PM.add(MMI); PM.add(MMI);
MCContext *Context = &MMI->getContext(); // Return the MCContext by-ref.
// Set up a MachineFunction for the rest of CodeGen to work on. // Set up a MachineFunction for the rest of CodeGen to work on.
PM.add(new MachineFunctionAnalysis(*TM)); PM.add(new MachineFunctionAnalysis(*TM));
@ -134,7 +133,7 @@ static MCContext *addPassesToGenerateCode(LLVMTargetMachine *TM,
PassConfig->setInitialized(); PassConfig->setInitialized();
return Context; return &MMI->getContext();
} }
bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM, bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,

View File

@ -396,12 +396,12 @@ void TargetPassConfig::addPassesToHandleExceptions() {
// removed from the parent invoke(s). This could happen when a landing // removed from the parent invoke(s). This could happen when a landing
// pad is shared by multiple invokes and is also a target of a normal // pad is shared by multiple invokes and is also a target of a normal
// edge from elsewhere. // edge from elsewhere.
addPass(createSjLjEHPreparePass(TM->getTargetLowering())); addPass(createSjLjEHPreparePass(TM));
// FALLTHROUGH // FALLTHROUGH
case ExceptionHandling::DwarfCFI: case ExceptionHandling::DwarfCFI:
case ExceptionHandling::ARM: case ExceptionHandling::ARM:
case ExceptionHandling::Win64: case ExceptionHandling::Win64:
addPass(createDwarfEHPass(TM->getTargetLowering())); addPass(createDwarfEHPass(TM));
break; break;
case ExceptionHandling::None: case ExceptionHandling::None:
addPass(createLowerInvokePass(TM->getTargetLowering())); addPass(createLowerInvokePass(TM->getTargetLowering()));
@ -422,7 +422,7 @@ void TargetPassConfig::addCodeGenPrepare() {
/// Add common passes that perform LLVM IR to IR transforms in preparation for /// Add common passes that perform LLVM IR to IR transforms in preparation for
/// instruction selection. /// instruction selection.
void TargetPassConfig::addISelPrepare() { void TargetPassConfig::addISelPrepare() {
addPass(createStackProtectorPass(getTargetLowering())); addPass(createStackProtectorPass(TM));
addPreISel(); addPreISel();

View File

@ -43,7 +43,7 @@ STATISTIC(NumSpilled, "Number of registers live across unwind edges");
namespace { namespace {
class SjLjEHPrepare : public FunctionPass { class SjLjEHPrepare : public FunctionPass {
const TargetLoweringBase *TLI; const TargetMachine *TM;
Type *FunctionContextTy; Type *FunctionContextTy;
Constant *RegisterFn; Constant *RegisterFn;
Constant *UnregisterFn; Constant *UnregisterFn;
@ -58,8 +58,8 @@ namespace {
AllocaInst *FuncCtx; AllocaInst *FuncCtx;
public: public:
static char ID; // Pass identification, replacement for typeid static char ID; // Pass identification, replacement for typeid
explicit SjLjEHPrepare(const TargetLoweringBase *tli = NULL) explicit SjLjEHPrepare(const TargetMachine *TM)
: FunctionPass(ID), TLI(tli) { } : FunctionPass(ID), TM(TM) { }
bool doInitialization(Module &M); bool doInitialization(Module &M);
bool runOnFunction(Function &F); bool runOnFunction(Function &F);
@ -82,8 +82,8 @@ namespace {
char SjLjEHPrepare::ID = 0; char SjLjEHPrepare::ID = 0;
// Public Interface To the SjLjEHPrepare pass. // Public Interface To the SjLjEHPrepare pass.
FunctionPass *llvm::createSjLjEHPreparePass(const TargetLoweringBase *TLI) { FunctionPass *llvm::createSjLjEHPreparePass(const TargetMachine *TM) {
return new SjLjEHPrepare(TLI); return new SjLjEHPrepare(TM);
} }
// doInitialization - Set up decalarations and types needed to process // doInitialization - Set up decalarations and types needed to process
// exceptions. // exceptions.
@ -190,6 +190,7 @@ setupFunctionContext(Function &F, ArrayRef<LandingPadInst*> LPads) {
// Create an alloca for the incoming jump buffer ptr and the new jump buffer // Create an alloca for the incoming jump buffer ptr and the new jump buffer
// that needs to be restored on all exits from the function. This is an alloca // that needs to be restored on all exits from the function. This is an alloca
// because the value needs to be added to the global context list. // because the value needs to be added to the global context list.
const TargetLowering *TLI = TM->getTargetLowering();
unsigned Align = unsigned Align =
TLI->getDataLayout()->getPrefTypeAlignment(FunctionContextTy); TLI->getDataLayout()->getPrefTypeAlignment(FunctionContextTy);
FuncCtx = FuncCtx =

View File

@ -41,9 +41,11 @@ STATISTIC(NumAddrTaken, "Number of local variables that have their address"
namespace { namespace {
class StackProtector : public FunctionPass { class StackProtector : public FunctionPass {
const TargetMachine *TM;
/// TLI - Keep a pointer of a TargetLowering to consult for determining /// TLI - Keep a pointer of a TargetLowering to consult for determining
/// target type sizes. /// target type sizes.
const TargetLoweringBase *const TLI; const TargetLoweringBase *TLI;
const Triple Trip; const Triple Trip;
Function *F; Function *F;
@ -83,12 +85,11 @@ namespace {
bool RequiresStackProtector(); bool RequiresStackProtector();
public: public:
static char ID; // Pass identification, replacement for typeid. static char ID; // Pass identification, replacement for typeid.
StackProtector() : FunctionPass(ID), TLI(0) { StackProtector() : FunctionPass(ID), TM(0), TLI(0) {
initializeStackProtectorPass(*PassRegistry::getPassRegistry()); initializeStackProtectorPass(*PassRegistry::getPassRegistry());
} }
StackProtector(const TargetLoweringBase *tli) StackProtector(const TargetMachine *TM)
: FunctionPass(ID), TLI(tli), : FunctionPass(ID), TM(TM), TLI(0), Trip(TM->getTargetTriple()) {
Trip(tli->getTargetMachine().getTargetTriple()) {
initializeStackProtectorPass(*PassRegistry::getPassRegistry()); initializeStackProtectorPass(*PassRegistry::getPassRegistry());
} }
@ -104,14 +105,15 @@ char StackProtector::ID = 0;
INITIALIZE_PASS(StackProtector, "stack-protector", INITIALIZE_PASS(StackProtector, "stack-protector",
"Insert stack protectors", false, false) "Insert stack protectors", false, false)
FunctionPass *llvm::createStackProtectorPass(const TargetLoweringBase *tli) { FunctionPass *llvm::createStackProtectorPass(const TargetMachine *TM) {
return new StackProtector(tli); return new StackProtector(TM);
} }
bool StackProtector::runOnFunction(Function &Fn) { bool StackProtector::runOnFunction(Function &Fn) {
F = &Fn; F = &Fn;
M = F->getParent(); M = F->getParent();
DT = getAnalysisIfAvailable<DominatorTree>(); DT = getAnalysisIfAvailable<DominatorTree>();
TLI = TM->getTargetLowering();
if (!RequiresStackProtector()) return false; if (!RequiresStackProtector()) return false;

View File

@ -60,7 +60,7 @@ void ARMBaseTargetMachine::addAnalysisPasses(PassManagerBase &PM) {
// Add first the target-independent BasicTTI pass, then our ARM pass. This // Add first the target-independent BasicTTI pass, then our ARM pass. This
// allows the ARM pass to delegate to the target independent layer when // allows the ARM pass to delegate to the target independent layer when
// appropriate. // appropriate.
PM.add(createBasicTargetTransformInfoPass(getTargetLowering())); PM.add(createBasicTargetTransformInfoPass(this));
PM.add(createARMTargetTransformInfoPass(this)); PM.add(createARMTargetTransformInfoPass(this));
} }

View File

@ -162,7 +162,7 @@ void PPCTargetMachine::addAnalysisPasses(PassManagerBase &PM) {
// Add first the target-independent BasicTTI pass, then our PPC pass. This // Add first the target-independent BasicTTI pass, then our PPC pass. This
// allows the PPC pass to delegate to the target independent layer when // allows the PPC pass to delegate to the target independent layer when
// appropriate. // appropriate.
PM.add(createBasicTargetTransformInfoPass(getTargetLowering())); PM.add(createBasicTargetTransformInfoPass(this));
PM.add(createPPCTargetTransformInfoPass(this)); PM.add(createPPCTargetTransformInfoPass(this));
} }

View File

@ -132,7 +132,7 @@ void X86TargetMachine::addAnalysisPasses(PassManagerBase &PM) {
// Add first the target-independent BasicTTI pass, then our X86 pass. This // Add first the target-independent BasicTTI pass, then our X86 pass. This
// allows the X86 pass to delegate to the target independent layer when // allows the X86 pass to delegate to the target independent layer when
// appropriate. // appropriate.
PM.add(createBasicTargetTransformInfoPass(getTargetLowering())); PM.add(createBasicTargetTransformInfoPass(this));
PM.add(createX86TargetTransformInfoPass(this)); PM.add(createX86TargetTransformInfoPass(this));
} }