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] Support VAArg in shape #1100

Merged
merged 1 commit into from
Nov 13, 2024
Merged
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 @@ -252,6 +252,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 @@ -48,6 +48,17 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
return create<cir::ConstantOp>(loc, ty, getAttr<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<cir::ConstantOp>(loc, typ, getAttr<cir::IntAttr>(typ, val));
Expand Down
20 changes: 20 additions & 0 deletions clang/include/clang/CIR/Dialect/IR/CIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -4485,6 +4485,26 @@ def AssumeSepStorageOp : CIR_Op<"assume.separate_storage", [SameTypeOperands]> {
}];
}

//===----------------------------------------------------------------------===//
// PtrMask Operations
//===----------------------------------------------------------------------===//

def PtrMaskOp : CIR_Op<"ptr_mask", [AllTypesMatch<["ptr", "result"]>]> {
let summary = "Masks out bits of the pointer according to a mask";
let description = [{
The `cir.ptr_mask` operation takes a pointer and an interger `mask` as its
argument and return the masked pointer type according to the `mask`.
}];

let arguments = (ins CIR_PointerType:$ptr,
CIR_IntType:$mask);
let results = (outs CIR_PointerType:$result);
bcardosolopes marked this conversation as resolved.
Show resolved Hide resolved

let assemblyFormat = [{
`(` $ptr `,` $mask `:` type($mask) `)` `:` qualified(type($result)) attr-dict
}];
}

//===----------------------------------------------------------------------===//
// Branch Probability Operations
//===----------------------------------------------------------------------===//
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 @@ -124,9 +124,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, cir::VAArgOp op,
const cir::CIRDataLayout &datalayout) = 0;
Expand Down
Empty file.
12 changes: 12 additions & 0 deletions clang/lib/CIR/Dialect/Transforms/TargetLowering/ABIInfoImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ bool isAggregateTypeForABI(mlir::Type T) {
return !LowerFunction::hasScalarEvaluationKind(T);
}

mlir::Value emitRoundPointerUpToAlignment(cir::CIRBaseBuilderTy &builder,
mlir::Value ptr, unsigned alignment) {
// OverflowArgArea = (OverflowArgArea + Align - 1) & -Align;
mlir::Location loc = ptr.getLoc();
mlir::Value roundUp = builder.createPtrStride(
loc, builder.createPtrBitcast(ptr, builder.getUIntNTy(8)),
builder.getUnsignedInt(loc, alignment - 1, /*width=*/32));
return builder.create<cir::PtrMaskOp>(
bcardosolopes marked this conversation as resolved.
Show resolved Hide resolved
loc, roundUp.getType(), roundUp,
builder.getSignedInt(loc, -alignment, /*width=*/32));
}

mlir::Type useFirstFieldIfTransparentUnion(mlir::Type Ty) {
if (auto RT = mlir::dyn_cast<StructType>(Ty)) {
if (RT.isUnion())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ bool classifyReturnType(const CIRCXXABI &CXXABI, LowerFunctionInfo &FI,

bool isAggregateTypeForABI(mlir::Type T);

mlir::Value emitRoundPointerUpToAlignment(cir::CIRBaseBuilderTy &builder,
mlir::Value ptr, unsigned alignment);

/// Pass transparent unions as if they were the type of the first element. Sema
/// should ensure that all elements of the union have the same "machine type".
mlir::Type useFirstFieldIfTransparentUnion(mlir::Type Ty);
Expand Down
19 changes: 0 additions & 19 deletions clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRCXXABI.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,4 @@ CIRCXXABI *CreateItaniumCXXABI(LowerModule &CGM);

} // namespace cir

// 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, cir::VAArgOp op,
const cir::CIRDataLayout &datalayout) = 0;
virtual ~LoweringPrepareCXXABI() {}

virtual mlir::Value lowerDynamicCast(CIRBaseBuilderTy &builder,
clang::ASTContext &astCtx,
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 @@ -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