[llvm] r279876 - [MachineFunction] Introduce a reset method.
Quentin Colombet via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 26 15:32:53 PDT 2016
Author: qcolombet
Date: Fri Aug 26 17:32:53 2016
New Revision: 279876
URL: http://llvm.org/viewvc/llvm-project?rev=279876&view=rev
Log:
[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.
Modified:
llvm/trunk/include/llvm/CodeGen/MachineFunction.h
llvm/trunk/lib/CodeGen/MachineFunction.cpp
Modified: llvm/trunk/include/llvm/CodeGen/MachineFunction.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineFunction.h?rev=279876&r1=279875&r2=279876&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineFunction.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineFunction.h Fri Aug 26 17:32:53 2016
@@ -238,11 +238,28 @@ class MachineFunction {
MachineFunction(const MachineFunction &) = delete;
void operator=(const MachineFunction&) = delete;
+
+ /// Clear all the members of this MachineFunction, but the ones used
+ /// to initialize again the MachineFunction.
+ /// More specifically, this deallocates all the dynamically allocated
+ /// objects and get rid of all the XXXInfo data structure, but keep
+ /// unchanged the references to Fn, Target, MMI, and FunctionNumber.
+ void clear();
+ /// Allocate and initialize the different members.
+ /// In particular, the XXXInfo data structure.
+ /// \pre Fn, Target, MMI, and FunctionNumber are properly set.
+ void init();
public:
MachineFunction(const Function *Fn, const TargetMachine &TM,
unsigned FunctionNum, MachineModuleInfo &MMI);
~MachineFunction();
+ /// Reset the instance as if it was just created.
+ void reset() {
+ clear();
+ init();
+ }
+
MachineModuleInfo &getMMI() const { return MMI; }
MCContext &getContext() const { return Ctx; }
Modified: llvm/trunk/lib/CodeGen/MachineFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineFunction.cpp?rev=279876&r1=279875&r2=279876&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineFunction.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineFunction.cpp Fri Aug 26 17:32:53 2016
@@ -100,6 +100,11 @@ MachineFunction::MachineFunction(const F
unsigned FunctionNum, MachineModuleInfo &mmi)
: Fn(F), Target(TM), STI(TM.getSubtargetImpl(*F)), Ctx(mmi.getContext()),
MMI(mmi) {
+ FunctionNumber = FunctionNum;
+ init();
+}
+
+void MachineFunction::init() {
// Assume the function starts in SSA form with correct liveness.
Properties.set(MachineFunctionProperties::Property::IsSSA);
Properties.set(MachineFunctionProperties::Property::TracksLiveness);
@@ -112,11 +117,11 @@ MachineFunction::MachineFunction(const F
// We can realign the stack if the target supports it and the user hasn't
// explicitly asked us not to.
bool CanRealignSP = STI->getFrameLowering()->isStackRealignable() &&
- !F->hasFnAttribute("no-realign-stack");
+ !Fn->hasFnAttribute("no-realign-stack");
FrameInfo = new (Allocator) MachineFrameInfo(
getFnStackAlignment(STI, Fn), /*StackRealignable=*/CanRealignSP,
/*ForceRealign=*/CanRealignSP &&
- F->hasFnAttribute(Attribute::StackAlignment));
+ Fn->hasFnAttribute(Attribute::StackAlignment));
if (Fn->hasFnAttribute(Attribute::StackAlignment))
FrameInfo->ensureMaxAlignment(Fn->getFnStackAlignment());
@@ -133,15 +138,14 @@ MachineFunction::MachineFunction(const F
if (AlignAllFunctions)
Alignment = AlignAllFunctions;
- FunctionNumber = FunctionNum;
JumpTableInfo = nullptr;
if (isFuncletEHPersonality(classifyEHPersonality(
- F->hasPersonalityFn() ? F->getPersonalityFn() : nullptr))) {
+ Fn->hasPersonalityFn() ? Fn->getPersonalityFn() : nullptr))) {
WinEHInfo = new (Allocator) WinEHFuncInfo();
}
- assert(TM.isCompatibleDataLayout(getDataLayout()) &&
+ assert(Target.isCompatibleDataLayout(getDataLayout()) &&
"Can't create a MachineFunction using a Module with a "
"Target-incompatible DataLayout attached\n");
@@ -149,6 +153,11 @@ MachineFunction::MachineFunction(const F
}
MachineFunction::~MachineFunction() {
+ clear();
+}
+
+void MachineFunction::clear() {
+ Properties.reset();
// Don't call destructors on MachineInstr and MachineOperand. All of their
// memory comes from the BumpPtrAllocator which is about to be purged.
//
More information about the llvm-commits
mailing list