summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-09-04 12:08:11 +0000
committerDan Gohman <gohman@apple.com>2009-09-04 12:08:11 +0000
commit0c2477c26b530ad91c44814bf6fbea1c390ae7a6 (patch)
tree2f9468d36d193fc6f5992d72626062de46a8063b /llvm/lib/Bitcode/Reader/BitcodeReader.cpp
parentbc74cae983bc7110e6299f7b3c12a7e6f86e2a2f (diff)
downloadbcm5719-llvm-0c2477c26b530ad91c44814bf6fbea1c390ae7a6.tar.gz
bcm5719-llvm-0c2477c26b530ad91c44814bf6fbea1c390ae7a6.zip
Include optional subclass flags, such as inbounds, nsw, etc., in the
Constant uniquing tables. This allows distinct ConstantExpr objects with the same operation and different flags. Even though a ConstantExpr "a + b" is either always overflowing or never overflowing (due to being a ConstantExpr), it's still necessary to be able to represent it both with and without overflow flags at the same time within the IR, because the safety of the flag may depend on the context of the use. If the constant really does overflow, it wouldn't ever be safe to use with the flag set, however the use may be in code that is never actually executed. This also makes it possible to merge all the flags tests into a single test. llvm-svn: 80998
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp56
1 files changed, 34 insertions, 22 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 9ed75ab1313..05f7b52292d 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -883,19 +883,6 @@ bool BitcodeReader::ResolveGlobalAndAliasInits() {
return false;
}
-static void SetOptimizationFlags(Value *V, uint64_t Flags) {
- if (OverflowingBinaryOperator *OBO =
- dyn_cast<OverflowingBinaryOperator>(V)) {
- if (Flags & (1 << bitc::OBO_NO_SIGNED_WRAP))
- OBO->setHasNoSignedWrap(true);
- if (Flags & (1 << bitc::OBO_NO_UNSIGNED_WRAP))
- OBO->setHasNoUnsignedWrap(true);
- } else if (SDivOperator *Div = dyn_cast<SDivOperator>(V)) {
- if (Flags & (1 << bitc::SDIV_EXACT))
- Div->setIsExact(true);
- }
-}
-
bool BitcodeReader::ParseConstants() {
if (Stream.EnterSubBlock(bitc::CONSTANTS_BLOCK_ID))
return Error("Malformed block record");
@@ -1047,10 +1034,22 @@ bool BitcodeReader::ParseConstants() {
} else {
Constant *LHS = ValueList.getConstantFwdRef(Record[1], CurTy);
Constant *RHS = ValueList.getConstantFwdRef(Record[2], CurTy);
- V = ConstantExpr::get(Opc, LHS, RHS);
+ unsigned Flags = 0;
+ if (Record.size() >= 4) {
+ if (Opc == Instruction::Add ||
+ Opc == Instruction::Sub ||
+ Opc == Instruction::Mul) {
+ if (Record[3] & (1 << bitc::OBO_NO_SIGNED_WRAP))
+ Flags |= OverflowingBinaryOperator::NoSignedWrap;
+ if (Record[3] & (1 << bitc::OBO_NO_UNSIGNED_WRAP))
+ Flags |= OverflowingBinaryOperator::NoUnsignedWrap;
+ } else if (Opc == Instruction::SDiv) {
+ if (Record[3] & (1 << bitc::SDIV_EXACT))
+ Flags |= SDivOperator::IsExact;
+ }
+ }
+ V = ConstantExpr::get(Opc, LHS, RHS, Flags);
}
- if (Record.size() >= 4)
- SetOptimizationFlags(V, Record[3]);
break;
}
case bitc::CST_CODE_CE_CAST: { // CE_CAST: [opcode, opty, opval]
@@ -1075,10 +1074,12 @@ bool BitcodeReader::ParseConstants() {
if (!ElTy) return Error("Invalid CE_GEP record");
Elts.push_back(ValueList.getConstantFwdRef(Record[i+1], ElTy));
}
- V = ConstantExpr::getGetElementPtr(Elts[0], &Elts[1],
- Elts.size()-1);
if (BitCode == bitc::CST_CODE_CE_INBOUNDS_GEP)
- cast<GEPOperator>(V)->setIsInBounds(true);
+ V = ConstantExpr::getInBoundsGetElementPtr(Elts[0], &Elts[1],
+ Elts.size()-1);
+ else
+ V = ConstantExpr::getGetElementPtr(Elts[0], &Elts[1],
+ Elts.size()-1);
break;
}
case bitc::CST_CODE_CE_SELECT: // CE_SELECT: [opval#, opval#, opval#]
@@ -1610,8 +1611,19 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
int Opc = GetDecodedBinaryOpcode(Record[OpNum++], LHS->getType());
if (Opc == -1) return Error("Invalid BINOP record");
I = BinaryOperator::Create((Instruction::BinaryOps)Opc, LHS, RHS);
- if (OpNum < Record.size())
- SetOptimizationFlags(I, Record[3]);
+ if (OpNum < Record.size()) {
+ if (Opc == Instruction::Add ||
+ Opc == Instruction::Sub ||
+ Opc == Instruction::Mul) {
+ if (Record[3] & (1 << bitc::OBO_NO_SIGNED_WRAP))
+ cast<BinaryOperator>(I)->setHasNoSignedWrap(true);
+ if (Record[3] & (1 << bitc::OBO_NO_UNSIGNED_WRAP))
+ cast<BinaryOperator>(I)->setHasNoUnsignedWrap(true);
+ } else if (Opc == Instruction::SDiv) {
+ if (Record[3] & (1 << bitc::SDIV_EXACT))
+ cast<BinaryOperator>(I)->setIsExact(true);
+ }
+ }
break;
}
case bitc::FUNC_CODE_INST_CAST: { // CAST: [opval, opty, destty, castopc]
@@ -1645,7 +1657,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
I = GetElementPtrInst::Create(BasePtr, GEPIdx.begin(), GEPIdx.end());
if (BitCode == bitc::FUNC_CODE_INST_INBOUNDS_GEP)
- cast<GEPOperator>(I)->setIsInBounds(true);
+ cast<GetElementPtrInst>(I)->setIsInBounds(true);
break;
}
OpenPOWER on IntegriCloud