10#include "TargetInfo.h"
11#include "llvm/ADT/StringExtras.h"
24 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 auto *
Fn = dyn_cast<llvm::Function>(GV);
58 const auto *FD = dyn_cast_or_null<FunctionDecl>(D);
60 if (
const auto *Attr =
61 FD ? FD->getAttr<HexagonHLXVectorStackLimitAttr>() :
nullptr)
62 Fn->addFnAttr(
"hlx-vector-stack-limit", llvm::utostr(Attr->getLimit()));
64 Fn->addFnAttr(
"hlx-vector-stack-limit", llvm::utostr(Limit));
71 unsigned RegsLeft = 6;
79 assert(Size <= 64 &&
"Not expecting to pass arguments larger than 64 bits"
80 " through registers");
90 if (2 <= (*RegsLeft & (~1U))) {
91 *RegsLeft = (*RegsLeft & (~1U)) - 2;
103ABIArgInfo HexagonABIInfo::classifyArgumentType(QualType Ty,
104 unsigned *RegsLeft)
const {
108 Ty = ED->getIntegerType();
115 return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace(),
119 : ABIArgInfo::getDirect();
123 return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace(),
131 unsigned Align = getContext().getTypeAlign(Ty);
134 return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace(),
138 Align =
Size <= 32 ? 32 : 64;
141 Size = llvm::bit_ceil(Size);
147ABIArgInfo HexagonABIInfo::classifyReturnType(QualType RetTy)
const {
151 const TargetInfo &
T = CGT.getTarget();
154 if (RetTy->
getAs<VectorType>()) {
156 if (
T.hasFeature(
"hvx")) {
157 assert(
T.hasFeature(
"hvx-length64b") ||
T.hasFeature(
"hvx-length128b"));
158 uint64_t VecSize =
T.hasFeature(
"hvx-length64b") ? 64*8 : 128*8;
159 if (Size == VecSize || Size == 2*VecSize)
163 if (
T.hasFeature(
"hlx")) {
165 if (Size == VecSize || Size == 2 * VecSize)
170 return getNaturalAlignIndirect(RetTy,
171 getDataLayout().getAllocaAddrSpace());
177 RetTy = ED->getIntegerType();
180 return getNaturalAlignIndirect(
181 RetTy, getDataLayout().getAllocaAddrSpace(),
false);
184 : ABIArgInfo::getDirect();
194 Size = llvm::bit_ceil(Size);
197 return getNaturalAlignIndirect(RetTy, getDataLayout().getAllocaAddrSpace(),
201Address HexagonABIInfo::EmitVAArgFromMemory(CodeGenFunction &CGF,
205 Address __overflow_area_pointer_p =
208 __overflow_area_pointer_p,
"__overflow_area_pointer");
213 assert((Align & (Align - 1)) == 0 &&
"Alignment is not power of 2!");
216 llvm::Value *Offset = llvm::ConstantInt::get(CGF.
Int64Ty, Align - 1);
219 __overflow_area_pointer =
226 llvm::Value *Mask = llvm::ConstantInt::getSigned(CGF.
Int32Ty, -(
int)Align);
227 __overflow_area_pointer = CGF.
Builder.CreateIntToPtr(
228 CGF.
Builder.CreateAnd(AsInt, Mask), __overflow_area_pointer->getType(),
229 "__overflow_area_pointer.align");
242 CGF.
Int8Ty, __overflow_area_pointer,
243 llvm::ConstantInt::get(CGF.
Int32Ty, Offset),
244 "__overflow_area_pointer.next");
250Address HexagonABIInfo::EmitVAArgForHexagon(CodeGenFunction &CGF,
255 CGBuilderTy &Builder = CGF.
Builder;
257 llvm::Value *
Addr = Builder.CreateLoad(VAListAddrAsBPP,
"ap.cur");
261 assert((TyAlign & (TyAlign - 1)) == 0 &&
"Alignment is not power of 2!");
262 llvm::Value *AddrAsInt = Builder.CreatePtrToInt(
Addr, CGF.
Int32Ty);
263 AddrAsInt = Builder.CreateAdd(AddrAsInt, Builder.getInt32(TyAlign - 1));
264 AddrAsInt = Builder.CreateAnd(AddrAsInt, Builder.getInt32(~(TyAlign - 1)));
265 Addr = Builder.CreateIntToPtr(AddrAsInt, BP);
271 llvm::Value *NextAddr = Builder.CreateGEP(
273 Builder.CreateStore(NextAddr, VAListAddrAsBPP);
278Address HexagonABIInfo::EmitVAArgForHexagonLinux(CodeGenFunction &CGF,
284 return EmitVAArgFromMemory(CGF, VAListAddr, Ty);
290 unsigned RegsLeft = 6;
301 ArgSize = (CGF.
getContext().getTypeSize(Ty) <= 32) ? 4 : 8;
302 int ArgAlign = (CGF.
getContext().getTypeSize(Ty) <= 32) ? 4 : 8;
309 VAListAddr, 0,
"__current_saved_reg_area_pointer_p");
311 __current_saved_reg_area_pointer_p,
"__current_saved_reg_area_pointer");
315 VAListAddr, 1,
"__saved_reg_area_end_pointer_p");
317 __saved_reg_area_end_pointer_p,
"__saved_reg_area_end_pointer");
323 llvm::Value *__current_saved_reg_area_pointer_int =
324 CGF.
Builder.CreatePtrToInt(__current_saved_reg_area_pointer,
327 __current_saved_reg_area_pointer_int = CGF.
Builder.CreateAdd(
328 __current_saved_reg_area_pointer_int,
329 llvm::ConstantInt::get(CGF.
Int32Ty, (ArgAlign - 1)),
330 "align_current_saved_reg_area_pointer");
332 __current_saved_reg_area_pointer_int = CGF.
Builder.CreateAnd(
333 __current_saved_reg_area_pointer_int,
334 llvm::ConstantInt::getSigned(CGF.
Int32Ty, -ArgAlign),
335 "align_current_saved_reg_area_pointer");
337 __current_saved_reg_area_pointer =
338 CGF.
Builder.CreateIntToPtr(__current_saved_reg_area_pointer_int,
339 __current_saved_reg_area_pointer->getType(),
340 "align_current_saved_reg_area_pointer");
343 llvm::Value *__new_saved_reg_area_pointer =
345 llvm::ConstantInt::get(CGF.
Int32Ty, ArgSize),
346 "__new_saved_reg_area_pointer");
348 llvm::Value *UsingStack =
nullptr;
349 UsingStack = CGF.
Builder.CreateICmpSGT(__new_saved_reg_area_pointer,
350 __saved_reg_area_end_pointer);
352 CGF.
Builder.CreateCondBr(UsingStack, OnStackBlock, InRegBlock);
359 __current_saved_reg_area_pointer_p);
368 Address __overflow_area_pointer_p =
371 __overflow_area_pointer_p,
"__overflow_area_pointer");
375 llvm::Value *__overflow_area_pointer_int =
378 __overflow_area_pointer_int =
379 CGF.
Builder.CreateAdd(__overflow_area_pointer_int,
380 llvm::ConstantInt::get(CGF.
Int32Ty, ArgAlign - 1),
381 "align_overflow_area_pointer");
383 __overflow_area_pointer_int = CGF.
Builder.CreateAnd(
384 __overflow_area_pointer_int,
385 llvm::ConstantInt::getSigned(CGF.
Int32Ty, -ArgAlign),
386 "align_overflow_area_pointer");
388 __overflow_area_pointer = CGF.
Builder.CreateIntToPtr(
389 __overflow_area_pointer_int, __overflow_area_pointer->getType(),
390 "align_overflow_area_pointer");
396 CGF.
Int8Ty, __overflow_area_pointer,
397 llvm::ConstantInt::get(CGF.
Int32Ty, ArgSize),
398 "__overflow_area_pointer.next");
401 __overflow_area_pointer_p);
404 __current_saved_reg_area_pointer_p);
412 llvm::PHINode *ArgAddr = CGF.
Builder.CreatePHI(
413 llvm::PointerType::getUnqual(MemTy->getContext()), 2,
"vaarg.addr");
414 ArgAddr->addIncoming(__current_saved_reg_area_pointer, InRegBlock);
415 ArgAddr->addIncoming(__overflow_area_pointer, OnStackBlock);
420RValue HexagonABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
421 QualType Ty, AggValueSlot Slot)
const {
425 CGF.
MakeAddrLValue(EmitVAArgForHexagonLinux(CGF, VAListAddr, Ty), Ty),
429 CGF.
MakeAddrLValue(EmitVAArgForHexagon(CGF, VAListAddr, Ty), Ty), Slot);
432std::unique_ptr<TargetCodeGenInfo>
434 return std::make_unique<HexagonTargetCodeGenInfo>(CGM.
getTypes());
static bool HexagonAdjustRegsLeft(uint64_t Size, unsigned *RegsLeft)
static StringRef getTriple(const Command &Job)
static CanQualType getCanonicalType(QualType T)
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)
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, llvm::Type *Padding=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()
const CodeGenOptions & getCodeGenOpts() const
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.
@ Address
A pointer to a ValueDecl.
Top level wrappers for InstallAPI frontend operations.
const FunctionProtoType * T
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t uint64_t __builtin_riscv_ssha_i32 __builtin_riscv_sshl_u32 uint64_t
llvm::IntegerType * Int64Ty
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
llvm::IntegerType * Int32Ty
llvm::PointerType * Int8PtrTy