Skip to content

In Which I Send a LEG into Spasm

November 17, 2014

Some of what makes an LLVM target is in files with the extension.td like LEGRegisterInfo.td which describes the registers. These are in the source directory (llvmlegcos/lib/target/LEG) but get processed by the tablegen program and end up in /build/lib/target/LEG/ with slightly different names LEGGenRegisterinfo.inc in this case.

//===-- LEGRegisterInfo.td - LEG Register defs ---------*- tablegen -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

//===----------------------------------------------------------------------===//
//  Declarations that describe the LEG register file 
//===----------------------------------------------------------------------===//

class LEGReg<bits<16> Enc, string n> : Register<n> {
  let HWEncoding = Enc;
  let Namespace = "LEG";
}

// CPU registers
def R0  : LEGReg< 0, "r0">;
def R1  : LEGReg< 1, "r1">;
def R2  : LEGReg< 2, "r2">;
def R3  : LEGReg< 3, "r3">;
def R4  : LEGReg< 4, "r4">;
def R5  : LEGReg< 5, "r5">;
def R6  : LEGReg< 6, "r6">;
def R7  : LEGReg< 7, "r7">;
def R8  : LEGReg< 8, "r8">;
def R9  : LEGReg< 9, "r9">;

def SP  : LEGReg<13, "sp">;
def LR  : LEGReg<14, "lr">;


// COSMAC CPU registers
def CR0  : LEGReg< 0, "cr0">;
def CR1  : LEGReg< 1, "cr0">;


// Register classes.
//
def GRRegs : RegisterClass<"LEG", [i32], 32,
  // Return values and arguments
  (add R0, R1, R2, R3,
       R4, R5, R6, R7, R8, R9, SP)>;
// Register classes.
//
def CGRRegs : RegisterClass<"LEG", [i16], 16,
  // Return values and arguments
  (add CR0, CR1)>;

I wasn’t sure whether the tablegen program would run automatically in the Xcode build so I added some register definitions modelled on what was there and pushed build. This ran in seconds so I thought maybe it didn’t work. I picked a spot in LEGRegisterInfo.cpp that was returning a register object and substituted one of my new ones.

unsigned LEGRegisterInfo::getFrameRegister(const MachineFunction &MF) const {
  return LEG::CR0; //wjr:was SP
}

This took 90 minutes to build without complaint(indicating the tablegen had run) and blew up in execution (indicating that the substitution was not a good idea!). I’ll spare you most of the mess but the gist is that the register is unallocatable. I am taking that to be because I hadn’t done anything other than define the register and it’s default attributes weren’t ok for where I used it.

bill-rowes-MacBook:llvmcosmac billrowe$ ./build/bin/debug/clang -cc1 -triple leg-unknown-unknown -S  -o ex1.s llvmlegcos/docs/Codeplay/examples/ex1/ex1.c
This is MY leg
Assertion failed: (RegClass->isAllocatable() && "Virtual register RegClass must be allocatable."), function createVirtualRegister, file /Users/billrowe/llvmcosmac/llvmlegcos/lib/CodeGen/MachineRegisterInfo.cpp, line 107.

Line 107 is the closing bracket after I returned SP, the rest of the error log is here.

Update: oops, fixing the line I changed and re-running the build left me with exactly the same error! Poor Clang is broken 😦

So: to clear the error, i eventually quit Xcode, copied back the original of the LEGRegisterInfo.td file (updating it’s date modified), restarted Xcode and re-built. The build-log is here. I have some doubt about what happens when you modify .td files but i think the issue is that i made registers without putting any code behind them.

Also: Xcode is just too much for this poor little macbook. I’ll either go back to straigh make or move to the big windows box.

Advertisements

From → LLVM

Leave a Comment

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: