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