Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions clang/include/clang/CIR/MissingFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,17 @@ struct MissingFeatures {
static bool mustProgress() { return false; }

static bool skipTempCopy() { return false; }

static bool addressSpaceInGlobalVar() { return false; }

static bool useARMGuardVarABI() { return false; }

// PtrAuth added a RawAddress type subclassing from Address.
static bool rawAddress() { return false; }

// LLVM has values that can be named (e.g. %x) and MLIR doens't, add this when
// we have a solution
static bool namedValues() { return false; }
};

} // namespace cir
Expand Down
44 changes: 44 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@
#include "TargetInfo.h"

#include "clang/AST/Attr.h"
#include "clang/AST/Attrs.inc"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclBase.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/GlobalDecl.h"
#include "clang/Basic/Specifiers.h"
#include "clang/CIR/ABIArgInfo.h"
#include "clang/CIR/Dialect/IR/CIRDialect.h"
#include "clang/CIR/Dialect/IR/CIRTypes.h"
#include "clang/CIR/FnInfoOpts.h"
Expand Down Expand Up @@ -943,6 +948,12 @@ static CanQual<FunctionProtoType> GetFormalType(const CXXMethodDecl *MD) {
.getAs<FunctionProtoType>();
}

void CIRGenFunction::emitFunctionProlog(const CIRGenFunctionInfo &functionInfo,
cir::FuncOp fn,
const FunctionArgList &args) {
return;
}

/// TODO(cir): this should be shared with LLVM codegen
static void addExtParameterInfosForCall(
llvm::SmallVectorImpl<FunctionProtoType::ExtParameterInfo> &paramInfos,
Expand Down Expand Up @@ -1319,6 +1330,7 @@ CIRGenTypes::arrangeUnprototypedMustTailThunk(const CXXMethodDecl *md) {
return arrangeCIRFunctionInfo(astContext.VoidTy, cir::FnInfoOpts::None,
ArgTys, FTP->getExtInfo(), {}, RequiredArgs(1));
}

/// Figure out the rules for calling a function with the given formal type using
/// the given arguments. The arguments are necessary because the function might
/// be unprototyped, in which case it's target-dependent in crazy ways.
Expand Down Expand Up @@ -1483,3 +1495,35 @@ void CIRGenModule::getDefaultFunctionAttributes(
// TODO(cir): addMergableDefaultFunctionAttributes(codeGenOpts, funcAttrs);
}
}

void CIRGenFunction::createCoercedStore(mlir::Value src, Address dst,
llvm::TypeSize dstSize,
bool dstIsVolatile) {
if (!dstSize)
return;

mlir::Type srcTy = src.getType();
llvm::TypeSize srcSize = CGM.getDataLayout().getTypeAllocSize(srcTy);

// GEP into structs to try to make typesm match.
// FIXME: This isn't really that useful with opaque types, but it impacts a
// lot of regressiont ests.
if (srcTy != dst.getElementType()) {
llvm_unreachable("NYI");
}

if (srcSize.isScalable() || srcSize <= dstSize) {
if (isa<cir::IntType>(srcTy) &&
isa<cir::PointerType>(dst.getElementType()) &&
srcSize == CGM.getDataLayout().getTypeAllocSize(dst.getElementType())) {
llvm_unreachable("NYI");
} else {
getBuilder().createStore(src.getLoc(), src, dst.withElementType(getBuilder(), srcTy),
dstIsVolatile);
}
} else if (isa<cir::IntType>(srcTy)) {
llvm_unreachable("NYI");
} else {
llvm_unreachable("NYI");
}
}
81 changes: 81 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1289,3 +1289,84 @@ void CIRGenFunction::pushDestroyAndDeferDeactivation(
pushDestroy(cleanupKind, addr, type, destroyer, useEHCleanupForArray);
DeferredDeactivationCleanupStack.push_back({EHStack.stable_begin(), flag});
}

/// Emit an alloca (or GlobalValue depending on target)
/// for the specified parameter and set up LocalDeclMap.
void CIRGenFunction::emitParmDecl(const VarDecl &varDecl, ParamValue arg,
unsigned argNo) {
bool noDebugInfo = false;
// FIXME: Why isn't ImplicitParamDecl a ParmVarDecl?
assert((isa<ParmVarDecl>(varDecl) || isa<ImplicitParamDecl>(varDecl)) &&
"Invalid argument to buildParmDecl");

// Set the name of the parameter's initial value to make IR easier to read.
// Don't modify the names of globals.
if (cir::MissingFeatures::namedValues())
llvm_unreachable("NYI");

QualType ty = varDecl.getType();

// Use better CIR generation for certain implicit parameters.
if ([[maybe_unused]] auto const *ipd =
dyn_cast<ImplicitParamDecl>(&varDecl)) {
llvm_unreachable("NYI");
}

Address declPtr = Address::invalid();
assert(!cir::MissingFeatures::rawAddress());
Address allocaPtr = Address::invalid();
bool doStore = false;
bool isScalar = hasScalarEvaluationKind(ty);
bool useIndirectDebugAddress = false;

// If we already have a pointer to the argument, reuse the input pointer.
if (arg.isIndirect()) {
llvm_unreachable("NYI");
} else {
// Check if the parameter address is controlled by OpenMP runtime.
Address openMPLocalAddr =
getLangOpts().OpenMP
? CGM.getOpenMPRuntime().getAddressOfLocalVariable(*this, &varDecl)
: Address::invalid();
if (getLangOpts().OpenMP && openMPLocalAddr.isValid()) {
llvm_unreachable("NYI");
} else {
// Otherwise, create a temporary to hold the value.
declPtr = CreateMemTemp(ty, getContext().getDeclAlign(&varDecl),
getLoc(varDecl.getLocation()),
varDecl.getName() + ".addr", &allocaPtr);
}
doStore = true;
}

mlir::Value argVal = (doStore ? arg.getDirectValue() : nullptr);

LValue lv = makeAddrLValue(declPtr, ty);
if (isScalar) {
Qualifiers qs = ty.getQualifiers();
if ([[maybe_unused]] Qualifiers::ObjCLifetime lt = qs.getObjCLifetime()) {
llvm_unreachable("NYI");
}
}

// Store the initial value into the alloca.
if (doStore)
emitStoreOfScalar(argVal, lv, /*isInit=*/true);

setAddrOfLocalVar(&varDecl, declPtr);

// Emit debug info for param declarations in non-thunk functions.
if (CIRGenDebugInfo *di = getDebugInfo()) {
llvm_unreachable("NYI");
}

if (varDecl.hasAttr<AnnotateAttr>())
llvm_unreachable("NYI");

// We can only check return value nullability if all arguments to the function
// staisfy their nullability preconditions. This makes it necessary to emit
// null checks for args in the function body itself.
if (requiresReturnValueNullabilityCheck()) {
llvm_unreachable("NYI");
}
}
2 changes: 1 addition & 1 deletion clang/lib/CIR/CodeGen/CIRGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,7 @@ void CIRGenFunction::StartFunction(GlobalDecl gd, QualType retTy,
llvm_unreachable("NYI");
}

// TODO: emitFunctionProlog
emitFunctionProlog(*CurFnInfo, cast<cir::FuncOp>(CurFn), args);

{
// Set the insertion point in the builder to the beginning of the
Expand Down
Loading