-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[RISCV] Support the large code model. #70308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
fdacc7e
[RFC][RISCV] Support the large code model.
13b7416
Alphabetize forward declaration
tclin914 27a9742
Remove unused Modifier
tclin914 0a99b3a
clang-foramt
tclin914 b63a05a
Rewrite the code to avoid adding unneeded function.
tclin914 6f392e6
Address topperc's comments
tclin914 3d4df04
Move `enum RISCVCPKind` into the class that uses it.
tclin914 ea5f693
clang-format
tclin914 624766b
Use PtrVT instead of getPointerTy(DAG.getDataLayout())
tclin914 9eb398d
Use else if to avoid touching all the lines below
tclin914 0e3f0ea
Remove getLargeBlockAddress function
tclin914 f02a178
Remove two subclasses
tclin914 31e8c6c
`unrecognized constant pool value` -> `unrecognized constant pool type`
tclin914 f6e60b5
Remove Type cast
tclin914 ee38bb4
Remove `else` from after `return`
tclin914 a8cd4f7
Use `auto *`
tclin914 6216bc5
Drop curly braces around single line statement
tclin914 4be2bcc
Inline getLargeAddr function
tclin914 544286a
Pass SDLoc by const reference
tclin914 56cd55b
Capitalize `s`
tclin914 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| //===------- RISCVConstantPoolValue.cpp - RISC-V constantpool value -------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This file implements the RISC-V specific constantpool value class. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "RISCVConstantPoolValue.h" | ||
| #include "llvm/ADT/FoldingSet.h" | ||
| #include "llvm/IR/Constants.h" | ||
| #include "llvm/IR/DerivedTypes.h" | ||
| #include "llvm/IR/GlobalValue.h" | ||
| #include "llvm/IR/Type.h" | ||
| #include "llvm/Support/Casting.h" | ||
| #include "llvm/Support/raw_ostream.h" | ||
|
|
||
| using namespace llvm; | ||
|
|
||
| RISCVConstantPoolValue::RISCVConstantPoolValue(Type *Ty, const GlobalValue *GV) | ||
| : MachineConstantPoolValue(Ty), GV(GV), Kind(RISCVCPKind::GlobalValue) {} | ||
|
|
||
| RISCVConstantPoolValue::RISCVConstantPoolValue(LLVMContext &C, StringRef S) | ||
| : MachineConstantPoolValue(Type::getInt64Ty(C)), S(S), | ||
| Kind(RISCVCPKind::ExtSymbol) {} | ||
|
|
||
| RISCVConstantPoolValue *RISCVConstantPoolValue::Create(const GlobalValue *GV) { | ||
| return new RISCVConstantPoolValue(GV->getType(), GV); | ||
| } | ||
|
|
||
| RISCVConstantPoolValue *RISCVConstantPoolValue::Create(LLVMContext &C, | ||
| StringRef s) { | ||
| return new RISCVConstantPoolValue(C, s); | ||
| } | ||
|
|
||
| int RISCVConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP, | ||
| Align Alignment) { | ||
| const std::vector<MachineConstantPoolEntry> &Constants = CP->getConstants(); | ||
| for (unsigned i = 0, e = Constants.size(); i != e; ++i) { | ||
| if (Constants[i].isMachineConstantPoolEntry() && | ||
| Constants[i].getAlign() >= Alignment) { | ||
| auto *CPV = | ||
| static_cast<RISCVConstantPoolValue *>(Constants[i].Val.MachineCPVal); | ||
| if (equals(CPV)) | ||
| return i; | ||
| } | ||
| } | ||
|
|
||
| return -1; | ||
| } | ||
|
|
||
| void RISCVConstantPoolValue::addSelectionDAGCSEId(FoldingSetNodeID &ID) { | ||
| if (isGlobalValue()) | ||
| ID.AddPointer(GV); | ||
| else { | ||
| assert(isExtSymbol() && "unrecognized constant pool type"); | ||
| ID.AddString(S); | ||
| } | ||
| } | ||
|
|
||
| void RISCVConstantPoolValue::print(raw_ostream &O) const { | ||
| if (isGlobalValue()) | ||
| O << GV->getName(); | ||
| else { | ||
| assert(isExtSymbol() && "unrecognized constant pool type"); | ||
| O << S; | ||
| } | ||
| } | ||
|
|
||
| bool RISCVConstantPoolValue::equals(const RISCVConstantPoolValue *A) const { | ||
| if (isGlobalValue() && A->isGlobalValue()) | ||
| return GV == A->GV; | ||
| if (isExtSymbol() && A->isExtSymbol()) | ||
| return S == A->S; | ||
|
|
||
| return false; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| //===--- RISCVConstantPoolValue.h - RISC-V constantpool value ---*- C++ -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This file implements the RISC-V specific constantpool value class. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLVM_LIB_TARGET_RISCV_RISCVCONSTANTPOOLVALUE_H | ||
| #define LLVM_LIB_TARGET_RISCV_RISCVCONSTANTPOOLVALUE_H | ||
|
|
||
| #include "llvm/ADT/StringRef.h" | ||
| #include "llvm/CodeGen/MachineConstantPool.h" | ||
| #include "llvm/Support/Casting.h" | ||
| #include "llvm/Support/ErrorHandling.h" | ||
|
|
||
| namespace llvm { | ||
|
|
||
| class BlockAddress; | ||
| class GlobalValue; | ||
| class LLVMContext; | ||
|
|
||
| /// A RISCV-specific constant pool value. | ||
| class RISCVConstantPoolValue : public MachineConstantPoolValue { | ||
| const GlobalValue *GV; | ||
| const StringRef S; | ||
|
|
||
| RISCVConstantPoolValue(Type *Ty, const GlobalValue *GV); | ||
| RISCVConstantPoolValue(LLVMContext &C, StringRef s); | ||
|
|
||
| private: | ||
| enum class RISCVCPKind { ExtSymbol, GlobalValue }; | ||
| RISCVCPKind Kind; | ||
|
|
||
| public: | ||
| ~RISCVConstantPoolValue() = default; | ||
|
|
||
| static RISCVConstantPoolValue *Create(const GlobalValue *GV); | ||
| static RISCVConstantPoolValue *Create(LLVMContext &C, StringRef s); | ||
tclin914 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| bool isGlobalValue() const { return Kind == RISCVCPKind::GlobalValue; } | ||
| bool isExtSymbol() const { return Kind == RISCVCPKind::ExtSymbol; } | ||
|
|
||
| const GlobalValue *getGlobalValue() const { return GV; } | ||
| StringRef getSymbol() const { return S; } | ||
|
|
||
| int getExistingMachineCPValue(MachineConstantPool *CP, | ||
| Align Alignment) override; | ||
|
|
||
| void addSelectionDAGCSEId(FoldingSetNodeID &ID) override; | ||
|
|
||
| void print(raw_ostream &O) const override; | ||
|
|
||
| bool equals(const RISCVConstantPoolValue *A) const; | ||
| }; | ||
|
|
||
| } // end namespace llvm | ||
|
|
||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.