Don't cache the TargetLoweringInfo object inside of the FunctionLowering object.

The TargetLoweringInfo object is owned by the TargetMachine. In the future, the
TargetMachine object may change, which may also change the TargetLoweringInfo
object.

llvm-svn: 183356
This commit is contained in:
Bill Wendling 2013-06-06 00:11:39 +00:00
parent 30aa6b6243
commit 8db01cb262
3 changed files with 22 additions and 20 deletions

View File

@ -49,8 +49,9 @@ class Value;
/// function that is used when lowering a region of the function. /// function that is used when lowering a region of the function.
/// ///
class FunctionLoweringInfo { class FunctionLoweringInfo {
const TargetMachine &TM;
const TargetLowering *TLI;
public: public:
const TargetLowering &TLI;
const Function *Fn; const Function *Fn;
MachineFunction *MF; MachineFunction *MF;
MachineRegisterInfo *RegInfo; MachineRegisterInfo *RegInfo;
@ -115,7 +116,7 @@ public:
/// there's no other convenient place for it to live right now. /// there's no other convenient place for it to live right now.
std::vector<std::pair<MachineInstr*, unsigned> > PHINodesToUpdate; std::vector<std::pair<MachineInstr*, unsigned> > PHINodesToUpdate;
explicit FunctionLoweringInfo(const TargetLowering &TLI); explicit FunctionLoweringInfo(const TargetMachine &TM);
/// set - Initialize this FunctionLoweringInfo with the given Function /// set - Initialize this FunctionLoweringInfo with the given Function
/// and its associated MachineFunction. /// and its associated MachineFunction.

View File

@ -55,21 +55,22 @@ static bool isUsedOutsideOfDefiningBlock(const Instruction *I) {
return false; return false;
} }
FunctionLoweringInfo::FunctionLoweringInfo(const TargetLowering &tli) FunctionLoweringInfo::FunctionLoweringInfo(const TargetMachine &TM)
: TLI(tli) { : TM(TM), TLI(0) {
} }
void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf) { void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf) {
Fn = &fn; Fn = &fn;
MF = &mf; MF = &mf;
RegInfo = &MF->getRegInfo(); RegInfo = &MF->getRegInfo();
TLI = TM.getTargetLowering();
// Check whether the function can return without sret-demotion. // Check whether the function can return without sret-demotion.
SmallVector<ISD::OutputArg, 4> Outs; SmallVector<ISD::OutputArg, 4> Outs;
GetReturnInfo(Fn->getReturnType(), Fn->getAttributes(), Outs, TLI); GetReturnInfo(Fn->getReturnType(), Fn->getAttributes(), Outs, *TLI);
CanLowerReturn = TLI.CanLowerReturn(Fn->getCallingConv(), *MF, CanLowerReturn = TLI->CanLowerReturn(Fn->getCallingConv(), *MF,
Fn->isVarArg(), Fn->isVarArg(),
Outs, Fn->getContext()); Outs, Fn->getContext());
// Initialize the mapping of values to registers. This is only set up for // Initialize the mapping of values to registers. This is only set up for
// instruction values that are used outside of the block that defines // instruction values that are used outside of the block that defines
@ -79,9 +80,9 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf) {
if (const AllocaInst *AI = dyn_cast<AllocaInst>(I)) if (const AllocaInst *AI = dyn_cast<AllocaInst>(I))
if (const ConstantInt *CUI = dyn_cast<ConstantInt>(AI->getArraySize())) { if (const ConstantInt *CUI = dyn_cast<ConstantInt>(AI->getArraySize())) {
Type *Ty = AI->getAllocatedType(); Type *Ty = AI->getAllocatedType();
uint64_t TySize = TLI.getDataLayout()->getTypeAllocSize(Ty); uint64_t TySize = TLI->getDataLayout()->getTypeAllocSize(Ty);
unsigned Align = unsigned Align =
std::max((unsigned)TLI.getDataLayout()->getPrefTypeAlignment(Ty), std::max((unsigned)TLI->getDataLayout()->getPrefTypeAlignment(Ty),
AI->getAlignment()); AI->getAlignment());
TySize *= CUI->getZExtValue(); // Get total allocated size. TySize *= CUI->getZExtValue(); // Get total allocated size.
@ -167,10 +168,10 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf) {
assert(PHIReg && "PHI node does not have an assigned virtual register!"); assert(PHIReg && "PHI node does not have an assigned virtual register!");
SmallVector<EVT, 4> ValueVTs; SmallVector<EVT, 4> ValueVTs;
ComputeValueVTs(TLI, PN->getType(), ValueVTs); ComputeValueVTs(*TLI, PN->getType(), ValueVTs);
for (unsigned vti = 0, vte = ValueVTs.size(); vti != vte; ++vti) { for (unsigned vti = 0, vte = ValueVTs.size(); vti != vte; ++vti) {
EVT VT = ValueVTs[vti]; EVT VT = ValueVTs[vti];
unsigned NumRegisters = TLI.getNumRegisters(Fn->getContext(), VT); unsigned NumRegisters = TLI->getNumRegisters(Fn->getContext(), VT);
const TargetInstrInfo *TII = MF->getTarget().getInstrInfo(); const TargetInstrInfo *TII = MF->getTarget().getInstrInfo();
for (unsigned i = 0; i != NumRegisters; ++i) for (unsigned i = 0; i != NumRegisters; ++i)
BuildMI(MBB, DL, TII->get(TargetOpcode::PHI), PHIReg + i); BuildMI(MBB, DL, TII->get(TargetOpcode::PHI), PHIReg + i);
@ -208,7 +209,7 @@ void FunctionLoweringInfo::clear() {
/// CreateReg - Allocate a single virtual register for the given type. /// CreateReg - Allocate a single virtual register for the given type.
unsigned FunctionLoweringInfo::CreateReg(MVT VT) { unsigned FunctionLoweringInfo::CreateReg(MVT VT) {
return RegInfo->createVirtualRegister(TLI.getRegClassFor(VT)); return RegInfo->createVirtualRegister(TLI->getRegClassFor(VT));
} }
/// CreateRegs - Allocate the appropriate number of virtual registers of /// CreateRegs - Allocate the appropriate number of virtual registers of
@ -220,14 +221,14 @@ unsigned FunctionLoweringInfo::CreateReg(MVT VT) {
/// ///
unsigned FunctionLoweringInfo::CreateRegs(Type *Ty) { unsigned FunctionLoweringInfo::CreateRegs(Type *Ty) {
SmallVector<EVT, 4> ValueVTs; SmallVector<EVT, 4> ValueVTs;
ComputeValueVTs(TLI, Ty, ValueVTs); ComputeValueVTs(*TLI, Ty, ValueVTs);
unsigned FirstReg = 0; unsigned FirstReg = 0;
for (unsigned Value = 0, e = ValueVTs.size(); Value != e; ++Value) { for (unsigned Value = 0, e = ValueVTs.size(); Value != e; ++Value) {
EVT ValueVT = ValueVTs[Value]; EVT ValueVT = ValueVTs[Value];
MVT RegisterVT = TLI.getRegisterType(Ty->getContext(), ValueVT); MVT RegisterVT = TLI->getRegisterType(Ty->getContext(), ValueVT);
unsigned NumRegs = TLI.getNumRegisters(Ty->getContext(), ValueVT); unsigned NumRegs = TLI->getNumRegisters(Ty->getContext(), ValueVT);
for (unsigned i = 0; i != NumRegs; ++i) { for (unsigned i = 0; i != NumRegs; ++i) {
unsigned R = CreateReg(RegisterVT); unsigned R = CreateReg(RegisterVT);
if (!FirstReg) FirstReg = R; if (!FirstReg) FirstReg = R;
@ -267,14 +268,14 @@ void FunctionLoweringInfo::ComputePHILiveOutRegInfo(const PHINode *PN) {
return; return;
SmallVector<EVT, 1> ValueVTs; SmallVector<EVT, 1> ValueVTs;
ComputeValueVTs(TLI, Ty, ValueVTs); ComputeValueVTs(*TLI, Ty, ValueVTs);
assert(ValueVTs.size() == 1 && assert(ValueVTs.size() == 1 &&
"PHIs with non-vector integer types should have a single VT."); "PHIs with non-vector integer types should have a single VT.");
EVT IntVT = ValueVTs[0]; EVT IntVT = ValueVTs[0];
if (TLI.getNumRegisters(PN->getContext(), IntVT) != 1) if (TLI->getNumRegisters(PN->getContext(), IntVT) != 1)
return; return;
IntVT = TLI.getTypeToTransformTo(PN->getContext(), IntVT); IntVT = TLI->getTypeToTransformTo(PN->getContext(), IntVT);
unsigned BitWidth = IntVT.getSizeInBits(); unsigned BitWidth = IntVT.getSizeInBits();
unsigned DestReg = ValueMap[PN]; unsigned DestReg = ValueMap[PN];

View File

@ -278,7 +278,7 @@ void TargetLowering::AdjustInstrPostInstrSelection(MachineInstr *MI,
SelectionDAGISel::SelectionDAGISel(const TargetMachine &tm, SelectionDAGISel::SelectionDAGISel(const TargetMachine &tm,
CodeGenOpt::Level OL) : CodeGenOpt::Level OL) :
MachineFunctionPass(ID), TM(tm), TLI(*tm.getTargetLowering()), MachineFunctionPass(ID), TM(tm), TLI(*tm.getTargetLowering()),
FuncInfo(new FunctionLoweringInfo(TLI)), FuncInfo(new FunctionLoweringInfo(TM)),
CurDAG(new SelectionDAG(tm, OL)), CurDAG(new SelectionDAG(tm, OL)),
SDB(new SelectionDAGBuilder(*CurDAG, *FuncInfo, OL)), SDB(new SelectionDAGBuilder(*CurDAG, *FuncInfo, OL)),
GFI(), GFI(),