Unbreak build with gcc 4.3: provide missed includes and silence most annoying warnings.
[oota-llvm.git] / lib / VMCore / Instructions.cpp
index 1a4a5ce7258de9c166f288324520ea61ad984a30..65bc1830e5fe8138c7323ea801b5677e1898879f 100644 (file)
@@ -55,11 +55,11 @@ void CallSite::setParamAttrs(const ParamAttrsList *PAL) {
   else
     cast<InvokeInst>(I)->setParamAttrs(PAL);
 }
-bool CallSite::paramHasAttr(uint16_t i, unsigned attr) const {
+bool CallSite::paramHasAttr(uint16_t i, ParameterAttributes attr) const {
   if (CallInst *CI = dyn_cast<CallInst>(I))
-    return CI->paramHasAttr(i, (ParameterAttributes)attr);
+    return CI->paramHasAttr(i, attr);
   else
-    return cast<InvokeInst>(I)->paramHasAttr(i, (ParameterAttributes)attr);
+    return cast<InvokeInst>(I)->paramHasAttr(i, attr);
 }
 bool CallSite::doesNotAccessMemory() const {
   if (CallInst *CI = dyn_cast<CallInst>(I))
@@ -186,11 +186,12 @@ void PHINode::resizeOperands(unsigned NumOps) {
 ///
 Value *PHINode::hasConstantValue(bool AllowNonDominatingInstruction) const {
   // If the PHI node only has one incoming value, eliminate the PHI node...
-  if (getNumIncomingValues() == 1)
+  if (getNumIncomingValues() == 1) {
     if (getIncomingValue(0) != this)   // not  X = phi X
       return getIncomingValue(0);
     else
       return UndefValue::get(getType());  // Self cycle is dead.
+  }
       
   // Otherwise if all of the incoming values are the same for the PHI, replace
   // the PHI node with the incoming value.
@@ -198,13 +199,14 @@ Value *PHINode::hasConstantValue(bool AllowNonDominatingInstruction) const {
   Value *InVal = 0;
   bool HasUndefInput = false;
   for (unsigned i = 0, e = getNumIncomingValues(); i != e; ++i)
-    if (isa<UndefValue>(getIncomingValue(i)))
+    if (isa<UndefValue>(getIncomingValue(i))) {
       HasUndefInput = true;
-    else if (getIncomingValue(i) != this)  // Not the PHI node itself...
+    } else if (getIncomingValue(i) != this) { // Not the PHI node itself...
       if (InVal && getIncomingValue(i) != InVal)
         return 0;  // Not the same, bail out.
       else
         InVal = getIncomingValue(i);
+    }
   
   // The only case that could cause InVal to be null is if we have a PHI node
   // that only has entries for itself.  In this case, there is no entry into the
@@ -374,11 +376,11 @@ void CallInst::setParamAttrs(const ParamAttrsList *newAttrs) {
   ParamAttrs = newAttrs; 
 }
 
-bool CallInst::paramHasAttr(uint16_t i, unsigned attr) const {
-  if (ParamAttrs && ParamAttrs->paramHasAttr(i, (ParameterAttributes)attr))
+bool CallInst::paramHasAttr(uint16_t i, ParameterAttributes attr) const {
+  if (ParamAttrs && ParamAttrs->paramHasAttr(i, attr))
     return true;
   if (const Function *F = getCalledFunction())
-    return F->paramHasAttr(i, (ParameterAttributes)attr);
+    return F->paramHasAttr(i, attr);
   return false;
 }
 
@@ -451,8 +453,8 @@ void InvokeInst::init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
     cast<FunctionType>(cast<PointerType>(Fn->getType())->getElementType());
   FTy = FTy;  // silence warning.
 
-  assert((NumArgs == FTy->getNumParams()) ||
-         (FTy->isVarArg() && NumArgs > FTy->getNumParams()) &&
+  assert(((NumArgs == FTy->getNumParams()) ||
+          (FTy->isVarArg() && NumArgs > FTy->getNumParams())) &&
          "Calling a function with bad signature");
 
   for (unsigned i = 0, e = NumArgs; i != e; i++) {
@@ -498,11 +500,11 @@ void InvokeInst::setParamAttrs(const ParamAttrsList *newAttrs) {
   ParamAttrs = newAttrs; 
 }
 
-bool InvokeInst::paramHasAttr(uint16_t i, unsigned attr) const {
-  if (ParamAttrs && ParamAttrs->paramHasAttr(i, (ParameterAttributes)attr))
+bool InvokeInst::paramHasAttr(uint16_t i, ParameterAttributes attr) const {
+  if (ParamAttrs && ParamAttrs->paramHasAttr(i, attr))
     return true;
   if (const Function *F = getCalledFunction())
-    return F->paramHasAttr(i, (ParameterAttributes)attr);
+    return F->paramHasAttr(i, attr);
   return false;
 }
 
@@ -1037,12 +1039,13 @@ const Type* GetElementPtrInst::getIndexedType(const Type *Ptr,
   if (!isa<PointerType>(Ptr)) return 0;   // Type isn't a pointer type!
 
   // Handle the special case of the empty set index set...
-  if (NumIdx == 0)
+  if (NumIdx == 0) {
     if (AllowCompositeLeaf ||
         cast<PointerType>(Ptr)->getElementType()->isFirstClassType())
       return cast<PointerType>(Ptr)->getElementType();
     else
       return 0;
+  }
 
   unsigned CurIdx = 0;
   while (const CompositeType *CT = dyn_cast<CompositeType>(Ptr)) {
@@ -2329,7 +2332,7 @@ CmpInst::CmpInst(OtherOps op, unsigned short predicate, Value *LHS, Value *RHS,
     assert(Op0Ty == Op1Ty &&
           "Both operands to ICmp instruction are not of the same type!");
     // Check that the operands are the right type
-    assert(Op0Ty->isInteger() || isa<PointerType>(Op0Ty) &&
+    assert((Op0Ty->isInteger() || isa<PointerType>(Op0Ty)) &&
            "Invalid operand types for ICmp instruction");
     return;
   }
@@ -2698,6 +2701,29 @@ void SwitchInst::setSuccessorV(unsigned idx, BasicBlock *B) {
   setSuccessor(idx, B);
 }
 
+//===----------------------------------------------------------------------===//
+//                           GetResultInst Implementation
+//===----------------------------------------------------------------------===//
+
+GetResultInst::GetResultInst(Value *Aggr, Value *Index,
+                             const std::string &Name,
+                             Instruction *InsertBef)
+  : Instruction(Aggr->getType(),
+                GetResult, Ops, 2, InsertBef) {
+  assert(isValidOperands(Aggr, Index) && "Invalid GetResultInst operands!");
+  Ops[0].init(Aggr, this);
+  Ops[1].init(Index, this);
+  setName(Name);
+}
+
+bool GetResultInst::isValidOperands(const Value *Aggr, const Value *Index) {
+  if (!Aggr || !Index)
+    return false;
+  if (!isa<StructType>(Aggr->getType()) || Index->getType() != Type::Int32Ty)
+    return false;
+  return true;
+}
+
 
 // Define these methods here so vtables don't get emitted into every translation
 // unit that uses these classes.
@@ -2754,3 +2780,4 @@ SwitchInst *SwitchInst::clone() const { return new SwitchInst(*this); }
 InvokeInst *InvokeInst::clone() const { return new InvokeInst(*this); }
 UnwindInst *UnwindInst::clone() const { return new UnwindInst(); }
 UnreachableInst *UnreachableInst::clone() const { return new UnreachableInst();}
+GetResultInst *GetResultInst::clone() const { return new GetResultInst(*this); }