//===----------------------------------------------------------------------===//
#include "llvm/Constant.h"
+#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/InstrTypes.h"
#include "llvm/Instructions.h"
Value::Value(const Type *ty, unsigned scid)
: SubclassID(scid), SubclassData(0), Ty(checkType(ty)),
UseList(0), Name(0) {
- if (isa<CallInst>(this))
+ if (isa<CallInst>(this) || isa<InvokeInst>(this))
assert((Ty->isFirstClassType() || Ty == Type::VoidTy ||
isa<OpaqueType>(ty) || Ty->getTypeID() == Type::StructTyID) &&
"invalid CallInst type!");
// a <badref>
//
if (!use_empty()) {
- DOUT << "While deleting: " << *Ty << " %" << Name << "\n";
+ DOUT << "While deleting: " << *Ty << " %" << getNameStr() << "\n";
for (use_iterator I = use_begin(), E = use_end(); I != E; ++I)
DOUT << "Use still stuck around after Def is destroyed:"
<< **I << "\n";
return Name ? Name->getKeyLength() : 0;
}
+/// isName - Return true if this value has the name specified by the provided
+/// nul terminated string.
+bool Value::isName(const char *N) const {
+ unsigned InLen = strlen(N);
+ return InLen == getNameLen() && memcmp(getNameStart(), N, InLen) == 0;
+}
+
std::string Value::getNameStr() const {
if (Name == 0) return "";
uncheckedReplaceAllUsesWith(New);
}
+Value *Value::stripPointerCasts() {
+ if (ConstantExpr *CE = dyn_cast<ConstantExpr>(this)) {
+ if (CE->getOpcode() == Instruction::BitCast) {
+ if (isa<PointerType>(CE->getOperand(0)->getType()))
+ return CE->getOperand(0)->stripPointerCasts();
+ } else if (CE->getOpcode() == Instruction::GetElementPtr) {
+ for (unsigned i = 1, e = CE->getNumOperands(); i != e; ++i)
+ if (!CE->getOperand(i)->isNullValue())
+ return this;
+ return CE->getOperand(0)->stripPointerCasts();
+ }
+ return this;
+ }
+
+ if (BitCastInst *CI = dyn_cast<BitCastInst>(this)) {
+ if (isa<PointerType>(CI->getOperand(0)->getType()))
+ return CI->getOperand(0)->stripPointerCasts();
+ } else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(this)) {
+ if (GEP->hasAllZeroIndices())
+ return GEP->getOperand(0)->stripPointerCasts();
+ }
+ return this;
+}
+
//===----------------------------------------------------------------------===//
// User Class
//===----------------------------------------------------------------------===//
}
}
+void *User::operator new(size_t s, unsigned Us) {
+ void *Storage = ::operator new(s + sizeof(Use) * Us);
+ Use *Start = static_cast<Use*>(Storage);
+ Use *End = Start + Us;
+ User *Obj = reinterpret_cast<User*>(End);
+ Obj->OperandList = Start;
+ Obj->NumOperands = Us;
+ Use::initTags(Start, End);
+ return Obj;
+}
+
+void User::operator delete(void *Usr) {
+ User *Start = static_cast<User*>(Usr);
+ Use *Storage = static_cast<Use*>(Usr) - Start->NumOperands;
+ ::operator delete(Storage == Start->OperandList
+ ? Storage
+ : Usr);
+}