clang: lib/CodeGen/ABIInfoImpl.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

10

11using namespace clang;

13

14

16

19

21

22

26

28 }

29

30

32 Ty = ED->getIntegerType();

33

36 if (EIT->getNumBits() >

37 Context.getTypeSize(Context.getTargetInfo().hasInt128Type()

38 ? Context.Int128Ty

39 : Context.LongLongTy))

41

45}

46

50

53

54

56 RetTy = ED->getIntegerType();

57

59 if (EIT->getNumBits() >

65

68}

69

76

84

86 llvm::Value *Array, llvm::Value *Value,

87 unsigned FirstIndex, unsigned LastIndex) {

88

89 for (unsigned I = FirstIndex; I <= LastIndex; ++I) {

90 llvm::Value *Cell =

91 Builder.CreateConstInBoundsGEP1_32(Builder.getInt8Ty(), Array, I);

93 }

94}

95

98 T->isMemberFunctionPointerType();

99}

100

105

108 const RecordDecl *RD = RT->getDecl()->getDefinitionOrSelf();

109 if (const auto *CXXRD = dyn_cast(RD))

110 return CXXABI.getRecordArgABI(CXXRD);

114}

115

117 const RecordType *RT = T->getAsCanonical();

118 if (!RT)

121}

122

126

131 return true;

132 }

133

134 return CXXABI.classifyReturnType(FI);

135}

136

140 if (UD->hasAttr()) {

141 assert(!UD->field_empty() && "sema created an empty transparent union");

143 }

144 }

145 return Ty;

146}

147

149 llvm::Value *Ptr,

151

152 llvm::Value *RoundUp = CGF.Builder.CreateConstInBoundsGEP1_32(

154 return CGF.Builder.CreateIntrinsic(

155 llvm::Intrinsic::ptrmask, {Ptr->getType(), CGF.IntPtrTy},

157 nullptr, Ptr->getName() + ".aligned");

158}

159

162 llvm::Type *DirectTy, CharUnits DirectSize,

164 bool AllowHigherAlign, bool ForceRightAdjust) {

165

166

169

170 llvm::Value *Ptr = CGF.Builder.CreateLoad(VAListAddr, "argp.cur");

171

172

174 if (AllowHigherAlign && DirectAlign > SlotSize) {

176 CGF.Int8Ty, DirectAlign);

177 } else {

179 }

180

181

186

187

188

189 if (DirectSize < SlotSize && CGF.CGM.getDataLayout().isBigEndian() &&

190 (!DirectTy->isStructTy() || ForceRightAdjust)) {

192 }

193

194 return Addr.withElementType(DirectTy);

195}

196

198 QualType ValueTy, bool IsIndirect,

202 bool ForceRightAdjust) {

203

204 CharUnits DirectSize, DirectAlign;

205 if (IsIndirect) {

208 } else {

209 DirectSize = ValueInfo.Width;

210 DirectAlign = ValueInfo.Align;

211 }

212

213

214 llvm::Type *DirectTy = CGF.ConvertTypeForMem(ValueTy), *ElementTy = DirectTy;

215 if (IsIndirect) {

216 unsigned AllocaAS = CGF.CGM.getDataLayout().getAllocaAddrSpace();

217 DirectTy = llvm::PointerType::get(CGF.getLLVMContext(), AllocaAS);

218 }

219

221 DirectAlign, SlotSizeAndAlign,

222 AllowHigherAlign, ForceRightAdjust);

223

224 if (IsIndirect) {

226 }

227

229}

230

232 llvm::BasicBlock *Block1, Address Addr2,

233 llvm::BasicBlock *Block2,

234 const llvm::Twine &Name) {

236 llvm::PHINode *PHI = CGF.Builder.CreatePHI(Addr1.getType(), 2, Name);

241}

242

244 bool AllowArrays, bool AsIfNoUniqueAddr) {

246 return true;

247

249

250

251

252 bool WasArray = false;

253 if (AllowArrays)

254 while (const ConstantArrayType *AT = Context.getAsConstantArrayType(FT)) {

255 if (AT->isZeroSize())

256 return true;

257 FT = AT->getElementType();

258

259

260 WasArray = true;

261 }

262

263 const RecordType *RT = FT->getAsCanonical();

264 if (!RT)

265 return false;

266

267

268

269

270

271

272

273

274

275

276

278 (WasArray || (!AsIfNoUniqueAddr && !FD->hasAttr())))

279 return false;

280

