NO-OP

Guys,

     I am in need of a no-op instruction: an instruction that does not do anything, and has no operands. Does LLVM predefine such an instruction? I want to transform the program so that there is no empty basic block.

Fernando

Hi Fernando,

Guys,

     I am in need of a no-op instruction: an instruction that does not do
anything, and has no operands. Does LLVM predefine such an instruction? I
want to transform the program so that there is no empty basic block.

While there's no direct "no-op" instruction, there is an equivalent you
can use:

bitcast i8 0 to i8

- or -

EntryInsertionPoint =
    new BitCastInst(Constant::getNullValue(Type::Int32Ty),Type::Int32Ty,
        "entry_point", TheEntryBlock);

Both hlvm and the llvm-gcc4 front end use this to create an insertion
point instruction in the function's entry block where new alloca's are
inserted.

Reid

Fernando Magno Quintao Pereira wrote:

     I am in need of a no-op instruction: an instruction that does not do
anything, and has no operands. Does LLVM predefine such an instruction? I
want to transform the program so that there is no empty basic block.

You can never have an empty basic block. All BBs must have a TerminatorInst.

Nick

     I am in need of a no-op instruction: an instruction that does not do
anything, and has no operands. Does LLVM predefine such an instruction? I
want to transform the program so that there is no empty basic block.

You can never have an empty basic block. All BBs must have a TerminatorInst.

I've built a pass to split critical edges of machine functions, and I have to insert new basic blocks. Some of them will have MBB->begin() == MBB->end().

Fernando

Ah, machine basic blocks are different. They *are* allowed to be empty.

-Chris

I've built a pass to split critical edges of machine functions, and I have
to insert new basic blocks. Some of them will have MBB->begin() ==
MBB->end().

Ah, machine basic blocks are different. They *are* allowed to be empty.

I would like to build an "insertNoOp" and add it to MRegisterInfo. I would have one for each target. For the x86 I am moving the stack pointer to itself. Is there a better "no-op"? A better one would be one that does not use any register, so it will add absolutely no burden on the register allocator.

Fernando

Why do you want to do this? Empty MBBs are valid, and it's probably
better to have your code handle them.

There is a NOP "instruction" on x86, equivalent to XCHG EAX, EAX.

Why do you want to do this? Empty MBBs are valid, and it's probably
better to have your code handle them.

Currently, that is the solution. I have a special treatment for empty basic blocks. I think the code would be more homogeneous if there were no empty basic blocks.

There is a NOP "instruction" on x86, equivalent to XCHG EAX, EAX.

The problem with xchk EAX, EAX is that is uses registers, and it would add a small burden on the register allocator.

Fernando

Hello, Fernando.

The problem with xchk EAX, EAX is that is uses registers, and it would
add a small burden on the register allocator.

There is "just" NOP instruction on x86. Its opcode is 0x90.

Why do you want to do this? Empty MBBs are valid, and it's probably
better to have your code handle them.

Currently, that is the solution. I have a special treatment for empty
basic blocks. I think the code would be more homogeneous if there were no
empty basic blocks.

There is a NOP "instruction" on x86, equivalent to XCHG EAX, EAX.

The problem with xchk EAX, EAX is that is uses registers, and it would
add a small burden on the register allocator.

It won't. EAX is not an explicit operand. The register allocator doesn't need to know it touches any register.

Evan