Remove much cruft from the MemAccessInst instruction
authorChris Lattner <sabre@nondot.org>
Wed, 14 Nov 2001 11:27:58 +0000 (11:27 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 14 Nov 2001 11:27:58 +0000 (11:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1298 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/iMemory.h
lib/CodeGen/InstrSelection/InstrForest.cpp
lib/CodeGen/InstrSelection/InstrSelectionSupport.cpp
lib/Target/SparcV9/InstrSelection/InstrForest.cpp
lib/Target/SparcV9/InstrSelection/InstrSelectionSupport.cpp
lib/Target/SparcV9/SparcV9InstrSelection.cpp
lib/Transforms/ExprTypeConvert.cpp
lib/Transforms/Instrumentation/TraceValues.cpp
lib/Transforms/LevelRaise.cpp

index 29518686cfef0f49a106fbe09ad5f2bac2d97b1e..1dbc1dbea3482ab2f309035e9c328f0c5b2fc8b1 100644 (file)
@@ -182,16 +182,19 @@ public:
                                    const vector<ConstPoolVal*> &Indices,
                                    bool AllowStructLeaf = false);
   
-  const vector<ConstPoolVal*> &getIndices() const { return indexVec; }
-
-  inline bool hasIndices() const { return !indexVec.empty(); }
-  
-  virtual Value *getPtrOperand() = 0;
+  Value *getPointerOperand() {
+    return getOperand(getFirstIndexOperandNumber()-1);
+  }
   const Value *getPointerOperand() const {
-    return ((MemAccessInst*)this)->getPtrOperand();
+    return getOperand(getFirstIndexOperandNumber()-1);
   }
   
-  virtual int getFirstOffsetIdx() const = 0;
+  virtual unsigned getFirstIndexOperandNumber() const = 0;
+
+  const vector<ConstPoolVal*> &getIndices() const { return indexVec; }
+  inline bool hasIndices() const {
+    return getNumOperands() <= getFirstIndexOperandNumber();
+  }
 };
 
 
@@ -213,8 +216,8 @@ public:
 
   virtual Instruction *clone() const { return new LoadInst(*this); }
   virtual const char *getOpcodeName() const { return "load"; }  
-  virtual Value *getPtrOperand() { return this->getOperand(0); }
-  virtual int getFirstOffsetIdx() const { return (this->getNumOperands() > 1)? 1 : -1; }
+
+  virtual unsigned getFirstIndexOperandNumber() const { return 1; }
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const LoadInst *) { return true; }
@@ -247,8 +250,7 @@ public:
   virtual const char *getOpcodeName() const { return "store"; }  
   
   virtual bool hasSideEffects() const { return true; }
-  virtual Value *getPtrOperand() { return this->getOperand(1); }
-  virtual int getFirstOffsetIdx() const { return (this->getNumOperands() > 2)? 2 : -1;}
+  virtual unsigned getFirstIndexOperandNumber() const { return 2; }
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const StoreInst *) { return true; }
@@ -277,8 +279,7 @@ public:
                    const string &Name = "");
   virtual Instruction *clone() const { return new GetElementPtrInst(*this); }
   virtual const char *getOpcodeName() const { return "getelementptr"; }  
-  virtual Value *getPtrOperand() { return this->getOperand(0); }
-  virtual int getFirstOffsetIdx() const { return (this->getNumOperands() > 1)? 1 : -1;}
+  virtual unsigned getFirstIndexOperandNumber() const { return 1; }
   
   inline bool isArraySelector() const { return !isStructSelector(); }
   bool isStructSelector() const;
index d460bb77e23ff6f51e5e353098aeba342e44de95..f928683060a0ba86d8a96113183750fcddf3a503 100644 (file)
@@ -76,7 +76,7 @@ InstructionNode::InstructionNode(Instruction* I)
     }
   else if ((opLabel == Instruction::Load ||
            opLabel == Instruction::GetElementPtr) &&
-          ((MemAccessInst*)I)->getFirstOffsetIdx() > 0)
+          cast<MemAccessInst>(I)->hasIndices())
     {
       opLabel = opLabel + 100;          // load/getElem with index vector
     }
index 0a6d7d331d36bb2d445d9137f0bd3bbaaa04b70a..cb3f9a15822e7f5bc21c64403cdf4d9e95783b9b 100644 (file)
@@ -117,7 +117,7 @@ FoldGetElemChain(const InstructionNode* getElemInstrNode,
     getElemInstrNode->getInstruction();
   
   // Initialize return values from the incoming instruction
-  Value* ptrVal = getElemInst->getPtrOperand();
+  Value* ptrVal = getElemInst->getPointerOperand();
   chainIdxVec = getElemInst->getIndices(); // copies index vector values
   
   // Now chase the chain of getElementInstr instructions, if any
@@ -131,7 +131,7 @@ FoldGetElemChain(const InstructionNode* getElemInstrNode,
       const vector<ConstPoolVal*>& idxVec = getElemInst->getIndices();
       
       // Get the pointer value out of ptrChild and *prepend* its index vector
-      ptrVal = getElemInst->getPtrOperand();
+      ptrVal = getElemInst->getPointerOperand();
       chainIdxVec.insert(chainIdxVec.begin(), idxVec.begin(), idxVec.end());
       
       ptrChild = ptrChild->leftChild();
index d460bb77e23ff6f51e5e353098aeba342e44de95..f928683060a0ba86d8a96113183750fcddf3a503 100644 (file)
@@ -76,7 +76,7 @@ InstructionNode::InstructionNode(Instruction* I)
     }
   else if ((opLabel == Instruction::Load ||
            opLabel == Instruction::GetElementPtr) &&
-          ((MemAccessInst*)I)->getFirstOffsetIdx() > 0)
+          cast<MemAccessInst>(I)->hasIndices())
     {
       opLabel = opLabel + 100;          // load/getElem with index vector
     }
