[patch] Remove the reg2mem pass
Alp Toker
alp at nuanti.com
Mon Jun 9 19:51:40 PDT 2014
On 10/06/2014 05:26, Rafael EspĂndola wrote:
> While the utilities functions are still used for sjlj lowering, the
> pass itself looks dead.
>
> Cheers,
> Rafael
>
> t.patch
>
>
> diff --git a/include/llvm/InitializePasses.h b/include/llvm/InitializePasses.h
> index 0c840f3..ea7eaff 100644
> --- a/include/llvm/InitializePasses.h
> +++ b/include/llvm/InitializePasses.h
> @@ -224,7 +224,6 @@ void initializeProcessImplicitDefsPass(PassRegistry&);
> void initializePromotePassPass(PassRegistry&);
> void initializePruneEHPass(PassRegistry&);
> void initializeReassociatePass(PassRegistry&);
> -void initializeRegToMemPass(PassRegistry&);
> void initializeRegionInfoPass(PassRegistry&);
> void initializeRegionOnlyPrinterPass(PassRegistry&);
> void initializeRegionOnlyViewerPass(PassRegistry&);
> diff --git a/include/llvm/LinkAllPasses.h b/include/llvm/LinkAllPasses.h
> index b2309ff..6aa5822 100644
> --- a/include/llvm/LinkAllPasses.h
> +++ b/include/llvm/LinkAllPasses.h
> @@ -108,7 +108,6 @@ namespace {
> (void) llvm::createObjCARCContractPass();
> (void) llvm::createObjCARCOptPass();
> (void) llvm::createPromoteMemoryToRegisterPass();
> - (void) llvm::createDemoteRegisterToMemoryPass();
> (void) llvm::createPruneEHPass();
> (void) llvm::createPostDomOnlyPrinterPass();
> (void) llvm::createPostDomPrinterPass();
> diff --git a/include/llvm/Transforms/Scalar.h b/include/llvm/Transforms/Scalar.h
> index 8ecfd80..535b8f7 100644
> --- a/include/llvm/Transforms/Scalar.h
> +++ b/include/llvm/Transforms/Scalar.h
> @@ -180,15 +180,6 @@ FunctionPass *createPromoteMemoryToRegisterPass();
>
> //===----------------------------------------------------------------------===//
> //
> -// DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
> -// references. In basically undoes the PromoteMemoryToRegister pass to make cfg
> -// hacking easier.
> -//
> -FunctionPass *createDemoteRegisterToMemoryPass();
> -extern char &DemoteRegisterToMemoryID;
> -
> -//===----------------------------------------------------------------------===//
> -//
> // Reassociate - This pass reassociates commutative expressions in an order that
> // is designed to promote better constant propagation, GCSE, LICM, PRE...
> //
> diff --git a/lib/Transforms/Scalar/CMakeLists.txt b/lib/Transforms/Scalar/CMakeLists.txt
> index b2461fc..50e275c 100644
> --- a/lib/Transforms/Scalar/CMakeLists.txt
> +++ b/lib/Transforms/Scalar/CMakeLists.txt
> @@ -25,7 +25,6 @@ add_llvm_library(LLVMScalarOpts
> MemCpyOptimizer.cpp
> PartiallyInlineLibCalls.cpp
> Reassociate.cpp
> - Reg2Mem.cpp
> SCCP.cpp
> SROA.cpp
> SampleProfile.cpp
> diff --git a/lib/Transforms/Scalar/Reg2Mem.cpp b/lib/Transforms/Scalar/Reg2Mem.cpp
> deleted file mode 100644
> index b6023e2..0000000
> --- a/lib/Transforms/Scalar/Reg2Mem.cpp
> +++ /dev/null
> @@ -1,133 +0,0 @@
> -//===- Reg2Mem.cpp - Convert registers to allocas -------------------------===//
> -//
> -// The LLVM Compiler Infrastructure
> -//
> -// This file is distributed under the University of Illinois Open Source
> -// License. See LICENSE.TXT for details.
> -//
> -//===----------------------------------------------------------------------===//
> -//
> -// This file demotes all registers to memory references. It is intended to be
> -// the inverse of PromoteMemoryToRegister. By converting to loads, the only
> -// values live across basic blocks are allocas and loads before phi nodes.
> -// It is intended that this should make CFG hacking much easier.
> -// To make later hacking easier, the entry block is split into two, such that
> -// all introduced allocas and nothing else are in the entry block.
> -//
> -//===----------------------------------------------------------------------===//
> -
> -#include "llvm/Transforms/Scalar.h"
> -#include "llvm/ADT/Statistic.h"
> -#include "llvm/IR/BasicBlock.h"
> -#include "llvm/IR/CFG.h"
> -#include "llvm/IR/Function.h"
> -#include "llvm/IR/Instructions.h"
> -#include "llvm/IR/LLVMContext.h"
> -#include "llvm/IR/Module.h"
> -#include "llvm/Pass.h"
> -#include "llvm/Transforms/Utils/Local.h"
> -#include <list>
> -using namespace llvm;
> -
> -#define DEBUG_TYPE "reg2mem"
> -
> -STATISTIC(NumRegsDemoted, "Number of registers demoted");
> -STATISTIC(NumPhisDemoted, "Number of phi-nodes demoted");
> -
> -namespace {
> - struct RegToMem : public FunctionPass {
> - static char ID; // Pass identification, replacement for typeid
> - RegToMem() : FunctionPass(ID) {
> - initializeRegToMemPass(*PassRegistry::getPassRegistry());
> - }
> -
> - void getAnalysisUsage(AnalysisUsage &AU) const override {
> - AU.addRequiredID(BreakCriticalEdgesID);
> - AU.addPreservedID(BreakCriticalEdgesID);
> - }
> -
> - bool valueEscapes(const Instruction *Inst) const {
> - const BasicBlock *BB = Inst->getParent();
> - for (const User *U : Inst->users()) {
> - const Instruction *UI = cast<Instruction>(U);
> - if (UI->getParent() != BB || isa<PHINode>(UI))
> - return true;
> - }
> - return false;
> - }
> -
> - bool runOnFunction(Function &F) override;
> - };
> -}
> -
> -char RegToMem::ID = 0;
> -INITIALIZE_PASS_BEGIN(RegToMem, "reg2mem", "Demote all values to stack slots",
> - false, false)
> -INITIALIZE_PASS_DEPENDENCY(BreakCriticalEdges)
> -INITIALIZE_PASS_END(RegToMem, "reg2mem", "Demote all values to stack slots",
> - false, false)
> -
> -bool RegToMem::runOnFunction(Function &F) {
> - if (F.isDeclaration())
> - return false;
> -
> - // Insert all new allocas into entry block.
> - BasicBlock *BBEntry = &F.getEntryBlock();
> - assert(pred_begin(BBEntry) == pred_end(BBEntry) &&
> - "Entry block to function must not have predecessors!");
> -
> - // Find first non-alloca instruction and create insertion point. This is
> - // safe if block is well-formed: it always have terminator, otherwise
> - // we'll get and assertion.
> - BasicBlock::iterator I = BBEntry->begin();
> - while (isa<AllocaInst>(I)) ++I;
> -
> - CastInst *AllocaInsertionPoint =
> - new BitCastInst(Constant::getNullValue(Type::getInt32Ty(F.getContext())),
> - Type::getInt32Ty(F.getContext()),
> - "reg2mem alloca point", I);
> -
> - // Find the escaped instructions. But don't create stack slots for
> - // allocas in entry block.
> - std::list<Instruction*> WorkList;
> - for (Function::iterator ibb = F.begin(), ibe = F.end();
> - ibb != ibe; ++ibb)
> - for (BasicBlock::iterator iib = ibb->begin(), iie = ibb->end();
> - iib != iie; ++iib) {
> - if (!(isa<AllocaInst>(iib) && iib->getParent() == BBEntry) &&
> - valueEscapes(iib)) {
> - WorkList.push_front(&*iib);
> - }
> - }
> -
> - // Demote escaped instructions
> - NumRegsDemoted += WorkList.size();
> - for (std::list<Instruction*>::iterator ilb = WorkList.begin(),
> - ile = WorkList.end(); ilb != ile; ++ilb)
> - DemoteRegToStack(**ilb, false, AllocaInsertionPoint);
> -
> - WorkList.clear();
> -
> - // Find all phi's
> - for (Function::iterator ibb = F.begin(), ibe = F.end();
> - ibb != ibe; ++ibb)
> - for (BasicBlock::iterator iib = ibb->begin(), iie = ibb->end();
> - iib != iie; ++iib)
> - if (isa<PHINode>(iib))
> - WorkList.push_front(&*iib);
> -
> - // Demote phi nodes
> - NumPhisDemoted += WorkList.size();
> - for (std::list<Instruction*>::iterator ilb = WorkList.begin(),
> - ile = WorkList.end(); ilb != ile; ++ilb)
> - DemotePHIToStack(cast<PHINode>(*ilb), AllocaInsertionPoint);
> -
> - return true;
> -}
> -
> -
> -// createDemoteRegisterToMemory - Provide an entry point to create this pass.
> -char &llvm::DemoteRegisterToMemoryID = RegToMem::ID;
> -FunctionPass *llvm::createDemoteRegisterToMemoryPass() {
> - return new RegToMem();
> -}
> diff --git a/lib/Transforms/Scalar/Scalar.cpp b/lib/Transforms/Scalar/Scalar.cpp
> index edf012d..93e7dd1 100644
> --- a/lib/Transforms/Scalar/Scalar.cpp
> +++ b/lib/Transforms/Scalar/Scalar.cpp
> @@ -54,7 +54,6 @@ void llvm::initializeScalarOpts(PassRegistry &Registry) {
> initializeMemCpyOptPass(Registry);
> initializePartiallyInlineLibCallsPass(Registry);
> initializeReassociatePass(Registry);
> - initializeRegToMemPass(Registry);
> initializeSCCPPass(Registry);
> initializeIPSCCPPass(Registry);
> initializeSROAPass(Registry);
> @@ -178,7 +177,7 @@ void LLVMAddConstantPropagationPass(LLVMPassManagerRef PM) {
> }
>
> void LLVMAddDemoteMemoryToRegisterPass(LLVMPassManagerRef PM) {
> - unwrap(PM)->add(createDemoteRegisterToMemoryPass());
> + // NOTE: This has been removed.
> }
I suppose that'll make
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20130916/188302.html
redundant?
Could you mention what replaces the functionality? I vaguely remember it
was useful for working with IR but that was a long time ago :-)
Anyway, don't forget to update the reg2mem documentation in Passes.rst
if you remove this.
Alp.
>
> void LLVMAddVerifierPass(LLVMPassManagerRef PM) {
> diff --git a/test/Transforms/Reg2Mem/crash.ll b/test/Transforms/Reg2Mem/crash.ll
> deleted file mode 100644
> index 02fed94..0000000
> --- a/test/Transforms/Reg2Mem/crash.ll
> +++ /dev/null
> @@ -1,88 +0,0 @@
> -; RUN: opt -reg2mem -disable-output < %s
> -; PR14782
> -
> -declare void @f1()
> -
> -declare i32 @__gxx_personality_sj0(...)
> -
> -declare void @f2()
> -
> -declare void @f3()
> -
> -declare void @f4_()
> -
> -declare void @_Z12xxxdtsP10xxxpq()
> -
> -define hidden void @_ZN12xxxyzIi9xxxwLi29ELi0EE4f3NewES0_i() ssp align 2 {
> -bb:
> - invoke void @f4_()
> - to label %bb1 unwind label %.thread
> -
> -.thread: ; preds = %bb
> - %tmp = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_sj0 to i8*)
> - cleanup
> - br label %bb13
> -
> -bb1: ; preds = %bb
> - invoke void @f1()
> - to label %.noexc unwind label %bb10
> -
> -.noexc: ; preds = %bb1
> - invoke void @f4_()
> - to label %bb6 unwind label %bb2
> -
> -bb2: ; preds = %.noexc
> - %tmp3 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_sj0 to i8*)
> - cleanup
> - invoke void @f3()
> - to label %.body unwind label %bb4
> -
> -bb4: ; preds = %bb2
> - %tmp5 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_sj0 to i8*)
> - catch i8* null
> - unreachable
> -
> -bb6: ; preds = %.noexc
> - invoke void @_Z12xxxdtsP10xxxpq()
> - to label %_ZN6xxxdIN12xxxyzIi9xxxwLi29ELi0EE4fr1jS3_.exit unwind label %bb10
> -
> -_ZN6xxxdIN12xxxyzIi9xxxwLi29ELi0EE4fr1jS3_.exit: ; preds = %bb6
> - invoke void @f2()
> - to label %bb7 unwind label %bb8
> -
> -bb7: ; preds = %_ZN6xxxdIN12xxxyzIi9xxxwLi29ELi0EE4fr1jS3_.exit
> - ret void
> -
> -bb8: ; preds = %_ZN6xxxdIN12xxxyzIi9xxxwLi29ELi0EE4fr1jS3_.exit
> - %tmp9 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_sj0 to i8*)
> - cleanup
> - br label %_ZN10xxxpqdlev.exit
> -
> -bb10: ; preds = %bb6, %bb1
> - %.1 = phi i1 [ true, %bb1 ], [ false, %bb6 ]
> - %tmp11 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_sj0 to i8*)
> - cleanup
> - br label %.body
> -
> -.body: ; preds = %bb10, %bb2
> - %.1.lpad-body = phi i1 [ %.1, %bb10 ], [ true, %bb2 ]
> - invoke void @f2()
> - to label %bb12 unwind label %bb14
> -
> -bb12: ; preds = %.body
> - br i1 %.1.lpad-body, label %bb13, label %_ZN10xxxpqdlev.exit
> -
> -bb13: ; preds = %bb12, %.thread
> - invoke void @xxx_MemFree()
> - to label %_ZN10xxxpqdlev.exit unwind label %bb14
> -
> -_ZN10xxxpqdlev.exit: ; preds = %bb13, %bb12, %bb8
> - resume { i8*, i32 } undef
> -
> -bb14: ; preds = %bb13, %.body
> - %tmp15 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_sj0 to i8*)
> - catch i8* null
> - unreachable
> -}
> -
> -declare void @xxx_MemFree()
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
--
http://www.nuanti.com
the browser experts
More information about the llvm-commits
mailing list