[llvm-commits] [llvm] r140547 - in /llvm/trunk: lib/Target/PTX/PTXAsmPrinter.cpp lib/Target/PTX/PTXISelDAGToDAG.cpp lib/Target/PTX/PTXInstrLoadStore.td test/CodeGen/PTX/stack-object.ll
Justin Holewinski
justin.holewinski at gmail.com
Mon Sep 26 11:57:22 PDT 2011
Author: jholewinski
Date: Mon Sep 26 13:57:22 2011
New Revision: 140547
URL: http://llvm.org/viewvc/llvm-project?rev=140547&view=rev
Log:
PTX: Fix detection of stack load/store vs. global load/store, as well as fix the
printing of local offsets
Modified:
llvm/trunk/lib/Target/PTX/PTXAsmPrinter.cpp
llvm/trunk/lib/Target/PTX/PTXISelDAGToDAG.cpp
llvm/trunk/lib/Target/PTX/PTXInstrLoadStore.td
llvm/trunk/test/CodeGen/PTX/stack-object.ll
Modified: llvm/trunk/lib/Target/PTX/PTXAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PTX/PTXAsmPrinter.cpp?rev=140547&r1=140546&r2=140547&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PTX/PTXAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/PTX/PTXAsmPrinter.cpp Mon Sep 26 13:57:22 2011
@@ -299,10 +299,12 @@
if (FrameInfo->getObjectSize(i) > 0) {
std::string def = "\t.local .align ";
def += utostr(FrameInfo->getObjectAlignment(i));
- def += " .b";
- def += utostr(FrameInfo->getObjectSize(i)*8); // Convert to bits
+ def += " .b8";
def += " __local";
def += utostr(i);
+ def += "[";
+ def += utostr(FrameInfo->getObjectSize(i)); // Convert to bits
+ def += "]";
def += ";";
OutStreamer.EmitRawText(Twine(def));
}
@@ -465,6 +467,11 @@
void PTXAsmPrinter::printLocalOperand(const MachineInstr *MI, int opNum,
raw_ostream &OS, const char *Modifier) {
OS << "__local" << MI->getOperand(opNum).getImm();
+
+ if (MI->getOperand(opNum+1).isImm() && MI->getOperand(opNum+1).getImm() != 0){
+ OS << "+";
+ printOperand(MI, opNum+1, OS);
+ }
}
void PTXAsmPrinter::EmitVariableDeclaration(const GlobalVariable *gv) {
Modified: llvm/trunk/lib/Target/PTX/PTXISelDAGToDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PTX/PTXISelDAGToDAG.cpp?rev=140547&r1=140546&r2=140547&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PTX/PTXISelDAGToDAG.cpp (original)
+++ llvm/trunk/lib/Target/PTX/PTXISelDAGToDAG.cpp Mon Sep 26 13:57:22 2011
@@ -213,14 +213,54 @@
// Match memory operand of the form [reg], [imm+reg], and [reg+imm]
bool PTXDAGToDAGISel::SelectADDRri(SDValue &Addr, SDValue &Base,
SDValue &Offset) {
- if (Addr.getOpcode() != ISD::ADD) {
+ // FrameIndex addresses are handled separately
+ //errs() << "SelectADDRri: ";
+ //Addr.getNode()->dumpr();
+ if (isa<FrameIndexSDNode>(Addr)) {
+ //errs() << "Failure\n";
+ return false;
+ }
+
+ if (CurDAG->isBaseWithConstantOffset(Addr)) {
+ Base = Addr.getOperand(0);
+ if (isa<FrameIndexSDNode>(Base)) {
+ //errs() << "Failure\n";
+ return false;
+ }
+ ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Addr.getOperand(1));
+ Offset = CurDAG->getTargetConstant(CN->getZExtValue(), MVT::i32);
+ //errs() << "Success\n";
+ return true;
+ }
+
+ /*if (Addr.getNumOperands() == 1) {
+ Base = Addr;
+ Offset = CurDAG->getTargetConstant(0, Addr.getValueType().getSimpleVT());
+ errs() << "Success\n";
+ return true;
+ }*/
+
+ //errs() << "SelectADDRri fails on: ";
+ //Addr.getNode()->dumpr();
+
+ if (isImm(Addr)) {
+ //errs() << "Failure\n";
+ return false;
+ }
+
+ Base = Addr;
+ Offset = CurDAG->getTargetConstant(0, Addr.getValueType().getSimpleVT());
+
+ //errs() << "Success\n";
+ return true;
+
+ /*if (Addr.getOpcode() != ISD::ADD) {
// let SelectADDRii handle the [imm] case
if (isImm(Addr))
return false;
// it is [reg]
assert(Addr.getValueType().isSimple() && "Type must be simple");
-
Base = Addr;
Offset = CurDAG->getTargetConstant(0, Addr.getValueType().getSimpleVT());
@@ -242,7 +282,7 @@
}
// neither [reg+imm] nor [imm+reg]
- return false;
+ return false;*/
}
// Match memory operand of the form [imm+imm] and [imm]
@@ -269,35 +309,30 @@
// Match memory operand of the form [reg], [imm+reg], and [reg+imm]
bool PTXDAGToDAGISel::SelectADDRlocal(SDValue &Addr, SDValue &Base,
SDValue &Offset) {
- if (Addr.getOpcode() != ISD::ADD) {
- // let SelectADDRii handle the [imm] case
- if (isImm(Addr))
- return false;
- // it is [reg]
-
- assert(Addr.getValueType().isSimple() && "Type must be simple");
-
+ //errs() << "SelectADDRlocal: ";
+ //Addr.getNode()->dumpr();
+ if (isa<FrameIndexSDNode>(Addr)) {
Base = Addr;
Offset = CurDAG->getTargetConstant(0, Addr.getValueType().getSimpleVT());
-
+ //errs() << "Success\n";
return true;
}
- if (Addr.getNumOperands() < 2)
- return false;
-
- // let SelectADDRii handle the [imm+imm] case
- if (isImm(Addr.getOperand(0)) && isImm(Addr.getOperand(1)))
- return false;
-
- // try [reg+imm] and [imm+reg]
- for (int i = 0; i < 2; i ++)
- if (SelectImm(Addr.getOperand(1-i), Offset)) {
- Base = Addr.getOperand(i);
- return true;
+ if (CurDAG->isBaseWithConstantOffset(Addr)) {
+ Base = Addr.getOperand(0);
+ if (!isa<FrameIndexSDNode>(Base)) {
+ //errs() << "Failure\n";
+ return false;
}
+ ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Addr.getOperand(1));
+ Offset = CurDAG->getTargetConstant(CN->getZExtValue(), MVT::i32);
+ //errs() << "Offset: ";
+ //Offset.getNode()->dumpr();
+ //errs() << "Success\n";
+ return true;
+ }
- // neither [reg+imm] nor [imm+reg]
+ //errs() << "Failure\n";
return false;
}
Modified: llvm/trunk/lib/Target/PTX/PTXInstrLoadStore.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PTX/PTXInstrLoadStore.td?rev=140547&r1=140546&r2=140547&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PTX/PTXInstrLoadStore.td (original)
+++ llvm/trunk/lib/Target/PTX/PTXInstrLoadStore.td Mon Sep 26 13:57:22 2011
@@ -24,9 +24,7 @@
def load_global : PatFrag<(ops node:$ptr), (load node:$ptr), [{
const Value *Src;
const PointerType *PT;
- const SDValue &MemOp = N->getOperand(1);
- if ((MemOp.getOpcode() != ISD::FrameIndex) &&
- (Src = cast<LoadSDNode>(N)->getSrcValue()) &&
+ if ((Src = cast<LoadSDNode>(N)->getSrcValue()) &&
(PT = dyn_cast<PointerType>(Src->getType())))
return PT->getAddressSpace() == PTX::GLOBAL;
return false;
@@ -41,11 +39,6 @@
return false;
}]>;
-def load_local : PatFrag<(ops node:$ptr), (load node:$ptr), [{
- const SDValue &MemOp = N->getOperand(1);
- return MemOp.getOpcode() == ISD::FrameIndex;
-}]>;
-
def load_shared : PatFrag<(ops node:$ptr), (load node:$ptr), [{
const Value *Src;
const PointerType *PT;
@@ -59,20 +52,12 @@
: PatFrag<(ops node:$d, node:$ptr), (store node:$d, node:$ptr), [{
const Value *Src;
const PointerType *PT;
- const SDValue &MemOp = N->getOperand(2);
- if ((MemOp.getOpcode() != ISD::FrameIndex) &&
- (Src = cast<StoreSDNode>(N)->getSrcValue()) &&
+ if ((Src = cast<StoreSDNode>(N)->getSrcValue()) &&
(PT = dyn_cast<PointerType>(Src->getType())))
return PT->getAddressSpace() == PTX::GLOBAL;
return false;
}]>;
-def store_local
- : PatFrag<(ops node:$d, node:$ptr), (store node:$d, node:$ptr), [{
- const SDValue &MemOp = N->getOperand(2);
- return MemOp.getOpcode() == ISD::FrameIndex;
-}]>;
-
def store_shared
: PatFrag<(ops node:$d, node:$ptr), (store node:$d, node:$ptr), [{
const Value *Src;
@@ -221,16 +206,16 @@
multiclass PTX_LOCAL_LD_ST<string typestr, RegisterClass RC> {
def LDri32 : InstPTX<(outs RC:$d), (ins LOCALri32:$a),
!strconcat("ld.local", !strconcat(typestr, "\t$d, [$a]")),
- [(set RC:$d, (load_local ADDRlocal32:$a))]>;
+ [(set RC:$d, (load_global ADDRlocal32:$a))]>;
def LDri64 : InstPTX<(outs RC:$d), (ins LOCALri64:$a),
!strconcat("ld.local", !strconcat(typestr, "\t$d, [$a]")),
- [(set RC:$d, (load_local ADDRlocal64:$a))]>;
+ [(set RC:$d, (load_global ADDRlocal64:$a))]>;
def STri32 : InstPTX<(outs), (ins RC:$d, LOCALri32:$a),
!strconcat("st.local", !strconcat(typestr, "\t[$a], $d")),
- [(store_local RC:$d, ADDRlocal32:$a)]>;
+ [(store_global RC:$d, ADDRlocal32:$a)]>;
def STri64 : InstPTX<(outs), (ins RC:$d, LOCALri64:$a),
!strconcat("st.local", !strconcat(typestr, "\t[$a], $d")),
- [(store_local RC:$d, ADDRlocal64:$a)]>;
+ [(store_global RC:$d, ADDRlocal64:$a)]>;
}
multiclass PTX_PARAM_LD_ST<string typestr, RegisterClass RC> {
Modified: llvm/trunk/test/CodeGen/PTX/stack-object.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/PTX/stack-object.ll?rev=140547&r1=140546&r2=140547&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/PTX/stack-object.ll (original)
+++ llvm/trunk/test/CodeGen/PTX/stack-object.ll Mon Sep 26 13:57:22 2011
@@ -1,7 +1,7 @@
; RUN: llc < %s -march=ptx32 -mattr=sm20 | FileCheck %s
define ptx_device float @stack1(float %a) {
- ; CHECK: .local .align 4 .b32 __local0;
+ ; CHECK: .local .align 4 .b8 __local0[4];
%a.2 = alloca float, align 4
; CHECK: st.local.f32 [__local0], %f0
store float %a, float* %a.2
@@ -10,7 +10,7 @@
}
define ptx_device float @stack1_align8(float %a) {
- ; CHECK: .local .align 8 .b32 __local0;
+ ; CHECK: .local .align 8 .b8 __local0[4];
%a.2 = alloca float, align 8
; CHECK: st.local.f32 [__local0], %f0
store float %a, float* %a.2
More information about the llvm-commits
mailing list