Skip to content

Commit 9c05cc5

Browse files
committed
Revert r256277 and r256279.
Some of the bots failed again. llvm-svn: 256280
1 parent 3f1bf25 commit 9c05cc5

File tree

9 files changed

+38
-232
lines changed

9 files changed

+38
-232
lines changed

llvm/include/llvm/IR/Attributes.h

-8
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class AttributeSetImpl;
3333
class AttributeSetNode;
3434
class Constant;
3535
template<typename T> struct DenseMapInfo;
36-
class Function;
3736
class LLVMContext;
3837
class Type;
3938

@@ -533,13 +532,6 @@ namespace AttributeFuncs {
533532
/// \brief Which attributes cannot be applied to a type.
534533
AttrBuilder typeIncompatible(Type *Ty);
535534

536-
/// \returns Return true if the two functions have compatible target-independent
537-
/// attributes for inlining purposes.
538-
bool areInlineCompatible(const Function &Caller, const Function &Callee);
539-
540-
/// \brief Merge caller's and callee's attributes.
541-
void mergeAttributesForInlining(Function &Caller, const Function &Callee);
542-
543535
} // end AttributeFuncs namespace
544536

545537
} // end llvm namespace

llvm/include/llvm/IR/Attributes.td

-25
Original file line numberDiff line numberDiff line change
@@ -165,28 +165,3 @@ def LessPreciseFPMAD : StrBoolAttr<"less-precise-fpmad">;
165165
def NoInfsFPMath : StrBoolAttr<"no-infs-fp-math">;
166166
def NoNansFPMath : StrBoolAttr<"no-nans-fp-math">;
167167
def UnsafeFPMath : StrBoolAttr<"unsafe-fp-math">;
168-
169-
class CompatRule<string F> {
170-
// The name of the function called to check the attribute of the caller and
171-
// callee and decide whether inlining should be allowed. The function's
172-
// signature must match "bool(const Function&, const Function &)", where the
173-
// first parameter is the reference to the caller and the second parameter is
174-
// the reference to the callee. It must return false if the attributes of the
175-
// caller and callee are incompatible, and true otherwise.
176-
string CompatFunc = F;
177-
}
178-
179-
def : CompatRule<"isEqual<SanitizeAddressAttr>">;
180-
def : CompatRule<"isEqual<SanitizeThreadAttr>">;
181-
def : CompatRule<"isEqual<SanitizeMemoryAttr>">;
182-
183-
class MergeRule<string F> {
184-
// The name of the function called to merge the attributes of the caller and
185-
// callee. The function's signature must match
186-
// "void(Function&, const Function &)", where the first parameter is the
187-
// reference to the caller and the second parameter is the reference to the
188-
// callee.
189-
string MergeFunc = F;
190-
}
191-
192-
def : MergeRule<"adjustCallerSSPLevel">;

llvm/lib/Analysis/InlineCost.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,9 @@ static bool functionsHaveCompatibleAttributes(Function *Caller,
13621362
Function *Callee,
13631363
TargetTransformInfo &TTI) {
13641364
return TTI.areInlineCompatible(Caller, Callee) &&
1365-
AttributeFuncs::areInlineCompatible(*Caller, *Callee);
1365+
attributeMatches(Caller, Callee, Attribute::SanitizeAddress) &&
1366+
attributeMatches(Caller, Callee, Attribute::SanitizeMemory) &&
1367+
attributeMatches(Caller, Callee, Attribute::SanitizeThread);
13661368
}
13671369

