Skip to content

Hah! – Found IT! Plus another non-pro Mac Tip

March 29, 2015

I’m an old command line hand but a desperate mac newbie.  I like OS X command line but it has a very busy prompt for a single user system. This helpful goody showed me how to change it with
export PS1=”\e[0;31m\w>\e[m “
I also learned to edit my logon profile with
nano ~/.bash_profile
and to make it take effect right away with
source ~/.bash_profile

Now, the reason I was at the command line is I was trying to figure out how to change the format of the assembler labels that are emitted by LLVM so my assembler would allow them. For example:

int main(void){
  return 0;
	;file	"loop.c"
	;globl	main
	;type	main,@function
	LBR .LBB0_1
	;size	main, (.Ltmp0)-main

	;ident	"clang version 3.6.0 "
	.section	".note.GNU-stack","",@progbits

I looked in what seemed like all the sensible and recommended places, I found
PrivateGlobalPrefix = “.L”;
but changing it had no effect. Finally, with my newly prettied command prompt, I
~/documents/legc/src> grep -r -F \”.L .
and found that buried in a header file: /include/llvm/IR/DataLayout.h
were a bunch of hardcoded values including:

  const char *getPrivateGlobalPrefix() const {
    switch (ManglingMode) {
    case MM_None:
      return "";
    case MM_ELF:
      return ".L";         ************* HAH! ******************
    case MM_Mips:
      return "$";
    case MM_MachO:
    case MM_WINCOFF:
      return "L";
    llvm_unreachable("invalid mangling mode");

I can’t believe this is original llvm code but i haven’t tracked it down yet. Anyway, changing that to $$L worked in the short term. Actually, I doubt that the $$L is the right thing to use, I believe that the ‘.’ just means it’s local to the assembly and my $$L labels are more temporary than that. I may need to use something like _$_L and see what happens.

I have been trying to come to grips with the llvm conditional branch to match it in
While I was grep’ing,
grep -r br_cc . turned up
./lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp:  case ISD::BR_CC: return “br_cc”;

and looking for ISD::BR_CC, I found – among other things

SDValue ARMTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
  switch (Op.getOpcode()) {
  default: llvm_unreachable("Don't know how to custom lower this!");
  case ISD::ConstantPool:  return LowerConstantPool(Op, DAG);
  case ISD::BlockAddress:  return LowerBlockAddress(Op, DAG);
  case ISD::GlobalAddress:
    switch (Subtarget->getTargetTriple().getObjectFormat()) {
    default: llvm_unreachable("unknown object format");
    case Triple::COFF:
      return LowerGlobalAddressWindows(Op, DAG);
    case Triple::ELF:
      return LowerGlobalAddressELF(Op, DAG);
    case Triple::MachO:
      return LowerGlobalAddressDarwin(Op, DAG);
  case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG);
  case ISD::SELECT:        return LowerSELECT(Op, DAG);
  case ISD::SELECT_CC:     return LowerSELECT_CC(Op, DAG);
  case ISD::BR_CC:         return LowerBR_CC(Op, DAG);

Where LEG has

SDValue LEGTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
  switch (Op.getOpcode()) {
    llvm_unreachable("Unimplemented operand");
  case ISD::GlobalAddress:
    return LowerGlobalAddress(Op, DAG);

so somewhere something tells llvm which ops to try lowering. I THINK if I had a pattern that matched the BR_CC that would drive me into LowerOperation – NOPE, because I have one that matches BR and I don’t go in for that.


From → LLVM

Leave a Comment

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

%d bloggers like this: