change the LabelSDNode to be EHLabelSDNode and make it hold
authorChris Lattner <sabre@nondot.org>
Sun, 14 Mar 2010 02:33:54 +0000 (02:33 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 14 Mar 2010 02:33:54 +0000 (02:33 +0000)
an MCSymbol.  Make the EH_LABEL MachineInstr hold its label
with an MCSymbol instead of ID.  Fix a bug in MMI.cpp which
would return labels named "Label4" instead of "label4".

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

14 files changed:
include/llvm/CodeGen/MachineModuleInfo.h
include/llvm/CodeGen/SelectionDAG.h
include/llvm/CodeGen/SelectionDAGISel.h
include/llvm/CodeGen/SelectionDAGNodes.h
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
lib/CodeGen/AsmPrinter/DwarfException.cpp
lib/CodeGen/MachineModuleInfo.cpp
lib/CodeGen/SelectionDAG/InstrEmitter.cpp
lib/CodeGen/SelectionDAG/SelectionDAG.cpp
lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
lib/Target/ARM/ARMCodeEmitter.cpp
lib/Target/PowerPC/PPCCodeEmitter.cpp
lib/Target/X86/X86CodeEmitter.cpp

index 9215b3354015c1962b8510827ed9918a981292d8..6783599be3930b5f1a7982a2952a6f4f79aaddb9 100644 (file)
@@ -228,7 +228,7 @@ public:
   
   /// addLandingPad - Add a new panding pad.  Returns the label ID for the 
   /// landing pad entry.
-  unsigned addLandingPad(MachineBasicBlock *LandingPad);
+  MCSymbol *addLandingPad(MachineBasicBlock *LandingPad);
   
   /// addPersonality - Provide the personality function for the exception
   /// information.
index 714addb129f8da5c6614b66f52858b3371f3207a..c8d29aa0c7d1ea3c09bd506fe68dc9716c77816e 100644 (file)
@@ -383,8 +383,7 @@ public:
                                   unsigned char TargetFlags = 0);
   SDValue getValueType(EVT);
   SDValue getRegister(unsigned Reg, EVT VT);
-  SDValue getLabel(unsigned Opcode, DebugLoc dl, SDValue Root,
-                   unsigned LabelID);
+  SDValue getEHLabel(DebugLoc dl, SDValue Root, MCSymbol *Label);
   SDValue getBlockAddress(BlockAddress *BA, EVT VT,
                           bool isTarget = false, unsigned char TargetFlags = 0);
 
index d9c1374a01d32ece0dab5e4092474ef3aebae859..a1576be90b78c3b9a89d4a09a5ea5d3415ea4ab9 100644 (file)
@@ -274,7 +274,6 @@ private:
   // Calls to these functions are generated by tblgen.
   SDNode *Select_INLINEASM(SDNode *N);
   SDNode *Select_UNDEF(SDNode *N);
-  SDNode *Select_EH_LABEL(SDNode *N);
   void CannotYetSelect(SDNode *N);
 
 private:
index 52ccc2d9b37b9a4da341b284e87c397e14d0f3a3..e61672dc3bcfbc3d4efb4e0bfb69f1ecc6be04aa 100644 (file)
@@ -40,6 +40,7 @@ class MachineBasicBlock;
 class MachineConstantPoolValue;
 class SDNode;
 class Value;
+class MCSymbol;
 template <typename T> struct DenseMapInfo;
 template <typename T> struct simplify_type;
 template <typename T> struct ilist_traits;
@@ -2088,18 +2089,18 @@ public:
   }
 };
 
