2009-12-04 02:10:16 +00:00
|
|
|
//===- PHITransAddr.h - PHI Translation for Addresses -----------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file declares the PHITransAddr class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_ANALYSIS_PHITRANSADDR_H
|
|
|
|
#define LLVM_ANALYSIS_PHITRANSADDR_H
|
|
|
|
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/Instruction.h"
|
2009-12-04 02:10:16 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
class DominatorTree;
|
2012-10-08 16:38:25 +00:00
|
|
|
class DataLayout;
|
2011-12-01 03:08:23 +00:00
|
|
|
class TargetLibraryInfo;
|
|
|
|
|
2009-12-04 02:10:16 +00:00
|
|
|
/// PHITransAddr - An address value which tracks and handles phi translation.
|
|
|
|
/// As we walk "up" the CFG through predecessors, we need to ensure that the
|
|
|
|
/// address we're tracking is kept up to date. For example, if we're analyzing
|
|
|
|
/// an address of "&A[i]" and walk through the definition of 'i' which is a PHI
|
|
|
|
/// node, we *must* phi translate i to get "&A[j]" or else we will analyze an
|
|
|
|
/// incorrect pointer in the predecessor block.
|
|
|
|
///
|
|
|
|
/// This is designed to be a relatively small object that lives on the stack and
|
|
|
|
/// is copyable.
|
|
|
|
///
|
|
|
|
class PHITransAddr {
|
|
|
|
/// Addr - The actual address we're analyzing.
|
|
|
|
Value *Addr;
|
|
|
|
|
2009-12-07 18:36:53 +00:00
|
|
|
/// TD - The target data we are playing with if known, otherwise null.
|
2012-10-08 16:38:25 +00:00
|
|
|
const DataLayout *TD;
|
2011-12-01 03:08:23 +00:00
|
|
|
|
|
|
|
/// TLI - The target library info if known, otherwise null.
|
|
|
|
const TargetLibraryInfo *TLI;
|
2009-12-07 18:36:53 +00:00
|
|
|
|
2009-12-04 02:10:16 +00:00
|
|
|
/// InstInputs - The inputs for our symbolic address.
|
|
|
|
SmallVector<Instruction*, 4> InstInputs;
|
|
|
|
public:
|
2012-10-08 16:38:25 +00:00
|
|
|
PHITransAddr(Value *addr, const DataLayout *td) : Addr(addr), TD(td), TLI(0) {
|
2009-12-04 02:10:16 +00:00
|
|
|
// If the address is an instruction, the whole thing is considered an input.
|
|
|
|
if (Instruction *I = dyn_cast<Instruction>(Addr))
|
|
|
|
InstInputs.push_back(I);
|
|
|
|
}
|
|
|
|
|
2009-12-07 19:45:30 +00:00
|
|
|
Value *getAddr() const { return Addr; }
|
|
|
|
|
2009-12-04 02:10:16 +00:00
|
|
|
/// NeedsPHITranslationFromBlock - Return true if moving from the specified
|
|
|
|
/// BasicBlock to its predecessors requires PHI translation.
|
|
|
|
bool NeedsPHITranslationFromBlock(BasicBlock *BB) const {
|
|
|
|
// We do need translation if one of our input instructions is defined in
|
|
|
|
// this block.
|
|
|
|
for (unsigned i = 0, e = InstInputs.size(); i != e; ++i)
|
|
|
|
if (InstInputs[i]->getParent() == BB)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-12-07 18:36:53 +00:00
|
|
|
/// IsPotentiallyPHITranslatable - 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 PHITranslateValue in hopeless situations.
|
|
|
|
bool IsPotentiallyPHITranslatable() const;
|
|
|
|
|
|
|
|
/// PHITranslateValue - PHI translate the current address up the CFG from
|
2010-02-24 08:48:04 +00:00
|
|
|
/// CurBB to Pred, updating our state to reflect any needed changes. If the
|
|
|
|
/// dominator tree DT is non-null, the translated value must dominate
|
|
|
|
/// PredBB. This returns true on failure and sets Addr to null.
|
|
|
|
bool PHITranslateValue(BasicBlock *CurBB, BasicBlock *PredBB,
|
|
|
|
const DominatorTree *DT);
|
2009-12-07 18:36:53 +00:00
|
|
|
|
|
|
|
/// PHITranslateWithInsertion - PHI translate this value into the specified
|
|
|
|
/// predecessor block, inserting a computation of the value if it is
|
|
|
|
/// unavailable.
|
|
|
|
///
|
|
|
|
/// All newly created instructions are added to the NewInsts list. This
|
|
|
|
/// returns null on failure.
|
|
|
|
///
|
|
|
|
Value *PHITranslateWithInsertion(BasicBlock *CurBB, BasicBlock *PredBB,
|
|
|
|
const DominatorTree &DT,
|
|
|
|
SmallVectorImpl<Instruction*> &NewInsts);
|
2009-12-09 00:01:00 +00:00
|
|
|
|
|
|
|
void dump() const;
|
|
|
|
|
2009-12-09 00:10:55 +00:00
|
|
|
/// Verify - Check internal consistency of this data structure. If the
|
|
|
|
/// structure is valid, it returns true. If invalid, it prints errors and
|
|
|
|
/// returns false.
|
2009-12-09 00:01:00 +00:00
|
|
|
bool Verify() const;
|
2009-12-07 18:36:53 +00:00
|
|
|
private:
|
2010-02-24 08:48:04 +00:00
|
|
|
Value *PHITranslateSubExpr(Value *V, BasicBlock *CurBB, BasicBlock *PredBB,
|
|
|
|
const DominatorTree *DT);
|
2009-12-04 02:10:16 +00:00
|
|
|
|
2009-12-07 18:36:53 +00:00
|
|
|
/// InsertPHITranslatedSubExpr - Insert a computation of the PHI translated
|
2009-12-04 02:10:16 +00:00
|
|
|
/// 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.
|
|
|
|
///
|
2009-12-07 18:36:53 +00:00
|
|
|
Value *InsertPHITranslatedSubExpr(Value *InVal, BasicBlock *CurBB,
|
|
|
|
BasicBlock *PredBB, const DominatorTree &DT,
|
|
|
|
SmallVectorImpl<Instruction*> &NewInsts);
|
2009-12-08 23:42:51 +00:00
|
|
|
|
2009-12-09 00:56:14 +00:00
|
|
|
/// AddAsInput - If the specified value is an instruction, add it as an input.
|
|
|
|
Value *AddAsInput(Value *V) {
|
|
|
|
// If V is an instruction, it is now an input.
|
|
|
|
if (Instruction *VI = dyn_cast<Instruction>(V))
|
|
|
|
InstInputs.push_back(VI);
|
|
|
|
return V;
|
|
|
|
}
|
2009-12-09 00:01:00 +00:00
|
|
|
|
2009-12-04 02:10:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|