13681370
InlineCost InlineCostAnalysis::getInlineCost(CallSite CS, Function *Callee,

llvm/lib/IR/Attributes.cpp

-78
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
//===----------------------------------------------------------------------===//
1515

1616
#include "llvm/IR/Attributes.h"
17-
#include "llvm/IR/Function.h"
1817
#include "AttributeImpl.h"
1918
#include "LLVMContextImpl.h"
2019
#include "llvm/ADT/STLExtras.h"
@@ -1432,80 +1431,3 @@ AttrBuilder AttributeFuncs::typeIncompatible(Type *Ty) {
14321431

14331432
return Incompatible;
14341433
}
1435-
1436-
template<typename AttrClass>
1437-
static bool isEqual(const Function &Caller, const Function &Callee) {
1438-
return Caller.getFnAttribute(AttrClass::getKind()) ==
1439-
Callee.getFnAttribute(AttrClass::getKind());
1440-
}
1441-
1442-
/// \brief Compute the logical AND of the attributes of the caller and the
1443-
/// callee.
1444-
///
1445-
/// This function sets the caller's attribute to false if the callee's attribute
1446-
/// is false.
1447-
template<typename AttrClass>
1448-
static void setAND(Function &Caller, const Function &Callee) {
1449-
if (AttrClass::isSet(Caller, AttrClass::getKind()) &&
1450-
!AttrClass::isSet(Callee, AttrClass::getKind()))
1451-
AttrClass::set(Caller, AttrClass::getKind(), false);
1452-
}
1453-
1454-
/// \brief Compute the logical OR of the attributes of the caller and the
1455-
/// callee.
1456-
///
1457-
/// This function sets the caller's attribute to true if the callee's attribute
1458-
/// is true.
1459-
template<typename AttrClass>
1460-
static void setOR(Function &Caller, const Function &Callee) {
1461-
if (!AttrClass::isSet(Caller, AttrClass::getKind()) &&
1462-
AttrClass::isSet(Callee, AttrClass::getKind()))
1463-
AttrClass::set(Caller, AttrClass::getKind(), true);
1464-
}
1465-
1466-
/// \brief If the inlined function had a higher stack protection level than the
1467-
/// calling function, then bump up the caller's stack protection level.
1468-
static void adjustCallerSSPLevel(Function &Caller, const Function &Callee) {
1469-
// If upgrading the SSP attribute, clear out the old SSP Attributes first.
1470-
// Having multiple SSP attributes doesn't actually hurt, but it adds useless
1471-
// clutter to the IR.
1472-
AttrBuilder B;
1473-
B.addAttribute(Attribute::StackProtect)
1474-
.addAttribute(Attribute::StackProtectStrong)
1475-
.addAttribute(Attribute::StackProtectReq);
1476-
AttributeSet OldSSPAttr = AttributeSet::get(Caller.getContext(),
1477-
AttributeSet::FunctionIndex,
1478-
B);
1479-
1480-
if (Callee.hasFnAttribute(Attribute::SafeStack)) {
1481-
Caller.removeAttributes(AttributeSet::FunctionIndex, OldSSPAttr);
1482-
Caller.addFnAttr(Attribute::SafeStack);
1483-
} else if (Callee.hasFnAttribute(Attribute::StackProtectReq) &&
1484-
!Caller.hasFnAttribute(Attribute::SafeStack)) {
1485-
Caller.removeAttributes(AttributeSet::FunctionIndex, OldSSPAttr);
1486-
Caller.addFnAttr(Attribute::StackProtectReq);
1487-
} else if (Callee.hasFnAttribute(Attribute::StackProtectStrong) &&
1488-
!Caller.hasFnAttribute(Attribute::SafeStack) &&
1489-
!Caller.hasFnAttribute(Attribute::StackProtectReq)) {
1490-
Caller.removeAttributes(AttributeSet::FunctionIndex, OldSSPAttr);
1491-
Caller.addFnAttr(Attribute::StackProtectStrong);
1492-
} else if (Callee.hasFnAttribute(Attribute::StackProtect) &&
1493-
!Caller.hasFnAttribute(Attribute::SafeStack) &&
1494-
!Caller.hasFnAttribute(Attribute::StackProtectReq) &&
1495-
!Caller.hasFnAttribute(Attribute::StackProtectStrong))
1496-
Caller.addFnAttr(Attribute::StackProtect);
1497-
}
1498-
1499-
#define GET_ATTR_COMPAT_FUNC
1500-
#include "AttributesCompatFunc.inc"
1501-
1502-
bool AttributeFuncs::areInlineCompatible(const Function &Caller,
1503-
const Function &Callee) {
1504-
return hasCompatibleFnAttrs(Caller, Callee);
1505-
}
1506-
1507-
1508-
void AttributeFuncs::mergeAttributesForInlining(Function &Caller,
1509-
const Function &Callee) {
1510-
mergeFnAttrs(Caller, Callee);
1511-
}

llvm/lib/IR/AttributesCompatFunc.td

-1
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
include "llvm/IR/Attributes.td"

llvm/lib/IR/CMakeLists.txt

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
set(LLVM_TARGET_DEFINITIONS AttributesCompatFunc.td)
2-
tablegen(LLVM AttributesCompatFunc.inc -gen-attrs)
3-
add_public_tablegen_target(AttributeCompatFuncTableGen)
4-
51
add_llvm_library(LLVMCore
62
AsmWriter.cpp
73
Attributes.cpp

llvm/lib/IR/Makefile

+1-17
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,16 @@ LIBRARYNAME = LLVMCore
1111
BUILD_ARCHIVE = 1
1212

1313
BUILT_SOURCES = $(PROJ_OBJ_ROOT)/include/llvm/IR/Intrinsics.gen \
14-
$(PROJ_OBJ_ROOT)/include/llvm/IR/Attributes.inc \
15-
$(PROJ_OBJ_ROOT)/lib/IR/AttributesCompatFunc.inc
14+
$(PROJ_OBJ_ROOT)/include/llvm/IR/Attributes.inc
1615

1716
include $(LEVEL)/Makefile.common
1817

1918
GENFILE:=$(PROJ_OBJ_ROOT)/include/llvm/IR/Intrinsics.gen
2019
ATTRINCFILE:=$(PROJ_OBJ_ROOT)/include/llvm/IR/Attributes.inc
21-
ATTRCOMPATFUNCINCFILE:=$(PROJ_OBJ_ROOT)/lib/IR/AttributesCompatFunc.inc
2220

2321
INTRINSICTD := $(PROJ_SRC_ROOT)/include/llvm/IR/Intrinsics.td
2422
INTRINSICTDS := $(wildcard $(PROJ_SRC_ROOT)/include/llvm/IR/Intrinsics*.td)
2523
ATTRIBUTESTD := $(PROJ_SRC_ROOT)/include/llvm/IR/Attributes.td
26-
ATTRCOMPATFUNCTD := $(PROJ_SRC_ROOT)/lib/IR/AttributesCompatFunc.td
2724

2825
$(ObjDir)/Intrinsics.gen.tmp: $(ObjDir)/.dir $(INTRINSICTDS) $(LLVM_TBLGEN)
2926
$(Echo) Building Intrinsics.gen.tmp from Intrinsics.td
@@ -43,23 +40,10 @@ $(ATTRINCFILE): $(ObjDir)/Attributes.inc.tmp $(PROJ_OBJ_ROOT)/include/llvm/IR/.d
4340
$(EchoCmd) Updated Attributes.inc because Attributes.inc.tmp \
4441
changed significantly. )
4542

46-
$(ObjDir)/AttributesCompatFunc.inc.tmp: $(ObjDir)/.dir $(ATTRCOMPATFUNCTD) $(LLVM_TBLGEN)
47-
$(Echo) Building AttributesCompatFunc.inc.tmp from $(ATTRCOMPATFUNCTD)
48-
$(Verb) $(LLVMTableGen) $(call SYSPATH, $(ATTRCOMPATFUNCTD)) -o $(call SYSPATH, $@) -gen-attrs
49-
50-
$(ATTRCOMPATFUNCINCFILE): $(ObjDir)/AttributesCompatFunc.inc.tmp $(PROJ_OBJ_ROOT)/include/llvm/IR/.dir
51-
$(Verb) $(CMP) -s $@ $< || ( $(CP) $< $@ && \
52-
$(EchoCmd) Updated AttributesCompatFunc.inc because AttributesCompatFunc.inc.tmp \
53-
changed significantly. )
54-
5543
install-local:: $(GENFILE)
5644
$(Echo) Installing $(DESTDIR)$(PROJ_includedir)/llvm/IR/Intrinsics.gen
5745
$(Verb) $(DataInstall) $(GENFILE) $(DESTDIR)$(PROJ_includedir)/llvm/IR/Intrinsics.gen
5846

5947
install-local:: $(ATTRINCFILE)
6048
$(Echo) Installing $(DESTDIR)$(PROJ_includedir)/llvm/IR/Attributes.inc
6149
$(Verb) $(DataInstall) $(ATTRINCFILE) $(DESTDIR)$(PROJ_includedir)/llvm/IR/Attributes.inc
62-
63-
install-local:: $(ATTRCOMPATFUNCINCFILE)
64-
$(Echo) Installing $(DESTDIR)$(PROJ_libdir)/IR/AttributesCompatFunc.inc
65-
$(Verb) $(DataInstall) $(ATTRCOMPATFUNCINCFILE) $(DESTDIR)$(PROJ_libdir)/IR/AttributesCompatFunc.inc

llvm/lib/Transforms/IPO/Inliner.cpp

+34-1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,39 @@ void Inliner::getAnalysisUsage(AnalysisUsage &AU) const {
8686
typedef DenseMap<ArrayType*, std::vector<AllocaInst*> >
8787
InlinedArrayAllocasTy;
8888

89+
/// \brief If the inlined function had a higher stack protection level than the
90+
/// calling function, then bump up the caller's stack protection level.
91+
static void AdjustCallerSSPLevel(Function *Caller, Function *Callee) {
92+
// If upgrading the SSP attribute, clear out the old SSP Attributes first.
93+
// Having multiple SSP attributes doesn't actually hurt, but it adds useless
94+
// clutter to the IR.
95+
AttrBuilder B;
96+
B.addAttribute(Attribute::StackProtect)
97+
.addAttribute(Attribute::StackProtectStrong)
98+
.addAttribute(Attribute::StackProtectReq);
99+
AttributeSet OldSSPAttr = AttributeSet::get(Caller->getContext(),
100+
AttributeSet::FunctionIndex,
101+
B);
102+
103+
if (Callee->hasFnAttribute(Attribute::SafeStack)) {
104+
Caller->removeAttributes(AttributeSet::FunctionIndex, OldSSPAttr);
105+
Caller->addFnAttr(Attribute::SafeStack);
106+
} else if (Callee->hasFnAttribute(Attribute::StackProtectReq) &&
107+
!Caller->hasFnAttribute(Attribute::SafeStack)) {
108+
Caller->removeAttributes(AttributeSet::FunctionIndex, OldSSPAttr);
109+
Caller->addFnAttr(Attribute::StackProtectReq);
110+
} else if (Callee->hasFnAttribute(Attribute::StackProtectStrong) &&
111+
!Caller->hasFnAttribute(Attribute::SafeStack) &&
112+
!Caller->hasFnAttribute(Attribute::StackProtectReq)) {
113+
Caller->removeAttributes(AttributeSet::FunctionIndex, OldSSPAttr);
114+
Caller->addFnAttr(Attribute::StackProtectStrong);
115+
} else if (Callee->hasFnAttribute(Attribute::StackProtect) &&
116+
!Caller->hasFnAttribute(Attribute::SafeStack) &&
117+
!Caller->hasFnAttribute(Attribute::StackProtectReq) &&
118+
!Caller->hasFnAttribute(Attribute::StackProtectStrong))
119+
Caller->addFnAttr(Attribute::StackProtect);
120+
}
121+
89122
/// If it is possible to inline the specified call site,
90123
/// do so and update the CallGraph for this operation.
91124
///
@@ -113,7 +146,7 @@ static bool InlineCallIfPossible(Pass &P, CallSite CS, InlineFunctionInfo &IFI,
113146
if (!InlineFunction(CS, IFI, &AAR, InsertLifetime))
114147
return false;
115148

116-
AttributeFuncs::mergeAttributesForInlining(*Caller, *Callee);
149+
AdjustCallerSSPLevel(Caller, Callee);
117150

118151
// Look at all of the allocas that we inlined through this call site. If we
119152
// have already inlined other allocas through other calls into this function,

llvm/utils/TableGen/Attributes.cpp

-97
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ class Attributes {
2727

2828
private:
2929
void emitTargetIndependentEnums(raw_ostream &OS);
30-
void emitFnAttrCompatCheck(raw_ostream &OS, bool IsStringAttr);
31-
32-
void printEnumAttrClasses(raw_ostream &OS,
33-
const std::vector<Record *> &Records);
34-
void printStrBoolAttrClasses(raw_ostream &OS,
35-
const std::vector<Record *> &Records);
3630

3731
RecordKeeper &Records;
3832
};
@@ -52,99 +46,8 @@ void Attributes::emitTargetIndependentEnums(raw_ostream &OS) {
5246
OS << "#endif\n";
5347
}
5448

55-
void Attributes::emitFnAttrCompatCheck(raw_ostream &OS, bool IsStringAttr) {
56-
OS << "#ifdef GET_ATTR_COMPAT_FUNC\n";
57-
OS << "#undef GET_ATTR_COMPAT_FUNC\n";
58-
59-
OS << "struct EnumAttr {\n";
60-
OS << " static bool isSet(const Function &Fn,\n";
61-
OS << " Attribute::AttrKind Kind) {\n";
62-
OS << " return Fn.hasFnAttribute(Kind);\n";
63-
OS << " }\n\n";
64-
OS << " static void set(Function &Fn,\n";
65-
OS << " Attribute::AttrKind Kind, bool Val) {\n";
66-
OS << " if (Val)\n";
67-
OS << " Fn.addFnAttr(Kind);\n";
68-
OS << " else\n";
69-
OS << " Fn.removeFnAttr(Kind);\n";
70-
OS << " }\n";
71-
OS << "};\n\n";
72-
73-
OS << "struct StrBoolAttr {\n";
74-
OS << " static bool isSet(const Function &Fn,\n";
75-
OS << " StringRef Kind) {\n";
76-
OS << " auto A = Fn.getFnAttribute(Kind);\n";
77-
OS << " return A.getValueAsString().equals(\"true\");\n";
78-
OS << " }\n\n";
79-
OS << " static void set(Function &Fn,\n";
80-
OS << " StringRef Kind, bool Val) {\n";
81-
OS << " Fn.addFnAttr(Kind, Val ? \"true\" : \"false\");\n";
82-
OS << " }\n";
83-
OS << "};\n\n";
84-
85-
printEnumAttrClasses(OS ,Records.getAllDerivedDefinitions("EnumAttr"));
86-
printStrBoolAttrClasses(OS , Records.getAllDerivedDefinitions("StrBoolAttr"));
87-
88-
OS << "static inline bool hasCompatibleFnAttrs(const Function &Caller,\n"
89-
<< " const Function &Callee) {\n";
90-
OS << " bool Ret = true;\n\n";
91-
92-
std::vector<Record *> CompatRules =
93-
Records.getAllDerivedDefinitions("CompatRule");
94-
95-
for (auto *Rule : CompatRules) {
96-
StringRef FuncName = Rule->getValueAsString("CompatFunc");
97-
OS << " Ret &= " << FuncName << "(Caller, Callee);\n";
98-
}
99-
100-
OS << "\n";
101-
OS << " return Ret;\n";
102-
OS << "}\n\n";
103-
104-
std::vector<Record *> MergeRules =
105-
Records.getAllDerivedDefinitions("MergeRule");
106-
OS << "static inline void mergeFnAttrs(Function &Caller,\n"
107-
<< " const Function &Callee) {\n";
108-
109-
for (auto *Rule : MergeRules) {
110-
StringRef FuncName = Rule->getValueAsString("MergeFunc");
111-
OS << " " << FuncName << "(Caller, Callee);\n";
112-
}
113-
114-
OS << "}\n\n";
115-
116-
OS << "#endif\n";
117-
}
118-
119-
void Attributes::printEnumAttrClasses(raw_ostream &OS,
120-
const std::vector<Record *> &Records) {
121-
OS << "// EnumAttr classes\n";
122-
for (const auto *R : Records) {
123-
OS << "struct " << R->getName() << "Attr : EnumAttr {\n";
124-
OS << " static enum Attribute::AttrKind getKind() {\n";
125-
OS << " return llvm::Attribute::" << R->getName() << ";\n";
126-
OS << " }\n";
127-
OS << "};\n";
128-
}
129-
OS << "\n";
130-
}
131-
132-
void Attributes::printStrBoolAttrClasses(raw_ostream &OS,
133-
const std::vector<Record *> &Records) {
134-
OS << "// StrBoolAttr classes\n";
135-
for (const auto *R : Records) {
136-
OS << "struct " << R->getName() << "Attr : StrBoolAttr {\n";
137-
OS << " static const char *getKind() {\n";
138-
OS << " return \"" << R->getValueAsString("AttrString") << "\";\n";
139-
OS << " }\n";
140-
OS << "};\n";
141-
}
142-
OS << "\n";
143-
}
144-
14549
void Attributes::emit(raw_ostream &OS) {
14650
emitTargetIndependentEnums(OS);
147-
emitFnAttrCompatCheck(OS, false);
14851
}
14952

15053
namespace llvm {

0 commit comments

Comments
 (0)