diff options
author | Eric Christopher <echristo@apple.com> | 2010-02-09 17:29:18 +0000 |
---|---|---|
committer | Eric Christopher <echristo@apple.com> | 2010-02-09 17:29:18 +0000 |
commit | d2592ff69ba86d8d5da5b598429f373cb2842699 (patch) | |
tree | 73180c65a0c03cdba9005183760c276955f5137f /lib/Transforms | |
parent | 4b42a1e40f82143baea033c41e448af5cf801a28 (diff) | |
download | external_llvm-d2592ff69ba86d8d5da5b598429f373cb2842699.zip external_llvm-d2592ff69ba86d8d5da5b598429f373cb2842699.tar.gz external_llvm-d2592ff69ba86d8d5da5b598429f373cb2842699.tar.bz2 |
Pull these back out, they're a little too aggressive and time
consuming for a simple optimization.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95671 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/Scalar/CMakeLists.txt | 1 | ||||
-rw-r--r-- | lib/Transforms/Scalar/ObjectSizeLowering.cpp | 114 |
2 files changed, 0 insertions, 115 deletions
diff --git a/lib/Transforms/Scalar/CMakeLists.txt b/lib/Transforms/Scalar/CMakeLists.txt index fd95014..683c1c2 100644 --- a/lib/Transforms/Scalar/CMakeLists.txt +++ b/lib/Transforms/Scalar/CMakeLists.txt @@ -18,7 +18,6 @@ add_llvm_library(LLVMScalarOpts LoopUnrollPass.cpp LoopUnswitch.cpp MemCpyOptimizer.cpp - ObjectSizeLowering.cpp Reassociate.cpp Reg2Mem.cpp SCCP.cpp diff --git a/lib/Transforms/Scalar/ObjectSizeLowering.cpp b/lib/Transforms/Scalar/ObjectSizeLowering.cpp deleted file mode 100644 index 9660e79..0000000 --- a/lib/Transforms/Scalar/ObjectSizeLowering.cpp +++ /dev/null @@ -1,114 +0,0 @@ -//===-- ObjectSizeLowering.cpp - Loop unroller pass -----------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This pass lowers Intrinsic::objectsize using SCEV to determine minimum or -// maximum space left in an allocated object. -//===----------------------------------------------------------------------===// - -#define DEBUG_TYPE "objsize-lower" -#include "llvm/Constants.h" -#include "llvm/Module.h" -#include "llvm/Value.h" -#include "llvm/Target/TargetData.h" -#include "llvm/IntrinsicInst.h" -#include "llvm/Transforms/Scalar.h" -#include "llvm/Analysis/ScalarEvolution.h" -#include "llvm/Analysis/ScalarEvolutionExpander.h" -#include "llvm/Support/CommandLine.h" -#include "llvm/Support/Debug.h" -#include "llvm/Support/raw_ostream.h" - -using namespace llvm; - -namespace { - class ObjSizeLower : public FunctionPass { - ScalarEvolution *SE; - TargetData *TD; - public: - static char ID; // Pass identification, replacement for typeid - ObjSizeLower() : FunctionPass(&ID) {} - - bool runOnFunction(Function &F); - virtual void getAnalysisUsage(AnalysisUsage &AU) const { - AU.setPreservesCFG(); - AU.addRequired<ScalarEvolution>(); - AU.addPreserved<ScalarEvolution>(); - } - private: - bool LowerCall(IntrinsicInst *); - void ReplaceAllUsesWithUnknown(IntrinsicInst *, bool); - }; -} - -char ObjSizeLower::ID = 0; -static RegisterPass<ObjSizeLower> X("objsize-lower", - "Object Size Lowering"); - -// Public interface to the Object Size Lowering pass -FunctionPass *llvm::createObjectSizeLoweringPass() { - return new ObjSizeLower(); -} - -/// runOnFunction - Top level algorithm - Loop over each object size intrinsic -/// and use Scalar Evolutions to get the maximum or minimum size left in the -/// allocated object at any point. -bool ObjSizeLower::runOnFunction(Function &F) { - SE = &getAnalysis<ScalarEvolution>(); - TD = getAnalysisIfAvailable<TargetData>(); - - // We really need TargetData for size calculations. - if (!TD) return false; - - bool Changed = false; - for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) { - for (BasicBlock::iterator I = BB->begin(), L = BB->end(); I != L; ) { - CallInst *CI = dyn_cast<CallInst>(I++); - if (!CI) continue; - - // The only thing we care about are Intrinsic::objectsize calls - IntrinsicInst *II = dyn_cast<IntrinsicInst>(CI); - if (!II || II->getIntrinsicID() != Intrinsic::objectsize) continue; - - Changed |= LowerCall(II); - } - } - return Changed; -} - -// Unknown for llvm.objsize is -1 for maximum size, and 0 for minimum size. -void ObjSizeLower::ReplaceAllUsesWithUnknown(IntrinsicInst *II, bool min) { - const Type *ReturnTy = II->getCalledFunction()->getReturnType(); - II->replaceAllUsesWith(ConstantInt::get(ReturnTy, min ? 0 : -1ULL)); - II->eraseFromParent(); -} - -bool ObjSizeLower::LowerCall(IntrinsicInst *II) { - ConstantInt *CI = cast<ConstantInt>(II->getOperand(2)); - bool minimum = (CI->getZExtValue() == 1); - Value *Op = II->getOperand(1); - const Type *ReturnTy = II->getCalledFunction()->getReturnType(); - - // Grab the SCEV for our access. - const SCEV *thisEV = SE->getSCEV(Op); - - if (const SCEVUnknown *SU = dyn_cast<SCEVUnknown>(thisEV)) { - if (GlobalVariable *GV = dyn_cast<GlobalVariable>(SU->getValue())) { - if (GV->hasDefinitiveInitializer()) { - Constant *C = GV->getInitializer(); - size_t globalSize = TD->getTypeAllocSize(C->getType()); - II->replaceAllUsesWith(ConstantInt::get(ReturnTy, globalSize)); - II->eraseFromParent(); - return true; - } - } - } - - ReplaceAllUsesWithUnknown(II, minimum); - return true; -} |