Commit cabfa304 by Jim Stichnoth

Subzero: Render constants in dump() to be more like LLVM.

Integers are generally dumped as signed instead of unsigned values. Integers of i1 type are dumped as 'false' and 'true'. Floating point values still don't match LLVM. BUG= none R=kschimpf@google.com Review URL: https://codereview.chromium.org/539743002
parent 71ba8222
...@@ -103,7 +103,7 @@ public: ...@@ -103,7 +103,7 @@ public:
GV->getName()); GV->getName());
} else if (const ConstantInt *CI = dyn_cast<ConstantInt>(Const)) { } else if (const ConstantInt *CI = dyn_cast<ConstantInt>(Const)) {
return Ctx->getConstantInt(convertToIceType(CI->getType()), return Ctx->getConstantInt(convertToIceType(CI->getType()),
CI->getZExtValue()); CI->getSExtValue());
} else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(Const)) { } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(Const)) {
Ice::Type Type = convertToIceType(CFP->getType()); Ice::Type Type = convertToIceType(CFP->getType());
if (Type == Ice::IceType_f32) if (Type == Ice::IceType_f32)
...@@ -497,7 +497,7 @@ private: ...@@ -497,7 +497,7 @@ private:
unsigned CurrentCase = 0; unsigned CurrentCase = 0;
for (SwitchInst::ConstCaseIt I = Inst->case_begin(), E = Inst->case_end(); for (SwitchInst::ConstCaseIt I = Inst->case_begin(), E = Inst->case_end();
I != E; ++I, ++CurrentCase) { I != E; ++I, ++CurrentCase) {
uint64_t CaseValue = I.getCaseValue()->getZExtValue(); uint64_t CaseValue = I.getCaseValue()->getSExtValue();
Ice::CfgNode *CaseSuccessor = mapBasicBlockToNode(I.getCaseSuccessor()); Ice::CfgNode *CaseSuccessor = mapBasicBlockToNode(I.getCaseSuccessor());
Switch->addBranch(CurrentCase, CaseValue, CaseSuccessor); Switch->addBranch(CurrentCase, CaseValue, CaseSuccessor);
} }
......
...@@ -663,8 +663,8 @@ void InstSwitch::dump(const Cfg *Func) const { ...@@ -663,8 +663,8 @@ void InstSwitch::dump(const Cfg *Func) const {
getSrc(0)->dump(Func); getSrc(0)->dump(Func);
Str << ", label %" << getLabelDefault()->getName() << " [\n"; Str << ", label %" << getLabelDefault()->getName() << " [\n";
for (SizeT I = 0; I < getNumCases(); ++I) { for (SizeT I = 0; I < getNumCases(); ++I) {
Str << " " << Ty << " " << getValue(I) << ", label %" Str << " " << Ty << " " << static_cast<int64_t>(getValue(I))
<< getLabel(I)->getName() << "\n"; << ", label %" << getLabel(I)->getName() << "\n";
} }
Str << " ]"; Str << " ]";
} }
......
...@@ -146,6 +146,14 @@ typedef ConstantPrimitive<uint64_t, Operand::kConstInteger> ConstantInteger; ...@@ -146,6 +146,14 @@ typedef ConstantPrimitive<uint64_t, Operand::kConstInteger> ConstantInteger;
typedef ConstantPrimitive<float, Operand::kConstFloat> ConstantFloat; typedef ConstantPrimitive<float, Operand::kConstFloat> ConstantFloat;
typedef ConstantPrimitive<double, Operand::kConstDouble> ConstantDouble; typedef ConstantPrimitive<double, Operand::kConstDouble> ConstantDouble;
template <> inline void ConstantInteger::dump(GlobalContext *Ctx) const {
Ostream &Str = Ctx->getStrDump();
if (getType() == IceType_i1)
Str << (getValue() ? "true" : "false");
else
Str << static_cast<int64_t>(getValue());
}
// RelocatableTuple bundles the parameters that are used to // RelocatableTuple bundles the parameters that are used to
// construct an ConstantRelocatable. It is done this way so that // construct an ConstantRelocatable. It is done this way so that
// ConstantRelocatable can fit into the global constant pool // ConstantRelocatable can fit into the global constant pool
......
...@@ -3919,6 +3919,7 @@ void TargetX8632::lowerSwitch(const InstSwitch *Inst) { ...@@ -3919,6 +3919,7 @@ void TargetX8632::lowerSwitch(const InstSwitch *Inst) {
else else
Src0 = legalize(Src0, Legal_Reg | Legal_Mem, true); Src0 = legalize(Src0, Legal_Reg | Legal_Mem, true);
for (SizeT I = 0; I < NumCases; ++I) { for (SizeT I = 0; I < NumCases; ++I) {
// TODO(stichnot): Correct lowering for IceType_i64.
Operand *Value = Ctx->getConstantInt(IceType_i32, Inst->getValue(I)); Operand *Value = Ctx->getConstantInt(IceType_i32, Inst->getValue(I));
_cmp(Src0, Value); _cmp(Src0, Value);
_br(InstX8632Br::Br_e, Inst->getLabel(I)); _br(InstX8632Br::Br_e, Inst->getLabel(I));
......
...@@ -72,9 +72,8 @@ if __name__ == '__main__': ...@@ -72,9 +72,8 @@ if __name__ == '__main__':
lines_total = 0 lines_total = 0
lines_diff = 0 lines_diff = 0
ignore_pattern = re.compile( ignore_pattern = re.compile(
'|'.join([' -[0-9]', # negative constants '|'.join(['[ (](float|double) [-0-9]', # FP constants
' (float|double) [-0-9]', # FP constants '[ (](float|double) %\w+, [-0-9]',
' (float|double) %\w+, [-0-9]',
' @llvm\..*i\d+\*', # intrinsic calls w/ pointer args ' @llvm\..*i\d+\*', # intrinsic calls w/ pointer args
' i\d+\* @llvm\.', # intrinsic calls w/ pointer ret ' i\d+\* @llvm\.', # intrinsic calls w/ pointer ret
' inttoptr ', # inttoptr pointer types ' inttoptr ', # inttoptr pointer types
......
...@@ -1159,8 +1159,8 @@ entry: ...@@ -1159,8 +1159,8 @@ entry:
define internal void @store64Const(i32 %a) { define internal void @store64Const(i32 %a) {
entry: entry:
%a.asptr = inttoptr i32 %a to i64* %__1 = inttoptr i32 %a to i64*
store i64 -2401053092306725256, i64* %a.asptr, align 1 store i64 -2401053092306725256, i64* %__1, align 1
ret void ret void
} }
; CHECK-LABEL: store64Const ; CHECK-LABEL: store64Const
......
...@@ -29,7 +29,7 @@ Unequal: ...@@ -29,7 +29,7 @@ Unequal:
define internal i32 @test_br_const() { define internal i32 @test_br_const() {
__0: __0:
br i1 1, label %__1, label %__2 br i1 true, label %__1, label %__2
__1: __1:
ret i32 21 ret i32 21
__2: __2:
......
...@@ -117,7 +117,7 @@ entry: ...@@ -117,7 +117,7 @@ entry:
%dst = inttoptr i32 %iptr_dst to i8* %dst = inttoptr i32 %iptr_dst to i8*
%src = inttoptr i32 %iptr_src to i8* %src = inttoptr i32 %iptr_src to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dst, i8* %src, call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dst, i8* %src,
i32 %len, i32 1, i1 0) i32 %len, i32 1, i1 false)
ret void ret void
} }
; CHECK-LABEL: test_memcpy ; CHECK-LABEL: test_memcpy
...@@ -134,7 +134,7 @@ entry: ...@@ -134,7 +134,7 @@ entry:
%dst = inttoptr i32 %iptr_dst to i8* %dst = inttoptr i32 %iptr_dst to i8*
%src = inttoptr i32 %iptr_src to i8* %src = inttoptr i32 %iptr_src to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dst, i8* %src, call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dst, i8* %src,
i32 8, i32 1, i1 0) i32 8, i32 1, i1 false)
ret void ret void
} }
; CHECK-LABEL: test_memcpy_const_len_align ; CHECK-LABEL: test_memcpy_const_len_align
...@@ -147,7 +147,7 @@ entry: ...@@ -147,7 +147,7 @@ entry:
%dst = inttoptr i32 %iptr_dst to i8* %dst = inttoptr i32 %iptr_dst to i8*
%src = inttoptr i32 %iptr_src to i8* %src = inttoptr i32 %iptr_src to i8*
call void @llvm.memmove.p0i8.p0i8.i32(i8* %dst, i8* %src, call void @llvm.memmove.p0i8.p0i8.i32(i8* %dst, i8* %src,
i32 %len, i32 1, i1 0) i32 %len, i32 1, i1 false)
ret void ret void
} }
; CHECK-LABEL: test_memmove ; CHECK-LABEL: test_memmove
...@@ -160,7 +160,7 @@ entry: ...@@ -160,7 +160,7 @@ entry:
%dst = inttoptr i32 %iptr_dst to i8* %dst = inttoptr i32 %iptr_dst to i8*
%src = inttoptr i32 %iptr_src to i8* %src = inttoptr i32 %iptr_src to i8*
call void @llvm.memmove.p0i8.p0i8.i32(i8* %dst, i8* %src, call void @llvm.memmove.p0i8.p0i8.i32(i8* %dst, i8* %src,
i32 8, i32 1, i1 0) i32 8, i32 1, i1 false)
ret void ret void
} }
; CHECK-LABEL: test_memmove_const_len_align ; CHECK-LABEL: test_memmove_const_len_align
...@@ -173,7 +173,7 @@ entry: ...@@ -173,7 +173,7 @@ entry:
%val = trunc i32 %wide_val to i8 %val = trunc i32 %wide_val to i8
%dst = inttoptr i32 %iptr_dst to i8* %dst = inttoptr i32 %iptr_dst to i8*
call void @llvm.memset.p0i8.i32(i8* %dst, i8 %val, call void @llvm.memset.p0i8.i32(i8* %dst, i8 %val,
i32 %len, i32 1, i1 0) i32 %len, i32 1, i1 false)
ret void ret void
} }
; CHECK-LABEL: test_memset ; CHECK-LABEL: test_memset
...@@ -187,7 +187,7 @@ entry: ...@@ -187,7 +187,7 @@ entry:
%val = trunc i32 %wide_val to i8 %val = trunc i32 %wide_val to i8
%dst = inttoptr i32 %iptr_dst to i8* %dst = inttoptr i32 %iptr_dst to i8*
call void @llvm.memset.p0i8.i32(i8* %dst, i8 %val, call void @llvm.memset.p0i8.i32(i8* %dst, i8 %val,
i32 8, i32 1, i1 0) i32 8, i32 1, i1 false)
ret void ret void
} }
; CHECK-LABEL: test_memset_const_len_align ; CHECK-LABEL: test_memset_const_len_align
...@@ -199,7 +199,7 @@ entry: ...@@ -199,7 +199,7 @@ entry:
define void @test_memset_const_val(i32 %iptr_dst, i32 %len) { define void @test_memset_const_val(i32 %iptr_dst, i32 %len) {
entry: entry:
%dst = inttoptr i32 %iptr_dst to i8* %dst = inttoptr i32 %iptr_dst to i8*
call void @llvm.memset.p0i8.i32(i8* %dst, i8 0, i32 %len, i32 1, i1 0) call void @llvm.memset.p0i8.i32(i8* %dst, i8 0, i32 %len, i32 1, i1 false)
ret void ret void
} }
; CHECK-LABEL: test_memset_const_val ; CHECK-LABEL: test_memset_const_val
...@@ -350,7 +350,7 @@ entry: ...@@ -350,7 +350,7 @@ entry:
define i32 @test_ctlz_32(i32 %x) { define i32 @test_ctlz_32(i32 %x) {
entry: entry:
%r = call i32 @llvm.ctlz.i32(i32 %x, i1 0) %r = call i32 @llvm.ctlz.i32(i32 %x, i1 false)
ret i32 %r ret i32 %r
} }
; CHECK-LABEL: test_ctlz_32 ; CHECK-LABEL: test_ctlz_32
...@@ -364,7 +364,7 @@ entry: ...@@ -364,7 +364,7 @@ entry:
define i32 @test_ctlz_32_const() { define i32 @test_ctlz_32_const() {
entry: entry:
%r = call i32 @llvm.ctlz.i32(i32 123456, i1 0) %r = call i32 @llvm.ctlz.i32(i32 123456, i1 false)
ret i32 %r ret i32 %r
} }
; Could potentially constant fold this, but the front-end should have done that. ; Could potentially constant fold this, but the front-end should have done that.
...@@ -375,7 +375,7 @@ entry: ...@@ -375,7 +375,7 @@ entry:
define i32 @test_ctlz_32_ignored(i32 %x) { define i32 @test_ctlz_32_ignored(i32 %x) {
entry: entry:
%ignored = call i32 @llvm.ctlz.i32(i32 %x, i1 0) %ignored = call i32 @llvm.ctlz.i32(i32 %x, i1 false)
ret i32 1 ret i32 1
} }
; CHECKO2REM-LABEL: test_ctlz_32_ignored ; CHECKO2REM-LABEL: test_ctlz_32_ignored
...@@ -383,7 +383,7 @@ entry: ...@@ -383,7 +383,7 @@ entry:
define i64 @test_ctlz_64(i64 %x) { define i64 @test_ctlz_64(i64 %x) {
entry: entry:
%r = call i64 @llvm.ctlz.i64(i64 %x, i1 0) %r = call i64 @llvm.ctlz.i64(i64 %x, i1 false)
ret i64 %r ret i64 %r
} }
; CHECKO2REM-LABEL: test_ctlz_64 ; CHECKO2REM-LABEL: test_ctlz_64
...@@ -401,7 +401,7 @@ entry: ...@@ -401,7 +401,7 @@ entry:
define i32 @test_ctlz_64_const(i64 %x) { define i32 @test_ctlz_64_const(i64 %x) {
entry: entry:
%r = call i64 @llvm.ctlz.i64(i64 123456789012, i1 0) %r = call i64 @llvm.ctlz.i64(i64 123456789012, i1 false)
%r2 = trunc i64 %r to i32 %r2 = trunc i64 %r to i32
ret i32 %r2 ret i32 %r2
} }
...@@ -412,7 +412,7 @@ entry: ...@@ -412,7 +412,7 @@ entry:
define i32 @test_ctlz_64_ignored(i64 %x) { define i32 @test_ctlz_64_ignored(i64 %x) {
entry: entry:
%ignored = call i64 @llvm.ctlz.i64(i64 1234567890, i1 0) %ignored = call i64 @llvm.ctlz.i64(i64 1234567890, i1 false)
ret i32 2 ret i32 2
} }
; CHECKO2REM-LABEL: test_ctlz_64_ignored ; CHECKO2REM-LABEL: test_ctlz_64_ignored
...@@ -420,7 +420,7 @@ entry: ...@@ -420,7 +420,7 @@ entry:
define i32 @test_cttz_32(i32 %x) { define i32 @test_cttz_32(i32 %x) {
entry: entry:
%r = call i32 @llvm.cttz.i32(i32 %x, i1 0) %r = call i32 @llvm.cttz.i32(i32 %x, i1 false)
ret i32 %r ret i32 %r
} }
; CHECK-LABEL: test_cttz_32 ; CHECK-LABEL: test_cttz_32
...@@ -430,7 +430,7 @@ entry: ...@@ -430,7 +430,7 @@ entry:
define i64 @test_cttz_64(i64 %x) { define i64 @test_cttz_64(i64 %x) {
entry: entry:
%r = call i64 @llvm.cttz.i64(i64 %x, i1 0) %r = call i64 @llvm.cttz.i64(i64 %x, i1 false)
ret i64 %r ret i64 %r
} }
; CHECK-LABEL: test_cttz_64 ; CHECK-LABEL: test_cttz_64
......
...@@ -46,7 +46,7 @@ declare void @useIntHelper(i32) ...@@ -46,7 +46,7 @@ declare void @useIntHelper(i32)
; operand is an immediate. ; operand is an immediate.
define i32 @testSelectImm32(i32 %a, i32 %b) { define i32 @testSelectImm32(i32 %a, i32 %b) {
entry: entry:
%cond = select i1 0, i32 %a, i32 %b %cond = select i1 false, i32 %a, i32 %b
ret i32 %cond ret i32 %cond
} }
; CHECK-LABEL: testSelectImm32 ; CHECK-LABEL: testSelectImm32
...@@ -57,7 +57,7 @@ entry: ...@@ -57,7 +57,7 @@ entry:
; sequence for 64-bit operands. ; sequence for 64-bit operands.
define i64 @testSelectImm64(i64 %a, i64 %b) { define i64 @testSelectImm64(i64 %a, i64 %b) {
entry: entry:
%cond = select i1 1, i64 %a, i64 %b %cond = select i1 true, i64 %a, i64 %b
ret i64 %cond ret i64 %cond
} }
; CHECK-LABEL: testSelectImm64 ; CHECK-LABEL: testSelectImm64
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment