diff options
author | Ramkumar Ramachandra <artagnon@gmail.com> | 2015-02-14 19:37:54 +0000 |
---|---|---|
committer | Ramkumar Ramachandra <artagnon@gmail.com> | 2015-02-14 19:37:54 +0000 |
commit | 8fcb498a9a0825c7f6fd114f4832a5f875a05db4 (patch) | |
tree | c289569a2f5dbb8d40b419d17ff422393b65de56 /llvm/lib | |
parent | 320fc2657bf4567a495e9ce02adf6de9e97721cc (diff) | |
download | bcm5719-llvm-8fcb498a9a0825c7f6fd114f4832a5f875a05db4.tar.gz bcm5719-llvm-8fcb498a9a0825c7f6fd114f4832a5f875a05db4.zip |
InstCombine: propagate deref via new addDereferenceableAttr
The "dereferenceable" attribute cannot be added via .addAttribute(),
since it also expects a size in bytes. AttrBuilder#addAttribute or
AttributeSet#addAttribute is wrapped by classes Function, InvokeInst,
and CallInst. Add corresponding wrappers to
AttrBuilder#addDereferenceableAttr.
Having done this, propagate the dereferenceable attribute via
gc.relocate, adding a test to exercise it. Note that -datalayout is
required during execution over and above -instcombine, because
InstCombine only optionally requires DataLayoutPass.
Differential Revision: http://reviews.llvm.org/D7510
llvm-svn: 229265
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/IR/Attributes.cpp | 7 | ||||
-rw-r--r-- | llvm/lib/IR/Function.cpp | 6 | ||||
-rw-r--r-- | llvm/lib/IR/Instructions.cpp | 12 | ||||
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | 10 |
4 files changed, 33 insertions, 2 deletions
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp index 04545ea919a..daac6b5f639 100644 --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -835,6 +835,13 @@ AttributeSet AttributeSet::removeAttributes(LLVMContext &C, unsigned Index, return get(C, AttrSet); } +AttributeSet AttributeSet::addDereferenceableAttr(LLVMContext &C, unsigned Index, + uint64_t Bytes) const { + llvm::AttrBuilder B; + B.addDereferenceableAttr(Bytes); + return addAttributes(C, Index, AttributeSet::get(C, Index, B)); +} + //===----------------------------------------------------------------------===// // AttributeSet Accessor Methods //===----------------------------------------------------------------------===// diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp index fe44f17d686..33e15262524 100644 --- a/llvm/lib/IR/Function.cpp +++ b/llvm/lib/IR/Function.cpp @@ -343,6 +343,12 @@ void Function::removeAttributes(unsigned i, AttributeSet attrs) { setAttributes(PAL); } +void Function::addDereferenceableAttr(unsigned i, uint64_t Bytes) { + AttributeSet PAL = getAttributes(); + PAL = PAL.addDereferenceableAttr(getContext(), i, Bytes); + setAttributes(PAL); +} + // Maintain the GC name for each function in an on-the-side table. This saves // allocating an additional word in Function for programs which do not use GC // (i.e., most programs) at the cost of increased overhead for clients which do diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp index 132800efeeb..8c4eeafdf84 100644 --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -346,6 +346,12 @@ void CallInst::removeAttribute(unsigned i, Attribute attr) { setAttributes(PAL); } +void CallInst::addDereferenceableAttr(unsigned i, uint64_t Bytes) { + AttributeSet PAL = getAttributes(); + PAL = PAL.addDereferenceableAttr(getContext(), i, Bytes); + setAttributes(PAL); +} + bool CallInst::hasFnAttrImpl(Attribute::AttrKind A) const { if (AttributeList.hasAttribute(AttributeSet::FunctionIndex, A)) return true; @@ -605,6 +611,12 @@ void InvokeInst::removeAttribute(unsigned i, Attribute attr) { setAttributes(PAL); } +void InvokeInst::addDereferenceableAttr(unsigned i, uint64_t Bytes) { + AttributeSet PAL = getAttributes(); + PAL = PAL.addDereferenceableAttr(getContext(), i, Bytes); + setAttributes(PAL); +} + LandingPadInst *InvokeInst::getLandingPadInst() const { return cast<LandingPadInst>(getUnwindDest()->getFirstNonPHI()); } diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index 87dc8621a95..53a90d05af7 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -1127,11 +1127,17 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) { if (isKnownNonNull(DerivedPtr)) II->addAttribute(AttributeSet::ReturnIndex, Attribute::NonNull); - // TODO: dereferenceable -> deref attribute + // isDereferenceablePointer -> deref attribute + if (DerivedPtr->isDereferenceablePointer(DL)) { + if (Argument *A = dyn_cast<Argument>(DerivedPtr)) { + uint64_t Bytes = A->getDereferenceableBytes(); + II->addDereferenceableAttr(AttributeSet::ReturnIndex, Bytes); + } + } // TODO: bitcast(relocate(p)) -> relocate(bitcast(p)) // Canonicalize on the type from the uses to the defs - + // TODO: relocate((gep p, C, C2, ...)) -> gep(relocate(p), C, C2, ...) } } |