index 0a6d7d331d36bb2d445d9137f0bd3bbaaa04b70a..cb3f9a15822e7f5bc21c64403cdf4d9e95783b9b 100644 (file)
@@ -117,7 +117,7 @@ FoldGetElemChain(const InstructionNode* getElemInstrNode,
     getElemInstrNode->getInstruction();
   
   // Initialize return values from the incoming instruction
-  Value* ptrVal = getElemInst->getPtrOperand();
+  Value* ptrVal = getElemInst->getPointerOperand();
   chainIdxVec = getElemInst->getIndices(); // copies index vector values
   
   // Now chase the chain of getElementInstr instructions, if any
@@ -131,7 +131,7 @@ FoldGetElemChain(const InstructionNode* getElemInstrNode,
       const vector<ConstPoolVal*>& idxVec = getElemInst->getIndices();
       
       // Get the pointer value out of ptrChild and *prepend* its index vector
-      ptrVal = getElemInst->getPtrOperand();
+      ptrVal = getElemInst->getPointerOperand();
       chainIdxVec.insert(chainIdxVec.begin(), idxVec.begin(), idxVec.end());
       
       ptrChild = ptrChild->leftChild();
index 4feecbb1bd1ed0328f3a4df0c41272e627b9db35..8966db2f3e4a3693191313bdd2864d6e57ccf417 100644 (file)
@@ -781,17 +781,16 @@ SetOperandsForMemInstr(MachineInstr* minstr,
       // Use the pointer value and the index vector from the Mem instruction.
       // If it is an array reference, get the array offset value.
       // 
-      ptrVal = memInst->getPtrOperand();
+      ptrVal = memInst->getPointerOperand();
 
-      const Type* opType =
-        ((const PointerType*) ptrVal->getType())->getValueType();
+      const Type* opType = cast<PointerType>(ptrVal->getType())->getValueType();
       if (opType->isArrayType())
         {
           assert((memInst->getNumOperands()
-                  == (unsigned) 1 + memInst->getFirstOffsetIdx())
+                  == (unsigned) 1 + memInst->getFirstIndexOperandNumber())
                  && "Array refs must be lowered before Instruction Selection");
           
-          arrayOffsetVal = memInst->getOperand(memInst->getFirstOffsetIdx());
+          arrayOffsetVal = memInst->getOperand(memInst->getFirstIndexOperandNumber());
         }
     }
   
@@ -1835,7 +1834,7 @@ GetInstructionsByRule(InstructionNode* subtreeRoot,
                 GetElementPtrInst* getElemInst =
                   cast<GetElementPtrInst>(subtreeRoot->getInstruction());
                 const PointerType* ptrType =
-                  (const PointerType*) getElemInst->getPtrOperand()->getType();
+                  cast<PointerType>(getElemInst->getPointerOperand()->getType());
                 if (! ptrType->getValueType()->isArrayType())
                   {// we don't need a separate instr
                     numInstr = 0;              // don't forward operand!
index f8052b249424c7c1c6ca82134fbe893173a8e1b6..2e7c297907304184d1be10daa73e9846048ea9ea 100644 (file)
@@ -131,8 +131,8 @@ bool ExpressionConvertableToType(Value *V, const Type *Ty,
         if (!CPV[i]->isNullValue()) return false;
     }
 
-    if (!ExpressionConvertableToType(LI->getPtrOperand(), PointerType::get(Ty),
-                                     CTMap))
+    if (!ExpressionConvertableToType(LI->getPointerOperand(),
+                                     PointerType::get(Ty), CTMap))
       return false;
     break;                                     
   }
@@ -163,7 +163,7 @@ bool ExpressionConvertableToType(Value *V, const Type *Ty,
     // get to the right type...
     //
     vector<ConstPoolVal*> Indices = GEP->getIndices();
-    const Type *BaseType = GEP->getPtrOperand()->getType();
+    const Type *BaseType = GEP->getPointerOperand()->getType();
 
     while (Indices.size() &&
            cast<ConstPoolUInt>(Indices.back())->getValue() == 0) {
@@ -268,7 +268,7 @@ Value *ConvertExpressionToType(Value *V, const Type *Ty, ValueMapCache &VMC) {
     Res = new LoadInst(ConstPoolVal::getNullConstant(PointerType::get(Ty)), 
                        Name);
     VMC.ExprMap[I] = Res;
-    Res->setOperand(0, ConvertExpressionToType(LI->getPtrOperand(),
+    Res->setOperand(0, ConvertExpressionToType(LI->getPointerOperand(),
                                                PointerType::get(Ty), VMC));
     assert(Res->getOperand(0)->getType() == PointerType::get(Ty));
     assert(Ty == Res->getType());
@@ -310,7 +310,7 @@ Value *ConvertExpressionToType(Value *V, const Type *Ty, ValueMapCache &VMC) {
     // get to the right type...
     //
     vector<ConstPoolVal*> Indices = GEP->getIndices();
-    const Type *BaseType = GEP->getPtrOperand()->getType();
+    const Type *BaseType = GEP->getPointerOperand()->getType();
     const Type *PVTy = cast<PointerType>(Ty)->getValueType();
     Res = 0;
     while (Indices.size() &&
@@ -318,9 +318,9 @@ Value *ConvertExpressionToType(Value *V, const Type *Ty, ValueMapCache &VMC) {
       Indices.pop_back();
       if (GetElementPtrInst::getIndexedType(BaseType, Indices, true) == PVTy) {
         if (Indices.size() == 0) {
-          Res = new CastInst(GEP->getPtrOperand(), BaseType); // NOOP
+          Res = new CastInst(GEP->getPointerOperand(), BaseType); // NOOP
         } else {
-          Res = new GetElementPtrInst(GEP->getPtrOperand(), Indices, Name);
+          Res = new GetElementPtrInst(GEP->getPointerOperand(), Indices, Name);
         }
         break;
       }
@@ -549,7 +549,7 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty,
     // get to the right type...
     //
     vector<ConstPoolVal*> Indices = GEP->getIndices();
-    const Type *BaseType = GEP->getPtrOperand()->getType();
+    const Type *BaseType = GEP->getPointerOperand()->getType();
 
     while (Indices.size() &&
            cast<ConstPoolUInt>(Indices.back())->getValue() == 0) {
@@ -713,7 +713,7 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal,
     // get to the right type...
     //
     vector<ConstPoolVal*> Indices = GEP->getIndices();
-    const Type *BaseType = GEP->getPtrOperand()->getType();
+    const Type *BaseType = GEP->getPointerOperand()->getType();
     const Type *PVTy = cast<PointerType>(Ty)->getValueType();
     Res = 0;
     while (Indices.size() &&
@@ -721,9 +721,9 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal,
       Indices.pop_back();
       if (GetElementPtrInst::getIndexedType(BaseType, Indices, true) == PVTy) {
         if (Indices.size() == 0) {
-          Res = new CastInst(GEP->getPtrOperand(), BaseType); // NOOP
+          Res = new CastInst(GEP->getPointerOperand(), BaseType); // NOOP
         } else {
-          Res = new GetElementPtrInst(GEP->getPtrOperand(), Indices, Name);
+          Res = new GetElementPtrInst(GEP->getPointerOperand(), Indices, Name);
         }
         break;
       }
index 06c8438f26f3f4a26be032a7805b1db3534295ae..e8598b9d859e656aca3dc0ae65090db09b3a9a35 100644 (file)
@@ -310,7 +310,7 @@ InsertLoadInst(StoreInst* storeInst,
                BasicBlock *bb,
                BasicBlock::iterator &BBI)
 {
-  LoadInst* loadInst = new LoadInst(storeInst->getPtrOperand(),
+  LoadInst* loadInst = new LoadInst(storeInst->getPointerOperand(),
                                     storeInst->getIndices());
   BBI = bb->getInstList().insert(BBI, loadInst) + 1;
   return loadInst;
index dfe92ee234c39b7fde9b0641da5cdc45dfd4204c..78bb2ebce2d4122e7af39b510497cc37b495349c 100644 (file)
@@ -630,7 +630,7 @@ static bool PeepholeOptimize(BasicBlock *BB, BasicBlock::iterator &BI) {
 
   } else if (StoreInst *SI = dyn_cast<StoreInst>(I)) {
     Value *Val     = SI->getOperand(0);
-    Value *Pointer = SI->getPtrOperand();
+    Value *Pointer = SI->getPointerOperand();
     
     // Peephole optimize the following instructions:
     // %t1 = getelementptr {<...>} * %StructPtr, <element indices>
@@ -648,7 +648,7 @@ static bool PeepholeOptimize(BasicBlock *BB, BasicBlock::iterator &BI) {
 
       PRINT_PEEPHOLE2("gep-store:in", GEP, SI);
       ReplaceInstWithInst(BB->getInstList(), BI,
-                          SI = new StoreInst(Val, GEP->getPtrOperand(),
+                          SI = new StoreInst(Val, GEP->getPointerOperand(),
                                              Indices));
       PRINT_PEEPHOLE1("gep-store:out", SI);
       return true;
@@ -685,7 +685,7 @@ static bool PeepholeOptimize(BasicBlock *BB, BasicBlock::iterator &BI) {
 
 
   } else if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
-    Value *Pointer = LI->getPtrOperand();
+    Value *Pointer = LI->getPointerOperand();
     
     // Peephole optimize the following instructions:
     // %t1 = getelementptr {<...>} * %StructPtr, <element indices>
@@ -703,7 +703,7 @@ static bool PeepholeOptimize(BasicBlock *BB, BasicBlock::iterator &BI) {
 
       PRINT_PEEPHOLE2("gep-load:in", GEP, LI);
       ReplaceInstWithInst(BB->getInstList(), BI,
-                          LI = new LoadInst(GEP->getPtrOperand(),
+                          LI = new LoadInst(GEP->getPointerOperand(),
                                             Indices));
       PRINT_PEEPHOLE1("gep-load:out", LI);
       return true;