-class LabelSDNode : public SDNode {
+class EHLabelSDNode : public SDNode {
   SDUse Chain;
-  unsigned LabelID;
+  MCSymbol *Label;
   friend class SelectionDAG;
-  LabelSDNode(unsigned NodeTy, DebugLoc dl, SDValue ch, unsigned id)
-    : SDNode(NodeTy, dl, getSDVTList(MVT::Other)), LabelID(id) {
+  EHLabelSDNode(DebugLoc dl, SDValue ch, MCSymbol *L)
+    : SDNode(ISD::EH_LABEL, dl, getSDVTList(MVT::Other)), Label(L) {
     InitOperands(&Chain, ch);
   }
 public:
-  unsigned getLabelID() const { return LabelID; }
+  MCSymbol *getLabel() const { return Label; }
 
-  static bool classof(const LabelSDNode *) { return true; }
+  static bool classof(const EHLabelSDNode *) { return true; }
   static bool classof(const SDNode *N) {
     return N->getOpcode() == ISD::EH_LABEL;
   }
index b7cc5b3a21dce1da04d759d8c6c97e80450b1869..31151f304afd46623f24a355484b7ee7a7a6b0b3 100644 (file)
@@ -1553,7 +1553,12 @@ void AsmPrinter::printKill(const MachineInstr *MI) const {
 /// printLabel - This method prints a local label used by debug and
 /// exception handling tables.
 void AsmPrinter::printLabelInst(const MachineInstr *MI) const {
-  MCSymbol *Sym = 
+  MCSymbol *Sym; 
+  
+  if (MI->getOperand(0).isMCSymbol())
+    Sym = MI->getOperand(0).getMCSymbol();
+  else
+    Sym =
     OutContext.GetOrCreateTemporarySymbol(Twine(MAI->getPrivateGlobalPrefix()) +
                                  "label" + Twine(MI->getOperand(0).getImm()));
   OutStreamer.EmitLabel(Sym);
index ff0aa80b1d79865410a70bd363b018ad6aa07617..b5f7270ba5e7b5b7f866a5ffd13476851b89e0cc 100644 (file)
@@ -475,9 +475,15 @@ ComputeCallSiteTable(SmallVectorImpl<CallSiteEntry> &CallSites,
         continue;
       }
 
-      unsigned BeginLabelNo = MI->getOperand(0).getImm();
-      assert(BeginLabelNo && "Invalid label!");
-      MCSymbol *BeginLabel = getDWLabel("label", BeginLabelNo);
+      MCSymbol *BeginLabel;
+      if (MI->getOperand(0).isImm()) {
+        unsigned BeginLabelNo = MI->getOperand(0).getImm();
+        assert(BeginLabelNo && "Invalid label!");
+        BeginLabel = getDWLabel("label", BeginLabelNo);
+      } else {
+        BeginLabel = MI->getOperand(0).getMCSymbol();
+      }
+      
 
       // End of the previous try-range?
       if (BeginLabel == LastLabel)
index 42c6a7fef3f84e0d07b0a9d4cba8d82b076167d1..e7373711cb78513c6add7428dde1e30267d4f612 100644 (file)
@@ -73,7 +73,7 @@ bool MachineModuleInfo::doFinalization() {
 /// getLabelSym - Turn a label ID into a symbol.
 MCSymbol *MachineModuleInfo::getLabelSym(unsigned ID) {
   return Context.GetOrCreateTemporarySymbol
-    (Twine(Context.getAsmInfo().getPrivateGlobalPrefix()) + "Label" +Twine(ID));
+    (Twine(Context.getAsmInfo().getPrivateGlobalPrefix()) + "label" +Twine(ID));
 }
 
 /// EndFunction - Discard function meta information.
@@ -139,12 +139,11 @@ void MachineModuleInfo::addInvoke(MachineBasicBlock *LandingPad,
 
 /// addLandingPad - Provide the label of a try LandingPad block.
 ///
-unsigned MachineModuleInfo::addLandingPad(MachineBasicBlock *LandingPad) {
-  unsigned LandingPadID = NextLabelID();
-  MCSymbol *LandingPadLabel = getLabelSym(LandingPadID);
+MCSymbol *MachineModuleInfo::addLandingPad(MachineBasicBlock *LandingPad) {
+  MCSymbol *LandingPadLabel = getLabelSym(NextLabelID());
   LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
   LP.LandingPadLabel = LandingPadLabel;
-  return LandingPadID;
+  return LandingPadLabel;
 }
 
 /// addPersonality - Provide the personality function for the exception
index 223704305b714ebde0086d4eff86b53612213f36..49105a8a9dfd64f56175fa8542d02e8085e64aa9 100644 (file)
@@ -705,6 +705,13 @@ void InstrEmitter::EmitNode(SDNode *Node, bool IsClone, bool IsCloned,
     EmitCopyFromReg(Node, 0, IsClone, IsCloned, SrcReg, VRBaseMap);
     break;
   }
+  case ISD::EH_LABEL: {
+    MCSymbol *S = cast<EHLabelSDNode>(Node)->getLabel();
+    BuildMI(*MBB, InsertPos, Node->getDebugLoc(),
+            TII->get(TargetOpcode::EH_LABEL)).addSym(S);
+    break;
+  }
+      
   case ISD::INLINEASM: {
     unsigned NumOps = Node->getNumOperands();
     if (Node->getOperand(NumOps-1).getValueType() == MVT::Flag)
index 58a475c0a87a05c8f7779e2e8f45b2d6abb9fb2a..1911103450aa30bf1220abfc1bd8c38ccdc28897 100644 (file)
@@ -1314,24 +1314,23 @@ SDValue SelectionDAG::getRegister(unsigned RegNo, EVT VT) {
   return SDValue(N, 0);
 }
 
-SDValue SelectionDAG::getLabel(unsigned Opcode, DebugLoc dl,
-                               SDValue Root,
-                               unsigned LabelID) {
+SDValue SelectionDAG::getEHLabel(DebugLoc dl, SDValue Root, MCSymbol *Label) {
   FoldingSetNodeID ID;
   SDValue Ops[] = { Root };
-  AddNodeIDNode(ID, Opcode, getVTList(MVT::Other), &Ops[0], 1);
-  ID.AddInteger(LabelID);
+  AddNodeIDNode(ID, ISD::EH_LABEL, getVTList(MVT::Other), &Ops[0], 1);
+  ID.AddPointer(Label);
   void *IP = 0;
   if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP))
     return SDValue(E, 0);
-
-  SDNode *N = NodeAllocator.Allocate<LabelSDNode>();
-  new (N) LabelSDNode(Opcode, dl, Root, LabelID);
+  
+  SDNode *N = NodeAllocator.Allocate<EHLabelSDNode>();
+  new (N) EHLabelSDNode(dl, Root, Label);
   CSEMap.InsertNode(N, IP);
   AllNodes.push_back(N);
   return SDValue(N, 0);
 }
 
+
 SDValue SelectionDAG::getBlockAddress(BlockAddress *BA, EVT VT,
                                       bool isTarget,
                                       unsigned char TargetFlags) {
index 08ba62b659d683a66348d801c96f4719ae1ba02c..00ee13f7b1384ff698a08cc6f6edfa81ca505d74 100644 (file)
@@ -4362,8 +4362,7 @@ void SelectionDAGBuilder::LowerCallTo(CallSite CS, SDValue Callee,
   if (LandingPad && MMI) {
     // Insert a label before the invoke call to mark the try range.  This can be
     // used to detect deletion of the invoke via the MachineModuleInfo.
-    unsigned BeginLabelID = MMI->NextLabelID();
-    BeginLabel = MMI->getLabelSym(BeginLabelID);
+    BeginLabel = MMI->getLabelSym(MMI->NextLabelID());
 
     // For SjLj, keep track of which landing pads go with which invokes
     // so as to maintain the ordering of pads in the LSDA.
@@ -4377,8 +4376,7 @@ void SelectionDAGBuilder::LowerCallTo(CallSite CS, SDValue Callee,
     // Both PendingLoads and PendingExports must be flushed here;
     // this call might not return.
     (void)getRoot();
-    DAG.setRoot(DAG.getLabel(ISD::EH_LABEL, getCurDebugLoc(),
-                             getControlRoot(), BeginLabelID));
+    DAG.setRoot(DAG.getEHLabel(getCurDebugLoc(), getControlRoot(), BeginLabel));
   }
 
   // Check if target-independent constraints permit a tail call here.
@@ -4466,10 +4464,8 @@ void SelectionDAGBuilder::LowerCallTo(CallSite CS, SDValue Callee,
   if (LandingPad && MMI) {
     // Insert a label at the end of the invoke call to mark the try range.  This
     // can be used to detect deletion of the invoke via the MachineModuleInfo.
-    unsigned EndLabelID = MMI->NextLabelID();
-    MCSymbol *EndLabel = MMI->getLabelSym(EndLabelID);
-    DAG.setRoot(DAG.getLabel(ISD::EH_LABEL, getCurDebugLoc(),
-                             getRoot(), EndLabelID));
+    MCSymbol *EndLabel = MMI->getLabelSym(MMI->NextLabelID());
+    DAG.setRoot(DAG.getEHLabel(getCurDebugLoc(), getRoot(), EndLabel));
 
     // Inform MachineModuleInfo of range.
     MMI->addInvoke(LandingPad, BeginLabel, EndLabel);
index a82f0f71fea5b64aad936c39c2fca4494fcf8cec..ac71af5a78c6d6d3f82e8c1b666f74c6c5ce63c8 100644 (file)
@@ -879,10 +879,10 @@ void SelectionDAGISel::SelectAllBasicBlocks(Function &Fn,
     if (MMI && BB->isLandingPad()) {
       // Add a label to mark the beginning of the landing pad.  Deletion of the
       // landing pad can thus be detected via the MachineModuleInfo.
-      unsigned LabelID = MMI->addLandingPad(BB);
+      MCSymbol *Label = MMI->addLandingPad(BB);
 
       const TargetInstrDesc &II = TII.get(TargetOpcode::EH_LABEL);
-      BuildMI(BB, SDB->getCurDebugLoc(), II).addImm(LabelID);
+      BuildMI(BB, SDB->getCurDebugLoc(), II).addSym(Label);
 
       // Mark exception register as live in.
       unsigned Reg = TLI.getExceptionAddressRegister();
@@ -1517,14 +1517,6 @@ SDNode *SelectionDAGISel::Select_UNDEF(SDNode *N) {
   return CurDAG->SelectNodeTo(N, TargetOpcode::IMPLICIT_DEF,N->getValueType(0));
 }
 
-SDNode *SelectionDAGISel::Select_EH_LABEL(SDNode *N) {
-  SDValue Chain = N->getOperand(0);
-  unsigned C = cast<LabelSDNode>(N)->getLabelID();
-  SDValue Tmp = CurDAG->getTargetConstant(C, MVT::i32);
-  return CurDAG->SelectNodeTo(N, TargetOpcode::EH_LABEL,
-                              MVT::Other, Tmp, Chain);
-}
-
 /// GetVBR - decode a vbr encoding whose top bit is set.
 ALWAYS_INLINE static uint64_t
 GetVBR(uint64_t Val, const unsigned char *MatcherTable, unsigned &Idx) {
@@ -1651,7 +1643,8 @@ WalkChainUsers(SDNode *ChainedNode,
     
     if (User->getOpcode() == ISD::CopyToReg ||
         User->getOpcode() == ISD::CopyFromReg ||
-        User->getOpcode() == ISD::INLINEASM) {
+        User->getOpcode() == ISD::INLINEASM ||
+        User->getOpcode() == ISD::EH_LABEL) {
       // If their node ID got reset to -1 then they've already been selected.
       // Treat them like a MachineOpcode.
       if (User->getNodeId() == -1)
@@ -2055,6 +2048,7 @@ SelectCodeCommon(SDNode *NodeToMatch, const unsigned char *MatcherTable,
   case ISD::TokenFactor:
   case ISD::CopyFromReg:
   case ISD::CopyToReg:
+  case ISD::EH_LABEL:
     NodeToMatch->setNodeId(-1); // Mark selected.
     return 0;
   case ISD::AssertSext:
@@ -2063,7 +2057,6 @@ SelectCodeCommon(SDNode *NodeToMatch, const unsigned char *MatcherTable,
                                       NodeToMatch->getOperand(0));
     return 0;
   case ISD::INLINEASM: return Select_INLINEASM(NodeToMatch);
-  case ISD::EH_LABEL:  return Select_EH_LABEL(NodeToMatch);
   case ISD::UNDEF:     return Select_UNDEF(NodeToMatch);
   }
   
index f7e5e4ed80e77d66a5fc52c80968d9c6872ca480..e3b1dda39c972540027d49f3e580e228059c8f55 100644 (file)
@@ -564,9 +564,11 @@ void ARMCodeEmitter::emitPseudoInstruction(const MachineInstr &MI) {
     break;
   }
   case TargetOpcode::DBG_LABEL:
-  case TargetOpcode::EH_LABEL:
     MCE.emitLabel(MMI->getLabelSym(MI.getOperand(0).getImm()));
     break;
+  case TargetOpcode::EH_LABEL:
+    MCE.emitLabel(MI.getOperand(0).getMCSymbol());
+    break;
   case TargetOpcode::IMPLICIT_DEF:
   case TargetOpcode::KILL:
     // Do nothing.
index 3d8daf7586dde6d2a31f69038fc92fa1e8dfc77f..6c4cf800a55867f55c4d616a6c51c4f08f9c6bb3 100644 (file)
@@ -111,9 +111,11 @@ void PPCCodeEmitter::emitBasicBlock(MachineBasicBlock &MBB) {
       MCE.emitWordBE(getBinaryCodeForInstr(MI));
       break;
     case TargetOpcode::DBG_LABEL:
-    case TargetOpcode::EH_LABEL:
       MCE.emitLabel(MMI->getLabelSym(MI.getOperand(0).getImm()));
       break;
+    case TargetOpcode::EH_LABEL:
+      MCE.emitLabel(MI.getOperand(0).getMCSymbol());
+      break;
     case TargetOpcode::IMPLICIT_DEF:
     case TargetOpcode::KILL:
       break; // pseudo opcode, no side effects
index 2267752a5bd1204787e9176363a3103eb91293a5..d5ecd3b72e8b61a83aa1d288ff168d4ab4b22ea2 100644 (file)
@@ -603,10 +603,13 @@ void Emitter<CodeEmitter>::emitInstruction(const MachineInstr &MI,
         llvm_report_error("JIT does not support inline asm!");
       break;
     case TargetOpcode::DBG_LABEL:
-    case TargetOpcode::EH_LABEL:
     case TargetOpcode::GC_LABEL:
       MCE.emitLabel(MMI->getLabelSym(MI.getOperand(0).getImm()));
       break;
+    case TargetOpcode::EH_LABEL:
+      MCE.emitLabel(MI.getOperand(0).getMCSymbol());
+      break;
+        
     case TargetOpcode::IMPLICIT_DEF:
     case TargetOpcode::KILL:
     case X86::FP_REG_KILL: