LLVM API Documentation
00001 //===-- InstrinsicInst.cpp - Intrinsic Instruction Wrappers -----*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by James M. Laskey and is distributed under 00006 // the University of Illinois Open Source 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 with the isa/dyncast family of functions. In particular, this 00012 // allows you to do things like: 00013 // 00014 // if (DbgStopPointInst *SPI = dyn_cast<DbgStopPointInst>(Inst)) 00015 // ... SPI->getFileName() ... SPI->getDirectory() ... 00016 // 00017 // All intrinsic function calls are instances of the call instruction, so these 00018 // are all subclasses of the CallInst class. Note that none of these classes 00019 // has state or virtual methods, which is an important part of this gross/neat 00020 // hack working. 00021 // 00022 // In some cases, arguments to intrinsics need to be generic and are defined as 00023 // type pointer to empty struct { }*. To access the real item of interest the 00024 // cast instruction needs to be stripped away. 00025 // 00026 //===----------------------------------------------------------------------===// 00027 00028 #include "llvm/IntrinsicInst.h" 00029 00030 #include "llvm/Constants.h" 00031 #include "llvm/GlobalVariable.h" 00032 #include "llvm/CodeGen/MachineDebugInfo.h" 00033 00034 using namespace llvm; 00035 00036 //===----------------------------------------------------------------------===// 00037 /// DbgInfoIntrinsic - This is the common base class for debug info intrinsics 00038 /// 00039 00040 static Value *CastOperand(Value *C) { 00041 if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) 00042 if (CE->getOpcode() == Instruction::Cast) 00043 return CE->getOperand(0); 00044 return NULL; 00045 } 00046 00047 Value *DbgInfoIntrinsic::StripCast(Value *C) { 00048 if (Value *CO = CastOperand(C)) { 00049 C = StripCast(CO); 00050 } else if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) { 00051 if (GV->hasInitializer()) 00052 if (Value *CO = CastOperand(GV->getInitializer())) 00053 C = StripCast(CO); 00054 } 00055 return dyn_cast<GlobalVariable>(C); 00056 } 00057 00058 //===----------------------------------------------------------------------===// 00059 /// DbgStopPointInst - This represents the llvm.dbg.stoppoint instruction. 00060 /// 00061 00062 std::string DbgStopPointInst::getFileName() const { 00063 // Once the operand indices are verified, update this assert 00064 assert(LLVMDebugVersion == (5 << 16) && "Verify operand indices"); 00065 GlobalVariable *GV = cast<GlobalVariable>(getContext()); 00066 ConstantStruct *CS = cast<ConstantStruct>(GV->getInitializer()); 00067 return CS->getOperand(3)->getStringValue(); 00068 } 00069 00070 std::string DbgStopPointInst::getDirectory() const { 00071 // Once the operand indices are verified, update this assert 00072 assert(LLVMDebugVersion == (5 << 16) && "Verify operand indices"); 00073 GlobalVariable *GV = cast<GlobalVariable>(getContext()); 00074 ConstantStruct *CS = cast<ConstantStruct>(GV->getInitializer()); 00075 return CS->getOperand(4)->getStringValue(); 00076 } 00077 00078 //===----------------------------------------------------------------------===// 00079 /// Ensure that users of IntrinsicInst.h will link with this module. 00080 DEFINING_FILE_FOR(IntrinsicInst)