Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

- #25

Closed
wants to merge 1 commit into from
Closed

- #25

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion include/llvm-c/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ typedef enum {
LLVMCatchRet = 62,
LLVMCatchPad = 63,
LLVMCleanupPad = 64,
LLVMCatchSwitch = 65
LLVMCatchSwitch = 65,

/* Undef Handling Operators */
LLVMFreeze = 66
} LLVMOpcode;

typedef enum {
Expand Down
1 change: 1 addition & 0 deletions include/llvm/Bitcode/LLVMBitCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ enum FunctionCodes {
// 53 is unused.
// 54 is unused.
FUNC_CODE_OPERAND_BUNDLE = 55, // OPERAND_BUNDLE: [tag#, value...]
FUNC_CODE_INST_FREEZE = 56, // FREEZE: [opty, opval]
};

enum UseListCodes {
Expand Down
1 change: 1 addition & 0 deletions include/llvm/IR/InstVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ class InstVisitor {
RetTy visitFuncletPadInst(FuncletPadInst &I) { DELEGATE(Instruction); }
RetTy visitCleanupPadInst(CleanupPadInst &I) { DELEGATE(FuncletPadInst); }
RetTy visitCatchPadInst(CatchPadInst &I) { DELEGATE(FuncletPadInst); }
RetTy visitFreezeInst(FreezeInst &I) { DELEGATE(Instruction); }

// Handle the special instrinsic instruction classes.
RetTy visitDbgDeclareInst(DbgDeclareInst &I) { DELEGATE(DbgInfoIntrinsic);}
Expand Down
3 changes: 2 additions & 1 deletion include/llvm/IR/Instruction.def
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ HANDLE_OTHER_INST(61, ShuffleVector, ShuffleVectorInst) // shuffle two vectors.
HANDLE_OTHER_INST(62, ExtractValue, ExtractValueInst)// extract from aggregate
HANDLE_OTHER_INST(63, InsertValue, InsertValueInst) // insert into aggregate
HANDLE_OTHER_INST(64, LandingPad, LandingPadInst) // Landing pad instruction.
LAST_OTHER_INST(64)
HANDLE_OTHER_INST(65, Freeze, FreezeInst) // Freeze instruction.
LAST_OTHER_INST(65)

#undef FIRST_TERM_INST
#undef HANDLE_TERM_INST
Expand Down
36 changes: 36 additions & 0 deletions include/llvm/IR/Instructions.h
Original file line number Diff line number Diff line change
Expand Up @@ -4891,6 +4891,42 @@ class AddrSpaceCastInst : public CastInst {
}
};

//===----------------------------------------------------------------------===//
// FreezeInst Class
//===----------------------------------------------------------------------===//

/// \brief This class represents a freeze function that returns
/// random concrete value if an operand is an undefine value
class FreezeInst : public UnaryInstruction {
protected:
// Note: Instruction needs to be a friend here to call cloneImpl.
friend class Instruction;
/// \brief Clone an identical FreezeInst
FreezeInst *cloneImpl() const;

public:
/// \brief Constructor with insert-before-instruction semantics
FreezeInst(
Value *S, ///< The value to freeze
const Twine &NameStr = "", ///< A name for the new instruction
Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
);

/// \brief Constructor with insert-at-end-of-block semantics
FreezeInst(
Value *S, ///< The value to freeze
const Twine &NameStr, ///< A name for the new instruction
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
);

// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const Instruction *I) {
return I->getOpcode() == Freeze;
}
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};
} // End llvm namespace

