[LLVMdev] CloneBasicBlock and Unnamed Temporaries

Prakash Prabhu prakash.prabhu at gmail.com
Tue Sep 2 08:46:25 PDT 2008


Hi,

I was trying to use CloneBasicBlock() (in Cloning.h) to clone basic
blocks in one of my transform passes. For example, when I have a basic
block like:

bb1:		; preds = %bb
	load i32* %i, align 4		; <i32>:11 [#uses=2]
	load i32* %n_addr, align 4		; <i32>:12 [#uses=2]
	icmp slt i32 %11, %12		; <i1>:13 [#uses=2]	

cloning it gives something like:

bb1_clone: 	; preds = %entry
	load i32* %i, align 4		; <i32>:28 [#uses=0]
	load i32* %n_addr, align 4		; <i32>:29 [#uses=0]
	icmp slt i32 %11, %12		; <i1>:30 [#uses=0]

Since the temporaries referred to in the cloned icmp instruction are
still those created in bb1, I get the "Instruction does not dominate
all uses" error thrown by Verifier.  A couple of questions (assuming
that the code is not in SSA form, courtesy -reg2ssa pass):

(1) Is it always true in the general case (it was true in the example
I tested with) that the unnamed temporaries referenced/created are
local to a basic block ?

(2) If the answer to (1) is no:

If I add the cloned basic block (bb1_clone) into the same function at
a place such that all paths to bb1_clone from the entry are the same
as the earlier paths to bb1 (except that I am now removing an earlier
path to bb1 from one of its predecessor), would repatching the unnamed
temporaries in bb_clone1 to the new ones (local to the cloned block ?)
in the client transform pass be good enough to result in a well formed
LLVM IR representation ?

Thanks much for your time.

- Prakash



More information about the llvm-dev mailing list