r256622 - [MS ABI] Improve our mangling of pass_object_size
David Majnemer via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 29 21:13:04 PST 2015
Author: majnemer
Date: Tue Dec 29 23:13:03 2015
New Revision: 256622
URL: http://llvm.org/viewvc/llvm-project?rev=256622&view=rev
Log:
[MS ABI] Improve our mangling of pass_object_size
We didn't add the artificial pass_object_size arguments to the
backreference map which bloated the size of manglings which involved
pass_object_size with duplicate types.
This lets us go from:
?qux at PassObjectSize@@YAHQAHW4__pass_object_size1 at __clang@@0W4__pass_object_size1 at 3@@Z
to:
?qux at PassObjectSize@@YAHQAHW4__pass_object_size1 at __clang@@01 at Z
Modified:
cfe/trunk/lib/AST/MicrosoftMangle.cpp
cfe/trunk/test/CodeGenCXX/mangle-ms.cpp
Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=256622&r1=256621&r2=256622&view=diff
==============================================================================
--- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
+++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Tue Dec 29 23:13:03 2015
@@ -224,6 +224,9 @@ class MicrosoftCXXNameMangler {
typedef llvm::DenseMap<void *, unsigned> ArgBackRefMap;
ArgBackRefMap TypeBackReferences;
+ typedef std::set<int> PassObjectSizeArgsSet;
+ PassObjectSizeArgsSet PassObjectSizeArgs;
+
ASTContext &getASTContext() const { return Context.getASTContext(); }
// FIXME: If we add support for __ptr32/64 qualifiers, then we should push
@@ -293,6 +296,7 @@ private:
void mangleObjCMethodName(const ObjCMethodDecl *MD);
void mangleArgumentType(QualType T, SourceRange Range);
+ void manglePassObjectSizeArg(const PassObjectSizeAttr *POSA);
// Declare manglers for every type class.
#define ABSTRACT_TYPE(CLASS, PARENT)
@@ -1083,8 +1087,10 @@ void MicrosoftCXXNameMangler::mangleTemp
// Templates have their own context for back references.
ArgBackRefMap OuterArgsContext;
BackRefVec OuterTemplateContext;
+ PassObjectSizeArgsSet OuterPassObjectSizeArgs;
NameBackReferences.swap(OuterTemplateContext);
TypeBackReferences.swap(OuterArgsContext);
+ PassObjectSizeArgs.swap(OuterPassObjectSizeArgs);
mangleUnscopedTemplateName(TD);
mangleTemplateArgs(TD, TemplateArgs);
@@ -1092,6 +1098,7 @@ void MicrosoftCXXNameMangler::mangleTemp
// Restore the previous back reference contexts.
NameBackReferences.swap(OuterTemplateContext);
TypeBackReferences.swap(OuterArgsContext);
+ PassObjectSizeArgs.swap(OuterPassObjectSizeArgs);
}
void
@@ -1477,6 +1484,27 @@ void MicrosoftCXXNameMangler::mangleArgu
}
}
+void MicrosoftCXXNameMangler::manglePassObjectSizeArg(
+ const PassObjectSizeAttr *POSA) {
+ int Type = POSA->getType();
+
+ auto Iter = PassObjectSizeArgs.insert(Type).first;
+ void *TypePtr = (void *)&*Iter;
+ ArgBackRefMap::iterator Found = TypeBackReferences.find(TypePtr);
+
+ if (Found == TypeBackReferences.end()) {
+ mangleArtificalTagType(TTK_Enum, "__pass_object_size" + llvm::utostr(Type),
+ {"__clang"});
+
+ if (TypeBackReferences.size() < 10) {
+ size_t Size = TypeBackReferences.size();
+ TypeBackReferences[TypePtr] = Size;
+ }
+ } else {
+ Out << Found->second;
+ }
+}
+
void MicrosoftCXXNameMangler::mangleType(QualType T, SourceRange Range,
QualifierMangleMode QMM) {
// Don't use the canonical types. MSVC includes things like 'const' on
@@ -1879,10 +1907,8 @@ void MicrosoftCXXNameMangler::mangleFunc
// necessary to just cross our fingers and hope this type+namespace
// combination doesn't conflict with anything?
if (D)
- if (auto *P = D->getParamDecl(I)->getAttr<PassObjectSizeAttr>())
- mangleArtificalTagType(TTK_Enum, "__pass_object_size" +
- llvm::utostr(P->getType()),
- {"__clang"});
+ if (const auto *P = D->getParamDecl(I)->getAttr<PassObjectSizeAttr>())
+ manglePassObjectSizeArg(P);
}
// <builtin-type> ::= Z # ellipsis
if (Proto->isVariadic())
Modified: cfe/trunk/test/CodeGenCXX/mangle-ms.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-ms.cpp?rev=256622&r1=256621&r2=256622&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle-ms.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle-ms.cpp Tue Dec 29 23:13:03 2015
@@ -440,6 +440,10 @@ namespace PassObjectSize {
int foo(int *const i __attribute__((pass_object_size(0)))) { return 0; }
// CHECK-DAG: define i32 @"\01?bar at PassObjectSize@@YAHQAHW4__pass_object_size1 at __clang@@@Z"
int bar(int *const i __attribute__((pass_object_size(1)))) { return 0; }
+// CHECK-DAG: define i32 @"\01?qux at PassObjectSize@@YAHQAHW4__pass_object_size1 at __clang@@0W4__pass_object_size0 at 3@@Z"
+int qux(int *const i __attribute__((pass_object_size(1))), int *const j __attribute__((pass_object_size(0)))) { return 0; }
+// CHECK-DAG: define i32 @"\01?zot at PassObjectSize@@YAHQAHW4__pass_object_size1 at __clang@@01 at Z"
+int zot(int *const i __attribute__((pass_object_size(1))), int *const j __attribute__((pass_object_size(1)))) { return 0; }
}
namespace Atomic {
More information about the cfe-commits
mailing list