[cfe-commits] r42766 - in /cfe/trunk: CodeGen/CGStmt.cpp CodeGen/CodeGenFunction.cpp CodeGen/CodeGenFunction.h test/CodeGen/switch.c
Devang Patel
dpatel at apple.com
Tue Oct 9 10:12:13 PDT 2007
On Oct 8, 2007, at 8:03 PM, Chris Lattner wrote:
>> URL: http://llvm.org/viewvc/llvm-project?rev=42766&view=rev
>> Log:
>> Code gen case statement ranges.
>
> Nice!
Thanks!
>> +++ 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.
Now RHS is const&. However LHS is still a copied value because it is
incremented.
>
>
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =====================================================================
>> --- 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. :)
fixed.
>
>
>>
>> + /// CaseRangeBlock - This is used, while constructiong swtich
>> instruction,
>
> 2 typos 'constructiong swtich'
fixed.
-
Devang
More information about the cfe-commits
mailing list