aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
diff options
context:
space:
mode:
authoraqjune <aqjune@gmail.com>2019-11-07 01:17:49 +0900
committeraqjune <aqjune@gmail.com>2019-11-12 10:49:00 +0900
commite87d71668e10f51abe4b2f1f3c44591aca783750 (patch)
treec33db0298cc2ef75a9c7fd30bf082f6e150c527a /llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
parentc46b3a2abd38d6fecd389c97dfa7df54af77fdb9 (diff)
downloadllvm-e87d71668e10f51abe4b2f1f3c44591aca783750.zip
llvm-e87d71668e10f51abe4b2f1f3c44591aca783750.tar.gz
llvm-e87d71668e10f51abe4b2f1f3c44591aca783750.tar.bz2
[IR] Redefine Freeze instruction
Summary: This patch redefines freeze instruction from being UnaryOperator to a subclass of UnaryInstruction. ConstantExpr freeze is removed, as discussed in the previous review. FreezeOperator is not added because there's no ConstantExpr freeze. `freeze i8* null` test is added to `test/Bindings/llvm-c/freeze.ll` as well, because the null pointer-related bug in `tools/llvm-c/echo.cpp` is now fixed. InstVisitor has visitFreeze now because freeze is not unaryop anymore. Reviewers: whitequark, deadalnix, craig.topper, jdoerfert, lebedev.ri Reviewed By: craig.topper, lebedev.ri Subscribers: regehr, nlopes, mehdi_amini, hiraditya, steven_wu, dexonsmith, jfb, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D69932
Diffstat (limited to 'llvm/lib/Bitcode/Writer/BitcodeWriter.cpp')
-rw-r--r--llvm/lib/Bitcode/Writer/BitcodeWriter.cpp50
1 files changed, 27 insertions, 23 deletions
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index c3531a7..6defe3a 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -521,7 +521,6 @@ static unsigned getEncodedUnaryOpcode(unsigned Opcode) {
switch (Opcode) {
default: llvm_unreachable("Unknown binary instruction!");
case Instruction::FNeg: return bitc::UNOP_FNEG;
- case Instruction::Freeze: return bitc::UNOP_FREEZE;
}
}
@@ -2435,17 +2434,6 @@ void ModuleBitcodeWriter::writeConstants(unsigned FirstVal, unsigned LastVal,
Record.push_back(VE.getTypeID(C->getOperand(0)->getType()));
Record.push_back(VE.getValueID(C->getOperand(0)));
AbbrevToUse = CONSTANTS_CE_CAST_Abbrev;
- } else if (Instruction::isUnaryOp(CE->getOpcode())) {
- assert(CE->getNumOperands() == 1 && "Unknown constant expr!");
- Code = bitc::CST_CODE_CE_UNOP;
- Record.push_back(getEncodedUnaryOpcode(CE->getOpcode()));
- Record.push_back(VE.getValueID(C->getOperand(0)));
- uint64_t Flags = getOptimizationFlags(CE);
- if (Flags != 0) {
- assert(CE->getOpcode() == Instruction::FNeg);
- Record.push_back(Flags);
- }
- break;
} else {
assert(CE->getNumOperands() == 2 && "Unknown constant expr!");
Code = bitc::CST_CODE_CE_BINOP;
@@ -2457,6 +2445,16 @@ void ModuleBitcodeWriter::writeConstants(unsigned FirstVal, unsigned LastVal,
Record.push_back(Flags);
}
break;
+ case Instruction::FNeg: {
+ assert(CE->getNumOperands() == 1 && "Unknown constant expr!");
+ Code = bitc::CST_CODE_CE_UNOP;
+ Record.push_back(getEncodedUnaryOpcode(CE->getOpcode()));
+ Record.push_back(VE.getValueID(C->getOperand(0)));
+ uint64_t Flags = getOptimizationFlags(CE);
+ if (Flags != 0)
+ Record.push_back(Flags);
+ break;
+ }
case Instruction::GetElementPtr: {
Code = bitc::CST_CODE_CE_GEP;
const auto *GO = cast<GEPOperator>(C);
@@ -2614,17 +2612,6 @@ void ModuleBitcodeWriter::writeInstruction(const Instruction &I,
AbbrevToUse = FUNCTION_INST_CAST_ABBREV;
Vals.push_back(VE.getTypeID(I.getType()));
Vals.push_back(getEncodedCastOpcode(I.getOpcode()));
- } else if (isa<UnaryOperator>(I)) {
- Code = bitc::FUNC_CODE_INST_UNOP;
- if (!pushValueAndType(I.getOperand(0), InstID, Vals))
- AbbrevToUse = FUNCTION_INST_UNOP_ABBREV;
- Vals.push_back(getEncodedUnaryOpcode(I.getOpcode()));
- uint64_t Flags = getOptimizationFlags(&I);
- if (Flags != 0) {
- if (AbbrevToUse == FUNCTION_INST_UNOP_ABBREV)
- AbbrevToUse = FUNCTION_INST_UNOP_FLAGS_ABBREV;
- Vals.push_back(Flags);
- }
} else {
assert(isa<BinaryOperator>(I) && "Unknown instruction!");
Code = bitc::FUNC_CODE_INST_BINOP;
@@ -2640,6 +2627,19 @@ void ModuleBitcodeWriter::writeInstruction(const Instruction &I,
}
}
break;
+ case Instruction::FNeg: {
+ Code = bitc::FUNC_CODE_INST_UNOP;
+ if (!pushValueAndType(I.getOperand(0), InstID, Vals))
+ AbbrevToUse = FUNCTION_INST_UNOP_ABBREV;
+ Vals.push_back(getEncodedUnaryOpcode(I.getOpcode()));
+ uint64_t Flags = getOptimizationFlags(&I);
+ if (Flags != 0) {
+ if (AbbrevToUse == FUNCTION_INST_UNOP_ABBREV)
+ AbbrevToUse = FUNCTION_INST_UNOP_FLAGS_ABBREV;
+ Vals.push_back(Flags);
+ }
+ break;
+ }
case Instruction::GetElementPtr: {
Code = bitc::FUNC_CODE_INST_GEP;
AbbrevToUse = FUNCTION_INST_GEP_ABBREV;
@@ -3034,6 +3034,10 @@ void ModuleBitcodeWriter::writeInstruction(const Instruction &I,
pushValue(I.getOperand(0), InstID, Vals); // valist.
Vals.push_back(VE.getTypeID(I.getType())); // restype.
break;
+ case Instruction::Freeze:
+ Code = bitc::FUNC_CODE_INST_FREEZE;
+ pushValueAndType(I.getOperand(0), InstID, Vals);
+ break;
}
Stream.EmitRecord(Code, Vals, AbbrevToUse);