1 //===-- InstrinsicInst.cpp - Intrinsic Instruction Wrappers -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements methods that make it really easy to deal with intrinsic
11 // functions with the isa/dyncast family of functions. In particular, this
12 // allows you to do things like:
14 // if (DbgStopPointInst *SPI = dyn_cast<DbgStopPointInst>(Inst))
15 // ... SPI->getFileName() ... SPI->getDirectory() ...
17 // All intrinsic function calls are instances of the call instruction, so these
18 // are all subclasses of the CallInst class. Note that none of these classes
19 // has state or virtual methods, which is an important part of this gross/neat
22 // In some cases, arguments to intrinsics need to be generic and are defined as
23 // type pointer to empty struct { }*. To access the real item of interest the
24 // cast instruction needs to be stripped away.
26 //===----------------------------------------------------------------------===//
28 #include "llvm/IntrinsicInst.h"
29 #include "llvm/Constants.h"
30 #include "llvm/GlobalVariable.h"
31 #include "llvm/Analysis/ValueTracking.h"
32 #include "llvm/CodeGen/MachineDebugInfoDesc.h"
33 #include "llvm/CodeGen/MachineModuleInfo.h"
36 //===----------------------------------------------------------------------===//
37 /// DbgInfoIntrinsic - This is the common base class for debug info intrinsics
40 static Value *CastOperand(Value *C) {
41 if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C))
43 return CE->getOperand(0);
47 Value *DbgInfoIntrinsic::StripCast(Value *C) {
48 if (Value *CO = CastOperand(C)) {
50 } else if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) {
51 if (GV->hasInitializer())
52 if (Value *CO = CastOperand(GV->getInitializer()))
55 return dyn_cast<GlobalVariable>(C);
58 //===----------------------------------------------------------------------===//
59 /// DbgStopPointInst - This represents the llvm.dbg.stoppoint instruction.
62 Value *DbgStopPointInst::getFileName() const {
63 // Once the operand indices are verified, update this assert
64 assert(LLVMDebugVersion == (6 << 16) && "Verify operand indices");
65 GlobalVariable *GV = cast<GlobalVariable>(getContext());
66 if (!GV->hasInitializer()) return NULL;
67 ConstantStruct *CS = cast<ConstantStruct>(GV->getInitializer());
68 return CS->getOperand(4);
71 Value *DbgStopPointInst::getDirectory() const {
72 // Once the operand indices are verified, update this assert
73 assert(LLVMDebugVersion == (6 << 16) && "Verify operand indices");
74 GlobalVariable *GV = cast<GlobalVariable>(getContext());
75 if (!GV->hasInitializer()) return NULL;
76 ConstantStruct *CS = cast<ConstantStruct>(GV->getInitializer());
77 return CS->getOperand(4);