[llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp SelectionDAG.cpp SelectionDAGISel.cpp SelectionDAGPrinter.cpp

Chris Lattner lattner at cs.uiuc.edu
Mon Nov 28 22:21:18 PST 2005



Changes in directory llvm/lib/CodeGen/SelectionDAG:

LegalizeDAG.cpp updated: 1.216 -> 1.217
SelectionDAG.cpp updated: 1.215 -> 1.216
SelectionDAGISel.cpp updated: 1.105 -> 1.106
SelectionDAGPrinter.cpp updated: 1.28 -> 1.29
---
Log message:

Add support for a new STRING and LOCATION node for line number support, patch 
contributed by Daniel Berlin, with a few cleanups here and there by me.



---
Diffs of the changes:  (+113 -2)

 LegalizeDAG.cpp         |   27 ++++++++++++++++++
 SelectionDAG.cpp        |   16 +++++++++++
 SelectionDAGISel.cpp    |   69 ++++++++++++++++++++++++++++++++++++++++++++++--
 SelectionDAGPrinter.cpp |    3 ++
 4 files changed, 113 insertions(+), 2 deletions(-)


Index: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.216 llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.217
--- llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.216	Mon Nov 28 23:45:29 2005
+++ llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp	Tue Nov 29 00:21:05 2005
@@ -540,6 +540,7 @@
   case ISD::CONDCODE:
   case ISD::VALUETYPE:
   case ISD::SRCVALUE:
+  case ISD::STRING:
     switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) {
     default: assert(0 && "This action is not supported yet!");
     case TargetLowering::Custom: {
@@ -601,6 +602,32 @@
     }
     break;
   }
+
+  case ISD::LOCATION:
+    assert(Node->getNumOperands() == 5 && "Invalid LOCATION node!");
+    Tmp1 = LegalizeOp(Node->getOperand(0));  // Legalize the input chain.
+    
+    switch (TLI.getOperationAction(ISD::LOCATION, MVT::Other)) {
+    case TargetLowering::Promote:
+    default: assert(0 && "This action is not supported yet!");
+    case TargetLowering::Expand:
+      // If the target doesn't support line numbers, ignore this node.
+      Result = Tmp1;
+      break;
+    case TargetLowering::Legal:
+      if (Tmp1 != Node->getOperand(0)) {
+        std::vector<SDOperand> Ops;
+        Ops.push_back(Tmp1);
+        Ops.push_back(Node->getOperand(1));  // line # must be legal.
+        Ops.push_back(Node->getOperand(2));  // col # must be legal.
+        Ops.push_back(Node->getOperand(3));  // filename must be legal.
+        Ops.push_back(Node->getOperand(4));  // working dir # must be legal.
+        Result = DAG.getNode(ISD::LOCATION, MVT::Other, Ops);
+      }
+      break;
+    }
+    break;
+
   case ISD::Constant:
     // We know we don't need to expand constants here, constants only have one
     // value and we check that it is fine above.


Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.215 llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.216
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.215	Tue Nov 22 12:16:00 2005
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp	Tue Nov 29 00:21:05 2005
@@ -274,6 +274,9 @@
     Erased = ConstantFPs.erase(std::make_pair(V, N->getValueType(0)));
     break;
   }
+  case ISD::STRING:
+    Erased = StringNodes.erase(cast<StringSDNode>(N)->getValue());
+    break;
   case ISD::CONDCODE:
     assert(CondCodeNodes[cast<CondCodeSDNode>(N)->get()] &&
            "Cond code doesn't exist!");
@@ -448,6 +451,15 @@
   return SDOperand(N, 0);
 }
 
