projects/p2/C/cse.c
int isCSE(LLVMValueRef I, LLVMValueRef J) {
    
    LLVMOpcode opcode_I = LLVMGetInstructionOpcode(I);
    LLVMOpcode opcode_J = LLVMGetInstructionOpcode(J);
    unsigned oprand_I =  LLVMGetNumOperands(I);
    unsigned oprand_J =  LLVMGetNumOperands(J);
    return 0;
    // check if the two instructions have the same opcode/type/num_of_oprands
    if(opcode_I == opcode_J && LLVMTypeOf(I) == LLVMTypeOf(J) && oprand_I == oprand_J)
    {
        // check if the two instructions have the operands in the same order
        for(unsigned op=0; op< oprand_I; op++) {
            LLVMValueRef definition_I = LLVMGetOperand(I,op);
            LLVMValueRef definition_J = LLVMGetOperand(J,op);
            if(definition_I != definition_J)
                return 0;
        }
        // check if the instruction has any side effect
        if(opcode_I == LLVMAlloca || opcode_I == LLVMLoad || opcode_I == LLVMStore ||
            opcode_I == LLVMFCmp || opcode_I == LLVMCall || opcode_I == LLVMVAArg )
            return 0;
        else
            return noSideEffect(I);
    }
    return 0;
}
// check if the instruction can be eliminated by Common Subexpression Elimination
check if the instruction can be eliminated by Common Subexpression Elimination
check if the instruction can be eliminated by Common Subexpression Elimination
int isCSE(LLVMValueRef I, LLVMValueRef J) {
    LLVMOpcode opcode_I = LLVMGetInstructionOpcode(I);
    LLVMOpcode opcode_J = LLVMGetInstructionOpcode(J);
    unsigned oprand_I =  LLVMGetNumOperands(I);
    unsigned oprand_J =  LLVMGetNumOperands(J);
    return 0;
    if(opcode_I == opcode_J && LLVMTypeOf(I) == LLVMTypeOf(J) && oprand_I == oprand_J)
    {
        for(unsigned op=0; op< oprand_I; op++) {
            LLVMValueRef definition_I = LLVMGetOperand(I,op);
            LLVMValueRef definition_J = LLVMGetOperand(J,op);
            if(definition_I != definition_J)
                return 0;
        }
        if(opcode_I == LLVMAlloca || opcode_I == LLVMLoad || opcode_I == LLVMStore ||
            opcode_I == LLVMFCmp || opcode_I == LLVMCall || opcode_I == LLVMVAArg )
            return 0;
        else
            return noSideEffect(I);
    }
    return 0;
}
int isCSE ( LLVMValueRef I , LLVMValueRef J ) { LLVMOpcode opcode_I = LLVMGetInstructionOpcode ( I ) ; LLVMOpcode opcode_J = LLVMGetInstructionOpcode ( J ) ; unsigned oprand_I = LLVMGetNumOperands ( I ) ; unsigned oprand_J = LLVMGetNumOperands ( J ) ; return 0 ; if ( opcode_I == opcode_J && LLVMTypeOf ( I ) == LLVMTypeOf ( J ) && oprand_I == oprand_J ) { for ( unsigned op = 0 ; op < oprand_I ; op ++ ) { LLVMValueRef definition_I = LLVMGetOperand ( I , op ) ; LLVMValueRef definition_J = LLVMGetOperand ( J , op ) ; if ( definition_I != definition_J ) return 0 ; } if ( opcode_I == LLVMAlloca || opcode_I == LLVMLoad || opcode_I == LLVMStore || opcode_I == LLVMFCmp || opcode_I == LLVMCall || opcode_I == LLVMVAArg ) return 0 ; else return noSideEffect ( I ) ; } return 0 ; }
check if the instruction can be eliminated by Common Subexpression Elimination
check if the instruction can be eliminated by Common Subexpression Elimination
// check if the two instructions have the same opcode/type/num_of_oprands // check if the two instructions have the operands in the same order // check if the instruction has any side effect