Эх сурвалжийг харах

Revert 85678/85680. The decision is to stay with the current form of
indirectbr, thus we don't need "blockaddr(@func, null)". Eliminate it
for simplicity.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@85699 91177308-0d34-0410-b5e6-96231b3b80d8

Chris Lattner 16 жил өмнө
parent
commit
cdfc940912

+ 2 - 4
docs/LangRef.html

@@ -2176,13 +2176,11 @@ has undefined behavior.</p>
     Blocks</a></div>
     Blocks</a></div>
 <div class="doc_text">
 <div class="doc_text">
 
 
-<p><b><tt>blockaddress(@function, %block)</tt></b><br>
-   <b><tt>blockaddress(@function, null)</tt></b></p>
+<p><b><tt>blockaddress(@function, %block)</tt></b></p>
 
 
 <p>The '<tt>blockaddress</tt>' constant computes the address of the specified
 <p>The '<tt>blockaddress</tt>' constant computes the address of the specified
    basic block in the specified function, and always has an i8* type.  Taking
    basic block in the specified function, and always has an i8* type.  Taking
-   the address of the entry block is illegal.  The BasicBlock operand may also
-   be null.</p>
+   the address of the entry block is illegal.</p>
      
      
 <p>This value only has defined behavior when used as an operand to the
 <p>This value only has defined behavior when used as an operand to the
    '<a href="#i_indirectbr"><tt>indirectbr</tt></a>' instruction or for comparisons
    '<a href="#i_indirectbr"><tt>indirectbr</tt></a>' instruction or for comparisons

+ 0 - 4
include/llvm/Constants.h

@@ -567,10 +567,6 @@ public:
   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
   
   
   Function *getFunction() const { return (Function*)Op<0>().get(); }
   Function *getFunction() const { return (Function*)Op<0>().get(); }
-  
-  /// getBasicBlock - This returns the block associated with this BlockAddress.
-  /// Note that this can return null if the block this originally referred to
-  /// was deleted.
   BasicBlock *getBasicBlock() const { return (BasicBlock*)Op<1>().get(); }
   BasicBlock *getBasicBlock() const { return (BasicBlock*)Op<1>().get(); }
   
   
   /// isNullValue - Return true if this is the value that would be returned by
   /// isNullValue - Return true if this is the value that would be returned by

+ 5 - 11
lib/AsmParser/LLParser.cpp

