[LLVMdev] X86: copyConstantToRegister

Vladimir Prus ghost at cs.msu.su
Mon Jun 7 08:42:00 PDT 2004


Hello,
looking at X86 codegen, I see this:

void ISel::copyConstantToRegister(MachineBasicBlock *MBB,
                                  MachineBasicBlock::iterator IP,
                                  Constant *C, unsigned R) {
  if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
	.....
       case Instruction::Add:
          emitSimpleBinaryOperation(MBB, IP, CE->getOperand(0),
                                                  CE->getOperand(1), 
                                                  Class, R);

I'm not sure I understand this logic. If we have "1 + 2" as constant 
expression, then why emit the code to perform addition? It should be possible 
to just fold the expression and copy immediate "3" into a register.

I must be missing something, but what?

Another question is about TargetInstrInfo::CreateCodeToLoadConst. This seems 
like a perfect fit for the task, but it's not used in X86 backend at all. 
Further, the destination register is represented by Instruction*, and not by 
integer number as elsewhere. What does that Instruction* mean?

Thanks,
Volodya




More information about the llvm-dev mailing list