From: Benjamin Kramer Date: Wed, 7 Dec 2016 12:31:45 +0000 (+0000) Subject: [LowerTypeTests] Use the TrailingObjects infrastructure for trailing objects. X-Git-Tag: android-x86-7.1-r4~23567 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=fe16faa967bc8ed0258edc41d1bf60422c8985f1;p=android-x86%2Fexternal-llvm.git [LowerTypeTests] Use the TrailingObjects infrastructure for trailing objects. Also avoid allocating ~3x as much memory as needed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288904 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/IPO/LowerTypeTests.cpp b/lib/Transforms/IPO/LowerTypeTests.cpp index e4e3f151073..88942fdebff 100644 --- a/lib/Transforms/IPO/LowerTypeTests.cpp +++ b/lib/Transforms/IPO/LowerTypeTests.cpp @@ -30,6 +30,7 @@ #include "llvm/IR/Operator.h" #include "llvm/Pass.h" #include "llvm/Support/Debug.h" +#include "llvm/Support/TrailingObjects.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/IPO.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" @@ -211,26 +212,29 @@ struct ByteArrayInfo { /// metadata types referenced by a global, which at the IR level is an expensive /// operation involving a map lookup; this data structure helps to reduce the /// number of times we need to do this lookup. -class GlobalTypeMember { +class GlobalTypeMember final : TrailingObjects { GlobalObject *GO; size_t NTypes; - MDNode *Types[1]; // We treat this as a flexible array member. + + friend class TrailingObjects; + size_t numTrailingObjects(OverloadToken) const { return NTypes; } public: static GlobalTypeMember *create(BumpPtrAllocator &Alloc, GlobalObject *GO, ArrayRef Types) { - auto GTM = Alloc.Allocate( - sizeof(GlobalTypeMember) + (Types.size() - 1) * sizeof(MDNode *)); + auto *GTM = static_cast(Alloc.Allocate( + totalSizeToAlloc(Types.size()), alignof(GlobalTypeMember))); GTM->GO = GO; GTM->NTypes = Types.size(); - std::copy(Types.begin(), Types.end(), GTM->Types); + std::uninitialized_copy(Types.begin(), Types.end(), + GTM->getTrailingObjects()); return GTM; } GlobalObject *getGlobal() const { return GO; } ArrayRef types() const { - return {&Types[0], &Types[NTypes]}; + return makeArrayRef(getTrailingObjects(), NTypes); } };