From 79660deb492eff4ea3c30968c2db3c05b9fed8e1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Harboe?= Date: Wed, 10 Nov 2010 23:06:00 +0100 Subject: [PATCH] zpu: managed to compile program that writes constant to global variable MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Øyvind Harboe --- lib/Target/ZPU/AsmPrinter/ZPUAsmPrinter.cpp | 25 ++++++++++- lib/Target/ZPU/ZPUISelLowering.cpp | 15 +++++++ lib/Target/ZPU/ZPUISelLowering.h | 4 ++ lib/Target/ZPU/ZPUInstrInfo.td | 12 ++--- lib/Target/ZPU/notes.txt | 70 +++++++++++++---------------- 5 files changed, 81 insertions(+), 45 deletions(-) rewrite lib/Target/ZPU/notes.txt (95%) diff --git a/lib/Target/ZPU/AsmPrinter/ZPUAsmPrinter.cpp b/lib/Target/ZPU/AsmPrinter/ZPUAsmPrinter.cpp index 6a4eb97f9f..f7023074bf 100644 --- a/lib/Target/ZPU/AsmPrinter/ZPUAsmPrinter.cpp +++ b/lib/Target/ZPU/AsmPrinter/ZPUAsmPrinter.cpp @@ -177,7 +177,30 @@ bool ZPUAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, void ZPUAsmPrinter::printOperand(const MachineInstr *MI, int opNum, raw_ostream &O) { - O << "asm 10"; + const MachineOperand &MO = MI->getOperand (opNum); + bool CloseParen = false; + switch (MO.getType()) { + case MachineOperand::MO_Register: + O << "%" << LowercaseString(getRegisterName(MO.getReg())); + break; + + case MachineOperand::MO_Immediate: + O << (int)MO.getImm(); + break; + case MachineOperand::MO_MachineBasicBlock: + O << *MO.getMBB()->getSymbol(); + return; + case MachineOperand::MO_GlobalAddress: + O << *Mang->getSymbol(MO.getGlobal()); + break; + case MachineOperand::MO_ExternalSymbol: + O << MO.getSymbolName(); + break; + default: + llvm_unreachable(""); + } + if (CloseParen) O << ")"; + } void ZPUAsmPrinter::printUnsignedImm(const MachineInstr *MI, int opNum, diff --git a/lib/Target/ZPU/ZPUISelLowering.cpp b/lib/Target/ZPU/ZPUISelLowering.cpp index 585bfaa673..e5fbff9e34 100644 --- a/lib/Target/ZPU/ZPUISelLowering.cpp +++ b/lib/Target/ZPU/ZPUISelLowering.cpp @@ -60,6 +60,8 @@ ZPUTargetLowering(ZPUTargetMachine &TM) // Set up the register classes addRegisterClass(MVT::i32, ZPU::CPURegsRegisterClass); + setOperationAction(ISD::GlobalAddress, MVT::i32, Custom); + // Load extented operations for i1 types must be promoted setLoadExtAction(ISD::EXTLOAD, MVT::i1, Promote); setLoadExtAction(ISD::ZEXTLOAD, MVT::i1, Promote); @@ -123,9 +125,22 @@ unsigned ZPUTargetLowering::getFunctionAlignment(const Function *) const { SDValue ZPUTargetLowering:: LowerOperation(SDValue Op, SelectionDAG &DAG) const { + switch (Op.getOpcode()) { + default: llvm_unreachable("Wasn't expecting to be able to lower this!"); + case ISD::GlobalAddress: return LowerGlobalAddress(Op, DAG); + } + return SDValue(); } +SDValue ZPUTargetLowering::LowerGlobalAddress(SDValue Op, + SelectionDAG &DAG) const { + DebugLoc DL = Op.getDebugLoc(); + const GlobalValue *GV = cast(Op)->getGlobal(); + + return Op = DAG.getTargetGlobalAddress(GV, DL, MVT::i32); +} + //===----------------------------------------------------------------------===// // Lower helper functions //===----------------------------------------------------------------------===// diff --git a/lib/Target/ZPU/ZPUISelLowering.h b/lib/Target/ZPU/ZPUISelLowering.h index 3ebb3fc648..c4b19595c1 100644 --- a/lib/Target/ZPU/ZPUISelLowering.h +++ b/lib/Target/ZPU/ZPUISelLowering.h @@ -57,6 +57,8 @@ namespace llvm { // Floating Point Rounding FPRound, + Wrapper, // Address wrapper + // Return Ret }; @@ -156,6 +158,8 @@ namespace llvm { /// specified FP immediate natively. If false, the legalizer will /// materialize the FP immediate as a load from a constant pool. virtual bool isFPImmLegal(const APFloat &Imm, EVT VT) const; + SDValue LowerGlobalAddress(SDValue Op, + SelectionDAG &DAG) const; }; } diff --git a/lib/Target/ZPU/ZPUInstrInfo.td b/lib/Target/ZPU/ZPUInstrInfo.td index ae1c316cd5..03fc27491d 100644 --- a/lib/Target/ZPU/ZPUInstrInfo.td +++ b/lib/Target/ZPU/ZPUInstrInfo.td @@ -15,25 +15,27 @@ include "ZPUInstrFormats.td" // Address operands def memdst : Operand { - let PrintMethod = "printSrcMemOperand"; + let PrintMethod = "printOperand"; let MIOperandInfo = (ops i32imm); } // Address operand -/* def memaddr : Operand { - let PrintMethod = "printMemOperand"; + let PrintMethod = "printOperand"; let MIOperandInfo = (ops i32imm); } -*/ +def ZPUWrapper: SDNode<"ZPUISD::Wrapper", SDTIntUnaryOp>; + +// addressing mode //def addr : ComplexPattern; def IM : ZPUIm <(outs CPURegs:$dst), (ins i32imm:$a), "im $a", [(set CPURegs:$dst, imm:$a)]>; - + +// First operands, in the DAG the addressing modes def ZPUSTORE : ZPUIm <(outs), (ins memdst:$dst, i32imm:$a), "store $a $dst", [(store imm:$a, tglobaladdr:$dst)]>; diff --git a/lib/Target/ZPU/notes.txt b/lib/Target/ZPU/notes.txt dissimilarity index 95% index f042815400..ddce3d5761 100644 --- a/lib/Target/ZPU/notes.txt +++ b/lib/Target/ZPU/notes.txt @@ -1,39 +1,31 @@ - - -clang -ccc-host-triple arm-none-none test.c -S - - -oyvind@fiend:~/workspace/lbuild$ cat test.c -int c; -int foo(int b) -{ - return c+b; -} - -oyvind@fiend:~/workspace/lbuild$ clang -ccc-host-triple zpu-none-none test.c -S -0 clang 0x09c473f3 -1 clang 0x09c47180 -2 0x002d2400 __kernel_sigreturn + 0 -3 clang 0x0978845a llvm::LLVMTargetMachine::addCommonCodeGenPasses(llvm::PassManagerBase&, llvm::CodeGenOpt::Level, bool, llvm::MCContext*&) + 460 -4 clang 0x09787cf1 llvm::LLVMTargetMachine::addPassesToEmitFile(llvm::PassManagerBase&, llvm::formatted_raw_ostream&, llvm::TargetMachine::CodeGenFileType, llvm::CodeGenOpt::Level, bool) + 73 -5 clang 0x08bc1f86 -6 clang 0x08bc215b -7 clang 0x08bc2349 clang::EmitBackendOutput(clang::Diagnostic&, clang::CodeGenOptions const&, clang::TargetOptions const&, llvm::Module*, clang::BackendAction, llvm::raw_ostream*) + 70 -8 clang 0x08bbe54d -9 clang 0x08d17da7 clang::ParseAST(clang::Sema&, bool) + 599 -10 clang 0x08a9aaf3 clang::ASTFrontendAction::ExecuteAction() + 253 -11 clang 0x08bbf35f clang::CodeGenAction::ExecuteAction() + 913 -12 clang 0x08a9a74a clang::FrontendAction::Execute() + 316 -13 clang 0x08a85dff clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 779 -14 clang 0x08a3a6d2 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 787 -15 clang 0x08a2e35f cc1_main(char const**, char const**, char const*, void*) + 976 -16 clang 0x08a36be1 main + 521 -17 libc.so.6 0x00c97bd6 __libc_start_main + 230 -18 clang 0x08a2da61 -Stack dump: -0. Program arguments: /home/oyvind/workspace/lbuild/install/bin/clang -cc1 -triple zpu-none-none -S -disable-free -main-file-name test.c -mrelocation-model static -mdisable-fp-elim -mconstructor-aliases -target-linker-version 2.20.1 -resource-dir /home/oyvind/workspace/lbuild/install/bin/../lib/clang/2.9 -ferror-limit 19 -fmessage-length 80 -fgnu-runtime -fdiagnostics-show-option -fcolor-diagnostics -o test.s -x c test.c -1. parser at end of file -clang: error: unable to execute command: Segmentation fault -clang: error: clang frontend command failed due to signal 1 (use -v to see invocation) -oyvind@fiend:~/workspace/lbuild - + + +clang -ccc-host-triple arm-none-none test.c -S + + +oyvind@fiend:~/workspace/lbuild$ cat test.c +int b; +int c; +void foo(void) +{ + //return c+b; + b = 1234; +} + + +clang -ccc-host-triple zpu-none-none test.c -S +oyvind@fiend:~/workspace/lbuild$ cat test.s + .file "test.c" + .text + .globl foo + .align 2 + .type foo,@function + store 1234 b +$tmp0: + .size foo, ($tmp0)-foo + + .type b,@object + .comm b,4,4 + .type c,@object + .comm c,4,4 +oyvind@fiend:~/workspace/lbuild$ -- 2.11.4.GIT