llvm.org GIT mirror llvm / ac0c6d3
[MachineFunction] Introduce a reset method. This method allows to reset the state of a MachineFunction as if it was just created. This will be used during the bring-up of GlobalISel to provide a way to fallback on SelectionDAG. That way, we can start doing correctness testing even if we are not able to select all functions via the global instruction selector. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279876 91177308-0d34-0410-b5e6-96231b3b80d8 Quentin Colombet 4 years ago
2 changed file(s) with 31 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
237237
238238 MachineFunction(const MachineFunction &) = delete;
239239 void operator=(const MachineFunction&) = delete;
240
241 /// Clear all the members of this MachineFunction, but the ones used
242 /// to initialize again the MachineFunction.
243 /// More specifically, this deallocates all the dynamically allocated
244 /// objects and get rid of all the XXXInfo data structure, but keep
245 /// unchanged the references to Fn, Target, MMI, and FunctionNumber.
246 void clear();
247 /// Allocate and initialize the different members.
248 /// In particular, the XXXInfo data structure.
249 /// \pre Fn, Target, MMI, and FunctionNumber are properly set.
250 void init();
240251 public:
241252 MachineFunction(const Function *Fn, const TargetMachine &TM,
242253 unsigned FunctionNum, MachineModuleInfo &MMI);
243254 ~MachineFunction();
255
256 /// Reset the instance as if it was just created.
257 void reset() {
258 clear();
259 init();
260 }
244261
245262 MachineModuleInfo &getMMI() const { return MMI; }
246263 MCContext &getContext() const { return Ctx; }
9999 unsigned FunctionNum, MachineModuleInfo &mmi)
100100 : Fn(F), Target(TM), STI(TM.getSubtargetImpl(*F)), Ctx(mmi.getContext()),
101101 MMI(mmi) {
102 FunctionNumber = FunctionNum;
103 init();
104 }
105
106 void MachineFunction::init() {
102107 // Assume the function starts in SSA form with correct liveness.
103108 Properties.set(MachineFunctionProperties::Property::IsSSA);
104109 Properties.set(MachineFunctionProperties::Property::TracksLiveness);
111116 // We can realign the stack if the target supports it and the user hasn't
112117 // explicitly asked us not to.
113118 bool CanRealignSP = STI->getFrameLowering()->isStackRealignable() &&
114 !F->hasFnAttribute("no-realign-stack");
119 !Fn->hasFnAttribute("no-realign-stack");
115120 FrameInfo = new (Allocator) MachineFrameInfo(
116121 getFnStackAlignment(STI, Fn), /*StackRealignable=*/CanRealignSP,
117122 /*ForceRealign=*/CanRealignSP &&
118 F->hasFnAttribute(Attribute::StackAlignment));
123 Fn->hasFnAttribute(Attribute::StackAlignment));
119124
120125 if (Fn->hasFnAttribute(Attribute::StackAlignment))
121126 FrameInfo->ensureMaxAlignment(Fn->getFnStackAlignment());
132137 if (AlignAllFunctions)
133138 Alignment = AlignAllFunctions;
134139
135 FunctionNumber = FunctionNum;
136140 JumpTableInfo = nullptr;
137141
138142 if (isFuncletEHPersonality(classifyEHPersonality(
139 F->hasPersonalityFn() ? F->getPersonalityFn() : nullptr))) {
143 Fn->hasPersonalityFn() ? Fn->getPersonalityFn() : nullptr))) {
140144 WinEHInfo = new (Allocator) WinEHFuncInfo();
141145 }
142146
143 assert(TM.isCompatibleDataLayout(getDataLayout()) &&
147 assert(Target.isCompatibleDataLayout(getDataLayout()) &&
144148 "Can't create a MachineFunction using a Module with a "
145149 "Target-incompatible DataLayout attached\n");
146150
148152 }
149153
150154 MachineFunction::~MachineFunction() {
155 clear();
156 }
157
158 void MachineFunction::clear() {
159 Properties.reset();
151160 // Don't call destructors on MachineInstr and MachineOperand. All of their
152161 // memory comes from the BumpPtrAllocator which is about to be purged.
153162 //