llvm.org GIT mirror llvm / 99b648a
Merge from mainline. git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_23@51869 91177308-0d34-0410-b5e6-96231b3b80d8 Tanya Lattner 12 years ago
2 changed file(s) with 60 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
154154
155155 void writeOperand(Value *Operand);
156156 void writeOperandRaw(Value *Operand);
157 void writeInstComputationInline(Instruction &I);
157158 void writeOperandInternal(Value *Operand);
158159 void writeOperandWithCast(Value* Operand, unsigned Opcode);
159160 void writeOperandWithCast(Value* Operand, const ICmpInst &I);
12161217 return Name;
12171218 }
12181219
1220 /// writeInstComputationInline - Emit the computation for the specified
1221 /// instruction inline, with no destination provided.
1222 void CWriter::writeInstComputationInline(Instruction &I) {
1223 // If this is a non-trivial bool computation, make sure to truncate down to
1224 // a 1 bit value. This is important because we want "add i1 x, y" to return
1225 // "0" when x and y are true, not "2" for example.
1226 bool NeedBoolTrunc = false;
1227 if (I.getType() == Type::Int1Ty && !isa(I) && !isa(I))
1228 NeedBoolTrunc = true;
1229
1230 if (NeedBoolTrunc)
1231 Out << "((";
1232
1233 visit(I);
1234
1235 if (NeedBoolTrunc)
1236 Out << ")&1)";
1237 }
1238
1239
12191240 void CWriter::writeOperandInternal(Value *Operand) {
12201241 if (Instruction *I = dyn_cast(Operand))
1242 // Should we inline this instruction to build a tree?
12211243 if (isInlinableInst(*I) && !isDirectAlloca(I)) {
1222 // Should we inline this instruction to build a tree?
12231244 Out << '(';
1224 visit(*I);
1245 writeInstComputationInline(*I);
12251246 Out << ')';
12261247 return;
12271248 }
21452166 outputLValue(II);
21462167 else
21472168 Out << " ";
2148 visit(*II);
2169 writeInstComputationInline(*II);
21492170 Out << ";\n";
21502171 }
21512172 }
21522173
2153 // Don't emit prefix or suffix for the terminator...
2174 // Don't emit prefix or suffix for the terminator.
21542175 visit(*BB->getTerminator());
21552176 }
21562177
24742495 void CWriter::visitCastInst(CastInst &I) {
24752496 const Type *DstTy = I.getType();
24762497 const Type *SrcTy = I.getOperand(0)->getType();
2477 Out << '(';
24782498 if (isFPIntBitCast(I)) {
2499 Out << '(';
24792500 // These int<->float and long<->double casts need to be handled specially
24802501 Out << GetValueName(&I) << "__BITCAST_TEMPORARY."
24812502 << getFloatBitCastField(I.getOperand(0)->getType()) << " = ";
24822503 writeOperand(I.getOperand(0));
24832504 Out << ", " << GetValueName(&I) << "__BITCAST_TEMPORARY."
24842505 << getFloatBitCastField(I.getType());
2485 } else {
2486 printCast(I.getOpcode(), SrcTy, DstTy);
2487 if (I.getOpcode() == Instruction::SExt && SrcTy == Type::Int1Ty) {
2488 // Make sure we really get a sext from bool by subtracing the bool from 0
2489 Out << "0-";
2490 }
2491 writeOperand(I.getOperand(0));
2492 if (DstTy == Type::Int1Ty &&
2493 (I.getOpcode() == Instruction::Trunc ||
2494 I.getOpcode() == Instruction::FPToUI ||
2495 I.getOpcode() == Instruction::FPToSI ||
2496 I.getOpcode() == Instruction::PtrToInt)) {
2497 // Make sure we really get a trunc to bool by anding the operand with 1
2498 Out << "&1u";
2499 }
2506 Out << ')';
2507 return;
2508 }
2509
2510 Out << '(';
2511 printCast(I.getOpcode(), SrcTy, DstTy);
2512
2513 // Make a sext from i1 work by subtracting the i1 from 0 (an int).
2514 if (SrcTy == Type::Int1Ty && I.getOpcode() == Instruction::SExt)
2515 Out << "0-";
2516
2517 writeOperand(I.getOperand(0));
2518
2519 if (DstTy == Type::Int1Ty &&
2520 (I.getOpcode() == Instruction::Trunc ||
2521 I.getOpcode() == Instruction::FPToUI ||
2522 I.getOpcode() == Instruction::FPToSI ||
2523 I.getOpcode() == Instruction::PtrToInt)) {
2524 // Make sure we really get a trunc to bool by anding the operand with 1
2525 Out << "&1u";
25002526 }
25012527 Out << ')';
25022528 }
0 ; RUN: llvm-as < %s | llc -march=c | grep {llvm_cbe_t.*&1}
1 define i32 @test(i32 %r) {
2 %s = icmp eq i32 %r, 0
3 %t = add i1 %s, %s
4 %u = zext i1 %t to i32
5 br i1 %t, label %A, label %B
6 A:
7
8 ret i32 %u
9 B:
10
11 %v = select i1 %t, i32 %r, i32 %u
12 ret i32 %v
13 }