From: Anton S. <an...@so...> - 2011-06-10 04:42:06
|
Hello Borja, John, Eric and all, I would love to see great Clang/LLVM support for the AVR architecture. And so I'm hoping to help out here. To get a feel for Clang and LLVM, as well as the avr-llvm back end I have been trying to get the full tool chain to compile. I ran into a couple of problems (patches included) that I'm not sure are actually problems, or just my missunderstandings, or perhaps known issues that are being ignored because of the forthcoming rewrite. In any case, working out these few blockers has help me understand the code base (that and the excellent documentation online on how to write an LLVM backend). Eric, I think we talked a couple of years ago at ESC about alternatives to the PROGMEM solution in avr-gcc and avr-libc. I am excited to see that progress with named address spaces has been made in both GCC and Clang/LLVM and it seems like an excellent tool to simplify not just flash, but also external memory and EEPROM access. The two issues I ran into are that TargetMachine::getFrameInfo() has been renamed to TargetMachine::getFrameLowering() and that TargetLowering::ReplaceNodeResults was not implemented in AVRTargetLowering. I don't expect that the patches below will be very useful by them selves. I'm more curious if I'm at least on the right page. It seems like until the new backend is available it may be more worth my time looking into helping out with the Clang cross compilation work. In particular the TargetInfo being baked into libs/Basic/Targets.cpp seems like an area for cleanup. I think that there was a thread about this on the clang list recently. I'll do some more reading there. Thanks, Anton >From 17ac3236221dd46556c240fe61491614b6c7b536 Mon Sep 17 00:00:00 2001 From: Anton Staaf <an...@so...> Date: Wed, 1 Jun 2011 08:47:48 -0700 Subject: [PATCH 1/2] TargetMachine: Track name change: GetFrameInfo -> GetFrameLowering Signed-off-by: Anton Staaf <an...@so...> --- llvm/trunk/AVR/AVRTargetMachine.cpp | 2 +- llvm/trunk/AVR/AVRTargetMachine.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/trunk/AVR/AVRTargetMachine.cpp b/llvm/trunk/AVR/AVRTargetMachine.cpp index 19772c7..7d8ca24 100644 --- a/llvm/trunk/AVR/AVRTargetMachine.cpp +++ b/llvm/trunk/AVR/AVRTargetMachine.cpp @@ -65,7 +65,7 @@ const AVRSubtarget *AVRTargetMachine::getSubtargetImpl() const return &Subtarget; } -const TargetFrameLowering *AVRTargetMachine::getFrameInfo() const +const TargetFrameLowering *AVRTargetMachine::getFrameLowering() const { return &FrameLowering; } diff --git a/llvm/trunk/AVR/AVRTargetMachine.h b/llvm/trunk/AVR/AVRTargetMachine.h index 2d81ccb..3078fb2 100644 --- a/llvm/trunk/AVR/AVRTargetMachine.h +++ b/llvm/trunk/AVR/AVRTargetMachine.h @@ -39,7 +39,7 @@ public: // TargetMachine const TargetData *getTargetData() const; const AVRRegisterInfo *getRegisterInfo() const; const AVRSubtarget *getSubtargetImpl() const; - const TargetFrameLowering *getFrameInfo() const; + const TargetFrameLowering *getFrameLowering() const; const AVRSelectionDAGInfo *getSelectionDAGInfo() const; bool addInstSelector(PassManagerBase &PM, CodeGenOpt::Level OptLevel); bool addPreEmitPass(PassManagerBase &PM, CodeGenOpt::Level OptLevel); -- 1.7.1 >From 19f96f2c4f64279e4bbbfa9d9de9f80f4fa15a2e Mon Sep 17 00:00:00 2001 From: Anton Staaf <an...@so...> Date: Wed, 1 Jun 2011 08:48:39 -0700 Subject: [PATCH 2/2] Add AVRTargetLowering::ReplaceNodeResults method. Signed-off-by: Anton Staaf <an...@so...> --- llvm/trunk/AVR/AVRISelLowering.cpp | 28 ++++++++++++++++++++++++---- llvm/trunk/AVR/AVRISelLowering.h | 4 +++- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/llvm/trunk/AVR/AVRISelLowering.cpp b/llvm/trunk/AVR/AVRISelLowering.cpp index 5f18763..1698b24 100644 --- a/llvm/trunk/AVR/AVRISelLowering.cpp +++ b/llvm/trunk/AVR/AVRISelLowering.cpp @@ -255,7 +255,7 @@ SDValue AVRTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const case ISD::ROTR: case ISD::SRL: case ISD::SHL: return LowerShifts(Op, DAG); - case ISD::GlobalAddress: return LowerGlobalAddress(Op, DAG); + case ISD::GlobalAddress: return LowerGlobalAddress(Op.getNode(), DAG); case ISD::ADD: return ExpandADDSUB(Op.getNode(), DAG); case ISD::ADDE: return ExpandADDSUB(Op.getNode(), DAG); case ISD::OR: return ExpandOR(Op.getNode(), DAG); @@ -266,6 +266,25 @@ SDValue AVRTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const } } +/// ReplaceNodeResults - Replace the results of node with an illegal result +/// type with new values built out of custom code. +void AVRTargetLowering::ReplaceNodeResults(SDNode *N, + SmallVectorImpl<SDValue>&Results, + SelectionDAG &DAG) const +{ + SDValue Res; + switch (N->getOpcode()) { + default: + llvm_unreachable("Don't know how to custom expand this!"); + break; + case ISD::GlobalAddress: + Res = LowerGlobalAddress(N, DAG); + break; + } + if (Res.getNode()) + Results.push_back(Res); +} + //===----------------------------------------------------------------------===// // Calling Convention Implementation //===----------------------------------------------------------------------===// @@ -761,11 +780,12 @@ SDValue AVRTargetLowering::LowerShifts(SDValue Op, SelectionDAG &DAG) const } SDValue -AVRTargetLowering::LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const +AVRTargetLowering::LowerGlobalAddress(SDNode *N, SelectionDAG &DAG) const { - DebugLoc dl = Op.getDebugLoc(); + SDValue Op; + DebugLoc dl = N->getDebugLoc(); assert(0 && "custom GLOBADDRESD" ); - const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); + const GlobalValue *GV = cast<GlobalAddressSDNode>(N)->getGlobal(); Op = DAG.getTargetGlobalAddress(GV, dl, getPointerTy()); return DAG.getNode(AVRISD::Wrapper, dl, getPointerTy(), Op); diff --git a/llvm/trunk/AVR/AVRISelLowering.h b/llvm/trunk/AVR/AVRISelLowering.h index 0535171..a46318c 100644 --- a/llvm/trunk/AVR/AVRISelLowering.h +++ b/llvm/trunk/AVR/AVRISelLowering.h @@ -50,6 +50,8 @@ public : // TargetLowering unsigned getFunctionAlignment(const Function *) const; const char *getTargetNodeName(unsigned Opcode) const; SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const; + void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results, + SelectionDAG &DAG) const; private: void AnalyzeArguments(const Function *F, CCState &CCInfo) const; void AnalyzeReturn(CCState &CCInfo, @@ -91,7 +93,7 @@ private: SmallVectorImpl<SDValue> &InVals) const; // Custom lowering functions SDValue LowerShifts(SDValue Op, SelectionDAG &DAG) const; - SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const; + SDValue LowerGlobalAddress(SDNode *N, SelectionDAG &DAG) const; private: const TargetData *TD; }; -- 1.7.1 |