LLVM API Documentation
00001 //===-- InstrinsicInst.cpp - Intrinsic Instruction Wrappers ---------------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file implements methods that make it really easy to deal with intrinsic 00011 // functions. 00012 // 00013 // All intrinsic function calls are instances of the call instruction, so these 00014 // are all subclasses of the CallInst class. Note that none of these classes 00015 // has state or virtual methods, which is an important part of this gross/neat 00016 // hack working. 00017 // 00018 // In some cases, arguments to intrinsics need to be generic and are defined as 00019 // type pointer to empty struct { }*. To access the real item of interest the 00020 // cast instruction needs to be stripped away. 00021 // 00022 //===----------------------------------------------------------------------===// 00023 00024 #include "llvm/IR/IntrinsicInst.h" 00025 #include "llvm/IR/Constants.h" 00026 #include "llvm/IR/GlobalVariable.h" 00027 #include "llvm/IR/Metadata.h" 00028 using namespace llvm; 00029 00030 //===----------------------------------------------------------------------===// 00031 /// DbgInfoIntrinsic - This is the common base class for debug info intrinsics 00032 /// 00033 00034 static Value *CastOperand(Value *C) { 00035 if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) 00036 if (CE->isCast()) 00037 return CE->getOperand(0); 00038 return nullptr; 00039 } 00040 00041 Value *DbgInfoIntrinsic::StripCast(Value *C) { 00042 if (Value *CO = CastOperand(C)) { 00043 C = StripCast(CO); 00044 } else if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) { 00045 if (GV->hasInitializer()) 00046 if (Value *CO = CastOperand(GV->getInitializer())) 00047 C = StripCast(CO); 00048 } 00049 return dyn_cast<GlobalVariable>(C); 00050 } 00051 00052 //===----------------------------------------------------------------------===// 00053 /// DbgDeclareInst - This represents the llvm.dbg.declare instruction. 00054 /// 00055 00056 Value *DbgDeclareInst::getAddress() const { 00057 if (MDNode* MD = cast_or_null<MDNode>(getArgOperand(0))) 00058 return MD->getOperand(0); 00059 else 00060 return nullptr; 00061 } 00062 00063 //===----------------------------------------------------------------------===// 00064 /// DbgValueInst - This represents the llvm.dbg.value instruction. 00065 /// 00066 00067 const Value *DbgValueInst::getValue() const { 00068 return cast<MDNode>(getArgOperand(0))->getOperand(0); 00069 } 00070 00071 Value *DbgValueInst::getValue() { 00072 return cast<MDNode>(getArgOperand(0))->getOperand(0); 00073 }