Skip to content

Commit 9ff1d0d

Browse files
committed
Extend Indirect Args to carry an address space.
1 parent 5ccd554 commit 9ff1d0d

File tree

11 files changed

+30
-24
lines changed

11 files changed

+30
-24
lines changed

clang/include/clang/CodeGen/CGFunctionInfo.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,16 @@ class ABIArgInfo {
206206
static ABIArgInfo getIgnore() {
207207
return ABIArgInfo(Ignore);
208208
}
209-
static ABIArgInfo getIndirect(CharUnits Alignment, bool ByVal = true,
210-
bool Realign = false,
209+
static ABIArgInfo getIndirect(CharUnits Alignment, unsigned AddrSpace = 0,
210+
bool ByVal = true, bool Realign = false,
211211
llvm::Type *Padding = nullptr) {
212212
auto AI = ABIArgInfo(Indirect);
213213
AI.setIndirectAlign(Alignment);
214214
AI.setIndirectByVal(ByVal);
215215
AI.setIndirectRealign(Realign);
216216
AI.setSRetAfterThis(false);
217217
AI.setPaddingType(Padding);
218+
AI.setIndirectAddrSpace(AddrSpace);
218219
return AI;
219220
}
220221

@@ -232,7 +233,7 @@ class ABIArgInfo {
232233

233234
static ABIArgInfo getIndirectInReg(CharUnits Alignment, bool ByVal = true,
234235
bool Realign = false) {
235-
auto AI = getIndirect(Alignment, ByVal, Realign);
236+
auto AI = getIndirect(Alignment, 0, ByVal, Realign);
236237
AI.setInReg(true);
237238
return AI;
238239
}
@@ -422,12 +423,12 @@ class ABIArgInfo {
422423
}
423424

424425
unsigned getIndirectAddrSpace() const {
425-
assert(isIndirectAliased() && "Invalid kind!");
426+
assert((isIndirect() || isIndirectAliased()) && "Invalid kind!");
426427
return IndirectAttr.AddrSpace;
427428
}
428429

429430
void setIndirectAddrSpace(unsigned AddrSpace) {
430-
assert(isIndirectAliased() && "Invalid kind!");
431+
assert((isIndirect() || isIndirectAliased()) && "Invalid kind!");
431432
IndirectAttr.AddrSpace = AddrSpace;
432433
}
433434

clang/lib/CodeGen/ABIInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ bool ABIInfo::isPromotableIntegerTypeForABI(QualType Ty) const {
174174
ABIArgInfo ABIInfo::getNaturalAlignIndirect(QualType Ty, bool ByVal,
175175
bool Realign,
176176
llvm::Type *Padding) const {
177-
return ABIArgInfo::getIndirect(getContext().getTypeAlignInChars(Ty), ByVal,
177+
return ABIArgInfo::getIndirect(getContext().getTypeAlignInChars(Ty), 0, ByVal,
178178
Realign, Padding);
179179
}
180180

clang/lib/CodeGen/ItaniumCXXABI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,7 @@ bool ItaniumCXXABI::classifyReturnType(CGFunctionInfo &FI) const {
13511351
// If C++ prohibits us from making a copy, return by address.
13521352
if (!RD->canPassInRegisters()) {
13531353
auto Align = CGM.getContext().getTypeAlignInChars(FI.getReturnType());
1354-
FI.getReturnInfo() = ABIArgInfo::getIndirect(Align, /*ByVal=*/false);
1354+
FI.getReturnInfo() = ABIArgInfo::getIndirect(Align, 0, /*ByVal=*/false);
13551355
return true;
13561356
}
13571357
return false;

clang/lib/CodeGen/MicrosoftCXXABI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ bool MicrosoftCXXABI::classifyReturnType(CGFunctionInfo &FI) const {
11711171

11721172
if (isIndirectReturn) {
11731173
CharUnits Align = CGM.getContext().getTypeAlignInChars(FI.getReturnType());
1174-
FI.getReturnInfo() = ABIArgInfo::getIndirect(Align, /*ByVal=*/false);
1174+
FI.getReturnInfo() = ABIArgInfo::getIndirect(Align, 0, /*ByVal=*/false);
11751175

11761176
// MSVC always passes `this` before the `sret` parameter.
11771177
FI.getReturnInfo().setSRetAfterThis(FI.isInstanceMethod());

clang/lib/CodeGen/SwiftCallingConv.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ static ABIArgInfo classifyExpandedType(SwiftAggLowering &lowering,
801801
if (lowering.empty()) {
802802
return ABIArgInfo::getIgnore();
803803
} else if (lowering.shouldPassIndirectly(forReturn)) {
804-
return ABIArgInfo::getIndirect(alignmentForIndirect, /*byval*/ false);
804+
return ABIArgInfo::getIndirect(alignmentForIndirect, 0, /*byval*/ false);
805805
} else {
806806
auto types = lowering.getCoerceAndExpandTypes();
807807
return ABIArgInfo::getCoerceAndExpand(types.first, types.second);
@@ -815,7 +815,7 @@ static ABIArgInfo classifyType(CodeGenModule &CGM, CanQualType type,
815815
auto &layout = CGM.getContext().getASTRecordLayout(record);
816816

817817
if (mustPassRecordIndirectly(CGM, record))
818-
return ABIArgInfo::getIndirect(layout.getAlignment(), /*byval*/ false);
818+
return ABIArgInfo::getIndirect(layout.getAlignment(), 0, /*byval*/ false);
819819

820820
SwiftAggLowering lowering(CGM);
821821
lowering.addTypedData(recordType->getDecl(), CharUnits::Zero(), layout);

clang/lib/CodeGen/Targets/AMDGPU.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ void AMDGPUABIInfo::computeInfo(CGFunctionInfo &FI) const {
105105
if (!getCXXABI().classifyReturnType(FI))
106106
FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
107107

108+
// srets / indirect returns are unconditionally in the alloca AS.
109+
if (FI.getReturnInfo().isIndirect())
110+
FI.getReturnInfo().setIndirectAddrSpace(
111+
getDataLayout().getAllocaAddrSpace());
112+
108113
unsigned ArgumentIndex = 0;
109114
const unsigned numFixedArguments = FI.getNumRequiredArgs();
110115

clang/lib/CodeGen/Targets/ARC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ ABIArgInfo ARCABIInfo::getIndirectByValue(QualType Ty) const {
7777
// Compute the byval alignment.
7878
const unsigned MinABIStackAlignInBytes = 4;
7979
unsigned TypeAlign = getContext().getTypeAlign(Ty) / 8;
80-
return ABIArgInfo::getIndirect(CharUnits::fromQuantity(4), /*ByVal=*/true,
80+
return ABIArgInfo::getIndirect(CharUnits::fromQuantity(4), 0, /*ByVal=*/true,
8181
TypeAlign > MinABIStackAlignInBytes);
8282
}
8383

clang/lib/CodeGen/Targets/ARM.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ ABIArgInfo ARMABIInfo::classifyArgumentType(QualType Ty, bool isVariadic,
397397
// bigger than 128-bits, they get placed in space allocated by the caller,
398398
// and a pointer is passed.
399399
return ABIArgInfo::getIndirect(
400-
CharUnits::fromQuantity(getContext().getTypeAlign(Ty) / 8), false);
400+
CharUnits::fromQuantity(getContext().getTypeAlign(Ty) / 8), 0, false);
401401
}
402402

403403
// Support byval for ARM.
@@ -415,7 +415,7 @@ ABIArgInfo ARMABIInfo::classifyArgumentType(QualType Ty, bool isVariadic,
415415
}
416416
if (getContext().getTypeSizeInChars(Ty) > CharUnits::fromQuantity(64)) {
417417
assert(getABIKind() != ARMABIKind::AAPCS16_VFP && "unexpected byval");
418-
return ABIArgInfo::getIndirect(CharUnits::fromQuantity(ABIAlign),
418+
return ABIArgInfo::getIndirect(CharUnits::fromQuantity(ABIAlign), 0,
419419
/*ByVal=*/true,
420420
/*Realign=*/TyAlign > ABIAlign);
421421
}

clang/lib/CodeGen/Targets/Lanai.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ ABIArgInfo LanaiABIInfo::getIndirectResult(QualType Ty, bool ByVal,
7878
// Compute the byval alignment.
7979
const unsigned MinABIStackAlignInBytes = 4;
8080
unsigned TypeAlign = getContext().getTypeAlign(Ty) / 8;
81-
return ABIArgInfo::getIndirect(CharUnits::fromQuantity(4), /*ByVal=*/true,
81+
return ABIArgInfo::getIndirect(CharUnits::fromQuantity(4), 0, /*ByVal=*/true,
8282
/*Realign=*/TypeAlign >
8383
MinABIStackAlignInBytes);
8484
}

clang/lib/CodeGen/Targets/PPC.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ ABIArgInfo AIXABIInfo::classifyArgumentType(QualType Ty) const {
213213
CharUnits CCAlign = getParamTypeAlignment(Ty);
214214
CharUnits TyAlign = getContext().getTypeAlignInChars(Ty);
215215

216-
return ABIArgInfo::getIndirect(CCAlign, /*ByVal*/ true,
216+
return ABIArgInfo::getIndirect(CCAlign, 0, /*ByVal*/ true,
217217
/*Realign*/ TyAlign > CCAlign);
218218
}
219219

@@ -887,7 +887,7 @@ PPC64_SVR4_ABIInfo::classifyArgumentType(QualType Ty) const {
887887
}
888888

889889
// All other aggregates are passed ByVal.
890-
return ABIArgInfo::getIndirect(CharUnits::fromQuantity(ABIAlign),
890+
return ABIArgInfo::getIndirect(CharUnits::fromQuantity(ABIAlign), 0,
891891
/*ByVal=*/true,
892892
/*Realign=*/TyAlign > ABIAlign);
893893
}

0 commit comments

Comments
 (0)