2007-01-26 21:38:26 +00:00
|
|
|
//===-- llvm/CodeGen/MachineModuleInfo.h ------------------------*- C++ -*-===//
|
2005-12-16 22:45:29 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-12-16 22:45:29 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2007-01-26 21:38:26 +00:00
|
|
|
// Collect meta information for a module. This information should be in a
|
|
|
|
// neutral form that can be used by different debugging and exception handling
|
|
|
|
// schemes.
|
2005-12-16 22:45:29 +00:00
|
|
|
//
|
2006-01-17 17:31:53 +00:00
|
|
|
// The organization of information is primarily clustered around the source
|
2006-02-06 19:12:02 +00:00
|
|
|
// compile units. The main exception is source line correspondence where
|
2006-01-17 17:31:53 +00:00
|
|
|
// inlining may interleave code from various compile units.
|
|
|
|
//
|
2007-01-26 21:38:26 +00:00
|
|
|
// The following information can be retrieved from the MachineModuleInfo.
|
2006-01-17 17:31:53 +00:00
|
|
|
//
|
|
|
|
// -- Source directories - Directories are uniqued based on their canonical
|
2006-02-06 15:33:21 +00:00
|
|
|
// string and assigned a sequential numeric ID (base 1.)
|
2006-01-17 17:31:53 +00:00
|
|
|
// -- Source files - Files are also uniqued based on their name and directory
|
2006-02-06 15:33:21 +00:00
|
|
|
// ID. A file ID is sequential number (base 1.)
|
2006-10-17 21:51:44 +00:00
|
|
|
// -- Source line correspondence - A vector of file ID, line#, column# triples.
|
2006-01-17 17:31:53 +00:00
|
|
|
// A DEBUG_LOCATION instruction is generated by the DAG Legalizer
|
|
|
|
// corresponding to each entry in the source line list. This allows a debug
|
2006-02-06 19:12:02 +00:00
|
|
|
// emitter to generate labels referenced by debug information tables.
|
2006-01-17 17:31:53 +00:00
|
|
|
//
|
2005-12-16 22:45:29 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-01-26 21:38:26 +00:00
|
|
|
#ifndef LLVM_CODEGEN_MACHINEMODULEINFO_H
|
|
|
|
#define LLVM_CODEGEN_MACHINEMODULEINFO_H
|
2005-12-16 22:45:29 +00:00
|
|
|
|
2008-07-03 22:53:42 +00:00
|
|
|
#include "llvm/Support/Dwarf.h"
|
|
|
|
#include "llvm/Support/DataTypes.h"
|
2008-06-27 00:09:40 +00:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2008-07-03 22:53:42 +00:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2008-06-27 00:09:40 +00:00
|
|
|
#include "llvm/ADT/UniqueVector.h"
|
2008-07-03 22:53:42 +00:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2009-04-10 18:58:59 +00:00
|
|
|
#include "llvm/ADT/SmallSet.h"
|
2008-07-07 20:59:31 +00:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
2008-10-16 00:20:14 +00:00
|
|
|
#include "llvm/CodeGen/MachineLocation.h"
|
2008-07-03 22:53:42 +00:00
|
|
|
#include "llvm/GlobalValue.h"
|
|
|
|
#include "llvm/Pass.h"
|
2005-12-16 22:45:29 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
2006-01-17 17:31:53 +00:00
|
|
|
|
2006-02-06 15:33:21 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2006-01-26 20:21:46 +00:00
|
|
|
// Forward declarations.
|
2006-02-11 01:01:30 +00:00
|
|
|
class Constant;
|
2006-01-26 20:21:46 +00:00
|
|
|
class GlobalVariable;
|
2007-02-21 22:38:31 +00:00
|
|
|
class MachineBasicBlock;
|
2006-04-07 16:34:46 +00:00
|
|
|
class MachineFunction;
|
2006-01-26 20:21:46 +00:00
|
|
|
class Module;
|
2006-02-06 15:33:21 +00:00
|
|
|
class PointerType;
|
|
|
|
class StructType;
|
2008-07-03 22:53:42 +00:00
|
|
|
|
2007-02-21 22:38:31 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// LandingPadInfo - This structure is used to retain landing pad info for
|
|
|
|
/// the current function.
|
|
|
|
///
|
|
|
|
struct LandingPadInfo {
|
|
|
|
MachineBasicBlock *LandingPadBlock; // Landing pad block.
|
2007-05-10 22:34:59 +00:00
|
|
|
SmallVector<unsigned, 1> BeginLabels; // Labels prior to invoke.
|
|
|
|
SmallVector<unsigned, 1> EndLabels; // Labels after invoke.
|
2007-02-21 22:38:31 +00:00
|
|
|
unsigned LandingPadLabel; // Label at beginning of landing pad.
|
|
|
|
Function *Personality; // Personality function.
|
2007-06-02 16:53:42 +00:00
|
|
|
std::vector<int> TypeIds; // List of type ids (filters negative)
|
|
|
|
|
2007-09-24 15:48:49 +00:00
|
|
|
explicit LandingPadInfo(MachineBasicBlock *MBB)
|
2007-02-21 22:38:31 +00:00
|
|
|
: LandingPadBlock(MBB)
|
|
|
|
, LandingPadLabel(0)
|
2007-05-23 11:08:31 +00:00
|
|
|
, Personality(NULL)
|
2007-02-21 22:38:31 +00:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2005-12-16 22:45:29 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-01-26 21:38:26 +00:00
|
|
|
/// MachineModuleInfo - This class contains meta information specific to a
|
|
|
|
/// module. Queries can be made by different debugging and exception handling
|
|
|
|
/// schemes and reformated for specific use.
|
2005-12-16 22:45:29 +00:00
|
|
|
///
|
2007-01-26 21:38:26 +00:00
|
|
|
class MachineModuleInfo : public ImmutablePass {
|
2005-12-16 22:45:29 +00:00
|
|
|
private:
|
2006-11-07 19:33:46 +00:00
|
|
|
// LabelIDList - One entry per assigned label. Normally the entry is equal to
|
|
|
|
// the list index(+1). If the entry is zero then the label has been deleted.
|
|
|
|
// Any other value indicates the label has been deleted by is mapped to
|
|
|
|
// another label.
|
|
|
|
std::vector<unsigned> LabelIDList;
|
2006-03-23 18:07:55 +00:00
|
|
|
|
2006-04-07 16:34:46 +00:00
|
|
|
// FrameMoves - List of moves done by a function's prolog. Used to construct
|
2007-01-26 21:38:26 +00:00
|
|
|
// frame maps by debug and exception handling consumers.
|
2007-01-24 18:45:13 +00:00
|
|
|
std::vector<MachineMove> FrameMoves;
|
2007-02-21 22:38:31 +00:00
|
|
|
|
|
|
|
// LandingPads - List of LandingPadInfo describing the landing pad information
|
|
|
|
// in the current function.
|
|
|
|
std::vector<LandingPadInfo> LandingPads;
|
|
|
|
|
2007-02-22 16:40:10 +00:00
|
|
|
// TypeInfos - List of C++ TypeInfo used in the current function.
|
2007-02-21 22:38:31 +00:00
|
|
|
//
|
|
|
|
std::vector<GlobalVariable *> TypeInfos;
|
2005-12-16 22:45:29 +00:00
|
|
|
|
2007-06-02 16:53:42 +00:00
|
|
|
// FilterIds - List of typeids encoding filters used in the current function.
|
|
|
|
//
|
|
|
|
std::vector<unsigned> FilterIds;
|
|
|
|
|
2007-07-05 15:15:01 +00:00
|
|
|
// FilterEnds - List of the indices in FilterIds corresponding to filter
|
|
|
|
// terminators.
|
|
|
|
//
|
|
|
|
std::vector<unsigned> FilterEnds;
|
|
|
|
|
2007-05-13 15:42:26 +00:00
|
|
|
// Personalities - Vector of all personality functions ever seen. Used to emit
|
|
|
|
// common EH frames.
|
|
|
|
std::vector<Function *> Personalities;
|
2007-07-14 14:06:15 +00:00
|
|
|
|
2008-01-16 19:59:28 +00:00
|
|
|
// UsedFunctions - the functions in the llvm.used list in a more easily
|
|
|
|
// searchable format.
|
|
|
|
SmallPtrSet<const Function *, 32> UsedFunctions;
|
|
|
|
|
2009-04-10 18:58:59 +00:00
|
|
|
/// UsedDbgLabels - labels are used by debug info entries.
|
|
|
|
SmallSet<unsigned, 8> UsedDbgLabels;
|
|
|
|
|
2007-07-14 14:06:15 +00:00
|
|
|
bool CallsEHReturn;
|
|
|
|
bool CallsUnwindInit;
|
2009-01-13 23:02:17 +00:00
|
|
|
|
|
|
|
/// DbgInfoAvailable - True if debugging information is available
|
|
|
|
/// in this module.
|
|
|
|
bool DbgInfoAvailable;
|
2005-12-16 22:45:29 +00:00
|
|
|
public:
|
2007-05-06 13:37:16 +00:00
|
|
|
static char ID; // Pass identification, replacement for typeid
|
2007-05-01 21:15:47 +00:00
|
|
|
|
2007-01-26 21:38:26 +00:00
|
|
|
MachineModuleInfo();
|
|
|
|
~MachineModuleInfo();
|
2005-12-16 22:45:29 +00:00
|
|
|
|
2007-01-26 21:38:26 +00:00
|
|
|
/// doInitialization - Initialize the state for a new module.
|
2006-01-04 14:29:26 +00:00
|
|
|
///
|
2006-01-17 17:31:53 +00:00
|
|
|
bool doInitialization();
|
|
|
|
|
2007-01-26 21:38:26 +00:00
|
|
|
/// doFinalization - Tear down the state after completion of a module.
|
2005-12-16 22:45:29 +00:00
|
|
|
///
|
2006-01-17 17:31:53 +00:00
|
|
|
bool doFinalization();
|
|
|
|
|
2007-01-26 21:38:26 +00:00
|
|
|
/// BeginFunction - Begin gathering function meta information.
|
2006-04-07 16:34:46 +00:00
|
|
|
///
|
|
|
|
void BeginFunction(MachineFunction *MF);
|
|
|
|
|
2007-01-26 21:38:26 +00:00
|
|
|
/// EndFunction - Discard function meta information.
|
2006-04-07 16:34:46 +00:00
|
|
|
///
|
|
|
|
void EndFunction();
|
|
|
|
|
2006-01-26 20:21:46 +00:00
|
|
|
/// AnalyzeModule - Scan the module for global debug information.
|
|
|
|
///
|
|
|
|
void AnalyzeModule(Module &M);
|
|
|
|
|
2007-01-26 21:38:26 +00:00
|
|
|
/// hasDebugInfo - Returns true if valid debug info is present.
|
2006-01-17 17:31:53 +00:00
|
|
|
///
|
2009-01-13 23:02:17 +00:00
|
|
|
bool hasDebugInfo() const { return DbgInfoAvailable; }
|
|
|
|
void setDebugInfoAvailability(bool avail) { DbgInfoAvailable = true; }
|
|
|
|
|
2007-07-14 14:06:15 +00:00
|
|
|
bool callsEHReturn() const { return CallsEHReturn; }
|
|
|
|
void setCallsEHReturn(bool b) { CallsEHReturn = b; }
|
|
|
|
|
|
|
|
bool callsUnwindInit() const { return CallsUnwindInit; }
|
|
|
|
void setCallsUnwindInit(bool b) { CallsUnwindInit = b; }
|
2007-01-29 23:20:22 +00:00
|
|
|
|
2006-03-23 18:07:55 +00:00
|
|
|
/// NextLabelID - Return the next unique label id.
|
|
|
|
///
|
2006-11-07 19:33:46 +00:00
|
|
|
unsigned NextLabelID() {
|
2008-05-05 18:30:58 +00:00
|
|
|
unsigned ID = (unsigned)LabelIDList.size() + 1;
|
2006-11-07 19:33:46 +00:00
|
|
|
LabelIDList.push_back(ID);
|
|
|
|
return ID;
|
|
|
|
}
|
2006-03-23 18:07:55 +00:00
|
|
|
|
2008-02-01 02:05:57 +00:00
|
|
|
/// RecordSourceLine - Records location information and associates it with a
|
2007-01-26 21:38:26 +00:00
|
|
|
/// label. Returns a unique label ID used to generate a label and
|
2006-01-17 17:31:53 +00:00
|
|
|
/// provide correspondence to the source line list.
|
2008-02-01 02:05:57 +00:00
|
|
|
unsigned RecordSourceLine(unsigned Line, unsigned Column, unsigned Source);
|
2006-01-05 01:25:28 +00:00
|
|
|
|
2006-10-23 14:56:37 +00:00
|
|
|
/// InvalidateLabel - Inhibit use of the specified label # from
|
2007-01-26 21:38:26 +00:00
|
|
|
/// MachineModuleInfo, for example because the code was deleted.
|
2006-11-07 19:33:46 +00:00
|
|
|
void InvalidateLabel(unsigned LabelID) {
|
|
|
|
// Remap to zero to indicate deletion.
|
|
|
|
RemapLabel(LabelID, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// RemapLabel - Indicate that a label has been merged into another.
|
|
|
|
///
|
|
|
|
void RemapLabel(unsigned OldLabelID, unsigned NewLabelID) {
|
2006-11-08 14:16:39 +00:00
|
|
|
assert(0 < OldLabelID && OldLabelID <= LabelIDList.size() &&
|
2007-01-26 21:38:26 +00:00
|
|
|
"Old label ID out of range.");
|
2006-11-08 14:16:39 +00:00
|
|
|
assert(NewLabelID <= LabelIDList.size() &&
|
2007-01-26 21:38:26 +00:00
|
|
|
"New label ID out of range.");
|
2006-11-07 19:33:46 +00:00
|
|
|
LabelIDList[OldLabelID - 1] = NewLabelID;
|
|
|
|
}
|
2006-10-17 23:16:42 +00:00
|
|
|
|
2006-11-07 19:33:46 +00:00
|
|
|
/// MappedLabel - Find out the label's final ID. Zero indicates deletion.
|
|
|
|
/// ID != Mapped ID indicates that the label was folded into another label.
|
|
|
|
unsigned MappedLabel(unsigned LabelID) const {
|
2006-11-08 14:16:39 +00:00
|
|
|
assert(LabelID <= LabelIDList.size() && "Debug label ID out of range.");
|
|
|
|
return LabelID ? LabelIDList[LabelID - 1] : 0;
|
2006-11-07 19:33:46 +00:00
|
|
|
}
|
2006-10-23 14:56:37 +00:00
|
|
|
|
2009-04-10 18:58:59 +00:00
|
|
|
/// isDbgLabelUsed - Return true if label with LabelID is used by
|
|
|
|
/// DwarfWriter.
|
|
|
|
bool isDbgLabelUsed(unsigned LabelID) {
|
|
|
|
return UsedDbgLabels.count(LabelID);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// RecordUsedDbgLabel - Mark label with LabelID as used. This is used
|
|
|
|
/// by DwarfWriter to inform DebugLabelFolder that certain labels are
|
|
|
|
/// not to be deleted.
|
|
|
|
void RecordUsedDbgLabel(unsigned LabelID) {
|
|
|
|
UsedDbgLabels.insert(LabelID);
|
|
|
|
}
|
|
|
|
|
2006-04-07 16:34:46 +00:00
|
|
|
/// getFrameMoves - Returns a reference to a list of moves done in the current
|
2007-01-26 21:38:26 +00:00
|
|
|
/// function's prologue. Used to construct frame maps for debug and exception
|
|
|
|
/// handling comsumers.
|
2007-01-24 18:45:13 +00:00
|
|
|
std::vector<MachineMove> &getFrameMoves() { return FrameMoves; }
|
2007-02-21 22:38:31 +00:00
|
|
|
|
|
|
|
//===-EH-----------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// getOrCreateLandingPadInfo - Find or create an LandingPadInfo for the
|
|
|
|
/// specified MachineBasicBlock.
|
|
|
|
LandingPadInfo &getOrCreateLandingPadInfo(MachineBasicBlock *LandingPad);
|
|
|
|
|
|
|
|
/// addInvoke - Provide the begin and end labels of an invoke style call and
|
|
|
|
/// associate it with a try landing pad block.
|
|
|
|
void addInvoke(MachineBasicBlock *LandingPad, unsigned BeginLabel,
|
|
|
|
unsigned EndLabel);
|
|
|
|
|
|
|
|
/// addLandingPad - Add a new panding pad. Returns the label ID for the
|
|
|
|
/// landing pad entry.
|
|
|
|
unsigned addLandingPad(MachineBasicBlock *LandingPad);
|
|
|
|
|
|
|
|
/// addPersonality - Provide the personality function for the exception
|
|
|
|
/// information.
|
|
|
|
void addPersonality(MachineBasicBlock *LandingPad, Function *Personality);
|
2007-05-13 15:42:26 +00:00
|
|
|
|
|
|
|
/// getPersonalityIndex - Get index of the current personality function inside
|
|
|
|
/// Personalitites array
|
|
|
|
unsigned getPersonalityIndex() const;
|
|
|
|
|
|
|
|
/// getPersonalities - Return array of personality functions ever seen.
|
|
|
|
const std::vector<Function *>& getPersonalities() const {
|
|
|
|
return Personalities;
|
|
|
|
}
|
2007-06-02 16:53:42 +00:00
|
|
|
|
2008-01-16 19:59:28 +00:00
|
|
|
// UsedFunctions - Return set of the functions in the llvm.used list.
|
|
|
|
const SmallPtrSet<const Function *, 32>& getUsedFunctions() const {
|
|
|
|
return UsedFunctions;
|
|
|
|
}
|
|
|
|
|
2007-02-21 22:38:31 +00:00
|
|
|
/// addCatchTypeInfo - Provide the catch typeinfo for a landing pad.
|
|
|
|
///
|
|
|
|
void addCatchTypeInfo(MachineBasicBlock *LandingPad,
|
|
|
|
std::vector<GlobalVariable *> &TyInfo);
|
2007-06-02 16:53:42 +00:00
|
|
|
|
|
|
|
/// addFilterTypeInfo - Provide the filter typeinfo for a landing pad.
|
2007-03-01 20:25:32 +00:00
|
|
|
///
|
2007-06-02 16:53:42 +00:00
|
|
|
void addFilterTypeInfo(MachineBasicBlock *LandingPad,
|
|
|
|
std::vector<GlobalVariable *> &TyInfo);
|
|
|
|
|
There is an impedance matching problem between LLVM and
gcc exception handling: if an exception unwinds through
an invoke, then execution must branch to the invoke's
unwind target. We previously tried to enforce this by
appending a cleanup action to every selector, however
this does not always work correctly due to an optimization
in the C++ unwinding runtime: if only cleanups would be
run while unwinding an exception, then the program just
terminates without actually executing the cleanups, as
invoke semantics would require. I was hoping this
wouldn't be a problem, but in fact it turns out to be the
cause of all the remaining failures in the LLVM testsuite
(these also fail with -enable-correct-eh-support, so turning
on -enable-eh didn't make things worse!). Instead we need
to append a full-blown catch-all to the end of each
selector. The correct way of doing this depends on the
personality function, i.e. it is language dependent, so
can only be done by gcc. Thus this patch which generalizes
the eh.selector intrinsic so that it can handle all possible
kinds of action table entries (before it didn't accomodate
cleanups): now 0 indicates a cleanup, and filters have to be
specified using the number of type infos plus one rather than
the number of type infos. Related gcc patches will cause
Ada to pass a cleanup (0) to force the selector to always
fire, while C++ will use a C++ catch-all (null).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41484 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-27 15:47:50 +00:00
|
|
|
/// addCleanup - Add a cleanup action for a landing pad.
|
|
|
|
///
|
|
|
|
void addCleanup(MachineBasicBlock *LandingPad);
|
|
|
|
|
2007-02-21 22:38:31 +00:00
|
|
|
/// getTypeIDFor - Return the type id for the specified typeinfo. This is
|
|
|
|
/// function wide.
|
|
|
|
unsigned getTypeIDFor(GlobalVariable *TI);
|
2007-06-02 16:53:42 +00:00
|
|
|
|
|
|
|
/// getFilterIDFor - Return the id of the filter encoded by TyIds. This is
|
|
|
|
/// function wide.
|
2008-06-27 01:27:56 +00:00
|
|
|
int getFilterIDFor(std::vector<unsigned> &TyIds);
|
2007-06-02 16:53:42 +00:00
|
|
|
|
2007-02-21 22:38:31 +00:00
|
|
|
/// TidyLandingPads - Remap landing pad labels and remove any deleted landing
|
|
|
|
/// pads.
|
|
|
|
void TidyLandingPads();
|
|
|
|
|
2007-05-13 15:42:26 +00:00
|
|
|
/// getLandingPads - Return a reference to the landing pad info for the
|
2007-02-21 22:38:31 +00:00
|
|
|
/// current function.
|
|
|
|
const std::vector<LandingPadInfo> &getLandingPads() const {
|
|
|
|
return LandingPads;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getTypeInfos - Return a reference to the C++ typeinfo for the current
|
|
|
|
/// function.
|
|
|
|
const std::vector<GlobalVariable *> &getTypeInfos() const {
|
|
|
|
return TypeInfos;
|
|
|
|
}
|
2007-06-02 16:53:42 +00:00
|
|
|
|
|
|
|
/// getFilterIds - Return a reference to the typeids encoding filters used in
|
|
|
|
/// the current function.
|
|
|
|
const std::vector<unsigned> &getFilterIds() const {
|
|
|
|
return FilterIds;
|
|
|
|
}
|
|
|
|
|
2007-02-21 22:38:31 +00:00
|
|
|
/// getPersonality - Return a personality function if available. The presence
|
|
|
|
/// of one is required to emit exception handling info.
|
|
|
|
Function *getPersonality() const;
|
2006-01-26 20:21:46 +00:00
|
|
|
|
2007-01-26 21:38:26 +00:00
|
|
|
}; // End class MachineModuleInfo
|
2005-12-16 22:45:29 +00:00
|
|
|
|
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|