1 //===-- InstrinsicInst.cpp - Intrinsic Instruction Wrappers -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by James M. Laskey and is distributed under
6 // the University of Illinois Open Source 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"
30 #include "llvm/Constants.h"
31 #include "llvm/GlobalVariable.h"
35 //===----------------------------------------------------------------------===//
36 /// DbgInfoIntrinsic - This is the common base class for debug info intrinsics
39 static Value *CastOperand(Value *C) {
40 if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C))
41 if (CE->getOpcode() == Instruction::Cast)
42 return CE->getOperand(0);
46 Value *DbgInfoIntrinsic::StripCast(Value *C) {
47 if (Value *CO = CastOperand(C)) {
49 } else if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) {
50 if (GV->hasInitializer())
51 if (Value *CO = CastOperand(GV->getInitializer()))
54 return dyn_cast<GlobalVariable>(C);
57 //===----------------------------------------------------------------------===//
58 /// DbgStopPointInst - This represents the llvm.dbg.stoppoint instruction.
61 std::string DbgStopPointInst::getFileName() const {
62 GlobalVariable *GV = cast<GlobalVariable>(getContext());
63 ConstantStruct *CS = cast<ConstantStruct>(GV->getInitializer());
64 return CS->getOperand(4)->getStringValue();
67 std::string DbgStopPointInst::getDirectory() const {
68 GlobalVariable *GV = cast<GlobalVariable>(getContext());
69 ConstantStruct *CS = cast<ConstantStruct>(GV->getInitializer());
70 return CS->getOperand(5)->getStringValue();
73 //===----------------------------------------------------------------------===//
74 /// Ensure that users of IntrinsicInst.h will link with this module.
75 DEFINING_FILE_FOR(IntrinsicInst)