Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CIR] [Lowering] [X86_64] VaArg for long double in x86 #1087

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/include/clang/CIR/ABIArgInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ class ABIArgInfo {
bool isExpand() const { return TheKind == Expand; }
bool isCoerceAndExpand() const { return TheKind == CoerceAndExpand; }

bool isIgnore() const { return TheKind == Ignore; }

bool isSignExt() const {
assert(isExtend() && "Invalid kind!");
return SignExt;
Expand Down
11 changes: 11 additions & 0 deletions clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
getAttr<mlir::cir::IntAttr>(ty, val));
}

mlir::Value getSignedInt(mlir::Location loc, int64_t val, unsigned numBits) {
return getConstAPSInt(
loc, llvm::APSInt(llvm::APInt(numBits, val), /*isUnsigned=*/false));
}

mlir::Value getUnsignedInt(mlir::Location loc, uint64_t val,
unsigned numBits) {
return getConstAPSInt(
loc, llvm::APSInt(llvm::APInt(numBits, val), /*isUnsigned=*/true));
}

mlir::Value getConstAPInt(mlir::Location loc, mlir::Type typ,
const llvm::APInt &val) {
return create<mlir::cir::ConstantOp>(loc, typ,
Expand Down
9 changes: 8 additions & 1 deletion clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,16 @@ struct LoweringPreparePass : public LoweringPrepareBase<LoweringPreparePass> {

void setASTContext(clang::ASTContext *c) {
astCtx = c;
auto abiStr = c->getTargetInfo().getABI();
const clang::TargetInfo &target = c->getTargetInfo();
auto abiStr = target.getABI();
switch (c->getCXXABIKind()) {
case clang::TargetCXXABI::GenericItanium:
if (target.getTriple().getArch() == llvm::Triple::x86_64) {
cxxABI.reset(
::cir::LoweringPrepareCXXABI::createX86ABI(/*is64bit=*/true));
break;
}

cxxABI.reset(::cir::LoweringPrepareCXXABI::createItaniumABI());
break;
case clang::TargetCXXABI::GenericAArch64:
Expand Down
1 change: 1 addition & 0 deletions clang/lib/CIR/Dialect/Transforms/LoweringPrepareCXXABI.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class LoweringPrepareCXXABI {
public:
static LoweringPrepareCXXABI *createItaniumABI();
static LoweringPrepareCXXABI *createAArch64ABI(::cir::AArch64ABIKind k);
static LoweringPrepareCXXABI *createX86ABI(bool is64Bit);

virtual mlir::Value lowerVAArg(CIRBaseBuilderTy &builder,
mlir::cir::VAArgOp op,
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,12 @@ CIRCXXABI::RecordArgABI getRecordArgABI(const StructType RT,
return CXXABI.getRecordArgABI(RT);
}

CIRCXXABI::RecordArgABI getRecordArgABI(mlir::Type ty, CIRCXXABI &CXXABI) {
auto sTy = dyn_cast<StructType>(ty);
if (!sTy)
return CIRCXXABI::RAA_Default;
return getRecordArgABI(sTy, CXXABI);
}

} // namespace cir
} // namespace mlir
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ bool isAggregateTypeForABI(Type T);
Type useFirstFieldIfTransparentUnion(Type Ty);

CIRCXXABI::RecordArgABI getRecordArgABI(const StructType RT, CIRCXXABI &CXXABI);
CIRCXXABI::RecordArgABI getRecordArgABI(mlir::Type ty, CIRCXXABI &CXXABI);

} // namespace cir
} // namespace mlir
Expand Down
20 changes: 0 additions & 20 deletions clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRCXXABI.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,4 @@ CIRCXXABI *CreateItaniumCXXABI(LowerModule &CGM);
} // namespace cir
} // namespace mlir

// FIXME(cir): Merge this into the CIRCXXABI class above. To do so, this code
// should be updated to follow some level of codegen parity.
namespace cir {

class LoweringPrepareCXXABI {
public:
static LoweringPrepareCXXABI *createItaniumABI();
static LoweringPrepareCXXABI *createAArch64ABI(::cir::AArch64ABIKind k);

virtual mlir::Value lowerVAArg(CIRBaseBuilderTy &builder,
mlir::cir::VAArgOp op,
const cir::CIRDataLayout &datalayout) = 0;
virtual ~LoweringPrepareCXXABI() {}

virtual mlir::Value lowerDynamicCast(CIRBaseBuilderTy &builder,
clang::ASTContext &astCtx,
mlir::cir::DynamicCastOp op) = 0;
};
} // namespace cir

#endif // LLVM_CLANG_LIB_CIR_DIALECT_TRANSFORMS_TARGETLOWERING_CIRCXXABI_H
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ clang::TypeInfo CIRLowerContext::getTypeInfoImpl(const Type T) const {
Align = Target->getDoubleAlign();
break;
}
if (auto longDoubleTy = dyn_cast<LongDoubleType>(T)) {
if (getLangOpts().OpenMP && getLangOpts().OpenMPIsTargetDevice &&
(Target->getLongDoubleWidth() != AuxTarget->getLongDoubleWidth() ||
Target->getLongDoubleAlign() != AuxTarget->getLongDoubleAlign())) {
Width = AuxTarget->getLongDoubleWidth();
Align = AuxTarget->getLongDoubleAlign();
} else {
Width = Target->getLongDoubleWidth();
Align = Target->getLongDoubleAlign();
}
break;
}
cir_cconv_unreachable("Unknown builtin type!");
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ add_clang_library(TargetLowering
Targets/X86.cpp
Targets/LoweringPrepareAArch64CXXABI.cpp
Targets/LoweringPrepareItaniumCXXABI.cpp
Targets/LoweringPrepareX86CXXABI.cpp

DEPENDS
clangBasic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
//
//===----------------------------------------------------------------------===//

#include "../LoweringPrepareCXXABI.h"
#include "CIRCXXABI.h"
#include "LowerModule.h"
#include "llvm/Support/ErrorHandling.h"
Expand Down
Loading