Get new SelectionDAG stuff building with Visual Studio.
[oota-llvm.git] / include / llvm / Instructions.h
index 96772edd7691f1c7df2b3fe4c5243b8ea702d5e5..58cc1ee4f154d1b1533e178cab4752ad59125495 100644 (file)
@@ -21,7 +21,7 @@
 
 namespace llvm {
 
-struct BasicBlock;
+class BasicBlock;
 class PointerType;
 
 //===----------------------------------------------------------------------===//
@@ -275,7 +275,7 @@ class GetElementPtrInst : public Instruction {
     : Instruction((static_cast<const Instruction*>(&EPI)->getType()),
                   GetElementPtr) {
     Operands.reserve(EPI.Operands.size());
-    for (unsigned i = 0, E = EPI.Operands.size(); i != E; ++i)
+    for (unsigned i = 0, E = (unsigned)EPI.Operands.size(); i != E; ++i)
       Operands.push_back(Use(EPI.Operands[i], this));
   }
   void init(Value *Ptr, const std::vector<Value*> &Idx);
@@ -357,7 +357,6 @@ public:
 /// le, or ge.
 ///
 class SetCondInst : public BinaryOperator {
-  BinaryOps OpType;
 public:
   SetCondInst(BinaryOps Opcode, Value *LHS, Value *RHS,
              const std::string &Name = "", Instruction *InsertBefore = 0);
@@ -481,10 +480,12 @@ public:
   virtual CallInst *clone() const;
   bool mayWriteToMemory() const { return true; }
 
-  // FIXME: These methods should be inline once we eliminate
-  // ConstantPointerRefs!
-  const Function *getCalledFunction() const;
-  Function *getCalledFunction();
+  /// getCalledFunction - Return the function being called by this instruction
+  /// if it is a direct call.  If it is a call through a function pointer,
+  /// return null.
+  Function *getCalledFunction() const {
+    return dyn_cast<Function>(Operands[0]);
+  }
 
   // getCalledValue - Get a pointer to a method that is invoked by this inst.
   inline const Value *getCalledValue() const { return Operands[0]; }
@@ -712,7 +713,7 @@ public:
 
   /// getNumIncomingValues - Return the number of incoming edges
   ///
-  unsigned getNumIncomingValues() const { return Operands.size()/2; }
+  unsigned getNumIncomingValues() const { return (unsigned)Operands.size()/2; }
 
   /// getIncomingValue - Return incoming value #x
   ///
@@ -807,23 +808,20 @@ class ReturnInst : public TerminatorInst {
     }
   }
 
-  void init(Value *RetVal) {
-    if (RetVal) {
-      assert(!isa<BasicBlock>(RetVal) && 
-             "Cannot return basic block.  Probably using the incorrect ctor");
-      Operands.reserve(1);
-      Operands.push_back(Use(RetVal, this));
-    }
-  }
+  void init(Value *RetVal);
 
 public:
   // ReturnInst constructors:
   // ReturnInst()                  - 'ret void' instruction
+  // ReturnInst(    null)          - 'ret void' instruction
   // ReturnInst(Value* X)          - 'ret X'    instruction
   // ReturnInst(    null, Inst *)  - 'ret void' instruction, insert before I
   // ReturnInst(Value* X, Inst *I) - 'ret X'    instruction, insert before I
   // ReturnInst(    null, BB *B)   - 'ret void' instruction, insert @ end of BB
   // ReturnInst(Value* X, BB *B)   - 'ret X'    instruction, insert @ end of BB
+  //
+  // NOTE: If the Value* passed is of type void then the constructor behaves as
+  // if it was passed NULL.
   ReturnInst(Value *RetVal = 0, Instruction *InsertBefore = 0)
     : TerminatorInst(Instruction::Ret, InsertBefore) {
     init(RetVal);
@@ -984,6 +982,8 @@ public:
   //
   inline const Value *getCondition() const { return Operands[0]; }
   inline       Value *getCondition()       { return Operands[0]; }
+  void setCondition(Value *V) { Operands[0] = V; }
+
   inline const BasicBlock *getDefaultDest() const {
     return cast<BasicBlock>(Operands[1].get());
   }
@@ -994,7 +994,7 @@ public:
   /// getNumCases - return the number of 'cases' in this switch instruction.
   /// Note that case #0 is always the default case.
   unsigned getNumCases() const {
-    return Operands.size()/2;
+    return (unsigned)Operands.size()/2;
   }
 
   /// getCaseValue - Return the specified case value.  Note that case #0, the
@@ -1055,7 +1055,7 @@ public:
     assert(idx < getNumSuccessors() && "Successor # out of range!");
     return cast<Constant>(Operands[idx*2].get());
   }
-  virtual unsigned getNumSuccessors() const { return Operands.size()/2; }
+  virtual unsigned getNumSuccessors() const { return (unsigned)Operands.size()/2; }
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const SwitchInst *) { return true; }
@@ -1091,12 +1091,11 @@ public:
   bool mayWriteToMemory() const { return true; }
 
   /// getCalledFunction - Return the function called, or null if this is an
-  /// indirect function invocation... 
-  ///
-  /// FIXME: These should be inlined once we get rid of ConstantPointerRefs!
+  /// indirect function invocation.
   ///
-  const Function *getCalledFunction() const;
-  Function *getCalledFunction();
+  Function *getCalledFunction() const {
+    return dyn_cast<Function>(Operands[0]);
+  }
 
   // getCalledValue - Get a pointer to a function that is invoked by this inst.
   inline const Value *getCalledValue() const { return Operands[0]; }
@@ -1159,7 +1158,8 @@ public:
 /// UnwindInst - Immediately exit the current function, unwinding the stack
 /// until an invoke instruction is found.
 ///
-struct UnwindInst : public TerminatorInst {
+class UnwindInst : public TerminatorInst {
+public:
   UnwindInst(Instruction *InsertBefore = 0)
     : TerminatorInst(Instruction::Unwind, InsertBefore) {
   }
@@ -1196,7 +1196,8 @@ struct UnwindInst : public TerminatorInst {
 /// presence of this instruction indicates some higher level knowledge that the
 /// end of the block cannot be reached.
 ///
-struct UnreachableInst : public TerminatorInst {
+class UnreachableInst : public TerminatorInst {
+public:
   UnreachableInst(Instruction *InsertBefore = 0)
     : TerminatorInst(Instruction::Unreachable, InsertBefore) {
   }