Skip to content

Commit

Permalink
[π˜€π—½π—Ώ] initial version
Browse files Browse the repository at this point in the history
Created using spr 1.3.5
  • Loading branch information
lanza committed Oct 21, 2024
1 parent cb0cb34 commit f00bc07
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 24 deletions.
2 changes: 2 additions & 0 deletions clang/include/clang/CIR/MissingFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ struct MissingFeatures {
static bool parameterAttributes() { return false; }
static bool minLegalVectorWidthAttr() { return false; }
static bool vscaleRangeAttr() { return false; }
static bool stackrealign() { return false; }
static bool zerocallusedregs() { return false; }

// Coroutines
static bool unhandledException() { return false; }
Expand Down
108 changes: 84 additions & 24 deletions clang/lib/CIR/CodeGen/CIRGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "CIRGenCXXABI.h"
#include "CIRGenModule.h"
#include "CIRGenOpenMPRuntime.h"
#include "clang/AST/Attrs.inc"
#include "clang/Basic/CodeGenOptions.h"
#include "clang/CIR/MissingFeatures.h"

#include "clang/AST/ASTLambda.h"
Expand All @@ -24,6 +26,7 @@
#include "clang/CIR/Dialect/IR/CIRDialect.h"
#include "clang/CIR/Dialect/IR/FPEnv.h"
#include "clang/Frontend/FrontendDiagnostic.h"
#include "llvm/ADT/PointerIntPair.h"

#include "CIRGenTBAA.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
Expand Down Expand Up @@ -930,7 +933,7 @@ void CIRGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,

#include "clang/Basic/Sanitizers.def"
#undef SANITIZER
} while (0);
} while (false);

if (D) {
const bool SanitizeBounds = SanOpts.hasOneOf(SanitizerKind::Bounds);
Expand Down Expand Up @@ -994,6 +997,9 @@ void CIRGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
if (SanOpts.has(SanitizerKind::ShadowCallStack))
assert(!MissingFeatures::sanitizeOther());

if (SanOpts.has(SanitizerKind::Realtime))
llvm_unreachable("NYI");

// Apply fuzzing attribute to the function.
if (SanOpts.hasOneOf(SanitizerKind::Fuzzer | SanitizerKind::FuzzerNoLink))
assert(!MissingFeatures::sanitizeOther());
Expand Down Expand Up @@ -1022,6 +1028,17 @@ void CIRGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
FD->getBody()->getStmtClass() == Stmt::CoroutineBodyStmtClass)
SanOpts.Mask &= ~SanitizerKind::Null;

// Add pointer authentication attriburtes.
const CodeGenOptions &codeGenOptions = CGM.getCodeGenOpts();
if (codeGenOptions.PointerAuth.ReturnAddresses)
llvm_unreachable("NYI");
if (codeGenOptions.PointerAuth.FunctionPointers)
llvm_unreachable("NYI");
if (codeGenOptions.PointerAuth.AuthTraps)
llvm_unreachable("NYI");
if (codeGenOptions.PointerAuth.IndirectGotos)
llvm_unreachable("NYI");

