Remove some dead methods.
[oota-llvm.git] / lib / VMCore / Instructions.cpp
index 819a090cc3cb9115e09504f78bcd8cc999f3d22f..8c3013b0bbc73bc3a1e7a2af2add57af1b06fd0e 100644 (file)
@@ -161,8 +161,14 @@ Value *PHINode::hasConstantValue() const {
   // Exploit the fact that phi nodes always have at least one entry.
   Value *ConstantValue = getIncomingValue(0);
   for (unsigned i = 1, e = getNumIncomingValues(); i != e; ++i)
-    if (getIncomingValue(i) != ConstantValue)
-      return 0; // Incoming values not all the same.
+    if (getIncomingValue(i) != ConstantValue && getIncomingValue(i) != this) {
+      if (ConstantValue != this)
+        return 0; // Incoming values not all the same.
+       // The case where the first value is this PHI.
+      ConstantValue = getIncomingValue(i);
+    }
+  if (ConstantValue == this)
+    return UndefValue::get(getType());
   return ConstantValue;
 }
 
@@ -336,11 +342,117 @@ void CallInst::removeAttribute(unsigned i, Attributes attr) {
   setAttributes(PAL);
 }
 
-bool CallInst::paramHasAttr(unsigned i, Attributes attr) const {
-  if (AttributeList.paramHasAttr(i, attr))
+bool CallInst::fnHasNoAliasAttr() const {
+  if (AttributeList.getParamAttributes(~0U).hasNoAliasAttr())
+    return true;
+  if (const Function *F = getCalledFunction())
+    return F->getParamAttributes(~0U).hasNoAliasAttr();
+  return false;
+}
+bool CallInst::fnHasNoInlineAttr() const {
+  if (AttributeList.getParamAttributes(~0U).hasNoInlineAttr())
+    return true;
+  if (const Function *F = getCalledFunction())
+    return F->getParamAttributes(~0U).hasNoInlineAttr();
+  return false;
+}
+bool CallInst::fnHasNoReturnAttr() const {
+  if (AttributeList.getParamAttributes(~0U).hasNoReturnAttr())
+    return true;
+  if (const Function *F = getCalledFunction())
+    return F->getParamAttributes(~0U).hasNoReturnAttr();
+  return false;
+}
+bool CallInst::fnHasNoUnwindAttr() const {
+  if (AttributeList.getParamAttributes(~0U).hasNoUnwindAttr())
+    return true;
+  if (const Function *F = getCalledFunction())
+    return F->getParamAttributes(~0U).hasNoUnwindAttr();
+  return false;
+}
+bool CallInst::fnHasReadNoneAttr() const {
+  if (AttributeList.getParamAttributes(~0U).hasReadNoneAttr())
+    return true;
+  if (const Function *F = getCalledFunction())
+    return F->getParamAttributes(~0U).hasReadNoneAttr();
+  return false;
+}
+bool CallInst::fnHasReadOnlyAttr() const {
+  if (AttributeList.getParamAttributes(~0U).hasReadOnlyAttr())
+    return true;
+  if (const Function *F = getCalledFunction())
+    return F->getParamAttributes(~0U).hasReadOnlyAttr();
+  return false;
+}
+bool CallInst::fnHasReturnsTwiceAttr() const {
+  if (AttributeList.getParamAttributes(~0U).hasReturnsTwiceAttr())
+    return true;
+  if (const Function *F = getCalledFunction())
+    return F->getParamAttributes(~0U).hasReturnsTwiceAttr();
+  return false;
+}
+
+bool CallInst::paramHasSExtAttr(unsigned i) const {
+  if (AttributeList.getParamAttributes(i).hasSExtAttr())
+    return true;
+  if (const Function *F = getCalledFunction())
+    return F->getParamAttributes(i).hasSExtAttr();
+  return false;
+}
+
+bool CallInst::paramHasZExtAttr(unsigned i) const {
+  if (AttributeList.getParamAttributes(i).hasZExtAttr())
+    return true;
+  if (const Function *F = getCalledFunction())
+    return F->getParamAttributes(i).hasZExtAttr();
+  return false;
+}
+
+bool CallInst::paramHasInRegAttr(unsigned i) const {
+  if (AttributeList.getParamAttributes(i).hasInRegAttr())
+    return true;
+  if (const Function *F = getCalledFunction())
+    return F->getParamAttributes(i).hasInRegAttr();
+  return false;
+}
+
+bool CallInst::paramHasStructRetAttr(unsigned i) const {
+  if (AttributeList.getParamAttributes(i).hasStructRetAttr())
+    return true;
+  if (const Function *F = getCalledFunction())
+    return F->getParamAttributes(i).hasStructRetAttr();
+  return false;
+}
+
+bool CallInst::paramHasNestAttr(unsigned i) const {
+  if (AttributeList.getParamAttributes(i).hasNestAttr())
+    return true;
+  if (const Function *F = getCalledFunction())
+    return F->getParamAttributes(i).hasNestAttr();
+  return false;
+}
+
+bool CallInst::paramHasByValAttr(unsigned i) const {
+  if (AttributeList.getParamAttributes(i).hasByValAttr())
+    return true;
+  if (const Function *F = getCalledFunction())
+    return F->getParamAttributes(i).hasByValAttr();
+  return false;
+}
+
+bool CallInst::paramHasNoAliasAttr(unsigned i) const {
+  if (AttributeList.getParamAttributes(i).hasNoAliasAttr())
     return true;
   if (const Function *F = getCalledFunction())
-    return F->paramHasAttr(i, attr);
+    return F->getParamAttributes(i).hasNoAliasAttr();
+  return false;
+}
+
+bool CallInst::paramHasNoCaptureAttr(unsigned i) const {
+  if (AttributeList.getParamAttributes(i).hasNoCaptureAttr())
+    return true;
+  if (const Function *F = getCalledFunction())
+    return F->getParamAttributes(i).hasNoCaptureAttr();
   return false;
 }
 
@@ -556,11 +668,117 @@ void InvokeInst::setSuccessorV(unsigned idx, BasicBlock *B) {
   return setSuccessor(idx, B);
 }
 
-bool InvokeInst::paramHasAttr(unsigned i, Attributes attr) const {
-  if (AttributeList.paramHasAttr(i, attr))
+bool InvokeInst::fnHasNoAliasAttr() const {
+  if (AttributeList.getParamAttributes(~0U).hasNoAliasAttr())
+    return true;
+  if (const Function *F = getCalledFunction())
+    return F->getParamAttributes(~0U).hasNoAliasAttr();
+  return false;
+}
+bool InvokeInst::fnHasNoInlineAttr() const {
+  if (AttributeList.getParamAttributes(~0U).hasNoInlineAttr())
+    return true;
+  if (const Function *F = getCalledFunction())
+    return F->getParamAttributes(~0U).hasNoInlineAttr();
+  return false;
+}
+bool InvokeInst::fnHasNoReturnAttr() const {
+  if (AttributeList.getParamAttributes(~0U).hasNoReturnAttr())
+    return true;
+  if (const Function *F = getCalledFunction())
+    return F->getParamAttributes(~0U).hasNoReturnAttr();
+  return false;
+}
+bool InvokeInst::fnHasNoUnwindAttr() const {
+  if (AttributeList.getParamAttributes(~0U).hasNoUnwindAttr())
+    return true;
+  if (const Function *F = getCalledFunction())
+    return F->getParamAttributes(~0U).hasNoUnwindAttr();
+  return false;
+}
+bool InvokeInst::fnHasReadNoneAttr() const {
+  if (AttributeList.getParamAttributes(~0U).hasReadNoneAttr())
+    return true;
+  if (const Function *F = getCalledFunction())
+    return F->getParamAttributes(~0U).hasReadNoneAttr();
+  return false;
+}
+bool InvokeInst::fnHasReadOnlyAttr() const {
+  if (AttributeList.getParamAttributes(~0U).hasReadOnlyAttr())
+    return true;
+  if (const Function *F = getCalledFunction())
+    return F->getParamAttributes(~0U).hasReadOnlyAttr();
+  return false;
+}
+bool InvokeInst::fnHasReturnsTwiceAttr() const {
+  if (AttributeList.getParamAttributes(~0U).hasReturnsTwiceAttr())
+    return true;
+  if (const Function *F = getCalledFunction())
+    return F->getParamAttributes(~0U).hasReturnsTwiceAttr();
+  return false;
+}
+
+bool InvokeInst::paramHasSExtAttr(unsigned i) const {
+  if (AttributeList.getParamAttributes(i).hasSExtAttr())
+    return true;
+  if (const Function *F = getCalledFunction())
+    return F->getParamAttributes(i).hasSExtAttr();
+  return false;
+}
+
+bool InvokeInst::paramHasZExtAttr(unsigned i) const {
+  if (AttributeList.getParamAttributes(i).hasZExtAttr())
+    return true;
+  if (const Function *F = getCalledFunction())
+    return F->getParamAttributes(i).hasZExtAttr();
+  return false;
+}
+
+bool InvokeInst::paramHasInRegAttr(unsigned i) const {
+  if (AttributeList.getParamAttributes(i).hasInRegAttr())
+    return true;
+  if (const Function *F = getCalledFunction())
+    return F->getParamAttributes(i).hasInRegAttr();
+  return false;
+}
+
+bool InvokeInst::paramHasStructRetAttr(unsigned i) const {
+  if (AttributeList.getParamAttributes(i).hasStructRetAttr())
+    return true;
+  if (const Function *F = getCalledFunction())
+    return F->getParamAttributes(i).hasStructRetAttr();
+  return false;
+}
+
+bool InvokeInst::paramHasNestAttr(unsigned i) const {
+  if (AttributeList.getParamAttributes(i).hasNestAttr())
+    return true;
+  if (const Function *F = getCalledFunction())
+    return F->getParamAttributes(i).hasNestAttr();
+  return false;
+}
+
+bool InvokeInst::paramHasByValAttr(unsigned i) const {
+  if (AttributeList.getParamAttributes(i).hasByValAttr())
     return true;
   if (const Function *F = getCalledFunction())
-    return F->paramHasAttr(i, attr);
+    return F->getParamAttributes(i).hasByValAttr();
+  return false;
+}
+
+bool InvokeInst::paramHasNoAliasAttr(unsigned i) const {
+  if (AttributeList.getParamAttributes(i).hasNoAliasAttr())
+    return true;
+  if (const Function *F = getCalledFunction())
+    return F->getParamAttributes(i).hasNoAliasAttr();
+  return false;
+}
+
+bool InvokeInst::paramHasNoCaptureAttr(unsigned i) const {
+  if (AttributeList.getParamAttributes(i).hasNoCaptureAttr())
+    return true;
+  if (const Function *F = getCalledFunction())
+    return F->getParamAttributes(i).hasNoCaptureAttr();
   return false;
 }
 
@@ -2830,7 +3048,7 @@ BitCastInst::BitCastInst(
 //                               CmpInst Classes
 //===----------------------------------------------------------------------===//
 
-void CmpInst::Anchor() const {}
+void CmpInst::anchor() {}
 
 CmpInst::CmpInst(Type *ty, OtherOps op, unsigned short predicate,
                  Value *LHS, Value *RHS, const Twine &Name,
@@ -3158,6 +3376,7 @@ SwitchInst::SwitchInst(const SwitchInst &SI)
     OL[i] = InOL[i];
     OL[i+1] = InOL[i+1];
   }
+  TheSubsets = SI.TheSubsets;
   SubclassOptionalData = SI.SubclassOptionalData;
 }
 
@@ -3169,13 +3388,16 @@ SwitchInst::~SwitchInst() {
 /// addCase - Add an entry to the switch instruction...
 ///
 void SwitchInst::addCase(ConstantInt *OnVal, BasicBlock *Dest) {
-  CRSBuilder CB;
-  CB.add(OnVal);
-  ConstantRangesSet CRS = CB.getCase();
-  addCase(CRS, Dest);
+  IntegersSubsetToBB Mapping;
+  
+  // FIXME: Currently we work with ConstantInt based cases.
+  // So inititalize IntItem container directly from ConstantInt.
+  Mapping.add(IntItem::fromConstantInt(OnVal));
+  IntegersSubset CaseRanges = Mapping.getCase();
+  addCase(CaseRanges, Dest);
 }
 
-void SwitchInst::addCase(ConstantRangesSet& OnVal, BasicBlock *Dest) {
+void SwitchInst::addCase(IntegersSubset& OnVal, BasicBlock *Dest) {
   unsigned NewCaseIdx = getNumCases(); 
   unsigned OpNo = NumOperands;
   if (OpNo+2 > ReservedSpace)
@@ -3183,14 +3405,17 @@ void SwitchInst::addCase(ConstantRangesSet& OnVal, BasicBlock *Dest) {
   // Initialize some new operands.
   assert(OpNo+1 < ReservedSpace && "Growing didn't work!");
   NumOperands = OpNo+2;
-  CaseIt Case(this, NewCaseIdx);
-  Case.setValueEx(OnVal);
+
+  SubsetsIt TheSubsetsIt = TheSubsets.insert(TheSubsets.end(), OnVal);
+  
+  CaseIt Case(this, NewCaseIdx, TheSubsetsIt);
+  Case.updateCaseValueOperand(OnVal);
   Case.setSuccessor(Dest);
 }
 
 /// removeCase - This method removes the specified case and its successor
 /// from the switch instruction.
-void SwitchInst::removeCase(CaseIt i) {
+void SwitchInst::removeCase(CaseIt& i) {
   unsigned idx = i.getCaseIndex();
   
   assert(2 + idx*2 < getNumOperands() && "Case index out of range!!!");
@@ -3207,6 +3432,16 @@ void SwitchInst::removeCase(CaseIt i) {
   // Nuke the last value.
   OL[NumOps-2].set(0);
   OL[NumOps-2+1].set(0);
+
+  // Do the same with TheCases collection:
+  if (i.SubsetIt != --TheSubsets.end()) {
+    *i.SubsetIt = TheSubsets.back();
+    TheSubsets.pop_back();
+  } else {
+    TheSubsets.pop_back();
+    i.SubsetIt = TheSubsets.end();
+  }
+  
   NumOperands = NumOps-2;
 }