diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2006-11-27 01:05:10 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2006-11-27 01:05:10 +0000 |
commit | 3da59db637a887474c1b1346c1f3ccf53b6c4663 (patch) | |
tree | b061e2133efdb9ea9bb334c1b15ceea881bb88f8 /lib/VMCore/Verifier.cpp | |
parent | 5fed9b90447a9a95a1f670ccd9c23aea8c937451 (diff) | |
download | external_llvm-3da59db637a887474c1b1346c1f3ccf53b6c4663.tar.gz external_llvm-3da59db637a887474c1b1346c1f3ccf53b6c4663.tar.bz2 external_llvm-3da59db637a887474c1b1346c1f3ccf53b6c4663.zip |
For PR950:
The long awaited CAST patch. This introduces 12 new instructions into LLVM
to replace the cast instruction. Corresponding changes throughout LLVM are
provided. This passes llvm-test, llvm/test, and SPEC CPUINT2000 with the
exception of 175.vpr which fails only on a slight floating point output
difference.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31931 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Verifier.cpp')
-rw-r--r-- | lib/VMCore/Verifier.cpp | 175 |
1 files changed, 175 insertions, 0 deletions
diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp index 065ac3b775..d57cd51596 100644 --- a/lib/VMCore/Verifier.cpp +++ b/lib/VMCore/Verifier.cpp @@ -177,6 +177,18 @@ namespace { // Anonymous namespace for class void visitGlobalVariable(GlobalVariable &GV); void visitFunction(Function &F); void visitBasicBlock(BasicBlock &BB); + void visitTruncInst(TruncInst &I); + void visitZExtInst(ZExtInst &I); + void visitSExtInst(SExtInst &I); + void visitFPTruncInst(FPTruncInst &I); + void visitFPExtInst(FPExtInst &I); + void visitFPToUIInst(FPToUIInst &I); + void visitFPToSIInst(FPToSIInst &I); + void visitUIToFPInst(UIToFPInst &I); + void visitSIToFPInst(SIToFPInst &I); + void visitIntToPtrInst(IntToPtrInst &I); + void visitPtrToIntInst(PtrToIntInst &I); + void visitBitCastInst(BitCastInst &I); void visitPHINode(PHINode &PN); void visitBinaryOperator(BinaryOperator &B); void visitICmpInst(ICmpInst &IC); @@ -467,6 +479,169 @@ void Verifier::visitUserOp1(Instruction &I) { Assert1(0, "User-defined operators should not live outside of a pass!", &I); } +void Verifier::visitTruncInst(TruncInst &I) { + // Get the source and destination types + const Type *SrcTy = I.getOperand(0)->getType(); + const Type *DestTy = I.getType(); + + // Get the size of the types in bits, we'll need this later + unsigned SrcBitSize = SrcTy->getPrimitiveSizeInBits(); + unsigned DestBitSize = DestTy->getPrimitiveSizeInBits(); + + Assert1(SrcTy->isIntegral(), "Trunc only operates on integer", &I); + Assert1(DestTy->isIntegral(),"Trunc only produces integral", &I); + Assert1(SrcBitSize > DestBitSize,"DestTy too big for Trunc", &I); + + visitInstruction(I); +} + +void Verifier::visitZExtInst(ZExtInst &I) { + // Get the source and destination types + const Type *SrcTy = I.getOperand(0)->getType(); + const Type *DestTy = I.getType(); + + // Get the size of the types in bits, we'll need this later + unsigned SrcBitSize = SrcTy->getPrimitiveSizeInBits(); + unsigned DestBitSize = DestTy->getPrimitiveSizeInBits(); + + Assert1(SrcTy->isIntegral(),"ZExt only operates on integral", &I); + Assert1(DestTy->isInteger(),"ZExt only produces an integer", &I); + Assert1(SrcBitSize < DestBitSize,"Type too small for ZExt", &I); + + visitInstruction(I); +} + +void Verifier::visitSExtInst(SExtInst &I) { + // Get the source and destination types + const Type *SrcTy = I.getOperand(0)->getType(); + const Type *DestTy = I.getType(); + + // Get the size of the types in bits, we'll need this later + unsigned SrcBitSize = SrcTy->getPrimitiveSizeInBits(); + unsigned DestBitSize = DestTy->getPrimitiveSizeInBits(); + + Assert1(SrcTy->isIntegral(),"SExt only operates on integral", &I); + Assert1(DestTy->isInteger(),"SExt only produces an integer", &I); + Assert1(SrcBitSize < DestBitSize,"Type too small for SExt", &I); + + visitInstruction(I); +} + +void Verifier::visitFPTruncInst(FPTruncInst &I) { + // Get the source and destination types + const Type *SrcTy = I.getOperand(0)->getType(); + const Type *DestTy = I.getType(); + // Get the size of the types in bits, we'll need this later + unsigned SrcBitSize = SrcTy->getPrimitiveSizeInBits(); + unsigned DestBitSize = DestTy->getPrimitiveSizeInBits(); + + Assert1(SrcTy->isFloatingPoint(),"FPTrunc only operates on FP", &I); + Assert1(DestTy->isFloatingPoint(),"FPTrunc only produces an FP", &I); + Assert1(SrcBitSize > DestBitSize,"DestTy too big for FPTrunc", &I); + + visitInstruction(I); +} + +void Verifier::visitFPExtInst(FPExtInst &I) { + // Get the source and destination types + const Type *SrcTy = I.getOperand(0)->getType(); + const Type *DestTy = I.getType(); + + // Get the size of the types in bits, we'll need this later + unsigned SrcBitSize = SrcTy->getPrimitiveSizeInBits(); + unsigned DestBitSize = DestTy->getPrimitiveSizeInBits(); + + Assert1(SrcTy->isFloatingPoint(),"FPExt only operates on FP", &I); + Assert1(DestTy->isFloatingPoint(),"FPExt only produces an FP", &I); + Assert1(SrcBitSize < DestBitSize,"DestTy too small for FPExt", &I); + + visitInstruction(I); +} + +void Verifier::visitUIToFPInst(UIToFPInst &I) { + // Get the source and destination types + const Type *SrcTy = I.getOperand(0)->getType(); + const Type *DestTy = I.getType(); + + Assert1(SrcTy->isIntegral(),"UInt2FP source must be integral", &I); + Assert1(DestTy->isFloatingPoint(),"UInt2FP result must be FP", &I); + + visitInstruction(I); +} + +void Verifier::visitSIToFPInst(SIToFPInst &I) { + // Get the source and destination types + const Type *SrcTy = I.getOperand(0)->getType(); + const Type *DestTy = I.getType(); + + Assert1(SrcTy->isIntegral(),"SInt2FP source must be integral", &I); + Assert1(DestTy->isFloatingPoint(),"SInt2FP result must be FP", &I); + + visitInstruction(I); +} + +void Verifier::visitFPToUIInst(FPToUIInst &I) { + // Get the source and destination types + const Type *SrcTy = I.getOperand(0)->getType(); + const Type *DestTy = I.getType(); + + Assert1(SrcTy->isFloatingPoint(),"FP2UInt source must be FP", &I); + Assert1(DestTy->isIntegral(),"FP2UInt result must be integral", &I); + + visitInstruction(I); +} + +void Verifier::visitFPToSIInst(FPToSIInst &I) { + // Get the source and destination types + const Type *SrcTy = I.getOperand(0)->getType(); + const Type *DestTy = I.getType(); + + Assert1(SrcTy->isFloatingPoint(),"FPToSI source must be FP", &I); + Assert1(DestTy->isIntegral(),"FP2ToI result must be integral", &I); + + visitInstruction(I); +} + +void Verifier::visitPtrToIntInst(PtrToIntInst &I) { + // Get the source and destination types + const Type *SrcTy = I.getOperand(0)->getType(); + const Type *DestTy = I.getType(); + + Assert1(isa<PointerType>(SrcTy), "PtrToInt source must be pointer", &I); + Assert1(DestTy->isIntegral(), "PtrToInt result must be integral", &I); + + visitInstruction(I); +} + +void Verifier::visitIntToPtrInst(IntToPtrInst &I) { + // Get the source and destination types + const Type *SrcTy = I.getOperand(0)->getType(); + const Type *DestTy = I.getType(); + + Assert1(SrcTy->isIntegral(), "IntToPtr source must be an integral", &I); + Assert1(isa<PointerType>(DestTy), "IntToPtr result must be a pointer",&I); + + visitInstruction(I); +} + +void Verifier::visitBitCastInst(BitCastInst &I) { + // Get the source and destination types + const Type *SrcTy = I.getOperand(0)->getType(); + const Type *DestTy = I.getType(); + + // Get the size of the types in bits, we'll need this later + unsigned SrcBitSize = SrcTy->getPrimitiveSizeInBits(); + unsigned DestBitSize = DestTy->getPrimitiveSizeInBits(); + + // BitCast implies a no-op cast of type only. No bits change. + // However, you can't cast pointers to anything but pointers. + Assert1(isa<PointerType>(DestTy) == isa<PointerType>(DestTy), + "Bitcast requires both operands to be pointer or neither", &I); + Assert1(SrcBitSize == DestBitSize, "Bitcast requies types of same width", &I); + + visitInstruction(I); +} + /// visitPHINode - Ensure that a PHI node is well formed. /// void Verifier::visitPHINode(PHINode &PN) { |