From: Peter Collingbourne Date: Tue, 10 May 2016 17:54:43 +0000 (+0000) Subject: Revert r269081 and r269082 while I try to find the right incantation to fix MSVC... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b6f6e4455cf9a41ab59625e53282c47e49be8126;p=llvm Revert r269081 and r269082 while I try to find the right incantation to fix MSVC build. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269091 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Analysis/BitSetUtils.h b/include/llvm/Analysis/BitSetUtils.h deleted file mode 100644 index 8f799482b80..00000000000 --- a/include/llvm/Analysis/BitSetUtils.h +++ /dev/null @@ -1,38 +0,0 @@ -//===- BitSetUtils.h - Utilities related to pointer bitsets ------*- C++ -*-==// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file contains functions that make it easier to manipulate bitsets for -// devirtualization. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_ANALYSIS_BITSETUTILS_H -#define LLVM_ANALYSIS_BITSETUTILS_H - -#include "llvm/ADT/SmallVector.h" -#include "llvm/IR/CallSite.h" - -namespace llvm { - -/// A call site that could be devirtualized. -struct DevirtCallSite { - /// The offset from the address point to the virtual function. - uint64_t Offset; - /// The call site itself. - CallSite CS; -}; - -/// Given a call to the intrinsic @llvm.bitset.test, find all devirtualizable -/// call sites based on the call and return them in DevirtCalls. -void findDevirtualizableCalls(SmallVectorImpl &DevirtCalls, - SmallVectorImpl &Assumes, - CallInst *CI); -} - -#endif diff --git a/lib/Analysis/BitSetUtils.cpp b/lib/Analysis/BitSetUtils.cpp deleted file mode 100644 index d83dca60cce..00000000000 --- a/lib/Analysis/BitSetUtils.cpp +++ /dev/null @@ -1,82 +0,0 @@ -//===- BitSetUtils.cpp - Utilities related to pointer bitsets -------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file contains functions that make it easier to manipulate bitsets for -// devirtualization. -// -//===----------------------------------------------------------------------===// - -#include "llvm/Analysis/BitSetUtils.h" -#include "llvm/IR/Intrinsics.h" -#include "llvm/IR/Module.h" - -using namespace llvm; - -// Search for virtual calls that call FPtr and add them to DevirtCalls. -static void -findCallsAtConstantOffset(SmallVectorImpl &DevirtCalls, - Value *FPtr, uint64_t Offset) { - for (const Use &U : FPtr->uses()) { - Value *User = U.getUser(); - if (isa(User)) { - findCallsAtConstantOffset(DevirtCalls, User, Offset); - } else if (auto CI = dyn_cast(User)) { - DevirtCalls.push_back({Offset, CI}); - } else if (auto II = dyn_cast(User)) { - DevirtCalls.push_back({Offset, II}); - } - } -} - -// Search for virtual calls that load from VPtr and add them to DevirtCalls. -static void -findLoadCallsAtConstantOffset(Module *M, - SmallVectorImpl &DevirtCalls, - Value *VPtr, uint64_t Offset) { - for (const Use &U : VPtr->uses()) { - Value *User = U.getUser(); - if (isa(User)) { - findLoadCallsAtConstantOffset(M, DevirtCalls, User, Offset); - } else if (isa(User)) { - findCallsAtConstantOffset(DevirtCalls, User, Offset); - } else if (auto GEP = dyn_cast(User)) { - // Take into account the GEP offset. - if (VPtr == GEP->getPointerOperand() && GEP->hasAllConstantIndices()) { - SmallVector Indices(GEP->op_begin() + 1, GEP->op_end()); - uint64_t GEPOffset = M->getDataLayout().getIndexedOffsetInType( - GEP->getSourceElementType(), Indices); - findLoadCallsAtConstantOffset(M, DevirtCalls, User, Offset + GEPOffset); - } - } - } -} - -void llvm::findDevirtualizableCalls( - SmallVectorImpl &DevirtCalls, - SmallVectorImpl &Assumes, CallInst *CI) { - assert(CI->getCalledFunction()->getIntrinsicID() == Intrinsic::bitset_test); - - Module *M = CI->getParent()->getParent()->getParent(); - - // Find llvm.assume intrinsics for this llvm.bitset.test call. - for (const Use &CIU : CI->uses()) { - auto AssumeCI = dyn_cast(CIU.getUser()); - if (AssumeCI) { - Function *F = AssumeCI->getCalledFunction(); - if (F && F->getIntrinsicID() == Intrinsic::assume) - Assumes.push_back(AssumeCI); - } - } - - // If we found any, search for virtual calls based on %p and add them to - // DevirtCalls. - if (!Assumes.empty()) - findLoadCallsAtConstantOffset(M, DevirtCalls, - CI->getArgOperand(0)->stripPointerCasts(), 0); -} diff --git a/lib/Analysis/CMakeLists.txt b/lib/Analysis/CMakeLists.txt index c598d9e4971..0ec27443d8a 100644 --- a/lib/Analysis/CMakeLists.txt +++ b/lib/Analysis/CMakeLists.txt @@ -5,7 +5,6 @@ add_llvm_library(LLVMAnalysis Analysis.cpp AssumptionCache.cpp BasicAliasAnalysis.cpp - BitSetUtils.cpp BlockFrequencyInfo.cpp BlockFrequencyInfoImpl.cpp BranchProbabilityInfo.cpp diff --git a/lib/Transforms/IPO/WholeProgramDevirt.cpp b/lib/Transforms/IPO/WholeProgramDevirt.cpp index 49f0b503aec..e7c161dd029 100644 --- a/lib/Transforms/IPO/WholeProgramDevirt.cpp +++ b/lib/Transforms/IPO/WholeProgramDevirt.cpp @@ -31,7 +31,6 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/MapVector.h" -#include "llvm/Analysis/BitSetUtils.h" #include "llvm/IR/CallSite.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DataLayout.h" @@ -232,6 +231,10 @@ struct DevirtModule { : M(M), Int8Ty(Type::getInt8Ty(M.getContext())), Int8PtrTy(Type::getInt8PtrTy(M.getContext())), Int32Ty(Type::getInt32Ty(M.getContext())) {} + void findLoadCallsAtConstantOffset(Metadata *BitSet, Value *Ptr, + uint64_t Offset, Value *VTable); + void findCallsAtConstantOffset(Metadata *BitSet, Value *Ptr, uint64_t Offset, + Value *VTable); void buildBitSets(std::vector &Bits, DenseMap> &BitSets); @@ -280,6 +283,43 @@ ModulePass *llvm::createWholeProgramDevirtPass() { return new WholeProgramDevirt; } +// Search for virtual calls that call FPtr and add them to CallSlots. +void DevirtModule::findCallsAtConstantOffset(Metadata *BitSet, Value *FPtr, + uint64_t Offset, Value *VTable) { + for (const Use &U : FPtr->uses()) { + Value *User = U.getUser(); + if (isa(User)) { + findCallsAtConstantOffset(BitSet, User, Offset, VTable); + } else if (auto CI = dyn_cast(User)) { + CallSlots[{BitSet, Offset}].push_back({VTable, CI}); + } else if (auto II = dyn_cast(User)) { + CallSlots[{BitSet, Offset}].push_back({VTable, II}); + } + } +} + +// Search for virtual calls that load from VPtr and add them to CallSlots. +void DevirtModule::findLoadCallsAtConstantOffset(Metadata *BitSet, Value *VPtr, + uint64_t Offset, + Value *VTable) { + for (const Use &U : VPtr->uses()) { + Value *User = U.getUser(); + if (isa(User)) { + findLoadCallsAtConstantOffset(BitSet, User, Offset, VTable); + } else if (isa(User)) { + findCallsAtConstantOffset(BitSet, User, Offset, VTable); + } else if (auto GEP = dyn_cast(User)) { + // Take into account the GEP offset. + if (VPtr == GEP->getPointerOperand() && GEP->hasAllConstantIndices()) { + SmallVector Indices(GEP->op_begin() + 1, GEP->op_end()); + uint64_t GEPOffset = M.getDataLayout().getIndexedOffsetInType( + GEP->getSourceElementType(), Indices); + findLoadCallsAtConstantOffset(BitSet, User, Offset + GEPOffset, VTable); + } + } + } +} + void DevirtModule::buildBitSets( std::vector &Bits, DenseMap> &BitSets) { @@ -634,23 +674,22 @@ bool DevirtModule::run() { if (!CI) continue; - // Search for virtual calls based on %p and add them to DevirtCalls. - SmallVector DevirtCalls; + // Find llvm.assume intrinsics for this llvm.bitset.test call. SmallVector Assumes; - findDevirtualizableCalls(DevirtCalls, Assumes, CI); + for (const Use &CIU : CI->uses()) { + auto AssumeCI = dyn_cast(CIU.getUser()); + if (AssumeCI && AssumeCI->getCalledValue() == AssumeFunc) + Assumes.push_back(AssumeCI); + } - // If we found any, add them to CallSlots. Only do this if we haven't seen - // the vtable pointer before, as it may have been CSE'd with pointers from - // other call sites, and we don't want to process call sites multiple times. + // If we found any, search for virtual calls based on %p and add them to + // CallSlots. if (!Assumes.empty()) { Metadata *BitSet = cast(CI->getArgOperand(1))->getMetadata(); Value *Ptr = CI->getArgOperand(0)->stripPointerCasts(); - if (SeenPtrs.insert(Ptr).second) { - for (DevirtCallSite Call : DevirtCalls) - CallSlots[{BitSet, Call.Offset}].push_back( - {CI->getArgOperand(0), Call.CS}); - } + if (SeenPtrs.insert(Ptr).second) + findLoadCallsAtConstantOffset(BitSet, Ptr, 0, CI->getArgOperand(0)); } // We no longer need the assumes or the bitset test.