forked from llvm/clangir
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTargetInfo.cpp
More file actions
682 lines (552 loc) · 22.6 KB
/
TargetInfo.cpp
File metadata and controls
682 lines (552 loc) · 22.6 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
#include "TargetInfo.h"
#include "ABIInfo.h"
#include "CIRGenCXXABI.h"
#include "CIRGenFunctionInfo.h"
#include "CIRGenTypes.h"
#include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/CIR/ABIArgInfo.h"
#include "clang/CIR/MissingFeatures.h"
#include "clang/CIR/Target/x86.h"
using namespace clang;
using namespace clang::CIRGen;
static bool isAggregateTypeForABI(QualType T) {
return !CIRGenFunction::hasScalarEvaluationKind(T) ||
T->isMemberFunctionPointerType();
}
/// Pass transparent unions as if they were the type of the first element. Sema
/// should ensure that all elements of the union have the same "machine type".
static QualType useFirstFieldIfTransparentUnion(QualType Ty) {
assert(!Ty->getAsUnionType() && "NYI");
return Ty;
}
bool clang::CIRGen::isEmptyRecordForLayout(const ASTContext &Context,
QualType T) {
const RecordType *RT = T->getAs<RecordType>();
if (!RT)
return false;
const RecordDecl *RD = RT->getDecl();
// If this is a C++ record, check the bases first.
if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
if (CXXRD->isDynamicClass())
return false;
for (const auto &I : CXXRD->bases())
if (!isEmptyRecordForLayout(Context, I.getType()))
return false;
}
for (const auto *I : RD->fields())
if (!isEmptyFieldForLayout(Context, I))
return false;
return true;
}
bool clang::CIRGen::isEmptyFieldForLayout(const ASTContext &Context,
const FieldDecl *FD) {
if (FD->isZeroLengthBitField())
return true;
if (FD->isUnnamedBitField())
return false;
return isEmptyRecordForLayout(Context, FD->getType());
}
namespace {
/// The default implementation for ABI specific
/// details. This implementation provides information which results in
/// self-consistent and sensible LLVM IR generation, but does not
/// conform to any particular ABI.
class DefaultABIInfo : public ABIInfo {
public:
DefaultABIInfo(CIRGenTypes &CGT) : ABIInfo(CGT) {}
virtual ~DefaultABIInfo() = default;
cir::ABIArgInfo classifyReturnType(QualType RetTy) const {
if (RetTy->isVoidType())
return cir::ABIArgInfo::getIgnore();
if (isAggregateTypeForABI(RetTy))
llvm_unreachable("NYI");
// Treat an enum type as its underlying type.
if (RetTy->getAs<EnumType>())
llvm_unreachable("NYI");
if (RetTy->getAs<BitIntType>())
llvm_unreachable("NYI");
return (isPromotableIntegerTypeForABI(RetTy)
? cir::ABIArgInfo::getExtend(RetTy)
: cir::ABIArgInfo::getDirect());
}
cir::ABIArgInfo classifyArgumentType(QualType Ty) const {
Ty = useFirstFieldIfTransparentUnion(Ty);
if (isAggregateTypeForABI(Ty)) {
llvm_unreachable("NYI");
}
// Treat an enum type as its underlying type.
if (Ty->getAs<EnumType>())
llvm_unreachable("NYI");
if (Ty->getAs<BitIntType>())
llvm_unreachable("NYI");
return (isPromotableIntegerTypeForABI(Ty) ? cir::ABIArgInfo::getExtend(Ty)
: cir::ABIArgInfo::getDirect());
}
};
} // namespace
//===----------------------------------------------------------------------===//
// AArch64 ABI Implementation
//===----------------------------------------------------------------------===//
namespace {
using ABIKind = cir::AArch64ABIKind;
class AArch64ABIInfo : public ABIInfo {
private:
ABIKind Kind;
public:
AArch64ABIInfo(CIRGenTypes &CGT, ABIKind Kind) : ABIInfo(CGT), Kind(Kind) {}
virtual bool allowBFloatArgsAndRet() const override {
// TODO: Should query target info instead of hardcoding.
assert(!cir::MissingFeatures::useTargetLoweringABIInfo());
return true;
}
private:
ABIKind getABIKind() const { return Kind; }
bool isDarwinPCS() const { return Kind == ABIKind::DarwinPCS; }
cir::ABIArgInfo classifyReturnType(QualType RetTy, bool IsVariadic) const;
cir::ABIArgInfo classifyArgumentType(QualType RetTy, bool IsVariadic,
unsigned CallingConvention) const;
};
class AArch64TargetCIRGenInfo : public TargetCIRGenInfo {
public:
AArch64TargetCIRGenInfo(CIRGenTypes &CGT, ABIKind Kind)
: TargetCIRGenInfo(std::make_unique<AArch64ABIInfo>(CGT, Kind)) {}
};
} // namespace
std::unique_ptr<TargetCIRGenInfo>
clang::CIRGen::createAArch64TargetCIRGenInfo(CIRGenTypes &CGT,
cir::AArch64ABIKind Kind) {
return std::make_unique<AArch64TargetCIRGenInfo>(CGT, Kind);
}
//===----------------------------------------------------------------------===//
// X86 ABI Implementation
//===----------------------------------------------------------------------===//
namespace {
/// The AVX ABI leel for X86 targets.
using X86AVXABILevel = cir::X86AVXABILevel;
class X86_64ABIInfo : public ABIInfo {
using Class = cir::X86ArgClass;
// X86AVXABILevel AVXLevel;
// Some ABIs (e.g. X32 ABI and Native Client OS) use 32 bit pointers on 64-bit
// hardware.
// bool Has64BitPointers;
public:
X86_64ABIInfo(CIRGenTypes &CGT, X86AVXABILevel AVXLevel)
: ABIInfo(CGT)
// , AVXLevel(AVXLevel)
// , Has64BitPointers(CGT.getDataLayout().getPointeSize(0) == 8)
{}
/// classify - Determine the x86_64 register classes in which the given type T
/// should be passed.
///
/// \param Lo - The classification for the parts of the type residing in the
/// low word of the containing object.
///
/// \param Hi - The classification for the parts of the type residing in the
/// high word of the containing object.
///
/// \param OffsetBase - The bit offset of this type in the containing object.
/// Some parameters are classified different depending on whether they
/// straddle an eightbyte boundary.
///
/// \param isNamedArg - Whether the argument in question is a "named"
/// argument, as used in AMD64-ABI 3.5.7.
///
/// If a word is unused its result will be NoClass; if a type should be passed
/// in Memory then at least the classification of \arg Lo will be Memory.
///
/// The \arg Lo class will be NoClass iff the argument is ignored.
///
/// If the \arg Lo class is ComplexX87, then the \arg Hi class will also be
/// ComplexX87.
void classify(clang::QualType T, uint64_t OffsetBase, Class &Lo, Class &Hi,
bool isNamedArg) const;
mlir::Type GetSSETypeAtOffset(mlir::Type CIRType, unsigned CIROffset,
clang::QualType SourceTy,
unsigned SourceOffset) const;
cir::ABIArgInfo classifyReturnType(QualType RetTy) const;
cir::ABIArgInfo classifyArgumentType(clang::QualType Ty, unsigned freeIntRegs,
unsigned &neededInt, unsigned &neededSSE,
bool isNamedArg) const;
mlir::Type GetINTEGERTypeAtOffset(mlir::Type CIRType, unsigned CIROffset,
QualType SourceTy,
unsigned SourceOffset) const;
/// getIndirectResult - Give a source type \arg Ty, return a suitable result
/// such that the argument will be passed in memory.
///
/// \param freeIntRegs - The number of free integer registers remaining
/// available.
cir::ABIArgInfo getIndirectResult(QualType Ty, unsigned freeIntRegs) const;
};
class X86_64TargetCIRGenInfo : public TargetCIRGenInfo {
public:
X86_64TargetCIRGenInfo(CIRGenTypes &CGT, X86AVXABILevel AVXLevel)
: TargetCIRGenInfo(std::make_unique<X86_64ABIInfo>(CGT, AVXLevel)) {}
};
} // namespace
std::unique_ptr<TargetCIRGenInfo>
clang::CIRGen::createX86_64TargetCIRGenInfo(CIRGenTypes &CGT,
X86AVXABILevel AVXLevel) {
return std::make_unique<X86_64TargetCIRGenInfo>(CGT, AVXLevel);
}
//===----------------------------------------------------------------------===//
// Base ABI and target codegen info implementation common between SPIR and
// SPIR-V.
//===----------------------------------------------------------------------===//
namespace {
class CommonSPIRABIInfo : public DefaultABIInfo {
public:
CommonSPIRABIInfo(CIRGenTypes &CGT) : DefaultABIInfo(CGT) {}
};
class SPIRVABIInfo : public CommonSPIRABIInfo {
public:
SPIRVABIInfo(CIRGenTypes &CGT) : CommonSPIRABIInfo(CGT) {}
private:
cir::ABIArgInfo classifyKernelArgumentType(QualType Ty) const {
assert(!getContext().getLangOpts().CUDAIsDevice && "NYI");
return classifyArgumentType(Ty);
}
};
class CommonSPIRTargetCIRGenInfo : public TargetCIRGenInfo {
public:
CommonSPIRTargetCIRGenInfo(std::unique_ptr<ABIInfo> ABIInfo)
: TargetCIRGenInfo(std::move(ABIInfo)) {}
mlir::ptr::MemorySpaceAttrInterface
getCIRAllocaAddressSpace() const override {
return cir::LangAddressSpaceAttr::get(
&getABIInfo().CGT.getMLIRContext(),
cir::LangAddressSpace::OffloadPrivate);
}
cir::CallingConv getOpenCLKernelCallingConv() const override {
return cir::CallingConv::SpirKernel;
}
};
class SPIRVTargetCIRGenInfo : public CommonSPIRTargetCIRGenInfo {
public:
SPIRVTargetCIRGenInfo(CIRGenTypes &CGT)
: CommonSPIRTargetCIRGenInfo(std::make_unique<SPIRVABIInfo>(CGT)) {}
void setCUDAKernelCallingConvention(const FunctionType *&ft) const override {
llvm_unreachable("NYI");
}
};
} // namespace
std::unique_ptr<TargetCIRGenInfo>
clang::CIRGen::createSPIRVTargetCIRGenInfo(CIRGenTypes &CGT) {
return std::make_unique<SPIRVTargetCIRGenInfo>(CGT);
}
//===----------------------------------------------------------------------===//
// NVPTX ABI Implementation
//===----------------------------------------------------------------------===//
namespace {
class NVPTXABIInfo : public ABIInfo {
public:
NVPTXABIInfo(CIRGenTypes &cgt) : ABIInfo(cgt) {}
cir::ABIArgInfo classifyReturnType(QualType retTy) const;
cir::ABIArgInfo classifyArgumentType(QualType ty) const;
};
class NVPTXTargetCIRGenInfo : public TargetCIRGenInfo {
public:
NVPTXTargetCIRGenInfo(CIRGenTypes &cgt)
: TargetCIRGenInfo(std::make_unique<NVPTXABIInfo>(cgt)) {}
mlir::Type getCUDADeviceBuiltinSurfaceDeviceType() const override {
// On the device side, surface reference is represented as an object handle
// in 64-bit integer.
return cir::IntType::get(&getABIInfo().CGT.getMLIRContext(), 64, true);
}
mlir::Type getCUDADeviceBuiltinTextureDeviceType() const override {
// On the device side, texture reference is represented as an object handle
// in 64-bit integer.
return cir::IntType::get(&getABIInfo().CGT.getMLIRContext(), 64, true);
}
void setTargetAttributes(const clang::Decl *decl, mlir::Operation *global,
CIRGenModule &cgm) const override {
if (clang::isa_and_nonnull<clang::VarDecl>(decl)) {
assert(!cir::MissingFeatures::emitNVVMMetadata());
return;
}
if (const auto *fd = clang::dyn_cast_or_null<clang::FunctionDecl>(decl)) {
cir::FuncOp func = mlir::cast<cir::FuncOp>(global);
if (func.isDeclaration())
return;
if (cgm.getLangOpts().CUDA) {
if (fd->hasAttr<CUDAGlobalAttr>()) {
func.setCallingConv(cir::CallingConv::PTXKernel);
// In LLVM we should create metadata like:
// !{<func-ref>, metadata !"kernel", i32 1}
assert(!cir::MissingFeatures::emitNVVMMetadata());
}
}
if (fd->getAttr<CUDALaunchBoundsAttr>())
llvm_unreachable("NYI");
}
}
};
} // namespace
std::unique_ptr<TargetCIRGenInfo>
clang::CIRGen::createNVPTXTargetCIRGenInfo(CIRGenTypes &CGT) {
return std::make_unique<NVPTXTargetCIRGenInfo>(CGT);
}
//===----------------------------------------------------------------------===//
// AMDGPU ABI Implementation
//===----------------------------------------------------------------------===//
namespace {
class AMDGPUABIInfo : public ABIInfo {
public:
AMDGPUABIInfo(CIRGenTypes &cgt) : ABIInfo(cgt) {}
cir::ABIArgInfo classifyReturnType(QualType retTy) const;
cir::ABIArgInfo classifyArgumentType(QualType ty) const;
};
class AMDGPUTargetCIRGenInfo : public TargetCIRGenInfo {
public:
AMDGPUTargetCIRGenInfo(CIRGenTypes &cgt)
: TargetCIRGenInfo(std::make_unique<AMDGPUABIInfo>(cgt)) {}
cir::CallingConv getOpenCLKernelCallingConv() const override {
return cir::CallingConv::AMDGPUKernel;
}
void setCUDAKernelCallingConvention(const FunctionType *&ft) const override {
ft = getABIInfo().getContext().adjustFunctionType(
ft, ft->getExtInfo().withCallingConv(CC_DeviceKernel));
}
};
} // namespace
std::unique_ptr<TargetCIRGenInfo>
clang::CIRGen::createAMDGPUTargetCIRGenInfo(CIRGenTypes &CGT) {
return std::make_unique<AMDGPUTargetCIRGenInfo>(CGT);
}
// TODO(cir): remove the attribute once this gets used.
LLVM_ATTRIBUTE_UNUSED
static bool classifyReturnType(const CIRGenCXXABI &CXXABI,
CIRGenFunctionInfo &FI, const ABIInfo &Info) {
QualType Ty = FI.getReturnType();
assert(!Ty->getAs<RecordType>() && "RecordType returns NYI");
return CXXABI.classifyReturnType(FI);
}
CIRGenCXXABI &ABIInfo::getCXXABI() const { return CGT.getCXXABI(); }
cir::VectorType
ABIInfo::getOptimalVectorMemoryType(cir::VectorType T,
const clang::LangOptions &Opt) const {
if (T.getSize() == 3 && !Opt.PreserveVec3Type) {
return cir::VectorType::get(T.getElementType(), 4);
}
return T;
}
clang::ASTContext &ABIInfo::getContext() const { return CGT.getContext(); }
cir::ABIArgInfo X86_64ABIInfo::getIndirectResult(QualType Ty,
unsigned freeIntRegs) const {
assert(false && "NYI");
}
/// GetINTEGERTypeAtOffset - The ABI specifies that a value should be passed in
/// an 8-byte GPR. This means that we either have a scalar or we are talking
/// about the high or low part of an up-to-16-byte struct. This routine picks
/// the best CIR type to represent this, which may be i64 or may be anything
/// else that the backend will pass in a GPR that works better (e.g. i8, %foo*,
/// etc).
///
/// PrefType is a CIR type that corresponds to (part of) the IR type for the
/// source type. CIROffset is an offset in bytes into the CIR type taht the
/// 8-byte value references. PrefType may be null.
///
/// SourceTy is the source-level type for the entire argument. SourceOffset is
/// an offset into this that we're processing (which is always either 0 or 8).
///
mlir::Type X86_64ABIInfo::GetINTEGERTypeAtOffset(mlir::Type CIRType,
unsigned CIROffset,
QualType SourceTy,
unsigned SourceOffset) const {
// TODO: entirely stubbed out
assert(CIROffset == 0 && "NYI");
assert(SourceOffset == 0 && "NYI");
return CIRType;
}
cir::ABIArgInfo X86_64ABIInfo::classifyArgumentType(QualType Ty,
unsigned int freeIntRegs,
unsigned int &neededInt,
unsigned int &neededSSE,
bool isNamedArg) const {
Ty = useFirstFieldIfTransparentUnion(Ty);
X86_64ABIInfo::Class Lo, Hi;
classify(Ty, 0, Lo, Hi, isNamedArg);
// Check some invariants
// FIXME: Enforce these by construction.
assert((Hi != Class::Memory || Lo == Class::Memory) &&
"Invalid memory classification.");
assert((Hi != Class::SSEUp || Lo == Class::SSE) &&
"Invalid SSEUp classification.");
neededInt = 0;
neededSSE = 0;
mlir::Type ResType = nullptr;
switch (Lo) {
default:
assert(false && "NYI");
// AMD64-ABI 3.2.3p3: Rule 2. If the class is INTEGER, the next available
// register of the sequence %rdi, %rsi, %rdx, %rcx, %r8 and %r9 is used.
case Class::Integer:
++neededInt;
// Pick an 8-byte type based on the preferred type.
ResType = GetINTEGERTypeAtOffset(CGT.convertType(Ty), 0, Ty, 0);
// If we have a sign or zero extended integer, make sure to return Extend so
// that the parameter gets the right LLVM IR attributes.
if (Hi == Class::NoClass && mlir::isa<cir::IntType>(ResType)) {
assert(!Ty->getAs<EnumType>() && "NYI");
if (Ty->isSignedIntegerOrEnumerationType() &&
isPromotableIntegerTypeForABI(Ty))
return cir::ABIArgInfo::getExtend(Ty);
}
break;
// AMD64-ABI 3.2.3p3: Rule 3. If the class is SSE, the next available SSE
// register is used, the registers are taken in the order from %xmm0 to
// %xmm7.
case Class::SSE: {
mlir::Type CIRType = CGT.convertType(Ty);
ResType = GetSSETypeAtOffset(CIRType, 0, Ty, 0);
++neededSSE;
break;
}
}
mlir::Type HighPart = nullptr;
switch (Hi) {
default:
assert(false && "NYI");
case Class::NoClass:
break;
}
assert(!HighPart && "NYI");
return cir::ABIArgInfo::getDirect(ResType);
}
// Skeleton only. Implement when used in TargetLower stage.
cir::ABIArgInfo NVPTXABIInfo::classifyReturnType(QualType retTy) const {
llvm_unreachable("not yet implemented");
}
cir::ABIArgInfo NVPTXABIInfo::classifyArgumentType(QualType ty) const {
llvm_unreachable("not yet implemented");
}
// Skeleton only. Implement when used in TargetLower stage.
cir::ABIArgInfo AMDGPUABIInfo::classifyReturnType(QualType retTy) const {
llvm_unreachable("not yet implemented");
}
cir::ABIArgInfo AMDGPUABIInfo::classifyArgumentType(QualType ty) const {
llvm_unreachable("not yet implemented");
}
ABIInfo::~ABIInfo() {}
bool ABIInfo::isPromotableIntegerTypeForABI(QualType Ty) const {
if (getContext().isPromotableIntegerType(Ty))
return true;
assert(!Ty->getAs<BitIntType>() && "NYI");
return false;
}
void X86_64ABIInfo::classify(QualType Ty, uint64_t OffsetBase, Class &Lo,
Class &Hi, bool isNamedArg) const {
// FIXME: This code can be simplified by introducing a simple value class for
// Class pairs with appropriate constructor methods for the various
// situations.
// FIXME: Some of the split computations are wrong; unaligned vectors
// shouldn't be passed in registers for example, so there is no chance they
// can straddle an eightbyte. Verify & simplify.
Lo = Hi = Class::NoClass;
Class &Current = OffsetBase < 64 ? Lo : Hi;
Current = Class::Memory;
if (const auto *BT = Ty->getAs<BuiltinType>()) {
BuiltinType::Kind k = BT->getKind();
if (k == BuiltinType::Void) {
Current = Class::NoClass;
} else if (k == BuiltinType::Int128 || k == BuiltinType::UInt128) {
assert(false && "NYI");
Lo = Class::Integer;
Hi = Class::Integer;
} else if (k >= BuiltinType::Bool && k <= BuiltinType::LongLong) {
Current = Class::Integer;
} else if (k == BuiltinType::Float || k == BuiltinType::Double ||
k == BuiltinType::Float16) {
Current = Class::SSE;
} else if (k == BuiltinType::LongDouble) {
assert(false && "NYI");
} else
assert(false &&
"Only void and Integer supported so far for builtin types");
// FIXME: _Decimal32 and _Decimal64 are SSE.
// FIXME: _float128 and _Decimal128 are (SSE, SSEUp).
return;
}
assert(!Ty->getAs<EnumType>() && "Enums NYI");
if (Ty->hasPointerRepresentation()) {
Current = Class::Integer;
return;
}
assert(false && "Nothing else implemented yet");
}
/// GetSSETypeAtOffset - Return a type that will be passed by the backend in the
/// low 8 bytes of an XMM register, corresponding to the SSE class.
mlir::Type X86_64ABIInfo::GetSSETypeAtOffset(mlir::Type CIRType,
unsigned int CIROffset,
clang::QualType SourceTy,
unsigned int SourceOffset) const {
// TODO: entirely stubbed out
assert(CIROffset == 0 && "NYI");
assert(SourceOffset == 0 && "NYI");
return CIRType;
}
cir::ABIArgInfo X86_64ABIInfo::classifyReturnType(QualType RetTy) const {
// AMD64-ABI 3.2.3p4: Rule 1. Classify the return type with the classification
// algorithm.
X86_64ABIInfo::Class Lo, Hi;
classify(RetTy, 0, Lo, Hi, /*isNamedArg*/ true);
// Check some invariants.
assert((Hi != Class::Memory || Lo == Class::Memory) &&
"Invalid memory classification.");
assert((Hi != Class::SSEUp || Lo == Class::SSE) &&
"Invalid SSEUp classification.");
mlir::Type ResType = nullptr;
assert(Lo == Class::NoClass || Lo == Class::Integer ||
Lo == Class::SSE && "Only NoClass and Integer supported so far");
switch (Lo) {
case Class::NoClass:
assert(Hi == Class::NoClass && "Only NoClass supported so far for Hi");
return cir::ABIArgInfo::getIgnore();
// AMD64-ABI 3.2.3p4: Rule 3. If the class is INTEGER, the next available
// register of the sequence %rax, %rdx is used.
case Class::Integer:
ResType = GetINTEGERTypeAtOffset(CGT.convertType(RetTy), 0, RetTy, 0);
// If we have a sign or zero extended integer, make sure to return Extend so
// that the parameter gets the right LLVM IR attributes.
// TODO: extend the above consideration to MLIR
if (Hi == Class::NoClass && mlir::isa<cir::IntType>(ResType)) {
// Treat an enum type as its underlying type.
if (const auto *EnumTy = RetTy->getAs<EnumType>())
RetTy = EnumTy->getDecl()->getIntegerType();
if (RetTy->isIntegralOrEnumerationType() &&
isPromotableIntegerTypeForABI(RetTy)) {
return cir::ABIArgInfo::getExtend(RetTy);
}
}
break;
// AMD64-ABI 3.2.3p4: Rule 4. If the class is SSE, the next available SSE
// register of the sequence %xmm0, %xmm1 is used.
case Class::SSE:
ResType = GetSSETypeAtOffset(CGT.convertType(RetTy), 0, RetTy, 0);
break;
default:
llvm_unreachable("NYI");
}
mlir::Type HighPart = nullptr;
if (HighPart)
assert(false && "NYI");
return cir::ABIArgInfo::getDirect(ResType);
}
clang::LangAS
TargetCIRGenInfo::getGlobalVarAddressSpace(CIRGenModule &CGM,
const clang::VarDecl *D) const {
assert(!CGM.getLangOpts().OpenCL &&
!(CGM.getLangOpts().CUDA && CGM.getLangOpts().CUDAIsDevice) &&
"Address space agnostic languages only");
return D ? D->getType().getAddressSpace() : LangAS::Default;
}
mlir::Value TargetCIRGenInfo::performAddrSpaceCast(
CIRGenFunction &CGF, mlir::Value Src, mlir::Attribute SrcAddr,
mlir::Attribute DestAddr, mlir::Type DestTy, bool IsNonNull) const {
// Since target may map different address spaces in AST to the same address
// space, an address space conversion may end up as a bitcast.
if (auto globalOp = Src.getDefiningOp<cir::GlobalOp>())
llvm_unreachable("Global ops addrspace cast NYI");
// Try to preserve the source's name to make IR more readable.
return CGF.getBuilder().createAddrSpaceCast(Src, DestTy);
}