#endif
2 changes: 2 additions & 0 deletions lib/AsmParser/LLLexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,8 @@ lltok::Kind LLLexer::LexIdentifier() {
INSTKEYWORD(catchswitch, CatchSwitch);
INSTKEYWORD(catchpad, CatchPad);
INSTKEYWORD(cleanuppad, CleanupPad);

INSTKEYWORD(freeze, Freeze);
#undef INSTKEYWORD

#define DWKEYWORD(TYPE, TOKEN) \
Expand Down
13 changes: 13 additions & 0 deletions lib/AsmParser/LLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4988,6 +4988,7 @@ int LLParser::ParseInstruction(Instruction *&Inst, BasicBlock *BB,
case lltok::kw_shufflevector: return ParseShuffleVector(Inst, PFS);
case lltok::kw_phi: return ParsePHI(Inst, PFS);
case lltok::kw_landingpad: return ParseLandingPad(Inst, PFS);
case lltok::kw_freeze: return ParseFreeze(Inst, PFS);
// Call.
case lltok::kw_call: return ParseCall(Inst, PFS, CallInst::TCK_None);
case lltok::kw_tail: return ParseCall(Inst, PFS, CallInst::TCK_Tail);
Expand Down Expand Up @@ -5788,6 +5789,18 @@ bool LLParser::ParseLandingPad(Instruction *&Inst, PerFunctionState &PFS) {
return false;
}

/// ParseFreeze
/// ::= 'freeze' Type Value
bool LLParser::ParseFreeze(Instruction *&Inst, PerFunctionState &PFS) {
LocTy Loc;
Value *Op;
if (ParseTypeAndValue(Op, Loc, PFS))
return true;

Inst = new FreezeInst(Op, "");
return false;
}

/// ParseCall
/// ::= 'call' OptionalFastMathFlags OptionalCallingConv
/// OptionalAttrs Type Value ParameterList OptionalAttrs
Expand Down
1 change: 1 addition & 0 deletions lib/AsmParser/LLParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ namespace llvm {
int ParseGetElementPtr(Instruction *&I, PerFunctionState &PFS);
int ParseExtractValue(Instruction *&I, PerFunctionState &PFS);
int ParseInsertValue(Instruction *&I, PerFunctionState &PFS);
bool ParseFreeze(Instruction *&I, PerFunctionState &PFS);

// Use-list order directives.
bool ParseUseListOrder(PerFunctionState *PFS = nullptr);
Expand Down
2 changes: 2 additions & 0 deletions lib/AsmParser/LLToken.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ enum Kind {
kw_insertvalue,
kw_blockaddress,

kw_freeze,

// Metadata types.
kw_distinct,

Expand Down
13 changes: 13 additions & 0 deletions lib/Bitcode/Reader/BitcodeReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5492,6 +5492,19 @@ std::error_code BitcodeReader::parseFunctionBody(Function *F) {
OperandBundles.emplace_back(BundleTags[Record[0]], std::move(Inputs));
continue;
}

case bitc::FUNC_CODE_INST_FREEZE: { // FREEZE: [opty,opval]
unsigned OpNum = 0;
Value *Op = nullptr;
if (getValueTypePair(Record, OpNum, NextValueNo, Op))
return error("Invalid record");
if (OpNum != Record.size())
return error("Invalid record");

I = new FreezeInst(Op, "");
InstructionList.push_back(I);
break;
}
}

// Add instruction to end of current BB. If there is no current BB, reject
Expand Down
4 changes: 4 additions & 0 deletions lib/Bitcode/Writer/BitcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2639,6 +2639,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);
Expand Down
4 changes: 4 additions & 0 deletions lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9110,3 +9110,7 @@ void SelectionDAGBuilder::visitSwitch(const SwitchInst &SI) {
lowerWorkItem(W, SI.getCondition(), SwitchMBB, DefaultMBB);
}
}

void SelectionDAGBuilder::visitFreeze(const FreezeInst &I) {
assert(false && "SelectionDAGBuilder::visitFreeze Not Implemented");
}
1 change: 1 addition & 0 deletions lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,7 @@ class SelectionDAGBuilder {
void visitAtomicStore(const StoreInst &I);
void visitLoadFromSwiftError(const LoadInst &I);
void visitStoreToSwiftError(const StoreInst &I);
void visitFreeze(const FreezeInst &I);

void visitInlineAsm(ImmutableCallSite CS);
const char *visitIntrinsicCall(const CallInst &I, unsigned Intrinsic);
Expand Down
1 change: 1 addition & 0 deletions lib/IR/Instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ const char *Instruction::getOpcodeName(unsigned OpCode) {
case InsertValue: return "insertvalue";
case LandingPad: return "landingpad";
case CleanupPad: return "cleanuppad";
case Freeze: return "freeze";

default: return "<Invalid operator> ";
}
Expand Down
20 changes: 20 additions & 0 deletions lib/IR/Instructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3814,6 +3814,22 @@ void IndirectBrInst::setSuccessorV(unsigned idx, BasicBlock *B) {
setSuccessor(idx, B);
}

//===----------------------------------------------------------------------===//
// FreezeInst Implementation
//===----------------------------------------------------------------------===//

FreezeInst::FreezeInst(Value *S,
const Twine &Name, Instruction *InsertBefore)
: UnaryInstruction(S->getType(), Freeze, S, InsertBefore) {
setName(Name);
}

FreezeInst::FreezeInst(Value *S,
const Twine &Name, BasicBlock *InsertAtEnd)
: UnaryInstruction(S->getType(), Freeze, S, InsertAtEnd) {
setName(Name);
}

//===----------------------------------------------------------------------===//
// cloneImpl() implementations
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -4016,3 +4032,7 @@ UnreachableInst *UnreachableInst::cloneImpl() const {
LLVMContext &Context = getContext();
return new UnreachableInst(Context);
}

FreezeInst *FreezeInst::cloneImpl() const {
return new FreezeInst(getOperand(0));
}