2003-10-13 11:32:08 +08:00
|
|
|
//===-- TransformInternals.h - Shared functions for Transforms --*- C++ -*-===//
|
2005-04-22 07:48:37 +08:00
|
|
|
//
|
2003-10-21 23:17:13 +08: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.
|
2005-04-22 07:48:37 +08:00
|
|
|
//
|
2003-10-21 23:17:13 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-11-05 07:24:06 +08: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-09 04:19:56 +08:00
|
|
|
#include "llvm/DerivedTypes.h"
|
2002-04-29 03:55:58 +08:00
|
|
|
#include "llvm/Constants.h"
|
2001-11-05 07:24:06 +08:00
|
|
|
#include <map>
|
2001-11-06 02:30:53 +08:00
|
|
|
#include <set>
|
2001-11-05 07:24:06 +08:00
|
|
|
|
2003-11-12 06:41:34 +08:00
|
|
|
namespace llvm {
|
|
|
|
|
2002-09-17 02:32:33 +08:00
|
|
|
static inline int64_t getConstantValue(const ConstantInt *CPI) {
|
2003-07-23 23:22:26 +08:00
|
|
|
return (int64_t)cast<ConstantInt>(CPI)->getRawValue();
|
2001-11-27 01:00:13 +08:00
|
|
|
}
|
2001-11-05 07:24:06 +08:00
|
|
|
|
|
|
|
|
2001-11-27 01:00:13 +08: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-09 04:19:56 +08:00
|
|
|
//
|
2001-11-27 01:00:13 +08:00
|
|
|
static inline const CompositeType *getPointedToComposite(const Type *Ty) {
|
2001-11-09 04:19:56 +08:00
|
|
|
const PointerType *PT = dyn_cast<PointerType>(Ty);
|
2001-12-04 08:03:30 +08:00
|
|
|
return PT ? dyn_cast<CompositeType>(PT->getElementType()) : 0;
|
2001-11-09 04:19:56 +08:00
|
|
|
}
|
|
|
|
|
2001-11-27 01:00:13 +08:00
|
|
|
|
2001-11-06 02:30:53 +08: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.
|
2005-04-22 07:48:37 +08:00
|
|
|
//
|
2002-07-18 01:11:33 +08:00
|
|
|
class ValueMapCache;
|
2001-11-06 02:30:53 +08:00
|
|
|
class ValueHandle : public Instruction {
|
2005-01-29 08:37:36 +08:00
|
|
|
Use Op;
|
2001-11-13 13:01:36 +08:00
|
|
|
ValueMapCache &Cache;
|
2001-11-06 02:30:53 +08:00
|
|
|
public:
|
2001-11-13 13:01:36 +08:00
|
|
|
ValueHandle(ValueMapCache &VMC, Value *V);
|
2002-07-18 01:11:33 +08:00
|
|
|
ValueHandle(const ValueHandle &);
|
2001-11-06 02:30:53 +08:00
|
|
|
~ValueHandle();
|
|
|
|
|
|
|
|
virtual Instruction *clone() const { abort(); return 0; }
|
|
|
|
|
|
|
|
virtual const char *getOpcodeName() const {
|
|
|
|
return "ValueHandle";
|
|
|
|
}
|
|
|
|
|
2002-07-18 01:11:33 +08:00
|
|
|
inline bool operator<(const ValueHandle &VH) const {
|
|
|
|
return getOperand(0) < VH.getOperand(0);
|
|
|
|
}
|
|
|
|
|
2001-11-06 02:30:53 +08: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-18 01:11:33 +08:00
|
|
|
|
|
|
|
// ------------- Expression Conversion ---------------------
|
|
|
|
|
|
|
|
typedef std::map<const Value*, const Type*> ValueTypeCache;
|
|
|
|
|
2004-10-28 00:14:51 +08:00
|
|
|
class ValueMapCache {
|
|
|
|
public:
|
2002-07-18 01:11:33 +08:00
|
|
|
// 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-22 06:14:26 +08:00
|
|
|
// changed independently for each part. Because of this, our old naive
|
2002-07-18 01:11:33 +08: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-21 02:45:36 +08:00
|
|
|
bool ExpressionConvertibleToType(Value *V, const Type *Ty, ValueTypeCache &Map,
|
2003-04-25 02:25:27 +08:00
|
|
|
const TargetData &TD);
|
|
|
|
Value *ConvertExpressionToType(Value *V, const Type *Ty, ValueMapCache &VMC,
|
|
|
|
const TargetData &TD);
|
2002-07-18 01:11:33 +08:00
|
|
|
|
2003-05-21 02:45:36 +08:00
|
|
|
// ValueConvertibleToType - Return true if it is possible
|
|
|
|
bool ValueConvertibleToType(Value *V, const Type *Ty,
|
2003-04-25 02:25:27 +08:00
|
|
|
ValueTypeCache &ConvertedTypes,
|
|
|
|
const TargetData &TD);
|
2002-07-18 01:11:33 +08:00
|
|
|
|
2003-04-25 02:25:27 +08:00
|
|
|
void ConvertValueToNewType(Value *V, Value *NewVal, ValueMapCache &VMC,
|
|
|
|
const TargetData &TD);
|
2002-07-18 01:11:33 +08:00
|
|
|
|
|
|
|
|
2001-11-09 04:19:56 +08: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-21 06:54:45 +08:00
|
|
|
std::vector<Value*> &Offsets,
|
2003-04-25 02:25:27 +08:00
|
|
|
const TargetData &TD, bool StopEarly = true);
|
2001-11-09 04:19:56 +08:00
|
|
|
|
2003-11-12 06:41:34 +08:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2001-11-05 07:24:06 +08:00
|
|
|
#endif
|