281 return isEmptyRecord(Context, FT, AllowArrays, AsIfNoUniqueAddr);

282}

283

285 bool AsIfNoUniqueAddr) {

286 const auto *RD = T->getAsRecordDecl();

287 if (!RD)

288 return false;

289 if (RD->hasFlexibleArrayMember())

290 return false;

291

292

293 if (const CXXRecordDecl *CXXRD = dyn_cast(RD))

294 for (const auto &I : CXXRD->bases())

295 if (isEmptyRecord(Context, I.getType(), true, AsIfNoUniqueAddr))

296 return false;

297

298 for (const auto *I : RD->fields())

299 if (isEmptyField(Context, I, AllowArrays, AsIfNoUniqueAddr))

300 return false;

301 return true;

302}

303

307 return true;

308

310 return false;

311

313}

314

316 const auto *RD = T->getAsRecordDecl();

317 if (!RD)

318 return false;

319

320

321 if (const CXXRecordDecl *CXXRD = dyn_cast(RD)) {

322 if (CXXRD->isDynamicClass())

323 return false;

324

325 for (const auto &I : CXXRD->bases())

327 return false;

328 }

329

330 for (const auto *I : RD->fields())

332 return false;

333

334 return true;

335}

336

338 const auto *RD = T->getAsRecordDecl();

339 if (!RD)

340 return nullptr;

341

342 if (RD->hasFlexibleArrayMember())

343 return nullptr;

344

346

347

348 if (const CXXRecordDecl *CXXRD = dyn_cast(RD)) {

349 for (const auto &I : CXXRD->bases()) {

350

352 continue;

353

354

356 return nullptr;

357

358

359

362 return nullptr;

363 }

364 }

365

366

367 for (const auto *FD : RD->fields()) {

369

370

372 continue;

373

374

375

377 return nullptr;

378

379

380 while (const ConstantArrayType *AT = Context.getAsConstantArrayType(FT)) {

381 if (AT->getZExtSize() != 1)

382 break;

383 FT = AT->getElementType();

384 }

385

388 } else {

391 return nullptr;

392 }

393 }

394

395

396

397 if (Found && Context.getTypeSize(Found) != Context.getTypeSize(T))

398 return nullptr;

399

401}

402

405

406

407

408

409

410

411

412

413

414 llvm::Value *Val;

415

418 "Unexpected PaddingType seen in arginfo in generic VAArg emitter!");

419 assert(

421 "Unexpected IndirectRealign seen in arginfo in generic VAArg emitter!");

422

424 CharUnits TyAlignForABI = TyInfo.Align;

425

427 llvm::Type *BaseTy = llvm::PointerType::getUnqual(CGF.getLLVMContext());

428 llvm::Value *Addr =

430 return Address(Addr, ElementTy, TyAlignForABI);

431 } else {

433 "Unexpected ArgInfo Kind in generic VAArg emitter!");

434

436 "Unexpected InReg seen in arginfo in generic VAArg emitter!");

438 "Unexpected PaddingType seen in arginfo in generic VAArg emitter!");

440 "Unexpected DirectOffset seen in arginfo in generic VAArg emitter!");

442 "Unexpected CoerceToType seen in arginfo in generic VAArg emitter!");

443

448 return Temp;

449 }

450}

451

455

458 if (!RD)

459 return false;

460

461

462 if (const CXXRecordDecl *CXXRD = dyn_cast(RD))

463 for (const auto &I : CXXRD->bases())

465 return false;

466

467 for (const auto *i : RD->fields()) {

469

471 return true;

472

474 return true;

475 }

476

477 return false;

478}

Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...

QualType getBuiltinVaListType() const

Retrieve the type of the __builtin_va_list type.

TypeInfoChars getTypeInfoInChars(const Type *T) const

A fixed int type of a specified bitwidth.

Implements C++ ABI-specific semantic analysis functions.

Represents a C++ struct/union/class.

CharUnits - This is an opaque type for sizes expressed in character units.

QuantityType getQuantity() const

getQuantity - Get the raw integer representation of this quantity.

static CharUnits One()

One - Construct a CharUnits quantity of one.

CharUnits alignTo(const CharUnits &Align) const

alignTo - Returns the next integer (mod 2**64) that is greater than or equal to this quantity and is ...

ABIArgInfo - Helper class to encapsulate information about how a specific C type should be passed to ...

bool getIndirectRealign() const

static ABIArgInfo getIgnore()

unsigned getDirectOffset() const

