git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184349
91177308-0d34-0410-b5e6-
96231b3b80d8
/// This pass implements the target transform info analysis using the target
/// independent information available to the LLVM code generator.
ImmutablePass *
/// This pass implements the target transform info analysis using the target
/// independent information available to the LLVM code generator.
ImmutablePass *
- createBasicTargetTransformInfoPass(const TargetLoweringBase *TLI);
+ createBasicTargetTransformInfoPass(const TargetMachine *TLI);
/// createUnreachableBlockEliminationPass - The LLVM code generator does not
/// work well with unreachable basic blocks (what live ranges make sense for a
/// createUnreachableBlockEliminationPass - The LLVM code generator does not
/// work well with unreachable basic blocks (what live ranges make sense for a
/// 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
/// instructions for correctness.
/// createMachineVerifierPass - This pass verifies cenerated machine code
/// instructions for correctness.
/// createDwarfEHPass - This pass mulches exception handling code into a form
/// adapted to code generation. Required if using dwarf exception handling.
/// createDwarfEHPass - This pass mulches exception handling code into a form
/// 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
/// the GCC-style builtin setjmp/longjmp (sjlj) to handling EH control flow.
///
/// createSjLjEHPreparePass - This pass adapts exception handling code to use
/// 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
/// slots relative to one another and allocates base registers to access them
/// LocalStackSlotAllocation - This pass assigns local frame indices to stack
/// slots relative to one another and allocates base registers to access them
namespace {
class BasicTTI : public ImmutablePass, public TargetTransformInfo {
namespace {
class BasicTTI : public ImmutablePass, public TargetTransformInfo {
- const TargetLoweringBase *TLI;
+ const TargetMachine *TM;
/// Estimate the overhead of scalarizing an instruction. Insert and Extract
/// are set if the result needs to be inserted and/or extracted from vectors.
unsigned getScalarizationOverhead(Type *Ty, bool Insert, bool Extract) const;
/// Estimate the overhead of scalarizing an instruction. Insert and Extract
/// are set if the result needs to be inserted and/or extracted from vectors.
unsigned getScalarizationOverhead(Type *Ty, bool Insert, bool Extract) const;
+ const TargetLoweringBase *getTLI() const { return TM->getTargetLowering(); }
+
- 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());
}
char BasicTTI::ID = 0;
ImmutablePass *
char BasicTTI::ID = 0;
ImmutablePass *
-llvm::createBasicTargetTransformInfoPass(const TargetLoweringBase *TLI) {
- return new BasicTTI(TLI);
+llvm::createBasicTargetTransformInfoPass(const TargetMachine *TM) {
+ 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,
AM.BaseOffs = BaseOffset;
AM.HasBaseReg = HasBaseReg;
AM.Scale = Scale;
AM.BaseOffs = BaseOffset;
AM.HasBaseReg = HasBaseReg;
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,
AM.BaseOffs = BaseOffset;
AM.HasBaseReg = HasBaseReg;
AM.Scale = Scale;
AM.BaseOffs = BaseOffset;
AM.HasBaseReg = HasBaseReg;
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);
- return TLI->isTypeLegal(T);
+ EVT T = getTLI()->getValueType(Ty);
+ 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() &&
(TLI->isOperationLegalOrCustom(ISD::BR_JT, MVT::Other) ||
TLI->isOperationLegalOrCustom(ISD::BRIND, MVT::Other));
return TLI->supportJumpTables() &&
(TLI->isOperationLegalOrCustom(ISD::BR_JT, MVT::Other) ||
TLI->isOperationLegalOrCustom(ISD::BRIND, MVT::Other));
OperandValueKind,
OperandValueKind) const {
// Check if any of the operands are vector operands.
OperandValueKind,
OperandValueKind) const {
// Check if any of the operands are vector operands.
+ const TargetLoweringBase *TLI = getTLI();
int ISD = TLI->InstructionOpcodeToISD(Opcode);
assert(ISD && "Invalid opcode");
int ISD = TLI->InstructionOpcodeToISD(Opcode);
assert(ISD && "Invalid opcode");
unsigned BasicTTI::getCastInstrCost(unsigned Opcode, Type *Dst,
Type *Src) const {
unsigned BasicTTI::getCastInstrCost(unsigned Opcode, Type *Dst,
Type *Src) const {
+ const TargetLoweringBase *TLI = getTLI();
int ISD = TLI->InstructionOpcodeToISD(Opcode);
assert(ISD && "Invalid opcode");
int ISD = TLI->InstructionOpcodeToISD(Opcode);
assert(ISD && "Invalid opcode");
unsigned BasicTTI::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
Type *CondTy) const {
unsigned BasicTTI::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
Type *CondTy) const {
+ const TargetLoweringBase *TLI = getTLI();
int ISD = TLI->InstructionOpcodeToISD(Opcode);
assert(ISD && "Invalid opcode");
int ISD = TLI->InstructionOpcodeToISD(Opcode);
assert(ISD && "Invalid opcode");
unsigned Alignment,
unsigned AddressSpace) const {
assert(!Src->isVoidTy() && "Invalid type");
unsigned Alignment,
unsigned AddressSpace) const {
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.
return LT.first;
// Assume that all loads of legal types cost 1.
return LT.first;
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);
if (TLI->isOperationLegalOrPromote(ISD, LT.second)) {
std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(RetTy);
if (TLI->isOperationLegalOrPromote(ISD, LT.second)) {
}
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);
namespace {
class DwarfEHPrepare : public FunctionPass {
namespace {
class DwarfEHPrepare : public FunctionPass {
- const TargetLoweringBase *TLI;
+ const TargetMachine *TM;
// RewindFunction - _Unwind_Resume or the target equivalent.
Constant *RewindFunction;
// RewindFunction - _Unwind_Resume or the target equivalent.
Constant *RewindFunction;
public:
static char ID; // Pass identification, replacement for typeid.
public:
static char ID; // Pass identification, replacement for typeid.
- DwarfEHPrepare(const TargetLoweringBase *TLI) :
- FunctionPass(ID), TLI(TLI), RewindFunction(0) {
+ DwarfEHPrepare(const TargetMachine *TM) :
+ FunctionPass(ID), TM(TM), RewindFunction(0) {
initializeDominatorTreePass(*PassRegistry::getPassRegistry());
}
initializeDominatorTreePass(*PassRegistry::getPassRegistry());
}
char DwarfEHPrepare::ID = 0;
char DwarfEHPrepare::ID = 0;
-FunctionPass *llvm::createDwarfEHPass(const TargetLoweringBase *TLI) {
- return new DwarfEHPrepare(TLI);
+FunctionPass *llvm::createDwarfEHPass(const TargetMachine *TM) {
+ return new DwarfEHPrepare(TM);
}
/// GetExceptionObject - Return the exception object from the value passed into
}
/// GetExceptionObject - Return the exception object from the value passed into
return false;
// Find the rewind function if we didn't already.
return false;
// Find the rewind function if we didn't already.
+ const TargetLowering *TLI = TM->getTargetLowering();
if (!RewindFunction) {
LLVMContext &Ctx = Resumes[0]->getContext();
FunctionType *FTy = FunctionType::get(Type::getVoidTy(Ctx),
if (!RewindFunction) {
LLVMContext &Ctx = Resumes[0]->getContext();
FunctionType *FTy = FunctionType::get(Type::getVoidTy(Ctx),
}
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.
new MachineModuleInfo(*TM->getMCAsmInfo(), *TM->getRegisterInfo(),
&TM->getTargetLowering()->getObjFileLowering());
PM.add(MMI);
new MachineModuleInfo(*TM->getMCAsmInfo(), *TM->getRegisterInfo(),
&TM->getTargetLowering()->getObjFileLowering());
PM.add(MMI);
- MCContext *Context = &MMI->getContext(); // Return the MCContext by-ref.
// Set up a MachineFunction for the rest of CodeGen to work on.
PM.add(new MachineFunctionAnalysis(*TM));
// Set up a MachineFunction for the rest of CodeGen to work on.
PM.add(new MachineFunctionAnalysis(*TM));
PassConfig->setInitialized();
PassConfig->setInitialized();
+ return &MMI->getContext();
}
bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
}
bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
// 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
// edge from elsewhere.
// 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
// edge from elsewhere.
- addPass(createSjLjEHPreparePass(TM->getTargetLowering()));
+ addPass(createSjLjEHPreparePass(TM));
// FALLTHROUGH
case ExceptionHandling::DwarfCFI:
case ExceptionHandling::ARM:
case ExceptionHandling::Win64:
// FALLTHROUGH
case ExceptionHandling::DwarfCFI:
case ExceptionHandling::ARM:
case ExceptionHandling::Win64:
- addPass(createDwarfEHPass(TM->getTargetLowering()));
+ addPass(createDwarfEHPass(TM));
break;
case ExceptionHandling::None:
addPass(createLowerInvokePass(TM->getTargetLowering()));
break;
case ExceptionHandling::None:
addPass(createLowerInvokePass(TM->getTargetLowering()));
/// Add common passes that perform LLVM IR to IR transforms in preparation for
/// instruction selection.
void TargetPassConfig::addISelPrepare() {
/// Add common passes that perform LLVM IR to IR transforms in preparation for
/// instruction selection.
void TargetPassConfig::addISelPrepare() {
- addPass(createStackProtectorPass(getTargetLowering()));
+ addPass(createStackProtectorPass(TM));
namespace {
class SjLjEHPrepare : public FunctionPass {
namespace {
class SjLjEHPrepare : public FunctionPass {
- const TargetLoweringBase *TLI;
+ const TargetMachine *TM;
Type *FunctionContextTy;
Constant *RegisterFn;
Constant *UnregisterFn;
Type *FunctionContextTy;
Constant *RegisterFn;
Constant *UnregisterFn;
AllocaInst *FuncCtx;
public:
static char ID; // Pass identification, replacement for typeid
AllocaInst *FuncCtx;
public:
static char ID; // Pass identification, replacement for typeid
- explicit SjLjEHPrepare(const TargetLoweringBase *tli = NULL)
- : FunctionPass(ID), TLI(tli) { }
+ explicit SjLjEHPrepare(const TargetMachine *TM)
+ : FunctionPass(ID), TM(TM) { }
bool doInitialization(Module &M);
bool runOnFunction(Function &F);
bool doInitialization(Module &M);
bool runOnFunction(Function &F);
char SjLjEHPrepare::ID = 0;
// Public Interface To the SjLjEHPrepare pass.
char SjLjEHPrepare::ID = 0;
// Public Interface To the SjLjEHPrepare pass.
-FunctionPass *llvm::createSjLjEHPreparePass(const TargetLoweringBase *TLI) {
- return new SjLjEHPrepare(TLI);
+FunctionPass *llvm::createSjLjEHPreparePass(const TargetMachine *TM) {
+ return new SjLjEHPrepare(TM);
}
// doInitialization - Set up decalarations and types needed to process
// exceptions.
}
// doInitialization - Set up decalarations and types needed to process
// exceptions.
// 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
// because the value needs to be added to the global context list.
// 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
// because the value needs to be added to the global context list.
+ const TargetLowering *TLI = TM->getTargetLowering();
unsigned Align =
TLI->getDataLayout()->getPrefTypeAlignment(FunctionContextTy);
FuncCtx =
unsigned Align =
TLI->getDataLayout()->getPrefTypeAlignment(FunctionContextTy);
FuncCtx =
namespace {
class StackProtector : public FunctionPass {
namespace {
class StackProtector : public FunctionPass {
+ const TargetMachine *TM;
+
/// TLI - Keep a pointer of a TargetLowering to consult for determining
/// target type sizes.
/// TLI - Keep a pointer of a TargetLowering to consult for determining
/// target type sizes.
- const TargetLoweringBase *const TLI;
+ const TargetLoweringBase *TLI;
const Triple Trip;
Function *F;
const Triple Trip;
Function *F;
bool RequiresStackProtector();
public:
static char ID; // Pass identification, replacement for typeid.
bool RequiresStackProtector();
public:
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)
- : FunctionPass(ID), TLI(tli),
- Trip(tli->getTargetMachine().getTargetTriple()) {
+ StackProtector(const TargetMachine *TM)
+ : FunctionPass(ID), TM(TM), TLI(0), Trip(TM->getTargetTriple()) {
initializeStackProtectorPass(*PassRegistry::getPassRegistry());
}
initializeStackProtectorPass(*PassRegistry::getPassRegistry());
}
INITIALIZE_PASS(StackProtector, "stack-protector",
"Insert stack protectors", false, false)
INITIALIZE_PASS(StackProtector, "stack-protector",
"Insert stack protectors", false, false)
-FunctionPass *llvm::createStackProtectorPass(const TargetLoweringBase *tli) {
- return new StackProtector(tli);
+FunctionPass *llvm::createStackProtectorPass(const TargetMachine *TM) {
+ return new StackProtector(TM);
}
bool StackProtector::runOnFunction(Function &Fn) {
F = &Fn;
M = F->getParent();
DT = getAnalysisIfAvailable<DominatorTree>();
}
bool StackProtector::runOnFunction(Function &Fn) {
F = &Fn;
M = F->getParent();
DT = getAnalysisIfAvailable<DominatorTree>();
+ TLI = TM->getTargetLowering();
if (!RequiresStackProtector()) return false;
if (!RequiresStackProtector()) return false;
// Add first the target-independent BasicTTI pass, then our ARM pass. This
// allows the ARM pass to delegate to the target independent layer when
// appropriate.
// Add first the target-independent BasicTTI pass, then our ARM pass. This
// allows the ARM pass to delegate to the target independent layer when
// appropriate.
- PM.add(createBasicTargetTransformInfoPass(getTargetLowering()));
+ PM.add(createBasicTargetTransformInfoPass(this));
PM.add(createARMTargetTransformInfoPass(this));
}
PM.add(createARMTargetTransformInfoPass(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
// appropriate.
// Add first the target-independent BasicTTI pass, then our PPC pass. This
// allows the PPC pass to delegate to the target independent layer when
// appropriate.
- PM.add(createBasicTargetTransformInfoPass(getTargetLowering()));
+ PM.add(createBasicTargetTransformInfoPass(this));
PM.add(createPPCTargetTransformInfoPass(this));
}
PM.add(createPPCTargetTransformInfoPass(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
// appropriate.
// Add first the target-independent BasicTTI pass, then our X86 pass. This
// allows the X86 pass to delegate to the target independent layer when
// appropriate.
- PM.add(createBasicTargetTransformInfoPass(getTargetLowering()));
+ PM.add(createBasicTargetTransformInfoPass(this));
PM.add(createX86TargetTransformInfoPass(this));
}
PM.add(createX86TargetTransformInfoPass(this));
}