// Apply xray attributes to the function (as a string, for now)
if (const auto *XRayAttr = D ? D->getAttr<XRayInstrumentAttr>() : nullptr) {
assert(!MissingFeatures::xray());
Expand All @@ -1048,6 +1065,15 @@ void CIRGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
if (Count && Offset <= Count) {
llvm_unreachable("NYI");
}
// Instruct that functions for COFF/CodeView targets should start with a
// pathable instruction, but only on x86/x64. Don't forward this to ARM/ARM64
// backends as they don't need it -- instructions on these architectures are
// always automatically patachable at runtime.
if (CGM.getCodeGenOpts().HotPatch &&
getContext().getTargetInfo().getTriple().isX86() &&
getContext().getTargetInfo().getTriple().getEnvironment() !=
llvm::Triple::CODE16)
llvm_unreachable("NYI");

// Add no-jump-tables value.
if (CGM.getCodeGenOpts().NoUseJumpTables)
Expand All @@ -1070,10 +1096,28 @@ void CIRGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
if (D && D->hasAttr<NoProfileFunctionAttr>())
llvm_unreachable("NYI");

if (FD && getLangOpts().OpenCL) {
if (D && D->hasAttr<HybridPatchableAttr>())
llvm_unreachable("NYI");

if (D) {
// Funciton attribiutes take precedence over command line flags.
if ([[maybe_unused]] auto *a = D->getAttr<FunctionReturnThunksAttr>()) {
llvm_unreachable("NYI");
} else if (CGM.getCodeGenOpts().FunctionReturnThunks)
llvm_unreachable("NYI");
}

if (FD && (getLangOpts().OpenCL ||
((getLangOpts().HIP || getLangOpts().OffloadViaLLVM) &&
getLangOpts().CUDAIsDevice))) {
// Add metadata for a kernel function.
buildKernelMetadata(FD, Fn);
}

if (FD && FD->hasAttr<ClspvLibclcBuiltinAttr>()) {
llvm_unreachable("NYI");
}

// If we are checking function types, emit a function type signature as
// prologue data.
if (FD && getLangOpts().CPlusPlus && SanOpts.has(SanitizerKind::Function)) {
Expand Down Expand Up @@ -1115,13 +1159,18 @@ void CIRGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
llvm_unreachable("NYI");
}

// TODO: stackrealign attr
if (MissingFeatures::stackrealign())
llvm_unreachable("NYI");

if (FD && FD->isMain() && MissingFeatures::zerocallusedregs())
llvm_unreachable("NYI");

mlir::Block *EntryBB = &Fn.getBlocks().front();

// TODO: allocapt insertion? probably don't need for CIR
// TODO: allocapt insertion? probaly don't need for CIR

// TODO: return value checking
if (MissingFeatures::requiresReturnValueCheck())
llvm_unreachable("NYI");

if (getDebugInfo()) {
llvm_unreachable("NYI");
Expand Down Expand Up @@ -1151,9 +1200,18 @@ void CIRGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
// FIXME(cir): vla.c test currently crashes here.
// PrologueCleanupDepth = EHStack.stable_begin();

// Emit OpenMP specific initialization of the device functions.
if (getLangOpts().OpenMP && CurCodeDecl)
CGM.getOpenMPRuntime().emitFunctionProlog(*this, CurCodeDecl);

if (FD && getLangOpts().HLSL) {
// Handle emitting HLSL entry functions.
if (FD->hasAttr<HLSLShaderAttr>()) {
llvm_unreachable("NYI");
}
llvm_unreachable("NYI");
}

// TODO: buildFunctionProlog

{
Expand Down Expand Up @@ -1250,32 +1308,34 @@ void CIRGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
}

// If any of the arguments have a variably modified type, make sure to emit
// the type size.
for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end(); i != e;
++i) {
const VarDecl *VD = *i;

// Dig out the type as written from ParmVarDecls; it's unclear whether the
// standard (C99 6.9.1p10) requires this, but we're following the
// precedent set by gcc.
QualType Ty;
if (const auto *PVD = dyn_cast<ParmVarDecl>(VD))
Ty = PVD->getOriginalType();
else
Ty = VD->getType();

if (Ty->isVariablyModifiedType())
buildVariablyModifiedType(Ty);
// the type size, but only if the function is not naked. Naked functions have
// no prolog to run this evaluation.
if (!FD || !FD->hasAttr<NakedAttr>()) {
for (const VarDecl *vd : Args) {
// Dig out the type as written from ParmVarDecls; it's unclear whether the
// standard (C99 6.9.1p10) requires this, but we're following the
// precedent set by gcc.
QualType ty;
if (const auto *pvd = dyn_cast<ParmVarDecl>(vd))
ty = pvd->getOriginalType();
else
ty = vd->getType();

if (ty->isVariablyModifiedType())
buildVariablyModifiedType(ty);
}
}
// Emit a location at the end of the prologue.
if (getDebugInfo())
llvm_unreachable("NYI");

// TODO: Do we need to handle this in two places like we do with
// target-features/target-cpu?
if (CurFuncDecl)
if (const auto *VecWidth = CurFuncDecl->getAttr<MinVectorWidthAttr>())
if ([[maybe_unused]] const auto *vecWidth = CurFuncDecl->getAttr<MinVectorWidthAttr>())
llvm_unreachable("NYI");

if (CGM.shouldEmitConvergenceTokens())
llvm_unreachable("NYI");
}

/// Return true if the current function should be instrumented with
Expand Down Expand Up @@ -1834,4 +1894,4 @@ void CIRGenFunction::buildVarAnnotations(const VarDecl *decl, mlir::Value val) {
auto allocaOp = dyn_cast_or_null<mlir::cir::AllocaOp>(val.getDefiningOp());
assert(allocaOp && "expects available alloca");
allocaOp.setAnnotationsAttr(builder.getArrayAttr(annotations));
}
}
8 changes: 8 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,14 @@ class CIRGenModule : public CIRGenTypeCache {
void AddGlobalDtor(mlir::cir::FuncOp Dtor, int Priority = 65535,
bool IsDtorAttrFunc = false);

// Return whether structured convergence intrinsics should be generated for
// this target.
bool shouldEmitConvergenceTokens() const {
// TODO: this shuld probably become unconditional once the controlled
// convergence becomes the norm.
return getTriple().isSPIRVLogical();
}

/// Return the mlir::Value for the address of the given global variable.
/// If Ty is non-null and if the global doesn't exist, then it will be created
/// with the specified type instead of whatever the normal requested type
Expand Down

0 comments on commit f00bc07

Please sign in to comment.