Skip to content

Commit

Permalink
use CIRDataLayout to get some ABI info
Browse files Browse the repository at this point in the history
  • Loading branch information
ghehg committed May 28, 2024
1 parent 09b1536 commit 2f2214c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 23 deletions.
4 changes: 3 additions & 1 deletion clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "clang/Basic/Module.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/CIR/Dialect/Builder/CIRBaseBuilder.h"
#include "clang/CIR/Dialect/IR/CIRDataLayout.h"
#include "clang/CIR/Dialect/IR/CIRDialect.h"
#include "clang/CIR/Dialect/Passes.h"
#include "clang/CIR/Interfaces/ASTAttrInterfaces.h"
Expand Down Expand Up @@ -334,8 +335,9 @@ static void canonicalizeIntrinsicThreeWayCmp(CIRBaseBuilderTy &builder,
void LoweringPreparePass::lowerVAArgOp(VAArgOp op) {
CIRBaseBuilderTy builder(getContext());
builder.setInsertionPoint(op);
::cir::CIRDataLayout datalayout(theModule);

auto res = cxxABI->lowerVAArg(builder, op);
auto res = cxxABI->lowerVAArg(builder, op, datalayout);
if (res) {
op.replaceAllUsesWith(res);
op.erase();
Expand Down
41 changes: 24 additions & 17 deletions clang/lib/CIR/Dialect/Transforms/LoweringPrepareAArch64CXXABI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "../IR/MissingFeatures.h"
#include "LoweringPrepareItaniumCXXABI.h"
#include "clang/AST/CharUnits.h"
#include "clang/CIR/Dialect/IR/CIRDataLayout.h"
#include "clang/CIR/Dialect/IR/CIRTypes.h"

#include <assert.h>
Expand All @@ -25,20 +26,23 @@ namespace {
class LoweringPrepareAArch64CXXABI : public LoweringPrepareItaniumCXXABI {
public:
LoweringPrepareAArch64CXXABI(AArch64ABIKind k) : Kind(k) {}
mlir::Value lowerVAArg(cir::CIRBaseBuilderTy &builder,
mlir::cir::VAArgOp op) override;
mlir::Value lowerVAArg(cir::CIRBaseBuilderTy &builder, mlir::cir::VAArgOp op,
const cir::CIRDataLayout &datalayout) override;

private:
AArch64ABIKind Kind;
mlir::Value lowerAAPCSVAArg(cir::CIRBaseBuilderTy &builder,
mlir::cir::VAArgOp op);
mlir::cir::VAArgOp op,
const cir::CIRDataLayout &datalayout);
bool isDarwinPCS() const { return Kind == AArch64ABIKind::DarwinPCS; }
mlir::Value lowerMSVAArg(cir::CIRBaseBuilderTy &builder,
mlir::cir::VAArgOp op) {
mlir::cir::VAArgOp op,
const cir::CIRDataLayout &datalayout) {
llvm_unreachable("MSVC ABI not supported yet");
}
mlir::Value lowerDarwinVAArg(cir::CIRBaseBuilderTy &builder,
mlir::cir::VAArgOp op) {
mlir::cir::VAArgOp op,
const cir::CIRDataLayout &datalayout) {
llvm_unreachable("Darwin ABI not supported yet");
}
};
Expand All @@ -49,9 +53,9 @@ cir::LoweringPrepareCXXABI::createAArch64ABI(AArch64ABIKind k) {
return new LoweringPrepareAArch64CXXABI(k);
}

mlir::Value
LoweringPrepareAArch64CXXABI::lowerAAPCSVAArg(cir::CIRBaseBuilderTy &builder,
mlir::cir::VAArgOp op) {
mlir::Value LoweringPrepareAArch64CXXABI::lowerAAPCSVAArg(
cir::CIRBaseBuilderTy &builder, mlir::cir::VAArgOp op,
const cir::CIRDataLayout &datalayout) {
auto loc = op->getLoc();
auto valist = op->getOperand(0);
auto opResTy = op.getType();
Expand Down Expand Up @@ -118,9 +122,10 @@ LoweringPrepareAArch64CXXABI::lowerAAPCSVAArg(cir::CIRBaseBuilderTy &builder,
assert(!cir::MissingFeatures::supportTyAlignQueryForAArch64());
// One is just place holder for now, as we don't have a way to query
// type size and alignment.
clang::CharUnits tySize = clang::CharUnits::One();
clang::CharUnits tyAlign = clang::CharUnits::One();
;
clang::CharUnits tySize =
clang::CharUnits::fromQuantity(datalayout.getTypeStoreSize(opResTy));
clang::CharUnits tyAlign =
clang::CharUnits::fromQuantity(datalayout.getAlignment(opResTy, true));

// indirectness, type size and type alignment all
// decide regSize, but they are all ABI defined
Expand Down Expand Up @@ -215,9 +220,10 @@ LoweringPrepareAArch64CXXABI::lowerAAPCSVAArg(cir::CIRBaseBuilderTy &builder,
uint64_t numMembers = 0;
assert(!cir::MissingFeatures::supportisHomogeneousAggregateQueryForAArch64());
bool isHFA = false;
// though endianess can be known from datalayout, it might need an unified
// ABI lowering query system to answer the question.
assert(!cir::MissingFeatures::supportisEndianQueryForAArch64());
// TODO: endianess should be query result from ABI info
bool isBigEndian = false;
bool isBigEndian = datalayout.isBigEndian();
assert(!cir::MissingFeatures::supportisAggregateTypeForABIAArch64());
// TODO: isAggregateTypeForABI should be query result from ABI info
bool isAggregateTypeForABI = false;
Expand Down Expand Up @@ -336,8 +342,9 @@ LoweringPrepareAArch64CXXABI::lowerAAPCSVAArg(cir::CIRBaseBuilderTy &builder,

mlir::Value
LoweringPrepareAArch64CXXABI::lowerVAArg(cir::CIRBaseBuilderTy &builder,
mlir::cir::VAArgOp op) {
return Kind == AArch64ABIKind::Win64 ? lowerMSVAArg(builder, op)
: isDarwinPCS() ? lowerDarwinVAArg(builder, op)
: lowerAAPCSVAArg(builder, op);
mlir::cir::VAArgOp op,
const cir::CIRDataLayout &datalayout) {
return Kind == AArch64ABIKind::Win64 ? lowerMSVAArg(builder, op, datalayout)
: isDarwinPCS() ? lowerDarwinVAArg(builder, op, datalayout)
: lowerAAPCSVAArg(builder, op, datalayout);
}
4 changes: 3 additions & 1 deletion clang/lib/CIR/Dialect/Transforms/LoweringPrepareCXXABI.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "mlir/IR/Value.h"
#include "clang/AST/ASTContext.h"
#include "clang/CIR/Dialect/Builder/CIRBaseBuilder.h"
#include "clang/CIR/Dialect/IR/CIRDataLayout.h"
#include "clang/CIR/Dialect/IR/CIRDialect.h"

namespace cir {
Expand All @@ -36,7 +37,8 @@ class LoweringPrepareCXXABI {
static LoweringPrepareCXXABI *createAArch64ABI(AArch64ABIKind k);

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

virtual mlir::Value lowerDynamicCast(CIRBaseBuilderTy &builder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "clang/Basic/TargetInfo.h"
#include "clang/CIR/Dialect/Builder/CIRBaseBuilder.h"
#include "clang/CIR/Dialect/IR/CIRAttrs.h"
#include "clang/CIR/Dialect/IR/CIRDataLayout.h"
#include "clang/CIR/Dialect/IR/CIRDialect.h"

using namespace cir;
Expand Down Expand Up @@ -160,8 +161,9 @@ LoweringPrepareItaniumCXXABI::lowerDynamicCast(CIRBaseBuilderTy &builder,
.getResult();
}

mlir::Value LoweringPrepareItaniumCXXABI::lowerVAArg(CIRBaseBuilderTy &builder,
mlir::cir::VAArgOp op) {
mlir::Value LoweringPrepareItaniumCXXABI::lowerVAArg(
CIRBaseBuilderTy &builder, mlir::cir::VAArgOp op,
const ::cir::CIRDataLayout &datalayout) {
// There is no generic cir lowering for var_arg, here we fail
// so to prevent attempt of calling lowerVAArg for ItaniumCXXABI
llvm_unreachable("NYI");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
//===----------------------------------------------------------------------===//

#include "LoweringPrepareCXXABI.h"
#include "clang/CIR/Dialect/IR/CIRDataLayout.h"

class LoweringPrepareItaniumCXXABI : public cir::LoweringPrepareCXXABI {
public:
mlir::Value lowerDynamicCast(cir::CIRBaseBuilderTy &builder,
clang::ASTContext &astCtx,
mlir::cir::DynamicCastOp op) override;
mlir::Value lowerVAArg(cir::CIRBaseBuilderTy &builder,
mlir::cir::VAArgOp op) override;
mlir::Value lowerVAArg(cir::CIRBaseBuilderTy &builder, mlir::cir::VAArgOp op,
const cir::CIRDataLayout &datalayout) override;
};

0 comments on commit 2f2214c

Please sign in to comment.