Index: include/llvm/CodeGen/Passes.h =================================================================== --- include/llvm/CodeGen/Passes.h +++ include/llvm/CodeGen/Passes.h @@ -143,6 +143,7 @@ /// VirtRegRewriter pass. Rewrite virtual registers to physical registers as /// assigned in VirtRegMap. extern char &VirtRegRewriterID; + FunctionPass *createVirtRegRewriter(bool ClearVirtRegs = true); /// UnreachableMachineBlockElimination - This pass removes unreachable /// machine basic blocks. Index: lib/CodeGen/VirtRegMap.cpp =================================================================== --- lib/CodeGen/VirtRegMap.cpp +++ lib/CodeGen/VirtRegMap.cpp @@ -182,6 +182,7 @@ SlotIndexes *Indexes; LiveIntervals *LIS; VirtRegMap *VRM; + bool ClearVirtRegs; void rewrite(); void addMBBLiveIns(); @@ -193,16 +194,21 @@ public: static char ID; - - VirtRegRewriter() : MachineFunctionPass(ID) {} + VirtRegRewriter(bool ClearVirtRegs_ = true) : + MachineFunctionPass(ID), + ClearVirtRegs(ClearVirtRegs_) {} void getAnalysisUsage(AnalysisUsage &AU) const override; bool runOnMachineFunction(MachineFunction&) override; MachineFunctionProperties getSetProperties() const override { - return MachineFunctionProperties().set( + if (ClearVirtRegs) { + return MachineFunctionProperties().set( MachineFunctionProperties::Property::NoVRegs); + } + + return MachineFunctionProperties(); } }; @@ -258,10 +264,13 @@ // Write out new DBG_VALUE instructions. getAnalysis().emitDebugValues(VRM); - // All machine operands and other references to virtual registers have been - // replaced. Remove the virtual registers and release all the transient data. - VRM->clearAllVirt(); - MRI->clearVirtRegs(); + if (ClearVirtRegs) { + // All machine operands and other references to virtual registers have been + // replaced. Remove the virtual registers and release all the transient data. + VRM->clearAllVirt(); + MRI->clearVirtRegs(); + } + return true; } @@ -592,3 +601,7 @@ } } } + +FunctionPass *llvm::createVirtRegRewriter(bool ClearVirtRegs) { + return new VirtRegRewriter(ClearVirtRegs); +}