mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
[BlockExtract][NewPM] Port -extract-blocks to NPM
Reviewed By: thakis Differential Revision: https://reviews.llvm.org/D89015
This commit is contained in:
parent
782086bdc2
commit
7faaf7ec26
@ -83,7 +83,7 @@ void initializeBasicBlockSectionsPass(PassRegistry &);
|
||||
void initializeBDCELegacyPassPass(PassRegistry&);
|
||||
void initializeBarrierNoopPass(PassRegistry&);
|
||||
void initializeBasicAAWrapperPassPass(PassRegistry&);
|
||||
void initializeBlockExtractorPass(PassRegistry &);
|
||||
void initializeBlockExtractorLegacyPassPass(PassRegistry &);
|
||||
void initializeBlockFrequencyInfoWrapperPassPass(PassRegistry&);
|
||||
void initializeBoundsCheckingLegacyPassPass(PassRegistry&);
|
||||
void initializeBranchFolderPassPass(PassRegistry&);
|
||||
|
25
include/llvm/Transforms/IPO/BlockExtractor.h
Normal file
25
include/llvm/Transforms/IPO/BlockExtractor.h
Normal file
@ -0,0 +1,25 @@
|
||||
//===- BlockExtractor.h - Extracts blocks into their own functions --------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This pass extracts the specified basic blocks from the module into their
|
||||
// own functions.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_TRANSFORMS_IPO_BLOCKEXTRACTOR_H
|
||||
#define LLVM_TRANSFORMS_IPO_BLOCKEXTRACTOR_H
|
||||
|
||||
#include "llvm/IR/PassManager.h"
|
||||
|
||||
namespace llvm {
|
||||
struct BlockExtractorPass : PassInfoMixin<BlockExtractorPass> {
|
||||
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
|
||||
};
|
||||
} // namespace llvm
|
||||
|
||||
#endif // LLVM_TRANSFORMS_IPO_BLOCKEXTRACTOR_H
|
@ -84,6 +84,7 @@
|
||||
#include "llvm/Transforms/IPO/AlwaysInliner.h"
|
||||
#include "llvm/Transforms/IPO/ArgumentPromotion.h"
|
||||
#include "llvm/Transforms/IPO/Attributor.h"
|
||||
#include "llvm/Transforms/IPO/BlockExtractor.h"
|
||||
#include "llvm/Transforms/IPO/CalledValuePropagation.h"
|
||||
#include "llvm/Transforms/IPO/ConstantMerge.h"
|
||||
#include "llvm/Transforms/IPO/CrossDSOCFI.h"
|
||||
|
@ -50,6 +50,7 @@ MODULE_PASS("constmerge", ConstantMergePass())
|
||||
MODULE_PASS("cross-dso-cfi", CrossDSOCFIPass())
|
||||
MODULE_PASS("deadargelim", DeadArgumentEliminationPass())
|
||||
MODULE_PASS("elim-avail-extern", EliminateAvailableExternallyPass())
|
||||
MODULE_PASS("extract-blocks", BlockExtractorPass())
|
||||
MODULE_PASS("forceattrs", ForceFunctionAttrsPass())
|
||||
MODULE_PASS("function-import", FunctionImportPass())
|
||||
MODULE_PASS("globaldce", GlobalDCEPass())
|
||||
|
@ -11,10 +11,12 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Transforms/IPO/BlockExtractor.h"
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
#include "llvm/ADT/Statistic.h"
|
||||
#include "llvm/IR/Instructions.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/IR/PassManager.h"
|
||||
#include "llvm/InitializePasses.h"
|
||||
#include "llvm/Pass.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
@ -38,13 +40,10 @@ cl::opt<bool> BlockExtractorEraseFuncs("extract-blocks-erase-funcs",
|
||||
cl::desc("Erase the existing functions"),
|
||||
cl::Hidden);
|
||||
namespace {
|
||||
class BlockExtractor : public ModulePass {
|
||||
SmallVector<SmallVector<BasicBlock *, 16>, 4> GroupsOfBlocks;
|
||||
bool EraseFunctions;
|
||||
/// Map a function name to groups of blocks.
|
||||
SmallVector<std::pair<std::string, SmallVector<std::string, 4>>, 4>
|
||||
BlocksByName;
|
||||
|
||||
class BlockExtractor {
|
||||
public:
|
||||
BlockExtractor(bool EraseFunctions) : EraseFunctions(EraseFunctions) {}
|
||||
bool runOnModule(Module &M);
|
||||
void init(const SmallVectorImpl<SmallVector<BasicBlock *, 16>>
|
||||
&GroupsOfBlocksToExtract) {
|
||||
for (const SmallVectorImpl<BasicBlock *> &GroupOfBlocks :
|
||||
@ -57,11 +56,26 @@ class BlockExtractor : public ModulePass {
|
||||
loadFile();
|
||||
}
|
||||
|
||||
private:
|
||||
SmallVector<SmallVector<BasicBlock *, 16>, 4> GroupsOfBlocks;
|
||||
bool EraseFunctions;
|
||||
/// Map a function name to groups of blocks.
|
||||
SmallVector<std::pair<std::string, SmallVector<std::string, 4>>, 4>
|
||||
BlocksByName;
|
||||
|
||||
void loadFile();
|
||||
void splitLandingPadPreds(Function &F);
|
||||
};
|
||||
|
||||
class BlockExtractorLegacyPass : public ModulePass {
|
||||
BlockExtractor BE;
|
||||
bool runOnModule(Module &M) override;
|
||||
|
||||
public:
|
||||
static char ID;
|
||||
BlockExtractor(const SmallVectorImpl<BasicBlock *> &BlocksToExtract,
|
||||
bool EraseFunctions)
|
||||
: ModulePass(ID), EraseFunctions(EraseFunctions) {
|
||||
BlockExtractorLegacyPass(const SmallVectorImpl<BasicBlock *> &BlocksToExtract,
|
||||
bool EraseFunctions)
|
||||
: ModulePass(ID), BE(EraseFunctions) {
|
||||
// We want one group per element of the input list.
|
||||
SmallVector<SmallVector<BasicBlock *, 16>, 4> MassagedGroupsOfBlocks;
|
||||
for (BasicBlock *BB : BlocksToExtract) {
|
||||
@ -69,39 +83,38 @@ public:
|
||||
NewGroup.push_back(BB);
|
||||
MassagedGroupsOfBlocks.push_back(NewGroup);
|
||||
}
|
||||
init(MassagedGroupsOfBlocks);
|
||||
BE.init(MassagedGroupsOfBlocks);
|
||||
}
|
||||
|
||||
BlockExtractor(const SmallVectorImpl<SmallVector<BasicBlock *, 16>>
|
||||
&GroupsOfBlocksToExtract,
|
||||
bool EraseFunctions)
|
||||
: ModulePass(ID), EraseFunctions(EraseFunctions) {
|
||||
init(GroupsOfBlocksToExtract);
|
||||
BlockExtractorLegacyPass(const SmallVectorImpl<SmallVector<BasicBlock *, 16>>
|
||||
&GroupsOfBlocksToExtract,
|
||||
bool EraseFunctions)
|
||||
: ModulePass(ID), BE(EraseFunctions) {
|
||||
BE.init(GroupsOfBlocksToExtract);
|
||||
}
|
||||
|
||||
BlockExtractor() : BlockExtractor(SmallVector<BasicBlock *, 0>(), false) {}
|
||||
bool runOnModule(Module &M) override;
|
||||
|
||||
private:
|
||||
void loadFile();
|
||||
void splitLandingPadPreds(Function &F);
|
||||
BlockExtractorLegacyPass()
|
||||
: BlockExtractorLegacyPass(SmallVector<BasicBlock *, 0>(), false) {}
|
||||
};
|
||||
|
||||
} // end anonymous namespace
|
||||
|
||||
char BlockExtractor::ID = 0;
|
||||
INITIALIZE_PASS(BlockExtractor, "extract-blocks",
|
||||
char BlockExtractorLegacyPass::ID = 0;
|
||||
INITIALIZE_PASS(BlockExtractorLegacyPass, "extract-blocks",
|
||||
"Extract basic blocks from module", false, false)
|
||||
|
||||
ModulePass *llvm::createBlockExtractorPass() { return new BlockExtractor(); }
|
||||
ModulePass *llvm::createBlockExtractorPass() {
|
||||
return new BlockExtractorLegacyPass();
|
||||
}
|
||||
ModulePass *llvm::createBlockExtractorPass(
|
||||
const SmallVectorImpl<BasicBlock *> &BlocksToExtract, bool EraseFunctions) {
|
||||
return new BlockExtractor(BlocksToExtract, EraseFunctions);
|
||||
return new BlockExtractorLegacyPass(BlocksToExtract, EraseFunctions);
|
||||
}
|
||||
ModulePass *llvm::createBlockExtractorPass(
|
||||
const SmallVectorImpl<SmallVector<BasicBlock *, 16>>
|
||||
&GroupsOfBlocksToExtract,
|
||||
bool EraseFunctions) {
|
||||
return new BlockExtractor(GroupsOfBlocksToExtract, EraseFunctions);
|
||||
return new BlockExtractorLegacyPass(GroupsOfBlocksToExtract, EraseFunctions);
|
||||
}
|
||||
|
||||
/// Gets all of the blocks specified in the input file.
|
||||
@ -233,3 +246,15 @@ bool BlockExtractor::runOnModule(Module &M) {
|
||||
|
||||
return Changed;
|
||||
}
|
||||
|
||||
bool BlockExtractorLegacyPass::runOnModule(Module &M) {
|
||||
return BE.runOnModule(M);
|
||||
}
|
||||
|
||||
PreservedAnalyses BlockExtractorPass::run(Module &M,
|
||||
ModuleAnalysisManager &AM) {
|
||||
BlockExtractor BE(false);
|
||||
BE.init(SmallVector<SmallVector<BasicBlock *, 16>, 0>());
|
||||
return BE.runOnModule(M) ? PreservedAnalyses::none()
|
||||
: PreservedAnalyses::all();
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ void llvm::initializeIPO(PassRegistry &Registry) {
|
||||
initializeInferFunctionAttrsLegacyPassPass(Registry);
|
||||
initializeInternalizeLegacyPassPass(Registry);
|
||||
initializeLoopExtractorLegacyPassPass(Registry);
|
||||
initializeBlockExtractorPass(Registry);
|
||||
initializeBlockExtractorLegacyPassPass(Registry);
|
||||
initializeSingleLoopExtractorPass(Registry);
|
||||
initializeLowerTypeTestsPass(Registry);
|
||||
initializeMergeFunctionsLegacyPassPass(Registry);
|
||||
|
@ -2,6 +2,8 @@
|
||||
; RUN: echo 'foo bb20' >> %t
|
||||
; RUN: opt -S -extract-blocks -extract-blocks-file=%t %s | FileCheck %s --check-prefix=CHECK-NO-ERASE
|
||||
; RUN: opt -S -extract-blocks -extract-blocks-file=%t -extract-blocks-erase-funcs %s | FileCheck %s --check-prefix=CHECK-ERASE
|
||||
; RUN: opt -S -passes=extract-blocks -extract-blocks-file=%t %s | FileCheck %s --check-prefix=CHECK-NO-ERASE
|
||||
; RUN: opt -S -passes=extract-blocks -extract-blocks-file=%t -extract-blocks-erase-funcs %s | FileCheck %s --check-prefix=CHECK-ERASE
|
||||
|
||||
; CHECK-NO-ERASE: @foo(
|
||||
; CHECK-NO-ERASE: @foo.bb9(
|
||||
|
Loading…
x
Reference in New Issue
Block a user