blob: 9e746232e42e1c4ab527af35e11513926a46746c (
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
|
//===---- TargetInfo.cpp - Encapsulate target details -----------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// These classes wrap the information about a call or function
// definition used to handle ABI compliancy.
//
//===----------------------------------------------------------------------===//
#include "TargetInfo.h"
#include "ABIInfo.h"
#include "CGABI.h"
#include "CodeGenFunction.h"
#include "CodeGenModule.h"
#include "llvm/ADT/Triple.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Type.h"
#include "llvm/Support/raw_ostream.h"
namespace flang {
TargetCodeGenInfo::~TargetCodeGenInfo() {}
namespace CodeGen {
class DefaultABIInfo : public ABIInfo {
public:
void computeReturnTypeInfo(QualType T, ABIRetInfo &Info) const;
};
void DefaultABIInfo::computeReturnTypeInfo(QualType T, ABIRetInfo &Info) const {
if(!T->isComplexType())
return;
Info = ABIRetInfo(ABIRetInfo::AggregateValueAsArg);
}
/// ABI Info for x86_32
class X86_32ABIInfo : public ABIInfo {
public:
void computeReturnTypeInfo(QualType T, ABIRetInfo &Info) const;
};
void X86_32ABIInfo::computeReturnTypeInfo(QualType T, ABIRetInfo &Info) const {
if(!T->isComplexType())
return;
Info = ABIRetInfo(ABIRetInfo::AggregateValueAsArg);
}
/// ABI Info for x86_64
/// NB: works only with x86_64-pc-{linux,darwin}
class X86_64ABIInfo : public ABIInfo {
CodeGenModule &CGM;
public:
X86_64ABIInfo(CodeGenModule &cgm) : CGM(cgm) {}
void computeReturnTypeInfo(QualType T, ABIRetInfo &Info) const;
};
void X86_64ABIInfo::computeReturnTypeInfo(QualType T, ABIRetInfo &Info) const {
if(!T->isComplexType())
return;
if(Info.getKind() == ABIRetInfo::Value) {
switch(T->getBuiltinTypeKind()) {
case BuiltinType::Real4:
Info = ABIRetInfo(ABIRetInfo::Value, llvm::VectorType::get(CGM.FloatTy, 2));
break;
case BuiltinType::Real8:
break;
default:
llvm_unreachable("invalid type kind");
}
}
}
//===----------------------------------------------------------------------===//
// Driver code
//===----------------------------------------------------------------------===//
const TargetCodeGenInfo &CodeGenModule::getTargetCodeGenInfo() {
if (TheTargetCodeGenInfo)
return *TheTargetCodeGenInfo;
llvm::Triple Triple(TheModule.getTargetTriple());
switch (Triple.getArch()) {
default:
TheTargetCodeGenInfo = new TargetCodeGenInfo(new DefaultABIInfo());
break;
case llvm::Triple::x86:
TheTargetCodeGenInfo = new TargetCodeGenInfo(new X86_32ABIInfo());
break;
case llvm::Triple::x86_64:
TheTargetCodeGenInfo = new TargetCodeGenInfo(new X86_64ABIInfo(*this));
break;
}
return *TheTargetCodeGenInfo;
}
}
}
|