Skip to content

Commit b47b86a

Browse files
dpaoliellosivadeilra
authored andcommitted
Apply 0032-shrinkwrap-control.patch
1 parent 986a01f commit b47b86a

File tree

9 files changed

+37
-0
lines changed

9 files changed

+37
-0
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5262,3 +5262,10 @@ def DynamicFixup : InheritableAttr {
52625262
let LangOpts = [MicrosoftExt];
52635263
let Documentation = [Undocumented];
52645264
}
5265+
5266+
def NoShrinkWrapping : InheritableAttr {
5267+
let Spellings = [Declspec<"noshrinkwrap">];
5268+
let Subjects = SubjectList<[Function]>;
5269+
let Documentation = [NoShrinkWrappingDocs];
5270+
let SimpleHandler = 1;
5271+
}

clang/include/clang/Basic/AttrDocs.td

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9427,3 +9427,12 @@ silence diagnostics with code like:
94279427
__attribute__((nonstring)) char NotAStr[3] = "foo"; // Not diagnosed
94289428
}];
94299429
}
9430+
9431+
def NoShrinkWrappingDocs : Documentation {
9432+
let Category = DocCatFunction;
9433+
let Content = [{
9434+
The ``__declspec(noshrinkwrap)`` attribute disables the shrinkwrapping
9435+
process for this function.
9436+
}];
9437+
}
9438+

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2641,6 +2641,10 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
26412641
else if (isStackProtectorOn(LangOpts, getTriple(), LangOptions::SSPReq))
26422642
B.addAttribute(llvm::Attribute::StackProtectReq);
26432643

2644+
if (D && D->hasAttr<NoShrinkWrappingAttr>()) {
2645+
B.addAttribute(llvm::Attribute::NoShrinkWrap);
2646+
}
2647+
26442648
if (!D) {
26452649
// Non-entry HLSL functions must always be inlined.
26462650
if (getLangOpts().HLSL && !F->hasFnAttribute(llvm::Attribute::NoInline))

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7895,6 +7895,10 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL,
78957895
handleDynamicFixup(S, D, AL);
78967896
break;
78977897

7898+
case ParsedAttr::AT_NoShrinkWrapping:
7899+
handleSimpleAttribute<NoShrinkWrappingAttr>(S, D, AL);
7900+
break;
7901+
78987902
}
78997903
}
79007904

llvm/include/llvm/Bitcode/LLVMBitCodes.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,9 @@ enum UseListCodes {
695695
};
696696

697697
enum AttributeKindCodes {
698+
// TODO: assign real values; these are placed here to reduce likelihood of merge conflicts with additions
699+
ATTR_KIND_NO_SHRINKWRAP = INT_MAX,
700+
698701
// = 0 is unused
699702
ATTR_KIND_ALIGNMENT = 1,
700703
ATTR_KIND_ALWAYS_INLINE = 2,

llvm/include/llvm/IR/Attributes.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,9 @@ def MarkedForWindowsSecureHotPatching
402402
def AllowDirectAccessInHotPatchFunction
403403
: StrBoolAttr<"allow_direct_access_in_hot_patch_function">;
404404

405+
/// Function should not be shrinkwrapped
406+
def NoShrinkWrap : EnumAttr<"noshrinkwrap", IntersectPreserve, [FnAttr]>;
407+
405408
/// Target-independent string attributes.
406409
def LessPreciseFPMAD : StrBoolAttr<"less-precise-fpmad">;
407410
def NoInfsFPMath : StrBoolAttr<"no-infs-fp-math">;

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,6 +2246,8 @@ static Attribute::AttrKind getAttrFromCode(uint64_t Code) {
22462246
return Attribute::Captures;
22472247
case bitc::ATTR_KIND_DEAD_ON_RETURN:
22482248
return Attribute::DeadOnReturn;
2249+
case bitc::ATTR_KIND_NO_SHRINKWRAP:
2250+
return Attribute::NoShrinkWrap;
22492251
}
22502252
}
22512253

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,8 @@ static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind) {
946946
return bitc::ATTR_KIND_CAPTURES;
947947
case Attribute::DeadOnReturn:
948948
return bitc::ATTR_KIND_DEAD_ON_RETURN;
949+
case Attribute::NoShrinkWrap:
950+
return bitc::ATTR_KIND_NO_SHRINKWRAP;
949951
case Attribute::EndAttrKinds:
950952
llvm_unreachable("Can not encode end-attribute kinds marker.");
951953
case Attribute::None:

llvm/lib/CodeGen/ShrinkWrap.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,9 @@ PreservedAnalyses ShrinkWrapPass::run(MachineFunction &MF,
10131013
bool ShrinkWrapImpl::isShrinkWrapEnabled(const MachineFunction &MF) {
10141014
const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering();
10151015

1016+
if (MF.getFunction().hasFnAttribute(Attribute::NoShrinkWrap))
1017+
return false;
1018+
10161019
switch (EnableShrinkWrapOpt) {
10171020
case cl::BOU_UNSET:
10181021
return TFI->enableShrinkWrapping(MF) &&

0 commit comments

Comments
 (0)