mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-19 18:24:00 +00:00
Compute and cache information about the storage size and layout
of structures. This information is machine-dependent. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -12,7 +12,11 @@
|
|||||||
#define LLVM_DERIVED_TYPES_H
|
#define LLVM_DERIVED_TYPES_H
|
||||||
|
|
||||||
#include "llvm/Type.h"
|
#include "llvm/Type.h"
|
||||||
#include <vector>
|
#include "llvm/Codegen/TargetMachine.h"
|
||||||
|
#include "vector"
|
||||||
|
|
||||||
|
class TargetMachine;
|
||||||
|
|
||||||
|
|
||||||
// Future derived types: SIMD packed format
|
// Future derived types: SIMD packed format
|
||||||
|
|
||||||
@ -81,12 +85,20 @@ public:
|
|||||||
class StructType : public Type {
|
class StructType : public Type {
|
||||||
public:
|
public:
|
||||||
typedef vector<const Type*> ElementTypes;
|
typedef vector<const Type*> ElementTypes;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ElementTypes ETypes;
|
ElementTypes ETypes;
|
||||||
|
struct StructSizeAndOffsetInfo {
|
||||||
|
int storageSize; // -1 until the value is computd
|
||||||
|
vector<int> memberOffsets; // -1 until values are computed
|
||||||
|
const TargetMachine* targetInfo;
|
||||||
|
}
|
||||||
|
*layoutCache;
|
||||||
|
|
||||||
|
private:
|
||||||
StructType(const StructType &); // Do not implement
|
StructType(const StructType &); // Do not implement
|
||||||
const StructType &operator=(const StructType &); // Do not implement
|
const StructType &operator=(const StructType &); // Do not implement
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// This should really be private, but it squelches a bogus warning
|
// This should really be private, but it squelches a bogus warning
|
||||||
// from GCC to make them protected: warning: `class StructType' only
|
// from GCC to make them protected: warning: `class StructType' only
|
||||||
@ -94,6 +106,10 @@ protected:
|
|||||||
|
|
||||||
// Private ctor - Only can be created by a static member...
|
// Private ctor - Only can be created by a static member...
|
||||||
StructType(const vector<const Type*> &Types, const string &Name);
|
StructType(const vector<const Type*> &Types, const string &Name);
|
||||||
|
|
||||||
|
// Reset cached info so it will be computed when first requested
|
||||||
|
void ResetCachedInfo() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
inline const ElementTypes &getElementTypes() const { return ETypes; }
|
inline const ElementTypes &getElementTypes() const { return ETypes; }
|
||||||
@ -101,9 +117,65 @@ public:
|
|||||||
static const StructType *get(const ElementTypes &Params) {
|
static const StructType *get(const ElementTypes &Params) {
|
||||||
return getStructType(Params);
|
return getStructType(Params);
|
||||||
}
|
}
|
||||||
|
unsigned int getStorageSize(const TargetMachine& tmi) const;
|
||||||
|
unsigned int getElementOffset(int i, const TargetMachine& tmi) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
inline unsigned int
|
||||||
|
StructType::getStorageSize(const TargetMachine& tmi) const
|
||||||
|
{
|
||||||
|
if (layoutCache->targetInfo != NULL && ! (* layoutCache->targetInfo == tmi))
|
||||||
|
{// target machine has changed (hey it could happen). discard cached info.
|
||||||
|
ResetCachedInfo();
|
||||||
|
layoutCache->targetInfo = &tmi;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (layoutCache->storageSize < 0)
|
||||||
|
{
|
||||||
|
layoutCache->storageSize = tmi.findOptimalStorageSize(this);
|
||||||
|
assert(layoutCache->storageSize >= 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return layoutCache->storageSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline unsigned int
|
||||||
|
StructType::getElementOffset(int i, const TargetMachine& tmi) const
|
||||||
|
{
|
||||||
|
if (layoutCache->targetInfo != NULL && ! (* layoutCache->targetInfo == tmi))
|
||||||
|
{// target machine has changed (hey it could happen). discard cached info.
|
||||||
|
ResetCachedInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (layoutCache->memberOffsets[i] < 0)
|
||||||
|
{
|
||||||
|
layoutCache->targetInfo = &tmi; // remember which target was used
|
||||||
|
|
||||||
|
unsigned int* offsetVec = tmi.findOptimalMemberOffsets(this);
|
||||||
|
for (unsigned i=0, N=layoutCache->memberOffsets.size(); i < N; i++)
|
||||||
|
{
|
||||||
|
layoutCache->memberOffsets[i] = offsetVec[i];
|
||||||
|
assert(layoutCache->memberOffsets[i] >= 0);
|
||||||
|
}
|
||||||
|
delete[] offsetVec;
|
||||||
|
}
|
||||||
|
|
||||||
|
return layoutCache->memberOffsets[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline void
|
||||||
|
StructType::ResetCachedInfo() const
|
||||||
|
{
|
||||||
|
layoutCache->storageSize = -1;
|
||||||
|
layoutCache->memberOffsets.insert(layoutCache->memberOffsets.begin(),
|
||||||
|
ETypes.size(), -1);
|
||||||
|
layoutCache->targetInfo = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class PointerType : public Type {
|
class PointerType : public Type {
|
||||||
private:
|
private:
|
||||||
const Type *ValueType;
|
const Type *ValueType;
|
||||||
|
@ -143,7 +143,11 @@ ArrayType::ArrayType(const Type *ElType, int NumEl, const string &Name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
StructType::StructType(const vector<const Type*> &Types, const string &Name)
|
StructType::StructType(const vector<const Type*> &Types, const string &Name)
|
||||||
: Type(Name, StructTyID), ETypes(Types) {
|
: Type(Name, StructTyID),
|
||||||
|
ETypes(Types),
|
||||||
|
layoutCache(new StructSizeAndOffsetInfo)
|
||||||
|
{
|
||||||
|
ResetCachedInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
PointerType::PointerType(const Type *E)
|
PointerType::PointerType(const Type *E)
|
||||||
|
Reference in New Issue
Block a user