[llvm-commits] [llvm] r47390 - in /llvm/trunk: include/llvm/Instructions.h lib/AsmParser/llvmAsmParser.y lib/VMCore/Instructions.cpp

Devang Patel dpatel at apple.com
Wed Feb 20 11:10:48 PST 2008


Author: dpatel
Date: Wed Feb 20 13:10:47 2008
New Revision: 47390

URL: http://llvm.org/viewvc/llvm-project?rev=47390&view=rev
Log:
Specify GetResultInst index as an unsigned.

Modified:
    llvm/trunk/include/llvm/Instructions.h
    llvm/trunk/lib/AsmParser/llvmAsmParser.y
    llvm/trunk/lib/VMCore/Instructions.cpp

Modified: llvm/trunk/include/llvm/Instructions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Instructions.h?rev=47390&r1=47389&r2=47390&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Instructions.h (original)
+++ llvm/trunk/include/llvm/Instructions.h Wed Feb 20 13:10:47 2008
@@ -2348,27 +2348,28 @@
 /// aggregate value, where aggregate value is returned by CallInst.
 ///
 class GetResultInst : public Instruction {
-  Use Ops[2];
+  Use Aggr;
+  unsigned Idx;
   GetResultInst(const GetResultInst &GRI) :
-    Instruction(GRI.getType(), Instruction::GetResult, Ops, 2) {
-    Ops[0].init(GRI.Ops[0], this);
-    Ops[1].init(GRI.Ops[1], this);
+    Instruction(GRI.getType(), Instruction::GetResult, &Aggr, 1) {
+    Aggr.init(GRI.Aggr, this);
+    Idx = GRI.Idx;
   }
 
 public:
-  explicit GetResultInst(Value *Aggr, Value *Index, 
+  explicit GetResultInst(Value *Aggr, unsigned index,
                          const std::string &Name = "",
                          Instruction *InsertBefore = 0);
 
   /// isValidOperands - Return true if an getresult instruction can be
   /// formed with the specified operands.
-  static bool isValidOperands(const Value *Aggr, const Value *Idx);
+  static bool isValidOperands(const Value *Aggr, unsigned index);
   
   virtual GetResultInst *clone() const;
   
   // getType - Get aggregate value element type
   inline const Type *getType() const {
-    return Ops[0]->getType();
+    return Aggr->getType();
   }
   
   inline Value *getAggregateValue() {
@@ -2379,11 +2380,11 @@
     return getOperand(0);
   }
 
-  const Value *getIndex() {
-    return getOperand(1);
+  unsigned getIndex() {
+    return Idx;
   }
 
-  unsigned getNumOperands() const { return 2; }
+  unsigned getNumOperands() const { return 1; }
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const GetResultInst *) { return true; }

Modified: llvm/trunk/lib/AsmParser/llvmAsmParser.y
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/llvmAsmParser.y?rev=47390&r1=47389&r2=47390&view=diff

==============================================================================
--- llvm/trunk/lib/AsmParser/llvmAsmParser.y (original)
+++ llvm/trunk/lib/AsmParser/llvmAsmParser.y Wed Feb 20 13:10:47 2008
@@ -3132,7 +3132,7 @@
     $$ = new StoreInst($3, tmpVal, $1, $7);
     delete $5;
   }
-| GETRESULT Types LocalName ',' ConstVal  {
+| GETRESULT Types LocalName ',' EUINT64VAL  {
   ValID TmpVID = ValID::createLocalName(*$3);
   Value *TmpVal = getVal($2->get(), TmpVID);
   if (!GetResultInst::isValidOperands(TmpVal, $5))

Modified: llvm/trunk/lib/VMCore/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Instructions.cpp?rev=47390&r1=47389&r2=47390&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Instructions.cpp (original)
+++ llvm/trunk/lib/VMCore/Instructions.cpp Wed Feb 20 13:10:47 2008
@@ -2705,23 +2705,25 @@
 //                           GetResultInst Implementation
 //===----------------------------------------------------------------------===//
 
-GetResultInst::GetResultInst(Value *Aggr, Value *Index,
+GetResultInst::GetResultInst(Value *Aggregate, unsigned 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);
+                GetResult, &Aggr, 1, InsertBef) {
+  assert(isValidOperands(Aggregate, Index) && "Invalid GetResultInst operands!");
+  Aggr.init(Aggregate, this);
+  Idx = Index;
   setName(Name);
 }
 
-bool GetResultInst::isValidOperands(const Value *Aggr, const Value *Index) {
-  if (!Aggr || !Index)
+bool GetResultInst::isValidOperands(const Value *Aggregate, unsigned Index) {
+  if (!Aggregate)
     return false;
-  if (!isa<StructType>(Aggr->getType()) || Index->getType() != Type::Int32Ty)
-    return false;
-  return true;
+  if (const StructType *STy = dyn_cast<StructType>(Aggregate->getType())) 
+    if (Index < STy->getNumElements())
+      return true;
+
+  return false;
 }
 
 





More information about the llvm-commits mailing list