The second patch of X86 support for read cycle counter.
authorAndrew Lenharth <andrewl@lenharth.org>
Sun, 20 Nov 2005 21:41:10 +0000 (21:41 +0000)
committerAndrew Lenharth <andrewl@lenharth.org>
Sun, 20 Nov 2005 21:41:10 +0000 (21:41 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24430 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86ISelLowering.cpp
lib/Target/X86/X86ISelLowering.h
lib/Target/X86/X86ISelPattern.cpp
lib/Target/X86/X86InstrInfo.td

index e33bf956860c338c12043697b61ddac9c390d7c5..aa221fbda3dea3f97b8bc67de8914284e77d3452 100644 (file)
@@ -101,6 +101,7 @@ X86TargetLowering::X86TargetLowering(TargetMachine &TM)
   setOperationAction(ISD::CTPOP            , MVT::i32  , Expand);
   setOperationAction(ISD::CTTZ             , MVT::i32  , Expand);
   setOperationAction(ISD::CTLZ             , MVT::i32  , Expand);
+  setOperationAction(ISD::READCYCLECOUNTER , MVT::i64  , Custom);
 
   setOperationAction(ISD::READIO           , MVT::i1   , Expand);
   setOperationAction(ISD::READIO           , MVT::i8   , Expand);
@@ -912,5 +913,11 @@ SDOperand X86TargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) {
     return DAG.getLoad(Op.getValueType(), FIST, StackSlot,
                        DAG.getSrcValue(NULL));
   }
+  case ISD::READCYCLECOUNTER: {
+    SDOperand rd = DAG.getNode(X86ISD::RDTSC_DAG, MVT::Other, Op.getOperand(0));
+    SDOperand Lo = DAG.getCopyFromReg(rd, X86::EAX, MVT::i32);
+    SDOperand Hi = DAG.getCopyFromReg(rd, X86::EDX, MVT::i32);
+    return DAG.getNode(ISD::BUILD_PAIR, MVT::i64, Lo, Hi);
+  }
   }
 }
index b4468ac8a3396322c7eb059828e054231aa3d217..ccec6ea23f7c0bc342e65338d67aaddaa3e63ff0 100644 (file)
@@ -62,6 +62,10 @@ namespace llvm {
       /// LLVM.
       CALL,
       TAILCALL,
+      
+      /// RDTSC_DAG - This operation implements the lowering for 
+      /// readcyclecounter
+      RDTSC_DAG,
     };
   }
 
index 58c60692b9d52aaf6b952092b85aaf9bc730b83b..5c4594aa9ec9bc2f16eb064b1e70bec62ff4f552 100644 (file)
@@ -3090,6 +3090,11 @@ void ISel::Select(SDOperand N) {
   default:
     Node->dump(); std::cerr << "\n";
     assert(0 && "Node not handled yet!");
+  case X86ISD::RDTSC_DAG:
+    Select(Node->getOperand(0)); //Chain
+    BuildMI(BB, X86::RDTSC, 0);
+    return;
+
   case ISD::EntryToken: return;  // Noop
   case ISD::TokenFactor:
     if (Node->getNumOperands() == 2) {
index 40b2481ab4ac35e1fa69cc381397fe57173320e3..0eaf337fd4ff77f2e2c3cc3c00de5d34fd49ef87 100644 (file)
@@ -167,6 +167,10 @@ class Ii32<bits<8> o, Format f, dag ops, string asm, list<dag> pattern>
 def PHI : I<0, Pseudo, (ops variable_ops), "PHINODE">;        // PHI node.
 def NOOP : I<0x90, RawFrm, (ops), "nop">; // nop
 
+//FIXME: encode this correctly
+let Defs = [EAX, EDX] in
+  def RDTSC : I<0, Pseudo, (ops ), "rdtsc">; //in binary, this inst is 0x0f 0x31
+
 def ADJCALLSTACKDOWN : I<0, Pseudo, (ops i32imm:$amt), "#ADJCALLSTACKDOWN">;
 def ADJCALLSTACKUP   : I<0, Pseudo, (ops i32imm:$amt1, i32imm:$amt2),
                          "#ADJCALLSTACKUP">;