llvm::Type * getPaddingType() const

static ABIArgInfo getDirect(llvm::Type *T=nullptr, unsigned Offset=0, llvm::Type *Padding=nullptr, bool CanBeFlattened=true, unsigned Align=0)

static ABIArgInfo getExtend(QualType Ty, llvm::Type *T=nullptr)

llvm::Type * getCoerceToType() const

ABIInfo - Target specific hooks for defining how a type should be passed or returned from functions.

const llvm::DataLayout & getDataLayout() const

CodeGen::ABIArgInfo getNaturalAlignIndirect(QualType Ty, unsigned AddrSpace, bool ByVal=true, bool Realign=false, llvm::Type *Padding=nullptr) const

A convenience method to return an indirect ABIArgInfo with an expected alignment equal to the ABI ali...

CodeGen::CodeGenTypes & CGT

CodeGen::CGCXXABI & getCXXABI() const

ASTContext & getContext() const

bool isPromotableIntegerTypeForABI(QualType Ty) const

Like RawAddress, an abstract representation of an aligned address, but the pointer contained in this ...

llvm::Value * emitRawPointer(CodeGenFunction &CGF) const

Return the pointer contained in this class after authenticating it and adding offset to it if necessa...

CharUnits getAlignment() const

llvm::Type * getElementType() const

Return the type of the values stored in this address.

Address withElementType(llvm::Type *ElemTy) const

Return address with different element type, but same pointer and alignment.

llvm::PointerType * getType() const

Return the type of the pointer value.

llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)

Address CreateConstInBoundsByteGEP(Address Addr, CharUnits Offset, const llvm::Twine &Name="")

Given a pointer to i8, adjust it by a given constant offset.

llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")

Implements C++ ABI-specific code generation functions.

RecordArgABI

Specify how one should pass an argument of a record type.

@ RAA_Default

Pass it using the normal C aggregate rules for the ABI, potentially introducing extra copies and pass...

@ RAA_Indirect

Pass it as a pointer to temporary memory.

@ RAA_DirectInMemory

Pass it on the stack using its defined layout.

CGFunctionInfo - Class to encapsulate the information about a function definition.

ABIArgInfo & getReturnInfo()

CanQualType getReturnType() const

MutableArrayRef< ArgInfo > arguments()

CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...

static bool hasScalarEvaluationKind(QualType T)

RValue EmitLoadOfAnyValue(LValue V, AggValueSlot Slot=AggValueSlot::ignored(), SourceLocation Loc={})

Like EmitLoadOfLValue but also handles complex and aggregate types.

ASTContext & getContext() const

llvm::Type * ConvertTypeForMem(QualType T)

RawAddress CreateMemTemp(QualType T, const Twine &Name="tmp", RawAddress *Alloca=nullptr)

CreateMemTemp - Create a temporary memory object of the given type, with appropriate alignmen and cas...

LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)

llvm::LLVMContext & getLLVMContext()

const llvm::DataLayout & getDataLayout() const

ABIArgInfo classifyArgumentType(QualType RetTy) const

Definition ABIInfoImpl.cpp:17

RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty, AggValueSlot Slot) const override

EmitVAArg - Emit the target dependent code to load a value of.

Definition ABIInfoImpl.cpp:77

ABIArgInfo classifyReturnType(QualType RetTy) const

Definition ABIInfoImpl.cpp:47

virtual ~DefaultABIInfo()

void computeInfo(CGFunctionInfo &FI) const override

Definition ABIInfoImpl.cpp:70

RValue - This trivial value class is used to represent the result of an expression that is evaluated.

Represents the canonical version of C arrays with a specified constant size.

Represents a member of a struct/union/class.

bool isUnnamedBitField() const

Determines whether this is an unnamed bitfield.

bool isZeroLengthBitField() const

Is this a zero-length bit-field?

A (possibly-)qualified type.

const Type * getTypePtr() const

Retrieves a pointer to the underlying (unqualified) type.

Represents a struct/union/class.

bool canPassInRegisters() const

Determine whether this class can be passed in registers.

RecordDecl * getDefinitionOrSelf() const

field_iterator field_begin() const

const RecordType * getAsUnionType() const

NOTE: getAs*ArrayType are methods on ASTContext.

RecordDecl * getAsRecordDecl() const

Retrieves the RecordDecl this type refers to.

QualType getPointeeType() const

If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.

EnumDecl * getAsEnumDecl() const

