Ramkumar Ramachandra
2015-Jan-17 19:25 UTC
[LLVMdev] How to test isDereferenceablePointer?
I'm have a [PATCH] isDereferenceablePointer: look through gc.relocates and I want to know how to test this patch. So far, I've found one candiate: speculative execution in SimplifyCFG (test/Transforms/SimplifyCFG/SpeculativeExec.ll). However, it's somewhat involved to show that SimplifyCFG does kick in for gc.relocate. Is there a better way to directly test it? Signed-off-by: Ramkumar Ramachandra <artagnon at gmail.com> --- lib/IR/Value.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/IR/Value.cpp b/lib/IR/Value.cpp index 5f7e258..aa701d5 100644 --- a/lib/IR/Value.cpp +++ b/lib/IR/Value.cpp @@ -23,8 +23,10 @@ #include "llvm/IR/GetElementPtrTypeIterator.h" #include "llvm/IR/InstrTypes.h" #include "llvm/IR/Instructions.h" +#include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Module.h" #include "llvm/IR/Operator.h" +#include "llvm/IR/Statepoint.h" #include "llvm/IR/ValueHandle.h" #include "llvm/IR/ValueSymbolTable.h" #include "llvm/Support/Debug.h" @@ -570,6 +572,13 @@ static bool isDereferenceablePointer(const Value *V, const DataLayout *DL, return true; } + // For gc.relocate, look through relocations + if (const IntrinsicInst *I = dyn_cast<IntrinsicInst>(V)) + if (I->getIntrinsicID() == Intrinsic::experimental_gc_relocate) { + GCRelocateOperands RelocateInst(I); + return isDereferenceablePointer(RelocateInst.derivedPtr(), DL, Visited); + } + if (const AddrSpaceCastInst *ASC = dyn_cast<AddrSpaceCastInst>(V)) return isDereferenceablePointer(ASC->getOperand(0), DL, Visited); -- 2.2.1
T.M.K., there's no direct way to test it. You have to construct a transformation which happens with the information you added and not otherwise. The easiest case might be LICM. Philip On 01/17/2015 11:25 AM, Ramkumar Ramachandra wrote:> I'm have a > [PATCH] isDereferenceablePointer: look through gc.relocates > > and I want to know how to test this patch. So far, I've found one > candiate: speculative execution in SimplifyCFG > (test/Transforms/SimplifyCFG/SpeculativeExec.ll). However, it's > somewhat involved to show that SimplifyCFG does kick in for > gc.relocate. Is there a better way to directly test it? > > Signed-off-by: Ramkumar Ramachandra <artagnon at gmail.com> > --- > lib/IR/Value.cpp | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/lib/IR/Value.cpp b/lib/IR/Value.cpp > index 5f7e258..aa701d5 100644 > --- a/lib/IR/Value.cpp > +++ b/lib/IR/Value.cpp > @@ -23,8 +23,10 @@ > #include "llvm/IR/GetElementPtrTypeIterator.h" > #include "llvm/IR/InstrTypes.h" > #include "llvm/IR/Instructions.h" > +#include "llvm/IR/IntrinsicInst.h" > #include "llvm/IR/Module.h" > #include "llvm/IR/Operator.h" > +#include "llvm/IR/Statepoint.h" > #include "llvm/IR/ValueHandle.h" > #include "llvm/IR/ValueSymbolTable.h" > #include "llvm/Support/Debug.h" > @@ -570,6 +572,13 @@ static bool isDereferenceablePointer(const Value *V, const DataLayout *DL, > return true; > } > > + // For gc.relocate, look through relocations > + if (const IntrinsicInst *I = dyn_cast<IntrinsicInst>(V)) > + if (I->getIntrinsicID() == Intrinsic::experimental_gc_relocate) { > + GCRelocateOperands RelocateInst(I); > + return isDereferenceablePointer(RelocateInst.derivedPtr(), DL, Visited); > + } > + > if (const AddrSpaceCastInst *ASC = dyn_cast<AddrSpaceCastInst>(V)) > return isDereferenceablePointer(ASC->getOperand(0), DL, Visited); >
Philip Reames wrote:> T.M.K., there's no direct way to test it.There is. See the 'unittests/' directory which contains the C++ unit tests. See unittests/IR/UserTest.cpp for an example that builds up IR from a .ll-in-a-C-string then queries C++ API operations on it. Nick You have to construct a> transformation which happens with the information you added and not > otherwise. > > The easiest case might be LICM. > > Philip > > On 01/17/2015 11:25 AM, Ramkumar Ramachandra wrote: >> I'm have a >> [PATCH] isDereferenceablePointer: look through gc.relocates >> >> and I want to know how to test this patch. So far, I've found one >> candiate: speculative execution in SimplifyCFG >> (test/Transforms/SimplifyCFG/SpeculativeExec.ll). However, it's >> somewhat involved to show that SimplifyCFG does kick in for >> gc.relocate. Is there a better way to directly test it? >> >> Signed-off-by: Ramkumar Ramachandra <artagnon at gmail.com> >> --- >> lib/IR/Value.cpp | 9 +++++++++ >> 1 file changed, 9 insertions(+) >> >> diff --git a/lib/IR/Value.cpp b/lib/IR/Value.cpp >> index 5f7e258..aa701d5 100644 >> --- a/lib/IR/Value.cpp >> +++ b/lib/IR/Value.cpp >> @@ -23,8 +23,10 @@ >> #include "llvm/IR/GetElementPtrTypeIterator.h" >> #include "llvm/IR/InstrTypes.h" >> #include "llvm/IR/Instructions.h" >> +#include "llvm/IR/IntrinsicInst.h" >> #include "llvm/IR/Module.h" >> #include "llvm/IR/Operator.h" >> +#include "llvm/IR/Statepoint.h" >> #include "llvm/IR/ValueHandle.h" >> #include "llvm/IR/ValueSymbolTable.h" >> #include "llvm/Support/Debug.h" >> @@ -570,6 +572,13 @@ static bool isDereferenceablePointer(const Value >> *V, const DataLayout *DL, >> return true; >> } >> + // For gc.relocate, look through relocations >> + if (const IntrinsicInst *I = dyn_cast<IntrinsicInst>(V)) >> + if (I->getIntrinsicID() == Intrinsic::experimental_gc_relocate) { >> + GCRelocateOperands RelocateInst(I); >> + return isDereferenceablePointer(RelocateInst.derivedPtr(), DL, >> Visited); >> + } >> + >> if (const AddrSpaceCastInst *ASC = dyn_cast<AddrSpaceCastInst>(V)) >> return isDereferenceablePointer(ASC->getOperand(0), DL, Visited); > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >