Skip to content

Commit

Permalink
Convert ConstantFolder APIs to use ArrayRef.
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135671 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
jayfoad committed Jul 21, 2011
1 parent c30a38f commit 12fc16f
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 59 deletions.
46 changes: 30 additions & 16 deletions include/llvm/Support/ConstantFolder.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,22 +118,36 @@ class ConstantFolder {
// Memory Instructions
//===--------------------------------------------------------------------===//

Constant *CreateGetElementPtr(Constant *C, Constant* const *IdxList,
unsigned NumIdx) const {
return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx);
}
Constant *CreateGetElementPtr(Constant *C, Value* const *IdxList,
unsigned NumIdx) const {
return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx);
}

Constant *CreateInBoundsGetElementPtr(Constant *C, Constant* const *IdxList,
unsigned NumIdx) const {
return ConstantExpr::getInBoundsGetElementPtr(C, IdxList, NumIdx);
}
Constant *CreateInBoundsGetElementPtr(Constant *C, Value* const *IdxList,
unsigned NumIdx) const {
return ConstantExpr::getInBoundsGetElementPtr(C, IdxList, NumIdx);
Constant *CreateGetElementPtr(Constant *C,
ArrayRef<Constant *> IdxList) const {
return ConstantExpr::getGetElementPtr(C, IdxList.data(), IdxList.size());
}
Constant *CreateGetElementPtr(Constant *C, Constant *Idx) const {
// This form of the function only exists to avoid ambiguous overload
// warnings about whether to convert Idx to ArrayRef<Constant *> or
// ArrayRef<Value *>.
return ConstantExpr::getGetElementPtr(C, &Idx, 1);
}
Constant *CreateGetElementPtr(Constant *C,
ArrayRef<Value *> IdxList) const {
return ConstantExpr::getGetElementPtr(C, IdxList.data(), IdxList.size());
}

Constant *CreateInBoundsGetElementPtr(Constant *C,
ArrayRef<Constant *> IdxList) const {
return ConstantExpr::getInBoundsGetElementPtr(C, IdxList.data(),
IdxList.size());
}
Constant *CreateInBoundsGetElementPtr(Constant *C, Constant *Idx) const {
// This form of the function only exists to avoid ambiguous overload
// warnings about whether to convert Idx to ArrayRef<Constant *> or
// ArrayRef<Value *>.
return ConstantExpr::getInBoundsGetElementPtr(C, &Idx, 1);
}
Constant *CreateInBoundsGetElementPtr(Constant *C,
ArrayRef<Value *> IdxList) const {
return ConstantExpr::getInBoundsGetElementPtr(C, IdxList.data(),
IdxList.size());
}

//===--------------------------------------------------------------------===//
Expand Down
28 changes: 14 additions & 14 deletions include/llvm/Support/IRBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -774,8 +774,8 @@ class IRBuilder : public IRBuilderBase, public Inserter {
if (!isa<Constant>(*i))
break;
if (i == IdxEnd)
return Insert(Folder.CreateGetElementPtr(PC, &IdxBegin[0],
IdxEnd - IdxBegin),
return Insert(Folder.CreateGetElementPtr(PC, makeArrayRef(IdxBegin,
IdxEnd)),
Name);
}
return Insert(GetElementPtrInst::Create(Ptr, IdxBegin, IdxEnd), Name);
Expand All @@ -792,8 +792,8 @@ class IRBuilder : public IRBuilderBase, public Inserter {
break;
if (i == IdxEnd)
return Insert(Folder.CreateInBoundsGetElementPtr(PC,
&IdxBegin[0],
IdxEnd - IdxBegin),
makeArrayRef(IdxBegin,
IdxEnd)),
Name);
}
return Insert(GetElementPtrInst::CreateInBounds(Ptr, IdxBegin, IdxEnd),
Expand All @@ -802,20 +802,20 @@ class IRBuilder : public IRBuilderBase, public Inserter {
Value *CreateGEP(Value *Ptr, Value *Idx, const Twine &Name = "") {
if (Constant *PC = dyn_cast<Constant>(Ptr))
if (Constant *IC = dyn_cast<Constant>(Idx))
return Insert(Folder.CreateGetElementPtr(PC, &IC, 1), Name);
return Insert(Folder.CreateGetElementPtr(PC, IC), Name);
return Insert(GetElementPtrInst::Create(Ptr, Idx), Name);
}
Value *CreateInBoundsGEP(Value *Ptr, Value *Idx, const Twine &Name = "") {
if (Constant *PC = dyn_cast<Constant>(Ptr))
if (Constant *IC = dyn_cast<Constant>(Idx))
return Insert(Folder.CreateInBoundsGetElementPtr(PC, &IC, 1), Name);
return Insert(Folder.CreateInBoundsGetElementPtr(PC, IC), Name);
return Insert(GetElementPtrInst::CreateInBounds(Ptr, Idx), Name);
}
Value *CreateConstGEP1_32(Value *Ptr, unsigned Idx0, const Twine &Name = "") {
Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0);

if (Constant *PC = dyn_cast<Constant>(Ptr))
return Insert(Folder.CreateGetElementPtr(PC, &Idx, 1), Name);
return Insert(Folder.CreateGetElementPtr(PC, Idx), Name);

return Insert(GetElementPtrInst::Create(Ptr, &Idx, &Idx+1), Name);
}
Expand All @@ -824,7 +824,7 @@ class IRBuilder : public IRBuilderBase, public Inserter {
Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0);

if (Constant *PC = dyn_cast<Constant>(Ptr))
return Insert(Folder.CreateInBoundsGetElementPtr(PC, &Idx, 1), Name);
return Insert(Folder.CreateInBoundsGetElementPtr(PC, Idx), Name);

return Insert(GetElementPtrInst::CreateInBounds(Ptr, &Idx, &Idx+1), Name);
}
Expand All @@ -836,7 +836,7 @@ class IRBuilder : public IRBuilderBase, public Inserter {
};

if (Constant *PC = dyn_cast<Constant>(Ptr))
return Insert(Folder.CreateGetElementPtr(PC, Idxs, 2), Name);
return Insert(Folder.CreateGetElementPtr(PC, Idxs), Name);

return Insert(GetElementPtrInst::Create(Ptr, Idxs, Idxs+2), Name);
}
Expand All @@ -848,15 +848,15 @@ class IRBuilder : public IRBuilderBase, public Inserter {
};

if (Constant *PC = dyn_cast<Constant>(Ptr))
return Insert(Folder.CreateInBoundsGetElementPtr(PC, Idxs, 2), Name);
return Insert(Folder.CreateInBoundsGetElementPtr(PC, Idxs), Name);

return Insert(GetElementPtrInst::CreateInBounds(Ptr, Idxs, Idxs+2), Name);
}
Value *CreateConstGEP1_64(Value *Ptr, uint64_t Idx0, const Twine &Name = "") {
Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);

if (Constant *PC = dyn_cast<Constant>(Ptr))
return Insert(Folder.CreateGetElementPtr(PC, &Idx, 1), Name);
return Insert(Folder.CreateGetElementPtr(PC, Idx), Name);

return Insert(GetElementPtrInst::Create(Ptr, &Idx, &Idx+1), Name);
}
Expand All @@ -865,7 +865,7 @@ class IRBuilder : public IRBuilderBase, public Inserter {
Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);

if (Constant *PC = dyn_cast<Constant>(Ptr))
return Insert(Folder.CreateInBoundsGetElementPtr(PC, &Idx, 1), Name);
return Insert(Folder.CreateInBoundsGetElementPtr(PC, Idx), Name);

return Insert(GetElementPtrInst::CreateInBounds(Ptr, &Idx, &Idx+1), Name);
}
Expand All @@ -877,7 +877,7 @@ class IRBuilder : public IRBuilderBase, public Inserter {
};

if (Constant *PC = dyn_cast<Constant>(Ptr))
return Insert(Folder.CreateGetElementPtr(PC, Idxs, 2), Name);
return Insert(Folder.CreateGetElementPtr(PC, Idxs), Name);

return Insert(GetElementPtrInst::Create(Ptr, Idxs, Idxs+2), Name);
}
Expand All @@ -889,7 +889,7 @@ class IRBuilder : public IRBuilderBase, public Inserter {
};

if (Constant *PC = dyn_cast<Constant>(Ptr))
return Insert(Folder.CreateInBoundsGetElementPtr(PC, Idxs, 2), Name);
return Insert(Folder.CreateInBoundsGetElementPtr(PC, Idxs), Name);

return Insert(GetElementPtrInst::CreateInBounds(Ptr, Idxs, Idxs+2), Name);
}
Expand Down
27 changes: 14 additions & 13 deletions include/llvm/Support/NoFolder.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,22 +177,23 @@ class NoFolder {
// Memory Instructions
//===--------------------------------------------------------------------===//

Constant *CreateGetElementPtr(Constant *C, Constant* const *IdxList,
unsigned NumIdx) const {
return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx);
Constant *CreateGetElementPtr(Constant *C,
ArrayRef<Constant *> IdxList) const {
return ConstantExpr::getGetElementPtr(C, IdxList.data(), IdxList.size());
}
Instruction *CreateGetElementPtr(Constant *C, Value* const *IdxList,
unsigned NumIdx) const {
return GetElementPtrInst::Create(C, IdxList, IdxList+NumIdx);
Instruction *CreateGetElementPtr(Constant *C,
ArrayRef<Value *> IdxList) const {
return GetElementPtrInst::Create(C, IdxList.begin(), IdxList.end());
}

Constant *CreateInBoundsGetElementPtr(Constant *C, Constant* const *IdxList,
unsigned NumIdx) const {
return ConstantExpr::getInBoundsGetElementPtr(C, IdxList, NumIdx);
}
Instruction *CreateInBoundsGetElementPtr(Constant *C, Value* const *IdxList,
unsigned NumIdx) const {
return GetElementPtrInst::CreateInBounds(C, IdxList, IdxList+NumIdx);
Constant *CreateInBoundsGetElementPtr(Constant *C,
ArrayRef<Constant *> IdxList) const {
return ConstantExpr::getInBoundsGetElementPtr(C, IdxList.data(),
IdxList.size());
}
Instruction *CreateInBoundsGetElementPtr(Constant *C,
ArrayRef<Value *> IdxList) const {
return GetElementPtrInst::CreateInBounds(C, IdxList.begin(), IdxList.end());
}

//===--------------------------------------------------------------------===//
Expand Down
42 changes: 26 additions & 16 deletions include/llvm/Support/TargetFolder.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,32 @@ class TargetFolder {
// Memory Instructions
//===--------------------------------------------------------------------===//

Constant *CreateGetElementPtr(Constant *C, Constant* const *IdxList,
unsigned NumIdx) const {
return Fold(ConstantExpr::getGetElementPtr(C, IdxList, NumIdx));
}
Constant *CreateGetElementPtr(Constant *C, Value* const *IdxList,
unsigned NumIdx) const {
return Fold(ConstantExpr::getGetElementPtr(C, IdxList, NumIdx));
}

Constant *CreateInBoundsGetElementPtr(Constant *C, Constant* const *IdxList,
unsigned NumIdx) const {
return Fold(ConstantExpr::getInBoundsGetElementPtr(C, IdxList, NumIdx));
}
Constant *CreateInBoundsGetElementPtr(Constant *C, Value* const *IdxList,
unsigned NumIdx) const {
return Fold(ConstantExpr::getInBoundsGetElementPtr(C, IdxList, NumIdx));
Constant *CreateGetElementPtr(Constant *C,
ArrayRef<Constant *> IdxList) const {
return Fold(ConstantExpr::getGetElementPtr(C, IdxList.data(),
IdxList.size()));
}
Constant *CreateGetElementPtr(Constant *C, Constant *Idx) const {
// This form of the function only exists to avoid ambiguous overload
// warnings about whether to convert Idx to ArrayRef<Constant *> or
// ArrayRef<Value *>.
return Fold(ConstantExpr::getGetElementPtr(C, &Idx, 1));
}
Constant *CreateGetElementPtr(Constant *C,
ArrayRef<Value *> IdxList) const {
return Fold(ConstantExpr::getGetElementPtr(C, IdxList.data(),
IdxList.size()));
}

Constant *CreateInBoundsGetElementPtr(Constant *C,
ArrayRef<Constant *> IdxList) const {
return Fold(ConstantExpr::getInBoundsGetElementPtr(C, IdxList.data(),
IdxList.size()));
}
Constant *CreateInBoundsGetElementPtr(Constant *C,
ArrayRef<Value *> IdxList) const {
return Fold(ConstantExpr::getInBoundsGetElementPtr(C, IdxList.data(),
IdxList.size()));
}

//===--------------------------------------------------------------------===//
Expand Down

0 comments on commit 12fc16f

Please sign in to comment.