LLVM: lib/Transforms/Scalar/FlattenCFGPass.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

21

22using namespace llvm;

23

24#define DEBUG_TYPE "flatten-cfg"

25

26namespace {

27struct FlattenCFGLegacyPass : public FunctionPass {

28 static char ID;

29public:

32 }

34

37 }

38

39private:

41};

42

43

44

46 bool Changed = false;

47 bool LocalChange = true;

48

49

50

51 std::vector Blocks;

53 for (auto &BB : F)

54 Blocks.push_back(&BB);

55

56 while (LocalChange) {

57 LocalChange = false;

58

59

61

62 if (auto *BB = cast_or_null(BlockHandle))

64 LocalChange = true;

65 }

66 Changed |= LocalChange;

67 }

68 return Changed;

69}

70}

71

72char FlattenCFGLegacyPass::ID = 0;

73

75 false, false)

79

80

82 return new FlattenCFGLegacyPass();

83}

84

85bool FlattenCFGLegacyPass::runOnFunction(Function &F) {

86 AA = &getAnalysis().getAAResults();

87 bool EverChanged = false;

88

89 while (iterativelyFlattenCFG(F, AA)) {

91 EverChanged = true;

92 }

93 return EverChanged;

94}

95

98 bool EverChanged = false;

100

101 while (iterativelyFlattenCFG(F, AA)) {

103 EverChanged = true;

104 }

106}

DenseMap< Block *, BlockRelaxAux > Blocks

This header defines various interfaces for pass management in LLVM.

#define INITIALIZE_PASS_DEPENDENCY(depName)

#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)

#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)

A manager for alias analyses.

A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object.

A container for analyses that lazily runs them and caches their results.

PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)

Get the result of an analysis pass for a given IR unit.

Represent the analysis usage information of a pass.

AnalysisUsage & addRequired()

FunctionPass class - This class is used to implement most global optimizations.

virtual bool runOnFunction(Function &F)=0

runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.

static PassRegistry * getPassRegistry()

getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...

virtual void getAnalysisUsage(AnalysisUsage &) const

getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...

A set of analyses that are preserved following a run of a transformation pass.

static PreservedAnalyses none()

Convenience factory function for the empty preserved set.

static PreservedAnalyses all()

Construct a special preserved set that preserves all passes.

A nullable Value handle that is nullable.

unsigned ID

LLVM IR allows to use arbitrary numbers as calling convention identifiers.

This is an optimization pass for GlobalISel generic memory operations.

FunctionPass * createFlattenCFGPass()

bool FlattenCFG(BasicBlock *BB, AAResults *AA=nullptr)

This function is used to flatten a CFG.

void initializeFlattenCFGLegacyPassPass(PassRegistry &)

bool removeUnreachableBlocks(Function &F, DomTreeUpdater *DTU=nullptr, MemorySSAUpdater *MSSAU=nullptr)

Remove all blocks that can not be reached from the function's entry.

PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)