Index: docs/LangRef.rst =================================================================== --- docs/LangRef.rst +++ docs/LangRef.rst @@ -2168,6 +2168,26 @@ label +.. _t_token: + +Token Type +^^^^^^^^^^ + +:Overview: + +The token type is used when a value is associated with an instruction +but all uses of the value must not attempt to introspect or obscure it. +As such, it is not appropriate to have a :ref:`phi ` or +:ref:`select ` of type token. + +:Syntax: + +:: + + token + + + .. _t_metadata: Metadata Type Index: include/llvm-c/Core.h =================================================================== --- include/llvm-c/Core.h +++ include/llvm-c/Core.h @@ -274,7 +274,8 @@ LLVMPointerTypeKind, /**< Pointers */ LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */ LLVMMetadataTypeKind, /**< Metadata */ - LLVMX86_MMXTypeKind /**< X86 MMX */ + LLVMX86_MMXTypeKind, /**< X86 MMX */ + LLVMTokenTypeKind /**< Tokens */ } LLVMTypeKind; typedef enum { Index: include/llvm/Bitcode/LLVMBitCodes.h =================================================================== --- include/llvm/Bitcode/LLVMBitCodes.h +++ include/llvm/Bitcode/LLVMBitCodes.h @@ -121,7 +121,9 @@ TYPE_CODE_STRUCT_NAME = 19, // STRUCT_NAME: [strchr x N] TYPE_CODE_STRUCT_NAMED = 20,// STRUCT_NAMED: [ispacked, eltty x N] - TYPE_CODE_FUNCTION = 21 // FUNCTION: [vararg, retty, paramty x N] + TYPE_CODE_FUNCTION = 21, // FUNCTION: [vararg, retty, paramty x N] + + TYPE_CODE_TOKEN = 22 // TOKEN }; // The type symbol table only has one code (TST_ENTRY_CODE). Index: include/llvm/IR/Type.h =================================================================== --- include/llvm/IR/Type.h +++ include/llvm/IR/Type.h @@ -63,15 +63,16 @@ LabelTyID, ///< 7: Labels MetadataTyID, ///< 8: Metadata X86_MMXTyID, ///< 9: MMX vectors (64 bits, X86 specific) + TokenTyID, ///< 10: Tokens // Derived types... see DerivedTypes.h file. // Make sure FirstDerivedTyID stays up to date! - IntegerTyID, ///< 10: Arbitrary bit width integers - FunctionTyID, ///< 11: Functions - StructTyID, ///< 12: Structures - ArrayTyID, ///< 13: Arrays - PointerTyID, ///< 14: Pointers - VectorTyID ///< 15: SIMD 'packed' format, or other vector type + IntegerTyID, ///< 11: Arbitrary bit width integers + FunctionTyID, ///< 12: Functions + StructTyID, ///< 13: Structures + ArrayTyID, ///< 14: Arrays + PointerTyID, ///< 15: Pointers + VectorTyID ///< 16: SIMD 'packed' format, or other vector type }; private: @@ -178,6 +179,9 @@ /// isMetadataTy - Return true if this is 'metadata'. bool isMetadataTy() const { return getTypeID() == MetadataTyID; } + /// isTokenTy - Return true if this is 'token'. + bool isTokenTy() const { return getTypeID() == TokenTyID; } + /// isIntegerTy - True if this is an instance of IntegerType. /// bool isIntegerTy() const { return getTypeID() == IntegerTyID; } @@ -378,6 +382,7 @@ static Type *getFP128Ty(LLVMContext &C); static Type *getPPC_FP128Ty(LLVMContext &C); static Type *getX86_MMXTy(LLVMContext &C); + static Type *getTokenTy(LLVMContext &C); static IntegerType *getIntNTy(LLVMContext &C, unsigned N); static IntegerType *getInt1Ty(LLVMContext &C); static IntegerType *getInt8Ty(LLVMContext &C); Index: lib/Analysis/CodeMetrics.cpp =================================================================== --- lib/Analysis/CodeMetrics.cpp +++ lib/Analysis/CodeMetrics.cpp @@ -155,6 +155,9 @@ if (isa(II) || II->getType()->isVectorTy()) ++NumVectorInsts; + if (II->getType()->isTokenTy()) + notDuplicatable = true; + if (const CallInst *CI = dyn_cast(II)) if (CI->cannotDuplicate()) notDuplicatable = true; Index: lib/Analysis/LoopInfo.cpp =================================================================== --- lib/Analysis/LoopInfo.cpp +++ lib/Analysis/LoopInfo.cpp @@ -208,6 +208,9 @@ // Return false if any loop blocks contain indirectbrs, or there are any calls // to noduplicate functions. for (Loop::block_iterator I = block_begin(), E = block_end(); I != E; ++I) { + if ((*I)->getType()->isTokenTy()) + return false; + if (isa((*I)->getTerminator())) return false; Index: lib/AsmParser/LLLexer.cpp =================================================================== --- lib/AsmParser/LLLexer.cpp +++ lib/AsmParser/LLLexer.cpp @@ -691,6 +691,7 @@ TYPEKEYWORD("label", Type::getLabelTy(Context)); TYPEKEYWORD("metadata", Type::getMetadataTy(Context)); TYPEKEYWORD("x86_mmx", Type::getX86_MMXTy(Context)); + TYPEKEYWORD("token", Type::getTokenTy(Context)); #undef TYPEKEYWORD // Keywords for instructions. Index: lib/Bitcode/Reader/BitcodeReader.cpp =================================================================== --- lib/Bitcode/Reader/BitcodeReader.cpp +++ lib/Bitcode/Reader/BitcodeReader.cpp @@ -1360,6 +1360,9 @@ case bitc::TYPE_CODE_X86_MMX: // X86_MMX ResultTy = Type::getX86_MMXTy(Context); break; + case bitc::TYPE_CODE_TOKEN: // TOKEN + ResultTy = Type::getTokenTy(Context); + break; case bitc::TYPE_CODE_INTEGER: { // INTEGER: [width] if (Record.size() < 1) return error("Invalid record"); Index: lib/Bitcode/Writer/BitcodeWriter.cpp =================================================================== --- lib/Bitcode/Writer/BitcodeWriter.cpp +++ lib/Bitcode/Writer/BitcodeWriter.cpp @@ -405,6 +405,7 @@ case Type::LabelTyID: Code = bitc::TYPE_CODE_LABEL; break; case Type::MetadataTyID: Code = bitc::TYPE_CODE_METADATA; break; case Type::X86_MMXTyID: Code = bitc::TYPE_CODE_X86_MMX; break; + case Type::TokenTyID: Code = bitc::TYPE_CODE_TOKEN; break; case Type::IntegerTyID: // INTEGER: [width] Code = bitc::TYPE_CODE_INTEGER; Index: lib/IR/AsmWriter.cpp =================================================================== --- lib/IR/AsmWriter.cpp +++ lib/IR/AsmWriter.cpp @@ -467,6 +467,7 @@ case Type::LabelTyID: OS << "label"; return; case Type::MetadataTyID: OS << "metadata"; return; case Type::X86_MMXTyID: OS << "x86_mmx"; return; + case Type::TokenTyID: OS << "token"; return; case Type::IntegerTyID: OS << 'i' << cast(Ty)->getBitWidth(); return; Index: lib/IR/Core.cpp =================================================================== --- lib/IR/Core.cpp +++ lib/IR/Core.cpp @@ -262,6 +262,8 @@ return LLVMVectorTypeKind; case Type::X86_MMXTyID: return LLVMX86_MMXTypeKind; + case Type::TokenTyID: + return LLVMTokenTypeKind; } llvm_unreachable("Unhandled TypeID."); } @@ -366,6 +368,9 @@ LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C) { return (LLVMTypeRef) Type::getX86_MMXTy(*unwrap(C)); } +LLVMTypeRef LLVMTokenTypeInContext(LLVMContextRef C) { + return (LLVMTypeRef) Type::getTokenTy(*unwrap(C)); +} LLVMTypeRef LLVMHalfType(void) { return LLVMHalfTypeInContext(LLVMGetGlobalContext()); Index: lib/IR/Instructions.cpp =================================================================== --- lib/IR/Instructions.cpp +++ lib/IR/Instructions.cpp @@ -62,7 +62,10 @@ const char *SelectInst::areInvalidOperands(Value *Op0, Value *Op1, Value *Op2) { if (Op1->getType() != Op2->getType()) return "both values to select must have same type"; - + + if (Op1->getType()->isTokenTy()) + return "select values cannot have token type"; + if (VectorType *VT = dyn_cast(Op0->getType())) { // Vector select. if (VT->getElementType() != Type::getInt1Ty(Op0->getContext())) Index: lib/IR/LLVMContextImpl.h =================================================================== --- lib/IR/LLVMContextImpl.h +++ lib/IR/LLVMContextImpl.h @@ -928,7 +928,7 @@ ConstantInt *TheFalseVal; // Basic type instances. - Type VoidTy, LabelTy, HalfTy, FloatTy, DoubleTy, MetadataTy; + Type VoidTy, LabelTy, HalfTy, FloatTy, DoubleTy, MetadataTy, TokenTy; Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy; IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty, Int128Ty; Index: lib/IR/LLVMContextImpl.cpp =================================================================== --- lib/IR/LLVMContextImpl.cpp +++ lib/IR/LLVMContextImpl.cpp @@ -27,6 +27,7 @@ FloatTy(C, Type::FloatTyID), DoubleTy(C, Type::DoubleTyID), MetadataTy(C, Type::MetadataTyID), + TokenTy(C, Type::TokenTyID), X86_FP80Ty(C, Type::X86_FP80TyID), FP128Ty(C, Type::FP128TyID), PPC_FP128Ty(C, Type::PPC_FP128TyID), Index: lib/IR/Type.cpp =================================================================== --- lib/IR/Type.cpp +++ lib/IR/Type.cpp @@ -35,6 +35,7 @@ case LabelTyID : return getLabelTy(C); case MetadataTyID : return getMetadataTy(C); case X86_MMXTyID : return getX86_MMXTy(C); + case TokenTyID : return getTokenTy(C); default: return nullptr; } @@ -220,6 +221,7 @@ Type *Type::getFloatTy(LLVMContext &C) { return &C.pImpl->FloatTy; } Type *Type::getDoubleTy(LLVMContext &C) { return &C.pImpl->DoubleTy; } Type *Type::getMetadataTy(LLVMContext &C) { return &C.pImpl->MetadataTy; } +Type *Type::getTokenTy(LLVMContext &C) { return &C.pImpl->TokenTy; } Type *Type::getX86_FP80Ty(LLVMContext &C) { return &C.pImpl->X86_FP80Ty; } Type *Type::getFP128Ty(LLVMContext &C) { return &C.pImpl->FP128Ty; } Type *Type::getPPC_FP128Ty(LLVMContext &C) { return &C.pImpl->PPC_FP128Ty; } @@ -596,7 +598,8 @@ bool StructType::isValidElementType(Type *ElemTy) { return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() && - !ElemTy->isMetadataTy() && !ElemTy->isFunctionTy(); + !ElemTy->isMetadataTy() && !ElemTy->isFunctionTy() && + !ElemTy->isTokenTy(); } /// isLayoutIdentical - Return true if this is layout identical to the @@ -691,7 +694,8 @@ bool ArrayType::isValidElementType(Type *ElemTy) { return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() && - !ElemTy->isMetadataTy() && !ElemTy->isFunctionTy(); + !ElemTy->isMetadataTy() && !ElemTy->isFunctionTy() && + !ElemTy->isTokenTy(); } //===----------------------------------------------------------------------===// @@ -759,7 +763,7 @@ bool PointerType::isValidElementType(Type *ElemTy) { return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() && - !ElemTy->isMetadataTy(); + !ElemTy->isMetadataTy() && !ElemTy->isTokenTy(); } bool PointerType::isLoadableOrStorableType(Type *ElemTy) { Index: lib/IR/Verifier.cpp =================================================================== --- lib/IR/Verifier.cpp +++ lib/IR/Verifier.cpp @@ -2189,6 +2189,9 @@ isa(--BasicBlock::iterator(&PN)), "PHI nodes not grouped at top of basic block!", &PN, PN.getParent()); + // Check that a PHI doesn't yield a Token. + Assert(!PN.getType()->isTokenTy(), "PHI nodes cannot have token type!"); + // Check that all of the values of the PHI node have the same type as the // result, and that the incoming blocks are really basic blocks. for (Value *IncValue : PN.incoming_values()) { Index: lib/Target/CppBackend/CPPBackend.cpp =================================================================== --- lib/Target/CppBackend/CPPBackend.cpp +++ lib/Target/CppBackend/CPPBackend.cpp @@ -551,7 +551,8 @@ void CppWriter::printType(Type* Ty) { // We don't print definitions for primitive types if (Ty->isFloatingPointTy() || Ty->isX86_MMXTy() || Ty->isIntegerTy() || - Ty->isLabelTy() || Ty->isMetadataTy() || Ty->isVoidTy()) + Ty->isLabelTy() || Ty->isMetadataTy() || Ty->isVoidTy() || + Ty->isTokenTy()) return; // If we already defined this type, we don't need to define it again. Index: lib/Transforms/IPO/MergeFunctions.cpp =================================================================== --- lib/Transforms/IPO/MergeFunctions.cpp +++ lib/Transforms/IPO/MergeFunctions.cpp @@ -654,6 +654,7 @@ case Type::PPC_FP128TyID: case Type::LabelTyID: case Type::MetadataTyID: + case Type::TokenTyID: return 0; case Type::PointerTyID: { Index: lib/Transforms/Scalar/JumpThreading.cpp =================================================================== --- lib/Transforms/Scalar/JumpThreading.cpp +++ lib/Transforms/Scalar/JumpThreading.cpp @@ -260,6 +260,11 @@ if (isa(I) && I->getType()->isPointerTy()) continue; + // Bail out if this instruction gives back a token type, it is not possible + // to duplicate it. + if (I->getType()->isTokenTy()) + return ~0U; + // All other instructions count for at least one unit. ++Size; Index: lib/Transforms/Utils/InlineFunction.cpp =================================================================== --- lib/Transforms/Utils/InlineFunction.cpp +++ lib/Transforms/Utils/InlineFunction.cpp @@ -337,14 +337,8 @@ TPI->eraseFromParent(); UpdatePHINodes(BB); } - } else if (auto *CPI = dyn_cast(I)) { - if (CPI->getNumOperands() == 0) { - CleanupPadInst::Create(CPI->getType(), {UnwindDest}, CPI->getName(), - CPI); - CPI->eraseFromParent(); - } } else { - assert(isa(I)); + assert(isa(I) || isa(I)); } } Index: lib/Transforms/Utils/SimplifyCFG.cpp =================================================================== --- lib/Transforms/Utils/SimplifyCFG.cpp +++ lib/Transforms/Utils/SimplifyCFG.cpp @@ -1639,8 +1639,11 @@ /// \returns True if this block contains a CallInst with the NoDuplicate /// attribute. -static bool HasNoDuplicateCall(const BasicBlock *BB) { +static bool BlockCannotBeDuplicated(const BasicBlock *BB) { for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I) { + if (I->getType()->isTokenTy()) + return true; + const CallInst *CI = dyn_cast(I); if (!CI) continue; @@ -1694,7 +1697,7 @@ // Now we know that this block has multiple preds and two succs. if (!BlockIsSimpleEnoughToThreadThrough(BB)) return false; - if (HasNoDuplicateCall(BB)) return false; + if (BlockCannotBeDuplicated(BB)) return false; // Okay, this is a simple enough basic block. See if any phi values are // constants. Index: test/Assembler/token.ll =================================================================== --- /dev/null +++ test/Assembler/token.ll @@ -0,0 +1,10 @@ +; RUN: llvm-as < %s | llvm-dis | FileCheck %s +; RUN: verify-uselistorder %s +; Basic smoke test for token type. + +; CHECK: define void @sh16(token +define void @sh16(token %A) { +entry: + ret void +; CHECK: ret void +} Index: test/Verifier/token1.ll =================================================================== --- /dev/null +++ test/Verifier/token1.ll @@ -0,0 +1,11 @@ +; RUN: not llvm-as %s -o /dev/null 2>&1 | FileCheck %s + +define void @f(token %A, token %B) { +entry: + br label %bb + +bb: + %phi = phi token [ %A, %bb ], [ %B, %entry] +; CHECK: PHI nodes cannot have token type! + br label %bb +} Index: test/Verifier/token2.ll =================================================================== --- /dev/null +++ test/Verifier/token2.ll @@ -0,0 +1,11 @@ +; RUN: not llvm-as %s -o /dev/null 2>&1 | FileCheck %s + +define void @f(token %A, token %B) { +entry: + br label %bb + +bb: + %sel = select i1 undef, token %A, token %B +; CHECK: select values cannot have token type + br label %bb +} Index: test/Verifier/token3.ll =================================================================== --- /dev/null +++ test/Verifier/token3.ll @@ -0,0 +1,8 @@ +; RUN: not llvm-as %s -o /dev/null 2>&1 | FileCheck %s + +define void @f(token %A, token %B) { +entry: + alloca token +; CHECK: invalid type for alloca + ret void +} Index: test/Verifier/token4.ll =================================================================== --- /dev/null +++ test/Verifier/token4.ll @@ -0,0 +1,4 @@ +; RUN: not llvm-as %s -o /dev/null 2>&1 | FileCheck %s + +@GV = external global token +; CHECK: invalid type for global variable