@@ -123,25 +123,20 @@ bool LLParser::ResolveForwardRefBlockAddresses(Function *TheFn,
   // Loop over all the references, resolving them.
   // Loop over all the references, resolving them.
   for (unsigned i = 0, e = Refs.size(); i != e; ++i) {
   for (unsigned i = 0, e = Refs.size(); i != e; ++i) {
     BasicBlock *Res;
     BasicBlock *Res;
-    if (Refs[i].first.Kind == ValID::t_Null)
-      Res = 0;
-    else if (PFS) {
+    if (PFS) {
       if (Refs[i].first.Kind == ValID::t_LocalName)
       if (Refs[i].first.Kind == ValID::t_LocalName)
         Res = PFS->GetBB(Refs[i].first.StrVal, Refs[i].first.Loc);
         Res = PFS->GetBB(Refs[i].first.StrVal, Refs[i].first.Loc);
-      else {
-        assert(Refs[i].first.Kind == ValID::t_LocalID);
+      else
         Res = PFS->GetBB(Refs[i].first.UIntVal, Refs[i].first.Loc);
         Res = PFS->GetBB(Refs[i].first.UIntVal, Refs[i].first.Loc);
-      }
     } else if (Refs[i].first.Kind == ValID::t_LocalID) {
     } else if (Refs[i].first.Kind == ValID::t_LocalID) {
       return Error(Refs[i].first.Loc,
       return Error(Refs[i].first.Loc,
        "cannot take address of numeric label after it the function is defined");
        "cannot take address of numeric label after it the function is defined");
     } else {
     } else {
-      assert(Refs[i].first.Kind == ValID::t_LocalName);
       Res = dyn_cast_or_null<BasicBlock>(
       Res = dyn_cast_or_null<BasicBlock>(
                      TheFn->getValueSymbolTable().lookup(Refs[i].first.StrVal));
                      TheFn->getValueSymbolTable().lookup(Refs[i].first.StrVal));
     }
     }
     
     
-    if (Res == 0 && Refs[i].first.Kind != ValID::t_Null)
+    if (Res == 0)
       return Error(Refs[i].first.Loc,
       return Error(Refs[i].first.Loc,
                    "referenced value is not a basic block");
                    "referenced value is not a basic block");
     
     
@@ -2060,11 +2055,10 @@ bool LLParser::ParseValID(ValID &ID) {
         ParseValID(Label) ||
         ParseValID(Label) ||
         ParseToken(lltok::rparen, "expected ')' in block address expression"))
         ParseToken(lltok::rparen, "expected ')' in block address expression"))
       return true;
       return true;
-      
+    
     if (Fn.Kind != ValID::t_GlobalID && Fn.Kind != ValID::t_GlobalName)
     if (Fn.Kind != ValID::t_GlobalID && Fn.Kind != ValID::t_GlobalName)
       return Error(Fn.Loc, "expected function name in blockaddress");
       return Error(Fn.Loc, "expected function name in blockaddress");
-    if (Label.Kind != ValID::t_LocalID && Label.Kind != ValID::t_LocalName &&
-        Label.Kind != ValID::t_Null)
+    if (Label.Kind != ValID::t_LocalID && Label.Kind != ValID::t_LocalName)
       return Error(Label.Loc, "expected basic block name in blockaddress");
       return Error(Label.Loc, "expected basic block name in blockaddress");
     
     
     // Make a global variable as a placeholder for this reference.
     // Make a global variable as a placeholder for this reference.

+ 2 - 3
lib/Bitcode/Reader/BitcodeReader.cpp

@@ -2274,12 +2274,11 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
     std::vector<BlockAddrRefTy> &RefList = BAFRI->second;
     std::vector<BlockAddrRefTy> &RefList = BAFRI->second;
     for (unsigned i = 0, e = RefList.size(); i != e; ++i) {
     for (unsigned i = 0, e = RefList.size(); i != e; ++i) {
       unsigned BlockIdx = RefList[i].first;
       unsigned BlockIdx = RefList[i].first;
-      if (BlockIdx > FunctionBBs.size())
+      if (BlockIdx >= FunctionBBs.size())
         return Error("Invalid blockaddress block #");
         return Error("Invalid blockaddress block #");
     
     
       GlobalVariable *FwdRef = RefList[i].second;
       GlobalVariable *FwdRef = RefList[i].second;
-      BasicBlock *BB = BlockIdx == 0 ? 0 : FunctionBBs[BlockIdx-1];
-      FwdRef->replaceAllUsesWith(BlockAddress::get(F, BB));
+      FwdRef->replaceAllUsesWith(BlockAddress::get(F, FunctionBBs[BlockIdx]));
       FwdRef->eraseFromParent();
       FwdRef->eraseFromParent();
     }
     }
     
     

+ 1 - 2
lib/Bitcode/Writer/BitcodeWriter.cpp

@@ -854,8 +854,7 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal,
         break;
         break;
       }
       }
     } else if (const BlockAddress *BA = dyn_cast<BlockAddress>(C)) {
     } else if (const BlockAddress *BA = dyn_cast<BlockAddress>(C)) {
-      assert((!BA->getBasicBlock() ||
-              BA->getFunction() == BA->getBasicBlock()->getParent()) &&
+      assert(BA->getFunction() == BA->getBasicBlock()->getParent() &&
              "Malformed blockaddress");
              "Malformed blockaddress");
       Code = bitc::CST_CODE_BLOCKADDRESS;
       Code = bitc::CST_CODE_BLOCKADDRESS;
       Record.push_back(VE.getTypeID(BA->getFunction()->getType()));
       Record.push_back(VE.getTypeID(BA->getFunction()->getType()));

+ 3 - 5
lib/Bitcode/Writer/ValueEnumerator.cpp

@@ -265,8 +265,6 @@ void ValueEnumerator::EnumerateValue(const Value *V) {
       // Do not enumerate the initializers for an array of simple characters.
       // Do not enumerate the initializers for an array of simple characters.
       // The initializers just polute the value table, and we emit the strings
       // The initializers just polute the value table, and we emit the strings
       // specially.
       // specially.
-    } else if (isa<BlockAddress>(C)) {
-      // Don't enumerate function or block.
     } else if (C->getNumOperands()) {
     } else if (C->getNumOperands()) {
       // If a constant has operands, enumerate them.  This makes sure that if a
       // If a constant has operands, enumerate them.  This makes sure that if a
       // constant has uses (for example an array of const ints), that they are
       // constant has uses (for example an array of const ints), that they are
@@ -278,7 +276,8 @@ void ValueEnumerator::EnumerateValue(const Value *V) {
       // graph that don't go through a global variable.
       // graph that don't go through a global variable.
       for (User::const_op_iterator I = C->op_begin(), E = C->op_end();
       for (User::const_op_iterator I = C->op_begin(), E = C->op_end();
            I != E; ++I)
            I != E; ++I)
-        EnumerateValue(*I);
+        if (!isa<BasicBlock>(*I)) // Don't enumerate BB operand to BlockAddress.
+          EnumerateValue(*I);
 
 
       // Finally, add the value.  Doing this could make the ValueID reference be
       // Finally, add the value.  Doing this could make the ValueID reference be
       // dangling, don't reuse it.
       // dangling, don't reuse it.
@@ -418,10 +417,9 @@ static void IncorporateFunctionInfoGlobalBBIDs(const Function *F,
 /// specified basic block.  This is relatively expensive information, so it
 /// specified basic block.  This is relatively expensive information, so it
 /// should only be used by rare constructs such as address-of-label.
 /// should only be used by rare constructs such as address-of-label.
 unsigned ValueEnumerator::getGlobalBasicBlockID(const BasicBlock *BB) const {
 unsigned ValueEnumerator::getGlobalBasicBlockID(const BasicBlock *BB) const {
-  if (BB == 0) return 0;
   unsigned &Idx = GlobalBasicBlockIDs[BB];
   unsigned &Idx = GlobalBasicBlockIDs[BB];
   if (Idx != 0)
   if (Idx != 0)
-    return Idx;
+    return Idx-1;
 
 
   IncorporateFunctionInfoGlobalBBIDs(BB->getParent(), GlobalBasicBlockIDs);
   IncorporateFunctionInfoGlobalBBIDs(BB->getParent(), GlobalBasicBlockIDs);
   return getGlobalBasicBlockID(BB);
   return getGlobalBasicBlockID(BB);

+ 2 - 1
lib/Transforms/IPO/GlobalOpt.cpp

@@ -2345,7 +2345,8 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal,
         Value *Val = getVal(Values, IBI->getAddress())->stripPointerCasts();
         Value *Val = getVal(Values, IBI->getAddress())->stripPointerCasts();
         if (BlockAddress *BA = dyn_cast<BlockAddress>(Val))
         if (BlockAddress *BA = dyn_cast<BlockAddress>(Val))
           NewBB = BA->getBasicBlock();
           NewBB = BA->getBasicBlock();
-        if (NewBB == 0) return false;  // Cannot determine.
+        else
+          return false;  // Cannot determine.
       } else if (ReturnInst *RI = dyn_cast<ReturnInst>(CurInst)) {
       } else if (ReturnInst *RI = dyn_cast<ReturnInst>(CurInst)) {
         if (RI->getNumOperands())
         if (RI->getNumOperands())
           RetVal = getVal(Values, RI->getOperand(0));
           RetVal = getVal(Values, RI->getOperand(0));

+ 2 - 7
lib/Transforms/Utils/ValueMapper.cpp

@@ -113,13 +113,8 @@ Value *llvm::MapValue(const Value *V, ValueMapTy &VM) {
   
   
   if (BlockAddress *BA = dyn_cast<BlockAddress>(C)) {
   if (BlockAddress *BA = dyn_cast<BlockAddress>(C)) {
     Function *F = cast<Function>(MapValue(BA->getFunction(), VM));
     Function *F = cast<Function>(MapValue(BA->getFunction(), VM));
-    BasicBlock *BB = 0;
-    if (BA->getBasicBlock()) {
-      BB = cast_or_null<BasicBlock>(MapValue(BA->getBasicBlock(),VM));
-      BB = BB ? BB : BA->getBasicBlock();
-    }
-    
-    return VM[V] = BlockAddress::get(F, BB);
+    BasicBlock *BB = cast_or_null<BasicBlock>(MapValue(BA->getBasicBlock(),VM));
+    return VM[V] = BlockAddress::get(F, BB ? BB : BA->getBasicBlock());
   }
   }
   
   
   llvm_unreachable("Unknown type of constant!");
   llvm_unreachable("Unknown type of constant!");

+ 1 - 4
lib/VMCore/AsmWriter.cpp

@@ -1065,10 +1065,7 @@ static void WriteConstantInt(raw_ostream &Out, const Constant *CV,
     Out << "blockaddress(";
     Out << "blockaddress(";
     WriteAsOperandInternal(Out, BA->getFunction(), &TypePrinter, Machine);
     WriteAsOperandInternal(Out, BA->getFunction(), &TypePrinter, Machine);
     Out << ", ";
     Out << ", ";
-    if (BA->getBasicBlock())
-      WriteAsOperandInternal(Out, BA->getBasicBlock(), &TypePrinter, Machine);
-    else
-      Out << "null";
+    WriteAsOperandInternal(Out, BA->getBasicBlock(), &TypePrinter, Machine);
     Out << ")";
     Out << ")";
     return;
     return;
   }
   }

+ 5 - 3
lib/VMCore/BasicBlock.cpp

@@ -63,13 +63,15 @@ BasicBlock::~BasicBlock() {
   // hanging off the block, or an undefined use of the block (source code
   // hanging off the block, or an undefined use of the block (source code
   // expecting the address of a label to keep the block alive even though there
   // expecting the address of a label to keep the block alive even though there
   // is no indirect branch).  Handle these cases by zapping the BlockAddress
   // is no indirect branch).  Handle these cases by zapping the BlockAddress
-  // nodes, replacing them with BlockAddress(F, NULL).  There are no other
-  // possible uses at this point.
+  // nodes.  There are no other possible uses at this point.
   if (hasAddressTaken()) {
   if (hasAddressTaken()) {
     assert(!use_empty() && "There should be at least one blockaddress!");
     assert(!use_empty() && "There should be at least one blockaddress!");
+    Constant *Replacement =
+      ConstantInt::get(llvm::Type::getInt32Ty(getContext()), 1);
     while (!use_empty()) {
     while (!use_empty()) {
       BlockAddress *BA = cast<BlockAddress>(use_back());
       BlockAddress *BA = cast<BlockAddress>(use_back());
-      BA->replaceAllUsesWith(BlockAddress::get(BA->getFunction(), 0));
+      BA->replaceAllUsesWith(ConstantExpr::getIntToPtr(Replacement,
+                                                       BA->getType()));
       BA->destroyConstant();
       BA->destroyConstant();
     }
     }
   }
   }

+ 2 - 3
lib/VMCore/Constants.cpp

@@ -1045,7 +1045,7 @@ BlockAddress::BlockAddress(Function *F, BasicBlock *BB)
            &Op<0>(), 2) {
            &Op<0>(), 2) {
   Op<0>() = F;
   Op<0>() = F;
   Op<1>() = BB;
   Op<1>() = BB;
-  if (BB) BB->AdjustBlockAddressRefCount(1);
+  BB->AdjustBlockAddressRefCount(1);
 }
 }
 
 
 
 
@@ -1054,8 +1054,7 @@ BlockAddress::BlockAddress(Function *F, BasicBlock *BB)
 void BlockAddress::destroyConstant() {
 void BlockAddress::destroyConstant() {
   getFunction()->getType()->getContext().pImpl
   getFunction()->getType()->getContext().pImpl
     ->BlockAddresses.erase(std::make_pair(getFunction(), getBasicBlock()));
     ->BlockAddresses.erase(std::make_pair(getFunction(), getBasicBlock()));
-  if (BasicBlock *BB = getBasicBlock())
-    BB->AdjustBlockAddressRefCount(-1);
+  getBasicBlock()->AdjustBlockAddressRefCount(-1);
   destroyConstantImpl();
   destroyConstantImpl();
 }
 }