mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-05-13 17:38:39 +00:00
Add range adapters predecessors() and successors() for BBs
Use them in two isolated transforms so we know they work and aren't dead code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228173 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
eb884daa38
commit
7724d08fc6
@ -16,6 +16,7 @@
|
|||||||
#define LLVM_IR_CFG_H
|
#define LLVM_IR_CFG_H
|
||||||
|
|
||||||
#include "llvm/ADT/GraphTraits.h"
|
#include "llvm/ADT/GraphTraits.h"
|
||||||
|
#include "llvm/ADT/iterator_range.h"
|
||||||
#include "llvm/IR/Function.h"
|
#include "llvm/IR/Function.h"
|
||||||
#include "llvm/IR/InstrTypes.h"
|
#include "llvm/IR/InstrTypes.h"
|
||||||
|
|
||||||
@ -84,6 +85,8 @@ public:
|
|||||||
typedef PredIterator<BasicBlock, Value::user_iterator> pred_iterator;
|
typedef PredIterator<BasicBlock, Value::user_iterator> pred_iterator;
|
||||||
typedef PredIterator<const BasicBlock,
|
typedef PredIterator<const BasicBlock,
|
||||||
Value::const_user_iterator> const_pred_iterator;
|
Value::const_user_iterator> const_pred_iterator;
|
||||||
|
typedef llvm::iterator_range<pred_iterator> pred_range;
|
||||||
|
typedef llvm::iterator_range<const_pred_iterator> pred_const_range;
|
||||||
|
|
||||||
inline pred_iterator pred_begin(BasicBlock *BB) { return pred_iterator(BB); }
|
inline pred_iterator pred_begin(BasicBlock *BB) { return pred_iterator(BB); }
|
||||||
inline const_pred_iterator pred_begin(const BasicBlock *BB) {
|
inline const_pred_iterator pred_begin(const BasicBlock *BB) {
|
||||||
@ -96,8 +99,12 @@ inline const_pred_iterator pred_end(const BasicBlock *BB) {
|
|||||||
inline bool pred_empty(const BasicBlock *BB) {
|
inline bool pred_empty(const BasicBlock *BB) {
|
||||||
return pred_begin(BB) == pred_end(BB);
|
return pred_begin(BB) == pred_end(BB);
|
||||||
}
|
}
|
||||||
|
inline pred_range predecessors(BasicBlock *BB) {
|
||||||
|
return pred_range(pred_begin(BB), pred_end(BB));
|
||||||
|
}
|
||||||
|
inline pred_const_range predecessors(const BasicBlock *BB) {
|
||||||
|
return pred_const_range(pred_begin(BB), pred_end(BB));
|
||||||
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// BasicBlock succ_iterator definition
|
// BasicBlock succ_iterator definition
|
||||||
@ -247,6 +254,8 @@ public:
|
|||||||
typedef SuccIterator<TerminatorInst*, BasicBlock> succ_iterator;
|
typedef SuccIterator<TerminatorInst*, BasicBlock> succ_iterator;
|
||||||
typedef SuccIterator<const TerminatorInst*,
|
typedef SuccIterator<const TerminatorInst*,
|
||||||
const BasicBlock> succ_const_iterator;
|
const BasicBlock> succ_const_iterator;
|
||||||
|
typedef llvm::iterator_range<succ_iterator> succ_range;
|
||||||
|
typedef llvm::iterator_range<succ_const_iterator> succ_const_range;
|
||||||
|
|
||||||
inline succ_iterator succ_begin(BasicBlock *BB) {
|
inline succ_iterator succ_begin(BasicBlock *BB) {
|
||||||
return succ_iterator(BB->getTerminator());
|
return succ_iterator(BB->getTerminator());
|
||||||
@ -263,6 +272,13 @@ inline succ_const_iterator succ_end(const BasicBlock *BB) {
|
|||||||
inline bool succ_empty(const BasicBlock *BB) {
|
inline bool succ_empty(const BasicBlock *BB) {
|
||||||
return succ_begin(BB) == succ_end(BB);
|
return succ_begin(BB) == succ_end(BB);
|
||||||
}
|
}
|
||||||
|
inline succ_range successors(BasicBlock *BB) {
|
||||||
|
return succ_range(succ_begin(BB), succ_end(BB));
|
||||||
|
}
|
||||||
|
inline succ_const_range successors(const BasicBlock *BB) {
|
||||||
|
return succ_const_range(succ_begin(BB), succ_end(BB));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template <typename T, typename U> struct isPodLike<SuccIterator<T, U> > {
|
template <typename T, typename U> struct isPodLike<SuccIterator<T, U> > {
|
||||||
static const bool value = isPodLike<T>::value;
|
static const bool value = isPodLike<T>::value;
|
||||||
|
@ -561,8 +561,7 @@ bool ArgPromotion::isSafeToPromoteArgument(Argument *Arg,
|
|||||||
// Now check every path from the entry block to the load for transparency.
|
// Now check every path from the entry block to the load for transparency.
|
||||||
// To do this, we perform a depth first search on the inverse CFG from the
|
// To do this, we perform a depth first search on the inverse CFG from the
|
||||||
// loading block.
|
// loading block.
|
||||||
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
|
for (BasicBlock *P : predecessors(BB)) {
|
||||||
BasicBlock *P = *PI;
|
|
||||||
for (BasicBlock *TranspBB : inverse_depth_first_ext(P, TranspBlocks))
|
for (BasicBlock *TranspBB : inverse_depth_first_ext(P, TranspBlocks))
|
||||||
if (AA.canBasicBlockModify(*TranspBB, Loc))
|
if (AA.canBasicBlockModify(*TranspBB, Loc))
|
||||||
return false;
|
return false;
|
||||||
|
@ -58,13 +58,13 @@ Function* PartialInliner::unswitchFunction(Function* F) {
|
|||||||
BasicBlock* returnBlock = nullptr;
|
BasicBlock* returnBlock = nullptr;
|
||||||
BasicBlock* nonReturnBlock = nullptr;
|
BasicBlock* nonReturnBlock = nullptr;
|
||||||
unsigned returnCount = 0;
|
unsigned returnCount = 0;
|
||||||
for (succ_iterator SI = succ_begin(entryBlock), SE = succ_end(entryBlock);
|
for (BasicBlock *BB : successors(entryBlock)) {
|
||||||
SI != SE; ++SI)
|
if (isa<ReturnInst>(BB->getTerminator())) {
|
||||||
if (isa<ReturnInst>((*SI)->getTerminator())) {
|
returnBlock = BB;
|
||||||
returnBlock = *SI;
|
|
||||||
returnCount++;
|
returnCount++;
|
||||||
} else
|
} else
|
||||||
nonReturnBlock = *SI;
|
nonReturnBlock = BB;
|
||||||
|
}
|
||||||
|
|
||||||
if (returnCount != 1)
|
if (returnCount != 1)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user