aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2007-11-25 14:10:56 +0000
committerDuncan Sands <baldrick@free.fr>2007-11-25 14:10:56 +0000
commit827cde1c8319e51463007078a7ce3660ebc93036 (patch)
treea14ff574ff8b56c6eafd7d864d2cf756451a9d8d /lib
parent789d34f8c3d78cf439f0da2f1ba7856bdaed01a4 (diff)
downloadexternal_llvm-827cde1c8319e51463007078a7ce3660ebc93036.zip
external_llvm-827cde1c8319e51463007078a7ce3660ebc93036.tar.gz
external_llvm-827cde1c8319e51463007078a7ce3660ebc93036.tar.bz2
Fix PR1816. If a bitcast of a function only exists because of a
trivial difference in function attributes, allow calls to it to be converted to direct calls. Based on a patch by Török Edwin. While there, move the various lists of mutually incompatible parameters etc out of the verifier and into ParameterAttributes.h. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44315 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp9
-rw-r--r--lib/VMCore/Function.cpp45
-rw-r--r--lib/VMCore/Verifier.cpp37
3 files changed, 56 insertions, 35 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 5537631..85fd2c3 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -7990,11 +7990,12 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
const FunctionType *ActualFT =
cast<FunctionType>(cast<PointerType>(CE->getType())->getElementType());
- // If the parameter attributes don't match up, don't do the xform. We don't
- // want to lose an sret attribute or something.
- if (FT->getParamAttrs() != ActualFT->getParamAttrs())
+ // If the parameter attributes are not compatible, don't do the xform. We
+ // don't want to lose an sret attribute or something.
+ if (!ParamAttrsList::areCompatible(FT->getParamAttrs(),
+ ActualFT->getParamAttrs()))
return false;
-
+
// Check to see if we are changing the return type...
if (OldRetTy != FT->getReturnType()) {
if (Callee->isDeclaration() && !Caller->use_empty() &&
diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp
index 6c29371..2b83e6b 100644
--- a/lib/VMCore/Function.cpp
+++ b/lib/VMCore/Function.cpp
@@ -86,7 +86,6 @@ ParamAttrsList::getParamAttrs(uint16_t Index) const {
return ParamAttr::None;
}
-
std::string
ParamAttrsList::getParamAttrsText(uint16_t Attrs) {
std::string Result;
@@ -115,6 +114,50 @@ ParamAttrsList::getParamAttrsText(uint16_t Attrs) {
return Result;
}
+/// onlyInformative - Returns whether only informative attributes are set.
+static inline bool onlyInformative(uint16_t attrs) {
+ return !(attrs & ~ParamAttr::Informative);
+}
+
+bool
+ParamAttrsList::areCompatible(const ParamAttrsList *A, const ParamAttrsList *B){
+ if (A == B)
+ return true;
+ unsigned ASize = A ? A->size() : 0;
+ unsigned BSize = B ? B->size() : 0;
+ unsigned AIndex = 0;
+ unsigned BIndex = 0;
+
+ while (AIndex < ASize && BIndex < BSize) {
+ uint16_t AIdx = A->getParamIndex(AIndex);
+ uint16_t BIdx = B->getParamIndex(BIndex);
+ uint16_t AAttrs = A->getParamAttrsAtIndex(AIndex);
+ uint16_t BAttrs = B->getParamAttrsAtIndex(AIndex);
+
+ if (AIdx < BIdx) {
+ if (!onlyInformative(AAttrs))
+ return false;
+ ++AIndex;
+ } else if (BIdx < AIdx) {
+ if (!onlyInformative(BAttrs))
+ return false;
+ ++BIndex;
+ } else {
+ if (!onlyInformative(AAttrs ^ BAttrs))
+ return false;
+ ++AIndex;
+ ++BIndex;
+ }
+ }
+ for (; AIndex < ASize; ++AIndex)
+ if (!onlyInformative(A->getParamAttrsAtIndex(AIndex)))
+ return false;
+ for (; BIndex < BSize; ++BIndex)
+ if (!onlyInformative(B->getParamAttrsAtIndex(AIndex)))
+ return false;
+ return true;
+}
+
void
ParamAttrsList::Profile(FoldingSetNodeID &ID) const {
for (unsigned i = 0; i < attrs.size(); ++i) {
diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp
index 1f726af..a547721 100644
--- a/lib/VMCore/Verifier.cpp
+++ b/lib/VMCore/Verifier.cpp
@@ -393,30 +393,6 @@ void Verifier::visitFunction(Function &F) {
Assert1(!FT->isStructReturn() || FT->getReturnType() == Type::VoidTy,
"Invalid struct-return function!", &F);
- const uint16_t ReturnIncompatible =
- ParamAttr::ByVal | ParamAttr::InReg |
- ParamAttr::Nest | ParamAttr::StructRet;
-
- const uint16_t ParameterIncompatible =
- ParamAttr::NoReturn | ParamAttr::NoUnwind |
- ParamAttr::ReadNone | ParamAttr::ReadOnly;
-
- const uint16_t MutuallyIncompatible[3] = {
- ParamAttr::ByVal | ParamAttr::InReg |
- ParamAttr::Nest | ParamAttr::StructRet,
-
- ParamAttr::ZExt | ParamAttr::SExt,
-
- ParamAttr::ReadNone | ParamAttr::ReadOnly
- };
-
- const uint16_t IntegerTypeOnly =
- ParamAttr::SExt | ParamAttr::ZExt;
-
- const uint16_t PointerTypeOnly =
- ParamAttr::ByVal | ParamAttr::Nest |
- ParamAttr::NoAlias | ParamAttr::StructRet;
-
bool SawSRet = false;
if (const ParamAttrsList *Attrs = FT->getParamAttrs()) {
@@ -426,28 +402,29 @@ void Verifier::visitFunction(Function &F) {
uint16_t Attr = Attrs->getParamAttrs(Idx);
if (!Idx) {
- uint16_t RetI = Attr & ReturnIncompatible;
+ uint16_t RetI = Attr & ParamAttr::ParameterOnly;
Assert1(!RetI, "Attribute " + Attrs->getParamAttrsText(RetI) +
"should not apply to functions!", &F);
} else {
- uint16_t ParmI = Attr & ParameterIncompatible;
+ uint16_t ParmI = Attr & ParamAttr::ReturnOnly;
Assert1(!ParmI, "Attribute " + Attrs->getParamAttrsText(ParmI) +
"should only be applied to function!", &F);
}
- for (unsigned i = 0; i < array_lengthof(MutuallyIncompatible); ++i) {
- uint16_t MutI = Attr & MutuallyIncompatible[i];
+ for (unsigned i = 0;
+ i < array_lengthof(ParamAttr::MutuallyIncompatible); ++i) {
+ uint16_t MutI = Attr & ParamAttr::MutuallyIncompatible[i];
Assert1(!(MutI & (MutI - 1)), "Attributes " +
Attrs->getParamAttrsText(MutI) + "are incompatible!", &F);
}
- uint16_t IType = Attr & IntegerTypeOnly;
+ uint16_t IType = Attr & ParamAttr::IntegerTypeOnly;
Assert1(!IType || FT->getParamType(Idx-1)->isInteger(),
"Attribute " + Attrs->getParamAttrsText(IType) +
"should only apply to Integer type!", &F);
- uint16_t PType = Attr & PointerTypeOnly;
+ uint16_t PType = Attr & ParamAttr::PointerTypeOnly;
Assert1(!PType || isa<PointerType>(FT->getParamType(Idx-1)),
"Attribute " + Attrs->getParamAttrsText(PType) +
"should only apply to Pointer type!", &F);