Retrieves the EnumDecl this type refers to.

const T * getAsCanonical() const

If this type is canonically the specified type, return its canonical type cast to that specified type...

const T * getAs() const

Member-template getAs'.

Represents a GCC generic vector type.

bool isEmptyRecordForLayout(const ASTContext &Context, QualType T)

isEmptyRecordForLayout - Return true iff a structure contains only empty base classes (per isEmptyRec...

Definition ABIInfoImpl.cpp:315

@ Type

The l-value was considered opaque, so the alignment was determined from a type.

CGCXXABI::RecordArgABI getRecordArgABI(const RecordType *RT, CGCXXABI &CXXABI)

Definition ABIInfoImpl.cpp:106

bool classifyReturnType(const CGCXXABI &CXXABI, CGFunctionInfo &FI, const ABIInfo &Info)

Definition ABIInfoImpl.cpp:123

Address EmitVAArgInstr(CodeGenFunction &CGF, Address VAListAddr, QualType Ty, const ABIArgInfo &AI)

Definition ABIInfoImpl.cpp:403

bool isEmptyFieldForLayout(const ASTContext &Context, const FieldDecl *FD)

isEmptyFieldForLayout - Return true iff the field is "empty", that is, either a zero-width bit-field ...

Definition ABIInfoImpl.cpp:304

Address emitVoidPtrDirectVAArg(CodeGenFunction &CGF, Address VAListAddr, llvm::Type *DirectTy, CharUnits DirectSize, CharUnits DirectAlign, CharUnits SlotSize, bool AllowHigherAlign, bool ForceRightAdjust=false)

Emit va_arg for a platform using the common void* representation, where arguments are simply emitted ...

Definition ABIInfoImpl.cpp:161

bool isRecordWithSIMDVectorType(ASTContext &Context, QualType Ty)

Definition ABIInfoImpl.cpp:456

RValue emitVoidPtrVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType ValueTy, bool IsIndirect, TypeInfoChars ValueInfo, CharUnits SlotSizeAndAlign, bool AllowHigherAlign, AggValueSlot Slot, bool ForceRightAdjust=false)

Emit va_arg for a platform using the common void* representation, where arguments are simply emitted ...

Definition ABIInfoImpl.cpp:197

Address emitMergePHI(CodeGenFunction &CGF, Address Addr1, llvm::BasicBlock *Block1, Address Addr2, llvm::BasicBlock *Block2, const llvm::Twine &Name="")

Definition ABIInfoImpl.cpp:231

bool isEmptyField(ASTContext &Context, const FieldDecl *FD, bool AllowArrays, bool AsIfNoUniqueAddr=false)

isEmptyField - Return true iff a the field is "empty", that is it is an unnamed bit-field or an (arra...

Definition ABIInfoImpl.cpp:243

llvm::Value * emitRoundPointerUpToAlignment(CodeGenFunction &CGF, llvm::Value *Ptr, CharUnits Align)

Definition ABIInfoImpl.cpp:148

bool isAggregateTypeForABI(QualType T)

Definition ABIInfoImpl.cpp:96

const Type * isSingleElementStruct(QualType T, ASTContext &Context)

isSingleElementStruct - Determine if a structure is a "singleelement struct", i.e.

Definition ABIInfoImpl.cpp:337

llvm::Type * getVAListElementType(CodeGenFunction &CGF)

Definition ABIInfoImpl.cpp:101

void AssignToArrayRange(CodeGen::CGBuilderTy &Builder, llvm::Value *Array, llvm::Value *Value, unsigned FirstIndex, unsigned LastIndex)

Definition ABIInfoImpl.cpp:85

QualType useFirstFieldIfTransparentUnion(QualType Ty)

Pass transparent unions as if they were the type of the first element.

Definition ABIInfoImpl.cpp:137

bool isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays, bool AsIfNoUniqueAddr=false)

isEmptyRecord - Return true iff a structure contains only empty fields.

Definition ABIInfoImpl.cpp:284

bool isSIMDVectorType(ASTContext &Context, QualType Ty)

Definition ABIInfoImpl.cpp:452

The JSON file list parser is used to communicate input to InstallAPI.

bool isa(CodeGen::Address addr)

const FunctionProtoType * T

llvm::IntegerType * Int8Ty

i8, i16, i32, and i64

CharUnits getPointerSize() const

llvm::IntegerType * IntPtrTy

llvm::PointerType * Int8PtrTy

CharUnits getPointerAlign() const