aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/PHITransAddr.cpp
blob: ce7eca5d27c155823f9e161a36b1a99011ea7f4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//===- PHITransAddr.cpp - PHI Translation for Addresses -------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements the PHITransAddr class.
//
//===----------------------------------------------------------------------===//

#include "llvm/Analysis/PHITransAddr.h"
#include "llvm/Analysis/Dominators.h"
using namespace llvm;

/// IsPHITranslatable - If this needs PHI translation, return true if we have
/// some hope of doing it.  This should be used as a filter to avoid calling
/// GetPHITranslatedValue in hopeless situations.
bool PHITransAddr::IsPHITranslatable() const {
  return true; // not a good filter.
}

/// GetPHITranslatedValue - Given a computation that satisfied the
/// isPHITranslatable predicate, see if we can translate the computation into
/// the specified predecessor block.  If so, return that value, otherwise
/// return null.
Value *PHITransAddr::GetPHITranslatedValue(Value *InVal, BasicBlock *CurBB,
                                           BasicBlock *Pred,
                                           const TargetData *TD) const {
  // Not a great implementation.
  return 0;
}

/// GetAvailablePHITranslatePointer - Return the value computed by
/// PHITranslatePointer if it dominates PredBB, otherwise return null.
Value *PHITransAddr::
GetAvailablePHITranslatedValue(Value *V,
                               BasicBlock *CurBB, BasicBlock *PredBB,
                               const TargetData *TD,
                               const DominatorTree &DT) const {
  // See if PHI translation succeeds.
  V = GetPHITranslatedValue(V, CurBB, PredBB, TD);
  if (V == 0) return 0;
  
  // Make sure the value is live in the predecessor.
  if (Instruction *Inst = dyn_cast_or_null<Instruction>(V))
    if (!DT.dominates(Inst->getParent(), PredBB))
      return 0;
  return V;
}

/// InsertPHITranslatedPointer - Insert a computation of the PHI translated
/// version of 'V' for the edge PredBB->CurBB into the end of the PredBB
/// block.  All newly created instructions are added to the NewInsts list.
/// This returns null on failure.
///
Value *PHITransAddr::
InsertPHITranslatedPointer(Value *InVal, BasicBlock *CurBB,
                           BasicBlock *PredBB, const TargetData *TD,
                           const DominatorTree &DT,
                           SmallVectorImpl<Instruction*> &NewInsts) const {
  // See if we have a version of this value already available and dominating
  // PredBB.  If so, there is no need to insert a new copy.
  if (Value *Res = GetAvailablePHITranslatedValue(InVal, CurBB, PredBB, TD, DT))
    return Res;

  // Not a great implementation.
  return 0;
}