diff options
Diffstat (limited to 'llvm/lib/Target')
-rw-r--r-- | llvm/lib/Target/ARM/ARMAsmPrinter.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp | 37 | ||||
-rw-r--r-- | llvm/lib/Target/NVPTX/NVPTXUtilities.cpp | 7 |
3 files changed, 26 insertions, 22 deletions
diff --git a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp index 90f16f58afc..d3fdbcca2dd 100644 --- a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp +++ b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp @@ -798,7 +798,7 @@ void ARMAsmPrinter::emitAttributes() { if (const Module *SourceModule = MMI->getModule()) { // ABI_PCS_wchar_t to indicate wchar_t width // FIXME: There is no way to emit value 0 (wchar_t prohibited). - if (auto WCharWidthValue = cast_or_null<ConstantInt>( + if (auto WCharWidthValue = mdconst::extract_or_null<ConstantInt>( SourceModule->getModuleFlag("wchar_size"))) { int WCharWidth = WCharWidthValue->getZExtValue(); assert((WCharWidth == 2 || WCharWidth == 4) && @@ -809,7 +809,7 @@ void ARMAsmPrinter::emitAttributes() { // ABI_enum_size to indicate enum width // FIXME: There is no way to emit value 0 (enums prohibited) or value 3 // (all enums contain a value needing 32 bits to encode). - if (auto EnumWidthValue = cast_or_null<ConstantInt>( + if (auto EnumWidthValue = mdconst::extract_or_null<ConstantInt>( SourceModule->getModuleFlag("min_enum_size"))) { int EnumWidth = EnumWidthValue->getZExtValue(); assert((EnumWidth == 1 || EnumWidth == 4) && diff --git a/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp b/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp index 58fa95b54ac..e50f6de01e1 100644 --- a/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp @@ -394,31 +394,34 @@ void GenericToNVVM::remapNamedMDNode(Module *M, NamedMDNode *N) { MDNode *GenericToNVVM::remapMDNode(Module *M, MDNode *N) { bool OperandChanged = false; - SmallVector<Value *, 8> NewOperands; + SmallVector<Metadata *, 8> NewOperands; unsigned NumOperands = N->getNumOperands(); // Check if any operand is or contains a global variable in GVMap, and thus // converted to another value. for (unsigned i = 0; i < NumOperands; ++i) { - Value *Operand = N->getOperand(i); - Value *NewOperand = Operand; + Metadata *Operand = N->getOperand(i); + Metadata *NewOperand = Operand; if (Operand) { - if (isa<GlobalVariable>(Operand)) { - GVMapTy::iterator I = GVMap.find(cast<GlobalVariable>(Operand)); - if (I != GVMap.end()) { - NewOperand = I->second; - if (++i < NumOperands) { - NewOperands.push_back(NewOperand); - // Address space of the global variable follows the global variable - // in the global variable debug info (see createGlobalVariable in - // lib/Analysis/DIBuilder.cpp). - NewOperand = - ConstantInt::get(Type::getInt32Ty(M->getContext()), - I->second->getType()->getAddressSpace()); + if (auto *N = dyn_cast<MDNode>(Operand)) { + NewOperand = remapMDNode(M, N); + } else if (auto *C = dyn_cast<ConstantAsMetadata>(Operand)) { + if (auto *G = dyn_cast<GlobalVariable>(C->getValue())) { + GVMapTy::iterator I = GVMap.find(G); + if (I != GVMap.end()) { + NewOperand = ConstantAsMetadata::get(I->second); + if (++i < NumOperands) { + NewOperands.push_back(NewOperand); + // Address space of the global variable follows the global + // variable + // in the global variable debug info (see createGlobalVariable in + // lib/Analysis/DIBuilder.cpp). + NewOperand = ConstantAsMetadata::get( + ConstantInt::get(Type::getInt32Ty(M->getContext()), + I->second->getType()->getAddressSpace())); + } } } - } else if (isa<MDNode>(Operand)) { - NewOperand = remapMDNode(M, cast<MDNode>(Operand)); } } OperandChanged |= Operand != NewOperand; diff --git a/llvm/lib/Target/NVPTX/NVPTXUtilities.cpp b/llvm/lib/Target/NVPTX/NVPTXUtilities.cpp index 5caa8bd12ca..5d896b46209 100644 --- a/llvm/lib/Target/NVPTX/NVPTXUtilities.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXUtilities.cpp @@ -52,7 +52,7 @@ static void cacheAnnotationFromMD(const MDNode *md, key_val_pair_t &retval) { assert(prop && "Annotation property not a string"); // value - ConstantInt *Val = dyn_cast<ConstantInt>(md->getOperand(i + 1)); + ConstantInt *Val = mdconst::dyn_extract<ConstantInt>(md->getOperand(i + 1)); assert(Val && "Value operand not a constant int"); std::string keyname = prop->getString().str(); @@ -75,7 +75,8 @@ static void cacheAnnotationFromMD(const Module *m, const GlobalValue *gv) { for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) { const MDNode *elem = NMD->getOperand(i); - Value *entity = elem->getOperand(0); + GlobalValue *entity = + mdconst::dyn_extract_or_null<GlobalValue>(elem->getOperand(0)); // entity may be null due to DCE if (!entity) continue; @@ -322,7 +323,7 @@ bool llvm::getAlign(const CallInst &I, unsigned index, unsigned &align) { if (MDNode *alignNode = I.getMetadata("callalign")) { for (int i = 0, n = alignNode->getNumOperands(); i < n; i++) { if (const ConstantInt *CI = - dyn_cast<ConstantInt>(alignNode->getOperand(i))) { + mdconst::dyn_extract<ConstantInt>(alignNode->getOperand(i))) { unsigned v = CI->getZExtValue(); if ((v >> 16) == index) { align = v & 0xFFFF; |