Skip to content

In Which I Examine A LEG Quite Closely

November 12, 2014

LLVM is THE modern procedural language compiler. I’m planning to implement LLVM for the 1802 to replace my existing LCC1802 C compiler.

I got the LLVM-LEG compiler example code working and now I’m looking at exactly what is involved in the back end. I’ve been through the codeplay tutorial and others but I’m still working on how exactly to proceed with building my own back end for the 1802.

Today I pulled down the original LLVM release 3.4.2 code and diff’d it against the llvm-leg-leg_for_release_34 that paul-andre saulais provided. This excludes the Clang compiler front end which I’ll diff later. I found several sets of differences:

  • (A)In the main source directory, cmakelists.txt just adds LEG to a list of targets (there is also a readme added to this directory
  • (B)There’s a codeplay directory added to the docs directory which has a bunch of examples
  • (C)There is a LEG directory added to the lib\target directory alongside all the other targets like X86 and ARM. This presumably contains all the actual code and definitions for LEG.
  • (D)There are eight other files files in the include\ and lib\ directory structures that show changes.  Some of them are clearly just adding LEG to existing lists of architectures/targets and some have something to do with reusing code from the ARM target

I’d like to think that if i just duplicated the LEG(C) target directory changing LEG to(say) COSMAC wherever it shows up then added COSMAC wherever LEG has been added in the (D) files then I would have a clone that would also use whatever part of the ARM code LEG is using.

The files in the actual LEG target directory are as follows

.\lib\target\leg\cmakelists.txt	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\leg.h	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\leg.td	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\legasmprinter.cpp	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\legcallingconv.td	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\legframelowering.cpp	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\legframelowering.h	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\leginstrformats.td	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\leginstrinfo.cpp	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\leginstrinfo.h	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\leginstrinfo.td	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\legiseldagtodag.cpp	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\legisellowering.cpp	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\legisellowering.h	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\legmachinefunctioninfo.h	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\legmcinstlower.cpp	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\legmcinstlower.h	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\legoperators.td	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\legregisterinfo.cpp	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\legregisterinfo.h	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\legregisterinfo.td	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\legselectiondaginfo.cpp	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\legselectiondaginfo.h	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\legsubtarget.cpp	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\legsubtarget.h	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\legtargetmachine.cpp	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\legtargetmachine.h	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\llvmbuild.txt	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\instprinter\cmakelists.txt	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\instprinter\leginstprinter.cpp	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\instprinter\leginstprinter.h	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\instprinter\llvmbuild.txt	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\mctargetdesc\cmakelists.txt	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\mctargetdesc\legasmbackend.cpp	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\mctargetdesc\legbaseinfo.h	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\mctargetdesc\legelfobjectwriter.cpp	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\mctargetdesc\legfixupkinds.h	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\mctargetdesc\legmcasminfo.cpp	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\mctargetdesc\legmcasminfo.h	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\mctargetdesc\legmccodeemitter.cpp	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\mctargetdesc\legmctargetdesc.cpp	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\mctargetdesc\legmctargetdesc.h	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\mctargetdesc\llvmbuild.txt	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\targetinfo\cmakelists.txt	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\targetinfo\legtargetinfo.cpp	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34
.\lib\target\leg\targetinfo\llvmbuild.txt	only in C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34

The files in the include and lib structures are as follows:

.\include\llvm\adt\triple.h	different (C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34 is more recent)
	adds archtype line 75:     leg      // LEG: leg
.\include\llvm\mc\mcexpr.h	different (C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34 is more recent)
	adds lines 251-2 to VariantKind:
	    VK_LEG_LO,
	    VK_LEG_HI,
.\include\llvm\mc\mcstreamer.h	different (C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34 is more recent)
	adds lines 99-122 generally duplicating preceding section
	class ARMTargetAsmStreamer : public ARMTargetStreamer {
	  formatted_raw_ostream &OS;
	  MCInstPrinter &InstPrinter;
	
	  virtual void emitFnStart();
	  virtual void emitFnEnd();
	  virtual void emitCantUnwind();
	  virtual void emitPersonality(const MCSymbol *Personality);
	  virtual void emitHandlerData();
	  virtual void emitSetFP(unsigned FpReg, unsigned SpReg, int64_t Offset = 0);
	  virtual void emitPad(int64_t Offset);
	  virtual void emitRegSave(const SmallVectorImpl &RegList,
	                           bool isVector);
	
	  virtual void switchVendor(StringRef Vendor);
	  virtual void emitAttribute(unsigned Attribute, unsigned Value);
	  virtual void emitTextAttribute(unsigned Attribute, StringRef String);
	  virtual void emitFPU(unsigned FPU);
	  virtual void finishAttributeSection();
	
	public:
	  ARMTargetAsmStreamer(formatted_raw_ostream &OS, MCInstPrinter &InstPrinter);
	};
	
.\include\llvm\support\elf.h	different (C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34 is more recent)
	adds line 290 to enum for machine architectures
	  EM_LEG           = 220

.\lib\mc\mcexpr.cpp	different (C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34 is more recent)
	adds lines 275-276 to switch in MCSymbolRefExpr::getVariantKindName
	    case VK_LEG_LO: return "LEG_LO";
	    case VK_LEG_HI: return "LEG_HI";

	adds lines 414-415 to switch in MCSymbolRefExpr::getVariantKindForName
	      .Case("LEG_LO", VK_LEG_LO)
	      .Case("LEG_HI", VK_LEG_HI)
.\lib\support\triple.cpp	different (C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34 is more recent)
	adds lines 48, 94, 193, 257, 696,752, 780 to switches in getArchTypeName,getArchTypePrefix, getArchTypeForLLVMName
								parseArch,getArchPointerBitWidth**, get32BitArchVariant,
								get64BitArchVariant
	 case leg:         return "leg";
	 case leg:         return "leg";
	 .Case("leg", leg)
	 .Case("leg", Triple::leg)
	 case llvm::Triple::leg:
	 case Triple::leg:
	 case Triple::leg:

.\lib\target\llvmbuild.txt	different (C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34 is more recent)
  	adds LEG to line 19
  	subdirectories = AArch64 ARM CppBackend Hexagon MSP430 NVPTX Mips PowerPC R600 Sparc SystemZ X86 XCore LEG

.\lib\target\arm\mctargetdesc\armelfstreamer.cpp	different (C:\Users\bill\Downloads\LLVM\llvm-leg-leg_for_release_34 is more recent)
	replaces a whole bunch of lines around line 64, with a few around line 124 to do with using the "arm streamer"
	This happens because a class that was required to be implemented in 3.4 (MCTargetStreamer) is now optional in 3.5. 
	When porting back to 3.4, the easiest thing to do was to piggyback ARM's ARMTargetAsmStreamer
	(see LEG/TargetDesc/LEGMCTargetDesc.cpp). 
	This however requires the ARM target to be built in order to avoid linking errors. 
	This could be avoided by implementing LEGTargetAsmStreamer but I didn't like the idea of copy-pasting the entire code.
	64,91d64
	< namespace {
	< 
	< class ARMELFStreamer;
	< 
	< class ARMTargetAsmStreamer : public ARMTargetStreamer {
	<   formatted_raw_ostream &OS;
	<   MCInstPrinter &InstPrinter;
	< 
	<   virtual void emitFnStart();
	<   virtual void emitFnEnd();
	<   virtual void emitCantUnwind();
	<   virtual void emitPersonality(const MCSymbol *Personality);
	<   virtual void emitHandlerData();
	<   virtual void emitSetFP(unsigned FpReg, unsigned SpReg, int64_t Offset = 0);
	<   virtual void emitPad(int64_t Offset);
	<   virtual void emitRegSave(const SmallVectorImpl &RegList,
	<                            bool isVector);
	< 
	<   virtual void switchVendor(StringRef Vendor);
	<   virtual void emitAttribute(unsigned Attribute, unsigned Value);
	<   virtual void emitTextAttribute(unsigned Attribute, StringRef String);
	<   virtual void emitFPU(unsigned FPU);
	<   virtual void finishAttributeSection();
	< 
	< public:
	<   ARMTargetAsmStreamer(formatted_raw_ostream &OS, MCInstPrinter &InstPrinter);
	< };
	<  	152a124,127 	> namespace {
	> 
	> class ARMELFStreamer;
	> 
Advertisements

From → LLVM

One Comment

Trackbacks & Pingbacks

  1. And What is A Clang Exactly | olduino

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: