[LLVMbugs] New pass: LowerConstantExpressions.cpp

Vladimir Prus ghost at cs.msu.su
Thu Jun 24 02:32:04 PDT 2004


Chris,
as promised, here's the pass to convert all constants expression into regular 
instructions. I attach the new file (supposed to go to lib/CodeGen), a patch 
to header file, and a testcase I've used -- it has getelementptr, sub and 
cast const expressions, and also phi nodes, and when I invoke the pass inside 
my codegen, results are OK.

- Volodya
-------------- next part --------------
A non-text attachment was scrubbed...
Name: LowerConstantExpressions.cpp
Type: text/x-c++src
Size: 6331 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20040624/fb2c07fb/attachment.cpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Passes.diff
Type: text/x-diff
Size: 706 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20040624/fb2c07fb/attachment.diff>
-------------- next part --------------
target endian = little
target pointersize = 32
%.str_1 = internal constant [16 x sbyte] c"%d %d %d %d %d\0A\00"		; <[16 x sbyte]*> [#uses=1]

%XA = external global int;
%XB = external global int;

implementation   ; Functions:

declare int %printf(sbyte*, ...)

void %test(int %A, int %B, int %C, int %D) {
entry:
        %t1 = setlt int %A, 0
	br bool %t1, label %less, label %not_less
less:    
        br label %not_less
not_less:	
;	%t2 = phi sbyte* [ getelementptr ([16 x sbyte]*  %.str_1, long 0, long 0), %less], [getelementptr ([16 x sbyte]*  %.str_1, long 0, long 0), %entry]
	%t2 = phi int [ sub ( int cast (int* %XA to int), 
			       int cast (int* %XB to int) ), %less], 
                      [ sub ( int cast (int* %XA to int), 
			       int cast (int* %XB to int) ), %entry]
	%tmp.39 = call int (sbyte*, ...)* %printf( sbyte* getelementptr ([16 x sbyte]*  %.str_1, long 0, long 0) )		; <int> [#uses=0]
	ret void
}

void %main() {
entry:
	call void %__main( )
	call void %test( int 7, int 8, int -5, int 5 )
	ret void
}

declare void %__main()


More information about the llvm-bugs mailing list