2007-06-16 08:12:05 +08:00
|
|
|
//===--- CodeGenTypes.h - Type translation for LLVM CodeGen -----*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by Chris Lattner and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This is the code that handles AST -> LLVM type lowering.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef CODEGEN_CODEGENTYPES_H
|
|
|
|
#define CODEGEN_CODEGENTYPES_H
|
|
|
|
|
2007-08-21 08:21:21 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2007-06-16 08:12:05 +08:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace llvm {
|
2007-08-18 06:00:32 +08:00
|
|
|
class Module;
|
2007-06-16 08:12:05 +08:00
|
|
|
class Type;
|
2007-10-26 02:32:36 +08:00
|
|
|
class PATypeHolder;
|
2007-11-01 04:01:01 +08:00
|
|
|
class TargetData;
|
2007-06-16 08:12:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace clang {
|
2007-07-14 09:29:45 +08:00
|
|
|
class ASTContext;
|
2007-08-21 08:21:21 +08:00
|
|
|
class TagDecl;
|
2007-06-16 08:12:05 +08:00
|
|
|
class TargetInfo;
|
|
|
|
class QualType;
|
2007-10-26 02:32:36 +08:00
|
|
|
class Type;
|
2007-06-16 08:12:05 +08:00
|
|
|
class FunctionTypeProto;
|
2007-10-24 07:26:46 +08:00
|
|
|
class FieldDecl;
|
|
|
|
class RecordDecl;
|
2007-10-23 10:10:49 +08:00
|
|
|
|
2007-06-16 08:12:05 +08:00
|
|
|
namespace CodeGen {
|
2007-10-23 10:10:49 +08:00
|
|
|
class CodeGenTypes;
|
|
|
|
|
2007-11-02 03:11:01 +08:00
|
|
|
/// CGRecordLayout - This class handles struct and union layout info while
|
2007-10-23 10:10:49 +08:00
|
|
|
/// lowering AST types to LLVM types.
|
2007-11-02 03:11:01 +08:00
|
|
|
class CGRecordLayout {
|
|
|
|
CGRecordLayout(); // DO NOT IMPLEMENT
|
2007-10-23 10:10:49 +08:00
|
|
|
public:
|
2007-11-02 03:11:01 +08:00
|
|
|
CGRecordLayout(llvm::Type *T) : STy(T) {
|
2007-10-25 04:38:06 +08:00
|
|
|
// FIXME : Collect info about fields that requires adjustments
|
|
|
|
// (i.e. fields that do not directly map to llvm struct fields.)
|
|
|
|
}
|
2007-10-23 10:10:49 +08:00
|
|
|
|
|
|
|
/// getLLVMType - Return llvm type associated with this record.
|
2007-10-24 08:56:23 +08:00
|
|
|
llvm::Type *getLLVMType() const {
|
2007-10-23 10:10:49 +08:00
|
|
|
return STy;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
llvm::Type *STy;
|
|
|
|
};
|
2007-06-16 08:12:05 +08:00
|
|
|
|
|
|
|
/// CodeGenTypes - This class organizes the cross-module state that is used
|
|
|
|
/// while lowering AST types to LLVM types.
|
|
|
|
class CodeGenTypes {
|
2007-07-14 09:29:45 +08:00
|
|
|
ASTContext &Context;
|
2007-06-16 08:12:05 +08:00
|
|
|
TargetInfo &Target;
|
2007-08-18 06:00:32 +08:00
|
|
|
llvm::Module& TheModule;
|
2007-11-01 04:01:01 +08:00
|
|
|
const llvm::TargetData& TheTargetData;
|
2007-08-21 08:21:21 +08:00
|
|
|
|
|
|
|
llvm::DenseMap<const TagDecl*, llvm::Type*> TagDeclTypes;
|
2007-10-23 10:10:49 +08:00
|
|
|
|
2007-11-02 03:11:01 +08:00
|
|
|
/// CGRecordLayouts - This maps llvm struct type with corresponding
|
2007-10-23 10:10:49 +08:00
|
|
|
/// record layout info.
|
2007-11-02 03:11:01 +08:00
|
|
|
/// FIXME : If CGRecordLayout is less than 16 bytes then use
|
2007-10-24 08:32:16 +08:00
|
|
|
/// inline it in the map.
|
2007-11-02 03:11:01 +08:00
|
|
|
llvm::DenseMap<const llvm::Type*, CGRecordLayout *> CGRecordLayouts;
|
2007-10-23 10:10:49 +08:00
|
|
|
|
|
|
|
/// FieldInfo - This maps struct field with corresponding llvm struct type
|
|
|
|
/// field no. This info is populated by record organizer.
|
|
|
|
llvm::DenseMap<const FieldDecl *, unsigned> FieldInfo;
|
|
|
|
|
2007-11-07 09:57:13 +08:00
|
|
|
class BitFieldInfo {
|
|
|
|
public:
|
2007-12-11 09:23:33 +08:00
|
|
|
explicit BitFieldInfo(unsigned N, unsigned B, unsigned E)
|
|
|
|
: No(N), Begin(B), End(E) {}
|
2007-11-07 09:57:13 +08:00
|
|
|
private:
|
2007-12-11 09:23:33 +08:00
|
|
|
// No - llvm struct field number that is used to
|
|
|
|
// access this field. It may be not same as struct field number.
|
|
|
|
// For example,
|
|
|
|
// struct S { char a; short b:2; }
|
|
|
|
// Here field 'b' is second field however it is accessed as
|
|
|
|
// 9th and 10th bitfield of first field whose type is short.
|
2007-11-07 09:57:13 +08:00
|
|
|
unsigned No;
|
|
|
|
unsigned Begin;
|
|
|
|
unsigned End;
|
|
|
|
};
|
|
|
|
llvm::DenseMap<const FieldDecl *, BitFieldInfo> BitFields;
|
|
|
|
|
2007-10-24 07:26:46 +08:00
|
|
|
/// RecordTypesToResolve - This keeps track of record types that are not
|
|
|
|
/// yet incomplete. One llvm::OpaqueType is associated with each incomplete
|
|
|
|
/// record.
|
|
|
|
llvm::DenseMap<const RecordDecl *, llvm::Type *> RecordTypesToResolve;
|
|
|
|
|
2007-10-26 02:32:36 +08:00
|
|
|
/// TypeHolderMap - This map keeps cache of llvm::Types (through PATypeHolder)
|
|
|
|
/// and maps llvm::Types to corresponding clang::Type. llvm::PATypeHolder is
|
|
|
|
/// used instead of llvm::Type because it allows us to bypass potential
|
|
|
|
/// dangling type pointers due to type refinement on llvm side.
|
2007-10-31 04:46:47 +08:00
|
|
|
llvm::DenseMap<Type *, llvm::PATypeHolder> TypeHolderMap;
|
2007-10-26 05:40:12 +08:00
|
|
|
|
|
|
|
/// ConvertNewType - Convert type T into a llvm::Type. Do not use this
|
|
|
|
/// method directly because it does not do any type caching. This method
|
|
|
|
/// is available only for ConvertType(). CovertType() is preferred
|
|
|
|
/// interface to convert type T into a llvm::Type.
|
|
|
|
const llvm::Type *ConvertNewType(QualType T);
|
2007-06-16 08:12:05 +08:00
|
|
|
public:
|
2007-11-01 04:01:01 +08:00
|
|
|
CodeGenTypes(ASTContext &Ctx, llvm::Module &M, const llvm::TargetData &TD);
|
2007-10-23 10:10:49 +08:00
|
|
|
~CodeGenTypes();
|
2007-06-16 08:12:05 +08:00
|
|
|
|
2007-11-01 04:08:22 +08:00
|
|
|
const llvm::TargetData &getTargetData() const { return TheTargetData; }
|
2007-06-16 08:12:05 +08:00
|
|
|
TargetInfo &getTarget() const { return Target; }
|
2007-10-30 04:50:19 +08:00
|
|
|
ASTContext &getContext() const { return Context; }
|
2007-10-26 05:40:12 +08:00
|
|
|
|
|
|
|
/// ConvertType - Convert type T into a llvm::Type. Maintain and use
|
|
|
|
/// type cache through TypeHOlderMap.
|
2007-06-23 03:05:19 +08:00
|
|
|
const llvm::Type *ConvertType(QualType T);
|
2007-06-16 08:12:05 +08:00
|
|
|
void DecodeArgumentTypes(const FunctionTypeProto &FTP,
|
2007-06-23 03:05:19 +08:00
|
|
|
std::vector<const llvm::Type*> &ArgTys);
|
2007-10-23 10:10:49 +08:00
|
|
|
|
2007-11-02 03:11:01 +08:00
|
|
|
const CGRecordLayout *getCGRecordLayout(const llvm::Type*) const;
|
2007-10-23 10:10:49 +08:00
|
|
|
|
|
|
|
/// getLLVMFieldNo - Return llvm::StructType element number
|
|
|
|
/// that corresponds to the field FD.
|
|
|
|
unsigned getLLVMFieldNo(const FieldDecl *FD);
|
|
|
|
|
|
|
|
/// addFieldInfo - Assign field number to field FD.
|
2007-11-07 09:57:13 +08:00
|
|
|
void addFieldInfo(const FieldDecl *FD, unsigned No, unsigned Begin,
|
2007-12-11 09:23:33 +08:00
|
|
|
unsigned End);
|
2007-06-16 08:12:05 +08:00
|
|
|
};
|
2007-07-14 06:13:22 +08:00
|
|
|
|
2007-06-16 08:12:05 +08:00
|
|
|
} // end namespace CodeGen
|
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
#endif
|