Skip to content

Commit

Permalink
remove counter-intuitive modifications of inline attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
aparshin-intel authored and Konstantin Vladimirov committed Oct 6, 2021
1 parent e3bdf0b commit 226e1ef
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 32 deletions.
3 changes: 0 additions & 3 deletions include/clang/Basic/CodeGenOptions.def
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,6 @@ CODEGENOPT(FatalWarnings , 1, 0) ///< Set when -Wa,--fatal-warnings is
CODEGENOPT(EnableSegmentedStacks , 1, 0) ///< Set when -fsplit-stack is enabled.
CODEGENOPT(NoImplicitFloat , 1, 0) ///< Set when -mno-implicit-float is enabled.
CODEGENOPT(NoInfsFPMath , 1, 0) ///< Assume FP arguments, results not +-Inf.
CODEGENOPT(NoInline , 1, 0) ///< Set when -fno-inline is enabled.
///< Disables use of the inline keyword.
CODEGENOPT(ForceNoInline, 1, 1) ///< Set noinline as the default attribute
CODEGENOPT(NoSignedZeros , 1, 0) ///< Allow ignoring the signedness of FP zero
CODEGENOPT(NullPointerIsValid , 1, 0) ///< Assume Null pointer deference is defined.
CODEGENOPT(Reassociate , 1, 0) ///< Allow reassociation of FP math ops
Expand Down
35 changes: 8 additions & 27 deletions lib/CodeGen/CodeGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,34 +862,15 @@ void CodeGenFunction::StartFunction(GlobalDecl GD,
assert(CurFn->isDeclaration() && "Function already has body?");

// Pass inline keyword to optimizer if it appears explicitly on any
// declaration. Also, in the case of -fno-inline attach NoInline
// attribute to all function that are not marked AlwaysInline.
// declaration.
if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) {
if (!CGM.getCodeGenOpts().NoInline) {
for (auto RI : FD->redecls())
if (RI->isInlineSpecified()) {
// For MDF CM, emit inline attribute as alwaysinline.
if (getLangOpts().MdfCM)
Fn->addFnAttr(llvm::Attribute::AlwaysInline);
else
Fn->addFnAttr(llvm::Attribute::InlineHint);
break;
}
} else if (!FD->hasAttr<AlwaysInlineAttr>())
Fn->addFnAttr(llvm::Attribute::NoInline);

// For a GenX function if it is not alwaysinline, it will be noinline to
// match the old compiler's behavior. This behavior can be overwritten
// with option -fno-force-noinline.
//
// For C++ members, make them always inline to optimize away this pointer.
if (getLangOpts().MdfCM && FD->isCXXInstanceMember())
Fn->addFnAttr(llvm::Attribute::AlwaysInline);

if (getLangOpts().MdfCM &&
CGM.getCodeGenOpts().ForceNoInline &&
!Fn->getAttributes().hasAttrSomewhere(llvm::Attribute::AlwaysInline))
Fn->addFnAttr(llvm::Attribute::NoInline);
for (auto RI : FD->redecls()) {
if (RI->isInlineSpecified()) {
// For MDF CM, emit inline attribute as alwaysinline.
if (getLangOpts().MdfCM)
Fn->addFnAttr(llvm::Attribute::AlwaysInline);
}
}
}

// Finer control on the loop info for MDF cm.
Expand Down
2 changes: 0 additions & 2 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -779,8 +779,6 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
Args.hasFlag(OPT_funroll_loops, OPT_fno_unroll_loops,
(Opts.OptimizationLevel > 1));

// For CM only, set as noinline for functions without inline attribute.
Opts.ForceNoInline = !Args.hasArg(OPT_fno_force_noinline);
if (Args.hasArg(OPT_mCM_import_bif))
Opts.GenXBiFName = Args.getLastArgValue(OPT_mCM_import_bif);
// By default, CM global variables are not default initialized, this option
Expand Down
45 changes: 45 additions & 0 deletions test/CMFE/compiler_options/Ox_modes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*========================== begin_copyright_notice ============================
Copyright (C) 2021 Intel Corporation
SPDX-License-Identifier: MIT
============================= end_copyright_notice ===========================*/

// RUN: IGC_CMFE_CC1_EXTRA="-O2;-disable-llvm-passes" %cmc -fcmocl -march=skl -emit-llvm -S -o %t.ll -- %s
// RUN: FileCheck --input-file=%t.ll %s --check-prefixes=MODE_O2,MODE_O2_NO_NOINLINE
// RUN: FileCheck --input-file=%t.ll %s --check-prefixes=MODE_O2,MODE_O2_NO_OPTNONE
// MODE_O2: subgroup_8{{.*}}#[[SUBGROUP_ATTR:[0-9]+]]
// MODE_O2: attributes #[[SUBGROUP_ATTR]] = {
// MODE_O2_NO_NOINLINE-NOT: noinline
// MODE_O2_NO_OPTNONE-NOT: optnone
// MODE_O2-SAME: }

// RUN: %cmc -fcmocl -march=skl -emit-llvm -S -o %t.ll -- %s
// RUN: FileCheck --input-file=%t.ll %s --check-prefixes=MODE_O0,MODE_O0_NOINLINE
// RUN: FileCheck --input-file=%t.ll %s --check-prefixes=MODE_O0,MODE_O0_OPTNONE
// MODE_O0: subgroup_8{{.*}}#[[SUBGROUP_ATTR:[0-9]+]]
// MODE_O0: attributes #[[SUBGROUP_ATTR]] = {
// MODE_O0_NOINLINE-SAME: noinline
// MODE_O0_OPTNONE-SAME: optnone

#include <cm/cm.h>

int S1(vector<int, 8> v_out) {
return v_out[0];
}

extern "C" _GENX_MAIN_ void subgroup_8(
SurfaceIndex L [[type("buffer_t")]],
SurfaceIndex R [[type("buffer_t")]],
SurfaceIndex Res [[type("buffer_t")]]
) {
vector<int64_t, 8> l;
vector<int64_t, 8> res;

read(L, 0, l);
res = S1(l);

write(Res, 0, res);
}

0 comments on commit 226e1ef

Please sign in to comment.