2003-10-13 03:32:08 +00:00
|
|
|
//===-- TransformInternals.h - Shared functions for Transforms --*- C++ -*-===//
|
2003-10-21 15:17:13 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2001-11-04 23:24:06 +00:00
|
|
|
//
|
|
|
|
// This header file declares shared functions used by the different components
|
|
|
|
// of the Transforms library.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef TRANSFORM_INTERNALS_H
|
|
|
|
#define TRANSFORM_INTERNALS_H
|
|
|
|
|
|
|
|
#include "llvm/BasicBlock.h"
|
|
|
|
#include "llvm/Target/TargetData.h"
|
2001-11-08 20:19:56 +00:00
|
|
|
#include "llvm/DerivedTypes.h"
|
2002-04-28 19:55:58 +00:00
|
|
|
#include "llvm/Constants.h"
|
2001-11-04 23:24:06 +00:00
|
|
|
#include <map>
|
2001-11-05 18:30:53 +00:00
|
|
|
#include <set>
|
2001-11-04 23:24:06 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2002-09-16 18:32:33 +00:00
|
|
|
static inline int64_t getConstantValue(const ConstantInt *CPI) {
|
2003-07-23 15:22:26 +00:00
|
|
|
return (int64_t)cast<ConstantInt>(CPI)->getRawValue();
|
2001-11-26 17:00:13 +00:00
|
|
|
}
|
2001-11-04 23:24:06 +00:00
|
|
|
|
|
|
|
|
2001-11-26 17:00:13 +00:00
|
|
|
// getPointedToComposite - If the argument is a pointer type, and the pointed to
|
|
|
|
// value is a composite type, return the composite type, else return null.
|
2001-11-08 20:19:56 +00:00
|
|
|
//
|
2001-11-26 17:00:13 +00:00
|
|
|
static inline const CompositeType *getPointedToComposite(const Type *Ty) {
|
2001-11-08 20:19:56 +00:00
|
|
|
const PointerType *PT = dyn_cast<PointerType>(Ty);
|
2001-12-04 00:03:30 +00:00
|
|
|
return PT ? dyn_cast<CompositeType>(PT->getElementType()) : 0;
|
2001-11-08 20:19:56 +00:00
|
|
|
}
|
|
|
|
|
2003-05-20 18:45:36 +00:00
|
|
|
// ConvertibleToGEP - This function returns true if the specified value V is
|
2001-11-26 17:00:13 +00:00
|
|
|
// a valid index into a pointer of type Ty. If it is valid, Idx is filled in
|
|
|
|
// with the values that would be appropriate to make this a getelementptr
|
|
|
|
// instruction. The type returned is the root type that the GEP would point
|
|
|
|
// to if it were synthesized with this operands.
|
|
|
|
//
|
|
|
|
// If BI is nonnull, cast instructions are inserted as appropriate for the
|
|
|
|
// arguments of the getelementptr.
|
|
|
|
//
|
2003-05-20 18:45:36 +00:00
|
|
|
const Type *ConvertibleToGEP(const Type *Ty, Value *V,
|
2002-01-20 22:54:45 +00:00
|
|
|
std::vector<Value*> &Indices,
|
2003-04-24 18:25:27 +00:00
|
|
|
const TargetData &TD,
|
2001-11-26 17:00:13 +00:00
|
|
|
BasicBlock::iterator *BI = 0);
|
|
|
|
|
|
|
|
|
2001-11-05 18:30:53 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ValueHandle Class - Smart pointer that occupies a slot on the users USE list
|
|
|
|
// that prevents it from being destroyed. This "looks" like an Instruction
|
|
|
|
// with Opcode UserOp1.
|
|
|
|
//
|
2002-07-17 17:11:33 +00:00
|
|
|
class ValueMapCache;
|
2001-11-05 18:30:53 +00:00
|
|
|
class ValueHandle : public Instruction {
|
2001-11-13 05:01:36 +00:00
|
|
|
ValueMapCache &Cache;
|
2001-11-05 18:30:53 +00:00
|
|
|
public:
|
2001-11-13 05:01:36 +00:00
|
|
|
ValueHandle(ValueMapCache &VMC, Value *V);
|
2002-07-17 17:11:33 +00:00
|
|
|
ValueHandle(const ValueHandle &);
|
2001-11-05 18:30:53 +00:00
|
|
|
~ValueHandle();
|
|
|
|
|
|
|
|
virtual Instruction *clone() const { abort(); return 0; }
|
|
|
|
|
|
|
|
virtual const char *getOpcodeName() const {
|
|
|
|
return "ValueHandle";
|
|
|
|
}
|
|
|
|
|
2002-07-17 17:11:33 +00:00
|
|
|
inline bool operator<(const ValueHandle &VH) const {
|
|
|
|
return getOperand(0) < VH.getOperand(0);
|
|
|
|
}
|
|
|
|
|
2001-11-05 18:30:53 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const ValueHandle *) { return true; }
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return (I->getOpcode() == Instruction::UserOp1);
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2002-07-17 17:11:33 +00:00
|
|
|
|
|
|
|
// ------------- Expression Conversion ---------------------
|
|
|
|
|
|
|
|
typedef std::map<const Value*, const Type*> ValueTypeCache;
|
|
|
|
|
|
|
|
struct ValueMapCache {
|
|
|
|
// Operands mapped - Contains an entry if the first value (the user) has had
|
|
|
|
// the second value (the operand) mapped already.
|
|
|
|
//
|
|
|
|
std::set<const User*> OperandsMapped;
|
|
|
|
|
|
|
|
// Expression Map - Contains an entry from the old value to the new value of
|
|
|
|
// an expression that has been converted over.
|
|
|
|
//
|
|
|
|
std::map<const Value *, Value *> ExprMap;
|
|
|
|
typedef std::map<const Value *, Value *> ExprMapTy;
|
|
|
|
|
|
|
|
// Cast Map - Cast instructions can have their source and destination values
|
2003-08-21 22:14:26 +00:00
|
|
|
// changed independently for each part. Because of this, our old naive
|
2002-07-17 17:11:33 +00:00
|
|
|
// implementation would create a TWO new cast instructions, which would cause
|
|
|
|
// all kinds of problems. Here we keep track of the newly allocated casts, so
|
|
|
|
// that we only create one for a particular instruction.
|
|
|
|
//
|
|
|
|
std::set<ValueHandle> NewCasts;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-05-20 18:45:36 +00:00
|
|
|
bool ExpressionConvertibleToType(Value *V, const Type *Ty, ValueTypeCache &Map,
|
2003-04-24 18:25:27 +00:00
|
|
|
const TargetData &TD);
|
|
|
|
Value *ConvertExpressionToType(Value *V, const Type *Ty, ValueMapCache &VMC,
|
|
|
|
const TargetData &TD);
|
2002-07-17 17:11:33 +00:00
|
|
|
|
2003-05-20 18:45:36 +00:00
|
|
|
// ValueConvertibleToType - Return true if it is possible
|
|
|
|
bool ValueConvertibleToType(Value *V, const Type *Ty,
|
2003-04-24 18:25:27 +00:00
|
|
|
ValueTypeCache &ConvertedTypes,
|
|
|
|
const TargetData &TD);
|
2002-07-17 17:11:33 +00:00
|
|
|
|
2003-04-24 18:25:27 +00:00
|
|
|
void ConvertValueToNewType(Value *V, Value *NewVal, ValueMapCache &VMC,
|
|
|
|
const TargetData &TD);
|
2002-07-17 17:11:33 +00:00
|
|
|
|
|
|
|
|
2001-11-08 20:19:56 +00:00
|
|
|
// getStructOffsetType - Return a vector of offsets that are to be used to index
|
|
|
|
// into the specified struct type to get as close as possible to index as we
|
|
|
|
// can. Note that it is possible that we cannot get exactly to Offset, in which
|
|
|
|
// case we update offset to be the offset we actually obtained. The resultant
|
|
|
|
// leaf type is returned.
|
|
|
|
//
|
|
|
|
// If StopEarly is set to true (the default), the first object with the
|
|
|
|
// specified type is returned, even if it is a struct type itself. In this
|
|
|
|
// case, this routine will not drill down to the leaf type. Set StopEarly to
|
|
|
|
// false if you want a leaf
|
|
|
|
//
|
|
|
|
const Type *getStructOffsetType(const Type *Ty, unsigned &Offset,
|
2002-01-20 22:54:45 +00:00
|
|
|
std::vector<Value*> &Offsets,
|
2003-04-24 18:25:27 +00:00
|
|
|
const TargetData &TD, bool StopEarly = true);
|
2001-11-08 20:19:56 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2001-11-04 23:24:06 +00:00
|
|
|
#endif
|