2003-09-30 18:37:50 +00:00
|
|
|
//===-- llvm/Target/TargetData.h - Data size & alignment info ---*- C++ -*-===//
|
2005-04-21 20:59:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +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.
|
2005-04-21 20:59:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-09-18 12:38:31 +00:00
|
|
|
//
|
|
|
|
// This file defines target properties related to datatype size/offset/alignment
|
2005-04-21 20:59:05 +00:00
|
|
|
// information. It uses lazy annotations to cache information about how
|
2001-09-18 12:38:31 +00:00
|
|
|
// structure types are laid out and used.
|
|
|
|
//
|
|
|
|
// This structure should be created once, filled in if the defaults are not
|
|
|
|
// correct and then passed around by const&. None of the members functions
|
|
|
|
// require modification to the object.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_TARGET_TARGETDATA_H
|
|
|
|
#define LLVM_TARGET_TARGETDATA_H
|
|
|
|
|
2002-09-25 23:46:56 +00:00
|
|
|
#include "llvm/Pass.h"
|
2004-09-01 22:55:40 +00:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
2002-02-03 07:20:47 +00:00
|
|
|
#include <vector>
|
2004-02-26 08:01:57 +00:00
|
|
|
#include <string>
|
2003-11-11 22:41:34 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2002-02-03 07:20:47 +00:00
|
|
|
class Value;
|
|
|
|
class Type;
|
2001-09-18 12:38:31 +00:00
|
|
|
class StructType;
|
|
|
|
class StructLayout;
|
2006-10-24 20:32:14 +00:00
|
|
|
class GlobalVariable;
|
2001-09-18 12:38:31 +00:00
|
|
|
|
2002-09-25 23:46:56 +00:00
|
|
|
class TargetData : public ImmutablePass {
|
2002-10-14 22:41:13 +00:00
|
|
|
bool LittleEndian; // Defaults to false
|
2004-07-23 01:08:13 +00:00
|
|
|
unsigned char BoolAlignment; // Defaults to 1 byte
|
|
|
|
unsigned char ByteAlignment; // Defaults to 1 byte
|
2001-09-18 12:38:31 +00:00
|
|
|
unsigned char ShortAlignment; // Defaults to 2 bytes
|
|
|
|
unsigned char IntAlignment; // Defaults to 4 bytes
|
|
|
|
unsigned char LongAlignment; // Defaults to 8 bytes
|
|
|
|
unsigned char FloatAlignment; // Defaults to 4 bytes
|
|
|
|
unsigned char DoubleAlignment; // Defaults to 8 bytes
|
|
|
|
unsigned char PointerSize; // Defaults to 8 bytes
|
|
|
|
unsigned char PointerAlignment; // Defaults to 8 bytes
|
2004-04-14 17:45:48 +00:00
|
|
|
|
2001-09-18 12:38:31 +00:00
|
|
|
public:
|
2006-06-16 18:21:53 +00:00
|
|
|
/// Default ctor - This has to exist, because this is a pass, but it should
|
|
|
|
/// never be used.
|
|
|
|
TargetData() {
|
|
|
|
assert(0 && "ERROR: Bad TargetData ctor used. "
|
|
|
|
"Tool did not specify a TargetData to use?");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2006-05-12 05:49:47 +00:00
|
|
|
/// Constructs a TargetData from a string of the following format:
|
2006-05-20 23:28:54 +00:00
|
|
|
/// "E-p:64:64-d:64-f:32-l:64-i:32-s:16-b:8-B:8"
|
2006-05-12 05:49:47 +00:00
|
|
|
/// The above string is considered the default, and any values not specified
|
|
|
|
/// in the string will be assumed to be as above.
|
2006-06-16 18:21:53 +00:00
|
|
|
TargetData(const std::string &TargetDescription) {
|
2006-06-16 18:11:26 +00:00
|
|
|
init(TargetDescription);
|
|
|
|
}
|
2006-06-16 18:21:53 +00:00
|
|
|
|
|
|
|
/// Initialize target data from properties stored in the module.
|
|
|
|
TargetData(const Module *M);
|
|
|
|
|
|
|
|
TargetData(const TargetData &TD) :
|
2004-07-23 01:08:13 +00:00
|
|
|
ImmutablePass(),
|
2006-05-04 21:17:35 +00:00
|
|
|
LittleEndian(TD.isLittleEndian()),
|
|
|
|
BoolAlignment(TD.getBoolAlignment()),
|
|
|
|
ByteAlignment(TD.getByteAlignment()),
|
|
|
|
ShortAlignment(TD.getShortAlignment()),
|
|
|
|
IntAlignment(TD.getIntAlignment()),
|
|
|
|
LongAlignment(TD.getLongAlignment()),
|
|
|
|
FloatAlignment(TD.getFloatAlignment()),
|
|
|
|
DoubleAlignment(TD.getDoubleAlignment()),
|
|
|
|
PointerSize(TD.getPointerSize()),
|
|
|
|
PointerAlignment(TD.getPointerAlignment()) {
|
2004-04-14 17:45:48 +00:00
|
|
|
}
|
2005-04-21 20:59:05 +00:00
|
|
|
|
2001-09-18 12:38:31 +00:00
|
|
|
~TargetData(); // Not virtual, do not subclass this class
|
|
|
|
|
2006-06-16 18:11:26 +00:00
|
|
|
/// init - Specify configuration if not available at ctor time.
|
|
|
|
///
|
|
|
|
void init(const std::string &TargetDescription);
|
|
|
|
|
|
|
|
|
2002-10-14 22:41:13 +00:00
|
|
|
/// Target endianness...
|
2005-04-23 22:35:26 +00:00
|
|
|
bool isLittleEndian() const { return LittleEndian; }
|
|
|
|
bool isBigEndian() const { return !LittleEndian; }
|
2002-10-14 22:41:13 +00:00
|
|
|
|
|
|
|
/// Target alignment constraints
|
2005-04-23 22:35:26 +00:00
|
|
|
unsigned char getBoolAlignment() const { return BoolAlignment; }
|
|
|
|
unsigned char getByteAlignment() const { return ByteAlignment; }
|
|
|
|
unsigned char getShortAlignment() const { return ShortAlignment; }
|
|
|
|
unsigned char getIntAlignment() const { return IntAlignment; }
|
|
|
|
unsigned char getLongAlignment() const { return LongAlignment; }
|
|
|
|
unsigned char getFloatAlignment() const { return FloatAlignment; }
|
|
|
|
unsigned char getDoubleAlignment() const { return DoubleAlignment; }
|
|
|
|
unsigned char getPointerAlignment() const { return PointerAlignment; }
|
|
|
|
unsigned char getPointerSize() const { return PointerSize; }
|
|
|
|
unsigned char getPointerSizeInBits() const { return 8*PointerSize; }
|
2001-09-18 12:38:31 +00:00
|
|
|
|
2006-05-12 07:01:44 +00:00
|
|
|
/// getStringRepresentation - Return the string representation of the
|
|
|
|
/// TargetData. This representation is in the same format accepted by the
|
|
|
|
/// string constructor above.
|
|
|
|
std::string getStringRepresentation() const;
|
|
|
|
|
2003-12-22 05:00:45 +00:00
|
|
|
/// getTypeSize - Return the number of bytes necessary to hold the specified
|
2004-08-17 19:12:44 +00:00
|
|
|
/// type.
|
2005-04-23 22:35:26 +00:00
|
|
|
///
|
2003-12-22 05:00:45 +00:00
|
|
|
uint64_t getTypeSize(const Type *Ty) const;
|
2001-09-18 12:38:31 +00:00
|
|
|
|
2003-12-22 05:00:45 +00:00
|
|
|
/// getTypeAlignment - Return the minimum required alignment for the specified
|
2004-08-17 19:12:44 +00:00
|
|
|
/// type.
|
2005-04-23 22:35:26 +00:00
|
|
|
///
|
2001-09-18 12:38:31 +00:00
|
|
|
unsigned char getTypeAlignment(const Type *Ty) const;
|
|
|
|
|
2004-08-17 19:12:44 +00:00
|
|
|
/// getTypeAlignmentShift - Return the minimum required alignment for the
|
|
|
|
/// specified type, returned as log2 of the value (a shift amount).
|
2005-04-23 22:35:26 +00:00
|
|
|
///
|
2004-08-17 19:12:44 +00:00
|
|
|
unsigned char getTypeAlignmentShift(const Type *Ty) const;
|
|
|
|
|
2003-12-22 05:00:45 +00:00
|
|
|
/// getIntPtrType - Return an unsigned integer type that is the same size or
|
|
|
|
/// greater to the host pointer size.
|
2005-04-23 22:35:26 +00:00
|
|
|
///
|
2003-12-22 05:00:45 +00:00
|
|
|
const Type *getIntPtrType() const;
|
|
|
|
|
|
|
|
/// getIndexOffset - return the offset from the beginning of the type for the
|
|
|
|
/// specified indices. This is used to implement getelementptr.
|
|
|
|
///
|
2005-04-21 20:59:05 +00:00
|
|
|
uint64_t getIndexedOffset(const Type *Ty,
|
2003-12-22 05:00:45 +00:00
|
|
|
const std::vector<Value*> &Indices) const;
|
2005-04-21 20:59:05 +00:00
|
|
|
|
2006-01-14 00:06:42 +00:00
|
|
|
/// getStructLayout - Return a StructLayout object, indicating the alignment
|
|
|
|
/// of the struct, its size, and the offsets of its fields. Note that this
|
|
|
|
/// information is lazily cached.
|
2004-02-26 08:01:57 +00:00
|
|
|
const StructLayout *getStructLayout(const StructType *Ty) const;
|
2006-01-14 00:06:42 +00:00
|
|
|
|
|
|
|
/// InvalidateStructLayoutInfo - TargetData speculatively caches StructLayout
|
|
|
|
/// objects. If a TargetData object is alive when types are being refined and
|
|
|
|
/// removed, this method must be called whenever a StructType is removed to
|
|
|
|
/// avoid a dangling pointer in this cache.
|
|
|
|
void InvalidateStructLayoutInfo(const StructType *Ty) const;
|
2006-10-24 20:32:14 +00:00
|
|
|
|
|
|
|
/// getPreferredAlignmentLog - Return the preferred alignment of the
|
|
|
|
/// specified global, returned in log form. This includes an explicitly
|
|
|
|
/// requested alignment (if the global has one).
|
2006-10-24 20:48:29 +00:00
|
|
|
unsigned getPreferredAlignmentLog(const GlobalVariable *GV) const;
|
2001-09-18 12:38:31 +00:00
|
|
|
};
|
|
|
|
|
2005-04-23 22:35:26 +00:00
|
|
|
/// StructLayout - used to lazily calculate structure layout information for a
|
|
|
|
/// target machine, based on the TargetData structure.
|
|
|
|
///
|
2004-10-27 16:14:51 +00:00
|
|
|
class StructLayout {
|
|
|
|
public:
|
2002-05-19 15:28:02 +00:00
|
|
|
std::vector<uint64_t> MemberOffsets;
|
|
|
|
uint64_t StructSize;
|
2001-09-18 12:38:31 +00:00
|
|
|
unsigned StructAlignment;
|
2005-03-13 19:04:04 +00:00
|
|
|
|
|
|
|
/// getElementContainingOffset - Given a valid offset into the structure,
|
|
|
|
/// return the structure index that contains it.
|
2005-04-23 22:35:26 +00:00
|
|
|
///
|
2005-03-13 19:04:04 +00:00
|
|
|
unsigned getElementContainingOffset(uint64_t Offset) const;
|
|
|
|
|
2001-09-18 12:38:31 +00:00
|
|
|
private:
|
|
|
|
friend class TargetData; // Only TargetData can create this class
|
2004-02-26 08:01:57 +00:00
|
|
|
StructLayout(const StructType *ST, const TargetData &TD);
|
2001-09-18 12:38:31 +00:00
|
|
|
};
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2001-09-18 12:38:31 +00:00
|
|
|
#endif
|