[llvm-commits] [llvm] r78506 - in /llvm/trunk: lib/Target/Blackfin/BlackfinISelLowering.cpp lib/Target/Blackfin/BlackfinISelLowering.h lib/Target/Blackfin/BlackfinRegisterInfo.cpp test/CodeGen/Blackfin/cycles.ll
Jakob Stoklund Olesen
stoklund at 2pi.dk
Sat Aug 8 14:42:23 PDT 2009
Author: stoklund
Date: Sat Aug 8 16:42:22 2009
New Revision: 78506
URL: http://llvm.org/viewvc/llvm-project?rev=78506&view=rev
Log:
Add support for READCYCLECOUNTER in Blackfin back-end.
Modified:
llvm/trunk/lib/Target/Blackfin/BlackfinISelLowering.cpp
llvm/trunk/lib/Target/Blackfin/BlackfinISelLowering.h
llvm/trunk/lib/Target/Blackfin/BlackfinRegisterInfo.cpp
llvm/trunk/test/CodeGen/Blackfin/cycles.ll
Modified: llvm/trunk/lib/Target/Blackfin/BlackfinISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Blackfin/BlackfinISelLowering.cpp?rev=78506&r1=78505&r2=78506&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Blackfin/BlackfinISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/Blackfin/BlackfinISelLowering.cpp Sat Aug 8 16:42:22 2009
@@ -111,6 +111,9 @@
setOperationAction(ISD::CTLZ, MVT::i32, Expand);
setOperationAction(ISD::CTTZ, MVT::i32, Expand);
+ // READCYCLECOUNTER needs special type legalization.
+ setOperationAction(ISD::READCYCLECOUNTER, MVT::i64, Custom);
+
// We don't have line number support yet.
setOperationAction(ISD::DBG_STOPPOINT, MVT::Other, Expand);
setOperationAction(ISD::DEBUG_LOC, MVT::Other, Expand);
@@ -463,6 +466,34 @@
}
}
+void
+BlackfinTargetLowering::ReplaceNodeResults(SDNode *N,
+ SmallVectorImpl<SDValue> &Results,
+ SelectionDAG &DAG) {
+ DebugLoc dl = N->getDebugLoc();
+ switch (N->getOpcode()) {
+ default:
+ llvm_unreachable("Do not know how to custom type legalize this operation!");
+ return;
+ case ISD::READCYCLECOUNTER: {
+ // The low part of the cycle counter is in CYCLES, the high part in
+ // CYCLES2. Reading CYCLES will latch the value of CYCLES2, so we must read
+ // CYCLES2 last.
+ SDValue TheChain = N->getOperand(0);
+ SDValue lo = DAG.getCopyFromReg(TheChain, dl, BF::CYCLES, MVT::i32);
+ SDValue hi = DAG.getCopyFromReg(lo.getValue(1), dl, BF::CYCLES2, MVT::i32);
+ // Use a buildpair to merge the two 32-bit values into a 64-bit one.
+ Results.push_back(DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, lo, hi));
+ // Outgoing chain. If we were to use the chain from lo instead, it would be
+ // possible to entirely eliminate the CYCLES2 read in (i32 (trunc
+ // readcyclecounter)). Unfortunately this could possibly delay the CYCLES2
+ // read beyond the next CYCLES read, leading to invalid results.
+ Results.push_back(hi.getValue(1));
+ return;
+ }
+ }
+}
+
/// getFunctionAlignment - Return the Log2 alignment of this function.
unsigned BlackfinTargetLowering::getFunctionAlignment(const Function *F) const {
return 2;
Modified: llvm/trunk/lib/Target/Blackfin/BlackfinISelLowering.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Blackfin/BlackfinISelLowering.h?rev=78506&r1=78505&r2=78506&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Blackfin/BlackfinISelLowering.h (original)
+++ llvm/trunk/lib/Target/Blackfin/BlackfinISelLowering.h Sat Aug 8 16:42:22 2009
@@ -35,6 +35,9 @@
BlackfinTargetLowering(TargetMachine &TM);
virtual MVT getSetCCResultType(MVT VT) const;
virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG);
+ virtual void ReplaceNodeResults(SDNode *N,
+ SmallVectorImpl<SDValue> &Results,
+ SelectionDAG &DAG);
int getVarArgsFrameOffset() const { return VarArgsFrameOffset; }
Modified: llvm/trunk/lib/Target/Blackfin/BlackfinRegisterInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Blackfin/BlackfinRegisterInfo.cpp?rev=78506&r1=78505&r2=78506&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Blackfin/BlackfinRegisterInfo.cpp (original)
+++ llvm/trunk/lib/Target/Blackfin/BlackfinRegisterInfo.cpp Sat Aug 8 16:42:22 2009
@@ -74,6 +74,7 @@
Reserved.set(AV1S);
Reserved.set(V);
Reserved.set(VS);
+ Reserved.set(CYCLES).set(CYCLES2);
Reserved.set(L0);
Reserved.set(L1);
Reserved.set(L2);
Modified: llvm/trunk/test/CodeGen/Blackfin/cycles.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Blackfin/cycles.ll?rev=78506&r1=78505&r2=78506&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/Blackfin/cycles.ll (original)
+++ llvm/trunk/test/CodeGen/Blackfin/cycles.ll Sat Aug 8 16:42:22 2009
@@ -1,11 +1,17 @@
-; RUN: llvm-as < %s | llc -march=bfin | grep cycles
-; XFAIL: *
-; ExpandIntegerResult #0: 0x181a60c: i64,ch = ReadCycleCounter 0x1104b08
-; Do not know how to expand the result of this operator!
+; RUN: llvm-as < %s | llc -march=bfin | FileCheck %s
declare i64 @llvm.readcyclecounter()
-define i64 @foo() {
+; CHECK: cycles
+; CHECK: cycles2
+define i64 @cyc64() {
%tmp.1 = call i64 @llvm.readcyclecounter()
ret i64 %tmp.1
}
+
+; CHECK: cycles
+define i32 at cyc32() {
+ %tmp.1 = call i64 @llvm.readcyclecounter()
+ %s = trunc i64 %tmp.1 to i32
+ ret i32 %s
+}
More information about the llvm-commits
mailing list