Skip to content

Commit e6642f1

Browse files
bcardosolopeslanza
authored andcommitted
[CIR][NFC] Move code around to match OG
1 parent 89ebcb1 commit e6642f1

File tree

2 files changed

+82
-98
lines changed

2 files changed

+82
-98
lines changed

clang/lib/CIR/CodeGen/CIRGenClass.cpp

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,3 +1810,85 @@ void CIRGenFunction::buildCXXAggrConstructorCall(
18101810
if (constantCount.use_empty())
18111811
constantCount.erase();
18121812
}
1813+
1814+
void CIRGenFunction::buildCXXConstructorCall(const clang::CXXConstructorDecl *D,
1815+
clang::CXXCtorType Type,
1816+
bool ForVirtualBase,
1817+
bool Delegating,
1818+
AggValueSlot ThisAVS,
1819+
const clang::CXXConstructExpr *E) {
1820+
CallArgList Args;
1821+
Address This = ThisAVS.getAddress();
1822+
LangAS SlotAS = ThisAVS.getQualifiers().getAddressSpace();
1823+
QualType ThisType = D->getThisType();
1824+
LangAS ThisAS = ThisType.getTypePtr()->getPointeeType().getAddressSpace();
1825+
mlir::Value ThisPtr = This.getPointer();
1826+
1827+
assert(SlotAS == ThisAS && "This edge case NYI");
1828+
1829+
Args.add(RValue::get(ThisPtr), D->getThisType());
1830+
1831+
// In LLVM Codegen: If this is a trivial constructor, just emit what's needed.
1832+
// If this is a union copy constructor, we must emit a memcpy, because the AST
1833+
// does not model that copy.
1834+
if (isMemcpyEquivalentSpecialMember(D)) {
1835+
assert(!MissingFeatures::isMemcpyEquivalentSpecialMember());
1836+
}
1837+
1838+
const FunctionProtoType *FPT = D->getType()->castAs<FunctionProtoType>();
1839+
EvaluationOrder Order = E->isListInitialization()
1840+
? EvaluationOrder::ForceLeftToRight
1841+
: EvaluationOrder::Default;
1842+
1843+
buildCallArgs(Args, FPT, E->arguments(), E->getConstructor(),
1844+
/*ParamsToSkip*/ 0, Order);
1845+
1846+
buildCXXConstructorCall(D, Type, ForVirtualBase, Delegating, This, Args,
1847+
ThisAVS.mayOverlap(), E->getExprLoc(),
1848+
ThisAVS.isSanitizerChecked());
1849+
}
1850+
1851+
void CIRGenFunction::buildCXXConstructorCall(
1852+
const CXXConstructorDecl *D, CXXCtorType Type, bool ForVirtualBase,
1853+
bool Delegating, Address This, CallArgList &Args,
1854+
AggValueSlot::Overlap_t Overlap, SourceLocation Loc,
1855+
bool NewPointerIsChecked) {
1856+
1857+
const auto *ClassDecl = D->getParent();
1858+
1859+
if (!NewPointerIsChecked)
1860+
buildTypeCheck(CIRGenFunction::TCK_ConstructorCall, Loc, This.getPointer(),
1861+
getContext().getRecordType(ClassDecl), CharUnits::Zero());
1862+
1863+
// If this is a call to a trivial default constructor:
1864+
// In LLVM: do nothing.
1865+
// In CIR: emit as a regular call, other later passes should lower the
1866+
// ctor call into trivial initialization.
1867+
assert(!MissingFeatures::isTrivialCtorOrDtor());
1868+
1869+
if (isMemcpyEquivalentSpecialMember(D)) {
1870+
assert(!MissingFeatures::isMemcpyEquivalentSpecialMember());
1871+
}
1872+
1873+
bool PassPrototypeArgs = true;
1874+
1875+
assert(!D->getInheritedConstructor() && "inheritance NYI");
1876+
1877+
// Insert any ABI-specific implicit constructor arguments.
1878+
CIRGenCXXABI::AddedStructorArgCounts ExtraArgs =
1879+
CGM.getCXXABI().addImplicitConstructorArgs(*this, D, Type, ForVirtualBase,
1880+
Delegating, Args);
1881+
1882+
// Emit the call.
1883+
auto CalleePtr = CGM.getAddrOfCXXStructor(GlobalDecl(D, Type));
1884+
const CIRGenFunctionInfo &Info = CGM.getTypes().arrangeCXXConstructorCall(
1885+
Args, D, Type, ExtraArgs.Prefix, ExtraArgs.Suffix, PassPrototypeArgs);
1886+
CIRGenCallee Callee = CIRGenCallee::forDirect(CalleePtr, GlobalDecl(D, Type));
1887+
mlir::cir::CIRCallOpInterface C;
1888+
buildCall(Info, Callee, ReturnValueSlot(), Args, &C, false, getLoc(Loc));
1889+
1890+
assert(CGM.getCodeGenOpts().OptimizationLevel == 0 ||
1891+
ClassDecl->isDynamicClass() || Type == Ctor_Base ||
1892+
!CGM.getCodeGenOpts().StrictVTablePointers &&
1893+
"vtable assumption loads NYI");
1894+
}

clang/lib/CIR/CodeGen/CIRGenFunction.cpp

Lines changed: 0 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -747,104 +747,6 @@ mlir::Value CIRGenFunction::createLoad(const VarDecl *VD, const char *Name) {
747747
addr.getElementType(), addr.getPointer());
748748
}
749749

