2002-04-27 06:56:12 +00:00
|
|
|
//===-- UnifyFunctionExitNodes.h - Ensure fn's have one return ---*- C++ -*--=//
|
2002-01-30 23:29:35 +00:00
|
|
|
//
|
2002-04-27 06:56:12 +00:00
|
|
|
// This pass is used to ensure that functions have at most one return
|
|
|
|
// instruction in them. It also holds onto the return instruction of the last
|
|
|
|
// unified function.
|
2002-01-30 23:29:35 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2002-04-27 06:56:12 +00:00
|
|
|
#ifndef LLVM_XFORMS_UNIFY_FUNCTION_EXIT_NODES_H
|
|
|
|
#define LLVM_XFORMS_UNIFY_FUNCTION_EXIT_NODES_H
|
2002-01-30 23:29:35 +00:00
|
|
|
|
|
|
|
#include "llvm/Pass.h"
|
|
|
|
|
2002-04-27 06:59:56 +00:00
|
|
|
struct UnifyFunctionExitNodes : public FunctionPass {
|
2002-01-30 23:29:35 +00:00
|
|
|
BasicBlock *ExitNode;
|
|
|
|
public:
|
|
|
|
static AnalysisID ID; // Pass ID
|
2002-04-27 06:59:56 +00:00
|
|
|
UnifyFunctionExitNodes(AnalysisID id = ID) : ExitNode(0) { assert(ID == id); }
|
2002-01-30 23:29:35 +00:00
|
|
|
|
2002-04-29 14:57:45 +00:00
|
|
|
virtual const char *getPassName() const { return "Unify Function Exit Nodes";}
|
|
|
|
|
2002-01-31 01:12:06 +00:00
|
|
|
// UnifyAllExitNodes - Unify all exit nodes of the CFG by creating a new
|
|
|
|
// BasicBlock, and converting all returns to unconditional branches to this
|
|
|
|
// new basic block. The singular exit node is returned in ExitNode.
|
|
|
|
//
|
2002-04-27 06:56:12 +00:00
|
|
|
// If there are no return stmts in the function, a null pointer is returned.
|
2002-01-31 01:12:06 +00:00
|
|
|
//
|
2002-03-23 22:51:58 +00:00
|
|
|
static bool doit(Function *F, BasicBlock *&ExitNode);
|
2002-01-31 01:12:06 +00:00
|
|
|
|
2002-01-30 23:29:35 +00:00
|
|
|
|
2002-04-27 06:56:12 +00:00
|
|
|
virtual bool runOnFunction(Function *F) {
|
2002-03-23 22:51:58 +00:00
|
|
|
return doit(F, ExitNode);
|
2002-01-30 23:29:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BasicBlock *getExitNode() const { return ExitNode; }
|
|
|
|
|
2002-04-27 06:56:12 +00:00
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.addProvided(ID); // Provide self!
|
2002-01-30 23:29:35 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2002-04-27 06:59:56 +00:00
|
|
|
static inline Pass *createUnifyFunctionExitNodesPass() {
|
|
|
|
return new UnifyFunctionExitNodes();
|
2002-02-26 21:46:54 +00:00
|
|
|
}
|
|
|
|
|
2002-01-30 23:29:35 +00:00
|
|
|
#endif
|