aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/CodeGen
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2008-10-18 02:06:02 +0000
committerDan Gohman <gohman@apple.com>2008-10-18 02:06:02 +0000
commit36322c7717f7af5790ea0e64ce3d332e2df15060 (patch)
treebdd9f9d2f77e38a304c7abc38e87b8f734f06da8 /include/llvm/CodeGen
parent0d946af84c2a30b411cf0411a8b74d933a952e6c (diff)
downloadexternal_llvm-36322c7717f7af5790ea0e64ce3d332e2df15060.zip
external_llvm-36322c7717f7af5790ea0e64ce3d332e2df15060.tar.gz
external_llvm-36322c7717f7af5790ea0e64ce3d332e2df15060.tar.bz2
Teach DAGCombine to fold constant offsets into GlobalAddress nodes,
and add a TargetLowering hook for it to use to determine when this is legal (i.e. not in PIC mode, etc.) This allows instruction selection to emit folded constant offsets in more cases, such as the included testcase, eliminating the need for explicit arithmetic instructions. This eliminates the need for the C++ code in X86ISelDAGToDAG.cpp that attempted to achieve the same effect, but wasn't as effective. Also, fix handling of offsets in GlobalAddressSDNodes in several places, including changing GlobalAddressSDNode's offset from int to int64_t. The Mips, Alpha, Sparc, and CellSPU targets appear to be unaware of GlobalAddress offsets currently, so set the hook to false on those targets. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@57748 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/CodeGen')
-rw-r--r--include/llvm/CodeGen/MachineInstrBuilder.h7
-rw-r--r--include/llvm/CodeGen/MachineOperand.h10
-rw-r--r--include/llvm/CodeGen/SelectionDAG.h4
-rw-r--r--include/llvm/CodeGen/SelectionDAGNodes.h7
4 files changed, 15 insertions, 13 deletions
diff --git a/include/llvm/CodeGen/MachineInstrBuilder.h b/include/llvm/CodeGen/MachineInstrBuilder.h
index c63487d..f57168b 100644
--- a/include/llvm/CodeGen/MachineInstrBuilder.h
+++ b/include/llvm/CodeGen/MachineInstrBuilder.h
@@ -79,13 +79,14 @@ public:
}
const MachineInstrBuilder &addGlobalAddress(GlobalValue *GV,
- int Offset = 0) const {
+ int64_t Offset = 0) const {
MI->addOperand(MachineOperand::CreateGA(GV, Offset));
return *this;
}
- const MachineInstrBuilder &addExternalSymbol(const char *FnName) const{
- MI->addOperand(MachineOperand::CreateES(FnName, 0));
+ const MachineInstrBuilder &addExternalSymbol(const char *FnName,
+ int64_t Offset = 0) const {
+ MI->addOperand(MachineOperand::CreateES(FnName, Offset));
return *this;
}
};
diff --git a/include/llvm/CodeGen/MachineOperand.h b/include/llvm/CodeGen/MachineOperand.h
index f9d80c7..e3cc814 100644
--- a/include/llvm/CodeGen/MachineOperand.h
+++ b/include/llvm/CodeGen/MachineOperand.h
@@ -101,7 +101,7 @@ private:
const char *SymbolName; // For MO_ExternalSymbol.
GlobalValue *GV; // For MO_GlobalAddress.
} Val;
- int Offset; // An offset from the object.
+ int64_t Offset; // An offset from the object.
} OffsetedInfo;
} Contents;
@@ -273,7 +273,7 @@ public:
return Contents.OffsetedInfo.Val.GV;
}
- int getOffset() const {
+ int64_t getOffset() const {
assert((isGlobal() || isSymbol() || isCPI()) &&
"Wrong MachineOperand accessor");
return Contents.OffsetedInfo.Offset;
@@ -293,7 +293,7 @@ public:
Contents.ImmVal = immVal;
}
- void setOffset(int Offset) {
+ void setOffset(int64_t Offset) {
assert((isGlobal() || isSymbol() || isCPI()) &&
"Wrong MachineOperand accessor");
Contents.OffsetedInfo.Offset = Offset;
@@ -382,13 +382,13 @@ public:
Op.setIndex(Idx);
return Op;
}
- static MachineOperand CreateGA(GlobalValue *GV, int Offset) {
+ static MachineOperand CreateGA(GlobalValue *GV, int64_t Offset) {
MachineOperand Op(MachineOperand::MO_GlobalAddress);
Op.Contents.OffsetedInfo.Val.GV = GV;
Op.setOffset(Offset);
return Op;
}
- static MachineOperand CreateES(const char *SymName, int Offset = 0) {
+ static MachineOperand CreateES(const char *SymName, int64_t Offset = 0) {
MachineOperand Op(MachineOperand::MO_ExternalSymbol);
Op.Contents.OffsetedInfo.Val.SymbolName = SymName;
Op.setOffset(Offset);
diff --git a/include/llvm/CodeGen/SelectionDAG.h b/include/llvm/CodeGen/SelectionDAG.h
index d6a40a6..a6f9c1b 100644
--- a/include/llvm/CodeGen/SelectionDAG.h
+++ b/include/llvm/CodeGen/SelectionDAG.h
@@ -255,9 +255,9 @@ public:
return getConstantFP(Val, VT, true);
}
SDValue getGlobalAddress(const GlobalValue *GV, MVT VT,
- int offset = 0, bool isTargetGA = false);
+ int64_t offset = 0, bool isTargetGA = false);
SDValue getTargetGlobalAddress(const GlobalValue *GV, MVT VT,
- int offset = 0) {
+ int64_t offset = 0) {
return getGlobalAddress(GV, VT, offset, true);
}
SDValue getFrameIndex(int FI, MVT VT, bool isTarget = false);
diff --git a/include/llvm/CodeGen/SelectionDAGNodes.h b/include/llvm/CodeGen/SelectionDAGNodes.h
index 94c8dad..4947832 100644
--- a/include/llvm/CodeGen/SelectionDAGNodes.h
+++ b/include/llvm/CodeGen/SelectionDAGNodes.h
@@ -1819,15 +1819,16 @@ public:
class GlobalAddressSDNode : public SDNode {
GlobalValue *TheGlobal;
- int Offset;
+ int64_t Offset;
virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
protected:
friend class SelectionDAG;
- GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT VT, int o = 0);
+ GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT VT,
+ int64_t o = 0);
public:
GlobalValue *getGlobal() const { return TheGlobal; }
- int getOffset() const { return Offset; }
+ int64_t getOffset() const { return Offset; }
static bool classof(const GlobalAddressSDNode *) { return true; }
static bool classof(const SDNode *N) {