summaryrefslogtreecommitdiff
path: root/lib/CodeGen/CodeGenTypes.h
blob: 29e9ff3295e9c7dadac6966cbff08357f1d4dd55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//===--- CodeGenTypes.h - Type translation for LLVM CodeGen -----*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file 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 FLANG_CODEGEN_CODEGENTYPES_H
#define FLANG_CODEGEN_CODEGENTYPES_H

#include "CGCall.h"
#include "CGABI.h"
#include "flang/AST/Decl.h"
#include "flang/AST/Type.h"
#include "flang/Frontend/CodeGenOptions.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/IR/Module.h"
#include <vector>

namespace llvm {
  class FunctionType;
  class Module;
  class DataLayout;
  class Type;
  class LLVMContext;
  class StructType;
  class IntegerType;
}

namespace flang {
  class ASTContext;
  class TargetInfo;

namespace CodeGen {
  class CodeGenModule;

class CGType {
  QualType ASTType;
  llvm::Type *LLVMType;
public:
  CGType() : LLVMType(nullptr) {}
  CGType(QualType T) : ASTType(T), LLVMType(nullptr) {}
  CGType(llvm::Type *T) : LLVMType(T) {}

  bool isQualType() const { return LLVMType == nullptr; }
  QualType asQualType() const {
    return ASTType;
  }
  llvm::Type *asLLVMType() const {
    return LLVMType;
  }
};

/// CodeGenTypes - This class organizes the cross-module state that is used
/// while lowering AST types to LLVM types.
class CodeGenTypes {
public:
  CodeGenModule &CGM;
  ASTContext &Context;
  FortranABI DefaultABI;

public:
  CodeGenTypes(CodeGenModule &cgm);
  ~CodeGenTypes();

  /// ConvertType - Convert type T into a llvm::Type.
  llvm::Type *ConvertType(QualType T);

  /// ConvertTypeForMem - Convert type T into a llvm::Type.  This differs from
  /// ConvertType in that it is used to convert to the memory representation for
  /// a type.  For example, the scalar representation for _Bool is i1, but the
  /// memory representation is usually i8 or i32, depending on the target.
  llvm::Type *ConvertTypeForMem(QualType T);

  const CGFunctionInfo *GetFunctionType(const FunctionDecl *FD);

  const CGFunctionInfo *GetFunctionType(FortranABI &ABI,
                                        ArrayRef<CGType> Args,
                                        CGType ReturnType);

  llvm::Type *GetComplexType(llvm::Type *ElementType);
  llvm::Type *GetComplexTypeAsVector(llvm::Type *ElementType);

  llvm::Type *GetCharacterType(llvm::Type *PtrType);

  llvm::Type *ConvertBuiltInType(BuiltinType::TypeSpec Spec,
                                 BuiltinType::TypeKind Kind);

  llvm::Type *ConvertCharType(const CharacterType *T);
  llvm::Type *ConvertCharTypeForMem(const CharacterType *T);

  llvm::ArrayType *ConvertArrayTypeForMem(const ArrayType *T);

  llvm::Type *ConvertArrayType(const ArrayType *T);

  llvm::ArrayType *GetFixedSizeArrayType(const ArrayType *T,
                                         uint64_t Size);

  llvm::Type *ConvertRecordType(const RecordType *T);

  llvm::Type *ConvertFunctionType(const FunctionType *T);

  llvm::Type *ConvertReturnType(QualType T,
                                CGFunctionInfo::RetInfo &ReturnInfo);

  void ConvertArgumentType(SmallVectorImpl<llvm::Type *> &ArgTypes,
                           SmallVectorImpl<llvm::Type *> &AdditionalArgTypes,
                           QualType T,
                           const CGFunctionInfo::ArgInfo &ArgInfo);

  void ConvertArgumentTypeForReturnValue(SmallVectorImpl<CGFunctionInfo::ArgInfo> &ArgInfo,
                                         SmallVectorImpl<llvm::Type *> &ArgTypes,
                                         SmallVectorImpl<llvm::Type *> &AdditionalArgTypes,
                                         QualType T,
                                         const CGFunctionInfo::RetInfo &ReturnInfo);

};

}  // end namespace CodeGen
}  // end namespace flang

#endif