750-
static bool isMemcpyEquivalentSpecialMember(const CXXMethodDecl *D) {
751-
auto *CD = llvm::dyn_cast<CXXConstructorDecl>(D);
752-
if (!(CD && CD->isCopyOrMoveConstructor()) &&
753-
!D->isCopyAssignmentOperator() && !D->isMoveAssignmentOperator())
754-
return false;
755-
756-
// We can emit a memcpy for a trivial copy or move constructor/assignment
757-
if (D->isTrivial() && !D->getParent()->mayInsertExtraPadding())
758-
return true;
759-
760-
if (D->getParent()->isUnion() && D->isDefaulted())
761-
return true;
762-
763-
return false;
764-
}
765-
766-
void CIRGenFunction::buildCXXConstructorCall(const clang::CXXConstructorDecl *D,
767-
clang::CXXCtorType Type,
768-
bool ForVirtualBase,
769-
bool Delegating,
770-
AggValueSlot ThisAVS,
771-
const clang::CXXConstructExpr *E) {
772-
CallArgList Args;
773-
Address This = ThisAVS.getAddress();
774-
LangAS SlotAS = ThisAVS.getQualifiers().getAddressSpace();
775-
QualType ThisType = D->getThisType();
776-
LangAS ThisAS = ThisType.getTypePtr()->getPointeeType().getAddressSpace();
777-
mlir::Value ThisPtr = This.getPointer();
778-
779-
assert(SlotAS == ThisAS && "This edge case NYI");
780-
781-
Args.add(RValue::get(ThisPtr), D->getThisType());
782-
783-
// In LLVM Codegen: If this is a trivial constructor, just emit what's needed.
784-
// If this is a union copy constructor, we must emit a memcpy, because the AST
785-
// does not model that copy.
786-
if (isMemcpyEquivalentSpecialMember(D)) {
787-
assert(!MissingFeatures::isMemcpyEquivalentSpecialMember());
788-
}
789-
790-
const FunctionProtoType *FPT = D->getType()->castAs<FunctionProtoType>();
791-
EvaluationOrder Order = E->isListInitialization()
792-
? EvaluationOrder::ForceLeftToRight
793-
: EvaluationOrder::Default;
794-
795-
buildCallArgs(Args, FPT, E->arguments(), E->getConstructor(),
796-
/*ParamsToSkip*/ 0, Order);
797-
798-
buildCXXConstructorCall(D, Type, ForVirtualBase, Delegating, This, Args,
799-
ThisAVS.mayOverlap(), E->getExprLoc(),
800-
ThisAVS.isSanitizerChecked());
801-
}
802-
803-
void CIRGenFunction::buildCXXConstructorCall(
804-
const CXXConstructorDecl *D, CXXCtorType Type, bool ForVirtualBase,
805-
bool Delegating, Address This, CallArgList &Args,
806-
AggValueSlot::Overlap_t Overlap, SourceLocation Loc,
807-
bool NewPointerIsChecked) {
808-
809-
const auto *ClassDecl = D->getParent();
810-
811-
if (!NewPointerIsChecked)
812-
buildTypeCheck(CIRGenFunction::TCK_ConstructorCall, Loc, This.getPointer(),
813-
getContext().getRecordType(ClassDecl), CharUnits::Zero());
814-
815-
// If this is a call to a trivial default constructor:
816-
// In LLVM: do nothing.
817-
// In CIR: emit as a regular call, other later passes should lower the
818-
// ctor call into trivial initialization.
819-
assert(!MissingFeatures::isTrivialCtorOrDtor());
820-
821-
if (isMemcpyEquivalentSpecialMember(D)) {
822-
assert(!MissingFeatures::isMemcpyEquivalentSpecialMember());
823-
}
824-
825-
bool PassPrototypeArgs = true;
826-
827-
assert(!D->getInheritedConstructor() && "inheritance NYI");
828-
829-
// Insert any ABI-specific implicit constructor arguments.
830-
CIRGenCXXABI::AddedStructorArgCounts ExtraArgs =
831-
CGM.getCXXABI().addImplicitConstructorArgs(*this, D, Type, ForVirtualBase,
832-
Delegating, Args);
833-
834-
// Emit the call.
835-
auto CalleePtr = CGM.getAddrOfCXXStructor(GlobalDecl(D, Type));
836-
const CIRGenFunctionInfo &Info = CGM.getTypes().arrangeCXXConstructorCall(
837-
Args, D, Type, ExtraArgs.Prefix, ExtraArgs.Suffix, PassPrototypeArgs);
838-
CIRGenCallee Callee = CIRGenCallee::forDirect(CalleePtr, GlobalDecl(D, Type));
839-
mlir::cir::CIRCallOpInterface C;
840-
buildCall(Info, Callee, ReturnValueSlot(), Args, &C, false, getLoc(Loc));
841-
842-
assert(CGM.getCodeGenOpts().OptimizationLevel == 0 ||
843-
ClassDecl->isDynamicClass() || Type == Ctor_Base ||
844-
!CGM.getCodeGenOpts().StrictVTablePointers &&
845-
"vtable assumption loads NYI");
846-
}
847-
848750
void CIRGenFunction::buildConstructorBody(FunctionArgList &Args) {
849751
// TODO: EmitAsanPrologueOrEpilogue(true);
850752
const auto *Ctor = cast<CXXConstructorDecl>(CurGD.getDecl());

0 commit comments

Comments
 (0)