+SDOperand SelectionDAG::getString(const std::string &Val) {
+  StringSDNode *&N = StringNodes[Val];
+  if (!N) {
+    N = new StringSDNode(Val);
+    AllNodes.push_back(N);
+  }
+  return SDOperand(N, 0);
+}
+
 SDOperand SelectionDAG::getTargetConstant(uint64_t Val, MVT::ValueType VT) {
   assert(MVT::isInteger(VT) && "Cannot create FP integer constant!");
   // Mask out any bits that are not valid for this constant.
@@ -1670,6 +1682,7 @@
   case ISD::READCYCLECOUNTER: return "ReadCycleCounter";
   case ISD::SRCVALUE:      return "SrcValue";
   case ISD::VALUETYPE:     return "ValueType";
+  case ISD::STRING:        return "String";
   case ISD::EntryToken:    return "EntryToken";
   case ISD::TokenFactor:   return "TokenFactor";
   case ISD::AssertSext:    return "AssertSext";
@@ -1787,6 +1800,9 @@
   case ISD::READIO: return "readio";
   case ISD::WRITEIO: return "writeio";
 
+  // Debug info
+  case ISD::LOCATION: return "location";
+
   case ISD::CONDCODE:
     switch (cast<CondCodeSDNode>(this)->get()) {
     default: assert(0 && "Unknown setcc condition!");


Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1.105 llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1.106
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1.105	Tue Nov 22 12:16:00 2005
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp	Tue Nov 29 00:21:05 2005
@@ -17,6 +17,7 @@
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Function.h"
+#include "llvm/GlobalVariable.h"
 #include "llvm/Instructions.h"
 #include "llvm/Intrinsics.h"
 #include "llvm/CodeGen/IntrinsicLowering.h"
@@ -719,6 +720,44 @@
   CurMBB->getParent()->getFrameInfo()->CreateVariableSizedObject();
 }
 
+/// getStringValue - Turn an LLVM constant pointer that eventually points to a
+/// global into a string value.  Return an empty string if we can't do it.
+///
+static std::string getStringValue(Value *V, unsigned Offset = 0) {
+  if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
+    if (GV->hasInitializer() && isa<ConstantArray>(GV->getInitializer())) {
+      ConstantArray *Init = cast<ConstantArray>(GV->getInitializer());
+      if (Init->isString()) {
+        std::string Result = Init->getAsString();
+        if (Offset < Result.size()) {
+          // If we are pointing INTO The string, erase the beginning...
+          Result.erase(Result.begin(), Result.begin()+Offset);
+
+          // Take off the null terminator, and any string fragments after it.
+          std::string::size_type NullPos = Result.find_first_of((char)0);
+          if (NullPos != std::string::npos)
+            Result.erase(Result.begin()+NullPos, Result.end());
+          return Result;
+        }
+      }
+    }
+  } else if (Constant *C = dyn_cast<Constant>(V)) {
+    if (GlobalValue *GV = dyn_cast<GlobalValue>(C))
+      return getStringValue(GV, Offset);
+    else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
+      if (CE->getOpcode() == Instruction::GetElementPtr) {
+        // Turn a gep into the specified offset.
+        if (CE->getNumOperands() == 3 &&
+            cast<Constant>(CE->getOperand(1))->isNullValue() &&
+            isa<ConstantInt>(CE->getOperand(2))) {
+          return getStringValue(CE->getOperand(0),
+                   Offset+cast<ConstantInt>(CE->getOperand(2))->getRawValue());
+        }
+      }
+    }
+  }
+  return "";
+}
 
 void SelectionDAGLowering::visitLoad(LoadInst &I) {
   SDOperand Ptr = getValue(I.getOperand(0));
@@ -813,11 +852,37 @@
     return 0;
     
   case Intrinsic::dbg_stoppoint:
+    {
     if (TLI.getTargetMachine().getIntrinsicLowering().EmitDebugFunctions())
       return "llvm_debugger_stop";
-    if (I.getType() != Type::VoidTy)
-      setValue(&I, DAG.getNode(ISD::UNDEF, TLI.getValueType(I.getType())));
+    
+    std::string fname = "<unknown>";
+    std::vector<SDOperand> Ops;
+
+    // Pull the filename out of the the compilation unit.
+    const GlobalVariable *cunit = dyn_cast<GlobalVariable>(I.getOperand(4));
+    if (cunit && cunit->hasInitializer()) {
+      ConstantStruct *CS = dyn_cast<ConstantStruct>(cunit->getInitializer());
+      if (CS->getNumOperands() > 0) {
+          std::string dirname = getStringValue(CS->getOperand(4));
+          fname = dirname + "/" + getStringValue(CS->getOperand(3));
+        }
+      }
+    // Input Chain
+    Ops.push_back(getRoot());
+    
+    // line number
+    Ops.push_back(getValue(I.getOperand(2)));
+   
+    // column
+    Ops.push_back(getValue(I.getOperand(3)));
+
+    // filename
+    Ops.push_back(DAG.getString(fname));
+    Ops.push_back(DAG.getString(""));
+    DAG.setRoot(DAG.getNode(ISD::LOCATION, MVT::Other, Ops));
     return 0;
+  }
   case Intrinsic::dbg_region_start:
     if (TLI.getTargetMachine().getIntrinsicLowering().EmitDebugFunctions())
       return "llvm_dbg_region_start";


Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp:1.28 llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp:1.29
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp:1.28	Sat Nov 19 21:45:52 2005
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp	Tue Nov 29 00:21:05 2005
@@ -98,7 +98,10 @@
       Op += "<null:" + itostr(M->getOffset()) + ">";
   } else if (const VTSDNode *N = dyn_cast<VTSDNode>(Node)) {
     Op = Op + " VT=" + getValueTypeString(N->getVT());
+  } else if (const StringSDNode *N = dyn_cast<StringSDNode>(Node)) {
+    Op = Op + "\"" + N->getValue() + "\"";
   }
+  
   return Op;
 }
 






More information about the llvm-commits mailing list