Include optional subclass flags, such as inbounds, nsw, etc., in the

Constant uniquing tables. This allows distinct ConstantExpr objects
with the same operation and different flags.

Even though a ConstantExpr "a + b" is either always overflowing or
never overflowing (due to being a ConstantExpr), it's still necessary
to be able to represent it both with and without overflow flags at
the same time within the IR, because the safety of the flag may
depend on the context of the use. If the constant really does overflow,
it wouldn't ever be safe to use with the flag set, however the use
may be in code that is never actually executed.

This also makes it possible to merge all the flags tests into a single test.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80998 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman
2009-09-04 12:08:11 +00:00
parent 70327dabb4
commit 859fff476d
16 changed files with 349 additions and 243 deletions

View File

@ -496,7 +496,7 @@ public:
Instruction *InsertBefore = 0) {
GetElementPtrInst *GEP = Create(Ptr, IdxBegin, IdxEnd,
NameStr, InsertBefore);
cast<GEPOperator>(GEP)->setIsInBounds(true);
GEP->setIsInBounds(true);
return GEP;
}
template<typename InputIterator>
@ -507,21 +507,21 @@ public:
BasicBlock *InsertAtEnd) {
GetElementPtrInst *GEP = Create(Ptr, IdxBegin, IdxEnd,
NameStr, InsertAtEnd);
cast<GEPOperator>(GEP)->setIsInBounds(true);
GEP->setIsInBounds(true);
return GEP;
}
static GetElementPtrInst *CreateInBounds(Value *Ptr, Value *Idx,
const Twine &NameStr = "",
Instruction *InsertBefore = 0) {
GetElementPtrInst *GEP = Create(Ptr, Idx, NameStr, InsertBefore);
cast<GEPOperator>(GEP)->setIsInBounds(true);
GEP->setIsInBounds(true);
return GEP;
}
static GetElementPtrInst *CreateInBounds(Value *Ptr, Value *Idx,
const Twine &NameStr,
BasicBlock *InsertAtEnd) {
GetElementPtrInst *GEP = Create(Ptr, Idx, NameStr, InsertAtEnd);
cast<GEPOperator>(GEP)->setIsInBounds(true);
GEP->setIsInBounds(true);
return GEP;
}
@ -602,6 +602,10 @@ public:
/// a constant offset between them.
bool hasAllConstantIndices() const;
/// setIsInBounds - Set or clear the inbounds flag on this GEP instruction.
/// See LangRef.html for the meaning of inbounds on a getelementptr.
void setIsInBounds(bool);
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const GetElementPtrInst *) { return true; }
static inline bool classof(const Instruction *I) {