[cfe-commits] r42766 - in /cfe/trunk: CodeGen/CGStmt.cpp CodeGen/CodeGenFunction.cpp CodeGen/CodeGenFunction.h test/CodeGen/switch.c

Chris Lattner clattner at apple.com
Mon Oct 8 20:03:09 PDT 2007


> URL: http://llvm.org/viewvc/llvm-project?rev=42766&view=rev
> Log:
> Code gen case statement ranges.

Nice!

> +++ cfe/trunk/CodeGen/CGStmt.cpp Mon Oct  8 15:57:48 2007
> @@ -354,23 +354,73 @@
>    EmitBlock(new llvm::BasicBlock());
>  }
>
> +/// EmitCaseStmtRange - If case statement range is not too big then
> +/// add multiple cases to switch instruction, one for each value  
> within
> +/// the range. If range is too big then emit "if" condition check.
> +void CodeGenFunction::EmitCaseStmtRange(const CaseStmt &S) {
> +  assert (S.getRHS() && "Unexpected RHS value in CaseStmt");
> +
> +  const Expr *L = S.getLHS();
> +  const Expr *R = S.getRHS();
> +  llvm::ConstantInt *LV = cast<llvm::ConstantInt>(EmitScalarExpr(L));
> +  llvm::ConstantInt *RV = cast<llvm::ConstantInt>(EmitScalarExpr(R));
> +  llvm::APInt LHS = LV->getValue();
> +  llvm::APInt RHS = RV->getValue();

Please capture these with const& instead of copying them.

> ====================================================================== 
> ========
> --- cfe/trunk/CodeGen/CodeGenFunction.h (original)
> +++ cfe/trunk/CodeGen/CodeGenFunction.h Mon Oct  8 15:57:48 2007
> @@ -240,10 +240,14 @@
>    };
>    llvm::SmallVector<BreakContinue, 8> BreakContinueStack;
>
> +  /// SwitchInsn - This is used by EmitCaseStmt() and  
> EmitDefaultStmt() to
> +  /// populate switch instruction
>    llvm::SwitchInst *SwitchInsn;

Instead of saying what this is used for, please say what it is: it is  
the nearest current switch instruction, or null if the current  
context is not in a switch.  Also, please end sentence comments with  
periods. :)

>
> +  /// CaseRangeBlock - This is used, while constructiong swtich  
> instruction,

2 typos 'constructiong swtich'

Thanks Devang,

-Chris



More information about the cfe-commits mailing list