10#include "TargetInfo.h"
23 HexagonABIInfo(CodeGenTypes &CGT) : DefaultABIInfo(CGT) {}
30 void computeInfo(CGFunctionInfo &FI)
const override;
32 RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty,
33 AggValueSlot Slot)
const override;
34 Address EmitVAArgFromMemory(CodeGenFunction &CFG, Address VAListAddr,
36 Address EmitVAArgForHexagon(CodeGenFunction &CFG, Address VAListAddr,
38 Address EmitVAArgForHexagonLinux(CodeGenFunction &CFG, Address VAListAddr,
44 HexagonTargetCodeGenInfo(CodeGenTypes &CGT)
45 : TargetCodeGenInfo(std::make_unique<HexagonABIInfo>(CGT)) {}
47 int getDwarfEHStackPointer(CodeGen::CodeGenModule &M)
const override {
51 void setTargetAttributes(
const Decl *D, llvm::GlobalValue *GV,
52 CodeGen::CodeGenModule &GCM)
const override {
53 if (GV->isDeclaration())
55 const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D);
64 unsigned RegsLeft = 6;
72 assert(Size <= 64 &&
"Not expecting to pass arguments larger than 64 bits"
73 " through registers");
83 if (2 <= (*RegsLeft & (~1U))) {
84 *RegsLeft = (*RegsLeft & (~1U)) - 2;
96ABIArgInfo HexagonABIInfo::classifyArgumentType(QualType Ty,
97 unsigned *RegsLeft)
const {
101 Ty = ED->getIntegerType();
108 return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace(),
112 : ABIArgInfo::getDirect();
116 return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace(),
124 unsigned Align = getContext().getTypeAlign(Ty);
127 return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace(),
131 Align =
Size <= 32 ? 32 : 64;
134 Size = llvm::bit_ceil(Size);
140ABIArgInfo HexagonABIInfo::classifyReturnType(QualType RetTy)
const {
144 const TargetInfo &
T = CGT.getTarget();
147 if (RetTy->
getAs<VectorType>()) {
149 if (
T.hasFeature(
"hvx")) {
150 assert(
T.hasFeature(
"hvx-length64b") ||
T.hasFeature(
"hvx-length128b"));
151 uint64_t VecSize =
T.hasFeature(
"hvx-length64b") ? 64*8 : 128*8;
152 if (Size == VecSize || Size == 2*VecSize)
157 return getNaturalAlignIndirect(RetTy,
158 getDataLayout().getAllocaAddrSpace());
164 RetTy = ED->getIntegerType();
167 return getNaturalAlignIndirect(
168 RetTy, getDataLayout().getAllocaAddrSpace(),
false);
171 : ABIArgInfo::getDirect();
181 Size = llvm::bit_ceil(Size);
184 return getNaturalAlignIndirect(RetTy, getDataLayout().getAllocaAddrSpace(),
188Address HexagonABIInfo::EmitVAArgFromMemory(CodeGenFunction &CGF,
192 Address __overflow_area_pointer_p =
195 __overflow_area_pointer_p,
"__overflow_area_pointer");
200 assert((Align & (Align - 1)) == 0 &&
"Alignment is not power of 2!");
203 llvm::Value *Offset = llvm::ConstantInt::get(CGF.
Int64Ty, Align - 1);
206 __overflow_area_pointer =
213 llvm::Value *Mask = llvm::ConstantInt::get(CGF.
Int32Ty, -(
int)Align);
214 __overflow_area_pointer = CGF.
Builder.CreateIntToPtr(
215 CGF.
Builder.CreateAnd(AsInt, Mask), __overflow_area_pointer->getType(),
216 "__overflow_area_pointer.align");
229 CGF.
Int8Ty, __overflow_area_pointer,
230 llvm::ConstantInt::get(CGF.
Int32Ty, Offset),
231 "__overflow_area_pointer.next");
237Address HexagonABIInfo::EmitVAArgForHexagon(CodeGenFunction &CGF,
242 CGBuilderTy &Builder = CGF.
Builder;
244 llvm::Value *
Addr = Builder.CreateLoad(VAListAddrAsBPP,
"ap.cur");
248 assert((TyAlign & (TyAlign - 1)) == 0 &&
"Alignment is not power of 2!");
249 llvm::Value *AddrAsInt = Builder.CreatePtrToInt(
Addr, CGF.
Int32Ty);
250 AddrAsInt = Builder.CreateAdd(AddrAsInt, Builder.getInt32(TyAlign - 1));
251 AddrAsInt = Builder.CreateAnd(AddrAsInt, Builder.getInt32(~(TyAlign - 1)));
252 Addr = Builder.CreateIntToPtr(AddrAsInt, BP);
258 llvm::Value *NextAddr = Builder.CreateGEP(
260 Builder.CreateStore(NextAddr, VAListAddrAsBPP);
265Address HexagonABIInfo::EmitVAArgForHexagonLinux(CodeGenFunction &CGF,
271 return EmitVAArgFromMemory(CGF, VAListAddr, Ty);
277 unsigned RegsLeft = 6;
288 ArgSize = (CGF.
getContext().getTypeSize(Ty) <= 32) ? 4 : 8;
289 int ArgAlign = (CGF.
getContext().getTypeSize(Ty) <= 32) ? 4 : 8;
296 VAListAddr, 0,
"__current_saved_reg_area_pointer_p");
298 __current_saved_reg_area_pointer_p,
"__current_saved_reg_area_pointer");
302 VAListAddr, 1,
"__saved_reg_area_end_pointer_p");
304 __saved_reg_area_end_pointer_p,
"__saved_reg_area_end_pointer");
310 llvm::Value *__current_saved_reg_area_pointer_int =
311 CGF.
Builder.CreatePtrToInt(__current_saved_reg_area_pointer,
314 __current_saved_reg_area_pointer_int = CGF.
Builder.CreateAdd(
315 __current_saved_reg_area_pointer_int,
316 llvm::ConstantInt::get(CGF.
Int32Ty, (ArgAlign - 1)),
317 "align_current_saved_reg_area_pointer");
319 __current_saved_reg_area_pointer_int =
320 CGF.
Builder.CreateAnd(__current_saved_reg_area_pointer_int,
321 llvm::ConstantInt::get(CGF.
Int32Ty, -ArgAlign),
322 "align_current_saved_reg_area_pointer");
324 __current_saved_reg_area_pointer =
325 CGF.
Builder.CreateIntToPtr(__current_saved_reg_area_pointer_int,
326 __current_saved_reg_area_pointer->getType(),
327 "align_current_saved_reg_area_pointer");
330 llvm::Value *__new_saved_reg_area_pointer =
332 llvm::ConstantInt::get(CGF.
Int32Ty, ArgSize),
333 "__new_saved_reg_area_pointer");
335 llvm::Value *UsingStack =
nullptr;
336 UsingStack = CGF.
Builder.CreateICmpSGT(__new_saved_reg_area_pointer,
337 __saved_reg_area_end_pointer);
339 CGF.
Builder.CreateCondBr(UsingStack, OnStackBlock, InRegBlock);
346 __current_saved_reg_area_pointer_p);
355 Address __overflow_area_pointer_p =
358 __overflow_area_pointer_p,
"__overflow_area_pointer");
362 llvm::Value *__overflow_area_pointer_int =
365 __overflow_area_pointer_int =
366 CGF.
Builder.CreateAdd(__overflow_area_pointer_int,
367 llvm::ConstantInt::get(CGF.
Int32Ty, ArgAlign - 1),
368 "align_overflow_area_pointer");
370 __overflow_area_pointer_int =
371 CGF.
Builder.CreateAnd(__overflow_area_pointer_int,
372 llvm::ConstantInt::get(CGF.
Int32Ty, -ArgAlign),
373 "align_overflow_area_pointer");
375 __overflow_area_pointer = CGF.
Builder.CreateIntToPtr(
376 __overflow_area_pointer_int, __overflow_area_pointer->getType(),
377 "align_overflow_area_pointer");
383 CGF.
Int8Ty, __overflow_area_pointer,
384 llvm::ConstantInt::get(CGF.
Int32Ty, ArgSize),
385 "__overflow_area_pointer.next");
388 __overflow_area_pointer_p);
391 __current_saved_reg_area_pointer_p);
399 llvm::PHINode *ArgAddr = CGF.
Builder.CreatePHI(
400 llvm::PointerType::getUnqual(MemTy->getContext()), 2,
"vaarg.addr");
401 ArgAddr->addIncoming(__current_saved_reg_area_pointer, InRegBlock);
402 ArgAddr->addIncoming(__overflow_area_pointer, OnStackBlock);
407RValue HexagonABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
408 QualType Ty, AggValueSlot Slot)
const {
410 if (getTarget().getTriple().isMusl())
412 CGF.
MakeAddrLValue(EmitVAArgForHexagonLinux(CGF, VAListAddr, Ty), Ty),
416 CGF.
MakeAddrLValue(EmitVAArgForHexagon(CGF, VAListAddr, Ty), Ty), Slot);
419std::unique_ptr<TargetCodeGenInfo>
421 return std::make_unique<HexagonTargetCodeGenInfo>(CGM.
getTypes());
static bool HexagonAdjustRegsLeft(uint64_t Size, unsigned *RegsLeft)
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
unsigned getTypeAlign(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in bits.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
static ABIArgInfo getIgnore()
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)
static ABIArgInfo getDirectInReg(llvm::Type *T=nullptr)
Address withElementType(llvm::Type *ElemTy) const
Return address with different element type, but same pointer and alignment.
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
Address CreateGEP(CodeGenFunction &CGF, Address Addr, llvm::Value *Index, const llvm::Twine &Name="")
Address CreateStructGEP(Address Addr, unsigned Index, const llvm::Twine &Name="")
llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")
RecordArgABI
Specify how one should pass an argument of a record type.
@ 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()
llvm::Type * ConvertType(QualType T)
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
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)
void EmitBranch(llvm::BasicBlock *Block)
EmitBranch - Emit a branch to the specified basic block from the current insert block,...
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
This class organizes the cross-function state that is used while generating LLVM code.
CodeGenTypes & getTypes()
DefaultABIInfo - The default implementation for ABI specific details.
ABIArgInfo classifyArgumentType(QualType RetTy) const
TargetCodeGenInfo - This class organizes various target-specific codegeneration issues,...
bool isBitIntType() const
EnumDecl * getAsEnumDecl() const
Retrieves the EnumDecl this type refers to.
const T * getAs() const
Member-template getAs<specific type>'.
ABIArgInfo classifyArgumentType(CodeGenModule &CGM, CanQualType type)
Classify the rules for how to pass a particular type.
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
CGCXXABI::RecordArgABI getRecordArgABI(const RecordType *RT, CGCXXABI &CXXABI)
bool classifyReturnType(const CGCXXABI &CXXABI, CGFunctionInfo &FI, const ABIInfo &Info)
std::unique_ptr< TargetCodeGenInfo > createHexagonTargetCodeGenInfo(CodeGenModule &CGM)
bool isAggregateTypeForABI(QualType T)
bool isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays, bool AsIfNoUniqueAddr=false)
isEmptyRecord - Return true iff a structure contains only empty fields.
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
llvm::IntegerType * Int64Ty
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
llvm::IntegerType * Int32Ty
llvm::PointerType * Int8PtrTy