diff options
Diffstat (limited to 'llvm/lib/IR')
-rw-r--r-- | llvm/lib/IR/AsmWriter.cpp | 26 | ||||
-rw-r--r-- | llvm/lib/IR/Core.cpp | 8 | ||||
-rw-r--r-- | llvm/lib/IR/DIBuilder.cpp | 15 | ||||
-rw-r--r-- | llvm/lib/IR/Instructions.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/IR/IntrinsicInst.cpp | 67 | ||||
-rw-r--r-- | llvm/lib/IR/Operator.cpp | 21 | ||||
-rw-r--r-- | llvm/lib/IR/PassTimingInfo.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/IR/SafepointIRVerifier.cpp | 6 | ||||
-rw-r--r-- | llvm/lib/IR/Verifier.cpp | 31 |
9 files changed, 105 insertions, 73 deletions
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp index 7734c0a8de58..c9748e1387eb 100644 --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -353,12 +353,11 @@ void llvm::printLLVMNameWithoutPrefix(raw_ostream &OS, StringRef Name) { // Scan the name to see if it needs quotes first. bool NeedsQuotes = isdigit(static_cast<unsigned char>(Name[0])); if (!NeedsQuotes) { - for (unsigned i = 0, e = Name.size(); i != e; ++i) { + for (unsigned char C : Name) { // By making this unsigned, the value passed in to isalnum will always be // in the range 0-255. This is important when building with MSVC because // its implementation will assert. This situation can arise when dealing // with UTF-8 multibyte characters. - unsigned char C = Name[i]; if (!isalnum(static_cast<unsigned char>(C)) && C != '-' && C != '.' && C != '_') { NeedsQuotes = true; @@ -1309,27 +1308,8 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Metadata *MD, bool FromValue = false); static void WriteOptimizationInfo(raw_ostream &Out, const User *U) { - if (const FPMathOperator *FPO = dyn_cast<const FPMathOperator>(U)) { - // 'Fast' is an abbreviation for all fast-math-flags. - if (FPO->isFast()) - Out << " fast"; - else { - if (FPO->hasAllowReassoc()) - Out << " reassoc"; - if (FPO->hasNoNaNs()) - Out << " nnan"; - if (FPO->hasNoInfs()) - Out << " ninf"; - if (FPO->hasNoSignedZeros()) - Out << " nsz"; - if (FPO->hasAllowReciprocal()) - Out << " arcp"; - if (FPO->hasAllowContract()) - Out << " contract"; - if (FPO->hasApproxFunc()) - Out << " afn"; - } - } + if (const FPMathOperator *FPO = dyn_cast<const FPMathOperator>(U)) + Out << FPO->getFastMathFlags(); if (const OverflowingBinaryOperator *OBO = dyn_cast<OverflowingBinaryOperator>(U)) { diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp index 905372982dc2..2c396ae97499 100644 --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -2266,6 +2266,14 @@ LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee, unwrap<Constant>(Aliasee), unwrap(M))); } +LLVMValueRef LLVMAddAlias2(LLVMModuleRef M, LLVMTypeRef ValueTy, + unsigned AddrSpace, LLVMValueRef Aliasee, + const char *Name) { + return wrap(GlobalAlias::create(unwrap(ValueTy), AddrSpace, + GlobalValue::ExternalLinkage, Name, + unwrap<Constant>(Aliasee), unwrap(M))); +} + LLVMValueRef LLVMGetNamedGlobalAlias(LLVMModuleRef M, const char *Name, size_t NameLen) { return wrap(unwrap(M)->getNamedAlias(Name)); diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp index ca7dafc814ce..548962bd6a98 100644 --- a/llvm/lib/IR/DIBuilder.cpp +++ b/llvm/lib/IR/DIBuilder.cpp @@ -34,7 +34,20 @@ static cl::opt<bool> DIBuilder::DIBuilder(Module &m, bool AllowUnresolvedNodes, DICompileUnit *CU) : M(m), VMContext(M.getContext()), CUNode(CU), DeclareFn(nullptr), ValueFn(nullptr), LabelFn(nullptr), - AllowUnresolvedNodes(AllowUnresolvedNodes) {} + AllowUnresolvedNodes(AllowUnresolvedNodes) { + if (CUNode) { + if (const auto &ETs = CUNode->getEnumTypes()) + AllEnumTypes.assign(ETs.begin(), ETs.end()); + if (const auto &RTs = CUNode->getRetainedTypes()) + AllRetainTypes.assign(RTs.begin(), RTs.end()); + if (const auto &GVs = CUNode->getGlobalVariables()) + AllGVs.assign(GVs.begin(), GVs.end()); + if (const auto &IMs = CUNode->getImportedEntities()) + AllImportedModules.assign(IMs.begin(), IMs.end()); + if (const auto &MNs = CUNode->getMacros()) + AllMacrosPerParent.insert({nullptr, {MNs.begin(), MNs.end()}}); + } +} void DIBuilder::trackIfUnresolved(MDNode *N) { if (!N) diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp index c42df49d97ea..ad27a6d8c08e 100644 --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -2474,7 +2474,7 @@ bool ShuffleVectorInst::isReplicationMask(ArrayRef<int> Mask, // Additionally, mask size is a replication factor multiplied by vector size, // which further significantly reduces the search space. - // Before doing that, let's perform basic sanity check first. + // Before doing that, let's perform basic correctness checking first. int Largest = -1; for (int MaskElt : Mask) { if (MaskElt == UndefMaskElem) diff --git a/llvm/lib/IR/IntrinsicInst.cpp b/llvm/lib/IR/IntrinsicInst.cpp index 7552906fd07a..9206cd37a6d1 100644 --- a/llvm/lib/IR/IntrinsicInst.cpp +++ b/llvm/lib/IR/IntrinsicInst.cpp @@ -358,13 +358,13 @@ Value *VPIntrinsic::getMemoryPointerParam() const { Optional<unsigned> VPIntrinsic::getMemoryPointerParamPos(Intrinsic::ID VPID) { switch (VPID) { default: - return None; - -#define HANDLE_VP_IS_MEMOP(VPID, POINTERPOS, DATAPOS) \ - case Intrinsic::VPID: \ - return POINTERPOS; + break; +#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID: +#define VP_PROPERTY_MEMOP(POINTERPOS, ...) return POINTERPOS; +#define END_REGISTER_VP_INTRINSIC(VPID) break; #include "llvm/IR/VPIntrinsics.def" } + return None; } /// \return The data (payload) operand of this store or scatter. @@ -378,52 +378,51 @@ Value *VPIntrinsic::getMemoryDataParam() const { Optional<unsigned> VPIntrinsic::getMemoryDataParamPos(Intrinsic::ID VPID) { switch (VPID) { default: - return None; - -#define HANDLE_VP_IS_MEMOP(VPID, POINTERPOS, DATAPOS) \ - case Intrinsic::VPID: \ - return DATAPOS; + break; +#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID: +#define VP_PROPERTY_MEMOP(POINTERPOS, DATAPOS) return DATAPOS; +#define END_REGISTER_VP_INTRINSIC(VPID) break; #include "llvm/IR/VPIntrinsics.def" } + return None; } bool VPIntrinsic::isVPIntrinsic(Intrinsic::ID ID) { switch (ID) { default: - return false; - + break; #define BEGIN_REGISTER_VP_INTRINSIC(VPID, MASKPOS, VLENPOS) \ case Intrinsic::VPID: \ - break; + return true; #include "llvm/IR/VPIntrinsics.def" } - return true; + return false; } // Equivalent non-predicated opcode Optional<unsigned> VPIntrinsic::getFunctionalOpcodeForVP(Intrinsic::ID ID) { - Optional<unsigned> FunctionalOC; switch (ID) { default: break; #define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID: -#define HANDLE_VP_TO_OPC(OPC) FunctionalOC = Instruction::OPC; -#define END_REGISTER_VP_INTRINSIC(...) break; +#define VP_PROPERTY_FUNCTIONAL_OPC(OPC) return Instruction::OPC; +#define END_REGISTER_VP_INTRINSIC(VPID) break; #include "llvm/IR/VPIntrinsics.def" } - - return FunctionalOC; + return None; } Intrinsic::ID VPIntrinsic::getForOpcode(unsigned IROPC) { switch (IROPC) { default: - return Intrinsic::not_intrinsic; + break; -#define HANDLE_VP_TO_OPC(OPC) case Instruction::OPC: +#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) break; +#define VP_PROPERTY_FUNCTIONAL_OPC(OPC) case Instruction::OPC: #define END_REGISTER_VP_INTRINSIC(VPID) return Intrinsic::VPID; #include "llvm/IR/VPIntrinsics.def" } + return Intrinsic::not_intrinsic; } bool VPIntrinsic::canIgnoreVectorLengthParam() const { @@ -516,13 +515,13 @@ Function *VPIntrinsic::getDeclarationForParams(Module *M, Intrinsic::ID VPID, bool VPReductionIntrinsic::isVPReduction(Intrinsic::ID ID) { switch (ID) { default: - return false; -#define HANDLE_VP_REDUCTION(VPID, STARTPOS, VECTORPOS) \ - case Intrinsic::VPID: \ break; +#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID: +#define VP_PROPERTY_REDUCTION(STARTPOS, ...) return true; +#define END_REGISTER_VP_INTRINSIC(VPID) break; #include "llvm/IR/VPIntrinsics.def" } - return true; + return false; } unsigned VPReductionIntrinsic::getVectorParamPos() const { @@ -535,24 +534,26 @@ unsigned VPReductionIntrinsic::getStartParamPos() const { Optional<unsigned> VPReductionIntrinsic::getVectorParamPos(Intrinsic::ID ID) { switch (ID) { -#define HANDLE_VP_REDUCTION(VPID, STARTPOS, VECTORPOS) \ - case Intrinsic::VPID: \ - return VECTORPOS; +#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID: +#define VP_PROPERTY_REDUCTION(STARTPOS, VECTORPOS) return VECTORPOS; +#define END_REGISTER_VP_INTRINSIC(VPID) break; #include "llvm/IR/VPIntrinsics.def" default: - return None; + break; } + return None; } Optional<unsigned> VPReductionIntrinsic::getStartParamPos(Intrinsic::ID ID) { switch (ID) { -#define HANDLE_VP_REDUCTION(VPID, STARTPOS, VECTORPOS) \ - case Intrinsic::VPID: \ - return STARTPOS; +#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID: +#define VP_PROPERTY_REDUCTION(STARTPOS, VECTORPOS) return STARTPOS; +#define END_REGISTER_VP_INTRINSIC(VPID) break; #include "llvm/IR/VPIntrinsics.def" default: - return None; + break; } + return None; } Instruction::BinaryOps BinaryOpIntrinsic::getBinaryOp() const { diff --git a/llvm/lib/IR/Operator.cpp b/llvm/lib/IR/Operator.cpp index cf309ffd6212..d15fcfbc5b9f 100644 --- a/llvm/lib/IR/Operator.cpp +++ b/llvm/lib/IR/Operator.cpp @@ -226,4 +226,25 @@ bool GEPOperator::collectOffset( } return true; } + +void FastMathFlags::print(raw_ostream &O) const { + if (all()) + O << " fast"; + else { + if (allowReassoc()) + O << " reassoc"; + if (noNaNs()) + O << " nnan"; + if (noInfs()) + O << " ninf"; + if (noSignedZeros()) + O << " nsz"; + if (allowReciprocal()) + O << " arcp"; + if (allowContract()) + O << " contract"; + if (approxFunc()) + O << " afn"; + } +} } // namespace llvm diff --git a/llvm/lib/IR/PassTimingInfo.cpp b/llvm/lib/IR/PassTimingInfo.cpp index d0c1517f480b..a03fafec9fac 100644 --- a/llvm/lib/IR/PassTimingInfo.cpp +++ b/llvm/lib/IR/PassTimingInfo.cpp @@ -187,7 +187,7 @@ Timer &TimePassesHandler::getPassTimer(StringRef PassID) { Timer *T = new Timer(PassID, FullDesc, TG); Timers.emplace_back(T); - assert(Count == Timers.size() && "sanity check"); + assert(Count == Timers.size() && "Timers vector not adjusted correctly."); return *T; } diff --git a/llvm/lib/IR/SafepointIRVerifier.cpp b/llvm/lib/IR/SafepointIRVerifier.cpp index 9be6de693ee3..2117527a64f0 100644 --- a/llvm/lib/IR/SafepointIRVerifier.cpp +++ b/llvm/lib/IR/SafepointIRVerifier.cpp @@ -6,9 +6,9 @@ // //===----------------------------------------------------------------------===// // -// Run a sanity check on the IR to ensure that Safepoints - if they've been -// inserted - were inserted correctly. In particular, look for use of -// non-relocated values after a safepoint. It's primary use is to check the +// Run a basic correctness check on the IR to ensure that Safepoints - if +// they've been inserted - were inserted correctly. In particular, look for use +// of non-relocated values after a safepoint. It's primary use is to check the // correctness of safepoint insertion immediately after insertion, but it can // also be used to verify that later transforms have not found a way to break // safepoint semenatics. diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index dc4370d4b6ed..154b59835b01 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// // // This file defines the function verifier interface, that can be used for some -// sanity checking of input to the system. +// basic correctness checking of input to the system. // // Note that this does not provide full `Java style' security and verifications, // instead it just tries to ensure that code is well-formed. @@ -1604,7 +1604,7 @@ Verifier::visitModuleFlag(const MDNode *Op, Assert(ID, "invalid ID operand in module flag (expected metadata string)", Op->getOperand(1)); - // Sanity check the values for behaviors with additional requirements. + // Check the values for behaviors with additional requirements. switch (MFB) { case Module::Error: case Module::Warning: @@ -5269,24 +5269,32 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) { Op0ElemTy = cast<VectorType>(Call.getArgOperand(0)->getType())->getElementType(); break; - case Intrinsic::matrix_column_major_load: + case Intrinsic::matrix_column_major_load: { Stride = dyn_cast<ConstantInt>(Call.getArgOperand(1)); NumRows = cast<ConstantInt>(Call.getArgOperand(3)); NumColumns = cast<ConstantInt>(Call.getArgOperand(4)); ResultTy = cast<VectorType>(Call.getType()); - Op0ElemTy = - cast<PointerType>(Call.getArgOperand(0)->getType())->getElementType(); + + PointerType *Op0PtrTy = + cast<PointerType>(Call.getArgOperand(0)->getType()); + if (!Op0PtrTy->isOpaque()) + Op0ElemTy = Op0PtrTy->getElementType(); break; - case Intrinsic::matrix_column_major_store: + } + case Intrinsic::matrix_column_major_store: { Stride = dyn_cast<ConstantInt>(Call.getArgOperand(2)); NumRows = cast<ConstantInt>(Call.getArgOperand(4)); NumColumns = cast<ConstantInt>(Call.getArgOperand(5)); ResultTy = cast<VectorType>(Call.getArgOperand(0)->getType()); Op0ElemTy = cast<VectorType>(Call.getArgOperand(0)->getType())->getElementType(); - Op1ElemTy = - cast<PointerType>(Call.getArgOperand(1)->getType())->getElementType(); + + PointerType *Op1PtrTy = + cast<PointerType>(Call.getArgOperand(1)->getType()); + if (!Op1PtrTy->isOpaque()) + Op1ElemTy = Op1PtrTy->getElementType(); break; + } default: llvm_unreachable("unexpected intrinsic"); } @@ -5295,9 +5303,10 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) { ResultTy->getElementType()->isFloatingPointTy(), "Result type must be an integer or floating-point type!", IF); - Assert(ResultTy->getElementType() == Op0ElemTy, - "Vector element type mismatch of the result and first operand " - "vector!", IF); + if (Op0ElemTy) + Assert(ResultTy->getElementType() == Op0ElemTy, + "Vector element type mismatch of the result and first operand " + "vector!", IF); if (Op1ElemTy) Assert(ResultTy->getElementType() == Op1ElemTy, |